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