luser-dr00g / xpost

A PostScript interpreter in C
Other
96 stars 12 forks source link

MacOS make issue: no stdio_ext.h #56

Open flwyd opened 1 day ago

flwyd commented 1 day ago

./autogen.sh && make on macOS Monterey with the Xcode compiler fails with an error. It looks like stdio_ext.h is a glibc and Solaris thing, but not present on Mac (or the BSD family tree generally, perhaps?).

% uname -a
Darwin samwise 21.6.0 Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64 x86_64

% make
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
  CC       src/lib/libxpost_la-xpost_file.lo
src/lib/xpost_file.c:55:11: fatal error: 'stdio_ext.h' file not found
# include <stdio_ext.h> /* __fpurge */
          ^~~~~~~~~~~~~
1 error generated.
make[1]: *** [src/lib/libxpost_la-xpost_file.lo] Error 1
make: *** [all] Error 2
vtorri commented 1 day ago

for mac and freebsd (and certainly other bsd), fpurge() is in stdio.h:

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fpurge.3.html

https://man.freebsd.org/cgi/man.cgi?query=fpurge&apropos=0&sektion=0&manpath=FreeBSD+14.1-RELEASE+and+Ports&arch=default&format=html

linux and solaris : __fpurge() is in stdio_ext.h

https://docs.oracle.com/cd/E88353_01/html/E37843/u--fpurge-3c.html

nothing like fpurge() on windows afaics.

I'll fix it this evening or tomorrow, in a cross platform way

luser-dr00g commented 21 hours ago

I took a peek, and surprise! We already did that. It should already be cross-compatible here. All of these lines are inside of #ifdef _WIN32. Curiously, the function that uses it doesn't have a non-WIN32 branch https://github.com/luser-dr00g/xpost/blob/master/src/lib/xpost_file.c#L197. So, if it's compiling for MacOs, why is _WIN32 defined?

This is all a bit silly because fpurge() isn't used anywhere internally, it's all to support the obscure postscript operator 'resetfile'.

vtorri commented 17 hours ago

@luser-dr00g the problem is the code below in xpost_file.c:

#ifndef _WIN32
# include <stdio_ext.h> /* __fpurge */
#endif

which is for linux and solaris (see my comment above). And anyway, mac and BSD have fpurge(), not __fpurge()

I propose an xpost_fpurge() in xpost_compat.h.

vtorri commented 17 hours ago

but is disk_purge() even used btw ? I don't see it anywhere in the code