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 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. */
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 defined GNULIB_POSIXCHECK
79
(GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
80
"use gnulib module fprintf-posix for portable " \
81
"POSIX compliance"), \
85
#if @GNULIB_VFPRINTF_POSIX@
86
# if @REPLACE_VFPRINTF@
87
# define vfprintf rpl_vfprintf
88
extern int vfprintf (FILE *fp, const char *format, va_list args)
89
__attribute__ ((__format__ (__printf__, 2, 0)));
91
#elif defined GNULIB_POSIXCHECK
93
# define vfprintf(s,f,a) \
94
(GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
95
"use gnulib module vfprintf-posix for portable " \
96
"POSIX compliance"), \
100
#if @GNULIB_PRINTF_POSIX@
101
# if @REPLACE_PRINTF@
102
/* Don't break __attribute__((format(printf,M,N))). */
103
# define printf __printf__
104
extern int printf (const char *format, ...)
105
__attribute__ ((__format__ (__printf__, 1, 2)));
107
#elif defined GNULIB_POSIXCHECK
110
(GL_LINK_WARNING ("printf is not always POSIX compliant - " \
111
"use gnulib module printf-posix for portable " \
112
"POSIX compliance"), \
114
/* Don't break __attribute__((format(printf,M,N))). */
115
# define format(kind,m,n) format (__##kind##__, m, n)
116
# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
117
# define ____printf____ __printf__
118
# define ____scanf____ __scanf__
119
# define ____strftime____ __strftime__
120
# define ____strfmon____ __strfmon__
123
#if @GNULIB_VPRINTF_POSIX@
124
# if @REPLACE_VPRINTF@
125
# define vprintf rpl_vprintf
126
extern int vprintf (const char *format, va_list args)
127
__attribute__ ((__format__ (__printf__, 1, 0)));
129
#elif defined GNULIB_POSIXCHECK
131
# define vprintf(f,a) \
132
(GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
133
"use gnulib module vprintf-posix for portable " \
134
"POSIX compliance"), \
138
#if @GNULIB_SNPRINTF@
139
# if @REPLACE_SNPRINTF@
140
# define snprintf rpl_snprintf
142
# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
143
extern int snprintf (char *str, size_t size, const char *format, ...)
144
__attribute__ ((__format__ (__printf__, 3, 4)));
146
#elif defined GNULIB_POSIXCHECK
149
(GL_LINK_WARNING ("snprintf is unportable - " \
150
"use gnulib module snprintf for portability"), \
154
#if @GNULIB_VSNPRINTF@
155
# if @REPLACE_VSNPRINTF@
156
# define vsnprintf rpl_vsnprintf
158
# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
159
extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
160
__attribute__ ((__format__ (__printf__, 3, 0)));
162
#elif defined GNULIB_POSIXCHECK
164
# define vsnprintf(b,s,f,a) \
165
(GL_LINK_WARNING ("vsnprintf is unportable - " \
166
"use gnulib module vsnprintf for portability"), \
167
vsnprintf (b, s, f, a))
170
#if @GNULIB_SPRINTF_POSIX@
171
# if @REPLACE_SPRINTF@
172
# define sprintf rpl_sprintf
173
extern int sprintf (char *str, const char *format, ...)
174
__attribute__ ((__format__ (__printf__, 2, 3)));
176
#elif defined GNULIB_POSIXCHECK
179
(GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
180
"use gnulib module sprintf-posix for portable " \
181
"POSIX compliance"), \
185
#if @GNULIB_VSPRINTF_POSIX@
186
# if @REPLACE_VSPRINTF@
187
# define vsprintf rpl_vsprintf
188
extern int vsprintf (char *str, const char *format, va_list args)
189
__attribute__ ((__format__ (__printf__, 2, 0)));
191
#elif defined GNULIB_POSIXCHECK
193
# define vsprintf(b,f,a) \
194
(GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
195
"use gnulib module vsprintf-posix for portable " \
196
"POSIX compliance"), \
200
#if @GNULIB_VASPRINTF@
201
# if @REPLACE_VASPRINTF@
202
# define asprintf rpl_asprintf
203
# define vasprintf rpl_vasprintf
205
# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
206
/* Write formatted output to a string dynamically allocated with malloc().
207
If the memory allocation succeeds, store the address of the string in
208
*RESULT and return the number of resulting bytes, excluding the trailing
209
NUL. Upon memory allocation error, or some other error, return -1. */
210
extern int asprintf (char **result, const char *format, ...)
211
__attribute__ ((__format__ (__printf__, 2, 3)));
212
extern int vasprintf (char **result, const char *format, va_list args)
213
__attribute__ ((__format__ (__printf__, 2, 0)));
217
#if @GNULIB_OBSTACK_PRINTF@
218
# if @REPLACE_OBSTACK_PRINTF@
219
# define obstack_printf rpl_osbtack_printf
220
# define obstack_vprintf rpl_obstack_vprintf
222
# if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
224
/* Grow an obstack with formatted output. Return the number of
225
bytes added to OBS. No trailing nul byte is added, and the
226
object should be closed with obstack_finish before use. Upon
227
memory allocation error, call obstack_alloc_failed_handler. Upon
228
other error, return -1. */
229
extern int obstack_printf (struct obstack *obs, const char *format, ...)
230
__attribute__ ((__format__ (__printf__, 2, 3)));
231
extern int obstack_vprintf (struct obstack *obs, const char *format,
233
__attribute__ ((__format__ (__printf__, 2, 0)));
239
# define fopen rpl_fopen
240
extern FILE * fopen (const char *filename, const char *mode);
242
#elif defined GNULIB_POSIXCHECK
244
# define fopen(f,m) \
245
(GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
246
"use gnulib module fopen for portability"), \
251
# if @REPLACE_FREOPEN@
252
# define freopen rpl_freopen
253
extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
255
#elif defined GNULIB_POSIXCHECK
257
# define freopen(f,m,s) \
258
(GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
259
"use gnulib module freopen for portability"), \
264
# if @REPLACE_FSEEKO@
265
/* Provide fseek, fseeko functions that are aware of a preceding
266
fflush(), and which detect pipes. */
267
# define fseeko rpl_fseeko
268
extern int fseeko (FILE *fp, off_t offset, int whence);
269
# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
271
#elif defined GNULIB_POSIXCHECK
273
# define fseeko(f,o,w) \
274
(GL_LINK_WARNING ("fseeko is unportable - " \
275
"use gnulib module fseeko for portability"), \
279
#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
280
extern int rpl_fseek (FILE *fp, long offset, int whence);
282
# if defined GNULIB_POSIXCHECK
283
# define fseek(f,o,w) \
284
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
285
"on 32-bit platforms - " \
286
"use fseeko function for handling of large files"), \
289
# define fseek rpl_fseek
291
#elif defined GNULIB_POSIXCHECK
293
# define fseek(f,o,w) \
294
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
295
"on 32-bit platforms - " \
296
"use fseeko function for handling of large files"), \
302
# if @REPLACE_FTELLO@
303
# define ftello rpl_ftello
304
extern off_t ftello (FILE *fp);
305
# define ftell(fp) ftello (fp)
307
#elif defined GNULIB_POSIXCHECK
310
(GL_LINK_WARNING ("ftello is unportable - " \
311
"use gnulib module ftello for portability"), \
315
#if @GNULIB_FTELL@ && @REPLACE_FTELL@
316
extern long rpl_ftell (FILE *fp);
318
# if GNULIB_POSIXCHECK
320
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
321
"on 32-bit platforms - " \
322
"use ftello function for handling of large files"), \
325
# define ftell rpl_ftell
327
#elif defined GNULIB_POSIXCHECK
330
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
331
"on 32-bit platforms - " \
332
"use ftello function for handling of large files"), \
338
# if @REPLACE_FFLUSH@
339
# define fflush rpl_fflush
340
/* Flush all pending data on STREAM according to POSIX rules. Both
341
output and seekable input streams are supported.
342
Note! LOSS OF DATA can occur if fflush is applied on an input stream
343
that is _not_seekable_ or on an update stream that is _not_seekable_
344
and in which the most recent operation was input. Seekability can
345
be tested with lseek(fileno(fp),0,SEEK_CUR). */
346
extern int fflush (FILE *gl_stream);
348
#elif defined GNULIB_POSIXCHECK
351
(GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
352
"use gnulib module fflush for portable " \
353
"POSIX compliance"), \
357
#if @GNULIB_GETDELIM@
358
# if !@HAVE_DECL_GETDELIM@
359
/* Read input, up to (and including) the next occurrence of DELIMITER, from
360
STREAM, store it in *LINEPTR (and NUL-terminate it).
361
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
362
bytes of space. It is realloc'd as necessary.
363
Return the number of bytes read and stored at *LINEPTR (not including the
364
NUL terminator), or -1 on error or EOF. */
365
extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
368
#elif defined GNULIB_POSIXCHECK
370
# define getdelim(l, s, d, f) \
371
(GL_LINK_WARNING ("getdelim is unportable - " \
372
"use gnulib module getdelim for portability"), \
373
getdelim (l, s, d, f))
377
# if @REPLACE_GETLINE@
379
# define getline rpl_getline
381
# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
382
/* Read a line, up to (and including) the next newline, from STREAM, store it
383
in *LINEPTR (and NUL-terminate it).
384
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
385
bytes of space. It is realloc'd as necessary.
386
Return the number of bytes read and stored at *LINEPTR (not including the
387
NUL terminator), or -1 on error or EOF. */
388
extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
390
#elif defined GNULIB_POSIXCHECK
392
# define getline(l, s, f) \
393
(GL_LINK_WARNING ("getline is unportable - " \
394
"use gnulib module getline for portability"), \
399
# if @REPLACE_PERROR@
400
# define perror rpl_perror
401
/* Print a message to standard error, describing the value of ERRNO,
402
(if STRING is not NULL and not empty) prefixed with STRING and ": ",
403
and terminated with a newline. */
404
extern void perror (const char *string);
406
#elif defined GNULIB_POSIXCHECK
409
(GL_LINK_WARNING ("perror is not always POSIX compliant - " \
410
"use gnulib module perror for portability"), \
418
#endif /* _GL_STDIO_H */
419
#endif /* _GL_STDIO_H */