1 # strerror_r.m4 serial 7
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);
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 dnl FreeBSD 8.s strerror_r claims failure on 0
45 AC_CACHE_CHECK([whether strerror_r works],
46 [gl_cv_func_strerror_r_works],
54 if (strerror_r (EACCES, buf, 0) < 0)
57 if (strerror_r (EACCES, buf, sizeof buf) != 0)
59 if (strerror_r (0, buf, sizeof buf) != 0)
65 [gl_cv_func_strerror_r_works=yes],
66 [gl_cv_func_strerror_r_works=no],
71 aix*) gl_cv_func_strerror_r_works="guessing no";;
73 hpux*) gl_cv_func_strerror_r_works="guessing no";;
74 # Guess no on FreeBSD.
75 freebsd*) gl_cv_func_strerror_r_works="guessing no";;
76 # Guess yes otherwise.
77 *) gl_cv_func_strerror_r_works="guessing yes";;
82 case "$gl_cv_func_strerror_r_works" in
83 *no) REPLACE_STRERROR_R=1 ;;
86 dnl The system's strerror() has a wrong signature. Replace it.
88 dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
89 AC_CHECK_FUNCS([__xpg_strerror_r])
92 dnl The system's strerror_r() cannot know about the new errno values we
93 dnl add to <errno.h>. Replace it.
97 if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
98 AC_LIBOBJ([strerror_r])
103 # Prerequisites of lib/strerror_r.c.
104 AC_DEFUN([gl_PREREQ_STRERROR_R], [
105 AC_CHECK_FUNCS_ONCE([catgets])