Commit cbb311d0b14cb4acce86b32756101f73f4826f7c
Committed by
Phil Elwell
1 parent
445356e1
main: check _POSIX_VERSION for fmemopen
Previously two commits added a fallback fmemopen for OS X/BSD that didn't support fmemopen, then fixed some of the ifdef logic around it. Unforunately the logic was backwards, as libc implementations do not define _POSIX_C_SOURCE in order to advertise features. Instead the user defines _POSIX_C_SOURCE to control which definitions are available. Check _POSIX_VERSION to see if the libc is new enough to implement fmemopen. If it is too old, assume that we're on a BSD compatible system and use the fallback fmemopen that depends on funopen. This solves the problem for some environments, but is still incorrect as it will try to use the fallback even on a system that does not include funopen. Fixes: 45c7237 (Fixup for recent firmware inclusion changes (#34)) Fixes: 17f6b01 (Fix cross-platform building)
Showing
1 changed file
with
8 additions
and
3 deletions
main.c
| @@ -10,9 +10,14 @@ | @@ -10,9 +10,14 @@ | ||
| 10 | #include "msd/bootcode4.h" | 10 | #include "msd/bootcode4.h" |
| 11 | #include "msd/start4.h" | 11 | #include "msd/start4.h" |
| 12 | 12 | ||
| 13 | -/* Assume BSD without native fmemopen() if doesn't seem to be glibc */ | ||
| 14 | -#if defined(__APPLE__) || (!defined(_GNU_SOURCE) && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200809L)) | ||
| 15 | -#include "fmemopen.c" // BSD fmemopen() compat in terms of funopen() | 13 | +/* |
| 14 | + * Old OS X/BSD do not implement fmemopen(). If the version of POSIX | ||
| 15 | + * supported is old enough that fmemopen() isn't included, assume | ||
| 16 | + * we're on a BSD compatible system and define a fallback fmemopen() | ||
| 17 | + * that depends on funopen(). | ||
| 18 | + */ | ||
| 19 | +#if _POSIX_VERSION <= 200112L | ||
| 20 | +#include "fmemopen.c" | ||
| 16 | #endif | 21 | #endif |
| 17 | 22 | ||
| 18 | int signed_boot = 0; | 23 | int signed_boot = 0; |