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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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
);
230 # define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
232 #elif defined GNULIB_POSIXCHECK
234 # define fseeko(f,o,w) \
235 (GL_LINK_WARNING ("fseeko is unportable - " \
236 "use gnulib module fseeko for portability"), \
240 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
241 extern long rpl_ftell (FILE *fp
);
243 # if GNULIB_POSIXCHECK
245 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
246 "on 32-bit platforms - " \
247 "use ftello function for handling of large files"), \
250 # define ftell rpl_ftell
252 #elif defined GNULIB_POSIXCHECK
255 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
256 "on 32-bit platforms - " \
257 "use ftello function for handling of large files"), \
263 # if @REPLACE_FTELLO@
264 # define ftello rpl_ftello
265 extern off_t
ftello (FILE *fp
);
266 # define ftell(fp) ftello (fp)
268 #elif defined GNULIB_POSIXCHECK
271 (GL_LINK_WARNING ("ftello is unportable - " \
272 "use gnulib module ftello for portability"), \
276 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
278 # define fwrite rpl_fwrite
279 extern size_t fwrite (const void *ptr
, size_t s
, size_t n
, FILE *stream
);
282 #if @GNULIB_GETDELIM@
283 # if !@HAVE_DECL_GETDELIM@
284 /* Read input, up to (and including) the next occurrence of DELIMITER, from
285 STREAM, store it in *LINEPTR (and NUL-terminate it).
286 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
287 bytes of space. It is realloc'd as necessary.
288 Return the number of bytes read and stored at *LINEPTR (not including the
289 NUL terminator), or -1 on error or EOF. */
290 extern ssize_t
getdelim (char **lineptr
, size_t *linesize
, int delimiter
,
293 #elif defined GNULIB_POSIXCHECK
295 # define getdelim(l, s, d, f) \
296 (GL_LINK_WARNING ("getdelim is unportable - " \
297 "use gnulib module getdelim for portability"), \
298 getdelim (l, s, d, f))
302 # if @REPLACE_GETLINE@
304 # define getline rpl_getline
306 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
307 /* Read a line, up to (and including) the next newline, from STREAM, store it
308 in *LINEPTR (and NUL-terminate it).
309 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
310 bytes of space. It is realloc'd as necessary.
311 Return the number of bytes read and stored at *LINEPTR (not including the
312 NUL terminator), or -1 on error or EOF. */
313 extern ssize_t
getline (char **lineptr
, size_t *linesize
, FILE *stream
);
315 #elif defined GNULIB_POSIXCHECK
317 # define getline(l, s, f) \
318 (GL_LINK_WARNING ("getline is unportable - " \
319 "use gnulib module getline for portability"), \
323 #if @GNULIB_OBSTACK_PRINTF@
324 # if @REPLACE_OBSTACK_PRINTF@
325 # define obstack_printf rpl_osbtack_printf
326 # define obstack_vprintf rpl_obstack_vprintf
328 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
330 /* Grow an obstack with formatted output. Return the number of
331 bytes added to OBS. No trailing nul byte is added, and the
332 object should be closed with obstack_finish before use. Upon
333 memory allocation error, call obstack_alloc_failed_handler. Upon
334 other error, return -1. */
335 extern int obstack_printf (struct obstack
*obs
, const char *format
, ...)
336 __attribute__ ((__format__ (__printf__
, 2, 3)));
337 extern int obstack_vprintf (struct obstack
*obs
, const char *format
,
339 __attribute__ ((__format__ (__printf__
, 2, 0)));
344 # if @REPLACE_PERROR@
345 # define perror rpl_perror
346 /* Print a message to standard error, describing the value of ERRNO,
347 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
348 and terminated with a newline. */
349 extern void perror (const char *string
);
351 #elif defined GNULIB_POSIXCHECK
354 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
355 "use gnulib module perror for portability"), \
362 # define popen rpl_popen
363 extern FILE *popen (const char *cmd
, const char *mode
);
365 #elif defined GNULIB_POSIXCHECK
367 # define popen(c,m) \
368 (GL_LINK_WARNING ("popen is buggy on some platforms - " \
369 "use gnulib module popen or pipe for more portability"), \
373 #if @GNULIB_PRINTF_POSIX@
374 # if @REPLACE_PRINTF@
375 /* Don't break __attribute__((format(printf,M,N))). */
376 # define printf __printf__
377 extern int printf (const char *format
, ...)
378 __attribute__ ((__format__ (__printf__
, 1, 2)));
380 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
381 /* Don't break __attribute__((format(printf,M,N))). */
382 # define printf __printf__
383 extern int printf (const char *format
, ...)
384 __attribute__ ((__format__ (__printf__
, 1, 2)));
385 #elif defined GNULIB_POSIXCHECK
388 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
389 "use gnulib module printf-posix for portable " \
390 "POSIX compliance"), \
392 /* Don't break __attribute__((format(printf,M,N))). */
393 # define format(kind,m,n) format (__##kind##__, m, n)
394 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
395 # define ____printf____ __printf__
396 # define ____scanf____ __scanf__
397 # define ____strftime____ __strftime__
398 # define ____strfmon____ __strfmon__
401 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
403 # define putc rpl_fputc
404 extern int putc (int c
, FILE *stream
);
407 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
409 # define putchar rpl_putchar
410 extern int putchar (int c
);
413 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
415 # define puts rpl_puts
416 extern int puts (const char *string
);
420 # if @REPLACE_REMOVE@
422 # define remove rpl_remove
423 extern int remove (const char *name
);
425 #elif defined GNULIB_POSIXCHECK
428 (GL_LINK_WARNING ("remove cannot handle directories on some platforms - " \
429 "use gnulib module remove for more portability"), \
434 # if @REPLACE_RENAME@
436 # define rename rpl_rename
437 extern int rename (const char *old
, const char *new);
439 #elif defined GNULIB_POSIXCHECK
441 # define rename(o,n) \
442 (GL_LINK_WARNING ("rename is buggy on some platforms - " \
443 "use gnulib module rename for more portability"), \
447 #if @GNULIB_RENAMEAT@
448 # if @REPLACE_RENAMEAT@
450 # define renameat rpl_renameat
452 # if !@HAVE_RENAMEAT@ || @REPLACE_RENAMEAT@
453 extern int renameat (int fd1
, char const *file1
, int fd2
, char const *file2
);
455 #elif defined GNULIB_POSIXCHECK
457 # define renameat(d1,f1,d2,f2) \
458 (GL_LINK_WARNING ("renameat is not portable - " \
459 "use gnulib module renameat for portability"), \
460 renameat (d1, f1, d2, f2))
463 #if @GNULIB_SNPRINTF@
464 # if @REPLACE_SNPRINTF@
465 # define snprintf rpl_snprintf
467 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
468 extern int snprintf (char *str
, size_t size
, const char *format
, ...)
469 __attribute__ ((__format__ (__printf__
, 3, 4)));
471 #elif defined GNULIB_POSIXCHECK
474 (GL_LINK_WARNING ("snprintf is unportable - " \
475 "use gnulib module snprintf for portability"), \
479 #if @GNULIB_SPRINTF_POSIX@
480 # if @REPLACE_SPRINTF@
481 # define sprintf rpl_sprintf
482 extern int sprintf (char *str
, const char *format
, ...)
483 __attribute__ ((__format__ (__printf__
, 2, 3)));
485 #elif defined GNULIB_POSIXCHECK
488 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
489 "use gnulib module sprintf-posix for portable " \
490 "POSIX compliance"), \
494 #if @GNULIB_VASPRINTF@
495 # if @REPLACE_VASPRINTF@
496 # define asprintf rpl_asprintf
497 # define vasprintf rpl_vasprintf
499 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
500 /* Write formatted output to a string dynamically allocated with malloc().
501 If the memory allocation succeeds, store the address of the string in
502 *RESULT and return the number of resulting bytes, excluding the trailing
503 NUL. Upon memory allocation error, or some other error, return -1. */
504 extern int asprintf (char **result
, const char *format
, ...)
505 __attribute__ ((__format__ (__printf__
, 2, 3)));
506 extern int vasprintf (char **result
, const char *format
, va_list args
)
507 __attribute__ ((__format__ (__printf__
, 2, 0)));
511 #if @GNULIB_VDPRINTF@
512 # if @REPLACE_VDPRINTF@
513 # define vdprintf rpl_vdprintf
515 # if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
516 extern int vdprintf (int fd
, const char *format
, va_list args
)
517 __attribute__ ((__format__ (__printf__
, 2, 0)));
519 #elif defined GNULIB_POSIXCHECK
521 # define vdprintf(d,f,a) \
522 (GL_LINK_WARNING ("vdprintf is unportable - " \
523 "use gnulib module vdprintf for portability"), \
527 #if @GNULIB_VFPRINTF_POSIX@
528 # if @REPLACE_VFPRINTF@
529 # define vfprintf rpl_vfprintf
530 extern int vfprintf (FILE *fp
, const char *format
, va_list args
)
531 __attribute__ ((__format__ (__printf__
, 2, 0)));
533 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
534 # define vfprintf rpl_vfprintf
535 extern int vfprintf (FILE *fp
, const char *format
, va_list args
)
536 __attribute__ ((__format__ (__printf__
, 2, 0)));
537 #elif defined GNULIB_POSIXCHECK
539 # define vfprintf(s,f,a) \
540 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
541 "use gnulib module vfprintf-posix for portable " \
542 "POSIX compliance"), \
546 #if @GNULIB_VPRINTF_POSIX@
547 # if @REPLACE_VPRINTF@
548 # define vprintf rpl_vprintf
549 extern int vprintf (const char *format
, va_list args
)
550 __attribute__ ((__format__ (__printf__
, 1, 0)));
552 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
553 # define vprintf rpl_vprintf
554 extern int vprintf (const char *format
, va_list args
)
555 __attribute__ ((__format__ (__printf__
, 1, 0)));
556 #elif defined GNULIB_POSIXCHECK
558 # define vprintf(f,a) \
559 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
560 "use gnulib module vprintf-posix for portable " \
561 "POSIX compliance"), \
565 #if @GNULIB_VSNPRINTF@
566 # if @REPLACE_VSNPRINTF@
567 # define vsnprintf rpl_vsnprintf
569 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
570 extern int vsnprintf (char *str
, size_t size
, const char *format
, va_list args
)
571 __attribute__ ((__format__ (__printf__
, 3, 0)));
573 #elif defined GNULIB_POSIXCHECK
575 # define vsnprintf(b,s,f,a) \
576 (GL_LINK_WARNING ("vsnprintf is unportable - " \
577 "use gnulib module vsnprintf for portability"), \
578 vsnprintf (b, s, f, a))
581 #if @GNULIB_VSPRINTF_POSIX@
582 # if @REPLACE_VSPRINTF@
583 # define vsprintf rpl_vsprintf
584 extern int vsprintf (char *str
, const char *format
, va_list args
)
585 __attribute__ ((__format__ (__printf__
, 2, 0)));
587 #elif defined GNULIB_POSIXCHECK
589 # define vsprintf(b,f,a) \
590 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
591 "use gnulib module vsprintf-posix for portable " \
592 "POSIX compliance"), \
600 #endif /* _GL_STDIO_H */
601 #endif /* _GL_STDIO_H */