~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/zlib/zlib.h

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

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