OSDN Git Service

094ebad9cee439b705bf728f998265ad3dfcbfe4
[mingw/mingw-org-wsl.git] / mingwrt / 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.  Defined unconditionally since ISO and POSIX
105  * say they are defined here.
106  */
107 #define SEEK_SET  0
108 #define SEEK_CUR  1
109 #define SEEK_END  2
110
111 #ifndef RC_INVOKED
112
113 #ifndef __VALIST
114 #ifdef __GNUC__
115 #define __VALIST __gnuc_va_list
116 #else
117 #define __VALIST char*
118 #endif
119 #endif /* defined __VALIST  */
120
121 /*
122  * The structure underlying the FILE type.
123  *
124  * Some believe that nobody in their right mind should make use of the
125  * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
126  * <paag@tid.es>.
127  */
128 #ifndef _FILE_DEFINED
129 #define _FILE_DEFINED
130 typedef struct _iobuf
131 {
132         char*   _ptr;
133         int     _cnt;
134         char*   _base;
135         int     _flag;
136         int     _file;
137         int     _charbuf;
138         int     _bufsiz;
139         char*   _tmpfname;
140 } FILE;
141 #endif  /* Not _FILE_DEFINED */
142
143
144 /*
145  * The standard file handles
146  */
147 #ifndef __DECLSPEC_SUPPORTED
148
149 extern FILE (*_imp___iob)[];    /* A pointer to an array of FILE */
150
151 #define _iob    (*_imp___iob)   /* An array of FILE */
152
153 #else /* __DECLSPEC_SUPPORTED */
154
155 __MINGW_IMPORT FILE _iob[];     /* An array of FILE imported from DLL. */
156
157 #endif /* __DECLSPEC_SUPPORTED */
158
159 #define stdin   (&_iob[STDIN_FILENO])
160 #define stdout  (&_iob[STDOUT_FILENO])
161 #define stderr  (&_iob[STDERR_FILENO])
162
163 _BEGIN_C_DECLS
164
165 /*
166  * File Operations
167  */
168 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   fopen (const char*, const char*);
169 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   freopen (const char*, const char*, FILE*);
170 _CRTIMP int __cdecl __MINGW_NOTHROW     fflush (FILE*);
171 _CRTIMP int __cdecl __MINGW_NOTHROW     fclose (FILE*);
172 /* MS puts remove & rename (but not wide versions) in io.h  also */
173 _CRTIMP int __cdecl __MINGW_NOTHROW     remove (const char*);
174 _CRTIMP int __cdecl __MINGW_NOTHROW     rename (const char*, const char*);
175 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   tmpfile (void);
176 _CRTIMP char* __cdecl __MINGW_NOTHROW   tmpnam (char*);
177
178 #ifndef __STRICT_ANSI__
179 _CRTIMP char* __cdecl __MINGW_NOTHROW   _tempnam (const char*, const char*);
180 _CRTIMP int __cdecl __MINGW_NOTHROW     _rmtmp(void);
181 _CRTIMP int __cdecl __MINGW_NOTHROW     _unlink (const char*);
182
183 #ifndef NO_OLDNAMES
184 _CRTIMP char* __cdecl __MINGW_NOTHROW   tempnam (const char*, const char*);
185 _CRTIMP int __cdecl __MINGW_NOTHROW     rmtmp(void);
186 _CRTIMP int __cdecl __MINGW_NOTHROW     unlink (const char*);
187 #endif
188 #endif /* __STRICT_ANSI__ */
189
190 _CRTIMP int __cdecl __MINGW_NOTHROW     setvbuf (FILE*, char*, int, size_t);
191 _CRTIMP void __cdecl __MINGW_NOTHROW    setbuf (FILE*, char*);
192
193 /* Formatted Output
194  *
195  * MSVCRT implementations are not ANSI C99 conformant...
196  * we offer these conforming alternatives from libmingwex.a
197  */
198 #undef  __mingw_stdio_redirect__
199 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F
200
201 extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
202 extern int __mingw_stdio_redirect__(printf)(const char*, ...);
203 extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
204 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
205 extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
206 extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
207 extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
208 extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST);
209
210 /* When using these C99 conforming alternatives, we may wish to support
211  * some of Microsoft's quirky formatting options, even when they violate
212  * strict C99 conformance.
213  */
214 #define _MSVC_PRINTF_QUIRKS             0x0100U
215 #define _QUERY_MSVC_PRINTF_QUIRKS       ~0U, 0U
216 #define _DISABLE_MSVC_PRINTF_QUIRKS     ~_MSVC_PRINTF_QUIRKS, 0U
217 #define _ENABLE_MSVC_PRINTF_QUIRKS      ~0U, _MSVC_PRINTF_QUIRKS
218
219 /* Those quirks which conflict with ANSI C99 specified behaviour are
220  * disabled by default; use the following function, like this:
221  *
222  *   _mingw_output_format_control( _ENABLE_MSVC_PRINTF_QUIRKS );
223  *
224  * to enable them, like this:
225  *
226  *   state = _mingw_output_format_control( _QUERY_MSVC_PRINTF_QUIRKS )
227  *              & _MSVC_PRINTF_QUIRKS;
228  *
229  * to ascertain the currently active enabled state, or like this:
230  *
231  *   _mingw_output_format_control( _DISABLE_MSVC_PRINTF_QUIRKS );
232  *
233  * to disable them again.
234  */
235 extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
236
237 #if __USE_MINGW_ANSI_STDIO
238 /*
239  * User has expressed a preference for C99 conformance...
240  */
241 # undef __mingw_stdio_redirect__
242 # ifdef __cplusplus
243 /*
244  * For C++ we use inline implementations, to avoid interference
245  * with namespace qualification, which may result from using #defines.
246  */
247 #  define __mingw_stdio_redirect__  inline __cdecl __MINGW_NOTHROW
248
249 # elif defined __GNUC__
250 /*
251  * FIXME: Is there any GCC version prerequisite here?
252  *
253  * We also prefer inline implementations for C, when we can be confident
254  * that the GNU specific __inline__ mechanism is supported.
255  */
256 #  define __mingw_stdio_redirect__  static __inline__ __cdecl __MINGW_NOTHROW
257
258 # else
259 /*
260  * Can't use inlines; fall back on module local static stubs.
261  */
262 #  define __mingw_stdio_redirect__  static __cdecl __MINGW_NOTHROW
263 # endif
264
265 __mingw_stdio_redirect__
266 int fprintf (FILE *__stream, const char *__format, ...)
267 {
268   register int __retval;
269   __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
270   __retval = __mingw_vfprintf( __stream, __format, __local_argv );
271   __builtin_va_end( __local_argv );
272   return __retval;
273 }
274
275 __mingw_stdio_redirect__
276 int printf (const char *__format, ...)
277 {
278   register int __retval;
279   __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
280   __retval = __mingw_vprintf( __format, __local_argv );
281   __builtin_va_end( __local_argv );
282   return __retval;
283 }
284
285 __mingw_stdio_redirect__
286 int sprintf (char *__stream, const char *__format, ...)
287 {
288   register int __retval;
289   __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
290   __retval = __mingw_vsprintf( __stream, __format, __local_argv );
291   __builtin_va_end( __local_argv );
292   return __retval;
293 }
294
295 __mingw_stdio_redirect__
296 int vfprintf (FILE *__stream, const char *__format, __VALIST __local_argv)
297 {
298   return __mingw_vfprintf( __stream, __format, __local_argv );
299 }
300
301 __mingw_stdio_redirect__
302 int vprintf (const char *__format, __VALIST __local_argv)
303 {
304   return __mingw_vprintf( __format, __local_argv );
305 }
306
307 __mingw_stdio_redirect__
308 int vsprintf (char *__stream, const char *__format, __VALIST __local_argv)
309 {
310   return __mingw_vsprintf( __stream, __format, __local_argv );
311 }
312
313 #else
314 /*
315  * Default configuration: simply direct all calls to MSVCRT...
316  */
317 _CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...);
318 _CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...);
319 _CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...);
320 _CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST);
321 _CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST);
322 _CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST);
323
324 #endif
325 /*
326  * Regardless of user preference, always offer these alternative
327  * entry points, for direct access to the MSVCRT implementations.
328  */
329 #undef  __mingw_stdio_redirect__
330 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
331
332 _CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
333 _CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...);
334 _CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
335 _CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
336 _CRTIMP int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
337 _CRTIMP int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
338
339 #undef  __mingw_stdio_redirect__
340
341 /* The following three ALWAYS refer to the MSVCRT implementations...
342  */
343 _CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
344 _CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
345 _CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, __VALIST);
346
347 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
348 /*
349  * Microsoft does not provide implementations for the following,
350  * which are required by C99.  Note in particular that the corresponding
351  * Microsoft implementations of _snprintf() and _vsnprintf() are *not*
352  * compatible with C99, but the following are; if you want the MSVCRT
353  * behaviour, you *must* use the Microsoft uglified names.
354  */
355 int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...);
356 int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST);
357
358 int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);
359 int __cdecl __MINGW_NOTHROW vfscanf (FILE * __restrict__, const char * __restrict__,
360                      __VALIST);
361 int __cdecl __MINGW_NOTHROW vsscanf (const char * __restrict__,
362                      const char * __restrict__, __VALIST);
363
364 #endif  /* !__NO_ISOCEXT */
365
366 /*
367  * Formatted Input
368  */
369
370 _CRTIMP int __cdecl __MINGW_NOTHROW     fscanf (FILE*, const char*, ...);
371 _CRTIMP int __cdecl __MINGW_NOTHROW     scanf (const char*, ...);
372 _CRTIMP int __cdecl __MINGW_NOTHROW     sscanf (const char*, const char*, ...);
373 /*
374  * Character Input and Output Functions
375  */
376
377 _CRTIMP int __cdecl __MINGW_NOTHROW     fgetc (FILE*);
378 _CRTIMP char* __cdecl __MINGW_NOTHROW   fgets (char*, int, FILE*);
379 _CRTIMP int __cdecl __MINGW_NOTHROW     fputc (int, FILE*);
380 _CRTIMP int __cdecl __MINGW_NOTHROW     fputs (const char*, FILE*);
381 _CRTIMP char* __cdecl __MINGW_NOTHROW   gets (char*);
382 _CRTIMP int __cdecl __MINGW_NOTHROW     puts (const char*);
383 _CRTIMP int __cdecl __MINGW_NOTHROW     ungetc (int, FILE*);
384
385 /* Traditionally, getc and putc are defined as macros. but the
386    standard doesn't say that they must be macros.
387    We use inline functions here to allow the fast versions
388    to be used in C++ with namespace qualification, eg., ::getc.
389
390    _filbuf and _flsbuf  are not thread-safe. */
391 _CRTIMP int __cdecl __MINGW_NOTHROW     _filbuf (FILE*);
392 _CRTIMP int __cdecl __MINGW_NOTHROW     _flsbuf (int, FILE*);
393
394 #if !defined _MT
395
396 __CRT_INLINE int __cdecl __MINGW_NOTHROW getc (FILE* __F)
397 {
398   return (--__F->_cnt >= 0)
399     ?  (int) (unsigned char) *__F->_ptr++
400     : _filbuf (__F);
401 }
402
403 __CRT_INLINE int __cdecl __MINGW_NOTHROW putc (int __c, FILE* __F)
404 {
405   return (--__F->_cnt >= 0)
406     ?  (int) (unsigned char) (*__F->_ptr++ = (char)__c)
407     :  _flsbuf (__c, __F);
408 }
409
410 __CRT_INLINE int __cdecl __MINGW_NOTHROW getchar (void)
411 {
412   return (--stdin->_cnt >= 0)
413     ?  (int) (unsigned char) *stdin->_ptr++
414     : _filbuf (stdin);
415 }
416
417 __CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c)
418 {
419   return (--stdout->_cnt >= 0)
420     ?  (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
421     :  _flsbuf (__c, stdout);}
422
423 #else  /* Use library functions.  */
424
425 _CRTIMP int __cdecl __MINGW_NOTHROW     getc (FILE*);
426 _CRTIMP int __cdecl __MINGW_NOTHROW     putc (int, FILE*);
427 _CRTIMP int __cdecl __MINGW_NOTHROW     getchar (void);
428 _CRTIMP int __cdecl __MINGW_NOTHROW     putchar (int);
429
430 #endif
431
432 /*
433  * Direct Input and Output Functions
434  */
435
436 _CRTIMP size_t __cdecl __MINGW_NOTHROW  fread (void*, size_t, size_t, FILE*);
437 _CRTIMP size_t __cdecl __MINGW_NOTHROW  fwrite (const void*, size_t, size_t, FILE*);
438
439 /*
440  * File Positioning Functions
441  */
442
443 _CRTIMP int __cdecl __MINGW_NOTHROW     fseek (FILE*, long, int);
444 _CRTIMP long __cdecl __MINGW_NOTHROW    ftell (FILE*);
445 _CRTIMP void __cdecl __MINGW_NOTHROW    rewind (FILE*);
446
447 #if __MSVCRT_VERSION__ >= 0x800
448 _CRTIMP int __cdecl __MINGW_NOTHROW     _fseek_nolock (FILE*, long, int);
449 _CRTIMP long __cdecl __MINGW_NOTHROW    _ftell_nolock (FILE*);
450
451 _CRTIMP int __cdecl __MINGW_NOTHROW     _fseeki64 (FILE*, __int64, int);
452 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64 (FILE*);
453 _CRTIMP int __cdecl __MINGW_NOTHROW     _fseeki64_nolock (FILE*, __int64, int);
454 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64_nolock (FILE*);
455 #endif
456
457 #ifdef __USE_MINGW_FSEEK  /* These are in libmingwex.a */
458 /*
459  * Workaround for limitations on win9x where a file contents are
460  * not zero'd out if you seek past the end and then write.
461  */
462
463 int __cdecl __MINGW_NOTHROW __mingw_fseek (FILE *, long, int);
464 size_t __cdecl __MINGW_NOTHROW __mingw_fwrite (const void*, size_t, size_t, FILE*);
465 #define fseek(fp, offset, whence)  __mingw_fseek(fp, offset, whence)
466 #define fwrite(buffer, size, count, fp)  __mingw_fwrite(buffer, size, count, fp)
467 #endif /* __USE_MINGW_FSEEK */
468
469 /*
470  * An opaque data type used for storing file positions... The contents of
471  * this type are unknown, but we (the compiler) need to know the size
472  * because the programmer using fgetpos and fsetpos will be setting aside
473  * storage for fpos_t structres. Actually I tested using a byte array and
474  * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
475  * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
476  * MSVCRT however, and for now `long long' will do.
477  */
478 #ifdef __MSVCRT__
479 typedef long long fpos_t;
480 #else
481 typedef long    fpos_t;
482 #endif
483
484 _CRTIMP int __cdecl __MINGW_NOTHROW     fgetpos (FILE*, fpos_t*);
485 _CRTIMP int __cdecl __MINGW_NOTHROW     fsetpos (FILE*, const fpos_t*);
486
487 /*
488  * Error Functions
489  */
490
491 _CRTIMP int __cdecl __MINGW_NOTHROW     feof (FILE*);
492 _CRTIMP int __cdecl __MINGW_NOTHROW     ferror (FILE*);
493
494 #ifdef __cplusplus
495 inline int __cdecl __MINGW_NOTHROW feof (FILE* __F)
496   { return __F->_flag & _IOEOF; }
497 inline int __cdecl __MINGW_NOTHROW ferror (FILE* __F)
498   { return __F->_flag & _IOERR; }
499 #else
500 #define feof(__F)     ((__F)->_flag & _IOEOF)
501 #define ferror(__F)   ((__F)->_flag & _IOERR)
502 #endif
503
504 _CRTIMP void __cdecl __MINGW_NOTHROW    clearerr (FILE*);
505 _CRTIMP void __cdecl __MINGW_NOTHROW    perror (const char*);
506
507
508 #ifndef __STRICT_ANSI__
509 /*
510  * Pipes
511  */
512 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _popen (const char*, const char*);
513 _CRTIMP int __cdecl __MINGW_NOTHROW     _pclose (FILE*);
514
515 #ifndef NO_OLDNAMES
516 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   popen (const char*, const char*);
517 _CRTIMP int __cdecl __MINGW_NOTHROW     pclose (FILE*);
518 #endif
519
520 /*
521  * Other Non ANSI functions
522  */
523 _CRTIMP int __cdecl __MINGW_NOTHROW     _flushall (void);
524 _CRTIMP int __cdecl __MINGW_NOTHROW     _fgetchar (void);
525 _CRTIMP int __cdecl __MINGW_NOTHROW     _fputchar (int);
526 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _fdopen (int, const char*);
527 _CRTIMP int __cdecl __MINGW_NOTHROW     _fileno (FILE*);
528 _CRTIMP int __cdecl __MINGW_NOTHROW     _fcloseall (void);
529 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _fsopen (const char*, const char*, int);
530 #ifdef __MSVCRT__
531 _CRTIMP int __cdecl __MINGW_NOTHROW     _getmaxstdio (void);
532 _CRTIMP int __cdecl __MINGW_NOTHROW     _setmaxstdio (int);
533 #endif
534
535 /* Microsoft introduced a capability in MSVCR80.DLL and later, to
536  * set the minimum number of digits to be displayed in a printf()
537  * floating point exponent; they retro-fitted this in MSVCRT.DLL,
538  * from Windows-Vista onwards, but we provide our own wrappers in
539  * libmingwex.a, which make it possible for us to emulate the API
540  * for any version of MSVCRT.DLL (including WinXP and earlier).
541  */
542 #define _TWO_DIGIT_EXPONENT    1
543
544 /* While Microsoft define the preceding manifest constant, they
545  * appear to neglect to define its complement, (for restoration
546  * of their default exponent display format); for orthogonality,
547  * we will provide this regardless of Microsoft's negligence.
548  */
549 #define _THREE_DIGIT_EXPONENT  0
550
551 /* Once again, unspecified by Microsoft, (and mostly redundant),
552  * it is convenient to specify a combining mask for these.
553  */
554 #define _EXPONENT_DIGIT_MASK  (_TWO_DIGIT_EXPONENT | _THREE_DIGIT_EXPONENT)
555
556 unsigned int __cdecl __mingw_get_output_format (void);
557 unsigned int __cdecl __mingw_set_output_format (unsigned int);
558
559 /* Also appearing for the first time in MSVCR80.DLL, and then also
560  * retro-fitted to MSVCRT.DLL from Windows-Vista onwards, was this
561  * pair of functions to control availability of "%n" formatting in
562  * the MSVCRT.DLL printf() family of functions, for which we also
563  * provide our own DLL version agnostic wrappers:
564  */
565 int __cdecl __mingw_get_printf_count_output (void);
566 int __cdecl __mingw_set_printf_count_output (int);
567
568 #if __MSVCRT_VERSION__ >= 0x800
569 /*
570  * When the user declares that MSVCR80.DLL features are supported,
571  * we simply expose the corresponding APIs...
572  */
573 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void);
574 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int);
575
576 _CRTIMP int __cdecl __MINGW_NOTHROW _get_printf_count_output (void);
577 _CRTIMP int __cdecl __MINGW_NOTHROW _set_printf_count_output (int);
578
579 #else
580 /* ...otherwise, we emulate the APIs, in a DLL version agnostic
581  * manner, using our own implementation wrappers.
582  */
583 __CRT_ALIAS unsigned int __cdecl _get_output_format (void)
584 { return __mingw_get_output_format (); }
585
586 __CRT_ALIAS unsigned int __cdecl _set_output_format (unsigned int __style)
587 { return __mingw_set_output_format (__style); }
588
589 /* When using our own printf() implementation, "%n" format is ALWAYS
590  * supported, so we make this API a no-op, reporting it to be so; for
591  * the alternative case, when using MSVCRT.DLL's printf(), we delegate
592  * to our wrapper API implementation, which will invoke the API function
593  * calls within the DLL, if they are available, or persistently report
594  * the state of "%n" formatting as DISABLED if they are not.
595  */
596 #if __USE_MINGW_ANSI_STDIO
597 /*
598  * Note that __USE_MINGW_ANSI_STDIO is not guaranteed to resolve to any
599  * symbol which will represent a compilable logic state; map it to this
600  * alternative which will, for the true state...
601  */
602 # define __USE_MINGW_PRINTF  1
603 #else
604 /* ...and for the false.
605  */
606 # define __USE_MINGW_PRINTF  0
607 #endif
608
609 __CRT_ALIAS int __cdecl _get_printf_count_output (void)
610 { return __USE_MINGW_PRINTF ? 1 : __mingw_get_printf_count_output (); }
611
612 __CRT_ALIAS int __cdecl _set_printf_count_output (int __mode)
613 { return __USE_MINGW_PRINTF ? 1 : __mingw_set_printf_count_output (__mode); }
614 #endif
615
616 #ifndef _NO_OLDNAMES
617 _CRTIMP int __cdecl __MINGW_NOTHROW     fgetchar (void);
618 _CRTIMP int __cdecl __MINGW_NOTHROW     fputchar (int);
619 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   fdopen (int, const char*);
620 _CRTIMP int __cdecl __MINGW_NOTHROW     fileno (FILE*);
621 #endif  /* Not _NO_OLDNAMES */
622
623 #define _fileno(__F) ((__F)->_file)
624 #ifndef _NO_OLDNAMES
625 #define fileno(__F) ((__F)->_file)
626 #endif
627
628 #if defined (__MSVCRT__) && !defined (__NO_MINGW_LFS)
629 #include <sys/types.h>
630 __CRT_INLINE __JMPSTUB__(( FUNCTION = fopen64, REMAPPED = fopen ))
631 FILE* __cdecl __MINGW_NOTHROW fopen64 (const char* filename, const char* mode)
632 { return fopen (filename, mode); }
633
634 int __cdecl __MINGW_NOTHROW fseeko64 (FILE*, off64_t, int);
635
636 #ifdef __USE_MINGW_FSEEK
637 int __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, off64_t, int);
638 #define fseeko64(fp, offset, whence)  __mingw_fseeko64(fp, offset, whence)
639 #endif
640
641 __CRT_INLINE __LIBIMPL__(( FUNCTION = ftello64 ))
642 off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream)
643 {
644   fpos_t pos;
645   if (fgetpos(stream, &pos))
646     return  -1LL;
647   else
648    return ((off64_t) pos);
649 }
650 #endif /* __NO_MINGW_LFS */
651
652 #endif  /* Not __STRICT_ANSI__ */
653
654 /* Wide  versions */
655
656 #ifndef _WSTDIO_DEFINED
657 /*  also in wchar.h - keep in sync */
658 _CRTIMP int __cdecl __MINGW_NOTHROW     fwprintf (FILE*, const wchar_t*, ...);
659 _CRTIMP int __cdecl __MINGW_NOTHROW     wprintf (const wchar_t*, ...);
660 _CRTIMP int __cdecl __MINGW_NOTHROW     _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
661 _CRTIMP int __cdecl __MINGW_NOTHROW     vfwprintf (FILE*, const wchar_t*, __VALIST);
662 _CRTIMP int __cdecl __MINGW_NOTHROW     vwprintf (const wchar_t*, __VALIST);
663 _CRTIMP int __cdecl __MINGW_NOTHROW     _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
664 _CRTIMP int __cdecl __MINGW_NOTHROW     _vscwprintf (const wchar_t*, __VALIST);
665 _CRTIMP int __cdecl __MINGW_NOTHROW     fwscanf (FILE*, const wchar_t*, ...);
666 _CRTIMP int __cdecl __MINGW_NOTHROW     wscanf (const wchar_t*, ...);
667 _CRTIMP int __cdecl __MINGW_NOTHROW     swscanf (const wchar_t*, const wchar_t*, ...);
668 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  fgetwc (FILE*);
669 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  fputwc (wchar_t, FILE*);
670 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  ungetwc (wchar_t, FILE*);
671
672 /* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf).  */
673 #ifndef __STRICT_ANSI__
674 _CRTIMP int __cdecl __MINGW_NOTHROW     swprintf (wchar_t*, const wchar_t*, ...);
675 _CRTIMP int __cdecl __MINGW_NOTHROW     vswprintf (wchar_t*, const wchar_t*, __VALIST);
676 #endif
677
678 #ifdef __MSVCRT__
679 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*);
680 _CRTIMP int __cdecl __MINGW_NOTHROW     fputws (const wchar_t*, FILE*);
681 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  getwc (FILE*);
682 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  getwchar (void);
683 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*);
684 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  putwc (wint_t, FILE*);
685 _CRTIMP int __cdecl __MINGW_NOTHROW     _putws (const wchar_t*);
686 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  putwchar (wint_t);
687 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _wfdopen(int, const wchar_t *);
688 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _wfopen (const wchar_t*, const wchar_t*);
689 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _wfreopen (const wchar_t*, const wchar_t*, FILE*);
690 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _wfsopen (const wchar_t*, const wchar_t*, int);
691 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*);
692 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*);
693 _CRTIMP int __cdecl __MINGW_NOTHROW     _wrename (const wchar_t*, const wchar_t*);
694 _CRTIMP int __cdecl __MINGW_NOTHROW     _wremove (const wchar_t*);
695 _CRTIMP void __cdecl __MINGW_NOTHROW    _wperror (const wchar_t*);
696 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   _wpopen (const wchar_t*, const wchar_t*);
697 #endif  /* __MSVCRT__ */
698
699 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
700 int __cdecl __MINGW_NOTHROW snwprintf (wchar_t* s, size_t n, const wchar_t*  format, ...);
701 int __cdecl __MINGW_NOTHROW vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg);
702 #ifndef __NO_INLINE__
703 __CRT_INLINE int __cdecl __MINGW_NOTHROW
704 vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
705   { return _vsnwprintf ( s, n, format, arg);}
706 #endif
707 int __cdecl __MINGW_NOTHROW vwscanf (const wchar_t * __restrict__, __VALIST);
708 int __cdecl __MINGW_NOTHROW vfwscanf (FILE * __restrict__,
709                        const wchar_t * __restrict__, __VALIST);
710 int __cdecl __MINGW_NOTHROW vswscanf (const wchar_t * __restrict__,
711                        const wchar_t * __restrict__, __VALIST);
712 #endif
713
714 #define _WSTDIO_DEFINED
715 #endif /* _WSTDIO_DEFINED */
716
717 #ifndef __STRICT_ANSI__
718 #ifdef __MSVCRT__
719 #ifndef NO_OLDNAMES
720 _CRTIMP FILE* __cdecl __MINGW_NOTHROW   wpopen (const wchar_t*, const wchar_t*);
721 #endif /* not NO_OLDNAMES */
722 #endif /* MSVCRT runtime */
723
724 /*
725  * Other Non ANSI wide functions
726  */
727 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  _fgetwchar (void);
728 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  _fputwchar (wint_t);
729 _CRTIMP int __cdecl __MINGW_NOTHROW     _getw (FILE*);
730 _CRTIMP int __cdecl __MINGW_NOTHROW     _putw (int, FILE*);
731
732 #ifndef _NO_OLDNAMES
733 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  fgetwchar (void);
734 _CRTIMP wint_t __cdecl __MINGW_NOTHROW  fputwchar (wint_t);
735 _CRTIMP int __cdecl __MINGW_NOTHROW     getw (FILE*);
736 _CRTIMP int __cdecl __MINGW_NOTHROW     putw (int, FILE*);
737 #endif  /* Not _NO_OLDNAMES */
738
739 #endif /* __STRICT_ANSI */
740
741 _END_C_DECLS
742
743 #endif  /* Not RC_INVOKED */
744 #endif /* _STDIO_H_ */