Hi Eric, > 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.
Very nice. Good improvement. I'm applying a couple of follow-up tweaks: - In gl_FUNC_STRERROR, we don't need to emit code in configure that tests the value of gl_cv_func_strerror_r_works if that variable cannot have been set. - gl_FUNC_STRERROR_R_WORKS does not need to require gl_HEADER_STRING_H_DEFAULTS, since it doesn't set HAVE_* or REPLACE_* variables. It's gl_FUNC_STRERROR_R which needs to require it. - gl_PREREQ_STRERROR_R needs to test whether __xpg_strerror_r exists, since lib/strerror_r.c tests HAVE___XPG_STRERROR_R. Until two weeks ago, there was the assumption that it had already been tested by gl_FUNC_STRERROR_R, but that's not the case any more since we have added the 'test -z "$ERRNO_H"' and since the list of platforms that have __xpg_strerror_r now includes Cygwin (for which "$ERRNO_H" ends up non-empty). - Fix a couple of unclear comments. 2011-06-08 Bruno Haible <br...@clisp.org> strerror_r-posix: Tweaks. * m4/strerror.m4 (gl_FUNC_STRERROR): Omit the code that tests gl_cv_func_strerror_r_works if gl_FUNC_STRERROR_R_WORKS is not present. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R_WORKS): Fix AC_CACHE_CHECK message. Move gl_HEADER_STRING_H_DEFAULTS invocation from here... (gl_FUNC_STRERROR_R): ... to here. (gl_PREREQ_STRERROR_R): Test for __xpg_strerror_r. --- m4/strerror.m4.orig Wed Jun 8 12:21:39 2011 +++ m4/strerror.m4 Wed Jun 8 11:52:01 2011 @@ -35,10 +35,13 @@ 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 + m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [ + dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's + dnl buffer, 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. --- m4/strerror_r.m4.orig Wed Jun 8 12:21:39 2011 +++ m4/strerror_r.m4 Wed Jun 8 12:00:47 2011 @@ -6,6 +6,7 @@ AC_DEFUN([gl_FUNC_STRERROR_R], [ + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS]) dnl Persuade Solaris <string.h> to declare strerror_r(). @@ -26,7 +27,7 @@ *no) REPLACE_STRERROR_R=1 ;; esac else - dnl The system's strerror() has a wrong signature. Replace it. + dnl The system's strerror_r() has a wrong signature. Replace it. REPLACE_STRERROR_R=1 fi else @@ -39,15 +40,15 @@ # Prerequisites of lib/strerror_r.c. AC_DEFUN([gl_PREREQ_STRERROR_R], [ + dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r. + AC_CHECK_FUNCS([__xpg_strerror_r]) AC_CHECK_FUNCS_ONCE([catgets]) - : ]) # Detect if strerror_r works, but without affecting whether a replacement # strerror_r will be used. AC_DEFUN([gl_FUNC_STRERROR_R_WORKS], [ - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_REQUIRE([gl_HEADER_ERRNO_H]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles @@ -120,10 +121,10 @@ dnl The system's strerror() has a wrong signature. dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r. AC_CHECK_FUNCS([__xpg_strerror_r]) - dnl glibc < 2.14 does not populate buf on failure - dnl cygwin < 1.7.10 clobbers strerror + dnl In glibc < 2.14, __xpg_strerror_r does not populate buf on failure. + dnl In cygwin < 1.7.10, __xpg_strerror_r clobbers strerror's buffer. if test $ac_cv_func___xpg_strerror_r = yes; then - AC_CACHE_CHECK([whether strerror_r works], + AC_CACHE_CHECK([whether __xpg_strerror_r works], [gl_cv_func_strerror_r_works], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( @@ -147,8 +148,8 @@ ]])], [gl_cv_func_strerror_r_works=yes], [gl_cv_func_strerror_r_works=no], - [dnl guess no on all platforms that have __xpg_strerror_r, - dnl at least until fixed glibc and cygwin are more common + [dnl Guess no on all platforms that have __xpg_strerror_r, + dnl at least until fixed glibc and cygwin are more common. gl_cv_func_strerror_r_works="guessing no" ]) ]) -- In memoriam Larisa Yudina <http://en.wikipedia.org/wiki/Larisa_Yudina>