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 an fseeko function that is aware of a preceding fflush(), and which
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)));
333 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
336 _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
337 _GL_ARG_NONNULL ((1)));
339 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
341 _GL_CXXALIASWARN (fseeko);
342 # if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
343 /* Provide an fseek function that is consistent with fseeko. */
344 /* In order to avoid that fseek gets defined as a macro here, the
345 developer can request the 'fseek' module. */
347 # define fseek rpl_fseek
348 static inline int _GL_ARG_NONNULL ((1))
349 rpl_fseek (FILE *fp, long offset, int whence)
351 # if @REPLACE_FSEEKO@
352 return rpl_fseeko (fp, offset, whence);
354 return fseeko (fp, offset, whence);
358 #elif defined GNULIB_POSIXCHECK
359 # define _GL_FSEEK_WARN /* Category 1, above. */
362 # if HAVE_RAW_DECL_FSEEKO
363 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
364 "use gnulib module fseeko for portability");
368 #ifdef _GL_FSEEK_WARN
369 # undef _GL_FSEEK_WARN
370 /* Here, either fseek is undefined (but C89 guarantees that it is
371 declared), or it is defined as rpl_fseek (declared above). */
372 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
373 "on 32-bit platforms - "
374 "use fseeko function for handling of large files");
378 /* ftell, ftello. See the comments on fseek/fseeko. */
381 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
382 # define _GL_FTELL_WARN /* Category 2, above. */
386 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
388 # define ftell rpl_ftell
390 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
391 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
393 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
395 _GL_CXXALIASWARN (ftell);
399 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
400 # define _GL_FTELL_WARN /* Category 3, above. */
403 # if @REPLACE_FTELLO@
404 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
406 # define ftello rpl_ftello
408 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
409 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
412 _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
414 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
416 _GL_CXXALIASWARN (ftello);
417 # if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
418 /* Provide an ftell function that is consistent with ftello. */
419 /* In order to avoid that ftell gets defined as a macro here, the
420 developer can request the 'ftell' module. */
422 # define ftell rpl_ftell
423 static inline long _GL_ARG_NONNULL ((1))
426 # if @REPLACE_FTELLO@
427 return rpl_ftello (f);
433 #elif defined GNULIB_POSIXCHECK
434 # define _GL_FTELL_WARN /* Category 1, above. */
437 # if HAVE_RAW_DECL_FTELLO
438 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
439 "use gnulib module ftello for portability");
443 #ifdef _GL_FTELL_WARN
444 # undef _GL_FTELL_WARN
445 /* Here, either ftell is undefined (but C89 guarantees that it is
446 declared), or it is defined as rpl_ftell (declared above). */
447 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
448 "on 32-bit platforms - "
449 "use ftello function for handling of large files");
454 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
455 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
457 # define fwrite rpl_fwrite
459 _GL_FUNCDECL_RPL (fwrite, size_t,
460 (const void *ptr, size_t s, size_t n, FILE *stream)
461 _GL_ARG_NONNULL ((1, 4)));
462 _GL_CXXALIAS_RPL (fwrite, size_t,
463 (const void *ptr, size_t s, size_t n, FILE *stream));
465 _GL_CXXALIAS_SYS (fwrite, size_t,
466 (const void *ptr, size_t s, size_t n, FILE *stream));
468 _GL_CXXALIASWARN (fwrite);
471 #if @GNULIB_GETDELIM@
472 /* Read input, up to (and including) the next occurrence of DELIMITER, from
473 STREAM, store it in *LINEPTR (and NUL-terminate it).
474 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
475 bytes of space. It is realloc'd as necessary.
476 Return the number of bytes read and stored at *LINEPTR (not including the
477 NUL terminator), or -1 on error or EOF. */
478 # if @REPLACE_GETDELIM@
479 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
481 # define getdelim rpl_getdelim
483 _GL_FUNCDECL_RPL (getdelim, ssize_t,
484 (char **lineptr, size_t *linesize, int delimiter,
486 _GL_ARG_NONNULL ((1, 2, 4)));
487 _GL_CXXALIAS_RPL (getdelim, ssize_t,
488 (char **lineptr, size_t *linesize, int delimiter,
491 # if !@HAVE_DECL_GETDELIM@
492 _GL_FUNCDECL_SYS (getdelim, ssize_t,
493 (char **lineptr, size_t *linesize, int delimiter,
495 _GL_ARG_NONNULL ((1, 2, 4)));
497 _GL_CXXALIAS_SYS (getdelim, ssize_t,
498 (char **lineptr, size_t *linesize, int delimiter,
501 _GL_CXXALIASWARN (getdelim);
502 #elif defined GNULIB_POSIXCHECK
504 # if HAVE_RAW_DECL_GETDELIM
505 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
506 "use gnulib module getdelim for portability");
511 /* Read a line, up to (and including) the next newline, from STREAM, store it
512 in *LINEPTR (and NUL-terminate it).
513 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
514 bytes of space. It is realloc'd as necessary.
515 Return the number of bytes read and stored at *LINEPTR (not including the
516 NUL terminator), or -1 on error or EOF. */
517 # if @REPLACE_GETLINE@
518 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
520 # define getline rpl_getline
522 _GL_FUNCDECL_RPL (getline, ssize_t,
523 (char **lineptr, size_t *linesize, FILE *stream)
524 _GL_ARG_NONNULL ((1, 2, 3)));
525 _GL_CXXALIAS_RPL (getline, ssize_t,
526 (char **lineptr, size_t *linesize, FILE *stream));
528 # if !@HAVE_DECL_GETLINE@
529 _GL_FUNCDECL_SYS (getline, ssize_t,
530 (char **lineptr, size_t *linesize, FILE *stream)
531 _GL_ARG_NONNULL ((1, 2, 3)));
533 _GL_CXXALIAS_SYS (getline, ssize_t,
534 (char **lineptr, size_t *linesize, FILE *stream));
536 # if @HAVE_DECL_GETLINE@
537 _GL_CXXALIASWARN (getline);
539 #elif defined GNULIB_POSIXCHECK
541 # if HAVE_RAW_DECL_GETLINE
542 _GL_WARN_ON_USE (getline, "getline is unportable - "
543 "use gnulib module getline for portability");
547 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
549 /* Grow an obstack with formatted output. Return the number of
550 bytes added to OBS. No trailing nul byte is added, and the
551 object should be closed with obstack_finish before use. Upon
552 memory allocation error, call obstack_alloc_failed_handler. Upon
553 other error, return -1. */
554 # if @REPLACE_OBSTACK_PRINTF@
555 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
556 # define obstack_printf rpl_obstack_printf
558 _GL_FUNCDECL_RPL (obstack_printf, int,
559 (struct obstack *obs, const char *format, ...)
560 __attribute__ ((__format__ (__printf__, 2, 3)))
561 _GL_ARG_NONNULL ((1, 2)));
562 _GL_CXXALIAS_RPL (obstack_printf, int,
563 (struct obstack *obs, const char *format, ...));
565 # if !@HAVE_DECL_OBSTACK_PRINTF@
566 _GL_FUNCDECL_SYS (obstack_printf, int,
567 (struct obstack *obs, const char *format, ...)
568 __attribute__ ((__format__ (__printf__, 2, 3)))
569 _GL_ARG_NONNULL ((1, 2)));
571 _GL_CXXALIAS_SYS (obstack_printf, int,
572 (struct obstack *obs, const char *format, ...));
574 _GL_CXXALIASWARN (obstack_printf);
575 # if @REPLACE_OBSTACK_PRINTF@
576 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
577 # define obstack_vprintf rpl_obstack_vprintf
579 _GL_FUNCDECL_RPL (obstack_vprintf, int,
580 (struct obstack *obs, const char *format, va_list args)
581 __attribute__ ((__format__ (__printf__, 2, 0)))
582 _GL_ARG_NONNULL ((1, 2)));
583 _GL_CXXALIAS_RPL (obstack_vprintf, int,
584 (struct obstack *obs, const char *format, va_list args));
586 # if !@HAVE_DECL_OBSTACK_PRINTF@
587 _GL_FUNCDECL_SYS (obstack_vprintf, int,
588 (struct obstack *obs, const char *format, va_list args)
589 __attribute__ ((__format__ (__printf__, 2, 0)))
590 _GL_ARG_NONNULL ((1, 2)));
592 _GL_CXXALIAS_SYS (obstack_vprintf, int,
593 (struct obstack *obs, const char *format, va_list args));
595 _GL_CXXALIASWARN (obstack_vprintf);
599 /* Print a message to standard error, describing the value of ERRNO,
600 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
601 and terminated with a newline. */
602 # if @REPLACE_PERROR@
603 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
604 # define perror rpl_perror
606 _GL_FUNCDECL_RPL (perror, void, (const char *string));
607 _GL_CXXALIAS_RPL (perror, void, (const char *string));
609 _GL_CXXALIAS_SYS (perror, void, (const char *string));
611 _GL_CXXALIASWARN (perror);
612 #elif defined GNULIB_POSIXCHECK
614 /* Assume perror is always declared. */
615 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
616 "use gnulib module perror for portability");
621 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
623 # define popen rpl_popen
625 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
626 _GL_ARG_NONNULL ((1, 2)));
627 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
629 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
631 _GL_CXXALIASWARN (popen);
632 #elif defined GNULIB_POSIXCHECK
634 # if HAVE_RAW_DECL_POPEN
635 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
636 "use gnulib module popen or pipe for more portability");
640 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
641 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
642 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
643 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
644 /* Don't break __attribute__((format(printf,M,N))). */
645 # define printf __printf__
647 # define GNULIB_overrides_printf 1
648 _GL_FUNCDECL_RPL_1 (__printf__, int,
649 (const char *format, ...)
650 __attribute__ ((__format__ (__printf__, 1, 2)))
651 _GL_ARG_NONNULL ((1)));
652 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
654 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
656 _GL_CXXALIASWARN (printf);
658 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
659 # if !GNULIB_overrides_printf
662 /* Assume printf is always declared. */
663 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
664 "use gnulib module printf-posix for portable "
669 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
670 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
672 # define putc rpl_fputc
674 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
675 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
677 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
679 _GL_CXXALIASWARN (putc);
683 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
684 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
686 # define putchar rpl_putchar
688 _GL_FUNCDECL_RPL (putchar, int, (int c));
689 _GL_CXXALIAS_RPL (putchar, int, (int c));
691 _GL_CXXALIAS_SYS (putchar, int, (int c));
693 _GL_CXXALIASWARN (putchar);
697 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
698 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
700 # define puts rpl_puts
702 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
703 _GL_CXXALIAS_RPL (puts, int, (const char *string));
705 _GL_CXXALIAS_SYS (puts, int, (const char *string));
707 _GL_CXXALIASWARN (puts);
711 # if @REPLACE_REMOVE@
712 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714 # define remove rpl_remove
716 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
717 _GL_CXXALIAS_RPL (remove, int, (const char *name));
719 _GL_CXXALIAS_SYS (remove, int, (const char *name));
721 _GL_CXXALIASWARN (remove);
722 #elif defined GNULIB_POSIXCHECK
724 /* Assume remove is always declared. */
725 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
726 "use gnulib module remove for more portability");
730 # if @REPLACE_RENAME@
731 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
733 # define rename rpl_rename
735 _GL_FUNCDECL_RPL (rename, int,
736 (const char *old_filename, const char *new_filename)
737 _GL_ARG_NONNULL ((1, 2)));
738 _GL_CXXALIAS_RPL (rename, int,
739 (const char *old_filename, const char *new_filename));
741 _GL_CXXALIAS_SYS (rename, int,
742 (const char *old_filename, const char *new_filename));
744 _GL_CXXALIASWARN (rename);
745 #elif defined GNULIB_POSIXCHECK
747 /* Assume rename is always declared. */
748 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
749 "use gnulib module rename for more portability");
752 #if @GNULIB_RENAMEAT@
753 # if @REPLACE_RENAMEAT@
754 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
756 # define renameat rpl_renameat
758 _GL_FUNCDECL_RPL (renameat, int,
759 (int fd1, char const *file1, int fd2, char const *file2)
760 _GL_ARG_NONNULL ((2, 4)));
761 _GL_CXXALIAS_RPL (renameat, int,
762 (int fd1, char const *file1, int fd2, char const *file2));
764 # if !@HAVE_RENAMEAT@
765 _GL_FUNCDECL_SYS (renameat, int,
766 (int fd1, char const *file1, int fd2, char const *file2)
767 _GL_ARG_NONNULL ((2, 4)));
769 _GL_CXXALIAS_SYS (renameat, int,
770 (int fd1, char const *file1, int fd2, char const *file2));
772 _GL_CXXALIASWARN (renameat);
773 #elif defined GNULIB_POSIXCHECK
775 # if HAVE_RAW_DECL_RENAMEAT
776 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
777 "use gnulib module renameat for portability");
781 #if @GNULIB_SNPRINTF@
782 # if @REPLACE_SNPRINTF@
783 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
784 # define snprintf rpl_snprintf
786 _GL_FUNCDECL_RPL (snprintf, int,
787 (char *str, size_t size, const char *format, ...)
788 __attribute__ ((__format__ (__printf__, 3, 4)))
789 _GL_ARG_NONNULL ((3)));
790 _GL_CXXALIAS_RPL (snprintf, int,
791 (char *str, size_t size, const char *format, ...));
793 # if !@HAVE_DECL_SNPRINTF@
794 _GL_FUNCDECL_SYS (snprintf, int,
795 (char *str, size_t size, const char *format, ...)
796 __attribute__ ((__format__ (__printf__, 3, 4)))
797 _GL_ARG_NONNULL ((3)));
799 _GL_CXXALIAS_SYS (snprintf, int,
800 (char *str, size_t size, const char *format, ...));
802 _GL_CXXALIASWARN (snprintf);
803 #elif defined GNULIB_POSIXCHECK
805 # if HAVE_RAW_DECL_SNPRINTF
806 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
807 "use gnulib module snprintf for portability");
811 /* Some people would argue that sprintf should be handled like gets
812 (for example, OpenBSD issues a link warning for both functions),
813 since both can cause security holes due to buffer overruns.
814 However, we believe that sprintf can be used safely, and is more
815 efficient than snprintf in those safe cases; and as proof of our
816 belief, we use sprintf in several gnulib modules. So this header
817 intentionally avoids adding a warning to sprintf except when
818 GNULIB_POSIXCHECK is defined. */
820 #if @GNULIB_SPRINTF_POSIX@
821 # if @REPLACE_SPRINTF@
822 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
823 # define sprintf rpl_sprintf
825 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
826 __attribute__ ((__format__ (__printf__, 2, 3)))
827 _GL_ARG_NONNULL ((1, 2)));
828 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
830 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
832 _GL_CXXALIASWARN (sprintf);
833 #elif defined GNULIB_POSIXCHECK
835 /* Assume sprintf is always declared. */
836 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
837 "use gnulib module sprintf-posix for portable "
842 # if @REPLACE_TMPFILE@
843 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
844 # define tmpfile rpl_tmpfile
846 _GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
847 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
849 _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
851 _GL_CXXALIASWARN (tmpfile);
852 #elif defined GNULIB_POSIXCHECK
854 # if HAVE_RAW_DECL_TMPFILE
855 _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
856 "use gnulib module tmpfile for portability");
860 #if @GNULIB_VASPRINTF@
861 /* Write formatted output to a string dynamically allocated with malloc().
862 If the memory allocation succeeds, store the address of the string in
863 *RESULT and return the number of resulting bytes, excluding the trailing
864 NUL. Upon memory allocation error, or some other error, return -1. */
865 # if @REPLACE_VASPRINTF@
866 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
867 # define asprintf rpl_asprintf
869 _GL_FUNCDECL_RPL (asprintf, int,
870 (char **result, const char *format, ...)
871 __attribute__ ((__format__ (__printf__, 2, 3)))
872 _GL_ARG_NONNULL ((1, 2)));
873 _GL_CXXALIAS_RPL (asprintf, int,
874 (char **result, const char *format, ...));
876 # if !@HAVE_VASPRINTF@
877 _GL_FUNCDECL_SYS (asprintf, int,
878 (char **result, const char *format, ...)
879 __attribute__ ((__format__ (__printf__, 2, 3)))
880 _GL_ARG_NONNULL ((1, 2)));
882 _GL_CXXALIAS_SYS (asprintf, int,
883 (char **result, const char *format, ...));
885 _GL_CXXALIASWARN (asprintf);
886 # if @REPLACE_VASPRINTF@
887 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
888 # define vasprintf rpl_vasprintf
890 _GL_FUNCDECL_RPL (vasprintf, int,
891 (char **result, const char *format, va_list args)
892 __attribute__ ((__format__ (__printf__, 2, 0)))
893 _GL_ARG_NONNULL ((1, 2)));
894 _GL_CXXALIAS_RPL (vasprintf, int,
895 (char **result, const char *format, va_list args));
897 # if !@HAVE_VASPRINTF@
898 _GL_FUNCDECL_SYS (vasprintf, int,
899 (char **result, const char *format, va_list args)
900 __attribute__ ((__format__ (__printf__, 2, 0)))
901 _GL_ARG_NONNULL ((1, 2)));
903 _GL_CXXALIAS_SYS (vasprintf, int,
904 (char **result, const char *format, va_list args));
906 _GL_CXXALIASWARN (vasprintf);
909 #if @GNULIB_VDPRINTF@
910 # if @REPLACE_VDPRINTF@
911 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
912 # define vdprintf rpl_vdprintf
914 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
915 __attribute__ ((__format__ (__printf__, 2, 0)))
916 _GL_ARG_NONNULL ((2)));
917 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
919 # if !@HAVE_VDPRINTF@
920 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
921 __attribute__ ((__format__ (__printf__, 2, 0)))
922 _GL_ARG_NONNULL ((2)));
924 /* Need to cast, because on Solaris, the third parameter will likely be
926 _GL_CXXALIAS_SYS_CAST (vdprintf, int,
927 (int fd, const char *format, va_list args));
929 _GL_CXXALIASWARN (vdprintf);
930 #elif defined GNULIB_POSIXCHECK
932 # if HAVE_RAW_DECL_VDPRINTF
933 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
934 "use gnulib module vdprintf for portability");
938 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
939 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
940 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
941 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
942 # define vfprintf rpl_vfprintf
944 # define GNULIB_overrides_vfprintf 1
945 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
946 __attribute__ ((__format__ (__printf__, 2, 0)))
947 _GL_ARG_NONNULL ((1, 2)));
948 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
950 /* Need to cast, because on Solaris, the third parameter is
952 and GCC's fixincludes did not change this to __gnuc_va_list. */
953 _GL_CXXALIAS_SYS_CAST (vfprintf, int,
954 (FILE *fp, const char *format, va_list args));
956 _GL_CXXALIASWARN (vfprintf);
958 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
959 # if !GNULIB_overrides_vfprintf
962 /* Assume vfprintf is always declared. */
963 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
964 "use gnulib module vfprintf-posix for portable "
968 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
969 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
970 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
971 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
972 # define vprintf rpl_vprintf
974 # define GNULIB_overrides_vprintf 1
975 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
976 __attribute__ ((__format__ (__printf__, 1, 0)))
977 _GL_ARG_NONNULL ((1)));
978 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
980 /* Need to cast, because on Solaris, the second parameter is
982 and GCC's fixincludes did not change this to __gnuc_va_list. */
983 _GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
985 _GL_CXXALIASWARN (vprintf);
987 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
988 # if !GNULIB_overrides_vprintf
991 /* Assume vprintf is always declared. */
992 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
993 "use gnulib module vprintf-posix for portable "
997 #if @GNULIB_VSNPRINTF@
998 # if @REPLACE_VSNPRINTF@
999 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1000 # define vsnprintf rpl_vsnprintf
1002 _GL_FUNCDECL_RPL (vsnprintf, int,
1003 (char *str, size_t size, const char *format, va_list args)
1004 __attribute__ ((__format__ (__printf__, 3, 0)))
1005 _GL_ARG_NONNULL ((3)));
1006 _GL_CXXALIAS_RPL (vsnprintf, int,
1007 (char *str, size_t size, const char *format, va_list args));
1009 # if !@HAVE_DECL_VSNPRINTF@
1010 _GL_FUNCDECL_SYS (vsnprintf, int,
1011 (char *str, size_t size, const char *format, va_list args)
1012 __attribute__ ((__format__ (__printf__, 3, 0)))
1013 _GL_ARG_NONNULL ((3)));
1015 _GL_CXXALIAS_SYS (vsnprintf, int,
1016 (char *str, size_t size, const char *format, va_list args));
1018 _GL_CXXALIASWARN (vsnprintf);
1019 #elif defined GNULIB_POSIXCHECK
1021 # if HAVE_RAW_DECL_VSNPRINTF
1022 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1023 "use gnulib module vsnprintf for portability");
1027 #if @GNULIB_VSPRINTF_POSIX@
1028 # if @REPLACE_VSPRINTF@
1029 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1030 # define vsprintf rpl_vsprintf
1032 _GL_FUNCDECL_RPL (vsprintf, int,
1033 (char *str, const char *format, va_list args)
1034 __attribute__ ((__format__ (__printf__, 2, 0)))
1035 _GL_ARG_NONNULL ((1, 2)));
1036 _GL_CXXALIAS_RPL (vsprintf, int,
1037 (char *str, const char *format, va_list args));
1039 /* Need to cast, because on Solaris, the third parameter is
1041 and GCC's fixincludes did not change this to __gnuc_va_list. */
1042 _GL_CXXALIAS_SYS_CAST (vsprintf, int,
1043 (char *str, const char *format, va_list args));
1045 _GL_CXXALIASWARN (vsprintf);
1046 #elif defined GNULIB_POSIXCHECK
1048 /* Assume vsprintf is always declared. */
1049 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1050 "use gnulib module vsprintf-posix for portable "
1051 "POSIX compliance");
1055 #endif /* _GL_STDIO_H */
1056 #endif /* _GL_STDIO_H */