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