1# perror.m4 serial 6
2dnl Copyright (C) 2008-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_PERROR],
8[
9  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10  AC_REQUIRE([gl_HEADER_ERRNO_H])
11  AC_REQUIRE([gl_FUNC_STRERROR_R])
12  AC_REQUIRE([gl_FUNC_STRERROR_0])
13  dnl We intentionally do not check for the broader REPLACE_STRERROR_R,
14  dnl since on glibc systems, strerror_r is replaced only for signature
15  dnl issues, and perror is just fine.  Rather, we only want to
16  dnl replace perror if strerror_r was replaced for a content fix.
17  if test "$ERRNO_H:$REPLACE_STRERROR_0" != :0; then
18    dnl The system's perror() cannot know about the new errno values we add
19    dnl to <errno.h>, or any fix for strerror(0). Replace it.
20    REPLACE_PERROR=1
21  fi
22  case ${gl_cv_func_strerror_r_works-unset} in
23    unset|*yes)
24      AC_CACHE_CHECK([whether perror matches strerror],
25        [gl_cv_func_perror_works],
26        [AC_RUN_IFELSE(
27           [AC_LANG_PROGRAM(
28              [[#include <errno.h>
29                #include <stdio.h>
30                #include <stdlib.h>
31                #include <string.h>
32              ]],
33              [[char *str = strerror (-1);
34                if (!getenv("CONFTEST_OUTPUT")) return 0;
35                if (!str) str = "";
36                puts (str);
37                errno = -1;
38                perror ("");
39                return 0;
40              ]])],
41           [if CONFTEST_OUTPUT=1 ./conftest$EXEEXT >conftest.txt1 2>conftest.txt2 \
42               && cmp conftest.txt1 conftest.txt2 >/dev/null; then
43              gl_cv_func_perror_works=yes
44            else
45              gl_cv_func_perror_works=no
46            fi
47            rm -rf conftest.txt1 conftest.txt2],
48           [gl_cv_func_perror_works=no],
49           [dnl Guess no when cross-compiling.
50            gl_cv_func_perror_works="guessing no"
51           ])
52        ])
53      if test "$gl_cv_func_perror_works" != yes; then
54        REPLACE_PERROR=1
55      fi
56      ;;
57    *)
58      dnl The system's perror() probably inherits the bugs in the
59      dnl system's strerror_r(). Replace it.
60      REPLACE_PERROR=1
61      ;;
62  esac
63])
64