summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-03-15 19:42:43 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-23 13:00:37 -0400
commit7a6577513633b943202fc82ab7aa162e1d293c0a (patch)
tree704cdebde25170300f9d244582957a8efe9edf65
parent26ba86f73c9125c03968aec88be919bdd6a2152b (diff)
downloadhaskell-7a6577513633b943202fc82ab7aa162e1d293c0a.tar.gz
rts: Use long-path-aware stat
Previously `pathstat` relied on msvcrt's `stat` implementation, which was not long-path-aware. It should rather be defined in terms of the `stat` implementation provided by `utils/fs`. Fixes #19541.
-rw-r--r--rts/PathUtils.h7
-rw-r--r--utils/fs/fs.c2
-rw-r--r--utils/fs/fs.h6
3 files changed, 11 insertions, 4 deletions
diff --git a/rts/PathUtils.h b/rts/PathUtils.h
index b1746f8769..8a42e34b54 100644
--- a/rts/PathUtils.h
+++ b/rts/PathUtils.h
@@ -12,10 +12,13 @@
// Use wchar_t for pathnames on Windows (#5697)
#if defined(mingw32_HOST_OS)
+#include "fs_rts.h"
+
#define pathcmp wcscmp
#define pathlen wcslen
-#define pathopen __rts_fwopen
-#define pathstat _wstat
+// N.B. Use the Win32-based file routines from utils/fs.
+#define pathopen FS(fwopen)
+#define pathstat FS(_wstat)
#define struct_stat struct _stat
#define open wopen
#define WSTR(s) L##s
diff --git a/utils/fs/fs.c b/utils/fs/fs.c
index ebed2ca0fc..a5377af7e2 100644
--- a/utils/fs/fs.c
+++ b/utils/fs/fs.c
@@ -21,8 +21,6 @@
#include <io.h>
#include <fcntl.h>
#include <wchar.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <share.h>
#include <errno.h>
diff --git a/utils/fs/fs.h b/utils/fs/fs.h
index 9e4b8e2052..6c5f56ccdd 100644
--- a/utils/fs/fs.h
+++ b/utils/fs/fs.h
@@ -25,6 +25,12 @@
#if defined(_WIN32)
#include <wchar.h>
+// N.B. <sys/stat.h> defines some macro rewrites to, e.g., turn _wstat into
+// _wstat64i32. We must include it here to ensure tat this rewrite applies to
+// both the definition and use sites.
+#include <sys/types.h>
+#include <sys/stat.h>
+
wchar_t* FS(create_device_name) (const wchar_t*);
int FS(translate_mode) (const wchar_t*);
int FS(swopen) (const wchar_t* filename, int oflag,