1 /* A GNU-like <stdio.h>.
3 Copyright (C) 2004, 2007-2009 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 /* Get off_t and ssize_t. */
47 # include <sys/types.h>
51 /* This feature is available in gcc versions 2.5 and later. */
52 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
53 # define __attribute__(Spec) /* empty */
55 /* The __-protected variants of `format' and `printf' attributes
56 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
57 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
58 # define __format__ format
59 # define __printf__ printf
64 /* The definition of GL_LINK_WARNING is copied here. */
72 # if @REPLACE_DPRINTF@
73 # define dprintf rpl_dprintf
75 # if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
76 extern int dprintf (int fd, const char *format, ...)
77 __attribute__ ((__format__ (__printf__, 2, 3)));
79 #elif defined GNULIB_POSIXCHECK
81 # define dprintf(d,f,a) \
82 (GL_LINK_WARNING ("dprintf is unportable - " \
83 "use gnulib module dprintf for portability"), \
89 # define fclose rpl_fclose
90 /* Close STREAM and its underlying file descriptor. */
91 extern int fclose (FILE *stream);
93 #elif defined GNULIB_POSIXCHECK
96 (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
97 "use gnulib module fclose for portable " \
98 "POSIX compliance"), \
103 # if @REPLACE_FFLUSH@
104 # define fflush rpl_fflush
105 /* Flush all pending data on STREAM according to POSIX rules. Both
106 output and seekable input streams are supported.
107 Note! LOSS OF DATA can occur if fflush is applied on an input stream
108 that is _not_seekable_ or on an update stream that is _not_seekable_
109 and in which the most recent operation was input. Seekability can
110 be tested with lseek(fileno(fp),0,SEEK_CUR). */
111 extern int fflush (FILE *gl_stream);
113 #elif defined GNULIB_POSIXCHECK
116 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
117 "use gnulib module fflush for portable " \
118 "POSIX compliance"), \
125 # define fopen rpl_fopen
126 extern FILE * fopen (const char *filename, const char *mode);
128 #elif defined GNULIB_POSIXCHECK
130 # define fopen(f,m) \
131 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
132 "use gnulib module fopen for portability"), \
136 #if @GNULIB_FPRINTF_POSIX@
137 # if @REPLACE_FPRINTF@
138 # define fprintf rpl_fprintf
139 extern int fprintf (FILE *fp, const char *format, ...)
140 __attribute__ ((__format__ (__printf__, 2, 3)));
142 #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
143 # define fprintf rpl_fprintf
144 extern int fprintf (FILE *fp, const char *format, ...)
145 __attribute__ ((__format__ (__printf__, 2, 3)));
146 #elif defined GNULIB_POSIXCHECK
149 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
150 "use gnulib module fprintf-posix for portable " \
151 "POSIX compliance"), \
156 # if @REPLACE_FPURGE@
157 # define fpurge rpl_fpurge
159 # if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
160 /* Discard all pending buffered I/O data on STREAM.
161 STREAM must not be wide-character oriented.
162 When discarding pending output, the file position is set back to where it
163 was before the write calls. When discarding pending input, the file
164 position is advanced to match the end of the previously read input.
165 Return 0 if successful. Upon error, return -1 and set errno. */
166 extern int fpurge (FILE *gl_stream);
168 #elif defined GNULIB_POSIXCHECK
171 (GL_LINK_WARNING ("fpurge is not always present - " \
172 "use gnulib module fpurge for portability"), \
176 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
178 # define fputc rpl_fputc
179 extern int fputc (int c, FILE *stream);
182 #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
184 # define fputs rpl_fputs
185 extern int fputs (const char *string, FILE *stream);
189 # if @REPLACE_FREOPEN@
191 # define freopen rpl_freopen
192 extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
194 #elif defined GNULIB_POSIXCHECK
196 # define freopen(f,m,s) \
197 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
198 "use gnulib module freopen for portability"), \
202 #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
203 extern int rpl_fseek (FILE *fp, long offset, int whence);
205 # if defined GNULIB_POSIXCHECK
206 # define fseek(f,o,w) \
207 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
208 "on 32-bit platforms - " \
209 "use fseeko function for handling of large files"), \
212 # define fseek rpl_fseek
214 #elif defined GNULIB_POSIXCHECK
216 # define fseek(f,o,w) \
217 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
218 "on 32-bit platforms - " \
219 "use fseeko function for handling of large files"), \
225 # if @REPLACE_FSEEKO@
226 /* Provide fseek, fseeko functions that are aware of a preceding
227 fflush(), and which detect pipes. */
228 # define fseeko rpl_fseeko
229 extern int fseeko (FILE *fp, off_t offset, int whence);
232 # define fseek(f,o,w) \
233 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
234 "on 32-bit platforms - " \
235 "use fseeko function for handling of large files"), \
239 #elif defined GNULIB_POSIXCHECK
241 # define fseeko(f,o,w) \
242 (GL_LINK_WARNING ("fseeko is unportable - " \
243 "use gnulib module fseeko for portability"), \
247 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
248 extern long rpl_ftell (FILE *fp);
250 # if GNULIB_POSIXCHECK
252 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
253 "on 32-bit platforms - " \
254 "use ftello function for handling of large files"), \
257 # define ftell rpl_ftell
259 #elif defined GNULIB_POSIXCHECK
262 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
263 "on 32-bit platforms - " \
264 "use ftello function for handling of large files"), \
270 # if @REPLACE_FTELLO@
271 # define ftello rpl_ftello
272 extern off_t ftello (FILE *fp);
276 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
277 "on 32-bit platforms - " \
278 "use ftello function for handling of large files"), \
282 #elif defined GNULIB_POSIXCHECK
285 (GL_LINK_WARNING ("ftello is unportable - " \
286 "use gnulib module ftello for portability"), \
290 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
292 # define fwrite rpl_fwrite
293 extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
296 #if @GNULIB_GETDELIM@
297 # if !@HAVE_DECL_GETDELIM@
298 /* Read input, up to (and including) the next occurrence of DELIMITER, from
299 STREAM, store it in *LINEPTR (and NUL-terminate it).
300 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
301 bytes of space. It is realloc'd as necessary.
302 Return the number of bytes read and stored at *LINEPTR (not including the
303 NUL terminator), or -1 on error or EOF. */
304 extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
307 #elif defined GNULIB_POSIXCHECK
309 # define getdelim(l, s, d, f) \
310 (GL_LINK_WARNING ("getdelim is unportable - " \
311 "use gnulib module getdelim for portability"), \
312 getdelim (l, s, d, f))
316 # if @REPLACE_GETLINE@
318 # define getline rpl_getline
320 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
321 /* Read a line, up to (and including) the next newline, from STREAM, store it
322 in *LINEPTR (and NUL-terminate it).
323 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
324 bytes of space. It is realloc'd as necessary.
325 Return the number of bytes read and stored at *LINEPTR (not including the
326 NUL terminator), or -1 on error or EOF. */
327 extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
329 #elif defined GNULIB_POSIXCHECK
331 # define getline(l, s, f) \
332 (GL_LINK_WARNING ("getline is unportable - " \
333 "use gnulib module getline for portability"), \
337 #if @GNULIB_OBSTACK_PRINTF@
338 # if @REPLACE_OBSTACK_PRINTF@
339 # define obstack_printf rpl_osbtack_printf
340 # define obstack_vprintf rpl_obstack_vprintf
342 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
344 /* Grow an obstack with formatted output. Return the number of
345 bytes added to OBS. No trailing nul byte is added, and the
346 object should be closed with obstack_finish before use. Upon
347 memory allocation error, call obstack_alloc_failed_handler. Upon
348 other error, return -1. */
349 extern int obstack_printf (struct obstack *obs, const char *format, ...)
350 __attribute__ ((__format__ (__printf__, 2, 3)));
351 extern int obstack_vprintf (struct obstack *obs, const char *format,
353 __attribute__ ((__format__ (__printf__, 2, 0)));
358 # if @REPLACE_PERROR@
359 # define perror rpl_perror
360 /* Print a message to standard error, describing the value of ERRNO,
361 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
362 and terminated with a newline. */
363 extern void perror (const char *string);
365 #elif defined GNULIB_POSIXCHECK
368 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
369 "use gnulib module perror for portability"), \
376 # define popen rpl_popen
377 extern FILE *popen (const char *cmd, const char *mode);
379 #elif defined GNULIB_POSIXCHECK
381 # define popen(c,m) \
382 (GL_LINK_WARNING ("popen is buggy on some platforms - " \
383 "use gnulib module popen or pipe for more portability"), \
387 #if @GNULIB_PRINTF_POSIX@
388 # if @REPLACE_PRINTF@
389 /* Don't break __attribute__((format(printf,M,N))). */
390 # define printf __printf__
391 extern int printf (const char *format, ...)
392 __attribute__ ((__format__ (__printf__, 1, 2)));
394 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
395 /* Don't break __attribute__((format(printf,M,N))). */
396 # define printf __printf__
397 extern int printf (const char *format, ...)
398 __attribute__ ((__format__ (__printf__, 1, 2)));
399 #elif defined GNULIB_POSIXCHECK
402 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
403 "use gnulib module printf-posix for portable " \
404 "POSIX compliance"), \
406 /* Don't break __attribute__((format(printf,M,N))). */
407 # define format(kind,m,n) format (__##kind##__, m, n)
408 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
409 # define ____printf____ __printf__
410 # define ____scanf____ __scanf__
411 # define ____strftime____ __strftime__
412 # define ____strfmon____ __strfmon__
415 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
417 # define putc rpl_fputc
418 extern int putc (int c, FILE *stream);
421 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
423 # define putchar rpl_putchar
424 extern int putchar (int c);
427 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
429 # define puts rpl_puts
430 extern int puts (const char *string);
434 # if @REPLACE_REMOVE@
436 # define remove rpl_remove
437 extern int remove (const char *name);
439 #elif defined GNULIB_POSIXCHECK
442 (GL_LINK_WARNING ("remove cannot handle directories on some platforms - " \
443 "use gnulib module remove for more portability"), \
448 # if @REPLACE_RENAME@
450 # define rename rpl_rename
451 extern int rename (const char *old, const char *new);
453 #elif defined GNULIB_POSIXCHECK
455 # define rename(o,n) \
456 (GL_LINK_WARNING ("rename is buggy on some platforms - " \
457 "use gnulib module rename for more portability"), \
461 #if @GNULIB_RENAMEAT@
462 # if @REPLACE_RENAMEAT@
464 # define renameat rpl_renameat
466 # if !@HAVE_RENAMEAT@ || @REPLACE_RENAMEAT@
467 extern int renameat (int fd1, char const *file1, int fd2, char const *file2);
469 #elif defined GNULIB_POSIXCHECK
471 # define renameat(d1,f1,d2,f2) \
472 (GL_LINK_WARNING ("renameat is not portable - " \
473 "use gnulib module renameat for portability"), \
474 renameat (d1, f1, d2, f2))
477 #if @GNULIB_SNPRINTF@
478 # if @REPLACE_SNPRINTF@
479 # define snprintf rpl_snprintf
481 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
482 extern int snprintf (char *str, size_t size, const char *format, ...)
483 __attribute__ ((__format__ (__printf__, 3, 4)));
485 #elif defined GNULIB_POSIXCHECK
488 (GL_LINK_WARNING ("snprintf is unportable - " \
489 "use gnulib module snprintf for portability"), \
493 #if @GNULIB_SPRINTF_POSIX@
494 # if @REPLACE_SPRINTF@
495 # define sprintf rpl_sprintf
496 extern int sprintf (char *str, const char *format, ...)
497 __attribute__ ((__format__ (__printf__, 2, 3)));
499 #elif defined GNULIB_POSIXCHECK
502 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
503 "use gnulib module sprintf-posix for portable " \
504 "POSIX compliance"), \
508 #if @GNULIB_VASPRINTF@
509 # if @REPLACE_VASPRINTF@
510 # define asprintf rpl_asprintf
511 # define vasprintf rpl_vasprintf
513 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
514 /* Write formatted output to a string dynamically allocated with malloc().
515 If the memory allocation succeeds, store the address of the string in
516 *RESULT and return the number of resulting bytes, excluding the trailing
517 NUL. Upon memory allocation error, or some other error, return -1. */
518 extern int asprintf (char **result, const char *format, ...)
519 __attribute__ ((__format__ (__printf__, 2, 3)));
520 extern int vasprintf (char **result, const char *format, va_list args)
521 __attribute__ ((__format__ (__printf__, 2, 0)));
525 #if @GNULIB_VDPRINTF@
526 # if @REPLACE_VDPRINTF@
527 # define vdprintf rpl_vdprintf
529 # if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
530 extern int vdprintf (int fd, const char *format, va_list args)
531 __attribute__ ((__format__ (__printf__, 2, 0)));
533 #elif defined GNULIB_POSIXCHECK
535 # define vdprintf(d,f,a) \
536 (GL_LINK_WARNING ("vdprintf is unportable - " \
537 "use gnulib module vdprintf for portability"), \
541 #if @GNULIB_VFPRINTF_POSIX@
542 # if @REPLACE_VFPRINTF@
543 # define vfprintf rpl_vfprintf
544 extern int vfprintf (FILE *fp, const char *format, va_list args)
545 __attribute__ ((__format__ (__printf__, 2, 0)));
547 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
548 # define vfprintf rpl_vfprintf
549 extern int vfprintf (FILE *fp, const char *format, va_list args)
550 __attribute__ ((__format__ (__printf__, 2, 0)));
551 #elif defined GNULIB_POSIXCHECK
553 # define vfprintf(s,f,a) \
554 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
555 "use gnulib module vfprintf-posix for portable " \
556 "POSIX compliance"), \
560 #if @GNULIB_VPRINTF_POSIX@
561 # if @REPLACE_VPRINTF@
562 # define vprintf rpl_vprintf
563 extern int vprintf (const char *format, va_list args)
564 __attribute__ ((__format__ (__printf__, 1, 0)));
566 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
567 # define vprintf rpl_vprintf
568 extern int vprintf (const char *format, va_list args)
569 __attribute__ ((__format__ (__printf__, 1, 0)));
570 #elif defined GNULIB_POSIXCHECK
572 # define vprintf(f,a) \
573 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
574 "use gnulib module vprintf-posix for portable " \
575 "POSIX compliance"), \
579 #if @GNULIB_VSNPRINTF@
580 # if @REPLACE_VSNPRINTF@
581 # define vsnprintf rpl_vsnprintf
583 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
584 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
585 __attribute__ ((__format__ (__printf__, 3, 0)));
587 #elif defined GNULIB_POSIXCHECK
589 # define vsnprintf(b,s,f,a) \
590 (GL_LINK_WARNING ("vsnprintf is unportable - " \
591 "use gnulib module vsnprintf for portability"), \
592 vsnprintf (b, s, f, a))
595 #if @GNULIB_VSPRINTF_POSIX@
596 # if @REPLACE_VSPRINTF@
597 # define vsprintf rpl_vsprintf
598 extern int vsprintf (char *str, const char *format, va_list args)
599 __attribute__ ((__format__ (__printf__, 2, 0)));
601 #elif defined GNULIB_POSIXCHECK
603 # define vsprintf(b,f,a) \
604 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
605 "use gnulib module vsprintf-posix for portable " \
606 "POSIX compliance"), \
614 #endif /* _GL_STDIO_H */
615 #endif /* _GL_STDIO_H */