summaryrefslogtreecommitdiffstats
path: root/gl/m4/stdio_h.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/stdio_h.m4')
-rw-r--r--gl/m4/stdio_h.m4229
1 files changed, 130 insertions, 99 deletions
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index ebade06..42e9607 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,72 +1,71 @@
1# stdio_h.m4 serial 43 1# stdio_h.m4 serial 59
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7AC_DEFUN([gl_STDIO_H], 7AC_DEFUN_ONCE([gl_STDIO_H],
8[ 8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 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
14#endif
15])
16 AC_DEFINE([__USE_MINGW_ANSI_STDIO])
10 gl_NEXT_HEADERS([stdio.h]) 17 gl_NEXT_HEADERS([stdio.h])
11 18
12 dnl No need to create extra modules for these functions. Everyone who uses 19 dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
13 dnl <stdio.h> likely needs them. 20 dnl inttypes.h behave like gnu instead of system; we must give our
14 GNULIB_FSCANF=1 21 dnl printf wrapper the right attribute to match.
15 gl_MODULE_INDICATOR([fscanf]) 22 AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
16 GNULIB_SCANF=1 23 [gl_cv_func_printf_attribute_flavor],
17 gl_MODULE_INDICATOR([scanf]) 24 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
18 GNULIB_FGETC=1 25 #define __STDC_FORMAT_MACROS 1
19 GNULIB_GETC=1 26 #include <stdio.h>
20 GNULIB_GETCHAR=1 27 #include <inttypes.h>
21 GNULIB_FGETS=1 28 /* For non-mingw systems, compilation will trivially succeed.
22 GNULIB_FREAD=1 29 For mingw, compilation will succeed for older mingw (system
23 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c" 30 printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
24 dnl "expected source file, required through AC_LIBSOURCES, not found". It is 31 #if (defined _WIN32 && ! defined __CYGWIN__) && \
25 dnl also an optimization, to avoid performing a configure check whose result 32 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
26 dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING 33 extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
27 dnl or GNULIB_NONBLOCKING redundant. 34 #endif
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__"])
41 fi
42
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.
28 m4_ifdef([gl_NONBLOCKING_IO], [ 46 m4_ifdef([gl_NONBLOCKING_IO], [
29 gl_NONBLOCKING_IO 47 gl_NONBLOCKING_IO
30 if test $gl_cv_have_nonblocking != yes; then 48 if test $gl_cv_have_nonblocking != yes; then
31 REPLACE_STDIO_READ_FUNCS=1 49 REPLACE_STDIO_READ_FUNCS=1
32 AC_LIBOBJ([stdio-read])
33 fi 50 fi
34 ]) 51 ])
35 52
36 dnl No need to create extra modules for these functions. Everyone who uses 53 dnl This ifdef is an optimization, to avoid performing a configure check whose
37 dnl <stdio.h> likely needs them. 54 dnl result is not used. But it does not make the test of
38 GNULIB_FPRINTF=1 55 dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
39 GNULIB_PRINTF=1
40 GNULIB_VFPRINTF=1
41 GNULIB_VPRINTF=1
42 GNULIB_FPUTC=1
43 GNULIB_PUTC=1
44 GNULIB_PUTCHAR=1
45 GNULIB_FPUTS=1
46 GNULIB_PUTS=1
47 GNULIB_FWRITE=1
48 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c"
49 dnl "expected source file, required through AC_LIBSOURCES, not found". It is
50 dnl also an optimization, to avoid performing a configure check whose result
51 dnl is not used. But it does not make the test of GNULIB_STDIO_H_SIGPIPE or
52 dnl GNULIB_SIGPIPE redundant.
53 m4_ifdef([gl_SIGNAL_SIGPIPE], [ 56 m4_ifdef([gl_SIGNAL_SIGPIPE], [
54 gl_SIGNAL_SIGPIPE 57 gl_SIGNAL_SIGPIPE
55 if test $gl_cv_header_signal_h_SIGPIPE != yes; then 58 if test $gl_cv_header_signal_h_SIGPIPE != yes; then
56 REPLACE_STDIO_WRITE_FUNCS=1 59 REPLACE_STDIO_WRITE_FUNCS=1
57 AC_LIBOBJ([stdio-write])
58 fi 60 fi
59 ]) 61 ])
60 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c" 62 dnl This ifdef is an optimization, to avoid performing a configure check whose
61 dnl "expected source file, required through AC_LIBSOURCES, not found". It is 63 dnl result is not used. But it does not make the test of
62 dnl also an optimization, to avoid performing a configure check whose result 64 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
63 dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
64 dnl or GNULIB_NONBLOCKING redundant.
65 m4_ifdef([gl_NONBLOCKING_IO], [ 65 m4_ifdef([gl_NONBLOCKING_IO], [
66 gl_NONBLOCKING_IO 66 gl_NONBLOCKING_IO
67 if test $gl_cv_have_nonblocking != yes; then 67 if test $gl_cv_have_nonblocking != yes; then
68 REPLACE_STDIO_WRITE_FUNCS=1 68 REPLACE_STDIO_WRITE_FUNCS=1
69 AC_LIBOBJ([stdio-write])
70 fi 69 fi
71 ]) 70 ])
72 71
@@ -76,73 +75,104 @@ AC_DEFUN([gl_STDIO_H],
76 gl_WARN_ON_USE_PREPARE([[#include <stdio.h> 75 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
77 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen 76 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
78 renameat snprintf tmpfile vdprintf vsnprintf]) 77 renameat snprintf tmpfile vdprintf vsnprintf])
78
79 AC_REQUIRE([AC_C_RESTRICT])
80
81 AC_CHECK_DECLS_ONCE([fcloseall])
82 if test $ac_cv_have_decl_fcloseall = no; then
83 HAVE_DECL_FCLOSEALL=0
84 fi
79]) 85])
80 86
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.
81AC_DEFUN([gl_STDIO_MODULE_INDICATOR], 91AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
82[ 92[
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 93 dnl Ensure to expand the default settings once only.
84 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 94 gl_STDIO_H_REQUIRE_DEFAULTS
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 95 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
86 dnl Define it also as a C macro, for the benefit of the unit tests. 96 dnl Define it also as a C macro, for the benefit of the unit tests.
87 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 97 gl_MODULE_INDICATOR_FOR_TESTS([$1])
88]) 98])
89 99
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.
103AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
104[
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])
167 ])
168 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
169 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
170])
171
90AC_DEFUN([gl_STDIO_H_DEFAULTS], 172AC_DEFUN([gl_STDIO_H_DEFAULTS],
91[ 173[
92 GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF])
93 GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
94 GNULIB_FDOPEN=0; AC_SUBST([GNULIB_FDOPEN])
95 GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
96 GNULIB_FGETC=0; AC_SUBST([GNULIB_FGETC])
97 GNULIB_FGETS=0; AC_SUBST([GNULIB_FGETS])
98 GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN])
99 GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF])
100 GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
101 GNULIB_FPURGE=0; AC_SUBST([GNULIB_FPURGE])
102 GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
103 GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS])
104 GNULIB_FREAD=0; AC_SUBST([GNULIB_FREAD])
105 GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN])
106 GNULIB_FSCANF=0; AC_SUBST([GNULIB_FSCANF])
107 GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
108 GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
109 GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
110 GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
111 GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE])
112 GNULIB_GETC=0; AC_SUBST([GNULIB_GETC])
113 GNULIB_GETCHAR=0; AC_SUBST([GNULIB_GETCHAR])
114 GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM])
115 GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE])
116 GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF])
117 GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
118 GNULIB_PCLOSE=0; AC_SUBST([GNULIB_PCLOSE])
119 GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR])
120 GNULIB_POPEN=0; AC_SUBST([GNULIB_POPEN])
121 GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF])
122 GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
123 GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
124 GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
125 GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS])
126 GNULIB_REMOVE=0; AC_SUBST([GNULIB_REMOVE])
127 GNULIB_RENAME=0; AC_SUBST([GNULIB_RENAME])
128 GNULIB_RENAMEAT=0; AC_SUBST([GNULIB_RENAMEAT])
129 GNULIB_SCANF=0; AC_SUBST([GNULIB_SCANF])
130 GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
131 GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
132 GNULIB_STDIO_H_NONBLOCKING=0; AC_SUBST([GNULIB_STDIO_H_NONBLOCKING])
133 GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
134 GNULIB_TMPFILE=0; AC_SUBST([GNULIB_TMPFILE])
135 GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
136 GNULIB_VFSCANF=0; AC_SUBST([GNULIB_VFSCANF])
137 GNULIB_VSCANF=0; AC_SUBST([GNULIB_VSCANF])
138 GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF])
139 GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
140 GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
141 GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF])
142 GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
143 GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
144 GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
145 dnl Assume proper GNU behavior unless another module says otherwise. 174 dnl Assume proper GNU behavior unless another module says otherwise.
175 HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
146 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE]) 176 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
147 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO]) 177 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
148 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO]) 178 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
@@ -164,6 +194,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
164 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN]) 194 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN])
165 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) 195 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
166 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN]) 196 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
197 REPLACE_FOPEN_FOR_FOPEN_GNU=0; AC_SUBST([REPLACE_FOPEN_FOR_FOPEN_GNU])
167 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) 198 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
168 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE]) 199 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
169 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN]) 200 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])