strerror_r: simplify AIX code.
authorEric Blake <eblake@redhat.com>
Fri, 20 May 2011 21:19:05 +0000 (15:19 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 20 May 2011 21:19:05 +0000 (15:19 -0600)
* lib/strerror_r.c (strerror_r): Filter out buflen of 1 up front.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
lib/strerror_r.c

index 598238f..bda43a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 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.
index 30dcd44..2144fc6 100644 (file)
@@ -95,6 +95,15 @@ int
 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 \
@@ -492,27 +501,6 @@ strerror_r (int errnum, char *buf, size_t buflen)
     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;