Replace strsignal if it does not work fine.
[gnulib.git] / m4 / strsignal.m4
1 # strsignal.m4 serial 2
2 dnl Copyright (C) 2008 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.
6
7 AC_DEFUN([gl_FUNC_STRSIGNAL],
8 [
9   dnl Persuade glibc <string.h> to declare strsignal().
10   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11
12   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
13   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14
15   AC_CHECK_DECLS_ONCE([strsignal])
16   if test $ac_cv_have_decl_strsignal = no; then
17     HAVE_DECL_STRSIGNAL=0
18   fi
19
20   AC_CHECK_FUNCS([strsignal])
21   if test $ac_cv_func_strsignal = yes; then
22     dnl Check if strsignal behaves reasonably for out-of-range signal numbers.
23     dnl On Solaris it returns NULL; on AIX 5.1 it returns (char *) -1.
24     AC_CACHE_CHECK([whether strsignal always returns a string],
25       [gl_cv_func_working_strsignal],
26       [AC_RUN_IFELSE(
27          [AC_LANG_PROGRAM(
28             [[#include <string.h>
29             ]],
30             [[char *s = strsignal (-1);
31               return !(s != (char *) 0 && s != (char *) -1);]])],
32          [gl_cv_func_working_strsignal=yes],
33          [gl_cv_func_working_strsignal=no],
34          [case "$host_os" in
35             solaris* | aix*) gl_cv_func_working_strsignal=no;;
36             *)               gl_cv_func_working_strsignal="guessing yes";;
37           esac])])
38   else
39     gl_cv_func_working_strsignal=no
40   fi
41
42   if test "$gl_cv_func_working_strsignal" = no; then
43     if test $ac_cv_func_strsignal = yes; then
44       REPLACE_STRSIGNAL=1
45     fi
46     AC_LIBOBJ([strsignal])
47     gl_PREREQ_STRSIGNAL
48   fi
49 ])
50
51 # Prerequisites of lib/strsignal.c.
52 AC_DEFUN([gl_PREREQ_STRSIGNAL], [
53   AC_REQUIRE([AC_DECL_SYS_SIGLIST])
54   :
55 ])