From 02104ca0f81ef4105cf0c4a558ad7d24c8fe97c4 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 3 Oct 2024 11:52:50 +0200 Subject: [PATCH] clar: simplify how we handle stat(3P) on Win32 The Windows platform has multiple different definitions for stat(3P) and its `struct stat` with different integer widths for both the filesize and the timestamps. For our usecase, we really only need to care whether we end up using `_stat()` or `stat()`, which require us to use either `struct _stat` or `struct stat`, respectively. The way we handle this in "clar.c" is somewhat convoluted though because we select the function and structure to use independently of each other. This can cause us to pick the wrong combination of features in some environments, like mingw-w64. Refactor the code so that both function and struct get set up under the same condition, thus fixing the issue. --- clar.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/clar.c b/clar.c index f463ee8..12fa66d 100644 --- a/clar.c +++ b/clar.c @@ -30,6 +30,9 @@ # ifndef stat # define stat(path, st) _stat(path, st) + typedef struct _stat STAT_T; +# else + typedef struct stat STAT_T; # endif # ifndef mkdir # define mkdir(path, mode) _mkdir(path) @@ -62,12 +65,6 @@ # else # define p_snprintf snprintf # endif - -# if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - typedef struct stat STAT_T; -# else - typedef struct _stat STAT_T; -# endif #else # include /* waitpid(2) */ # include