[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 <m_kato@ga2.so-net.ne.jp>.
This commit is contained in:
Eli Zaretskii 2021-05-29 11:37:09 +03:00
parent 1ae90c030d
commit 012918bf11

View file

@ -35,6 +35,13 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
#endif #endif
#ifdef WINDOWS32 #ifdef WINDOWS32
#include <io.h> #include <io.h>
#include <sys/stat.h>
#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 #endif
@ -1466,7 +1473,11 @@ static FILE_TIMESTAMP
name_mtime (const char *name) name_mtime (const char *name)
{ {
FILE_TIMESTAMP mtime; FILE_TIMESTAMP mtime;
#if defined(WINDOWS32)
struct STAT st;
#else
struct stat st; struct stat st;
#endif
int e; int e;
#if defined(WINDOWS32) #if defined(WINDOWS32)
@ -1498,7 +1509,11 @@ name_mtime (const char *name)
tend = &tem[0]; tend = &tem[0];
} }
#if defined(WINDOWS32)
e = STAT (tem, &st);
#else
e = stat (tem, &st); e = stat (tem, &st);
#endif
if (e == 0 && !_S_ISDIR (st.st_mode) && tend < tem + (p - name - 1)) if (e == 0 && !_S_ISDIR (st.st_mode) && tend < tem + (p - name - 1))
{ {
errno = ENOTDIR; errno = ENOTDIR;