OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [include/] [net/] [zlib.h] - Blame information for rev 158

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* $FreeBSD: src/sys/net/zlib.h,v 1.7 1999/12/29 04:38:38 peter Exp $   */
2
 
3
/*
4
 * This file is derived from zlib.h and zconf.h from the zlib-1.0.4
5
 * distribution by Jean-loup Gailly and Mark Adler, with some additions
6
 * by Paul Mackerras to aid in implementing Deflate compression and
7
 * decompression for PPP packets.
8
 */
9
 
10
/*
11
 *  ==FILEVERSION 971127==
12
 *
13
 * This marker is used by the Linux installation script to determine
14
 * whether an up-to-date version of this file is already installed.
15
 */
16
 
17
 
18
/* +++ zlib.h */
19
/* zlib.h -- interface of the 'zlib' general purpose compression library
20
  version 1.0.4, Jul 24th, 1996.
21
 
22
  Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
23
 
24
  This software is provided 'as-is', without any express or implied
25
  warranty.  In no event will the authors be held liable for any damages
26
  arising from the use of this software.
27
 
28
  Permission is granted to anyone to use this software for any purpose,
29
  including commercial applications, and to alter it and redistribute it
30
  freely, subject to the following restrictions:
31
 
32
  1. The origin of this software must not be misrepresented; you must not
33
     claim that you wrote the original software. If you use this software
34
     in a product, an acknowledgment in the product documentation would be
35
     appreciated but is not required.
36
  2. Altered source versions must be plainly marked as such, and must not be
37
     misrepresented as being the original software.
38
  3. This notice may not be removed or altered from any source distribution.
39
 
40
  Jean-loup Gailly        Mark Adler
41
  gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
42
 
43
 
44
  The data format used by the zlib library is described by RFCs (Request for
45
  Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
46
  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
47
*/
48
 
49
#ifndef _ZLIB_H
50
#define _ZLIB_H
51
 
52
#ifdef __cplusplus
53
extern "C" {
54
#endif
55
 
56
 
57
/* +++ zconf.h */
58
/* zconf.h -- configuration of the zlib compression library
59
 * Copyright (C) 1995-1996 Jean-loup Gailly.
60
 * For conditions of distribution and use, see copyright notice in zlib.h
61
 */
62
 
63
/* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */
64
 
65
#ifndef _ZCONF_H
66
#define _ZCONF_H
67
 
68
/*
69
 * If you *really* need a unique prefix for all types and library functions,
70
 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
71
 */
72
#ifdef Z_PREFIX
73
#  define deflateInit_  z_deflateInit_
74
#  define deflate       z_deflate
75
#  define deflateEnd    z_deflateEnd
76
#  define inflateInit_  z_inflateInit_
77
#  define inflate       z_inflate
78
#  define inflateEnd    z_inflateEnd
79
#  define deflateInit2_ z_deflateInit2_
80
#  define deflateSetDictionary z_deflateSetDictionary
81
#  define deflateCopy   z_deflateCopy
82
#  define deflateReset  z_deflateReset
83
#  define deflateParams z_deflateParams
84
#  define inflateInit2_ z_inflateInit2_
85
#  define inflateSetDictionary z_inflateSetDictionary
86
#  define inflateSync   z_inflateSync
87
#  define inflateReset  z_inflateReset
88
#  define compress      z_compress
89
#  define uncompress    z_uncompress
90
#  define adler32       z_adler32
91
#  define crc32         z_crc32
92
#  define get_crc_table z_get_crc_table
93
 
94
#  define Byte          z_Byte
95
#  define uInt          z_uInt
96
#  define uLong         z_uLong
97
#  define Bytef         z_Bytef
98
#  define charf         z_charf
99
#  define intf          z_intf
100
#  define uIntf         z_uIntf
101
#  define uLongf        z_uLongf
102
#  define voidpf        z_voidpf
103
#  define voidp         z_voidp
104
#endif
105
 
106
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
107
#  define WIN32
108
#endif
109
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
110
#  ifndef __32BIT__
111
#    define __32BIT__
112
#  endif
113
#endif
114
#if defined(__MSDOS__) && !defined(MSDOS)
115
#  define MSDOS
116
#endif
117
 
118
/*
119
 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
120
 * than 64k bytes at a time (needed on systems with 16-bit int).
121
 */
122
#if defined(MSDOS) && !defined(__32BIT__)
123
#  define MAXSEG_64K
124
#endif
125
#ifdef MSDOS
126
#  define UNALIGNED_OK
127
#endif
128
 
129
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)
130
#  define STDC
131
#endif
132
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
133
#  define STDC
134
#endif
135
 
136
#ifndef STDC
137
#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
138
#    define const
139
#  endif
140
#endif
141
 
142
/* Some Mac compilers merge all .h files incorrectly: */
143
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
144
#  define NO_DUMMY_DECL
145
#endif
146
 
