1# stdio_h.m4 serial 50
2dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_STDIO_H],
8[
9  AH_VERBATIM([MINGW_ANSI_STDIO],
10[/* Use GNU style printf and scanf.  */
11#ifndef __USE_MINGW_ANSI_STDIO
12# undef __USE_MINGW_ANSI_STDIO
13#endif
14])
15  AC_DEFINE([__USE_MINGW_ANSI_STDIO])
16  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
17  gl_NEXT_HEADERS([stdio.h])
18
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
26       #include <stdio.h>
27       #include <inttypes.h>
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];
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 No need to create extra modules for these functions. Everyone who uses
44  dnl <stdio.h> likely needs them.
45  GNULIB_FSCANF=1
46  gl_MODULE_INDICATOR([fscanf])
47  GNULIB_SCANF=1
48  gl_MODULE_INDICATOR([scanf])
49  GNULIB_FGETC=1
50  GNULIB_GETC=1
51  GNULIB_GETCHAR=1
52  GNULIB_FGETS=1
53  GNULIB_FREAD=1
54  dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c"
55  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
56  dnl also an optimization, to avoid performing a configure check whose result
57  dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
58  dnl or GNULIB_NONBLOCKING redundant.
59  m4_ifdef([gl_NONBLOCKING_IO], [
60    gl_NONBLOCKING_IO
61    if test $gl_cv_have_nonblocking != yes; then
62      REPLACE_STDIO_READ_FUNCS=1
63      AC_LIBOBJ([stdio-read])
64    fi
65  ])
66
67  dnl No need to create extra modules for these functions. Everyone who uses
68  dnl <stdio.h> likely needs them.
69  GNULIB_FPRINTF=1
70  GNULIB_PRINTF=1
71  GNULIB_VFPRINTF=1
72  GNULIB_VPRINTF=1
73  GNULIB_FPUTC=1
74  GNULIB_PUTC=1
75  GNULIB_PUTCHAR=1
76  GNULIB_FPUTS=1
77  GNULIB_PUTS=1
78  GNULIB_FWRITE=1
79  dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c"
80  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
81  dnl also an optimization, to avoid performing a configure check whose result
82  dnl is not used. But it does not make the test of GNULIB_STDIO_H_SIGPIPE or
83  dnl GNULIB_SIGPIPE redundant.
84  m4_ifdef([gl_SIGNAL_SIGPIPE], [
85    gl_SIGNAL_SIGPIPE
86    if test $gl_cv_header_signal_h_SIGPIPE != yes; then
87      REPLACE_STDIO_WRITE_FUNCS=1
88      AC_LIBOBJ([stdio-write])
89    fi
90  ])
91  dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c"
92  dnl "expected source file, required through AC_LIBSOURCES, not found". It is
93  dnl also an optimization, to avoid performing a configure check whose result
94  dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
95  dnl or GNULIB_NONBLOCKING redundant.
96  m4_ifdef([gl_NONBLOCKING_IO], [
97    gl_NONBLOCKING_IO
98    if test $gl_cv_have_nonblocking != yes; then
99      REPLACE_STDIO_WRITE_FUNCS=1
100      AC_LIBOBJ([stdio-write])
101    fi
102  ])
103
104  dnl Check for declarations of anything we want to poison if the
105  dnl corresponding gnulib module is not in use, and which is not
106  dnl guaranteed by both C89 and C11.
107  gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
108    ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
109    renameat snprintf tmpfile vdprintf vsnprintf])
110
111  AC_REQUIRE([AC_C_RESTRICT])
112])
113
114AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
115[
116  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
117  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
118  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
119  dnl Define it also as a C macro, for the benefit of the unit tests.
120  gl_MODULE_INDICATOR_FOR_TESTS([$1])
121])
122
123AC_DEFUN([gl_STDIO_H_DEFAULTS],
124[
125  GNULIB_DPRINTF=0;              AC_SUBST([GNULIB_DPRINTF])
126  GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
127  GNULIB_FDOPEN=0;               AC_SUBST([GNULIB_FDOPEN])
128  GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
129  GNULIB_FGETC=0;                AC_SUBST([GNULIB_FGETC])
130  GNULIB_FGETS=0;                AC_SUBST([GNULIB_FGETS])
131  GNULIB_FOPEN=0;                AC_SUBST([GNULIB_FOPEN])
132  GNULIB_FPRINTF=0;              AC_SUBST([GNULIB_FPRINTF])
133  GNULIB_FPRINTF_POSIX=0;        AC_SUBST([GNULIB_FPRINTF_POSIX])
134  GNULIB_FPURGE=0;               AC_SUBST([GNULIB_FPURGE])
135  GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
136  GNULIB_FPUTS=0;                AC_SUBST([GNULIB_FPUTS])
137  GNULIB_FREAD=0;                AC_SUBST([GNULIB_FREAD])
138  GNULIB_FREOPEN=0;              AC_SUBST([GNULIB_FREOPEN])
139  GNULIB_FSCANF=0;               AC_SUBST([GNULIB_FSCANF])
140  GNULIB_FSEEK=0;                AC_SUBST([GNULIB_FSEEK])
141  GNULIB_FSEEKO=0;               AC_SUBST([GNULIB_FSEEKO])
142  GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
143  GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
144  GNULIB_FWRITE=0;               AC_SUBST([GNULIB_FWRITE])
145  GNULIB_GETC=0;                 AC_SUBST([GNULIB_GETC])
146  GNULIB_GETCHAR=0;              AC_SUBST([GNULIB_GETCHAR])
147  GNULIB_GETDELIM=0;             AC_SUBST([GNULIB_GETDELIM])
148  GNULIB_GETLINE=0;              AC_SUBST([GNULIB_GETLINE])
149  GNULIB_OBSTACK_PRINTF=0;       AC_SUBST([GNULIB_OBSTACK_PRINTF])
150  GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
151  GNULIB_PCLOSE=0;               AC_SUBST([GNULIB_PCLOSE])
152  GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
153  GNULIB_POPEN=0;                AC_SUBST([GNULIB_POPEN])
154  GNULIB_PRINTF=0;               AC_SUBST([GNULIB_PRINTF])
155  GNULIB_PRINTF_POSIX=0;         AC_SUBST([GNULIB_PRINTF_POSIX])
156  GNULIB_PUTC=0;                 AC_SUBST([GNULIB_PUTC])
157  GNULIB_PUTCHAR=0;              AC_SUBST([GNULIB_PUTCHAR])
158  GNULIB_PUTS=0;                 AC_SUBST([GNULIB_PUTS])
159  GNULIB_REMOVE=0;               AC_SUBST([GNULIB_REMOVE])
160  GNULIB_RENAME=0;               AC_SUBST([GNULIB_RENAME])
161  GNULIB_RENAMEAT=0;             AC_SUBST([GNULIB_RENAMEAT])
162  GNULIB_SCANF=0;                AC_SUBST([GNULIB_SCANF])
163  GNULIB_SNPRINTF=0;             AC_SUBST([GNULIB_SNPRINTF])
164  GNULIB_SPRINTF_POSIX=0;        AC_SUBST([GNULIB_SPRINTF_POSIX])
165  GNULIB_STDIO_H_NONBLOCKING=0;  AC_SUBST([GNULIB_STDIO_H_NONBLOCKING])
166  GNULIB_STDIO_H_SIGPIPE=0;      AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
167  GNULIB_TMPFILE=0;              AC_SUBST([GNULIB_TMPFILE])
168  GNULIB_VASPRINTF=0;            AC_SUBST([GNULIB_VASPRINTF])
169  GNULIB_VFSCANF=0;              AC_SUBST([GNULIB_VFSCANF])
170  GNULIB_VSCANF=0;               AC_SUBST([GNULIB_VSCANF])
171  GNULIB_VDPRINTF=0;             AC_SUBST([GNULIB_VDPRINTF])
172  GNULIB_VFPRINTF=0;             AC_SUBST([GNULIB_VFPRINTF])
173  GNULIB_VFPRINTF_POSIX=0;       AC_SUBST([GNULIB_VFPRINTF_POSIX])
174  GNULIB_VPRINTF=0;              AC_SUBST([GNULIB_VPRINTF])
175  GNULIB_VPRINTF_POSIX=0;        AC_SUBST([GNULIB_VPRINTF_POSIX])
176  GNULIB_VSNPRINTF=0;            AC_SUBST([GNULIB_VSNPRINTF])
177  GNULIB_VSPRINTF_POSIX=0;       AC_SUBST([GNULIB_VSPRINTF_POSIX])
178  dnl Assume proper GNU behavior unless another module says otherwise.
179  HAVE_DECL_FPURGE=1;            AC_SUBST([HAVE_DECL_FPURGE])
180  HAVE_DECL_FSEEKO=1;            AC_SUBST([HAVE_DECL_FSEEKO])
181  HAVE_DECL_FTELLO=1;            AC_SUBST([HAVE_DECL_FTELLO])
182  HAVE_DECL_GETDELIM=1;          AC_SUBST([HAVE_DECL_GETDELIM])
183  HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
184  HAVE_DECL_OBSTACK_PRINTF=1;    AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
185  HAVE_DECL_SNPRINTF=1;          AC_SUBST([HAVE_DECL_SNPRINTF])
186  HAVE_DECL_VSNPRINTF=1;         AC_SUBST([HAVE_DECL_VSNPRINTF])
187  HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
188  HAVE_FSEEKO=1;                 AC_SUBST([HAVE_FSEEKO])
189  HAVE_FTELLO=1;                 AC_SUBST([HAVE_FTELLO])
190  HAVE_PCLOSE=1;                 AC_SUBST([HAVE_PCLOSE])
191  HAVE_POPEN=1;                  AC_SUBST([HAVE_POPEN])
192  HAVE_RENAMEAT=1;               AC_SUBST([HAVE_RENAMEAT])
193  HAVE_VASPRINTF=1;              AC_SUBST([HAVE_VASPRINTF])
194  HAVE_VDPRINTF=1;               AC_SUBST([HAVE_VDPRINTF])
195  REPLACE_DPRINTF=0;             AC_SUBST([REPLACE_DPRINTF])
196  REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
197  REPLACE_FDOPEN=0;              AC_SUBST([REPLACE_FDOPEN])
198  REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
199  REPLACE_FOPEN=0;               AC_SUBST([REPLACE_FOPEN])
200  REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
201  REPLACE_FPURGE=0;              AC_SUBST([REPLACE_FPURGE])
202  REPLACE_FREOPEN=0;             AC_SUBST([REPLACE_FREOPEN])
203  REPLACE_FSEEK=0;               AC_SUBST([REPLACE_FSEEK])
204  REPLACE_FSEEKO=0;              AC_SUBST([REPLACE_FSEEKO])
205  REPLACE_FTELL=0;               AC_SUBST([REPLACE_FTELL])
206  REPLACE_FTELLO=0;              AC_SUBST([REPLACE_FTELLO])
207  REPLACE_GETDELIM=0;            AC_SUBST([REPLACE_GETDELIM])
208  REPLACE_GETLINE=0;             AC_SUBST([REPLACE_GETLINE])
209  REPLACE_OBSTACK_PRINTF=0;      AC_SUBST([REPLACE_OBSTACK_PRINTF])
210  REPLACE_PERROR=0;              AC_SUBST([REPLACE_PERROR])
211  REPLACE_POPEN=0;               AC_SUBST([REPLACE_POPEN])
212  REPLACE_PRINTF=0;              AC_SUBST([REPLACE_PRINTF])
213  REPLACE_REMOVE=0;              AC_SUBST([REPLACE_REMOVE])
214  REPLACE_RENAME=0;              AC_SUBST([REPLACE_RENAME])
215  REPLACE_RENAMEAT=0;            AC_SUBST([REPLACE_RENAMEAT])
216  REPLACE_SNPRINTF=0;            AC_SUBST([REPLACE_SNPRINTF])
217  REPLACE_SPRINTF=0;             AC_SUBST([REPLACE_SPRINTF])
218  REPLACE_STDIO_READ_FUNCS=0;    AC_SUBST([REPLACE_STDIO_READ_FUNCS])
219  REPLACE_STDIO_WRITE_FUNCS=0;   AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
220  REPLACE_TMPFILE=0;             AC_SUBST([REPLACE_TMPFILE])
221  REPLACE_VASPRINTF=0;           AC_SUBST([REPLACE_VASPRINTF])
222  REPLACE_VDPRINTF=0;            AC_SUBST([REPLACE_VDPRINTF])
223  REPLACE_VFPRINTF=0;            AC_SUBST([REPLACE_VFPRINTF])
224  REPLACE_VPRINTF=0;             AC_SUBST([REPLACE_VPRINTF])
225  REPLACE_VSNPRINTF=0;           AC_SUBST([REPLACE_VSNPRINTF])
226  REPLACE_VSPRINTF=0;            AC_SUBST([REPLACE_VSPRINTF])
227])
228