4 * Definitions of types and prototypes of functions for operations on
5 * standard input and standard output streams.
9 * Written by Rob Savoye <rob@cygnus.com>
10 * Copyright (C) 1997-2005, 2007-2010, 2014-2016, MinGW.org Project.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice, this permission notice, and the following
21 * disclaimer shall be included in all copies or substantial portions of
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
30 * DEALINGS IN THE SOFTWARE.
32 * NOTE: The file manipulation functions provided by Microsoft seem to
33 * work with either slash (/) or backslash (\) as the directory separator;
34 * (this is consistent with Microsoft's own documentation, on MSDN).
38 #pragma GCC system_header
40 /* When including <wchar.h>, some of the definitions and declarations
41 * which are nominally provided in <stdio.h> must be duplicated. Rather
42 * than require duplicated maintenance effort, we provide for partial
43 * inclusion of <stdio.h> by <wchar.h>; only when not included in
44 * this partial fashion...
46 #ifndef __WCHAR_H_SOURCED__
48 * ...which is exclusive to <wchar.h>, do we assert the multiple
49 * inclusion guard for <stdio.h> itself.
54 /* All the headers include this file.
59 /* POSIX stipulates that the following set of types, (as identified by
60 * __need_TYPENAME macros), shall be defined consistently with <stddef.h>;
61 * by defining the appropriate __need_TYPENAME macros, we may selectively
62 * obtain the required definitions by inclusion of <stddef.h>, WITHOUT
63 * automatic exposure of any of its additional content.
67 #define __need_wchar_t
71 #if _POSIX_C_SOURCE >= 200809L
72 /* Similarly, for types defined in <sys/types.h>, (which are explicitly
73 * dependent on the POSIX.1-2008 feature test)...
76 # define __need_ssize_t
78 #if !(defined __STRICT_ANSI__ || defined (__NO_MINGW_LFS)) \
79 && defined (__MSVCRT__)
80 /* ...while this is required to support our fseeko64() and ftello64()
81 * implementations, (neither of which is in any way standardized)...
83 # define __need___off64_t
85 /* It is sufficient to test for just one define from each of the two
88 #if defined __need_off_t || defined __need___off64_t
89 /* ...to identify a requirement for selective inclusion from...
91 # include <sys/types.h>
95 /* Also similarly, for the va_list type, defined in <stdarg.h>
97 # if defined __GNUC__ && __GNUC__ >= 3
98 # define __need___va_list
100 # define __VALIST __builtin_va_list
102 # define __VALIST char *
105 #endif /* ! RC_INVOKED */
108 /* Flags for the iobuf structure
110 #define _IOREAD 1 /* currently reading */
111 #define _IOWRT 2 /* currently writing */
112 #define _IORW 0x0080 /* opened as "r+w" */
114 /* The three standard file pointers provided by the run time library.
115 * NOTE: These will go to the bit-bucket silently in GUI applications!
117 #define STDIN_FILENO 0
118 #define STDOUT_FILENO 1
119 #define STDERR_FILENO 2
121 /* Returned by various functions on end of file condition or error.
125 #endif /* _STDIO_H */
127 /* The maximum length of a file name. It may be better to use the Windows'
128 * GetVolumeInformation() function in preference to this constant, but hey,
129 * this works! Note that <io.h> also defines it, but we don't guard it, so
130 * that the compiler has a chance to catch inconsistencies.
132 * FIXME: Right now, we define this unconditionally for both full <stdio.h>
133 * inclusion, and for partial inclusion on behalf of <wchar.h>, (which needs
134 * it for some non-ANSI structure declarations). The conditions under which
135 * <wchar.h> needs this require review, because defining it as a consequence
136 * of including <wchar.h> alone may violate strict ANSI conformity.
138 #define FILENAME_MAX (260)
141 /* The maximum number of files that may be open at once. I have set this to
142 * a conservative number. The actual value may be higher.
144 #define FOPEN_MAX (20)
146 /* After creating this many names, tmpnam and tmpfile return NULL
148 #define TMP_MAX 32767
150 /* Tmpnam, tmpfile and, sometimes, _tempnam try to create
151 * temp files in the root directory of the current drive
152 * (not in pwd, as suggested by some older MS doc's).
153 * Redefining these macros does not effect the CRT functions.
155 #define _P_tmpdir "\\"
156 #ifndef __STRICT_ANSI__
157 #define P_tmpdir _P_tmpdir
159 #define _wP_tmpdir L"\\"
161 /* The maximum size of name (including NUL) that will be put in the user
162 * supplied buffer caName for tmpnam.
163 * Inferred from the size of the static buffer returned by tmpnam
164 * when passed a NULL argument. May actually be smaller.
166 #define L_tmpnam (16)
168 #define _IOFBF 0x0000 /* full buffered */
169 #define _IOLBF 0x0040 /* line buffered */
170 #define _IONBF 0x0004 /* not buffered */
172 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
173 #define _IOEOF 0x0010 /* EOF reached on read */
174 #define _IOERR 0x0020 /* I/O error from system */
175 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
177 # define _IOAPPEND 0x0200
180 /* The buffer size as used by setbuf such that it is equivalent to
181 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
185 /* Constants for nOrigin indicating the position relative to which fseek
186 * sets the file position. Defined unconditionally since ISO and POSIX
187 * say they are defined here.
193 #endif /* _STDIO_H */
196 #if ! (defined _STDIO_H && defined _WCHAR_H)
197 /* The structure underlying the FILE type; this should be defined when
198 * including either <stdio.h> or <wchar.h>. If both header include guards
199 * are now in place, then we must currently be including <stdio.h> in its
200 * own right, having already processed this block during a prior partial
201 * inclusion by <wchar.h>; there is no need to process it a second time.
203 * Some believe that nobody in their right mind should make use of the
204 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
207 typedef struct _iobuf
219 #endif /* ! (_STDIO_H && _WCHAR_H) */
221 /* Content to be exposed only when including <stdio.h> in its own right;
222 * these will not be exposed when __WCHAR_H_SOURCE__ is defined, as will
223 * be the case when <stdio.h> is included indirectly, by <wchar.h>
226 * The standard file handles
228 #ifndef __DECLSPEC_SUPPORTED
230 extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */
232 #define _iob (*_imp___iob) /* An array of FILE */
234 #else /* __DECLSPEC_SUPPORTED */
236 __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */
238 #endif /* __DECLSPEC_SUPPORTED */
240 #define stdin (&_iob[STDIN_FILENO])
241 #define stdout (&_iob[STDOUT_FILENO])
242 #define stderr (&_iob[STDERR_FILENO])
248 _CRTIMP __cdecl __MINGW_NOTHROW FILE * fopen (const char *, const char *);
249 _CRTIMP __cdecl __MINGW_NOTHROW FILE * freopen (const char *, const char *, FILE *);
250 _CRTIMP __cdecl __MINGW_NOTHROW int fflush (FILE *);
251 _CRTIMP __cdecl __MINGW_NOTHROW int fclose (FILE *);
253 /* Note: Microsoft also declares remove & rename (but not their wide char
254 * variants) in <io.h>; since duplicate prototypes are acceptable, provided
255 * they are consistent, we simply declare them here anyway, while allowing
256 * the compiler to check consistency as appropriate.
258 _CRTIMP __cdecl __MINGW_NOTHROW int remove (const char *);
259 _CRTIMP __cdecl __MINGW_NOTHROW int rename (const char *, const char *);
260 _CRTIMP __cdecl __MINGW_NOTHROW FILE * tmpfile (void);
261 _CRTIMP __cdecl __MINGW_NOTHROW char * tmpnam (char *);
263 #ifndef __STRICT_ANSI__
264 _CRTIMP __cdecl __MINGW_NOTHROW char *_tempnam (const char *, const char *);
265 _CRTIMP __cdecl __MINGW_NOTHROW int _rmtmp (void);
266 _CRTIMP __cdecl __MINGW_NOTHROW int _unlink (const char *);
269 _CRTIMP __cdecl __MINGW_NOTHROW char * tempnam (const char *, const char *);
270 _CRTIMP __cdecl __MINGW_NOTHROW int rmtmp (void);
271 _CRTIMP __cdecl __MINGW_NOTHROW int unlink (const char *);
273 #endif /* __STRICT_ANSI__ */
275 _CRTIMP __cdecl __MINGW_NOTHROW int setvbuf (FILE *, char *, int, size_t);
276 _CRTIMP __cdecl __MINGW_NOTHROW void setbuf (FILE *, char *);
280 * MSVCRT implementations are not ANSI C99 conformant...
281 * we offer these conforming alternatives from libmingwex.a
283 #undef __mingw_stdio_redirect__
284 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F
286 extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
287 extern int __mingw_stdio_redirect__(printf)(const char*, ...);
288 extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
289 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
290 extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
291 extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
292 extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
293 extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST);
295 /* When using these C99 conforming alternatives, we may wish to support
296 * some of Microsoft's quirky formatting options, even when they violate
297 * strict C99 conformance.
299 #define _MSVC_PRINTF_QUIRKS 0x0100U
300 #define _QUERY_MSVC_PRINTF_QUIRKS ~0U, 0U
301 #define _DISABLE_MSVC_PRINTF_QUIRKS ~_MSVC_PRINTF_QUIRKS, 0U
302 #define _ENABLE_MSVC_PRINTF_QUIRKS ~0U, _MSVC_PRINTF_QUIRKS
304 /* Those quirks which conflict with ANSI C99 specified behaviour are
305 * disabled by default; use the following function, like this:
307 * _mingw_output_format_control( _ENABLE_MSVC_PRINTF_QUIRKS );
309 * to enable them, like this:
311 * state = _mingw_output_format_control( _QUERY_MSVC_PRINTF_QUIRKS )
312 * & _MSVC_PRINTF_QUIRKS;
314 * to ascertain the currently active enabled state, or like this:
316 * _mingw_output_format_control( _DISABLE_MSVC_PRINTF_QUIRKS );
318 * to disable them again.
320 extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
322 #if __USE_MINGW_ANSI_STDIO
323 /* User has expressed a preference for C99 conformance...
325 # undef __mingw_stdio_redirect__
327 /* For C++ we use inline implementations, to avoid interference
328 * with namespace qualification, which may result from using #defines.
330 # define __mingw_stdio_redirect__ inline __cdecl __MINGW_NOTHROW
332 # elif defined __GNUC__
333 /* FIXME: Is there any GCC version prerequisite here?
335 * We also prefer inline implementations for C, when we can be confident
336 * that the GNU specific __inline__ mechanism is supported.
338 # define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW
341 /* Can't use inlines; fall back on module local static stubs.
343 # define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW
346 __mingw_stdio_redirect__
347 int fprintf (FILE *__stream, const char *__format, ...)
349 register int __retval;
350 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
351 __retval = __mingw_vfprintf( __stream, __format, __local_argv );
352 __builtin_va_end( __local_argv );
356 __mingw_stdio_redirect__
357 int printf (const char *__format, ...)
359 register int __retval;
360 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
361 __retval = __mingw_vprintf( __format, __local_argv );
362 __builtin_va_end( __local_argv );
366 __mingw_stdio_redirect__
367 int sprintf (char *__stream, const char *__format, ...)
369 register int __retval;
370 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
371 __retval = __mingw_vsprintf( __stream, __format, __local_argv );
372 __builtin_va_end( __local_argv );
376 __mingw_stdio_redirect__
377 int vfprintf (FILE *__stream, const char *__format, __VALIST __local_argv)
379 return __mingw_vfprintf( __stream, __format, __local_argv );
382 __mingw_stdio_redirect__
383 int vprintf (const char *__format, __VALIST __local_argv)
385 return __mingw_vprintf( __format, __local_argv );
388 __mingw_stdio_redirect__
389 int vsprintf (char *__stream, const char *__format, __VALIST __local_argv)
391 return __mingw_vsprintf( __stream, __format, __local_argv );
395 /* Default configuration: simply direct all calls to MSVCRT...
397 _CRTIMP __cdecl __MINGW_NOTHROW int fprintf (FILE *, const char *, ...);
398 _CRTIMP __cdecl __MINGW_NOTHROW int printf (const char *, ...);
399 _CRTIMP __cdecl __MINGW_NOTHROW int sprintf (char *, const char *, ...);
400 _CRTIMP __cdecl __MINGW_NOTHROW int vfprintf (FILE *, const char *, __VALIST);
401 _CRTIMP __cdecl __MINGW_NOTHROW int vprintf (const char *, __VALIST);
402 _CRTIMP __cdecl __MINGW_NOTHROW int vsprintf (char *, const char *, __VALIST);
405 /* Regardless of user preference, always offer these alternative
406 * entry points, for direct access to the MSVCRT implementations.
408 #undef __mingw_stdio_redirect__
409 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
411 _CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE *, const char *, ...);
412 _CRTIMP int __mingw_stdio_redirect__(printf)(const char *, ...);
413 _CRTIMP int __mingw_stdio_redirect__(sprintf)(char *, const char *, ...);
414 _CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE *, const char *, __VALIST);
415 _CRTIMP int __mingw_stdio_redirect__(vprintf)(const char *, __VALIST);
416 _CRTIMP int __mingw_stdio_redirect__(vsprintf)(char *, const char *, __VALIST);
418 #undef __mingw_stdio_redirect__
420 /* The following three ALWAYS refer to the MSVCRT implementations...
422 _CRTIMP __cdecl __MINGW_NOTHROW int _snprintf (char *, size_t, const char *, ...);
423 _CRTIMP __cdecl __MINGW_NOTHROW int _vsnprintf (char *, size_t, const char *, __VALIST);
424 _CRTIMP __cdecl __MINGW_NOTHROW int _vscprintf (const char *, __VALIST);
426 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
428 * Microsoft does not provide implementations for the following,
429 * which are required by C99. Note in particular that the corresponding
430 * Microsoft implementations of _snprintf() and _vsnprintf() are *not*
431 * compatible with C99, but the following are; if you want the MSVCRT
432 * behaviour, you *must* use the Microsoft uglified names.
434 __cdecl __MINGW_NOTHROW int snprintf (char *, size_t, const char *, ...);
435 __cdecl __MINGW_NOTHROW int vsnprintf (char *, size_t, const char *, __VALIST);
437 __cdecl __MINGW_NOTHROW int vscanf (const char * __restrict__, __VALIST);
439 __cdecl __MINGW_NOTHROW
440 int vfscanf (FILE * __restrict__, const char * __restrict__, __VALIST);
442 __cdecl __MINGW_NOTHROW
443 int vsscanf (const char * __restrict__, const char * __restrict__, __VALIST);
445 #endif /* !__NO_ISOCEXT */
446 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
448 * In MSVCR80.DLL, (and its descendants), Microsoft introduced variants
449 * of the printf() functions, with names qualified by an underscore prefix
450 * and "_p" or "_p_l" suffixes; implemented in Microsoft's typically crass,
451 * non-standard, and non-portable fashion, these provide support for access
452 * to printf() arguments in random order, as was standardised by POSIX as a
453 * feature of the optional Extended Systems Interface (XSI) specification,
454 * and is now required for conformity with the POSIX.1-2008 base standard.
455 * Although these additional Microsoft functions were subsequently added
456 * to MSVCRT.DLL, from Windows-Vista onward, and they are prototyped here,
457 * MinGW applications are strenuously encouraged to avoid using them; a
458 * much better alternative is to "#define _XOPEN_SOURCE 700" before any
459 * system header is included, then use POSIX standard printf() functions
460 * instead; this is both portable to many non-Windows platforms, and it
461 * offers better compatibility with earlier Windows versions.
463 _CRTIMP __cdecl __MINGW_NOTHROW
464 int _printf_p (const char *, ...);
466 _CRTIMP __cdecl __MINGW_NOTHROW
467 int _fprintf_p (FILE *, const char *, ...);
469 _CRTIMP __cdecl __MINGW_NOTHROW
470 int _sprintf_p (char *, size_t, const char *, ...);
472 _CRTIMP __cdecl __MINGW_NOTHROW
473 int _vprintf_p (const char *, __VALIST);
475 _CRTIMP __cdecl __MINGW_NOTHROW
476 int _vfprintf_p (FILE *, const char *, __VALIST);
478 _CRTIMP __cdecl __MINGW_NOTHROW
479 int _vsprintf_p (char *, size_t, const char *, __VALIST);
481 _CRTIMP __cdecl __MINGW_NOTHROW
482 int _printf_p_l (const char *, locale_t, ...);
484 _CRTIMP __cdecl __MINGW_NOTHROW
485 int _fprintf_p_l (FILE *, const char *, locale_t, ...);
487 _CRTIMP __cdecl __MINGW_NOTHROW
488 int _sprintf_p_l (char *, size_t, const char *, locale_t, ...);
490 _CRTIMP __cdecl __MINGW_NOTHROW
491 int _vprintf_p_l (const char *, locale_t, __VALIST);
493 _CRTIMP __cdecl __MINGW_NOTHROW
494 int _vfprintf_p_l (FILE *, const char *, locale_t, __VALIST);
496 _CRTIMP __cdecl __MINGW_NOTHROW
497 int _vsprintf_p_l (char *, size_t, const char *, locale_t, __VALIST);
499 #endif /* MSVCR80.DLL and descendants, or MSVCRT.DLL since Vista */
500 #endif /* <stdio.h> included in its own right */
501 #if ! (defined _STDIO_H && defined _WCHAR_H) \
502 && __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
504 * Wide character variants of the foregoing "positional parameter" printf()
505 * functions; MSDN says that these should be declared when either <stdio.h>, or
506 * <wchar.h> is included, so we make them selectively available to <wchar.h>,
507 * but, just as in the foregoing, we advise against their use.
509 _CRTIMP __cdecl __MINGW_NOTHROW
510 int _wprintf_p (const wchar_t *, ...);
512 _CRTIMP __cdecl __MINGW_NOTHROW
513 int _fwprintf_p (FILE *, const wchar_t *, ...);
515 _CRTIMP __cdecl __MINGW_NOTHROW
516 int _swprintf_p (wchar_t *, size_t, const wchar_t *, ...);
518 _CRTIMP __cdecl __MINGW_NOTHROW
519 int _vwprintf_p (const wchar_t *, __VALIST);
521 _CRTIMP __cdecl __MINGW_NOTHROW
522 int _vfwprintf_p (FILE *, const wchar_t *, __VALIST);
524 _CRTIMP __cdecl __MINGW_NOTHROW
525 int _vswprintf_p (wchar_t *, size_t, const wchar_t *, __VALIST);
527 _CRTIMP __cdecl __MINGW_NOTHROW
528 int _wprintf_p_l (const wchar_t *, locale_t, ...);
530 _CRTIMP __cdecl __MINGW_NOTHROW
531 int _fwprintf_p_l (FILE *, const wchar_t *, locale_t, ...);
533 _CRTIMP __cdecl __MINGW_NOTHROW
534 int _swprintf_p_l (wchar_t *, size_t, const wchar_t *, locale_t, ...);
536 _CRTIMP __cdecl __MINGW_NOTHROW
537 int _vwprintf_p_l (const wchar_t *, locale_t, __VALIST);
539 _CRTIMP __cdecl __MINGW_NOTHROW
540 int _vfwprintf_p_l (FILE *, const wchar_t *, locale_t, __VALIST);
542 _CRTIMP __cdecl __MINGW_NOTHROW
543 int _vswprintf_p_l (wchar_t *, size_t, const wchar_t *, locale_t, __VALIST);
545 #endif /* ! (defined _STDIO_H && defined _WCHAR_H) */
547 /* Once again, back to <stdio.h> specific declarations.
552 _CRTIMP __cdecl __MINGW_NOTHROW int fscanf (FILE *, const char *, ...);
553 _CRTIMP __cdecl __MINGW_NOTHROW int scanf (const char *, ...);
554 _CRTIMP __cdecl __MINGW_NOTHROW int sscanf (const char *, const char *, ...);
556 /* Character Input and Output Functions
558 _CRTIMP __cdecl __MINGW_NOTHROW int fgetc (FILE *);
559 _CRTIMP __cdecl __MINGW_NOTHROW char * fgets (char *, int, FILE *);
560 _CRTIMP __cdecl __MINGW_NOTHROW int fputc (int, FILE *);
561 _CRTIMP __cdecl __MINGW_NOTHROW int fputs (const char *, FILE *);
562 _CRTIMP __cdecl __MINGW_NOTHROW char * gets (char *);
563 _CRTIMP __cdecl __MINGW_NOTHROW int puts (const char *);
564 _CRTIMP __cdecl __MINGW_NOTHROW int ungetc (int, FILE *);
566 /* Traditionally, getc and putc are defined as macros. but the
567 * standard doesn't say that they must be macros. We use inline
568 * functions here to allow the fast versions to be used in C++
569 * with namespace qualification, eg., ::getc.
571 * NOTE: _filbuf and _flsbuf are not thread-safe.
573 _CRTIMP __cdecl __MINGW_NOTHROW int _filbuf (FILE *);
574 _CRTIMP __cdecl __MINGW_NOTHROW int _flsbuf (int, FILE *);
578 __CRT_INLINE __cdecl __MINGW_NOTHROW int getc (FILE * __F)
580 return (--__F->_cnt >= 0)
581 ? (int) (unsigned char) *__F->_ptr++
585 __CRT_INLINE __cdecl __MINGW_NOTHROW int putc (int __c, FILE * __F)
587 return (--__F->_cnt >= 0)
588 ? (int) (unsigned char) (*__F->_ptr++ = (char)__c)
589 : _flsbuf (__c, __F);
592 __CRT_INLINE __cdecl __MINGW_NOTHROW int getchar (void)
594 return (--stdin->_cnt >= 0)
595 ? (int) (unsigned char) *stdin->_ptr++
599 __CRT_INLINE __cdecl __MINGW_NOTHROW int putchar(int __c)
601 return (--stdout->_cnt >= 0)
602 ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
603 : _flsbuf (__c, stdout);}
605 #else /* Use library functions. */
607 _CRTIMP __cdecl __MINGW_NOTHROW int getc (FILE *);
608 _CRTIMP __cdecl __MINGW_NOTHROW int putc (int, FILE *);
609 _CRTIMP __cdecl __MINGW_NOTHROW int getchar (void);
610 _CRTIMP __cdecl __MINGW_NOTHROW int putchar (int);
614 /* Direct Input and Output Functions
616 _CRTIMP __cdecl __MINGW_NOTHROW size_t fread (void *, size_t, size_t, FILE *);
617 _CRTIMP __cdecl __MINGW_NOTHROW size_t fwrite (const void *, size_t, size_t, FILE *);
619 /* File Positioning Functions
621 _CRTIMP __cdecl __MINGW_NOTHROW int fseek (FILE *, long, int);
622 _CRTIMP __cdecl __MINGW_NOTHROW long ftell (FILE *);
623 _CRTIMP __cdecl __MINGW_NOTHROW void rewind (FILE *);
625 #if _WIN32_WINNT >= _WIN32_WINNT_VISTA || __MSVCRT_VERSION__ >= __MSVCR80_DLL
627 * Microsoft introduced a number of variations on fseek() and ftell(),
628 * beginning with MSVCR80.DLL; the bare _fseeki64() and _ftelli64() were
629 * subsequently integrated into MSVCRT.DLL, from Vista onward...
631 _CRTIMP __cdecl __MINGW_NOTHROW int _fseeki64 (FILE *, __int64, int);
632 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64 (FILE *);
634 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL
636 * ...while the "nolock" variants remain exclusive to MSVCR80.DLL, and
637 * its later MSVC specific derivatives.
639 _CRTIMP __cdecl __MINGW_NOTHROW int _fseek_nolock (FILE *, long, int);
640 _CRTIMP __cdecl __MINGW_NOTHROW long _ftell_nolock (FILE *);
642 _CRTIMP __cdecl __MINGW_NOTHROW int _fseeki64_nolock (FILE *, __int64, int);
643 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64_nolock (FILE *);
645 #endif /* MSVCR80.DLL and later derivatives ONLY */
646 #endif /* MSVCR80.DLL and descendants, or MSVCRT.DLL since Vista */
648 #ifdef __USE_MINGW_FSEEK
649 /* Workaround for a limitation on Win9x where a file is not zero padded
650 * on write, following a seek beyond the original end of file; these are
651 * implemented in libmingwex.a
653 __cdecl __MINGW_NOTHROW int __mingw_fseek (FILE *, long, int);
654 __cdecl __MINGW_NOTHROW size_t __mingw_fwrite (const void *, size_t, size_t, FILE *);
656 #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp)
657 #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence)
658 #endif /* __USE_MINGW_FSEEK */
660 /* An opaque data type used for storing file positions... The contents of
661 * this type are unknown, but we (the compiler) need to know the size
662 * because the programmer using fgetpos and fsetpos will be setting aside
663 * storage for fpos_t structres. Actually I tested using a byte array and
664 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
665 * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
666 * MSVCRT however, and for now `long long' will do.
669 typedef long long fpos_t;
674 _CRTIMP __cdecl __MINGW_NOTHROW int fgetpos (FILE *, fpos_t *);
675 _CRTIMP __cdecl __MINGW_NOTHROW int fsetpos (FILE *, const fpos_t *);
679 _CRTIMP __cdecl __MINGW_NOTHROW int feof (FILE *);
680 _CRTIMP __cdecl __MINGW_NOTHROW int ferror (FILE *);
683 inline __cdecl __MINGW_NOTHROW int feof (FILE * __F){ return __F->_flag & _IOEOF; }
684 inline __cdecl __MINGW_NOTHROW int ferror (FILE * __F){ return __F->_flag & _IOERR; }
686 #define feof(__F) ((__F)->_flag & _IOEOF)
687 #define ferror(__F) ((__F)->_flag & _IOERR)
690 _CRTIMP __cdecl __MINGW_NOTHROW void clearerr (FILE *);
691 _CRTIMP __cdecl __MINGW_NOTHROW void perror (const char *);
694 #ifndef __STRICT_ANSI__
698 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _popen (const char *, const char *);
699 _CRTIMP __cdecl __MINGW_NOTHROW int _pclose (FILE *);
702 _CRTIMP __cdecl __MINGW_NOTHROW FILE * popen (const char *, const char *);
703 _CRTIMP __cdecl __MINGW_NOTHROW int pclose (FILE *);
706 /* Other Non ANSI functions
708 _CRTIMP __cdecl __MINGW_NOTHROW int _flushall (void);
709 _CRTIMP __cdecl __MINGW_NOTHROW int _fgetchar (void);
710 _CRTIMP __cdecl __MINGW_NOTHROW int _fputchar (int);
711 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _fdopen (int, const char *);
712 _CRTIMP __cdecl __MINGW_NOTHROW int _fileno (FILE *);
713 _CRTIMP __cdecl __MINGW_NOTHROW int _fcloseall (void);
714 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _fsopen (const char *, const char *, int);
716 _CRTIMP __cdecl __MINGW_NOTHROW int _getmaxstdio (void);
717 _CRTIMP __cdecl __MINGW_NOTHROW int _setmaxstdio (int);
720 /* Microsoft introduced a capability in MSVCR80.DLL and later, to
721 * set the minimum number of digits to be displayed in a printf()
722 * floating point exponent; they retro-fitted this in MSVCRT.DLL,
723 * from Windows-Vista onwards, but we provide our own wrappers in
724 * libmingwex.a, which make it possible for us to emulate the API
725 * for any version of MSVCRT.DLL (including WinXP and earlier).
727 #define _TWO_DIGIT_EXPONENT 1
729 /* While Microsoft define the preceding manifest constant, they
730 * appear to neglect to define its complement, (for restoration
731 * of their default exponent display format); for orthogonality,
732 * we will provide this regardless of Microsoft's negligence.
734 #define _THREE_DIGIT_EXPONENT 0
736 /* Once again, unspecified by Microsoft, (and mostly redundant),
737 * it is convenient to specify a combining mask for these.
739 #define _EXPONENT_DIGIT_MASK (_TWO_DIGIT_EXPONENT | _THREE_DIGIT_EXPONENT)
741 unsigned int __cdecl __mingw_get_output_format (void);
742 unsigned int __cdecl __mingw_set_output_format (unsigned int);
744 /* Also appearing for the first time in MSVCR80.DLL, and then also
745 * retro-fitted to MSVCRT.DLL from Windows-Vista onwards, was this
746 * pair of functions to control availability of "%n" formatting in
747 * the MSVCRT.DLL printf() family of functions, for which we also
748 * provide our own DLL version agnostic wrappers:
750 int __cdecl __mingw_get_printf_count_output (void);
751 int __cdecl __mingw_set_printf_count_output (int);
753 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL
754 /* When the user declares that MSVCR80.DLL features are supported,
755 * we simply expose the corresponding APIs...
757 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void);
758 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int);
760 _CRTIMP __cdecl __MINGW_NOTHROW int _get_printf_count_output (void);
761 _CRTIMP __cdecl __MINGW_NOTHROW int _set_printf_count_output (int);
764 /* ...otherwise, we emulate the APIs, in a DLL version agnostic
765 * manner, using our own implementation wrappers.
767 __CRT_ALIAS unsigned int __cdecl _get_output_format (void)
768 { return __mingw_get_output_format (); }
770 __CRT_ALIAS unsigned int __cdecl _set_output_format (unsigned int __style)
771 { return __mingw_set_output_format (__style); }
773 /* When using our own printf() implementation, "%n" format is ALWAYS
774 * supported, so we make this API a no-op, reporting it to be so; for
775 * the alternative case, when using MSVCRT.DLL's printf(), we delegate
776 * to our wrapper API implementation, which will invoke the API function
777 * calls within the DLL, if they are available, or persistently report
778 * the state of "%n" formatting as DISABLED if they are not.
780 #if __USE_MINGW_ANSI_STDIO
781 /* Note that __USE_MINGW_ANSI_STDIO is not guaranteed to resolve to any
782 * symbol which will represent a compilable logic state; map it to this
783 * alternative which will, for the true state...
785 # define __USE_MINGW_PRINTF 1
787 /* ...and for the false.
789 # define __USE_MINGW_PRINTF 0
792 __CRT_ALIAS int __cdecl _get_printf_count_output (void)
793 { return __USE_MINGW_PRINTF ? 1 : __mingw_get_printf_count_output (); }
795 __CRT_ALIAS int __cdecl _set_printf_count_output (int __mode)
796 { return __USE_MINGW_PRINTF ? 1 : __mingw_set_printf_count_output (__mode); }
800 _CRTIMP __cdecl __MINGW_NOTHROW int fgetchar (void);
801 _CRTIMP __cdecl __MINGW_NOTHROW int fputchar (int);
802 _CRTIMP __cdecl __MINGW_NOTHROW FILE * fdopen (int, const char *);
803 _CRTIMP __cdecl __MINGW_NOTHROW int fileno (FILE *);
804 #endif /* !_NO_OLDNAMES */
806 #define _fileno(__F) ((__F)->_file)
808 #define fileno(__F) ((__F)->_file)
811 #if defined (__MSVCRT__) && ! defined (__NO_MINGW_LFS)
812 __CRT_INLINE __JMPSTUB__(( FUNCTION = fopen64, REMAPPED = fopen ))
813 FILE * __cdecl __MINGW_NOTHROW fopen64 (const char * filename, const char * mode)
814 { return fopen (filename, mode); }
816 int __cdecl __MINGW_NOTHROW fseeko64 (FILE *, __off64_t, int);
818 #ifdef __USE_MINGW_FSEEK
819 int __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, __off64_t, int);
820 #define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence)
823 __CRT_INLINE __LIBIMPL__(( FUNCTION = ftello64 ))
824 __off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream)
825 { fpos_t __pos; return (fgetpos(stream, &__pos)) ? -1LL : (__off64_t)(__pos); }
827 #endif /* __MSVCRT__ && !__NO_MINGW_LFS */
828 #endif /* !__STRICT_ANSI__ */
829 #endif /* _STDIO_H */
831 #if ! (defined _STDIO_H && defined _WCHAR_H)
832 /* The following are declared when including either <stdio.h> or <wchar.h>.
833 * If both header include guards are now in place, then we must currently be
834 * including <stdio.h> in its own right, having already processed this block
835 * during prior partial inclusion by <wchar.h>; there is no need to process
838 _CRTIMP __cdecl __MINGW_NOTHROW int fwprintf (FILE *, const wchar_t *, ...);
839 _CRTIMP __cdecl __MINGW_NOTHROW int wprintf (const wchar_t *, ...);
840 _CRTIMP __cdecl __MINGW_NOTHROW int vfwprintf (FILE *, const wchar_t *, __VALIST);
841 _CRTIMP __cdecl __MINGW_NOTHROW int vwprintf (const wchar_t *, __VALIST);
842 _CRTIMP __cdecl __MINGW_NOTHROW int _snwprintf (wchar_t *, size_t, const wchar_t *, ...);
843 _CRTIMP __cdecl __MINGW_NOTHROW int _vscwprintf (const wchar_t *, __VALIST);
844 _CRTIMP __cdecl __MINGW_NOTHROW int _vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
845 _CRTIMP __cdecl __MINGW_NOTHROW int fwscanf (FILE *, const wchar_t *, ...);
846 _CRTIMP __cdecl __MINGW_NOTHROW int wscanf (const wchar_t *, ...);
847 _CRTIMP __cdecl __MINGW_NOTHROW int swscanf (const wchar_t *, const wchar_t *, ...);
848 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fgetwc (FILE *);
849 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fputwc (wchar_t, FILE *);
850 _CRTIMP __cdecl __MINGW_NOTHROW wint_t ungetwc (wchar_t, FILE *);
852 #ifndef __STRICT_ANSI__
853 /* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf).
855 _CRTIMP __cdecl __MINGW_NOTHROW int swprintf (wchar_t *, const wchar_t *, ...);
856 _CRTIMP __cdecl __MINGW_NOTHROW int vswprintf (wchar_t *, const wchar_t *, __VALIST);
860 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * fgetws (wchar_t *, int, FILE *);
861 _CRTIMP __cdecl __MINGW_NOTHROW int fputws (const wchar_t *, FILE *);
862 _CRTIMP __cdecl __MINGW_NOTHROW wint_t getwc (FILE *);
863 _CRTIMP __cdecl __MINGW_NOTHROW wint_t getwchar (void);
864 _CRTIMP __cdecl __MINGW_NOTHROW wint_t putwc (wint_t, FILE *);
865 _CRTIMP __cdecl __MINGW_NOTHROW wint_t putwchar (wint_t);
867 #ifndef __STRICT_ANSI__
868 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _getws (wchar_t *);
869 _CRTIMP __cdecl __MINGW_NOTHROW int _putws (const wchar_t *);
870 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfdopen(int, const wchar_t *);
871 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfopen (const wchar_t *, const wchar_t *);
872 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfreopen (const wchar_t *, const wchar_t *, FILE *);
873 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfsopen (const wchar_t *, const wchar_t *, int);
874 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _wtmpnam (wchar_t *);
875 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _wtempnam (const wchar_t *, const wchar_t *);
876 _CRTIMP __cdecl __MINGW_NOTHROW int _wrename (const wchar_t *, const wchar_t *);
877 _CRTIMP __cdecl __MINGW_NOTHROW int _wremove (const wchar_t *);
878 _CRTIMP __cdecl __MINGW_NOTHROW void _wperror (const wchar_t *);
879 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wpopen (const wchar_t *, const wchar_t *);
881 #endif /* !__STRICT_ANSI__ */
882 #endif /* __MSVCRT__ */
884 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */
885 __cdecl __MINGW_NOTHROW int snwprintf (wchar_t *, size_t, const wchar_t *, ...);
886 __cdecl __MINGW_NOTHROW int vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
888 #ifndef __NO_INLINE__
889 __CRT_INLINE __cdecl __MINGW_NOTHROW
890 __JMPSTUB__(( FUNCTION = vsnwprintf, REMAPPED = _vsnwprintf ))
891 int vsnwprintf (wchar_t *__s, size_t __n, const wchar_t *__fmt, __VALIST __arg)
892 { return _vsnwprintf ( __s, __n, __fmt, __arg); }
895 __cdecl __MINGW_NOTHROW int vwscanf (const wchar_t *__restrict__, __VALIST);
896 __cdecl __MINGW_NOTHROW
897 int vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, __VALIST);
898 __cdecl __MINGW_NOTHROW
899 int vswscanf (const wchar_t *__restrict__, const wchar_t * __restrict__, __VALIST);
901 #endif /* !__NO__ISOCEXT */
902 #endif /* ! (_STDIO_H && _WCHAR_H) */
904 #if defined _STDIO_H && ! defined __STRICT_ANSI__
905 #if defined __MSVCRT__ && ! defined _NO_OLDNAMES
906 _CRTIMP __cdecl __MINGW_NOTHROW FILE * wpopen (const wchar_t *, const wchar_t *);
909 /* Other non-ANSI wide character functions...
911 _CRTIMP __cdecl __MINGW_NOTHROW wint_t _fgetwchar (void);
912 _CRTIMP __cdecl __MINGW_NOTHROW wint_t _fputwchar (wint_t);
913 _CRTIMP __cdecl __MINGW_NOTHROW int _getw (FILE *);
914 _CRTIMP __cdecl __MINGW_NOTHROW int _putw (int, FILE *);
917 /* ...and their original names, before Microsoft uglification...
919 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fgetwchar (void);
920 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fputwchar (wint_t);
921 _CRTIMP __cdecl __MINGW_NOTHROW int getw (FILE *);
922 _CRTIMP __cdecl __MINGW_NOTHROW int putw (int, FILE *);
924 #endif /* !_NO_OLDNAMES */
925 #endif /* !__STRICT_ANSI__ */
929 #endif /* ! RC_INVOKED */
930 #endif /* !_STDIO_H: $RCSfile$: end of file */