+2017-10-29 Bruno Haible <bruno@clisp.org>
+
+ strerror_r-posix: Fix behaviour and test failure on Haiku.
+ * lib/strerror_r.c (strerror_r): Don't assume that valid error numbers
+ are positive. Work around return value 0 instead of ERANGE on Haiku.
+ For unknown error numbers, use a format string consistent with perror().
+ * doc/posix-functions/strerror_r.texi: Mention the Haiku problem.
+ * tests/test-strerror_r.c (main): Don't assume that valid error numbers
+ are positive.
+
2017-10-29 Bruno Haible <bruno@clisp.org>
get-rusage-data: Avoid crash on Haiku.
When the buffer is too small and the value is in range, this function
does not fail, but instead truncates the result and returns 0 on some
platforms:
-AIX 6.1, OSF/1 5.1.
+AIX 6.1, OSF/1 5.1, Haiku 2017.
@item
When the value is not in range or the buffer is too small, this
function fails to leave a NUL-terminated string in the buffer on some
# else
ret = strerror_r (errnum, buf, buflen);
- /* Some old implementations may return (-1, EINVAL) instead of EINVAL. */
+ /* Some old implementations may return (-1, EINVAL) instead of EINVAL.
+ But on Haiku, valid error numbers are negative. */
+# if !defined __HAIKU__
if (ret < 0)
ret = errno;
+# endif
# endif
-# ifdef _AIX
- /* AIX returns 0 rather than ERANGE when truncating strings; try
+# if defined _AIX || defined __HAIKU__
+ /* AIX and Haiku return 0 rather than ERANGE when truncating strings; try
again until we are sure we got the entire string. */
if (!ret && strlen (buf) == buflen - 1)
{
#endif
if (ret == EINVAL && !*buf)
- snprintf (buf, buflen, "Unknown error %d", errnum);
+ {
+#if defined __HAIKU__
+ /* For consistency with perror(). */
+ snprintf (buf, buflen, "Unknown Application Error (%d)", errnum);
+#else
+ snprintf (buf, buflen, "Unknown error %d", errnum);
+#endif
+ }
errno = saved_errno;
return ret;