POSIX struct stat has 4 variants in mingw-w64 based on the
_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 ++
 mingw-w64-crt/stdio/__mingw_fix_stat_path.c   |  65 ++++++++++
 mingw-w64-crt/stdio/__mingw_fix_wstat_path.c  |  65 ++++++++++
 mingw-w64-crt/stdio/_stat.c                   | 120 ------------------
 mingw-w64-crt/stdio/_wstat.c                  | 119 -----------------
 mingw-w64-crt/stdio/stat32.c                  |  29 +++++
 mingw-w64-crt/stdio/stat32i64.c               |  22 ++++
 mingw-w64-crt/stdio/stat64.c                  |  23 ++++
 mingw-w64-crt/stdio/stat64i32.c               |  29 +++++
 mingw-w64-crt/stdio/wstat32.c                 |  30 +++++
 mingw-w64-crt/stdio/wstat32i64.c              |  22 ++++
 mingw-w64-crt/stdio/wstat64.c                 |  22 ++++
 mingw-w64-crt/stdio/wstat64i32.c              |  30 +++++
 15 files changed, 393 insertions(+), 244 deletions(-)
 create mode 100644 mingw-w64-crt/stdio/__mingw_fix_stat_path.c
 create mode 100644 mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
 delete mode 100644 mingw-w64-crt/stdio/_stat.c
 delete mode 100644 mingw-w64-crt/stdio/_wstat.c
 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 54e84ee62f4e..c849a85b3a1a 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -182,6 +182,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 \
@@ -1017,11 +1025,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 5f1f8bfad746..e939d2ed45a0 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
@@ -296,6 +299,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
@@ -564,6 +582,18 @@ __ms_vwscanf == vwscanf
 ; 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/__mingw_fix_stat_path.c 
