1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /*-------------------------------------------------------------*/ 18 /*--- Public header file for the library. ---*/ 19 /*--- bzlib.h ---*/ 20 /*-------------------------------------------------------------*/ 21 22 /* ------------------------------------------------------------------ 23 The original source for this example: 24 This file is part of bzip2/libbzip2, a program and library for 25 lossless, block-sorting data compression. 26 27 bzip2/libbzip2 version 1.0.6 of 6 September 2010 28 Copyright (C) 1996-2010 Julian Seward <[email protected]> 29 30 This program, "bzip2", the associated library "libbzip2", and all 31 documentation, are copyright (C) 1996-2010 Julian R Seward. All 32 rights reserved. 33 34 Redistribution and use in source and binary forms, with or without 35 modification, are permitted provided that the following conditions 36 are met: 37 38 1. Redistributions of source code must retain the above copyright 39 notice, this list of conditions and the following disclaimer. 40 41 2. The origin of this software must not be misrepresented; you must 42 not claim that you wrote the original software. If you use this 43 software in a product, an acknowledgment in the product 44 documentation would be appreciated but is not required. 45 46 3. Altered source versions must be plainly marked as such, and must 47 not be misrepresented as being the original software. 48 49 4. The name of the author may not be used to endorse or promote 50 products derived from this software without specific prior written 51 permission. 52 53 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 54 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 55 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 57 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 59 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 61 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 62 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 63 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 65 Julian Seward, [email protected] 66 bzip2/libbzip2 version 1.0.6 of 6 September 2010 67 ------------------------------------------------------------------ */ 68 69 #ifndef _BZLIB_H 70 #define _BZLIB_H 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 #define BZ_RUN 0 77 #define BZ_FLUSH 1 78 #define BZ_FINISH 2 79 80 #define BZ_OK 0 81 #define BZ_RUN_OK 1 82 #define BZ_FLUSH_OK 2 83 #define BZ_FINISH_OK 3 84 #define BZ_STREAM_END 4 85 #define BZ_SEQUENCE_ERROR (-1) 86 #define BZ_PARAM_ERROR (-2) 87 #define BZ_MEM_ERROR (-3) 88 #define BZ_DATA_ERROR (-4) 89 #define BZ_DATA_ERROR_MAGIC (-5) 90 #define BZ_IO_ERROR (-6) 91 #define BZ_UNEXPECTED_EOF (-7) 92 #define BZ_OUTBUFF_FULL (-8) 93 #define BZ_CONFIG_ERROR (-9) 94 95 typedef struct { 96 char* next_in; 97 unsigned int avail_in; 98 unsigned int total_in_lo32; 99 unsigned int total_in_hi32; 100 101 char* next_out; 102 unsigned int avail_out; 103 unsigned int total_out_lo32; 104 unsigned int total_out_hi32; 105 106 void* state; 107 108 void* (*bzalloc)(void*, int, int); 109 void (*bzfree)(void*, void*); 110 void* opaque; 111 } bz_stream; 112 113 #ifndef BZ_IMPORT 114 #define BZ_EXPORT 115 #endif 116 117 #ifndef BZ_NO_STDIO 118 /* Need a definitition for FILE */ 119 #include <stdio.h> 120 #endif 121 122 #ifdef _WIN32 123 #include <windows.h> 124 #ifdef small 125 /* windows.h define small to char */ 126 #undef small 127 #endif 128 #ifdef BZ_EXPORT 129 #define BZ_API(func) WINAPI func 130 #define BZ_EXTERN extern 131 #else 132 /* import windows dll dynamically */ 133 #define BZ_API(func) (WINAPI * func) 134 #define BZ_EXTERN 135 #endif 136 #else 137 #define BZ_API(func) func 138 #define BZ_EXTERN extern 139 #endif 140 141 /*-- Core (low-level) library functions --*/ 142 143 BZ_EXTERN int BZ_API(BZ2_bzCompressInit)(bz_stream* strm, 144 int blockSize100k, 145 int verbosity, 146 int workFactor); 147 148 BZ_EXTERN int BZ_API(BZ2_bzCompress)(bz_stream* strm, int action); 149 150 BZ_EXTERN int BZ_API(BZ2_bzCompressEnd)(bz_stream* strm); 151 152 BZ_EXTERN int BZ_API(BZ2_bzDecompressInit)(bz_stream* strm, int verbosity, int small); 153 154 BZ_EXTERN int BZ_API(BZ2_bzDecompress)(bz_stream* strm); 155 156 BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd)(bz_stream* strm); 157 158 /*-- High(er) level library functions --*/ 159 160 #ifndef BZ_NO_STDIO 161 #define BZ_MAX_UNUSED 5000 162 163 typedef void BZFILE; 164 165 BZ_EXTERN BZFILE* BZ_API( 166 BZ2_bzReadOpen)(int* bzerror, FILE* f, int verbosity, int small, void* unused, int nUnused); 167 168 BZ_EXTERN void BZ_API(BZ2_bzReadClose)(int* bzerror, BZFILE* b); 169 170 BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused)(int* bzerror, BZFILE* b, void** unused, int* nUnused); 171 172 BZ_EXTERN int BZ_API(BZ2_bzRead)(int* bzerror, BZFILE* b, void* buf, int len); 173 174 BZ_EXTERN BZFILE* BZ_API( 175 BZ2_bzWriteOpen)(int* bzerror, FILE* f, int blockSize100k, int verbosity, int workFactor); 176 177 BZ_EXTERN void BZ_API(BZ2_bzWrite)(int* bzerror, BZFILE* b, void* buf, int len); 178 179 BZ_EXTERN void BZ_API(BZ2_bzWriteClose)(int* bzerror, 180 BZFILE* b, 181 int abandon, 182 unsigned int* nbytes_in, 183 unsigned int* nbytes_out); 184 185 BZ_EXTERN void BZ_API(BZ2_bzWriteClose64)(int* bzerror, 186 BZFILE* b, 187 int abandon, 188 unsigned int* nbytes_in_lo32, 189 unsigned int* nbytes_in_hi32, 190 unsigned int* nbytes_out_lo32, 191 unsigned int* nbytes_out_hi32); 192 #endif 193 194 /*-- Utility functions --*/ 195 196 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress)(char* dest, 197 unsigned int* destLen, 198 char* source, 199 unsigned int sourceLen, 200 int blockSize100k, 201 int verbosity, 202 int workFactor); 203 204 BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress)(char* dest, 205 unsigned int* destLen, 206 char* source, 207 unsigned int sourceLen, 208 int small, 209 int verbosity); 210 211 /*-- 212 Code contributed by Yoshioka Tsuneo ([email protected]) 213 to support better zlib compatibility. 214 This code is not _officially_ part of libbzip2 (yet); 215 I haven't tested it, documented it, or considered the 216 threading-safeness of it. 217 If this code breaks, please contact both Yoshioka and me. 218 --*/ 219 220 BZ_EXTERN const char* BZ_API(BZ2_bzlibVersion)(void); 221 222 #ifndef BZ_NO_STDIO 223 BZ_EXTERN BZFILE* BZ_API(BZ2_bzopen)(const char* path, const char* mode); 224 225 BZ_EXTERN BZFILE* BZ_API(BZ2_bzdopen)(int fd, const char* mode); 226 227 BZ_EXTERN int BZ_API(BZ2_bzread)(BZFILE* b, void* buf, int len); 228 229 BZ_EXTERN int BZ_API(BZ2_bzwrite)(BZFILE* b, void* buf, int len); 230 231 BZ_EXTERN int BZ_API(BZ2_bzflush)(BZFILE* b); 232 233 BZ_EXTERN void BZ_API(BZ2_bzclose)(BZFILE* b); 234 235 BZ_EXTERN const char* BZ_API(BZ2_bzerror)(BZFILE* b, int* errnum); 236 #endif 237 238 #ifdef __cplusplus 239 } 240 #endif 241 242 #endif 243 244 /*-------------------------------------------------------------*/ 245 /*--- end bzlib.h ---*/ 246 /*-------------------------------------------------------------*/ 247