Skip to content

Fix Windows/MinGW build: reserved errno parameter name, missing err.h - #107

Open
doomfrawen wants to merge 1 commit into
nfc-tools:masterfrom
doomfrawen:windows-mingw-fixes
Open

Fix Windows/MinGW build: reserved errno parameter name, missing err.h#107
doomfrawen wants to merge 1 commit into
nfc-tools:masterfrom
doomfrawen:windows-mingw-fixes

Conversation

@doomfrawen

Copy link
Copy Markdown

Building mfoc for native Windows via MSYS2 MinGW64 against a working libnfc, ./configure succeeds but the build fails on two portability issues:

1. src/mfoc.c / src/mfoc.husage(FILE *stream, int errno) uses the reserved identifier errno as a parameter name. MinGW's <errno.h> (pulled in transitively) defines errno as a macro expanding to a function call, which mangles this declaration and produces passing argument 2 of usage makes pointer from integer without a cast. Renamed the parameter to exit_code (also updated the one call site, exit(errno) -> exit(exit_code)).

2. src/nfc-utils.h / src/nfc-utils.c — includes <err.h>, a BSD/glibc-only header not shipped by MinGW-w64, so the build fails with err.h: No such file or directory. The only thing actually used from it is warnx() (via the DBG/WARN/ERR macros), so this adds a small static inline warnx() shim under #ifdef _WIN32 instead of the header, and drops the redundant second #include <err.h> in nfc-utils.c (nfc-utils.h already brings it in).

Both changes are additive/platform-scoped and don't touch non-Windows behavior.

- usage(FILE *stream, int errno) uses the reserved identifier 'errno'
  as a parameter name. MinGW's <errno.h> (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 <err.h>, 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 <err.h> in nfc-utils.c (nfc-utils.h already
  provides it).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant