OSDN Git Service

Refactor <stdio.h> vs. <wchar.h> to avoid duplication.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 29 Jan 2016 17:39:38 +0000 (17:39 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 29 Jan 2016 17:39:38 +0000 (17:39 +0000)
mingwrt/ChangeLog
mingwrt/include/stdio.h
mingwrt/include/wchar.h
mingwrt/pseudo-reloc.c

index 34493d9..d596292 100644 (file)
@@ -1,5 +1,37 @@
 2016-01-29  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
+       Refactor <stdio.h> vs. <wchar.h> to avoid duplication.
+
+       * include/wchar.h: Some minor layout adjustments.
+       (__WCHAR_H_SOURCED__): New macro; define it temporarily, only while
+       within the scope of reading <wchar.h>; undefine it at end of file.
+       (struct tm): Do not define; it is sufficient to keep it opaque.
+       (FILE, FILENAME_MAX, NULL, __VALIST, off_t, __off64_t, size_t)
+       (ssize_t, va_list, wchar_t, wint_t): Do not require or define them
+       directly; delegate to indirect definition by including <stdio.h>.
+       (fgetwc, fputwc, fgetws, fputws, fwprintf, fwscanf, getwc, getwchar)
+       (_getws, putwc, putwchar, _putws, snwprintf, _snwprintf, swprintf)
+       (swscanf, ungetwc, vfwprintf, vfwscanf, _vscwprintf, vsnwprintf)
+       (_vsnwprintf, vswprintf, vwprintf, vswscanf, vwscanf, _wfdopen)
+       (_wfopen, _wfreopen, _wfsopen, _wperror, _wpopen, wprintf, _wrename)
+       (_wremove, wscanf, _wtmpnam, _wtempnam): Omit prototypes; acquire them
+       indirectly, by selective inclusion from <stdio.h>; hence include it.
+
+       * include/stdio.h: Assert copyright; tidy layout.
+       [__WCHAR_H_SOURCED__]: Selectively define and declare only those
+       entities which are required by <wchar.h>; do not define...
+       [__WCHAR_H_SOURCED__] (_STDIO_H): ...this; define it only if...
+       [!__WCHAR_H_SOURCED__]: ...this; define and declare ALL entities which
+       are normally specified within <stdio.h>, INCLUDING those specifically
+       itemised above, as selectively required by <wchar.h>.
+
+       * pseudo-reloc.c: Some minor layout adjustments.
+       (WIN32_LEAN_AND_MEAN): Define it; we don't need the windows baggage.
+       [typedef ptrdiff_t]: Do not assume this is gratuitously defined;
+       include <stdint.h> to guarantee it.
+
+2016-01-29  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
        Enable selective definition of POSIX system types.
 
        * include/sys/types.h (_SYS_TYPES_H): Do NOT define, if including with
index 2fc3c47..3a86a87 100644 (file)
 /*
  * stdio.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
  *
- * Definitions of types and prototypes of functions for standard input and
- * output.
+ * Definitions of types and prototypes of functions for operations on
+ * standard input and standard output streams.
+ *
+ * $Id$
+ *
+ * Written by Rob Savoye <rob@cygnus.com>
+ * Copyright (C) 1997-2005, 2007-2010, 2014-2016, MinGW.org Project.
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * NOTE: The file manipulation functions provided by Microsoft seem to
- * work with either slash (/) or backslash (\) as the directory separator.
+ * work with either slash (/) or backslash (\) as the directory separator;
+ * (this is consistent with Microsoft's own documentation, on MSDN).
  *
- * TODO: File requires review; rationalization and refactoring recommended.
  */
+#ifndef _STDIO_H
+#pragma GCC system_header
+
+/* When including <wchar.h>, some of the definitions and declarations
+ * which are nominally provided in <stdio.h> must be duplicated.  Rather
+ * than require duplicated maintenance effort, we provide for partial
+ * inclusion of <stdio.h> by <wchar.h>; only when not included in
+ * this partial fashion...
+ */
+#ifndef __WCHAR_H_SOURCED__
+ /*
+  * ...which is exclusive to <wchar.h>, do we assert the multiple
+  * inclusion guard for <stdio.h> itself.
+  */
+#define _STDIO_H
+#endif
 
-#ifndef _STDIO_H_
-#define        _STDIO_H_
-
-/* All the headers include this file. */
+/* All the headers include this file.
+ */
 #include <_mingw.h>
 
 #ifndef RC_INVOKED
-#define __need_size_t
+/* POSIX stipulates that the following set of types, (as identified by
+ * __need_TYPENAME macros), shall be defined consistently with <stddef.h>;
+ * by defining the appropriate __need_TYPENAME macros, we may selectively
+ * obtain the required definitions by inclusion of <stddef.h>, WITHOUT
+ * automatic exposure of any of its additional content.
+ */
 #define __need_NULL
+#define __need_size_t
 #define __need_wchar_t
-#define        __need_wint_t
+#define __need_wint_t
 #include <stddef.h>
-#define __need___va_list
-#include <stdarg.h>
-#endif /* Not RC_INVOKED */
 
+#if _POSIX_C_SOURCE >= 200809L
+ /* Similarly, for types defined in <sys/types.h>, (which are explicitly
+  * dependent on the POSIX.1-2008 feature test)...
+  */
+# define __need_off_t
+# define __need_ssize_t
+#endif
+#if !(defined __STRICT_ANSI__ || defined (__NO_MINGW_LFS)) \
+ && defined (__MSVCRT__)
+ /* ...while this is required to support our fseeko64() and ftello64()
+  * implementations, (neither of which is in any way standardized)...
+  */
+# define __need___off64_t
+#endif
+/* It is sufficient to test for just one define from each of the two
+ * preceding groups...
+ */
+#if defined __need_off_t || defined __need___off64_t
+ /* ...to identify a requirement for selective inclusion from...
+  */
+# include <sys/types.h>
+#endif
 
-/* Flags for the iobuf structure  */
-#define        _IOREAD 1 /* currently reading */
-#define        _IOWRT  2 /* currently writing */
-#define        _IORW   0x0080 /* opened as "r+w" */
+#ifndef __VALIST
+ /* Also similarly, for the va_list type, defined in <stdarg.h>
+  */
+# if defined __GNUC__ && __GNUC__ >= 3
+#  define __need___va_list
+#  include <stdarg.h>
+#  define __VALIST __builtin_va_list
+# else
+#  define __VALIST char *
+# endif
+#endif
+#endif /* ! RC_INVOKED */
 
+#ifdef _STDIO_H
+/* Flags for the iobuf structure
+ */
+#define _IOREAD        1       /* currently reading */
+#define _IOWRT         2       /* currently writing */
+#define _IORW     0x0080       /* opened as "r+w" */
 
-/*
- * The three standard file pointers provided by the run time library.
+/* The three standard file pointers provided by the run time library.
  * NOTE: These will go to the bit-bucket silently in GUI applications!
  */
-#define        STDIN_FILENO    0
-#define        STDOUT_FILENO   1
-#define        STDERR_FILENO   2
+#define STDIN_FILENO   0
+#define STDOUT_FILENO  1
+#define STDERR_FILENO  2
 
-/* Returned by various functions on end of file condition or error. */
-#define        EOF     (-1)
+/* Returned by various functions on end of file condition or error.
+ */
+#define EOF          (-1)
 
-/*
- * The maximum length of a file name. You should use GetVolumeInformation
- * instead of this constant. But hey, this works.
- * Also defined in io.h.
+#endif /* _STDIO_H */
+
+/* The maximum length of a file name.  It may be better to use the Windows'
+ * GetVolumeInformation() function in preference to this constant, but hey,
+ * this works!  Note that <io.h> also defines it, but we don't guard it, so
+ * that the compiler has a chance to catch inconsistencies.
+ *
+ * FIXME: Right now, we define this unconditionally for both full <stdio.h>
+ * inclusion, and for partial inclusion on behalf of <wchar.h>, (which needs
+ * it for some non-ANSI structure declarations).  The conditions under which
+ * <wchar.h> needs this require review, because defining it as a consequence
+ * of including <wchar.h> alone may violate strict ANSI conformity.
  */
-#ifndef FILENAME_MAX
-#define        FILENAME_MAX    (260)
-#endif
+#define FILENAME_MAX  (260)
 
-/*
- * The maximum number of files that may be open at once. I have set this to
+#ifdef _STDIO_H
+/* The maximum number of files that may be open at once. I have set this to
  * a conservative number. The actual value may be higher.
  */
-#define FOPEN_MAX      (20)
+#define FOPEN_MAX      (20)
 
-/* After creating this many names, tmpnam and tmpfile return NULL */
-#define TMP_MAX        32767
-/*
- * Tmpnam, tmpfile and, sometimes, _tempnam try to create
+/* After creating this many names, tmpnam and tmpfile return NULL
+ */
+#define TMP_MAX      32767
+
+/* Tmpnam, tmpfile and, sometimes, _tempnam try to create
  * temp files in the root directory of the current drive
  * (not in pwd, as suggested by some older MS doc's).
  * Redefining these macros does not effect the CRT functions.
 #endif
 #define _wP_tmpdir  L"\\"
 
-/*
- * The maximum size of name (including NUL) that will be put in the user
+/* The maximum size of name (including NUL) that will be put in the user
  * supplied buffer caName for tmpnam.
  * Inferred from the size of the static buffer returned by tmpnam
  * when passed a NULL argument. May actually be smaller.
  */
 #define L_tmpnam (16)
 
-#define _IOFBF    0x0000  /* full buffered */
-#define _IOLBF    0x0040  /* line buffered */
-#define _IONBF    0x0004  /* not buffered */
+#define _IOFBF         0x0000  /* full buffered */
+#define _IOLBF         0x0040  /* line buffered */
+#define _IONBF         0x0004  /* not buffered */
 
-#define _IOMYBUF  0x0008  /* stdio malloc()'d buffer */
-#define _IOEOF    0x0010  /* EOF reached on read */
-#define _IOERR    0x0020  /* I/O error from system */
-#define _IOSTRG   0x0040  /* Strange or no file descriptor */
+#define _IOMYBUF       0x0008  /* stdio malloc()'d buffer */
+#define _IOEOF         0x0010  /* EOF reached on read */
+#define _IOERR         0x0020  /* I/O error from system */
+#define _IOSTRG        0x0040  /* Strange or no file descriptor */
 #ifdef _POSIX_SOURCE
-# define _IOAPPEND 0x0200
+# define _IOAPPEND     0x0200
 #endif
-/*
- * The buffer size as used by setbuf such that it is equivalent to
+
+/* The buffer size as used by setbuf such that it is equivalent to
  * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
  */
-#define        BUFSIZ  512
+#define BUFSIZ            512
 
 /* Constants for nOrigin indicating the position relative to which fseek
  * sets the file position.  Defined unconditionally since ISO and POSIX
  * say they are defined here.
  */
-#define SEEK_SET  0
-#define SEEK_CUR  1
-#define SEEK_END  2
-
-#ifndef        RC_INVOKED
+#define SEEK_SET            0
+#define SEEK_CUR            1
+#define SEEK_END            2
 
-#ifndef __VALIST
-#ifdef __GNUC__
-#define __VALIST __gnuc_va_list
-#else
-#define __VALIST char*
-#endif
-#endif /* defined __VALIST  */
+#endif /* _STDIO_H */
 
-/*
- * The structure underlying the FILE type.
+#ifndef RC_INVOKED
+#if ! (defined _STDIO_H && defined _WCHAR_H)
+/* The structure underlying the FILE type; this should be defined when
+ * including either <stdio.h> or <wchar.h>.  If both header include guards
+ * are now in place, then we must currently be including <stdio.h> in its
+ * own right, having already processed this block during a prior partial
+ * inclusion by <wchar.h>; there is no need to process it a second time.
  *
  * Some believe that nobody in their right mind should make use of the
  * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
  * <paag@tid.es>.
  */
-#ifndef _FILE_DEFINED
-#define        _FILE_DEFINED
 typedef struct _iobuf
 {
-       char*   _ptr;
-       int     _cnt;
-       char*   _base;
-       int     _flag;
-       int     _file;
-       int     _charbuf;
-       int     _bufsiz;
-       char*   _tmpfname;
+  char *_ptr;
+  int   _cnt;
+  char *_base;
+  int   _flag;
+  int   _file;
+  int   _charbuf;
+  int   _bufsiz;
+  char *_tmpfname;
 } FILE;
-#endif /* Not _FILE_DEFINED */
 
+#endif  /* ! (_STDIO_H && _WCHAR_H) */
 
-/*
- * The standard file handles
+#ifdef _STDIO_H
+
+/* The standard file handles
  */
 #ifndef __DECLSPEC_SUPPORTED
 
 extern FILE (*_imp___iob)[];   /* A pointer to an array of FILE */
 
-#define _iob   (*_imp___iob)   /* An array of FILE */
+#define _iob (*_imp___iob)     /* An array of FILE */
 
 #else /* __DECLSPEC_SUPPORTED */
 
@@ -163,33 +240,37 @@ __MINGW_IMPORT FILE _iob[];       /* An array of FILE imported from DLL. */
 
 _BEGIN_C_DECLS
 
-/*
- * File Operations
- */
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  fopen (const char*, const char*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  freopen (const char*, const char*, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fflush (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fclose (FILE*);
-/* MS puts remove & rename (but not wide versions) in io.h  also */
-_CRTIMP int __cdecl __MINGW_NOTHROW    remove (const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    rename (const char*, const char*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  tmpfile (void);
-_CRTIMP char* __cdecl __MINGW_NOTHROW  tmpnam (char*);
+/* File Operations
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * fopen (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * freopen (const char *, const char *, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fflush (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fclose (FILE *);
+
+/* Note: Microsoft also declares remove & rename (but not their wide char
+ * variants) in <io.h>; since duplicate prototypes are acceptable, provided
+ * they are consistent, we simply declare them here anyway, while allowing
+ * the compiler to check consistency as appropriate.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    remove (const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    rename (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * tmpfile (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  char * tmpnam (char *);
 
 #ifndef __STRICT_ANSI__
-_CRTIMP char* __cdecl __MINGW_NOTHROW  _tempnam (const char*, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _rmtmp(void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _unlink (const char*);
-
-#ifndef        NO_OLDNAMES
-_CRTIMP char* __cdecl __MINGW_NOTHROW  tempnam (const char*, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    rmtmp(void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    unlink (const char*);
+_CRTIMP __cdecl __MINGW_NOTHROW  char *_tempnam (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int   _rmtmp (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int   _unlink (const char *);
+
+#ifndef NO_OLDNAMES
+_CRTIMP __cdecl __MINGW_NOTHROW  char * tempnam (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    rmtmp (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    unlink (const char *);
 #endif
 #endif /* __STRICT_ANSI__ */
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    setvbuf (FILE*, char*, int, size_t);
-_CRTIMP void __cdecl __MINGW_NOTHROW   setbuf (FILE*, char*);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    setvbuf (FILE *, char *, int, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  void   setbuf (FILE *, char *);
 
 /* Formatted Output
  *
@@ -236,20 +317,17 @@ extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VAL
 extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
 
 #if __USE_MINGW_ANSI_STDIO
-/*
- * User has expressed a preference for C99 conformance...
+/* User has expressed a preference for C99 conformance...
  */
 # undef __mingw_stdio_redirect__
 # ifdef __cplusplus
-/*
- * For C++ we use inline implementations, to avoid interference
+/* For C++ we use inline implementations, to avoid interference
  * with namespace qualification, which may result from using #defines.
  */
 #  define __mingw_stdio_redirect__  inline __cdecl __MINGW_NOTHROW
 
 # elif defined __GNUC__
-/*
- * FIXME: Is there any GCC version prerequisite here?
+/* FIXME: Is there any GCC version prerequisite here?
  *
  * We also prefer inline implementations for C, when we can be confident
  * that the GNU specific __inline__ mechanism is supported.
@@ -257,8 +335,7 @@ extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
 #  define __mingw_stdio_redirect__  static __inline__ __cdecl __MINGW_NOTHROW
 
 # else
-/*
- * Can't use inlines; fall back on module local static stubs.
+/* Can't use inlines; fall back on module local static stubs.
  */
 #  define __mingw_stdio_redirect__  static __cdecl __MINGW_NOTHROW
 # endif
@@ -312,38 +389,36 @@ int vsprintf (char *__stream, const char *__format, __VALIST __local_argv)
 }
 
 #else
-/*
- * Default configuration: simply direct all calls to MSVCRT...
+/* Default configuration: simply direct all calls to MSVCRT...
  */
-_CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int fprintf (FILE *, const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int printf (const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int sprintf (char *, const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int vfprintf (FILE *, const char *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int vprintf (const char *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int vsprintf (char *, const char *, __VALIST);
 
 #endif
-/*
- * Regardless of user preference, always offer these alternative
+/* Regardless of user preference, always offer these alternative
  * entry points, for direct access to the MSVCRT implementations.
  */
 #undef  __mingw_stdio_redirect__
 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F
 
-_CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...);
-_CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...);
-_CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...);
-_CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST);
-_CRTIMP int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST);
-_CRTIMP int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST);
+_CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE *, const char *, ...);
+_CRTIMP int __mingw_stdio_redirect__(printf)(const char *, ...);
+_CRTIMP int __mingw_stdio_redirect__(sprintf)(char *, const char *, ...);
+_CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE *, const char *, __VALIST);
+_CRTIMP int __mingw_stdio_redirect__(vprintf)(const char *, __VALIST);
+_CRTIMP int __mingw_stdio_redirect__(vsprintf)(char *, const char *, __VALIST);
 
 #undef  __mingw_stdio_redirect__
 
 /* The following three ALWAYS refer to the MSVCRT implementations...
  */
-_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _snprintf (char *, size_t, const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _vsnprintf (char *, size_t, const char *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _vscprintf (const char *, __VALIST);
 
 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
 /*
@@ -353,69 +428,67 @@ _CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, __VALIST);
  * compatible with C99, but the following are; if you want the MSVCRT
  * behaviour, you *must* use the Microsoft uglified names.
  */
-int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...);
-int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST);
+__cdecl __MINGW_NOTHROW  int snprintf (char *, size_t, const char *, ...);
+__cdecl __MINGW_NOTHROW  int vsnprintf (char *, size_t, const char *, __VALIST);
 
-int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);
-int __cdecl __MINGW_NOTHROW vfscanf (FILE * __restrict__, const char * __restrict__,
-                    __VALIST);
-int __cdecl __MINGW_NOTHROW vsscanf (const char * __restrict__,
-                    const char * __restrict__, __VALIST);
+__cdecl __MINGW_NOTHROW  int vscanf (const char * __restrict__, __VALIST);
+__cdecl __MINGW_NOTHROW
+int vfscanf (FILE * __restrict__, const char * __restrict__, __VALIST);
+__cdecl __MINGW_NOTHROW
+int vsscanf (const char * __restrict__, const char * __restrict__, __VALIST);
 
 #endif  /* !__NO_ISOCEXT */
 
-/*
- * Formatted Input
+/* Formatted Input
  */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fscanf (FILE *, const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    scanf (const char *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    sscanf (const char *, const char *, ...);
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    fscanf (FILE*, const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    scanf (const char*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    sscanf (const char*, const char*, ...);
-/*
- * Character Input and Output Functions
+/* Character Input and Output Functions
  */
-
-_CRTIMP int __cdecl __MINGW_NOTHROW    fgetc (FILE*);
-_CRTIMP char* __cdecl __MINGW_NOTHROW  fgets (char*, int, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fputc (int, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fputs (const char*, FILE*);
-_CRTIMP char* __cdecl __MINGW_NOTHROW  gets (char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    puts (const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    ungetc (int, FILE*);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fgetc (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  char * fgets (char *, int, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fputc (int, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fputs (const char *, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  char * gets (char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    puts (const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    ungetc (int, FILE *);
 
 /* Traditionally, getc and putc are defined as macros. but the
-   standard doesn't say that they must be macros.
-   We use inline functions here to allow the fast versions
-   to be used in C++ with namespace qualification, eg., ::getc.
-
-   _filbuf and _flsbuf  are not thread-safe. */
-_CRTIMP int __cdecl __MINGW_NOTHROW    _filbuf (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _flsbuf (int, FILE*);
+ * standard doesn't say that they must be macros.  We use inline
+ * functions here to allow the fast versions to be used in C++
+ * with namespace qualification, eg., ::getc.
+ *
+ * NOTE: _filbuf and _flsbuf  are not thread-safe.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  int   _filbuf (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int   _flsbuf (int, FILE *);
 
 #if !defined _MT
 
-__CRT_INLINE int __cdecl __MINGW_NOTHROW getc (FILE* __F)
+__CRT_INLINE __cdecl __MINGW_NOTHROW  int getc (FILE * __F)
 {
   return (--__F->_cnt >= 0)
     ?  (int) (unsigned char) *__F->_ptr++
     : _filbuf (__F);
 }
 
-__CRT_INLINE int __cdecl __MINGW_NOTHROW putc (int __c, FILE* __F)
+__CRT_INLINE __cdecl __MINGW_NOTHROW  int putc (int __c, FILE * __F)
 {
   return (--__F->_cnt >= 0)
     ?  (int) (unsigned char) (*__F->_ptr++ = (char)__c)
     :  _flsbuf (__c, __F);
 }
 
-__CRT_INLINE int __cdecl __MINGW_NOTHROW getchar (void)
+__CRT_INLINE __cdecl __MINGW_NOTHROW  int getchar (void)
 {
   return (--stdin->_cnt >= 0)
     ?  (int) (unsigned char) *stdin->_ptr++
     : _filbuf (stdin);
 }
 
-__CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c)
+__CRT_INLINE __cdecl __MINGW_NOTHROW  int putchar(int __c)
 {
   return (--stdout->_cnt >= 0)
     ?  (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
@@ -423,52 +496,60 @@ __CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c)
 
 #else  /* Use library functions.  */
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    getc (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    putc (int, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    getchar (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    putchar (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    getc (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    putc (int, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    getchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    putchar (int);
 
 #endif
 
-/*
- * Direct Input and Output Functions
+/* Direct Input and Output Functions
  */
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t fread (void *, size_t, size_t, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t fwrite (const void *, size_t, size_t, FILE *);
 
-_CRTIMP size_t __cdecl __MINGW_NOTHROW fread (void*, size_t, size_t, FILE*);
-_CRTIMP size_t __cdecl __MINGW_NOTHROW fwrite (const void*, size_t, size_t, FILE*);
-
-/*
- * File Positioning Functions
+/* File Positioning Functions
  */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fseek (FILE *, long, int);
+_CRTIMP __cdecl __MINGW_NOTHROW  long   ftell (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  void   rewind (FILE *);
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    fseek (FILE*, long, int);
-_CRTIMP long __cdecl __MINGW_NOTHROW   ftell (FILE*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   rewind (FILE*);
+#if _WIN32_WINNT >= _WIN32_WINNT_VISTA || __MSVCRT_VERSION__ >= __MSVCR80_DLL
+ /*
+  * Microsoft introduced a number of variations on fseek() and ftell(),
+  * beginning with MSVCR80.DLL; the bare _fseeki64() and _ftelli64() were
+  * subsequently integrated into MSVCRT.DLL, from Vista onward...
+  */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fseeki64 (FILE *, __int64, int);
+_CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64 (FILE *);
 
-#if __MSVCRT_VERSION__ >= 0x800
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fseek_nolock (FILE*, long, int);
-_CRTIMP long __cdecl __MINGW_NOTHROW   _ftell_nolock (FILE*);
+#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
+ /*
+  * ...while the "nolock" variants remain exclusive to MSVCR80.DLL, and
+  * its later MSVC specific derivatives.
+  */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fseek_nolock (FILE *, long, int);
+_CRTIMP __cdecl __MINGW_NOTHROW  long   _ftell_nolock (FILE *);
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fseeki64 (FILE*, __int64, int);
-_CRTIMP __int64 __cdecl __MINGW_NOTHROW        _ftelli64 (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fseeki64_nolock (FILE*, __int64, int);
-_CRTIMP __int64 __cdecl __MINGW_NOTHROW        _ftelli64_nolock (FILE*);
-#endif
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fseeki64_nolock (FILE *, __int64, int);
+_CRTIMP __cdecl __MINGW_NOTHROW __int64 _ftelli64_nolock (FILE *);
 
-#ifdef __USE_MINGW_FSEEK  /* These are in libmingwex.a */
-/*
- * Workaround for limitations on win9x where a file contents are
- * not zero'd out if you seek past the end and then write.
+#endif  /* MSVCR80.DLL and later derivatives ONLY */
+#endif  /* MSVCR80.DLL and later or MSVCRT.DLL since Vista */
+
+#ifdef __USE_MINGW_FSEEK
+/* Workaround for a limitation on Win9x where a file is not zero padded
+ * on write, following a seek beyond the original end of file; these are
+ * implemented in libmingwex.a
  */
+__cdecl __MINGW_NOTHROW  int    __mingw_fseek (FILE *, long, int);
+__cdecl __MINGW_NOTHROW  size_t __mingw_fwrite (const void *, size_t, size_t, FILE *);
 
-int __cdecl __MINGW_NOTHROW __mingw_fseek (FILE *, long, int);
-size_t __cdecl __MINGW_NOTHROW __mingw_fwrite (const void*, size_t, size_t, FILE*);
-#define fseek(fp, offset, whence)  __mingw_fseek(fp, offset, whence)
 #define fwrite(buffer, size, count, fp)  __mingw_fwrite(buffer, size, count, fp)
+#define fseek(fp, offset, whence)        __mingw_fseek(fp, offset, whence)
 #endif /* __USE_MINGW_FSEEK */
 
-/*
- * An opaque data type used for storing file positions... The contents of
+/* An opaque data type used for storing file positions... The contents of
  * this type are unknown, but we (the compiler) need to know the size
  * because the programmer using fgetpos and fsetpos will be setting aside
  * storage for fpos_t structres. Actually I tested using a byte array and
@@ -477,60 +558,55 @@ size_t __cdecl __MINGW_NOTHROW __mingw_fwrite (const void*, size_t, size_t, FILE
  * MSVCRT however, and for now `long long' will do.
  */
 #ifdef __MSVCRT__
-typedef long long fpos_t;
+typedef long long  fpos_t;
 #else
-typedef long   fpos_t;
+typedef long       fpos_t;
 #endif
 
-_CRTIMP int __cdecl __MINGW_NOTHROW    fgetpos (FILE*, fpos_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fsetpos (FILE*, const fpos_t*);
+_CRTIMP __cdecl __MINGW_NOTHROW  int fgetpos (FILE *, fpos_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int fsetpos (FILE *, const fpos_t *);
 
-/*
- * Error Functions
+/* Error Functions
  */
-
-_CRTIMP int __cdecl __MINGW_NOTHROW    feof (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    ferror (FILE*);
+_CRTIMP __cdecl __MINGW_NOTHROW  int feof (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int ferror (FILE *);
 
 #ifdef __cplusplus
-inline int __cdecl __MINGW_NOTHROW feof (FILE* __F)
-  { return __F->_flag & _IOEOF; }
-inline int __cdecl __MINGW_NOTHROW ferror (FILE* __F)
-  { return __F->_flag & _IOERR; }
+inline __cdecl __MINGW_NOTHROW  int feof (FILE * __F){ return __F->_flag & _IOEOF; }
+inline __cdecl __MINGW_NOTHROW  int ferror (FILE * __F){ return __F->_flag & _IOERR; }
 #else
 #define feof(__F)     ((__F)->_flag & _IOEOF)
 #define ferror(__F)   ((__F)->_flag & _IOERR)
 #endif
 
-_CRTIMP void __cdecl __MINGW_NOTHROW   clearerr (FILE*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   perror (const char*);
+_CRTIMP __cdecl __MINGW_NOTHROW  void clearerr (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  void perror (const char *);
 
 
 #ifndef __STRICT_ANSI__
 /*
  * Pipes
  */
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _popen (const char*, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _pclose (FILE*);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * _popen (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _pclose (FILE *);
 
 #ifndef NO_OLDNAMES
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  popen (const char*, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    pclose (FILE*);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE *  popen (const char *, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     pclose (FILE *);
 #endif
 
-/*
- * Other Non ANSI functions
- */
-_CRTIMP int __cdecl __MINGW_NOTHROW    _flushall (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fgetchar (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fputchar (int);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _fdopen (int, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fileno (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _fcloseall (void);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _fsopen (const char*, const char*, int);
+/* Other Non ANSI functions
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _flushall (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fgetchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fputchar (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * _fdopen (int, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fileno (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _fcloseall (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * _fsopen (const char *, const char *, int);
 #ifdef __MSVCRT__
-_CRTIMP int __cdecl __MINGW_NOTHROW    _getmaxstdio (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _setmaxstdio (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _getmaxstdio (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _setmaxstdio (int);
 #endif
 
 /* Microsoft introduced a capability in MSVCR80.DLL and later, to
@@ -566,16 +642,15 @@ unsigned int __cdecl __mingw_set_output_format (unsigned int);
 int __cdecl __mingw_get_printf_count_output (void);
 int __cdecl __mingw_set_printf_count_output (int);
 
-#if __MSVCRT_VERSION__ >= 0x800
-/*
- * When the user declares that MSVCR80.DLL features are supported,
+#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
+/* When the user declares that MSVCR80.DLL features are supported,
  * we simply expose the corresponding APIs...
  */
 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void);
 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int);
 
-_CRTIMP int __cdecl __MINGW_NOTHROW _get_printf_count_output (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW _set_printf_count_output (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _get_printf_count_output (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _set_printf_count_output (int);
 
 #else
 /* ...otherwise, we emulate the APIs, in a DLL version agnostic
@@ -595,8 +670,7 @@ __CRT_ALIAS unsigned int __cdecl _set_output_format (unsigned int __style)
  * the state of "%n" formatting as DISABLED if they are not.
  */
 #if __USE_MINGW_ANSI_STDIO
-/*
- * Note that __USE_MINGW_ANSI_STDIO is not guaranteed to resolve to any
+/* Note that __USE_MINGW_ANSI_STDIO is not guaranteed to resolve to any
  * symbol which will represent a compilable logic state; map it to this
  * alternative which will, for the true state...
  */
@@ -615,11 +689,11 @@ __CRT_ALIAS int __cdecl _set_printf_count_output (int __mode)
 #endif
 
 #ifndef _NO_OLDNAMES
-_CRTIMP int __cdecl __MINGW_NOTHROW    fgetchar (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fputchar (int);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  fdopen (int, const char*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fileno (FILE*);
-#endif /* Not _NO_OLDNAMES */
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fgetchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fputchar (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * fdopen (int, const char *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    fileno (FILE *);
+#endif /* !_NO_OLDNAMES */
 
 #define _fileno(__F) ((__F)->_file)
 #ifndef _NO_OLDNAMES
@@ -627,12 +701,11 @@ _CRTIMP int __cdecl __MINGW_NOTHROW       fileno (FILE*);
 #endif
 
 #if defined (__MSVCRT__) && ! defined (__NO_MINGW_LFS)
-#include <sys/types.h>
 __CRT_INLINE __JMPSTUB__(( FUNCTION = fopen64, REMAPPED = fopen ))
-FILE* __cdecl __MINGW_NOTHROW fopen64 (const char* filename, const char* mode)
+FILE * __cdecl __MINGW_NOTHROW  fopen64 (const char * filename, const char * mode)
 { return fopen (filename, mode); }
 
-int __cdecl __MINGW_NOTHROW fseeko64 (FILE*, __off64_t, int);
+int __cdecl __MINGW_NOTHROW  fseeko64 (FILE *, __off64_t, int);
 
 #ifdef __USE_MINGW_FSEEK
 int __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, __off64_t, int);
@@ -643,96 +716,107 @@ __CRT_INLINE __LIBIMPL__(( FUNCTION = ftello64 ))
 __off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream)
 { fpos_t __pos; return (fgetpos(stream, &__pos)) ? -1LL : (__off64_t)(__pos); }
 
-#endif /* __MSVCRT__ && !__NO_MINGW_LFS */
+#endif /* __MSVCRT__ && !__NO_MINGW_LFS */
 #endif /* !__STRICT_ANSI__ */
+#endif /* _STDIO_H */
+
+#if ! (defined _STDIO_H && defined _WCHAR_H)
+/* The following are declared when including either <stdio.h> or <wchar.h>.
+ * If both header include guards are now in place, then we must currently be
+ * including <stdio.h> in its own right, having already processed this block
+ * during prior partial inclusion by <wchar.h>; there is no need to process
+ * it a second time.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  int     fwprintf (FILE *, const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     wprintf (const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     vfwprintf (FILE *, const wchar_t *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     vwprintf (const wchar_t *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _snwprintf (wchar_t *, size_t, const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _vscwprintf (const wchar_t *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     fwscanf (FILE *, const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     wscanf (const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     swscanf (const wchar_t *, const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t  fgetwc (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t  fputwc (wchar_t, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t  ungetwc (wchar_t, FILE *);
 
-/* Wide  versions */
-#ifndef _WSTDIO_DEFINED
-/*  also in wchar.h - keep in sync */
-_CRTIMP int __cdecl __MINGW_NOTHROW    fwprintf (FILE*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    wprintf (const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vfwprintf (FILE*, const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vwprintf (const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _vscwprintf (const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fwscanf (FILE*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    wscanf (const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    swscanf (const wchar_t*, const wchar_t*, ...);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fgetwc (FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fputwc (wchar_t, FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW ungetwc (wchar_t, FILE*);
-
-/* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf).  */
 #ifndef __STRICT_ANSI__
-_CRTIMP int __cdecl __MINGW_NOTHROW    swprintf (wchar_t*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vswprintf (wchar_t*, const wchar_t*, __VALIST);
+/* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf).
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  int  swprintf (wchar_t *, const wchar_t *, ...);
+_CRTIMP __cdecl __MINGW_NOTHROW  int  vswprintf (wchar_t *, const wchar_t *, __VALIST);
 #endif
 
 #ifdef __MSVCRT__
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fputws (const wchar_t*, FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW getwc (FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW getwchar (void);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _putws (const wchar_t*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfdopen(int, const wchar_t *);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfopen (const wchar_t*, const wchar_t*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfreopen (const wchar_t*, const wchar_t*, FILE*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfsopen (const wchar_t*, const wchar_t*, int);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wrename (const wchar_t*, const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wremove (const wchar_t*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   _wperror (const wchar_t*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wpopen (const wchar_t*, const wchar_t*);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t * fgetws (wchar_t *, int, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int       fputws (const wchar_t *, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t    getwc (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t    getwchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t    putwc (wint_t, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t    putwchar (wint_t);
+
+#ifndef __STRICT_ANSI__
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t * _getws (wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int       _putws (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE    * _wfdopen(int, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE    * _wfopen (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE    * _wfreopen (const wchar_t *, const wchar_t *, FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE    * _wfsopen (const wchar_t *, const wchar_t *, int);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t * _wtmpnam (wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t * _wtempnam (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int       _wrename (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int       _wremove (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  void      _wperror (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE    * _wpopen (const wchar_t *, const wchar_t *);
+
+#endif  /* !__STRICT_ANSI__ */
 #endif /* __MSVCRT__ */
 
 #ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
-int __cdecl __MINGW_NOTHROW snwprintf (wchar_t* s, size_t n, const wchar_t*  format, ...);
-int __cdecl __MINGW_NOTHROW vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg);
+__cdecl __MINGW_NOTHROW  int  snwprintf (wchar_t *, size_t, const wchar_t *, ...);
+__cdecl __MINGW_NOTHROW  int  vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
+
 #ifndef __NO_INLINE__
-__CRT_INLINE int __cdecl __MINGW_NOTHROW
-vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
-  { return _vsnwprintf ( s, n, format, arg);}
-#endif
-int __cdecl __MINGW_NOTHROW vwscanf (const wchar_t * __restrict__, __VALIST);
-int __cdecl __MINGW_NOTHROW vfwscanf (FILE * __restrict__,
-                      const wchar_t * __restrict__, __VALIST);
-int __cdecl __MINGW_NOTHROW vswscanf (const wchar_t * __restrict__,
-                      const wchar_t * __restrict__, __VALIST);
+__CRT_INLINE __cdecl __MINGW_NOTHROW
+__JMPSTUB__(( FUNCTION = vsnwprintf, REMAPPED = _vsnwprintf ))
+int vsnwprintf (wchar_t *__s, size_t __n, const wchar_t *__fmt, __VALIST __arg)
+{ return _vsnwprintf ( __s, __n, __fmt, __arg); }
 #endif
 
-#define _WSTDIO_DEFINED
-#endif /* _WSTDIO_DEFINED */
+__cdecl __MINGW_NOTHROW  int  vwscanf (const wchar_t *__restrict__, __VALIST);
+__cdecl __MINGW_NOTHROW
+int  vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, __VALIST);
+__cdecl __MINGW_NOTHROW
+int  vswscanf (const wchar_t *__restrict__, const wchar_t * __restrict__, __VALIST);
 
-#ifndef __STRICT_ANSI__
-#ifdef __MSVCRT__
-#ifndef NO_OLDNAMES
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  wpopen (const wchar_t*, const wchar_t*);
-#endif /* not NO_OLDNAMES */
-#endif /* MSVCRT runtime */
+#endif  /* !__NO__ISOCEXT */
+#endif  /* ! (_STDIO_H && _WCHAR_H) */
 
-/*
- * Other Non ANSI wide functions
+#if defined _STDIO_H && ! defined __STRICT_ANSI__
+#if defined __MSVCRT__ && ! defined _NO_OLDNAMES
+_CRTIMP __cdecl __MINGW_NOTHROW  FILE * wpopen (const wchar_t *, const wchar_t *);
+#endif
+
+/* Other non-ANSI wide character functions...
  */
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW _fgetwchar (void);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW _fputwchar (wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _getw (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _putw (int, FILE*);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t _fgetwchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t _fputwchar (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _getw (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int    _putw (int, FILE *);
 
 #ifndef _NO_OLDNAMES
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fgetwchar (void);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fputwchar (wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW    getw (FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    putw (int, FILE*);
-#endif /* Not _NO_OLDNAMES */
+/* ...and their original names, before Microsoft uglification...
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t  fgetwchar (void);
+_CRTIMP __cdecl __MINGW_NOTHROW  wint_t  fputwchar (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     getw (FILE *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int     putw (int, FILE *);
 
-#endif /* __STRICT_ANSI */
+#endif  /* !_NO_OLDNAMES */
+#endif  /* !__STRICT_ANSI__ */
 
 _END_C_DECLS
 
-#endif /* Not RC_INVOKED */
-#endif /* _STDIO_H_ */
+#endif /* ! RC_INVOKED */
+#endif  /* !_STDIO_H: $RCSfile$: end of file */
index 3ab0830..83db1e8 100644 (file)
@@ -7,7 +7,7 @@
  * $Id$
  *
  * Written by Rob Savoye <rob@cygnus.com>
- * Copyright (C) 1997, 1999-2009, 2011, 2015, MinGW.org Project.
+ * Copyright (C) 1997, 1999-2009, 2011, 2015, 2016, MinGW.org Project.
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
 #define _WCHAR_H
 #pragma GCC system_header
 
-/* All the headers include this file. */
-#include <_mingw.h>
-
-/* MSDN says that isw* char classifications are in wchar.h and wctype.h.
- * Although the wctype names are ANSI, their exposure in this header is
- * not; nevertheless, we replicate them here, for MSDN conformity.
+/* All the headers include this file.
  */
-#include <wctype.h>
+#include <_mingw.h>
 
 #ifndef __STRICT_ANSI__
-/* This is also necessary, to support the non-ANSI wchar.h declarations
- * which MSDN identifies as being provided here.
- */
+ /* MSDN says that isw* char classifications are in wchar.h and wctype.h.
+  * Although the wctype names are ANSI, their exposure in this header is
+  * not; nevertheless, we replicate them here, for MSDN conformity.
+  */
+# include <wctype.h>
+
+ /* This is also necessary, to support the non-ANSI wchar.h declarations
+  * which MSDN identifies as being provided here.
+  */
 # include <sys/types.h>
-#endif /* __STRICT_ANSI__ */
+#endif /* !__STRICT_ANSI__ */
 
 #define WCHAR_MIN      0
 #define WCHAR_MAX      0xffff
 # define WEOF          (wchar_t)(0xffff)
 
 #ifndef RC_INVOKED
-
-#define __need_size_t
-#define __need_wint_t
-#define __need_wchar_t
-#define __need_NULL
-#include <stddef.h>
-
-#ifndef __VALIST
-# if defined __GNUC__ && __GNUC__ >= 3
-#  define __need___va_list
-#  include <stdarg.h>
-#  define __VALIST __builtin_va_list
-# else
-#  define __VALIST char*
-# endif
-#endif
-
+#define __WCHAR_H_SOURCED__
+/* ISO-C, POSIX, and Microsoft specify an overlap of content between
+ * <wchar.h> and other system header files; by inclusion of such other
+ * headers within this "__WCHAR_H_SOURCED__" scope, we may selectively
+ * retrieve the overlapping content, without requiring duplication of
+ * that content here; thus, from...
+ */
+#include <stdio.h>
+/* ...we obtain (possibly indirect) definitions and declarations for:
+ *
+ *  macros  NULL, FILENAME_MAX
+ *  types   size_t, wchar_t, wint_t, va_list (a.k.a. __VALIST), FILE
+ *  types   ssize_t, off_t, __off64_t, (conditionally, as needed)
+ *
+ *  int     fwprintf (FILE *, const wchar_t *, ...);
+ *  int     wprintf (const wchar_t *, ...);
+ *  int     vfwprintf (FILE *, const wchar_t *, __VALIST);
+ *  int     vwprintf (const wchar_t *, __VALIST);
+ *  int     snwprintf (wchar_t *, size_t, const wchar_t *, ...);
+ *  int    _snwprintf (wchar_t *, size_t, const wchar_t *, ...);
+ *  int    _vscwprintf (const wchar_t *, __VALIST);
+ *  int    _vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
+ *  int     vsnwprintf (wchar_t *, size_t, const wchar_t *, __VALIST);
+ *  int     fwscanf (FILE *, const wchar_t *, ...);
+ *  int     wscanf (const wchar_t *, ...);
+ *  int     swscanf (const wchar_t *, const wchar_t *, ...);
+ *  int     vwscanf (const wchar_t *, __VALIST);
+ *  int     vfwscanf (FILE *, const wchar_t *, __VALIST);
+ *  int     vswscanf (const wchar_t *, const wchar_t *, __VALIST);
+ *  wint_t  fgetwc (FILE *);
+ *  wint_t  fputwc (wchar_t, FILE *);
+ *  wint_t  ungetwc (wchar_t, FILE *);
+ *
+ *  The following pair of Microsoft functions conflict with their
+ *  corresponding ISO-C prototypes; consequently they will not be
+ *  declared when "__STRICT_ANSI__" checking is in effect:
+ *
+ *  int  swprintf (wchar_t *, const wchar_t *, ...);
+ *  int  vswprintf (wchar_t *, const wchar_t *, __VALIST);
+ *
+ *  The following group of functions is specified by ISO-C, but
+ *  their Microsoft implementations are available only if use of
+ *  "__MSVCRT__" is specified:
+ *
+ *  wchar_t * fgetws (wchar_t *, int, FILE *);
+ *  int       fputws (const wchar_t *, FILE *);
+ *  wint_t    getwc (FILE *);
+ *  wint_t    getwchar (void);
+ *  wint_t    putwc (wint_t, FILE *);
+ *  wint_t    putwchar (wint_t);
+ *
+ *  The following group of functions is also dependent on use of
+ *  "__MSVCRT__"; however, these are Microsoft specific, so their
+ *  are not declared if "__STRICT_ANSI__" checking is specified:
+ *
+ *  wchar_t * _getws (wchar_t *);
+ *  int       _putws (const wchar_t *);
+ *  FILE    * _wfdopen(int, const wchar_t *);
+ *  FILE    * _wfopen (const wchar_t *, const wchar_t *);
+ *  FILE    * _wfreopen (const wchar_t *, const wchar_t *, FILE *);
+ *  FILE    * _wfsopen (const wchar_t *, const wchar_t *, int);
+ *  wchar_t * _wtmpnam (wchar_t *);
+ *  wchar_t * _wtempnam (const wchar_t *, const wchar_t *);
+ *  int       _wrename (const wchar_t *, const wchar_t *);
+ *  int       _wremove (const wchar_t *);
+ *  void      _wperror (const wchar_t *);
+ *  FILE    * _wpopen (const wchar_t *, const wchar_t *);
+ *
+ */
 _BEGIN_C_DECLS
 
-#ifndef _FILE_DEFINED  /* Also in stdio.h */
-#define        _FILE_DEFINED
-typedef struct _iobuf
-{
-       char*   _ptr;
-       int     _cnt;
-       char*   _base;
-       int     _flag;
-       int     _file;
-       int     _charbuf;
-       int     _bufsiz;
-       char*   _tmpfname;
-} FILE;
-#endif /* Not _FILE_DEFINED */
-
-#define __need_time_t
-#define _FAKE_TIME_H_SOURCED 1
-#include <parts/time.h>
-
-#ifndef _TM_DEFINED /* Also in time.h */
-struct tm {
-        int tm_sec;     /* seconds after the minute - [0,59] */
-        int tm_min;     /* minutes after the hour - [0,59] */
-        int tm_hour;    /* hours since midnight - [0,23] */
-        int tm_mday;    /* day of the month - [1,31] */
-        int tm_mon;     /* months since January - [0,11] */
-        int tm_year;    /* years since 1900 */
-        int tm_wday;    /* days since Sunday - [0,6] */
-        int tm_yday;    /* days since January 1 - [0,365] */
-        int tm_isdst;   /* daylight savings time flag */
-        };
-#define _TM_DEFINED
-#endif
-
-#ifndef _WSTDIO_DEFINED
-/*  Also in stdio.h - keep in sync */
-_CRTIMP int __cdecl __MINGW_NOTHROW    fwprintf (FILE*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    wprintf (const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vfwprintf (FILE*, const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vwprintf (const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fwscanf (FILE*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    wscanf (const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    swscanf (const wchar_t*, const wchar_t*, ...);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fgetwc (FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW fputwc (wchar_t, FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW ungetwc (wchar_t, FILE*);
-
-/* These differ from the ISO C prototypes, which have a maxlen parameter like snprintf.  */
-#ifndef __STRICT_ANSI__
-_CRTIMP int __cdecl __MINGW_NOTHROW    swprintf (wchar_t*, const wchar_t*, ...);
-_CRTIMP int __cdecl __MINGW_NOTHROW    vswprintf (wchar_t*, const wchar_t*, __VALIST);
-#endif
-
-#ifdef __MSVCRT__
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    fputws (const wchar_t*, FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW getwc (FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW getwchar (void);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t);
-#ifndef __STRICT_ANSI__
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _putws (const wchar_t*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfdopen(int, const wchar_t *);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfopen (const wchar_t*, const wchar_t*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfreopen (const wchar_t*, const wchar_t*, FILE*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wfsopen (const wchar_t*, const wchar_t*, int);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wrename (const wchar_t*, const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wremove (const wchar_t*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   _wperror (const wchar_t*);
-_CRTIMP FILE* __cdecl __MINGW_NOTHROW  _wpopen (const wchar_t*, const wchar_t*);
-#endif  /* __STRICT_ANSI__ */
-#endif /* __MSVCRT__ */
-
-#ifndef __NO_ISOCEXT  /* externs in libmingwex.a */
-int __cdecl __MINGW_NOTHROW snwprintf (wchar_t*, size_t, const wchar_t*, ...);
-int __cdecl __MINGW_NOTHROW vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
-#ifndef __NO_INLINE__
-__CRT_INLINE int __cdecl __MINGW_NOTHROW
-vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
-  { return _vsnwprintf ( s, n, format, arg);}
-#endif
-int __cdecl __MINGW_NOTHROW vwscanf (const wchar_t * __restrict__, __VALIST);
-int __cdecl __MINGW_NOTHROW vfwscanf (FILE * __restrict__,
-                      const wchar_t * __restrict__, __VALIST);
-int __cdecl __MINGW_NOTHROW vswscanf (const wchar_t * __restrict__,
-                      const wchar_t * __restrict__, __VALIST);
-#endif
-
-#define _WSTDIO_DEFINED
-#endif /* _WSTDIO_DEFINED */
-
-#ifndef _WSTDLIB_DEFINED /* also declared in stdlib.h */
+#ifndef _WSTDLIB_DEFINED
+/* Also declared in stdlib.h; FIXME: should be factored out.
+ */
 _CRTIMP long __cdecl __MINGW_NOTHROW   wcstol (const wchar_t*, wchar_t**, int);
 _CRTIMP unsigned long __cdecl __MINGW_NOTHROW wcstoul (const wchar_t*, wchar_t**, int);
 _CRTIMP double __cdecl __MINGW_NOTHROW wcstod (const wchar_t*, wchar_t**);
@@ -192,9 +151,9 @@ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wfullpath (wchar_t*, const wchar_t*, s
 #endif /* _WSTDLIB_DEFINED */
 
 #ifndef _WTIME_DEFINED
-#ifndef __STRICT_ANSI__
-#ifdef __MSVCRT__
-/* wide function prototypes, also declared in time.h */
+#if defined __MSVCRT__ && ! defined __STRICT_ANSI__
+/* Wide function prototypes, also declared in time.h; FIXME: factor out.
+ */
 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wasctime (const struct tm*);
 #if __MSVCRT_VERSION__ < 0x0800
 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wctime (const time_t*);
@@ -213,8 +172,7 @@ _CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW  _wctime (const time_t* _v)      { return(_
 #endif
 #endif
 
-#endif /* __MSVCRT__ */
-#endif /* __STRICT_ANSI__ */
+#endif /* __MSVCRT__ && ! __STRICT_ANSI__ */
 _CRTIMP size_t __cdecl __MINGW_NOTHROW wcsftime (wchar_t*, size_t, const wchar_t*, const struct tm*);
 #define _WTIME_DEFINED
 #endif /* _WTIME_DEFINED */
@@ -312,7 +270,6 @@ struct __wfinddata64_t {
 };
 #endif
 #if __MSVCRT_VERSION__ >= 0x0800
-#include <stdio.h>
 struct __wfinddata32_t {
        unsigned        attrib;
        __time32_t      time_create;
@@ -558,7 +515,9 @@ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wsetlocale (int, const wchar_t*);
 #define _WLOCALE_DEFINED
 #endif
 
-#ifndef _WPROCESS_DEFINED  /* also declared in process.h */
+#ifndef _WPROCESS_DEFINED
+/* Also declared in process.h; FIXME: to be factored out.
+ */
 #include <stdint.h>  /* For intptr_t.  */
 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wexecl       (const wchar_t*, const wchar_t*, ...);
 _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wexecle      (const wchar_t*, const wchar_t*, ...);
@@ -584,5 +543,6 @@ _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wspawnvpe (int, const wchar_t*, const
 
 _END_C_DECLS
 
+#undef __WCHAR_H_SOURCED__
 #endif /* ! RC_INVOKED */
 #endif /* ! _WCHAR_H */
index 2c80c5e..8b29f47 100644 (file)
@@ -1,26 +1,33 @@
-/* pseudo-reloc.c
-
-   Contributed by Egor Duda  <deo@logos-m.ru>
-   Modified by addition of runtime_pseudo_reloc version 2
-   by Kai Tietz  <kai.tietz@onevision.com>
-
-   THIS SOFTWARE IS NOT COPYRIGHTED
-
-   This source code is offered for use in the public domain. You may
-   use, modify or distribute it freely.
-
-   This code is distributed in the hope that it will be useful but
-   WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
-   DISCLAMED. This includes but is not limited to warrenties of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-*/
-
-#include <windows.h>
+/*
+ * pseudo-reloc.c
+ *
+ * Contributed by Egor Duda  <deo@logos-m.ru>
+ * Modified by addition of runtime_pseudo_reloc version 2
+ * by Kai Tietz  <kai.tietz@onevision.com>
+ *
+ * THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ * This source code is offered for use in the public domain. You may
+ * use, modify or distribute it freely.
+ *
+ * This code is distributed in the hope that it will be useful but
+ * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
+ * DISCLAMED. This includes but is not limited to warrenties of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
 #include <stdio.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <memory.h>
 
+/* We need some of the MS-Windows data types and structures;
+ * define them, but with minimal namespace pollution.
+ */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
 #if defined(__CYGWIN__)
 #include <wchar.h>
 #include <ntdef.h>
@@ -312,16 +319,16 @@ do_pseudo_reloc (void * start, void * end, void * base)
            break;
          case 32:
            reldata = (ptrdiff_t) (*((unsigned int *)reloc_target));
-#ifdef _WIN64
-           if ((reldata & 0x80000000) != 0)
-             reldata |= ~((ptrdiff_t) 0xffffffff);
-#endif
+#          ifdef _WIN64
+             if ((reldata & 0x80000000) != 0)
+               reldata |= ~((ptrdiff_t) 0xffffffff);
+#          endif
            break;
-#ifdef _WIN64
+#        ifdef _WIN64
          case 64:
            reldata = (ptrdiff_t) (*((unsigned long long *)reloc_target));
            break;
-#endif
+#        endif
          default:
            reldata=0;
            __report_error ("  Unknown pseudo relocation bit size %d.\n",
@@ -336,20 +343,20 @@ do_pseudo_reloc (void * start, void * end, void * base)
       /* Write the new relocation value back to *reloc_target */
       switch ((r->flags & 0xff))
        {
-         case 8:
-           __write_memory ((void *) reloc_target, &reldata, 1);
-          break;
-        case 16:
-           __write_memory ((void *) reloc_target, &reldata, 2);
-          break;
-        case 32:
-           __write_memory ((void *) reloc_target, &reldata, 4);
-          break;
-#ifdef _WIN64
-        case 64:
-           __write_memory ((void *) reloc_target, &reldata, 8);
-          break;
-#endif
+         case 8:
+           __write_memory ((void *) reloc_target, &reldata, 1);
+           break;
+         case 16:
+           __write_memory ((void *) reloc_target, &reldata, 2);
+           break;
+         case 32:
+           __write_memory ((void *) reloc_target, &reldata, 4);
+           break;
+#        ifdef _WIN64
+         case 64:
+           __write_memory ((void *) reloc_target, &reldata, 8);
+           break;
+#        endif
        }
      }
 }