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