Fix lseek on mingw.
[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_FSEEKO@ && @REPLACE_FSEEKO@) || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@)
46 /* Get off_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) || __STRICT_ANSI__
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
72 #if @GNULIB_FPRINTF_POSIX@
73 # if @REPLACE_FPRINTF@
74 #  define fprintf rpl_fprintf
75 extern int fprintf (FILE *fp, const char *format, ...)
76        __attribute__ ((__format__ (__printf__, 2, 3)));
77 # endif
78 #elif defined GNULIB_POSIXCHECK
79 # undef fprintf
80 # define fprintf \
81     (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
82                       "use gnulib module fprintf-posix for portable " \
83                       "POSIX compliance"), \
84      fprintf)
85 #endif
86
87 #if @GNULIB_VFPRINTF_POSIX@
88 # if @REPLACE_VFPRINTF@
89 #  define vfprintf rpl_vfprintf
90 extern int vfprintf (FILE *fp, const char *format, va_list args)
91        __attribute__ ((__format__ (__printf__, 2, 0)));
92 # endif
93 #elif defined GNULIB_POSIXCHECK
94 # undef vfprintf
95 # define vfprintf(s,f,a) \
96     (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
97                       "use gnulib module vfprintf-posix for portable " \
98                       "POSIX compliance"), \
99      vfprintf (s, f, a))
100 #endif
101
102 #if @GNULIB_PRINTF_POSIX@
103 # if @REPLACE_PRINTF@
104 /* Don't break __attribute__((format(printf,M,N))).  */
105 #  define printf __printf__
106 extern int printf (const char *format, ...)
107        __attribute__ ((__format__ (__printf__, 1, 2)));
108 # endif
109 #elif defined GNULIB_POSIXCHECK
110 # undef printf
111 # define printf \
112     (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
113                       "use gnulib module printf-posix for portable " \
114                       "POSIX compliance"), \
115      printf)
116 /* Don't break __attribute__((format(printf,M,N))).  */
117 # define format(kind,m,n) format (__##kind##__, m, n)
118 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
119 # define ____printf____ __printf__
120 # define ____scanf____ __scanf__
121 # define ____strftime____ __strftime__
122 # define ____strfmon____ __strfmon__
123 #endif
124
125 #if @GNULIB_VPRINTF_POSIX@
126 # if @REPLACE_VPRINTF@
127 #  define vprintf rpl_vprintf
128 extern int vprintf (const char *format, va_list args)
129        __attribute__ ((__format__ (__printf__, 1, 0)));
130 # endif
131 #elif defined GNULIB_POSIXCHECK
132 # undef vprintf
133 # define vprintf(f,a) \
134     (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
135                       "use gnulib module vprintf-posix for portable " \
136                       "POSIX compliance"), \
137      vprintf (f, a))
138 #endif
139
140 #if @GNULIB_SNPRINTF@
141 # if @REPLACE_SNPRINTF@
142 #  define snprintf rpl_snprintf
143 # endif
144 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
145 extern int snprintf (char *str, size_t size, const char *format, ...)
146        __attribute__ ((__format__ (__printf__, 3, 4)));
147 # endif
148 #elif defined GNULIB_POSIXCHECK
149 # undef snprintf
150 # define snprintf \
151     (GL_LINK_WARNING ("snprintf is unportable - " \
152                       "use gnulib module snprintf for portability"), \
153      snprintf)
154 #endif
155
156 #if @GNULIB_VSNPRINTF@
157 # if @REPLACE_VSNPRINTF@
158 #  define vsnprintf rpl_vsnprintf
159 # endif
160 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
161 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
162        __attribute__ ((__format__ (__printf__, 3, 0)));
163 # endif
164 #elif defined GNULIB_POSIXCHECK
165 # undef vsnprintf
166 # define vsnprintf(b,s,f,a) \
167     (GL_LINK_WARNING ("vsnprintf is unportable - " \
168                       "use gnulib module vsnprintf for portability"), \
169      vsnprintf (b, s, f, a))
170 #endif
171
172 #if @GNULIB_SPRINTF_POSIX@
173 # if @REPLACE_SPRINTF@
174 #  define sprintf rpl_sprintf
175 extern int sprintf (char *str, const char *format, ...)
176        __attribute__ ((__format__ (__printf__, 2, 3)));
177 # endif
178 #elif defined GNULIB_POSIXCHECK
179 # undef sprintf
180 # define sprintf \
181     (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
182                       "use gnulib module sprintf-posix for portable " \
183                       "POSIX compliance"), \
184      sprintf)
185 #endif
186
187 #if @GNULIB_VSPRINTF_POSIX@
188 # if @REPLACE_VSPRINTF@
189 #  define vsprintf rpl_vsprintf
190 extern int vsprintf (char *str, const char *format, va_list args)
191        __attribute__ ((__format__ (__printf__, 2, 0)));
192 # endif
193 #elif defined GNULIB_POSIXCHECK
194 # undef vsprintf
195 # define vsprintf(b,f,a) \
196     (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
197                       "use gnulib module vsprintf-posix for portable " \
198                       "POSIX compliance"), \
199      vsprintf (b, f, a))
200 #endif
201
202 #if @GNULIB_VASPRINTF@
203 # if @REPLACE_VASPRINTF@
204 #  define asprintf rpl_asprintf
205 #  define vasprintf rpl_vasprintf
206 # endif
207 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
208   /* Write formatted output to a string dynamically allocated with malloc().
209      If the memory allocation succeeds, store the address of the string in
210      *RESULT and return the number of resulting bytes, excluding the trailing
211      NUL.  Upon memory allocation error, or some other error, return -1.  */
212   extern int asprintf (char **result, const char *format, ...)
213     __attribute__ ((__format__ (__printf__, 2, 3)));
214   extern int vasprintf (char **result, const char *format, va_list args)
215     __attribute__ ((__format__ (__printf__, 2, 0)));
216 # endif
217 #endif
218
219 #if @GNULIB_FSEEKO@
220 # if @REPLACE_FSEEKO@
221 /* Provide fseek, fseeko functions that are aware of a preceding
222    fflush(), and which detect pipes.  */
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 # endif
227 #elif defined GNULIB_POSIXCHECK
228 # undef fseeko
229 # define fseeko(f,o,w) \
230    (GL_LINK_WARNING ("fseeko is unportable - " \
231                      "use gnulib module fseeko for portability"), \
232     fseeko (f, o, w))
233 #endif
234
235 #if defined GNULIB_POSIXCHECK
236 # ifndef fseek
237 #  define fseek(f,o,w) \
238      (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
239                        "on 32-bit platforms - " \
240                        "use fseeko function for handling of large files"), \
241       fseek (f, o, w))
242 # endif
243 #endif
244
245 #if @GNULIB_FTELLO@
246 # if @REPLACE_FTELLO@
247 #  define ftello rpl_ftello
248 extern off_t ftello (FILE *fp);
249 #  define ftell(fp) ftello (fp)
250 # endif
251 #elif defined GNULIB_POSIXCHECK
252 # undef ftello
253 # define ftello(f) \
254    (GL_LINK_WARNING ("ftello is unportable - " \
255                      "use gnulib module ftello for portability"), \
256     ftello (f))
257 #endif
258
259 #if defined GNULIB_POSIXCHECK
260 # ifndef ftell
261 #  define ftell(f) \
262      (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
263                        "on 32-bit platforms - " \
264                        "use ftello function for handling of large files"), \
265       ftell (f))
266 # endif
267 #endif
268
269 #if @GNULIB_FFLUSH@
270 # if @REPLACE_FFLUSH@
271 #  define fflush rpl_fflush
272   /* Flush all pending data on STREAM according to POSIX rules.  Both
273      output and seekable input streams are supported.  */
274   extern int fflush (FILE *gl_stream);
275 # endif
276 #elif defined GNULIB_POSIXCHECK
277 # undef fflush
278 # define fflush(f) \
279    (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
280                      "use gnulib module fflush for portable " \
281                      "POSIX compliance"), \
282     fflush (f))
283 #endif
284
285 #ifdef __cplusplus
286 }
287 #endif
288
289 #endif /* _GL_STDIO_H */
290 #endif