b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
new file mode 100644
index 000000000000..1efb3fea3da9
--- /dev/null
+++ b/mingw-w64-crt/stdio/__mingw_fix_stat_path.c
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+
+#define __CRT__NO_INLINE
+#include <sys/stat.h>
+#include <stdlib.h>
+
+/**
+ * Returns _path without trailing slash if any
+ *
+ * - if _path has no trailing slash, the function returns it
+ * - if _path has a trailing slash, but is of the form C:/, then it returns it
+ * - otherwise, the function creates a new string, which is a copy of _path
+ *   without the trailing slash. It is then the responsibility of the caller
+ *   to free it.
+ */
+
+char* __mingw_fix_stat_path (const char* _path);
+char* __mingw_fix_stat_path (const char* _path)
+{
+  int len;
+  char *p;
+
+  p = (char*)_path;
+
+  if (_path && *_path) {
+    len = strlen (_path);
+
+    /* Ignore X:\ */
+
+    if (len <= 1 || ((len == 2 || len == 3) && _path[1] == ':'))
+      return p;
+
+    /* Check UNC \\abc\<name>\ */
+    if ((_path[0] == '\\' || _path[0] == '/')
+       && (_path[1] == '\\' || _path[1] == '/'))
+      {
+       const char *r = &_path[2];
+       while (*r != 0 && *r != '\\' && *r != '/')
+         ++r;
+       if (*r != 0)
+         ++r;
+       if (*r == 0)
+         return p;
+       while (*r != 0 && *r != '\\' && *r != '/')
+         ++r;
+       if (*r != 0)
+         ++r;
+       if (*r == 0)
+         return p;
+      }
+
+    if (_path[len - 1] == '/' || _path[len - 1] == '\\')
+      {
+       p = (char*)malloc (len);
+       memcpy (p, _path, len - 1);
+       p[len - 1] = '\0';
+      }
+  }
+
+  return p;
+}
diff --git a/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c 
b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
new file mode 100644
index 000000000000..0984cace48c7
--- /dev/null
+++ b/mingw-w64-crt/stdio/__mingw_fix_wstat_path.c
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+
+#define __CRT__NO_INLINE
+#include <sys/stat.h>
+#include <stdlib.h>
+
+/**
+ * Returns _path without trailing slash if any
+ *
+ * - if _path has no trailing slash, the function returns it
+ * - if _path has a trailing slash, but is of the form C:/, then it returns it
+ * - otherwise, the function creates a new string, which is a copy of _path
+ *   without the trailing slash. It is then the responsibility of the caller
+ *   to free it.
+ */
+
+wchar_t* __mingw_fix_wstat_path (wchar_t* _path);
+wchar_t* __mingw_fix_wstat_path (wchar_t* _path)
+{
+  int len;
+  wchar_t *p;
+
+  p = (wchar_t*)_path;
+
+  if (_path && *_path) {
+    len = wcslen (_path);
+
+    /* Ignore X:\ */
+
+    if (len <= 1 || ((len == 2 || len == 3) && _path[1] == L':'))
+      return p;
+
+    /* Check UNC \\abc\<name>\ */
+    if ((_path[0] == L'\\' || _path[0] == L'/')
+       && (_path[1] == L'\\' || _path[1] == L'/'))
+      {
+       const wchar_t *r = &_path[2];
+       while (*r != 0 && *r != L'\\' && *r != L'/')
+         ++r;
+       if (*r != 0)
+         ++r;
+       if (*r == 0)
+         return p;
+       while (*r != 0 && *r != L'\\' && *r != L'/')
+         ++r;
+       if (*r != 0)
+         ++r;
+       if (*r == 0)
+         return p;
+      }
+
+    if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
+      {
+       p = (wchar_t*)malloc (len * sizeof(wchar_t));
+       memcpy (p, _path, (len - 1) * sizeof(wchar_t));
+       p[len - 1] = L'\0';
+      }
+  }
+
+  return p;
+}
diff --git a/mingw-w64-crt/stdio/_stat.c b/mingw-w64-crt/stdio/_stat.c
deleted file mode 100644
index fbb985e389e9..000000000000
--- a/mingw-w64-crt/stdio/_stat.c
+++ /dev/null
@@ -1,120 +0,0 @@
-#define __CRT__NO_INLINE
-#include <sys/stat.h>
-#include <stdlib.h>
-
-/**
- * Returns _path without trailing slash if any
- *
- * - if _path has no trailing slash, the function returns it
- * - if _path has a trailing slash, but is of the form C:/, then it returns it
- * - otherwise, the function creates a new string, which is a copy of _path
- *   without the trailing slash. It is then the responsibility of the caller
- *   to free it.
- */
-
-static char*
-_mingw_no_trailing_slash (const char* _path)
-{
-  int len;
-  char *p;
-
-  p = (char*)_path;
-
-  if (_path && *_path) {
-    len = strlen (_path);
-
-    /* Ignore X:\ */
-
-    if (len <= 1 || ((len == 2 || len == 3) && _path[1] == ':'))
-      return p;
-
-    /* Check UNC \\abc\<name>\ */
-    if ((_path[0] == '\\' || _path[0] == '/')
-       && (_path[1] == '\\' || _path[1] == '/'))
-      {
-       const char *r = &_path[2];
-       while (*r != 0 && *r != '\\' && *r != '/')
-         ++r;
-       if (*r != 0)
-         ++r;
-       if (*r == 0)
-         return p;
-       while (*r != 0 && *r != '\\' && *r != '/')
-         ++r;
-       if (*r != 0)
-         ++r;
-       if (*r == 0)
-         return p;
-      }
-
-    if (_path[len - 1] == '/' || _path[len - 1] == '\\')
-      {
-       p = (char*)malloc (len);
-       memcpy (p, _path, len - 1);
-       p[len - 1] = '\0';
-      }
-  }
-
-  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) {
-    memset(_Stat,0,sizeof(struct stat));
-    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) {
-    memset(_Stat,0,sizeof(struct stat));
-    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/_wstat.c
deleted file mode 100644
index 08566168fbe5..000000000000
--- a/mingw-w64-crt/stdio/_wstat.c
+++ /dev/null
@@ -1,119 +0,0 @@
-#define __CRT__NO_INLINE
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <malloc.h>
-
-/**
- * Returns _path without trailing slash if any
- *
- * - if _path has no trailing slash, the function returns it
- * - if _path has a trailing slash, but is of the form C:/, then it returns it
- * - otherwise, the function creates a new string, which is a copy of _path
- *   without the trailing slash. It is then the responsibility of the caller
- *   to free it.
- */
-
-static wchar_t*
-_mingw_no_trailing_slash (const wchar_t* _path)
-{
-  int len;
-  wchar_t *p;
-
-  p = (wchar_t*)_path;
-
-  if (_path && *_path) {
-    len = wcslen (_path);
-
-    /* Ignore X:\ */
-
-    if (len <= 1 || ((len == 2 || len == 3) && _path[1] == L':'))
-      return p;
-
-    /* Check UNC \\abc\<name>\ */
-    if ((_path[0] == L'\\' || _path[0] == L'/')
-       && (_path[1] == L'\\' || _path[1] == L'/'))
-      {
-       const wchar_t *r = &_path[2];
-       while (*r != 0 && *r != L'\\' && *r != L'/')
-         ++r;
-       if (*r != 0)
-         ++r;
-       if (*r == 0)
-         return p;
-       while (*r != 0 && *r != L'\\' && *r != L'/')
-         ++r;
-       if (*r != 0)
-         ++r;
-       if (*r == 0)
-         return p;
-      }
-
-    if (_path[len - 1] == L'/' || _path[len - 1] == L'\\')
-      {
-       p = (wchar_t*)malloc (len * sizeof(wchar_t));
-       memcpy (p, _path, (len - 1) * sizeof(wchar_t));
-       p[len - 1] = L'\0';
-      }
-  }
-
-  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) {
-    memset(_Stat,0,sizeof(struct stat));
-    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) {
-    memset(_Stat,0,sizeof(struct stat));
-    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..be3e4694b83f
--- /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.
+ */
+
+#define __CRT__NO_INLINE
+#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
+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..f853d7a3f25f
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat32i64.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.
+ */
+
+#define __CRT__NO_INLINE
+#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..2e1d66ebc3fd
--- /dev/null
+++ b/mingw-w64-crt/stdio/stat64.c
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+#define __CRT__NO_INLINE
+#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..66f069722f12
--- /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.
+ */
+
+#define __CRT__NO_INLINE
+#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
+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..41e3b1c85550
--- /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.
+ */
+
+#define __CRT__NO_INLINE
+#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
+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..15acacb532ce
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat32i64.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.
+ */
+
+#define __CRT__NO_INLINE
+#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..a24d81cd244e
--- /dev/null
+++ b/mingw-w64-crt/stdio/wstat64.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.
+ */
+
+#define __CRT__NO_INLINE
+#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..5821cc464c38
--- /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.
+ */
+
+#define __CRT__NO_INLINE
+#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
+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
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to