Mercurial > gnulib
changeset 38922:0f680033845a
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 29 Oct 2017 17:33:22 +0100 |
parents | 8c3c1dae80c7 |
children | 61e91eb6157b |
files | ChangeLog doc/posix-functions/strerror_r.texi lib/strerror_r.c tests/test-strerror_r.c |
diffstat | 4 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Oct 29 14:34:21 2017 +0100 +++ b/ChangeLog Sun Oct 29 17:33:22 2017 +0100 @@ -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.
--- a/doc/posix-functions/strerror_r.texi Sun Oct 29 14:34:21 2017 +0100 +++ b/doc/posix-functions/strerror_r.texi Sun Oct 29 17:33:22 2017 +0100 @@ -62,7 +62,7 @@ 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
--- a/lib/strerror_r.c Sun Oct 29 14:34:21 2017 +0100 +++ b/lib/strerror_r.c Sun Oct 29 17:33:22 2017 +0100 @@ -212,13 +212,16 @@ # 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 @@ #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;
--- a/tests/test-strerror_r.c Sun Oct 29 14:34:21 2017 +0100 +++ b/tests/test-strerror_r.c Sun Oct 29 17:33:22 2017 +0100 @@ -108,7 +108,7 @@ 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);