1 /* zutil.h -- internal interface and configuration of the compression library 2 * Copyright (C) 1995-2022 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_H 15 16 #ifdef HAVE_HIDDEN 17 # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 #else 19 # define ZLIB_INTERNAL 20 #endif 21 22 #include "zlib.h" 23 24 #if defined(STDC) && !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 #ifdef NO_ERRNO_H 32 # ifdef _WIN32_WCE 33 /* The Microsoft C Run-Time Library for Windows CE doesn't have 34 * errno. We define it as a global variable to simplify porting. 35 * Its value is always 0 and should not be used. We rename it to 36 * avoid conflict with other libraries that use the same workaround. 37 */ 38 # define errno z_errno 39 # endif 40 extern int errno; 41 #else 42 # ifndef _WIN32_WCE 43 # include <errno.h> 44 # endif 45 #endif 46 47 #ifndef local 48 # define local static 49 #endif 50 /* since "static" is used to mean two completely different things in C, we 51 define "local" for the non-static meaning of "static", for readability 52 (compile with -Dlocal if your debugger can't find static symbols) */ 53 54 typedef unsigned char uch; 55 typedef uch FAR uchf; 56 typedef unsigned short ush; 57 typedef ush FAR ushf; 58 typedef unsigned long ulg; 59 60 #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC) 61 # include <limits.h> 62 # if (ULONG_MAX == 0xffffffffffffffff) 63 # define Z_U8 unsigned long 64 # elif (ULLONG_MAX == 0xffffffffffffffff) 65 # define Z_U8 unsigned long long 66 # elif (UINT_MAX == 0xffffffffffffffff) 67 # define Z_U8 unsigned 68 # endif 69 #endif 70 71 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 72 /* (size given to avoid silly warnings with Visual C++) */ 73 74 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 75 76 #define ERR_RETURN(strm,err) \ 77 return (strm->msg = ERR_MSG(err), (err)) 78 /* To be used only when the state is known to be valid */ 79 80 /* common constants */ 81 82 #ifndef DEF_WBITS 83 # define DEF_WBITS MAX_WBITS 84 #endif 85 /* default windowBits for decompression. MAX_WBITS is for compression only */ 86 87 #if MAX_MEM_LEVEL >= 8 88 # define DEF_MEM_LEVEL 8 89 #else 90 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 91 #endif 92 /* default memLevel */ 93 94 #define STORED_BLOCK 0 95 #define STATIC_TREES 1 96 #define DYN_TREES 2 97 /* The three kinds of block type */ 98 99 #define MIN_MATCH 3 100 #define MAX_MATCH 258 101 /* The minimum and maximum match lengths */ 102 103 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 104 105 /* target dependencies */ 106 107 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 108 # define OS_CODE 0x00 109 # ifndef Z_SOLO 110 # if defined(__TURBOC__) || defined(__BORLANDC__) 111 # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 112 /* Allow compilation with ANSI keywords only enabled */ 113 void _Cdecl farfree( void *block ); 114 void *_Cdecl farmalloc( unsigned long nbytes ); 115 # else 116 # include <alloc.h> 117 # endif 118 # else /* MSC or DJGPP */ 119 # include <malloc.h> 120 # endif 121 # endif 122 #endif 123 124 #ifdef AMIGA 125 # define OS_CODE 1 126 #endif 127 128 #if defined(VAXC) || defined(VMS) 129 # define OS_CODE 2 130 # define F_OPEN(name, mode) \ 131 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 132 #endif 133 134 #ifdef __370__ 135 # if __TARGET_LIB__ < 0x20000000 136 # define OS_CODE 4 137 # elif __TARGET_LIB__ < 0x40000000 138 # define OS_CODE 11 139 # else 140 # define OS_CODE 8 141 # endif 142 #endif 143 144 #if defined(ATARI) || defined(atarist) 145 # define OS_CODE 5 146 #endif 147 148 #ifdef OS2 149 # define OS_CODE 6 150 # if defined(M_I86) && !defined(Z_SOLO) 151 # include <malloc.h> 152 # endif 153 #endif 154 155 #if defined(MACOS) 156 # define OS_CODE 7 157 #endif 158 159 #ifdef __acorn 160 # define OS_CODE 13 161 #endif 162 163 #if defined(WIN32) && !defined(__CYGWIN__) 164 # define OS_CODE 10 165 #endif 166 167 #ifdef _BEOS_ 168 # define OS_CODE 16 169 #endif 170 171 #ifdef __TOS_OS400__ 172 # define OS_CODE 18 173 #endif 174 175 #ifdef __APPLE__ 176 # define OS_CODE 19 177 #endif 178 179 #if defined(__BORLANDC__) && !defined(MSDOS) 180 #pragma warn -8004 181 #pragma warn -8008 182 #pragma warn -8066 183 #endif 184 185 /* provide prototypes for these when building zlib without LFS */ 186 #if !defined(_WIN32) && \ 187 (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 188 ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); 189 ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); 190 ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); 191 #endif 192 193 /* common defaults */ 194 195 #ifndef OS_CODE 196 # define OS_CODE 3 /* assume Unix */ 197 #endif 198 199 #ifndef F_OPEN 200 # define F_OPEN(name, mode) fopen((name), (mode)) 201 #endif 202 203 /* functions */ 204 205 #if defined(pyr) || defined(Z_SOLO) 206 # define NO_MEMCPY 207 #endif 208 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 209 /* Use our own functions for small and medium model with MSC <= 5.0. 210 * You may have to use the same strategy for Borland C (untested). 211 * The __SC__ check is for Symantec. 212 */ 213 # define NO_MEMCPY 214 #endif 215 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 216 # define HAVE_MEMCPY 217 #endif 218 #ifdef HAVE_MEMCPY 219 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 220 # define zmemcpy _fmemcpy 221 # define zmemcmp _fmemcmp 222 # define zmemzero(dest, len) _fmemset(dest, 0, len) 223 # else 224 # define zmemcpy memcpy 225 # define zmemcmp memcmp 226 # define zmemzero(dest, len) memset(dest, 0, len) 227 # endif 228 #else 229 void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); 230 int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); 231 void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); 232 #endif 233 234 /* Diagnostic functions */ 235 #ifdef ZLIB_DEBUG 236 # include <stdio.h> 237 extern int ZLIB_INTERNAL z_verbose; 238 extern void ZLIB_INTERNAL z_error(char *m); 239 # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 240 # define Trace(x) {if (z_verbose>=0) fprintf x ;} 241 # define Tracev(x) {if (z_verbose>0) fprintf x ;} 242 # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 243 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 244 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 245 #else 246 # define Assert(cond,msg) 247 # define Trace(x) 248 # define Tracev(x) 249 # define Tracevv(x) 250 # define Tracec(c,x) 251 # define Tracecv(c,x) 252 #endif 253 254 #ifndef Z_SOLO 255 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, 256 unsigned size); 257 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); 258 #endif 259 260 #define ZALLOC(strm, items, size) \ 261 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 262 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 263 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 264 265 /* Reverse the bytes in a 32-bit value */ 266 #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 267 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 268 269 #ifdef _MSC_VER 270 #define zalign(x) __declspec(align(x)) 271 #else 272 #define zalign(x) __attribute__((aligned((x)))) 273 #endif 274 275 #endif /* ZUTIL_H */ 276