147
/* Maximum value for memLevel in deflateInit2 */
148
#ifndef MAX_MEM_LEVEL
149
#  ifdef MAXSEG_64K
150
#    define MAX_MEM_LEVEL 8
151
#  else
152
#    define MAX_MEM_LEVEL 9
153
#  endif
154
#endif
155
 
156
/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
157
#ifndef MAX_WBITS
158
#  define MAX_WBITS   15 /* 32K LZ77 window */
159
#endif
160
 
161
/* The memory requirements for deflate are (in bytes):
162
            1 << (windowBits+2)   +  1 << (memLevel+9)
163
 that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
164
 plus a few kilobytes for small objects. For example, if you want to reduce
165
 the default memory requirements from 256K to 128K, compile with
166
     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
167
 Of course this will generally degrade compression (there's no free lunch).
168
 
169
   The memory requirements for inflate are (in bytes) 1 << windowBits
170
 that is, 32K for windowBits=15 (default value) plus a few kilobytes
171
 for small objects.
172
*/
173
 
174
                        /* Type declarations */
175
 
176
#ifndef OF /* function prototypes */
177
#  ifdef STDC
178
#    define OF(args)  args
179
#  else
180
#    define OF(args)  ()
181
#  endif
182
#endif
183
 
184
/* The following definitions for FAR are needed only for MSDOS mixed
185
 * model programming (small or medium model with some far allocations).
186
 * This was tested only with MSC; for other MSDOS compilers you may have
187
 * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
188
 * just define FAR to be empty.
189
 */
190
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
191
   /* MSC small or medium model */
192
#  define SMALL_MEDIUM
193
#  ifdef _MSC_VER
194
#    define FAR __far
195
#  else
196
#    define FAR far
197
#  endif
198
#endif
199
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
200
#  ifndef __32BIT__
201
#    define SMALL_MEDIUM
202
#    define FAR __far
203
#  endif
204
#endif
205
#ifndef FAR
206
#   define FAR
207
#endif
208
 
209
typedef unsigned char  Byte;  /* 8 bits */
210
typedef unsigned int   uInt;  /* 16 bits or more */
211
typedef unsigned long  uLong; /* 32 bits or more */
212
 
213
#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
214
   /* Borland C/C++ ignores FAR inside typedef */
215
#  define Bytef Byte FAR
216
#else
217
   typedef Byte  FAR Bytef;
218
#endif
219
typedef char  FAR charf;
220
typedef int   FAR intf;
221
typedef uInt  FAR uIntf;
222
typedef uLong FAR uLongf;
223
 
224
#ifdef STDC
225
   typedef void FAR *voidpf;
226
   typedef void     *voidp;
227
#else
228
   typedef Byte FAR *voidpf;
229
   typedef Byte     *voidp;
230
#endif
231
 
232
 
233
/* Compile with -DZLIB_DLL for Windows DLL support */
234
#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
235
#  include <windows.h>
236
#  define EXPORT  WINAPI
237
#else
238
#  define EXPORT
239
#endif
240
 
241
#endif /* _ZCONF_H */
242
/* --- zconf.h */
243
 
244
#define ZLIB_VERSION "1.0.4P"
245
 
246
/*
247
     The 'zlib' compression library provides in-memory compression and
248
  decompression functions, including integrity checks of the uncompressed
249
  data.  This version of the library supports only one compression method
250
  (deflation) but other algorithms may be added later and will have the same
251
  stream interface.
252
 
253
     For compression the application must provide the output buffer and
254
  may optionally provide the input buffer for optimization. For decompression,
255
  the application must provide the input buffer and may optionally provide
256
  the output buffer for optimization.
257
 
258
     Compression can be done in a single step if the buffers are large
259
  enough (for example if an input file is mmap'ed), or can be done by
260
  repeated calls of the compression function.  In the latter case, the
261
  application must provide more input and/or consume the output
262
  (providing more output space) before each call.
263
 
264
     The library does not install any signal handler. It is recommended to
265
  add at least a handler for SIGSEGV when decompressing; the library checks
266
  the consistency of the input data whenever possible but may go nuts
267
  for some forms of corrupted input.
268
*/
269
 
270
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
271
typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
272
 
273
struct internal_state;
274
 
275
typedef struct z_stream_s {
276
    Bytef    *next_in;  /* next input byte */
277
    uInt     avail_in;  /* number of bytes available at next_in */
278
    uLong    total_in;  /* total nb of input bytes read so far */
279
 
280
    Bytef    *next_out; /* next output byte should be put there */
281
    uInt     avail_out; /* remaining free space at next_out */
282
    uLong    total_out; /* total nb of bytes output so far */
283
 
284
    const char     *msg; /* last error message, NULL if no error */
285
    struct internal_state FAR *state; /* not visible by applications */
286
 
287
    alloc_func zalloc;  /* used to allocate the internal state */
288
    free_func  zfree;   /* used to free the internal state */
289
    voidpf     opaque;  /* private data object passed to zalloc and zfree */
290
 
291
    int     data_type;  /* best guess about the data type: ascii or binary */
292
    uLong   adler;      /* adler32 value of the uncompressed data */
293
    uLong   reserved;   /* reserved for future use */
294
} z_stream;
295
 
