]> git.lizzy.rs Git - zlib.git/blob - zutil.h
zlib 0.93
[zlib.git] / zutil.h
1 /* zutil.h -- internal interface and configuration of the compression library
2  * Copyright (C) 1995 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: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp $ */
12
13 #ifndef _Z_UTIL_H
14 #define _Z_UTIL_H
15
16 #include "zlib.h"
17
18 /* #ifndef __GNUC__   disable inline for now */
19 #  define inline
20 /* #endif */
21
22 #ifdef MSDOS
23 #   include <stddef.h>
24 #   include <errno.h>
25 #else
26     extern int errno;
27 #endif
28 #ifdef STDC
29 #  include <string.h>
30 #endif
31
32 #ifndef local
33 #  define local static
34 #endif
35 /* compile with -Dlocal if your debugger can't find static symbols */
36
37 typedef unsigned char  uch;
38 typedef unsigned short ush;
39 typedef unsigned long  ulg;
40
41 extern char *z_errmsg[]; /* indexed by 1-zlib_error */
42
43 #define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
44 /* To be used only when the state is known to be valid */
45
46         /* common constants */
47
48 #define DEFLATED   8
49
50 #define DEF_WBITS 15
51 /* default windowBits for decompression. MAX_WBITS is for compression only */
52
53 #if MAX_MEM_LEVEL >= 8
54 #  define DEF_MEM_LEVEL 8
55 #else
56 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
57 #endif
58 /* default memLevel */
59
60 #define STORED_BLOCK 0
61 #define STATIC_TREES 1
62 #define DYN_TREES    2
63 /* The three kinds of block type */
64
65 #define MIN_MATCH  3
66 #define MAX_MATCH  258
67 /* The minimum and maximum match lengths */
68
69         /* target dependencies */
70
71 #ifdef MSDOS
72 #  define OS_CODE  0x00
73 #  ifdef __TURBOC__
74 #    include <alloc.h>
75 #  else /* MSC */
76 #    include <malloc.h>
77 #  endif
78 #endif
79
80 #ifdef OS2
81 #  define OS_CODE  0x06
82 #endif
83
84 #ifdef WIN32 /* Windows NT */
85 #  define OS_CODE  0x0b
86 #endif
87
88 #if defined(VAXC) || defined(VMS)
89 #  define OS_CODE  0x02
90 #  define FOPEN(name, mode) \
91      fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
92 #endif
93
94 #ifdef AMIGA
95 #  define OS_CODE  0x01
96 #endif
97
98 #if defined(ATARI) || defined(atarist)
99 #  define OS_CODE  0x05
100 #endif
101
102 #ifdef MACOS
103 #  define OS_CODE  0x07
104 #endif
105
106 #ifdef __50SERIES /* Prime/PRIMOS */
107 #  define OS_CODE  0x0F
108 #endif
109
110 #ifdef TOPS20
111 #  define OS_CODE  0x0a
112 #endif
113
114         /* Common defaults */
115
116 #ifndef OS_CODE
117 #  define OS_CODE  0x03  /* assume Unix */
118 #endif
119
120 #ifndef FOPEN
121 #  define FOPEN(name, mode) fopen((name), (mode))
122 #endif
123
124          /* functions */
125
126 #ifdef HAVE_STRERROR
127    extern char *strerror __P((int));
128 #  define zstrerror(errnum) strerror(errnum)
129 #else
130 #  define zstrerror(errnum) ""
131 #endif
132
133 #if defined(pyr) && !defined(NO_MEMCPY)
134 #  define NO_MEMCPY
135 #endif
136 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
137 #  define HAVE_MEMCPY
138 #endif
139 #ifdef HAVE_MEMCPY
140 #  define zmemcpy memcpy
141 #  define zmemzero(dest, len) memset(dest, 0, len)
142 #else
143    extern void zmemcpy  __P((Byte* dest, Byte* source, uInt len));
144    extern void zmemzero __P((Byte* dest, uInt len));
145 #endif
146
147 /* Diagnostic functions */
148 #ifdef DEBUG
149 #  include <stdio.h>
150 #  ifndef verbose
151 #    define verbose 0
152 #  endif
153 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
154 #  define Trace(x) fprintf x
155 #  define Tracev(x) {if (verbose) fprintf x ;}
156 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
157 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
158 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
159 #else
160 #  define Assert(cond,msg)
161 #  define Trace(x)
162 #  define Tracev(x)
163 #  define Tracevv(x)
164 #  define Tracec(c,x)
165 #  define Tracecv(c,x)
166 #endif
167
168
169 typedef uLong (*check_func) __P((uLong check, Byte *buf, uInt len));
170
171 extern void z_error    __P((char *m));
172
173 voidp zcalloc __P((voidp opaque, unsigned items, unsigned size));
174 void  zcfree  __P((voidp opaque, voidp ptr));
175
176 #define ZALLOC(strm, items, size) \
177            (*((strm)->zalloc))((strm)->opaque, (items), (size))
178 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidp)(addr))
179 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
180
181 #endif /* _Z_UTIL_H */