Fix mg_fs_posix.st() for Windows symlinks

This commit is contained in:
cpq committed 2023-02-17 10:20:33 +00:00
1 parent ca3dfb3c07
commit 24e3514640
3 files changed
+22 -2

No files matched your search

+10
View File
@@ -20,6 +20,16 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) {
wchar_t tmp[MG_PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
if (_wstati64(tmp, &st) != 0) return 0;
// If path is a symlink, windows reports 0 in st.st_size.
// Get a real file size by opening it and jumping to the end
if (st.st_size == 0 && (st.st_mode & _S_IFREG)) {
FILE *fp = _wfopen(tmp, L"rb");
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
if (_ftelli64(fp) > 0) st.st_size = _ftelli64(fp);
fclose(fp);
}
}
#else
struct MG_STAT_STRUCT st;
if (MG_STAT_FUNC(path, &st) != 0) return 0;