296
typedef z_stream FAR *z_streamp;
297
 
298
/*
299
   The application must update next_in and avail_in when avail_in has
300
   dropped to zero. It must update next_out and avail_out when avail_out
301
   has dropped to zero. The application must initialize zalloc, zfree and
302
   opaque before calling the init function. All other fields are set by the
303
   compression library and must not be updated by the application.
304
 
305
   The opaque value provided by the application will be passed as the first
306
   parameter for calls of zalloc and zfree. This can be useful for custom
307
   memory management. The compression library attaches no meaning to the
308
   opaque value.
309
 
310
   zalloc must return Z_NULL if there is not enough memory for the object.
311
   On 16-bit systems, the functions zalloc and zfree must be able to allocate
312
   exactly 65536 bytes, but will not be required to allocate more than this
313
   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
314
   pointers returned by zalloc for objects of exactly 65536 bytes *must*
315
   have their offset normalized to zero. The default allocation function
316
   provided by this library ensures this (see zutil.c). To reduce memory
317
   requirements and avoid any allocation of 64K objects, at the expense of
318
   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
319
 
320
   The fields total_in and total_out can be used for statistics or
321
   progress reports. After compression, total_in holds the total size of
322
   the uncompressed data and may be saved for use in the decompressor
323
   (particularly if the decompressor wants to decompress everything in
324
   a single step).
325
*/
326
 
327
                        /* constants */
328
 
329
#define Z_NO_FLUSH      0
330
#define Z_PARTIAL_FLUSH 1
331
#define Z_PACKET_FLUSH  2
332
#define Z_SYNC_FLUSH    3
333
#define Z_FULL_FLUSH    4
334
#define Z_FINISH        5
335
/* Allowed flush values; see deflate() below for details */
336
 
337
#define Z_OK            0
338
#define Z_STREAM_END    1
339
#define Z_NEED_DICT     2
340
#define Z_ERRNO        (-1)
341
#define Z_STREAM_ERROR (-2)
342
#define Z_DATA_ERROR   (-3)
343
#define Z_MEM_ERROR    (-4)
344
#define Z_BUF_ERROR    (-5)
345
#define Z_VERSION_ERROR (-6)
346
/* Return codes for the compression/decompression functions. Negative
347
 * values are errors, positive values are used for special but normal events.
348
 */
349
 
350
#define Z_NO_COMPRESSION         0
351
#define Z_BEST_SPEED             1
352
#define Z_BEST_COMPRESSION       9
353
#define Z_DEFAULT_COMPRESSION  (-1)
354
/* compression levels */
355
 
356
#define Z_FILTERED            1
357
#define Z_HUFFMAN_ONLY        2
358
#define Z_DEFAULT_STRATEGY    0
359
/* compression strategy; see deflateInit2() below for details */
360
 
361
#define Z_BINARY   0
362
#define Z_ASCII    1
363
#define Z_UNKNOWN  2
364
/* Possible values of the data_type field */
365
 
366
#define Z_DEFLATED   8
367
/* The deflate compression method (the only one supported in this version) */
368
 
369
#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
370
 
371
#define zlib_version zlibVersion()
372
/* for compatibility with versions < 1.0.2 */
373
 
374
                        /* basic functions */
375
 
376
extern const char * EXPORT zlibVersion OF((void));
377
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
378
   If the first character differs, the library code actually used is
379
   not compatible with the zlib.h header file used by the application.
380
   This check is automatically made by deflateInit and inflateInit.
381
 */
382
 
383
/*
384
extern int EXPORT deflateInit OF((z_streamp strm, int level));
385
 
386
     Initializes the internal stream state for compression. The fields
387
   zalloc, zfree and opaque must be initialized before by the caller.
388
   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
389
   use default allocation functions.
390
 
391
     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
392
   1 gives best speed, 9 gives best compression, 0 gives no compression at
393
   all (the input data is simply copied a block at a time).
394
   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
395
   compression (currently equivalent to level 6).
396
 
397
     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
398
   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
399
   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
400
   with the version assumed by the caller (ZLIB_VERSION).
401
   msg is set to null if there is no error message.  deflateInit does not
402
   perform any compression: this will be done by deflate().
403
*/
404
 
405
 
