Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,11 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
#endif

#if defined(MACOS) || defined(TARGET_OS_MAC)
#if TARGET_OS_OSX
# define OS_CODE 7
# ifndef Z_SOLO
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
Copy link

@glandium glandium Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The history of this code is interesting.
zlib 0.71 (the first version in git) had:

#ifdef MACOS
#  define OS_CODE  0x07
#endif

zlib 1.0.8 added the fdopen thing, but differently:

#if defined(MACOS) || defined(TARGET_OS_MAC)
#  define OS_CODE  0x07
#  ifndef fdopen
#    define fdopen(fd,mode) NULL /* No fdopen() */
#  endif
#endif
#if defined(__MWERKS__) && !defined(fdopen)
#  if __dest_os != __be_os && __dest_os != __win32_os
#    define fdopen(fd,mode) NULL
#  endif
#endif

The corresponding changelog:

  • check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
  • do not use fdopen for Metrowerks on Mac (Brad Pettit))

zlib 1.1.3 changed it to:

#if defined(MACOS) || defined(TARGET_OS_MAC)
#  define OS_CODE  0x07
#  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
#    include <unix.h> /* for fdopen */
#  else
#    ifndef fdopen
#      define fdopen(fd,mode) NULL /* No fdopen() */
#    endif
#  endif
#endif

I think the corresponding changelog entry is:

  • Support gzdopen on Mac with Metrowerks (Jason Linhart)

Presumably, Metrowerks was defining TARGET_OS_MAC, and probably didn't define TARGET_OS_OSX, so my assumption here is that this change breaks Metrowerks. However, it's also a long gone compiler, so maybe this part can go entirely, which leaves us with two different OS_CODE values for macOS, one of which was added in ce12c5c

Copy link

@markmentovai markmentovai Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which leaves us with two different OS_CODE values for macOS, one of which was added in ce12c5c

Ever since ce12c5c, OS_CODE = 19 has meant macOS (or any other modern Apple OS). Prior to that, modern Apple OSes were reported as OS_CODE = 3, “assume Unix”. So what’s the story with OS_CODE = 7 mentioning TARGET_OS_MAC, then?

TARGET_OS_MAC has long been defined by the macOS SDK back to the very earliest days—I see it in the Mac OS X 10.1.5 SDK from Xcode 1.0 (2003-09-28)—but only by <TargetConditionals.h>, which would not normally have been #included into any translation unit that also #included zutil.h. zutil.h is zlib-internal and not generally made available to zlib consumers, so the lack of <TargetConditionals.h> in zlib code is largely dispositive.

The TARGET_OS_MAC macro as used in zutil.h (until 4bd9a71) was presumably used as another synonym for classic (pre-X, previous century) Mac OS, just as MACOS. It would never have meant macOS (or OS X or Mac OS X) in this code, until llvm/llvm-project@6e1f191 (in upstream Clang 18.1, 2024-01-29, and in Xcode 16.3, 2025-03-31).

The ce12c5c commit message says that appnote.txt defines the meaning of these bytes, and appnote.txt §4.4.2 makes it somewhat clear by stating assignments of 7 - Macintosh and 19 - OS X (Darwin).

# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
# endif
#endif
Expand Down