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@
24 #if defined __need_FILE || defined __need___FILE
25 /* Special invocation convention inside glibc header files. */
27 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
30 /* Normal invocation convention. */
34 /* The include_next requires a split double-inclusion guard. */
35 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
40 /* Get va_list. Needed on many systems, including glibc 2.8. */
45 /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8. */
46 #include <sys/types.h>
49 /* The __attribute__ feature is available in gcc versions 2.5 and later.
50 The __-protected variants of the attributes 'format' and 'printf' are
51 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
52 We enable __attribute__ only if these are supported too, because
53 gnulib and libintl do '#define printf __printf__' when they override
54 the 'printf' function. */
55 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
56 # define __attribute__(Spec) /* empty */
61 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
63 /* The definition of _GL_ARG_NONNULL is copied here. */
65 /* The definition of _GL_WARN_ON_USE is copied here. */
67 /* Macros for stringification. */
68 #define _GL_STDIO_STRINGIZE(token) #token
69 #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
73 # if @REPLACE_DPRINTF@
74 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
75 # define dprintf rpl_dprintf
77 _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
78 __attribute__ ((__format__ (__printf__, 2, 3)))
79 _GL_ARG_NONNULL ((2)));
80 _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
83 _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
84 __attribute__ ((__format__ (__printf__, 2, 3)))
85 _GL_ARG_NONNULL ((2)));
87 _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
89 _GL_CXXALIASWARN (dprintf);
90 #elif defined GNULIB_POSIXCHECK
92 # if HAVE_RAW_DECL_DPRINTF
93 _GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
94 "use gnulib module dprintf for portability");
99 /* Close STREAM and its underlying file descriptor. */
100 # if @REPLACE_FCLOSE@
101 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
102 # define fclose rpl_fclose
104 _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
105 _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
107 _GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
109 _GL_CXXALIASWARN (fclose);
110 #elif defined GNULIB_POSIXCHECK
112 /* Assume fclose is always declared. */
113 _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
114 "use gnulib module fclose for portable POSIX compliance");
118 /* Flush all pending data on STREAM according to POSIX rules. Both
119 output and seekable input streams are supported.
120 Note! LOSS OF DATA can occur if fflush is applied on an input stream
121 that is _not_seekable_ or on an update stream that is _not_seekable_
122 and in which the most recent operation was input. Seekability can
123 be tested with lseek(fileno(fp),0,SEEK_CUR). */
124 # if @REPLACE_FFLUSH@
125 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
126 # define fflush rpl_fflush
128 _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
129 _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
131 _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
133 _GL_CXXALIASWARN (fflush);
134 #elif defined GNULIB_POSIXCHECK
136 /* Assume fflush is always declared. */
137 _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
138 "use gnulib module fflush for portable POSIX compliance");
141 /* It is very rare that the developer ever has full control of stdin,
142 so any use of gets warrants an unconditional warning. Assume it is
143 always declared, since it is required by C89. */
145 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
149 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
151 # define fopen rpl_fopen
153 _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
154 _GL_ARG_NONNULL ((1, 2)));
155 _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
157 _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
159 _GL_CXXALIASWARN (fopen);
160 #elif defined GNULIB_POSIXCHECK
162 /* Assume fopen is always declared. */
163 _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
164 "use gnulib module fopen for portability");
167 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
168 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
169 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
170 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
171 # define fprintf rpl_fprintf
173 # define GNULIB_overrides_fprintf 1
174 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
175 __attribute__ ((__format__ (__printf__, 2, 3)))
176 _GL_ARG_NONNULL ((1, 2)));
177 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
179 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
181 _GL_CXXALIASWARN (fprintf);
183 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
184 # if !GNULIB_overrides_fprintf
187 /* Assume fprintf is always declared. */
188 _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
189 "use gnulib module fprintf-posix for portable "
194 /* Discard all pending buffered I/O data on STREAM.
195 STREAM must not be wide-character oriented.
196 When discarding pending output, the file position is set back to where it
197 was before the write calls. When discarding pending input, the file
198 position is advanced to match the end of the previously read input.
199 Return 0 if successful. Upon error, return -1 and set errno. */
200 # if @REPLACE_FPURGE@
201 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
202 # define fpurge rpl_fpurge
204 _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
205 _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
207 # if !@HAVE_DECL_FPURGE@
208 _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
210 _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
212 _GL_CXXALIASWARN (fpurge);
213 #elif defined GNULIB_POSIXCHECK
215 # if HAVE_RAW_DECL_FPURGE
216 _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
217 "use gnulib module fpurge for portability");
222 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
223 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
225 # define fputc rpl_fputc
227 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
228 _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
230 _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
232 _GL_CXXALIASWARN (fputc);
236 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
237 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
239 # define fputs rpl_fputs
241 _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
242 _GL_ARG_NONNULL ((1, 2)));
243 _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
245 _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
247 _GL_CXXALIASWARN (fputs);
251 # if @REPLACE_FREOPEN@
252 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
254 # define freopen rpl_freopen
256 _GL_FUNCDECL_RPL (freopen, FILE *,
257 (const char *filename, const char *mode, FILE *stream)
258 _GL_ARG_NONNULL ((2, 3)));
259 _GL_CXXALIAS_RPL (freopen, FILE *,
260 (const char *filename, const char *mode, FILE *stream));
262 _GL_CXXALIAS_SYS (freopen, FILE *,
263 (const char *filename, const char *mode, FILE *stream));
265 _GL_CXXALIASWARN (freopen);
266 #elif defined GNULIB_POSIXCHECK
268 /* Assume freopen is always declared. */
269 _GL_WARN_ON_USE (freopen,
270 "freopen on Win32 platforms is not POSIX compatible - "
271 "use gnulib module freopen for portability");
275 /* Set up the following warnings, based on which modules are in use.
276 GNU Coding Standards discourage the use of fseek, since it imposes
277 an arbitrary limitation on some 32-bit hosts. Remember that the
278 fseek module depends on the fseeko module, so we only have three
281 1. The developer is not using either module. Issue a warning under
282 GNULIB_POSIXCHECK for both functions, to remind them that both
283 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
284 impact on this warning.
286 2. The developer is using both modules. They may be unaware of the
287 arbitrary limitations of fseek, so issue a warning under
288 GNULIB_POSIXCHECK. On the other hand, they may be using both
289 modules intentionally, so the developer can define
290 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
291 is safe, to silence the warning.
293 3. The developer is using the fseeko module, but not fseek. Gnulib
294 guarantees that fseek will still work around platform bugs in that
295 case, but we presume that the developer is aware of the pitfalls of
296 fseek and was trying to avoid it, so issue a warning even when
297 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
298 defined to silence the warning in particular compilation units.
299 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
300 fseek gets defined as a macro, it is recommended that the developer
301 uses the fseek module, even if he is not calling the fseek function.
303 Most gnulib clients that perform stream operations should fall into
307 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
308 # define _GL_FSEEK_WARN /* Category 2, above. */
312 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
314 # define fseek rpl_fseek
316 _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
317 _GL_ARG_NONNULL ((1)));
318 _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
320 _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
322 _GL_CXXALIASWARN (fseek);
326 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
327 # define _GL_FSEEK_WARN /* Category 3, above. */
330 # if @REPLACE_FSEEKO@
331 /* Provide an fseeko function that is aware of a preceding fflush(), and which
333 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
335 # define fseeko rpl_fseeko
337 _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
338 _GL_ARG_NONNULL ((1)));
339 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
342 _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
343 _GL_ARG_NONNULL ((1)));
345 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
347 _GL_CXXALIASWARN (fseeko);
348 # if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
349 /* Provide an fseek function that is consistent with fseeko. */
350 /* In order to avoid that fseek gets defined as a macro here, the
351 developer can request the 'fseek' module. */
353 # define fseek rpl_fseek
354 static inline int _GL_ARG_NONNULL ((1))
355 rpl_fseek (FILE *fp, long offset, int whence)
357 # if @REPLACE_FSEEKO@
358 return rpl_fseeko (fp, offset, whence);
360 return fseeko (fp, offset, whence);
364 #elif defined GNULIB_POSIXCHECK
365 # define _GL_FSEEK_WARN /* Category 1, above. */
368 # if HAVE_RAW_DECL_FSEEKO
369 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
370 "use gnulib module fseeko for portability");
374 #ifdef _GL_FSEEK_WARN
375 # undef _GL_FSEEK_WARN
376 /* Here, either fseek is undefined (but C89 guarantees that it is
377 declared), or it is defined as rpl_fseek (declared above). */
378 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
379 "on 32-bit platforms - "
380 "use fseeko function for handling of large files");
384 /* ftell, ftello. See the comments on fseek/fseeko. */
387 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
388 # define _GL_FTELL_WARN /* Category 2, above. */
392 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
394 # define ftell rpl_ftell
396 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
397 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
399 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
401 _GL_CXXALIASWARN (ftell);
405 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
406 # define _GL_FTELL_WARN /* Category 3, above. */
409 # if @REPLACE_FTELLO@
410 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
412 # define ftello rpl_ftello
414 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
415 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
418 _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
420 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
422 _GL_CXXALIASWARN (ftello);
423 # if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
424 /* Provide an ftell function that is consistent with ftello. */
425 /* In order to avoid that ftell gets defined as a macro here, the
426 developer can request the 'ftell' module. */
428 # define ftell rpl_ftell
429 static inline long _GL_ARG_NONNULL ((1))
432 # if @REPLACE_FTELLO@
433 return rpl_ftello (f);
439 #elif defined GNULIB_POSIXCHECK
440 # define _GL_FTELL_WARN /* Category 1, above. */
443 # if HAVE_RAW_DECL_FTELLO
444 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
445 "use gnulib module ftello for portability");
449 #ifdef _GL_FTELL_WARN
450 # undef _GL_FTELL_WARN
451 /* Here, either ftell is undefined (but C89 guarantees that it is
452 declared), or it is defined as rpl_ftell (declared above). */
453 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
454 "on 32-bit platforms - "
455 "use ftello function for handling of large files");
460 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
461 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
463 # define fwrite rpl_fwrite
465 _GL_FUNCDECL_RPL (fwrite, size_t,
466 (const void *ptr, size_t s, size_t n, FILE *stream)
467 _GL_ARG_NONNULL ((1, 4)));
468 _GL_CXXALIAS_RPL (fwrite, size_t,
469 (const void *ptr, size_t s, size_t n, FILE *stream));
471 _GL_CXXALIAS_SYS (fwrite, size_t,
472 (const void *ptr, size_t s, size_t n, FILE *stream));
474 _GL_CXXALIASWARN (fwrite);
477 #if @GNULIB_GETDELIM@
478 /* Read input, up to (and including) the next occurrence of DELIMITER, from
479 STREAM, store it in *LINEPTR (and NUL-terminate it).
480 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
481 bytes of space. It is realloc'd as necessary.
482 Return the number of bytes read and stored at *LINEPTR (not including the
483 NUL terminator), or -1 on error or EOF. */
484 # if @REPLACE_GETDELIM@
485 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
487 # define getdelim rpl_getdelim
489 _GL_FUNCDECL_RPL (getdelim, ssize_t,
490 (char **lineptr, size_t *linesize, int delimiter,
492 _GL_ARG_NONNULL ((1, 2, 4)));
493 _GL_CXXALIAS_RPL (getdelim, ssize_t,
494 (char **lineptr, size_t *linesize, int delimiter,
497 # if !@HAVE_DECL_GETDELIM@
498 _GL_FUNCDECL_SYS (getdelim, ssize_t,
499 (char **lineptr, size_t *linesize, int delimiter,
501 _GL_ARG_NONNULL ((1, 2, 4)));
503 _GL_CXXALIAS_SYS (getdelim, ssize_t,
504 (char **lineptr, size_t *linesize, int delimiter,
507 _GL_CXXALIASWARN (getdelim);
508 #elif defined GNULIB_POSIXCHECK
510 # if HAVE_RAW_DECL_GETDELIM
511 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
512 "use gnulib module getdelim for portability");
517 /* Read a line, up to (and including) the next newline, from STREAM, store it
518 in *LINEPTR (and NUL-terminate it).
519 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
520 bytes of space. It is realloc'd as necessary.
521 Return the number of bytes read and stored at *LINEPTR (not including the
522 NUL terminator), or -1 on error or EOF. */
523 # if @REPLACE_GETLINE@
524 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
526 # define getline rpl_getline
528 _GL_FUNCDECL_RPL (getline, ssize_t,
529 (char **lineptr, size_t *linesize, FILE *stream)
530 _GL_ARG_NONNULL ((1, 2, 3)));
531 _GL_CXXALIAS_RPL (getline, ssize_t,
532 (char **lineptr, size_t *linesize, FILE *stream));
534 # if !@HAVE_DECL_GETLINE@
535 _GL_FUNCDECL_SYS (getline, ssize_t,
536 (char **lineptr, size_t *linesize, FILE *stream)
537 _GL_ARG_NONNULL ((1, 2, 3)));
539 _GL_CXXALIAS_SYS (getline, ssize_t,
540 (char **lineptr, size_t *linesize, FILE *stream));
542 # if @HAVE_DECL_GETLINE@
543 _GL_CXXALIASWARN (getline);
545 #elif defined GNULIB_POSIXCHECK
547 # if HAVE_RAW_DECL_GETLINE
548 _GL_WARN_ON_USE (getline, "getline is unportable - "
549 "use gnulib module getline for portability");
553 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
555 /* Grow an obstack with formatted output. Return the number of
556 bytes added to OBS. No trailing nul byte is added, and the
557 object should be closed with obstack_finish before use. Upon
558 memory allocation error, call obstack_alloc_failed_handler. Upon
559 other error, return -1. */
560 # if @REPLACE_OBSTACK_PRINTF@
561 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
562 # define obstack_printf rpl_obstack_printf
564 _GL_FUNCDECL_RPL (obstack_printf, int,
565 (struct obstack *obs, const char *format, ...)
566 __attribute__ ((__format__ (__printf__, 2, 3)))
567 _GL_ARG_NONNULL ((1, 2)));
568 _GL_CXXALIAS_RPL (obstack_printf, int,
569 (struct obstack *obs, const char *format, ...));
571 # if !@HAVE_DECL_OBSTACK_PRINTF@
572 _GL_FUNCDECL_SYS (obstack_printf, int,
573 (struct obstack *obs, const char *format, ...)
574 __attribute__ ((__format__ (__printf__, 2, 3)))
575 _GL_ARG_NONNULL ((1, 2)));
577 _GL_CXXALIAS_SYS (obstack_printf, int,
578 (struct obstack *obs, const char *format, ...));
580 _GL_CXXALIASWARN (obstack_printf);
581 # if @REPLACE_OBSTACK_PRINTF@
582 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
583 # define obstack_vprintf rpl_obstack_vprintf
585 _GL_FUNCDECL_RPL (obstack_vprintf, int,
586 (struct obstack *obs, const char *format, va_list args)
587 __attribute__ ((__format__ (__printf__, 2, 0)))
588 _GL_ARG_NONNULL ((1, 2)));
589 _GL_CXXALIAS_RPL (obstack_vprintf, int,
590 (struct obstack *obs, const char *format, va_list args));
592 # if !@HAVE_DECL_OBSTACK_PRINTF@
593 _GL_FUNCDECL_SYS (obstack_vprintf, int,
594 (struct obstack *obs, const char *format, va_list args)
595 __attribute__ ((__format__ (__printf__, 2, 0)))
596 _GL_ARG_NONNULL ((1, 2)));
598 _GL_CXXALIAS_SYS (obstack_vprintf, int,
599 (struct obstack *obs, const char *format, va_list args));
601 _GL_CXXALIASWARN (obstack_vprintf);
605 /* Print a message to standard error, describing the value of ERRNO,
606 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
607 and terminated with a newline. */
608 # if @REPLACE_PERROR@
609 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
610 # define perror rpl_perror
612 _GL_FUNCDECL_RPL (perror, void, (const char *string));
613 _GL_CXXALIAS_RPL (perror, void, (const char *string));
615 _GL_CXXALIAS_SYS (perror, void, (const char *string));
617 _GL_CXXALIASWARN (perror);
618 #elif defined GNULIB_POSIXCHECK
620 /* Assume perror is always declared. */
621 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
622 "use gnulib module perror for portability");
627 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
629 # define popen rpl_popen
631 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
632 _GL_ARG_NONNULL ((1, 2)));
633 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
635 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
637 _GL_CXXALIASWARN (popen);
638 #elif defined GNULIB_POSIXCHECK
640 # if HAVE_RAW_DECL_POPEN
641 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
642 "use gnulib module popen or pipe for more portability");
646 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
647 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
648 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
649 # if defined __GNUC__
650 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
651 /* Don't break __attribute__((format(printf,M,N))). */
652 # define printf __printf__
654 _GL_FUNCDECL_RPL_1 (__printf__, int,
655 (const char *format, ...)
656 __asm__ (@ASM_SYMBOL_PREFIX@
657 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
658 __attribute__ ((__format__ (__printf__, 1, 2)))
659 _GL_ARG_NONNULL ((1)));
660 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
662 _GL_FUNCDECL_RPL (printf, int,
663 (const char *format, ...)
664 __attribute__ ((__format__ (__printf__, 1, 2)))
665 _GL_ARG_NONNULL ((1)));
666 _GL_CXXALIAS_RPL (printf, int, (const char *format, ...));
668 # define GNULIB_overrides_printf 1
670 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
672 _GL_CXXALIASWARN (printf);
674 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
675 # if !GNULIB_overrides_printf
678 /* Assume printf is always declared. */
679 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
680 "use gnulib module printf-posix for portable "
685 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
688 # define putc rpl_fputc
690 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
691 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
693 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
695 _GL_CXXALIASWARN (putc);
699 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
700 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
702 # define putchar rpl_putchar
704 _GL_FUNCDECL_RPL (putchar, int, (int c));
705 _GL_CXXALIAS_RPL (putchar, int, (int c));
707 _GL_CXXALIAS_SYS (putchar, int, (int c));
709 _GL_CXXALIASWARN (putchar);
713 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
714 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
716 # define puts rpl_puts
718 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
719 _GL_CXXALIAS_RPL (puts, int, (const char *string));
721 _GL_CXXALIAS_SYS (puts, int, (const char *string));
723 _GL_CXXALIASWARN (puts);
727 # if @REPLACE_REMOVE@
728 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
730 # define remove rpl_remove
732 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
733 _GL_CXXALIAS_RPL (remove, int, (const char *name));
735 _GL_CXXALIAS_SYS (remove, int, (const char *name));
737 _GL_CXXALIASWARN (remove);
738 #elif defined GNULIB_POSIXCHECK
740 /* Assume remove is always declared. */
741 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
742 "use gnulib module remove for more portability");
746 # if @REPLACE_RENAME@
747 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
749 # define rename rpl_rename
751 _GL_FUNCDECL_RPL (rename, int,
752 (const char *old_filename, const char *new_filename)
753 _GL_ARG_NONNULL ((1, 2)));
754 _GL_CXXALIAS_RPL (rename, int,
755 (const char *old_filename, const char *new_filename));
757 _GL_CXXALIAS_SYS (rename, int,
758 (const char *old_filename, const char *new_filename));
760 _GL_CXXALIASWARN (rename);
761 #elif defined GNULIB_POSIXCHECK
763 /* Assume rename is always declared. */
764 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
765 "use gnulib module rename for more portability");
768 #if @GNULIB_RENAMEAT@
769 # if @REPLACE_RENAMEAT@
770 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
772 # define renameat rpl_renameat
774 _GL_FUNCDECL_RPL (renameat, int,
775 (int fd1, char const *file1, int fd2, char const *file2)
776 _GL_ARG_NONNULL ((2, 4)));
777 _GL_CXXALIAS_RPL (renameat, int,
778 (int fd1, char const *file1, int fd2, char const *file2));
780 # if !@HAVE_RENAMEAT@
781 _GL_FUNCDECL_SYS (renameat, int,
782 (int fd1, char const *file1, int fd2, char const *file2)
783 _GL_ARG_NONNULL ((2, 4)));
785 _GL_CXXALIAS_SYS (renameat, int,
786 (int fd1, char const *file1, int fd2, char const *file2));
788 _GL_CXXALIASWARN (renameat);
789 #elif defined GNULIB_POSIXCHECK
791 # if HAVE_RAW_DECL_RENAMEAT
792 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
793 "use gnulib module renameat for portability");
797 #if @GNULIB_SNPRINTF@
798 # if @REPLACE_SNPRINTF@
799 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
800 # define snprintf rpl_snprintf
802 _GL_FUNCDECL_RPL (snprintf, int,
803 (char *str, size_t size, const char *format, ...)
804 __attribute__ ((__format__ (__printf__, 3, 4)))
805 _GL_ARG_NONNULL ((3)));
806 _GL_CXXALIAS_RPL (snprintf, int,
807 (char *str, size_t size, const char *format, ...));
809 # if !@HAVE_DECL_SNPRINTF@
810 _GL_FUNCDECL_SYS (snprintf, int,
811 (char *str, size_t size, const char *format, ...)
812 __attribute__ ((__format__ (__printf__, 3, 4)))
813 _GL_ARG_NONNULL ((3)));
815 _GL_CXXALIAS_SYS (snprintf, int,
816 (char *str, size_t size, const char *format, ...));
818 _GL_CXXALIASWARN (snprintf);
819 #elif defined GNULIB_POSIXCHECK
821 # if HAVE_RAW_DECL_SNPRINTF
822 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
823 "use gnulib module snprintf for portability");
827 /* Some people would argue that sprintf should be handled like gets
828 (for example, OpenBSD issues a link warning for both functions),
829 since both can cause security holes due to buffer overruns.
830 However, we believe that sprintf can be used safely, and is more
831 efficient than snprintf in those safe cases; and as proof of our
832 belief, we use sprintf in several gnulib modules. So this header
833 intentionally avoids adding a warning to sprintf except when
834 GNULIB_POSIXCHECK is defined. */
836 #if @GNULIB_SPRINTF_POSIX@
837 # if @REPLACE_SPRINTF@
838 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
839 # define sprintf rpl_sprintf
841 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
842 __attribute__ ((__format__ (__printf__, 2, 3)))
843 _GL_ARG_NONNULL ((1, 2)));
844 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
846 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
848 _GL_CXXALIASWARN (sprintf);
849 #elif defined GNULIB_POSIXCHECK
851 /* Assume sprintf is always declared. */
852 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
853 "use gnulib module sprintf-posix for portable "
858 # if @REPLACE_TMPFILE@
859 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
860 # define tmpfile rpl_tmpfile
862 _GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
863 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
865 _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
867 _GL_CXXALIASWARN (tmpfile);
868 #elif defined GNULIB_POSIXCHECK
870 # if HAVE_RAW_DECL_TMPFILE
871 _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
872 "use gnulib module tmpfile for portability");
876 #if @GNULIB_VASPRINTF@
877 /* Write formatted output to a string dynamically allocated with malloc().
878 If the memory allocation succeeds, store the address of the string in
879 *RESULT and return the number of resulting bytes, excluding the trailing
880 NUL. Upon memory allocation error, or some other error, return -1. */
881 # if @REPLACE_VASPRINTF@
882 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
883 # define asprintf rpl_asprintf
885 _GL_FUNCDECL_RPL (asprintf, int,
886 (char **result, const char *format, ...)
887 __attribute__ ((__format__ (__printf__, 2, 3)))
888 _GL_ARG_NONNULL ((1, 2)));
889 _GL_CXXALIAS_RPL (asprintf, int,
890 (char **result, const char *format, ...));
892 # if !@HAVE_VASPRINTF@
893 _GL_FUNCDECL_SYS (asprintf, int,
894 (char **result, const char *format, ...)
895 __attribute__ ((__format__ (__printf__, 2, 3)))
896 _GL_ARG_NONNULL ((1, 2)));
898 _GL_CXXALIAS_SYS (asprintf, int,
899 (char **result, const char *format, ...));
901 _GL_CXXALIASWARN (asprintf);
902 # if @REPLACE_VASPRINTF@
903 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
904 # define vasprintf rpl_vasprintf
906 _GL_FUNCDECL_RPL (vasprintf, int,
907 (char **result, const char *format, va_list args)
908 __attribute__ ((__format__ (__printf__, 2, 0)))
909 _GL_ARG_NONNULL ((1, 2)));
910 _GL_CXXALIAS_RPL (vasprintf, int,
911 (char **result, const char *format, va_list args));
913 # if !@HAVE_VASPRINTF@
914 _GL_FUNCDECL_SYS (vasprintf, int,
915 (char **result, const char *format, va_list args)
916 __attribute__ ((__format__ (__printf__, 2, 0)))
917 _GL_ARG_NONNULL ((1, 2)));
919 _GL_CXXALIAS_SYS (vasprintf, int,
920 (char **result, const char *format, va_list args));
922 _GL_CXXALIASWARN (vasprintf);
925 #if @GNULIB_VDPRINTF@
926 # if @REPLACE_VDPRINTF@
927 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
928 # define vdprintf rpl_vdprintf
930 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
931 __attribute__ ((__format__ (__printf__, 2, 0)))
932 _GL_ARG_NONNULL ((2)));
933 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
935 # if !@HAVE_VDPRINTF@
936 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
937 __attribute__ ((__format__ (__printf__, 2, 0)))
938 _GL_ARG_NONNULL ((2)));
940 /* Need to cast, because on Solaris, the third parameter will likely be
942 _GL_CXXALIAS_SYS_CAST (vdprintf, int,
943 (int fd, const char *format, va_list args));
945 _GL_CXXALIASWARN (vdprintf);
946 #elif defined GNULIB_POSIXCHECK
948 # if HAVE_RAW_DECL_VDPRINTF
949 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
950 "use gnulib module vdprintf for portability");
954 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
955 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
956 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
957 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
958 # define vfprintf rpl_vfprintf
960 # define GNULIB_overrides_vfprintf 1
961 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
962 __attribute__ ((__format__ (__printf__, 2, 0)))
963 _GL_ARG_NONNULL ((1, 2)));
964 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
966 /* Need to cast, because on Solaris, the third parameter is
968 and GCC's fixincludes did not change this to __gnuc_va_list. */
969 _GL_CXXALIAS_SYS_CAST (vfprintf, int,
970 (FILE *fp, const char *format, va_list args));
972 _GL_CXXALIASWARN (vfprintf);
974 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
975 # if !GNULIB_overrides_vfprintf
978 /* Assume vfprintf is always declared. */
979 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
980 "use gnulib module vfprintf-posix for portable "
984 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
985 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
986 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
987 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
988 # define vprintf rpl_vprintf
990 # define GNULIB_overrides_vprintf 1
991 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
992 __attribute__ ((__format__ (__printf__, 1, 0)))
993 _GL_ARG_NONNULL ((1)));
994 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
996 /* Need to cast, because on Solaris, the second parameter is
998 and GCC's fixincludes did not change this to __gnuc_va_list. */
999 _GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
1001 _GL_CXXALIASWARN (vprintf);
1003 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1004 # if !GNULIB_overrides_vprintf
1007 /* Assume vprintf is always declared. */
1008 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1009 "use gnulib module vprintf-posix for portable "
1010 "POSIX compliance");
1013 #if @GNULIB_VSNPRINTF@
1014 # if @REPLACE_VSNPRINTF@
1015 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1016 # define vsnprintf rpl_vsnprintf
1018 _GL_FUNCDECL_RPL (vsnprintf, int,
1019 (char *str, size_t size, const char *format, va_list args)
1020 __attribute__ ((__format__ (__printf__, 3, 0)))
1021 _GL_ARG_NONNULL ((3)));
1022 _GL_CXXALIAS_RPL (vsnprintf, int,
1023 (char *str, size_t size, const char *format, va_list args));
1025 # if !@HAVE_DECL_VSNPRINTF@
1026 _GL_FUNCDECL_SYS (vsnprintf, int,
1027 (char *str, size_t size, const char *format, va_list args)
1028 __attribute__ ((__format__ (__printf__, 3, 0)))
1029 _GL_ARG_NONNULL ((3)));
1031 _GL_CXXALIAS_SYS (vsnprintf, int,
1032 (char *str, size_t size, const char *format, va_list args));
1034 _GL_CXXALIASWARN (vsnprintf);
1035 #elif defined GNULIB_POSIXCHECK
1037 # if HAVE_RAW_DECL_VSNPRINTF
1038 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1039 "use gnulib module vsnprintf for portability");
1043 #if @GNULIB_VSPRINTF_POSIX@
1044 # if @REPLACE_VSPRINTF@
1045 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1046 # define vsprintf rpl_vsprintf
1048 _GL_FUNCDECL_RPL (vsprintf, int,
1049 (char *str, const char *format, va_list args)
1050 __attribute__ ((__format__ (__printf__, 2, 0)))
1051 _GL_ARG_NONNULL ((1, 2)));
1052 _GL_CXXALIAS_RPL (vsprintf, int,
1053 (char *str, const char *format, va_list args));
1055 /* Need to cast, because on Solaris, the third parameter is
1057 and GCC's fixincludes did not change this to __gnuc_va_list. */
1058 _GL_CXXALIAS_SYS_CAST (vsprintf, int,
1059 (char *str, const char *format, va_list args));
1061 _GL_CXXALIASWARN (vsprintf);
1062 #elif defined GNULIB_POSIXCHECK
1064 /* Assume vsprintf is always declared. */
1065 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1066 "use gnulib module vsprintf-posix for portable "
1067 "POSIX compliance");
1071 #endif /* _GL_STDIO_H */
1072 #endif /* _GL_STDIO_H */