fix: guard fdopen() NULL macro with !defined(__APPLE__) in zutil.h#3
Open
pgarciagon wants to merge 8 commits intocpp-pm:hunter-1.3.1from
Open
fix: guard fdopen() NULL macro with !defined(__APPLE__) in zutil.h#3pgarciagon wants to merge 8 commits intocpp-pm:hunter-1.3.1from
pgarciagon wants to merge 8 commits intocpp-pm:hunter-1.3.1from
Conversation
To be consistent with the remaining file replace the two occurences of tabs with 4 spaces.
On macOS, TARGET_OS_MAC is defined by the SDK headers. zutil.h defines fdopen(fd,mode) as NULL under this condition, but macOS stdio.h already declares fdopen() as a proper function — causing a redeclaration conflict when both headers are included in the same translation unit (e.g. when gRPC or other C++ libraries pull in both zlib and stdio headers). Add && !defined(__APPLE__) so the fdopen NULL macro only applies to legacy Mac OS (pre-macOS) targets, not modern macOS where the libc provides a real fdopen implementation. Fixes: compile error with Apple Clang on macOS 10.15+ (Catalina and later)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
zutil.hdefines:Wait — the original code is:
On modern Apple platforms
TARGET_OS_MACis always defined (it is set by<TargetConditionals.h>). macOS also provides a realfdopen()declarationin
<stdio.h>. When both are visible the preprocessor replaces the functioncall site with
NULL, causing compilation errors such as:Fix
Add
&& !defined(__APPLE__)to the guard so that on genuine Apple/macOS buildsthe real
fdopen()from<stdio.h>is used. The macro remains in place fornon-Apple platforms where it was originally needed.
Testing
Built as a Hunter dependency of koinos-chain on macOS 15 (Apple M-series, arm64)
with Xcode 16.3.