Fix license info ( BSD-3-Clause -> BSD-2.0 )
[platform/upstream/bzip2.git] / bzlib.h
1
2 /*-------------------------------------------------------------*/
3 /*--- Public header file for the library.                   ---*/
4 /*---                                               bzlib.h ---*/
5 /*-------------------------------------------------------------*/
6
7 /* ------------------------------------------------------------------
8    This file is part of bzip2/libbzip2, a program and library for
9    lossless, block-sorting data compression.
10
11    bzip2/libbzip2 version 1.0.6 of 6 September 2010
12    Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
13
14    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
15    README file.
16
17    This program is released under the terms of the license contained
18    in the file LICENSE.
19    ------------------------------------------------------------------ */
20
21
22 #ifndef _BZLIB_H
23 #define _BZLIB_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define BZ_RUN               0
30 #define BZ_FLUSH             1
31 #define BZ_FINISH            2
32
33 #define BZ_OK                0
34 #define BZ_RUN_OK            1
35 #define BZ_FLUSH_OK          2
36 #define BZ_FINISH_OK         3
37 #define BZ_STREAM_END        4
38 #define BZ_SEQUENCE_ERROR    (-1)
39 #define BZ_PARAM_ERROR       (-2)
40 #define BZ_MEM_ERROR         (-3)
41 #define BZ_DATA_ERROR        (-4)
42 #define BZ_DATA_ERROR_MAGIC  (-5)
43 #define BZ_IO_ERROR          (-6)
44 #define BZ_UNEXPECTED_EOF    (-7)
45 #define BZ_OUTBUFF_FULL      (-8)
46 #define BZ_CONFIG_ERROR      (-9)
47
48 typedef 
49    struct {
50       char *next_in;
51       unsigned int avail_in;
52       unsigned int total_in_lo32;
53       unsigned int total_in_hi32;
54
55       char *next_out;
56       unsigned int avail_out;
57       unsigned int total_out_lo32;
58       unsigned int total_out_hi32;
59
60       void *state;
61
62       void *(*bzalloc)(void *,int,int);
63       void (*bzfree)(void *,void *);
64       void *opaque;
65    } 
66    bz_stream;
67
68
69 #ifndef BZ_IMPORT
70 #define BZ_EXPORT
71 #endif
72
73 #ifndef BZ_NO_STDIO
74 /* Need a definitition for FILE */
75 #include <stdio.h>
76 #endif
77
78 #ifdef _WIN32
79 #   include <windows.h>
80 #   ifdef small
81       /* windows.h define small to char */
82 #      undef small
83 #   endif
84 #   ifdef BZ_EXPORT
85 #   define BZ_API(func) WINAPI func
86 #   define BZ_EXTERN extern
87 #   else
88    /* import windows dll dynamically */
89 #   define BZ_API(func) (WINAPI * func)
90 #   define BZ_EXTERN
91 #   endif
92 #else
93 #   define BZ_API(func) func
94 #endif
95
96 #ifndef BZ_EXTERN
97 #define BZ_EXTERN extern
98 #endif
99
100 /*-- Core (low-level) library functions --*/
101
102 BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 
103       bz_stream* strm, 
104       int        blockSize100k, 
105       int        verbosity, 
106       int        workFactor 
107    );
108
109 BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 
110       bz_stream* strm, 
111       int action 
112    );
113
114 BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 
115       bz_stream* strm 
116    );
117
118 BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 
119       bz_stream *strm, 
120       int       verbosity, 
121       int       small
122    );
123
124 BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 
125       bz_stream* strm 
126    );
127
128 BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 
129       bz_stream *strm 
130    );
131
132
133
134 /*-- High(er) level library functions --*/
135
136 #ifndef BZ_NO_STDIO
137 #define BZ_MAX_UNUSED 5000
138
139 typedef void BZFILE;
140
141 BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 
142       int*  bzerror,   
143       FILE* f, 
144       int   verbosity, 
145       int   small,
146       void* unused,    
147       int   nUnused 
148    );
149
150 BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 
151       int*    bzerror, 
152       BZFILE* b 
153    );
154
155 BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 
156       int*    bzerror, 
157       BZFILE* b, 
158       void**  unused,  
159       int*    nUnused 
160    );
161
162 BZ_EXTERN int BZ_API(BZ2_bzRead) ( 
163       int*    bzerror, 
164       BZFILE* b, 
165       void*   buf, 
166       int     len 
167    );
168
169 BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 
170       int*  bzerror,      
171       FILE* f, 
172       int   blockSize100k, 
173       int   verbosity, 
174       int   workFactor 
175    );
176
177 BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 
178       int*    bzerror, 
179       BZFILE* b, 
180       void*   buf, 
181       int     len 
182    );
183
184 BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 
185       int*          bzerror, 
186       BZFILE*       b, 
187       int           abandon, 
188       unsigned int* nbytes_in, 
189       unsigned int* nbytes_out 
190    );
191
192 BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 
193       int*          bzerror, 
194       BZFILE*       b, 
195       int           abandon, 
196       unsigned int* nbytes_in_lo32, 
197       unsigned int* nbytes_in_hi32, 
198       unsigned int* nbytes_out_lo32, 
199       unsigned int* nbytes_out_hi32
200    );
201 #endif
202
203
204 /*-- Utility functions --*/
205
206 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 
207       char*         dest, 
208       unsigned int* destLen,
209       char*         source, 
210       unsigned int  sourceLen,
211       int           blockSize100k, 
212       int           verbosity, 
213       int           workFactor 
214    );
215
216 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 
217       char*         dest, 
218       unsigned int* destLen,
219       char*         source, 
220       unsigned int  sourceLen,
221       int           small, 
222       int           verbosity 
223    );
224
225
226 /*--
227    Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
228    to support better zlib compatibility.
229    This code is not _officially_ part of libbzip2 (yet);
230    I haven't tested it, documented it, or considered the
231    threading-safeness of it.
232    If this code breaks, please contact both Yoshioka and me.
233 --*/
234
235 BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
236       void
237    );
238
239 #ifndef BZ_NO_STDIO
240 BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
241       const char *path,
242       const char *mode
243    );
244
245 BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
246       int        fd,
247       const char *mode
248    );
249          
250 BZ_EXTERN int BZ_API(BZ2_bzread) (
251       BZFILE* b, 
252       void* buf, 
253       int len 
254    );
255
256 BZ_EXTERN int BZ_API(BZ2_bzwrite) (
257       BZFILE* b, 
258       void*   buf, 
259       int     len 
260    );
261
262 BZ_EXTERN int BZ_API(BZ2_bzflush) (
263       BZFILE* b
264    );
265
266 BZ_EXTERN void BZ_API(BZ2_bzclose) (
267       BZFILE* b
268    );
269
270 BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
271       BZFILE *b, 
272       int    *errnum
273    );
274 #endif
275
276 #ifdef __cplusplus
277 }
278 #endif
279
280 #endif
281
282 /*-------------------------------------------------------------*/
283 /*--- end                                           bzlib.h ---*/
284 /*-------------------------------------------------------------*/