bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] strerror_r: avoid corrupting errno on Solaris


From: Eric Blake
Subject: [PATCH] strerror_r: avoid corrupting errno on Solaris
Date: Fri, 20 May 2011 17:50:44 -0600

On Solaris, a non-zero return was also reflected into errno.
Leaving errno unchanged is a useful feature worth guaranteeing.

* m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Check for Solaris behavior.
* doc/posix-functions/strerror_r.texi (strerror_r): Document it.

Signed-off-by: Eric Blake <address@hidden>
---

This fixes a testsuite failure caused by my earlier tightening of
test-strerror_r.c

 ChangeLog                           |    4 ++++
 doc/posix-functions/strerror_r.texi |    3 +++
 m4/strerror_r.m4                    |    8 +++++++-
 3 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fafa86f..bb0eeb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-05-20  Eric Blake  <address@hidden>

+       strerror_r: avoid corrupting errno on Solaris
+       * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Check for Solaris behavior.
+       * doc/posix-functions/strerror_r.texi (strerror_r): Document it.
+
        strerror_r: avoid compiler warning
        * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Don't return a char*.

diff --git a/doc/posix-functions/strerror_r.texi 
b/doc/posix-functions/strerror_r.texi
index 9d6639e..35cee29 100644
--- a/doc/posix-functions/strerror_r.texi
+++ b/doc/posix-functions/strerror_r.texi
@@ -33,6 +33,9 @@ strerror_r
 returning the error number, on some platforms:
 glibc 2.12 with @code{-D_POSIX_C_SOURCE=200112L}, AIX 6.1, OSF/1 5.1.
 @item
+When this function fails, it corrupts @code{errno}, on some platforms:
+Solaris 10.
address@hidden
 This function does not support the error values that are specified by POSIX
 but not defined by the system, on some platforms:
 OpenBSD 4.0, OSF/1 5.1, NonStop Kernel, Cygwin 1.5.x.
diff --git a/m4/strerror_r.m4 b/m4/strerror_r.m4
index 13fb931..ddaf10f 100644
--- a/m4/strerror_r.m4
+++ b/m4/strerror_r.m4
@@ -1,4 +1,4 @@
-# strerror_r.m4 serial 7
+# strerror_r.m4 serial 8
 dnl Copyright (C) 2002, 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -42,6 +42,7 @@ AC_DEFUN([gl_FUNC_STRERROR_R],
         dnl HP-UX 11.31 strerror_r always fails when the buffer length argument
         dnl is less than 80.
         dnl FreeBSD 8.s strerror_r claims failure on 0
+        dnl Solaris 10 strerror_r corrupts errno on failure
         AC_CACHE_CHECK([whether strerror_r works],
           [gl_cv_func_strerror_r_works],
           [AC_RUN_IFELSE(
@@ -60,6 +61,11 @@ AC_DEFUN([gl_FUNC_STRERROR_R],
                     result |= 4;
                   if (errno)
                     result |= 8;
+                  errno = 0;
+                  if (strerror_r (-3, buf, sizeof buf) != 0)
+                    result |= 0x10;
+                  if (errno)
+                    result |= 0x20;
                   return result;
                 ]])],
              [gl_cv_func_strerror_r_works=yes],
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]