CRT _fstat function returns S_IFREG for directories, but CRT _stat function
returns S_IFDIR for directories. mingw-w64 fstat functions fixes this
_fstat issues, so use fstat for _wstat emulation used for crtdll.dll and
msvcrt10.dll builds.
This change fixes the t_stat_slash test when compiled against crtdll.dll.
---
This change depends on "[PATCH v2] crt: Fix fstat() to signal overflow and
return correct type for directories".
---
mingw-w64-crt/stdio/_wstat32.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mingw-w64-crt/stdio/_wstat32.c b/mingw-w64-crt/stdio/_wstat32.c
index e9270809c06f..6b0ac1b7e7fc 100644
--- a/mingw-w64-crt/stdio/_wstat32.c
+++ b/mingw-w64-crt/stdio/_wstat32.c
@@ -11,6 +11,7 @@
#ifndef _WIN64
#include <fcntl.h>
#include <windows.h>
+int __cdecl fstat32(int fd, struct _stat32 *stat);
#endif
/* When the file time does not fit into the st_Xtime field:
@@ -52,8 +53,10 @@ int __cdecl _wstat32(const wchar_t *_Name,struct _stat32
*_Stat)
#else
/* mingw-w64 _wstat64() on 32-bit systems is implemented as wrapper around
the _wstat32().
* Therefore mingw-w64 _wstat32() implementation cannot call _wstat64().
- * This _wstat32 implementation uses _fstat32() with handle obtained from
CreateFileW().
- * _fstat requires only FILE_READ_ATTRIBUTES access and
FILE_FLAG_BACKUP_SEMANTICS is
+ * This _wstat32() implementation uses mingw-w64 fstat32() with handle
obtained from CreateFileW().
+ * mingw-w64 fstat32() is a wrapper around the CRT _fstat32() and which
fixes the S_IFMT to
+ * S_IFDIR for directories. The CRT _fstat32() returns S_IFREG for
directories.
+ * _fstat32() requires only FILE_READ_ATTRIBUTES access and
FILE_FLAG_BACKUP_SEMANTICS is
* required for opening directory via CreateFileW().
* Using just FILE_READ_ATTRIBUTES access allows to open also path which is
was denied for
* reading by another process. msvcrt.dll _wstat32() also allows to be
called on such path.
@@ -87,7 +90,7 @@ int __cdecl _wstat32(const wchar_t *_Name,struct _stat32
*_Stat)
CloseHandle(handle);
return -1;
}
- ret = _fstat32(fd, _Stat);
+ ret = fstat32(fd, _Stat);
err = errno;
close(fd);
errno = err;
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public