summaryrefslogtreecommitdiff
path: root/lib/strerror_r.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-05-23 21:37:11 -0600
committerEric Blake <eblake@redhat.com>2011-05-24 13:42:57 -0600
commit8ea7a67217abecef3dce757f11f719e1c205f7a8 (patch)
tree4aacf0aa0a311d29c1dd87deefe42dd3562626ae /lib/strerror_r.c
parente67e250d98e9dc0177a564f2cbfa99330902fe9e (diff)
downloadgnulib-8ea7a67217abecef3dce757f11f719e1c205f7a8.tar.gz
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>
Diffstat (limited to 'lib/strerror_r.c')
-rw-r--r--lib/strerror_r.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/strerror_r.c b/lib/strerror_r.c
index f6ce8a3248..034c22e93f 100644
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -473,7 +473,8 @@ strerror_r (int errnum, char *buf, size_t buflen)
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 @@ strerror_r (int errnum, char *buf, size_t buflen)
}
# 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;