From 4053192182658147f98bddddcec55eb1ff1dd67c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 26 Oct 2007 10:50:43 +0200 Subject: [PATCH] src/common.c: Serialize access to `strerror' if `strerror_r' doesn't exist. Apparently this is a problem under Solaris 9.. --- src/common.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 974a29ea..1138f96f 100644 --- a/src/common.c +++ b/src/common.c @@ -48,6 +48,10 @@ extern kstat_ctl_t *kc; static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER; #endif +#if !HAVE_STRERROR_R +static pthread_mutex_t strerror_r_lock = PTHREAD_MUTEX_INITIALIZER; +#endif + void sstrncpy (char *d, const char *s, int len) { strncpy (d, s, len); @@ -76,7 +80,21 @@ char *sstrdup (const char *s) char *sstrerror (int errnum, char *buf, size_t buflen) { buf[0] = '\0'; -#ifdef STRERROR_R_CHAR_P + +#if !HAVE_STRERROR_R + { + char *temp; + + pthread_mutex_lock (&strerror_r_lock); + + temp = strerror (errnum); + strncpy (buf, temp, buflen); + + pthread_mutex_unlock (&strerror_r_lock); + } +/* #endif !HAVE_STRERROR_R */ + +#elif STRERROR_R_CHAR_P { char *temp; temp = strerror_r (errnum, buf, buflen); @@ -87,9 +105,10 @@ char *sstrerror (int errnum, char *buf, size_t buflen) else strncpy (buf, "strerror_r did not return " "an error message", buflen); - buf[buflen - 1] = '\0'; } } +/* #endif STRERROR_R_CHAR_P */ + #else if (strerror_r (errnum, buf, buflen) != 0) { @@ -98,6 +117,7 @@ char *sstrerror (int errnum, char *buf, size_t buflen) errnum); } #endif /* STRERROR_R_CHAR_P */ + buf[buflen - 1] = '\0'; return (buf); } /* char *sstrerror */ -- 2.11.0