POSIX struct stat has 4 variants in mingw-w64 based on the macros
_FILE_OFFSET_BITS and _USE_32BIT_TIME_T settings. st_size can be either
32-bit or 64-bit, and st_atime/st_mtime/st_ctime can also be 32-bit or
64-bit.

So for each ABI of struct stat there has to be separate POSIX stat function
which correctly fills either 32-bit or 64-bit st_* values.

To follow existing msvcrt/UCRT symbol naming convention, provide 4 symbols
for stat function: stat32, stat32i64, stat64i32 and stat64. And also
provide stat symbol as alias to stat32 on 32-bit systems or to stat64i32 on
64-bit systems. Same as existing msvcrt/UCRT ABI for _stat function.

Note that stat64 function is part of the Large File Specification but it
does not describe if the st_atime/st_mtime/st_ctime should be also 64-bit
or only 32-bit. msvcrt/UCRT ABI expects them to be also 64-bit.

Do same for wstat symbol, wide UTF-16 variant of stat.

At the same time remove old and broken stat and wstat symbols, they are
replaced by the new alias.

Extract existing and duplicated function _mingw_no_trailing_slash into new
file and rename it to __mingw_fix_stat_path which better describe its
purpose. Do same for wide variant __mingw_fix_wstat_path. These two
functions have some known bugs and will be fixed later.

This change is not fixing bugs in these functions, it is only fixing the
API/ABI incompatibility which comes from the _FILE_OFFSET_BITS and
_USE_32BIT_TIME_T settings.
---
 mingw-w64-crt/Makefile.am                     | 14 +++-
 mingw-w64-crt/def-include/crt-aliases.def.in  | 34 ++++++++-
 .../api-ms-win-crt-filesystem-l1-1-0.def.in   | 13 ++++
 .../{_stat.c => __mingw_fix_stat_path.c}      | 72 +++----------------
 .../{_wstat.c => __mingw_fix_wstat_path.c}    | 71 +++---------------
 mingw-w64-crt/stdio/stat32.c                  | 29 ++++++++
 mingw-w64-crt/stdio/stat32i64.c               | 21 ++++++
 mingw-w64-crt/stdio/stat64.c                  | 22 ++++++
 mingw-w64-crt/stdio/stat64i32.c               | 29 ++++++++
 mingw-w64-crt/stdio/wstat32.c                 | 30 ++++++++
 mingw-w64-crt/stdio/wstat32i64.c              | 21 ++++++
 mingw-w64-crt/stdio/wstat64.c                 | 21 ++++++
 mingw-w64-crt/stdio/wstat64i32.c              | 30 ++++++++
 13 files changed, 275 insertions(+), 132 deletions(-)
 rename mingw-w64-crt/stdio/{_stat.c => __mingw_fix_stat_path.c} (42%)
 rename mingw-w64-crt/stdio/{_wstat.c => __mingw_fix_wstat_path.c} (44%)
 create mode 100644 mingw-w64-crt/stdio/stat32.c
 create mode 100644 mingw-w64-crt/stdio/stat32i64.c
 create mode 100644 mingw-w64-crt/stdio/stat64.c
 create mode 100644 mingw-w64-crt/stdio/stat64i32.c
 create mode 100644 mingw-w64-crt/stdio/wstat32.c
 create mode 100644 mingw-w64-crt/stdio/wstat32i64.c
 create mode 100644 mingw-w64-crt/stdio/wstat64.c
 create mode 100644 mingw-w64-crt/stdio/wstat64i32.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 76c12f682857..e231aab20c21 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -186,6 +186,14 @@ src_msvcrt_common=\
   stdio/vsnwprintf_alias.c \
   stdio/vswprintf.c \
   stdio/vswprintf_alias.c \
