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.
7 AC_DEFUN([gl_FUNC_STRERROR_R],
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
13 dnl Persuade Solaris <string.h> to declare strerror_r().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Some systems don't declare strerror_r() if _THREAD_SAFE and _REENTRANT
18 AC_CHECK_DECLS_ONCE([strerror_r])
19 if test $ac_cv_have_decl_strerror_r = no; then
20 HAVE_DECL_STRERROR_R=0
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, Cygwin: 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],
34 int strerror_r (int, char *, size_t);
36 [[return strerror (0);]])],
37 [gl_cv_func_strerror_r_posix_signature=yes],
38 [gl_cv_func_strerror_r_posix_signature=no])
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
44 AC_CACHE_CHECK([whether strerror_r works],
45 [gl_cv_func_strerror_r_works],
50 int strerror_r (int, char *, size_t);
54 if (strerror_r (EACCES, buf, 0) < 0)
56 if (strerror_r (EACCES, buf, sizeof (buf)) != 0)
60 [gl_cv_func_strerror_r_works=yes],
61 [gl_cv_func_strerror_r_works=no],
66 aix*) gl_cv_func_strerror_r_works="guessing no";;
68 hpux*) gl_cv_func_strerror_r_works="guessing no";;
69 # Guess yes otherwise.
70 *) gl_cv_func_strerror_r_works="guessing yes";;
75 case "$gl_cv_func_strerror_r_works" in
76 *no) REPLACE_STRERROR_R=1 ;;
79 dnl The system's strerror() has a wrong signature. Replace it.
81 dnl glibc >= 2.3.4 has a function __xpg_strerror_r.
82 AC_CHECK_FUNCS([__xpg_strerror_r])
85 dnl The system's strerror_r() cannot know about the new errno values we
86 dnl add to <errno.h>. Replace it.
88 AC_DEFINE([EXTEND_STRERROR_R], [1],
89 [Define to 1 if strerror_r needs to be extended so that it handles the
93 if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
94 AC_LIBOBJ([strerror_r])
99 # Prerequisites of lib/strerror_r.c.
100 AC_DEFUN([gl_PREREQ_STRERROR_R], [