- Fixed wrong _stat() function being used.

- Use the internal _stat version unconditionally since it's broken on Windows.

# Conflicts:
#	src/cmdlib.cpp
#	src/win32/i_system.cpp
This commit is contained in:
drfrag 2020-11-23 10:34:55 +01:00
parent 70ceced6b0
commit fe1ac50740
2 changed files with 15 additions and 13 deletions

View file

@ -145,6 +145,10 @@ void ReplaceString (char **ptr, const char *str)
*/
#ifdef _WIN32
int my_wstat64(const wchar_t *path, struct _stat64 *buffer);
#endif
//==========================================================================
//
// FileExists
@ -195,8 +199,8 @@ bool DirEntryExists(const char *pathname, bool *isdir)
#else
// Windows must use the wide version of stat to preserve non-standard paths.
auto wstr = WideString(pathname);
struct _stat64i32 info;
bool res = _wstat64i32(wstr.c_str(), &info) == 0;
struct _stat64 info;
bool res = my_wstat64(wstr.c_str(), &info) == 0;
#endif
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
return res;
@ -204,9 +208,9 @@ bool DirEntryExists(const char *pathname, bool *isdir)
//==========================================================================
//
// DirEntryExists
// GetFileInfo
//
// Returns true if the given path exists, be it a directory or a file.
// Returns true if the file info can be retrieved.
//
//==========================================================================
@ -221,8 +225,8 @@ bool GetFileInfo(const char* pathname, size_t *size, time_t *time)
#else
// Windows must use the wide version of stat to preserve non-standard paths.
auto wstr = WideString(pathname);
struct _stat64i32 info;
bool res = _wstat64i32(wstr.c_str(), &info) == 0;
struct _stat64 info;
bool res = my_wstat64(wstr.c_str(), &info) == 0;
#endif
if (!res || (info.st_mode & S_IFDIR)) return false;
if (size) *size = info.st_size;

View file

@ -1233,18 +1233,16 @@ FString I_GetLongPathName(const FString &shortpath)
return longpath;
}
#ifdef _USING_V110_SDK71_
#ifdef _WIN32
//==========================================================================
//
// _stat64i32
// _stat64
//
// Work around an issue where stat() function doesn't work
// with Windows XP compatible toolset.
// It uses GetFileInformationByHandleEx() which requires Windows Vista.
// Work around an issue where _stat() function doesn't work.
//
//==========================================================================
int _wstat64i32(const wchar_t *path, struct _stat64i32 *buffer)
int my_wstat64(const wchar_t *path, struct _stat64 *buffer)
{
WIN32_FILE_ATTRIBUTE_DATA data;
if(!GetFileAttributesExW(path, GetFileExInfoStandard, &data))
@ -1257,7 +1255,7 @@ int _wstat64i32(const wchar_t *path, struct _stat64i32 *buffer)
buffer->st_nlink = 1;
buffer->st_uid = 0;
buffer->st_gid = 0;
buffer->st_size = data.nFileSizeLow;
buffer->st_size = ((uint64_t)data.nFileSizeHigh << 32) + data.nFileSizeLow;
buffer->st_atime = (*(uint64_t*)&data.ftLastAccessTime) / 10000000 - 11644473600LL;
buffer->st_mtime = (*(uint64_t*)&data.ftLastWriteTime) / 10000000 - 11644473600LL;
buffer->st_ctime = (*(uint64_t*)&data.ftCreationTime) / 10000000 - 11644473600LL;