1 /* A GNU-like <stdio.h>.
3 Copyright (C) 2004, 2007-2008 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 @GNULIB_FPRINTF_POSIX@
73 # if @REPLACE_FPRINTF@
74 # define fprintf rpl_fprintf
75 extern int fprintf (FILE *fp, const char *format, ...)
76 __attribute__ ((__format__ (__printf__, 2, 3)));
78 #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
79 # define fprintf rpl_fprintf
80 extern int fprintf (FILE *fp, const char *format, ...)
81 __attribute__ ((__format__ (__printf__, 2, 3)));
82 #elif defined GNULIB_POSIXCHECK
85 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
86 "use gnulib module fprintf-posix for portable " \
87 "POSIX compliance"), \
91 #if @GNULIB_VFPRINTF_POSIX@
92 # if @REPLACE_VFPRINTF@
93 # define vfprintf rpl_vfprintf
94 extern int vfprintf (FILE *fp, const char *format, va_list args)
95 __attribute__ ((__format__ (__printf__, 2, 0)));
97 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
98 # define vfprintf rpl_vfprintf
99 extern int vfprintf (FILE *fp, const char *format, va_list args)
100 __attribute__ ((__format__ (__printf__, 2, 0)));
101 #elif defined GNULIB_POSIXCHECK
103 # define vfprintf(s,f,a) \
104 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
105 "use gnulib module vfprintf-posix for portable " \
106 "POSIX compliance"), \
110 #if @GNULIB_PRINTF_POSIX@
111 # if @REPLACE_PRINTF@
112 /* Don't break __attribute__((format(printf,M,N))). */
113 # define printf __printf__
114 extern int printf (const char *format, ...)
115 __attribute__ ((__format__ (__printf__, 1, 2)));
117 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
118 /* Don't break __attribute__((format(printf,M,N))). */
119 # define printf __printf__
120 extern int printf (const char *format, ...)
121 __attribute__ ((__format__ (__printf__, 1, 2)));
122 #elif defined GNULIB_POSIXCHECK
125 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
126 "use gnulib module printf-posix for portable " \
127 "POSIX compliance"), \
129 /* Don't break __attribute__((format(printf,M,N))). */
130 # define format(kind,m,n) format (__##kind##__, m, n)
131 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
132 # define ____printf____ __printf__
133 # define ____scanf____ __scanf__
134 # define ____strftime____ __strftime__
135 # define ____strfmon____ __strfmon__
138 #if @GNULIB_VPRINTF_POSIX@
139 # if @REPLACE_VPRINTF@
140 # define vprintf rpl_vprintf
141 extern int vprintf (const char *format, va_list args)
142 __attribute__ ((__format__ (__printf__, 1, 0)));
144 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
145 # define vprintf rpl_vprintf
146 extern int vprintf (const char *format, va_list args)
147 __attribute__ ((__format__ (__printf__, 1, 0)));
148 #elif defined GNULIB_POSIXCHECK
150 # define vprintf(f,a) \
151 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
152 "use gnulib module vprintf-posix for portable " \
153 "POSIX compliance"), \
157 #if @GNULIB_SNPRINTF@
158 # if @REPLACE_SNPRINTF@
159 # define snprintf rpl_snprintf
161 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
162 extern int snprintf (char *str, size_t size, const char *format, ...)
163 __attribute__ ((__format__ (__printf__, 3, 4)));
165 #elif defined GNULIB_POSIXCHECK
168 (GL_LINK_WARNING ("snprintf is unportable - " \
169 "use gnulib module snprintf for portability"), \
173 #if @GNULIB_VSNPRINTF@
174 # if @REPLACE_VSNPRINTF@
175 # define vsnprintf rpl_vsnprintf
177 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
178 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
179 __attribute__ ((__format__ (__printf__, 3, 0)));
181 #elif defined GNULIB_POSIXCHECK
183 # define vsnprintf(b,s,f,a) \
184 (GL_LINK_WARNING ("vsnprintf is unportable - " \
185 "use gnulib module vsnprintf for portability"), \
186 vsnprintf (b, s, f, a))
189 #if @GNULIB_SPRINTF_POSIX@
190 # if @REPLACE_SPRINTF@
191 # define sprintf rpl_sprintf
192 extern int sprintf (char *str, const char *format, ...)
193 __attribute__ ((__format__ (__printf__, 2, 3)));
195 #elif defined GNULIB_POSIXCHECK
198 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
199 "use gnulib module sprintf-posix for portable " \
200 "POSIX compliance"), \
204 #if @GNULIB_VSPRINTF_POSIX@
205 # if @REPLACE_VSPRINTF@
206 # define vsprintf rpl_vsprintf
207 extern int vsprintf (char *str, const char *format, va_list args)
208 __attribute__ ((__format__ (__printf__, 2, 0)));
210 #elif defined GNULIB_POSIXCHECK
212 # define vsprintf(b,f,a) \
213 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
214 "use gnulib module vsprintf-posix for portable " \
215 "POSIX compliance"), \
219 #if @GNULIB_VASPRINTF@
220 # if @REPLACE_VASPRINTF@
221 # define asprintf rpl_asprintf
222 # define vasprintf rpl_vasprintf
224 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
225 /* Write formatted output to a string dynamically allocated with malloc().
226 If the memory allocation succeeds, store the address of the string in
227 *RESULT and return the number of resulting bytes, excluding the trailing
228 NUL. Upon memory allocation error, or some other error, return -1. */
229 extern int asprintf (char **result, const char *format, ...)
230 __attribute__ ((__format__ (__printf__, 2, 3)));
231 extern int vasprintf (char **result, const char *format, va_list args)
232 __attribute__ ((__format__ (__printf__, 2, 0)));
236 #if @GNULIB_OBSTACK_PRINTF@
237 # if @REPLACE_OBSTACK_PRINTF@
238 # define obstack_printf rpl_osbtack_printf
239 # define obstack_vprintf rpl_obstack_vprintf
241 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
243 /* Grow an obstack with formatted output. Return the number of
244 bytes added to OBS. No trailing nul byte is added, and the
245 object should be closed with obstack_finish before use. Upon
246 memory allocation error, call obstack_alloc_failed_handler. Upon
247 other error, return -1. */
248 extern int obstack_printf (struct obstack *obs, const char *format, ...)
249 __attribute__ ((__format__ (__printf__, 2, 3)));
250 extern int obstack_vprintf (struct obstack *obs, const char *format,
252 __attribute__ ((__format__ (__printf__, 2, 0)));
259 # define fopen rpl_fopen
260 extern FILE * fopen (const char *filename, const char *mode);
262 #elif defined GNULIB_POSIXCHECK
264 # define fopen(f,m) \
265 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
266 "use gnulib module fopen for portability"), \
271 # if @REPLACE_FREOPEN@
273 # define freopen rpl_freopen
274 extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
276 #elif defined GNULIB_POSIXCHECK
278 # define freopen(f,m,s) \
279 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
280 "use gnulib module freopen for portability"), \
285 # if @REPLACE_FSEEKO@
286 /* Provide fseek, fseeko functions that are aware of a preceding
287 fflush(), and which detect pipes. */
288 # define fseeko rpl_fseeko
289 extern int fseeko (FILE *fp, off_t offset, int whence);
290 # define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
292 #elif defined GNULIB_POSIXCHECK
294 # define fseeko(f,o,w) \
295 (GL_LINK_WARNING ("fseeko is unportable - " \
296 "use gnulib module fseeko for portability"), \
300 #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
301 extern int rpl_fseek (FILE *fp, long offset, int whence);
303 # if defined GNULIB_POSIXCHECK
304 # define fseek(f,o,w) \
305 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
306 "on 32-bit platforms - " \
307 "use fseeko function for handling of large files"), \
310 # define fseek rpl_fseek
312 #elif defined GNULIB_POSIXCHECK
314 # define fseek(f,o,w) \
315 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
316 "on 32-bit platforms - " \
317 "use fseeko function for handling of large files"), \
323 # if @REPLACE_FTELLO@
324 # define ftello rpl_ftello
325 extern off_t ftello (FILE *fp);
326 # define ftell(fp) ftello (fp)
328 #elif defined GNULIB_POSIXCHECK
331 (GL_LINK_WARNING ("ftello is unportable - " \
332 "use gnulib module ftello for portability"), \
336 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
337 extern long rpl_ftell (FILE *fp);
339 # if GNULIB_POSIXCHECK
341 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
342 "on 32-bit platforms - " \
343 "use ftello function for handling of large files"), \
346 # define ftell rpl_ftell
348 #elif defined GNULIB_POSIXCHECK
351 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
352 "on 32-bit platforms - " \
353 "use ftello function for handling of large files"), \
359 # if @REPLACE_FFLUSH@
360 # define fflush rpl_fflush
361 /* Flush all pending data on STREAM according to POSIX rules. Both
362 output and seekable input streams are supported.
363 Note! LOSS OF DATA can occur if fflush is applied on an input stream
364 that is _not_seekable_ or on an update stream that is _not_seekable_
365 and in which the most recent operation was input. Seekability can
366 be tested with lseek(fileno(fp),0,SEEK_CUR). */
367 extern int fflush (FILE *gl_stream);
369 #elif defined GNULIB_POSIXCHECK
372 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
373 "use gnulib module fflush for portable " \
374 "POSIX compliance"), \
379 # if @REPLACE_FCLOSE@
380 # define fclose rpl_fclose
381 /* Close STREAM and its underlying file descriptor. */
382 extern int fclose (FILE *stream);
384 #elif defined GNULIB_POSIXCHECK
387 (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
388 "use gnulib module fclose for portable " \
389 "POSIX compliance"), \
393 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
395 # define fputc rpl_fputc
396 extern int fputc (int c, FILE *stream);
399 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
401 # define putc rpl_fputc
402 extern int putc (int c, FILE *stream);
405 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
407 # define putchar rpl_putchar
408 extern int putchar (int c);
411 #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
413 # define fputs rpl_fputs
414 extern int fputs (const char *string, FILE *stream);
417 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
419 # define puts rpl_puts
420 extern int puts (const char *string);
423 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
425 # define fwrite rpl_fwrite
426 extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
429 #if @GNULIB_GETDELIM@
430 # if !@HAVE_DECL_GETDELIM@
431 /* Read input, up to (and including) the next occurrence of DELIMITER, from
432 STREAM, store it in *LINEPTR (and NUL-terminate it).
433 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
434 bytes of space. It is realloc'd as necessary.
435 Return the number of bytes read and stored at *LINEPTR (not including the
436 NUL terminator), or -1 on error or EOF. */
437 extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
440 #elif defined GNULIB_POSIXCHECK
442 # define getdelim(l, s, d, f) \
443 (GL_LINK_WARNING ("getdelim is unportable - " \
444 "use gnulib module getdelim for portability"), \
445 getdelim (l, s, d, f))
449 # if @REPLACE_GETLINE@
451 # define getline rpl_getline
453 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
454 /* Read a line, up to (and including) the next newline, from STREAM, store it
455 in *LINEPTR (and NUL-terminate it).
456 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
457 bytes of space. It is realloc'd as necessary.
458 Return the number of bytes read and stored at *LINEPTR (not including the
459 NUL terminator), or -1 on error or EOF. */
460 extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
462 #elif defined GNULIB_POSIXCHECK
464 # define getline(l, s, f) \
465 (GL_LINK_WARNING ("getline is unportable - " \
466 "use gnulib module getline for portability"), \
471 # if @REPLACE_PERROR@
472 # define perror rpl_perror
473 /* Print a message to standard error, describing the value of ERRNO,
474 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
475 and terminated with a newline. */
476 extern void perror (const char *string);
478 #elif defined GNULIB_POSIXCHECK
481 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
482 "use gnulib module perror for portability"), \
490 #endif /* _GL_STDIO_H */
491 #endif /* _GL_STDIO_H */