e3b5d0cfda00aa0b3b9472b7fced915b68cb4d33
[gnulib.git] / m4 / strerror_r.m4
1 #serial 1004
2 # This file is not needed if you can assume Autoconf 2.54 or later.
3 # Experimental replacement for the function in the latest CVS autoconf.
4 # Use with the error.c file in ../lib.
5
6 # Copyright (C) 2001 Free Software Foundation, Inc.
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10
11 undefine([AC_FUNC_STRERROR_R])
12
13 # AC_FUNC_STRERROR_R
14 # ------------------
15 AC_DEFUN([AC_FUNC_STRERROR_R],
16 [AC_CHECK_DECLS([strerror_r])
17 AC_CHECK_FUNCS([strerror_r])
18 AC_CACHE_CHECK([whether strerror_r returns char *],
19                ac_cv_func_strerror_r_char_p,
20    [
21     ac_cv_func_strerror_r_char_p=no
22     if test $ac_cv_have_decl_strerror_r = yes; then
23       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
24         [[
25           char buf[100];
26           char x = *strerror_r (0, buf, sizeof buf);
27           char *p = strerror_r (0, buf, sizeof buf);
28           return !p || x;
29         ]])],
30                         ac_cv_func_strerror_r_char_p=yes)
31     else
32       # strerror_r is not declared.  Choose between
33       # systems that have relatively inaccessible declarations for the
34       # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
35       # former has a strerror_r that returns char*, while the latter
36       # has a strerror_r that returns `int'.
37       # This test should segfault on the DEC system.
38       AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
39         extern char *strerror_r ();],
40         [[char buf[100];
41           char x = *strerror_r (0, buf, sizeof buf);
42           exit (!isalpha (x));]])],
43                     ac_cv_func_strerror_r_char_p=yes, , :)
44     fi
45   ])
46 if test $ac_cv_func_strerror_r_char_p = yes; then
47   AC_DEFINE([STRERROR_R_CHAR_P], 1,
48             [Define to 1 if strerror_r returns char *.])
49 fi
50 ])# AC_FUNC_STRERROR_R