+  stdio/stat32.c \
+  stdio/stat32i64.c \
+  stdio/stat64.c \
+  stdio/stat64i32.c \
+  stdio/wstat32.c \
+  stdio/wstat32i64.c \
+  stdio/wstat64.c \
+  stdio/wstat64i32.c \
   math/cbrt.c math/cbrtf.c \
   math/copysign.c math/copysignf.c \
   math/coshf.c \
@@ -1049,11 +1057,11 @@ src_libmingwex=\
   ssp/stpcpy_chk.c       ssp/strcpy_chk.c           ssp/strncat_chk.c       
ssp/strncpy_chk.c \
   \
   stdio/strtok_r.c \
-  stdio/_Exit.c            stdio/_findfirst64i32.c   stdio/_findnext64i32.c \
-  stdio/_stat.c            stdio/_wfindfirst64i32.c  stdio/_wfindnext64i32.c \
-  stdio/_wstat.c           stdio/asprintf.c \
+  stdio/_Exit.c            stdio/_findfirst64i32.c   stdio/_findnext64i32.c   
stdio/_wfindfirst64i32.c  stdio/_wfindnext64i32.c \
+  stdio/asprintf.c \
   stdio/fopen64.c          stdio/fseeko32.c          stdio/fseeko64.c          
                         stdio/ftello.c          \
   stdio/ftello64.c         stdio/ftruncate64.c       stdio/lltoa.c            
stdio/lltow.c             stdio/lseek64.c         \
+  stdio/__mingw_fix_stat_path.c stdio/__mingw_fix_wstat_path.c \
   \
   stdio/mingw_pformat.h    mingw_sformat.h           mingw_swformat.h \
   stdio/mingw_fprintf.c    stdio/mingw_fwprintf.c    stdio/mingw_fscanf.c     
stdio/mingw_fwscanf.c     stdio/mingw_pformat.c   \
diff --git a/mingw-w64-crt/def-include/crt-aliases.def.in 
b/mingw-w64-crt/def-include/crt-aliases.def.in
index 887535430183..6335237900f1 100644
--- a/mingw-w64-crt/def-include/crt-aliases.def.in
+++ b/mingw-w64-crt/def-include/crt-aliases.def.in
@@ -137,8 +137,11 @@ ADD_UNDERSCORE(spawnve)
 ADD_UNDERSCORE(spawnvp)
 ADD_UNDERSCORE(spawnvpe)
 #endif
-#ifndef CRTDLL
-; stat is provided by mingw to workaround trailing slash issue in _stat
+#ifdef UCRTBASE
+F32(stat == _stat32)
+F64(stat == _stat64i32)
+#else
+; stat for non-UCRT is provided by mingw to workaround trailing slash issue in 
_stat
 #endif
 #ifdef NO_STRCMPI_ALIAS
 ; Symbol _strcmpi is natively present and defined in the library def file
@@ -297,6 +300,21 @@ ADD_UNDERSCORE(popen)
 fgetpos64 == fgetpos
 fsetpos64 == fsetpos
 #endif
+#ifdef UCRTBASE
+stat32 == _stat32
+stat32i64 == _stat32i64
+stat64 == _stat64
+stat64i32 == _stat64i32
+#else
+; stat for non-UCRT is provided by mingw to workaround trailing slash issue in 
_stat
+#endif
+#ifdef FIXED_SIZE_SYMBOLS
+#if !defined(NO_I64_FIXED_SIZE) && !defined(NO_FIXED_SIZE_64_ALIAS)
+F64(fstat64 == _fstati64)
+#endif
+#else
+fstat64 == _fstat64
+#endif
 
 ; This is list of symbol aliases for GNU functions which are not part of POSIX 
or ISO C
 strcasecmp == _stricmp
@@ -557,6 +575,18 @@ __ms_wscanf == wscanf
 ; This is list of additional symbol aliases not available in any library as 
neither native symbols nor aliases
 ; FIXME: check if these really are needed
 
