4 * Definitions of types and prototypes of functions for operations on
5 * standard input and standard output streams.
9 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10 * Copyright (C) 1997-2005, 2007-2010, 2014-2017, 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 of one or more
90 * of these type definitions from "sys/types.h"; (note that we use the
91 * #include "..." form here, to ensure that we get the correct header
92 * file, relative to the location of this <stdio.h>).
94 # include "sys/types.h"
98 /* Also similarly, for the va_list type, defined in "stdarg.h"
100 # if defined __GNUC__ && __GNUC__ >= 3
101 # define __need___va_list
103 # define __VALIST __builtin_va_list
105 # define __VALIST char *
108 #endif /* ! RC_INVOKED */
111 /* Flags for the iobuf structure
113 #define _IOREAD 1 /* currently reading */
114 #define _IOWRT 2 /* currently writing */
115 #define _IORW 0x0080 /* opened as "r+w" */
117 /* The three standard file pointers provided by the run time library.
118 * NOTE: These will go to the bit-bucket silently in GUI applications!
120 #define STDIN_FILENO 0
121 #define STDOUT_FILENO 1
122 #define STDERR_FILENO 2
124 /* Returned by various functions on end of file condition or error.
128 #endif /* _STDIO_H */
130 /* The maximum length of a file name. It may be better to use the Windows'
131 * GetVolumeInformation() function in preference to this constant, but hey,
132 * this works! Note that <io.h> also defines it, but we don't guard it, so
133 * that the compiler has a chance to catch inconsistencies.
135 * FIXME: Right now, we define this unconditionally for both full <stdio.h>
136 * inclusion, and for partial inclusion on behalf of <wchar.h>, (which needs
137 * it for some non-ANSI structure declarations). The conditions under which
138 * <wchar.h> needs this require review, because defining it as a consequence
139 * of including <wchar.h> alone may violate strict ANSI conformity.
141 #define FILENAME_MAX (260)
144 /* The maximum number of files that may be open at once. I have set this to
145 * a conservative number. The actual value may be higher.
147 #define FOPEN_MAX (20)
149 /* After creating this many names, tmpnam and tmpfile return NULL
151 #define TMP_MAX 32767
153 /* Tmpnam, tmpfile and, sometimes, _tempnam try to create
154 * temp files in the root directory of the current drive
155 * (not in pwd, as suggested by some older MS doc's).
156 * Redefining these macros does not effect the CRT functions.
158 #define _P_tmpdir "\\"
159 #ifndef __STRICT_ANSI__
160 #define P_tmpdir _P_tmpdir
162 #define _wP_tmpdir L"\\"
164 /* The maximum size of name (including NUL) that will be put in the user
165 * supplied buffer caName for tmpnam.
166 * Inferred from the size of the static buffer returned by tmpnam
167 * when passed a NULL argument. May actually be smaller.
169 #define L_tmpnam (16)
171 #define _IOFBF 0x0000 /* full buffered */
172 #define _IOLBF 0x0040 /* line buffered */
173 #define _IONBF 0x0004 /* not buffered */
175 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
176 #define _IOEOF 0x0010 /* EOF reached on read */
177 #define _IOERR 0x0020 /* I/O error from system */
178 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
180 # define _IOAPPEND 0x0200
183 /* The buffer size as used by setbuf such that it is equivalent to
184 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
188 /* Constants for nOrigin indicating the position relative to which fseek
189 * sets the file position. Defined unconditionally since ISO and POSIX
190 * say they are defined here.
196 #endif /* _STDIO_H */
199 #if ! (defined _STDIO_H && defined _WCHAR_H)
200 /* The structure underlying the FILE type; this should be defined when
201 * including either <stdio.h> or <wchar.h>. If both header include guards
202 * are now in place, then we must currently be including <stdio.h> in its
203 * own right, having already processed this block during a prior partial
204 * inclusion by <wchar.h>; there is no need to process it a second time.
206 * Some believe that nobody in their right mind should make use of the
207 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
210 typedef struct _iobuf
222 #endif /* ! (_STDIO_H && _WCHAR_H) */
224 /* Content to be exposed only when including <stdio.h> in its own right;
225 * these will not be exposed when __WCHAR_H_SOURCE__ is defined, as will
226 * be the case when <stdio.h> is included indirectly, by <wchar.h>
229 * The standard file handles
231 #ifndef __DECLSPEC_SUPPORTED
233 extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */
235 #define _iob (*_imp___iob) /* An array of FILE */
237 #else /* __DECLSPEC_SUPPORTED */
239 __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */
241 #endif /* __DECLSPEC_SUPPORTED */
243 #define stdin (&_iob[STDIN_FILENO])
244 #define stdout (&_iob[STDOUT_FILENO])
245 #define stderr (&_iob[STDERR_FILENO])
247 /* Need to close the current _STDIO_H specific block here...
250 /* ...because, we need this regardless of the inclusion mode...
255 /* ...then revert to _STDIO_H specific mode, to declare...
260 _CRTIMP __cdecl __MINGW_NOTHROW FILE * fopen (const char *, const char *);
261 _CRTIMP __cdecl __MINGW_NOTHROW FILE * freopen (const char *, const char *, FILE *);
262 _CRTIMP __cdecl __MINGW_NOTHROW int fflush (FILE *);
263 _CRTIMP __cdecl __MINGW_NOTHROW int fclose (FILE *);
265 /* Note: Microsoft also declares remove & rename (but not their wide char
266 * variants) in <io.h>; since duplicate prototypes are acceptable, provided
267 * they are consistent, we simply declare them here anyway, while allowing
268 * the compiler to check consistency as appropriate.
270 _CRTIMP __cdecl __MINGW_NOTHROW int remove (const char *);
271 _CRTIMP __cdecl __MINGW_NOTHROW int rename (const char *, const char *);
272 _CRTIMP __cdecl __MINGW_NOTHROW FILE * tmpfile (void);
273 _CRTIMP __cdecl __MINGW_NOTHROW char * tmpnam (char *);
275 #ifndef __STRICT_ANSI__
276 _CRTIMP __cdecl __MINGW_NOTHROW char *_tempnam (const char *, const char *);
277 _CRTIMP __cdecl __MINGW_NOTHROW int _rmtmp (void);
278 _CRTIMP __cdecl __MINGW_NOTHROW int _unlink (const char *);
280 #if __MSVCRT_VERSION__>=__MSVCR80_DLL
281 /* The following pair of non-ANSI functions require a non-free version of
282 * the Microsoft runtime; neither is provided by any MSVCRT.DLL variant.
284 _CRTIMP __cdecl __MINGW_NOTHROW void _lock_file(FILE *);
285 _CRTIMP __cdecl __MINGW_NOTHROW void _unlock_file(FILE *);
289 _CRTIMP __cdecl __MINGW_NOTHROW char * tempnam (const char *, const char *);
290 _CRTIMP __cdecl __MINGW_NOTHROW int rmtmp (void);
291 _CRTIMP __cdecl __MINGW_NOTHROW int unlink (const char *);
293 #endif /* __STRICT_ANSI__ */
295 _CRTIMP __cdecl __MINGW_NOTHROW int setvbuf (FILE *, char *, int, size_t);
296 _CRTIMP __cdecl __MINGW_NOTHROW void setbuf (FILE *, char *);
300 * MSVCRT implementations are not ANSI C99 conformant...
301 * we offer these conforming alternatives from libmingwex.a
303 #undef __mingw_stdio_redirect__
304 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F
306 extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
307 extern int __mingw_stdio_redirect__(printf)(const char*, ...);
308 extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
309 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
310 extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
311 extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
312 extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
313 extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST);
315 /* When using these C99 conforming alternatives, we may wish to support
316 * some of Microsoft's quirky formatting options, even when they violate
317 * strict C99 conformance.
319 #define _MSVC_PRINTF_QUIRKS 0x0100U
320 #define _QUERY_MSVC_PRINTF_QUIRKS ~0U, 0U
321 #define _DISABLE_MSVC_PRINTF_QUIRKS ~_MSVC_PRINTF_QUIRKS, 0U
322 #define _ENABLE_MSVC_PRINTF_QUIRKS ~0U, _MSVC_PRINTF_QUIRKS
324 /* Those quirks which conflict with ANSI C99 specified behaviour are
325 * disabled by default; use the following function, like this:
327 * _mingw_output_format_control( _ENABLE_MSVC_PRINTF_QUIRKS );
329 * to enable them, like this:
331 * state = _mingw_output_format_control( _QUERY_MSVC_PRINTF_QUIRKS )
332 * & _MSVC_PRINTF_QUIRKS;
334 * to ascertain the currently active enabled state, or like this:
336 * _mingw_output_format_control( _DISABLE_MSVC_PRINTF_QUIRKS );
338 * to disable them again.
340 extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
342 #if __USE_MINGW_ANSI_STDIO
343 /* User has expressed a preference for C99 conformance...
345 # undef __mingw_stdio_redirect__
347 /* For C++ we use inline implementations, to avoid interference
348 * with namespace qualification, which may result from using #defines.
350 # define __mingw_stdio_redirect__ inline __cdecl __MINGW_NOTHROW
352 # elif defined __GNUC__
353 /* FIXME: Is there any GCC version prerequisite here?
355 * We also prefer inline implementations for C, when we can be confident
356 * that the GNU specific __inline__ mechanism is supported.
358 # define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW
361 /* Can't use inlines; fall back on module local static stubs.
363 # define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW
366 __mingw_stdio_redirect__
367 int fprintf (FILE *__stream, const char *__format, ...)
369 register int __retval;
370 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
371 __retval = __mingw_vfprintf( __stream, __format, __local_argv );
372 __builtin_va_end( __local_argv );
376 __mingw_stdio_redirect__
377 int printf (const char *__format, ...)
379 register int __retval;
380 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
381 __retval = __mingw_vprintf( __format, __local_argv );
382 __builtin_va_end( __local_argv );
386 __mingw_stdio_redirect__
387 int sprintf (char *__stream, const char *__format, ...)
389 register int __retval;
390 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
391 __retval = __mingw_vsprintf( __stream, __format, __local_argv );
392 __builtin_va_end( __local_argv );
396 __mingw_stdio_redirect__
397 int snprintf (char *__stream, size_t __len, const char *__format, ...)
399 register int __retval;
400 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
401 __retval = __mingw_vsnprintf( __stream, __len, __format, __local_argv );
402 __builtin_va_end( __local_argv );
406 __mingw_stdio_redirect__
407 int vfprintf (FILE *__stream, const char *__format, __VALIST __local_argv)
409 return __mingw_vfprintf( __stream, __format, __local_argv );
412 __mingw_stdio_redirect__
413 int vprintf (const char *__format, __VALIST __local_argv)
415 return __mingw_vprintf( __format, __local_argv );
418 __mingw_stdio_redirect__
419 int vsprintf (char *__stream, const char *__format, __VALIST __local_argv)
421 return __mingw_vsprintf( __stream, __format, __local_argv );
424 __mingw_stdio_redirect__
425 int vsnprintf (char *__stream, size_t __len, const char *__format, __VALIST __local_argv)
427 return __mingw_vsnprintf( __stream, __len, __format, __local_argv );
431 /* Default configuration: simply direct all calls to MSVCRT...
433 _CRTIMP __cdecl __MINGW_NOTHROW int fprintf (FILE *, const char *, ...);
434 _CRTIMP __cdecl __MINGW_NOTHROW int printf (const char *, ...);
435 _CRTIMP __cdecl __MINGW_NOTHROW int sprintf (char *, const char *, ...);
436 _CRTIMP __cdecl __MINGW_NOTHROW int vfprintf (FILE *, const char *, __VALIST);
437 _CRTIMP __cdecl __MINGW_NOTHROW int vprintf (const char *, __VALIST);
438 _CRTIMP __cdecl __MINGW_NOTHROW int vsprintf (char *, const char *, __VALIST);
441 /* Regardless of user preference, always offer these alternative
442 * entry points, for direct access to the MSVCRT implementations.
444 #undef __mingw_stdio_redirect__
445 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
447 _CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE *, const char *, ...);
448 _CRTIMP int __mingw_stdio_redirect__(printf)(const char *, ...);
449 _CRTIMP int __mingw_stdio_redirect__(sprintf)(char *, const char *, ...);
450 _CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE *, const char *, __VALIST);
451 _CRTIMP int __mingw_stdio_redirect__(vprintf)(const char *, __VALIST);
452 _CRTIMP int __mingw_stdio_redirect__(vsprintf)(char *, const char *, __VALIST);
454 #undef __mingw_stdio_redirect__
456 /* The following three ALWAYS refer to the MSVCRT implementations...
458 _CRTIMP __cdecl __MINGW_NOTHROW int _snprintf (char *, size_t, const char *, ...);
459 _CRTIMP __cdecl __MINGW_NOTHROW int _vsnprintf (char *, size_t, const char *, __VALIST);
460 _CRTIMP __cdecl __MINGW_NOTHROW int _vscprintf (const char *, __VALIST);
462 #ifdef _ISOC99_SOURCE
463 /* Microsoft does not provide implementations for the following,
464 * which are required by C99. Note in particular that Microsoft's
465 * corresponding implementations of _snprintf() and _vsnprintf() are
466 * NOT compatible with C99, but the following are; if you want the
467 * MSVCRT behaviour, you MUST use the Microsoft "uglified" names.
469 __cdecl __MINGW_NOTHROW int snprintf (char *, size_t, const char *, ...);
470 __cdecl __MINGW_NOTHROW int vsnprintf (char *, size_t, const char *, __VALIST);
472 __cdecl __MINGW_NOTHROW int vscanf (const char * __restrict__, __VALIST);
474 __cdecl __MINGW_NOTHROW
475 int vfscanf (FILE * __restrict__, const char * __restrict__, __VALIST);
477 __cdecl __MINGW_NOTHROW
478 int vsscanf (const char * __restrict__, const char * __restrict__, __VALIST);
480 #endif /* _ISOC99_SOURCE */
481 #endif /* <stdio.h> included in its own right */
483 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
485 * In MSVCR80.DLL, (and its descendants), Microsoft introduced variants
486 * of the printf() functions, with names qualified by an underscore prefix
487 * and "_p" or "_p_l" suffixes; implemented in Microsoft's typically crass,
488 * non-standard, and non-portable fashion, these provide support for access
489 * to printf() arguments in random order, as was standardised by POSIX as a
490 * feature of the optional Extended Systems Interface (XSI) specification,
491 * and is now required for conformity with the POSIX.1-2008 base standard.
492 * Although these additional Microsoft functions were subsequently added
493 * to MSVCRT.DLL, from Windows-Vista onward, and they are prototyped here,
494 * MinGW applications are strenuously encouraged to avoid using them; a
495 * much better alternative is to "#define _XOPEN_SOURCE 700" before any
496 * system header is included, then use POSIX standard printf() functions
497 * instead; this is both portable to many non-Windows platforms, and it
498 * offers better compatibility with earlier Windows versions.
500 #ifndef __have_typedef_locale_t
501 /* Note that some of the following require the opaque locale_t data type,
502 * which we may obtain, by selective inclusion, from <locale.h>
504 #define __need_locale_t
509 /* The following are to be declared only when <stdio.h> is explicitly
510 * included; the first six are NOT dependent on locale_t...
512 _CRTIMP __cdecl __MINGW_NOTHROW
513 int _printf_p (const char *, ...);
515 _CRTIMP __cdecl __MINGW_NOTHROW
516 int _fprintf_p (FILE *, const char *, ...);
518 _CRTIMP __cdecl __MINGW_NOTHROW
519 int _sprintf_p (char *, size_t, const char *, ...);
521 _CRTIMP __cdecl __MINGW_NOTHROW
522 int _vprintf_p (const char *, __VALIST);
524 _CRTIMP __cdecl __MINGW_NOTHROW
525 int _vfprintf_p (FILE *, const char *, __VALIST);
527 _CRTIMP __cdecl __MINGW_NOTHROW
528 int _vsprintf_p (char *, size_t, const char *, __VALIST);
530 /* ...whereas the following six DO depend on locale_t.
532 * CAVEAT: unless you are linking with non-free MSVCR80.DLL, or one
533 * of its later derivatives, good luck trying to use these; see the
534 * explanation in <locale.t>, as to why you may be unable to create,
535 * or otherwise acquire a reference to, a locale_t object.
537 _CRTIMP __cdecl __MINGW_NOTHROW
538 int _printf_p_l (const char *, locale_t, ...);
540 _CRTIMP __cdecl __MINGW_NOTHROW
541 int _fprintf_p_l (FILE *, const char *, locale_t, ...);
543 _CRTIMP __cdecl __MINGW_NOTHROW
544 int _sprintf_p_l (char *, size_t, const char *, locale_t, ...);
546 _CRTIMP __cdecl __MINGW_NOTHROW
547 int _vprintf_p_l (const char *, locale_t, __VALIST);
549 _CRTIMP __cdecl __MINGW_NOTHROW
550 int _vfprintf_p_l (FILE *, const char *, locale_t, __VALIST);
552 _CRTIMP __cdecl __MINGW_NOTHROW
553 int _vsprintf_p_l (char *, size_t, const char *, locale_t, __VALIST);
555 #endif /* <stdio.h> included in its own right */
556 #endif /* MSVCR80.DLL and descendants, or MSVCRT.DLL since Vista */
558 #if ! (defined _STDIO_H && defined _WCHAR_H)
559 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
561 * Wide character variants of the foregoing "positional parameter" printf()
562 * functions; MSDN says that these should be declared when either <stdio.h>, or
563 * <wchar.h> is included, so we make them selectively available to <wchar.h>,
564 * but, just as in the foregoing, we advise against their use.
566 _CRTIMP __cdecl __MINGW_NOTHROW
567 int _wprintf_p (const wchar_t *, ...);
569 _CRTIMP __cdecl __MINGW_NOTHROW
570 int _fwprintf_p (FILE *, const wchar_t *, ...);
572 _CRTIMP __cdecl __MINGW_NOTHROW
573 int _swprintf_p (wchar_t *, size_t, const wchar_t *, ...);
575 _CRTIMP __cdecl __MINGW_NOTHROW
576 int _vwprintf_p (const wchar_t *, __VALIST);
578 _CRTIMP __cdecl __MINGW_NOTHROW
579 int _vfwprintf_p (FILE *, const wchar_t *, __VALIST);
581 _CRTIMP __cdecl __MINGW_NOTHROW
582 int _vswprintf_p (wchar_t *, size_t, const wchar_t *, __VALIST);
584 _CRTIMP __cdecl __MINGW_NOTHROW
585 int _wprintf_p_l (const wchar_t *, locale_t, ...);
587 _CRTIMP __cdecl __MINGW_NOTHROW
588 int _fwprintf_p_l (FILE *, const wchar_t *, locale_t, ...);
590 _CRTIMP __cdecl __MINGW_NOTHROW
591 int _swprintf_p_l (wchar_t *, size_t, const wchar_t *, locale_t, ...);
593 _CRTIMP __cdecl __MINGW_NOTHROW
594 int _vwprintf_p_l (const wchar_t *, locale_t, __VALIST);
596 _CRTIMP __cdecl __MINGW_NOTHROW
597 int _vfwprintf_p_l (FILE *, const wchar_t *, locale_t, __VALIST);
599 _CRTIMP __cdecl __MINGW_NOTHROW
600 int _vswprintf_p_l (wchar_t *, size_t, const wchar_t *, locale_t, __VALIST);
602 #endif /* MSVCR80.DLL and descendants, or MSVCRT.DLL since Vista */
603 #endif /* ! (defined _STDIO_H && defined _WCHAR_H) */
605 /* Once again, back to <stdio.h> specific declarations.
607 #if _POSIX_C_SOURCE >= 200809L
608 /* POSIX standard IEEE 1003.1-2008 added getdelim() and getline()
610 __cdecl __MINGW_NOTHROW ssize_t
611 getdelim (char ** __restrict__, size_t * __restrict__, int, FILE * __restrict__);
613 __cdecl __MINGW_NOTHROW ssize_t
614 getline (char ** __restrict__, size_t * __restrict__, FILE * __restrict__);
616 #ifndef __NO_INLINE__
617 /* getline() is a trivial specialization of getdelim(), which may
618 * be readily expressed by inline expansion.
620 __CRT_ALIAS __LIBIMPL__(( FUNCTION = getline ))
621 __cdecl __MINGW_NOTHROW ssize_t getline
622 ( char **__restrict__ __l, size_t *__restrict__ __n, FILE *__restrict__ __s )
623 { return getdelim( __l, __n, '\n', __s ); }
625 #endif /* !__NO_INLINE__ */
626 #endif /* POSIX.1-2008 */
630 _CRTIMP __cdecl __MINGW_NOTHROW int fscanf (FILE *, const char *, ...);
631 _CRTIMP __cdecl __MINGW_NOTHROW int scanf (const char *, ...);
632 _CRTIMP __cdecl __MINGW_NOTHROW int sscanf (const char *, const char *, ...);
634 /* Character Input and Output Functions
636 _CRTIMP __cdecl __MINGW_NOTHROW int fgetc (FILE *);
637 _CRTIMP __cdecl __MINGW_NOTHROW char * fgets (char *, int, FILE *);
638 _CRTIMP __cdecl __MINGW_NOTHROW int fputc (int, FILE *);
639 _CRTIMP __cdecl __MINGW_NOTHROW int fputs (const char *, FILE *);
640 _CRTIMP __cdecl __MINGW_NOTHROW char * gets (char *);
641 _CRTIMP __cdecl __MINGW_NOTHROW int puts (const char *);
642 _CRTIMP __cdecl __MINGW_NOTHROW int ungetc (int, FILE *);
644 /* Traditionally, getc and putc are defined as macros. but the
645 * standard doesn't say that they must be macros. We use inline
646 * functions here to allow the fast versions to be used in C++
647 * with namespace qualification, eg., ::getc.
649 * NOTE: _filbuf and _flsbuf are not thread-safe.
651 _CRTIMP __cdecl __MINGW_NOTHROW int _filbuf (FILE *);
652 _CRTIMP __cdecl __MINGW_NOTHROW int _flsbuf (int, FILE *);
656 __CRT_INLINE __cdecl __MINGW_NOTHROW int getc (FILE *);
657 __CRT_INLINE __cdecl __MINGW_NOTHROW int getc (FILE * __F)
659 return (--__F->_cnt >= 0)
660 ? (int) (unsigned char) *__F->_ptr++
664 __CRT_INLINE __cdecl __MINGW_NOTHROW int putc (int, FILE *);
665 __CRT_INLINE __cdecl __MINGW_NOTHROW int putc (int __c, FILE * __F)
667 return (--__F->_cnt >= 0)
668 ? (int) (unsigned char) (*__F->_ptr++ = (char)__c)
669 : _flsbuf (__c, __F);
672 __CRT_INLINE __cdecl __MINGW_NOTHROW int getchar (void);
673 __CRT_INLINE __cdecl __MINGW_NOTHROW int getchar (void)
675 return (--stdin->_cnt >= 0)
676 ? (int) (unsigned char) *stdin->_ptr++
680 __CRT_INLINE __cdecl __MINGW_NOTHROW int putchar(int);
681 __CRT_INLINE __cdecl __MINGW_NOTHROW int putchar(int __c)
683 return (--stdout->_cnt >= 0)
684 ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
685 : _flsbuf (__c, stdout);}
687 #else /* Use library functions. */
689 _CRTIMP __cdecl __MINGW_NOTHROW int getc (FILE *);
690 _CRTIMP __cdecl __MINGW_NOTHROW int putc (int, FILE *);
691 _CRTIMP __cdecl __MINGW_NOTHROW int getchar (void);
692 _CRTIMP __cdecl __MINGW_NOTHROW int putchar (int);
696 /* Direct Input and Output Functions
698 _CRTIMP __cdecl __MINGW_NOTHROW size_t fread (void *, size_t, size_t, FILE *);
699 _CRTIMP __cdecl __MINGW_NOTHROW size_t fwrite (const void *, size_t, size_t, FILE *);
701 /* File Positioning Functions
703 _CRTIMP __cdecl __MINGW_NOTHROW int fseek (FILE *, long, int);
704 _CRTIMP __cdecl __MINGW_NOTHROW long ftell (FILE *);
705 _CRTIMP __cdecl __MINGW_NOTHROW void rewind (FILE *);
707 #if _WIN32_WINNT >= _WIN32_WINNT_VISTA || __MSVCRT_VERSION__ >= __MSVCR80_DLL
709 * Microsoft introduced a number of variations on fseek() and ftell(),
710 * beginning with MSVCR80.DLL; the bare _fseeki64() and _ftelli64() were
711 * subsequently integrated into MSVCRT.DLL, from Vista onward...
713 _CRTIMP __cdecl __MINGW_NOTHROW int _fseeki64 (FILE *, __int64, int);
714 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64 (FILE *);
716 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL
718 * ...while the "nolock" variants remain exclusive to MSVCR80.DLL, and
719 * its later MSVC specific derivatives.
721 _CRTIMP __cdecl __MINGW_NOTHROW int _fseek_nolock (FILE *, long, int);
722 _CRTIMP __cdecl __MINGW_NOTHROW long _ftell_nolock (FILE *);
724 _CRTIMP __cdecl __MINGW_NOTHROW int _fseeki64_nolock (FILE *, __int64, int);
725 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64_nolock (FILE *);
727 #endif /* MSVCR80.DLL and later derivatives ONLY */
728 #endif /* MSVCR80.DLL and descendants, or MSVCRT.DLL since Vista */
730 #ifdef __USE_MINGW_FSEEK
731 /* Workaround for a limitation on Win9x where a file is not zero padded
732 * on write, following a seek beyond the original end of file; these are
733 * implemented in libmingwex.a
735 __cdecl __MINGW_NOTHROW int __mingw_fseek (FILE *, long, int);
736 __cdecl __MINGW_NOTHROW size_t __mingw_fwrite (const void *, size_t, size_t, FILE *);
738 #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp)
739 #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence)
740 #endif /* __USE_MINGW_FSEEK */
742 /* An opaque data type used for storing file positions... The contents of
743 * this type are unknown, but we (the compiler) need to know the size
744 * because the programmer using fgetpos and fsetpos will be setting aside
745 * storage for fpos_t structres. Actually I tested using a byte array and
746 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
747 * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in
748 * MSVCRT however, and for now `long long' will do.
751 typedef long long fpos_t;
756 _CRTIMP __cdecl __MINGW_NOTHROW int fgetpos (FILE *, fpos_t *);
757 _CRTIMP __cdecl __MINGW_NOTHROW int fsetpos (FILE *, const fpos_t *);
761 _CRTIMP __cdecl __MINGW_NOTHROW int feof (FILE *);
762 _CRTIMP __cdecl __MINGW_NOTHROW int ferror (FILE *);
765 inline __cdecl __MINGW_NOTHROW int feof (FILE * __F){ return __F->_flag & _IOEOF; }
766 inline __cdecl __MINGW_NOTHROW int ferror (FILE * __F){ return __F->_flag & _IOERR; }
768 #define feof(__F) ((__F)->_flag & _IOEOF)
769 #define ferror(__F) ((__F)->_flag & _IOERR)
772 _CRTIMP __cdecl __MINGW_NOTHROW void clearerr (FILE *);
773 _CRTIMP __cdecl __MINGW_NOTHROW void perror (const char *);
776 #ifndef __STRICT_ANSI__
780 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _popen (const char *, const char *);
781 _CRTIMP __cdecl __MINGW_NOTHROW int _pclose (FILE *);
784 _CRTIMP __cdecl __MINGW_NOTHROW FILE * popen (const char *, const char *);
785 _CRTIMP __cdecl __MINGW_NOTHROW int pclose (FILE *);
788 /* Other Non ANSI functions
790 _CRTIMP __cdecl __MINGW_NOTHROW int _flushall (void);
791 _CRTIMP __cdecl __MINGW_NOTHROW int _fgetchar (void);
792 _CRTIMP __cdecl __MINGW_NOTHROW int _fputchar (int);
793 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _fdopen (int, const char *);
794 _CRTIMP __cdecl __MINGW_NOTHROW int _fileno (FILE *);
795 _CRTIMP __cdecl __MINGW_NOTHROW int _fcloseall (void);
796 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _fsopen (const char *, const char *, int);
798 _CRTIMP __cdecl __MINGW_NOTHROW int _getmaxstdio (void);
799 _CRTIMP __cdecl __MINGW_NOTHROW int _setmaxstdio (int);
802 /* Microsoft introduced a capability in MSVCR80.DLL and later, to
803 * set the minimum number of digits to be displayed in a printf()
804 * floating point exponent; they retro-fitted this in MSVCRT.DLL,
805 * from Windows-Vista onwards, but we provide our own wrappers in
806 * libmingwex.a, which make it possible for us to emulate the API
807 * for any version of MSVCRT.DLL (including WinXP and earlier).
809 #define _TWO_DIGIT_EXPONENT 1
811 /* While Microsoft define the preceding manifest constant, they
812 * appear to neglect to define its complement, (for restoration
813 * of their default exponent display format); for orthogonality,
814 * we will provide this regardless of Microsoft's negligence.
816 #define _THREE_DIGIT_EXPONENT 0
818 /* Once again, unspecified by Microsoft, (and mostly redundant),
819 * it is convenient to specify a combining mask for these.
821 #define _EXPONENT_DIGIT_MASK (_TWO_DIGIT_EXPONENT | _THREE_DIGIT_EXPONENT)
823 unsigned int __cdecl __mingw_get_output_format (void);
824 unsigned int __cdecl __mingw_set_output_format (unsigned int);
826 /* Also appearing for the first time in MSVCR80.DLL, and then also
827 * retro-fitted to MSVCRT.DLL from Windows-Vista onwards, was this
828 * pair of functions to control availability of "%n" formatting in
829 * the MSVCRT.DLL printf() family of functions, for which we also
830 * provide our own DLL version agnostic wrappers:
832 int __cdecl __mingw_get_printf_count_output (void);
833 int __cdecl __mingw_set_printf_count_output (int);
835 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL
836 /* When the user declares that MSVCR80.DLL features are supported,
837 * we simply expose the corresponding APIs...
839 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void);
840 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int);
842 _CRTIMP __cdecl __MINGW_NOTHROW int _get_printf_count_output (void);
843 _CRTIMP __cdecl __MINGW_NOTHROW int _set_printf_count_output (int);
846 /* ...otherwise, we emulate the APIs, in a DLL version agnostic
847 * manner, using our own implementation wrappers.
849 __CRT_ALIAS unsigned int __cdecl _get_output_format (void)
850 { return __mingw_get_output_format (); }
852 __CRT_ALIAS unsigned int __cdecl _set_output_format (unsigned int __style)
853 { return __mingw_set_output_format (__style); }
855 /* When using our own printf() implementation, "%n" format is ALWAYS
856 * supported, so we make this API a no-op, reporting it to be so; for
857 * the alternative case, when using MSVCRT.DLL's printf(), we delegate
858 * to our wrapper API implementation, which will invoke the API function
859 * calls within the DLL, if they are available, or persistently report
860 * the state of "%n" formatting as DISABLED if they are not.
862 #if __USE_MINGW_ANSI_STDIO
863 /* Note that __USE_MINGW_ANSI_STDIO is not guaranteed to resolve to any
864 * symbol which will represent a compilable logic state; map it to this
865 * alternative which will, for the true state...
867 # define __USE_MINGW_PRINTF 1
869 /* ...and for the false.
871 # define __USE_MINGW_PRINTF 0
874 __CRT_ALIAS int __cdecl _get_printf_count_output (void)
875 { return __USE_MINGW_PRINTF ? 1 : __mingw_get_printf_count_output (); }
877 __CRT_ALIAS int __cdecl _set_printf_count_output (int __mode)
878 { return __USE_MINGW_PRINTF ? 1 : __mingw_set_printf_count_output (__mode); }
882 _CRTIMP __cdecl __MINGW_NOTHROW int fgetchar (void);
883 _CRTIMP __cdecl __MINGW_NOTHROW int fputchar (int);
884 _CRTIMP __cdecl __MINGW_NOTHROW FILE * fdopen (int, const char *);
885 _CRTIMP __cdecl __MINGW_NOTHROW int fileno (FILE *);
886 #endif /* !_NO_OLDNAMES */
888 #define _fileno(__F) ((__F)->_file)
890 #define fileno(__F) ((__F)->_file)
893 #if defined (__MSVCRT__) && ! defined (__NO_MINGW_LFS)
894 __CRT_ALIAS FILE * __cdecl __MINGW_NOTHROW fopen64 (const char *, const char *);
895 __CRT_ALIAS __JMPSTUB__(( FUNCTION = fopen64, REMAPPED = fopen ))
896 FILE * __cdecl __MINGW_NOTHROW fopen64 (const char * filename, const char * mode)
897 { return fopen (filename, mode); }
899 int __cdecl __MINGW_NOTHROW fseeko64 (FILE *, __off64_t, int);
901 #ifdef __USE_MINGW_FSEEK
902 int __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, __off64_t, int);
903 #define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence)
906 __CRT_ALIAS __off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE *);
907 __CRT_ALIAS __LIBIMPL__(( FUNCTION = ftello64 ))
908 __off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream)
909 { fpos_t __pos; return (fgetpos(stream, &__pos)) ? -1LL : (__off64_t)(__pos); }
911 #endif /* __MSVCRT__ && !__NO_MINGW_LFS */
912 #endif /* !__STRICT_ANSI__ */
913 #endif /* _STDIO_H */
915 #if ! (defined _STDIO_H && defined _WCHAR_H)
916 /* The following are declared when including either <stdio.h> or <wchar.h>.
917 * If both header include guards are now in place, then we must currently be
918 * including <stdio.h> in its own right, having already processed this block
919 * during prior partial inclusion by <wchar.h>; there is no need to process
922 _CRTIMP __cdecl __MINGW_NOTHROW int fwprintf (FILE *, const wchar_t *, ...);
923 _CRTIMP __cdecl __MINGW_NOTHROW int wprintf (const wchar_t *, ...);
924 _CRTIMP __cdecl __MINGW_NOTHROW int vfwprintf (FILE *, const wchar_t *, __VALIST);
925 _CRTIMP __cdecl __MINGW_NOTHROW int vwprintf (const wchar_t *, __VALIST);
926 _CRTIMP __cdecl __MINGW_NOTHROW int _snwprintf (wchar_t *, size_t, const wchar_t *, ...);
927 _CRTIMP __cdecl __MINGW_NOTHROW int _vscwprintf (const wchar_t *, __VALIST);
928 _CRTIMP __cdecl __MINGW_NOTHROW int _vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
929 _CRTIMP __cdecl __MINGW_NOTHROW int fwscanf (FILE *, const wchar_t *, ...);
930 _CRTIMP __cdecl __MINGW_NOTHROW int wscanf (const wchar_t *, ...);
931 _CRTIMP __cdecl __MINGW_NOTHROW int swscanf (const wchar_t *, const wchar_t *, ...);
932 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fgetwc (FILE *);
933 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fputwc (wchar_t, FILE *);
934 _CRTIMP __cdecl __MINGW_NOTHROW wint_t ungetwc (wchar_t, FILE *);
936 #ifndef __STRICT_ANSI__
937 /* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf).
939 _CRTIMP __cdecl __MINGW_NOTHROW int swprintf (wchar_t *, const wchar_t *, ...);
940 _CRTIMP __cdecl __MINGW_NOTHROW int vswprintf (wchar_t *, const wchar_t *, __VALIST);
944 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * fgetws (wchar_t *, int, FILE *);
945 _CRTIMP __cdecl __MINGW_NOTHROW int fputws (const wchar_t *, FILE *);
946 _CRTIMP __cdecl __MINGW_NOTHROW wint_t getwc (FILE *);
947 _CRTIMP __cdecl __MINGW_NOTHROW wint_t getwchar (void);
948 _CRTIMP __cdecl __MINGW_NOTHROW wint_t putwc (wint_t, FILE *);
949 _CRTIMP __cdecl __MINGW_NOTHROW wint_t putwchar (wint_t);
951 #ifndef __STRICT_ANSI__
952 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _getws (wchar_t *);
953 _CRTIMP __cdecl __MINGW_NOTHROW int _putws (const wchar_t *);
954 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfdopen(int, const wchar_t *);
955 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfopen (const wchar_t *, const wchar_t *);
956 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfreopen (const wchar_t *, const wchar_t *, FILE *);
957 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wfsopen (const wchar_t *, const wchar_t *, int);
958 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _wtmpnam (wchar_t *);
959 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t * _wtempnam (const wchar_t *, const wchar_t *);
960 _CRTIMP __cdecl __MINGW_NOTHROW int _wrename (const wchar_t *, const wchar_t *);
961 _CRTIMP __cdecl __MINGW_NOTHROW int _wremove (const wchar_t *);
962 _CRTIMP __cdecl __MINGW_NOTHROW void _wperror (const wchar_t *);
963 _CRTIMP __cdecl __MINGW_NOTHROW FILE * _wpopen (const wchar_t *, const wchar_t *);
965 #endif /* !__STRICT_ANSI__ */
966 #endif /* __MSVCRT__ */
968 #ifdef _ISOC99_SOURCE
969 __JMPSTUB__(( FUNCTION = snwprintf, DLLENTRY = _snwprintf ))
970 __cdecl __MINGW_NOTHROW int snwprintf (wchar_t *, size_t, const wchar_t *, ...);
971 __cdecl __MINGW_NOTHROW int vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
973 #ifndef __NO_INLINE__
974 __CRT_INLINE __cdecl __MINGW_NOTHROW
975 __JMPSTUB__(( FUNCTION = vsnwprintf, DLLENTRY = _vsnwprintf ))
976 int vsnwprintf (wchar_t *__s, size_t __n, const wchar_t *__fmt, __VALIST __arg)
977 { return _vsnwprintf ( __s, __n, __fmt, __arg); }
980 __cdecl __MINGW_NOTHROW int vwscanf (const wchar_t *__restrict__, __VALIST);
981 __cdecl __MINGW_NOTHROW
982 int vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, __VALIST);
983 __cdecl __MINGW_NOTHROW
984 int vswscanf (const wchar_t *__restrict__, const wchar_t * __restrict__, __VALIST);
986 #endif /* _ISOC99_SOURCE */
987 #endif /* ! (_STDIO_H && _WCHAR_H) */
989 #if defined _STDIO_H && ! defined __STRICT_ANSI__
990 #if defined __MSVCRT__ && ! defined _NO_OLDNAMES
991 _CRTIMP __cdecl __MINGW_NOTHROW FILE * wpopen (const wchar_t *, const wchar_t *);
994 /* Other non-ANSI wide character functions...
996 _CRTIMP __cdecl __MINGW_NOTHROW wint_t _fgetwchar (void);
997 _CRTIMP __cdecl __MINGW_NOTHROW wint_t _fputwchar (wint_t);
998 _CRTIMP __cdecl __MINGW_NOTHROW int _getw (FILE *);
999 _CRTIMP __cdecl __MINGW_NOTHROW int _putw (int, FILE *);
1001 #ifndef _NO_OLDNAMES
1002 /* ...and their original names, before Microsoft uglification...
1004 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fgetwchar (void);
1005 _CRTIMP __cdecl __MINGW_NOTHROW wint_t fputwchar (wint_t);
1006 _CRTIMP __cdecl __MINGW_NOTHROW int getw (FILE *);
1007 _CRTIMP __cdecl __MINGW_NOTHROW int putw (int, FILE *);
1009 #endif /* !_NO_OLDNAMES */
1010 #endif /* !__STRICT_ANSI__ */
1014 #endif /* ! RC_INVOKED */
1015 #endif /* !_STDIO_H: $RCSfile$: end of file */