1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Sun designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Sun in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  21  * CA 95054 USA or visit www.sun.com if you need additional information or
  22  * have any questions.
  23  *
  24  * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
  25  */
  26 
  27 /*
  28   This file is available under and governed by the GNU General Public
  29   License version 2 only, as published by the Free Software Foundation.
  30   However, the following notice accompanied the original version of this
  31   file and, per its terms, should not be removed:
  32 
  33   zlib.h -- interface of the 'zlib' general purpose compression library
  34   version 1.1.3, July 9th, 1998
  35 
  36   Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
  37 
  38   This software is provided 'as-is', without any express or implied
  39   warranty.  In no event will the authors be held liable for any damages
  40   arising from the use of this software.
  41 
  42   Permission is granted to anyone to use this software for any purpose,
  43   including commercial applications, and to alter it and redistribute it
  44   freely, subject to the following restrictions:
  45 
  46   1. The origin of this software must not be misrepresented; you must not
  47      claim that you wrote the original software. If you use this software
  48      in a product, an acknowledgment in the product documentation would be
  49      appreciated but is not required.
  50   2. Altered source versions must be plainly marked as such, and must not be
  51      misrepresented as being the original software.
  52   3. This notice may not be removed or altered from any source distribution.
  53 
  54   Jean-loup Gailly        Mark Adler
  55   jloup@gzip.org          madler@alumni.caltech.edu
  56 
  57 
  58   The data format used by the zlib library is described by RFCs (Request for
  59   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
  60   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  61 */
  62 
  63 /* This distribution of zlib 1.1.3.f-jdk contains changes by Sun Microsystems.
  64    The changes, made on or before 23 Apr 2003, are are described in ChangeLog.
  65 
  66    For help or issues with these changes, please contact: tl-dev@sun.com
  67 */
  68 
  69 #ifndef _ZLIB_H
  70 #define _ZLIB_H
  71 
  72 #include "zconf.h"
  73 
  74 #ifdef __cplusplus
  75 extern "C" {
  76 #endif
  77 
  78 #define ZLIB_VERSION "1.1.3.f-jdk"
  79 
  80 /*
  81      The 'zlib' compression library provides in-memory compression and
  82   decompression functions, including integrity checks of the uncompressed
  83   data.  This version of the library supports only one compression method
  84   (deflation) but other algorithms will be added later and will have the same
  85   stream interface.
  86 
  87      Compression can be done in a single step if the buffers are large
  88   enough (for example if an input file is mmap'ed), or can be done by
  89   repeated calls of the compression function.  In the latter case, the
  90   application must provide more input and/or consume the output
  91   (providing more output space) before each call.
  92 
  93      The library also supports reading and writing files in gzip (.gz) format
  94   with an interface similar to that of stdio.
  95 
  96      The library does not install any signal handler. The decoder checks
  97   the consistency of the compressed data, so the library should never
  98   crash even in case of corrupted input.
  99 */
 100 
 101 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
 102 typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
 103 
 104 struct internal_state;
 105 
 106 typedef struct z_stream_s {
 107     Bytef    *next_in;  /* next input byte */
 108     uInt     avail_in;  /* number of bytes available at next_in */
 109     uLong    total_in;  /* total nb of input bytes read so far */
 110 
 111     Bytef    *next_out; /* next output byte should be put there */
 112     uInt     avail_out; /* remaining free space at next_out */
 113     uLong    total_out; /* total nb of bytes output so far */
 114 
 115     char     *msg;      /* last error message, NULL if no error */
 116     struct internal_state FAR *state; /* not visible by applications */
 117 
 118     alloc_func zalloc;  /* used to allocate the internal state */
 119     free_func  zfree;   /* used to free the internal state */
 120     voidpf     opaque;  /* private data object passed to zalloc and zfree */
 121 
 122     int     data_type;  /* best guess about the data type: ascii or binary */
 123     uLong   adler;      /* adler32 value of the uncompressed data */
 124     uLong   reserved;   /* reserved for future use */
 125 } z_stream;
 126 
 127 typedef z_stream FAR *z_streamp;
 128 
 129 /*
 130    The application must update next_in and avail_in when avail_in has
 131    dropped to zero. It must update next_out and avail_out when avail_out
 132    has dropped to zero. The application must initialize zalloc, zfree and
 133    opaque before calling the init function. All other fields are set by the
 134    compression library and must not be updated by the application.
 135 
 136    The opaque value provided by the application will be passed as the first
 137    parameter for calls of zalloc and zfree. This can be useful for custom
 138    memory management. The compression library attaches no meaning to the
 139    opaque value.
 140 
 141    zalloc must return Z_NULL if there is not enough memory for the object.
 142    If zlib is used in a multi-threaded application, zalloc and zfree must be
 143    thread safe.
 144 
 145    On 16-bit systems, the functions zalloc and zfree must be able to allocate
 146    exactly 65536 bytes, but will not be required to allocate more than this
 147    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
 148    pointers returned by zalloc for objects of exactly 65536 bytes *must*
 149    have their offset normalized to zero. The default allocation function
 150    provided by this library ensures this (see zutil.c). To reduce memory
 151    requirements and avoid any allocation of 64K objects, at the expense of
 152    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
 153 
 154    The fields total_in and total_out can be used for statistics or
 155    progress reports. After compression, total_in holds the total size of
 156    the uncompressed data and may be saved for use in the decompressor
 157    (particularly if the decompressor wants to decompress everything in
 158    a single step).
 159 */
 160 
 161                         /* constants */
 162 
 163 #define Z_NO_FLUSH      0
 164 #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
 165 #define Z_SYNC_FLUSH    2
 166 #define Z_FULL_FLUSH    3
 167 #define Z_FINISH        4
 168 /* Allowed flush values; see deflate() below for details */
 169 
 170 #define Z_OK            0
 171 #define Z_STREAM_END    1
 172 #define Z_NEED_DICT     2
 173 #define Z_ERRNO        (-1)
 174 #define Z_STREAM_ERROR (-2)
 175 #define Z_DATA_ERROR   (-3)
 176 #define Z_MEM_ERROR    (-4)
 177 #define Z_BUF_ERROR    (-5)
 178 #define Z_VERSION_ERROR (-6)
 179 /* Return codes for the compression/decompression functions. Negative
 180  * values are errors, positive values are used for special but normal events.
 181  */
 182 
 183 #define Z_NO_COMPRESSION         0
 184 #define Z_BEST_SPEED             1
 185 #define Z_BEST_COMPRESSION       9
 186 #define Z_DEFAULT_COMPRESSION  (-1)
 187 /* compression levels */
 188 
 189 #define Z_FILTERED            1
 190 #define Z_HUFFMAN_ONLY        2
 191 #define Z_DEFAULT_STRATEGY    0
 192 /* compression strategy; see deflateInit2() below for details */
 193 
 194 #define Z_BINARY   0
 195 #define Z_ASCII    1
 196 #define Z_UNKNOWN  2
 197 /* Possible values of the data_type field */
 198 
 199 #define Z_DEFLATED   8
 200 /* The deflate compression method (the only one supported in this version) */
 201 
 202 #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
 203 
 204 #define zlib_version zlibVersion()
 205 /* for compatibility with versions < 1.0.2 */
 206 
 207                         /* basic functions */
 208 
 209 ZEXTERN const char * ZEXPORT zlibVersion OF((void));
 210 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
 211    If the first character differs, the library code actually used is
 212    not compatible with the zlib.h header file used by the application.
 213    This check is automatically made by deflateInit and inflateInit.
 214  */
 215 
 216 /*
 217 ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
 218 
 219      Initializes the internal stream state for compression. The fields
 220    zalloc, zfree and opaque must be initialized before by the caller.
 221    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
 222    use default allocation functions.
 223 
 224      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 225    1 gives best speed, 9 gives best compression, 0 gives no compression at
 226    all (the input data is simply copied a block at a time).
 227    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
 228    compression (currently equivalent to level 6).
 229 
 230      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
 231    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
 232    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
 233    with the version assumed by the caller (ZLIB_VERSION).
 234    msg is set to null if there is no error message.  deflateInit does not
 235    perform any compression: this will be done by deflate().
 236 */
 237 
 238 
 239 ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
 240 /*
 241     deflate compresses as much data as possible, and stops when the input
 242   buffer becomes empty or the output buffer becomes full. It may introduce some
 243   output latency (reading input without producing any output) except when
 244   forced to flush.
 245 
 246     The detailed semantics are as follows. deflate performs one or both of the
 247   following actions:
 248 
 249   - Compress more input starting at next_in and update next_in and avail_in
 250     accordingly. If not all input can be processed (because there is not
 251     enough room in the output buffer), next_in and avail_in are updated and
 252     processing will resume at this point for the next call of deflate().
 253 
 254   - Provide more output starting at next_out and update next_out and avail_out
 255     accordingly. This action is forced if the parameter flush is non zero.
 256     Forcing flush frequently degrades the compression ratio, so this parameter
 257     should be set only when necessary (in interactive applications).
 258     Some output may be provided even if flush is not set.
 259 
 260   Before the call of deflate(), the application should ensure that at least
 261   one of the actions is possible, by providing more input and/or consuming
 262   more output, and updating avail_in or avail_out accordingly; avail_out
 263   should never be zero before the call. The application can consume the
 264   compressed output when it wants, for example when the output buffer is full
 265   (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
 266   and with zero avail_out, it must be called again after making room in the
 267   output buffer because there might be more output pending.
 268 
 269     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 270   flushed to the output buffer and the output is aligned on a byte boundary, so
 271   that the decompressor can get all input data available so far. (In particular
 272   avail_in is zero after the call if enough output space has been provided
 273   before the call.)  Flushing may degrade compression for some compression
 274   algorithms and so it should be used only when necessary.
 275 
 276     If flush is set to Z_FULL_FLUSH, all output is flushed as with
 277   Z_SYNC_FLUSH, and the compression state is reset so that decompression can
 278   restart from this point if previous compressed data has been damaged or if
 279   random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
 280   the compression.
 281 
 282     If deflate returns with avail_out == 0, this function must be called again
 283   with the same value of the flush parameter and more output space (updated
 284   avail_out), until the flush is complete (deflate returns with non-zero
 285   avail_out).
 286 
 287     If the parameter flush is set to Z_FINISH, pending input is processed,
 288   pending output is flushed and deflate returns with Z_STREAM_END if there
 289   was enough output space; if deflate returns with Z_OK, this function must be
 290   called again with Z_FINISH and more output space (updated avail_out) but no
 291   more input data, until it returns with Z_STREAM_END or an error. After
 292   deflate has returned Z_STREAM_END, the only possible operations on the
 293   stream are deflateReset or deflateEnd.
 294 
 295     Z_FINISH can be used immediately after deflateInit if all the compression
 296   is to be done in a single step. In this case, avail_out must be at least
 297   0.1% larger than avail_in plus 12 bytes.  If deflate does not return
 298   Z_STREAM_END, then it must be called again as described above.
 299 
 300     deflate() sets strm->adler to the adler32 checksum of all input read
 301   so far (that is, total_in bytes).
 302 
 303     deflate() may update data_type if it can make a good guess about
 304   the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
 305   binary. This field is only for information purposes and does not affect
 306   the compression algorithm in any manner.
 307 
 308     deflate() returns Z_OK if some progress has been made (more input
 309   processed or more output produced), Z_STREAM_END if all input has been
 310   consumed and all output has been produced (only when flush is set to
 311   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
 312   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
 313   (for example avail_in or avail_out was zero).
 314 */
 315 
 316 
 317 ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
 318 /*
 319      All dynamically allocated data structures for this stream are freed.
 320    This function discards any unprocessed input and does not flush any
 321    pending output.
 322 
 323      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
 324    stream state was inconsistent, Z_DATA_ERROR if the stream was freed
 325    prematurely (some input or output was discarded). In the error case,
 326    msg may be set but then points to a static string (which must not be
 327    deallocated).
 328 */
 329 
 330 
 331 /*
 332 ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
 333 
 334      Initializes the internal stream state for decompression. The fields
 335    next_in, avail_in, zalloc, zfree and opaque must be initialized before by
 336    the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
 337    value depends on the compression method), inflateInit determines the
 338    compression method from the zlib header and allocates all data structures
 339    accordingly; otherwise the allocation will be deferred to the first call of
 340    inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
 341    use default allocation functions.
 342 
 343      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
 344    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
 345    version assumed by the caller.  msg is set to null if there is no error
 346    message. inflateInit does not perform any decompression apart from reading
 347    the zlib header if present: this will be done by inflate().  (So next_in and
 348    avail_in may be modified, but next_out and avail_out are unchanged.)
 349 */
 350 
 351 
 352 ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
 353 /*
 354     inflate decompresses as much data as possible, and stops when the input
 355   buffer becomes empty or the output buffer becomes full. It may
 356   introduce some output latency (reading input without producing any output)
 357   except when forced to flush.
 358 
 359   The detailed semantics are as follows. inflate performs one or both of the
 360   following actions:
 361 
 362   - Decompress more input starting at next_in and update next_in and avail_in
 363     accordingly. If not all input can be processed (because there is not
 364     enough room in the output buffer), next_in is updated and processing
 365     will resume at this point for the next call of inflate().
 366 
 367   - Provide more output starting at next_out and update next_out and avail_out
 368     accordingly.  inflate() provides as much output as possible, until there
 369     is no more input data or no more space in the output buffer (see below
 370     about the flush parameter).
 371 
 372   Before the call of inflate(), the application should ensure that at least
 373   one of the actions is possible, by providing more input and/or consuming
 374   more output, and updating the next_* and avail_* values accordingly.
 375   The application can consume the uncompressed output when it wants, for
 376   example when the output buffer is full (avail_out == 0), or after each
 377   call of inflate(). If inflate returns Z_OK and with zero avail_out, it
 378   must be called again after making room in the output buffer because there
 379   might be more output pending.
 380 
 381     If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
 382   output as possible to the output buffer. The flushing behavior of inflate is
 383   not specified for values of the flush parameter other than Z_SYNC_FLUSH
 384   and Z_FINISH, but the current implementation actually flushes as much output
 385   as possible anyway.
 386 
 387     inflate() should normally be called until it returns Z_STREAM_END or an
 388   error. However if all decompression is to be performed in a single step
 389   (a single call of inflate), the parameter flush should be set to
 390   Z_FINISH. In this case all pending input is processed and all pending
 391   output is flushed; avail_out must be large enough to hold all the
 392   uncompressed data. (The size of the uncompressed data may have been saved
 393   by the compressor for this purpose.) The next operation on this stream must
 394   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
 395   is never required, but can be used to inform inflate that a faster routine
 396   may be used for the single inflate() call.
 397 
 398      If a preset dictionary is needed at this point (see inflateSetDictionary
 399   below), inflate sets strm->adler to the adler32 checksum of the
 400   dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
 401   it sets strm->adler to the adler32 checksum of all output produced
 402   so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
 403   an error code as described below. At the end of the stream, inflate()
 404   checks that its computed adler32 checksum is equal to that saved by the
 405   compressor and returns Z_STREAM_END only if the checksum is correct.
 406 
 407     inflate() returns Z_OK if some progress has been made (more input processed
 408   or more output produced), Z_STREAM_END if the end of the compressed data has
 409   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
 410   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
 411   corrupted (input stream not conforming to the zlib format or incorrect
 412   adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
 413   (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
 414   enough memory, Z_BUF_ERROR if no progress is possible or if there was not
 415   enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
 416   case, the application may then call inflateSync to look for a good
 417   compression block.
 418 */
 419 
 420 
 421 ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
 422 /*
 423      All dynamically allocated data structures for this stream are freed.
 424    This function discards any unprocessed input and does not flush any
 425    pending output.
 426 
 427      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
 428    was inconsistent. In the error case, msg may be set but then points to a
 429    static string (which must not be deallocated).
 430 */
 431 
 432                         /* Advanced functions */
 433 
 434 /*
 435     The following functions are needed only in some special applications.
 436 */
 437 
 438 /*
 439 ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
 440                                      int  level,
 441                                      int  method,
 442                                      int  windowBits,
 443                                      int  memLevel,
 444                                      int  strategy));
 445 
 446      This is another version of deflateInit with more compression options. The
 447    fields next_in, zalloc, zfree and opaque must be initialized before by
 448    the caller.
 449 
 450      The method parameter is the compression method. It must be Z_DEFLATED in
 451    this version of the library.
 452 
 453      The windowBits parameter is the base two logarithm of the window size
 454    (the size of the history buffer).  It should be in the range 8..15 for this
 455    version of the library. Larger values of this parameter result in better
 456    compression at the expense of memory usage. The default value is 15 if
 457    deflateInit is used instead.
 458 
 459      The memLevel parameter specifies how much memory should be allocated
 460    for the internal compression state. memLevel=1 uses minimum memory but
 461    is slow and reduces compression ratio; memLevel=9 uses maximum memory
 462    for optimal speed. The default value is 8. See zconf.h for total memory
 463    usage as a function of windowBits and memLevel.
 464 
 465      The strategy parameter is used to tune the compression algorithm. Use the
 466    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
 467    filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
 468    string match).  Filtered data consists mostly of small values with a
 469    somewhat random distribution. In this case, the compression algorithm is
 470    tuned to compress them better. The effect of Z_FILTERED is to force more
 471    Huffman coding and less string matching; it is somewhat intermediate
 472    between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
 473    the compression ratio but not the correctness of the compressed output even
 474    if it is not set appropriately.
 475 
 476       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 477    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
 478    method). msg is set to null if there is no error message.  deflateInit2 does
 479    not perform any compression: this will be done by deflate().
 480 */
 481 
 482 ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
 483                                              const Bytef *dictionary,
 484                                              uInt  dictLength));
 485 /*
 486      Initializes the compression dictionary from the given byte sequence
 487    without producing any compressed output. This function must be called
 488    immediately after deflateInit, deflateInit2 or deflateReset, before any
 489    call of deflate. The compressor and decompressor must use exactly the same
 490    dictionary (see inflateSetDictionary).
 491 
 492      The dictionary should consist of strings (byte sequences) that are likely
 493    to be encountered later in the data to be compressed, with the most commonly
 494    used strings preferably put towards the end of the dictionary. Using a
 495    dictionary is most useful when the data to be compressed is short and can be
 496    predicted with good accuracy; the data can then be compressed better than
 497    with the default empty dictionary.
 498 
 499      Depending on the size of the compression data structures selected by
 500    deflateInit or deflateInit2, a part of the dictionary may in effect be
 501    discarded, for example if the dictionary is larger than the window size in
 502    deflate or deflate2. Thus the strings most likely to be useful should be
 503    put at the end of the dictionary, not at the front.
 504 
 505      Upon return of this function, strm->adler is set to the Adler32 value
 506    of the dictionary; the decompressor may later use this value to determine
 507    which dictionary has been used by the compressor. (The Adler32 value
 508    applies to the whole dictionary even if only a subset of the dictionary is
 509    actually used by the compressor.)
 510 
 511      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
 512    parameter is invalid (such as NULL dictionary) or the stream state is
 513    inconsistent (for example if deflate has already been called for this stream
 514    or if the compression method is bsort). deflateSetDictionary does not
 515    perform any compression: this will be done by deflate().
 516 */
 517 
 518 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
 519                                     z_streamp source));
 520 /*
 521      Sets the destination stream as a complete copy of the source stream.
 522 
 523      This function can be useful when several compression strategies will be
 524    tried, for example when there are several ways of pre-processing the input
 525    data with a filter. The streams that will be discarded should then be freed
 526    by calling deflateEnd.  Note that deflateCopy duplicates the internal
 527    compression state which can be quite large, so this strategy is slow and
 528    can consume lots of memory.
 529 
 530      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
 531    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
 532    (such as zalloc being NULL). msg is left unchanged in both source and
 533    destination.
 534 */
 535 
 536 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
 537 /*
 538      This function is equivalent to deflateEnd followed by deflateInit,
 539    but does not free and reallocate all the internal compression state.
 540    The stream will keep the same compression level and any other attributes
 541    that may have been set by deflateInit2.
 542 
 543       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 544    stream state was inconsistent (such as zalloc or state being NULL).
 545 */
 546 
 547 ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
 548                                       int level,
 549                                       int strategy));
 550 /*
 551      Dynamically update the compression level and compression strategy.  The
 552    interpretation of level and strategy is as in deflateInit2.  This can be
 553    used to switch between compression and straight copy of the input data, or
 554    to switch to a different kind of input data requiring a different
 555    strategy. If the compression level is changed, the input available so far
 556    is compressed with the old level (and may be flushed); the new level will
 557    take effect only at the next call of deflate().
 558 
 559      Before the call of deflateParams, the stream state must be set as for
 560    a call of deflate(), since the currently available input may have to
 561    be compressed and flushed. In particular, strm->avail_out must be non-zero.
 562 
 563      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
 564    stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
 565    if strm->avail_out was zero.
 566 */
 567 
 568 /*
 569 ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
 570                                      int  windowBits));
 571 
 572      This is another version of inflateInit with an extra parameter. The
 573    fields next_in, avail_in, zalloc, zfree and opaque must be initialized
 574    before by the caller.
 575 
 576      The windowBits parameter is the base two logarithm of the maximum window
 577    size (the size of the history buffer).  It should be in the range 8..15 for
 578    this version of the library. The default value is 15 if inflateInit is used
 579    instead. If a compressed stream with a larger window size is given as
 580    input, inflate() will return with the error code Z_DATA_ERROR instead of
 581    trying to allocate a larger window.
 582 
 583       inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 584    memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
 585    memLevel). msg is set to null if there is no error message.  inflateInit2
 586    does not perform any decompression apart from reading the zlib header if
 587    present: this will be done by inflate(). (So next_in and avail_in may be
 588    modified, but next_out and avail_out are unchanged.)
 589 */
 590 
 591 ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
 592                                              const Bytef *dictionary,
 593                                              uInt  dictLength));
 594 /*
 595      Initializes the decompression dictionary from the given uncompressed byte
 596    sequence. This function must be called immediately after a call of inflate
 597    if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
 598    can be determined from the Adler32 value returned by this call of
 599    inflate. The compressor and decompressor must use exactly the same
 600    dictionary (see deflateSetDictionary).
 601 
 602      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
 603    parameter is invalid (such as NULL dictionary) or the stream state is
 604    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
 605    expected one (incorrect Adler32 value). inflateSetDictionary does not
 606    perform any decompression: this will be done by subsequent calls of
 607    inflate().
 608 */
 609 
 610 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
 611 /*
 612     Skips invalid compressed data until a full flush point (see above the
 613   description of deflate with Z_FULL_FLUSH) can be found, or until all
 614   available input is skipped. No output is provided.
 615 
 616     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
 617   if no more input was provided, Z_DATA_ERROR if no flush point has been found,
 618   or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
 619   case, the application may save the current current value of total_in which
 620   indicates where valid compressed data was found. In the error case, the
 621   application may repeatedly call inflateSync, providing more input each time,
 622   until success or end of the input data.
 623 */
 624 
 625 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
 626 /*
 627      This function is equivalent to inflateEnd followed by inflateInit,
 628    but does not free and reallocate all the internal decompression state.
 629    The stream will keep attributes that may have been set by inflateInit2.
 630 
 631       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 632    stream state was inconsistent (such as zalloc or state being NULL).
 633 */
 634 
 635 
 636                         /* utility functions */
 637 
 638 /*
 639      The following utility functions are implemented on top of the
 640    basic stream-oriented functions. To simplify the interface, some
 641    default options are assumed (compression level and memory usage,
 642    standard memory allocation functions). The source code of these
 643    utility functions can easily be modified if you need special options.
 644 */
 645 
 646 ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
 647                                  const Bytef *source, uLong sourceLen));
 648 /*
 649      Compresses the source buffer into the destination buffer.  sourceLen is
 650    the byte length of the source buffer. Upon entry, destLen is the total
 651    size of the destination buffer, which must be at least 0.1% larger than
 652    sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
 653    compressed buffer.
 654      This function can be used to compress a whole file at once if the
 655    input file is mmap'ed.
 656      compress returns Z_OK if success, Z_MEM_ERROR if there was not
 657    enough memory, Z_BUF_ERROR if there was not enough room in the output
 658    buffer.
 659 */
 660 
 661 ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
 662                                   const Bytef *source, uLong sourceLen,
 663                                   int level));
 664 /*
 665      Compresses the source buffer into the destination buffer. The level
 666    parameter has the same meaning as in deflateInit.  sourceLen is the byte
 667    length of the source buffer. Upon entry, destLen is the total size of the
 668    destination buffer, which must be at least 0.1% larger than sourceLen plus
 669    12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
 670 
 671      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 672    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
 673    Z_STREAM_ERROR if the level parameter is invalid.
 674 */
 675 
 676 ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 677                                    const Bytef *source, uLong sourceLen));
 678 /*
 679      Decompresses the source buffer into the destination buffer.  sourceLen is
 680    the byte length of the source buffer. Upon entry, destLen is the total
 681    size of the destination buffer, which must be large enough to hold the
 682    entire uncompressed data. (The size of the uncompressed data must have
 683    been saved previously by the compressor and transmitted to the decompressor
 684    by some mechanism outside the scope of this compression library.)
 685    Upon exit, destLen is the actual size of the compressed buffer.
 686      This function can be used to decompress a whole file at once if the
 687    input file is mmap'ed.
 688 
 689      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
 690    enough memory, Z_BUF_ERROR if there was not enough room in the output
 691    buffer, or Z_DATA_ERROR if the input data was corrupted.
 692 */
 693 
 694 
 695 typedef voidp gzFile;
 696 
 697 ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
 698 /*
 699      Opens a gzip (.gz) file for reading or writing. The mode parameter
 700    is as in fopen ("rb" or "wb") but can also include a compression level
 701    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
 702    Huffman only compression as in "wb1h". (See the description
 703    of deflateInit2 for more information about the strategy parameter.)
 704 
 705      gzopen can be used to read a file which is not in gzip format; in this
 706    case gzread will directly read from the file without decompression.
 707 
 708      gzopen returns NULL if the file could not be opened or if there was
 709    insufficient memory to allocate the (de)compression state; errno
 710    can be checked to distinguish the two cases (if errno is zero, the
 711    zlib error is Z_MEM_ERROR).  */
 712 
 713 ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
 714 /*
 715      gzdopen() associates a gzFile with the file descriptor fd.  File
 716    descriptors are obtained from calls like open, dup, creat, pipe or
 717    fileno (in the file has been previously opened with fopen).
 718    The mode parameter is as in gzopen.
 719      The next call of gzclose on the returned gzFile will also close the
 720    file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
 721    descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
 722      gzdopen returns NULL if there was insufficient memory to allocate
 723    the (de)compression state.
 724 */
 725 
 726 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
 727 /*
 728      Dynamically update the compression level or strategy. See the description
 729    of deflateInit2 for the meaning of these parameters.
 730      gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
 731    opened for writing.
 732 */
 733 
 734 ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
 735 /*
 736      Reads the given number of uncompressed bytes from the compressed file.
 737    If the input file was not in gzip format, gzread copies the given number
 738    of bytes into the buffer.
 739      gzread returns the number of uncompressed bytes actually read (0 for
 740    end of file, -1 for error). */
 741 
 742 ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,
 743                                    const voidp buf, unsigned len));
 744 /*
 745      Writes the given number of uncompressed bytes into the compressed file.
 746    gzwrite returns the number of uncompressed bytes actually written
 747    (0 in case of error).
 748 */
 749 
 750 ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
 751 /*
 752      Converts, formats, and writes the args to the compressed file under
 753    control of the format string, as in fprintf. gzprintf returns the number of
 754    uncompressed bytes actually written (0 in case of error).
 755 */
 756 
 757 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
 758 /*
 759       Writes the given null-terminated string to the compressed file, excluding
 760    the terminating null character.
 761       gzputs returns the number of characters written, or -1 in case of error.
 762 */
 763 
 764 ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
 765 /*
 766       Reads bytes from the compressed file until len-1 characters are read, or
 767    a newline character is read and transferred to buf, or an end-of-file
 768    condition is encountered.  The string is then terminated with a null
 769    character.
 770       gzgets returns buf, or Z_NULL in case of error.
 771 */
 772 
 773 ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
 774 /*
 775       Writes c, converted to an unsigned char, into the compressed file.
 776    gzputc returns the value that was written, or -1 in case of error.
 777 */
 778 
 779 ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
 780 /*
 781       Reads one byte from the compressed file. gzgetc returns this byte
 782    or -1 in case of end of file or error.
 783 */
 784 
 785 ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
 786 /*
 787      Flushes all pending output into the compressed file. The parameter
 788    flush is as in the deflate() function. The return value is the zlib
 789    error number (see function gzerror below). gzflush returns Z_OK if
 790    the flush parameter is Z_FINISH and all output could be flushed.
 791      gzflush should be called only when strictly necessary because it can
 792    degrade compression.
 793 */
 794 
 795 ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
 796                                       z_off_t offset, int whence));
 797 /*
 798       Sets the starting position for the next gzread or gzwrite on the
 799    given compressed file. The offset represents a number of bytes in the
 800    uncompressed data stream. The whence parameter is defined as in lseek(2);
 801    the value SEEK_END is not supported.
 802      If the file is opened for reading, this function is emulated but can be
 803    extremely slow. If the file is opened for writing, only forward seeks are
 804    supported; gzseek then compresses a sequence of zeroes up to the new
 805    starting position.
 806 
 807       gzseek returns the resulting offset location as measured in bytes from
 808    the beginning of the uncompressed stream, or -1 in case of error, in
 809    particular if the file is opened for writing and the new starting position
 810    would be before the current position.
 811 */
 812 
 813 ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
 814 /*
 815      Rewinds the given file. This function is supported only for reading.
 816 
 817    gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 818 */
 819 
 820 ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
 821 /*
 822      Returns the starting position for the next gzread or gzwrite on the
 823    given compressed file. This position represents a number of bytes in the
 824    uncompressed data stream.
 825 
 826    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 827 */
 828 
 829 ZEXTERN int ZEXPORT gzeof OF((gzFile file));
 830 /*
 831      Returns 1 when EOF has previously been detected reading the given
 832    input stream, otherwise zero.
 833 */
 834 
 835 ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
 836 /*
 837      Flushes all pending output if necessary, closes the compressed file
 838    and deallocates all the (de)compression state. The return value is the zlib
 839    error number (see function gzerror below).
 840 */
 841 
 842 ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
 843 /*
 844      Returns the error message for the last error which occurred on the
 845    given compressed file. errnum is set to zlib error number. If an
 846    error occurred in the file system and not in the compression library,
 847    errnum is set to Z_ERRNO and the application may consult errno
 848    to get the exact error code.
 849 */
 850 
 851                         /* checksum functions */
 852 
 853 /*
 854      These functions are not related to compression but are exported
 855    anyway because they might be useful in applications using the
 856    compression library.
 857 */
 858 
 859 ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
 860 
 861 /*
 862      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
 863    return the updated checksum. If buf is NULL, this function returns
 864    the required initial value for the checksum.
 865    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
 866    much faster. Usage example:
 867 
 868      uLong adler = adler32(0L, Z_NULL, 0);
 869 
 870      while (read_buffer(buffer, length) != EOF) {
 871        adler = adler32(adler, buffer, length);
 872      }
 873      if (adler != original_adler) error();
 874 */
 875 
 876 ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
 877 /*
 878      Update a running crc with the bytes buf[0..len-1] and return the updated
 879    crc. If buf is NULL, this function returns the required initial value
 880    for the crc. Pre- and post-conditioning (one's complement) is performed
 881    within this function so it shouldn't be done by the application.
 882    Usage example:
 883 
 884      uLong crc = crc32(0L, Z_NULL, 0);
 885 
 886      while (read_buffer(buffer, length) != EOF) {
 887        crc = crc32(crc, buffer, length);
 888      }
 889      if (crc != original_crc) error();
 890 */
 891 
 892 
 893                         /* various hacks, don't look :) */
 894 
 895 /* deflateInit and inflateInit are macros to allow checking the zlib version
 896  * and the compiler's view of z_stream:
 897  */
 898 ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
 899                                      const char *version, int stream_size));
 900 ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
 901                                      const char *version, int stream_size));
 902 ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
 903                                       int windowBits, int memLevel,
 904                                       int strategy, const char *version,
 905                                       int stream_size));
 906 ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
 907                                       const char *version, int stream_size));
 908 #define deflateInit(strm, level) \
 909         deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
 910 #define inflateInit(strm) \
 911         inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
 912 #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
 913         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
 914                       (strategy),           ZLIB_VERSION, sizeof(z_stream))
 915 #define inflateInit2(strm, windowBits) \
 916         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
 917 
 918 
 919 #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
 920     struct internal_state {int dummy;}; /* hack for buggy compilers */
 921 #endif
 922 
 923 ZEXTERN const char   * ZEXPORT zError           OF((int err));
 924 ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
 925 ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
 926 
 927 #ifdef __cplusplus
 928 }
 929 #endif
 930 
 931 #endif /* _ZLIB_H */