Use _filelengthi64 instead of _fstat64 to calculate file size on x64 machines

For some reason, `_fstat64` fails with errno 22 on Windows Server 2003 x64 when compiled using the `v141_xp` toolset.
Using `_filelengthi64` instead solves this issue
This commit is contained in:
Adi Lester 2018-11-27 14:16:25 +02:00 committed by GitHub
parent b492642282
commit 26d7c27bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -210,10 +210,10 @@ inline size_t filesize(FILE *f)
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int fd = _fileno(f); int fd = _fileno(f);
#if _WIN64 // 64 bits #if _WIN64 // 64 bits
struct _stat64 st; long long ret = _filelengthi64(fd);
if (_fstat64(fd, &st) == 0) if (ret >= 0)
{ {
return st.st_size; return static_cast<size_t>(ret);
} }
#else // windows 32 bits #else // windows 32 bits