1 /* A GNU-like <stdio.h>.
3 Copyright (C) 2004, 2007-2010 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_FILE || defined __need___FILE
24 /* Special invocation convention inside glibc header files. */
26 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
29 /* Normal invocation convention. */
33 /* The include_next requires a split double-inclusion guard. */
34 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
39 /* Get va_list. Needed on many systems, including glibc 2.8. */
44 /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8. */
45 #include <sys/types.h>
48 /* The __attribute__ feature is available in gcc versions 2.5 and later.
49 The __-protected variants of the attributes 'format' and 'printf' are
50 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
51 We enable __attribute__ only if these are supported too, because
52 gnulib and libintl do '#define printf __printf__' when they override
53 the 'printf' function. */
54 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
55 # define __attribute__(Spec) /* empty */
60 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
62 /* The definition of _GL_ARG_NONNULL is copied here. */
64 /* The definition of _GL_WARN_ON_USE is copied here. */
68 # if @REPLACE_DPRINTF@
69 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
70 # define dprintf rpl_dprintf
72 _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
73 __attribute__ ((__format__ (__printf__, 2, 3)))
74 _GL_ARG_NONNULL ((2)));
75 _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
78 _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
79 __attribute__ ((__format__ (__printf__, 2, 3)))
80 _GL_ARG_NONNULL ((2)));
82 _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
84 _GL_CXXALIASWARN (dprintf);
85 #elif defined GNULIB_POSIXCHECK
87 # if HAVE_RAW_DECL_DPRINTF
88 _GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
89 "use gnulib module dprintf for portability");
94 /* Close STREAM and its underlying file descriptor. */
96 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
97 # define fclose rpl_fclose
99 _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
100 _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
102 _GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
104 _GL_CXXALIASWARN (fclose);
105 #elif defined GNULIB_POSIXCHECK
107 /* Assume fclose is always declared. */
108 _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
109 "use gnulib module fclose for portable POSIX compliance");
113 /* Flush all pending data on STREAM according to POSIX rules. Both
114 output and seekable input streams are supported.
115 Note! LOSS OF DATA can occur if fflush is applied on an input stream
116 that is _not_seekable_ or on an update stream that is _not_seekable_
117 and in which the most recent operation was input. Seekability can
118 be tested with lseek(fileno(fp),0,SEEK_CUR). */
119 # if @REPLACE_FFLUSH@
120 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121 # define fflush rpl_fflush
123 _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
124 _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
126 _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
128 _GL_CXXALIASWARN (fflush);
129 #elif defined GNULIB_POSIXCHECK
131 /* Assume fflush is always declared. */
132 _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
133 "use gnulib module fflush for portable POSIX compliance");
136 /* It is very rare that the developer ever has full control of stdin,
137 so any use of gets warrants an unconditional warning. Assume it is
138 always declared, since it is required by C89. */
140 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
144 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
146 # define fopen rpl_fopen
148 _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
149 _GL_ARG_NONNULL ((1, 2)));
150 _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
152 _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
154 _GL_CXXALIASWARN (fopen);
155 #elif defined GNULIB_POSIXCHECK
157 /* Assume fopen is always declared. */
158 _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
159 "use gnulib module fopen for portability");
162 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
163 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
164 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
165 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166 # define fprintf rpl_fprintf
168 # define GNULIB_overrides_fprintf 1
169 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
170 __attribute__ ((__format__ (__printf__, 2, 3)))
171 _GL_ARG_NONNULL ((1, 2)));
172 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
174 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
176 _GL_CXXALIASWARN (fprintf);
178 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
179 # if !GNULIB_overrides_fprintf
182 /* Assume fprintf is always declared. */
183 _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
184 "use gnulib module fprintf-posix for portable "
189 /* Discard all pending buffered I/O data on STREAM.
190 STREAM must not be wide-character oriented.
191 When discarding pending output, the file position is set back to where it
192 was before the write calls. When discarding pending input, the file
193 position is advanced to match the end of the previously read input.
194 Return 0 if successful. Upon error, return -1 and set errno. */
195 # if @REPLACE_FPURGE@
196 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
197 # define fpurge rpl_fpurge
199 _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
200 _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
202 # if !@HAVE_DECL_FPURGE@
203 _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
205 _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
207 _GL_CXXALIASWARN (fpurge);
208 #elif defined GNULIB_POSIXCHECK
210 # if HAVE_RAW_DECL_FPURGE
211 _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
212 "use gnulib module fpurge for portability");
217 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
218 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
220 # define fputc rpl_fputc
222 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
223 _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
225 _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
227 _GL_CXXALIASWARN (fputc);
231 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
232 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
234 # define fputs rpl_fputs
236 _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
237 _GL_ARG_NONNULL ((1, 2)));
238 _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
240 _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
242 _GL_CXXALIASWARN (fputs);
246 # if @REPLACE_FREOPEN@
247 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
249 # define freopen rpl_freopen
251 _GL_FUNCDECL_RPL (freopen, FILE *,
252 (const char *filename, const char *mode, FILE *stream)
253 _GL_ARG_NONNULL ((2, 3)));
254 _GL_CXXALIAS_RPL (freopen, FILE *,
255 (const char *filename, const char *mode, FILE *stream));
257 _GL_CXXALIAS_SYS (freopen, FILE *,
258 (const char *filename, const char *mode, FILE *stream));
260 _GL_CXXALIASWARN (freopen);
261 #elif defined GNULIB_POSIXCHECK
263 /* Assume freopen is always declared. */
264 _GL_WARN_ON_USE (freopen, "freopen on Win32 platforms is not POSIX compatible - "
265 "use gnulib module freopen for portability");
269 /* Set up the following warnings, based on which modules are in use.
270 GNU Coding Standards discourage the use of fseek, since it imposes
271 an arbitrary limitation on some 32-bit hosts. Remember that the
272 fseek module depends on the fseeko module, so we only have three
275 1. The developer is not using either module. Issue a warning under
276 GNULIB_POSIXCHECK for both functions, to remind them that both
277 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
278 impact on this warning.
280 2. The developer is using both modules. They may be unaware of the
281 arbitrary limitations of fseek, so issue a warning under
282 GNULIB_POSIXCHECK. On the other hand, they may be using both
283 modules intentionally, so the developer can define
284 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
285 is safe, to silence the warning.
287 3. The developer is using the fseeko module, but not fseek. Gnulib
288 guarantees that fseek will still work around platform bugs in that
289 case, but we presume that the developer is aware of the pitfalls of
290 fseek and was trying to avoid it, so issue a warning even when
291 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
292 defined to silence the warning in particular compilation units.
293 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
294 fseek gets defined as a macro, it is recommended that the developer
295 uses the fseek module, even if he is not calling the fseek function.
297 Most gnulib clients that perform stream operations should fall into
301 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
302 # define _GL_FSEEK_WARN /* Category 2, above. */
306 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
308 # define fseek rpl_fseek
310 _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
311 _GL_ARG_NONNULL ((1)));
312 _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
314 _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
316 _GL_CXXALIASWARN (fseek);
320 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
321 # define _GL_FSEEK_WARN /* Category 3, above. */
324 # if @REPLACE_FSEEKO@
325 /* Provide fseek, fseeko functions that are aware of a preceding
326 fflush(), and which detect pipes. */
327 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
329 # define fseeko rpl_fseeko
331 _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
332 _GL_ARG_NONNULL ((1)));
334 /* In order to avoid that fseek gets defined as a macro here, the
335 developer can request the 'fseek' module. */
337 # define fseek rpl_fseek
338 static inline int _GL_ARG_NONNULL ((1))
339 rpl_fseek (FILE *fp, long offset, int whence)
341 return fseeko (fp, offset, whence);
344 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
346 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
348 _GL_CXXALIASWARN (fseeko);
349 #elif defined GNULIB_POSIXCHECK
350 # define _GL_FSEEK_WARN /* Category 1, above. */
353 # if HAVE_RAW_DECL_FSEEKO
354 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
355 "use gnulib module fseeko for portability");
359 #ifdef _GL_FSEEK_WARN
360 # undef _GL_FSEEK_WARN
361 /* Here, either fseek is undefined (but C89 guarantees that it is
362 declared), or it is defined as rpl_fseek (declared above). */
363 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
364 "on 32-bit platforms - "
365 "use fseeko function for handling of large files");
369 /* ftell, ftello. See the comments on fseek/fseeko. */
372 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
373 # define _GL_FTELL_WARN /* Category 2, above. */
377 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
379 # define ftell rpl_ftell
381 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
382 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
384 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
386 _GL_CXXALIASWARN (ftell);
390 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
391 # define _GL_FTELL_WARN /* Category 3, above. */
394 # if @REPLACE_FTELLO@
395 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
397 # define ftello rpl_ftello
399 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
401 /* In order to avoid that ftell gets defined as a macro here, the
402 developer can request the 'ftell' module. */
404 # define ftell rpl_ftell
405 static inline long _GL_ARG_NONNULL ((1))
411 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
413 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
415 _GL_CXXALIASWARN (ftello);
416 #elif defined GNULIB_POSIXCHECK
417 # define _GL_FTELL_WARN /* Category 1, above. */
420 # if HAVE_RAW_DECL_FTELLO
421 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
422 "use gnulib module ftello for portability");
426 #ifdef _GL_FTELL_WARN
427 # undef _GL_FTELL_WARN
428 /* Here, either ftell is undefined (but C89 guarantees that it is
429 declared), or it is defined as rpl_ftell (declared above). */
430 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
431 "on 32-bit platforms - "
432 "use ftello function for handling of large files");
437 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
438 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
440 # define fwrite rpl_fwrite
442 _GL_FUNCDECL_RPL (fwrite, size_t,
443 (const void *ptr, size_t s, size_t n, FILE *stream)
444 _GL_ARG_NONNULL ((1, 4)));
445 _GL_CXXALIAS_RPL (fwrite, size_t,
446 (const void *ptr, size_t s, size_t n, FILE *stream));
448 _GL_CXXALIAS_SYS (fwrite, size_t,
449 (const void *ptr, size_t s, size_t n, FILE *stream));
451 _GL_CXXALIASWARN (fwrite);
454 #if @GNULIB_GETDELIM@
455 /* Read input, up to (and including) the next occurrence of DELIMITER, from
456 STREAM, store it in *LINEPTR (and NUL-terminate it).
457 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
458 bytes of space. It is realloc'd as necessary.
459 Return the number of bytes read and stored at *LINEPTR (not including the
460 NUL terminator), or -1 on error or EOF. */
461 # if @REPLACE_GETDELIM@
462 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
464 # define getdelim rpl_getdelim
466 _GL_FUNCDECL_RPL (getdelim, ssize_t,
467 (char **lineptr, size_t *linesize, int delimiter,
469 _GL_ARG_NONNULL ((1, 2, 4)));
470 _GL_CXXALIAS_RPL (getdelim, ssize_t,
471 (char **lineptr, size_t *linesize, int delimiter,
474 # if !@HAVE_DECL_GETDELIM@
475 _GL_FUNCDECL_SYS (getdelim, ssize_t,
476 (char **lineptr, size_t *linesize, int delimiter,
478 _GL_ARG_NONNULL ((1, 2, 4)));
480 _GL_CXXALIAS_SYS (getdelim, ssize_t,
481 (char **lineptr, size_t *linesize, int delimiter,
484 _GL_CXXALIASWARN (getdelim);
485 #elif defined GNULIB_POSIXCHECK
487 # if HAVE_RAW_DECL_GETDELIM
488 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
489 "use gnulib module getdelim for portability");
494 /* Read a line, up to (and including) the next newline, from STREAM, store it
495 in *LINEPTR (and NUL-terminate it).
496 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
497 bytes of space. It is realloc'd as necessary.
498 Return the number of bytes read and stored at *LINEPTR (not including the
499 NUL terminator), or -1 on error or EOF. */
500 # if @REPLACE_GETLINE@
501 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
503 # define getline rpl_getline
505 _GL_FUNCDECL_RPL (getline, ssize_t,
506 (char **lineptr, size_t *linesize, FILE *stream)
507 _GL_ARG_NONNULL ((1, 2, 3)));
508 _GL_CXXALIAS_RPL (getline, ssize_t,
509 (char **lineptr, size_t *linesize, FILE *stream));
511 # if !@HAVE_DECL_GETLINE@
512 _GL_FUNCDECL_SYS (getline, ssize_t,
513 (char **lineptr, size_t *linesize, FILE *stream)
514 _GL_ARG_NONNULL ((1, 2, 3)));
516 _GL_CXXALIAS_SYS (getline, ssize_t,
517 (char **lineptr, size_t *linesize, FILE *stream));
519 _GL_CXXALIASWARN (getline);
520 #elif defined GNULIB_POSIXCHECK
522 # if HAVE_RAW_DECL_GETLINE
523 _GL_WARN_ON_USE (getline, "getline is unportable - "
524 "use gnulib module getline for portability");
528 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
530 /* Grow an obstack with formatted output. Return the number of
531 bytes added to OBS. No trailing nul byte is added, and the
532 object should be closed with obstack_finish before use. Upon
533 memory allocation error, call obstack_alloc_failed_handler. Upon
534 other error, return -1. */
535 # if @REPLACE_OBSTACK_PRINTF@
536 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
537 # define obstack_printf rpl_obstack_printf
539 _GL_FUNCDECL_RPL (obstack_printf, int,
540 (struct obstack *obs, const char *format, ...)
541 __attribute__ ((__format__ (__printf__, 2, 3)))
542 _GL_ARG_NONNULL ((1, 2)));
543 _GL_CXXALIAS_RPL (obstack_printf, int,
544 (struct obstack *obs, const char *format, ...));
546 # if !@HAVE_DECL_OBSTACK_PRINTF@
547 _GL_FUNCDECL_SYS (obstack_printf, int,
548 (struct obstack *obs, const char *format, ...)
549 __attribute__ ((__format__ (__printf__, 2, 3)))
550 _GL_ARG_NONNULL ((1, 2)));
552 _GL_CXXALIAS_SYS (obstack_printf, int,
553 (struct obstack *obs, const char *format, ...));
555 _GL_CXXALIASWARN (obstack_printf);
556 # if @REPLACE_OBSTACK_PRINTF@
557 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
558 # define obstack_vprintf rpl_obstack_vprintf
560 _GL_FUNCDECL_RPL (obstack_vprintf, int,
561 (struct obstack *obs, const char *format, va_list args)
562 __attribute__ ((__format__ (__printf__, 2, 0)))
563 _GL_ARG_NONNULL ((1, 2)));
564 _GL_CXXALIAS_RPL (obstack_vprintf, int,
565 (struct obstack *obs, const char *format, va_list args));
567 # if !@HAVE_DECL_OBSTACK_PRINTF@
568 _GL_FUNCDECL_SYS (obstack_vprintf, int,
569 (struct obstack *obs, const char *format, va_list args)
570 __attribute__ ((__format__ (__printf__, 2, 0)))
571 _GL_ARG_NONNULL ((1, 2)));
573 _GL_CXXALIAS_SYS (obstack_vprintf, int,
574 (struct obstack *obs, const char *format, va_list args));
576 _GL_CXXALIASWARN (obstack_vprintf);
580 /* Print a message to standard error, describing the value of ERRNO,
581 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
582 and terminated with a newline. */
583 # if @REPLACE_PERROR@
584 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585 # define perror rpl_perror
587 _GL_FUNCDECL_RPL (perror, void, (const char *string));
588 _GL_CXXALIAS_RPL (perror, void, (const char *string));
590 _GL_CXXALIAS_SYS (perror, void, (const char *string));
592 _GL_CXXALIASWARN (perror);
593 #elif defined GNULIB_POSIXCHECK
595 /* Assume perror is always declared. */
596 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
597 "use gnulib module perror for portability");
602 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
604 # define popen rpl_popen
606 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
607 _GL_ARG_NONNULL ((1, 2)));
608 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
610 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
612 _GL_CXXALIASWARN (popen);
613 #elif defined GNULIB_POSIXCHECK
615 # if HAVE_RAW_DECL_POPEN
616 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
617 "use gnulib module popen or pipe for more portability");
621 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
622 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
623 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
624 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
625 /* Don't break __attribute__((format(printf,M,N))). */
626 # define printf __printf__
628 # define GNULIB_overrides_printf 1
629 _GL_FUNCDECL_RPL_1 (__printf__, int,
630 (const char *format, ...)
631 __attribute__ ((__format__ (__printf__, 1, 2)))
632 _GL_ARG_NONNULL ((1)));
633 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
635 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
637 _GL_CXXALIASWARN (printf);
639 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
640 # if !GNULIB_overrides_printf
643 /* Assume printf is always declared. */
644 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
645 "use gnulib module printf-posix for portable "
650 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
651 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
653 # define putc rpl_fputc
655 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
656 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
658 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
660 _GL_CXXALIASWARN (putc);
664 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
665 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
667 # define putchar rpl_putchar
669 _GL_FUNCDECL_RPL (putchar, int, (int c));
670 _GL_CXXALIAS_RPL (putchar, int, (int c));
672 _GL_CXXALIAS_SYS (putchar, int, (int c));
674 _GL_CXXALIASWARN (putchar);
678 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
679 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
681 # define puts rpl_puts
683 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
684 _GL_CXXALIAS_RPL (puts, int, (const char *string));
686 _GL_CXXALIAS_SYS (puts, int, (const char *string));
688 _GL_CXXALIASWARN (puts);
692 # if @REPLACE_REMOVE@
693 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
695 # define remove rpl_remove
697 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
698 _GL_CXXALIAS_RPL (remove, int, (const char *name));
700 _GL_CXXALIAS_SYS (remove, int, (const char *name));
702 _GL_CXXALIASWARN (remove);
703 #elif defined GNULIB_POSIXCHECK
705 /* Assume remove is always declared. */
706 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
707 "use gnulib module remove for more portability");
711 # if @REPLACE_RENAME@
712 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714 # define rename rpl_rename
716 _GL_FUNCDECL_RPL (rename, int,
717 (const char *old_filename, const char *new_filename)
718 _GL_ARG_NONNULL ((1, 2)));
719 _GL_CXXALIAS_RPL (rename, int,
720 (const char *old_filename, const char *new_filename));
722 _GL_CXXALIAS_SYS (rename, int,
723 (const char *old_filename, const char *new_filename));
725 _GL_CXXALIASWARN (rename);
726 #elif defined GNULIB_POSIXCHECK
728 /* Assume rename is always declared. */
729 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
730 "use gnulib module rename for more portability");
733 #if @GNULIB_RENAMEAT@
734 # if @REPLACE_RENAMEAT@
735 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
737 # define renameat rpl_renameat
739 _GL_FUNCDECL_RPL (renameat, int,
740 (int fd1, char const *file1, int fd2, char const *file2)
741 _GL_ARG_NONNULL ((2, 4)));
742 _GL_CXXALIAS_RPL (renameat, int,
743 (int fd1, char const *file1, int fd2, char const *file2));
745 # if !@HAVE_RENAMEAT@
746 _GL_FUNCDECL_SYS (renameat, int,
747 (int fd1, char const *file1, int fd2, char const *file2)
748 _GL_ARG_NONNULL ((2, 4)));
750 _GL_CXXALIAS_SYS (renameat, int,
751 (int fd1, char const *file1, int fd2, char const *file2));
753 _GL_CXXALIASWARN (renameat);
754 #elif defined GNULIB_POSIXCHECK
756 # if HAVE_RAW_DECL_RENAMEAT
757 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
758 "use gnulib module renameat for portability");
762 #if @GNULIB_SNPRINTF@
763 # if @REPLACE_SNPRINTF@
764 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
765 # define snprintf rpl_snprintf
767 _GL_FUNCDECL_RPL (snprintf, int,
768 (char *str, size_t size, const char *format, ...)
769 __attribute__ ((__format__ (__printf__, 3, 4)))
770 _GL_ARG_NONNULL ((3)));
771 _GL_CXXALIAS_RPL (snprintf, int,
772 (char *str, size_t size, const char *format, ...));
774 # if !@HAVE_DECL_SNPRINTF@
775 _GL_FUNCDECL_SYS (snprintf, int,
776 (char *str, size_t size, const char *format, ...)
777 __attribute__ ((__format__ (__printf__, 3, 4)))
778 _GL_ARG_NONNULL ((3)));
780 _GL_CXXALIAS_SYS (snprintf, int,
781 (char *str, size_t size, const char *format, ...));
783 _GL_CXXALIASWARN (snprintf);
784 #elif defined GNULIB_POSIXCHECK
786 # if HAVE_RAW_DECL_SNPRINTF
787 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
788 "use gnulib module snprintf for portability");
792 /* Some people would argue that sprintf should be handled like gets
793 (for example, OpenBSD issues a link warning for both functions),
794 since both can cause security holes due to buffer overruns.
795 However, we believe that sprintf can be used safely, and is more
796 efficient than snprintf in those safe cases; and as proof of our
797 belief, we use sprintf in several gnulib modules. So this header
798 intentionally avoids adding a warning to sprintf except when
799 GNULIB_POSIXCHECK is defined. */
801 #if @GNULIB_SPRINTF_POSIX@
802 # if @REPLACE_SPRINTF@
803 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
804 # define sprintf rpl_sprintf
806 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
807 __attribute__ ((__format__ (__printf__, 2, 3)))
808 _GL_ARG_NONNULL ((1, 2)));
809 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
811 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
813 _GL_CXXALIASWARN (sprintf);
814 #elif defined GNULIB_POSIXCHECK
816 /* Assume sprintf is always declared. */
817 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
818 "use gnulib module sprintf-posix for portable "
822 #if @GNULIB_VASPRINTF@
823 /* Write formatted output to a string dynamically allocated with malloc().
824 If the memory allocation succeeds, store the address of the string in
825 *RESULT and return the number of resulting bytes, excluding the trailing
826 NUL. Upon memory allocation error, or some other error, return -1. */
827 # if @REPLACE_VASPRINTF@
828 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
829 # define asprintf rpl_asprintf
831 _GL_FUNCDECL_RPL (asprintf, int,
832 (char **result, const char *format, ...)
833 __attribute__ ((__format__ (__printf__, 2, 3)))
834 _GL_ARG_NONNULL ((1, 2)));
835 _GL_CXXALIAS_RPL (asprintf, int,
836 (char **result, const char *format, ...));
838 # if !@HAVE_VASPRINTF@
839 _GL_FUNCDECL_SYS (asprintf, int,
840 (char **result, const char *format, ...)
841 __attribute__ ((__format__ (__printf__, 2, 3)))
842 _GL_ARG_NONNULL ((1, 2)));
844 _GL_CXXALIAS_SYS (asprintf, int,
845 (char **result, const char *format, ...));
847 _GL_CXXALIASWARN (asprintf);
848 # if @REPLACE_VASPRINTF@
849 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
850 # define vasprintf rpl_vasprintf
852 _GL_FUNCDECL_RPL (vasprintf, int,
853 (char **result, const char *format, va_list args)
854 __attribute__ ((__format__ (__printf__, 2, 0)))
855 _GL_ARG_NONNULL ((1, 2)));
856 _GL_CXXALIAS_RPL (vasprintf, int,
857 (char **result, const char *format, va_list args));
859 # if !@HAVE_VASPRINTF@
860 _GL_FUNCDECL_SYS (vasprintf, int,
861 (char **result, const char *format, va_list args)
862 __attribute__ ((__format__ (__printf__, 2, 0)))
863 _GL_ARG_NONNULL ((1, 2)));
865 _GL_CXXALIAS_SYS (vasprintf, int,
866 (char **result, const char *format, va_list args));
868 _GL_CXXALIASWARN (vasprintf);
871 #if @GNULIB_VDPRINTF@
872 # if @REPLACE_VDPRINTF@
873 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
874 # define vdprintf rpl_vdprintf
876 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
877 __attribute__ ((__format__ (__printf__, 2, 0)))
878 _GL_ARG_NONNULL ((2)));
879 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
881 # if !@HAVE_VDPRINTF@
882 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
883 __attribute__ ((__format__ (__printf__, 2, 0)))
884 _GL_ARG_NONNULL ((2)));
886 _GL_CXXALIAS_SYS (vdprintf, int, (int fd, const char *format, va_list args));
888 _GL_CXXALIASWARN (vdprintf);
889 #elif defined GNULIB_POSIXCHECK
891 # if HAVE_RAW_DECL_VDPRINTF
892 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
893 "use gnulib module vdprintf for portability");
897 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
898 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
899 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
900 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
901 # define vfprintf rpl_vfprintf
903 # define GNULIB_overrides_vfprintf 1
904 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
905 __attribute__ ((__format__ (__printf__, 2, 0)))
906 _GL_ARG_NONNULL ((1, 2)));
907 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
909 _GL_CXXALIAS_SYS (vfprintf, int, (FILE *fp, const char *format, va_list args));
911 _GL_CXXALIASWARN (vfprintf);
913 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
914 # if !GNULIB_overrides_vfprintf
917 /* Assume vfprintf is always declared. */
918 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
919 "use gnulib module vfprintf-posix for portable "
923 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
924 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
925 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
926 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
927 # define vprintf rpl_vprintf
929 # define GNULIB_overrides_vprintf 1
930 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
931 __attribute__ ((__format__ (__printf__, 1, 0)))
932 _GL_ARG_NONNULL ((1)));
933 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
935 _GL_CXXALIAS_SYS (vprintf, int, (const char *format, va_list args));
937 _GL_CXXALIASWARN (vprintf);
939 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
940 # if !GNULIB_overrides_vprintf
943 /* Assume vprintf is always declared. */
944 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
945 "use gnulib module vprintf-posix for portable "
949 #if @GNULIB_VSNPRINTF@
950 # if @REPLACE_VSNPRINTF@
951 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
952 # define vsnprintf rpl_vsnprintf
954 _GL_FUNCDECL_RPL (vsnprintf, int,
955 (char *str, size_t size, const char *format, va_list args)
956 __attribute__ ((__format__ (__printf__, 3, 0)))
957 _GL_ARG_NONNULL ((3)));
958 _GL_CXXALIAS_RPL (vsnprintf, int,
959 (char *str, size_t size, const char *format, va_list args));
961 # if !@HAVE_DECL_VSNPRINTF@
962 _GL_FUNCDECL_SYS (vsnprintf, int,
963 (char *str, size_t size, const char *format, va_list args)
964 __attribute__ ((__format__ (__printf__, 3, 0)))
965 _GL_ARG_NONNULL ((3)));
967 _GL_CXXALIAS_SYS (vsnprintf, int,
968 (char *str, size_t size, const char *format, va_list args));
970 _GL_CXXALIASWARN (vsnprintf);
971 #elif defined GNULIB_POSIXCHECK
973 # if HAVE_RAW_DECL_VSNPRINTF
974 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
975 "use gnulib module vsnprintf for portability");
979 #if @GNULIB_VSPRINTF_POSIX@
980 # if @REPLACE_VSPRINTF@
981 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
982 # define vsprintf rpl_vsprintf
984 _GL_FUNCDECL_RPL (vsprintf, int,
985 (char *str, const char *format, va_list args)
986 __attribute__ ((__format__ (__printf__, 2, 0)))
987 _GL_ARG_NONNULL ((1, 2)));
988 _GL_CXXALIAS_RPL (vsprintf, int,
989 (char *str, const char *format, va_list args));
991 _GL_CXXALIAS_SYS (vsprintf, int,
992 (char *str, const char *format, va_list args));
994 _GL_CXXALIASWARN (vsprintf);
995 #elif defined GNULIB_POSIXCHECK
997 /* Assume vsprintf is always declared. */
998 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
999 "use gnulib module vsprintf-posix for portable "
1000 "POSIX compliance");
1004 #endif /* _GL_STDIO_H */
1005 #endif /* _GL_STDIO_H */