406
extern int EXPORT deflate OF((z_streamp strm, int flush));
407
/*
408
  Performs one or both of the following actions:
409
 
410
  - Compress more input starting at next_in and update next_in and avail_in
411
    accordingly. If not all input can be processed (because there is not
412
    enough room in the output buffer), next_in and avail_in are updated and
413
    processing will resume at this point for the next call of deflate().
414
 
415
  - Provide more output starting at next_out and update next_out and avail_out
416
    accordingly. This action is forced if the parameter flush is non zero.
417
    Forcing flush frequently degrades the compression ratio, so this parameter
418
    should be set only when necessary (in interactive applications).
419
    Some output may be provided even if flush is not set.
420
 
421
  Before the call of deflate(), the application should ensure that at least
422
  one of the actions is possible, by providing more input and/or consuming
423
  more output, and updating avail_in or avail_out accordingly; avail_out
424
  should never be zero before the call. The application can consume the
425
  compressed output when it wants, for example when the output buffer is full
426
  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
427
  and with zero avail_out, it must be called again after making room in the
428
  output buffer because there might be more output pending.
429
 
430
    If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
431
  block is terminated and flushed to the output buffer so that the
432
  decompressor can get all input data available so far. For method 9, a future
433
  variant on method 8, the current block will be flushed but not terminated.
434
  Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
435
  output is byte aligned (the compressor can clear its internal bit buffer)
436
  and the current block is always terminated; this can be useful if the
437
  compressor has to be restarted from scratch after an interruption (in which
438
  case the internal state of the compressor may be lost).
439
    If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
440
  special marker is output and the compression dictionary is discarded; this
441
  is useful to allow the decompressor to synchronize if one compressed block
442
  has been damaged (see inflateSync below).  Flushing degrades compression and
443
  so should be used only when necessary.  Using Z_FULL_FLUSH too often can
444
  seriously degrade the compression. If deflate returns with avail_out == 0,
445
  this function must be called again with the same value of the flush
446
  parameter and more output space (updated avail_out), until the flush is
447
  complete (deflate returns with non-zero avail_out).
448
 
449
    If the parameter flush is set to Z_PACKET_FLUSH, the compression
450
  block is terminated, and a zero-length stored block is output,
451
  omitting the length bytes (the effect of this is that the 3-bit type
452
  code 000 for a stored block is output, and the output is then
453
  byte-aligned).  This is designed for use at the end of a PPP packet.
454
 
455
    If the parameter flush is set to Z_FINISH, pending input is processed,
456
  pending output is flushed and deflate returns with Z_STREAM_END if there
457
  was enough output space; if deflate returns with Z_OK, this function must be
458
  called again with Z_FINISH and more output space (updated avail_out) but no
459
  more input data, until it returns with Z_STREAM_END or an error. After
460
  deflate has returned Z_STREAM_END, the only possible operations on the
461
  stream are deflateReset or deflateEnd.
462
 
463
    Z_FINISH can be used immediately after deflateInit if all the compression
464
  is to be done in a single step. In this case, avail_out must be at least
465
  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
466
  Z_STREAM_END, then it must be called again as described above.
467
 
468
    deflate() may update data_type if it can make a good guess about
469
  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
470
  binary. This field is only for information purposes and does not affect
471
  the compression algorithm in any manner.
472
 
473
    deflate() returns Z_OK if some progress has been made (more input
474
  processed or more output produced), Z_STREAM_END if all input has been
475
  consumed and all output has been produced (only when flush is set to
476
  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
477
  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
478
*/
479
 
480
 
481
extern int EXPORT deflateEnd OF((z_streamp strm));
482
/*
483
     All dynamically allocated data structures for this stream are freed.
484
   This function discards any unprocessed input and does not flush any
485
   pending output.
486
 
487
     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
488
   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
489
   prematurely (some input or output was discarded). In the error case,
490
   msg may be set but then points to a static string (which must not be
491
   deallocated).
492
*/
493
 
494
 
495
/*
496
extern int EXPORT inflateInit OF((z_streamp strm));
497
 
498
     Initializes the internal stream state for decompression. The fields
499
   zalloc, zfree and opaque must be initialized before by the caller.  If
500
   zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
501
   allocation functions.
502
 
503
     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
504
   enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
505
   with the version assumed by the caller.  msg is set to null if there is no
506
   error message. inflateInit does not perform any decompression: this will be
507
   done by inflate().
508
*/
509
 
510
#if defined(__FreeBSD__) && defined(_KERNEL)
511
#define inflate       inflate_ppp     /* FreeBSD already has an inflate :-( */
512
#endif
513
 
