*** empty log message ***
[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 #       include <ctype.h>
46
47         extern char *strerror_r ();
48
49         int
50         main ()
51         {
52           char buf[100];
53           char x = *strerror_r (0, buf, sizeof buf);
54           exit (!isalpha (x));
55         }
56        ],
57        ac_cv_func_strerror_r_works=yes,
58        ac_cv_func_strerror_r_works=no,
59        ac_cv_func_strerror_r_works=no)
60     fi
61
62     if test $ac_cv_func_strerror_r_works = yes; then
63       AC_DEFINE_UNQUOTED(HAVE_WORKING_STRERROR_R, 1,
64         [Define to 1 if `strerror_r' returns a string.])
65     fi
66   ])
67 fi
68 ])# AC_FUNC_STRERROR_R