10Sstevel@tonic-gate /* 2*3886Sahl * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate 6*3886Sahl /* zutil.h -- internal interface and configuration of the compression library 7*3886Sahl * Copyright (C) 1995-2005 Jean-loup Gailly. 80Sstevel@tonic-gate * For conditions of distribution and use, see copyright notice in zlib.h 90Sstevel@tonic-gate */ 100Sstevel@tonic-gate 11*3886Sahl /* WARNING: this file should *not* be used by applications. It is 12*3886Sahl part of the implementation of the compression library and is 13*3886Sahl subject to change. Applications should only use zlib.h. 14*3886Sahl */ 15*3886Sahl 16*3886Sahl #ifndef _ZUTIL_H 17*3886Sahl #define _ZUTIL_H 180Sstevel@tonic-gate 190Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 200Sstevel@tonic-gate 21*3886Sahl #define ZLIB_INTERNAL 22*3886Sahl #include "zlib.h" 230Sstevel@tonic-gate 24*3886Sahl #ifdef STDC 25*3886Sahl # ifndef _WIN32_WCE 26*3886Sahl # include <stddef.h> 27*3886Sahl # endif 28*3886Sahl # include <string.h> 29*3886Sahl # include <stdlib.h> 300Sstevel@tonic-gate #endif 31*3886Sahl #ifdef NO_ERRNO_H 32*3886Sahl # ifdef _WIN32_WCE 33*3886Sahl /* The Microsoft C Run-Time Library for Windows CE doesn't have 34*3886Sahl * errno. We define it as a global variable to simplify porting. 35*3886Sahl * Its value is always 0 and should not be used. We rename it to 36*3886Sahl * avoid conflict with other libraries that use the same workaround. 37*3886Sahl */ 38*3886Sahl # define errno z_errno 39*3886Sahl # endif 40*3886Sahl extern int errno; 41*3886Sahl #else 42*3886Sahl # ifndef _WIN32_WCE 43*3886Sahl # include <sys/errno.h> 44*3886Sahl # endif 45*3886Sahl #endif 460Sstevel@tonic-gate 470Sstevel@tonic-gate #ifndef local 480Sstevel@tonic-gate # define local static 490Sstevel@tonic-gate #endif 50*3886Sahl /* compile with -Dlocal if your debugger can't find static symbols */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate typedef unsigned char uch; 530Sstevel@tonic-gate typedef uch FAR uchf; 540Sstevel@tonic-gate typedef unsigned short ush; 550Sstevel@tonic-gate typedef ush FAR ushf; 560Sstevel@tonic-gate typedef unsigned long ulg; 570Sstevel@tonic-gate 58*3886Sahl extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 59*3886Sahl /* (size given to avoid silly warnings with Visual C++) */ 60*3886Sahl 61*3886Sahl #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 62*3886Sahl 63*3886Sahl #define ERR_RETURN(strm,err) \ 64*3886Sahl return (strm->msg = (char*)ERR_MSG(err), (err)) 65*3886Sahl /* To be used only when the state is known to be valid */ 66*3886Sahl 670Sstevel@tonic-gate /* common constants */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate #ifndef DEF_WBITS 700Sstevel@tonic-gate # define DEF_WBITS MAX_WBITS 710Sstevel@tonic-gate #endif 720Sstevel@tonic-gate /* default windowBits for decompression. MAX_WBITS is for compression only */ 730Sstevel@tonic-gate 740Sstevel@tonic-gate #if MAX_MEM_LEVEL >= 8 750Sstevel@tonic-gate # define DEF_MEM_LEVEL 8 760Sstevel@tonic-gate #else 770Sstevel@tonic-gate # define DEF_MEM_LEVEL MAX_MEM_LEVEL 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate /* default memLevel */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate #define STORED_BLOCK 0 820Sstevel@tonic-gate #define STATIC_TREES 1 830Sstevel@tonic-gate #define DYN_TREES 2 840Sstevel@tonic-gate /* The three kinds of block type */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate #define MIN_MATCH 3 870Sstevel@tonic-gate #define MAX_MATCH 258 880Sstevel@tonic-gate /* The minimum and maximum match lengths */ 890Sstevel@tonic-gate 900Sstevel@tonic-gate #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 910Sstevel@tonic-gate 92*3886Sahl /* target dependencies */ 93*3886Sahl 94*3886Sahl #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 95*3886Sahl # define OS_CODE 0x00 96*3886Sahl # if defined(__TURBOC__) || defined(__BORLANDC__) 97*3886Sahl # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 98*3886Sahl /* Allow compilation with ANSI keywords only enabled */ 99*3886Sahl void _Cdecl farfree( void *block ); 100*3886Sahl void *_Cdecl farmalloc( unsigned long nbytes ); 101*3886Sahl # else 102*3886Sahl # include <alloc.h> 103*3886Sahl # endif 104*3886Sahl # else /* MSC or DJGPP */ 105*3886Sahl # include <malloc.h> 106*3886Sahl # endif 107*3886Sahl #endif 108*3886Sahl 109*3886Sahl #ifdef AMIGA 110*3886Sahl # define OS_CODE 0x01 111*3886Sahl #endif 112*3886Sahl 113*3886Sahl #if defined(VAXC) || defined(VMS) 114*3886Sahl # define OS_CODE 0x02 115*3886Sahl # define F_OPEN(name, mode) \ 116*3886Sahl fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 117*3886Sahl #endif 118*3886Sahl 119*3886Sahl #if defined(ATARI) || defined(atarist) 120*3886Sahl # define OS_CODE 0x05 121*3886Sahl #endif 122*3886Sahl 123*3886Sahl #ifdef OS2 124*3886Sahl # define OS_CODE 0x06 125*3886Sahl # ifdef M_I86 126*3886Sahl #include <malloc.h> 127*3886Sahl # endif 128*3886Sahl #endif 129*3886Sahl 130*3886Sahl #if defined(MACOS) || defined(TARGET_OS_MAC) 131*3886Sahl # define OS_CODE 0x07 132*3886Sahl # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 133*3886Sahl # include <unix.h> /* for fdopen */ 134*3886Sahl # else 135*3886Sahl # ifndef fdopen 136*3886Sahl # define fdopen(fd,mode) NULL /* No fdopen() */ 137*3886Sahl # endif 138*3886Sahl # endif 139*3886Sahl #endif 140*3886Sahl 141*3886Sahl #ifdef TOPS20 142*3886Sahl # define OS_CODE 0x0a 143*3886Sahl #endif 144*3886Sahl 145*3886Sahl #ifdef WIN32 146*3886Sahl # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 147*3886Sahl # define OS_CODE 0x0b 148*3886Sahl # endif 149*3886Sahl #endif 150*3886Sahl 151*3886Sahl #ifdef __50SERIES /* Prime/PRIMOS */ 152*3886Sahl # define OS_CODE 0x0f 153*3886Sahl #endif 154*3886Sahl 155*3886Sahl #if defined(_BEOS_) || defined(RISCOS) 156*3886Sahl # define fdopen(fd,mode) NULL /* No fdopen() */ 157*3886Sahl #endif 158*3886Sahl 159*3886Sahl #if (defined(_MSC_VER) && (_MSC_VER > 600)) 160*3886Sahl # if defined(_WIN32_WCE) 161*3886Sahl # define fdopen(fd,mode) NULL /* No fdopen() */ 162*3886Sahl # ifndef _PTRDIFF_T_DEFINED 163*3886Sahl typedef int ptrdiff_t; 164*3886Sahl # define _PTRDIFF_T_DEFINED 165*3886Sahl # endif 166*3886Sahl # else 167*3886Sahl # define fdopen(fd,type) _fdopen(fd,type) 168*3886Sahl # endif 169*3886Sahl #endif 170*3886Sahl 171*3886Sahl /* common defaults */ 172*3886Sahl 173*3886Sahl #ifndef OS_CODE 174*3886Sahl # define OS_CODE 0x03 /* assume Unix */ 175*3886Sahl #endif 1760Sstevel@tonic-gate 177*3886Sahl #ifndef F_OPEN 178*3886Sahl # define F_OPEN(name, mode) fopen((name), (mode)) 179*3886Sahl #endif 180*3886Sahl 181*3886Sahl /* functions */ 182*3886Sahl 183*3886Sahl #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 184*3886Sahl # ifndef HAVE_VSNPRINTF 185*3886Sahl # define HAVE_VSNPRINTF 186*3886Sahl # endif 187*3886Sahl #endif 188*3886Sahl #if defined(__CYGWIN__) 189*3886Sahl # ifndef HAVE_VSNPRINTF 190*3886Sahl # define HAVE_VSNPRINTF 191*3886Sahl # endif 192*3886Sahl #endif 193*3886Sahl #ifndef HAVE_VSNPRINTF 194*3886Sahl # ifdef MSDOS 195*3886Sahl /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 196*3886Sahl but for now we just assume it doesn't. */ 197*3886Sahl # define NO_vsnprintf 198*3886Sahl # endif 199*3886Sahl # ifdef __TURBOC__ 200*3886Sahl # define NO_vsnprintf 201*3886Sahl # endif 202*3886Sahl # ifdef WIN32 203*3886Sahl /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 204*3886Sahl # if !defined(vsnprintf) && !defined(NO_vsnprintf) 205*3886Sahl # define vsnprintf _vsnprintf 206*3886Sahl # endif 207*3886Sahl # endif 208*3886Sahl # ifdef __SASC 209*3886Sahl # define NO_vsnprintf 210*3886Sahl # endif 211*3886Sahl #endif 212*3886Sahl #ifdef VMS 213*3886Sahl # define NO_vsnprintf 214*3886Sahl #endif 215*3886Sahl 216*3886Sahl #if defined(pyr) 217*3886Sahl # define NO_MEMCPY 218*3886Sahl #endif 219*3886Sahl #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 220*3886Sahl /* Use our own functions for small and medium model with MSC <= 5.0. 221*3886Sahl * You may have to use the same strategy for Borland C (untested). 222*3886Sahl * The __SC__ check is for Symantec. 223*3886Sahl */ 224*3886Sahl # define NO_MEMCPY 225*3886Sahl #endif 226*3886Sahl #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 227*3886Sahl # define HAVE_MEMCPY 228*3886Sahl #endif 229*3886Sahl #ifdef HAVE_MEMCPY 230*3886Sahl # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 231*3886Sahl # define zmemcpy _fmemcpy 232*3886Sahl # define zmemcmp _fmemcmp 233*3886Sahl # define zmemzero(dest, len) _fmemset(dest, 0, len) 234*3886Sahl # else 235*3886Sahl # define zmemcpy memcpy 236*3886Sahl # define zmemcmp memcmp 237*3886Sahl # define zmemzero(dest, len) memset(dest, 0, len) 238*3886Sahl # endif 239*3886Sahl #else 240*3886Sahl extern void zmemcpy OF((void* dest, const void* source, uInt len)); 241*3886Sahl extern int zmemcmp OF((const void* s1, const void* s2, uInt len)); 242*3886Sahl extern void zmemzero OF((void* dest, uInt len)); 243*3886Sahl #endif 244*3886Sahl 245*3886Sahl /* Diagnostic functions */ 246*3886Sahl #ifdef DEBUG 247*3886Sahl # include <stdio.h> 248*3886Sahl extern int z_verbose; 249*3886Sahl extern void z_error OF((char *m)); 250*3886Sahl # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 251*3886Sahl # define Trace(x) {if (z_verbose>=0) fprintf x ;} 252*3886Sahl # define Tracev(x) {if (z_verbose>0) fprintf x ;} 253*3886Sahl # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 254*3886Sahl # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 255*3886Sahl # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 256*3886Sahl #else 257*3886Sahl # define Assert(cond,msg) 258*3886Sahl # define Trace(x) 259*3886Sahl # define Tracev(x) 260*3886Sahl # define Tracevv(x) 261*3886Sahl # define Tracec(c,x) 262*3886Sahl # define Tracecv(c,x) 263*3886Sahl #endif 264*3886Sahl 265*3886Sahl 266*3886Sahl voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 267*3886Sahl void zcfree OF((voidpf opaque, voidpf ptr)); 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate #define ZALLOC(strm, items, size) \ 2700Sstevel@tonic-gate (*((strm)->zalloc))((strm)->opaque, (items), (size)) 2710Sstevel@tonic-gate #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 2720Sstevel@tonic-gate #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 2730Sstevel@tonic-gate 274*3886Sahl #endif /* _ZUTIL_H */ 275