changeset 14782:5a7b4517a078

strerror_r: simplify AIX code. * lib/strerror_r.c (strerror_r): Filter out buflen of 1 up front. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Fri, 20 May 2011 15:19:05 -0600
parents 36e3daf695d6
children daa3d25b0532
files ChangeLog lib/strerror_r.c
diffstat 2 files changed, 12 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -95,6 +95,15 @@
 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 @@
     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;