#include <libkern/zlib.h>
libkern/zlib.h
macroZLIB_H
#define ZLIB_H
macroZLIB_VERSION
#define ZLIB_VERSION "1.2.3"
macroZLIB_VERNUM
#define ZLIB_VERNUM 0x1230
typedefalloc_func
typedef voidpf (*alloc_func)
typedeffree_func
typedef void (*free_func)
structz_stream_s
| Bytef * | next_in | next input byte |
| uInt | avail_in | number of bytes available at next_in |
| uLong | total_in | total nb of input bytes read so far |
| Bytef * | next_out | next output byte should be put there |
| uInt | avail_out | remaining free space at next_out |
| uLong | total_out | total nb of bytes output so far |
| char * | msg | last error message, NULL if no error |
| struct internal_state * | state | not visible by applications |
| alloc_func | zalloc | used to allocate the internal state |
| free_func | zfree | used to free the internal state |
| voidpf | opaque | private data object passed to zalloc and zfree |
| int | data_type | best guess about the data type: binary or text |
| uLong | adler | adler32 value of the uncompressed data |
| uLong | reserved | reserved for future use |
typedefz_stream
typedef struct z_stream_s z_stream;
structgz_header_s
gzip header information passed to and from zlib routines. See RFC 1952
for more details on the meanings of these fields.
| int | text | true if compressed data believed to be text |
| uLong | time | modification time |
| int | xflags | extra flags (not used when writing a gzip file) |
| int | os | operating system |
| Bytef * | extra | pointer to extra field or Z_NULL if none |
| uInt | extra_len | extra field length (valid if extra != Z_NULL) |
| uInt | extra_max | space at extra (only when reading header) |
| Bytef * | name | pointer to zero-terminated file name or Z_NULL |
| uInt | name_max | space at name (only when reading header) |
| Bytef * | comment | pointer to zero-terminated comment or Z_NULL |
| uInt | comm_max | space at comment (only when reading header) |
| int | hcrc | true if there was or will be a header crc |
| int | done | true when done reading gzip header (not used when writing a gzip file) |
typedefgz_header
typedef struct gz_header_s gz_header;
typedefgz_headerp
typedef gz_header FAR *gz_headerp
macroZ_NO_FLUSH
#define Z_NO_FLUSH 0
macroZ_SYNC_FLUSH
2 is a reserved value (in zlib 1.2.3, Z_PACKET_FLUSH was removed)
#define Z_SYNC_FLUSH 3
macroZ_FULL_FLUSH
#define Z_FULL_FLUSH 4
macroZ_FINISH
#define Z_FINISH 5
macroZ_BLOCK
#define Z_BLOCK 6
macroZ_OK
#define Z_OK 0
macroZ_STREAM_END
#define Z_STREAM_END 1
macroZ_NEED_DICT
#define Z_NEED_DICT 2
macroZ_ERRNO
#define Z_ERRNO (-1)
macroZ_STREAM_ERROR
#define Z_STREAM_ERROR (-2)
macroZ_DATA_ERROR
#define Z_DATA_ERROR (-3)
macroZ_MEM_ERROR
#define Z_MEM_ERROR (-4)
macroZ_BUF_ERROR
#define Z_BUF_ERROR (-5)
macroZ_VERSION_ERROR
#define Z_VERSION_ERROR (-6)
macroZ_NO_COMPRESSION
#define Z_NO_COMPRESSION 0
macroZ_BEST_SPEED
#define Z_BEST_SPEED 1
macroZ_BEST_COMPRESSION
#define Z_BEST_COMPRESSION 9
macroZ_DEFAULT_COMPRESSION
#define Z_DEFAULT_COMPRESSION (-1)
macroZ_FILTERED
#define Z_FILTERED 1
macroZ_HUFFMAN_ONLY
#define Z_HUFFMAN_ONLY 2
macroZ_RLE
#define Z_RLE 3
macroZ_FIXED
#define Z_FIXED 4
macroZ_DEFAULT_STRATEGY
#define Z_DEFAULT_STRATEGY 0
macroZ_BINARY
#define Z_BINARY 0
macroZ_TEXT
#define Z_TEXT 1
macroZ_UNKNOWN
#define Z_UNKNOWN 2
macroZ_DEFLATED
#define Z_DEFLATED 8
macrozlib_version
#define zlib_version zlibVersion()
functionzlibVersion
ZEXTERN const char * ZEXPORT zlibVersion
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns the version string of the zlib library, "1.2.3" in the kernel copy. Applications compare it against the ZLIB_VERSION macro they were compiled with; the zlibInit macros perform this check automatically. The in-kernel zlib serves kext/mkext decompression, kernel core dumps, and other gzip/deflate uses.
functiondeflate
ZEXTERN int ZEXPORT deflate
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Compresses as much data as possible, consuming input from next_in/avail_in and writing compressed output to next_out/avail_out of the z_stream; it may introduce latency by accumulating input. The flush argument controls output forcing: Z_NO_FLUSH for normal operation, Z_SYNC_FLUSH or Z_FULL_FLUSH to align and emit pending output, Z_FINISH to end the stream. Returns Z_OK to continue, Z_STREAM_END when finished after Z_FINISH, Z_STREAM_ERROR for inconsistent state, or Z_BUF_ERROR if no progress was possible.
functiondeflateEnd
ZEXTERN int ZEXPORT deflateEnd
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Discards any unprocessed input and pending output and frees all dynamically allocated state for a deflate stream. Returns Z_OK, Z_STREAM_ERROR if the stream state was inconsistent, or Z_DATA_ERROR if the stream was freed prematurely with output pending.
functioninflate
ZEXTERN int ZEXPORT inflate
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Decompresses as much data as possible, consuming input from next_in/avail_in and writing uncompressed output to next_out/avail_out; called repeatedly until the stream ends. Returns Z_OK on progress, Z_STREAM_END at the logical end of the stream, Z_NEED_DICT if a preset dictionary is required (see inflateSetDictionary), Z_DATA_ERROR for corrupt input, Z_MEM_ERROR, or Z_BUF_ERROR if no progress was possible. The kernel uses it to decompress kexts and mkext archives (OSKext).
functioninflateEnd
ZEXTERN int ZEXPORT inflateEnd
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Discards any unprocessed input and pending output and frees all dynamically allocated state for an inflate stream. Returns Z_OK, or Z_STREAM_ERROR if the stream state was inconsistent.
functiondeflateSetDictionary
ZEXTERN int ZEXPORT deflateSetDictionary
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Initializes the deflate compression dictionary from the given byte sequence, immediately after deflateInit/deflateInit2 and before the first deflate call. The most recent dictionary bytes are kept if it exceeds the window size; the Adler-32 of the full dictionary is left in strm->adler for the decompressor to identify it. Returns Z_OK or Z_STREAM_ERROR; not usable with gzip streams.
functiondeflateCopy
ZEXTERN int ZEXPORT deflateCopy
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Duplicates the complete internal compression state of the source deflate stream into dest, so several compression strategies can be tried on the same data prefix. Duplicates roughly 256KB of state. Returns Z_OK, Z_MEM_ERROR, or Z_STREAM_ERROR if the source state was inconsistent.
functiondeflateReset
ZEXTERN int ZEXPORT deflateReset
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Resets a deflate stream for a new set of input, equivalent to deflateEnd followed by deflateInit but without freeing and reallocating the internal state; compression parameters are retained. Returns Z_OK, or Z_STREAM_ERROR if the stream state was inconsistent.
functiondeflateParams
ZEXTERN int ZEXPORT deflateParams
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Dynamically changes the compression level and strategy of an active deflate stream, e.g. to switch algorithms for different kinds of input. Data compressed so far is flushed with Z_SYNC_FLUSH before the new parameters take effect, so enough output space must be available. Returns Z_OK, Z_STREAM_ERROR, or Z_BUF_ERROR if strm->avail_out was zero.
functiondeflateTune
ZEXTERN int ZEXPORT deflateTune
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Fine-tunes deflate's internal match-search parameters (good_length, max_lazy, nice_length, max_chain), intended only for callers who understand the deflate algorithm; see deflate.c for the parameter meanings. May be called after deflateInit or deflateInit2. Returns Z_OK, or Z_STREAM_ERROR for an invalid stream.
functiondeflateBound
ZEXTERN uLong ZEXPORT deflateBound
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns an upper bound on the compressed size after deflation of sourceLen bytes, for use in sizing the output buffer for a single-pass deflate. Must be called after deflateInit or deflateInit2, whose parameters it takes into account.
functiondeflatePrime
ZEXTERN int ZEXPORT deflatePrime
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Inserts bits into the deflate output stream ahead of generated output, so compressed data can start at a bit position within a byte; up to 16 of the least significant bits of value are emitted. Intended for advanced applications such as appending to an existing deflate stream. Returns Z_OK or Z_STREAM_ERROR.
functiondeflateSetHeader
ZEXTERN int ZEXPORT deflateSetHeader
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Provides a gz_header structure whose fields (modification time, OS, extra field, name, comment, CRC flag) are written when compressing to gzip format, i.e. after deflateInit2 with windowBits greater than 15. Called before the first deflate; the caller must keep the referenced buffers alive until deflate finishes the header. Returns Z_OK or Z_STREAM_ERROR.
functioninflateSetDictionary
ZEXTERN int ZEXPORT inflateSetDictionary
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Initializes the inflate decompression dictionary from the given byte sequence; called immediately after inflate returns Z_NEED_DICT. The dictionary must match the one used by the compressor, checked via the Adler-32 value in strm->adler. Returns Z_OK, Z_STREAM_ERROR, or Z_DATA_ERROR if the checksum does not match.
functioninflateSync
ZEXTERN int ZEXPORT inflateSync
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Skips invalid compressed data until a possible full flush point (as emitted by deflate with Z_FULL_FLUSH) or the end of the input. Discards all pending output; used to resynchronize after corrupted input or a Z_DATA_ERROR. Returns Z_OK if a possible flush point was found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point was found, or Z_STREAM_ERROR.
functioninflateCopy
ZEXTERN int ZEXPORT inflateCopy
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Duplicates the complete internal decompression state of the source inflate stream into dest, e.g. to allow random access by saving state at sync points. Returns Z_OK, Z_MEM_ERROR, or Z_STREAM_ERROR if the source state was inconsistent.
functioninflateReset
ZEXTERN int ZEXPORT inflateReset
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Resets an inflate stream for a new set of input, equivalent to inflateEnd followed by inflateInit but without freeing and reallocating the internal state. Returns Z_OK, or Z_STREAM_ERROR if the stream state was inconsistent.
functioninflatePrime
ZEXTERN int ZEXPORT inflatePrime
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Inserts bits into the inflate input stream, so decompression can start at a bit position within a byte; up to 16 of the least significant bits of value are consumed before any bytes from next_in. Use only with raw inflate, before the first inflate call after inflateInit2 or inflateReset. Returns Z_OK or Z_STREAM_ERROR.
functioninflateGetHeader
ZEXTERN int ZEXPORT inflateGetHeader
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Requests that gzip header information be stored in the caller's gz_header structure as a gzip stream is decompressed; called after inflateInit2. head->done becomes 1 when the header is complete, or -1 for a raw or zlib stream with no gzip header. Returns Z_OK or Z_STREAM_ERROR.
typedefin_func
typedef unsigned (*in_func)
typedefout_func
typedef int (*out_func)
functioninflateBack
ZEXTERN int ZEXPORT inflateBack
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Performs a raw inflate in a single call using a call-back interface: the in() function supplies input and the out() function consumes output, which lowers overhead relative to inflate for whole-buffer decompression. The stream must first be set up with inflateBackInit and a caller-provided window. Returns Z_STREAM_END on success, or Z_BUF_ERROR, Z_DATA_ERROR, or Z_STREAM_ERROR on failure.
functioninflateBackEnd
ZEXTERN int ZEXPORT inflateBackEnd
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Frees all memory allocated by inflateBackInit for the call-back inflate interface. Returns Z_OK, or Z_STREAM_ERROR if the stream state was inconsistent.
functionzlibCompileFlags
ZEXTERN uLong ZEXPORT zlibCompileFlags
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns a bit mask of flags indicating compile-time options of the zlib library: sizes of uInt, uLong, voidpf and z_off_t, plus debug, and library-content options such as NO_GZCOMPRESS. Allows a caller to verify the library configuration matches its expectations.
functioncompress
ZEXTERN int ZEXPORT compress
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Compresses the source buffer into the destination buffer in one call, at the default compression level. destLen must hold the destination size on entry, at least compressBound(sourceLen), and receives the compressed size on return. Returns Z_OK, Z_MEM_ERROR, or Z_BUF_ERROR if the output buffer was too small.
functioncompress2
ZEXTERN int ZEXPORT compress2
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Compresses the source buffer into the destination buffer in one call at the given compression level (0-9, or Z_DEFAULT_COMPRESSION). destLen carries the destination size in and the compressed size out. Returns Z_OK, Z_MEM_ERROR, Z_BUF_ERROR if the output buffer was too small, or Z_STREAM_ERROR for an invalid level.
functioncompressBound
ZEXTERN uLong ZEXPORT compressBound
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns an upper bound on the compressed size after a compress or compress2 call on sourceLen bytes, for sizing the destination buffer.
functionuncompress
ZEXTERN int ZEXPORT uncompress
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Decompresses the source buffer into the destination buffer in one call. destLen must hold the destination buffer size on entry, large enough for the entire uncompressed output, and receives the actual uncompressed size on return. Returns Z_OK, Z_MEM_ERROR, Z_BUF_ERROR if the output buffer was too small, or Z_DATA_ERROR if the input was corrupted or incomplete.
functionadler32
ZEXTERN uLong ZEXPORT adler32
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Updates a running Adler-32 checksum with the len bytes at buf and returns the new checksum; the required initial value is obtained with adler32(0, Z_NULL, 0), which yields 1. Adler-32 is the checksum embedded in zlib-format streams and is faster to compute than CRC-32.
functionadler32_combine
ZEXTERN uLong ZEXPORT adler32_combine
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Combines two Adler-32 checksums: given adler1 of a first sequence and adler2 of a second sequence of length len2, returns the Adler-32 of the two sequences concatenated.
functionz_crc32
ZEXTERN uLong ZEXPORT z_crc32
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h, libkern/zlib/z_crc32.c
Updates a running CRC-32 with the len bytes at buf and returns the new checksum; the required initial value is obtained with z_crc32(0, Z_NULL, 0). This is zlib's crc32, renamed in the kernel to avoid colliding with the crc32 routine declared in libkern/libkern.h; both compute the same IEEE 802.3 polynomial used by gzip.
functionz_crc32_combine
ZEXTERN uLong ZEXPORT z_crc32_combine
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Combines two CRC-32 checksums: given crc1 of a first sequence and crc2 of a second sequence of length len2, returns the CRC-32 of the two sequences concatenated. Kernel rename of zlib's crc32_combine.
functiondeflateInit_
ZEXTERN int ZEXPORT deflateInit_
deflateInit and inflateInit are macros to allow checking the zlib version
and the compiler's view of z_stream:
functioninflateInit_
ZEXTERN int ZEXPORT inflateInit_
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Internal routine invoked by the inflateInit macro, which passes ZLIB_VERSION and sizeof(z_stream) so the library can verify that the caller was compiled against a compatible zlib. Initializes a z_stream for decompression of zlib-format data. Not called directly; returns Z_OK, Z_MEM_ERROR, or Z_VERSION_ERROR.
functiondeflateInit2_
ZEXTERN int ZEXPORT deflateInit2_
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Internal routine invoked by the deflateInit2 macro, which appends ZLIB_VERSION and sizeof(z_stream) for compatibility checking. Initializes a deflate stream with explicit parameters: compression level, method (Z_DEFLATED), windowBits (negative for raw deflate, +16 for gzip wrapping), memLevel, and strategy. Not called directly; returns Z_OK, Z_MEM_ERROR, Z_STREAM_ERROR, or Z_VERSION_ERROR.
functioninflateInit2_
ZEXTERN int ZEXPORT inflateInit2_
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Internal routine invoked by the inflateInit2 macro, which appends ZLIB_VERSION and sizeof(z_stream) for compatibility checking. Initializes an inflate stream with an explicit windowBits: negative for raw deflate data, +16 for gzip, or +32 for automatic zlib/gzip header detection. Not called directly; returns Z_OK, Z_MEM_ERROR, or Z_VERSION_ERROR.
functioninflateBackInit_
ZEXTERN int ZEXPORT inflateBackInit_
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Internal routine invoked by the inflateBackInit macro, with the version and stream-size check appended. Initializes a stream for the inflateBack call-back interface, using a caller-supplied window buffer of 2^windowBits bytes (up to 32KB) as the sliding window. Not called directly; returns Z_OK, Z_STREAM_ERROR, Z_MEM_ERROR, or Z_VERSION_ERROR.
macrodeflateInit
#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
macroinflateInit
#define inflateInit(strm) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
macrodeflateInit2
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) deflateInit2_((strm),(level),(method),(windowBits),(memLevel), (strategy), ZLIB_VERSION, sizeof(z_stream))
macroinflateInit2
#define inflateInit2(strm, windowBits) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
macroinflateBackInit
#define inflateBackInit(strm, windowBits, window) inflateBackInit_((strm), (windowBits), (window), ZLIB_VERSION, sizeof(z_stream))
structinternal_state
| int | dummy | hack for buggy compilers |
functionzError
ZEXTERN const char * ZEXPORT zError
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns the message string corresponding to a zlib error code, for callers that do not have access to the msg field of a z_stream.
functioninflateSyncPoint
ZEXTERN int ZEXPORT inflateSyncPoint
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns nonzero if the inflate stream is currently positioned at the end of a stored (uncompressed) block, where a full flush point permits random access. Returns 0 otherwise, or Z_STREAM_ERROR if the stream state is inconsistent.
functionget_crc_table
ZEXTERN const uLongf * ZEXPORT get_crc_table
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/libkern/zlib.h
Returns a pointer to zlib's internal 256-entry CRC-32 lookup table, provided so other code can share the table rather than duplicating it.