diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2011-10-31 19:54:01 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2011-10-31 19:54:01 +0100 |
commit | d725022844380852476dbef00d7dc3c2e7a37fdb (patch) | |
tree | 7df0f711e45b5b7a737d82ef2fcdabf1d2d168fd /src/port/netdb.c | |
parent | 780a04f1961d766f524386eb9c58574738fbfbb3 (diff) | |
download | wolfbones-d725022844380852476dbef00d7dc3c2e7a37fdb.tar.gz wolfbones-d725022844380852476dbef00d7dc3c2e7a37fdb.tar.bz2 |
added a HAVE_THREADS flag
Diffstat (limited to 'src/port/netdb.c')
-rw-r--r-- | src/port/netdb.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/port/netdb.c b/src/port/netdb.c index b913ef9..ea4458e 100644 --- a/src/port/netdb.c +++ b/src/port/netdb.c @@ -236,31 +236,39 @@ const char *wolf_port_gai_strerror( int errcode ) { #include "port/string.h" /* for strncmp */ #include <errno.h> /* for errno */ +#ifdef HAVE_THREADS static bool mutex_initialized = false; static wolf_mutex_t mutex; +#endif int wolf_port_gai_strerror_r( int errcode, char *buf, size_t buflen ) { int safe_errno = errno; const char *msg; /* critical section as gai_strerror is not thread-safe */ +#ifdef HAVE_THREADS if( !mutex_initialized ) { wolf_mutex_init( &mutex ); mutex_initialized = true; } wolf_mutex_lock( &mutex ); +#endif msg = gai_strerror( errcode ); if( strncmp( msg, "Unknown GAI errror", strlen( "Unknown GAI error" ) ) == 0 /* our own stub implementation */ ) { (void)snprintf( buf, buflen, "Unknown GAI error %d", errcode ); errno = EINVAL; +#ifdef HAVE_THREADS wolf_mutex_unlock( &mutex ); +#endif return -1; } strncpy( buf, msg, buflen-1 ); errno = safe_errno; +#ifdef HAVE_THREADS wolf_mutex_unlock( &mutex ); +#endif return 0; } |