1 #pragma prototyped
2 /*-------------------------------------------------------------*/
3 /*--- Public header file for the library.                   ---*/
4 /*---                                               bzlib.h ---*/
5 /*-------------------------------------------------------------*/
6 
7 /*--
8   This file is a part of bzip2 and/or libbzip2, a program and
9   library for lossless, block-sorting data compression.
10 
11   Copyright (C) 1996-1998 Julian R Seward.  All rights reserved.
12 
13   Redistribution and use in source and binary forms, with or without
14   modification, are permitted provided that the following conditions
15   are met:
16 
17   1. Redistributions of source code must retain the above copyright
18      notice, this list of conditions and the following disclaimer.
19 
20   2. The origin of this software must not be misrepresented; you must
21      not claim that you wrote the original software.  If you use this
22      software in a product, an acknowledgment in the product
23      documentation would be appreciated but is not required.
24 
25   3. Altered source versions must be plainly marked as such, and must
26      not be misrepresented as being the original software.
27 
28   4. The name of the author may not be used to endorse or promote
29      products derived from this software without specific prior written
30      permission.
31 
32   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 
44   Julian Seward, Guildford, Surrey, UK.
45   jseward@acm.org
46   bzip2/libbzip2 version 0.9.0c of 18 October 1998
47 
48   This program is based on (at least) the work of:
49      Mike Burrows
50      David Wheeler
51      Peter Fenwick
52      Alistair Moffat
53      Radford Neal
54      Ian H. Witten
55      Robert Sedgewick
56      Jon L. Bentley
57 
58   For more information on these sources, see the manual.
59 --*/
60 
61 
62 #ifndef _BZLIB_H
63 #define _BZLIB_H
64 
65 #define BZ_RUN               0
66 #define BZ_FLUSH             1
67 #define BZ_FINISH            2
68 
69 #define BZ_OK                0
70 #define BZ_RUN_OK            1
71 #define BZ_FLUSH_OK          2
72 #define BZ_FINISH_OK         3
73 #define BZ_STREAM_END        4
74 #define BZ_SEQUENCE_ERROR    (-1)
75 #define BZ_PARAM_ERROR       (-2)
76 #define BZ_MEM_ERROR         (-3)
77 #define BZ_DATA_ERROR        (-4)
78 #define BZ_DATA_ERROR_MAGIC  (-5)
79 #define BZ_IO_ERROR          (-6)
80 #define BZ_UNEXPECTED_EOF    (-7)
81 #define BZ_OUTBUFF_FULL      (-8)
82 
83 typedef
84    struct {
85       char *next_in;
86       unsigned int avail_in;
87       unsigned int total_in;
88 
89       char *next_out;
90       unsigned int avail_out;
91       unsigned int total_out;
92 
93       void *state;
94 
95       void *(*bzalloc)(void *,int,int);
96       void (*bzfree)(void *,void *);
97       void *opaque;
98    }
99    bz_stream;
100 
101 
102 #if _PACKAGE_ast
103 #include <ast_std.h>
104 #else
105 #if !defined(_WINIX) && (_UWIN || __CYGWIN__ || __EMX__)
106 #define _WINIX		1
107 #endif
108 #endif
109 
110 /*---------------------------------------------*/
111 /*--
112   Generic 32-bit Unix.
113   Also works on 64-bit Unix boxes.
114 --*/
115 #if !_WIN32 || _WINIX
116 #define BZ_UNIX      1
117 #endif
118 
119 /*--
120   Win32, as seen by Jacob Navia's excellent
121   port of (Chris Fraser & David Hanson)'s excellent
122   lcc compiler.
123 --*/
124 #if _WIN32 && !_WINIX
125 #define BZ_LCCWIN32 1
126 #define BZ_UNIX 0
127 #else
128 #define BZ_LCCWIN32  0
129 #endif
130 
131 #include <stdio.h>
132 
133 #if _BLD_bz
134 
135 #if defined(__EXPORT__)
136 #   define BZ_API(func)	func
137 #   define BZ_EXTERN __EXPORT__
138 #else
139 #   define BZ_API(func) func
140 #   define BZ_EXTERN extern
141 #endif
142 
143 #else
144 
145 #if _WIN32 && !_WINIX
146 #   include <windows.h>
147 #   ifdef small
148       /* windows.h define small to char */
149 #      undef small
150 #   endif
151 #   ifdef BZ_EXPORT
152 #   define BZ_API(func) WINAPI func
153 #   define BZ_EXTERN extern
154 #   else
155    /* import windows dll dynamically */
156 #   define BZ_API(func) (WINAPI * func)
157 #   define BZ_EXTERN
158 #   endif
159 #else
160 #   define BZ_API(func) func
161 #   define BZ_EXTERN extern
162 #endif
163 
164 #endif
165 
166 
167 /*-- Core (low-level) library functions --*/
168 
169 BZ_EXTERN int BZ_API(bzCompressInit) (
170       bz_stream* strm,
171       int        blockSize100k,
172       int        verbosity,
173       int        workFactor
174    );
175 
176 BZ_EXTERN int BZ_API(bzCompress) (
177       bz_stream* strm,
178       int action
179    );
180 
181 BZ_EXTERN int BZ_API(bzCompressEnd) (
182       bz_stream* strm
183    );
184 
185 BZ_EXTERN int BZ_API(bzDecompressInit) (
186       bz_stream *strm,
187       int       verbosity,
188       int       small
189    );
190 
191 BZ_EXTERN int BZ_API(bzDecompress) (
192       bz_stream* strm
193    );
194 
195 BZ_EXTERN int BZ_API(bzDecompressEnd) (
196       bz_stream *strm
197    );
198 
199 
200 
201 /*-- High(er) level library functions --*/
202 
203 #ifndef BZ_NO_STDIO
204 #define BZ_MAX_UNUSED 5000
205 
206 typedef void BZFILE;
207 
208 typedef BZFILE Bz_t;
209 
210 BZ_EXTERN BZFILE* BZ_API(bzReadOpen) (
211       int*  bzerror,
212       FILE* f,
213       int   verbosity,
214       int   small,
215       void* unused,
216       int   nUnused
217    );
218 
219 BZ_EXTERN void BZ_API(bzReadClose) (
220       int*    bzerror,
221       BZFILE* b
222    );
223 
224 BZ_EXTERN void BZ_API(bzReadGetUnused) (
225       int*    bzerror,
226       BZFILE* b,
227       void*   vUnused,
228       int*    nUnused
229    );
230 
231 BZ_EXTERN int BZ_API(bzRead) (
232       int*    bzerror,
233       BZFILE* b,
234       void*   buf,
235       int     len
236    );
237 
238 BZ_EXTERN BZFILE* BZ_API(bzWriteOpen) (
239       int*  bzerror,
240       FILE* f,
241       int   blockSize100k,
242       int   verbosity,
243       int   workFactor
244    );
245 
246 BZ_EXTERN void BZ_API(bzWrite) (
247       int*    bzerror,
248       BZFILE* b,
249       void*   buf,
250       int     len
251    );
252 
253 BZ_EXTERN void BZ_API(bzWriteClose) (
254       int*          bzerror,
255       BZFILE*       b,
256       int           abandon,
257       unsigned int* nbytes_in,
258       unsigned int* nbytes_out
259    );
260 #endif
261 
262 
263 /*-- Utility functions --*/
264 
265 BZ_EXTERN int BZ_API(bzBuffToBuffCompress) (
266       char*         dest,
267       unsigned int* destLen,
268       char*         source,
269       unsigned int  sourceLen,
270       int           blockSize100k,
271       int           verbosity,
272       int           workFactor
273    );
274 
275 BZ_EXTERN int BZ_API(bzBuffToBuffDecompress) (
276       char*         dest,
277       unsigned int* destLen,
278       char*         source,
279       unsigned int  sourceLen,
280       int           small,
281       int           verbosity
282    );
283 
284 
285 /*--
286    Code contributed by Yoshioka Tsuneo
287    (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
288    to support better zlib compatibility.
289    This code is not _officially_ part of libbzip2 (yet);
290    I haven't tested it, documented it, or considered the
291    threading-safeness of it.
292    If this code breaks, please contact both Yoshioka and me.
293 --*/
294 
295 BZ_EXTERN const char * BZ_API(bzlibVersion) (
296       void
297    );
298 
299 #ifndef BZ_NO_STDIO
300 BZ_EXTERN BZFILE * BZ_API(bzopen) (
301       const char *path,
302       const char *mode
303    );
304 
305 BZ_EXTERN BZFILE * BZ_API(bzfopen) (
306       FILE       *fp,
307       const char *mode
308    );
309 
310 BZ_EXTERN BZFILE * BZ_API(bzdopen) (
311       int        fd,
312       const char *mode
313    );
314 
315 BZ_EXTERN BZFILE * BZ_API(bzbopen) (
316       int          fd,
317       const char*  mode,
318       const void*  buf,
319       unsigned int len
320    );
321 
322 BZ_EXTERN int BZ_API(bzread) (
323       BZFILE* b,
324       void* buf,
325       int len
326    );
327 
328 BZ_EXTERN int BZ_API(bzwrite) (
329       BZFILE*     b,
330       const void* buf,
331       int         len
332    );
333 
334 BZ_EXTERN int BZ_API(bzflush) (
335       BZFILE* b
336    );
337 
338 BZ_EXTERN int BZ_API(bzclose) (
339       BZFILE* b
340    );
341 
342 BZ_EXTERN const char * BZ_API(bzerror) (
343       BZFILE *b,
344       int    *errnum
345    );
346 #endif
347 
348 
349 #endif
350 
351 /*-------------------------------------------------------------*/
352 /*--- end                                           bzlib.h ---*/
353 /*-------------------------------------------------------------*/
354