Merge branch 'collectd-4.0' into collectd-4.1
[collectd.git] / src / common.c
index 9ebfe27..7555b7e 100644 (file)
@@ -70,12 +70,25 @@ 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';
+#ifdef STRERROR_R_CHAR_P
+       {
+               char *temp;
+               temp = strerror_r (errnum, buf, buflen);
+               if (buf[0] == '\0')
+               {
+                       strncpy (buf, temp, buflen);
+                       buf[buflen - 1] = '\0';
+               }
+       }
+#else
        strerror_r (errnum, buf, buflen);
+#endif /* STRERROR_R_CHAR_P */
        return (buf);
 } /* char *sstrerror */