michaelrsweet / pdfio

PDFio is a simple C library for reading and writing PDF files.
https://www.msweet.org/pdfio
Apache License 2.0
198 stars 44 forks source link

Incompatibility with MinGW #66

Closed William65536 closed 5 months ago

William65536 commented 5 months ago

Currently pdfio-private.h contains the following three lines:

https://github.com/michaelrsweet/pdfio/blob/6c1db141a105b76ca1fa1b88175ae6a4e1e8c2ee/pdfio-private.h#L41-L43

which override three of the four definitions in io.h when using MinGW on Windows:

#define F_OK    0   /* Check for file existence */
#define X_OK    1   /* Check for execute permission. */
#define W_OK    2   /* Check for write permission */
#define R_OK    4   /* Check for read permission */

The second clause in section 6.10.3 of the ISO C99 Standard mandates that

An identifier currently defined as an object-like macro shall not be redefined by another

define preprocessing directive unless the second definition is an object-like macro

definition and the two replacement lists are identical.

and section 6.10.3 clause 1 defines the equality of macro bodies as

Two replacement lists are identical if and only if the preprocessing tokens in both have the same number, ordering, spelling, and white-space separation, where all white-space separations are considered identical.

Even though cpp does not necessarily complain about the above violation of the C standard, other tools such as Zig's translate-c do, preventing the user from building pdfio without manually editing the lines in pdfio-private.h.

All code of the same form as the definitions in pdfio-private.h should therefore be changed to:

#ifndef F_OK
#define F_OK    00
#endif
#ifndef W_OK
#define W_OK    02
#endif
#ifndef R_OK
#define R_OK    04
#endif

to ensure no conflicting definitions.

michaelrsweet commented 5 months ago

Scheduling for a future stable release.

Note that I have NOT tested PDFio with MinGW or any other alternative toolchain for Windows. These definitions are explicitly in place to support building on Windows using the Visual C compiler. Anything else is not supported at this time.

michaelrsweet commented 5 months ago

[master f040cc4] Add #define guard to allow MingW to build PDFio; note that MingW is NOT a supported toolchain for PDFio (Issue #66)