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