514
extern int EXPORT inflate OF((z_streamp strm, int flush));
515
/*
516
  Performs one or both of the following actions:
517
 
518
  - Decompress more input starting at next_in and update next_in and avail_in
519
    accordingly. If not all input can be processed (because there is not
520
    enough room in the output buffer), next_in is updated and processing
521
    will resume at this point for the next call of inflate().
522
 
523
  - Provide more output starting at next_out and update next_out and avail_out
524
    accordingly.  inflate() provides as much output as possible, until there
525
    is no more input data or no more space in the output buffer (see below
526
    about the flush parameter).
527
 
528
  Before the call of inflate(), the application should ensure that at least
529
  one of the actions is possible, by providing more input and/or consuming
530
  more output, and updating the next_* and avail_* values accordingly.
531
  The application can consume the uncompressed output when it wants, for
532
  example when the output buffer is full (avail_out == 0), or after each
533
  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
534
  must be called again after making room in the output buffer because there
535
  might be more output pending.
536
 
537
    If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
538
  inflate flushes as much output as possible to the output buffer. The
539
  flushing behavior of inflate is not specified for values of the flush
540
  parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
541
  current implementation actually flushes as much output as possible
542
  anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
543
  has been consumed, it is expecting to see the length field of a stored
544
  block; if not, it returns Z_DATA_ERROR.
545
 
546
    inflate() should normally be called until it returns Z_STREAM_END or an
547
  error. However if all decompression is to be performed in a single step
548
  (a single call of inflate), the parameter flush should be set to
549
  Z_FINISH. In this case all pending input is processed and all pending
550
  output is flushed; avail_out must be large enough to hold all the
551
  uncompressed data. (The size of the uncompressed data may have been saved
552
  by the compressor for this purpose.) The next operation on this stream must
553
  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
554
  is never required, but can be used to inform inflate that a faster routine
555
  may be used for the single inflate() call.
556
 
557
    inflate() returns Z_OK if some progress has been made (more input
558
  processed or more output produced), Z_STREAM_END if the end of the
559
  compressed data has been reached and all uncompressed output has been
560
  produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
561
  inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
562
  Z_STREAM_ERROR if the stream structure was inconsistent (for example if
563
  next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
564
  Z_BUF_ERROR if no progress is possible or if there was not enough room in
565
  the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
566
  application may then call inflateSync to look for a good compression block.
567
  In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
568
  dictionary chosen by the compressor.
569
*/
570
 
571
 
572
extern int EXPORT inflateEnd OF((z_streamp strm));
573
/*
574
     All dynamically allocated data structures for this stream are freed.
575
   This function discards any unprocessed input and does not flush any
576
   pending output.
577
 
578
     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
579
   was inconsistent. In the error case, msg may be set but then points to a
580
   static string (which must not be deallocated).
581
*/
582
 
583
                        /* Advanced functions */
584
 
585
/*
586
    The following functions are needed only in some special applications.
587
*/
588
 
589
/*
590
extern int EXPORT deflateInit2 OF((z_streamp strm,
591
                                   int  level,
592
                                   int  method,
593
                                   int  windowBits,
594
                                   int  memLevel,
595
                                   int  strategy));
596
 
597
     This is another version of deflateInit with more compression options. The
598
   fields next_in, zalloc, zfree and opaque must be initialized before by
599
   the caller.
600
 
601
     The method parameter is the compression method. It must be Z_DEFLATED in
602
   this version of the library. (Method 9 will allow a 64K history buffer and
603
   partial block flushes.)
604
 
605
     The windowBits parameter is the base two logarithm of the window size
606
   (the size of the history buffer).  It should be in the range 8..15 for this
607
   version of the library (the value 16 will be allowed for method 9). Larger
608
   values of this parameter result in better compression at the expense of
609
   memory usage. The default value is 15 if deflateInit is used instead.
610
 
611
     The memLevel parameter specifies how much memory should be allocated
612
   for the internal compression state. memLevel=1 uses minimum memory but
613
   is slow and reduces compression ratio; memLevel=9 uses maximum memory
614
   for optimal speed. The default value is 8. See zconf.h for total memory
615
   usage as a function of windowBits and memLevel.
616
 
617
     The strategy parameter is used to tune the compression algorithm. Use the
618
   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
619
   filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
620
   string match).  Filtered data consists mostly of small values with a
621
   somewhat random distribution. In this case, the compression algorithm is
622
   tuned to compress them better. The effect of Z_FILTERED is to force more
623
   Huffman coding and less string matching; it is somewhat intermediate
624
   between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
625
   the compression ratio but not the correctness of the compressed output even
626
   if it is not set appropriately.
627
 
628
     If next_in is not null, the library will use this buffer to hold also
629
   some history information; the buffer must either hold the entire input
630
   data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
631
   is null, the library will allocate its own history buffer (and leave next_in
632
   null). next_out need not be provided here but must be provided by the
633
   application for the next call of deflate().
634
 
635
     If the history buffer is provided by the application, next_in must
636
   must never be changed by the application since the compressor maintains
637
   information inside this buffer from call to call; the application
638
   must provide more input only by increasing avail_in. next_in is always
639
   reset by the library in this case.
640
 
641
      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
642
   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
643
   an invalid method). msg is set to null if there is no error message.
644
   deflateInit2 does not perform any compression: this will be done by
645
   deflate().
646
*/
647
 
