]> Savannah Git Hosting - gnulib.git/commitdiff
strerror_r-posix: Fix behaviour and test failure on Haiku.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Oct 2017 16:33:22 +0000 (17:33 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Oct 2017 20:27:52 +0000 (21:27 +0100)
* 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.

ChangeLog
doc/posix-functions/strerror_r.texi
lib/strerror_r.c
tests/test-strerror_r.c

index 66d0ef604a9a70df570505fdad409268611a183b..8539105fcab5a0d148eb7f7aa16ac4881f152c3a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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.
index 40a94659609eae548c14c4dea15675d0f3ba0fe5..220446a177ef35f857e79e0dc25d62d9ff813627 100644 (file)
@@ -62,7 +62,7 @@ HP-UX 11.31.
 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
index e3a1c29b5d08a1d5fb4cb9a172b03b5f0bba40b6..14e3195cf43a923c3841091c0b1a3508fd91448e 100644 (file)
@@ -212,13 +212,16 @@ strerror_r (int errnum, char *buf, size_t buflen)
 # 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)
       {
@@ -442,7 +445,14 @@ strerror_r (int errnum, char *buf, size_t buflen)
 #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;
index 16f99dfd266e41d3287b2ebfc11b39e99592291e..7a06ed654451aff21807b4e1da3715de337cc9da 100644 (file)
@@ -108,7 +108,7 @@ main (void)
             errno = 0;
             ret = strerror_r (err, buf, i);
             ASSERT (errno == 0);
-            if (err < 0)
+            if (j == 2)
               ASSERT (ret == ERANGE || ret == EINVAL);
             else
               ASSERT (ret == ERANGE);