blob: 76de8bd4ee4289378b5d477859bccaff96c2b70e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Sun designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Sun in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
25 */
26
27/*
28 * This file is available under and governed by the GNU General Public
29 * License version 2 only, as published by the Free Software Foundation.
30 * However, the following notice accompanied the original version of this
31 * file and, per its terms, should not be removed:
32 *
33 * zutil.h -- internal interface and configuration of the compression library
34 * Copyright (C) 1995-1998 Jean-loup Gailly.
35 * For conditions of distribution and use, see copyright notice in zlib.h
36 */
37
38/* WARNING: this file should *not* be used by applications. It is
39 part of the implementation of the compression library and is
40 subject to change. Applications should only use zlib.h.
41 */
42
43#ifndef _Z_UTIL_H
44#define _Z_UTIL_H
45
46#include "zlib.h"
47
48#ifdef STDC
49# include <stddef.h>
50# include <string.h>
51# include <stdlib.h>
52#endif
53#ifdef NO_ERRNO_H
54 extern int errno;
55#else
56# include <errno.h>
57#endif
58
59#ifndef local
60# define local static
61#endif
62/* compile with -Dlocal if your debugger can't find static symbols */
63
64typedef unsigned char uch;
65typedef uch FAR uchf;
66typedef unsigned short ush;
67typedef ush FAR ushf;
68typedef unsigned long ulg;
69#ifdef NEVER
70#ifndef _LP64
71typedef unsigned long ulg;
72#else
73typedef unsigned int ulg;
74#endif
75#endif
76
77extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
78/* (size given to avoid silly warnings with Visual C++) */
79
80#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
81
82#define ERR_RETURN(strm,err) \
83 return (strm->msg = (char*)ERR_MSG(err), (err))
84/* To be used only when the state is known to be valid */
85
86 /* common constants */
87
88#ifndef DEF_WBITS
89# define DEF_WBITS MAX_WBITS
90#endif
91/* default windowBits for decompression. MAX_WBITS is for compression only */
92
93#if MAX_MEM_LEVEL >= 8
94# define DEF_MEM_LEVEL 8
95#else
96# define DEF_MEM_LEVEL MAX_MEM_LEVEL
97#endif
98/* default memLevel */
99
100#define STORED_BLOCK 0
101#define STATIC_TREES 1
102#define DYN_TREES 2
103/* The three kinds of block type */
104
105#define MIN_MATCH 3
106#define MAX_MATCH 258
107/* The minimum and maximum match lengths */
108
109#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
110
111 /* target dependencies */
112
113#ifdef MSDOS
114# define OS_CODE 0x00
115# if defined(__TURBOC__) || defined(__BORLANDC__)
116# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
117 /* Allow compilation with ANSI keywords only enabled */
118 void _Cdecl farfree( void *block );
119 void *_Cdecl farmalloc( unsigned long nbytes );
120# else
121# include <alloc.h>
122# endif
123# else /* MSC or DJGPP */
124# include <malloc.h>
125# endif
126#endif
127
128#ifdef OS2
129# define OS_CODE 0x06
130#endif
131
132#ifdef WIN32 /* Window 95 & Windows NT */
133# define OS_CODE 0x0b
134#endif
135
136#if defined(VAXC) || defined(VMS)
137# define OS_CODE 0x02
138# define F_OPEN(name, mode) \
139 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
140#endif
141
142#ifdef AMIGA
143# define OS_CODE 0x01
144#endif
145
146#if defined(ATARI) || defined(atarist)
147# define OS_CODE 0x05
148#endif
149
150#if defined(MACOS) || defined(TARGET_OS_MAC)
151# define OS_CODE 0x07
152# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
153# include <unix.h> /* for fdopen */
154# else
155# ifndef fdopen
156# define fdopen(fd,mode) NULL /* No fdopen() */
157# endif
158# endif
159#endif
160
161#ifdef __50SERIES /* Prime/PRIMOS */
162# define OS_CODE 0x0F
163#endif
164
165#ifdef TOPS20
166# define OS_CODE 0x0a
167#endif
168
169#if defined(_BEOS_) || defined(RISCOS)
170# define fdopen(fd,mode) NULL /* No fdopen() */
171#endif
172
173#if (defined(_MSC_VER) && (_MSC_VER > 600))
174# define fdopen(fd,type) _fdopen(fd,type)
175#endif
176
177
178 /* Common defaults */
179
180#ifndef OS_CODE
181# define OS_CODE 0x03 /* assume Unix */
182#endif
183
184#ifndef F_OPEN
185# define F_OPEN(name, mode) fopen((name), (mode))
186#endif
187
188 /* functions */
189
190#ifdef HAVE_STRERROR
191 extern char *strerror OF((int));
192# define zstrerror(errnum) strerror(errnum)
193#else
194# define zstrerror(errnum) ""
195#endif
196
197#if defined(pyr)
198# define NO_MEMCPY
199#endif
200#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
201 /* Use our own functions for small and medium model with MSC <= 5.0.
202 * You may have to use the same strategy for Borland C (untested).
203 * The __SC__ check is for Symantec.
204 */
205# define NO_MEMCPY
206#endif
207#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
208# define HAVE_MEMCPY
209#endif
210#ifdef HAVE_MEMCPY
211# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
212# define zmemcpy _fmemcpy
213# define zmemcmp _fmemcmp
214# define zmemzero(dest, len) _fmemset(dest, 0, len)
215# else
216# define zmemcpy memcpy
217# define zmemcmp memcmp
218# define zmemzero(dest, len) memset(dest, 0, len)
219# endif
220#else
221 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
222 extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
223 extern void zmemzero OF((Bytef* dest, uInt len));
224#endif
225
226/* Diagnostic functions */
227#ifdef DEBUG
228# include <stdio.h>
229 extern int z_verbose;
230 extern void z_error OF((char *m));
231# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
232# define Trace(x) {if (z_verbose>=0) fprintf x ;}
233# define Tracev(x) {if (z_verbose>0) fprintf x ;}
234# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
235# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
236# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
237#else
238# define Assert(cond,msg)
239# define Trace(x)
240# define Tracev(x)
241# define Tracevv(x)
242# define Tracec(c,x)
243# define Tracecv(c,x)
244#endif
245
246
247typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
248 uInt len));
249voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
250void zcfree OF((voidpf opaque, voidpf ptr));
251
252#define ZALLOC(strm, items, size) \
253 (*((strm)->zalloc))((strm)->opaque, (items), (size))
254#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
255#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
256
257#endif /* _Z_UTIL_H */