648
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
649
                                           const Bytef *dictionary,
650
                                           uInt  dictLength));
651
/*
652
     Initializes the compression dictionary (history buffer) from the given
653
   byte sequence without producing any compressed output. This function must
654
   be called immediately after deflateInit or deflateInit2, before any call
655
   of deflate. The compressor and decompressor must use exactly the same
656
   dictionary (see inflateSetDictionary).
657
     The dictionary should consist of strings (byte sequences) that are likely
658
   to be encountered later in the data to be compressed, with the most commonly
659
   used strings preferably put towards the end of the dictionary. Using a
660
   dictionary is most useful when the data to be compressed is short and
661
   can be predicted with good accuracy; the data can then be compressed better
662
   than with the default empty dictionary. In this version of the library,
663
   only the last 32K bytes of the dictionary are used.
664
     Upon return of this function, strm->adler is set to the Adler32 value
665
   of the dictionary; the decompressor may later use this value to determine
666
   which dictionary has been used by the compressor. (The Adler32 value
667
   applies to the whole dictionary even if only a subset of the dictionary is
668
   actually used by the compressor.)
669
 
670
     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
671
   parameter is invalid (such as NULL dictionary) or the stream state
672
   is inconsistent (for example if deflate has already been called for this
673
   stream). deflateSetDictionary does not perform any compression: this will
674
   be done by deflate().
675
*/
676
 
677
extern int EXPORT deflateCopy OF((z_streamp dest,
678
                                  z_streamp source));
679
/*
680
     Sets the destination stream as a complete copy of the source stream.  If
681
   the source stream is using an application-supplied history buffer, a new
682
   buffer is allocated for the destination stream.  The compressed output
683
   buffer is always application-supplied. It's the responsibility of the
684
   application to provide the correct values of next_out and avail_out for the
685
   next call of deflate.
686
 
687
     This function can be useful when several compression strategies will be
688
   tried, for example when there are several ways of pre-processing the input
689
   data with a filter. The streams that will be discarded should then be freed
690
   by calling deflateEnd.  Note that deflateCopy duplicates the internal
691
   compression state which can be quite large, so this strategy is slow and
692
   can consume lots of memory.
693
 
694
     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
695
   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
696
   (such as zalloc being NULL). msg is left unchanged in both source and
697
   destination.
698
*/
699
 
700
extern int EXPORT deflateReset OF((z_streamp strm));
701
/*
702
     This function is equivalent to deflateEnd followed by deflateInit,
703
   but does not free and reallocate all the internal compression state.
704
   The stream will keep the same compression level and any other attributes
705
   that may have been set by deflateInit2.
706
 
707
      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
708
   stream state was inconsistent (such as zalloc or state being NULL).
709
*/
710
 
711
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
712
/*
713
     Dynamically update the compression level and compression strategy.
714
   This can be used to switch between compression and straight copy of
715
   the input data, or to switch to a different kind of input data requiring
716
   a different strategy. If the compression level is changed, the input
717
   available so far is compressed with the old level (and may be flushed);
718
   the new level will take effect only at the next call of deflate().
719
 
720
     Before the call of deflateParams, the stream state must be set as for
721
   a call of deflate(), since the currently available input may have to
722
   be compressed and flushed. In particular, strm->avail_out must be non-zero.
723
 
724
     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
725
   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
726
   if strm->avail_out was zero.
727
*/
728
 
729
extern int EXPORT deflateOutputPending OF((z_streamp strm));
730
/*
731
     Returns the number of bytes of output which are immediately
732
   available from the compressor (i.e. without any further input
733
   or flush).
734
*/
735
 
736
/*
737
extern int EXPORT inflateInit2 OF((z_streamp strm,
738
                                   int  windowBits));
739
 
740
     This is another version of inflateInit with more compression options. The
741
   fields next_out, zalloc, zfree and opaque must be initialized before by
742
   the caller.
743
 
744
     The windowBits parameter is the base two logarithm of the maximum window
745
   size (the size of the history buffer).  It should be in the range 8..15 for
746
   this version of the library (the value 16 will be allowed soon). The
747
   default value is 15 if inflateInit is used instead. If a compressed stream
748
   with a larger window size is given as input, inflate() will return with
749
   the error code Z_DATA_ERROR instead of trying to allocate a larger window.
750
 
751
     If next_out is not null, the library will use this buffer for the history
752
   buffer; the buffer must either be large enough to hold the entire output
753
   data, or have at least 1<<windowBits bytes.  If next_out is null, the
754
   library will allocate its own buffer (and leave next_out null). next_in
755
   need not be provided here but must be provided by the application for the
756
   next call of inflate().
757
 
758
     If the history buffer is provided by the application, next_out must
759
   never be changed by the application since the decompressor maintains
760
   history information inside this buffer from call to call; the application
761
   can only reset next_out to the beginning of the history buffer when
762
   avail_out is zero and all output has been consumed.
763
 
764
      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
765
   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
766
   windowBits < 8). msg is set to null if there is no error message.
767
   inflateInit2 does not perform any decompression: this will be done by
768
   inflate().
769
*/
770
 
