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