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