+; This is wstat and wstat64 symbol available only in mingw but for a long time
+#ifdef UCRTBASE
+F32(wstat == _wstat32)
+F64(wstat == _wstat64i32)
+wstat32 == _wstat32
+wstat32i64 == _wstat32i64
+wstat64 == _wstat64
+wstat64i32 == _wstat64i32
+#else
+; wstat for non-UCRT is provided by mingw to workaround trailing slash issue 
in _wstat
+#endif
+
 ; Origin of the symbol wcscmpi is unknown. This symbol is not present in
 ; crtdll.dll and neither in any msvcr* version. The only source of wcscmpi is
 ; wcstr.h header file from the Microsoft Visual C++ 1.0 (32-bit for NT) and
diff --git a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in 
b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in
index 684baf712dcf..a0665a3a3d31 100644
--- a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in
+++ b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in
@@ -39,6 +39,7 @@ F64(_fstati64 == _fstat64)
 _fstat32
 _fstat32i64
 _fstat64
+fstat64 == _fstat64
 _fstat64i32
 _fullpath
 _getdiskfree
@@ -53,14 +54,20 @@ _rmdir
 rmdir == _rmdir
 _splitpath
 _splitpath_s
+F32(stat == _stat32)
+F64(stat == _stat64i32)
 F32(_stat == _stat32)
 F64(_stat == _stat64i32)
 F32(_stati64 == _stat32i64)
 F64(_stati64 == _stat64)
 _stat32
+stat32 == _stat32
 _stat32i64
+stat32i64 == _stat32i64
 _stat64
+stat64 == _stat64
 _stat64i32
+stat64i32 == _stat64i32
 _umask
 umask == _umask
 _umask_s
@@ -96,14 +103,20 @@ _wrename
 _wrmdir
 _wsplitpath
 _wsplitpath_s
+F32(wstat == _wstat32)
+F64(wstat == _wstat64i32)
 F32(_wstat == _wstat32)
 F64(_wstat == _wstat64i32)
 F32(_wstati64 == _wstat32i64)
 F64(_wstati64 == _wstat64)
 _wstat32
+wstat32 == _wstat32
 _wstat32i64
+wstat32i64 == _wstat32i64
 _wstat64
+wstat64 == _wstat64
 _wstat64i32
+wstat64i32 == _wstat64i32
 _wunlink
 remove
 rename
diff --git a/mingw-w64-crt/stdio/_stat.c 
b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
similarity index 42%
rename from mingw-w64-crt/stdio/_stat.c
rename to mingw-w64-crt/stdio/__mingw_fix_stat_path.c
index cc39a90af4ea..564658473f02 100644
--- a/mingw-w64-crt/stdio/_stat.c
+++ b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
@@ -1,4 +1,9 @@
-#define __CRT__NO_INLINE
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
 #include <sys/stat.h>
 #include <stdlib.h>
 
@@ -12,8 +17,8 @@
  *   to free it.
  */
 
-static char*
-_mingw_no_trailing_slash (const char* _path)
+char* __mingw_fix_stat_path (const char* _path);
+char* __mingw_fix_stat_path (const char* _path)
 {
   int len;
   char *p;
@@ -57,64 +62,3 @@ _mingw_no_trailing_slash (const char* _path)
 
   return p;
 }
