2011-05-20 Eric Blake <eblake@redhat.com>
+ strerror_r: simplify AIX code.
+ * lib/strerror_r.c (strerror_r): Filter out buflen of 1 up front.
+
test-perror: avoid spurious failure on FreeBSD
* modules/perror-tests (Depends-on): Add strerror, now that
strerror_r no longer pulls it in.
strerror_r (int errnum, char *buf, size_t buflen)
#undef strerror_r
{
+ /* Filter this out now, so that rest of this replacement knows that
+ there is room for a non-empty message and trailing NUL. */
+ if (buflen <= 1)
+ {
+ if (buflen)
+ *buf = 0;
+ return ERANGE;
+ }
+
#if GNULIB_defined_ETXTBSY \
|| GNULIB_defined_ESOCK \
|| GNULIB_defined_ENOMSG \
ret = strerror_r (errnum, buf, buflen);
# endif
-# ifdef _AIX
- /* On AIX 6.1, strerror_r returns -1 and sets errno to EINVAL
- if buflen <= 1. */
- if (ret < 0 && errno == EINVAL && buflen <= 1)
- {
- /* Retry with a larger buffer. */
- char largerbuf[10];
- ret = strerror_r (errnum, largerbuf, sizeof (largerbuf));
- if (ret < 0 && errno == EINVAL)
- {
- /* errnum was out of range. */
- ret = EINVAL;
- }
- else
- {
- /* buf was too small. */
- ret = ERANGE;
- }
- }
-# endif
-
/* Some old implementations may return (-1, EINVAL) instead of EINVAL. */
if (ret < 0)
ret = errno;