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