-/* FIXME: Relying on _USE_32BIT_TIME_T, which is a user-macro,
-during CRT compilation is plainly broken.  Need an appropriate
-implementation to provide users the ability of compiling the
-CRT only with 32-bit time_t behavior. */
-#if defined(_USE_32BIT_TIME_T)
-int __cdecl
-stat(const char *_Filename,struct stat *_Stat)
-{
-  struct _stat32 st;
-  char *_path = _mingw_no_trailing_slash(_Filename);
-
-  int ret=_stat32(_path,&st);
-
-  if (_path != _Filename)
-    free (_path);
-
-  if (ret == -1) {
-    *_Stat = (struct stat){0};
-    return -1;
-  }
-  /* struct stat and struct _stat32
-     are the same for this case. */
-  memcpy(_Stat, &st, sizeof(struct _stat32));
-  return ret;
-}
-#else
-int __cdecl
-stat(const char *_Filename,struct stat *_Stat)
-{
-  struct _stat64 st;
-  char *_path = _mingw_no_trailing_slash(_Filename);
-
-  int ret=_stat64(_path,&st);
-
-  if (_path != _Filename)
-    free (_path);
-
-  if (ret == -1) {
-    *_Stat = (struct stat){0};
-    return -1;
-  }
-  /* struct stat and struct _stat64i32
-     are the same for this case. */
-  _Stat->st_dev=st.st_dev;
-  _Stat->st_ino=st.st_ino;
-  _Stat->st_mode=st.st_mode;
-  _Stat->st_nlink=st.st_nlink;
-  _Stat->st_uid=st.st_uid;
-  _Stat->st_gid=st.st_gid;
-  _Stat->st_rdev=st.st_rdev;
-  _Stat->st_size=(_off_t) st.st_size;
-  _Stat->st_atime=st.st_atime;
-  _Stat->st_mtime=st.st_mtime;
-  _Stat->st_ctime=st.st_ctime;
-  return ret;
-}
-#endif
-
-/* Add __imp__fstat and __imp__stat symbols.  */
-int (*__MINGW_IMP_SYMBOL(stat))(const char *,struct stat *) = &stat;
-
diff --git a/mingw-w64-crt/stdio/_wstat.c 
b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
similarity index 44%
rename from mingw-w64-crt/stdio/_wstat.c
rename to mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
index fb6b1c69ec42..838e4aa30d39 100644
--- a/mingw-w64-crt/stdio/_wstat.c
+++ b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
@@ -1,7 +1,11 @@
-#define __CRT__NO_INLINE
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
 #include <sys/stat.h>
 #include <stdlib.h>
-#include <malloc.h>
 
 /**
  * Returns _path without trailing slash if any
@@ -13,8 +17,8 @@
  *   to free it.
  */
 
-static wchar_t*
-_mingw_no_trailing_slash (const wchar_t* _path)
+wchar_t* __mingw_fix_wstat_path (const wchar_t* _path);
+wchar_t* __mingw_fix_wstat_path (const wchar_t* _path)
 {
   int len;
   wchar_t *p;
@@ -58,62 +62,3 @@ _mingw_no_trailing_slash (const wchar_t* _path)
 
   return p;
 }