771
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
772
                                           const Bytef *dictionary,
773
                                           uInt  dictLength));
774
/*
775
     Initializes the decompression dictionary (history buffer) from the given
776
   uncompressed byte sequence. This function must be called immediately after
777
   a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
778
   by the compressor can be determined from the Adler32 value returned by this
779
   call of inflate. The compressor and decompressor must use exactly the same
780
   dictionary (see deflateSetDictionary).
781
 
782
     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
783
   parameter is invalid (such as NULL dictionary) or the stream state is
784
   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
785
   expected one (incorrect Adler32 value). inflateSetDictionary does not
786
   perform any decompression: this will be done by subsequent calls of
787
   inflate().
788
*/
789
 
790
extern int EXPORT inflateSync OF((z_streamp strm));
791
/*
792
    Skips invalid compressed data until the special marker (see deflate()
793
  above) can be found, or until all available input is skipped. No output
794
  is provided.
795
 
796
    inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
797
  if no more input was provided, Z_DATA_ERROR if no marker has been found,
798
  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
799
  case, the application may save the current current value of total_in which
800
  indicates where valid compressed data was found. In the error case, the
801
  application may repeatedly call inflateSync, providing more input each time,
802
  until success or end of the input data.
803
*/
804
 
805
extern int EXPORT inflateReset OF((z_streamp strm));
806
/*
807
     This function is equivalent to inflateEnd followed by inflateInit,
808
   but does not free and reallocate all the internal decompression state.
809
   The stream will keep attributes that may have been set by inflateInit2.
810
 
811
      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
812
   stream state was inconsistent (such as zalloc or state being NULL).
813
*/
814
 
815
extern int inflateIncomp OF((z_stream *strm));
816
/*
817
     This function adds the data at next_in (avail_in bytes) to the output
818
   history without performing any output.  There must be no pending output,
819
   and the decompressor must be expecting to see the start of a block.
820
   Calling this function is equivalent to decompressing a stored block
821
   containing the data at next_in (except that the data is not output).
822
*/
823
 
824
                        /* utility functions */
825
 
826
/*
827
     The following utility functions are implemented on top of the
828
   basic stream-oriented functions. To simplify the interface, some
829
   default options are assumed (compression level, window size,
830
   standard memory allocation functions). The source code of these
831
   utility functions can easily be modified if you need special options.
832
*/
833
 
834
extern int EXPORT compress OF((Bytef *dest,   uLongf *destLen,
835
                               const Bytef *source, uLong sourceLen));
836
/*
837
     Compresses the source buffer into the destination buffer.  sourceLen is
838
   the byte length of the source buffer. Upon entry, destLen is the total
839
   size of the destination buffer, which must be at least 0.1% larger than
840
   sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
841
   compressed buffer.
842
     This function can be used to compress a whole file at once if the
843
   input file is mmap'ed.
844
     compress returns Z_OK if success, Z_MEM_ERROR if there was not
845
   enough memory, Z_BUF_ERROR if there was not enough room in the output
846
   buffer.
847
*/
848
 
849
extern int EXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
850
                                 const Bytef *source, uLong sourceLen));
851
/*
852
     Decompresses the source buffer into the destination buffer.  sourceLen is
853
   the byte length of the source buffer. Upon entry, destLen is the total
854
   size of the destination buffer, which must be large enough to hold the
855
   entire uncompressed data. (The size of the uncompressed data must have
856
   been saved previously by the compressor and transmitted to the decompressor
857
   by some mechanism outside the scope of this compression library.)
858
   Upon exit, destLen is the actual size of the compressed buffer.
859
     This function can be used to decompress a whole file at once if the
860
   input file is mmap'ed.
861
 
862
     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
863
   enough memory, Z_BUF_ERROR if there was not enough room in the output
864
   buffer, or Z_DATA_ERROR if the input data was corrupted.
865
*/
866
 
867
 
868
typedef voidp gzFile;
869
 
870
extern gzFile EXPORT gzopen  OF((const char *path, const char *mode));
871
/*
872
     Opens a gzip (.gz) file for reading or writing. The mode parameter
873
   is as in fopen ("rb" or "wb") but can also include a compression level
874
   ("wb9").  gzopen can be used to read a file which is not in gzip format;
875
   in this case gzread will directly read from the file without decompression.
876
     gzopen returns NULL if the file could not be opened or if there was
877
   insufficient memory to allocate the (de)compression state; errno
878
   can be checked to distinguish the two cases (if errno is zero, the
879
   zlib error is Z_MEM_ERROR).
880
*/
881
 
