diff m4/strerror.m4 @ 14889:a78ddb38a66b

strerror_r-posix: work around cygwin 1.7.9 Cygwin __xpg_strerror_r clobbers strerror, until cygwin 1.7.10; in this case, we must replace strerror, but there was nothing in strerror.m4 finding fault with cygwin's native strerror. Solve this by splitting strerror_r.m4 into two parts, one for probing for the strerror_r bug, and one for replacing strerror_r based on the presence of bugs unrelated to signature issues; that way, the 'strerror' module in isolation will not replace strerror, but if strerror_r is in use for any other reason, then the two use separate buffers. Note that cygwin's strerror is thread-safe while the gnulib replacement is not; but this is no worse than any other platform where strerror is not thread-safe; in a single-threaded program, the difference is not observable, and in a multi-threaded program, you really shouldn't be using strerror in the first place. Also note that this ends up replacing glibc 2.13 strerror as it deems __xpg_strerror_r broken on that platform, which isn't technically necessary for strerror, but doesn't hurt too much. Meanwhile, glibc 2.14 fixed __xpg_strerror_r, and strerror is not replaced in that scenario. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Split... (gl_FUNC_STRERROR_R_WORKS): ...into new macro, to detect Cygwin bug without replacing strerror_r. * m4/strerror.m4 (gl_FUNC_STRERROR): Replace strerror if strerror_r is buggy, but without requiring strerror_r compilation. * doc/posix-functions/strerror_r.texi (strerror_r): Fix docs. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Mon, 06 Jun 2011 17:59:01 -0600
parents b274dcf98d11
children 5059ee60d09a
line wrap: on
line diff
--- a/m4/strerror.m4
+++ b/m4/strerror.m4
@@ -1,4 +1,4 @@
-# strerror.m4 serial 12
+# strerror.m4 serial 13
 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,
@@ -8,6 +8,9 @@
 [
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_ERRNO_H])
+  m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
+    AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
+  ])
   if test -z "$ERRNO_H"; then
     AC_CACHE_CHECK([for working strerror function],
      [gl_cv_func_working_strerror],
@@ -32,6 +35,10 @@
       dnl integers. Replace it.
       REPLACE_STRERROR=1
     fi
+    dnl If the system's strerror_r clobbers strerror, we must replace strerror.
+    case $gl_cv_func_strerror_r_works in
+      *no) REPLACE_STRERROR=1 ;;
+    esac
   else
     dnl The system's strerror() cannot know about the new errno values we add
     dnl to <errno.h>. Replace it.