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