From 012918bf11fbc2a94dc2319d15d05595c351b811 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 29 May 2021 11:37:09 +0300 Subject: [PATCH] [SV 58656] Fix mtime for large files on MS-Windows In MSVC builds, 'stat' fails when called on files larger than 2GB. Call '_stat64' instead to work around this. * src/remake.c (STAT): Define to '_stat64' for MSVC builds. (name_mtime) [WINDOWS32]: Use STAT instead of 'stat'. Suggested by Makoto Kato . --- src/remake.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/remake.c b/src/remake.c index dc3097c2..f7605fc0 100644 --- a/src/remake.c +++ b/src/remake.c @@ -35,6 +35,13 @@ this program. If not, see . */ #endif #ifdef WINDOWS32 #include +#include +#if defined(_MSC_VER) && _MSC_VER > 1200 +/* VC7 or later supprots _stat64 to access 64-bit file size. */ +#define STAT _stat64 +#else +#define STAT stat +#endif #endif @@ -1466,7 +1473,11 @@ static FILE_TIMESTAMP name_mtime (const char *name) { FILE_TIMESTAMP mtime; +#if defined(WINDOWS32) + struct STAT st; +#else struct stat st; +#endif int e; #if defined(WINDOWS32) @@ -1498,7 +1509,11 @@ name_mtime (const char *name) tend = &tem[0]; } +#if defined(WINDOWS32) + e = STAT (tem, &st); +#else e = stat (tem, &st); +#endif if (e == 0 && !_S_ISDIR (st.st_mode) && tend < tem + (p - name - 1)) { errno = ENOTDIR;