1/* A GNU-like <stdio.h>.
2
3   Copyright (C) 2004, 2007 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 defined __need_FILE || defined __need___FILE
20/* Special invocation convention inside glibc header files.  */
21
22#if @HAVE_INCLUDE_NEXT@
23# include_next <stdio.h>
24#else
25# include @ABSOLUTE_STDIO_H@
26#endif
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#if @HAVE_INCLUDE_NEXT@
35# include_next <stdio.h>
36#else
37# include @ABSOLUTE_STDIO_H@
38#endif
39
40#ifndef _GL_STDIO_H
41#define _GL_STDIO_H
42
43#include <stdarg.h>
44#include <stddef.h>
45
46#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@)
47/* Get off_t.  */
48# include <sys/types.h>
49#endif
50
51#ifndef __attribute__
52/* This feature is available in gcc versions 2.5 and later.  */
53# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
54#  define __attribute__(Spec) /* empty */
55# endif
56/* The __-protected variants of `format' and `printf' attributes
57   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
58# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
59#  define __format__ format
60#  define __printf__ printf
61# endif
62#endif
63
64
65/* The definition of GL_LINK_WARNING is copied here.  */
66
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72
73#if @GNULIB_FPRINTF_POSIX@
74# if @REPLACE_FPRINTF@
75#  define fprintf rpl_fprintf
76extern int fprintf (FILE *fp, const char *format, ...)
77       __attribute__ ((__format__ (__printf__, 2, 3)));
78# endif
79#elif defined GNULIB_POSIXCHECK
80# undef fprintf
81# define fprintf \
82    (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
83                      "use gnulib module fprintf-posix for portable " \
84                      "POSIX compliance"), \
85     fprintf)
86#endif
87
88#if @GNULIB_VFPRINTF_POSIX@
89# if @REPLACE_VFPRINTF@
90#  define vfprintf rpl_vfprintf
91extern int vfprintf (FILE *fp, const char *format, va_list args)
92       __attribute__ ((__format__ (__printf__, 2, 0)));
93# endif
94#elif defined GNULIB_POSIXCHECK
95# undef vfprintf
96# define vfprintf(s,f,a) \
97    (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
98                      "use gnulib module vfprintf-posix for portable " \
99                      "POSIX compliance"), \
100     vfprintf (s, f, a))
101#endif
102
103#if @GNULIB_PRINTF_POSIX@
104# if @REPLACE_PRINTF@
105/* Don't break __attribute__((format(printf,M,N))).  */
106#  define printf __printf__
107extern int printf (const char *format, ...)
108       __attribute__ ((__format__ (__printf__, 1, 2)));
109# endif
110#elif defined GNULIB_POSIXCHECK
111# undef printf
112# define printf \
113    (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
114                      "use gnulib module printf-posix for portable " \
115                      "POSIX compliance"), \
116     printf)
117/* Don't break __attribute__((format(printf,M,N))).  */
118# define format(kind,m,n) format (__##kind##__, m, n)
119# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
120# define ____printf____ __printf__
121# define ____scanf____ __scanf__
122# define ____strftime____ __strftime__
123# define ____strfmon____ __strfmon__
124#endif
125
126#if @GNULIB_VPRINTF_POSIX@
127# if @REPLACE_VPRINTF@
128#  define vprintf rpl_vprintf
129extern int vprintf (const char *format, va_list args)
130       __attribute__ ((__format__ (__printf__, 1, 0)));
131# endif
132#elif defined GNULIB_POSIXCHECK
133# undef vprintf
134# define vprintf(f,a) \
135    (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
136                      "use gnulib module vprintf-posix for portable " \
137                      "POSIX compliance"), \
138     vprintf (f, a))
139#endif
140
141#if @GNULIB_SNPRINTF@
142# if @REPLACE_SNPRINTF@
143#  define snprintf rpl_snprintf
144# endif
145# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
146extern int snprintf (char *str, size_t size, const char *format, ...)
147       __attribute__ ((__format__ (__printf__, 3, 4)));
148# endif
149#elif defined GNULIB_POSIXCHECK
150# undef snprintf
151# define snprintf \
152    (GL_LINK_WARNING ("snprintf is unportable - " \
153                      "use gnulib module snprintf for portability"), \
154     snprintf)
155#endif
156
157#if @GNULIB_VSNPRINTF@
158# if @REPLACE_VSNPRINTF@
159#  define vsnprintf rpl_vsnprintf
160# endif
161# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
162extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
163       __attribute__ ((__format__ (__printf__, 3, 0)));
164# endif
165#elif defined GNULIB_POSIXCHECK
166# undef vsnprintf
167# define vsnprintf(b,s,f,a) \
168    (GL_LINK_WARNING ("vsnprintf is unportable - " \
169                      "use gnulib module vsnprintf for portability"), \
170     vsnprintf (b, s, f, a))
171#endif
172
173#if @GNULIB_SPRINTF_POSIX@
174# if @REPLACE_SPRINTF@
175#  define sprintf rpl_sprintf
176extern int sprintf (char *str, const char *format, ...)
177       __attribute__ ((__format__ (__printf__, 2, 3)));
178# endif
179#elif defined GNULIB_POSIXCHECK
180# undef sprintf
181# define sprintf \
182    (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
183                      "use gnulib module sprintf-posix for portable " \
184                      "POSIX compliance"), \
185     sprintf)
186#endif
187
188#if @GNULIB_VSPRINTF_POSIX@
189# if @REPLACE_VSPRINTF@
190#  define vsprintf rpl_vsprintf
191extern int vsprintf (char *str, const char *format, va_list args)
192       __attribute__ ((__format__ (__printf__, 2, 0)));
193# endif
194#elif defined GNULIB_POSIXCHECK
195# undef vsprintf
196# define vsprintf(b,f,a) \
197    (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
198                      "use gnulib module vsprintf-posix for portable " \
199                      "POSIX compliance"), \
200     vsprintf (b, f, a))
201#endif
202
203#if @GNULIB_VASPRINTF@
204# if @REPLACE_VASPRINTF@
205#  define asprintf rpl_asprintf
206#  define vasprintf rpl_vasprintf
207# endif
208# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
209  /* Write formatted output to a string dynamically allocated with malloc().
210     If the memory allocation succeeds, store the address of the string in
211     *RESULT and return the number of resulting bytes, excluding the trailing
212     NUL.  Upon memory allocation error, or some other error, return -1.  */
213  extern int asprintf (char **result, const char *format, ...)
214    __attribute__ ((__format__ (__printf__, 2, 3)));
215  extern int vasprintf (char **result, const char *format, va_list args)
216    __attribute__ ((__format__ (__printf__, 2, 0)));
217# endif
218#endif
219
220#if @GNULIB_FSEEKO@
221# if @REPLACE_FSEEKO@
222/* Provide fseek, fseeko functions that are aware of a preceding
223   fflush(), and which detect pipes.  */
224#  define fseeko rpl_fseeko
225extern int fseeko (FILE *fp, off_t offset, int whence);
226#  define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
227# endif
228#elif defined GNULIB_POSIXCHECK
229# undef fseeko
230# define fseeko(f,o,w) \
231   (GL_LINK_WARNING ("fseeko is unportable - " \
232                     "use gnulib module fseeko for portability"), \
233    fseeko (f, o, w))
234#endif
235
236#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
237extern int rpl_fseek (FILE *fp, long offset, int whence);
238# undef fseek
239# if defined GNULIB_POSIXCHECK
240#  define fseek(f,o,w) \
241     (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
242                       "on 32-bit platforms - " \
243                       "use fseeko function for handling of large files"), \
244      rpl_fseek (f, o, w))
245# else
246#  define fseek rpl_fseek
247# endif
248#elif defined GNULIB_POSIXCHECK
249# ifndef fseek
250#  define fseek(f,o,w) \
251     (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
252                       "on 32-bit platforms - " \
253                       "use fseeko function for handling of large files"), \
254      fseek (f, o, w))
255# endif
256#endif
257
258#if @GNULIB_FTELLO@
259# if @REPLACE_FTELLO@
260#  define ftello rpl_ftello
261extern off_t ftello (FILE *fp);
262#  define ftell(fp) ftello (fp)
263# endif
264#elif defined GNULIB_POSIXCHECK
265# undef ftello
266# define ftello(f) \
267   (GL_LINK_WARNING ("ftello is unportable - " \
268                     "use gnulib module ftello for portability"), \
269    ftello (f))
270#endif
271
272#if @GNULIB_FTELL@ && @REPLACE_FTELL@
273extern long rpl_ftell (FILE *fp);
274# undef ftell
275# if GNULIB_POSIXCHECK
276#  define ftell(f) \
277     (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
278                       "on 32-bit platforms - " \
279                       "use ftello function for handling of large files"), \
280      rpl_ftell (f))
281# else
282#  define ftell rpl_ftell
283# endif
284#elif defined GNULIB_POSIXCHECK
285# ifndef ftell
286#  define ftell(f) \
287     (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
288                       "on 32-bit platforms - " \
289                       "use ftello function for handling of large files"), \
290      ftell (f))
291# endif
292#endif
293
294#if @GNULIB_FFLUSH@
295# if @REPLACE_FFLUSH@
296#  define fflush rpl_fflush
297  /* Flush all pending data on STREAM according to POSIX rules.  Both
298     output and seekable input streams are supported.
299     Note! LOSS OF DATA can occur if fflush is applied on an input stream
300     that is _not_seekable_ or on an update stream that is _not_seekable_
301     and in which the most recent operation was input.  Seekability can
302     be tested with lseek(fileno(fp),0,SEEK_CUR).  */
303  extern int fflush (FILE *gl_stream);
304# endif
305#elif defined GNULIB_POSIXCHECK
306# undef fflush
307# define fflush(f) \
308   (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
309                     "use gnulib module fflush for portable " \
310                     "POSIX compliance"), \
311    fflush (f))
312#endif
313
314#ifdef __cplusplus
315}
316#endif
317
318#endif /* _GL_STDIO_H */
319#endif /* _GL_STDIO_H */
320#endif
321