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