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. */
19 @PRAGMA_SYSTEM_HEADER@
21 #if defined __need_FILE || defined __need___FILE
22 /* Special invocation convention inside glibc header files. */
24 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
27 /* Normal invocation convention. */
31 /* The include_next requires a split double-inclusion guard. */
32 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
40 #if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
41 || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
42 || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
43 || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
44 /* Get off_t and ssize_t. */
45 # include <sys/types.h>
49 /* This feature is available in gcc versions 2.5 and later. */
50 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
51 # define __attribute__(Spec) /* empty */
53 /* The __-protected variants of `format' and `printf' attributes
54 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
55 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
56 # define __format__ format
57 # define __printf__ printf
62 /* The definition of GL_LINK_WARNING is copied here. */
70 #if @GNULIB_FPRINTF_POSIX@
71 # if @REPLACE_FPRINTF@
72 # define fprintf rpl_fprintf
73 extern int fprintf (FILE *fp, const char *format, ...)
74 __attribute__ ((__format__ (__printf__, 2, 3)));
76 #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
77 # define fprintf rpl_fprintf
78 extern int fprintf (FILE *fp, const char *format, ...)
79 __attribute__ ((__format__ (__printf__, 2, 3)));
80 #elif defined GNULIB_POSIXCHECK
83 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
84 "use gnulib module fprintf-posix for portable " \
85 "POSIX compliance"), \
89 #if @GNULIB_VFPRINTF_POSIX@
90 # if @REPLACE_VFPRINTF@
91 # define vfprintf rpl_vfprintf
92 extern int vfprintf (FILE *fp, const char *format, va_list args)
93 __attribute__ ((__format__ (__printf__, 2, 0)));
95 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
96 # define vfprintf rpl_vfprintf
97 extern int vfprintf (FILE *fp, const char *format, va_list args)
98 __attribute__ ((__format__ (__printf__, 2, 0)));
99 #elif defined GNULIB_POSIXCHECK
101 # define vfprintf(s,f,a) \
102 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
103 "use gnulib module vfprintf-posix for portable " \
104 "POSIX compliance"), \
108 #if @GNULIB_PRINTF_POSIX@
109 # if @REPLACE_PRINTF@
110 /* Don't break __attribute__((format(printf,M,N))). */
111 # define printf __printf__
112 extern int printf (const char *format, ...)
113 __attribute__ ((__format__ (__printf__, 1, 2)));
115 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
116 /* Don't break __attribute__((format(printf,M,N))). */
117 # define printf __printf__
118 extern int printf (const char *format, ...)
119 __attribute__ ((__format__ (__printf__, 1, 2)));
120 #elif defined GNULIB_POSIXCHECK
123 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
124 "use gnulib module printf-posix for portable " \
125 "POSIX compliance"), \
127 /* Don't break __attribute__((format(printf,M,N))). */
128 # define format(kind,m,n) format (__##kind##__, m, n)
129 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
130 # define ____printf____ __printf__
131 # define ____scanf____ __scanf__
132 # define ____strftime____ __strftime__
133 # define ____strfmon____ __strfmon__
136 #if @GNULIB_VPRINTF_POSIX@
137 # if @REPLACE_VPRINTF@
138 # define vprintf rpl_vprintf
139 extern int vprintf (const char *format, va_list args)
140 __attribute__ ((__format__ (__printf__, 1, 0)));
142 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
143 # define vprintf rpl_vprintf
144 extern int vprintf (const char *format, va_list args)
145 __attribute__ ((__format__ (__printf__, 1, 0)));
146 #elif defined GNULIB_POSIXCHECK
148 # define vprintf(f,a) \
149 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
150 "use gnulib module vprintf-posix for portable " \
151 "POSIX compliance"), \
155 #if @GNULIB_SNPRINTF@
156 # if @REPLACE_SNPRINTF@
157 # define snprintf rpl_snprintf
159 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
160 extern int snprintf (char *str, size_t size, const char *format, ...)
161 __attribute__ ((__format__ (__printf__, 3, 4)));
163 #elif defined GNULIB_POSIXCHECK
166 (GL_LINK_WARNING ("snprintf is unportable - " \
167 "use gnulib module snprintf for portability"), \
171 #if @GNULIB_VSNPRINTF@
172 # if @REPLACE_VSNPRINTF@
173 # define vsnprintf rpl_vsnprintf
175 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
176 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
177 __attribute__ ((__format__ (__printf__, 3, 0)));
179 #elif defined GNULIB_POSIXCHECK
181 # define vsnprintf(b,s,f,a) \
182 (GL_LINK_WARNING ("vsnprintf is unportable - " \
183 "use gnulib module vsnprintf for portability"), \
184 vsnprintf (b, s, f, a))
187 #if @GNULIB_SPRINTF_POSIX@
188 # if @REPLACE_SPRINTF@
189 # define sprintf rpl_sprintf
190 extern int sprintf (char *str, const char *format, ...)
191 __attribute__ ((__format__ (__printf__, 2, 3)));
193 #elif defined GNULIB_POSIXCHECK
196 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
197 "use gnulib module sprintf-posix for portable " \
198 "POSIX compliance"), \
202 #if @GNULIB_VSPRINTF_POSIX@
203 # if @REPLACE_VSPRINTF@
204 # define vsprintf rpl_vsprintf
205 extern int vsprintf (char *str, const char *format, va_list args)
206 __attribute__ ((__format__ (__printf__, 2, 0)));
208 #elif defined GNULIB_POSIXCHECK
210 # define vsprintf(b,f,a) \
211 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
212 "use gnulib module vsprintf-posix for portable " \
213 "POSIX compliance"), \
217 #if @GNULIB_VASPRINTF@
218 # if @REPLACE_VASPRINTF@
219 # define asprintf rpl_asprintf
220 # define vasprintf rpl_vasprintf
222 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
223 /* Write formatted output to a string dynamically allocated with malloc().
224 If the memory allocation succeeds, store the address of the string in
225 *RESULT and return the number of resulting bytes, excluding the trailing
226 NUL. Upon memory allocation error, or some other error, return -1. */
227 extern int asprintf (char **result, const char *format, ...)
228 __attribute__ ((__format__ (__printf__, 2, 3)));
229 extern int vasprintf (char **result, const char *format, va_list args)
230 __attribute__ ((__format__ (__printf__, 2, 0)));
234 #if @GNULIB_OBSTACK_PRINTF@
235 # if @REPLACE_OBSTACK_PRINTF@
236 # define obstack_printf rpl_osbtack_printf
237 # define obstack_vprintf rpl_obstack_vprintf
239 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
241 /* Grow an obstack with formatted output. Return the number of
242 bytes added to OBS. No trailing nul byte is added, and the
243 object should be closed with obstack_finish before use. Upon
244 memory allocation error, call obstack_alloc_failed_handler. Upon
245 other error, return -1. */
246 extern int obstack_printf (struct obstack *obs, const char *format, ...)
247 __attribute__ ((__format__ (__printf__, 2, 3)));
248 extern int obstack_vprintf (struct obstack *obs, const char *format,
250 __attribute__ ((__format__ (__printf__, 2, 0)));
257 # define fopen rpl_fopen
258 extern FILE * fopen (const char *filename, const char *mode);
260 #elif defined GNULIB_POSIXCHECK
262 # define fopen(f,m) \
263 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
264 "use gnulib module fopen for portability"), \
269 # if @REPLACE_FREOPEN@
271 # define freopen rpl_freopen
272 extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
274 #elif defined GNULIB_POSIXCHECK
276 # define freopen(f,m,s) \
277 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
278 "use gnulib module freopen for portability"), \
283 # if @REPLACE_FSEEKO@
284 /* Provide fseek, fseeko functions that are aware of a preceding
285 fflush(), and which detect pipes. */
286 # define fseeko rpl_fseeko
287 extern int fseeko (FILE *fp, off_t offset, int whence);
288 # define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
290 #elif defined GNULIB_POSIXCHECK
292 # define fseeko(f,o,w) \
293 (GL_LINK_WARNING ("fseeko is unportable - " \
294 "use gnulib module fseeko for portability"), \
298 #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
299 extern int rpl_fseek (FILE *fp, long offset, int whence);
301 # if defined GNULIB_POSIXCHECK
302 # define fseek(f,o,w) \
303 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
304 "on 32-bit platforms - " \
305 "use fseeko function for handling of large files"), \
308 # define fseek rpl_fseek
310 #elif defined GNULIB_POSIXCHECK
312 # define fseek(f,o,w) \
313 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
314 "on 32-bit platforms - " \
315 "use fseeko function for handling of large files"), \
321 # if @REPLACE_FTELLO@
322 # define ftello rpl_ftello
323 extern off_t ftello (FILE *fp);
324 # define ftell(fp) ftello (fp)
326 #elif defined GNULIB_POSIXCHECK
329 (GL_LINK_WARNING ("ftello is unportable - " \
330 "use gnulib module ftello for portability"), \
334 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
335 extern long rpl_ftell (FILE *fp);
337 # if GNULIB_POSIXCHECK
339 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
340 "on 32-bit platforms - " \
341 "use ftello function for handling of large files"), \
344 # define ftell rpl_ftell
346 #elif defined GNULIB_POSIXCHECK
349 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
350 "on 32-bit platforms - " \
351 "use ftello function for handling of large files"), \
357 # if @REPLACE_FFLUSH@
358 # define fflush rpl_fflush
359 /* Flush all pending data on STREAM according to POSIX rules. Both
360 output and seekable input streams are supported.
361 Note! LOSS OF DATA can occur if fflush is applied on an input stream
362 that is _not_seekable_ or on an update stream that is _not_seekable_
363 and in which the most recent operation was input. Seekability can
364 be tested with lseek(fileno(fp),0,SEEK_CUR). */
365 extern int fflush (FILE *gl_stream);
367 #elif defined GNULIB_POSIXCHECK
370 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
371 "use gnulib module fflush for portable " \
372 "POSIX compliance"), \
376 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
378 # define fputc rpl_fputc
379 extern int fputc (int c, FILE *stream);
382 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
384 # define putc rpl_fputc
385 extern int putc (int c, FILE *stream);
388 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
390 # define putchar rpl_putchar
391 extern int putchar (int c);
394 #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
396 # define fputs rpl_fputs
397 extern int fputs (const char *string, FILE *stream);
400 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
402 # define puts rpl_puts
403 extern int puts (const char *string);
406 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
408 # define fwrite rpl_fwrite
409 extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
412 #if @GNULIB_GETDELIM@
413 # if !@HAVE_DECL_GETDELIM@
414 /* Read input, up to (and including) the next occurrence of DELIMITER, from
415 STREAM, store it in *LINEPTR (and NUL-terminate it).
416 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
417 bytes of space. It is realloc'd as necessary.
418 Return the number of bytes read and stored at *LINEPTR (not including the
419 NUL terminator), or -1 on error or EOF. */
420 extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
423 #elif defined GNULIB_POSIXCHECK
425 # define getdelim(l, s, d, f) \
426 (GL_LINK_WARNING ("getdelim is unportable - " \
427 "use gnulib module getdelim for portability"), \
428 getdelim (l, s, d, f))
432 # if @REPLACE_GETLINE@
434 # define getline rpl_getline
436 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
437 /* Read a line, up to (and including) the next newline, from STREAM, store it
438 in *LINEPTR (and NUL-terminate it).
439 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
440 bytes of space. It is realloc'd as necessary.
441 Return the number of bytes read and stored at *LINEPTR (not including the
442 NUL terminator), or -1 on error or EOF. */
443 extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
445 #elif defined GNULIB_POSIXCHECK
447 # define getline(l, s, f) \
448 (GL_LINK_WARNING ("getline is unportable - " \
449 "use gnulib module getline for portability"), \
454 # if @REPLACE_PERROR@
455 # define perror rpl_perror
456 /* Print a message to standard error, describing the value of ERRNO,
457 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
458 and terminated with a newline. */
459 extern void perror (const char *string);
461 #elif defined GNULIB_POSIXCHECK
464 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
465 "use gnulib module perror for portability"), \
473 #endif /* _GL_STDIO_H */
474 #endif /* _GL_STDIO_H */