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@
42 #if ((@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
43 || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
44 || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
45 || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@)) \
46 || defined GNULIB_POSIXCHECK)
47 /* Get off_t and ssize_t. */
48 # include <sys/types.h>
52 /* This feature is available in gcc versions 2.5 and later. */
53 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
54 # define __attribute__(Spec) /* empty */
56 /* The __-protected variants of `format' and `printf' attributes
57 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
58 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
59 # define __format__ format
60 # define __printf__ printf
65 /* The definition of GL_LINK_WARNING is copied here. */
67 /* The definition of _GL_ARG_NONNULL is copied here. */
75 # if @REPLACE_DPRINTF@
76 # define dprintf rpl_dprintf
78 # if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
79 extern int dprintf (int fd, const char *format, ...)
80 __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((2));
82 #elif defined GNULIB_POSIXCHECK
85 (GL_LINK_WARNING ("dprintf is unportable - " \
86 "use gnulib module dprintf for portability"), \
92 # define fclose rpl_fclose
93 /* Close STREAM and its underlying file descriptor. */
94 extern int fclose (FILE *stream) _GL_ARG_NONNULL ((1));
96 #elif defined GNULIB_POSIXCHECK
99 (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
100 "use gnulib module fclose for portable " \
101 "POSIX compliance"), \
106 # if @REPLACE_FFLUSH@
107 # define fflush rpl_fflush
108 /* Flush all pending data on STREAM according to POSIX rules. Both
109 output and seekable input streams are supported.
110 Note! LOSS OF DATA can occur if fflush is applied on an input stream
111 that is _not_seekable_ or on an update stream that is _not_seekable_
112 and in which the most recent operation was input. Seekability can
113 be tested with lseek(fileno(fp),0,SEEK_CUR). */
114 extern int fflush (FILE *gl_stream);
116 #elif defined GNULIB_POSIXCHECK
119 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
120 "use gnulib module fflush for portable " \
121 "POSIX compliance"), \
128 # define fopen rpl_fopen
129 extern FILE * fopen (const char *filename, const char *mode)
130 _GL_ARG_NONNULL ((1, 2));
132 #elif defined GNULIB_POSIXCHECK
134 # define fopen(f,m) \
135 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
136 "use gnulib module fopen for portability"), \
140 #if @GNULIB_FPRINTF_POSIX@
141 # if @REPLACE_FPRINTF@
142 # define fprintf rpl_fprintf
143 extern int fprintf (FILE *fp, const char *format, ...)
144 __attribute__ ((__format__ (__printf__, 2, 3)))
145 _GL_ARG_NONNULL ((1, 2));
147 #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
148 # define fprintf rpl_fprintf
149 extern int fprintf (FILE *fp, const char *format, ...)
150 __attribute__ ((__format__ (__printf__, 2, 3)))
151 _GL_ARG_NONNULL ((1, 2));
152 #elif defined GNULIB_POSIXCHECK
155 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
156 "use gnulib module fprintf-posix for portable " \
157 "POSIX compliance"), \
162 # if @REPLACE_FPURGE@
163 # define fpurge rpl_fpurge
165 # if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
166 /* Discard all pending buffered I/O data on STREAM.
167 STREAM must not be wide-character oriented.
168 When discarding pending output, the file position is set back to where it
169 was before the write calls. When discarding pending input, the file
170 position is advanced to match the end of the previously read input.
171 Return 0 if successful. Upon error, return -1 and set errno. */
172 extern int fpurge (FILE *gl_stream) _GL_ARG_NONNULL ((1));
174 #elif defined GNULIB_POSIXCHECK
177 (GL_LINK_WARNING ("fpurge is not always present - " \
178 "use gnulib module fpurge for portability"), \
182 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
184 # define fputc rpl_fputc
185 extern int fputc (int c, FILE *stream) _GL_ARG_NONNULL ((2));
188 #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
190 # define fputs rpl_fputs
191 extern int fputs (const char *string, FILE *stream) _GL_ARG_NONNULL ((1, 2));
195 # if @REPLACE_FREOPEN@
197 # define freopen rpl_freopen
198 extern FILE * freopen (const char *filename, const char *mode, FILE *stream)
199 _GL_ARG_NONNULL ((2, 3));
201 #elif defined GNULIB_POSIXCHECK
203 # define freopen(f,m,s) \
204 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
205 "use gnulib module freopen for portability"), \
209 #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
210 extern int rpl_fseek (FILE *fp, long offset, int whence) _GL_ARG_NONNULL ((1));
212 # if defined GNULIB_POSIXCHECK
213 # define fseek(f,o,w) \
214 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
215 "on 32-bit platforms - " \
216 "use fseeko function for handling of large files"), \
219 # define fseek rpl_fseek
221 #elif defined GNULIB_POSIXCHECK
223 # define fseek(f,o,w) \
224 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
225 "on 32-bit platforms - " \
226 "use fseeko function for handling of large files"), \
232 # if @REPLACE_FSEEKO@
233 /* Provide fseek, fseeko functions that are aware of a preceding
234 fflush(), and which detect pipes. */
235 # define fseeko rpl_fseeko
236 extern int fseeko (FILE *fp, off_t offset, int whence) _GL_ARG_NONNULL ((1));
239 # define fseek(f,o,w) \
240 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
241 "on 32-bit platforms - " \
242 "use fseeko function for handling of large files"), \
246 #elif defined GNULIB_POSIXCHECK
248 # define fseeko(f,o,w) \
249 (GL_LINK_WARNING ("fseeko is unportable - " \
250 "use gnulib module fseeko for portability"), \
254 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
255 extern long rpl_ftell (FILE *fp) _GL_ARG_NONNULL ((1));
257 # if GNULIB_POSIXCHECK
259 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
260 "on 32-bit platforms - " \
261 "use ftello function for handling of large files"), \
264 # define ftell rpl_ftell
266 #elif defined GNULIB_POSIXCHECK
269 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
270 "on 32-bit platforms - " \
271 "use ftello function for handling of large files"), \
277 # if @REPLACE_FTELLO@
278 # define ftello rpl_ftello
279 extern off_t ftello (FILE *fp) _GL_ARG_NONNULL ((1));
283 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
284 "on 32-bit platforms - " \
285 "use ftello function for handling of large files"), \
289 #elif defined GNULIB_POSIXCHECK
292 (GL_LINK_WARNING ("ftello is unportable - " \
293 "use gnulib module ftello for portability"), \
297 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
299 # define fwrite rpl_fwrite
300 extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
301 _GL_ARG_NONNULL ((1, 4));
304 #if @GNULIB_GETDELIM@
305 # if !@HAVE_DECL_GETDELIM@
306 /* Read input, up to (and including) the next occurrence of DELIMITER, from
307 STREAM, store it in *LINEPTR (and NUL-terminate it).
308 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
309 bytes of space. It is realloc'd as necessary.
310 Return the number of bytes read and stored at *LINEPTR (not including the
311 NUL terminator), or -1 on error or EOF. */
312 extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
314 _GL_ARG_NONNULL ((1, 2, 4));
316 #elif defined GNULIB_POSIXCHECK
318 # define getdelim(l, s, d, f) \
319 (GL_LINK_WARNING ("getdelim is unportable - " \
320 "use gnulib module getdelim for portability"), \
321 getdelim (l, s, d, f))
325 # if @REPLACE_GETLINE@
327 # define getline rpl_getline
329 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
330 /* Read a line, up to (and including) the next newline, from STREAM, store it
331 in *LINEPTR (and NUL-terminate it).
332 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
333 bytes of space. It is realloc'd as necessary.
334 Return the number of bytes read and stored at *LINEPTR (not including the
335 NUL terminator), or -1 on error or EOF. */
336 extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream)
337 _GL_ARG_NONNULL ((1, 2, 3));
339 #elif defined GNULIB_POSIXCHECK
341 # define getline(l, s, f) \
342 (GL_LINK_WARNING ("getline is unportable - " \
343 "use gnulib module getline for portability"), \
347 #if @GNULIB_OBSTACK_PRINTF@
348 # if @REPLACE_OBSTACK_PRINTF@
349 # define obstack_printf rpl_osbtack_printf
350 # define obstack_vprintf rpl_obstack_vprintf
352 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
354 /* Grow an obstack with formatted output. Return the number of
355 bytes added to OBS. No trailing nul byte is added, and the
356 object should be closed with obstack_finish before use. Upon
357 memory allocation error, call obstack_alloc_failed_handler. Upon
358 other error, return -1. */
359 extern int obstack_printf (struct obstack *obs, const char *format, ...)
360 __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((1, 2));
361 extern int obstack_vprintf (struct obstack *obs, const char *format,
363 __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((1, 2));
368 # if @REPLACE_PERROR@
369 # define perror rpl_perror
370 /* Print a message to standard error, describing the value of ERRNO,
371 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
372 and terminated with a newline. */
373 extern void perror (const char *string);
375 #elif defined GNULIB_POSIXCHECK
378 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
379 "use gnulib module perror for portability"), \
386 # define popen rpl_popen
387 extern FILE *popen (const char *cmd, const char *mode)
388 _GL_ARG_NONNULL ((1, 2));
390 #elif defined GNULIB_POSIXCHECK
392 # define popen(c,m) \
393 (GL_LINK_WARNING ("popen is buggy on some platforms - " \
394 "use gnulib module popen or pipe for more portability"), \
398 #if @GNULIB_PRINTF_POSIX@
399 # if @REPLACE_PRINTF@
400 /* Don't break __attribute__((format(printf,M,N))). */
401 # define printf __printf__
402 extern int printf (const char *format, ...)
403 __attribute__ ((__format__ (__printf__, 1, 2))) _GL_ARG_NONNULL ((1));
405 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
406 /* Don't break __attribute__((format(printf,M,N))). */
407 # define printf __printf__
408 extern int printf (const char *format, ...)
409 __attribute__ ((__format__ (__printf__, 1, 2))) _GL_ARG_NONNULL ((1));
410 #elif defined GNULIB_POSIXCHECK
413 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
414 "use gnulib module printf-posix for portable " \
415 "POSIX compliance"), \
417 /* Don't break __attribute__((format(printf,M,N))). */
418 # define format(kind,m,n) format (__##kind##__, m, n)
419 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
420 # define ____printf____ __printf__
421 # define ____scanf____ __scanf__
422 # define ____strftime____ __strftime__
423 # define ____strfmon____ __strfmon__
426 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
428 # define putc rpl_fputc
429 extern int putc (int c, FILE *stream) _GL_ARG_NONNULL ((2));
432 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
434 # define putchar rpl_putchar
435 extern int putchar (int c);
438 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
440 # define puts rpl_puts
441 extern int puts (const char *string) _GL_ARG_NONNULL ((1));
445 # if @REPLACE_REMOVE@
447 # define remove rpl_remove
448 extern int remove (const char *name) _GL_ARG_NONNULL ((1));
450 #elif defined GNULIB_POSIXCHECK
453 (GL_LINK_WARNING ("remove cannot handle directories on some platforms - " \
454 "use gnulib module remove for more portability"), \
459 # if @REPLACE_RENAME@
461 # define rename rpl_rename
462 extern int rename (const char *old_filename, const char *new_filename)
463 _GL_ARG_NONNULL ((1, 2));
465 #elif defined GNULIB_POSIXCHECK
467 # define rename(o,n) \
468 (GL_LINK_WARNING ("rename is buggy on some platforms - " \
469 "use gnulib module rename for more portability"), \
473 #if @GNULIB_RENAMEAT@
474 # if @REPLACE_RENAMEAT@
476 # define renameat rpl_renameat
478 # if !@HAVE_RENAMEAT@ || @REPLACE_RENAMEAT@
479 extern int renameat (int fd1, char const *file1, int fd2, char const *file2)
480 _GL_ARG_NONNULL ((2, 4));
482 #elif defined GNULIB_POSIXCHECK
484 # define renameat(d1,f1,d2,f2) \
485 (GL_LINK_WARNING ("renameat is not portable - " \
486 "use gnulib module renameat for portability"), \
487 renameat (d1, f1, d2, f2))
490 #if @GNULIB_SNPRINTF@
491 # if @REPLACE_SNPRINTF@
492 # define snprintf rpl_snprintf
494 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
495 extern int snprintf (char *str, size_t size, const char *format, ...)
496 __attribute__ ((__format__ (__printf__, 3, 4)))
497 _GL_ARG_NONNULL ((3));
499 #elif defined GNULIB_POSIXCHECK
502 (GL_LINK_WARNING ("snprintf is unportable - " \
503 "use gnulib module snprintf for portability"), \
507 #if @GNULIB_SPRINTF_POSIX@
508 # if @REPLACE_SPRINTF@
509 # define sprintf rpl_sprintf
510 extern int sprintf (char *str, const char *format, ...)
511 __attribute__ ((__format__ (__printf__, 2, 3)))
512 _GL_ARG_NONNULL ((1, 2));
514 #elif defined GNULIB_POSIXCHECK
517 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
518 "use gnulib module sprintf-posix for portable " \
519 "POSIX compliance"), \
523 #if @GNULIB_VASPRINTF@
524 # if @REPLACE_VASPRINTF@
525 # define asprintf rpl_asprintf
526 # define vasprintf rpl_vasprintf
528 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
529 /* Write formatted output to a string dynamically allocated with malloc().
530 If the memory allocation succeeds, store the address of the string in
531 *RESULT and return the number of resulting bytes, excluding the trailing
532 NUL. Upon memory allocation error, or some other error, return -1. */
533 extern int asprintf (char **result, const char *format, ...)
534 __attribute__ ((__format__ (__printf__, 2, 3))) _GL_ARG_NONNULL ((1, 2));
535 extern int vasprintf (char **result, const char *format, va_list args)
536 __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((1, 2));
540 #if @GNULIB_VDPRINTF@
541 # if @REPLACE_VDPRINTF@
542 # define vdprintf rpl_vdprintf
544 # if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
545 extern int vdprintf (int fd, const char *format, va_list args)
546 __attribute__ ((__format__ (__printf__, 2, 0))) _GL_ARG_NONNULL ((2));
548 #elif defined GNULIB_POSIXCHECK
550 # define vdprintf(d,f,a) \
551 (GL_LINK_WARNING ("vdprintf is unportable - " \
552 "use gnulib module vdprintf for portability"), \
556 #if @GNULIB_VFPRINTF_POSIX@
557 # if @REPLACE_VFPRINTF@
558 # define vfprintf rpl_vfprintf
559 extern int vfprintf (FILE *fp, const char *format, va_list args)
560 __attribute__ ((__format__ (__printf__, 2, 0)))
561 _GL_ARG_NONNULL ((1, 2));
563 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
564 # define vfprintf rpl_vfprintf
565 extern int vfprintf (FILE *fp, const char *format, va_list args)
566 __attribute__ ((__format__ (__printf__, 2, 0)))
567 _GL_ARG_NONNULL ((1, 2));
568 #elif defined GNULIB_POSIXCHECK
570 # define vfprintf(s,f,a) \
571 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
572 "use gnulib module vfprintf-posix for portable " \
573 "POSIX compliance"), \
577 #if @GNULIB_VPRINTF_POSIX@
578 # if @REPLACE_VPRINTF@
579 # define vprintf rpl_vprintf
580 extern int vprintf (const char *format, va_list args)
581 __attribute__ ((__format__ (__printf__, 1, 0))) _GL_ARG_NONNULL ((1));
583 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
584 # define vprintf rpl_vprintf
585 extern int vprintf (const char *format, va_list args)
586 __attribute__ ((__format__ (__printf__, 1, 0))) _GL_ARG_NONNULL ((1));
587 #elif defined GNULIB_POSIXCHECK
589 # define vprintf(f,a) \
590 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
591 "use gnulib module vprintf-posix for portable " \
592 "POSIX compliance"), \
596 #if @GNULIB_VSNPRINTF@
597 # if @REPLACE_VSNPRINTF@
598 # define vsnprintf rpl_vsnprintf
600 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
601 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
602 __attribute__ ((__format__ (__printf__, 3, 0)))
603 _GL_ARG_NONNULL ((3));
605 #elif defined GNULIB_POSIXCHECK
607 # define vsnprintf(b,s,f,a) \
608 (GL_LINK_WARNING ("vsnprintf is unportable - " \
609 "use gnulib module vsnprintf for portability"), \
610 vsnprintf (b, s, f, a))
613 #if @GNULIB_VSPRINTF_POSIX@
614 # if @REPLACE_VSPRINTF@
615 # define vsprintf rpl_vsprintf
616 extern int vsprintf (char *str, const char *format, va_list args)
617 __attribute__ ((__format__ (__printf__, 2, 0)))
618 _GL_ARG_NONNULL ((1, 2));
620 #elif defined GNULIB_POSIXCHECK
622 # define vsprintf(b,f,a) \
623 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
624 "use gnulib module vsprintf-posix for portable " \
625 "POSIX compliance"), \
633 #endif /* _GL_STDIO_H */
634 #endif /* _GL_STDIO_H */