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