changeset 14817:2835cfc7d63e

strerror_r: fix AIX test failures Already documented as an AIX limitation. * lib/strerror_r.c (strerror_r): Convert silent truncation to ERANGE failure. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Mon, 23 May 2011 21:37:11 -0600
parents b6363790caec
children 280af315920c
files ChangeLog lib/strerror_r.c
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-05-24  Eric Blake  <eblake@redhat.com>
 
+	strerror_r: fix AIX test failures
+	* lib/strerror_r.c (strerror_r): Convert silent truncation to
+	ERANGE failure.
+
 	strerror_r: fix Solaris test failures
 	* lib/strerror_r.c (strerror_r): Partially populate buf on ERANGE
 	failures.
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -473,7 +473,8 @@
       buflen = INT_MAX;
 
 # ifdef __hpux
-    /* On HP-UX 11.31, strerror_r always fails when buflen < 80.  */
+    /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it
+       also fails to change buf on EINVAL.  */
     {
       char stackbuf[80];
 
@@ -501,6 +502,23 @@
       }
 # endif
 
+# ifdef _AIX
+    /* AIX returns 0 rather than ERANGE when truncating strings; try
+       again until we are sure we got the entire string.  */
+    if (!ret && strlen (buf) == buflen - 1)
+      {
+        char stackbuf[STACKBUF_LEN];
+        size_t len;
+        strerror_r (errnum, stackbuf, sizeof stackbuf);
+        len = strlen (stackbuf);
+        /* stackbuf should have been large enough.  */
+        if (len + 1 == sizeof stackbuf)
+          abort ();
+        if (buflen <= len)
+          ret = ERANGE;
+      }
+# endif
+
     /* Some old implementations may return (-1, EINVAL) instead of EINVAL.  */
     if (ret < 0)
       ret = errno;