From: Eric Blake Date: Fri, 20 May 2011 21:19:05 +0000 (-0600) Subject: strerror_r: simplify AIX code. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d9ff2115d2807182f5334872e127dd75b1017d0;p=pspp strerror_r: simplify AIX code. * lib/strerror_r.c (strerror_r): Filter out buflen of 1 up front. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 598238f6da..bda43a69aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-05-20 Eric Blake + 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. diff --git a/lib/strerror_r.c b/lib/strerror_r.c index 30dcd44e7c..2144fc652e 100644 --- a/lib/strerror_r.c +++ b/lib/strerror_r.c @@ -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;