![]() |
|
|||
File indexing completed on 2025-05-11 08:23:54
0001 /* 0002 * This file is derived from zlib.h and zconf.h from the zlib-0.95 0003 * distribution by Jean-loup Gailly and Mark Adler, with some additions 0004 * by Paul Mackerras to aid in implementing Deflate compression and 0005 * decompression for PPP packets. 0006 */ 0007 0008 /* 0009 * ==FILEVERSION 960122== 0010 * 0011 * This marker is used by the Linux installation script to determine 0012 * whether an up-to-date version of this file is already installed. 0013 */ 0014 0015 /* zlib.h -- interface of the 'zlib' general purpose compression library 0016 version 0.95, Aug 16th, 1995. 0017 0018 Copyright (C) 1995 Jean-loup Gailly and Mark Adler 0019 0020 This software is provided 'as-is', without any express or implied 0021 warranty. In no event will the authors be held liable for any damages 0022 arising from the use of this software. 0023 0024 Permission is granted to anyone to use this software for any purpose, 0025 including commercial applications, and to alter it and redistribute it 0026 freely, subject to the following restrictions: 0027 0028 1. The origin of this software must not be misrepresented; you must not 0029 claim that you wrote the original software. If you use this software 0030 in a product, an acknowledgment in the product documentation would be 0031 appreciated but is not required. 0032 2. Altered source versions must be plainly marked as such, and must not be 0033 misrepresented as being the original software. 0034 3. This notice may not be removed or altered from any source distribution. 0035 0036 Jean-loup Gailly Mark Adler 0037 gzip@prep.ai.mit.edu madler@alumni.caltech.edu 0038 */ 0039 0040 #ifndef _ZLIB_H 0041 #define _ZLIB_H 0042 0043 #define local 0044 #ifdef DEBUG_ZLIB 0045 #include <bsp/consoleIo.h> 0046 #define fprintf printk 0047 #endif 0048 0049 /* #include "zconf.h" */ /* included directly here */ 0050 0051 /* zconf.h -- configuration of the zlib compression library 0052 * Copyright (C) 1995 Jean-loup Gailly. 0053 * For conditions of distribution and use, see copyright notice in zlib.h 0054 */ 0055 0056 /* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */ 0057 0058 /* 0059 The library does not install any signal handler. It is recommended to 0060 add at least a handler for SIGSEGV when decompressing; the library checks 0061 the consistency of the input data whenever possible but may go nuts 0062 for some forms of corrupted input. 0063 */ 0064 0065 /* 0066 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 0067 * than 64k bytes at a time (needed on systems with 16-bit int). 0068 * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints 0069 * at addresses which are not a multiple of their size. 0070 * Under DOS, -DFAR=far or -DFAR=__far may be needed. 0071 */ 0072 0073 #ifndef STDC 0074 # if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus) 0075 # define STDC 0076 # endif 0077 #endif 0078 0079 #ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */ 0080 # include <unix.h> 0081 #endif 0082 0083 /* Maximum value for memLevel in deflateInit2 */ 0084 #ifndef MAX_MEM_LEVEL 0085 # ifdef MAXSEG_64K 0086 # define MAX_MEM_LEVEL 8 0087 # else 0088 # define MAX_MEM_LEVEL 9 0089 # endif 0090 #endif 0091 0092 #ifndef FAR 0093 # define FAR 0094 #endif 0095 0096 /* Maximum value for windowBits in deflateInit2 and inflateInit2 */ 0097 #ifndef MAX_WBITS 0098 # define MAX_WBITS 15 /* 32K LZ77 window */ 0099 #endif 0100 0101 /* The memory requirements for deflate are (in bytes): 0102 1 << (windowBits+2) + 1 << (memLevel+9) 0103 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 0104 plus a few kilobytes for small objects. For example, if you want to reduce 0105 the default memory requirements from 256K to 128K, compile with 0106 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 0107 Of course this will generally degrade compression (there's no free lunch). 0108 0109 The memory requirements for inflate are (in bytes) 1 << windowBits 0110 that is, 32K for windowBits=15 (default value) plus a few kilobytes 0111 for small objects. 0112 */ 0113 0114 /* Type declarations */ 0115 0116 #ifndef OF /* function prototypes */ 0117 # ifdef STDC 0118 # define OF(args) args 0119 # else 0120 # define OF(args) () 0121 # endif 0122 #endif 0123 0124 typedef unsigned char Byte; /* 8 bits */ 0125 typedef unsigned int uInt; /* 16 bits or more */ 0126 typedef unsigned long uLong; /* 32 bits or more */ 0127 0128 typedef Byte FAR Bytef; 0129 typedef char FAR charf; 0130 typedef int FAR intf; 0131 typedef uInt FAR uIntf; 0132 typedef uLong FAR uLongf; 0133 0134 #ifdef STDC 0135 typedef void FAR *voidpf; 0136 typedef void *voidp; 0137 #else 0138 typedef Byte FAR *voidpf; 0139 typedef Byte *voidp; 0140 #endif 0141 0142 /* end of original zconf.h */ 0143 0144 #define ZLIB_VERSION "0.95P" 0145 0146 /* 0147 The 'zlib' compression library provides in-memory compression and 0148 decompression functions, including integrity checks of the uncompressed 0149 data. This version of the library supports only one compression method 0150 (deflation) but other algorithms may be added later and will have the same 0151 stream interface. 0152 0153 For compression the application must provide the output buffer and 0154 may optionally provide the input buffer for optimization. For decompression, 0155 the application must provide the input buffer and may optionally provide 0156 the output buffer for optimization. 0157 0158 Compression can be done in a single step if the buffers are large 0159 enough (for example if an input file is mmap'ed), or can be done by 0160 repeated calls of the compression function. In the latter case, the 0161 application must provide more input and/or consume the output 0162 (providing more output space) before each call. 0163 */ 0164 0165 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 0166 typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt nbytes)); 0167 0168 struct internal_state; 0169 0170 typedef struct z_stream_s { 0171 Bytef *next_in; /* next input byte */ 0172 uInt avail_in; /* number of bytes available at next_in */ 0173 uLong total_in; /* total nb of input bytes read so far */ 0174 0175 Bytef *next_out; /* next output byte should be put there */ 0176 uInt avail_out; /* remaining free space at next_out */ 0177 uLong total_out; /* total nb of bytes output so far */ 0178 0179 char *msg; /* last error message, NULL if no error */ 0180 struct internal_state FAR *state; /* not visible by applications */ 0181 0182 alloc_func zalloc; /* used to allocate the internal state */ 0183 free_func zfree; /* used to free the internal state */ 0184 voidp opaque; /* private data object passed to zalloc and zfree */ 0185 0186 Byte data_type; /* best guess about the data type: ascii or binary */ 0187 0188 } z_stream; 0189 0190 /* 0191 The application must update next_in and avail_in when avail_in has 0192 dropped to zero. It must update next_out and avail_out when avail_out 0193 has dropped to zero. The application must initialize zalloc, zfree and 0194 opaque before calling the init function. All other fields are set by the 0195 compression library and must not be updated by the application. 0196 0197 The opaque value provided by the application will be passed as the first 0198 parameter for calls of zalloc and zfree. This can be useful for custom 0199 memory management. The compression library attaches no meaning to the 0200 opaque value. 0201 0202 zalloc must return Z_NULL if there is not enough memory for the object. 0203 On 16-bit systems, the functions zalloc and zfree must be able to allocate 0204 exactly 65536 bytes, but will not be required to allocate more than this 0205 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 0206 pointers returned by zalloc for objects of exactly 65536 bytes *must* 0207 have their offset normalized to zero. The default allocation function 0208 provided by this library ensures this (see zutil.c). To reduce memory 0209 requirements and avoid any allocation of 64K objects, at the expense of 0210 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 0211 0212 The fields total_in and total_out can be used for statistics or 0213 progress reports. After compression, total_in holds the total size of 0214 the uncompressed data and may be saved for use in the decompressor 0215 (particularly if the decompressor wants to decompress everything in 0216 a single step). 0217 */ 0218 0219 /* constants */ 0220 0221 #define Z_NO_FLUSH 0 0222 #define Z_PARTIAL_FLUSH 1 0223 #define Z_FULL_FLUSH 2 0224 #define Z_SYNC_FLUSH 3 /* experimental: partial_flush + byte align */ 0225 #define Z_FINISH 4 0226 #define Z_PACKET_FLUSH 5 0227 /* See deflate() below for the usage of these constants */ 0228 0229 #define Z_OK 0 0230 #define Z_STREAM_END 1 0231 #define Z_ERRNO (-1) 0232 #define Z_STREAM_ERROR (-2) 0233 #define Z_DATA_ERROR (-3) 0234 #define Z_MEM_ERROR (-4) 0235 #define Z_BUF_ERROR (-5) 0236 /* error codes for the compression/decompression functions */ 0237 0238 #define Z_BEST_SPEED 1 0239 #define Z_BEST_COMPRESSION 9 0240 #define Z_DEFAULT_COMPRESSION (-1) 0241 /* compression levels */ 0242 0243 #define Z_FILTERED 1 0244 #define Z_HUFFMAN_ONLY 2 0245 #define Z_DEFAULT_STRATEGY 0 0246 0247 #define Z_BINARY 0 0248 #define Z_ASCII 1 0249 #define Z_UNKNOWN 2 0250 /* Used to set the data_type field */ 0251 0252 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 0253 0254 extern char *zlib_version; 0255 /* The application can compare zlib_version and ZLIB_VERSION for consistency. 0256 If the first character differs, the library code actually used is 0257 not compatible with the zlib.h header file used by the application. 0258 */ 0259 0260 /* basic functions */ 0261 0262 extern int inflateInit OF((z_stream *strm)); 0263 /* 0264 Initializes the internal stream state for decompression. The fields 0265 zalloc and zfree must be initialized before by the caller. If zalloc and 0266 zfree are set to Z_NULL, inflateInit updates them to use default allocation 0267 functions. 0268 0269 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 0270 enough memory. msg is set to null if there is no error message. 0271 inflateInit does not perform any decompression: this will be done by 0272 inflate(). 0273 */ 0274 0275 extern int inflate OF((z_stream *strm, int flush)); 0276 /* 0277 Performs one or both of the following actions: 0278 0279 - Decompress more input starting at next_in and update next_in and avail_in 0280 accordingly. If not all input can be processed (because there is not 0281 enough room in the output buffer), next_in is updated and processing 0282 will resume at this point for the next call of inflate(). 0283 0284 - Provide more output starting at next_out and update next_out and avail_out 0285 accordingly. inflate() always provides as much output as possible 0286 (until there is no more input data or no more space in the output buffer). 0287 0288 Before the call of inflate(), the application should ensure that at least 0289 one of the actions is possible, by providing more input and/or consuming 0290 more output, and updating the next_* and avail_* values accordingly. 0291 The application can consume the uncompressed output when it wants, for 0292 example when the output buffer is full (avail_out == 0), or after each 0293 call of inflate(). 0294 0295 If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH, 0296 inflate flushes as much output as possible to the output buffer. The 0297 flushing behavior of inflate is not specified for values of the flush 0298 parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the 0299 current implementation actually flushes as much output as possible 0300 anyway. For Z_PACKET_FLUSH, inflate checks that once all the input data 0301 has been consumed, it is expecting to see the length field of a stored 0302 block; if not, it returns Z_DATA_ERROR. 0303 0304 inflate() should normally be called until it returns Z_STREAM_END or an 0305 error. However if all decompression is to be performed in a single step 0306 (a single call of inflate), the parameter flush should be set to 0307 Z_FINISH. In this case all pending input is processed and all pending 0308 output is flushed; avail_out must be large enough to hold all the 0309 uncompressed data. (The size of the uncompressed data may have been saved 0310 by the compressor for this purpose.) The next operation on this stream must 0311 be inflateEnd to deallocate the decompression state. The use of Z_FINISH 0312 is never required, but can be used to inform inflate that a faster routine 0313 may be used for the single inflate() call. 0314 0315 inflate() returns Z_OK if some progress has been made (more input 0316 processed or more output produced), Z_STREAM_END if the end of the 0317 compressed data has been reached and all uncompressed output has been 0318 produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if 0319 the stream structure was inconsistent (for example if next_in or next_out 0320 was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no 0321 progress is possible or if there was not enough room in the output buffer 0322 when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then 0323 call inflateSync to look for a good compression block. */ 0324 0325 extern int inflateEnd OF((z_stream *strm)); 0326 /* 0327 All dynamically allocated data structures for this stream are freed. 0328 This function discards any unprocessed input and does not flush any 0329 pending output. 0330 0331 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 0332 was inconsistent. In the error case, msg may be set but then points to a 0333 static string (which must not be deallocated). 0334 */ 0335 0336 /* advanced functions */ 0337 0338 extern int inflateInit2 OF((z_stream *strm, 0339 int windowBits)); 0340 /* 0341 This is another version of inflateInit with more compression options. The 0342 fields next_out, zalloc and zfree must be initialized before by the caller. 0343 0344 The windowBits parameter is the base two logarithm of the maximum window 0345 size (the size of the history buffer). It should be in the range 8..15 for 0346 this version of the library (the value 16 will be allowed soon). The 0347 default value is 15 if inflateInit is used instead. If a compressed stream 0348 with a larger window size is given as input, inflate() will return with 0349 the error code Z_DATA_ERROR instead of trying to allocate a larger window. 0350 0351 If next_out is not null, the library will use this buffer for the history 0352 buffer; the buffer must either be large enough to hold the entire output 0353 data, or have at least 1<<windowBits bytes. If next_out is null, the 0354 library will allocate its own buffer (and leave next_out null). next_in 0355 need not be provided here but must be provided by the application for the 0356 next call of inflate(). 0357 0358 If the history buffer is provided by the application, next_out must 0359 never be changed by the application since the decompressor maintains 0360 history information inside this buffer from call to call; the application 0361 can only reset next_out to the beginning of the history buffer when 0362 avail_out is zero and all output has been consumed. 0363 0364 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was 0365 not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as 0366 windowBits < 8). msg is set to null if there is no error message. 0367 inflateInit2 does not perform any decompression: this will be done by 0368 inflate(). 0369 */ 0370 0371 extern int inflateSync OF((z_stream *strm)); 0372 /* 0373 Skips invalid compressed data until the special marker (see deflate() 0374 above) can be found, or until all available input is skipped. No output 0375 is provided. 0376 0377 inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR 0378 if no more input was provided, Z_DATA_ERROR if no marker has been found, 0379 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 0380 case, the application may save the current current value of total_in which 0381 indicates where valid compressed data was found. In the error case, the 0382 application may repeatedly call inflateSync, providing more input each time, 0383 until success or end of the input data. 0384 */ 0385 0386 extern int inflateReset OF((z_stream *strm)); 0387 /* 0388 This function is equivalent to inflateEnd followed by inflateInit, 0389 but does not free and reallocate all the internal decompression state. 0390 The stream will keep attributes that may have been set by inflateInit2. 0391 0392 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 0393 stream state was inconsistent (such as zalloc or state being NULL). 0394 */ 0395 0396 extern int inflateIncomp OF((z_stream *strm)); 0397 /* 0398 This function adds the data at next_in (avail_in bytes) to the output 0399 history without performing any output. There must be no pending output, 0400 and the decompressor must be expecting to see the start of a block. 0401 Calling this function is equivalent to decompressing a stored block 0402 containing the data at next_in (except that the data is not output). 0403 */ 0404 0405 /* checksum functions */ 0406 0407 /* 0408 This function is not related to compression but is exported 0409 anyway because it might be useful in applications using the 0410 compression library. 0411 */ 0412 0413 extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len)); 0414 0415 /* 0416 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 0417 return the updated checksum. If buf is NULL, this function returns 0418 the required initial value for the checksum. 0419 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 0420 much faster. Usage example: 0421 0422 uLong adler = adler32(0L, Z_NULL, 0); 0423 0424 while (read_buffer(buffer, length) != EOF) { 0425 adler = adler32(adler, buffer, length); 0426 } 0427 if (adler != original_adler) error(); 0428 */ 0429 0430 #ifndef _Z_UTIL_H 0431 struct internal_state {int dummy;}; /* hack for buggy compilers */ 0432 #endif 0433 0434 #endif /* _ZLIB_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |