| 1 |
# perror.m4 |
| 2 |
# serial 13 |
| 3 |
dnl Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_PERROR], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_HEADER_ERRNO_H]) |
| 13 |
AC_REQUIRE([gl_FUNC_STRERROR_R]) |
| 14 |
AC_REQUIRE([gl_FUNC_STRERROR_0]) |
| 15 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 16 |
dnl We intentionally do not check for the broader REPLACE_STRERROR_R, |
| 17 |
dnl since on glibc systems, strerror_r is replaced only for signature |
| 18 |
dnl issues, and perror is just fine. Rather, we only want to |
| 19 |
dnl replace perror if strerror_r was replaced for a content fix. |
| 20 |
if test "$GL_GENERATE_ERRNO_H:$REPLACE_STRERROR_0" != false:0; then |
| 21 |
dnl The system's perror() cannot know about the new errno values we add |
| 22 |
dnl to <errno.h>, or any fix for strerror(0). Replace it. |
| 23 |
REPLACE_PERROR=1 |
| 24 |
fi |
| 25 |
case ${gl_cv_func_strerror_r_works-unset} in |
| 26 |
unset|*yes) |
| 27 |
AC_CACHE_CHECK([whether perror matches strerror], |
| 28 |
[gl_cv_func_perror_works], |
| 29 |
[AC_RUN_IFELSE( |
| 30 |
[AC_LANG_PROGRAM( |
| 31 |
[[#include <errno.h> |
| 32 |
#include <stdio.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include <string.h> |
| 35 |
]], |
| 36 |
[[char *str = strerror (-1); |
| 37 |
if (!getenv("CONFTEST_OUTPUT")) return 0; |
| 38 |
if (!str) str = ""; |
| 39 |
puts (str); |
| 40 |
errno = -1; |
| 41 |
perror (""); |
| 42 |
return 0; |
| 43 |
]])], |
| 44 |
[if CONFTEST_OUTPUT=1 ./conftest$EXEEXT >conftest.txt1 2>conftest.txt2 \ |
| 45 |
&& cmp conftest.txt1 conftest.txt2 >/dev/null; then |
| 46 |
gl_cv_func_perror_works=yes |
| 47 |
else |
| 48 |
gl_cv_func_perror_works=no |
| 49 |
fi |
| 50 |
rm -rf conftest.txt1 conftest.txt2], |
| 51 |
[gl_cv_func_perror_works=no], |
| 52 |
[case "$host_os" in |
| 53 |
# Guess yes on musl systems. |
| 54 |
*-musl* | midipix*) gl_cv_func_perror_works="guessing yes" ;; |
| 55 |
# Guess yes on native Windows. |
| 56 |
mingw* | windows*) gl_cv_func_perror_works="guessing yes" ;; |
| 57 |
# Otherwise obey --enable-cross-guesses. |
| 58 |
*) gl_cv_func_perror_works="$gl_cross_guess_normal" ;; |
| 59 |
esac |
| 60 |
]) |
| 61 |
]) |
| 62 |
case "$gl_cv_func_perror_works" in |
| 63 |
*yes) ;; |
| 64 |
*) REPLACE_PERROR=1 ;; |
| 65 |
esac |
| 66 |
;; |
| 67 |
*) |
| 68 |
dnl The system's perror() probably inherits the bugs in the |
| 69 |
dnl system's strerror_r(). Replace it. |
| 70 |
REPLACE_PERROR=1 |
| 71 |
;; |
| 72 |
esac |
| 73 |
dnl Does perror clobber the strerror buffer? |
| 74 |
case "$host_os" in |
| 75 |
# Yes on Android 11. |
| 76 |
linux*-android*) REPLACE_PERROR=1 ;; |
| 77 |
esac |
| 78 |
]) |