• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# strerror.m4 serial 17
2dnl Copyright (C) 2002, 2007-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_STRERROR],
8[
9  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
10  AC_REQUIRE([gl_HEADER_ERRNO_H])
11  AC_REQUIRE([gl_FUNC_STRERROR_0])
12  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13  m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
14    AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
15  ])
16  if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
17    AC_CACHE_CHECK([for working strerror function],
18     [gl_cv_func_working_strerror],
19     [AC_RUN_IFELSE(
20        [AC_LANG_PROGRAM(
21           [[#include <string.h>
22           ]],
23           [[if (!*strerror (-2)) return 1;]])],
24        [gl_cv_func_working_strerror=yes],
25        [gl_cv_func_working_strerror=no],
26        [case "$host_os" in
27                   # Guess yes on glibc systems.
28           *-gnu*) gl_cv_func_working_strerror="guessing yes" ;;
29                   # If we don't know, assume the worst.
30           *)      gl_cv_func_working_strerror="guessing no" ;;
31         esac
32        ])
33    ])
34    case "$gl_cv_func_working_strerror" in
35      *yes) ;;
36      *)
37        dnl The system's strerror() fails to return a string for out-of-range
38        dnl integers. Replace it.
39        REPLACE_STRERROR=1
40        ;;
41    esac
42    m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
43      dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
44      dnl buffer, we must replace strerror.
45      case "$gl_cv_func_strerror_r_works" in
46        *no) REPLACE_STRERROR=1 ;;
47      esac
48    ])
49  else
50    dnl The system's strerror() cannot know about the new errno values we add
51    dnl to <errno.h>, or any fix for strerror(0). Replace it.
52    REPLACE_STRERROR=1
53  fi
54])
55
56dnl Detect if strerror(0) passes (that is, does not set errno, and does not
57dnl return a string that matches strerror(-1)).
58AC_DEFUN([gl_FUNC_STRERROR_0],
59[
60  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
61  REPLACE_STRERROR_0=0
62  AC_CACHE_CHECK([whether strerror(0) succeeds],
63   [gl_cv_func_strerror_0_works],
64   [AC_RUN_IFELSE(
65      [AC_LANG_PROGRAM(
66         [[#include <string.h>
67           #include <errno.h>
68         ]],
69         [[int result = 0;
70           char *str;
71           errno = 0;
72           str = strerror (0);
73           if (!*str) result |= 1;
74           if (errno) result |= 2;
75           if (strstr (str, "nknown") || strstr (str, "ndefined"))
76             result |= 4;
77           return result;]])],
78      [gl_cv_func_strerror_0_works=yes],
79      [gl_cv_func_strerror_0_works=no],
80      [case "$host_os" in
81                 # Guess yes on glibc systems.
82         *-gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
83                 # If we don't know, assume the worst.
84         *)      gl_cv_func_strerror_0_works="guessing no" ;;
85       esac
86      ])
87  ])
88  case "$gl_cv_func_strerror_0_works" in
89    *yes) ;;
90    *)
91      REPLACE_STRERROR_0=1
92      AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
93        does not return a message implying success.])
94      ;;
95  esac
96])
97