3 dnl Copyright (C) 2007-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.
8 AC_DEFUN([gl_STDIO_H_EARLY],
10 dnl Defining __USE_MINGW_ANSI_STDIO to 1 must be done early, because
11 dnl the results of several configure tests depend on it: The tests
12 dnl - checking whether snprintf returns a byte count as in C99...
13 dnl - checking whether snprintf truncates the result as in C99...
14 dnl - checking whether printf supports the 'F' directive...
15 dnl - checking whether printf supports the grouping flag...
16 dnl - checking whether printf supports the zero flag correctly...
17 dnl - checking whether printf supports infinite 'double' arguments...
18 dnl - checking whether printf supports large precisions...
19 dnl report 'yes' if __USE_MINGW_ANSI_STDIO is 1 but 'no' if
20 dnl __USE_MINGW_ANSI_STDIO is not set.
21 AH_VERBATIM([MINGW_ANSI_STDIO],
22 [/* Use GNU style printf and scanf. */
23 #ifndef __USE_MINGW_ANSI_STDIO
24 # undef __USE_MINGW_ANSI_STDIO
27 AC_DEFINE([__USE_MINGW_ANSI_STDIO])
30 AC_DEFUN_ONCE([gl_STDIO_H],
32 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
33 gl_NEXT_HEADERS([stdio.h])
35 dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
36 dnl inttypes.h behave like gnu instead of system; we must give our
37 dnl printf wrapper the right attribute to match.
38 AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
39 [gl_cv_func_printf_attribute_flavor],
40 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
41 #define __STDC_FORMAT_MACROS 1
44 /* For non-mingw systems, compilation will trivially succeed.
45 For mingw, compilation will succeed for older mingw (system
46 printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
47 #if (defined _WIN32 && ! defined __CYGWIN__) && \
48 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
49 extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
51 ]])], [gl_cv_func_printf_attribute_flavor=system],
52 [gl_cv_func_printf_attribute_flavor=gnu])])
53 if test "$gl_cv_func_printf_attribute_flavor" = gnu; then
54 AC_DEFINE([GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU], [1],
55 [Define to 1 if printf and friends should be labeled with
56 attribute "__gnu_printf__" instead of "__printf__"])
59 dnl For defining _PRINTF_NAN_LEN_MAX.
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_READ_FUNCS=1
72 dnl This ifdef is an optimization, to avoid performing a configure check whose
73 dnl result is not used. But it does not make the test of
74 dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
75 m4_ifdef([gl_SIGNAL_SIGPIPE], [
77 if test $gl_cv_header_signal_h_SIGPIPE != yes; then
78 REPLACE_STDIO_WRITE_FUNCS=1
81 dnl This ifdef is an optimization, to avoid performing a configure check whose
82 dnl result is not used. But it does not make the test of
83 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
84 m4_ifdef([gl_NONBLOCKING_IO], [
86 if test $gl_cv_have_nonblocking != yes; then
87 REPLACE_STDIO_WRITE_FUNCS=1
91 dnl Check for declarations of anything we want to poison if the
92 dnl corresponding gnulib module is not in use, and which is not
93 dnl guaranteed by both C89 and C11.
94 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
95 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
96 renameat snprintf tmpfile vdprintf vsnprintf])
98 AC_REQUIRE([AC_C_RESTRICT])
100 AC_CHECK_DECLS_ONCE([fcloseall])
101 if test $ac_cv_have_decl_fcloseall = no; then
102 HAVE_DECL_FCLOSEALL=0
105 AC_CHECK_DECLS_ONCE([getw])
106 if test $ac_cv_have_decl_getw = no; then
110 AC_CHECK_DECLS_ONCE([putw])
111 if test $ac_cv_have_decl_putw = no; then
116 # gl_STDIO_MODULE_INDICATOR([modulename])
117 # sets the shell variable that indicates the presence of the given module
118 # to a C preprocessor expression that will evaluate to 1.
119 # This macro invocation must not occur in macros that are AC_REQUIREd.
120 AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
122 dnl Ensure to expand the default settings once only.
123 gl_STDIO_H_REQUIRE_DEFAULTS
124 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
125 dnl Define it also as a C macro, for the benefit of the unit tests.
126 gl_MODULE_INDICATOR_FOR_TESTS([$1])
129 # Initializes the default values for AC_SUBSTed shell variables.
130 # This macro must not be AC_REQUIREd. It must only be invoked, and only
131 # outside of macros or in macros that are not AC_REQUIREd.
132 AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
134 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETC])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETS])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN_GNU])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF_POSIX])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPURGE])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTC])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTS])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREAD])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREOPEN])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSCANF])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEK])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEKO])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELL])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELLO])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FWRITE])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETC])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCHAR])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDELIM])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF_POSIX])
167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTC])
168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTCHAR])
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTS])
170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMOVE])
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAME])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
176 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
177 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
178 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
189 dnl Support Microsoft deprecated alias function names by default.
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
191 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FILENO], [1])
193 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETW], [1])
194 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTW], [1])
195 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TEMPNAM], [1])
197 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
198 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
201 AC_DEFUN([gl_STDIO_H_DEFAULTS],
203 dnl Assume proper GNU behavior unless another module says otherwise.
204 HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
205 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
206 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
207 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
208 HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
209 HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
210 HAVE_DECL_GETW=1; AC_SUBST([HAVE_DECL_GETW])
211 HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
212 HAVE_DECL_PUTW=1; AC_SUBST([HAVE_DECL_PUTW])
213 HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
214 HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
215 HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF])
216 HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
217 HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
218 HAVE_PCLOSE=1; AC_SUBST([HAVE_PCLOSE])
219 HAVE_POPEN=1; AC_SUBST([HAVE_POPEN])
220 HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT])
221 HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
222 HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
223 REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF])
224 REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
225 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN])
226 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
227 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
228 REPLACE_FOPEN_FOR_FOPEN_GNU=0; AC_SUBST([REPLACE_FOPEN_FOR_FOPEN_GNU])
229 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
230 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
231 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
232 REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
233 REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
234 REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
235 REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
236 REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM])
237 REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
238 REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF])
239 REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR])
240 REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN])
241 REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
242 REPLACE_REMOVE=0; AC_SUBST([REPLACE_REMOVE])
243 REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME])
244 REPLACE_RENAMEAT=0; AC_SUBST([REPLACE_RENAMEAT])
245 REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
246 REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
247 REPLACE_STDIO_READ_FUNCS=0; AC_SUBST([REPLACE_STDIO_READ_FUNCS])
248 REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
249 REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE])
250 REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
251 REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF])
252 REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
253 REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
254 REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
255 REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])