-
-/* FIXME: Relying on _USE_32BIT_TIME_T, which is a user-macro,
-during CRT compilation is plainly broken.  Need an appropriate
-implementation to provide users the ability of compiling the
-CRT only with 32-bit time_t behavior. */
-#if defined(_USE_32BIT_TIME_T)
-int __cdecl
-wstat(const wchar_t *_Filename,struct stat *_Stat)
-{
-  struct _stat32 st;
-  wchar_t *_path = _mingw_no_trailing_slash(_Filename);
-
-  int ret=_wstat32(_path,&st);
-
-  if (_path != _Filename)
-    free (_path);
-
-  if (ret == -1) {
-    *_Stat = (struct stat){0};
-    return -1;
-  }
-  /* struct stat and struct _stat32
-     are the same for this case. */
-  memcpy(_Stat, &st, sizeof(struct _stat32));
-  return ret;
-}
-#else
-int __cdecl
-wstat(const wchar_t *_Filename,struct stat *_Stat)
-{
-  struct _stat64 st;
-  wchar_t *_path = _mingw_no_trailing_slash(_Filename);
-
-  int ret=_wstat64(_path,&st);
-
-  if (_path != _Filename)
-    free (_path);
-
-  if (ret == -1) {
-    *_Stat = (struct stat){0};
-    return -1;
-  }
-  /* struct stat and struct _stat64i32
-     are the same for this case. */
-  _Stat->st_dev=st.st_dev;
-  _Stat->st_ino=st.st_ino;
-  _Stat->st_mode=st.st_mode;
-  _Stat->st_nlink=st.st_nlink;
-  _Stat->st_uid=st.st_uid;
-  _Stat->st_gid=st.st_gid;
-  _Stat->st_rdev=st.st_rdev;
-  _Stat->st_size=(_off_t) st.st_size;
-  _Stat->st_atime=st.st_atime;
-  _Stat->st_mtime=st.st_mtime;
-  _Stat->st_ctime=st.st_ctime;
-  return ret;
-}
-#endif
-
diff --git a/mingw-w64-crt/stdio/stat32.c b/mingw-w64-crt/stdio/stat32.c
new file mode 100644
index 000000000000..9623c80f5b35
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat32.c
@@ -0,0 +1,29 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+char *__mingw_fix_stat_path(const char *_path);
+
+int __cdecl stat32(const char *_Filename, struct _stat32 *_Stat);
+int __cdecl stat32(const char *_Filename, struct _stat32 *_Stat)
+{
+  char *_path = __mingw_fix_stat_path(_Filename);
+  int ret = _stat32(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(stat32))(const char *, struct _stat32 *) = 
stat32;
+
+/* On 32-bit systems is stat() function ABI compatible with stat32() function 
*/
+#ifndef _WIN64
+#undef stat
+struct stat;
+int __attribute__ ((alias ("stat32"))) __cdecl stat(const char *name, struct 
stat *stat);
+extern int __attribute__ ((alias 
(__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(stat32))))) (__cdecl 
*__MINGW_IMP_SYMBOL(stat))(const char *name, struct stat *stat);
+#endif
diff --git a/mingw-w64-crt/stdio/stat32i64.c b/mingw-w64-crt/stdio/stat32i64.c
new file mode 100644
index 000000000000..3291ef6b8a01
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat32i64.c
@@ -0,0 +1,21 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+char *__mingw_fix_stat_path(const char *_path);
+
+int __cdecl stat32i64(const char *_Filename, struct _stat32i64 *_Stat);
+int __cdecl stat32i64(const char *_Filename, struct _stat32i64 *_Stat)
+{
+  char *_path = __mingw_fix_stat_path(_Filename);
+  int ret = _stat32i64(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(stat32i64))(const char *, struct _stat32i64 
*) = stat32i64;
diff --git a/mingw-w64-crt/stdio/stat64.c b/mingw-w64-crt/stdio/stat64.c
new file mode 100644
index 000000000000..0f1c73fe0946
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat64.c
@@ -0,0 +1,22 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+char *__mingw_fix_stat_path(const char *_path);
+
+#undef stat64
+int __cdecl stat64(const char *_Filename, struct _stat64 *_Stat);
+int __cdecl stat64(const char *_Filename, struct _stat64 *_Stat)
+{
+  char *_path = __mingw_fix_stat_path(_Filename);
+  int ret = _stat64(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(stat64))(const char *, struct _stat64 *) = 
stat64;
diff --git a/mingw-w64-crt/stdio/stat64i32.c b/mingw-w64-crt/stdio/stat64i32.c
new file mode 100644
index 000000000000..2799ed42e368
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat64i32.c
@@ -0,0 +1,29 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+char *__mingw_fix_stat_path(const char *_path);
+
+int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat);
+int __cdecl stat64i32(const char *_Filename, struct _stat64i32 *_Stat)
+{
+  char *_path = __mingw_fix_stat_path(_Filename);
+  int ret = _stat64i32(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(stat64i32))(const char *, struct _stat64i32 
*) = stat64i32;
+
+/* On 64-bit systems is stat() function ABI compatible with stat64i32() 
function */
+#ifdef _WIN64
+#undef stat
+struct stat;
+int __attribute__ ((alias ("stat64i32"))) __cdecl stat(const char *name, 
struct stat *stat);
+extern int __attribute__ ((alias 
(__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(stat64i32))))) (__cdecl 
*__MINGW_IMP_SYMBOL(stat))(const char *name, struct stat *stat);
+#endif
diff --git a/mingw-w64-crt/stdio/wstat32.c b/mingw-w64-crt/stdio/wstat32.c
new file mode 100644
index 000000000000..0123148d56b6
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat32.c
@@ -0,0 +1,30 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+wchar_t *__mingw_fix_wstat_path(const wchar_t *_path);
+
+int __cdecl wstat32(const wchar_t *_Filename, struct _stat32 *_Stat);
+int __cdecl wstat32(const wchar_t *_Filename, struct _stat32 *_Stat)
+{
+  wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  int ret = _wstat32(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(wstat32))(const wchar_t *, struct _stat32 *) 
= wstat32;
+
+/* On 32-bit systems is wstat() function ABI compatible with wstat32() 
function */
+#ifndef _WIN64
+#undef stat
+#undef wstat
+struct stat;
+int __attribute__ ((alias ("wstat32"))) __cdecl wstat(const wchar_t *name, 
struct stat *stat);
+extern int __attribute__ ((alias 
(__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(wstat32))))) (__cdecl 
*__MINGW_IMP_SYMBOL(wstat))(const wchar_t *name, struct stat *stat);
+#endif
diff --git a/mingw-w64-crt/stdio/wstat32i64.c b/mingw-w64-crt/stdio/wstat32i64.c
new file mode 100644
index 000000000000..ea190f5737e4
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat32i64.c
@@ -0,0 +1,21 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+wchar_t *__mingw_fix_wstat_path(const wchar_t *_path);
+
+int __cdecl wstat32i64(const wchar_t *_Filename, struct _stat32i64 *_Stat);
+int __cdecl wstat32i64(const wchar_t *_Filename, struct _stat32i64 *_Stat)
+{
+  wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  int ret = _wstat32i64(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(wstat32i64))(const wchar_t *, struct 
_stat32i64 *) = wstat32i64;
diff --git a/mingw-w64-crt/stdio/wstat64.c b/mingw-w64-crt/stdio/wstat64.c
new file mode 100644
index 000000000000..96b0475cf4ae
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat64.c
@@ -0,0 +1,21 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+wchar_t *__mingw_fix_wstat_path(const wchar_t *_path);
+
+int __cdecl wstat64(const wchar_t *_Filename, struct _stat64 *_Stat);
+int __cdecl wstat64(const wchar_t *_Filename, struct _stat64 *_Stat)
+{
+  wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  int ret = _wstat64(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(wstat64))(const wchar_t *, struct _stat64 *) 
= wstat64;
diff --git a/mingw-w64-crt/stdio/wstat64i32.c b/mingw-w64-crt/stdio/wstat64i32.c
new file mode 100644
index 000000000000..1ad9b53b45f3
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat64i32.c
@@ -0,0 +1,30 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+
+wchar_t *__mingw_fix_wstat_path(const wchar_t *_path);
+
+int __cdecl wstat64i32(const wchar_t *_Filename, struct _stat64i32 *_Stat);
+int __cdecl wstat64i32(const wchar_t *_Filename, struct _stat64i32 *_Stat)
+{
+  wchar_t *_path = __mingw_fix_wstat_path(_Filename);
+  int ret = _wstat64i32(_path, _Stat);
+  if (_path != _Filename)
+    free(_path);
+  return ret;
+}
+int (__cdecl *__MINGW_IMP_SYMBOL(wstat64i32))(const wchar_t *, struct 
_stat64i32 *) = wstat64i32;
+
+/* On 64-bit systems is wstat() function ABI compatible with wstat64i32() 
function */
+#ifdef _WIN64
+#undef stat
+#undef wstat
+struct stat;
+int __attribute__ ((alias ("wstat64i32"))) __cdecl wstat(const wchar_t *name, 
struct stat *stat);
+extern int __attribute__ ((alias 
(__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(wstat64i32))))) (__cdecl 
*__MINGW_IMP_SYMBOL(wstat))(const wchar_t *name, struct stat *stat);
+#endif
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to