(AC_FUNC_STRERROR_R): Pass a reasonably large buffer to strerror_r.
[gnulib.git] / m4 / strerror_r.m4
1 #serial 1001
2 # Experimental replacement for the function in the latest CVS autoconf.
3 # If the compile-test says strerror_r doesn't work, then resort to a
4 # `run'-test that works on BeOS and segfaults on DEC Unix.
5 # Use with the error.c file in ../lib.
6
7 undefine([AC_FUNC_STRERROR_R])
8
9 # AC_FUNC_STRERROR_R
10 # ------------------
11 AC_DEFUN([AC_FUNC_STRERROR_R],
12 [# Check strerror_r
13 AC_CHECK_DECLS([strerror_r])
14 AC_CHECK_FUNCS([strerror_r])
15 if test $ac_cv_func_strerror_r = yes; then
16   AC_CHECK_HEADERS(string.h)
17   AC_CACHE_CHECK([for working strerror_r],
18                  ac_cv_func_strerror_r_works,
19    [
20     AC_TRY_COMPILE(
21      [
22 #       include <stdio.h>
23 #       if HAVE_STRING_H
24 #        include <string.h>
25 #       endif
26      ],
27      [
28        char buf[100];
29        char x = *strerror_r (0, buf, sizeof buf);
30      ],
31      ac_cv_func_strerror_r_works=yes,
32      ac_cv_func_strerror_r_works=no
33     )
34     if test $ac_cv_func_strerror_r_works = no; then
35       # strerror_r seems not to work, but now we have to choose between
36       # systems that have relatively inaccessible declarations for the
37       # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
38       # former has a strerror_r that returns char*, while the latter
39       # has a strerror_r that returns `int'.
40       # This test should segfault on the DEC system.
41       AC_TRY_RUN(
42        [
43 #       include <stdio.h>
44 #       include <string.h>
45
46         extern char *strerror_r ();
47
48         int
49         main ()
50         {
51           char buf[100];
52           char x = *strerror_r (0, buf, sizeof buf);
53           exit (!isalpha (x));
54         }
55        ],
56        ac_cv_func_strerror_r_works=yes,
57        ac_cv_func_strerror_r_works=no,
58        ac_cv_func_strerror_r_works=no)
59     fi
60
61     if test $ac_cv_func_strerror_r_works = yes; then
62       AC_DEFINE_UNQUOTED(HAVE_WORKING_STRERROR_R, 1,
63         [Define to 1 if `strerror_r' returns a string.])
64     fi
65   ])
66 fi
67 ])# AC_FUNC_STRERROR_R