annotate lib/zlib/zutil.h @ 0:8b8875f5b359

Initial commit
author Nomad
date Fri, 05 Oct 2012 16:07:14 +0200
parents
children
rev   line source
0
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1 /* zutil.h -- internal interface and configuration of the compression library
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2 * Copyright (C) 1995-1998 Jean-loup Gailly.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4 */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6 /* WARNING: this file should *not* be used by applications. It is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
7 part of the implementation of the compression library and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
8 subject to change. Applications should only use zlib.h.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
9 */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
10
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
11 /* @(#) $Id$ */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
12
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
13 #ifndef _Z_UTIL_H
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
14 #define _Z_UTIL_H
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
15
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
16 #include "zlib.h"
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
17
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
18 #ifdef STDC
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
19 # include <stddef.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
20 # include <string.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
21 # include <stdlib.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
22 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
23 #ifdef NO_ERRNO_H
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
24 extern int errno;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
25 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
26 # include <errno.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
27 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
28
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
29 #ifndef local
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
30 # define local static
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
31 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
32 /* compile with -Dlocal if your debugger can't find static symbols */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
33
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
34 typedef unsigned char uch;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
35 typedef uch FAR uchf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
36 typedef unsigned short ush;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
37 typedef ush FAR ushf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
38 typedef unsigned long ulg;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
39
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
40 extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
41 /* (size given to avoid silly warnings with Visual C++) */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
42
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
43 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
44
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
45 #define ERR_RETURN(strm,err) \
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
46 return (strm->msg = (char*)ERR_MSG(err), (err))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
47 /* To be used only when the state is known to be valid */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
48
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
49 /* common constants */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
50
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
51 #ifndef DEF_WBITS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
52 # define DEF_WBITS MAX_WBITS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
53 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
54 /* default windowBits for decompression. MAX_WBITS is for compression only */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
55
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
56 #if MAX_MEM_LEVEL >= 8
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
57 # define DEF_MEM_LEVEL 8
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
58 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
59 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
60 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
61 /* default memLevel */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
62
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
63 #define STORED_BLOCK 0
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
64 #define STATIC_TREES 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
65 #define DYN_TREES 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
66 /* The three kinds of block type */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
67
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
68 #define MIN_MATCH 3
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
69 #define MAX_MATCH 258
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
70 /* The minimum and maximum match lengths */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
71
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
72 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
73
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
74 /* target dependencies */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
75
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
76 #ifdef MSDOS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
77 # define OS_CODE 0x00
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
78 # if defined(__TURBOC__) || defined(__BORLANDC__)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
79 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
80 /* Allow compilation with ANSI keywords only enabled */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
81 void _Cdecl farfree( void *block );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
82 void *_Cdecl farmalloc( unsigned long nbytes );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
83 # else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
84 # include <alloc.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
85 # endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
86 # else /* MSC or DJGPP */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
87 # include <malloc.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
88 # endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
89 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
90
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
91 #ifdef OS2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
92 # define OS_CODE 0x06
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
93 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
94
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
95 #ifdef WIN32 /* Window 95 & Windows NT */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
96 # define OS_CODE 0x0b
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
97 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
98
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
99 #if defined(VAXC) || defined(VMS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
100 # define OS_CODE 0x02
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
101 # define F_OPEN(name, mode) \
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
102 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
103 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
104
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
105 #ifdef AMIGA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
106 # define OS_CODE 0x01
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
107 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
108
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
109 #if defined(ATARI) || defined(atarist)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
110 # define OS_CODE 0x05
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
111 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
112
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
113 #if defined(MACOS) || defined(TARGET_OS_MAC)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
114 # define OS_CODE 0x07
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
115 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
116 # include <unix.h> /* for fdopen */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
117 # else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
118 # ifndef fdopen
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
119 # define fdopen(fd,mode) NULL /* No fdopen() */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
120 # endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
121 # endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
122 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
123
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
124 #ifdef __50SERIES /* Prime/PRIMOS */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
125 # define OS_CODE 0x0F
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
126 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
127
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
128 #ifdef TOPS20
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
129 # define OS_CODE 0x0a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
130 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
131
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
132 #if defined(_BEOS_) || defined(RISCOS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
133 # define fdopen(fd,mode) NULL /* No fdopen() */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
134 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
135
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
136 #if (defined(_MSC_VER) && (_MSC_VER > 600))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
137 # define fdopen(fd,type) _fdopen(fd,type)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
138 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
139
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
140
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
141 /* Common defaults */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
142
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
143 #ifndef OS_CODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
144 # define OS_CODE 0x03 /* assume Unix */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
145 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
146
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
147 #ifndef F_OPEN
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
148 # define F_OPEN(name, mode) fopen((name), (mode))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
149 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
150
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
151 /* functions */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
152
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
153 #ifdef HAVE_STRERROR
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
154 extern char *strerror OF((int));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
155 # define zstrerror(errnum) strerror(errnum)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
156 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
157 # define zstrerror(errnum) ""
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
158 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
159
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
160 #if defined(pyr)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
161 # define NO_MEMCPY
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
162 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
163 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
164 /* Use our own functions for small and medium model with MSC <= 5.0.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
165 * You may have to use the same strategy for Borland C (untested).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
166 * The __SC__ check is for Symantec.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
167 */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
168 # define NO_MEMCPY
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
169 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
170 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
171 # define HAVE_MEMCPY
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
172 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
173 #ifdef HAVE_MEMCPY
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
174 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
175 # define zmemcpy _fmemcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
176 # define zmemcmp _fmemcmp
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
177 # define zmemzero(dest, len) _fmemset(dest, 0, len)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
178 # else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
179 # define zmemcpy memcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
180 # define zmemcmp memcmp
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
181 # define zmemzero(dest, len) memset(dest, 0, len)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
182 # endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
183 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
184 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
185 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
186 extern void zmemzero OF((Bytef* dest, uInt len));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
187 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
188
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
189 /* Diagnostic functions */
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
190 #ifdef DEBUG
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
191 # include <stdio.h>
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
192 extern int z_verbose;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
193 extern void z_error OF((char *m));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
194 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
195 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
196 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
197 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
198 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
199 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
200 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
201 # define Assert(cond,msg)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
202 # define Trace(x)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
203 # define Tracev(x)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
204 # define Tracevv(x)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
205 # define Tracec(c,x)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
206 # define Tracecv(c,x)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
207 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
208
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
209
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
210 typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
211 uInt len));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
212 voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
213 void zcfree OF((voidpf opaque, voidpf ptr));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
214
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
215 #define ZALLOC(strm, items, size) \
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
216 (*((strm)->zalloc))((strm)->opaque, (items), (size))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
217 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
218 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
219
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
220 #endif /* _Z_UTIL_H */