1 
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-1999 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, Cambridge, UK.
45   jseward@acm.org
46   bzip2/libbzip2 version 0.9.5 of 24 May 1999
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 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #define BZ_RUN               0
70 #define BZ_FLUSH             1
71 #define BZ_FINISH            2
72 
73 #define BZ_OK                0
74 #define BZ_RUN_OK            1
75 #define BZ_FLUSH_OK          2
76 #define BZ_FINISH_OK         3
77 #define BZ_STREAM_END        4
78 #define BZ_SEQUENCE_ERROR    (-1)
79 #define BZ_PARAM_ERROR       (-2)
80 #define BZ_MEM_ERROR         (-3)
81 #define BZ_DATA_ERROR        (-4)
82 #define BZ_DATA_ERROR_MAGIC  (-5)
83 #define BZ_IO_ERROR          (-6)
84 #define BZ_UNEXPECTED_EOF    (-7)
85 #define BZ_OUTBUFF_FULL      (-8)
86 
87 typedef
88    struct {
89       char *next_in;
90       unsigned int avail_in;
91       unsigned int total_in;
92 
93       char *next_out;
94       unsigned int avail_out;
95       unsigned int total_out;
96 
97       void *state;
98 
99       void *(*bzalloc)(void *,int,int);
100       void (*bzfree)(void *,void *);
101       void *opaque;
102    }
103    bz_stream;
104 
105 
106 #ifndef BZ_IMPORT
107 #define BZ_EXPORT
108 #endif
109 
110 #ifdef _WIN32
111 #   include <stdio.h>
112 #   include <windows.h>
113 #   ifdef small
114       /* windows.h define small to char */
115 #      undef small
116 #   endif
117 #   ifdef BZ_EXPORT
118 #   define BZ_API(func) WINAPI func
119 #   define BZ_EXTERN extern
120 #   else
121    /* import windows dll dynamically */
122 #   define BZ_API(func) (WINAPI * func)
123 #   define BZ_EXTERN
124 #   endif
125 #else
126 #   define BZ_API(func) func
127 #   define BZ_EXTERN extern
128 #endif
129 
130 
131 /*-- Core (low-level) library functions --*/
132 
133 BZ_EXTERN int BZ_API(bzCompressInit) (
134 //int bzCompressInit(
135       bz_stream* strm,
136       int        blockSize100k,
137       int        verbosity,
138       int        workFactor
139    );
140 
141 BZ_EXTERN int BZ_API(bzCompress) (
142       bz_stream* strm,
143       int action
144    );
145 
146 BZ_EXTERN int BZ_API(bzCompressEnd) (
147       bz_stream* strm
148    );
149 
150 BZ_EXTERN int BZ_API(bzDecompressInit) (
151       bz_stream *strm,
152       int       verbosity,
153       int       small
154    );
155 
156 BZ_EXTERN int BZ_API(bzDecompress) (
157       bz_stream* strm
158    );
159 
160 BZ_EXTERN int BZ_API(bzDecompressEnd) (
161       bz_stream *strm
162    );
163 
164 
165 
166 /*-- High(er) level library functions --*/
167 
168 #ifndef BZ_NO_STDIO
169 #define BZ_MAX_UNUSED 5000
170 
171 typedef void BZFILE;
172 
173 BZ_EXTERN BZFILE* BZ_API(bzReadOpen) (
174       int*  bzerror,
175       FILE* f,
176       int   verbosity,
177       int   small,
178       void* unused,
179       int   nUnused
180    );
181 
182 BZ_EXTERN void BZ_API(bzReadClose) (
183       int*    bzerror,
184       BZFILE* b
185    );
186 
187 BZ_EXTERN void BZ_API(bzReadGetUnused) (
188       int*    bzerror,
189       BZFILE* b,
190       void**  unused,
191       int*    nUnused
192    );
193 
194 BZ_EXTERN int BZ_API(bzRead) (
195       int*    bzerror,
196       BZFILE* b,
197       void*   buf,
198       int     len
199    );
200 
201 BZ_EXTERN BZFILE* BZ_API(bzWriteOpen) (
202       int*  bzerror,
203       FILE* f,
204       int   blockSize100k,
205       int   verbosity,
206       int   workFactor
207    );
208 
209 BZ_EXTERN void BZ_API(bzWrite) (
210       int*    bzerror,
211       BZFILE* b,
212       void*   buf,
213       int     len
214    );
215 
216 BZ_EXTERN void BZ_API(bzWriteClose) (
217       int*          bzerror,
218       BZFILE*       b,
219       int           abandon,
220       unsigned int* nbytes_in,
221       unsigned int* nbytes_out
222    );
223 #endif
224 
225 
226 /*-- Utility functions --*/
227 
228 BZ_EXTERN int BZ_API(bzBuffToBuffCompress) (
229       char*         dest,
230       unsigned int* destLen,
231       char*         source,
232       unsigned int  sourceLen,
233       int           blockSize100k,
234       int           verbosity,
235       int           workFactor
236    );
237 
238 BZ_EXTERN int BZ_API(bzBuffToBuffDecompress) (
239       char*         dest,
240       unsigned int* destLen,
241       char*         source,
242       unsigned int  sourceLen,
243       int           small,
244       int           verbosity
245    );
246 
247 
248 /*--
249    Code contributed by Yoshioka Tsuneo
250    (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
251    to support better zlib compatibility.
252    This code is not _officially_ part of libbzip2 (yet);
253    I haven't tested it, documented it, or considered the
254    threading-safeness of it.
255    If this code breaks, please contact both Yoshioka and me.
256 --*/
257 
258 BZ_EXTERN const char * BZ_API(bzlibVersion) (
259       void
260    );
261 
262 #ifndef BZ_NO_STDIO
263 BZ_EXTERN BZFILE * BZ_API(bzopen) (
264       const char *path,
265       const char *mode
266    );
267 
268 BZ_EXTERN BZFILE * BZ_API(bzdopen) (
269       int        fd,
270       const char *mode
271    );
272 
273 BZ_EXTERN int BZ_API(bzread) (
274       BZFILE* b,
275       void* buf,
276       int len
277    );
278 
279 BZ_EXTERN int BZ_API(bzwrite) (
280       BZFILE* b,
281       void*   buf,
282       int     len
283    );
284 
285 BZ_EXTERN int BZ_API(bzflush) (
286       BZFILE* b
287    );
288 
289 BZ_EXTERN void BZ_API(bzclose) (
290       BZFILE* b
291    );
292 
293 BZ_EXTERN const char * BZ_API(bzerror) (
294       BZFILE *b,
295       int    *errnum
296    );
297 #endif
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif
304 
305 /*-------------------------------------------------------------*/
306 /*--- end                                           bzlib.h ---*/
307 /*-------------------------------------------------------------*/
308