From b11bea56a53d300f43b500be55890dbd01393d60 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Wed, 5 Aug 2020 00:09:29 -0400 Subject: [PATCH] Introduce Dedicated Helper to Call stat() --- programs/util.c | 11 +++++++++++ programs/util.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/programs/util.c b/programs/util.c index 2493a4ad..c172150d 100644 --- a/programs/util.c +++ b/programs/util.c @@ -99,6 +99,17 @@ int g_utilDisplayLevel; * Functions ***************************************/ +int UTIL_stat(const char* filename, stat_t* statbuf) +{ +#if defined(_MSC_VER) + return !_stat64(filename, statbuf); +#elif defined(__MINGW32__) && defined (__MSVCRT__) + return !_stati64(filename, statbuf); +#else + return !stat(filename, statbuf); +#endif +} + int UTIL_fileExist(const char* filename) { stat_t statbuf; diff --git a/programs/util.h b/programs/util.h index 580266e7..0b58dfbb 100644 --- a/programs/util.h +++ b/programs/util.h @@ -100,6 +100,8 @@ extern int g_utilDisplayLevel; #if defined(_MSC_VER) typedef struct __stat64 stat_t; typedef int mode_t; +#elif defined(__MINGW32__) && defined (__MSVCRT__) + typedef struct _stati64 stat_t; #else typedef struct stat stat_t; #endif @@ -113,6 +115,11 @@ extern int g_utilDisplayLevel; #define STRDUP(s) strdup(s) #endif +/** + * Calls platform's equivalent of stat() on filename and writes info to statbuf. + * Returns success (1) or failure (0). + */ +int UTIL_stat(const char* filename, stat_t* statbuf); int UTIL_fileExist(const char* filename); int UTIL_isRegularFile(const char* infilename); int UTIL_isDirectory(const char* infilename);