1
/* A GNU-like <stdio.h>.
3
Copyright (C) 2004, 2007-2010 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 3, 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@
39
/* Get va_list. Needed on many systems, including glibc 2.8. */
44
/* Get off_t and ssize_t. Needed on many systems, including glibc 2.8. */
45
#include <sys/types.h>
48
/* The __attribute__ feature is available in gcc versions 2.5 and later.
49
The __-protected variants of the attributes 'format' and 'printf' are
50
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
51
We enable __attribute__ only if these are supported too, because
52
gnulib and libintl do '#define printf __printf__' when they override
53
the 'printf' function. */
54
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
55
# define __attribute__(Spec) /* empty */
60
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
62
/* The definition of _GL_ARG_NONNULL is copied here. */
64
/* The definition of _GL_WARN_ON_USE is copied here. */
66
/* Macros for stringification. */
67
#define _GL_STDIO_STRINGIZE(token) #token
68
#define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
72
# if @REPLACE_DPRINTF@
73
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
74
# define dprintf rpl_dprintf
76
_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
77
__attribute__ ((__format__ (__printf__, 2, 3)))
78
_GL_ARG_NONNULL ((2)));
79
_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
82
_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
83
__attribute__ ((__format__ (__printf__, 2, 3)))
84
_GL_ARG_NONNULL ((2)));
86
_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
88
_GL_CXXALIASWARN (dprintf);
89
#elif defined GNULIB_POSIXCHECK
91
# if HAVE_RAW_DECL_DPRINTF
92
_GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
93
"use gnulib module dprintf for portability");
98
/* Close STREAM and its underlying file descriptor. */
100
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
101
# define fclose rpl_fclose
103
_GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
104
_GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
106
_GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
108
_GL_CXXALIASWARN (fclose);
109
#elif defined GNULIB_POSIXCHECK
111
/* Assume fclose is always declared. */
112
_GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
113
"use gnulib module fclose for portable POSIX compliance");
117
/* Flush all pending data on STREAM according to POSIX rules. Both
118
output and seekable input streams are supported.
119
Note! LOSS OF DATA can occur if fflush is applied on an input stream
120
that is _not_seekable_ or on an update stream that is _not_seekable_
121
and in which the most recent operation was input. Seekability can
122
be tested with lseek(fileno(fp),0,SEEK_CUR). */
123
# if @REPLACE_FFLUSH@
124
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
125
# define fflush rpl_fflush
127
_GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
128
_GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
130
_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
132
_GL_CXXALIASWARN (fflush);
133
#elif defined GNULIB_POSIXCHECK
135
/* Assume fflush is always declared. */
136
_GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
137
"use gnulib module fflush for portable POSIX compliance");
140
/* It is very rare that the developer ever has full control of stdin,
141
so any use of gets warrants an unconditional warning. Assume it is
142
always declared, since it is required by C89. */
144
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
148
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
150
# define fopen rpl_fopen
152
_GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
153
_GL_ARG_NONNULL ((1, 2)));
154
_GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
156
_GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
158
_GL_CXXALIASWARN (fopen);
159
#elif defined GNULIB_POSIXCHECK
161
/* Assume fopen is always declared. */
162
_GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
163
"use gnulib module fopen for portability");
166
#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
167
# if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
168
|| (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
169
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170
# define fprintf rpl_fprintf
172
# define GNULIB_overrides_fprintf 1
173
_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
174
__attribute__ ((__format__ (__printf__, 2, 3)))
175
_GL_ARG_NONNULL ((1, 2)));
176
_GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
178
_GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
180
_GL_CXXALIASWARN (fprintf);
182
#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
183
# if !GNULIB_overrides_fprintf
186
/* Assume fprintf is always declared. */
187
_GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
188
"use gnulib module fprintf-posix for portable "
193
/* Discard all pending buffered I/O data on STREAM.
194
STREAM must not be wide-character oriented.
195
When discarding pending output, the file position is set back to where it
196
was before the write calls. When discarding pending input, the file
197
position is advanced to match the end of the previously read input.
198
Return 0 if successful. Upon error, return -1 and set errno. */
199
# if @REPLACE_FPURGE@
200
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
201
# define fpurge rpl_fpurge
203
_GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
204
_GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
206
# if !@HAVE_DECL_FPURGE@
207
_GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
209
_GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
211
_GL_CXXALIASWARN (fpurge);
212
#elif defined GNULIB_POSIXCHECK
214
# if HAVE_RAW_DECL_FPURGE
215
_GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
216
"use gnulib module fpurge for portability");
221
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
222
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224
# define fputc rpl_fputc
226
_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
227
_GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
229
_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
231
_GL_CXXALIASWARN (fputc);
235
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
236
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
238
# define fputs rpl_fputs
240
_GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
241
_GL_ARG_NONNULL ((1, 2)));
242
_GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
244
_GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
246
_GL_CXXALIASWARN (fputs);
250
# if @REPLACE_FREOPEN@
251
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
253
# define freopen rpl_freopen
255
_GL_FUNCDECL_RPL (freopen, FILE *,
256
(const char *filename, const char *mode, FILE *stream)
257
_GL_ARG_NONNULL ((2, 3)));
258
_GL_CXXALIAS_RPL (freopen, FILE *,
259
(const char *filename, const char *mode, FILE *stream));
261
_GL_CXXALIAS_SYS (freopen, FILE *,
262
(const char *filename, const char *mode, FILE *stream));
264
_GL_CXXALIASWARN (freopen);
265
#elif defined GNULIB_POSIXCHECK
267
/* Assume freopen is always declared. */
268
_GL_WARN_ON_USE (freopen, "freopen on Win32 platforms is not POSIX compatible - "
269
"use gnulib module freopen for portability");
273
/* Set up the following warnings, based on which modules are in use.
274
GNU Coding Standards discourage the use of fseek, since it imposes
275
an arbitrary limitation on some 32-bit hosts. Remember that the
276
fseek module depends on the fseeko module, so we only have three
279
1. The developer is not using either module. Issue a warning under
280
GNULIB_POSIXCHECK for both functions, to remind them that both
281
functions have bugs on some systems. _GL_NO_LARGE_FILES has no
282
impact on this warning.
284
2. The developer is using both modules. They may be unaware of the
285
arbitrary limitations of fseek, so issue a warning under
286
GNULIB_POSIXCHECK. On the other hand, they may be using both
287
modules intentionally, so the developer can define
288
_GL_NO_LARGE_FILES in the compilation units where the use of fseek
289
is safe, to silence the warning.
291
3. The developer is using the fseeko module, but not fseek. Gnulib
292
guarantees that fseek will still work around platform bugs in that
293
case, but we presume that the developer is aware of the pitfalls of
294
fseek and was trying to avoid it, so issue a warning even when
295
GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
296
defined to silence the warning in particular compilation units.
297
In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
298
fseek gets defined as a macro, it is recommended that the developer
299
uses the fseek module, even if he is not calling the fseek function.
301
Most gnulib clients that perform stream operations should fall into
305
# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
306
# define _GL_FSEEK_WARN /* Category 2, above. */
310
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312
# define fseek rpl_fseek
314
_GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
315
_GL_ARG_NONNULL ((1)));
316
_GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
318
_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
320
_GL_CXXALIASWARN (fseek);
324
# if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
325
# define _GL_FSEEK_WARN /* Category 3, above. */
328
# if @REPLACE_FSEEKO@
329
/* Provide an fseeko function that is aware of a preceding fflush(), and which
331
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
333
# define fseeko rpl_fseeko
335
_GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
336
_GL_ARG_NONNULL ((1)));
337
_GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
340
_GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
341
_GL_ARG_NONNULL ((1)));
343
_GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
345
_GL_CXXALIASWARN (fseeko);
346
# if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
347
/* Provide an fseek function that is consistent with fseeko. */
348
/* In order to avoid that fseek gets defined as a macro here, the
349
developer can request the 'fseek' module. */
351
# define fseek rpl_fseek
352
static inline int _GL_ARG_NONNULL ((1))
353
rpl_fseek (FILE *fp, long offset, int whence)
355
# if @REPLACE_FSEEKO@
356
return rpl_fseeko (fp, offset, whence);
358
return fseeko (fp, offset, whence);
362
#elif defined GNULIB_POSIXCHECK
363
# define _GL_FSEEK_WARN /* Category 1, above. */
366
# if HAVE_RAW_DECL_FSEEKO
367
_GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
368
"use gnulib module fseeko for portability");
372
#ifdef _GL_FSEEK_WARN
373
# undef _GL_FSEEK_WARN
374
/* Here, either fseek is undefined (but C89 guarantees that it is
375
declared), or it is defined as rpl_fseek (declared above). */
376
_GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
377
"on 32-bit platforms - "
378
"use fseeko function for handling of large files");
382
/* ftell, ftello. See the comments on fseek/fseeko. */
385
# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
386
# define _GL_FTELL_WARN /* Category 2, above. */
390
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
392
# define ftell rpl_ftell
394
_GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
395
_GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
397
_GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
399
_GL_CXXALIASWARN (ftell);
403
# if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
404
# define _GL_FTELL_WARN /* Category 3, above. */
407
# if @REPLACE_FTELLO@
408
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
410
# define ftello rpl_ftello
412
_GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
413
_GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
416
_GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
418
_GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
420
_GL_CXXALIASWARN (ftello);
421
# if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
422
/* Provide an ftell function that is consistent with ftello. */
423
/* In order to avoid that ftell gets defined as a macro here, the
424
developer can request the 'ftell' module. */
426
# define ftell rpl_ftell
427
static inline long _GL_ARG_NONNULL ((1))
430
# if @REPLACE_FTELLO@
431
return rpl_ftello (f);
437
#elif defined GNULIB_POSIXCHECK
438
# define _GL_FTELL_WARN /* Category 1, above. */
441
# if HAVE_RAW_DECL_FTELLO
442
_GL_WARN_ON_USE (ftello, "ftello is unportable - "
443
"use gnulib module ftello for portability");
447
#ifdef _GL_FTELL_WARN
448
# undef _GL_FTELL_WARN
449
/* Here, either ftell is undefined (but C89 guarantees that it is
450
declared), or it is defined as rpl_ftell (declared above). */
451
_GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
452
"on 32-bit platforms - "
453
"use ftello function for handling of large files");
458
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
459
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
461
# define fwrite rpl_fwrite
463
_GL_FUNCDECL_RPL (fwrite, size_t,
464
(const void *ptr, size_t s, size_t n, FILE *stream)
465
_GL_ARG_NONNULL ((1, 4)));
466
_GL_CXXALIAS_RPL (fwrite, size_t,
467
(const void *ptr, size_t s, size_t n, FILE *stream));
469
_GL_CXXALIAS_SYS (fwrite, size_t,
470
(const void *ptr, size_t s, size_t n, FILE *stream));
472
_GL_CXXALIASWARN (fwrite);
475
#if @GNULIB_GETDELIM@
476
/* Read input, up to (and including) the next occurrence of DELIMITER, from
477
STREAM, store it in *LINEPTR (and NUL-terminate it).
478
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
479
bytes of space. It is realloc'd as necessary.
480
Return the number of bytes read and stored at *LINEPTR (not including the
481
NUL terminator), or -1 on error or EOF. */
482
# if @REPLACE_GETDELIM@
483
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
485
# define getdelim rpl_getdelim
487
_GL_FUNCDECL_RPL (getdelim, ssize_t,
488
(char **lineptr, size_t *linesize, int delimiter,
490
_GL_ARG_NONNULL ((1, 2, 4)));
491
_GL_CXXALIAS_RPL (getdelim, ssize_t,
492
(char **lineptr, size_t *linesize, int delimiter,
495
# if !@HAVE_DECL_GETDELIM@
496
_GL_FUNCDECL_SYS (getdelim, ssize_t,
497
(char **lineptr, size_t *linesize, int delimiter,
499
_GL_ARG_NONNULL ((1, 2, 4)));
501
_GL_CXXALIAS_SYS (getdelim, ssize_t,
502
(char **lineptr, size_t *linesize, int delimiter,
505
_GL_CXXALIASWARN (getdelim);
506
#elif defined GNULIB_POSIXCHECK
508
# if HAVE_RAW_DECL_GETDELIM
509
_GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
510
"use gnulib module getdelim for portability");
515
/* Read a line, up to (and including) the next newline, from STREAM, store it
516
in *LINEPTR (and NUL-terminate it).
517
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
518
bytes of space. It is realloc'd as necessary.
519
Return the number of bytes read and stored at *LINEPTR (not including the
520
NUL terminator), or -1 on error or EOF. */
521
# if @REPLACE_GETLINE@
522
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
524
# define getline rpl_getline
526
_GL_FUNCDECL_RPL (getline, ssize_t,
527
(char **lineptr, size_t *linesize, FILE *stream)
528
_GL_ARG_NONNULL ((1, 2, 3)));
529
_GL_CXXALIAS_RPL (getline, ssize_t,
530
(char **lineptr, size_t *linesize, FILE *stream));
532
# if !@HAVE_DECL_GETLINE@
533
_GL_FUNCDECL_SYS (getline, ssize_t,
534
(char **lineptr, size_t *linesize, FILE *stream)
535
_GL_ARG_NONNULL ((1, 2, 3)));
537
_GL_CXXALIAS_SYS (getline, ssize_t,
538
(char **lineptr, size_t *linesize, FILE *stream));
540
# if @HAVE_DECL_GETLINE@
541
_GL_CXXALIASWARN (getline);
543
#elif defined GNULIB_POSIXCHECK
545
# if HAVE_RAW_DECL_GETLINE
546
_GL_WARN_ON_USE (getline, "getline is unportable - "
547
"use gnulib module getline for portability");
551
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
553
/* Grow an obstack with formatted output. Return the number of
554
bytes added to OBS. No trailing nul byte is added, and the
555
object should be closed with obstack_finish before use. Upon
556
memory allocation error, call obstack_alloc_failed_handler. Upon
557
other error, return -1. */
558
# if @REPLACE_OBSTACK_PRINTF@
559
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
560
# define obstack_printf rpl_obstack_printf
562
_GL_FUNCDECL_RPL (obstack_printf, int,
563
(struct obstack *obs, const char *format, ...)
564
__attribute__ ((__format__ (__printf__, 2, 3)))
565
_GL_ARG_NONNULL ((1, 2)));
566
_GL_CXXALIAS_RPL (obstack_printf, int,
567
(struct obstack *obs, const char *format, ...));
569
# if !@HAVE_DECL_OBSTACK_PRINTF@
570
_GL_FUNCDECL_SYS (obstack_printf, int,
571
(struct obstack *obs, const char *format, ...)
572
__attribute__ ((__format__ (__printf__, 2, 3)))
573
_GL_ARG_NONNULL ((1, 2)));
575
_GL_CXXALIAS_SYS (obstack_printf, int,
576
(struct obstack *obs, const char *format, ...));
578
_GL_CXXALIASWARN (obstack_printf);
579
# if @REPLACE_OBSTACK_PRINTF@
580
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
581
# define obstack_vprintf rpl_obstack_vprintf
583
_GL_FUNCDECL_RPL (obstack_vprintf, int,
584
(struct obstack *obs, const char *format, va_list args)
585
__attribute__ ((__format__ (__printf__, 2, 0)))
586
_GL_ARG_NONNULL ((1, 2)));
587
_GL_CXXALIAS_RPL (obstack_vprintf, int,
588
(struct obstack *obs, const char *format, va_list args));
590
# if !@HAVE_DECL_OBSTACK_PRINTF@
591
_GL_FUNCDECL_SYS (obstack_vprintf, int,
592
(struct obstack *obs, const char *format, va_list args)
593
__attribute__ ((__format__ (__printf__, 2, 0)))
594
_GL_ARG_NONNULL ((1, 2)));
596
_GL_CXXALIAS_SYS (obstack_vprintf, int,
597
(struct obstack *obs, const char *format, va_list args));
599
_GL_CXXALIASWARN (obstack_vprintf);
603
/* Print a message to standard error, describing the value of ERRNO,
604
(if STRING is not NULL and not empty) prefixed with STRING and ": ",
605
and terminated with a newline. */
606
# if @REPLACE_PERROR@
607
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
608
# define perror rpl_perror
610
_GL_FUNCDECL_RPL (perror, void, (const char *string));
611
_GL_CXXALIAS_RPL (perror, void, (const char *string));
613
_GL_CXXALIAS_SYS (perror, void, (const char *string));
615
_GL_CXXALIASWARN (perror);
616
#elif defined GNULIB_POSIXCHECK
618
/* Assume perror is always declared. */
619
_GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
620
"use gnulib module perror for portability");
625
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
627
# define popen rpl_popen
629
_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
630
_GL_ARG_NONNULL ((1, 2)));
631
_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
633
_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
635
_GL_CXXALIASWARN (popen);
636
#elif defined GNULIB_POSIXCHECK
638
# if HAVE_RAW_DECL_POPEN
639
_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
640
"use gnulib module popen or pipe for more portability");
644
#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
645
# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
646
|| (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
647
# if defined __GNUC__
648
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
649
/* Don't break __attribute__((format(printf,M,N))). */
650
# define printf __printf__
652
_GL_FUNCDECL_RPL_1 (__printf__, int,
653
(const char *format, ...)
654
__asm__ (@ASM_SYMBOL_PREFIX@
655
_GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
656
__attribute__ ((__format__ (__printf__, 1, 2)))
657
_GL_ARG_NONNULL ((1)));
658
_GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
660
_GL_FUNCDECL_RPL (printf, int,
661
(const char *format, ...)
662
__attribute__ ((__format__ (__printf__, 1, 2)))
663
_GL_ARG_NONNULL ((1)));
664
_GL_CXXALIAS_RPL (printf, int, (const char *format, ...));
666
# define GNULIB_overrides_printf 1
668
_GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
670
_GL_CXXALIASWARN (printf);
672
#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
673
# if !GNULIB_overrides_printf
676
/* Assume printf is always declared. */
677
_GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
678
"use gnulib module printf-posix for portable "
683
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
684
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
686
# define putc rpl_fputc
688
_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
689
_GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
691
_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
693
_GL_CXXALIASWARN (putc);
697
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
698
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
700
# define putchar rpl_putchar
702
_GL_FUNCDECL_RPL (putchar, int, (int c));
703
_GL_CXXALIAS_RPL (putchar, int, (int c));
705
_GL_CXXALIAS_SYS (putchar, int, (int c));
707
_GL_CXXALIASWARN (putchar);
711
# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
712
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714
# define puts rpl_puts
716
_GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
717
_GL_CXXALIAS_RPL (puts, int, (const char *string));
719
_GL_CXXALIAS_SYS (puts, int, (const char *string));
721
_GL_CXXALIASWARN (puts);
725
# if @REPLACE_REMOVE@
726
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
728
# define remove rpl_remove
730
_GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
731
_GL_CXXALIAS_RPL (remove, int, (const char *name));
733
_GL_CXXALIAS_SYS (remove, int, (const char *name));
735
_GL_CXXALIASWARN (remove);
736
#elif defined GNULIB_POSIXCHECK
738
/* Assume remove is always declared. */
739
_GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
740
"use gnulib module remove for more portability");
744
# if @REPLACE_RENAME@
745
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
747
# define rename rpl_rename
749
_GL_FUNCDECL_RPL (rename, int,
750
(const char *old_filename, const char *new_filename)
751
_GL_ARG_NONNULL ((1, 2)));
752
_GL_CXXALIAS_RPL (rename, int,
753
(const char *old_filename, const char *new_filename));
755
_GL_CXXALIAS_SYS (rename, int,
756
(const char *old_filename, const char *new_filename));
758
_GL_CXXALIASWARN (rename);
759
#elif defined GNULIB_POSIXCHECK
761
/* Assume rename is always declared. */
762
_GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
763
"use gnulib module rename for more portability");
766
#if @GNULIB_RENAMEAT@
767
# if @REPLACE_RENAMEAT@
768
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
770
# define renameat rpl_renameat
772
_GL_FUNCDECL_RPL (renameat, int,
773
(int fd1, char const *file1, int fd2, char const *file2)
774
_GL_ARG_NONNULL ((2, 4)));
775
_GL_CXXALIAS_RPL (renameat, int,
776
(int fd1, char const *file1, int fd2, char const *file2));
778
# if !@HAVE_RENAMEAT@
779
_GL_FUNCDECL_SYS (renameat, int,
780
(int fd1, char const *file1, int fd2, char const *file2)
781
_GL_ARG_NONNULL ((2, 4)));
783
_GL_CXXALIAS_SYS (renameat, int,
784
(int fd1, char const *file1, int fd2, char const *file2));
786
_GL_CXXALIASWARN (renameat);
787
#elif defined GNULIB_POSIXCHECK
789
# if HAVE_RAW_DECL_RENAMEAT
790
_GL_WARN_ON_USE (renameat, "renameat is not portable - "
791
"use gnulib module renameat for portability");
795
#if @GNULIB_SNPRINTF@
796
# if @REPLACE_SNPRINTF@
797
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
798
# define snprintf rpl_snprintf
800
_GL_FUNCDECL_RPL (snprintf, int,
801
(char *str, size_t size, const char *format, ...)
802
__attribute__ ((__format__ (__printf__, 3, 4)))
803
_GL_ARG_NONNULL ((3)));
804
_GL_CXXALIAS_RPL (snprintf, int,
805
(char *str, size_t size, const char *format, ...));
807
# if !@HAVE_DECL_SNPRINTF@
808
_GL_FUNCDECL_SYS (snprintf, int,
809
(char *str, size_t size, const char *format, ...)
810
__attribute__ ((__format__ (__printf__, 3, 4)))
811
_GL_ARG_NONNULL ((3)));
813
_GL_CXXALIAS_SYS (snprintf, int,
814
(char *str, size_t size, const char *format, ...));
816
_GL_CXXALIASWARN (snprintf);
817
#elif defined GNULIB_POSIXCHECK
819
# if HAVE_RAW_DECL_SNPRINTF
820
_GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
821
"use gnulib module snprintf for portability");
825
/* Some people would argue that sprintf should be handled like gets
826
(for example, OpenBSD issues a link warning for both functions),
827
since both can cause security holes due to buffer overruns.
828
However, we believe that sprintf can be used safely, and is more
829
efficient than snprintf in those safe cases; and as proof of our
830
belief, we use sprintf in several gnulib modules. So this header
831
intentionally avoids adding a warning to sprintf except when
832
GNULIB_POSIXCHECK is defined. */
834
#if @GNULIB_SPRINTF_POSIX@
835
# if @REPLACE_SPRINTF@
836
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
837
# define sprintf rpl_sprintf
839
_GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
840
__attribute__ ((__format__ (__printf__, 2, 3)))
841
_GL_ARG_NONNULL ((1, 2)));
842
_GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
844
_GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
846
_GL_CXXALIASWARN (sprintf);
847
#elif defined GNULIB_POSIXCHECK
849
/* Assume sprintf is always declared. */
850
_GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
851
"use gnulib module sprintf-posix for portable "
856
# if @REPLACE_TMPFILE@
857
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
858
# define tmpfile rpl_tmpfile
860
_GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
861
_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
863
_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
865
_GL_CXXALIASWARN (tmpfile);
866
#elif defined GNULIB_POSIXCHECK
868
# if HAVE_RAW_DECL_TMPFILE
869
_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
870
"use gnulib module tmpfile for portability");
874
#if @GNULIB_VASPRINTF@
875
/* Write formatted output to a string dynamically allocated with malloc().
876
If the memory allocation succeeds, store the address of the string in
877
*RESULT and return the number of resulting bytes, excluding the trailing
878
NUL. Upon memory allocation error, or some other error, return -1. */
879
# if @REPLACE_VASPRINTF@
880
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
881
# define asprintf rpl_asprintf
883
_GL_FUNCDECL_RPL (asprintf, int,
884
(char **result, const char *format, ...)
885
__attribute__ ((__format__ (__printf__, 2, 3)))
886
_GL_ARG_NONNULL ((1, 2)));
887
_GL_CXXALIAS_RPL (asprintf, int,
888
(char **result, const char *format, ...));
890
# if !@HAVE_VASPRINTF@
891
_GL_FUNCDECL_SYS (asprintf, int,
892
(char **result, const char *format, ...)
893
__attribute__ ((__format__ (__printf__, 2, 3)))
894
_GL_ARG_NONNULL ((1, 2)));
896
_GL_CXXALIAS_SYS (asprintf, int,
897
(char **result, const char *format, ...));
899
_GL_CXXALIASWARN (asprintf);
900
# if @REPLACE_VASPRINTF@
901
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
902
# define vasprintf rpl_vasprintf
904
_GL_FUNCDECL_RPL (vasprintf, int,
905
(char **result, const char *format, va_list args)
906
__attribute__ ((__format__ (__printf__, 2, 0)))
907
_GL_ARG_NONNULL ((1, 2)));
908
_GL_CXXALIAS_RPL (vasprintf, int,
909
(char **result, const char *format, va_list args));
911
# if !@HAVE_VASPRINTF@
912
_GL_FUNCDECL_SYS (vasprintf, int,
913
(char **result, const char *format, va_list args)
914
__attribute__ ((__format__ (__printf__, 2, 0)))
915
_GL_ARG_NONNULL ((1, 2)));
917
_GL_CXXALIAS_SYS (vasprintf, int,
918
(char **result, const char *format, va_list args));
920
_GL_CXXALIASWARN (vasprintf);
923
#if @GNULIB_VDPRINTF@
924
# if @REPLACE_VDPRINTF@
925
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
926
# define vdprintf rpl_vdprintf
928
_GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
929
__attribute__ ((__format__ (__printf__, 2, 0)))
930
_GL_ARG_NONNULL ((2)));
931
_GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
933
# if !@HAVE_VDPRINTF@
934
_GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
935
__attribute__ ((__format__ (__printf__, 2, 0)))
936
_GL_ARG_NONNULL ((2)));
938
/* Need to cast, because on Solaris, the third parameter will likely be
940
_GL_CXXALIAS_SYS_CAST (vdprintf, int,
941
(int fd, const char *format, va_list args));
943
_GL_CXXALIASWARN (vdprintf);
944
#elif defined GNULIB_POSIXCHECK
946
# if HAVE_RAW_DECL_VDPRINTF
947
_GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
948
"use gnulib module vdprintf for portability");
952
#if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
953
# if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
954
|| (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
955
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
956
# define vfprintf rpl_vfprintf
958
# define GNULIB_overrides_vfprintf 1
959
_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
960
__attribute__ ((__format__ (__printf__, 2, 0)))
961
_GL_ARG_NONNULL ((1, 2)));
962
_GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
964
/* Need to cast, because on Solaris, the third parameter is
966
and GCC's fixincludes did not change this to __gnuc_va_list. */
967
_GL_CXXALIAS_SYS_CAST (vfprintf, int,
968
(FILE *fp, const char *format, va_list args));
970
_GL_CXXALIASWARN (vfprintf);
972
#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
973
# if !GNULIB_overrides_vfprintf
976
/* Assume vfprintf is always declared. */
977
_GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
978
"use gnulib module vfprintf-posix for portable "
982
#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
983
# if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
984
|| (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
985
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
986
# define vprintf rpl_vprintf
988
# define GNULIB_overrides_vprintf 1
989
_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
990
__attribute__ ((__format__ (__printf__, 1, 0)))
991
_GL_ARG_NONNULL ((1)));
992
_GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
994
/* Need to cast, because on Solaris, the second parameter is
996
and GCC's fixincludes did not change this to __gnuc_va_list. */
997
_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
999
_GL_CXXALIASWARN (vprintf);
1001
#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1002
# if !GNULIB_overrides_vprintf
1005
/* Assume vprintf is always declared. */
1006
_GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1007
"use gnulib module vprintf-posix for portable "
1008
"POSIX compliance");
1011
#if @GNULIB_VSNPRINTF@
1012
# if @REPLACE_VSNPRINTF@
1013
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1014
# define vsnprintf rpl_vsnprintf
1016
_GL_FUNCDECL_RPL (vsnprintf, int,
1017
(char *str, size_t size, const char *format, va_list args)
1018
__attribute__ ((__format__ (__printf__, 3, 0)))
1019
_GL_ARG_NONNULL ((3)));
1020
_GL_CXXALIAS_RPL (vsnprintf, int,
1021
(char *str, size_t size, const char *format, va_list args));
1023
# if !@HAVE_DECL_VSNPRINTF@
1024
_GL_FUNCDECL_SYS (vsnprintf, int,
1025
(char *str, size_t size, const char *format, va_list args)
1026
__attribute__ ((__format__ (__printf__, 3, 0)))
1027
_GL_ARG_NONNULL ((3)));
1029
_GL_CXXALIAS_SYS (vsnprintf, int,
1030
(char *str, size_t size, const char *format, va_list args));
1032
_GL_CXXALIASWARN (vsnprintf);
1033
#elif defined GNULIB_POSIXCHECK
1035
# if HAVE_RAW_DECL_VSNPRINTF
1036
_GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1037
"use gnulib module vsnprintf for portability");
1041
#if @GNULIB_VSPRINTF_POSIX@
1042
# if @REPLACE_VSPRINTF@
1043
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1044
# define vsprintf rpl_vsprintf
1046
_GL_FUNCDECL_RPL (vsprintf, int,
1047
(char *str, const char *format, va_list args)
1048
__attribute__ ((__format__ (__printf__, 2, 0)))
1049
_GL_ARG_NONNULL ((1, 2)));
1050
_GL_CXXALIAS_RPL (vsprintf, int,
1051
(char *str, const char *format, va_list args));
1053
/* Need to cast, because on Solaris, the third parameter is
1055
and GCC's fixincludes did not change this to __gnuc_va_list. */
1056
_GL_CXXALIAS_SYS_CAST (vsprintf, int,
1057
(char *str, const char *format, va_list args));
1059
_GL_CXXALIASWARN (vsprintf);
1060
#elif defined GNULIB_POSIXCHECK
1062
/* Assume vsprintf is always declared. */
1063
_GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1064
"use gnulib module vsprintf-posix for portable "
1065
"POSIX compliance");
1069
#endif /* _GL_STDIO_H */
1070
#endif /* _GL_STDIO_H */