From 9cde3f8b2e7a9382b69f4a8362812405273e7cec Mon Sep 17 00:00:00 2001 From: ds77 Date: Thu, 9 Feb 2017 18:12:00 +0100 Subject: [PATCH 1/4] use _stat64() on MinGW On MinGW, use _stat64() and struct _stat64 instead of stat() and struct stat_t. This fixes reporting incorrect sizes for large files. --- programs/util.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/programs/util.h b/programs/util.h index 651027ba..f5bd4230 100644 --- a/programs/util.h +++ b/programs/util.h @@ -141,7 +141,7 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond) /*-**************************************** * File functions ******************************************/ -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) #define chmod _chmod typedef struct _stat64 stat_t; #else @@ -172,7 +172,7 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) r = _stat64(infilename, statbuf); if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -186,7 +186,7 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) UTIL_STATIC U64 UTIL_getFileSize(const char* infilename) { int r; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ @@ -212,7 +212,7 @@ UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFi UTIL_STATIC int UTIL_doesFileExists(const char* infilename) { int r; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ @@ -228,7 +228,7 @@ UTIL_STATIC int UTIL_doesFileExists(const char* infilename) UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) { int r; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; From 19f61b534e67e911ce888048aff3516dbdc3f7bd Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 10 Feb 2017 10:56:45 +0100 Subject: [PATCH 2/4] use _stat64 only when targetting Win2k or later --- programs/util.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/programs/util.h b/programs/util.h index f5bd4230..b0f12363 100644 --- a/programs/util.h +++ b/programs/util.h @@ -141,7 +141,7 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond) /*-**************************************** * File functions ******************************************/ -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K #define chmod _chmod typedef struct _stat64 stat_t; #else @@ -172,7 +172,7 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K r = _stat64(infilename, statbuf); if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -186,7 +186,7 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) UTIL_STATIC U64 UTIL_getFileSize(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ @@ -212,7 +212,7 @@ UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFi UTIL_STATIC int UTIL_doesFileExists(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ @@ -228,7 +228,7 @@ UTIL_STATIC int UTIL_doesFileExists(const char* infilename) UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; From 7ec315df0dd4bef8921bceb089bdbea2b88a9382 Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 10 Feb 2017 13:27:43 +0100 Subject: [PATCH 3/4] fix previous commit * struct _stat64 is not defined by (non-w64) MinGW releases, __stat64 should be everywhere * proper detection of _stat64() availability (as in MinGW sys/stat.h) --- programs/util.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/programs/util.h b/programs/util.h index b0f12363..fe3d8448 100644 --- a/programs/util.h +++ b/programs/util.h @@ -141,9 +141,9 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond) /*-**************************************** * File functions ******************************************/ -#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K #define chmod _chmod - typedef struct _stat64 stat_t; + typedef struct __stat64 stat_t; #else typedef struct stat stat_t; #endif @@ -172,7 +172,7 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K r = _stat64(infilename, statbuf); if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -186,8 +186,8 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) UTIL_STATIC U64 UTIL_getFileSize(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K - struct _stat64 statbuf; +#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K + struct __stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -212,8 +212,8 @@ UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFi UTIL_STATIC int UTIL_doesFileExists(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K - struct _stat64 statbuf; +#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K + struct __stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -228,8 +228,8 @@ UTIL_STATIC int UTIL_doesFileExists(const char* infilename) UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K - struct _stat64 statbuf; +#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K + struct __stat64 statbuf; r = _stat64(infilename, &statbuf); if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; #else From 45f0c207ab8e3955a6068cc845eceb175623fd63 Mon Sep 17 00:00:00 2001 From: ds77 Date: Fri, 10 Feb 2017 18:37:57 +0100 Subject: [PATCH 4/4] use _stati64() in UTIL_getFileSize() when compiling with mingw, get rid of introduces previously preprocessor checks. --- programs/util.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/programs/util.h b/programs/util.h index fe3d8448..b1217910 100644 --- a/programs/util.h +++ b/programs/util.h @@ -141,7 +141,7 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond) /*-**************************************** * File functions ******************************************/ -#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) #define chmod _chmod typedef struct __stat64 stat_t; #else @@ -172,7 +172,7 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) r = _stat64(infilename, statbuf); if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ #else @@ -186,10 +186,14 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) UTIL_STATIC U64 UTIL_getFileSize(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K - struct __stat64 statbuf; +#if defined(_MSC_VER) + struct _stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ +#elif defined(__MINGW32__) && defined (__MSVCRT__) + struct _stati64 statbuf; + r = _stati64(infilename, &statbuf); + if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ #else struct stat statbuf; r = stat(infilename, &statbuf); @@ -212,7 +216,7 @@ UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFi UTIL_STATIC int UTIL_doesFileExists(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) struct __stat64 statbuf; r = _stat64(infilename, &statbuf); if (r || !(statbuf.st_mode & S_IFREG)) return 0; /* No good... */ @@ -228,7 +232,7 @@ UTIL_STATIC int UTIL_doesFileExists(const char* infilename) UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) { int r; -#if defined(_MSC_VER) || defined(__MINGW32__) && defined(__MSVCRT__) && _WIN32_WINNT >= _WIN32_WINNT_WIN2K +#if defined(_MSC_VER) struct __stat64 statbuf; r = _stat64(infilename, &statbuf); if (!r && (statbuf.st_mode & _S_IFDIR)) return 1;