17c478bd9Sstevel@tonic-gate /* $Id: zlib.h,v 1.1 1999/03/23 03:21:58 paulus Exp $ */ 27c478bd9Sstevel@tonic-gate 37c478bd9Sstevel@tonic-gate /* 47c478bd9Sstevel@tonic-gate * This file is derived from zlib.h and zconf.h from the zlib-0.95 57c478bd9Sstevel@tonic-gate * distribution by Jean-loup Gailly and Mark Adler, with some additions 67c478bd9Sstevel@tonic-gate * by Paul Mackerras to aid in implementing Deflate compression and 77c478bd9Sstevel@tonic-gate * decompression for PPP packets. 87c478bd9Sstevel@tonic-gate */ 97c478bd9Sstevel@tonic-gate 107c478bd9Sstevel@tonic-gate /* zlib.h -- interface of the 'zlib' general purpose compression library 117c478bd9Sstevel@tonic-gate version 0.95, Aug 16th, 1995. 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate Copyright (C) 1995 Jean-loup Gailly and Mark Adler 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate This software is provided 'as-is', without any express or implied 167c478bd9Sstevel@tonic-gate warranty. In no event will the authors be held liable for any damages 177c478bd9Sstevel@tonic-gate arising from the use of this software. 187c478bd9Sstevel@tonic-gate 197c478bd9Sstevel@tonic-gate Permission is granted to anyone to use this software for any purpose, 207c478bd9Sstevel@tonic-gate including commercial applications, and to alter it and redistribute it 217c478bd9Sstevel@tonic-gate freely, subject to the following restrictions: 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate 1. The origin of this software must not be misrepresented; you must not 247c478bd9Sstevel@tonic-gate claim that you wrote the original software. If you use this software 257c478bd9Sstevel@tonic-gate in a product, an acknowledgment in the product documentation would be 267c478bd9Sstevel@tonic-gate appreciated but is not required. 277c478bd9Sstevel@tonic-gate 2. Altered source versions must be plainly marked as such, and must not be 287c478bd9Sstevel@tonic-gate misrepresented as being the original software. 297c478bd9Sstevel@tonic-gate 3. This notice may not be removed or altered from any source distribution. 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate Jean-loup Gailly Mark Adler 327c478bd9Sstevel@tonic-gate gzip@prep.ai.mit.edu madler@alumni.caltech.edu 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifndef _ZLIB_H 367c478bd9Sstevel@tonic-gate #define _ZLIB_H 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* #include "zconf.h" */ /* included directly here */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* zconf.h -- configuration of the zlib compression library 417c478bd9Sstevel@tonic-gate * Copyright (C) 1995 Jean-loup Gailly. 42*55fea89dSDan Cross * For conditions of distribution and use, see copyright notice in zlib.h 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate The library does not install any signal handler. It is recommended to 497c478bd9Sstevel@tonic-gate add at least a handler for SIGSEGV when decompressing; the library checks 507c478bd9Sstevel@tonic-gate the consistency of the input data whenever possible but may go nuts 517c478bd9Sstevel@tonic-gate for some forms of corrupted input. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 567c478bd9Sstevel@tonic-gate * than 64k bytes at a time (needed on systems with 16-bit int). 577c478bd9Sstevel@tonic-gate * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints 587c478bd9Sstevel@tonic-gate * at addresses which are not a multiple of their size. 597c478bd9Sstevel@tonic-gate * Under DOS, -DFAR=far or -DFAR=__far may be needed. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #ifndef STDC 637c478bd9Sstevel@tonic-gate # if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus) 647c478bd9Sstevel@tonic-gate # define STDC 657c478bd9Sstevel@tonic-gate # endif 667c478bd9Sstevel@tonic-gate #endif 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */ 697c478bd9Sstevel@tonic-gate # include <unix.h> 707c478bd9Sstevel@tonic-gate #endif 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* Maximum value for memLevel in deflateInit2 */ 737c478bd9Sstevel@tonic-gate #ifndef MAX_MEM_LEVEL 747c478bd9Sstevel@tonic-gate # ifdef MAXSEG_64K 757c478bd9Sstevel@tonic-gate # define MAX_MEM_LEVEL 8 767c478bd9Sstevel@tonic-gate # else 777c478bd9Sstevel@tonic-gate # define MAX_MEM_LEVEL 9 787c478bd9Sstevel@tonic-gate # endif 797c478bd9Sstevel@tonic-gate #endif 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #ifndef FAR 827c478bd9Sstevel@tonic-gate # define FAR 837c478bd9Sstevel@tonic-gate #endif 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* Maximum value for windowBits in deflateInit2 and inflateInit2 */ 867c478bd9Sstevel@tonic-gate #ifndef MAX_WBITS 877c478bd9Sstevel@tonic-gate # define MAX_WBITS 15 /* 32K LZ77 window */ 887c478bd9Sstevel@tonic-gate #endif 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* The memory requirements for deflate are (in bytes): 917c478bd9Sstevel@tonic-gate 1 << (windowBits+2) + 1 << (memLevel+9) 927c478bd9Sstevel@tonic-gate that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 937c478bd9Sstevel@tonic-gate plus a few kilobytes for small objects. For example, if you want to reduce 947c478bd9Sstevel@tonic-gate the default memory requirements from 256K to 128K, compile with 957c478bd9Sstevel@tonic-gate make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 967c478bd9Sstevel@tonic-gate Of course this will generally degrade compression (there's no free lunch). 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate The memory requirements for inflate are (in bytes) 1 << windowBits 997c478bd9Sstevel@tonic-gate that is, 32K for windowBits=15 (default value) plus a few kilobytes 1007c478bd9Sstevel@tonic-gate for small objects. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* Type declarations */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #ifndef OF /* function prototypes */ 1067c478bd9Sstevel@tonic-gate # ifdef STDC 1077c478bd9Sstevel@tonic-gate # define OF(args) args 1087c478bd9Sstevel@tonic-gate # else 1097c478bd9Sstevel@tonic-gate # define OF(args) () 1107c478bd9Sstevel@tonic-gate # endif 1117c478bd9Sstevel@tonic-gate #endif 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate typedef unsigned char Byte; /* 8 bits */ 1147c478bd9Sstevel@tonic-gate typedef unsigned int uInt; /* 16 bits or more */ 1157c478bd9Sstevel@tonic-gate typedef unsigned long uLong; /* 32 bits or more */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate typedef Byte FAR Bytef; 1187c478bd9Sstevel@tonic-gate typedef char FAR charf; 1197c478bd9Sstevel@tonic-gate typedef int FAR intf; 1207c478bd9Sstevel@tonic-gate typedef uInt FAR uIntf; 1217c478bd9Sstevel@tonic-gate typedef uLong FAR uLongf; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #ifdef STDC 1247c478bd9Sstevel@tonic-gate typedef void FAR *voidpf; 1257c478bd9Sstevel@tonic-gate typedef void *voidp; 1267c478bd9Sstevel@tonic-gate #else 1277c478bd9Sstevel@tonic-gate typedef Byte FAR *voidpf; 1287c478bd9Sstevel@tonic-gate typedef Byte *voidp; 1297c478bd9Sstevel@tonic-gate #endif 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* end of original zconf.h */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate #define ZLIB_VERSION "0.95P" 1347c478bd9Sstevel@tonic-gate 135*55fea89dSDan Cross /* 1367c478bd9Sstevel@tonic-gate The 'zlib' compression library provides in-memory compression and 1377c478bd9Sstevel@tonic-gate decompression functions, including integrity checks of the uncompressed 1387c478bd9Sstevel@tonic-gate data. This version of the library supports only one compression method 1397c478bd9Sstevel@tonic-gate (deflation) but other algorithms may be added later and will have the same 1407c478bd9Sstevel@tonic-gate stream interface. 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate For compression the application must provide the output buffer and 1437c478bd9Sstevel@tonic-gate may optionally provide the input buffer for optimization. For decompression, 1447c478bd9Sstevel@tonic-gate the application must provide the input buffer and may optionally provide 1457c478bd9Sstevel@tonic-gate the output buffer for optimization. 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate Compression can be done in a single step if the buffers are large 1487c478bd9Sstevel@tonic-gate enough (for example if an input file is mmap'ed), or can be done by 1497c478bd9Sstevel@tonic-gate repeated calls of the compression function. In the latter case, the 1507c478bd9Sstevel@tonic-gate application must provide more input and/or consume the output 1517c478bd9Sstevel@tonic-gate (providing more output space) before each call. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 1557c478bd9Sstevel@tonic-gate typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt nbytes)); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate struct internal_state; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate typedef struct z_stream_s { 1607c478bd9Sstevel@tonic-gate Bytef *next_in; /* next input byte */ 1617c478bd9Sstevel@tonic-gate uInt avail_in; /* number of bytes available at next_in */ 1627c478bd9Sstevel@tonic-gate uLong total_in; /* total nb of input bytes read so far */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate Bytef *next_out; /* next output byte should be put there */ 1657c478bd9Sstevel@tonic-gate uInt avail_out; /* remaining free space at next_out */ 1667c478bd9Sstevel@tonic-gate uLong total_out; /* total nb of bytes output so far */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate char *msg; /* last error message, NULL if no error */ 1697c478bd9Sstevel@tonic-gate struct internal_state FAR *state; /* not visible by applications */ 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate alloc_func zalloc; /* used to allocate the internal state */ 1727c478bd9Sstevel@tonic-gate free_func zfree; /* used to free the internal state */ 1737c478bd9Sstevel@tonic-gate voidp opaque; /* private data object passed to zalloc and zfree */ 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate Byte data_type; /* best guess about the data type: ascii or binary */ 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate } z_stream; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate The application must update next_in and avail_in when avail_in has 1817c478bd9Sstevel@tonic-gate dropped to zero. It must update next_out and avail_out when avail_out 1827c478bd9Sstevel@tonic-gate has dropped to zero. The application must initialize zalloc, zfree and 1837c478bd9Sstevel@tonic-gate opaque before calling the init function. All other fields are set by the 1847c478bd9Sstevel@tonic-gate compression library and must not be updated by the application. 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate The opaque value provided by the application will be passed as the first 1877c478bd9Sstevel@tonic-gate parameter for calls of zalloc and zfree. This can be useful for custom 1887c478bd9Sstevel@tonic-gate memory management. The compression library attaches no meaning to the 1897c478bd9Sstevel@tonic-gate opaque value. 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate zalloc must return Z_NULL if there is not enough memory for the object. 1927c478bd9Sstevel@tonic-gate On 16-bit systems, the functions zalloc and zfree must be able to allocate 1937c478bd9Sstevel@tonic-gate exactly 65536 bytes, but will not be required to allocate more than this 1947c478bd9Sstevel@tonic-gate if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 1957c478bd9Sstevel@tonic-gate pointers returned by zalloc for objects of exactly 65536 bytes *must* 1967c478bd9Sstevel@tonic-gate have their offset normalized to zero. The default allocation function 1977c478bd9Sstevel@tonic-gate provided by this library ensures this (see zutil.c). To reduce memory 1987c478bd9Sstevel@tonic-gate requirements and avoid any allocation of 64K objects, at the expense of 1997c478bd9Sstevel@tonic-gate compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate The fields total_in and total_out can be used for statistics or 2027c478bd9Sstevel@tonic-gate progress reports. After compression, total_in holds the total size of 2037c478bd9Sstevel@tonic-gate the uncompressed data and may be saved for use in the decompressor 2047c478bd9Sstevel@tonic-gate (particularly if the decompressor wants to decompress everything in 2057c478bd9Sstevel@tonic-gate a single step). 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* constants */ 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #define Z_NO_FLUSH 0 2117c478bd9Sstevel@tonic-gate #define Z_PARTIAL_FLUSH 1 2127c478bd9Sstevel@tonic-gate #define Z_FULL_FLUSH 2 2137c478bd9Sstevel@tonic-gate #define Z_SYNC_FLUSH 3 /* experimental: partial_flush + byte align */ 2147c478bd9Sstevel@tonic-gate #define Z_FINISH 4 2157c478bd9Sstevel@tonic-gate #define Z_PACKET_FLUSH 5 2167c478bd9Sstevel@tonic-gate /* See deflate() below for the usage of these constants */ 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate #define Z_OK 0 2197c478bd9Sstevel@tonic-gate #define Z_STREAM_END 1 2207c478bd9Sstevel@tonic-gate #define Z_ERRNO (-1) 2217c478bd9Sstevel@tonic-gate #define Z_STREAM_ERROR (-2) 2227c478bd9Sstevel@tonic-gate #define Z_DATA_ERROR (-3) 2237c478bd9Sstevel@tonic-gate #define Z_MEM_ERROR (-4) 2247c478bd9Sstevel@tonic-gate #define Z_BUF_ERROR (-5) 2257c478bd9Sstevel@tonic-gate /* error codes for the compression/decompression functions */ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #define Z_BEST_SPEED 1 2287c478bd9Sstevel@tonic-gate #define Z_BEST_COMPRESSION 9 2297c478bd9Sstevel@tonic-gate #define Z_DEFAULT_COMPRESSION (-1) 2307c478bd9Sstevel@tonic-gate /* compression levels */ 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate #define Z_FILTERED 1 2337c478bd9Sstevel@tonic-gate #define Z_HUFFMAN_ONLY 2 2347c478bd9Sstevel@tonic-gate #define Z_DEFAULT_STRATEGY 0 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate #define Z_BINARY 0 2377c478bd9Sstevel@tonic-gate #define Z_ASCII 1 2387c478bd9Sstevel@tonic-gate #define Z_UNKNOWN 2 2397c478bd9Sstevel@tonic-gate /* Used to set the data_type field */ 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate extern char *zlib_version; 2447c478bd9Sstevel@tonic-gate /* The application can compare zlib_version and ZLIB_VERSION for consistency. 2457c478bd9Sstevel@tonic-gate If the first character differs, the library code actually used is 2467c478bd9Sstevel@tonic-gate not compatible with the zlib.h header file used by the application. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* basic functions */ 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate extern int deflateInit OF((z_stream *strm, int level)); 252*55fea89dSDan Cross /* 2537c478bd9Sstevel@tonic-gate Initializes the internal stream state for compression. The fields 2547c478bd9Sstevel@tonic-gate zalloc, zfree and opaque must be initialized before by the caller. 2557c478bd9Sstevel@tonic-gate If zalloc and zfree are set to Z_NULL, deflateInit updates them to 2567c478bd9Sstevel@tonic-gate use default allocation functions. 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate The compression level must be Z_DEFAULT_COMPRESSION, or between 1 and 9: 2597c478bd9Sstevel@tonic-gate 1 gives best speed, 9 gives best compression. Z_DEFAULT_COMPRESSION requests 2607c478bd9Sstevel@tonic-gate a default compromise between speed and compression (currently equivalent 2617c478bd9Sstevel@tonic-gate to level 6). 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 2647c478bd9Sstevel@tonic-gate enough memory, Z_STREAM_ERROR if level is not a valid compression level. 2657c478bd9Sstevel@tonic-gate msg is set to null if there is no error message. deflateInit does not 2667c478bd9Sstevel@tonic-gate perform any compression: this will be done by deflate(). 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate extern int deflate OF((z_stream *strm, int flush)); 2717c478bd9Sstevel@tonic-gate /* 2727c478bd9Sstevel@tonic-gate Performs one or both of the following actions: 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate - Compress more input starting at next_in and update next_in and avail_in 2757c478bd9Sstevel@tonic-gate accordingly. If not all input can be processed (because there is not 2767c478bd9Sstevel@tonic-gate enough room in the output buffer), next_in and avail_in are updated and 2777c478bd9Sstevel@tonic-gate processing will resume at this point for the next call of deflate(). 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate - Provide more output starting at next_out and update next_out and avail_out 2807c478bd9Sstevel@tonic-gate accordingly. This action is forced if the parameter flush is non zero. 2817c478bd9Sstevel@tonic-gate Forcing flush frequently degrades the compression ratio, so this parameter 2827c478bd9Sstevel@tonic-gate should be set only when necessary (in interactive applications). 2837c478bd9Sstevel@tonic-gate Some output may be provided even if flush is not set. 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate Before the call of deflate(), the application should ensure that at least 2867c478bd9Sstevel@tonic-gate one of the actions is possible, by providing more input and/or consuming 2877c478bd9Sstevel@tonic-gate more output, and updating avail_in or avail_out accordingly; avail_out 2887c478bd9Sstevel@tonic-gate should never be zero before the call. The application can consume the 2897c478bd9Sstevel@tonic-gate compressed output when it wants, for example when the output buffer is full 2907c478bd9Sstevel@tonic-gate (avail_out == 0), or after each call of deflate(). 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression 2937c478bd9Sstevel@tonic-gate block is terminated and flushed to the output buffer so that the 2947c478bd9Sstevel@tonic-gate decompressor can get all input data available so far. For method 9, a future 2957c478bd9Sstevel@tonic-gate variant on method 8, the current block will be flushed but not terminated. 2967c478bd9Sstevel@tonic-gate If flush is set to Z_FULL_FLUSH, the compression block is terminated, a 2977c478bd9Sstevel@tonic-gate special marker is output and the compression dictionary is discarded; this 2987c478bd9Sstevel@tonic-gate is useful to allow the decompressor to synchronize if one compressed block 2997c478bd9Sstevel@tonic-gate has been damaged (see inflateSync below). Flushing degrades compression and 3007c478bd9Sstevel@tonic-gate so should be used only when necessary. Using Z_FULL_FLUSH too often can 3017c478bd9Sstevel@tonic-gate seriously degrade the compression. If deflate returns with avail_out == 0, 3027c478bd9Sstevel@tonic-gate this function must be called again with the same value of the flush 3037c478bd9Sstevel@tonic-gate parameter and more output space (updated avail_out), until the flush is 3047c478bd9Sstevel@tonic-gate complete (deflate returns with non-zero avail_out). 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_PACKET_FLUSH, the compression 3077c478bd9Sstevel@tonic-gate block is terminated, and a zero-length stored block is output, 3087c478bd9Sstevel@tonic-gate omitting the length bytes (the effect of this is that the 3-bit type 3097c478bd9Sstevel@tonic-gate code 000 for a stored block is output, and the output is then 3107c478bd9Sstevel@tonic-gate byte-aligned). This is designed for use at the end of a PPP packet. 3117c478bd9Sstevel@tonic-gate In addition, if the current compression block contains all the data 3127c478bd9Sstevel@tonic-gate since the last Z_PACKET_FLUSH, it is never output as a stored block. 3137c478bd9Sstevel@tonic-gate If the current compression block output as a static or dynamic block 3147c478bd9Sstevel@tonic-gate would not be at least `minCompression' bytes smaller than the 3157c478bd9Sstevel@tonic-gate original data, then nothing is output for that block. (The type 3167c478bd9Sstevel@tonic-gate code for the zero-length stored block is still output, resulting in 3177c478bd9Sstevel@tonic-gate a single zero byte being output for the whole packet.) 3187c478bd9Sstevel@tonic-gate `MinCompression' is a parameter to deflateInit2, or 0 if deflateInit 3197c478bd9Sstevel@tonic-gate is used. 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_FINISH, all pending input is processed, 3227c478bd9Sstevel@tonic-gate all pending output is flushed and deflate returns with Z_STREAM_END if there 3237c478bd9Sstevel@tonic-gate was enough output space; if deflate returns with Z_OK, this function must be 3247c478bd9Sstevel@tonic-gate called again with Z_FINISH and more output space (updated avail_out) but no 3257c478bd9Sstevel@tonic-gate more input data, until it returns with Z_STREAM_END or an error. After 3267c478bd9Sstevel@tonic-gate deflate has returned Z_STREAM_END, the only possible operations on the 3277c478bd9Sstevel@tonic-gate stream are deflateReset or deflateEnd. 328*55fea89dSDan Cross 3297c478bd9Sstevel@tonic-gate Z_FINISH can be used immediately after deflateInit if all the compression 3307c478bd9Sstevel@tonic-gate is to be done in a single step. In this case, avail_out must be at least 3317c478bd9Sstevel@tonic-gate 0.1% larger than avail_in plus 12 bytes. If deflate does not return 3327c478bd9Sstevel@tonic-gate Z_STREAM_END, then it must be called again as described above. 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate deflate() may update data_type if it can make a good guess about 3357c478bd9Sstevel@tonic-gate the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered 3367c478bd9Sstevel@tonic-gate binary. This field is only for information purposes and does not affect 3377c478bd9Sstevel@tonic-gate the compression algorithm in any manner. 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate deflate() returns Z_OK if some progress has been made (more input 3407c478bd9Sstevel@tonic-gate processed or more output produced), Z_STREAM_END if all input has been 3417c478bd9Sstevel@tonic-gate consumed and all output has been produced (only when flush is set to 3427c478bd9Sstevel@tonic-gate Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 3437c478bd9Sstevel@tonic-gate if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible. 3447c478bd9Sstevel@tonic-gate */ 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate extern int deflateEnd OF((z_stream *strm)); 3487c478bd9Sstevel@tonic-gate /* 3497c478bd9Sstevel@tonic-gate All dynamically allocated data structures for this stream are freed. 3507c478bd9Sstevel@tonic-gate This function discards any unprocessed input and does not flush any 3517c478bd9Sstevel@tonic-gate pending output. 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 3547c478bd9Sstevel@tonic-gate stream state was inconsistent. In the error case, msg may be set 3557c478bd9Sstevel@tonic-gate but then points to a static string (which must not be deallocated). 3567c478bd9Sstevel@tonic-gate */ 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate extern int inflateInit OF((z_stream *strm)); 360*55fea89dSDan Cross /* 3617c478bd9Sstevel@tonic-gate Initializes the internal stream state for decompression. The fields 3627c478bd9Sstevel@tonic-gate zalloc and zfree must be initialized before by the caller. If zalloc and 3637c478bd9Sstevel@tonic-gate zfree are set to Z_NULL, inflateInit updates them to use default allocation 3647c478bd9Sstevel@tonic-gate functions. 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 3677c478bd9Sstevel@tonic-gate enough memory. msg is set to null if there is no error message. 3687c478bd9Sstevel@tonic-gate inflateInit does not perform any decompression: this will be done by 3697c478bd9Sstevel@tonic-gate inflate(). 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate extern int inflate OF((z_stream *strm, int flush)); 3747c478bd9Sstevel@tonic-gate /* 3757c478bd9Sstevel@tonic-gate Performs one or both of the following actions: 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate - Decompress more input starting at next_in and update next_in and avail_in 3787c478bd9Sstevel@tonic-gate accordingly. If not all input can be processed (because there is not 3797c478bd9Sstevel@tonic-gate enough room in the output buffer), next_in is updated and processing 3807c478bd9Sstevel@tonic-gate will resume at this point for the next call of inflate(). 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate - Provide more output starting at next_out and update next_out and avail_out 3837c478bd9Sstevel@tonic-gate accordingly. inflate() always provides as much output as possible 3847c478bd9Sstevel@tonic-gate (until there is no more input data or no more space in the output buffer). 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate Before the call of inflate(), the application should ensure that at least 3877c478bd9Sstevel@tonic-gate one of the actions is possible, by providing more input and/or consuming 3887c478bd9Sstevel@tonic-gate more output, and updating the next_* and avail_* values accordingly. 3897c478bd9Sstevel@tonic-gate The application can consume the uncompressed output when it wants, for 3907c478bd9Sstevel@tonic-gate example when the output buffer is full (avail_out == 0), or after each 3917c478bd9Sstevel@tonic-gate call of inflate(). 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH, 3947c478bd9Sstevel@tonic-gate inflate flushes as much output as possible to the output buffer. The 3957c478bd9Sstevel@tonic-gate flushing behavior of inflate is not specified for values of the flush 3967c478bd9Sstevel@tonic-gate parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the 3977c478bd9Sstevel@tonic-gate current implementation actually flushes as much output as possible 3987c478bd9Sstevel@tonic-gate anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data 3997c478bd9Sstevel@tonic-gate has been consumed, it is expecting to see the length field of a stored 4007c478bd9Sstevel@tonic-gate block; if not, it returns Z_DATA_ERROR. 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate inflate() should normally be called until it returns Z_STREAM_END or an 4037c478bd9Sstevel@tonic-gate error. However if all decompression is to be performed in a single step 4047c478bd9Sstevel@tonic-gate (a single call of inflate), the parameter flush should be set to 4057c478bd9Sstevel@tonic-gate Z_FINISH. In this case all pending input is processed and all pending 4067c478bd9Sstevel@tonic-gate output is flushed; avail_out must be large enough to hold all the 4077c478bd9Sstevel@tonic-gate uncompressed data. (The size of the uncompressed data may have been saved 4087c478bd9Sstevel@tonic-gate by the compressor for this purpose.) The next operation on this stream must 4097c478bd9Sstevel@tonic-gate be inflateEnd to deallocate the decompression state. The use of Z_FINISH 4107c478bd9Sstevel@tonic-gate is never required, but can be used to inform inflate that a faster routine 4117c478bd9Sstevel@tonic-gate may be used for the single inflate() call. 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate inflate() returns Z_OK if some progress has been made (more input 4147c478bd9Sstevel@tonic-gate processed or more output produced), Z_STREAM_END if the end of the 4157c478bd9Sstevel@tonic-gate compressed data has been reached and all uncompressed output has been 4167c478bd9Sstevel@tonic-gate produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if 4177c478bd9Sstevel@tonic-gate the stream structure was inconsistent (for example if next_in or next_out 4187c478bd9Sstevel@tonic-gate was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no 4197c478bd9Sstevel@tonic-gate progress is possible or if there was not enough room in the output buffer 4207c478bd9Sstevel@tonic-gate when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then 4217c478bd9Sstevel@tonic-gate call inflateSync to look for a good compression block. */ 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate extern int inflateEnd OF((z_stream *strm)); 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate All dynamically allocated data structures for this stream are freed. 4277c478bd9Sstevel@tonic-gate This function discards any unprocessed input and does not flush any 4287c478bd9Sstevel@tonic-gate pending output. 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 4317c478bd9Sstevel@tonic-gate was inconsistent. In the error case, msg may be set but then points to a 4327c478bd9Sstevel@tonic-gate static string (which must not be deallocated). 4337c478bd9Sstevel@tonic-gate */ 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* advanced functions */ 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate /* 4387c478bd9Sstevel@tonic-gate The following functions are needed only in some special applications. 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate extern int deflateInit2 OF((z_stream *strm, 4427c478bd9Sstevel@tonic-gate int level, 4437c478bd9Sstevel@tonic-gate int method, 4447c478bd9Sstevel@tonic-gate int windowBits, 4457c478bd9Sstevel@tonic-gate int memLevel, 4467c478bd9Sstevel@tonic-gate int strategy, 4477c478bd9Sstevel@tonic-gate int minCompression)); 448*55fea89dSDan Cross /* 4497c478bd9Sstevel@tonic-gate This is another version of deflateInit with more compression options. The 4507c478bd9Sstevel@tonic-gate fields next_in, zalloc and zfree must be initialized before by the caller. 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate The method parameter is the compression method. It must be 8 in this 4537c478bd9Sstevel@tonic-gate version of the library. (Method 9 will allow a 64K history buffer and 4547c478bd9Sstevel@tonic-gate partial block flushes.) 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate The windowBits parameter is the base two logarithm of the window size 4577c478bd9Sstevel@tonic-gate (the size of the history buffer). It should be in the range 8..15 for this 4587c478bd9Sstevel@tonic-gate version of the library (the value 16 will be allowed for method 9). Larger 4597c478bd9Sstevel@tonic-gate values of this parameter result in better compression at the expense of 4607c478bd9Sstevel@tonic-gate memory usage. The default value is 15 if deflateInit is used instead. 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate The memLevel parameter specifies how much memory should be allocated 4637c478bd9Sstevel@tonic-gate for the internal compression state. memLevel=1 uses minimum memory but 4647c478bd9Sstevel@tonic-gate is slow and reduces compression ratio; memLevel=9 uses maximum memory 4657c478bd9Sstevel@tonic-gate for optimal speed. The default value is 8. See zconf.h for total memory 4667c478bd9Sstevel@tonic-gate usage as a function of windowBits and memLevel. 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate The strategy parameter is used to tune the compression algorithm. Use 4697c478bd9Sstevel@tonic-gate the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data 4707c478bd9Sstevel@tonic-gate produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman 4717c478bd9Sstevel@tonic-gate encoding only (no string match). Filtered data consists mostly of small 4727c478bd9Sstevel@tonic-gate values with a somewhat random distribution. In this case, the 4737c478bd9Sstevel@tonic-gate compression algorithm is tuned to compress them better. The strategy 4747c478bd9Sstevel@tonic-gate parameter only affects the compression ratio but not the correctness of 4757c478bd9Sstevel@tonic-gate the compressed output even if it is not set appropriately. 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate The minCompression parameter specifies the minimum reduction in size 4787c478bd9Sstevel@tonic-gate required for a compressed block to be output when Z_PACKET_FLUSH is 4797c478bd9Sstevel@tonic-gate used (see the description of deflate above). 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate If next_in is not null, the library will use this buffer to hold also 4827c478bd9Sstevel@tonic-gate some history information; the buffer must either hold the entire input 4837c478bd9Sstevel@tonic-gate data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in 4847c478bd9Sstevel@tonic-gate is null, the library will allocate its own history buffer (and leave next_in 4857c478bd9Sstevel@tonic-gate null). next_out need not be provided here but must be provided by the 4867c478bd9Sstevel@tonic-gate application for the next call of deflate(). 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate If the history buffer is provided by the application, next_in must 4897c478bd9Sstevel@tonic-gate must never be changed by the application since the compressor maintains 4907c478bd9Sstevel@tonic-gate information inside this buffer from call to call; the application 4917c478bd9Sstevel@tonic-gate must provide more input only by increasing avail_in. next_in is always 4927c478bd9Sstevel@tonic-gate reset by the library in this case. 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 4957c478bd9Sstevel@tonic-gate not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 4967c478bd9Sstevel@tonic-gate an invalid method). msg is set to null if there is no error message. 4977c478bd9Sstevel@tonic-gate deflateInit2 does not perform any compression: this will be done by 4987c478bd9Sstevel@tonic-gate deflate(). 4997c478bd9Sstevel@tonic-gate */ 500*55fea89dSDan Cross 5017c478bd9Sstevel@tonic-gate extern int deflateCopy OF((z_stream *dest, 5027c478bd9Sstevel@tonic-gate z_stream *source)); 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate Sets the destination stream as a complete copy of the source stream. If 5057c478bd9Sstevel@tonic-gate the source stream is using an application-supplied history buffer, a new 5067c478bd9Sstevel@tonic-gate buffer is allocated for the destination stream. The compressed output 5077c478bd9Sstevel@tonic-gate buffer is always application-supplied. It's the responsibility of the 5087c478bd9Sstevel@tonic-gate application to provide the correct values of next_out and avail_out for the 5097c478bd9Sstevel@tonic-gate next call of deflate. 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate This function is useful when several compression strategies will be 5127c478bd9Sstevel@tonic-gate tried, for example when there are several ways of pre-processing the input 5137c478bd9Sstevel@tonic-gate data with a filter. The streams that will be discarded should then be freed 5147c478bd9Sstevel@tonic-gate by calling deflateEnd. Note that deflateCopy duplicates the internal 5157c478bd9Sstevel@tonic-gate compression state which can be quite large, so this strategy is slow and 5167c478bd9Sstevel@tonic-gate can consume lots of memory. 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 5197c478bd9Sstevel@tonic-gate enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 5207c478bd9Sstevel@tonic-gate (such as zalloc being NULL). msg is left unchanged in both source and 5217c478bd9Sstevel@tonic-gate destination. 5227c478bd9Sstevel@tonic-gate */ 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate extern int deflateReset OF((z_stream *strm)); 5257c478bd9Sstevel@tonic-gate /* 5267c478bd9Sstevel@tonic-gate This function is equivalent to deflateEnd followed by deflateInit, 5277c478bd9Sstevel@tonic-gate but does not free and reallocate all the internal compression state. 5287c478bd9Sstevel@tonic-gate The stream will keep the same compression level and any other attributes 5297c478bd9Sstevel@tonic-gate that may have been set by deflateInit2. 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 5327c478bd9Sstevel@tonic-gate stream state was inconsistent (such as zalloc or state being NULL). 5337c478bd9Sstevel@tonic-gate */ 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate extern int inflateInit2 OF((z_stream *strm, 5367c478bd9Sstevel@tonic-gate int windowBits)); 537*55fea89dSDan Cross /* 5387c478bd9Sstevel@tonic-gate This is another version of inflateInit with more compression options. The 5397c478bd9Sstevel@tonic-gate fields next_out, zalloc and zfree must be initialized before by the caller. 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate The windowBits parameter is the base two logarithm of the maximum window 5427c478bd9Sstevel@tonic-gate size (the size of the history buffer). It should be in the range 8..15 for 5437c478bd9Sstevel@tonic-gate this version of the library (the value 16 will be allowed soon). The 5447c478bd9Sstevel@tonic-gate default value is 15 if inflateInit is used instead. If a compressed stream 5457c478bd9Sstevel@tonic-gate with a larger window size is given as input, inflate() will return with 5467c478bd9Sstevel@tonic-gate the error code Z_DATA_ERROR instead of trying to allocate a larger window. 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate If next_out is not null, the library will use this buffer for the history 5497c478bd9Sstevel@tonic-gate buffer; the buffer must either be large enough to hold the entire output 5507c478bd9Sstevel@tonic-gate data, or have at least 1<<windowBits bytes. If next_out is null, the 5517c478bd9Sstevel@tonic-gate library will allocate its own buffer (and leave next_out null). next_in 5527c478bd9Sstevel@tonic-gate need not be provided here but must be provided by the application for the 5537c478bd9Sstevel@tonic-gate next call of inflate(). 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate If the history buffer is provided by the application, next_out must 5567c478bd9Sstevel@tonic-gate never be changed by the application since the decompressor maintains 5577c478bd9Sstevel@tonic-gate history information inside this buffer from call to call; the application 5587c478bd9Sstevel@tonic-gate can only reset next_out to the beginning of the history buffer when 5597c478bd9Sstevel@tonic-gate avail_out is zero and all output has been consumed. 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 5627c478bd9Sstevel@tonic-gate not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 5637c478bd9Sstevel@tonic-gate windowBits < 8). msg is set to null if there is no error message. 5647c478bd9Sstevel@tonic-gate inflateInit2 does not perform any decompression: this will be done by 5657c478bd9Sstevel@tonic-gate inflate(). 5667c478bd9Sstevel@tonic-gate */ 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate extern int inflateSync OF((z_stream *strm)); 569*55fea89dSDan Cross /* 5707c478bd9Sstevel@tonic-gate Skips invalid compressed data until the special marker (see deflate() 5717c478bd9Sstevel@tonic-gate above) can be found, or until all available input is skipped. No output 5727c478bd9Sstevel@tonic-gate is provided. 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR 5757c478bd9Sstevel@tonic-gate if no more input was provided, Z_DATA_ERROR if no marker has been found, 5767c478bd9Sstevel@tonic-gate or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 5777c478bd9Sstevel@tonic-gate case, the application may save the current current value of total_in which 5787c478bd9Sstevel@tonic-gate indicates where valid compressed data was found. In the error case, the 5797c478bd9Sstevel@tonic-gate application may repeatedly call inflateSync, providing more input each time, 5807c478bd9Sstevel@tonic-gate until success or end of the input data. 5817c478bd9Sstevel@tonic-gate */ 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate extern int inflateReset OF((z_stream *strm)); 5847c478bd9Sstevel@tonic-gate /* 5857c478bd9Sstevel@tonic-gate This function is equivalent to inflateEnd followed by inflateInit, 5867c478bd9Sstevel@tonic-gate but does not free and reallocate all the internal decompression state. 5877c478bd9Sstevel@tonic-gate The stream will keep attributes that may have been set by inflateInit2. 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 5907c478bd9Sstevel@tonic-gate stream state was inconsistent (such as zalloc or state being NULL). 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate extern int inflateIncomp OF((z_stream *strm)); 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate This function adds the data at next_in (avail_in bytes) to the output 5967c478bd9Sstevel@tonic-gate history without performing any output. There must be no pending output, 5977c478bd9Sstevel@tonic-gate and the decompressor must be expecting to see the start of a block. 5987c478bd9Sstevel@tonic-gate Calling this function is equivalent to decompressing a stored block 5997c478bd9Sstevel@tonic-gate containing the data at next_in (except that the data is not output). 6007c478bd9Sstevel@tonic-gate */ 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* checksum functions */ 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate This function is not related to compression but is exported 6067c478bd9Sstevel@tonic-gate anyway because it might be useful in applications using the 6077c478bd9Sstevel@tonic-gate compression library. 6087c478bd9Sstevel@tonic-gate */ 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len)); 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate /* 6137c478bd9Sstevel@tonic-gate Update a running Adler-32 checksum with the bytes buf[0..len-1] and 6147c478bd9Sstevel@tonic-gate return the updated checksum. If buf is NULL, this function returns 6157c478bd9Sstevel@tonic-gate the required initial value for the checksum. 6167c478bd9Sstevel@tonic-gate An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 6177c478bd9Sstevel@tonic-gate much faster. Usage example: 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate uLong adler = adler32(0L, Z_NULL, 0); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate while (read_buffer(buffer, length) != EOF) { 6227c478bd9Sstevel@tonic-gate adler = adler32(adler, buffer, length); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate if (adler != original_adler) error(); 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate #ifndef _Z_UTIL_H 6287c478bd9Sstevel@tonic-gate struct internal_state {int dummy;}; /* hack for buggy compilers */ 6297c478bd9Sstevel@tonic-gate #endif 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate #endif /* _ZLIB_H */ 632