summaryrefslogtreecommitdiff
path: root/src/port/string.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2011-10-31 19:54:01 +0100
committerAndreas Baumann <abaumann@yahoo.com>2011-10-31 19:54:01 +0100
commitd725022844380852476dbef00d7dc3c2e7a37fdb (patch)
tree7df0f711e45b5b7a737d82ef2fcdabf1d2d168fd /src/port/string.c
parent780a04f1961d766f524386eb9c58574738fbfbb3 (diff)
downloadwolfbones-d725022844380852476dbef00d7dc3c2e7a37fdb.tar.gz
wolfbones-d725022844380852476dbef00d7dc3c2e7a37fdb.tar.bz2
added a HAVE_THREADS flag
Diffstat (limited to 'src/port/string.c')
-rw-r--r--src/port/string.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/port/string.c b/src/port/string.c
index 398788c..9c360d0 100644
--- a/src/port/string.c
+++ b/src/port/string.c
@@ -49,19 +49,23 @@ char *wolf_port_strdup( const char *s ) {
#include <errno.h> /* for errno */
#include "threads/mutex.h" /* for mutexes */
+#ifdef HAVE_THREADS
static bool mutex_initialized = false;
static wolf_mutex_t mutex;
+#endif
int wolf_port_strerror_r( int num, char *buf, size_t buflen ) {
int safe_errno = errno;
const char *msg;
/* critical section as strerror is not thread-safe */
+#ifdef HAVE_THREADS
if( !mutex_initialized ) {
wolf_mutex_init( &mutex );
mutex_initialized = true;
}
wolf_mutex_lock( &mutex );
+#endif
msg = strerror( num );
/* TODO: can we detect illegal error numbers? For sure on Linux NULL
@@ -73,13 +77,17 @@ int wolf_port_strerror_r( int num, char *buf, size_t buflen ) {
/* Linux returns an empty string in this case, why? */
(void)snprintf( buf, buflen, "Unknown error %d", num );
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;
}