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