Debian Codegraph @

m4/stdio_h.m4

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