00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ZUTIL_H
00014 #define ZUTIL_H
00015
00016 #define ZLIB_INTERNAL
00017 #include "zlib.h"
00018
00019 #ifdef STDC
00020 # include <stddef.h>
00021 # include <string.h>
00022 # include <stdlib.h>
00023 #endif
00024 #ifdef NO_ERRNO_H
00025 extern int errno;
00026 #else
00027 # include <errno.h>
00028 #endif
00029
00030 #ifndef local
00031 # define local static
00032 #endif
00033
00034
00035 typedef unsigned char uch;
00036 typedef uch FAR uchf;
00037 typedef unsigned short ush;
00038 typedef ush FAR ushf;
00039 typedef unsigned long ulg;
00040
00041 extern const char * const z_errmsg[10];
00042
00043
00044 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
00045
00046 #define ERR_RETURN(strm,err) \
00047 return (strm->msg = (char*)ERR_MSG(err), (err))
00048
00049
00050
00051
00052 #ifndef DEF_WBITS
00053 # define DEF_WBITS MAX_WBITS
00054 #endif
00055
00056
00057 #if MAX_MEM_LEVEL >= 8
00058 # define DEF_MEM_LEVEL 8
00059 #else
00060 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
00061 #endif
00062
00063
00064 #define STORED_BLOCK 0
00065 #define STATIC_TREES 1
00066 #define DYN_TREES 2
00067
00068
00069 #define MIN_MATCH 3
00070 #define MAX_MATCH 258
00071
00072
00073 #define PRESET_DICT 0x20
00074
00075
00076
00077 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
00078 # define OS_CODE 0x00
00079 # if defined(__TURBOC__) || defined(__BORLANDC__)
00080 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
00081
00082 void _Cdecl farfree( void *block );
00083 void *_Cdecl farmalloc( unsigned long nbytes );
00084 # else
00085 # include <alloc.h>
00086 # endif
00087 # else
00088 # include <malloc.h>
00089 # endif
00090 #endif
00091
00092 #ifdef AMIGA
00093 # define OS_CODE 0x01
00094 #endif
00095
00096 #if defined(VAXC) || defined(VMS)
00097 # define OS_CODE 0x02
00098 # define F_OPEN(name, mode) \
00099 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
00100 #endif
00101
00102 #if defined(ATARI) || defined(atarist)
00103 # define OS_CODE 0x05
00104 #endif
00105
00106 #ifdef OS2
00107 # define OS_CODE 0x06
00108 #endif
00109
00110 #if defined(MACOS) || defined(TARGET_OS_MAC)
00111 # define OS_CODE 0x07
00112 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
00113 # include <unix.h>
00114 # else
00115 # ifndef fdopen
00116 # define fdopen(fd,mode) NULL
00117 # endif
00118 # endif
00119 #endif
00120
00121 #ifdef TOPS20
00122 # define OS_CODE 0x0a
00123 #endif
00124
00125 #ifdef WIN32
00126 # ifndef __CYGWIN__
00127 # define OS_CODE 0x0b
00128 # endif
00129 #endif
00130
00131 #ifdef __50SERIES
00132 # define OS_CODE 0x0f
00133 #endif
00134
00135 #if defined(_BEOS_) || defined(RISCOS)
00136 # define fdopen(fd,mode) NULL
00137 #endif
00138
00139 #if (defined(_MSC_VER) && (_MSC_VER > 600))
00140 # if defined(_WIN32_WCE)
00141 # define fdopen(fd,mode) NULL
00142 # ifndef _PTRDIFF_T_DEFINED
00143 typedef int ptrdiff_t;
00144 # define _PTRDIFF_T_DEFINED
00145 # endif
00146 # else
00147 # define fdopen(fd,type) _fdopen(fd,type)
00148 # endif
00149 #endif
00150
00151
00152
00153 #ifndef OS_CODE
00154 # define OS_CODE 0x03
00155 #endif
00156
00157 #ifndef F_OPEN
00158 # define F_OPEN(name, mode) fopen((name), (mode))
00159 #endif
00160
00161
00162
00163 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
00164 # ifndef HAVE_VSNPRINTF
00165 # define HAVE_VSNPRINTF
00166 # endif
00167 #endif
00168 #if defined(__CYGWIN__)
00169 # ifndef HAVE_VSNPRINTF
00170 # define HAVE_VSNPRINTF
00171 # endif
00172 #endif
00173 #ifndef HAVE_VSNPRINTF
00174 # ifdef MSDOS
00175
00176
00177 # define NO_vsnprintf
00178 # endif
00179 # ifdef __TURBOC__
00180 # define NO_vsnprintf
00181 # endif
00182 # ifdef WIN32
00183
00184 # if !defined(vsnprintf) && !defined(NO_vsnprintf)
00185 # define vsnprintf _vsnprintf
00186 # endif
00187 # endif
00188 # ifdef __SASC
00189 # define NO_vsnprintf
00190 # endif
00191 #endif
00192
00193 #ifdef HAVE_STRERROR
00194 extern char *strerror OF((int));
00195 # define zstrerror(errnum) strerror(errnum)
00196 #else
00197 # define zstrerror(errnum) ""
00198 #endif
00199
00200 #if defined(pyr)
00201 # define NO_MEMCPY
00202 #endif
00203 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
00204
00205
00206
00207
00208 # define NO_MEMCPY
00209 #endif
00210 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
00211 # define HAVE_MEMCPY
00212 #endif
00213 #ifdef HAVE_MEMCPY
00214 # ifdef SMALL_MEDIUM
00215 # define zmemcpy _fmemcpy
00216 # define zmemcmp _fmemcmp
00217 # define zmemzero(dest, len) _fmemset(dest, 0, len)
00218 # else
00219 # define zmemcpy memcpy
00220 # define zmemcmp memcmp
00221 # define zmemzero(dest, len) memset(dest, 0, len)
00222 # endif
00223 #else
00224 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
00225 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
00226 extern void zmemzero OF((Bytef* dest, uInt len));
00227 #endif
00228
00229
00230 #ifdef DEBUG
00231 # include <stdio.h>
00232 extern int z_verbose;
00233 extern void z_error OF((char *m));
00234 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
00235 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
00236 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
00237 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
00238 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
00239 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
00240 #else
00241 # define Assert(cond,msg)
00242 # define Trace(x)
00243 # define Tracev(x)
00244 # define Tracevv(x)
00245 # define Tracec(c,x)
00246 # define Tracecv(c,x)
00247 #endif
00248
00249
00250 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
00251 void zcfree OF((voidpf opaque, voidpf ptr));
00252
00253 #define ZALLOC(strm, items, size) \
00254 (*((strm)->zalloc))((strm)->opaque, (items), (size))
00255 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
00256 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
00257
00258 #endif