X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcommon.c;h=951bae306e834d15f3b7d1e66fb217740bedaff0;hb=aa39b2bf774bf297f6c1a3967764bd7d84e0a49f;hp=9ebfe27cb60bc3cb56ae3317f084f69b4f8cf10d;hpb=14b7c735bf93b5a6260a0e064bccc28dc7581c7f;p=collectd.git diff --git a/src/common.c b/src/common.c index 9ebfe27c..951bae30 100644 --- a/src/common.c +++ b/src/common.c @@ -70,12 +70,35 @@ char *sstrdup (const char *s) return (r); } -/* Don't use the return value of `strerror_r', because the GNU-people got - * inventive there.. -octo */ +/* Even though Posix requires "strerror_r" to return an "int", + * some systems (e.g. the GNU libc) return a "char *" _and_ + * ignore the second argument ... -tokkee */ char *sstrerror (int errnum, char *buf, size_t buflen) { buf[0] = '\0'; - strerror_r (errnum, buf, buflen); +#ifdef STRERROR_R_CHAR_P + { + char *temp; + temp = strerror_r (errnum, buf, buflen); + if (buf[0] == '\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); + buf[buflen - 1] = '\0'; + } + } +#else + 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 */