Debian Codegraph @

m4/strerror.m4

raw
1 # strerror.m4
2 # serial 25
3 dnl Copyright (C) 2002, 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FUNC_STRERROR],
10 [
11 AC_REQUIRE([gl_STRING_H_DEFAULTS])
12 AC_REQUIRE([gl_HEADER_ERRNO_H])
13 AC_REQUIRE([gl_FUNC_STRERROR_0])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
16 AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
17 ])
18 if test "$GL_GENERATE_ERRNO_H:$REPLACE_STRERROR_0" = false:0; then
19 AC_CACHE_CHECK([for working strerror function],
20 [gl_cv_func_working_strerror],
21 [AC_RUN_IFELSE(
22 [AC_LANG_PROGRAM(
23 [[#include <string.h>
24 ]],
25 [[if (!*strerror (-2)) return 1;]])],
26 [gl_cv_func_working_strerror=yes],
27 [gl_cv_func_working_strerror=no],
28 [case "$host_os" in
29 # Guess yes on glibc systems.
30 *-gnu* | gnu*) gl_cv_func_working_strerror="guessing yes" ;;
31 # Guess yes on musl systems.
32 *-musl* | midipix*) gl_cv_func_working_strerror="guessing yes" ;;
33 # If we don't know, obey --enable-cross-guesses.
34 *) gl_cv_func_working_strerror="$gl_cross_guess_normal" ;;
35 esac
36 ])
37 ])
38 case "$gl_cv_func_working_strerror" in
39 *yes) ;;
40 *)
41 dnl The system's strerror() fails to return a string for out-of-range
42 dnl integers. Replace it.
43 REPLACE_STRERROR=1
44 ;;
45 esac
46 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
47 dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
48 dnl buffer, we must replace strerror.
49 case "$gl_cv_func_strerror_r_works" in
50 *no) REPLACE_STRERROR=1 ;;
51 esac
52 ])
53 else
54 dnl The system's strerror() cannot know about the new errno values we add
55 dnl to <errno.h>, or any fix for strerror(0). Replace it.
56 REPLACE_STRERROR=1
57 fi
58 ])
59
60 dnl Detect if strerror(0) passes (that is, does not set errno, and does not
61 dnl return a string that matches strerror(-1)).
62 AC_DEFUN([gl_FUNC_STRERROR_0],
63 [
64 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
65 REPLACE_STRERROR_0=0
66 AC_CACHE_CHECK([whether strerror(0) succeeds],
67 [gl_cv_func_strerror_0_works],
68 [AC_RUN_IFELSE(
69 [AC_LANG_PROGRAM(
70 [[#include <string.h>
71 #include <errno.h>
72 ]],
73 [[int result = 0;
74 char *str;
75 errno = 0;
76 str = strerror (0);
77 if (!*str) result |= 1;
78 if (errno) result |= 2;
79 if (strstr (str, "nknown") || strstr (str, "ndefined"))
80 result |= 4;
81 return result;]])],
82 [gl_cv_func_strerror_0_works=yes],
83 [gl_cv_func_strerror_0_works=no],
84 [case "$host_os" in
85 # Guess yes on glibc systems.
86 *-gnu* | gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
87 # Guess yes on musl systems.
88 *-musl* | midipix*) gl_cv_func_strerror_0_works="guessing yes" ;;
89 # Guess yes on native Windows.
90 mingw* | windows*) gl_cv_func_strerror_0_works="guessing yes" ;;
91 # If we don't know, obey --enable-cross-guesses.
92 *) gl_cv_func_strerror_0_works="$gl_cross_guess_normal" ;;
93 esac
94 ])
95 ])
96 case "$gl_cv_func_strerror_0_works" in
97 *yes) ;;
98 *)
99 REPLACE_STRERROR_0=1
100 AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
101 does not return a message implying success.])
102 ;;
103 esac
104 ])