maint: update almost all copyright ranges to include 2011
[gnulib.git] / m4 / strerror_r.m4
1 # strerror_r.m4 serial 3
2 dnl Copyright (C) 2002, 2007-2011 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_STRERROR_R],
8 [
9   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
10   AC_REQUIRE([gl_HEADER_ERRNO_H])
11   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12
13   dnl Persuade Solaris <string.h> to declare strerror_r().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Some systems don't declare strerror_r() if _THREAD_SAFE and _REENTRANT
17   dnl are not defined.
18   AC_CHECK_DECLS_ONCE([strerror_r])
19   if test $ac_cv_have_decl_strerror_r = no; then
20     HAVE_DECL_STRERROR_R=0
21   fi
22
23   AC_CHECK_FUNCS([strerror_r])
24   if test $ac_cv_func_strerror_r = yes; then
25     if test -z "$ERRNO_H"; then
26       dnl The POSIX prototype is:  int strerror_r (int, char *, size_t);
27       dnl glibc's prototype:       char *strerror_r (int, char *, size_t);
28       dnl AIX 5.1, OSF/1 5.1:      int strerror_r (int, char *, int);
29       AC_CACHE_CHECK([for strerror_r with POSIX signature],
30         [gl_cv_func_strerror_r_posix_signature],
31         [AC_COMPILE_IFELSE(
32            [AC_LANG_PROGRAM(
33               [[#include <string.h>
34                 int strerror_r (int, char *, size_t);
35               ]],
36               [[return strerror (0);]])],
37            [gl_cv_func_strerror_r_posix_signature=yes],
38            [gl_cv_func_strerror_r_posix_signature=no])
39         ])
40       if test $gl_cv_func_strerror_r_posix_signature = yes; then
41         dnl AIX 6.1 strerror_r fails by returning -1, not an error number.
42         dnl HP-UX 11.31 strerror_r always fails when the buffer length argument
43         dnl is less than 80.
44         AC_CACHE_CHECK([whether strerror_r works],
45           [gl_cv_func_strerror_r_works],
46           [AC_RUN_IFELSE(
47              [AC_LANG_PROGRAM(
48                 [[#include <errno.h>
49                   #include <string.h>
50                   int strerror_r (int, char *, size_t);
51                 ]],
52                 [[int result = 0;
53                   char buf[79];
54                   if (strerror_r (EACCES, buf, 0) < 0)
55                     result |= 1;
56                   if (strerror_r (EACCES, buf, sizeof (buf)) != 0)
57                     result |= 2;
58                   return result;
59                 ]])],
60              [gl_cv_func_strerror_r_works=yes],
61              [gl_cv_func_strerror_r_works=no],
62              [
63 changequote(,)dnl
64               case "$host_os" in
65                        # Guess no on AIX.
66                 aix*)  gl_cv_func_strerror_r_works="guessing no";;
67                        # Guess no on HP-UX.
68                 hpux*) gl_cv_func_strerror_r_works="guessing no";;
69                        # Guess yes otherwise.
70                 *)     gl_cv_func_strerror_r_works="guessing yes";;
71               esac
72 changequote([,])dnl
73              ])
74           ])
75         case "$gl_cv_func_strerror_r_works" in
76           *no) REPLACE_STRERROR_R=1 ;;
77         esac
78       else
79         dnl The system's strerror() has a wrong signature. Replace it.
80         REPLACE_STRERROR_R=1
81         dnl glibc >= 2.3.4 has a function __xpg_strerror_r.
82         AC_CHECK_FUNCS([__xpg_strerror_r])
83       fi
84     else
85       dnl The system's strerror_r() cannot know about the new errno values we
86       dnl add to <errno.h>. Replace it.
87       REPLACE_STRERROR_R=1
88       AC_DEFINE([EXTEND_STRERROR_R], [1],
89         [Define to 1 if strerror_r needs to be extended so that it handles the
90          extra errno values.])
91     fi
92   fi
93   if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
94     AC_LIBOBJ([strerror_r])
95     gl_PREREQ_STRERROR_R
96   fi
97 ])
98
99 # Prerequisites of lib/strerror_r.c.
100 AC_DEFUN([gl_PREREQ_STRERROR_R], [
101   :
102 ])