]> git.lizzy.rs Git - zlib.git/blob - zutil.h
zlib 0.94
[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 #if defined(MSDOS) || defined(VMS)
19 #   include <stddef.h>
20 #   include <errno.h>
21 #else
22     extern int errno;
23 #endif
24 #ifdef STDC
25 #  include <string.h>
26 #endif
27
28 #ifndef local
29 #  define local static
30 #endif
31 /* compile with -Dlocal if your debugger can't find static symbols */
32
33 typedef unsigned char  uch;
34 typedef uch FAR uchf;
35 typedef unsigned short ush;
36 typedef ush FAR ushf;
37 typedef unsigned long  ulg;
38
39 extern char *z_errmsg[]; /* indexed by 1-zlib_error */
40
41 #define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
42 /* To be used only when the state is known to be valid */
43
44         /* common constants */
45
46 #define DEFLATED   8
47
48 #ifndef DEF_WBITS
49 #  define DEF_WBITS 15
50 #endif
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 OF((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 #  ifdef M_I86MM /* MSC medium model */
141 #    define zmemcpy _fmemcpy
142 #    define zmemzero(dest, len) _fmemset(dest, 0, len)
143 #  else 
144 #    define zmemcpy memcpy
145 #    define zmemzero(dest, len) memset(dest, 0, len)
146 #  endif
147 #else
148    extern void zmemcpy  OF((Byte* dest, Byte* source, uInt len));
149    extern void zmemzero OF((Byte* dest, uInt len));
150 #endif
151
152 /* Diagnostic functions */
153 #ifdef DEBUG
154 #  include <stdio.h>
155 #  ifndef verbose
156 #    define verbose 0
157 #  endif
158 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
159 #  define Trace(x) fprintf x
160 #  define Tracev(x) {if (verbose) fprintf x ;}
161 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
162 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
163 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
164 #else
165 #  define Assert(cond,msg)
166 #  define Trace(x)
167 #  define Tracev(x)
168 #  define Tracevv(x)
169 #  define Tracec(c,x)
170 #  define Tracecv(c,x)
171 #endif
172
173
174 typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
175
176 extern void z_error    OF((char *m));
177
178 voidp zcalloc OF((voidp opaque, unsigned items, unsigned size));
179 void  zcfree  OF((voidp opaque, voidp ptr));
180
181 #define ZALLOC(strm, items, size) \
182            (*((strm)->zalloc))((strm)->opaque, (items), (size))
183 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidp)(addr))
184 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
185
186 #endif /* _Z_UTIL_H */