3 dnl Copyright (C) 1996-2024 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.
9 dnl Provide a working <error.h>.
11 AC_DEFUN_ONCE([gl_ERROR_H],
13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 gl_CHECK_NEXT_HEADERS([error.h])
16 if test $ac_cv_header_error_h = yes; then
21 AC_SUBST([HAVE_ERROR_H])
25 gl_CHECK_FUNCS_ANDROID([error], [[#include <error.h>]])
26 if test $ac_cv_func_error = yes; then
30 case "$gl_cv_onwards_func_error" in
31 future*) REPLACE_ERROR=1 ;;
35 dnl We don't use AC_FUNC_ERROR_AT_LINE any more, because it is no longer
36 dnl maintained in Autoconf and because it invokes AC_LIBOBJ.
37 dnl We need to notice a missing declaration, like gl_CHECK_FUNCS_ANDROID does.
38 AC_CHECK_DECL([error_at_line], , , [[#include <error.h>]])
39 if test $ac_cv_have_decl_error_at_line = yes; then
40 AC_CACHE_CHECK([for error_at_line], [ac_cv_lib_error_at_line],
43 [[#include <error.h>]],
44 [[error_at_line (0, 0, "", 0, "an error occurred");]])],
45 [ac_cv_lib_error_at_line=yes],
46 [ac_cv_lib_error_at_line=no])])
48 ac_cv_lib_error_at_line=no
50 if test $ac_cv_lib_error_at_line = yes; then
55 REPLACE_ERROR_AT_LINE=0
57 if test $ac_cv_func_error = yes && test $ac_cv_lib_error_at_line = yes; then
58 dnl On Android 11, when error_print_progname is set, the output of the
59 dnl error() function contains an extra space.
60 AC_CACHE_CHECK([for working error function],
61 [gl_cv_func_working_error],
62 [if test $cross_compiling != yes; then
66 static void print_no_progname (void) {}
68 error_print_progname = print_no_progname;
73 if test -s conftest$ac_exeext \
74 && ./conftest$ac_exeext 2> conftest.out; then
75 if grep ' ' conftest.out >/dev/null; then
76 gl_cv_func_working_error=no
78 gl_cv_func_working_error=yes
81 gl_cv_func_working_error=no
85 [gl_cv_func_working_error=no])
95 # Guess yes on glibc systems.
96 *-gnu* | gnu*) gl_cv_func_working_error="guessing yes" ;;
97 # Guess no on Android.
98 linux*-android*) gl_cv_func_working_error="guessing no" ;;
99 # If we don't know, obey --enable-cross-guesses.
100 *) gl_cv_func_working_error="$gl_cross_guess_normal" ;;
103 [gl_cv_func_working_error=no])
106 case "$gl_cv_func_working_error" in
109 REPLACE_ERROR_AT_LINE=1
114 if test $HAVE_ERROR = 0 || test $REPLACE_ERROR = 1 \
115 || test $HAVE_ERROR_AT_LINE = 0 || test $REPLACE_ERROR_AT_LINE = 1; then
121 AC_SUBST([HAVE_ERROR])
122 AC_SUBST([HAVE_ERROR_AT_LINE])
123 AC_SUBST([REPLACE_ERROR])
124 AC_SUBST([REPLACE_ERROR_AT_LINE])