sys_un: Avoid compilation error in C++ <string.h> on glibc systems.
[gnulib.git] / m4 / strsignal.m4
blob458f26e82d30a1b116330b16c0832cbd24d4a11e
1 # strsignal.m4
2 # serial 10
3 dnl Copyright (C) 2008-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.
8 AC_DEFUN([gl_FUNC_STRSIGNAL],
10   dnl Persuade glibc <string.h> to declare strsignal().
11   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
13   AC_REQUIRE([gl_STRING_H_DEFAULTS])
14   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16   AC_CHECK_DECLS_ONCE([strsignal])
17   if test $ac_cv_have_decl_strsignal = no; then
18     HAVE_DECL_STRSIGNAL=0
19   fi
21   AC_CHECK_FUNCS([strsignal])
22   if test $ac_cv_func_strsignal = yes; then
23     HAVE_STRSIGNAL=1
24     dnl Check if strsignal behaves reasonably for out-of-range signal numbers.
25     dnl On Solaris it returns NULL; on AIX 5.1 it returns (char *) -1.
26     AC_CACHE_CHECK([whether strsignal always returns a string],
27       [gl_cv_func_working_strsignal],
28       [AC_RUN_IFELSE(
29          [AC_LANG_PROGRAM(
30             [[#include <string.h>
31 #include <unistd.h> /* NetBSD 5.0 declares it in wrong header. */
32             ]],
33             [[int result = 0;
34               char *s = strsignal (-1);
35               if (s == (char *) 0)
36                 result |= 1;
37               if (s == (char *) -1)
38                 result |= 2;
39               return result;
40             ]])],
41          [gl_cv_func_working_strsignal=yes],
42          [gl_cv_func_working_strsignal=no],
43          [case "$host_os" in
44             solaris* | aix*) gl_cv_func_working_strsignal=no;;
45             *)               gl_cv_func_working_strsignal="guessing yes";;
46           esac])])
47     if test "$gl_cv_func_working_strsignal" = no; then
48       REPLACE_STRSIGNAL=1
49     fi
50   else
51     HAVE_STRSIGNAL=0
52   fi
55 # Prerequisites of lib/strsignal.c.
56 AC_DEFUN([gl_PREREQ_STRSIGNAL], [
57   AC_CHECK_HEADERS_ONCE([unistd.h])
58   AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
59   AC_CHECK_DECLS([_sys_siglist], [], [], [[#include <signal.h>]])