OSDN Git Service

Factor out <locale.h> vs. <wchar.h> duplicate declarations.
[mingw/mingw-org-wsl.git] / mingwrt / include / wchar.h
index 3ab0830..0828853 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
  *
  */
 #ifndef _WCHAR_H
-#define _WCHAR_H
 #pragma GCC system_header
 
-/* All the headers include this file. */
-#include <_mingw.h>
+/* This header declares prototypes for wchar_t string functions, as are
+ * prescribed by ISO-C, but which MSVC also expects, (in contravention of
+ * ISO-C prescriptions), to find in <string.h>.  To accommodate this MSVC
+ * anomaly, we make provision for <string.h> to include a selected subset
+ * of <wchar.h>; thus, we do not immediately define _WCHAR_T...
+ */
+#ifndef __STRING_H_SOURCED__
+/* ...but defer it until we have confirmed that this is NOT inclusion for
+ * only this subset of <wchar.h> declarations.
+ */
+#define _WCHAR_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 MinGW headers are required to include <_mingw.h>; in the case of
+ * selective inclusion by <string.h>, we expect it to have already done
+ * so, but since that doesn't apply here, we must do it ourselves.
  */
-#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 appear in both <wchar.h>,
+  * and in <wctype.h>.  Although these <wctype.h> classifications are as
+  * prescribed by ISO-C, their exposure in <wchar.h> is not; nonetheless,
+  * 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)
+#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 they
+ * 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 *);
+ *
+ *
+ * In similar fashion, from...
+ */
+#include <stdlib.h>
+/* ...we obtain prototypes for universally supported functions:
+ *
+ *  long wcstol (const wchar_t *, wchar_t **, int);
+ *  unsigned long wcstoul (const wchar_t *, wchar_t **, int);
+ *  double wcstod (const wchar_t *, wchar_t **);
+ *
+ * The following are Microsoft specific, and require MSCVRT.DLL,
+ * or any of its non-free derivatives; they are not available to
+ * applications which use CRTDLL.DLL:
+ *
+ *  wchar_t *_wgetenv (const wchar_t *);
+ *  int _wputenv (const wchar_t *);
+ *  void _wsearchenv (const wchar_t *, const wchar_t *, wchar_t *);
+ *  int _wsystem (const wchar_t *);
+ *  void _wmakepath (wchar_t *, const wchar_t *, const wchar_t *,
+ *          const wchar_t *, const wchar_t *
+ *        );
+ *  void _wsplitpath (const wchar_t *, wchar_t *, wchar_t *,
+ *          wchar_t *, wchar_t *
+ *        );
+ *  wchar_t *_wfullpath (wchar_t *, const wchar_t *, size_t);
+ *
+ * ...while this pair are ISO-C99 standards, which are available
+ * in libmingwex.a, but not in any version of MSVCRT.DLL, (nor in
+ * any of its non-free derivatives prior to MSVCR120.DLL), nor in
+ * CRTDLL.DLL:
+ *
+ *  float wcstof (const wchar_t *restrict, wchar_t **restrict);
+ *  long double wcstold (const wchar_t *restrict, wchar_t **restrict);
+ *
+ *
+ * Again, in similar fashion, from...
+ */
+#include <time.h>
+/* ...we obtain an opaque forward declaration of:
+ *
+ *  struct tm
+ *
+ * ...and prototype declarations for the following ISO-C99 function,
+ * (which is always provided):
+ *
+ *  size_t wcsftime (wchar_t *, size_t, const wchar_t *, const struct tm *);
+ *
+ * ...together with the following non-ISO-C functions, (which are
+ * NOT exposed when "__STRICT_ANSI__" checking is enabled):
+ *
+ *  wchar_t *_wctime (const time_t *);
+ *  wchar_t *_wasctime (const struct tm *);
+ *  wchar_t *_wstrdate (wchar_t *);
+ *  wchar_t *_wstrtime (wchar_t *);
+ *
+ * Of the preceding group, we also note that, while it remains in
+ * all versions of MSVCRT.DLL, (using a strictly 32-bit data type
+ * to represent its "time_t" argument), the _wctime() function is
+ * NOT present in MSVCR80.DLL, and later versions of the non-free
+ * MSVC runtime libraries, in which it is replaced by either of:
+ *
+ *  wchar_t *_wctime64 (const __time64_t *);
+ *  wchar_t *_wctime32 (const __time32_t *);
+ *
+ * ...with the actual replacement being chosen at compile time, on
+ * the basis of the user specified "_USE_32BIT_TIME_T" feature test
+ * macro, (a Microsoft specific, brain damaged concept), which maps
+ * _wctime() itself, as an in-line alias for its corresponding
+ * replacement library function.
+ *
+ *
+ * Also, from...
+ */
+#include <locale.h>
+/* ...we obtain the declaration for:
+ *
+ *   wchar_t *_wsetlocale (int, 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
+/* Wide character string functions must be specified here, as required
+ * by the ISO-C Standard; however, MSVC contravenes this standard by also
+ * requiring them to appear in <string.h>.  We declare them here, where
+ * they rightfully belong, but we also arrange for them to be available
+ * for selective inclusion by <string.h>; to facilitate this, we must
+ * change the declarative condition...
+ */
+#endif /* ! RC_INVOKED */
+#endif /* !__STRING_H_SOURCED__ */
+#if ! (defined RC_INVOKED || (defined _WCHAR_H && defined _STRING_H))
+/* ...such that these declarations are exposed when either _WCHAR_H, or
+ * _STRING_H is defined, (but not both, since that would indicate that
+ * these declarations have already been processed).
+ *
+ *
+ * Wide character versions of the ISO-C standard string functions.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcscat (wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcschr (const wchar_t *, wchar_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcscmp (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcscoll (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcscpy (wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t wcscspn (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t wcslen (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsncat (wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcsncmp (const wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsncpy (wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcspbrk (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsrchr (const wchar_t *, wchar_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t wcsspn (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsstr (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcstok (wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  size_t wcsxfrm (wchar_t *, const wchar_t *, size_t);
 
-#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 */
-_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**);
-#if !defined __NO_ISOCEXT /* in libmingwex.a */
-float __cdecl __MINGW_NOTHROW wcstof (const wchar_t * __restrict__, wchar_t ** __restrict__);
-long double __cdecl __MINGW_NOTHROW wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__);
-#endif /* __NO_ISOCEXT */
-#ifdef __MSVCRT__
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wgetenv(const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wputenv(const wchar_t*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   _wsearchenv(const wchar_t*, const wchar_t*, wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW    _wsystem(const wchar_t*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   _wmakepath(wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*);
-_CRTIMP void __cdecl __MINGW_NOTHROW   _wsplitpath (const wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wfullpath (wchar_t*, const wchar_t*, size_t);
-#endif
-#define  _WSTDLIB_DEFINED
-#endif /* _WSTDLIB_DEFINED */
+/* UTF-16LE versions of non-ANSI string functions provided by CRTDLL.DLL
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcsdup (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _wcsicmp (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _wcsicoll (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcslwr (wchar_t*);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _wcsnicmp (const wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcsnset (wchar_t *, wchar_t, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcsrev (wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcsset (wchar_t *, wchar_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcsupr (wchar_t *);
 
-#ifndef _WTIME_DEFINED
-#ifndef __STRICT_ANSI__
 #ifdef __MSVCRT__
-/* wide function prototypes, also declared in time.h */
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wasctime (const struct tm*);
-#if __MSVCRT_VERSION__ < 0x0800
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wctime (const time_t*);
-#endif
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wstrdate (wchar_t*);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wstrtime (wchar_t*);
-#if __MSVCRT_VERSION__ >= 0x601
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wctime64 (const __time64_t*);
-#endif
-#if __MSVCRT_VERSION__ >= 0x0800
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW       _wctime32 (const __time32_t*);
-#ifndef _USE_32BIT_TIME_T
-_CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW     _wctime (const time_t* _v)      { return(_wctime64 (_v)); }
-#else
-_CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW     _wctime (const time_t* _v)      { return(_wctime32 (_v)); }
-#endif
-#endif
-
-#endif /* __MSVCRT__ */
-#endif /* __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 */
+_CRTIMP __cdecl __MINGW_NOTHROW  int _wcsncoll (const wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  int _wcsnicoll (const wchar_t *, const wchar_t *, size_t);
 
+/* A wide character counterpart to the strerror() API was introduced in
+ * MSVCR70.DLL, and subsequently back-ported to MSVCRT.DLL in WinXP.
+ */
+#if __MSVCRT_VERSION__ >= __MSVCR70_DLL || NTDDI_VERSION >= NTDDI_WINXP
+ /*
+  * These are are the wide character counterparts to the strerror()
+  * function itself, and the _strerror() function, respectively.
+  */
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wcserror (int);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *__wcserror (const wchar_t *);
+
+#endif /* MSVCR70.DLL || WinXP */
+#endif /* __MSVCRT__ */
 
-/* Wide character string functions must be specified here, as required
- * by the ISO-C Standard; however, MSVC contravenes this standard by also
- * requiring them to appear in <string.h>, so we specify them in a shared
- * <parts/wchar.h> header, which we may include both here and in <string.h>
+/* MSVCRT.DLL provides neither _wcscmpi() nor wcscmpi(); the heritage
+ * is uncertain, but for the convenience, (and portability), of legacy
+ * applications which assume wcscmpi() should be available:
  */
-#include <parts/wchar.h>
+#define _wcscmpi _wcsicmp
+int __cdecl __MINGW_NOTHROW  wcscmpi (const wchar_t *, const wchar_t *);
 
+#ifndef __NO_INLINE__
+__CRT_ALIAS __JMPSTUB__(( FUNCTION = wcscmpi, REMAPPED = _wcsicmp ))
+  int wcscmpi (const wchar_t *__ws1, const wchar_t *__ws2)
+  { return _wcsicmp (__ws1, __ws2); }
+#endif /* __NO_INLINE__ */
+
+#ifndef _NO_OLDNAMES
+/* Older CRTDLL.DLL versions may have provided these alternatively named
+ * functions; we continue to support them, via the OLDNAME libraries:
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsdup (const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcsicmp (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcsicoll (const wchar_t *, const wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcslwr (wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  int wcsnicmp (const wchar_t *, const wchar_t *, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsnset (wchar_t *, wchar_t, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsrev (wchar_t *);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsset (wchar_t *, wchar_t);
+_CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *wcsupr (wchar_t *);
+
+#endif /* !_NO_OLDNAMES */
+#endif /* !__STRICT_ANSI__ */
+
+/* This completes the set of declarations which are to be duplicated by
+ * inclusion of <string.h>; revert the declarative condition, to make it
+ * specific to <wchar.h> alone.
+ */
+#endif /* !(RC_INVOKED || (_WCHAR_H && _STRING_H)) */
+#if defined _WCHAR_H && ! defined RC_INVOKED
 
 /* These are resolved by -lmingwex. Alternatively, they can be resolved by
    adding -lmsvcp60 to your command line, which will give you the VC++
@@ -275,11 +369,12 @@ unsigned long long __cdecl __MINGW_NOTHROW wcstoull(const wchar_t * __restrict__
                            wchar_t ** __restrict__, int);
 #endif /* __NO_ISOCEXT */
 
-#ifndef        __STRICT_ANSI__
-/* non-ANSI wide char functions from io.h, direct.h, sys/stat.h and locale.h.  */
-
-#ifndef        _FSIZE_T_DEFINED
-typedef        unsigned long   _fsize_t;
+#ifndef __STRICT_ANSI__
+/* non-ANSI wide char functions from io.h, direct.h, sys/stat.h and locale.h
+ * FIXME: these should be factored out, to avoid duplication.
+ */
+#ifndef _FSIZE_T_DEFINED
+typedef unsigned long  _fsize_t;
 #define _FSIZE_T_DEFINED
 #endif
 
@@ -312,7 +407,6 @@ struct __wfinddata64_t {
 };
 #endif
 #if __MSVCRT_VERSION__ >= 0x0800
-#include <stdio.h>
 struct __wfinddata32_t {
        unsigned        attrib;
        __time32_t      time_create;
@@ -429,7 +523,7 @@ struct _stat
        time_t  st_ctime;       /* Creation time */
 };
 
-#ifndef        _NO_OLDNAMES
+#ifndef _NO_OLDNAMES
 /* NOTE: Must be the same as _stat above. */
 struct stat
 {
@@ -553,12 +647,9 @@ _CRTALIAS int __cdecl __MINGW_NOTHROW      _wstati64 (const wchar_t* _v1, struct _sta
 #define _WSTAT_DEFINED
 #endif /* ! _WSTAT_DEFIND  */
 
-#ifndef _WLOCALE_DEFINED  /* also declared in locale.h */
-_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*, ...);
@@ -580,9 +671,10 @@ _CRTIMP intptr_t __cdecl __MINGW_NOTHROW _wspawnvpe        (int, const wchar_t*, const
 
 #define _WPROCESS_DEFINED
 #endif
-#endif /* ! __STRICT_ANSI__ */
+#endif /* ! __STRICT_ANSI__ */
 
 _END_C_DECLS
 
-#endif /* ! RC_INVOKED */
-#endif /* ! _WCHAR_H */
+#undef __WCHAR_H_SOURCED__
+#endif /* _WCHAR_H && ! RC_INVOKED */
+#endif /* !_WCHAR_H: $RCSfile$: end of file */