From b2a03268b991898194c774652b55d972914ebe0c Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Sun, 5 Jul 2026 11:42:09 -0700 Subject: [PATCH] windows: fix MinGW-w64 build of win_file.c Two issues prevent core/shared/platform/windows/win_file.c from compiling with the MinGW-w64 (GCC) toolchain: - The include of "PathCch.h" fails on a case-sensitive filesystem; the MinGW SDK installs the header lowercase (pathcch.h). - Three // comments in os_readlinkat() end with a backslash ("\??\"). GCC treats a backslash at the end of a // comment line as a line continuation, so the following line of code is swallowed into the comment and the function fails to parse. MSVC does not. Append a word to each so the comment no longer ends in a backslash, keeping the documented NT paths intact. The enclosing if/else-if block is reformatted (brace placement and indentation) to keep the modified lines clang-format clean. Signed-off-by: Jiawei Huang --- core/shared/platform/windows/win_file.c | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c index 7cfda4cc3a..878d6aa17a 100644 --- a/core/shared/platform/windows/win_file.c +++ b/core/shared/platform/windows/win_file.c @@ -7,7 +7,7 @@ #include "libc_errno.h" #include "win_util.h" -#include "PathCch.h" +#include "pathcch.h" #pragma comment(lib, "Pathcch.lib") @@ -1295,26 +1295,25 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf, if (wbufsize >= 4 && wbuf[0] == L'\\' && wbuf[1] == L'?' && wbuf[2] == L'?' && wbuf[3] == L'\\') { - // Starts with \??\ + // Starts with \??\ prefix if (wbufsize >= 6 && ((wbuf[4] >= L'A' && wbuf[4] <= L'Z') || (wbuf[4] >= L'a' && wbuf[4] <= L'z')) - && wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\')) - { - // \??\:\ - wbuf += 4; - wbufsize -= 4; - } - else if (wbufsize >= 8 && (wbuf[4] == L'U' || wbuf[4] == L'u') - && (wbuf[5] == L'N' || wbuf[5] == L'n') - && (wbuf[6] == L'C' || wbuf[6] == L'c') - && wbuf[7] == L'\\') - { - // \??\UNC\\\ - make sure the final path looks like \\\\ - wbuf += 6; - wbuf[0] = L'\\'; - wbufsize -= 6; - } + && wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\')) { + // \??\:\ form + wbuf += 4; + wbufsize -= 4; + } + else if (wbufsize >= 8 && (wbuf[4] == L'U' || wbuf[4] == L'u') + && (wbuf[5] == L'N' || wbuf[5] == L'n') + && (wbuf[6] == L'C' || wbuf[6] == L'c') + && wbuf[7] == L'\\') { + // \??\UNC\\\ - make sure the final path looks + // like \\\\ afterwards + wbuf += 6; + wbuf[0] = L'\\'; + wbufsize -= 6; + } } } else if (reparse_data->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {