Skip to content
Snippets Groups Projects
zlib.h 25.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
    
     * This file is derived from zlib.h and zconf.h from the zlib-1.2.3
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
     * distribution by Jean-loup Gailly and Mark Adler, with some additions
     * by Paul Mackerras to aid in implementing Deflate compression and
     * decompression for PPP packets.
     */
    
    
     /*
      * ==FILEVERSION 960122==
      *
      * This marker is used by the Linux installation script to determine
      * whether an up-to-date version of this file is already installed.
      */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    /* zlib.h -- interface of the 'zlib' general purpose compression library
    
      version 1.2.3, July 18th, 2005
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
      Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
      This software is provided 'as-is', without any express or implied
      warranty.  In no event will the authors be held liable for any damages
      arising from the use of this software.
    
      Permission is granted to anyone to use this software for any purpose,
      including commercial applications, and to alter it and redistribute it
      freely, subject to the following restrictions:
    
      1. The origin of this software must not be misrepresented; you must not
         claim that you wrote the original software. If you use this software
         in a product, an acknowledgment in the product documentation would be
         appreciated but is not required.
      2. Altered source versions must be plainly marked as such, and must not be
         misrepresented as being the original software.
      3. This notice may not be removed or altered from any source distribution.
    
      Jean-loup Gailly        Mark Adler
    
      jloup@gzip.org          madler@alumni.caltech.edu
    
    
      The data format used by the zlib library is described by RFCs (Request for
      Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
      (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
    */
    
    #ifndef ZLIB_H
    #define ZLIB_H
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    #define ZLIB_VERSION "1.2.3"
    #define ZLIB_VERNUM 0x1230
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    /* #include "zconf.h" */        /* included directly here */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /* zconf.h -- configuration of the zlib compression library
    
     * Copyright (C) 1995-2005 Jean-loup Gailly.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
     * For conditions of distribution and use, see copyright notice in zlib.h
     */
    
    
    /* Begin of new zconf.h */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
    
     * If you *really* need a unique prefix for all types and library functions,
     * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
     */
    
    #ifdef Z_PREFIX
    #  define deflateInit_          z_deflateInit_
    #  define deflate               z_deflate
    #  define deflateEnd            z_deflateEnd
    #  define inflateInit_          z_inflateInit_
    #  define inflate               z_inflate
    #  define inflateEnd            z_inflateEnd
    #  define deflateInit2_         z_deflateInit2_
    #  define deflateSetDictionary  z_deflateSetDictionary
    #  define deflateCopy           z_deflateCopy
    #  define deflateReset          z_deflateReset
    #  define deflateParams         z_deflateParams
    #  define deflateBound          z_deflateBound
    #  define deflatePrime          z_deflatePrime
    #  define inflateInit2_         z_inflateInit2_
    #  define inflateSetDictionary  z_inflateSetDictionary
    #  define inflateSync           z_inflateSync
    #  define inflateSyncPoint      z_inflateSyncPoint
    #  define inflateCopy           z_inflateCopy
    #  define inflateReset          z_inflateReset
    #  define inflateBack           z_inflateBack
    #  define inflateBackEnd        z_inflateBackEnd
    #  define compress              z_compress
    #  define compress2             z_compress2
    #  define compressBound         z_compressBound
    #  define uncompress            z_uncompress
    #  define adler32               z_adler32
    #  define crc32                 z_crc32
    #  define get_crc_table         z_get_crc_table
    #  define zError                z_zError
    
    #  define alloc_func            z_alloc_func
    #  define free_func             z_free_func
    #  define in_func               z_in_func
    #  define out_func              z_out_func
    #  define Byte                  z_Byte
    #  define uInt                  z_uInt
    #  define uLong                 z_uLong
    #  define Bytef                 z_Bytef
    #  define charf                 z_charf
    #  define intf                  z_intf
    #  define uIntf                 z_uIntf
    #  define uLongf                z_uLongf
    #  define voidpf                z_voidpf
    #  define voidp                 z_voidp
    #endif
    
    #if defined(__MSDOS__) && !defined(MSDOS)
    #  define MSDOS
    #endif
    #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
    #  define OS2
    #endif
    #if defined(_WINDOWS) && !defined(WINDOWS)
    #  define WINDOWS
    #endif
    #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
    #  ifndef WIN32
    #    define WIN32
    #  endif
    #endif
    #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
    #  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
    #    ifndef SYS16BIT
    #      define SYS16BIT
    #    endif
    #  endif
    #endif
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    /*
     * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
     * than 64k bytes at a time (needed on systems with 16-bit int).
     */
    
    #ifdef SYS16BIT
    #  define MAXSEG_64K
    #endif
    #ifdef MSDOS
    #  define UNALIGNED_OK
    #endif
    
    #ifdef __STDC_VERSION__
    #  ifndef STDC
    
    #    define STDC
    
    #  endif
    
    #  if __STDC_VERSION__ >= 199901L
    #    ifndef STDC99
    #      define STDC99
    #    endif
    #  endif
    #endif
    #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
    #  define STDC
    #endif
    #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
    #  define STDC
    #endif
    #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
    #  define STDC
    #endif
    #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
    #  define STDC
    #endif
    
    #if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
    #  define STDC
    #endif
    
    #ifndef STDC
    #  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
    #    define const       /* note: need a more gentle solution here */
    #  endif
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #endif
    
    
    /* Some Mac compilers merge all .h files incorrectly: */
    #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
    #  define NO_DUMMY_DECL
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #endif
    
    /* Maximum value for memLevel in deflateInit2 */
    #ifndef MAX_MEM_LEVEL
    #  ifdef MAXSEG_64K
    #    define MAX_MEM_LEVEL 8
    #  else
    #    define MAX_MEM_LEVEL 9
    #  endif
    #endif
    
    
    /* Maximum value for windowBits in deflateInit2 and inflateInit2.
     * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
     * created by gzip. (Files created by minigzip can still be extracted by
     * gzip.)
     */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #ifndef MAX_WBITS
    #  define MAX_WBITS   15 /* 32K LZ77 window */
    #endif
    
    /* The memory requirements for deflate are (in bytes):
    
                (1 << (windowBits+2)) +  (1 << (memLevel+9))
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
     that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
     plus a few kilobytes for small objects. For example, if you want to reduce
     the default memory requirements from 256K to 128K, compile with
         make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
     Of course this will generally degrade compression (there's no free lunch).
    
       The memory requirements for inflate are (in bytes) 1 << windowBits
     that is, 32K for windowBits=15 (default value) plus a few kilobytes
     for small objects.
    */
    
    
                            /* Type declarations */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    #ifndef OF /* function prototypes */
    #  ifdef STDC
    #    define OF(args)  args
    #  else
    #    define OF(args)  ()
    #  endif
    #endif
    
    
    /* The following definitions for FAR are needed only for MSDOS mixed
     * model programming (small or medium model with some far allocations).
     * This was tested only with MSC; for other MSDOS compilers you may have
     * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
     * just define FAR to be empty.
     */
    #ifdef SYS16BIT
    #  if defined(M_I86SM) || defined(M_I86MM)
         /* MSC small or medium model */
    #    define SMALL_MEDIUM
    #    ifdef _MSC_VER
    #      define FAR _far
    #    else
    #      define FAR far
    #    endif
    #  endif
    #  if (defined(__SMALL__) || defined(__MEDIUM__))
         /* Turbo C small or medium model */
    #    define SMALL_MEDIUM
    #    ifdef __BORLANDC__
    #      define FAR _far
    #    else
    #      define FAR far
    #    endif
    #  endif
    #endif
    
    #if defined(WINDOWS) || defined(WIN32)
       /* If building or using zlib as a DLL, define ZLIB_DLL.
        * This is not mandatory, but it offers a little performance increase.
        */
    #  ifdef ZLIB_DLL
    #    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
    #      ifdef ZLIB_INTERNAL
    #        define ZEXTERN extern __declspec(dllexport)
    #      else
    #        define ZEXTERN extern __declspec(dllimport)
    #      endif
    #    endif
    #  endif  /* ZLIB_DLL */
       /* If building or using zlib with the WINAPI/WINAPIV calling convention,
        * define ZLIB_WINAPI.
        * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
        */
    #  ifdef ZLIB_WINAPI
    #    ifdef FAR
    #      undef FAR
    #    endif
    #    include <windows.h>
         /* No need for _export, use ZLIB.DEF instead. */
         /* For complete Windows compatibility, use WINAPI, not __stdcall. */
    #    define ZEXPORT WINAPI
    #    ifdef WIN32
    #      define ZEXPORTVA WINAPIV
    #    else
    #      define ZEXPORTVA FAR CDECL
    #    endif
    #  endif
    #endif
    
    #if defined (__BEOS__)
    #  ifdef ZLIB_DLL
    #    ifdef ZLIB_INTERNAL
    #      define ZEXPORT   __declspec(dllexport)
    #      define ZEXPORTVA __declspec(dllexport)
    #    else
    #      define ZEXPORT   __declspec(dllimport)
    #      define ZEXPORTVA __declspec(dllimport)
    #    endif
    #  endif
    #endif
    
    #ifndef ZEXTERN
    #  define ZEXTERN extern
    #endif
    #ifndef ZEXPORT
    #  define ZEXPORT
    #endif
    #ifndef ZEXPORTVA
    #  define ZEXPORTVA
    #endif
    
    #ifndef FAR
    #  define FAR
    #endif
    
    #if !defined(__MACTYPES__)
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    typedef unsigned char  Byte;  /* 8 bits */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    typedef unsigned int   uInt;  /* 16 bits or more */
    typedef unsigned long  uLong; /* 32 bits or more */
    
    
    #ifdef SMALL_MEDIUM
       /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
    #  define Bytef Byte FAR
    #else
       typedef Byte  FAR Bytef;
    #endif
    typedef char  FAR charf;
    typedef int   FAR intf;
    typedef uInt  FAR uIntf;
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    typedef uLong FAR uLongf;
    
    #ifdef STDC
    
       typedef void const *voidpc;
       typedef void FAR   *voidpf;
       typedef void       *voidp;
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #else
    
       typedef Byte const *voidpc;
       typedef Byte FAR   *voidpf;
       typedef Byte       *voidp;
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    #  ifdef VMS
    #    include <unixio.h>   /* for off_t */
    #  endif
    #  define z_off_t off_t
    #ifndef SEEK_SET
    #  define SEEK_SET        0       /* Seek from beginning of file.  */
    #  define SEEK_CUR        1       /* Seek from current position.  */
    #  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
    #endif
    #ifndef z_off_t
    #  define z_off_t long
    #endif
    
    #if defined(__OS400__)
    #  define NO_vsnprintf
    #endif
    
    #if defined(__MVS__)
    #  define NO_vsnprintf
    #  ifdef FAR
    #    undef FAR
    #  endif
    #endif
    
    /* MVS linker does not support external names larger than 8 bytes */
    #if defined(__MVS__)
    #   pragma map(deflateInit_,"DEIN")
    #   pragma map(deflateInit2_,"DEIN2")
    #   pragma map(deflateEnd,"DEEND")
    #   pragma map(deflateBound,"DEBND")
    #   pragma map(inflateInit_,"ININ")
    #   pragma map(inflateInit2_,"ININ2")
    #   pragma map(inflateEnd,"INEND")
    #   pragma map(inflateSync,"INSY")
    #   pragma map(inflateSetDictionary,"INSEDI")
    #   pragma map(compressBound,"CMBND")
    #   pragma map(inflate_table,"INTABL")
    #   pragma map(inflate_fast,"INFA")
    #   pragma map(inflate_copyright,"INCOPY")
    #endif
    /* End of new zconf.h */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    /*
         The 'zlib' compression library provides in-memory compression and
      decompression functions, including integrity checks of the uncompressed
      data.  This version of the library supports only one compression method
    
      (deflation) but other algorithms will be added later and will have the same
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
      stream interface.
    
         Compression can be done in a single step if the buffers are large
      enough (for example if an input file is mmap'ed), or can be done by
      repeated calls of the compression function.  In the latter case, the
      application must provide more input and/or consume the output
      (providing more output space) before each call.
    
         The compressed data format used by default by the in-memory functions is
      the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
      around a deflate stream, which is itself documented in RFC 1951.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
         The library also supports reading and writing files in gzip (.gz) format
      with an interface similar to that of stdio using the functions that start
      with "gz".  The gzip format is different from the zlib format.  gzip is a
      gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
    
         This library can optionally read and write gzip streams in memory as well.
    
         The zlib format was designed to be compact and fast for use in memory
      and on communications channels.  The gzip format was designed for single-
      file compression on file systems, has a larger header than zlib to maintain
      directory information, and uses a different, slower check method than zlib.
    
         The library does not install any signal handler. The decoder checks
      the consistency of the compressed data, so the library should never
      crash even in case of corrupted input.
    */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
    typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt size));
    typedef void   (*cb_func)    OF((Bytef *buf, uInt len));
    
    struct internal_state;
    
    typedef struct z_stream_s {
    	Bytef	*next_in; /* next input byte */
    	uInt	avail_in; /* number of bytes available at next_in */
    	uLong	total_in; /* total nb of input bytes read so far */
    	Bytef	*next_out; /* next output byte should be put there */
    	uInt	avail_out; /* remaining free space at next_out */
    	uLong	total_out; /* total nb of bytes output so far */
    	char	*msg;	/* last error message, NULL if no error */
    	struct	internal_state FAR *state; /* not visible by applications */
    	alloc_func	zalloc;	/* used to allocate the internal state */
    	free_func	zfree;	/* used to free the internal state */
    	voidpf	opaque;	/* private data object passed to zalloc and zfree */
    	int	data_type;	/* best guess about the data type:
    					binary or text */
    	cb_func	outcb;	/* called regularly just before blocks of output */
    	uLong	adler;	/* adler32 value of the uncompressed data */
    	uLong	reserved;	/* reserved for future use */
    
    } z_stream;
    
    typedef z_stream FAR *z_streamp;
    
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
    
         gzip header information passed to and from zlib routines.  See RFC 1952
      for more details on the meanings of these fields.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    */
    
    typedef struct gz_header_s {
    	int	text;	/* true if compressed data believed to be text */
    	uLong	time;	/* modification time */
    	int	xflags;	/* extra flags (not used when writing a gzip file) */
    	int	os;	/* operating system */
    	Bytef	*extra;	/* pointer to extra field or Z_NULL if none */
    	uInt	extra_len; /* extra field length (valid if extra != Z_NULL) */
    	uInt	extra_max; /* space at extra (only when reading header) */
    	Bytef	*name; /* pointer to zero-terminated file name or Z_NULL */
    	uInt	name_max; /* space at name (only when reading header) */
    	Bytef	*comment; /* pointer to zero-terminated comment or Z_NULL */
    	uInt	comm_max; /* space at comment (only when reading header) */
    	int	hcrc; /* true if there was or will be a header crc */
    	int	done; /* true when done reading gzip header (not used
    			when writing a gzip file) */
    } gz_header;
    
    typedef gz_header FAR *gz_headerp;
    
                            /* constants */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_NO_FLUSH      0
    
    #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
    #define Z_SYNC_FLUSH    2
    #define Z_FULL_FLUSH    3
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_FINISH        4
    
    #define Z_BLOCK         5
    /* Allowed flush values; see deflate() and inflate() below for details */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    #define Z_OK            0
    #define Z_STREAM_END    1
    
    #define Z_NEED_DICT     2
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_ERRNO        (-1)
    #define Z_STREAM_ERROR (-2)
    #define Z_DATA_ERROR   (-3)
    #define Z_MEM_ERROR    (-4)
    #define Z_BUF_ERROR    (-5)
    
    #define Z_VERSION_ERROR (-6)
    /* Return codes for the compression/decompression functions. Negative
     * values are errors, positive values are used for special but normal events.
     */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    #define Z_NO_COMPRESSION         0
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_BEST_SPEED             1
    #define Z_BEST_COMPRESSION       9
    #define Z_DEFAULT_COMPRESSION  (-1)
    /* compression levels */
    
    #define Z_FILTERED            1
    #define Z_HUFFMAN_ONLY        2
    
    #define Z_RLE                 3
    #define Z_FIXED               4
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_DEFAULT_STRATEGY    0
    
    /* compression strategy; see deflateInit2() below for details */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    #define Z_BINARY   0
    
    #define Z_TEXT     1
    #define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #define Z_UNKNOWN  2
    
    /* Possible values of the data_type field (though see inflate()) */
    
    #define Z_DEFLATED   8
    /* The deflate compression method (the only one supported in this version) */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
    
    
                            /* basic functions */
    
    /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
       If the first character differs, the library code actually used is
       not compatible with the zlib.h header file used by the application.
    
       This check is automatically made by deflateInit and inflateInit.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
     */
    
    
    ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, const char *version,
    				int stream_size));
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
    
        inflate decompresses as much data as possible, and stops when the input
      buffer becomes empty or the output buffer becomes full. It may introduce
      some output latency (reading input without producing any output) except when
      forced to flush.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
      The detailed semantics are as follows. inflate performs one or both of the
      following actions:
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
      - Decompress more input starting at next_in and update next_in and avail_in
        accordingly. If not all input can be processed (because there is not
        enough room in the output buffer), next_in is updated and processing
        will resume at this point for the next call of inflate().
    
      - Provide more output starting at next_out and update next_out and avail_out
    
        accordingly.  inflate() provides as much output as possible, until there
        is no more input data or no more space in the output buffer (see below
        about the flush parameter).
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
      Before the call of inflate(), the application should ensure that at least
      one of the actions is possible, by providing more input and/or consuming
      more output, and updating the next_* and avail_* values accordingly.
      The application can consume the uncompressed output when it wants, for
      example when the output buffer is full (avail_out == 0), or after each
    
      call of inflate(). If inflate returns Z_OK and with zero avail_out, it
      must be called again after making room in the output buffer because there
      might be more output pending.
    
        The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
      Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
      output as possible to the output buffer. Z_BLOCK requests that inflate() stop
      if and when it gets to the next deflate block boundary. When decoding the
      zlib or gzip format, this will cause inflate() to return immediately after
      the header and before the first block. When doing a raw inflate, inflate()
      will go ahead and process the first block, and will return when it gets to
      the end of that block, or when it runs out of data.
    
        The Z_BLOCK option assists in appending to or combining deflate streams.
      Also to assist in this, on return inflate() will set strm->data_type to the
      number of unused bits in the last byte taken from strm->next_in, plus 64
      if inflate() is currently decoding the last block in the deflate stream,
      plus 128 if inflate() returned immediately after decoding an end-of-block
      code or decoding the complete header up to just before the first byte of the
      deflate stream. The end-of-block will not be indicated until all of the
      uncompressed data from that block has been written to strm->next_out.  The
      number of unused bits may in general be greater than seven, except when
      bit 7 of data_type is set, in which case the number of unused bits will be
      less than eight.
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
        inflate() should normally be called until it returns Z_STREAM_END or an
      error. However if all decompression is to be performed in a single step
      (a single call of inflate), the parameter flush should be set to
      Z_FINISH. In this case all pending input is processed and all pending
      output is flushed; avail_out must be large enough to hold all the
      uncompressed data. (The size of the uncompressed data may have been saved
      by the compressor for this purpose.) The next operation on this stream must
      be inflateEnd to deallocate the decompression state. The use of Z_FINISH
    
      is never required, but can be used to inform inflate that a faster approach
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
      may be used for the single inflate() call.
    
    
         In this implementation, inflate() always flushes as much output as
      possible to the output buffer, and always uses the faster approach on the
      first call. So the only effect of the flush parameter in this implementation
      is on the return value of inflate(), as noted below, or when it returns early
      because Z_BLOCK is used.
    
         If a preset dictionary is needed after this call (see inflateSetDictionary
      below), inflate sets strm->adler to the adler32 checksum of the dictionary
      chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
      strm->adler to the adler32 checksum of all output produced so far (that is,
      total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
      below. At the end of the stream, inflate() checks that its computed adler32
      checksum is equal to that saved by the compressor and returns Z_STREAM_END
      only if the checksum is correct.
    
        inflate() will decompress and check either zlib-wrapped or gzip-wrapped
      deflate data.  The header type is detected automatically.  Any information
      contained in the gzip header is not retained, so applications that need that
      information should instead use raw inflate, see inflateInit2() below, or
      inflateBack() and perform their own processing of the gzip header and
      trailer.
    
        inflate() returns Z_OK if some progress has been made (more input processed
      or more output produced), Z_STREAM_END if the end of the compressed data has
      been reached and all uncompressed output has been produced, Z_NEED_DICT if a
      preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
      corrupted (input stream not conforming to the zlib format or incorrect check
      value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
      if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
      Z_BUF_ERROR if no progress is possible or if there was not enough room in the
      output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
      inflate() can be called again with more input and more output space to
      continue decompressing. If Z_DATA_ERROR is returned, the application may then
      call inflateSync() to look for a good compression block if a partial recovery
      of the data is desired.
    */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
         All dynamically allocated data structures for this stream are freed.
       This function discards any unprocessed input and does not flush any
       pending output.
    
         inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
       was inconsistent. In the error case, msg may be set but then points to a
       static string (which must not be deallocated).
    */
    
    
                            /* Advanced functions */
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    
    
    ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
    
                            /* utility functions */
    
         The following utility functions are implemented on top of the
       basic stream-oriented functions. To simplify the interface, some
       default options are assumed (compression level and memory usage,
       standard memory allocation functions). The source code of these
       utility functions can easily be modified if you need special options.
    
    ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    /*
         Update a running Adler-32 checksum with the bytes buf[0..len-1] and
       return the updated checksum. If buf is NULL, this function returns
       the required initial value for the checksum.
       An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
       much faster. Usage example:
    
         uLong adler = adler32(0L, Z_NULL, 0);
    
         while (read_buffer(buffer, length) != EOF) {
           adler = adler32(adler, buffer, length);
         }
         if (adler != original_adler) error();
    */
    
    
    /*
         Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
       and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
       each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
       seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
    */
    
    ZEXTERN  uInt ZEXPORT crc32  OF((uInt crc, const Bytef *buf, uInt len));
    /*
         Update a running CRC-32 with the bytes buf[0..len-1] and return the
       updated CRC-32. If buf is NULL, this function returns the required initial
       value for the for the crc. Pre- and post-conditioning (one's complement) is
       performed within this function so it shouldn't be done by the application.
       Usage example:
    
         uLong crc = crc32(0L, Z_NULL, 0);
    
         while (read_buffer(buffer, length) != EOF) {
           crc = crc32(crc, buffer, length);
         }
         if (crc != original_crc) error();
    */
    
    ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
                                          const char *version, int stream_size));
    #define inflateInit(strm) \
    	inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
    #define inflateInit2(strm, windowBits) \
    	inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
    
    #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
    	struct internal_state {int dummy;}; /* hack for buggy compilers */
    #endif
    
    #ifdef __cplusplus
    }
    
    Wolfgang Denk's avatar
    Wolfgang Denk committed
    #endif
    
    
    #endif /* ZLIB_H */