From 26d7c27bee77ed6320a3f60492ed1db1c20dba9b Mon Sep 17 00:00:00 2001 From: Adi Lester Date: Tue, 27 Nov 2018 14:16:25 +0200 Subject: [PATCH 1/2] 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 --- include/spdlog/details/os.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index f2422904..573224ad 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -210,10 +210,10 @@ inline size_t filesize(FILE *f) #if defined(_WIN32) && !defined(__CYGWIN__) int fd = _fileno(f); #if _WIN64 // 64 bits - struct _stat64 st; - if (_fstat64(fd, &st) == 0) + long long ret = _filelengthi64(fd); + if (ret >= 0) { - return st.st_size; + return static_cast(ret); } #else // windows 32 bits From 247c4e55e7d306947cbb3fc4964579a0df23701b Mon Sep 17 00:00:00 2001 From: Adi Lester Date: Tue, 27 Nov 2018 14:39:41 +0200 Subject: [PATCH 2/2] Update os.h --- include/spdlog/details/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 573224ad..646805e6 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -210,7 +210,7 @@ inline size_t filesize(FILE *f) #if defined(_WIN32) && !defined(__CYGWIN__) int fd = _fileno(f); #if _WIN64 // 64 bits - long long ret = _filelengthi64(fd); + __int64 ret = _filelengthi64(fd); if (ret >= 0) { return static_cast(ret);