Skip to content

Commit

Permalink
clar: simplify how we handle stat(3P) on Win32
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Oct 3, 2024
1 parent 67e689a commit 02104ca
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <sys/wait.h> /* waitpid(2) */
# include <unistd.h>
Expand Down

0 comments on commit 02104ca

Please sign in to comment.