1 /* A GNU-like <stdio.h>.
3 Copyright (C) 2004, 2007-2011 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@
24 #if defined __need_FILE || defined __need___FILE || defined _GL_ALREADY_INCLUDING_STDIO_H
25 /* Special invocation convention:
26 - Inside glibc header files.
27 - On OSF/1 5.1 we have a sequence of nested includes
28 <stdio.h> -> <getopt.h> -> <ctype.h> -> <sys/localedef.h> ->
29 <sys/lc_core.h> -> <nl_types.h> -> <mesg.h> -> <stdio.h>.
30 In this situation, the functions are not yet declared, therefore we cannot
31 provide the C++ aliases. */
33 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
36 /* Normal invocation convention. */
40 #define _GL_ALREADY_INCLUDING_STDIO_H
42 /* The include_next requires a split double-inclusion guard. */
43 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
45 #undef _GL_ALREADY_INCLUDING_STDIO_H
50 /* Get va_list. Needed on many systems, including glibc 2.8. */
55 /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8
57 #include <sys/types.h>
60 /* The __attribute__ feature is available in gcc versions 2.5 and later.
61 The __-protected variants of the attributes 'format' and 'printf' are
62 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
63 We enable __attribute__ only if these are supported too, because
64 gnulib and libintl do '#define printf __printf__' when they override
65 the 'printf' function. */
66 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
67 # define __attribute__(Spec) /* empty */
71 /* Solaris 10 declares renameat in <unistd.h>, not in <stdio.h>. */
72 /* But in any case avoid namespace pollution on glibc systems. */
73 #if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __sun \
74 && ! defined __GLIBC__
79 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
81 /* The definition of _GL_ARG_NONNULL is copied here. */
83 /* The definition of _GL_WARN_ON_USE is copied here. */
85 /* Macros for stringification. */
86 #define _GL_STDIO_STRINGIZE(token) #token
87 #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
91 # if @REPLACE_DPRINTF@
92 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
93 # define dprintf rpl_dprintf
95 _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
96 __attribute__ ((__format__ (__printf__, 2, 3)))
97 _GL_ARG_NONNULL ((2)));
98 _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
101 _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
102 __attribute__ ((__format__ (__printf__, 2, 3)))
103 _GL_ARG_NONNULL ((2)));
105 _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
107 _GL_CXXALIASWARN (dprintf);
108 #elif defined GNULIB_POSIXCHECK
110 # if HAVE_RAW_DECL_DPRINTF
111 _GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
112 "use gnulib module dprintf for portability");
117 /* Close STREAM and its underlying file descriptor. */
118 # if @REPLACE_FCLOSE@
119 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
120 # define fclose rpl_fclose
122 _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
123 _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
125 _GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
127 _GL_CXXALIASWARN (fclose);
128 #elif defined GNULIB_POSIXCHECK
130 /* Assume fclose is always declared. */
131 _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
132 "use gnulib module fclose for portable POSIX compliance");
136 /* Flush all pending data on STREAM according to POSIX rules. Both
137 output and seekable input streams are supported.
138 Note! LOSS OF DATA can occur if fflush is applied on an input stream
139 that is _not_seekable_ or on an update stream that is _not_seekable_
140 and in which the most recent operation was input. Seekability can
141 be tested with lseek(fileno(fp),0,SEEK_CUR). */
142 # if @REPLACE_FFLUSH@
143 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
144 # define fflush rpl_fflush
146 _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
147 _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
149 _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
151 _GL_CXXALIASWARN (fflush);
152 #elif defined GNULIB_POSIXCHECK
154 /* Assume fflush is always declared. */
155 _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
156 "use gnulib module fflush for portable POSIX compliance");
159 /* It is very rare that the developer ever has full control of stdin,
160 so any use of gets warrants an unconditional warning. Assume it is
161 always declared, since it is required by C89. */
163 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
167 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169 # define fopen rpl_fopen
171 _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
172 _GL_ARG_NONNULL ((1, 2)));
173 _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
175 _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
177 _GL_CXXALIASWARN (fopen);
178 #elif defined GNULIB_POSIXCHECK
180 /* Assume fopen is always declared. */
181 _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
182 "use gnulib module fopen for portability");
185 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
186 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
187 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
188 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
189 # define fprintf rpl_fprintf
191 # define GNULIB_overrides_fprintf 1
192 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
193 __attribute__ ((__format__ (__printf__, 2, 3)))
194 _GL_ARG_NONNULL ((1, 2)));
195 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
197 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
199 _GL_CXXALIASWARN (fprintf);
201 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
202 # if !GNULIB_overrides_fprintf
205 /* Assume fprintf is always declared. */
206 _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
207 "use gnulib module fprintf-posix for portable "
212 /* Discard all pending buffered I/O data on STREAM.
213 STREAM must not be wide-character oriented.
214 When discarding pending output, the file position is set back to where it
215 was before the write calls. When discarding pending input, the file
216 position is advanced to match the end of the previously read input.
217 Return 0 if successful. Upon error, return -1 and set errno. */
218 # if @REPLACE_FPURGE@
219 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
220 # define fpurge rpl_fpurge
222 _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
223 _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
225 # if !@HAVE_DECL_FPURGE@
226 _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
228 _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
230 _GL_CXXALIASWARN (fpurge);
231 #elif defined GNULIB_POSIXCHECK
233 # if HAVE_RAW_DECL_FPURGE
234 _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
235 "use gnulib module fpurge for portability");
240 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
241 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
243 # define fputc rpl_fputc
245 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
246 _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
248 _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
250 _GL_CXXALIASWARN (fputc);
254 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
255 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
257 # define fputs rpl_fputs
259 _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
260 _GL_ARG_NONNULL ((1, 2)));
261 _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
263 _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
265 _GL_CXXALIASWARN (fputs);
269 # if @REPLACE_FREOPEN@
270 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
272 # define freopen rpl_freopen
274 _GL_FUNCDECL_RPL (freopen, FILE *,
275 (const char *filename, const char *mode, FILE *stream)
276 _GL_ARG_NONNULL ((2, 3)));
277 _GL_CXXALIAS_RPL (freopen, FILE *,
278 (const char *filename, const char *mode, FILE *stream));
280 _GL_CXXALIAS_SYS (freopen, FILE *,
281 (const char *filename, const char *mode, FILE *stream));
283 _GL_CXXALIASWARN (freopen);
284 #elif defined GNULIB_POSIXCHECK
286 /* Assume freopen is always declared. */
287 _GL_WARN_ON_USE (freopen,
288 "freopen on Win32 platforms is not POSIX compatible - "
289 "use gnulib module freopen for portability");
293 /* Set up the following warnings, based on which modules are in use.
294 GNU Coding Standards discourage the use of fseek, since it imposes
295 an arbitrary limitation on some 32-bit hosts. Remember that the
296 fseek module depends on the fseeko module, so we only have three
299 1. The developer is not using either module. Issue a warning under
300 GNULIB_POSIXCHECK for both functions, to remind them that both
301 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
302 impact on this warning.
304 2. The developer is using both modules. They may be unaware of the
305 arbitrary limitations of fseek, so issue a warning under
306 GNULIB_POSIXCHECK. On the other hand, they may be using both
307 modules intentionally, so the developer can define
308 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
309 is safe, to silence the warning.
311 3. The developer is using the fseeko module, but not fseek. Gnulib
312 guarantees that fseek will still work around platform bugs in that
313 case, but we presume that the developer is aware of the pitfalls of
314 fseek and was trying to avoid it, so issue a warning even when
315 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
316 defined to silence the warning in particular compilation units.
317 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
318 fseek gets defined as a macro, it is recommended that the developer
319 uses the fseek module, even if he is not calling the fseek function.
321 Most gnulib clients that perform stream operations should fall into
325 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
326 # define _GL_FSEEK_WARN /* Category 2, above. */
330 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
332 # define fseek rpl_fseek
334 _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
335 _GL_ARG_NONNULL ((1)));
336 _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
338 _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
340 _GL_CXXALIASWARN (fseek);
344 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
345 # define _GL_FSEEK_WARN /* Category 3, above. */
348 # if @REPLACE_FSEEKO@
349 /* Provide an fseeko function that is aware of a preceding fflush(), and which
351 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
353 # define fseeko rpl_fseeko
355 _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
356 _GL_ARG_NONNULL ((1)));
357 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
359 # if ! @HAVE_DECL_FSEEKO@
360 _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
361 _GL_ARG_NONNULL ((1)));
363 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
365 _GL_CXXALIASWARN (fseeko);
366 # if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
367 /* Provide an fseek function that is consistent with fseeko. */
368 /* In order to avoid that fseek gets defined as a macro here, the
369 developer can request the 'fseek' module. */
370 # if !GNULIB_defined_fseek_function
372 # define fseek rpl_fseek
373 static inline int _GL_ARG_NONNULL ((1))
374 rpl_fseek (FILE *fp, long offset, int whence)
376 # if @REPLACE_FSEEKO@
377 return rpl_fseeko (fp, offset, whence);
379 return fseeko (fp, offset, whence);
382 # define GNULIB_defined_fseek_function 1
385 #elif defined GNULIB_POSIXCHECK
386 # define _GL_FSEEK_WARN /* Category 1, above. */
389 # if HAVE_RAW_DECL_FSEEKO
390 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
391 "use gnulib module fseeko for portability");
395 #ifdef _GL_FSEEK_WARN
396 # undef _GL_FSEEK_WARN
397 /* Here, either fseek is undefined (but C89 guarantees that it is
398 declared), or it is defined as rpl_fseek (declared above). */
399 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
400 "on 32-bit platforms - "
401 "use fseeko function for handling of large files");
405 /* ftell, ftello. See the comments on fseek/fseeko. */
408 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
409 # define _GL_FTELL_WARN /* Category 2, above. */
413 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
415 # define ftell rpl_ftell
417 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
418 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
420 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
422 _GL_CXXALIASWARN (ftell);
426 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
427 # define _GL_FTELL_WARN /* Category 3, above. */
430 # if @REPLACE_FTELLO@
431 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
433 # define ftello rpl_ftello
435 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
436 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
438 # if ! @HAVE_DECL_FTELLO@
439 _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
441 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
443 _GL_CXXALIASWARN (ftello);
444 # if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
445 /* Provide an ftell function that is consistent with ftello. */
446 /* In order to avoid that ftell gets defined as a macro here, the
447 developer can request the 'ftell' module. */
448 # if !GNULIB_defined_ftell_function
450 # define ftell rpl_ftell
451 static inline long _GL_ARG_NONNULL ((1))
454 # if @REPLACE_FTELLO@
455 return rpl_ftello (f);
460 # define GNULIB_defined_ftell_function 1
463 #elif defined GNULIB_POSIXCHECK
464 # define _GL_FTELL_WARN /* Category 1, above. */
467 # if HAVE_RAW_DECL_FTELLO
468 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
469 "use gnulib module ftello for portability");
473 #ifdef _GL_FTELL_WARN
474 # undef _GL_FTELL_WARN
475 /* Here, either ftell is undefined (but C89 guarantees that it is
476 declared), or it is defined as rpl_ftell (declared above). */
477 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
478 "on 32-bit platforms - "
479 "use ftello function for handling of large files");
484 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
485 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
487 # define fwrite rpl_fwrite
489 _GL_FUNCDECL_RPL (fwrite, size_t,
490 (const void *ptr, size_t s, size_t n, FILE *stream)
491 _GL_ARG_NONNULL ((1, 4)));
492 _GL_CXXALIAS_RPL (fwrite, size_t,
493 (const void *ptr, size_t s, size_t n, FILE *stream));
495 _GL_CXXALIAS_SYS (fwrite, size_t,
496 (const void *ptr, size_t s, size_t n, FILE *stream));
498 _GL_CXXALIASWARN (fwrite);
501 #if @GNULIB_GETDELIM@
502 /* Read input, up to (and including) the next occurrence of DELIMITER, from
503 STREAM, store it in *LINEPTR (and NUL-terminate it).
504 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
505 bytes of space. It is realloc'd as necessary.
506 Return the number of bytes read and stored at *LINEPTR (not including the
507 NUL terminator), or -1 on error or EOF. */
508 # if @REPLACE_GETDELIM@
509 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
511 # define getdelim rpl_getdelim
513 _GL_FUNCDECL_RPL (getdelim, ssize_t,
514 (char **lineptr, size_t *linesize, int delimiter,
516 _GL_ARG_NONNULL ((1, 2, 4)));
517 _GL_CXXALIAS_RPL (getdelim, ssize_t,
518 (char **lineptr, size_t *linesize, int delimiter,
521 # if !@HAVE_DECL_GETDELIM@
522 _GL_FUNCDECL_SYS (getdelim, ssize_t,
523 (char **lineptr, size_t *linesize, int delimiter,
525 _GL_ARG_NONNULL ((1, 2, 4)));
527 _GL_CXXALIAS_SYS (getdelim, ssize_t,
528 (char **lineptr, size_t *linesize, int delimiter,
531 _GL_CXXALIASWARN (getdelim);
532 #elif defined GNULIB_POSIXCHECK
534 # if HAVE_RAW_DECL_GETDELIM
535 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
536 "use gnulib module getdelim for portability");
541 /* Read a line, up to (and including) the next newline, from STREAM, store it
542 in *LINEPTR (and NUL-terminate it).
543 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
544 bytes of space. It is realloc'd as necessary.
545 Return the number of bytes read and stored at *LINEPTR (not including the
546 NUL terminator), or -1 on error or EOF. */
547 # if @REPLACE_GETLINE@
548 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
550 # define getline rpl_getline
552 _GL_FUNCDECL_RPL (getline, ssize_t,
553 (char **lineptr, size_t *linesize, FILE *stream)
554 _GL_ARG_NONNULL ((1, 2, 3)));
555 _GL_CXXALIAS_RPL (getline, ssize_t,
556 (char **lineptr, size_t *linesize, FILE *stream));
558 # if !@HAVE_DECL_GETLINE@
559 _GL_FUNCDECL_SYS (getline, ssize_t,
560 (char **lineptr, size_t *linesize, FILE *stream)
561 _GL_ARG_NONNULL ((1, 2, 3)));
563 _GL_CXXALIAS_SYS (getline, ssize_t,
564 (char **lineptr, size_t *linesize, FILE *stream));
566 # if @HAVE_DECL_GETLINE@
567 _GL_CXXALIASWARN (getline);
569 #elif defined GNULIB_POSIXCHECK
571 # if HAVE_RAW_DECL_GETLINE
572 _GL_WARN_ON_USE (getline, "getline is unportable - "
573 "use gnulib module getline for portability");
577 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
579 /* Grow an obstack with formatted output. Return the number of
580 bytes added to OBS. No trailing nul byte is added, and the
581 object should be closed with obstack_finish before use. Upon
582 memory allocation error, call obstack_alloc_failed_handler. Upon
583 other error, return -1. */
584 # if @REPLACE_OBSTACK_PRINTF@
585 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
586 # define obstack_printf rpl_obstack_printf
588 _GL_FUNCDECL_RPL (obstack_printf, int,
589 (struct obstack *obs, const char *format, ...)
590 __attribute__ ((__format__ (__printf__, 2, 3)))
591 _GL_ARG_NONNULL ((1, 2)));
592 _GL_CXXALIAS_RPL (obstack_printf, int,
593 (struct obstack *obs, const char *format, ...));
595 # if !@HAVE_DECL_OBSTACK_PRINTF@
596 _GL_FUNCDECL_SYS (obstack_printf, int,
597 (struct obstack *obs, const char *format, ...)
598 __attribute__ ((__format__ (__printf__, 2, 3)))
599 _GL_ARG_NONNULL ((1, 2)));
601 _GL_CXXALIAS_SYS (obstack_printf, int,
602 (struct obstack *obs, const char *format, ...));
604 _GL_CXXALIASWARN (obstack_printf);
605 # if @REPLACE_OBSTACK_PRINTF@
606 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
607 # define obstack_vprintf rpl_obstack_vprintf
609 _GL_FUNCDECL_RPL (obstack_vprintf, int,
610 (struct obstack *obs, const char *format, va_list args)
611 __attribute__ ((__format__ (__printf__, 2, 0)))
612 _GL_ARG_NONNULL ((1, 2)));
613 _GL_CXXALIAS_RPL (obstack_vprintf, int,
614 (struct obstack *obs, const char *format, va_list args));
616 # if !@HAVE_DECL_OBSTACK_PRINTF@
617 _GL_FUNCDECL_SYS (obstack_vprintf, int,
618 (struct obstack *obs, const char *format, va_list args)
619 __attribute__ ((__format__ (__printf__, 2, 0)))
620 _GL_ARG_NONNULL ((1, 2)));
622 _GL_CXXALIAS_SYS (obstack_vprintf, int,
623 (struct obstack *obs, const char *format, va_list args));
625 _GL_CXXALIASWARN (obstack_vprintf);
629 /* Print a message to standard error, describing the value of ERRNO,
630 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
631 and terminated with a newline. */
632 # if @REPLACE_PERROR@
633 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
634 # define perror rpl_perror
636 _GL_FUNCDECL_RPL (perror, void, (const char *string));
637 _GL_CXXALIAS_RPL (perror, void, (const char *string));
639 _GL_CXXALIAS_SYS (perror, void, (const char *string));
641 _GL_CXXALIASWARN (perror);
642 #elif defined GNULIB_POSIXCHECK
644 /* Assume perror is always declared. */
645 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
646 "use gnulib module perror for portability");
651 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
653 # define popen rpl_popen
655 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
656 _GL_ARG_NONNULL ((1, 2)));
657 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
659 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
661 _GL_CXXALIASWARN (popen);
662 #elif defined GNULIB_POSIXCHECK
664 # if HAVE_RAW_DECL_POPEN
665 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
666 "use gnulib module popen or pipe for more portability");
670 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
671 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
672 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
673 # if defined __GNUC__
674 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
675 /* Don't break __attribute__((format(printf,M,N))). */
676 # define printf __printf__
678 _GL_FUNCDECL_RPL_1 (__printf__, int,
679 (const char *format, ...)
680 __asm__ (@ASM_SYMBOL_PREFIX@
681 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
682 __attribute__ ((__format__ (__printf__, 1, 2)))
683 _GL_ARG_NONNULL ((1)));
684 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # define printf rpl_printf
689 _GL_FUNCDECL_RPL (printf, int,
690 (const char *format, ...)
691 __attribute__ ((__format__ (__printf__, 1, 2)))
692 _GL_ARG_NONNULL ((1)));
693 _GL_CXXALIAS_RPL (printf, int, (const char *format, ...));
695 # define GNULIB_overrides_printf 1
697 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
699 _GL_CXXALIASWARN (printf);
701 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
702 # if !GNULIB_overrides_printf
705 /* Assume printf is always declared. */
706 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
707 "use gnulib module printf-posix for portable "
712 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715 # define putc rpl_fputc
717 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
718 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
720 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
722 _GL_CXXALIASWARN (putc);
726 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
727 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
729 # define putchar rpl_putchar
731 _GL_FUNCDECL_RPL (putchar, int, (int c));
732 _GL_CXXALIAS_RPL (putchar, int, (int c));
734 _GL_CXXALIAS_SYS (putchar, int, (int c));
736 _GL_CXXALIASWARN (putchar);
740 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
741 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
743 # define puts rpl_puts
745 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
746 _GL_CXXALIAS_RPL (puts, int, (const char *string));
748 _GL_CXXALIAS_SYS (puts, int, (const char *string));
750 _GL_CXXALIASWARN (puts);
754 # if @REPLACE_REMOVE@
755 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
757 # define remove rpl_remove
759 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
760 _GL_CXXALIAS_RPL (remove, int, (const char *name));
762 _GL_CXXALIAS_SYS (remove, int, (const char *name));
764 _GL_CXXALIASWARN (remove);
765 #elif defined GNULIB_POSIXCHECK
767 /* Assume remove is always declared. */
768 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
769 "use gnulib module remove for more portability");
773 # if @REPLACE_RENAME@
774 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
776 # define rename rpl_rename
778 _GL_FUNCDECL_RPL (rename, int,
779 (const char *old_filename, const char *new_filename)
780 _GL_ARG_NONNULL ((1, 2)));
781 _GL_CXXALIAS_RPL (rename, int,
782 (const char *old_filename, const char *new_filename));
784 _GL_CXXALIAS_SYS (rename, int,
785 (const char *old_filename, const char *new_filename));
787 _GL_CXXALIASWARN (rename);
788 #elif defined GNULIB_POSIXCHECK
790 /* Assume rename is always declared. */
791 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
792 "use gnulib module rename for more portability");
795 #if @GNULIB_RENAMEAT@
796 # if @REPLACE_RENAMEAT@
797 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
799 # define renameat rpl_renameat
801 _GL_FUNCDECL_RPL (renameat, int,
802 (int fd1, char const *file1, int fd2, char const *file2)
803 _GL_ARG_NONNULL ((2, 4)));
804 _GL_CXXALIAS_RPL (renameat, int,
805 (int fd1, char const *file1, int fd2, char const *file2));
807 # if !@HAVE_RENAMEAT@
808 _GL_FUNCDECL_SYS (renameat, int,
809 (int fd1, char const *file1, int fd2, char const *file2)
810 _GL_ARG_NONNULL ((2, 4)));
812 _GL_CXXALIAS_SYS (renameat, int,
813 (int fd1, char const *file1, int fd2, char const *file2));
815 _GL_CXXALIASWARN (renameat);
816 #elif defined GNULIB_POSIXCHECK
818 # if HAVE_RAW_DECL_RENAMEAT
819 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
820 "use gnulib module renameat for portability");
824 #if @GNULIB_SNPRINTF@
825 # if @REPLACE_SNPRINTF@
826 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
827 # define snprintf rpl_snprintf
829 _GL_FUNCDECL_RPL (snprintf, int,
830 (char *str, size_t size, const char *format, ...)
831 __attribute__ ((__format__ (__printf__, 3, 4)))
832 _GL_ARG_NONNULL ((3)));
833 _GL_CXXALIAS_RPL (snprintf, int,
834 (char *str, size_t size, const char *format, ...));
836 # if !@HAVE_DECL_SNPRINTF@
837 _GL_FUNCDECL_SYS (snprintf, int,
838 (char *str, size_t size, const char *format, ...)
839 __attribute__ ((__format__ (__printf__, 3, 4)))
840 _GL_ARG_NONNULL ((3)));
842 _GL_CXXALIAS_SYS (snprintf, int,
843 (char *str, size_t size, const char *format, ...));
845 _GL_CXXALIASWARN (snprintf);
846 #elif defined GNULIB_POSIXCHECK
848 # if HAVE_RAW_DECL_SNPRINTF
849 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
850 "use gnulib module snprintf for portability");
854 /* Some people would argue that sprintf should be handled like gets
855 (for example, OpenBSD issues a link warning for both functions),
856 since both can cause security holes due to buffer overruns.
857 However, we believe that sprintf can be used safely, and is more
858 efficient than snprintf in those safe cases; and as proof of our
859 belief, we use sprintf in several gnulib modules. So this header
860 intentionally avoids adding a warning to sprintf except when
861 GNULIB_POSIXCHECK is defined. */
863 #if @GNULIB_SPRINTF_POSIX@
864 # if @REPLACE_SPRINTF@
865 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
866 # define sprintf rpl_sprintf
868 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
869 __attribute__ ((__format__ (__printf__, 2, 3)))
870 _GL_ARG_NONNULL ((1, 2)));
871 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
873 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
875 _GL_CXXALIASWARN (sprintf);
876 #elif defined GNULIB_POSIXCHECK
878 /* Assume sprintf is always declared. */
879 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
880 "use gnulib module sprintf-posix for portable "
885 # if @REPLACE_TMPFILE@
886 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
887 # define tmpfile rpl_tmpfile
889 _GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
890 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
892 _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
894 _GL_CXXALIASWARN (tmpfile);
895 #elif defined GNULIB_POSIXCHECK
897 # if HAVE_RAW_DECL_TMPFILE
898 _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
899 "use gnulib module tmpfile for portability");
903 #if @GNULIB_VASPRINTF@
904 /* Write formatted output to a string dynamically allocated with malloc().
905 If the memory allocation succeeds, store the address of the string in
906 *RESULT and return the number of resulting bytes, excluding the trailing
907 NUL. Upon memory allocation error, or some other error, return -1. */
908 # if @REPLACE_VASPRINTF@
909 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
910 # define asprintf rpl_asprintf
912 _GL_FUNCDECL_RPL (asprintf, int,
913 (char **result, const char *format, ...)
914 __attribute__ ((__format__ (__printf__, 2, 3)))
915 _GL_ARG_NONNULL ((1, 2)));
916 _GL_CXXALIAS_RPL (asprintf, int,
917 (char **result, const char *format, ...));
919 # if !@HAVE_VASPRINTF@
920 _GL_FUNCDECL_SYS (asprintf, int,
921 (char **result, const char *format, ...)
922 __attribute__ ((__format__ (__printf__, 2, 3)))
923 _GL_ARG_NONNULL ((1, 2)));
925 _GL_CXXALIAS_SYS (asprintf, int,
926 (char **result, const char *format, ...));
928 _GL_CXXALIASWARN (asprintf);
929 # if @REPLACE_VASPRINTF@
930 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
931 # define vasprintf rpl_vasprintf
933 _GL_FUNCDECL_RPL (vasprintf, int,
934 (char **result, const char *format, va_list args)
935 __attribute__ ((__format__ (__printf__, 2, 0)))
936 _GL_ARG_NONNULL ((1, 2)));
937 _GL_CXXALIAS_RPL (vasprintf, int,
938 (char **result, const char *format, va_list args));
940 # if !@HAVE_VASPRINTF@
941 _GL_FUNCDECL_SYS (vasprintf, int,
942 (char **result, const char *format, va_list args)
943 __attribute__ ((__format__ (__printf__, 2, 0)))
944 _GL_ARG_NONNULL ((1, 2)));
946 _GL_CXXALIAS_SYS (vasprintf, int,
947 (char **result, const char *format, va_list args));
949 _GL_CXXALIASWARN (vasprintf);
952 #if @GNULIB_VDPRINTF@
953 # if @REPLACE_VDPRINTF@
954 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
955 # define vdprintf rpl_vdprintf
957 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
958 __attribute__ ((__format__ (__printf__, 2, 0)))
959 _GL_ARG_NONNULL ((2)));
960 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
962 # if !@HAVE_VDPRINTF@
963 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
964 __attribute__ ((__format__ (__printf__, 2, 0)))
965 _GL_ARG_NONNULL ((2)));
967 /* Need to cast, because on Solaris, the third parameter will likely be
969 _GL_CXXALIAS_SYS_CAST (vdprintf, int,
970 (int fd, const char *format, va_list args));
972 _GL_CXXALIASWARN (vdprintf);
973 #elif defined GNULIB_POSIXCHECK
975 # if HAVE_RAW_DECL_VDPRINTF
976 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
977 "use gnulib module vdprintf for portability");
981 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
982 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
983 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
984 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
985 # define vfprintf rpl_vfprintf
987 # define GNULIB_overrides_vfprintf 1
988 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
989 __attribute__ ((__format__ (__printf__, 2, 0)))
990 _GL_ARG_NONNULL ((1, 2)));
991 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
993 /* Need to cast, because on Solaris, the third parameter is
995 and GCC's fixincludes did not change this to __gnuc_va_list. */
996 _GL_CXXALIAS_SYS_CAST (vfprintf, int,
997 (FILE *fp, const char *format, va_list args));
999 _GL_CXXALIASWARN (vfprintf);
1001 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1002 # if !GNULIB_overrides_vfprintf
1005 /* Assume vfprintf is always declared. */
1006 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
1007 "use gnulib module vfprintf-posix for portable "
1008 "POSIX compliance");
1011 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
1012 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
1013 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
1014 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1015 # define vprintf rpl_vprintf
1017 # define GNULIB_overrides_vprintf 1
1018 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
1019 __attribute__ ((__format__ (__printf__, 1, 0)))
1020 _GL_ARG_NONNULL ((1)));
1021 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
1023 /* Need to cast, because on Solaris, the second parameter is
1025 and GCC's fixincludes did not change this to __gnuc_va_list. */
1026 _GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
1028 _GL_CXXALIASWARN (vprintf);
1030 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1031 # if !GNULIB_overrides_vprintf
1034 /* Assume vprintf is always declared. */
1035 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1036 "use gnulib module vprintf-posix for portable "
1037 "POSIX compliance");
1040 #if @GNULIB_VSNPRINTF@
1041 # if @REPLACE_VSNPRINTF@
1042 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1043 # define vsnprintf rpl_vsnprintf
1045 _GL_FUNCDECL_RPL (vsnprintf, int,
1046 (char *str, size_t size, const char *format, va_list args)
1047 __attribute__ ((__format__ (__printf__, 3, 0)))
1048 _GL_ARG_NONNULL ((3)));
1049 _GL_CXXALIAS_RPL (vsnprintf, int,
1050 (char *str, size_t size, const char *format, va_list args));
1052 # if !@HAVE_DECL_VSNPRINTF@
1053 _GL_FUNCDECL_SYS (vsnprintf, int,
1054 (char *str, size_t size, const char *format, va_list args)
1055 __attribute__ ((__format__ (__printf__, 3, 0)))
1056 _GL_ARG_NONNULL ((3)));
1058 _GL_CXXALIAS_SYS (vsnprintf, int,
1059 (char *str, size_t size, const char *format, va_list args));
1061 _GL_CXXALIASWARN (vsnprintf);
1062 #elif defined GNULIB_POSIXCHECK
1064 # if HAVE_RAW_DECL_VSNPRINTF
1065 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1066 "use gnulib module vsnprintf for portability");
1070 #if @GNULIB_VSPRINTF_POSIX@
1071 # if @REPLACE_VSPRINTF@
1072 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1073 # define vsprintf rpl_vsprintf
1075 _GL_FUNCDECL_RPL (vsprintf, int,
1076 (char *str, const char *format, va_list args)
1077 __attribute__ ((__format__ (__printf__, 2, 0)))
1078 _GL_ARG_NONNULL ((1, 2)));
1079 _GL_CXXALIAS_RPL (vsprintf, int,
1080 (char *str, const char *format, va_list args));
1082 /* Need to cast, because on Solaris, the third parameter is
1084 and GCC's fixincludes did not change this to __gnuc_va_list. */
1085 _GL_CXXALIAS_SYS_CAST (vsprintf, int,
1086 (char *str, const char *format, va_list args));
1088 _GL_CXXALIASWARN (vsprintf);
1089 #elif defined GNULIB_POSIXCHECK
1091 /* Assume vsprintf is always declared. */
1092 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1093 "use gnulib module vsprintf-posix for portable "
1094 "POSIX compliance");
1098 #endif /* _GL_STDIO_H */
1099 #endif /* _GL_STDIO_H */