882
extern gzFile EXPORT gzdopen  OF((int fd, const char *mode));
883
/*
884
     gzdopen() associates a gzFile with the file descriptor fd.  File
885
   descriptors are obtained from calls like open, dup, creat, pipe or
886
   fileno (in the file has been previously opened with fopen).
887
   The mode parameter is as in gzopen.
888
     The next call of gzclose on the returned gzFile will also close the
889
   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
890
   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
891
     gzdopen returns NULL if there was insufficient memory to allocate
892
   the (de)compression state.
893
*/
894
 
895
extern int EXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
896
/*
897
     Reads the given number of uncompressed bytes from the compressed file.
898
   If the input file was not in gzip format, gzread copies the given number
899
   of bytes into the buffer.
900
     gzread returns the number of uncompressed bytes actually read (0 for
901
   end of file, -1 for error). */
902
 
903
extern int EXPORT    gzwrite OF((gzFile file, const voidp buf, unsigned len));
904
/*
905
     Writes the given number of uncompressed bytes into the compressed file.
906
   gzwrite returns the number of uncompressed bytes actually written
907
   (0 in case of error).
908
*/
909
 
910
extern int EXPORT    gzflush OF((gzFile file, int flush));
911
/*
912
     Flushes all pending output into the compressed file. The parameter
913
   flush is as in the deflate() function. The return value is the zlib
914
   error number (see function gzerror below). gzflush returns Z_OK if
915
   the flush parameter is Z_FINISH and all output could be flushed.
916
     gzflush should be called only when strictly necessary because it can
917
   degrade compression.
918
*/
919
 
920
extern int EXPORT    gzclose OF((gzFile file));
921
/*
922
     Flushes all pending output if necessary, closes the compressed file
923
   and deallocates all the (de)compression state. The return value is the zlib
924
   error number (see function gzerror below).
925
*/
926
 
927
extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
928
/*
929
     Returns the error message for the last error which occurred on the
930
   given compressed file. errnum is set to zlib error number. If an
931
   error occurred in the file system and not in the compression library,
932
   errnum is set to Z_ERRNO and the application may consult errno
933
   to get the exact error code.
934
*/
935
 
936
                        /* checksum functions */
937
 
938
/*
939
     These functions are not related to compression but are exported
940
   anyway because they might be useful in applications using the
941
   compression library.
942
*/
943
 
944
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
945
 
946
/*
947
     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
948
   return the updated checksum. If buf is NULL, this function returns
949
   the required initial value for the checksum.
950
   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
951
   much faster. Usage example:
952
 
953
     uLong adler = adler32(0L, Z_NULL, 0);
954
 
955
     while (read_buffer(buffer, length) != EOF) {
956
       adler = adler32(adler, buffer, length);
957
     }
958
     if (adler != original_adler) error();
959
*/
960
 
961
extern uLong EXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
962
/*
963
     Update a running crc with the bytes buf[0..len-1] and return the updated
964
   crc. If buf is NULL, this function returns the required initial value
965
   for the crc. Pre- and post-conditioning (one's complement) is performed
966
   within this function so it shouldn't be done by the application.
967
   Usage example:
968
 
969
     uLong crc = crc32(0L, Z_NULL, 0);
970
 
971
     while (read_buffer(buffer, length) != EOF) {
972
       crc = crc32(crc, buffer, length);
973
     }
974
     if (crc != original_crc) error();
975
*/
976
 
977
 
978
                        /* various hacks, don't look :) */
979
 
980
/* deflateInit and inflateInit are macros to allow checking the zlib version
981
 * and the compiler's view of z_stream:
982
 */
983
extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
984
                                   const char *version, int stream_size));
985
extern int EXPORT inflateInit_ OF((z_streamp strm,
986
                                   const char *version, int stream_size));
987
extern int EXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
988
                                    int windowBits, int memLevel, int strategy,
989
                                    const char *version, int stream_size));
990
extern int EXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
991
                                    const char *version, int stream_size));
992
#define deflateInit(strm, level) \
993
        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
994
#define inflateInit(strm) \
995
        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
996
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
997
        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
998
                      (strategy),           ZLIB_VERSION, sizeof(z_stream))
999
#define inflateInit2(strm, windowBits) \
1000
        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1001
 
1002
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
1003
    struct internal_state {int dummy;}; /* hack for buggy compilers */
1004
#endif
1005
 
1006
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
1007
 
1008
#ifdef __cplusplus
1009
}
1010
#endif
1011
 
1012
#endif /* _ZLIB_H */
1013
/* --- zlib.h */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.