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. */
66 /* Macros for stringification. */
67 #define _GL_STDIO_STRINGIZE(token) #token
68 #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
72 # if @REPLACE_DPRINTF@
73 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
74 # define dprintf rpl_dprintf
76 _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
77 __attribute__ ((__format__ (__printf__, 2, 3)))
78 _GL_ARG_NONNULL ((2)));
79 _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
82 _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
83 __attribute__ ((__format__ (__printf__, 2, 3)))
84 _GL_ARG_NONNULL ((2)));
86 _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
88 _GL_CXXALIASWARN (dprintf);
89 #elif defined GNULIB_POSIXCHECK
91 # if HAVE_RAW_DECL_DPRINTF
92 _GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
93 "use gnulib module dprintf for portability");
98 /* Close STREAM and its underlying file descriptor. */
100 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
101 # define fclose rpl_fclose
103 _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
104 _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
106 _GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
108 _GL_CXXALIASWARN (fclose);
109 #elif defined GNULIB_POSIXCHECK
111 /* Assume fclose is always declared. */
112 _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
113 "use gnulib module fclose for portable POSIX compliance");
117 /* Flush all pending data on STREAM according to POSIX rules. Both
118 output and seekable input streams are supported.
119 Note! LOSS OF DATA can occur if fflush is applied on an input stream
120 that is _not_seekable_ or on an update stream that is _not_seekable_
121 and in which the most recent operation was input. Seekability can
122 be tested with lseek(fileno(fp),0,SEEK_CUR). */
123 # if @REPLACE_FFLUSH@
124 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
125 # define fflush rpl_fflush
127 _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
128 _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
130 _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
132 _GL_CXXALIASWARN (fflush);
133 #elif defined GNULIB_POSIXCHECK
135 /* Assume fflush is always declared. */
136 _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
137 "use gnulib module fflush for portable POSIX compliance");
140 /* It is very rare that the developer ever has full control of stdin,
141 so any use of gets warrants an unconditional warning. Assume it is
142 always declared, since it is required by C89. */
144 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
148 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
150 # define fopen rpl_fopen
152 _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
153 _GL_ARG_NONNULL ((1, 2)));
154 _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
156 _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
158 _GL_CXXALIASWARN (fopen);
159 #elif defined GNULIB_POSIXCHECK
161 /* Assume fopen is always declared. */
162 _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
163 "use gnulib module fopen for portability");
166 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
167 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
168 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
169 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170 # define fprintf rpl_fprintf
172 # define GNULIB_overrides_fprintf 1
173 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
174 __attribute__ ((__format__ (__printf__, 2, 3)))
175 _GL_ARG_NONNULL ((1, 2)));
176 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
178 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
180 _GL_CXXALIASWARN (fprintf);
182 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
183 # if !GNULIB_overrides_fprintf
186 /* Assume fprintf is always declared. */
187 _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
188 "use gnulib module fprintf-posix for portable "
193 /* Discard all pending buffered I/O data on STREAM.
194 STREAM must not be wide-character oriented.
195 When discarding pending output, the file position is set back to where it
196 was before the write calls. When discarding pending input, the file
197 position is advanced to match the end of the previously read input.
198 Return 0 if successful. Upon error, return -1 and set errno. */
199 # if @REPLACE_FPURGE@
200 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
201 # define fpurge rpl_fpurge
203 _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
204 _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
206 # if !@HAVE_DECL_FPURGE@
207 _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
209 _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
211 _GL_CXXALIASWARN (fpurge);
212 #elif defined GNULIB_POSIXCHECK
214 # if HAVE_RAW_DECL_FPURGE
215 _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
216 "use gnulib module fpurge for portability");
221 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define fputc rpl_fputc
226 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
227 _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
229 _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
231 _GL_CXXALIASWARN (fputc);
235 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
236 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
238 # define fputs rpl_fputs
240 _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
241 _GL_ARG_NONNULL ((1, 2)));
242 _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
244 _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
246 _GL_CXXALIASWARN (fputs);
250 # if @REPLACE_FREOPEN@
251 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
253 # define freopen rpl_freopen
255 _GL_FUNCDECL_RPL (freopen, FILE *,
256 (const char *filename, const char *mode, FILE *stream)
257 _GL_ARG_NONNULL ((2, 3)));
258 _GL_CXXALIAS_RPL (freopen, FILE *,
259 (const char *filename, const char *mode, FILE *stream));
261 _GL_CXXALIAS_SYS (freopen, FILE *,
262 (const char *filename, const char *mode, FILE *stream));
264 _GL_CXXALIASWARN (freopen);
265 #elif defined GNULIB_POSIXCHECK
267 /* Assume freopen is always declared. */
268 _GL_WARN_ON_USE (freopen,
269 "freopen on Win32 platforms is not POSIX compatible - "
270 "use gnulib module freopen for portability");
274 /* Set up the following warnings, based on which modules are in use.
275 GNU Coding Standards discourage the use of fseek, since it imposes
276 an arbitrary limitation on some 32-bit hosts. Remember that the
277 fseek module depends on the fseeko module, so we only have three
280 1. The developer is not using either module. Issue a warning under
281 GNULIB_POSIXCHECK for both functions, to remind them that both
282 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
283 impact on this warning.
285 2. The developer is using both modules. They may be unaware of the
286 arbitrary limitations of fseek, so issue a warning under
287 GNULIB_POSIXCHECK. On the other hand, they may be using both
288 modules intentionally, so the developer can define
289 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
290 is safe, to silence the warning.
292 3. The developer is using the fseeko module, but not fseek. Gnulib
293 guarantees that fseek will still work around platform bugs in that
294 case, but we presume that the developer is aware of the pitfalls of
295 fseek and was trying to avoid it, so issue a warning even when
296 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
297 defined to silence the warning in particular compilation units.
298 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
299 fseek gets defined as a macro, it is recommended that the developer
300 uses the fseek module, even if he is not calling the fseek function.
302 Most gnulib clients that perform stream operations should fall into
306 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
307 # define _GL_FSEEK_WARN /* Category 2, above. */
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
313 # define fseek rpl_fseek
315 _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
316 _GL_ARG_NONNULL ((1)));
317 _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
319 _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
321 _GL_CXXALIASWARN (fseek);
325 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
326 # define _GL_FSEEK_WARN /* Category 3, above. */
329 # if @REPLACE_FSEEKO@
330 /* Provide an fseeko function that is aware of a preceding fflush(), and which
332 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
334 # define fseeko rpl_fseeko
336 _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
337 _GL_ARG_NONNULL ((1)));
338 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
341 _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
342 _GL_ARG_NONNULL ((1)));
344 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
346 _GL_CXXALIASWARN (fseeko);
347 # if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
348 /* Provide an fseek function that is consistent with fseeko. */
349 /* In order to avoid that fseek gets defined as a macro here, the
350 developer can request the 'fseek' module. */
352 # define fseek rpl_fseek
353 static inline int _GL_ARG_NONNULL ((1))
354 rpl_fseek (FILE *fp, long offset, int whence)
356 # if @REPLACE_FSEEKO@
357 return rpl_fseeko (fp, offset, whence);
359 return fseeko (fp, offset, whence);
363 #elif defined GNULIB_POSIXCHECK
364 # define _GL_FSEEK_WARN /* Category 1, above. */
367 # if HAVE_RAW_DECL_FSEEKO
368 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
369 "use gnulib module fseeko for portability");
373 #ifdef _GL_FSEEK_WARN
374 # undef _GL_FSEEK_WARN
375 /* Here, either fseek is undefined (but C89 guarantees that it is
376 declared), or it is defined as rpl_fseek (declared above). */
377 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
378 "on 32-bit platforms - "
379 "use fseeko function for handling of large files");
383 /* ftell, ftello. See the comments on fseek/fseeko. */
386 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
387 # define _GL_FTELL_WARN /* Category 2, above. */
391 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
393 # define ftell rpl_ftell
395 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
396 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
398 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
400 _GL_CXXALIASWARN (ftell);
404 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
405 # define _GL_FTELL_WARN /* Category 3, above. */
408 # if @REPLACE_FTELLO@
409 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
411 # define ftello rpl_ftello
413 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
414 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
417 _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
419 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
421 _GL_CXXALIASWARN (ftello);
422 # if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
423 /* Provide an ftell function that is consistent with ftello. */
424 /* In order to avoid that ftell gets defined as a macro here, the
425 developer can request the 'ftell' module. */
427 # define ftell rpl_ftell
428 static inline long _GL_ARG_NONNULL ((1))
431 # if @REPLACE_FTELLO@
432 return rpl_ftello (f);
438 #elif defined GNULIB_POSIXCHECK
439 # define _GL_FTELL_WARN /* Category 1, above. */
442 # if HAVE_RAW_DECL_FTELLO
443 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
444 "use gnulib module ftello for portability");
448 #ifdef _GL_FTELL_WARN
449 # undef _GL_FTELL_WARN
450 /* Here, either ftell is undefined (but C89 guarantees that it is
451 declared), or it is defined as rpl_ftell (declared above). */
452 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
453 "on 32-bit platforms - "
454 "use ftello function for handling of large files");
459 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
460 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
462 # define fwrite rpl_fwrite
464 _GL_FUNCDECL_RPL (fwrite, size_t,
465 (const void *ptr, size_t s, size_t n, FILE *stream)
466 _GL_ARG_NONNULL ((1, 4)));
467 _GL_CXXALIAS_RPL (fwrite, size_t,
468 (const void *ptr, size_t s, size_t n, FILE *stream));
470 _GL_CXXALIAS_SYS (fwrite, size_t,
471 (const void *ptr, size_t s, size_t n, FILE *stream));
473 _GL_CXXALIASWARN (fwrite);
476 #if @GNULIB_GETDELIM@
477 /* Read input, up to (and including) the next occurrence of DELIMITER, from
478 STREAM, store it in *LINEPTR (and NUL-terminate it).
479 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
480 bytes of space. It is realloc'd as necessary.
481 Return the number of bytes read and stored at *LINEPTR (not including the
482 NUL terminator), or -1 on error or EOF. */
483 # if @REPLACE_GETDELIM@
484 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
486 # define getdelim rpl_getdelim
488 _GL_FUNCDECL_RPL (getdelim, ssize_t,
489 (char **lineptr, size_t *linesize, int delimiter,
491 _GL_ARG_NONNULL ((1, 2, 4)));
492 _GL_CXXALIAS_RPL (getdelim, ssize_t,
493 (char **lineptr, size_t *linesize, int delimiter,
496 # if !@HAVE_DECL_GETDELIM@
497 _GL_FUNCDECL_SYS (getdelim, ssize_t,
498 (char **lineptr, size_t *linesize, int delimiter,
500 _GL_ARG_NONNULL ((1, 2, 4)));
502 _GL_CXXALIAS_SYS (getdelim, ssize_t,
503 (char **lineptr, size_t *linesize, int delimiter,
506 _GL_CXXALIASWARN (getdelim);
507 #elif defined GNULIB_POSIXCHECK
509 # if HAVE_RAW_DECL_GETDELIM
510 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
511 "use gnulib module getdelim for portability");
516 /* Read a line, up to (and including) the next newline, from STREAM, store it
517 in *LINEPTR (and NUL-terminate it).
518 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
519 bytes of space. It is realloc'd as necessary.
520 Return the number of bytes read and stored at *LINEPTR (not including the
521 NUL terminator), or -1 on error or EOF. */
522 # if @REPLACE_GETLINE@
523 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
525 # define getline rpl_getline
527 _GL_FUNCDECL_RPL (getline, ssize_t,
528 (char **lineptr, size_t *linesize, FILE *stream)
529 _GL_ARG_NONNULL ((1, 2, 3)));
530 _GL_CXXALIAS_RPL (getline, ssize_t,
531 (char **lineptr, size_t *linesize, FILE *stream));
533 # if !@HAVE_DECL_GETLINE@
534 _GL_FUNCDECL_SYS (getline, ssize_t,
535 (char **lineptr, size_t *linesize, FILE *stream)
536 _GL_ARG_NONNULL ((1, 2, 3)));
538 _GL_CXXALIAS_SYS (getline, ssize_t,
539 (char **lineptr, size_t *linesize, FILE *stream));
541 # if @HAVE_DECL_GETLINE@
542 _GL_CXXALIASWARN (getline);
544 #elif defined GNULIB_POSIXCHECK
546 # if HAVE_RAW_DECL_GETLINE
547 _GL_WARN_ON_USE (getline, "getline is unportable - "
548 "use gnulib module getline for portability");
552 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
554 /* Grow an obstack with formatted output. Return the number of
555 bytes added to OBS. No trailing nul byte is added, and the
556 object should be closed with obstack_finish before use. Upon
557 memory allocation error, call obstack_alloc_failed_handler. Upon
558 other error, return -1. */
559 # if @REPLACE_OBSTACK_PRINTF@
560 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
561 # define obstack_printf rpl_obstack_printf
563 _GL_FUNCDECL_RPL (obstack_printf, int,
564 (struct obstack *obs, const char *format, ...)
565 __attribute__ ((__format__ (__printf__, 2, 3)))
566 _GL_ARG_NONNULL ((1, 2)));
567 _GL_CXXALIAS_RPL (obstack_printf, int,
568 (struct obstack *obs, const char *format, ...));
570 # if !@HAVE_DECL_OBSTACK_PRINTF@
571 _GL_FUNCDECL_SYS (obstack_printf, int,
572 (struct obstack *obs, const char *format, ...)
573 __attribute__ ((__format__ (__printf__, 2, 3)))
574 _GL_ARG_NONNULL ((1, 2)));
576 _GL_CXXALIAS_SYS (obstack_printf, int,
577 (struct obstack *obs, const char *format, ...));
579 _GL_CXXALIASWARN (obstack_printf);
580 # if @REPLACE_OBSTACK_PRINTF@
581 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
582 # define obstack_vprintf rpl_obstack_vprintf
584 _GL_FUNCDECL_RPL (obstack_vprintf, int,
585 (struct obstack *obs, const char *format, va_list args)
586 __attribute__ ((__format__ (__printf__, 2, 0)))
587 _GL_ARG_NONNULL ((1, 2)));
588 _GL_CXXALIAS_RPL (obstack_vprintf, int,
589 (struct obstack *obs, const char *format, va_list args));
591 # if !@HAVE_DECL_OBSTACK_PRINTF@
592 _GL_FUNCDECL_SYS (obstack_vprintf, int,
593 (struct obstack *obs, const char *format, va_list args)
594 __attribute__ ((__format__ (__printf__, 2, 0)))
595 _GL_ARG_NONNULL ((1, 2)));
597 _GL_CXXALIAS_SYS (obstack_vprintf, int,
598 (struct obstack *obs, const char *format, va_list args));
600 _GL_CXXALIASWARN (obstack_vprintf);
604 /* Print a message to standard error, describing the value of ERRNO,
605 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
606 and terminated with a newline. */
607 # if @REPLACE_PERROR@
608 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
609 # define perror rpl_perror
611 _GL_FUNCDECL_RPL (perror, void, (const char *string));
612 _GL_CXXALIAS_RPL (perror, void, (const char *string));
614 _GL_CXXALIAS_SYS (perror, void, (const char *string));
616 _GL_CXXALIASWARN (perror);
617 #elif defined GNULIB_POSIXCHECK
619 /* Assume perror is always declared. */
620 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
621 "use gnulib module perror for portability");
626 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
628 # define popen rpl_popen
630 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
631 _GL_ARG_NONNULL ((1, 2)));
632 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
634 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
636 _GL_CXXALIASWARN (popen);
637 #elif defined GNULIB_POSIXCHECK
639 # if HAVE_RAW_DECL_POPEN
640 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
641 "use gnulib module popen or pipe for more portability");
645 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
646 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
647 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
648 # if defined __GNUC__
649 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
650 /* Don't break __attribute__((format(printf,M,N))). */
651 # define printf __printf__
653 _GL_FUNCDECL_RPL_1 (__printf__, int,
654 (const char *format, ...)
655 __asm__ (@ASM_SYMBOL_PREFIX@
656 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
657 __attribute__ ((__format__ (__printf__, 1, 2)))
658 _GL_ARG_NONNULL ((1)));
659 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
661 _GL_FUNCDECL_RPL (printf, int,
662 (const char *format, ...)
663 __attribute__ ((__format__ (__printf__, 1, 2)))
664 _GL_ARG_NONNULL ((1)));
665 _GL_CXXALIAS_RPL (printf, int, (const char *format, ...));
667 # define GNULIB_overrides_printf 1
669 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
671 _GL_CXXALIASWARN (printf);
673 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
674 # if !GNULIB_overrides_printf
677 /* Assume printf is always declared. */
678 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
679 "use gnulib module printf-posix for portable "
684 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
685 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # define putc rpl_fputc
689 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
690 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
692 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
694 _GL_CXXALIASWARN (putc);
698 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
699 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
701 # define putchar rpl_putchar
703 _GL_FUNCDECL_RPL (putchar, int, (int c));
704 _GL_CXXALIAS_RPL (putchar, int, (int c));
706 _GL_CXXALIAS_SYS (putchar, int, (int c));
708 _GL_CXXALIASWARN (putchar);
712 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715 # define puts rpl_puts
717 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
718 _GL_CXXALIAS_RPL (puts, int, (const char *string));
720 _GL_CXXALIAS_SYS (puts, int, (const char *string));
722 _GL_CXXALIASWARN (puts);
726 # if @REPLACE_REMOVE@
727 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
729 # define remove rpl_remove
731 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
732 _GL_CXXALIAS_RPL (remove, int, (const char *name));
734 _GL_CXXALIAS_SYS (remove, int, (const char *name));
736 _GL_CXXALIASWARN (remove);
737 #elif defined GNULIB_POSIXCHECK
739 /* Assume remove is always declared. */
740 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
741 "use gnulib module remove for more portability");
745 # if @REPLACE_RENAME@
746 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
748 # define rename rpl_rename
750 _GL_FUNCDECL_RPL (rename, int,
751 (const char *old_filename, const char *new_filename)
752 _GL_ARG_NONNULL ((1, 2)));
753 _GL_CXXALIAS_RPL (rename, int,
754 (const char *old_filename, const char *new_filename));
756 _GL_CXXALIAS_SYS (rename, int,
757 (const char *old_filename, const char *new_filename));
759 _GL_CXXALIASWARN (rename);
760 #elif defined GNULIB_POSIXCHECK
762 /* Assume rename is always declared. */
763 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
764 "use gnulib module rename for more portability");
767 #if @GNULIB_RENAMEAT@
768 # if @REPLACE_RENAMEAT@
769 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
771 # define renameat rpl_renameat
773 _GL_FUNCDECL_RPL (renameat, int,
774 (int fd1, char const *file1, int fd2, char const *file2)
775 _GL_ARG_NONNULL ((2, 4)));
776 _GL_CXXALIAS_RPL (renameat, int,
777 (int fd1, char const *file1, int fd2, char const *file2));
779 # if !@HAVE_RENAMEAT@
780 _GL_FUNCDECL_SYS (renameat, int,
781 (int fd1, char const *file1, int fd2, char const *file2)
782 _GL_ARG_NONNULL ((2, 4)));
784 _GL_CXXALIAS_SYS (renameat, int,
785 (int fd1, char const *file1, int fd2, char const *file2));
787 _GL_CXXALIASWARN (renameat);
788 #elif defined GNULIB_POSIXCHECK
790 # if HAVE_RAW_DECL_RENAMEAT
791 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
792 "use gnulib module renameat for portability");
796 #if @GNULIB_SNPRINTF@
797 # if @REPLACE_SNPRINTF@
798 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
799 # define snprintf rpl_snprintf
801 _GL_FUNCDECL_RPL (snprintf, int,
802 (char *str, size_t size, const char *format, ...)
803 __attribute__ ((__format__ (__printf__, 3, 4)))
804 _GL_ARG_NONNULL ((3)));
805 _GL_CXXALIAS_RPL (snprintf, int,
806 (char *str, size_t size, const char *format, ...));
808 # if !@HAVE_DECL_SNPRINTF@
809 _GL_FUNCDECL_SYS (snprintf, int,
810 (char *str, size_t size, const char *format, ...)
811 __attribute__ ((__format__ (__printf__, 3, 4)))
812 _GL_ARG_NONNULL ((3)));
814 _GL_CXXALIAS_SYS (snprintf, int,
815 (char *str, size_t size, const char *format, ...));
817 _GL_CXXALIASWARN (snprintf);
818 #elif defined GNULIB_POSIXCHECK
820 # if HAVE_RAW_DECL_SNPRINTF
821 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
822 "use gnulib module snprintf for portability");
826 /* Some people would argue that sprintf should be handled like gets
827 (for example, OpenBSD issues a link warning for both functions),
828 since both can cause security holes due to buffer overruns.
829 However, we believe that sprintf can be used safely, and is more
830 efficient than snprintf in those safe cases; and as proof of our
831 belief, we use sprintf in several gnulib modules. So this header
832 intentionally avoids adding a warning to sprintf except when
833 GNULIB_POSIXCHECK is defined. */
835 #if @GNULIB_SPRINTF_POSIX@
836 # if @REPLACE_SPRINTF@
837 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
838 # define sprintf rpl_sprintf
840 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
841 __attribute__ ((__format__ (__printf__, 2, 3)))
842 _GL_ARG_NONNULL ((1, 2)));
843 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
845 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
847 _GL_CXXALIASWARN (sprintf);
848 #elif defined GNULIB_POSIXCHECK
850 /* Assume sprintf is always declared. */
851 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
852 "use gnulib module sprintf-posix for portable "
857 # if @REPLACE_TMPFILE@
858 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
859 # define tmpfile rpl_tmpfile
861 _GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
862 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
864 _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
866 _GL_CXXALIASWARN (tmpfile);
867 #elif defined GNULIB_POSIXCHECK
869 # if HAVE_RAW_DECL_TMPFILE
870 _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
871 "use gnulib module tmpfile for portability");
875 #if @GNULIB_VASPRINTF@
876 /* Write formatted output to a string dynamically allocated with malloc().
877 If the memory allocation succeeds, store the address of the string in
878 *RESULT and return the number of resulting bytes, excluding the trailing
879 NUL. Upon memory allocation error, or some other error, return -1. */
880 # if @REPLACE_VASPRINTF@
881 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
882 # define asprintf rpl_asprintf
884 _GL_FUNCDECL_RPL (asprintf, int,
885 (char **result, const char *format, ...)
886 __attribute__ ((__format__ (__printf__, 2, 3)))
887 _GL_ARG_NONNULL ((1, 2)));
888 _GL_CXXALIAS_RPL (asprintf, int,
889 (char **result, const char *format, ...));
891 # if !@HAVE_VASPRINTF@
892 _GL_FUNCDECL_SYS (asprintf, int,
893 (char **result, const char *format, ...)
894 __attribute__ ((__format__ (__printf__, 2, 3)))
895 _GL_ARG_NONNULL ((1, 2)));
897 _GL_CXXALIAS_SYS (asprintf, int,
898 (char **result, const char *format, ...));
900 _GL_CXXALIASWARN (asprintf);
901 # if @REPLACE_VASPRINTF@
902 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
903 # define vasprintf rpl_vasprintf
905 _GL_FUNCDECL_RPL (vasprintf, int,
906 (char **result, const char *format, va_list args)
907 __attribute__ ((__format__ (__printf__, 2, 0)))
908 _GL_ARG_NONNULL ((1, 2)));
909 _GL_CXXALIAS_RPL (vasprintf, int,
910 (char **result, const char *format, va_list args));
912 # if !@HAVE_VASPRINTF@
913 _GL_FUNCDECL_SYS (vasprintf, int,
914 (char **result, const char *format, va_list args)
915 __attribute__ ((__format__ (__printf__, 2, 0)))
916 _GL_ARG_NONNULL ((1, 2)));
918 _GL_CXXALIAS_SYS (vasprintf, int,
919 (char **result, const char *format, va_list args));
921 _GL_CXXALIASWARN (vasprintf);
924 #if @GNULIB_VDPRINTF@
925 # if @REPLACE_VDPRINTF@
926 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
927 # define vdprintf rpl_vdprintf
929 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
930 __attribute__ ((__format__ (__printf__, 2, 0)))
931 _GL_ARG_NONNULL ((2)));
932 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
934 # if !@HAVE_VDPRINTF@
935 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
936 __attribute__ ((__format__ (__printf__, 2, 0)))
937 _GL_ARG_NONNULL ((2)));
939 /* Need to cast, because on Solaris, the third parameter will likely be
941 _GL_CXXALIAS_SYS_CAST (vdprintf, int,
942 (int fd, const char *format, va_list args));
944 _GL_CXXALIASWARN (vdprintf);
945 #elif defined GNULIB_POSIXCHECK
947 # if HAVE_RAW_DECL_VDPRINTF
948 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
949 "use gnulib module vdprintf for portability");
953 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
954 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
955 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
956 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
957 # define vfprintf rpl_vfprintf
959 # define GNULIB_overrides_vfprintf 1
960 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
961 __attribute__ ((__format__ (__printf__, 2, 0)))
962 _GL_ARG_NONNULL ((1, 2)));
963 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
965 /* Need to cast, because on Solaris, the third parameter is
967 and GCC's fixincludes did not change this to __gnuc_va_list. */
968 _GL_CXXALIAS_SYS_CAST (vfprintf, int,
969 (FILE *fp, const char *format, va_list args));
971 _GL_CXXALIASWARN (vfprintf);
973 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
974 # if !GNULIB_overrides_vfprintf
977 /* Assume vfprintf is always declared. */
978 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
979 "use gnulib module vfprintf-posix for portable "
983 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
984 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
985 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
986 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
987 # define vprintf rpl_vprintf
989 # define GNULIB_overrides_vprintf 1
990 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
991 __attribute__ ((__format__ (__printf__, 1, 0)))
992 _GL_ARG_NONNULL ((1)));
993 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
995 /* Need to cast, because on Solaris, the second parameter is
997 and GCC's fixincludes did not change this to __gnuc_va_list. */
998 _GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
1000 _GL_CXXALIASWARN (vprintf);
1002 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1003 # if !GNULIB_overrides_vprintf
1006 /* Assume vprintf is always declared. */
1007 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1008 "use gnulib module vprintf-posix for portable "
1009 "POSIX compliance");
1012 #if @GNULIB_VSNPRINTF@
1013 # if @REPLACE_VSNPRINTF@
1014 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1015 # define vsnprintf rpl_vsnprintf
1017 _GL_FUNCDECL_RPL (vsnprintf, int,
1018 (char *str, size_t size, const char *format, va_list args)
1019 __attribute__ ((__format__ (__printf__, 3, 0)))
1020 _GL_ARG_NONNULL ((3)));
1021 _GL_CXXALIAS_RPL (vsnprintf, int,
1022 (char *str, size_t size, const char *format, va_list args));
1024 # if !@HAVE_DECL_VSNPRINTF@
1025 _GL_FUNCDECL_SYS (vsnprintf, int,
1026 (char *str, size_t size, const char *format, va_list args)
1027 __attribute__ ((__format__ (__printf__, 3, 0)))
1028 _GL_ARG_NONNULL ((3)));
1030 _GL_CXXALIAS_SYS (vsnprintf, int,
1031 (char *str, size_t size, const char *format, va_list args));
1033 _GL_CXXALIASWARN (vsnprintf);
1034 #elif defined GNULIB_POSIXCHECK
1036 # if HAVE_RAW_DECL_VSNPRINTF
1037 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1038 "use gnulib module vsnprintf for portability");
1042 #if @GNULIB_VSPRINTF_POSIX@
1043 # if @REPLACE_VSPRINTF@
1044 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1045 # define vsprintf rpl_vsprintf
1047 _GL_FUNCDECL_RPL (vsprintf, int,
1048 (char *str, const char *format, va_list args)
1049 __attribute__ ((__format__ (__printf__, 2, 0)))
1050 _GL_ARG_NONNULL ((1, 2)));
1051 _GL_CXXALIAS_RPL (vsprintf, int,
1052 (char *str, const char *format, va_list args));
1054 /* Need to cast, because on Solaris, the third parameter is
1056 and GCC's fixincludes did not change this to __gnuc_va_list. */
1057 _GL_CXXALIAS_SYS_CAST (vsprintf, int,
1058 (char *str, const char *format, va_list args));
1060 _GL_CXXALIASWARN (vsprintf);
1061 #elif defined GNULIB_POSIXCHECK
1063 /* Assume vsprintf is always declared. */
1064 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1065 "use gnulib module vsprintf-posix for portable "
1066 "POSIX compliance");
1070 #endif /* _GL_STDIO_H */
1071 #endif /* _GL_STDIO_H */