diff options
author | paulo <paul@bayleaf.org.uk> | 2010-02-04 15:48:35 +0000 |
---|---|---|
committer | paulo <paul@bayleaf.org.uk> | 2010-02-04 15:48:35 +0000 |
commit | c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1 (patch) | |
tree | 823514c9403eeb924b0b8a5c9029f45f174df46d /lib/pthread_safe.c | |
parent | 321902625926d21f511c2d0c55f5aad634224e75 (diff) | |
download | quagga-c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1.tar.bz2 quagga-c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1.tar.xz |
Missed a few non safe calls of strerror. Improved comments.
Diffstat (limited to 'lib/pthread_safe.c')
-rw-r--r-- | lib/pthread_safe.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/pthread_safe.c b/lib/pthread_safe.c index a8da3a71..f67e6b2a 100644 --- a/lib/pthread_safe.c +++ b/lib/pthread_safe.c @@ -65,6 +65,7 @@ safe_finish(void) pthread_key_delete(tsd_key); } +/* called when thread terminates, clean up */ static void destructor(void* data) { @@ -97,16 +98,28 @@ safe_strerror(int errnum) } } +/* Thread safe version of inet_ntoa. Never returns NULL. + * Contents of result remains intact until another call of + * a safe_ function. + */ const char * safe_inet_ntoa (struct in_addr in) { - if (qpthreads_enabled) - return inet_ntop(AF_INET, &in, thread_buff(), buff_size); - else - return inet_ntoa(in); + static const char * unknown = "Unknown address"; + const char * buff; + + buff = (qpthreads_enabled) + ? inet_ntop(AF_INET, &in, thread_buff(), buff_size) + : inet_ntoa(in); + + return buff != NULL + ? buff + : unknown; } -/* Return the thread's buffer */ +/* Return the thread's buffer, create it if necessary. + * (pthread Thread Specific Data) + */ static char * thread_buff(void) { |