From 2a963ff008e5302e8961ed2c2b5bd9fd97f7a462 Mon Sep 17 00:00:00 2001 From: doomfrawen Date: Sun, 9 Aug 2026 09:18:22 -0700 Subject: [PATCH] Fix Windows/MinGW build: reserved 'errno' parameter name, missing err.h - usage(FILE *stream, int errno) uses the reserved identifier 'errno' as a parameter name. MinGW's (pulled in transitively) defines errno as a macro expanding to a function call, which mangles this declaration/definition and produces 'passing argument 2 of usage makes pointer from integer without a cast'. Renamed to exit_code. - nfc-utils.h/.c include , a BSD/glibc-only header not provided by MinGW-w64. The only function actually used from it is warnx() (via the DBG/WARN/ERR macros), so on _WIN32 this adds a small static inline warnx() shim instead, and drops the redundant second #include in nfc-utils.c (nfc-utils.h already provides it). --- src/mfoc.c | 4 ++-- src/mfoc.h | 2 +- src/nfc-utils.c | 1 - src/nfc-utils.h | 15 ++++++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/mfoc.c b/src/mfoc.c index 9887553..3a6e1ac 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -753,7 +753,7 @@ int main(int argc, char *const argv[]) exit(EXIT_FAILURE); } -void usage(FILE *stream, int errno) +void usage(FILE *stream, int exit_code) { fprintf(stream, "Usage: mfoc [-h] [-k key] [-f file] ... [-P probnum] [-T tolerance] [-O output]\n"); fprintf(stream, "\n"); @@ -776,7 +776,7 @@ void usage(FILE *stream, int errno) fprintf(stream, "\n"); fprintf(stream, "This is mfoc version %s.\n", PACKAGE_VERSION); fprintf(stream, "For more information, run: 'man mfoc'.\n"); - exit(errno); + exit(exit_code); } void mf_init(mfreader *r) diff --git a/src/mfoc.h b/src/mfoc.h index 9ea7547..8b09274 100644 --- a/src/mfoc.h +++ b/src/mfoc.h @@ -82,7 +82,7 @@ typedef struct { } countKeys; -void usage(FILE *stream, int errno); +void usage(FILE *stream, int exit_code); void mf_init(mfreader *r); void mf_configure(nfc_device *pdi); void mf_select_tag(nfc_device *pdi, nfc_target *pnt); diff --git a/src/nfc-utils.c b/src/nfc-utils.c index 5c0a264..f5b13b1 100644 --- a/src/nfc-utils.c +++ b/src/nfc-utils.c @@ -37,7 +37,6 @@ * @brief Provide some examples shared functions like print, parity calculation, options parsing. */ #include -#include #include "nfc-utils.h" diff --git a/src/nfc-utils.h b/src/nfc-utils.h index 8c52d4c..54af06f 100644 --- a/src/nfc-utils.h +++ b/src/nfc-utils.h @@ -43,7 +43,20 @@ # include # include -# include +# ifdef _WIN32 +# include +# include +static inline void warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); +} +# else +# include +# endif /** * @macro DBG