-# 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,
[
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],
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.
-# strerror_r.m4 serial 9
+# strerror_r.m4 serial 10
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,
AC_DEFUN([gl_FUNC_STRERROR_R],
[
- AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
- AC_REQUIRE([gl_HEADER_ERRNO_H])
- AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
dnl Persuade Solaris <string.h> to declare strerror_r().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
HAVE_DECL_STRERROR_R=0
fi
- AC_CHECK_FUNCS([strerror_r])
+ if test $ac_cv_func_strerror_r = yes; then
+ if test -z "$ERRNO_H"; then
+ if test $gl_cv_func_strerror_r_posix_signature = yes; then
+ case "$gl_cv_func_strerror_r_works" in
+ dnl The system's strerror_r has bugs. Replace it.
+ *no) REPLACE_STRERROR_R=1 ;;
+ esac
+ else
+ dnl The system's strerror() has a wrong signature. Replace it.
+ REPLACE_STRERROR_R=1
+ fi
+ else
+ dnl The system's strerror_r() cannot know about the new errno values we
+ dnl add to <errno.h>. Replace it.
+ REPLACE_STRERROR_R=1
+ fi
+ fi
+])
+
+# Prerequisites of lib/strerror_r.c.
+AC_DEFUN([gl_PREREQ_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
+
+ AC_CHECK_FUNCS_ONCE([strerror_r])
if test $ac_cv_func_strerror_r = yes; then
if test -z "$ERRNO_H"; then
dnl The POSIX prototype is: int strerror_r (int, char *, size_t);
changequote([,])dnl
])
])
- case "$gl_cv_func_strerror_r_works" in
- *no) REPLACE_STRERROR_R=1 ;;
- esac
else
- dnl The system's strerror() has a wrong signature. Replace it.
- REPLACE_STRERROR_R=1
+ 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
+ if test $ac_cv_func___xpg_strerror_r = yes; then
+ AC_CACHE_CHECK([whether strerror_r works],
+ [gl_cv_func_strerror_r_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <errno.h>
+ #include <string.h>
+ extern int __xpg_strerror_r(int, char *, size_t);
+ ]],
+ [[int result = 0;
+ char buf[256] = "^";
+ char copy[256];
+ char *str = strerror (-1);
+ strcpy (copy, str);
+ if (__xpg_strerror_r (-2, buf, 1) == 0)
+ result |= 1;
+ if (*buf)
+ result |= 2;
+ __xpg_strerror_r (-2, buf, 256);
+ if (strcmp (str, copy))
+ result |= 4;
+ return result;
+ ]])],
+ [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
+ gl_cv_func_strerror_r_works="guessing no"
+ ])
+ ])
+ fi
fi
- else
- dnl The system's strerror_r() cannot know about the new errno values we
- dnl add to <errno.h>. Replace it.
- REPLACE_STRERROR_R=1
fi
fi
])
-
-# Prerequisites of lib/strerror_r.c.
-AC_DEFUN([gl_PREREQ_STRERROR_R], [
- AC_CHECK_FUNCS_ONCE([catgets])
- :
-])