wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 1 | /* |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 2 | * This file is derived from zlib.h and zconf.h from the zlib-1.2.3 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 3 | * distribution by Jean-loup Gailly and Mark Adler, with some additions |
| 4 | * by Paul Mackerras to aid in implementing Deflate compression and |
| 5 | * decompression for PPP packets. |
| 6 | */ |
| 7 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 8 | /* |
| 9 | * ==FILEVERSION 960122== |
| 10 | * |
| 11 | * This marker is used by the Linux installation script to determine |
| 12 | * whether an up-to-date version of this file is already installed. |
| 13 | */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 14 | |
| 15 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 16 | version 1.2.3, July 18th, 2005 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 17 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 18 | Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 19 | |
| 20 | This software is provided 'as-is', without any express or implied |
| 21 | warranty. In no event will the authors be held liable for any damages |
| 22 | arising from the use of this software. |
| 23 | |
| 24 | Permission is granted to anyone to use this software for any purpose, |
| 25 | including commercial applications, and to alter it and redistribute it |
| 26 | freely, subject to the following restrictions: |
| 27 | |
| 28 | 1. The origin of this software must not be misrepresented; you must not |
| 29 | claim that you wrote the original software. If you use this software |
| 30 | in a product, an acknowledgment in the product documentation would be |
| 31 | appreciated but is not required. |
| 32 | 2. Altered source versions must be plainly marked as such, and must not be |
| 33 | misrepresented as being the original software. |
| 34 | 3. This notice may not be removed or altered from any source distribution. |
| 35 | |
| 36 | Jean-loup Gailly Mark Adler |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 37 | jloup@gzip.org madler@alumni.caltech.edu |
| 38 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 39 | The data format used by the zlib library is described by RFCs (Request for |
| 40 | Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt |
| 41 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). |
| 42 | */ |
| 43 | |
| 44 | #ifndef ZLIB_H |
| 45 | #define ZLIB_H |
| 46 | |
| 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 50 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 51 | /* #include "zconf.h" */ /* included directly here */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 52 | /* zconf.h -- configuration of the zlib compression library |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 53 | * Copyright (C) 1995-2005 Jean-loup Gailly. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 54 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 55 | */ |
| 56 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 57 | /* Begin of new zconf.h */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 58 | /* |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 59 | * If you *really* need a unique prefix for all types and library functions, |
| 60 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 61 | */ |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 62 | #ifdef Z_PREFIX |
| 63 | # define deflateInit_ z_deflateInit_ |
| 64 | # define deflate z_deflate |
| 65 | # define deflateEnd z_deflateEnd |
| 66 | # define inflateInit_ z_inflateInit_ |
| 67 | # define inflate z_inflate |
| 68 | # define inflateEnd z_inflateEnd |
| 69 | # define deflateInit2_ z_deflateInit2_ |
| 70 | # define deflateSetDictionary z_deflateSetDictionary |
| 71 | # define deflateCopy z_deflateCopy |
| 72 | # define deflateReset z_deflateReset |
| 73 | # define deflateParams z_deflateParams |
| 74 | # define deflateBound z_deflateBound |
| 75 | # define deflatePrime z_deflatePrime |
| 76 | # define inflateInit2_ z_inflateInit2_ |
| 77 | # define inflateSetDictionary z_inflateSetDictionary |
| 78 | # define inflateSync z_inflateSync |
| 79 | # define inflateSyncPoint z_inflateSyncPoint |
| 80 | # define inflateCopy z_inflateCopy |
| 81 | # define inflateReset z_inflateReset |
| 82 | # define inflateBack z_inflateBack |
| 83 | # define inflateBackEnd z_inflateBackEnd |
| 84 | # define compress z_compress |
| 85 | # define compress2 z_compress2 |
| 86 | # define compressBound z_compressBound |
| 87 | # define uncompress z_uncompress |
| 88 | # define adler32 z_adler32 |
| 89 | # define crc32 z_crc32 |
| 90 | # define get_crc_table z_get_crc_table |
| 91 | # define zError z_zError |
| 92 | |
| 93 | # define alloc_func z_alloc_func |
| 94 | # define free_func z_free_func |
| 95 | # define in_func z_in_func |
| 96 | # define out_func z_out_func |
| 97 | # define Byte z_Byte |
| 98 | # define uInt z_uInt |
| 99 | # define uLong z_uLong |
| 100 | # define Bytef z_Bytef |
| 101 | # define charf z_charf |
| 102 | # define intf z_intf |
| 103 | # define uIntf z_uIntf |
| 104 | # define uLongf z_uLongf |
| 105 | # define voidpf z_voidpf |
| 106 | # define voidp z_voidp |
| 107 | #endif |
| 108 | |
Joao Marcos Costa | ae8abb1 | 2020-07-30 15:33:49 +0200 | [diff] [blame] | 109 | #if defined(ZLIB_CONST) && !defined(z_const) |
| 110 | # define z_const const |
| 111 | #else |
| 112 | # define z_const |
| 113 | #endif |
| 114 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 115 | #if defined(__MSDOS__) && !defined(MSDOS) |
| 116 | # define MSDOS |
| 117 | #endif |
| 118 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) |
| 119 | # define OS2 |
| 120 | #endif |
| 121 | #if defined(_WINDOWS) && !defined(WINDOWS) |
| 122 | # define WINDOWS |
| 123 | #endif |
| 124 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) |
| 125 | # ifndef WIN32 |
| 126 | # define WIN32 |
| 127 | # endif |
| 128 | #endif |
| 129 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) |
| 130 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) |
| 131 | # ifndef SYS16BIT |
| 132 | # define SYS16BIT |
| 133 | # endif |
| 134 | # endif |
| 135 | #endif |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more |
| 139 | * than 64k bytes at a time (needed on systems with 16-bit int). |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 140 | */ |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 141 | #ifdef SYS16BIT |
| 142 | # define MAXSEG_64K |
| 143 | #endif |
| 144 | #ifdef MSDOS |
| 145 | # define UNALIGNED_OK |
| 146 | #endif |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 147 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 148 | #ifdef __STDC_VERSION__ |
| 149 | # ifndef STDC |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 150 | # define STDC |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 151 | # endif |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 152 | # if __STDC_VERSION__ >= 199901L |
| 153 | # ifndef STDC99 |
| 154 | # define STDC99 |
| 155 | # endif |
| 156 | # endif |
| 157 | #endif |
| 158 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) |
| 159 | # define STDC |
| 160 | #endif |
| 161 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) |
| 162 | # define STDC |
| 163 | #endif |
| 164 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) |
| 165 | # define STDC |
| 166 | #endif |
| 167 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) |
| 168 | # define STDC |
| 169 | #endif |
| 170 | |
| 171 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ |
| 172 | # define STDC |
| 173 | #endif |
| 174 | |
| 175 | #ifndef STDC |
| 176 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ |
| 177 | # define const /* note: need a more gentle solution here */ |
| 178 | # endif |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 179 | #endif |
| 180 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 181 | /* Some Mac compilers merge all .h files incorrectly: */ |
| 182 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) |
| 183 | # define NO_DUMMY_DECL |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | /* Maximum value for memLevel in deflateInit2 */ |
| 187 | #ifndef MAX_MEM_LEVEL |
| 188 | # ifdef MAXSEG_64K |
| 189 | # define MAX_MEM_LEVEL 8 |
| 190 | # else |
| 191 | # define MAX_MEM_LEVEL 9 |
| 192 | # endif |
| 193 | #endif |
| 194 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 195 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. |
| 196 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files |
| 197 | * created by gzip. (Files created by minigzip can still be extracted by |
| 198 | * gzip.) |
| 199 | */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 200 | #ifndef MAX_WBITS |
| 201 | # define MAX_WBITS 15 /* 32K LZ77 window */ |
| 202 | #endif |
| 203 | |
| 204 | /* The memory requirements for deflate are (in bytes): |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 205 | (1 << (windowBits+2)) + (1 << (memLevel+9)) |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 206 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) |
| 207 | plus a few kilobytes for small objects. For example, if you want to reduce |
| 208 | the default memory requirements from 256K to 128K, compile with |
| 209 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" |
| 210 | Of course this will generally degrade compression (there's no free lunch). |
| 211 | |
| 212 | The memory requirements for inflate are (in bytes) 1 << windowBits |
| 213 | that is, 32K for windowBits=15 (default value) plus a few kilobytes |
| 214 | for small objects. |
| 215 | */ |
| 216 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 217 | /* Type declarations */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 218 | |
| 219 | #ifndef OF /* function prototypes */ |
| 220 | # ifdef STDC |
| 221 | # define OF(args) args |
| 222 | # else |
| 223 | # define OF(args) () |
| 224 | # endif |
| 225 | #endif |
| 226 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 227 | /* The following definitions for FAR are needed only for MSDOS mixed |
| 228 | * model programming (small or medium model with some far allocations). |
| 229 | * This was tested only with MSC; for other MSDOS compilers you may have |
| 230 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, |
| 231 | * just define FAR to be empty. |
| 232 | */ |
| 233 | #ifdef SYS16BIT |
| 234 | # if defined(M_I86SM) || defined(M_I86MM) |
| 235 | /* MSC small or medium model */ |
| 236 | # define SMALL_MEDIUM |
| 237 | # ifdef _MSC_VER |
| 238 | # define FAR _far |
| 239 | # else |
| 240 | # define FAR far |
| 241 | # endif |
| 242 | # endif |
| 243 | # if (defined(__SMALL__) || defined(__MEDIUM__)) |
| 244 | /* Turbo C small or medium model */ |
| 245 | # define SMALL_MEDIUM |
| 246 | # ifdef __BORLANDC__ |
| 247 | # define FAR _far |
| 248 | # else |
| 249 | # define FAR far |
| 250 | # endif |
| 251 | # endif |
| 252 | #endif |
| 253 | |
| 254 | #if defined(WINDOWS) || defined(WIN32) |
| 255 | /* If building or using zlib as a DLL, define ZLIB_DLL. |
| 256 | * This is not mandatory, but it offers a little performance increase. |
| 257 | */ |
| 258 | # ifdef ZLIB_DLL |
| 259 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) |
| 260 | # ifdef ZLIB_INTERNAL |
| 261 | # define ZEXTERN extern __declspec(dllexport) |
| 262 | # else |
| 263 | # define ZEXTERN extern __declspec(dllimport) |
| 264 | # endif |
| 265 | # endif |
| 266 | # endif /* ZLIB_DLL */ |
| 267 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, |
| 268 | * define ZLIB_WINAPI. |
| 269 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. |
| 270 | */ |
| 271 | # ifdef ZLIB_WINAPI |
| 272 | # ifdef FAR |
| 273 | # undef FAR |
| 274 | # endif |
| 275 | # include <windows.h> |
| 276 | /* No need for _export, use ZLIB.DEF instead. */ |
| 277 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ |
| 278 | # define ZEXPORT WINAPI |
| 279 | # ifdef WIN32 |
| 280 | # define ZEXPORTVA WINAPIV |
| 281 | # else |
| 282 | # define ZEXPORTVA FAR CDECL |
| 283 | # endif |
| 284 | # endif |
| 285 | #endif |
| 286 | |
| 287 | #if defined (__BEOS__) |
| 288 | # ifdef ZLIB_DLL |
| 289 | # ifdef ZLIB_INTERNAL |
| 290 | # define ZEXPORT __declspec(dllexport) |
| 291 | # define ZEXPORTVA __declspec(dllexport) |
| 292 | # else |
| 293 | # define ZEXPORT __declspec(dllimport) |
| 294 | # define ZEXPORTVA __declspec(dllimport) |
| 295 | # endif |
| 296 | # endif |
| 297 | #endif |
| 298 | |
| 299 | #ifndef ZEXTERN |
| 300 | # define ZEXTERN extern |
| 301 | #endif |
| 302 | #ifndef ZEXPORT |
| 303 | # define ZEXPORT |
| 304 | #endif |
| 305 | #ifndef ZEXPORTVA |
| 306 | # define ZEXPORTVA |
| 307 | #endif |
| 308 | |
| 309 | #ifndef FAR |
| 310 | # define FAR |
| 311 | #endif |
| 312 | |
| 313 | #if !defined(__MACTYPES__) |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 314 | typedef unsigned char Byte; /* 8 bits */ |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 315 | #endif |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 316 | typedef unsigned int uInt; /* 16 bits or more */ |
| 317 | typedef unsigned long uLong; /* 32 bits or more */ |
| 318 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 319 | #ifdef SMALL_MEDIUM |
| 320 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ |
| 321 | # define Bytef Byte FAR |
| 322 | #else |
| 323 | typedef Byte FAR Bytef; |
| 324 | #endif |
| 325 | typedef char FAR charf; |
| 326 | typedef int FAR intf; |
| 327 | typedef uInt FAR uIntf; |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 328 | typedef uLong FAR uLongf; |
| 329 | |
| 330 | #ifdef STDC |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 331 | typedef void const *voidpc; |
| 332 | typedef void FAR *voidpf; |
| 333 | typedef void *voidp; |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 334 | #else |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 335 | typedef Byte const *voidpc; |
| 336 | typedef Byte FAR *voidpf; |
| 337 | typedef Byte *voidp; |
| 338 | #endif |
| 339 | |
| 340 | # ifdef VMS |
| 341 | # include <unixio.h> /* for off_t */ |
| 342 | # endif |
| 343 | # define z_off_t off_t |
| 344 | #ifndef SEEK_SET |
| 345 | # define SEEK_SET 0 /* Seek from beginning of file. */ |
| 346 | # define SEEK_CUR 1 /* Seek from current position. */ |
| 347 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ |
| 348 | #endif |
| 349 | #ifndef z_off_t |
| 350 | # define z_off_t long |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 351 | #endif |
| 352 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 353 | #if defined(__OS400__) |
| 354 | # define NO_vsnprintf |
| 355 | #endif |
| 356 | |
| 357 | #if defined(__MVS__) |
| 358 | # define NO_vsnprintf |
| 359 | # ifdef FAR |
| 360 | # undef FAR |
| 361 | # endif |
| 362 | #endif |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 363 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 364 | /* MVS linker does not support external names larger than 8 bytes */ |
| 365 | #if defined(__MVS__) |
| 366 | # pragma map(deflateInit_,"DEIN") |
| 367 | # pragma map(deflateInit2_,"DEIN2") |
| 368 | # pragma map(deflateEnd,"DEEND") |
| 369 | # pragma map(deflateBound,"DEBND") |
| 370 | # pragma map(inflateInit_,"ININ") |
| 371 | # pragma map(inflateInit2_,"ININ2") |
| 372 | # pragma map(inflateEnd,"INEND") |
| 373 | # pragma map(inflateSync,"INSY") |
| 374 | # pragma map(inflateSetDictionary,"INSEDI") |
| 375 | # pragma map(compressBound,"CMBND") |
| 376 | # pragma map(inflate_table,"INTABL") |
| 377 | # pragma map(inflate_fast,"INFA") |
| 378 | # pragma map(inflate_copyright,"INCOPY") |
| 379 | #endif |
| 380 | /* End of new zconf.h */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 381 | |
| 382 | /* |
| 383 | The 'zlib' compression library provides in-memory compression and |
| 384 | decompression functions, including integrity checks of the uncompressed |
| 385 | data. This version of the library supports only one compression method |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 386 | (deflation) but other algorithms will be added later and will have the same |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 387 | stream interface. |
| 388 | |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 389 | Compression can be done in a single step if the buffers are large |
| 390 | enough (for example if an input file is mmap'ed), or can be done by |
| 391 | repeated calls of the compression function. In the latter case, the |
| 392 | application must provide more input and/or consume the output |
| 393 | (providing more output space) before each call. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 394 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 395 | The compressed data format used by default by the in-memory functions is |
| 396 | the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped |
| 397 | around a deflate stream, which is itself documented in RFC 1951. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 398 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 399 | The library also supports reading and writing files in gzip (.gz) format |
| 400 | with an interface similar to that of stdio using the functions that start |
| 401 | with "gz". The gzip format is different from the zlib format. gzip is a |
| 402 | gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 403 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 404 | This library can optionally read and write gzip streams in memory as well. |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 405 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 406 | The zlib format was designed to be compact and fast for use in memory |
| 407 | and on communications channels. The gzip format was designed for single- |
| 408 | file compression on file systems, has a larger header than zlib to maintain |
| 409 | directory information, and uses a different, slower check method than zlib. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 410 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 411 | The library does not install any signal handler. The decoder checks |
| 412 | the consistency of the compressed data, so the library should never |
| 413 | crash even in case of corrupted input. |
| 414 | */ |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 415 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 416 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
| 417 | typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt size)); |
| 418 | typedef void (*cb_func) OF((Bytef *buf, uInt len)); |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 419 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 420 | struct internal_state; |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 421 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 422 | typedef struct z_stream_s { |
| 423 | Bytef *next_in; /* next input byte */ |
| 424 | uInt avail_in; /* number of bytes available at next_in */ |
| 425 | uLong total_in; /* total nb of input bytes read so far */ |
| 426 | Bytef *next_out; /* next output byte should be put there */ |
| 427 | uInt avail_out; /* remaining free space at next_out */ |
| 428 | uLong total_out; /* total nb of bytes output so far */ |
| 429 | char *msg; /* last error message, NULL if no error */ |
| 430 | struct internal_state FAR *state; /* not visible by applications */ |
| 431 | alloc_func zalloc; /* used to allocate the internal state */ |
| 432 | free_func zfree; /* used to free the internal state */ |
| 433 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
| 434 | int data_type; /* best guess about the data type: |
| 435 | binary or text */ |
| 436 | cb_func outcb; /* called regularly just before blocks of output */ |
| 437 | uLong adler; /* adler32 value of the uncompressed data */ |
| 438 | uLong reserved; /* reserved for future use */ |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 439 | } z_stream; |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 440 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 441 | typedef z_stream FAR *z_streamp; |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 442 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 443 | /* |
| 444 | gzip header information passed to and from zlib routines. See RFC 1952 |
| 445 | for more details on the meanings of these fields. |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 446 | */ |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 447 | typedef struct gz_header_s { |
| 448 | int text; /* true if compressed data believed to be text */ |
| 449 | uLong time; /* modification time */ |
| 450 | int xflags; /* extra flags (not used when writing a gzip file) */ |
| 451 | int os; /* operating system */ |
| 452 | Bytef *extra; /* pointer to extra field or Z_NULL if none */ |
| 453 | uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ |
| 454 | uInt extra_max; /* space at extra (only when reading header) */ |
| 455 | Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ |
| 456 | uInt name_max; /* space at name (only when reading header) */ |
| 457 | Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ |
| 458 | uInt comm_max; /* space at comment (only when reading header) */ |
| 459 | int hcrc; /* true if there was or will be a header crc */ |
| 460 | int done; /* true when done reading gzip header (not used |
| 461 | when writing a gzip file) */ |
| 462 | } gz_header; |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 463 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 464 | typedef gz_header FAR *gz_headerp; |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 465 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 466 | /* constants */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 467 | #define Z_NO_FLUSH 0 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 468 | #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
| 469 | #define Z_SYNC_FLUSH 2 |
| 470 | #define Z_FULL_FLUSH 3 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 471 | #define Z_FINISH 4 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 472 | #define Z_BLOCK 5 |
| 473 | /* Allowed flush values; see deflate() and inflate() below for details */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 474 | |
| 475 | #define Z_OK 0 |
| 476 | #define Z_STREAM_END 1 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 477 | #define Z_NEED_DICT 2 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 478 | #define Z_ERRNO (-1) |
| 479 | #define Z_STREAM_ERROR (-2) |
| 480 | #define Z_DATA_ERROR (-3) |
| 481 | #define Z_MEM_ERROR (-4) |
| 482 | #define Z_BUF_ERROR (-5) |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 483 | /* Return codes for the compression/decompression functions. Negative |
| 484 | * values are errors, positive values are used for special but normal events. |
| 485 | */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 486 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 487 | #define Z_NO_COMPRESSION 0 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 488 | #define Z_BEST_SPEED 1 |
| 489 | #define Z_BEST_COMPRESSION 9 |
| 490 | #define Z_DEFAULT_COMPRESSION (-1) |
| 491 | /* compression levels */ |
| 492 | |
| 493 | #define Z_FILTERED 1 |
| 494 | #define Z_HUFFMAN_ONLY 2 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 495 | #define Z_RLE 3 |
| 496 | #define Z_FIXED 4 |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 497 | #define Z_DEFAULT_STRATEGY 0 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 498 | /* compression strategy; see deflateInit2() below for details */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 499 | |
| 500 | #define Z_BINARY 0 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 501 | #define Z_TEXT 1 |
| 502 | #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 503 | #define Z_UNKNOWN 2 |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 504 | /* Possible values of the data_type field (though see inflate()) */ |
| 505 | |
| 506 | #define Z_DEFLATED 8 |
| 507 | /* The deflate compression method (the only one supported in this version) */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 508 | |
Kim Phillips | 8eb6994 | 2012-10-29 13:34:35 +0000 | [diff] [blame] | 509 | #define Z_NULL (void *)0 /* for initializing zalloc, zfree, opaque */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 510 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 511 | /* basic functions */ |
| 512 | |
| 513 | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 514 | If the first character differs, the library code actually used is |
| 515 | not compatible with the zlib.h header file used by the application. |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 516 | This check is automatically made by deflateInit and inflateInit. |
Lei Wen | 8dd348f | 2012-09-28 04:26:44 +0000 | [diff] [blame] | 517 | */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 518 | |
Lei Wen | 8dd348f | 2012-09-28 04:26:44 +0000 | [diff] [blame] | 519 | ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); |
| 520 | ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 521 | int stream_size)); |
Lei Wen | 8dd348f | 2012-09-28 04:26:44 +0000 | [diff] [blame] | 522 | ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); |
| 523 | ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, |
| 524 | int windowBits, int memLevel, |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 525 | int strategy, |
Lei Wen | 8dd348f | 2012-09-28 04:26:44 +0000 | [diff] [blame] | 526 | int stream_size)); |
| 527 | ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); |
| 528 | ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, |
| 529 | const Bytef *dictionary, |
| 530 | uInt dictLength)); |
| 531 | ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, |
| 532 | gz_headerp head)); |
| 533 | ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, |
| 534 | int bits, |
| 535 | int value)); |
| 536 | ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, |
| 537 | int level, |
| 538 | int strategy)); |
| 539 | ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, |
| 540 | int good_length, |
| 541 | int max_lazy, |
| 542 | int nice_length, |
| 543 | int max_chain)); |
| 544 | ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, |
| 545 | uLong sourceLen)); |
| 546 | ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, |
| 547 | z_streamp source)); |
| 548 | |
Lei Wen | 8dd348f | 2012-09-28 04:26:44 +0000 | [diff] [blame] | 549 | ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 550 | int stream_size)); |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 551 | ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 552 | /* |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 553 | inflate decompresses as much data as possible, and stops when the input |
| 554 | buffer becomes empty or the output buffer becomes full. It may introduce |
| 555 | some output latency (reading input without producing any output) except when |
| 556 | forced to flush. |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 557 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 558 | The detailed semantics are as follows. inflate performs one or both of the |
| 559 | following actions: |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 560 | |
| 561 | - Decompress more input starting at next_in and update next_in and avail_in |
| 562 | accordingly. If not all input can be processed (because there is not |
| 563 | enough room in the output buffer), next_in is updated and processing |
| 564 | will resume at this point for the next call of inflate(). |
| 565 | |
| 566 | - Provide more output starting at next_out and update next_out and avail_out |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 567 | accordingly. inflate() provides as much output as possible, until there |
| 568 | is no more input data or no more space in the output buffer (see below |
| 569 | about the flush parameter). |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 570 | |
| 571 | Before the call of inflate(), the application should ensure that at least |
| 572 | one of the actions is possible, by providing more input and/or consuming |
| 573 | more output, and updating the next_* and avail_* values accordingly. |
| 574 | The application can consume the uncompressed output when it wants, for |
| 575 | example when the output buffer is full (avail_out == 0), or after each |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 576 | call of inflate(). If inflate returns Z_OK and with zero avail_out, it |
| 577 | must be called again after making room in the output buffer because there |
| 578 | might be more output pending. |
| 579 | |
| 580 | The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, |
| 581 | Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much |
| 582 | output as possible to the output buffer. Z_BLOCK requests that inflate() stop |
| 583 | if and when it gets to the next deflate block boundary. When decoding the |
| 584 | zlib or gzip format, this will cause inflate() to return immediately after |
| 585 | the header and before the first block. When doing a raw inflate, inflate() |
| 586 | will go ahead and process the first block, and will return when it gets to |
| 587 | the end of that block, or when it runs out of data. |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 588 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 589 | The Z_BLOCK option assists in appending to or combining deflate streams. |
| 590 | Also to assist in this, on return inflate() will set strm->data_type to the |
| 591 | number of unused bits in the last byte taken from strm->next_in, plus 64 |
| 592 | if inflate() is currently decoding the last block in the deflate stream, |
| 593 | plus 128 if inflate() returned immediately after decoding an end-of-block |
| 594 | code or decoding the complete header up to just before the first byte of the |
| 595 | deflate stream. The end-of-block will not be indicated until all of the |
| 596 | uncompressed data from that block has been written to strm->next_out. The |
| 597 | number of unused bits may in general be greater than seven, except when |
| 598 | bit 7 of data_type is set, in which case the number of unused bits will be |
| 599 | less than eight. |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 600 | |
| 601 | inflate() should normally be called until it returns Z_STREAM_END or an |
| 602 | error. However if all decompression is to be performed in a single step |
| 603 | (a single call of inflate), the parameter flush should be set to |
| 604 | Z_FINISH. In this case all pending input is processed and all pending |
| 605 | output is flushed; avail_out must be large enough to hold all the |
| 606 | uncompressed data. (The size of the uncompressed data may have been saved |
| 607 | by the compressor for this purpose.) The next operation on this stream must |
| 608 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 609 | is never required, but can be used to inform inflate that a faster approach |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 610 | may be used for the single inflate() call. |
| 611 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 612 | In this implementation, inflate() always flushes as much output as |
| 613 | possible to the output buffer, and always uses the faster approach on the |
| 614 | first call. So the only effect of the flush parameter in this implementation |
| 615 | is on the return value of inflate(), as noted below, or when it returns early |
| 616 | because Z_BLOCK is used. |
| 617 | |
| 618 | If a preset dictionary is needed after this call (see inflateSetDictionary |
| 619 | below), inflate sets strm->adler to the adler32 checksum of the dictionary |
| 620 | chosen by the compressor and returns Z_NEED_DICT; otherwise it sets |
| 621 | strm->adler to the adler32 checksum of all output produced so far (that is, |
| 622 | total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described |
| 623 | below. At the end of the stream, inflate() checks that its computed adler32 |
| 624 | checksum is equal to that saved by the compressor and returns Z_STREAM_END |
| 625 | only if the checksum is correct. |
| 626 | |
| 627 | inflate() will decompress and check either zlib-wrapped or gzip-wrapped |
| 628 | deflate data. The header type is detected automatically. Any information |
| 629 | contained in the gzip header is not retained, so applications that need that |
| 630 | information should instead use raw inflate, see inflateInit2() below, or |
| 631 | inflateBack() and perform their own processing of the gzip header and |
| 632 | trailer. |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 633 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 634 | inflate() returns Z_OK if some progress has been made (more input processed |
| 635 | or more output produced), Z_STREAM_END if the end of the compressed data has |
| 636 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
| 637 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was |
| 638 | corrupted (input stream not conforming to the zlib format or incorrect check |
| 639 | value), Z_STREAM_ERROR if the stream structure was inconsistent (for example |
| 640 | if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, |
| 641 | Z_BUF_ERROR if no progress is possible or if there was not enough room in the |
| 642 | output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and |
| 643 | inflate() can be called again with more input and more output space to |
| 644 | continue decompressing. If Z_DATA_ERROR is returned, the application may then |
| 645 | call inflateSync() to look for a good compression block if a partial recovery |
| 646 | of the data is desired. |
| 647 | */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 648 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 649 | ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 650 | /* |
| 651 | All dynamically allocated data structures for this stream are freed. |
| 652 | This function discards any unprocessed input and does not flush any |
| 653 | pending output. |
| 654 | |
| 655 | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state |
| 656 | was inconsistent. In the error case, msg may be set but then points to a |
| 657 | static string (which must not be deallocated). |
| 658 | */ |
| 659 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 660 | /* Advanced functions */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 661 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 662 | ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 663 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 664 | /* utility functions */ |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 665 | |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 666 | /* |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 667 | The following utility functions are implemented on top of the |
| 668 | basic stream-oriented functions. To simplify the interface, some |
| 669 | default options are assumed (compression level and memory usage, |
| 670 | standard memory allocation functions). The source code of these |
| 671 | utility functions can easily be modified if you need special options. |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 672 | */ |
| 673 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 674 | ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 675 | /* |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 676 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
| 677 | return the updated checksum. If buf is NULL, this function returns |
| 678 | the required initial value for the checksum. |
| 679 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed |
| 680 | much faster. Usage example: |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 681 | |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 682 | uLong adler = adler32(0L, Z_NULL, 0); |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 683 | |
| 684 | while (read_buffer(buffer, length) != EOF) { |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 685 | adler = adler32(adler, buffer, length); |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 686 | } |
Wolfgang Denk | 72d0bca | 2009-07-24 14:24:07 +0200 | [diff] [blame] | 687 | if (adler != original_adler) error(); |
Giuseppe CONDORELLI | b4a560a | 2009-07-23 04:54:45 -0400 | [diff] [blame] | 688 | */ |
| 689 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 690 | /* |
| 691 | Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 |
| 692 | and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for |
| 693 | each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of |
| 694 | seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. |
| 695 | */ |
| 696 | |
| 697 | ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len)); |
| 698 | /* |
| 699 | Update a running CRC-32 with the bytes buf[0..len-1] and return the |
| 700 | updated CRC-32. If buf is NULL, this function returns the required initial |
| 701 | value for the for the crc. Pre- and post-conditioning (one's complement) is |
| 702 | performed within this function so it shouldn't be done by the application. |
| 703 | Usage example: |
| 704 | |
| 705 | uLong crc = crc32(0L, Z_NULL, 0); |
| 706 | |
| 707 | while (read_buffer(buffer, length) != EOF) { |
| 708 | crc = crc32(crc, buffer, length); |
| 709 | } |
| 710 | if (crc != original_crc) error(); |
| 711 | */ |
| 712 | |
Joao Marcos Costa | ae8abb1 | 2020-07-30 15:33:49 +0200 | [diff] [blame] | 713 | ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, |
| 714 | const Bytef *source, uLong sourceLen)); |
| 715 | /* |
| 716 | Decompresses the source buffer into the destination buffer. sourceLen is |
| 717 | the byte length of the source buffer. Upon entry, destLen is the total size |
| 718 | of the destination buffer, which must be large enough to hold the entire |
| 719 | uncompressed data. (The size of the uncompressed data must have been saved |
| 720 | previously by the compressor and transmitted to the decompressor by some |
| 721 | mechanism outside the scope of this compression library.) Upon exit, destLen |
| 722 | is the actual size of the uncompressed data. |
| 723 | |
| 724 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
| 725 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
| 726 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In |
| 727 | the case where there is not enough room, uncompress() will fill the output |
| 728 | buffer with the uncompressed data up to that point. |
| 729 | */ |
| 730 | |
| 731 | ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, |
| 732 | const Bytef *source, uLong *sourceLen)); |
| 733 | /* |
| 734 | Same as uncompress, except that sourceLen is a pointer, where the |
| 735 | length of the source is *sourceLen. On return, *sourceLen is the number of |
| 736 | source bytes consumed. |
| 737 | */ |
| 738 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 739 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 740 | int stream_size)); |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 741 | #define inflateInit(strm) \ |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 742 | inflateInit_((strm), sizeof(z_stream)) |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 743 | #define inflateInit2(strm, windowBits) \ |
Tom Rini | 9796bdd | 2024-07-05 09:44:54 -0600 | [diff] [blame] | 744 | inflateInit2_((strm), (windowBits), sizeof(z_stream)) |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 745 | |
| 746 | #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) |
| 747 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
wdenk | 4a5b6a3 | 2001-04-28 17:59:11 +0000 | [diff] [blame] | 748 | #endif |
| 749 | |
Mike Frysinger | 802383b | 2012-04-09 13:39:53 +0000 | [diff] [blame] | 750 | extern void *gzalloc(void *, unsigned, unsigned); |
| 751 | extern void gzfree(void *, void *, unsigned); |
| 752 | |
Giuseppe CONDORELLI | 5e7e8e8 | 2009-07-29 08:05:08 -0400 | [diff] [blame] | 753 | #ifdef __cplusplus |
| 754 | } |
| 755 | #endif |
| 756 | |
| 757 | #endif /* ZLIB_H */ |