2 dnl Copyright (C) 2007-2022 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_ONCE([gl_STDIO_H],
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AH_VERBATIM([MINGW_ANSI_STDIO],
11 [/* Use GNU style printf and scanf. */
12 #ifndef __USE_MINGW_ANSI_STDIO
13 # undef __USE_MINGW_ANSI_STDIO
16 AC_DEFINE([__USE_MINGW_ANSI_STDIO])
17 gl_NEXT_HEADERS([stdio.h])
19 dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
20 dnl inttypes.h behave like gnu instead of system; we must give our
21 dnl printf wrapper the right attribute to match.
22 AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
23 [gl_cv_func_printf_attribute_flavor],
24 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
25 #define __STDC_FORMAT_MACROS 1
28 /* For non-mingw systems, compilation will trivially succeed.
29 For mingw, compilation will succeed for older mingw (system
30 printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
31 #if (defined _WIN32 && ! defined __CYGWIN__) && \
32 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
33 extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
35 ]])], [gl_cv_func_printf_attribute_flavor=system],
36 [gl_cv_func_printf_attribute_flavor=gnu])])
37 if test "$gl_cv_func_printf_attribute_flavor" = gnu; then
38 AC_DEFINE([GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU], [1],
39 [Define to 1 if printf and friends should be labeled with
40 attribute "__gnu_printf__" instead of "__printf__"])
43 dnl This ifdef is an optimization, to avoid performing a configure check whose
44 dnl result is not used. But it does not make the test of
45 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
46 m4_ifdef([gl_NONBLOCKING_IO], [
48 if test $gl_cv_have_nonblocking != yes; then
49 REPLACE_STDIO_READ_FUNCS=1
53 dnl This ifdef is an optimization, to avoid performing a configure check whose
54 dnl result is not used. But it does not make the test of
55 dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
56 m4_ifdef([gl_SIGNAL_SIGPIPE], [
58 if test $gl_cv_header_signal_h_SIGPIPE != yes; then
59 REPLACE_STDIO_WRITE_FUNCS=1
62 dnl This ifdef is an optimization, to avoid performing a configure check whose
63 dnl result is not used. But it does not make the test of
64 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
65 m4_ifdef([gl_NONBLOCKING_IO], [
67 if test $gl_cv_have_nonblocking != yes; then
68 REPLACE_STDIO_WRITE_FUNCS=1
72 dnl Check for declarations of anything we want to poison if the
73 dnl corresponding gnulib module is not in use, and which is not
74 dnl guaranteed by both C89 and C11.
75 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
76 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
77 renameat snprintf tmpfile vdprintf vsnprintf])
79 AC_REQUIRE([AC_C_RESTRICT])
81 AC_CHECK_DECLS_ONCE([fcloseall])
82 if test $ac_cv_have_decl_fcloseall = no; then
87 # gl_STDIO_MODULE_INDICATOR([modulename])
88 # sets the shell variable that indicates the presence of the given module
89 # to a C preprocessor expression that will evaluate to 1.
90 # This macro invocation must not occur in macros that are AC_REQUIREd.
91 AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
93 dnl Ensure to expand the default settings once only.
94 gl_STDIO_H_REQUIRE_DEFAULTS
95 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
96 dnl Define it also as a C macro, for the benefit of the unit tests.
97 gl_MODULE_INDICATOR_FOR_TESTS([$1])
100 # Initializes the default values for AC_SUBSTed shell variables.
101 # This macro must not be AC_REQUIREd. It must only be invoked, and only
102 # outside of macros or in macros that are not AC_REQUIREd.
103 AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
105 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
108 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETC])
111 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETS])
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN_GNU])
114 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF])
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF_POSIX])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPURGE])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTC])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTS])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREAD])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREOPEN])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSCANF])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEK])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEKO])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELL])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELLO])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FWRITE])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETC])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCHAR])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDELIM])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF_POSIX])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTC])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTCHAR])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTS])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMOVE])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAME])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
160 dnl Support Microsoft deprecated alias function names by default.
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FILENO], [1])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETW], [1])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTW], [1])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TEMPNAM], [1])
168 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
169 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
172 AC_DEFUN([gl_STDIO_H_DEFAULTS],
174 dnl Assume proper GNU behavior unless another module says otherwise.
175 HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
176 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
177 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
178 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
179 HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
180 HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
181 HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
182 HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
183 HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
184 HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF])
185 HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
186 HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
187 HAVE_PCLOSE=1; AC_SUBST([HAVE_PCLOSE])
188 HAVE_POPEN=1; AC_SUBST([HAVE_POPEN])
189 HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT])
190 HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
191 HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
192 REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF])
193 REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
194 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN])
195 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
196 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
197 REPLACE_FOPEN_FOR_FOPEN_GNU=0; AC_SUBST([REPLACE_FOPEN_FOR_FOPEN_GNU])
198 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
199 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
200 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
201 REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
202 REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
203 REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
204 REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
205 REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM])
206 REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
207 REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF])
208 REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR])
209 REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN])
210 REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
211 REPLACE_REMOVE=0; AC_SUBST([REPLACE_REMOVE])
212 REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME])
213 REPLACE_RENAMEAT=0; AC_SUBST([REPLACE_RENAMEAT])
214 REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
215 REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
216 REPLACE_STDIO_READ_FUNCS=0; AC_SUBST([REPLACE_STDIO_READ_FUNCS])
217 REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
218 REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE])
219 REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
220 REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF])
221 REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
222 REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
223 REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
224 REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])