Merge branch 'master' into wip-manual-2
[bpt/guile.git] / lib / stdio.in.h
1 /* A GNU-like <stdio.h>.
2
3 Copyright (C) 2004, 2007-2010 Free Software Foundation, Inc.
4
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, or (at your option)
8 any later version.
9
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.
14
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. */
18
19 #if __GNUC__ >= 3
20 @PRAGMA_SYSTEM_HEADER@
21 #endif
22
23 #if defined __need_FILE || defined __need___FILE
24 /* Special invocation convention inside glibc header files. */
25
26 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
27
28 #else
29 /* Normal invocation convention. */
30
31 #ifndef _GL_STDIO_H
32
33 /* The include_next requires a split double-inclusion guard. */
34 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
35
36 #ifndef _GL_STDIO_H
37 #define _GL_STDIO_H
38
39 /* Get va_list. Needed on many systems, including glibc 2.8. */
40 #include <stdarg.h>
41
42 #include <stddef.h>
43
44 /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8. */
45 #include <sys/types.h>
46
47 #ifndef __attribute__
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 */
56 # endif
57 #endif
58
59
60 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
61
62 /* The definition of _GL_ARG_NONNULL is copied here. */
63
64 /* The definition of _GL_WARN_ON_USE is copied here. */
65
66
67 #if @GNULIB_DPRINTF@
68 # if @REPLACE_DPRINTF@
69 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
70 # define dprintf rpl_dprintf
71 # endif
72 _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
73 __attribute__ ((__format__ (__printf__, 2, 3)))
74 _GL_ARG_NONNULL ((2)));
75 _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
76 # else
77 # if !@HAVE_DPRINTF@
78 _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
79 __attribute__ ((__format__ (__printf__, 2, 3)))
80 _GL_ARG_NONNULL ((2)));
81 # endif
82 _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
83 # endif
84 _GL_CXXALIASWARN (dprintf);
85 #elif defined GNULIB_POSIXCHECK
86 # undef dprintf
87 # if HAVE_RAW_DECL_DPRINTF
88 _GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
89 "use gnulib module dprintf for portability");
90 # endif
91 #endif
92
93 #if @GNULIB_FCLOSE@
94 /* Close STREAM and its underlying file descriptor. */
95 # if @REPLACE_FCLOSE@
96 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
97 # define fclose rpl_fclose
98 # endif
99 _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
100 _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
101 # else
102 _GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
103 # endif
104 _GL_CXXALIASWARN (fclose);
105 #elif defined GNULIB_POSIXCHECK
106 # undef fclose
107 /* Assume fclose is always declared. */
108 _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
109 "use gnulib module fclose for portable POSIX compliance");
110 #endif
111
112 #if @GNULIB_FFLUSH@
113 /* Flush all pending data on STREAM according to POSIX rules. Both
114 output and seekable input streams are supported.
115 Note! LOSS OF DATA can occur if fflush is applied on an input stream
116 that is _not_seekable_ or on an update stream that is _not_seekable_
117 and in which the most recent operation was input. Seekability can
118 be tested with lseek(fileno(fp),0,SEEK_CUR). */
119 # if @REPLACE_FFLUSH@
120 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121 # define fflush rpl_fflush
122 # endif
123 _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
124 _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
125 # else
126 _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
127 # endif
128 _GL_CXXALIASWARN (fflush);
129 #elif defined GNULIB_POSIXCHECK
130 # undef fflush
131 /* Assume fflush is always declared. */
132 _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
133 "use gnulib module fflush for portable POSIX compliance");
134 #endif
135
136 /* It is very rare that the developer ever has full control of stdin,
137 so any use of gets warrants an unconditional warning. Assume it is
138 always declared, since it is required by C89. */
139 #undef gets
140 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
141
142 #if @GNULIB_FOPEN@
143 # if @REPLACE_FOPEN@
144 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
145 # undef fopen
146 # define fopen rpl_fopen
147 # endif
148 _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
149 _GL_ARG_NONNULL ((1, 2)));
150 _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
151 # else
152 _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
153 # endif
154 _GL_CXXALIASWARN (fopen);
155 #elif defined GNULIB_POSIXCHECK
156 # undef fopen
157 /* Assume fopen is always declared. */
158 _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
159 "use gnulib module fopen for portability");
160 #endif
161
162 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
163 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
164 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
165 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166 # define fprintf rpl_fprintf
167 # endif
168 # define GNULIB_overrides_fprintf 1
169 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
170 __attribute__ ((__format__ (__printf__, 2, 3)))
171 _GL_ARG_NONNULL ((1, 2)));
172 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
173 # else
174 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
175 # endif
176 _GL_CXXALIASWARN (fprintf);
177 #endif
178 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
179 # if !GNULIB_overrides_fprintf
180 # undef fprintf
181 # endif
182 /* Assume fprintf is always declared. */
183 _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
184 "use gnulib module fprintf-posix for portable "
185 "POSIX compliance");
186 #endif
187
188 #if @GNULIB_FPURGE@
189 /* Discard all pending buffered I/O data on STREAM.
190 STREAM must not be wide-character oriented.
191 When discarding pending output, the file position is set back to where it
192 was before the write calls. When discarding pending input, the file
193 position is advanced to match the end of the previously read input.
194 Return 0 if successful. Upon error, return -1 and set errno. */
195 # if @REPLACE_FPURGE@
196 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
197 # define fpurge rpl_fpurge
198 # endif
199 _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
200 _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
201 # else
202 # if !@HAVE_DECL_FPURGE@
203 _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
204 # endif
205 _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
206 # endif
207 _GL_CXXALIASWARN (fpurge);
208 #elif defined GNULIB_POSIXCHECK
209 # undef fpurge
210 # if HAVE_RAW_DECL_FPURGE
211 _GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
212 "use gnulib module fpurge for portability");
213 # endif
214 #endif
215
216 #if @GNULIB_FPUTC@
217 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
218 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
219 # undef fputc
220 # define fputc rpl_fputc
221 # endif
222 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
223 _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
224 # else
225 _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
226 # endif
227 _GL_CXXALIASWARN (fputc);
228 #endif
229
230 #if @GNULIB_FPUTS@
231 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
232 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
233 # undef fputs
234 # define fputs rpl_fputs
235 # endif
236 _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
237 _GL_ARG_NONNULL ((1, 2)));
238 _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
239 # else
240 _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
241 # endif
242 _GL_CXXALIASWARN (fputs);
243 #endif
244
245 #if @GNULIB_FREOPEN@
246 # if @REPLACE_FREOPEN@
247 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
248 # undef freopen
249 # define freopen rpl_freopen
250 # endif
251 _GL_FUNCDECL_RPL (freopen, FILE *,
252 (const char *filename, const char *mode, FILE *stream)
253 _GL_ARG_NONNULL ((2, 3)));
254 _GL_CXXALIAS_RPL (freopen, FILE *,
255 (const char *filename, const char *mode, FILE *stream));
256 # else
257 _GL_CXXALIAS_SYS (freopen, FILE *,
258 (const char *filename, const char *mode, FILE *stream));
259 # endif
260 _GL_CXXALIASWARN (freopen);
261 #elif defined GNULIB_POSIXCHECK
262 # undef freopen
263 /* Assume freopen is always declared. */
264 _GL_WARN_ON_USE (freopen, "freopen on Win32 platforms is not POSIX compatible - "
265 "use gnulib module freopen for portability");
266 #endif
267
268
269 /* Set up the following warnings, based on which modules are in use.
270 GNU Coding Standards discourage the use of fseek, since it imposes
271 an arbitrary limitation on some 32-bit hosts. Remember that the
272 fseek module depends on the fseeko module, so we only have three
273 cases to consider:
274
275 1. The developer is not using either module. Issue a warning under
276 GNULIB_POSIXCHECK for both functions, to remind them that both
277 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
278 impact on this warning.
279
280 2. The developer is using both modules. They may be unaware of the
281 arbitrary limitations of fseek, so issue a warning under
282 GNULIB_POSIXCHECK. On the other hand, they may be using both
283 modules intentionally, so the developer can define
284 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
285 is safe, to silence the warning.
286
287 3. The developer is using the fseeko module, but not fseek. Gnulib
288 guarantees that fseek will still work around platform bugs in that
289 case, but we presume that the developer is aware of the pitfalls of
290 fseek and was trying to avoid it, so issue a warning even when
291 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
292 defined to silence the warning in particular compilation units.
293 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
294 fseek gets defined as a macro, it is recommended that the developer
295 uses the fseek module, even if he is not calling the fseek function.
296
297 Most gnulib clients that perform stream operations should fall into
298 category 3. */
299
300 #if @GNULIB_FSEEK@
301 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
302 # define _GL_FSEEK_WARN /* Category 2, above. */
303 # undef fseek
304 # endif
305 # if @REPLACE_FSEEK@
306 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
307 # undef fseek
308 # define fseek rpl_fseek
309 # endif
310 _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
311 _GL_ARG_NONNULL ((1)));
312 _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
313 # else
314 _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
315 # endif
316 _GL_CXXALIASWARN (fseek);
317 #endif
318
319 #if @GNULIB_FSEEKO@
320 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
321 # define _GL_FSEEK_WARN /* Category 3, above. */
322 # undef fseek
323 # endif
324 # if @REPLACE_FSEEKO@
325 /* Provide fseek, fseeko functions that are aware of a preceding
326 fflush(), and which detect pipes. */
327 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
328 # undef fseeko
329 # define fseeko rpl_fseeko
330 # endif
331 _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
332 _GL_ARG_NONNULL ((1)));
333 # if !@GNULIB_FSEEK@
334 /* In order to avoid that fseek gets defined as a macro here, the
335 developer can request the 'fseek' module. */
336 # undef fseek
337 # define fseek rpl_fseek
338 static inline int _GL_ARG_NONNULL ((1))
339 rpl_fseek (FILE *fp, long offset, int whence)
340 {
341 return fseeko (fp, offset, whence);
342 }
343 # endif
344 _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
345 # else
346 _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
347 # endif
348 _GL_CXXALIASWARN (fseeko);
349 #elif defined GNULIB_POSIXCHECK
350 # define _GL_FSEEK_WARN /* Category 1, above. */
351 # undef fseek
352 # undef fseeko
353 # if HAVE_RAW_DECL_FSEEKO
354 _GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
355 "use gnulib module fseeko for portability");
356 # endif
357 #endif
358
359 #ifdef _GL_FSEEK_WARN
360 # undef _GL_FSEEK_WARN
361 /* Here, either fseek is undefined (but C89 guarantees that it is
362 declared), or it is defined as rpl_fseek (declared above). */
363 _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
364 "on 32-bit platforms - "
365 "use fseeko function for handling of large files");
366 #endif
367
368
369 /* ftell, ftello. See the comments on fseek/fseeko. */
370
371 #if @GNULIB_FTELL@
372 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
373 # define _GL_FTELL_WARN /* Category 2, above. */
374 # undef ftell
375 # endif
376 # if @REPLACE_FTELL@
377 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
378 # undef ftell
379 # define ftell rpl_ftell
380 # endif
381 _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
382 _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
383 # else
384 _GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
385 # endif
386 _GL_CXXALIASWARN (ftell);
387 #endif
388
389 #if @GNULIB_FTELLO@
390 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
391 # define _GL_FTELL_WARN /* Category 3, above. */
392 # undef ftell
393 # endif
394 # if @REPLACE_FTELLO@
395 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
396 # undef ftello
397 # define ftello rpl_ftello
398 # endif
399 _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
400 # if !@GNULIB_FTELL@
401 /* In order to avoid that ftell gets defined as a macro here, the
402 developer can request the 'ftell' module. */
403 # undef ftell
404 # define ftell rpl_ftell
405 static inline long _GL_ARG_NONNULL ((1))
406 rpl_ftell (FILE *f)
407 {
408 return ftello (f);
409 }
410 # endif
411 _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
412 # else
413 _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
414 # endif
415 _GL_CXXALIASWARN (ftello);
416 #elif defined GNULIB_POSIXCHECK
417 # define _GL_FTELL_WARN /* Category 1, above. */
418 # undef ftell
419 # undef ftello
420 # if HAVE_RAW_DECL_FTELLO
421 _GL_WARN_ON_USE (ftello, "ftello is unportable - "
422 "use gnulib module ftello for portability");
423 # endif
424 #endif
425
426 #ifdef _GL_FTELL_WARN
427 # undef _GL_FTELL_WARN
428 /* Here, either ftell is undefined (but C89 guarantees that it is
429 declared), or it is defined as rpl_ftell (declared above). */
430 _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
431 "on 32-bit platforms - "
432 "use ftello function for handling of large files");
433 #endif
434
435
436 #if @GNULIB_FWRITE@
437 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
438 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
439 # undef fwrite
440 # define fwrite rpl_fwrite
441 # endif
442 _GL_FUNCDECL_RPL (fwrite, size_t,
443 (const void *ptr, size_t s, size_t n, FILE *stream)
444 _GL_ARG_NONNULL ((1, 4)));
445 _GL_CXXALIAS_RPL (fwrite, size_t,
446 (const void *ptr, size_t s, size_t n, FILE *stream));
447 # else
448 _GL_CXXALIAS_SYS (fwrite, size_t,
449 (const void *ptr, size_t s, size_t n, FILE *stream));
450 # endif
451 _GL_CXXALIASWARN (fwrite);
452 #endif
453
454 #if @GNULIB_GETDELIM@
455 /* Read input, up to (and including) the next occurrence of DELIMITER, from
456 STREAM, store it in *LINEPTR (and NUL-terminate it).
457 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
458 bytes of space. It is realloc'd as necessary.
459 Return the number of bytes read and stored at *LINEPTR (not including the
460 NUL terminator), or -1 on error or EOF. */
461 # if @REPLACE_GETDELIM@
462 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
463 # undef getdelim
464 # define getdelim rpl_getdelim
465 # endif
466 _GL_FUNCDECL_RPL (getdelim, ssize_t,
467 (char **lineptr, size_t *linesize, int delimiter,
468 FILE *stream)
469 _GL_ARG_NONNULL ((1, 2, 4)));
470 _GL_CXXALIAS_RPL (getdelim, ssize_t,
471 (char **lineptr, size_t *linesize, int delimiter,
472 FILE *stream));
473 # else
474 # if !@HAVE_DECL_GETDELIM@
475 _GL_FUNCDECL_SYS (getdelim, ssize_t,
476 (char **lineptr, size_t *linesize, int delimiter,
477 FILE *stream)
478 _GL_ARG_NONNULL ((1, 2, 4)));
479 # endif
480 _GL_CXXALIAS_SYS (getdelim, ssize_t,
481 (char **lineptr, size_t *linesize, int delimiter,
482 FILE *stream));
483 # endif
484 _GL_CXXALIASWARN (getdelim);
485 #elif defined GNULIB_POSIXCHECK
486 # undef getdelim
487 # if HAVE_RAW_DECL_GETDELIM
488 _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
489 "use gnulib module getdelim for portability");
490 # endif
491 #endif
492
493 #if @GNULIB_GETLINE@
494 /* Read a line, up to (and including) the next newline, from STREAM, store it
495 in *LINEPTR (and NUL-terminate it).
496 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
497 bytes of space. It is realloc'd as necessary.
498 Return the number of bytes read and stored at *LINEPTR (not including the
499 NUL terminator), or -1 on error or EOF. */
500 # if @REPLACE_GETLINE@
501 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
502 # undef getline
503 # define getline rpl_getline
504 # endif
505 _GL_FUNCDECL_RPL (getline, ssize_t,
506 (char **lineptr, size_t *linesize, FILE *stream)
507 _GL_ARG_NONNULL ((1, 2, 3)));
508 _GL_CXXALIAS_RPL (getline, ssize_t,
509 (char **lineptr, size_t *linesize, FILE *stream));
510 # else
511 # if !@HAVE_DECL_GETLINE@
512 _GL_FUNCDECL_SYS (getline, ssize_t,
513 (char **lineptr, size_t *linesize, FILE *stream)
514 _GL_ARG_NONNULL ((1, 2, 3)));
515 # endif
516 _GL_CXXALIAS_SYS (getline, ssize_t,
517 (char **lineptr, size_t *linesize, FILE *stream));
518 # endif
519 _GL_CXXALIASWARN (getline);
520 #elif defined GNULIB_POSIXCHECK
521 # undef getline
522 # if HAVE_RAW_DECL_GETLINE
523 _GL_WARN_ON_USE (getline, "getline is unportable - "
524 "use gnulib module getline for portability");
525 # endif
526 #endif
527
528 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
529 struct obstack;
530 /* Grow an obstack with formatted output. Return the number of
531 bytes added to OBS. No trailing nul byte is added, and the
532 object should be closed with obstack_finish before use. Upon
533 memory allocation error, call obstack_alloc_failed_handler. Upon
534 other error, return -1. */
535 # if @REPLACE_OBSTACK_PRINTF@
536 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
537 # define obstack_printf rpl_obstack_printf
538 # endif
539 _GL_FUNCDECL_RPL (obstack_printf, int,
540 (struct obstack *obs, const char *format, ...)
541 __attribute__ ((__format__ (__printf__, 2, 3)))
542 _GL_ARG_NONNULL ((1, 2)));
543 _GL_CXXALIAS_RPL (obstack_printf, int,
544 (struct obstack *obs, const char *format, ...));
545 # else
546 # if !@HAVE_DECL_OBSTACK_PRINTF@
547 _GL_FUNCDECL_SYS (obstack_printf, int,
548 (struct obstack *obs, const char *format, ...)
549 __attribute__ ((__format__ (__printf__, 2, 3)))
550 _GL_ARG_NONNULL ((1, 2)));
551 # endif
552 _GL_CXXALIAS_SYS (obstack_printf, int,
553 (struct obstack *obs, const char *format, ...));
554 # endif
555 _GL_CXXALIASWARN (obstack_printf);
556 # if @REPLACE_OBSTACK_PRINTF@
557 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
558 # define obstack_vprintf rpl_obstack_vprintf
559 # endif
560 _GL_FUNCDECL_RPL (obstack_vprintf, int,
561 (struct obstack *obs, const char *format, va_list args)
562 __attribute__ ((__format__ (__printf__, 2, 0)))
563 _GL_ARG_NONNULL ((1, 2)));
564 _GL_CXXALIAS_RPL (obstack_vprintf, int,
565 (struct obstack *obs, const char *format, va_list args));
566 # else
567 # if !@HAVE_DECL_OBSTACK_PRINTF@
568 _GL_FUNCDECL_SYS (obstack_vprintf, int,
569 (struct obstack *obs, const char *format, va_list args)
570 __attribute__ ((__format__ (__printf__, 2, 0)))
571 _GL_ARG_NONNULL ((1, 2)));
572 # endif
573 _GL_CXXALIAS_SYS (obstack_vprintf, int,
574 (struct obstack *obs, const char *format, va_list args));
575 # endif
576 _GL_CXXALIASWARN (obstack_vprintf);
577 #endif
578
579 #if @GNULIB_PERROR@
580 /* Print a message to standard error, describing the value of ERRNO,
581 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
582 and terminated with a newline. */
583 # if @REPLACE_PERROR@
584 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585 # define perror rpl_perror
586 # endif
587 _GL_FUNCDECL_RPL (perror, void, (const char *string));
588 _GL_CXXALIAS_RPL (perror, void, (const char *string));
589 # else
590 _GL_CXXALIAS_SYS (perror, void, (const char *string));
591 # endif
592 _GL_CXXALIASWARN (perror);
593 #elif defined GNULIB_POSIXCHECK
594 # undef perror
595 /* Assume perror is always declared. */
596 _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
597 "use gnulib module perror for portability");
598 #endif
599
600 #if @GNULIB_POPEN@
601 # if @REPLACE_POPEN@
602 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
603 # undef popen
604 # define popen rpl_popen
605 # endif
606 _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
607 _GL_ARG_NONNULL ((1, 2)));
608 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
609 # else
610 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
611 # endif
612 _GL_CXXALIASWARN (popen);
613 #elif defined GNULIB_POSIXCHECK
614 # undef popen
615 # if HAVE_RAW_DECL_POPEN
616 _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
617 "use gnulib module popen or pipe for more portability");
618 # endif
619 #endif
620
621 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
622 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
623 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
624 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
625 /* Don't break __attribute__((format(printf,M,N))). */
626 # define printf __printf__
627 # endif
628 # define GNULIB_overrides_printf 1
629 _GL_FUNCDECL_RPL_1 (__printf__, int,
630 (const char *format, ...)
631 __attribute__ ((__format__ (__printf__, 1, 2)))
632 _GL_ARG_NONNULL ((1)));
633 _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
634 # else
635 _GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
636 # endif
637 _GL_CXXALIASWARN (printf);
638 #endif
639 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
640 # if !GNULIB_overrides_printf
641 # undef printf
642 # endif
643 /* Assume printf is always declared. */
644 _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
645 "use gnulib module printf-posix for portable "
646 "POSIX compliance");
647 #endif
648
649 #if @GNULIB_PUTC@
650 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
651 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
652 # undef putc
653 # define putc rpl_fputc
654 # endif
655 _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
656 _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
657 # else
658 _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
659 # endif
660 _GL_CXXALIASWARN (putc);
661 #endif
662
663 #if @GNULIB_PUTCHAR@
664 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
665 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
666 # undef putchar
667 # define putchar rpl_putchar
668 # endif
669 _GL_FUNCDECL_RPL (putchar, int, (int c));
670 _GL_CXXALIAS_RPL (putchar, int, (int c));
671 # else
672 _GL_CXXALIAS_SYS (putchar, int, (int c));
673 # endif
674 _GL_CXXALIASWARN (putchar);
675 #endif
676
677 #if @GNULIB_PUTS@
678 # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
679 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
680 # undef puts
681 # define puts rpl_puts
682 # endif
683 _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
684 _GL_CXXALIAS_RPL (puts, int, (const char *string));
685 # else
686 _GL_CXXALIAS_SYS (puts, int, (const char *string));
687 # endif
688 _GL_CXXALIASWARN (puts);
689 #endif
690
691 #if @GNULIB_REMOVE@
692 # if @REPLACE_REMOVE@
693 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
694 # undef remove
695 # define remove rpl_remove
696 # endif
697 _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
698 _GL_CXXALIAS_RPL (remove, int, (const char *name));
699 # else
700 _GL_CXXALIAS_SYS (remove, int, (const char *name));
701 # endif
702 _GL_CXXALIASWARN (remove);
703 #elif defined GNULIB_POSIXCHECK
704 # undef remove
705 /* Assume remove is always declared. */
706 _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
707 "use gnulib module remove for more portability");
708 #endif
709
710 #if @GNULIB_RENAME@
711 # if @REPLACE_RENAME@
712 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
713 # undef rename
714 # define rename rpl_rename
715 # endif
716 _GL_FUNCDECL_RPL (rename, int,
717 (const char *old_filename, const char *new_filename)
718 _GL_ARG_NONNULL ((1, 2)));
719 _GL_CXXALIAS_RPL (rename, int,
720 (const char *old_filename, const char *new_filename));
721 # else
722 _GL_CXXALIAS_SYS (rename, int,
723 (const char *old_filename, const char *new_filename));
724 # endif
725 _GL_CXXALIASWARN (rename);
726 #elif defined GNULIB_POSIXCHECK
727 # undef rename
728 /* Assume rename is always declared. */
729 _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
730 "use gnulib module rename for more portability");
731 #endif
732
733 #if @GNULIB_RENAMEAT@
734 # if @REPLACE_RENAMEAT@
735 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
736 # undef renameat
737 # define renameat rpl_renameat
738 # endif
739 _GL_FUNCDECL_RPL (renameat, int,
740 (int fd1, char const *file1, int fd2, char const *file2)
741 _GL_ARG_NONNULL ((2, 4)));
742 _GL_CXXALIAS_RPL (renameat, int,
743 (int fd1, char const *file1, int fd2, char const *file2));
744 # else
745 # if !@HAVE_RENAMEAT@
746 _GL_FUNCDECL_SYS (renameat, int,
747 (int fd1, char const *file1, int fd2, char const *file2)
748 _GL_ARG_NONNULL ((2, 4)));
749 # endif
750 _GL_CXXALIAS_SYS (renameat, int,
751 (int fd1, char const *file1, int fd2, char const *file2));
752 # endif
753 _GL_CXXALIASWARN (renameat);
754 #elif defined GNULIB_POSIXCHECK
755 # undef renameat
756 # if HAVE_RAW_DECL_RENAMEAT
757 _GL_WARN_ON_USE (renameat, "renameat is not portable - "
758 "use gnulib module renameat for portability");
759 # endif
760 #endif
761
762 #if @GNULIB_SNPRINTF@
763 # if @REPLACE_SNPRINTF@
764 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
765 # define snprintf rpl_snprintf
766 # endif
767 _GL_FUNCDECL_RPL (snprintf, int,
768 (char *str, size_t size, const char *format, ...)
769 __attribute__ ((__format__ (__printf__, 3, 4)))
770 _GL_ARG_NONNULL ((3)));
771 _GL_CXXALIAS_RPL (snprintf, int,
772 (char *str, size_t size, const char *format, ...));
773 # else
774 # if !@HAVE_DECL_SNPRINTF@
775 _GL_FUNCDECL_SYS (snprintf, int,
776 (char *str, size_t size, const char *format, ...)
777 __attribute__ ((__format__ (__printf__, 3, 4)))
778 _GL_ARG_NONNULL ((3)));
779 # endif
780 _GL_CXXALIAS_SYS (snprintf, int,
781 (char *str, size_t size, const char *format, ...));
782 # endif
783 _GL_CXXALIASWARN (snprintf);
784 #elif defined GNULIB_POSIXCHECK
785 # undef snprintf
786 # if HAVE_RAW_DECL_SNPRINTF
787 _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
788 "use gnulib module snprintf for portability");
789 # endif
790 #endif
791
792 /* Some people would argue that sprintf should be handled like gets
793 (for example, OpenBSD issues a link warning for both functions),
794 since both can cause security holes due to buffer overruns.
795 However, we believe that sprintf can be used safely, and is more
796 efficient than snprintf in those safe cases; and as proof of our
797 belief, we use sprintf in several gnulib modules. So this header
798 intentionally avoids adding a warning to sprintf except when
799 GNULIB_POSIXCHECK is defined. */
800
801 #if @GNULIB_SPRINTF_POSIX@
802 # if @REPLACE_SPRINTF@
803 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
804 # define sprintf rpl_sprintf
805 # endif
806 _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
807 __attribute__ ((__format__ (__printf__, 2, 3)))
808 _GL_ARG_NONNULL ((1, 2)));
809 _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
810 # else
811 _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
812 # endif
813 _GL_CXXALIASWARN (sprintf);
814 #elif defined GNULIB_POSIXCHECK
815 # undef sprintf
816 /* Assume sprintf is always declared. */
817 _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
818 "use gnulib module sprintf-posix for portable "
819 "POSIX compliance");
820 #endif
821
822 #if @GNULIB_VASPRINTF@
823 /* Write formatted output to a string dynamically allocated with malloc().
824 If the memory allocation succeeds, store the address of the string in
825 *RESULT and return the number of resulting bytes, excluding the trailing
826 NUL. Upon memory allocation error, or some other error, return -1. */
827 # if @REPLACE_VASPRINTF@
828 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
829 # define asprintf rpl_asprintf
830 # endif
831 _GL_FUNCDECL_RPL (asprintf, int,
832 (char **result, const char *format, ...)
833 __attribute__ ((__format__ (__printf__, 2, 3)))
834 _GL_ARG_NONNULL ((1, 2)));
835 _GL_CXXALIAS_RPL (asprintf, int,
836 (char **result, const char *format, ...));
837 # else
838 # if !@HAVE_VASPRINTF@
839 _GL_FUNCDECL_SYS (asprintf, int,
840 (char **result, const char *format, ...)
841 __attribute__ ((__format__ (__printf__, 2, 3)))
842 _GL_ARG_NONNULL ((1, 2)));
843 # endif
844 _GL_CXXALIAS_SYS (asprintf, int,
845 (char **result, const char *format, ...));
846 # endif
847 _GL_CXXALIASWARN (asprintf);
848 # if @REPLACE_VASPRINTF@
849 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
850 # define vasprintf rpl_vasprintf
851 # endif
852 _GL_FUNCDECL_RPL (vasprintf, int,
853 (char **result, const char *format, va_list args)
854 __attribute__ ((__format__ (__printf__, 2, 0)))
855 _GL_ARG_NONNULL ((1, 2)));
856 _GL_CXXALIAS_RPL (vasprintf, int,
857 (char **result, const char *format, va_list args));
858 # else
859 # if !@HAVE_VASPRINTF@
860 _GL_FUNCDECL_SYS (vasprintf, int,
861 (char **result, const char *format, va_list args)
862 __attribute__ ((__format__ (__printf__, 2, 0)))
863 _GL_ARG_NONNULL ((1, 2)));
864 # endif
865 _GL_CXXALIAS_SYS (vasprintf, int,
866 (char **result, const char *format, va_list args));
867 # endif
868 _GL_CXXALIASWARN (vasprintf);
869 #endif
870
871 #if @GNULIB_VDPRINTF@
872 # if @REPLACE_VDPRINTF@
873 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
874 # define vdprintf rpl_vdprintf
875 # endif
876 _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
877 __attribute__ ((__format__ (__printf__, 2, 0)))
878 _GL_ARG_NONNULL ((2)));
879 _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
880 # else
881 # if !@HAVE_VDPRINTF@
882 _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
883 __attribute__ ((__format__ (__printf__, 2, 0)))
884 _GL_ARG_NONNULL ((2)));
885 # endif
886 _GL_CXXALIAS_SYS (vdprintf, int, (int fd, const char *format, va_list args));
887 # endif
888 _GL_CXXALIASWARN (vdprintf);
889 #elif defined GNULIB_POSIXCHECK
890 # undef vdprintf
891 # if HAVE_RAW_DECL_VDPRINTF
892 _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
893 "use gnulib module vdprintf for portability");
894 # endif
895 #endif
896
897 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
898 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
899 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
900 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
901 # define vfprintf rpl_vfprintf
902 # endif
903 # define GNULIB_overrides_vfprintf 1
904 _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
905 __attribute__ ((__format__ (__printf__, 2, 0)))
906 _GL_ARG_NONNULL ((1, 2)));
907 _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
908 # else
909 _GL_CXXALIAS_SYS (vfprintf, int, (FILE *fp, const char *format, va_list args));
910 # endif
911 _GL_CXXALIASWARN (vfprintf);
912 #endif
913 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
914 # if !GNULIB_overrides_vfprintf
915 # undef vfprintf
916 # endif
917 /* Assume vfprintf is always declared. */
918 _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
919 "use gnulib module vfprintf-posix for portable "
920 "POSIX compliance");
921 #endif
922
923 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
924 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
925 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
926 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
927 # define vprintf rpl_vprintf
928 # endif
929 # define GNULIB_overrides_vprintf 1
930 _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
931 __attribute__ ((__format__ (__printf__, 1, 0)))
932 _GL_ARG_NONNULL ((1)));
933 _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
934 # else
935 _GL_CXXALIAS_SYS (vprintf, int, (const char *format, va_list args));
936 # endif
937 _GL_CXXALIASWARN (vprintf);
938 #endif
939 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
940 # if !GNULIB_overrides_vprintf
941 # undef vprintf
942 # endif
943 /* Assume vprintf is always declared. */
944 _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
945 "use gnulib module vprintf-posix for portable "
946 "POSIX compliance");
947 #endif
948
949 #if @GNULIB_VSNPRINTF@
950 # if @REPLACE_VSNPRINTF@
951 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
952 # define vsnprintf rpl_vsnprintf
953 # endif
954 _GL_FUNCDECL_RPL (vsnprintf, int,
955 (char *str, size_t size, const char *format, va_list args)
956 __attribute__ ((__format__ (__printf__, 3, 0)))
957 _GL_ARG_NONNULL ((3)));
958 _GL_CXXALIAS_RPL (vsnprintf, int,
959 (char *str, size_t size, const char *format, va_list args));
960 # else
961 # if !@HAVE_DECL_VSNPRINTF@
962 _GL_FUNCDECL_SYS (vsnprintf, int,
963 (char *str, size_t size, const char *format, va_list args)
964 __attribute__ ((__format__ (__printf__, 3, 0)))
965 _GL_ARG_NONNULL ((3)));
966 # endif
967 _GL_CXXALIAS_SYS (vsnprintf, int,
968 (char *str, size_t size, const char *format, va_list args));
969 # endif
970 _GL_CXXALIASWARN (vsnprintf);
971 #elif defined GNULIB_POSIXCHECK
972 # undef vsnprintf
973 # if HAVE_RAW_DECL_VSNPRINTF
974 _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
975 "use gnulib module vsnprintf for portability");
976 # endif
977 #endif
978
979 #if @GNULIB_VSPRINTF_POSIX@
980 # if @REPLACE_VSPRINTF@
981 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
982 # define vsprintf rpl_vsprintf
983 # endif
984 _GL_FUNCDECL_RPL (vsprintf, int,
985 (char *str, const char *format, va_list args)
986 __attribute__ ((__format__ (__printf__, 2, 0)))
987 _GL_ARG_NONNULL ((1, 2)));
988 _GL_CXXALIAS_RPL (vsprintf, int,
989 (char *str, const char *format, va_list args));
990 # else
991 _GL_CXXALIAS_SYS (vsprintf, int,
992 (char *str, const char *format, va_list args));
993 # endif
994 _GL_CXXALIASWARN (vsprintf);
995 #elif defined GNULIB_POSIXCHECK
996 # undef vsprintf
997 /* Assume vsprintf is always declared. */
998 _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
999 "use gnulib module vsprintf-posix for portable "
1000 "POSIX compliance");
1001 #endif
1002
1003
1004 #endif /* _GL_STDIO_H */
1005 #endif /* _GL_STDIO_H */
1006 #endif