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