| 1 | /* zutil.h -- internal interface and configuration of the compression library |
| 2 | * Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ |
| 5 | |
| 6 | /* WARNING: this file should *not* be used by applications. It is |
| 7 | part of the implementation of the compression library and is |
| 8 | subject to change. Applications should only use zlib.h. |
| 9 | */ |
| 10 | |
| 11 | /* @(#) $Id$ */ |
| 12 | |
| 13 | #ifndef ZUTIL_H |
| 14 | #define ZUTIL_Hcxx . . $ `external/zlib/zutil.h:14:9`! |
| 15 | |
| 16 | #ifdef HAVE_HIDDEN |
| 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) |
| 18 | #else |
| 19 | # define ZLIB_INTERNALcxx . . $ `external/zlib/zutil.h:19:11`! |
| 20 | #endif |
| 21 | |
| 22 | #include "zlib.h"cxx . . $ `<file>/external/zlib/zlib.h`/ |
| 23 | |
| 24 | #if defined(STDCcxx . . $ `<external>/116306602880328527/zconf.h:214:13`!) && !defined(Z_SOLO) |
| 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) |
| 26 | # include <stddef.h> |
| 27 | # endif |
| 28 | # include <string.h> |
| 29 | # include <stdlib.h> |
| 30 | #endif |
| 31 | |
| 32 | #ifndef local |
| 33 | # define localcxx . . $ `external/zlib/zutil.h:33:11`! static |
| 34 | #endif |
| 35 | /* since "static" is used to mean two completely different things in C, we |
| 36 | define "local" for the non-static meaning of "static", for readability |
| 37 | (compile with -Dlocal if your debugger can't find static symbols) */ |
| 38 | |
| 39 | extern const char deflate_copyrightcxx . . $ deflate_copyright.[]; |
| 40 | extern const char inflate_copyrightcxx . . $ inflate_copyright.[]; |
| 41 | extern const char inflate9_copyrightcxx . . $ inflate9_copyright.[]; |
| 42 | |
| 43 | typedef unsigned char uchcxx . . $ uch#; |
| 44 | typedef uchcxx . . $ uch# FARcxx . . $ `<external>/116306602880328527/zconf.h:399:11`! uchfcxx . . $ uchf#; |
| 45 | typedef unsigned short ushcxx . . $ ush#; |
| 46 | typedef ushcxx . . $ ush# FARcxx . . $ `<external>/116306602880328527/zconf.h:399:11`! ushfcxx . . $ ushf#; |
| 47 | typedef unsigned long ulgcxx . . $ ulg#; |
| 48 | |
| 49 | #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDCcxx . . $ `<external>/116306602880328527/zconf.h:214:13`!) |
| 50 | # include <limits.h> |
| 51 | # if (ULONG_MAXcxx . . $ `<external>/67164224788392828/limits.h:135:9`! == 0xffffffffffffffff) |
| 52 | # define Z_U8cxx . . $ `external/zlib/zutil.h:52:13`! unsigned long |
| 53 | # elif (ULLONG_MAX == 0xffffffffffffffff) |
| 54 | # define Z_U8 unsigned long long |
| 55 | # elif (ULONG_LONG_MAX == 0xffffffffffffffff) |
| 56 | # define Z_U8 unsigned long long |
| 57 | # elif (UINT_MAX == 0xffffffffffffffff) |
| 58 | # define Z_U8 unsigned |
| 59 | # endif |
| 60 | #endif |
| 61 | |
| 62 | extern z_constcxx . . $ `<external>/116306602880328527/zconf.h:249:13`! char * const z_errmsgcxx . . $ z_errmsg.[10]; /* indexed by 2-zlib_error */ |
| 63 | /* (size given to avoid silly warnings with Visual C++) */ |
| 64 | |
| 65 | #define ERR_MSGcxx . . $ `external/zlib/zutil.h:65:9`!(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] |
| 66 | |
| 67 | #define ERR_RETURNcxx . . $ `external/zlib/zutil.h:67:9`!(strm,err) \ |
| 68 | return (strm->msg = ERR_MSG(err), (err)) |
| 69 | /* To be used only when the state is known to be valid */ |
| 70 | |
| 71 | /* common constants */ |
| 72 | #if MAX_WBITScxx . . $ `<external>/116306602880328527/zconf.h:287:11`! < 9 || MAX_WBITScxx . . $ `<external>/116306602880328527/zconf.h:287:11`! > 15 |
| 73 | # error MAX_WBITS must be in 9..15 |
| 74 | #endif |
| 75 | #ifndef DEF_WBITS |
| 76 | # define DEF_WBITScxx . . $ `external/zlib/zutil.h:76:11`! MAX_WBITS |
| 77 | #endif |
| 78 | /* default windowBits for decompression. MAX_WBITS is for compression only */ |
| 79 | |
| 80 | #if MAX_MEM_LEVELcxx . . $ `<external>/116306602880328527/zconf.h:277:13`! >= 8 |
| 81 | # define DEF_MEM_LEVELcxx . . $ `external/zlib/zutil.h:81:11`! 8 |
| 82 | #else |
| 83 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
| 84 | #endif |
| 85 | /* default memLevel */ |
| 86 | |
| 87 | #define STORED_BLOCKcxx . . $ `external/zlib/zutil.h:87:9`! 0 |
| 88 | #define STATIC_TREEScxx . . $ `external/zlib/zutil.h:88:9`! 1 |
| 89 | #define DYN_TREEScxx . . $ `external/zlib/zutil.h:89:9`! 2 |
| 90 | /* The three kinds of block type */ |
| 91 | |
| 92 | #define MIN_MATCHcxx . . $ `external/zlib/zutil.h:92:9`! 3 |
| 93 | #define MAX_MATCHcxx . . $ `external/zlib/zutil.h:93:9`! 258 |
| 94 | /* The minimum and maximum match lengths */ |
| 95 | |
| 96 | #define PRESET_DICTcxx . . $ `external/zlib/zutil.h:96:9`! 0x20 /* preset dictionary flag in zlib header */ |
| 97 | |
| 98 | /* target dependencies */ |
| 99 | |
| 100 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) |
| 101 | # define OS_CODE 0x00 |
| 102 | # ifndef Z_SOLO |
| 103 | # if defined(__TURBOC__) || defined(__BORLANDC__) |
| 104 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) |
| 105 | /* Allow compilation with ANSI keywords only enabled */ |
| 106 | void _Cdecl farfree( void *block ); |
| 107 | void *_Cdecl farmalloc( unsigned long nbytes ); |
| 108 | # else |
| 109 | # include <alloc.h> |
| 110 | # endif |
| 111 | # else /* MSC or DJGPP */ |
| 112 | # include <malloc.h> |
| 113 | # endif |
| 114 | # endif |
| 115 | #endif |
| 116 | |
| 117 | #ifdef AMIGA |
| 118 | # define OS_CODE 1 |
| 119 | #endif |
| 120 | |
| 121 | #if defined(VAXC) || defined(VMS) |
| 122 | # define OS_CODE 2 |
| 123 | # define F_OPEN(name, mode) \ |
| 124 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") |
| 125 | #endif |
| 126 | |
| 127 | #ifdef __370__ |
| 128 | # if __TARGET_LIB__ < 0x20000000 |
| 129 | # define OS_CODE 4 |
| 130 | # elif __TARGET_LIB__ < 0x40000000 |
| 131 | # define OS_CODE 11 |
| 132 | # else |
| 133 | # define OS_CODE 8 |
| 134 | # endif |
| 135 | #endif |
| 136 | |
| 137 | #if defined(ATARI) || defined(atarist) |
| 138 | # define OS_CODE 5 |
| 139 | #endif |
| 140 | |
| 141 | #ifdef OS2 |
| 142 | # define OS_CODE 6 |
| 143 | # if defined(M_I86) && !defined(Z_SOLO) |
| 144 | # include <malloc.h> |
| 145 | # endif |
| 146 | #endif |
| 147 | |
| 148 | #if defined(MACOS) |
| 149 | # define OS_CODE 7 |
| 150 | #endif |
| 151 | |
| 152 | #if defined(__acorn) || defined(__riscos) |
| 153 | # define OS_CODE 13 |
| 154 | #endif |
| 155 | |
| 156 | #if defined(WIN32) && !defined(__CYGWIN__) |
| 157 | # define OS_CODE 10 |
| 158 | #endif |
| 159 | |
| 160 | #ifdef _BEOS_ |
| 161 | # define OS_CODE 16 |
| 162 | #endif |
| 163 | |
| 164 | #ifdef __TOS_OS400__ |
| 165 | # define OS_CODE 18 |
| 166 | #endif |
| 167 | |
| 168 | #ifdef __APPLE__ |
| 169 | # define OS_CODE 19 |
| 170 | #endif |
| 171 | |
| 172 | #if defined(__BORLANDC__) && !defined(MSDOS) |
| 173 | #pragma warn -8004 |
| 174 | #pragma warn -8008 |
| 175 | #pragma warn -8066 |
| 176 | #endif |
| 177 | |
| 178 | /* provide prototypes for these when building zlib without LFS */ |
| 179 | #ifndef Z_LARGE64 |
| 180 | ZEXTERNcxx . . $ `<external>/116306602880328527/zconf.h:389:11`! uLongcxx . . $ uLong# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! adler32_combine64cxx . . $ adler32_combine64(551f9fdfca9bf338).(uLongcxx . . $ uLong#, uLongcxx . . $ uLong#, z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!); |
| 181 | ZEXTERNcxx . . $ `<external>/116306602880328527/zconf.h:389:11`! uLongcxx . . $ uLong# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! crc32_combine64cxx . . $ crc32_combine64(551f9fdfca9bf338).(uLongcxx . . $ uLong#, uLongcxx . . $ uLong#, z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!); |
| 182 | ZEXTERNcxx . . $ `<external>/116306602880328527/zconf.h:389:11`! uLongcxx . . $ uLong# ZEXPORTcxx . . $ `<external>/116306602880328527/zconf.h:392:11`! crc32_combine_gen64cxx . . $ crc32_combine_gen64(2b379ed948b94b7b).(z_off64_tcxx . . $ `<external>/116306602880328527/zconf.h:531:11`!); |
| 183 | #endif |
| 184 | |
| 185 | /* common defaults */ |
| 186 | |
| 187 | #ifndef OS_CODE |
| 188 | # define OS_CODEcxx . . $ `external/zlib/zutil.h:188:11`! 3 /* assume Unix */ |
| 189 | #endif |
| 190 | |
| 191 | #ifndef F_OPEN |
| 192 | # define F_OPENcxx . . $ `external/zlib/zutil.h:192:11`!(name, mode) fopen((name), (mode)) |
| 193 | #endif |
| 194 | |
| 195 | /* functions */ |
| 196 | |
| 197 | #if defined(pyr) || defined(Z_SOLO) |
| 198 | # define NO_MEMCPY |
| 199 | #endif |
| 200 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) |
| 201 | /* Use our own functions for small and medium model with MSC <= 5.0. |
| 202 | * You may have to use the same strategy for Borland C (untested). |
| 203 | * The __SC__ check is for Symantec. |
| 204 | */ |
| 205 | # define NO_MEMCPY |
| 206 | #endif |
| 207 | #if defined(STDCcxx . . $ `<external>/116306602880328527/zconf.h:214:13`!) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) |
| 208 | # define HAVE_MEMCPYcxx . . $ `external/zlib/zutil.h:208:11`! |
| 209 | #endif |
| 210 | #ifdef HAVE_MEMCPYcxx . . $ `external/zlib/zutil.h:208:11`! |
| 211 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ |
| 212 | # define zmemcpy _fmemcpy |
| 213 | # define zmemcmp _fmemcmp |
| 214 | # define zmemzero(dest, len) _fmemset(dest, 0, len) |
| 215 | # else |
| 216 | # define zmemcpycxx . . $ `external/zlib/zutil.h:216:13`! memcpy |
| 217 | # define zmemcmpcxx . . $ `external/zlib/zutil.h:217:13`! memcmp |
| 218 | # define zmemzerocxx . . $ `external/zlib/zutil.h:218:13`!(dest, len) memset(dest, 0, len) |
| 219 | # endif |
| 220 | #else |
| 221 | void ZLIB_INTERNAL zmemcpy(void FAR *, const void FAR *, z_size_t); |
| 222 | int ZLIB_INTERNAL zmemcmp(const void FAR *, const void FAR *, z_size_t); |
| 223 | void ZLIB_INTERNAL zmemzero(void FAR *, z_size_t); |
| 224 | #endif |
| 225 | |
| 226 | /* Diagnostic functions */ |
| 227 | #ifdef ZLIB_DEBUG |
| 228 | # include <stdio.h> |
| 229 | extern int ZLIB_INTERNAL z_verbose; |
| 230 | extern void ZLIB_INTERNAL z_error(char *m); |
| 231 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} |
| 232 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} |
| 233 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} |
| 234 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} |
| 235 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} |
| 236 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} |
| 237 | #else |
| 238 | # define Assertcxx . . $ `external/zlib/zutil.h:238:11`!(cond,msg) |
| 239 | # define Tracecxx . . $ `external/zlib/zutil.h:239:11`!(x) |
| 240 | # define Tracevcxx . . $ `external/zlib/zutil.h:240:11`!(x) |
| 241 | # define Tracevvcxx . . $ `external/zlib/zutil.h:241:11`!(x) |
| 242 | # define Traceccxx . . $ `external/zlib/zutil.h:242:11`!(c,x) |
| 243 | # define Tracecvcxx . . $ `external/zlib/zutil.h:243:11`!(c,x) |
| 244 | #endif |
| 245 | |
| 246 | #ifndef Z_SOLO |
| 247 | voidpfcxx . . $ voidpf# ZLIB_INTERNALcxx . . $ `external/zlib/zutil.h:19:11`! zcalloccxx . . $ zcalloc(451d6dce5cb9fed4).(voidpfcxx . . $ voidpf# opaque, unsigned items, |
| 248 | unsigned size); |
| 249 | void ZLIB_INTERNALcxx . . $ `external/zlib/zutil.h:19:11`! zcfreecxx . . $ zcfree(6c58c5e2437d25a2).(voidpfcxx . . $ voidpf# opaque, voidpfcxx . . $ voidpf# ptr); |
| 250 | #endif |
| 251 | |
| 252 | #define ZALLOCcxx . . $ `external/zlib/zutil.h:252:9`!(strm, items, size) \ |
| 253 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) |
| 254 | #define ZFREEcxx . . $ `external/zlib/zutil.h:254:9`!(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) |
| 255 | #define TRY_FREEcxx . . $ `external/zlib/zutil.h:255:9`!(s, p) {if (p) ZFREE(s, p);} |
| 256 | |
| 257 | /* Reverse the bytes in a 32-bit value */ |
| 258 | #define ZSWAP32cxx . . $ `external/zlib/zutil.h:258:9`!(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ |
| 259 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) |
| 260 | |
| 261 | #ifdef Z_ONCE |
| 262 | /* |
| 263 | Create a local z_once() function depending on the availability of atomics. |
| 264 | */ |
| 265 | |
| 266 | /* Check for the availability of atomics. */ |
| 267 | #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ |
| 268 | !defined(__STDC_NO_ATOMICS__) |
| 269 | |
| 270 | #include <stdatomic.h> |
| 271 | typedef struct { |
| 272 | atomic_flag begun; |
| 273 | atomic_int done; |
| 274 | } z_once_t; |
| 275 | #define Z_ONCE_INIT {ATOMIC_FLAG_INIT, 0} |
| 276 | |
| 277 | /* |
| 278 | Run the provided init() function exactly once, even if multiple threads |
| 279 | invoke once() at the same time. The state must be a once_t initialized with |
| 280 | Z_ONCE_INIT. |
| 281 | */ |
| 282 | local void z_once(z_once_t *state, void (*init)(void)) { |
| 283 | if (!atomic_load(&state->done)) { |
| 284 | if (atomic_flag_test_and_set(&state->begun)) |
| 285 | while (!atomic_load(&state->done)) |
| 286 | ; |
| 287 | else { |
| 288 | init(); |
| 289 | atomic_store(&state->done, 1); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | #else /* no atomics */ |
| 295 | |
| 296 | #warning zlib not thread-safe |
| 297 | |
| 298 | typedef struct z_once_s { |
| 299 | volatile int begun; |
| 300 | volatile int done; |
| 301 | } z_once_t; |
| 302 | #define Z_ONCE_INIT {0, 0} |
| 303 | |
| 304 | /* Test and set. Alas, not atomic, but tries to limit the period of |
| 305 | vulnerability. */ |
| 306 | local int test_and_set(int volatile *flag) { |
| 307 | int was; |
| 308 | |
| 309 | was = *flag; |
| 310 | *flag = 1; |
| 311 | return was; |
| 312 | } |
| 313 | |
| 314 | /* Run the provided init() function once. This is not thread-safe. */ |
| 315 | local void z_once(z_once_t *state, void (*init)(void)) { |
| 316 | if (!state->done) { |
| 317 | if (test_and_set(&state->begun)) |
| 318 | while (!state->done) |
| 319 | ; |
| 320 | else { |
| 321 | init(); |
| 322 | state->done = 1; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | #endif /* ?atomics */ |
| 328 | |
| 329 | #endif /* Z_ONCE */ |
| 330 | |
| 331 | #endif /* ZUTIL_H */ |