a7070101c3917898a9a3083a3dea202ebd05f69b
[reactos.git] / reactos / lib / mingw / include / stdio.h
1 /*
2 * stdio.h
3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
6 *
7 * Definitions of types and prototypes of functions for standard input and
8 * output.
9 *
10 * NOTE: The file manipulation functions provided by Microsoft seem to
11 * work with either slash (/) or backslash (\) as the directory separator.
12 *
13 */
14
15 #ifndef _STDIO_H_
16 #define _STDIO_H_
17
18 /* All the headers include this file. */
19 #include <_mingw.h>
20
21 #ifndef RC_INVOKED
22 #define __need_size_t
23 #define __need_NULL
24 #define __need_wchar_t
25 #define __need_wint_t
26 #include <stddef.h>
27 #define __need___va_list
28 #include <stdarg.h>
29 #endif /* Not RC_INVOKED */
30
31
32 /* Flags for the iobuf structure */
33 #define _IOREAD 1 /* currently reading */
34 #define _IOWRT 2 /* currently writing */
35 #define _IORW 0x0080 /* opened as "r+w" */
36
37
38 /*
39 * The three standard file pointers provided by the run time library.
40 * NOTE: These will go to the bit-bucket silently in GUI applications!
41 */
42 #define STDIN_FILENO 0
43 #define STDOUT_FILENO 1
44 #define STDERR_FILENO 2
45
46 /* Returned by various functions on end of file condition or error. */
47 #define EOF (-1)
48
49 /*
50 * The maximum length of a file name. You should use GetVolumeInformation
51 * instead of this constant. But hey, this works.
52 * Also defined in io.h.
53 */
54 #ifndef FILENAME_MAX
55 #define FILENAME_MAX (260)
56 #endif
57
58 /*
59 * The maximum number of files that may be open at once. I have set this to
60 * a conservative number. The actual value may be higher.
61 */
62 #define FOPEN_MAX (20)
63
64 /* After creating this many names, tmpnam and tmpfile return NULL */
65 #define TMP_MAX 32767
66 /*
67 * Tmpnam, tmpfile and, sometimes, _tempnam try to create
68 * temp files in the root directory of the current drive
69 * (not in pwd, as suggested by some older MS doc's).
70 * Redefining these macros does not effect the CRT functions.
71 */
72 #define _P_tmpdir "\\"
73 #ifndef __STRICT_ANSI__
74 #define P_tmpdir _P_tmpdir
75 #endif
76 #define _wP_tmpdir L"\\"
77
78 /*
79 * The maximum size of name (including NUL) that will be put in the user
80 * supplied buffer caName for tmpnam.
81 * Inferred from the size of the static buffer returned by tmpnam
82 * when passed a NULL argument. May actually be smaller.
83 */
84 #define L_tmpnam (16)
85
86 #define _IOFBF 0x0000 /* full buffered */
87 #define _IOLBF 0x0040 /* line buffered */
88 #define _IONBF 0x0004 /* not buffered */
89
90 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
91 #define _IOEOF 0x0010 /* EOF reached on read */
92 #define _IOERR 0x0020 /* I/O error from system */
93 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
94 #ifdef _POSIX_SOURCE
95 # define _IOAPPEND 0x0200
96 #endif
97 /*
98 * The buffer size as used by setbuf such that it is equivalent to
99 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
100 */
101 #define BUFSIZ 512
102
103 /* Constants for nOrigin indicating the position relative to which fseek
104 * sets the file position. Enclosed in ifdefs because io.h could also
105 * define them. (Though not anymore since io.h includes this file now.) */
106 #ifndef SEEK_SET
107 #define SEEK_SET (0)
108 #endif
109
110 #ifndef SEEK_CUR
111 #define SEEK_CUR (1)
112 #endif
113
114 #ifndef SEEK_END
115 #define SEEK_END (2)
116 #endif
117
118
119 #ifndef RC_INVOKED
120
121 #ifndef __VALIST
122 #ifdef __GNUC__
123 #define __VALIST __gnuc_va_list
124 #else
125 #define __VALIST char*
126 #endif
127 #endif /* defined __VALIST */
128
129 /*
130 * The structure underlying the FILE type.
131 *
132 * Some believe that nobody in their right mind should make use of the
133 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
134 * <paag@tid.es>.
135 */
136 #ifndef _FILE_DEFINED
137 #define _FILE_DEFINED
138 typedef struct _iobuf
139 {
140 char* _ptr;
141 int _cnt;
142 char* _base;
143 int _flag;
144 int _file;
145 int _charbuf;
146 int _bufsiz;
147 char* _tmpfname;
148 } FILE;
149 #endif /* Not _FILE_DEFINED */
150
151
152 /*
153 * The standard file handles
154 */
155 #ifndef __DECLSPEC_SUPPORTED
156
157 extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */
158
159 #define _iob (*_imp___iob) /* An array of FILE */
160
161 #else /* __DECLSPEC_SUPPORTED */
162
163 __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */
164
165 #endif /* __DECLSPEC_SUPPORTED */
166
167 #define stdin (&_iob[STDIN_FILENO])
168 #define stdout (&_iob[STDOUT_FILENO])
169 #define stderr (&_iob[STDERR_FILENO])
170
171 #ifdef __cplusplus
172 extern "C" {
173 #endif
174
175 /*
176 * File Operations
177 */
178 _CRTIMP FILE* __cdecl fopen (const char*, const char*);
179 _CRTIMP FILE* __cdecl freopen (const char*, const char*, FILE*);
180 _CRTIMP int __cdecl fflush (FILE*);
181 _CRTIMP int __cdecl fclose (FILE*);
182 /* MS puts remove & rename (but not wide versions) in io.h also */
183 _CRTIMP int __cdecl remove (const char*);
184 _CRTIMP int __cdecl rename (const char*, const char*);
185 _CRTIMP FILE* __cdecl tmpfile (void);
186 _CRTIMP char* __cdecl tmpnam (char*);
187
188 #ifndef __STRICT_ANSI__
189 _CRTIMP char* __cdecl _tempnam (const char*, const char*);
190 _CRTIMP int __cdecl _rmtmp(void);
191
192 #ifndef NO_OLDNAMES
193 _CRTIMP char* __cdecl tempnam (const char*, const char*);
194 _CRTIMP int __cdecl rmtmp(void);
195 #endif
196 #endif /* __STRICT_ANSI__ */
197
198 _CRTIMP int __cdecl setvbuf (FILE*, char*, int, size_t);
199
200 _CRTIMP void __cdecl setbuf (FILE*, char*);
201
202 /*
203 * Formatted Output
204 */
205
206 _CRTIMP int __cdecl fprintf (FILE*, const char*, ...);
207 _CRTIMP int __cdecl printf (const char*, ...);
208 _CRTIMP int __cdecl sprintf (char*, const char*, ...);
209 _CRTIMP int __cdecl _snprintf (char*, size_t, const char*, ...);
210 _CRTIMP int __cdecl vfprintf (FILE*, const char*, __VALIST);
211 _CRTIMP int __cdecl vprintf (const char*, __VALIST);
212 _CRTIMP int __cdecl vsprintf (char*, const char*, __VALIST);
213 _CRTIMP int __cdecl _vsnprintf (char*, size_t, const char*, __VALIST);
214
215 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
216 int __cdecl snprintf(char* s, size_t n, const char* format, ...);
217 __CRT_INLINE int __cdecl
218 vsnprintf (char* s, size_t n, const char* format, __VALIST arg)
219 { return _vsnprintf ( s, n, format, arg); }
220 int __cdecl vscanf (const char * __restrict__, __VALIST);
221 int __cdecl vfscanf (FILE * __restrict__, const char * __restrict__,
222 __VALIST);
223 int __cdecl vsscanf (const char * __restrict__,
224 const char * __restrict__, __VALIST);
225 #endif
226
227 /*
228 * Formatted Input
229 */
230
231 _CRTIMP int __cdecl fscanf (FILE*, const char*, ...);
232 _CRTIMP int __cdecl scanf (const char*, ...);
233 _CRTIMP int __cdecl sscanf (const char*, const char*, ...);
234 /*
235 * Character Input and Output Functions
236 */
237
238 _CRTIMP int __cdecl fgetc (FILE*);
239 _CRTIMP char* __cdecl fgets (char*, int, FILE*);
240 _CRTIMP int __cdecl fputc (int, FILE*);
241 _CRTIMP int __cdecl fputs (const char*, FILE*);
242 _CRTIMP char* __cdecl gets (char*);
243 _CRTIMP int __cdecl puts (const char*);
244 _CRTIMP int __cdecl ungetc (int, FILE*);
245
246 /* Traditionally, getc and putc are defined as macros. but the
247 standard doesn't say that they must be macros.
248 We use inline functions here to allow the fast versions
249 to be used in C++ with namespace qualification, eg., ::getc.
250
251 _filbuf and _flsbuf are not thread-safe. */
252 _CRTIMP int __cdecl _filbuf (FILE*);
253 _CRTIMP int __cdecl _flsbuf (int, FILE*);
254
255 #if !defined _MT
256
257 __CRT_INLINE int __cdecl getc (FILE* __F)
258 {
259 return (--__F->_cnt >= 0)
260 ? (int) (unsigned char) *__F->_ptr++
261 : _filbuf (__F);
262 }
263
264 __CRT_INLINE int __cdecl putc (int __c, FILE* __F)
265 {
266 return (--__F->_cnt >= 0)
267 ? (int) (unsigned char) (*__F->_ptr++ = (char)__c)
268 : _flsbuf (__c, __F);
269 }
270
271 __CRT_INLINE int __cdecl getchar (void)
272 {
273 return (--stdin->_cnt >= 0)
274 ? (int) (unsigned char) *stdin->_ptr++
275 : _filbuf (stdin);
276 }
277
278 __CRT_INLINE int __cdecl putchar(int __c)
279 {
280 return (--stdout->_cnt >= 0)
281 ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
282 : _flsbuf (__c, stdout);}
283
284 #else /* Use library functions. */
285
286 _CRTIMP int __cdecl getc (FILE*);
287 _CRTIMP int __cdecl putc (int, FILE*);
288 _CRTIMP int __cdecl getchar (void);
289 _CRTIMP int __cdecl putchar (int);
290
291 #endif
292
293 /*
294 * Direct Input and Output Functions
295 */
296
297 _CRTIMP size_t __cdecl fread (void*, size_t, size_t, FILE*);
298 _CRTIMP size_t __cdecl fwrite (const void*, size_t, size_t, FILE*);
299
300 /*
301 * File Positioning Functions
302 */
303
304 _CRTIMP int __cdecl fseek (FILE*, long, int);
305 _CRTIMP long __cdecl ftell (FILE*);
306 _CRTIMP void __cdecl rewind (FILE*);
307
308 #ifdef __USE_MINGW_FSEEK /* These are in libmingwex.a */
309 /*
310 * Workaround for limitations on win9x where a file contents are
311 * not zero'd out if you seek past the end and then write.
312 */
313
314 int __cdecl __mingw_fseek (FILE *, long, int);
315 size_t __cdecl __mingw_fwrite (const void*, size_t, size_t, FILE*);
316 #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence)
317 #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp)
318 #endif /* __USE_MINGW_FSEEK */
319
320 /*
321 * An opaque data type used for storing file positions... The contents of
322 * this type are unknown, but we (the compiler) need to know the size
323 * because the programmer using fgetpos and fsetpos will be setting aside
324 * storage for fpos_t structres. Actually I tested using a byte array and
325 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
326 * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
327 * MSVCRT however, and for now `long long' will do.
328 */
329 #ifdef __MSVCRT__
330 typedef long long fpos_t;
331 #else
332 typedef long fpos_t;
333 #endif
334
335 _CRTIMP int __cdecl fgetpos (FILE*, fpos_t*);
336 _CRTIMP int __cdecl fsetpos (FILE*, const fpos_t*);
337
338 /*
339 * Error Functions
340 */
341
342 _CRTIMP int __cdecl feof (FILE*);
343 _CRTIMP int __cdecl ferror (FILE*);
344
345 #ifdef __cplusplus
346 inline int __cdecl feof (FILE* __F)
347 { return __F->_flag & _IOEOF; }
348 inline int __cdecl ferror (FILE* __F)
349 { return __F->_flag & _IOERR; }
350 #else
351 #define feof(__F) ((__F)->_flag & _IOEOF)
352 #define ferror(__F) ((__F)->_flag & _IOERR)
353 #endif
354
355 _CRTIMP void __cdecl clearerr (FILE*);
356 _CRTIMP void __cdecl perror (const char*);
357
358
359 #ifndef __STRICT_ANSI__
360 /*
361 * Pipes
362 */
363 _CRTIMP FILE* __cdecl _popen (const char*, const char*);
364 _CRTIMP int __cdecl _pclose (FILE*);
365
366 #ifndef NO_OLDNAMES
367 _CRTIMP FILE* __cdecl popen (const char*, const char*);
368 _CRTIMP int __cdecl pclose (FILE*);
369 #endif
370
371 /*
372 * Other Non ANSI functions
373 */
374 _CRTIMP int __cdecl _flushall (void);
375 _CRTIMP int __cdecl _fgetchar (void);
376 _CRTIMP int __cdecl _fputchar (int);
377 _CRTIMP FILE* __cdecl _fdopen (int, const char*);
378 _CRTIMP int __cdecl _fileno (FILE*);
379 _CRTIMP int __cdecl _fcloseall(void);
380 _CRTIMP FILE* __cdecl _fsopen(const char*, const char*, int);
381 #ifdef __MSVCRT__
382 _CRTIMP int __cdecl _getmaxstdio(void);
383 _CRTIMP int __cdecl _setmaxstdio(int);
384 #endif
385
386 #ifndef _NO_OLDNAMES
387 _CRTIMP int __cdecl fgetchar (void);
388 _CRTIMP int __cdecl fputchar (int);
389 _CRTIMP FILE* __cdecl fdopen (int, const char*);
390 _CRTIMP int __cdecl fileno (FILE*);
391 #endif /* Not _NO_OLDNAMES */
392
393 #define _fileno(__F) ((__F)->_file)
394 #ifndef _NO_OLDNAMES
395 #define fileno(__F) ((__F)->_file)
396 #endif
397
398 #if defined (__MSVCRT__) && !defined (__NO_MINGW_LFS)
399 #include <sys/types.h>
400 __CRT_INLINE FILE* __cdecl fopen64 (const char* filename, const char* mode)
401 {
402 return fopen (filename, mode);
403 }
404
405 int __cdecl fseeko64 (FILE*, off64_t, int);
406
407 #ifdef __USE_MINGW_FSEEK
408 int __cdecl __mingw_fseeko64 (FILE *, off64_t, int);
409 #define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence)
410 #endif
411
412 __CRT_INLINE off64_t __cdecl ftello64 (FILE * stream)
413 {
414 fpos_t pos;
415 if (fgetpos(stream, &pos))
416 return -1LL;
417 else
418 return ((off64_t) pos);
419 }
420 #endif /* __NO_MINGW_LFS */
421
422 #endif /* Not __STRICT_ANSI__ */
423
424 /* Wide versions */
425
426 #ifndef _WSTDIO_DEFINED
427 /* also in wchar.h - keep in sync */
428 _CRTIMP int __cdecl fwprintf (FILE*, const wchar_t*, ...);
429 _CRTIMP int __cdecl wprintf (const wchar_t*, ...);
430 _CRTIMP int __cdecl swprintf (wchar_t*, const wchar_t*, ...);
431 _CRTIMP int __cdecl _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
432 _CRTIMP int __cdecl vfwprintf (FILE*, const wchar_t*, __VALIST);
433 _CRTIMP int __cdecl vwprintf (const wchar_t*, __VALIST);
434 _CRTIMP int __cdecl vswprintf (wchar_t*, const wchar_t*, __VALIST);
435 _CRTIMP int __cdecl _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
436 _CRTIMP int __cdecl fwscanf (FILE*, const wchar_t*, ...);
437 _CRTIMP int __cdecl wscanf (const wchar_t*, ...);
438 _CRTIMP int __cdecl swscanf (const wchar_t*, const wchar_t*, ...);
439 _CRTIMP wint_t __cdecl fgetwc (FILE*);
440 _CRTIMP wint_t __cdecl fputwc (wchar_t, FILE*);
441 _CRTIMP wint_t __cdecl ungetwc (wchar_t, FILE*);
442
443 #ifdef __MSVCRT__
444 _CRTIMP wchar_t* __cdecl fgetws (wchar_t*, int, FILE*);
445 _CRTIMP int __cdecl fputws (const wchar_t*, FILE*);
446 _CRTIMP wint_t __cdecl getwc (FILE*);
447 _CRTIMP wint_t __cdecl getwchar (void);
448 _CRTIMP wchar_t* __cdecl _getws (wchar_t*);
449 _CRTIMP wint_t __cdecl putwc (wint_t, FILE*);
450 _CRTIMP int __cdecl _putws (const wchar_t*);
451 _CRTIMP wint_t __cdecl putwchar (wint_t);
452 _CRTIMP FILE* __cdecl _wfdopen(int, wchar_t *);
453 _CRTIMP FILE* __cdecl _wfopen (const wchar_t*, const wchar_t*);
454 _CRTIMP FILE* __cdecl _wfreopen (const wchar_t*, const wchar_t*, FILE*);
455 _CRTIMP FILE* __cdecl _wfsopen (const wchar_t*, const wchar_t*, int);
456 _CRTIMP wchar_t* __cdecl _wtmpnam (wchar_t*);
457 _CRTIMP wchar_t* __cdecl _wtempnam (const wchar_t*, const wchar_t*);
458 _CRTIMP int __cdecl _wrename (const wchar_t*, const wchar_t*);
459 _CRTIMP int __cdecl _wremove (const wchar_t*);
460 _CRTIMP void __cdecl _wperror (const wchar_t*);
461 _CRTIMP FILE* __cdecl _wpopen (const wchar_t*, const wchar_t*);
462 #endif /* __MSVCRT__ */
463
464 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
465 int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...);
466 __CRT_INLINE int __cdecl
467 vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
468 { return _vsnwprintf ( s, n, format, arg);}
469 int __cdecl vwscanf (const wchar_t * __restrict__, __VALIST);
470 int __cdecl vfwscanf (FILE * __restrict__,
471 const wchar_t * __restrict__, __VALIST);
472 int __cdecl vswscanf (const wchar_t * __restrict__,
473 const wchar_t * __restrict__, __VALIST);
474 #endif
475
476 #define _WSTDIO_DEFINED
477 #endif /* _WSTDIO_DEFINED */
478
479 #ifndef __STRICT_ANSI__
480 #ifdef __MSVCRT__
481 #ifndef NO_OLDNAMES
482 _CRTIMP FILE* __cdecl wpopen (const wchar_t*, const wchar_t*);
483 #endif /* not NO_OLDNAMES */
484 #endif /* MSVCRT runtime */
485
486 /*
487 * Other Non ANSI wide functions
488 */
489 _CRTIMP wint_t __cdecl _fgetwchar (void);
490 _CRTIMP wint_t __cdecl _fputwchar (wint_t);
491 _CRTIMP int __cdecl _getw (FILE*);
492 _CRTIMP int __cdecl _putw (int, FILE*);
493
494 #ifndef _NO_OLDNAMES
495 _CRTIMP wint_t __cdecl fgetwchar (void);
496 _CRTIMP wint_t __cdecl fputwchar (wint_t);
497 _CRTIMP int __cdecl getw (FILE*);
498 _CRTIMP int __cdecl putw (int, FILE*);
499 #endif /* Not _NO_OLDNAMES */
500
501 #endif /* __STRICT_ANSI */
502
503 #ifdef __cplusplus
504 }
505 #endif
506
507 #endif /* Not RC_INVOKED */
508
509 #endif /* _STDIO_H_ */