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