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