1 # strerror.m4 serial 19
2 dnl Copyright (C) 2002, 2007-2018 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_STRERROR],
9 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
10 AC_REQUIRE([gl_HEADER_ERRNO_H])
11 AC_REQUIRE([gl_FUNC_STRERROR_0])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
14 AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
16 if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
17 AC_CACHE_CHECK([for working strerror function],
18 [gl_cv_func_working_strerror],
23 [[if (!*strerror (-2)) return 1;]])],
24 [gl_cv_func_working_strerror=yes],
25 [gl_cv_func_working_strerror=no],
27 # Guess yes on glibc systems.
28 *-gnu* | gnu*) gl_cv_func_working_strerror="guessing yes" ;;
29 # If we don't know, assume the worst.
30 *) gl_cv_func_working_strerror="guessing no" ;;
34 case "$gl_cv_func_working_strerror" in
37 dnl The system's strerror() fails to return a string for out-of-range
38 dnl integers. Replace it.
42 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
43 dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
44 dnl buffer, we must replace strerror.
45 case "$gl_cv_func_strerror_r_works" in
46 *no) REPLACE_STRERROR=1 ;;
50 dnl The system's strerror() cannot know about the new errno values we add
51 dnl to <errno.h>, or any fix for strerror(0). Replace it.
56 dnl Detect if strerror(0) passes (that is, does not set errno, and does not
57 dnl return a string that matches strerror(-1)).
58 AC_DEFUN([gl_FUNC_STRERROR_0],
60 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
62 AC_CACHE_CHECK([whether strerror(0) succeeds],
63 [gl_cv_func_strerror_0_works],
73 if (!*str) result |= 1;
74 if (errno) result |= 2;
75 if (strstr (str, "nknown") || strstr (str, "ndefined"))
78 [gl_cv_func_strerror_0_works=yes],
79 [gl_cv_func_strerror_0_works=no],
81 # Guess yes on glibc systems.
82 *-gnu* | gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
83 # Guess yes on native Windows.
84 mingw*) gl_cv_func_strerror_0_works="guessing yes" ;;
85 # If we don't know, assume the worst.
86 *) gl_cv_func_strerror_0_works="guessing no" ;;
90 case "$gl_cv_func_strerror_0_works" in
94 AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
95 does not return a message implying success.])