diff --git a/src/common.c b/src/common.c
index 7555b7ef99d26150d81193ce7e1d4d1a8e3a4b33..1138f96ff92e688063990c1bdd084eca816fbb47 100644 (file)
--- a/src/common.c
+++ b/src/common.c
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);
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);
if (buf[0] == '\0')
{
- strncpy (buf, temp, buflen);
- buf[buflen - 1] = '\0';
+ if ((temp != NULL) && (temp != buf) && (temp[0] != '\0'))
+ strncpy (buf, temp, buflen);
+ else
+ strncpy (buf, "strerror_r did not return "
+ "an error message", buflen);
}
}
+/* #endif STRERROR_R_CHAR_P */
+
#else
- strerror_r (errnum, buf, buflen);
+ if (strerror_r (errnum, buf, buflen) != 0)
+ {
+ snprintf (buf, buflen, "Error #%i; "
+ "Additionally, strerror_r failed.",
+ errnum);
+ }
#endif /* STRERROR_R_CHAR_P */
+
+ buf[buflen - 1] = '\0';
return (buf);
} /* char *sstrerror */
if (mkdir (dir, 0755) == -1)
{
char errbuf[1024];
- ERROR ("mkdir (%s): %s", dir,
+ ERROR ("check_create_dir: mkdir (%s): %s", dir,
sstrerror (errno,
errbuf, sizeof (errbuf)));
return (-1);
}
return (0);
-}
+} /* check_create_dir */
#ifdef HAVE_LIBKSTAT
int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)