summaryrefslogtreecommitdiffstats
path: root/gl/m4/strerror.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/strerror.m4')
-rw-r--r--gl/m4/strerror.m4116
1 files changed, 72 insertions, 44 deletions
diff --git a/gl/m4/strerror.m4 b/gl/m4/strerror.m4
index 1649b24..3989844 100644
--- a/gl/m4/strerror.m4
+++ b/gl/m4/strerror.m4
@@ -1,68 +1,96 @@
1# strerror.m4 serial 9 1# strerror.m4 serial 17
2dnl Copyright (C) 2002, 2007-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007-2013 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7AC_DEFUN([gl_FUNC_STRERROR], 7AC_DEFUN([gl_FUNC_STRERROR],
8[ 8[
9 AC_REQUIRE([gl_FUNC_STRERROR_SEPARATE])
10 if test $REPLACE_STRERROR = 1; then
11 AC_LIBOBJ([strerror])
12 AC_DEFINE_UNQUOTED([REPLACE_STRERROR], [$REPLACE_STRERROR],
13 [Define this to 1 if strerror is broken.])
14 fi
15])
16
17# Like gl_FUNC_STRERROR, except prepare for separate compilation (no AC_LIBOBJ).
18AC_DEFUN([gl_FUNC_STRERROR_SEPARATE],
19[
20 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 9 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
21 AC_REQUIRE([gl_HEADER_ERRNO_H]) 10 AC_REQUIRE([gl_HEADER_ERRNO_H])
22 if test -z "$ERRNO_H"; then 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])
15 ])
16 if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
23 AC_CACHE_CHECK([for working strerror function], 17 AC_CACHE_CHECK([for working strerror function],
24 [gl_cv_func_working_strerror], 18 [gl_cv_func_working_strerror],
25 [AC_RUN_IFELSE( 19 [AC_RUN_IFELSE(
26 [AC_LANG_PROGRAM( 20 [AC_LANG_PROGRAM(
27 [[#include <string.h> 21 [[#include <string.h>
28 ]], 22 ]],
29 [[return !*strerror (-2);]])], 23 [[if (!*strerror (-2)) return 1;]])],
30 [gl_cv_func_working_strerror=yes], 24 [gl_cv_func_working_strerror=yes],
31 [gl_cv_func_working_strerror=no], 25 [gl_cv_func_working_strerror=no],
32 [dnl Assume crossbuild works if it compiles. 26 [case "$host_os" in
33 AC_COMPILE_IFELSE( 27 # Guess yes on glibc systems.
34 [AC_LANG_PROGRAM( 28 *-gnu*) gl_cv_func_working_strerror="guessing yes" ;;
35 [[#include <string.h> 29 # If we don't know, assume the worst.
36 ]], 30 *) gl_cv_func_working_strerror="guessing no" ;;
37 [[return !*strerror (-2);]])], 31 esac
38 [gl_cv_func_working_strerror=yes], 32 ])
39 [gl_cv_func_working_strerror=no]) 33 ])
40 ]) 34 case "$gl_cv_func_working_strerror" in
35 *yes) ;;
36 *)
37 dnl The system's strerror() fails to return a string for out-of-range
38 dnl integers. Replace it.
39 REPLACE_STRERROR=1
40 ;;
41 esac
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 ;;
47 esac
41 ]) 48 ])
42 if test $gl_cv_func_working_strerror = no; then
43 dnl The system's strerror() fails to return a string for out-of-range
44 dnl integers. Replace it.
45 REPLACE_STRERROR=1
46 fi
47 else 49 else
48 dnl The system's strerror() cannot know about the new errno values we add 50 dnl The system's strerror() cannot know about the new errno values we add
49 dnl to <errno.h>. Replace it. 51 dnl to <errno.h>, or any fix for strerror(0). Replace it.
50 REPLACE_STRERROR=1 52 REPLACE_STRERROR=1
51 fi 53 fi
52 if test $REPLACE_STRERROR = 1; then
53 gl_PREREQ_STRERROR
54 fi
55]) 54])
56 55
57# Prerequisites of lib/strerror.c. 56dnl Detect if strerror(0) passes (that is, does not set errno, and does not
58AC_DEFUN([gl_PREREQ_STRERROR], [ 57dnl return a string that matches strerror(-1)).
59 AC_CHECK_DECLS([strerror]) 58AC_DEFUN([gl_FUNC_STRERROR_0],
60 AC_CHECK_HEADERS_ONCE([sys/socket.h]) 59[
61 if test $ac_cv_header_sys_socket_h != yes; then 60 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
62 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make 61 REPLACE_STRERROR_0=0
63 dnl the check for those headers unconditional; yet cygwin reports 62 AC_CACHE_CHECK([whether strerror(0) succeeds],
64 dnl that the headers are present but cannot be compiled (since on 63 [gl_cv_func_strerror_0_works],
65 dnl cygwin, all socket information should come from sys/socket.h). 64 [AC_RUN_IFELSE(
66 AC_CHECK_HEADERS([winsock2.h]) 65 [AC_LANG_PROGRAM(
67 fi 66 [[#include <string.h>
67 #include <errno.h>
68 ]],
69 [[int result = 0;
70 char *str;
71 errno = 0;
72 str = strerror (0);
73 if (!*str) result |= 1;
74 if (errno) result |= 2;
75 if (strstr (str, "nknown") || strstr (str, "ndefined"))
76 result |= 4;
77 return result;]])],
78 [gl_cv_func_strerror_0_works=yes],
79 [gl_cv_func_strerror_0_works=no],
80 [case "$host_os" in
81 # Guess yes on glibc systems.
82 *-gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
83 # If we don't know, assume the worst.
84 *) gl_cv_func_strerror_0_works="guessing no" ;;
85 esac
86 ])
87 ])
88 case "$gl_cv_func_strerror_0_works" in
89 *yes) ;;
90 *)
91 REPLACE_STRERROR_0=1
92 AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
93 does not return a message implying success.])
94 ;;
95 esac
68]) 96])