rename: modernize replacement
[gnulib.git] / lib / stdio.in.h
1 /* A GNU-like <stdio.h>.
2
3    Copyright (C) 2004, 2007-2009 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 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 General Public License for more details.
14
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.  */
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 #include <stdarg.h>
40 #include <stddef.h>
41
42 #if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
43   || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
44   || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
45   || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
46 /* Get off_t and ssize_t.  */
47 # include <sys/types.h>
48 #endif
49
50 #ifndef __attribute__
51 /* This feature is available in gcc versions 2.5 and later.  */
52 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
53 #  define __attribute__(Spec) /* empty */
54 # endif
55 /* The __-protected variants of `format' and `printf' attributes
56    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
57 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
58 #  define __format__ format
59 #  define __printf__ printf
60 # endif
61 #endif
62
63
64 /* The definition of GL_LINK_WARNING is copied here.  */
65
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 #if @GNULIB_DPRINTF@
72 # if @REPLACE_DPRINTF@
73 #  define dprintf rpl_dprintf
74 # endif
75 # if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
76 extern int dprintf (int fd, const char *format, ...)
77        __attribute__ ((__format__ (__printf__, 2, 3)));
78 # endif
79 #elif defined GNULIB_POSIXCHECK
80 # undef dprintf
81 # define dprintf(d,f,a) \
82     (GL_LINK_WARNING ("dprintf is unportable - " \
83                       "use gnulib module dprintf for portability"), \
84      dprintf (d, f, a))
85 #endif
86
87 #if @GNULIB_FCLOSE@
88 # if @REPLACE_FCLOSE@
89 #  define fclose rpl_fclose
90   /* Close STREAM and its underlying file descriptor.  */
91 extern int fclose (FILE *stream);
92 # endif
93 #elif defined GNULIB_POSIXCHECK
94 # undef fclose
95 # define fclose(f) \
96    (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
97                      "use gnulib module fclose for portable " \
98                      "POSIX compliance"), \
99     fclose (f))
100 #endif
101
102 #if @GNULIB_FFLUSH@
103 # if @REPLACE_FFLUSH@
104 #  define fflush rpl_fflush
105   /* Flush all pending data on STREAM according to POSIX rules.  Both
106      output and seekable input streams are supported.
107      Note! LOSS OF DATA can occur if fflush is applied on an input stream
108      that is _not_seekable_ or on an update stream that is _not_seekable_
109      and in which the most recent operation was input.  Seekability can
110      be tested with lseek(fileno(fp),0,SEEK_CUR).  */
111   extern int fflush (FILE *gl_stream);
112 # endif
113 #elif defined GNULIB_POSIXCHECK
114 # undef fflush
115 # define fflush(f) \
116    (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
117                      "use gnulib module fflush for portable " \
118                      "POSIX compliance"), \
119     fflush (f))
120 #endif
121
122 #if @GNULIB_FOPEN@
123 # if @REPLACE_FOPEN@
124 #  undef fopen
125 #  define fopen rpl_fopen
126 extern FILE * fopen (const char *filename, const char *mode);
127 # endif
128 #elif defined GNULIB_POSIXCHECK
129 # undef fopen
130 # define fopen(f,m) \
131    (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
132                      "use gnulib module fopen for portability"), \
133     fopen (f, m))
134 #endif
135
136 #if @GNULIB_FPRINTF_POSIX@
137 # if @REPLACE_FPRINTF@
138 #  define fprintf rpl_fprintf
139 extern int fprintf (FILE *fp, const char *format, ...)
140        __attribute__ ((__format__ (__printf__, 2, 3)));
141 # endif
142 #elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
143 # define fprintf rpl_fprintf
144 extern int fprintf (FILE *fp, const char *format, ...)
145        __attribute__ ((__format__ (__printf__, 2, 3)));
146 #elif defined GNULIB_POSIXCHECK
147 # undef fprintf
148 # define fprintf \
149     (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
150                       "use gnulib module fprintf-posix for portable " \
151                       "POSIX compliance"), \
152      fprintf)
153 #endif
154
155 #if @GNULIB_FPURGE@
156 # if @REPLACE_FPURGE@
157 #  define fpurge rpl_fpurge
158 # endif
159 # if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
160   /* Discard all pending buffered I/O data on STREAM.
161      STREAM must not be wide-character oriented.
162      When discarding pending output, the file position is set back to where it
163      was before the write calls.  When discarding pending input, the file
164      position is advanced to match the end of the previously read input.
165      Return 0 if successful.  Upon error, return -1 and set errno.  */
166   extern int fpurge (FILE *gl_stream);
167 # endif
168 #elif defined GNULIB_POSIXCHECK
169 # undef fpurge
170 # define fpurge(f) \
171    (GL_LINK_WARNING ("fpurge is not always present - " \
172                      "use gnulib module fpurge for portability"), \
173     fpurge (f))
174 #endif
175
176 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
177 # undef fputc
178 # define fputc rpl_fputc
179 extern int fputc (int c, FILE *stream);
180 #endif
181
182 #if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
183 # undef fputs
184 # define fputs rpl_fputs
185 extern int fputs (const char *string, FILE *stream);
186 #endif
187
188 #if @GNULIB_FREOPEN@
189 # if @REPLACE_FREOPEN@
190 #  undef freopen
191 #  define freopen rpl_freopen
192 extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
193 # endif
194 #elif defined GNULIB_POSIXCHECK
195 # undef freopen
196 # define freopen(f,m,s) \
197    (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
198                      "use gnulib module freopen for portability"), \
199     freopen (f, m, s))
200 #endif
201
202 #if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
203 extern int rpl_fseek (FILE *fp, long offset, int whence);
204 # undef fseek
205 # if defined GNULIB_POSIXCHECK
206 #  define fseek(f,o,w) \
207      (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
208                        "on 32-bit platforms - " \
209                        "use fseeko function for handling of large files"), \
210       rpl_fseek (f, o, w))
211 # else
212 #  define fseek rpl_fseek
213 # endif
214 #elif defined GNULIB_POSIXCHECK
215 # ifndef fseek
216 #  define fseek(f,o,w) \
217      (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
218                        "on 32-bit platforms - " \
219                        "use fseeko function for handling of large files"), \
220       fseek (f, o, w))
221 # endif
222 #endif
223
224 #if @GNULIB_FSEEKO@
225 # if @REPLACE_FSEEKO@
226 /* Provide fseek, fseeko functions that are aware of a preceding
227    fflush(), and which detect pipes.  */
228 #  define fseeko rpl_fseeko
229 extern int fseeko (FILE *fp, off_t offset, int whence);
230 #  define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
231 # endif
232 #elif defined GNULIB_POSIXCHECK
233 # undef fseeko
234 # define fseeko(f,o,w) \
235    (GL_LINK_WARNING ("fseeko is unportable - " \
236                      "use gnulib module fseeko for portability"), \
237     fseeko (f, o, w))
238 #endif
239
240 #if @GNULIB_FTELL@ && @REPLACE_FTELL@
241 extern long rpl_ftell (FILE *fp);
242 # undef ftell
243 # if GNULIB_POSIXCHECK
244 #  define ftell(f) \
245      (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
246                        "on 32-bit platforms - " \
247                        "use ftello function for handling of large files"), \
248       rpl_ftell (f))
249 # else
250 #  define ftell rpl_ftell
251 # endif
252 #elif defined GNULIB_POSIXCHECK
253 # ifndef ftell
254 #  define ftell(f) \
255      (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
256                        "on 32-bit platforms - " \
257                        "use ftello function for handling of large files"), \
258       ftell (f))
259 # endif
260 #endif
261
262 #if @GNULIB_FTELLO@
263 # if @REPLACE_FTELLO@
264 #  define ftello rpl_ftello
265 extern off_t ftello (FILE *fp);
266 #  define ftell(fp) ftello (fp)
267 # endif
268 #elif defined GNULIB_POSIXCHECK
269 # undef ftello
270 # define ftello(f) \
271    (GL_LINK_WARNING ("ftello is unportable - " \
272                      "use gnulib module ftello for portability"), \
273     ftello (f))
274 #endif
275
276 #if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
277 # undef fwrite
278 # define fwrite rpl_fwrite
279 extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
280 #endif
281
282 #if @GNULIB_GETDELIM@
283 # if !@HAVE_DECL_GETDELIM@
284 /* Read input, up to (and including) the next occurrence of DELIMITER, from
285    STREAM, store it in *LINEPTR (and NUL-terminate it).
286    *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
287    bytes of space.  It is realloc'd as necessary.
288    Return the number of bytes read and stored at *LINEPTR (not including the
289    NUL terminator), or -1 on error or EOF.  */
290 extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
291                          FILE *stream);
292 # endif
293 #elif defined GNULIB_POSIXCHECK
294 # undef getdelim
295 # define getdelim(l, s, d, f)                                       \
296   (GL_LINK_WARNING ("getdelim is unportable - "                     \
297                     "use gnulib module getdelim for portability"),  \
298    getdelim (l, s, d, f))
299 #endif
300
301 #if @GNULIB_GETLINE@
302 # if @REPLACE_GETLINE@
303 #  undef getline
304 #  define getline rpl_getline
305 # endif
306 # if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
307 /* Read a line, up to (and including) the next newline, from STREAM, store it
308    in *LINEPTR (and NUL-terminate it).
309    *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
310    bytes of space.  It is realloc'd as necessary.
311    Return the number of bytes read and stored at *LINEPTR (not including the
312    NUL terminator), or -1 on error or EOF.  */
313 extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
314 # endif
315 #elif defined GNULIB_POSIXCHECK
316 # undef getline
317 # define getline(l, s, f)                                               \
318   (GL_LINK_WARNING ("getline is unportable - "                          \
319                     "use gnulib module getline for portability"),       \
320    getline (l, s, f))
321 #endif
322
323 #if @GNULIB_OBSTACK_PRINTF@
324 # if @REPLACE_OBSTACK_PRINTF@
325 #  define obstack_printf rpl_osbtack_printf
326 #  define obstack_vprintf rpl_obstack_vprintf
327 # endif
328 # if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
329   struct obstack;
330   /* Grow an obstack with formatted output.  Return the number of
331      bytes added to OBS.  No trailing nul byte is added, and the
332      object should be closed with obstack_finish before use.  Upon
333      memory allocation error, call obstack_alloc_failed_handler.  Upon
334      other error, return -1.  */
335   extern int obstack_printf (struct obstack *obs, const char *format, ...)
336     __attribute__ ((__format__ (__printf__, 2, 3)));
337   extern int obstack_vprintf (struct obstack *obs, const char *format,
338                               va_list args)
339     __attribute__ ((__format__ (__printf__, 2, 0)));
340 # endif
341 #endif
342
343 #if @GNULIB_PERROR@
344 # if @REPLACE_PERROR@
345 #  define perror rpl_perror
346 /* Print a message to standard error, describing the value of ERRNO,
347    (if STRING is not NULL and not empty) prefixed with STRING and ": ",
348    and terminated with a newline.  */
349 extern void perror (const char *string);
350 # endif
351 #elif defined GNULIB_POSIXCHECK
352 # undef perror
353 # define perror(s) \
354     (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
355                       "use gnulib module perror for portability"), \
356      perror (s))
357 #endif
358
359 #if @GNULIB_POPEN@
360 # if @REPLACE_POPEN@
361 #  undef popen
362 #  define popen rpl_popen
363 extern FILE *popen (const char *cmd, const char *mode);
364 # endif
365 #elif defined GNULIB_POSIXCHECK
366 # undef popen
367 # define popen(c,m) \
368    (GL_LINK_WARNING ("popen is buggy on some platforms - " \
369                      "use gnulib module popen or pipe for more portability"), \
370     popen (c, m))
371 #endif
372
373 #if @GNULIB_PRINTF_POSIX@
374 # if @REPLACE_PRINTF@
375 /* Don't break __attribute__((format(printf,M,N))).  */
376 #  define printf __printf__
377 extern int printf (const char *format, ...)
378        __attribute__ ((__format__ (__printf__, 1, 2)));
379 # endif
380 #elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
381 /* Don't break __attribute__((format(printf,M,N))).  */
382 # define printf __printf__
383 extern int printf (const char *format, ...)
384        __attribute__ ((__format__ (__printf__, 1, 2)));
385 #elif defined GNULIB_POSIXCHECK
386 # undef printf
387 # define printf \
388     (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
389                       "use gnulib module printf-posix for portable " \
390                       "POSIX compliance"), \
391      printf)
392 /* Don't break __attribute__((format(printf,M,N))).  */
393 # define format(kind,m,n) format (__##kind##__, m, n)
394 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
395 # define ____printf____ __printf__
396 # define ____scanf____ __scanf__
397 # define ____strftime____ __strftime__
398 # define ____strfmon____ __strfmon__
399 #endif
400
401 #if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
402 # undef putc
403 # define putc rpl_fputc
404 extern int putc (int c, FILE *stream);
405 #endif
406
407 #if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
408 # undef putchar
409 # define putchar rpl_putchar
410 extern int putchar (int c);
411 #endif
412
413 #if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
414 # undef puts
415 # define puts rpl_puts
416 extern int puts (const char *string);
417 #endif
418
419 #if @GNULIB_RENAME@
420 # if @REPLACE_RENAME@
421 #  undef rename
422 #  define rename rpl_rename
423 extern int rename (const char *old, const char *new);
424 # endif
425 #elif defined GNULIB_POSIXCHECK
426 # undef rename
427 # define rename(o,n)                                       \
428    (GL_LINK_WARNING ("rename is buggy on some platforms - " \
429                      "use gnulib module rename for more portability"), \
430     rename (o, n))
431 #endif
432
433 #if @GNULIB_SNPRINTF@
434 # if @REPLACE_SNPRINTF@
435 #  define snprintf rpl_snprintf
436 # endif
437 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
438 extern int snprintf (char *str, size_t size, const char *format, ...)
439        __attribute__ ((__format__ (__printf__, 3, 4)));
440 # endif
441 #elif defined GNULIB_POSIXCHECK
442 # undef snprintf
443 # define snprintf \
444     (GL_LINK_WARNING ("snprintf is unportable - " \
445                       "use gnulib module snprintf for portability"), \
446      snprintf)
447 #endif
448
449 #if @GNULIB_SPRINTF_POSIX@
450 # if @REPLACE_SPRINTF@
451 #  define sprintf rpl_sprintf
452 extern int sprintf (char *str, const char *format, ...)
453        __attribute__ ((__format__ (__printf__, 2, 3)));
454 # endif
455 #elif defined GNULIB_POSIXCHECK
456 # undef sprintf
457 # define sprintf \
458     (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
459                       "use gnulib module sprintf-posix for portable " \
460                       "POSIX compliance"), \
461      sprintf)
462 #endif
463
464 #if @GNULIB_VASPRINTF@
465 # if @REPLACE_VASPRINTF@
466 #  define asprintf rpl_asprintf
467 #  define vasprintf rpl_vasprintf
468 # endif
469 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
470   /* Write formatted output to a string dynamically allocated with malloc().
471      If the memory allocation succeeds, store the address of the string in
472      *RESULT and return the number of resulting bytes, excluding the trailing
473      NUL.  Upon memory allocation error, or some other error, return -1.  */
474   extern int asprintf (char **result, const char *format, ...)
475     __attribute__ ((__format__ (__printf__, 2, 3)));
476   extern int vasprintf (char **result, const char *format, va_list args)
477     __attribute__ ((__format__ (__printf__, 2, 0)));
478 # endif
479 #endif
480
481 #if @GNULIB_VDPRINTF@
482 # if @REPLACE_VDPRINTF@
483 #  define vdprintf rpl_vdprintf
484 # endif
485 # if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
486 extern int vdprintf (int fd, const char *format, va_list args)
487        __attribute__ ((__format__ (__printf__, 2, 0)));
488 # endif
489 #elif defined GNULIB_POSIXCHECK
490 # undef vdprintf
491 # define vdprintf(d,f,a) \
492     (GL_LINK_WARNING ("vdprintf is unportable - " \
493                       "use gnulib module vdprintf for portability"), \
494      vdprintf (d, f, a))
495 #endif
496
497 #if @GNULIB_VFPRINTF_POSIX@
498 # if @REPLACE_VFPRINTF@
499 #  define vfprintf rpl_vfprintf
500 extern int vfprintf (FILE *fp, const char *format, va_list args)
501        __attribute__ ((__format__ (__printf__, 2, 0)));
502 # endif
503 #elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
504 # define vfprintf rpl_vfprintf
505 extern int vfprintf (FILE *fp, const char *format, va_list args)
506        __attribute__ ((__format__ (__printf__, 2, 0)));
507 #elif defined GNULIB_POSIXCHECK
508 # undef vfprintf
509 # define vfprintf(s,f,a) \
510     (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
511                       "use gnulib module vfprintf-posix for portable " \
512                       "POSIX compliance"), \
513      vfprintf (s, f, a))
514 #endif
515
516 #if @GNULIB_VPRINTF_POSIX@
517 # if @REPLACE_VPRINTF@
518 #  define vprintf rpl_vprintf
519 extern int vprintf (const char *format, va_list args)
520        __attribute__ ((__format__ (__printf__, 1, 0)));
521 # endif
522 #elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
523 # define vprintf rpl_vprintf
524 extern int vprintf (const char *format, va_list args)
525        __attribute__ ((__format__ (__printf__, 1, 0)));
526 #elif defined GNULIB_POSIXCHECK
527 # undef vprintf
528 # define vprintf(f,a) \
529     (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
530                       "use gnulib module vprintf-posix for portable " \
531                       "POSIX compliance"), \
532      vprintf (f, a))
533 #endif
534
535 #if @GNULIB_VSNPRINTF@
536 # if @REPLACE_VSNPRINTF@
537 #  define vsnprintf rpl_vsnprintf
538 # endif
539 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
540 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
541        __attribute__ ((__format__ (__printf__, 3, 0)));
542 # endif
543 #elif defined GNULIB_POSIXCHECK
544 # undef vsnprintf
545 # define vsnprintf(b,s,f,a) \
546     (GL_LINK_WARNING ("vsnprintf is unportable - " \
547                       "use gnulib module vsnprintf for portability"), \
548      vsnprintf (b, s, f, a))
549 #endif
550
551 #if @GNULIB_VSPRINTF_POSIX@
552 # if @REPLACE_VSPRINTF@
553 #  define vsprintf rpl_vsprintf
554 extern int vsprintf (char *str, const char *format, va_list args)
555        __attribute__ ((__format__ (__printf__, 2, 0)));
556 # endif
557 #elif defined GNULIB_POSIXCHECK
558 # undef vsprintf
559 # define vsprintf(b,f,a) \
560     (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
561                       "use gnulib module vsprintf-posix for portable " \
562                       "POSIX compliance"), \
563      vsprintf (b, f, a))
564 #endif
565
566 #ifdef __cplusplus
567 }
568 #endif
569
570 #endif /* _GL_STDIO_H */
571 #endif /* _GL_STDIO_H */
572 #endif