Debian Codegraph @

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