Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
zlib.h File Reference
#include "zconf.h"

Go to the source code of this file.

Classes

struct  z_stream_s
struct  gz_header_s
struct  gzFile_s

Macros

#define ZLIB_VERSION   "1.3.1"
#define ZLIB_VERNUM   0x1310
#define ZLIB_VER_MAJOR   1
#define ZLIB_VER_MINOR   3
#define ZLIB_VER_REVISION   1
#define ZLIB_VER_SUBREVISION   0
#define Z_NO_FLUSH   0
#define Z_PARTIAL_FLUSH   1
#define Z_SYNC_FLUSH   2
#define Z_FULL_FLUSH   3
#define Z_FINISH   4
#define Z_BLOCK   5
#define Z_TREES   6
#define Z_OK   0
#define Z_STREAM_END   1
#define Z_NEED_DICT   2
#define Z_ERRNO   (-1)
#define Z_STREAM_ERROR   (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR   (-4)
#define Z_BUF_ERROR   (-5)
#define Z_VERSION_ERROR   (-6)
#define Z_NO_COMPRESSION   0
#define Z_BEST_SPEED   1
#define Z_BEST_COMPRESSION   9
#define Z_DEFAULT_COMPRESSION   (-1)
#define Z_FILTERED   1
#define Z_HUFFMAN_ONLY   2
#define Z_RLE   3
#define Z_FIXED   4
#define Z_DEFAULT_STRATEGY   0
#define Z_BINARY   0
#define Z_TEXT   1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN   2
#define Z_DEFLATED   8
#define Z_NULL   0 /* for initializing zalloc, zfree, opaque */
#define zlib_version   zlibVersion()
#define deflateInit(strm, level)
#define inflateInit(strm)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
#define inflateInit2(strm, windowBits)
#define inflateBackInit(strm, windowBits, window)
#define gzgetc(g)

Typedefs

typedef voidpf(* alloc_func) (voidpf opaque, uInt items, uInt size)
typedef void(* free_func) (voidpf opaque, voidpf address)
typedef struct z_stream_s z_stream
typedef z_stream FAR * z_streamp
typedef struct gz_header_s gz_header
typedef gz_header FAR * gz_headerp
typedef unsigned(* in_func) (void FAR *, z_const unsigned char FAR *FAR *)
typedef int(* out_func) (void FAR *, unsigned char FAR *, unsigned)
typedef struct gzFile_sgzFile

Functions

ZEXTERN const char *ZEXPORT zlibVersion (void)
ZEXTERN int ZEXPORT deflate (z_streamp strm, int flush)
ZEXTERN int ZEXPORT deflateEnd (z_streamp strm)
ZEXTERN int ZEXPORT inflate (z_streamp strm, int flush)
ZEXTERN int ZEXPORT inflateEnd (z_streamp strm)
ZEXTERN int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
ZEXTERN int ZEXPORT deflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
ZEXTERN int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
ZEXTERN int ZEXPORT deflateReset (z_streamp strm)
ZEXTERN int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
ZEXTERN int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
ZEXTERN uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
ZEXTERN int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, int *bits)
ZEXTERN int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
ZEXTERN int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
ZEXTERN int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
ZEXTERN int ZEXPORT inflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
ZEXTERN int ZEXPORT inflateSync (z_streamp strm)
ZEXTERN int ZEXPORT inflateCopy (z_streamp dest, z_streamp source)
ZEXTERN int ZEXPORT inflateReset (z_streamp strm)
ZEXTERN int ZEXPORT inflateReset2 (z_streamp strm, int windowBits)
ZEXTERN int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
ZEXTERN long ZEXPORT inflateMark (z_streamp strm)
ZEXTERN int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
ZEXTERN int ZEXPORT inflateBack (z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
ZEXTERN int ZEXPORT inflateBackEnd (z_streamp strm)
ZEXTERN uLong ZEXPORT zlibCompileFlags (void)
ZEXTERN int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
ZEXTERN int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
ZEXTERN uLong ZEXPORT compressBound (uLong sourceLen)
ZEXTERN int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
ZEXTERN int ZEXPORT uncompress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
ZEXTERN gzFile ZEXPORT gzdopen (int fd, const char *mode)
ZEXTERN int ZEXPORT gzbuffer (gzFile file, unsigned size)
ZEXTERN int ZEXPORT gzsetparams (gzFile file, int level, int strategy)
ZEXTERN int ZEXPORT gzread (gzFile file, voidp buf, unsigned len)
ZEXTERN z_size_t ZEXPORT gzfread (voidp buf, z_size_t size, z_size_t nitems, gzFile file)
ZEXTERN int ZEXPORT gzwrite (gzFile file, voidpc buf, unsigned len)
ZEXTERN z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, z_size_t nitems, gzFile file)
ZEXTERN int ZEXPORTVA gzprintf (gzFile file, const char *format,...)
ZEXTERN int ZEXPORT gzputs (gzFile file, const char *s)
ZEXTERN char *ZEXPORT gzgets (gzFile file, char *buf, int len)
ZEXTERN int ZEXPORT gzputc (gzFile file, int c)
ZEXTERN int ZEXPORT gzgetc (gzFile file)
ZEXTERN int ZEXPORT gzungetc (int c, gzFile file)
ZEXTERN int ZEXPORT gzflush (gzFile file, int flush)
ZEXTERN int ZEXPORT gzrewind (gzFile file)
ZEXTERN int ZEXPORT gzeof (gzFile file)
ZEXTERN int ZEXPORT gzdirect (gzFile file)
ZEXTERN int ZEXPORT gzclose (gzFile file)
ZEXTERN int ZEXPORT gzclose_r (gzFile file)
ZEXTERN int ZEXPORT gzclose_w (gzFile file)
ZEXTERN const char *ZEXPORT gzerror (gzFile file, int *errnum)
ZEXTERN void ZEXPORT gzclearerr (gzFile file)
ZEXTERN uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
ZEXTERN uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, z_size_t len)
ZEXTERN uLong ZEXPORT crc32 (uLong crc, const Bytef *buf, uInt len)
ZEXTERN uLong ZEXPORT crc32_z (uLong crc, const Bytef *buf, z_size_t len)
ZEXTERN uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op)
ZEXTERN int ZEXPORT deflateInit_ (z_streamp strm, int level, const char *version, int stream_size)
ZEXTERN int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
ZEXTERN int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
ZEXTERN int ZEXPORT inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size)
ZEXTERN int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
ZEXTERN int ZEXPORT gzgetc_ (gzFile file)
ZEXTERN gzFile ZEXPORT gzopen (const char *, const char *)
ZEXTERN z_off_t ZEXPORT gzseek (gzFile, z_off_t, int)
ZEXTERN z_off_t ZEXPORT gztell (gzFile)
ZEXTERN z_off_t ZEXPORT gzoffset (gzFile)
ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t)
ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t)
ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t)
ZEXTERN const char *ZEXPORT zError (int)
ZEXTERN int ZEXPORT inflateSyncPoint (z_streamp)
ZEXTERN const z_crc_t FAR *ZEXPORT get_crc_table (void)
ZEXTERN int ZEXPORT inflateUndermine (z_streamp, int)
ZEXTERN int ZEXPORT inflateValidate (z_streamp, int)
ZEXTERN unsigned long ZEXPORT inflateCodesUsed (z_streamp)
ZEXTERN int ZEXPORT inflateResetKeep (z_streamp)
ZEXTERN int ZEXPORT deflateResetKeep (z_streamp)

Macro Definition Documentation

◆ deflateInit

#define deflateInit ( strm,
level )
Value:
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
Definition deflate.c:371
#define ZLIB_VERSION
Definition zlib.h:40
struct z_stream_s z_stream

Definition at line 1813 of file zlib.h.

1813# define deflateInit(strm, level) \
1814 deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))

Referenced by compress2().

◆ deflateInit2

#define deflateInit2 ( strm,
level,
method,
windowBits,
memLevel,
strategy )
Value:
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, (int)sizeof(z_stream))
ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
Definition deflate.c:379

Definition at line 1817 of file zlib.h.

1817# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1818 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1819 (strategy), ZLIB_VERSION, (int)sizeof(z_stream))

Referenced by gz_init().

◆ gzgetc

#define gzgetc ( g)
Value:
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#define gzgetc(g)
Definition zlib.h:1848

Definition at line 1848 of file zlib.h.

1848# define gzgetc(g) \
1849 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))

Referenced by gzgetc_().

◆ inflateBackInit

#define inflateBackInit ( strm,
windowBits,
window )
Value:
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, (int)sizeof(z_stream))
ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
Definition infback.c:25

Definition at line 1823 of file zlib.h.

1823# define inflateBackInit(strm, windowBits, window) \
1824 inflateBackInit_((strm), (windowBits), (window), \
1825 ZLIB_VERSION, (int)sizeof(z_stream))

◆ inflateInit

#define inflateInit ( strm)
Value:
inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
Definition inflate.c:218

Definition at line 1815 of file zlib.h.

1815# define inflateInit(strm) \
1816 inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))

Referenced by uncompress2().

◆ inflateInit2

#define inflateInit2 ( strm,
windowBits )
Value:
inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
(int)sizeof(z_stream))
ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
Definition inflate.c:178

Definition at line 1820 of file zlib.h.

1820# define inflateInit2(strm, windowBits) \
1821 inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
1822 (int)sizeof(z_stream))

Referenced by gz_look().

◆ Z_ASCII

#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */

Definition at line 205 of file zlib.h.

◆ Z_BEST_COMPRESSION

#define Z_BEST_COMPRESSION   9

Definition at line 192 of file zlib.h.

◆ Z_BEST_SPEED

#define Z_BEST_SPEED   1

Definition at line 191 of file zlib.h.

◆ Z_BINARY

#define Z_BINARY   0

Definition at line 203 of file zlib.h.

Referenced by detect_data_type().

◆ Z_BLOCK

#define Z_BLOCK   5

Definition at line 173 of file zlib.h.

Referenced by deflate(), deflateParams(), gzsetparams(), and inflate().

◆ Z_BUF_ERROR

◆ Z_DATA_ERROR

#define Z_DATA_ERROR   (-3)

◆ Z_DEFAULT_COMPRESSION

#define Z_DEFAULT_COMPRESSION   (-1)

Definition at line 193 of file zlib.h.

Referenced by compress(), deflateInit2_(), deflateParams(), and gz_open().

◆ Z_DEFAULT_STRATEGY

#define Z_DEFAULT_STRATEGY   0

Definition at line 200 of file zlib.h.

Referenced by deflateInit_(), and gz_open().

◆ Z_DEFLATED

#define Z_DEFLATED   8

Definition at line 209 of file zlib.h.

Referenced by deflate(), deflateInit2_(), deflateInit_(), gz_init(), and inflate().

◆ Z_ERRNO

#define Z_ERRNO   (-1)

Definition at line 180 of file zlib.h.

Referenced by gz_comp(), gz_load(), gzclose_r(), and gzclose_w().

◆ Z_FILTERED

#define Z_FILTERED   1

Definition at line 196 of file zlib.h.

Referenced by deflate_slow(), and gz_open().

◆ Z_FINISH

#define Z_FINISH   4

◆ Z_FIXED

#define Z_FIXED   4

Definition at line 199 of file zlib.h.

Referenced by _tr_flush_block(), deflateInit2_(), deflateParams(), and gz_open().

◆ Z_FULL_FLUSH

#define Z_FULL_FLUSH   3

Definition at line 171 of file zlib.h.

Referenced by deflate().

◆ Z_HUFFMAN_ONLY

#define Z_HUFFMAN_ONLY   2

Definition at line 197 of file zlib.h.

Referenced by deflate(), and gz_open().

◆ Z_MEM_ERROR

◆ Z_NEED_DICT

#define Z_NEED_DICT   2

Definition at line 179 of file zlib.h.

Referenced by gz_decomp(), inflate(), and uncompress2().

◆ Z_NO_COMPRESSION

#define Z_NO_COMPRESSION   0

Definition at line 190 of file zlib.h.

◆ Z_NO_FLUSH

◆ Z_NULL

◆ Z_OK

◆ Z_PARTIAL_FLUSH

#define Z_PARTIAL_FLUSH   1

Definition at line 169 of file zlib.h.

Referenced by deflate().

◆ Z_RLE

#define Z_RLE   3

Definition at line 198 of file zlib.h.

Referenced by deflate(), and gz_open().

◆ Z_STREAM_END

#define Z_STREAM_END   1

Definition at line 178 of file zlib.h.

Referenced by compress2(), deflate(), gz_comp(), gz_decomp(), inflate(), inflateBack(), and uncompress2().

◆ Z_STREAM_ERROR

◆ Z_SYNC_FLUSH

#define Z_SYNC_FLUSH   2

Definition at line 170 of file zlib.h.

◆ Z_TEXT

#define Z_TEXT   1

Definition at line 204 of file zlib.h.

Referenced by detect_data_type().

◆ Z_TREES

#define Z_TREES   6

Definition at line 174 of file zlib.h.

Referenced by inflate().

◆ Z_UNKNOWN

#define Z_UNKNOWN   2

Definition at line 206 of file zlib.h.

Referenced by _tr_flush_block(), and deflateResetKeep().

◆ Z_VERSION_ERROR

#define Z_VERSION_ERROR   (-6)

Definition at line 185 of file zlib.h.

Referenced by deflateInit2_(), inflateBackInit_(), and inflateInit2_().

◆ ZLIB_VER_MAJOR

#define ZLIB_VER_MAJOR   1

Definition at line 42 of file zlib.h.

◆ ZLIB_VER_MINOR

#define ZLIB_VER_MINOR   3

Definition at line 43 of file zlib.h.

◆ ZLIB_VER_REVISION

#define ZLIB_VER_REVISION   1

Definition at line 44 of file zlib.h.

◆ ZLIB_VER_SUBREVISION

#define ZLIB_VER_SUBREVISION   0

Definition at line 45 of file zlib.h.

◆ ZLIB_VERNUM

#define ZLIB_VERNUM   0x1310

Definition at line 41 of file zlib.h.

◆ ZLIB_VERSION

#define ZLIB_VERSION   "1.3.1"

Definition at line 40 of file zlib.h.

Referenced by deflateInit2_(), inflateBackInit_(), inflateInit2_(), and zlibVersion().

◆ zlib_version

#define zlib_version   zlibVersion()

Definition at line 214 of file zlib.h.

Typedef Documentation

◆ alloc_func

typedef voidpf(* alloc_func) (voidpf opaque, uInt items, uInt size)

Definition at line 81 of file zlib.h.

◆ free_func

typedef void(* free_func) (voidpf opaque, voidpf address)

Definition at line 82 of file zlib.h.

◆ gz_header

typedef struct gz_header_s gz_header

◆ gz_headerp

typedef gz_header FAR* gz_headerp

Definition at line 131 of file zlib.h.

◆ gzFile

typedef struct gzFile_s* gzFile

Definition at line 1305 of file zlib.h.

◆ in_func

typedef unsigned(* in_func) (void FAR *, z_const unsigned char FAR *FAR *)

Definition at line 1097 of file zlib.h.

◆ out_func

typedef int(* out_func) (void FAR *, unsigned char FAR *, unsigned)

Definition at line 1099 of file zlib.h.

◆ z_stream

typedef struct z_stream_s z_stream

◆ z_streamp

typedef z_stream FAR* z_streamp

Definition at line 108 of file zlib.h.

Function Documentation

◆ adler32()

ZEXTERN uLong ZEXPORT adler32 ( uLong adler,
const Bytef * buf,
uInt len )

Definition at line 128 of file adler32.c.

128 {
129 return adler32_z(adler, buf, len);
130}
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len)
Definition adler32.c:61

Referenced by deflate(), deflateResetKeep(), deflateSetDictionary(), inflate(), inflateSetDictionary(), and read_buf().

◆ adler32_combine()

ZEXTERN uLong ZEXPORT adler32_combine ( uLong adler1,
uLong adler2,
z_off_t len2 )

Definition at line 158 of file adler32.c.

158 {
159 return adler32_combine_(adler1, adler2, len2);
160}
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
Definition adler32.c:133

◆ adler32_z()

ZEXTERN uLong ZEXPORT adler32_z ( uLong adler,
const Bytef * buf,
z_size_t len )

Definition at line 61 of file adler32.c.

61 {
62 unsigned long sum2;
63 unsigned n;
64
65 /* split Adler-32 into component sums */
66 sum2 = (adler >> 16) & 0xffff;
67 adler &= 0xffff;
68
69 /* in case user likes doing a byte at a time, keep it fast */
70 if (len == 1) {
71 adler += buf[0];
72 if (adler >= BASE)
73 adler -= BASE;
74 sum2 += adler;
75 if (sum2 >= BASE)
76 sum2 -= BASE;
77 return adler | (sum2 << 16);
78 }
79
80 /* initial Adler-32 value (deferred check for len == 1 speed) */
81 if (buf == Z_NULL)
82 return 1L;
83
84 /* in case short lengths are provided, keep it somewhat fast */
85 if (len < 16) {
86 while (len--) {
87 adler += *buf++;
88 sum2 += adler;
89 }
90 if (adler >= BASE)
91 adler -= BASE;
92 MOD28(sum2); /* only added so many BASE's */
93 return adler | (sum2 << 16);
94 }
95
96 /* do length NMAX blocks -- requires just one modulo operation */
97 while (len >= NMAX) {
98 len -= NMAX;
99 n = NMAX / 16; /* NMAX is divisible by 16 */
100 do {
101 DO16(buf); /* 16 sums unrolled */
102 buf += 16;
103 } while (--n);
104 MOD(adler);
105 MOD(sum2);
106 }
107
108 /* do remaining bytes (less than NMAX, still just one modulo) */
109 if (len) { /* avoid modulos if none remaining */
110 while (len >= 16) {
111 len -= 16;
112 DO16(buf);
113 buf += 16;
114 }
115 while (len--) {
116 adler += *buf++;
117 sum2 += adler;
118 }
119 MOD(adler);
120 MOD(sum2);
121 }
122
123 /* return recombined sums */
124 return adler | (sum2 << 16);
125}
#define MOD28(a)
Definition adler32.c:56
#define NMAX
Definition adler32.c:11
#define DO16(buf)
Definition adler32.c:18
#define BASE
Definition adler32.c:10
#define MOD(a)
Definition adler32.c:55
#define Z_NULL
Definition zlib.h:212

Referenced by adler32().

◆ compress()

ZEXTERN int ZEXPORT compress ( Bytef * dest,
uLongf * destLen,
const Bytef * source,
uLong sourceLen )

Definition at line 63 of file compress.c.

64 {
65 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
66}
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
Definition compress.c:22
#define Z_DEFAULT_COMPRESSION
Definition zlib.h:193

◆ compress2()

ZEXTERN int ZEXPORT compress2 ( Bytef * dest,
uLongf * destLen,
const Bytef * source,
uLong sourceLen,
int level )

Definition at line 22 of file compress.c.

23 {
24 z_stream stream;
25 int err;
26 const uInt max = (uInt)-1;
27 uLong left;
28
29 left = *destLen;
30 *destLen = 0;
31
32 stream.zalloc = (alloc_func)0;
33 stream.zfree = (free_func)0;
34 stream.opaque = (voidpf)0;
35
36 err = deflateInit(&stream, level);
37 if (err != Z_OK) return err;
38
39 stream.next_out = dest;
40 stream.avail_out = 0;
41 stream.next_in = (z_const Bytef *)source;
42 stream.avail_in = 0;
43
44 do {
45 if (stream.avail_out == 0) {
46 stream.avail_out = left > (uLong)max ? max : (uInt)left;
47 left -= stream.avail_out;
48 }
49 if (stream.avail_in == 0) {
50 stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
51 sourceLen -= stream.avail_in;
52 }
53 err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
54 } while (err == Z_OK);
55
56 *destLen = stream.total_out;
57 deflateEnd(&stream);
58 return err == Z_STREAM_END ? Z_OK : err;
59}
T max(const T t1, const T t2)
brief Return the largest of the two arguments
uInt avail_in
Definition zlib.h:88
alloc_func zalloc
Definition zlib.h:98
uInt avail_out
Definition zlib.h:92
z_const Bytef * next_in
Definition zlib.h:87
free_func zfree
Definition zlib.h:99
voidpf opaque
Definition zlib.h:100
uLong total_out
Definition zlib.h:93
Bytef * next_out
Definition zlib.h:91
void(* free_func)(voidpf opaque, voidpf address)
Definition zlib.h:82
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition zlib.h:81
ZEXTERN int ZEXPORT deflateEnd(z_streamp strm)
Definition deflate.c:1262
#define Z_STREAM_END
Definition zlib.h:178
#define Z_FINISH
Definition zlib.h:172
#define Z_OK
Definition zlib.h:177
#define Z_NO_FLUSH
Definition zlib.h:168
ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush)
Definition deflate.c:950
#define deflateInit(strm, level)
Definition zlib.h:1813

Referenced by compress().

◆ compressBound()

ZEXTERN uLong ZEXPORT compressBound ( uLong sourceLen)

Definition at line 72 of file compress.c.

72 {
73 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
74 (sourceLen >> 25) + 13;
75}

◆ crc32()

ZEXTERN uLong ZEXPORT crc32 ( uLong crc,
const Bytef * buf,
uInt len )

◆ crc32_combine()

ZEXTERN uLong ZEXPORT crc32_combine ( uLong crc1,
uLong crc2,
z_off_t len2 )

Definition at line 1029 of file crc32.c.

1029 {
1030 return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1031}
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
Definition crc32.c:1021

◆ crc32_combine_gen()

ZEXTERN uLong ZEXPORT crc32_combine_gen ( z_off_t len2)

Definition at line 1042 of file crc32.c.

1042 {
1043 return crc32_combine_gen64((z_off64_t)len2);
1044}
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2)
Definition crc32.c:1034

◆ crc32_combine_op()

ZEXTERN uLong ZEXPORT crc32_combine_op ( uLong crc1,
uLong crc2,
uLong op )

Definition at line 1047 of file crc32.c.

1047 {
1048 return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1049}
local z_crc_t multmodp(z_crc_t a, z_crc_t b)
Definition crc32.c:155

◆ crc32_z()

ZEXTERN uLong ZEXPORT crc32_z ( uLong crc,
const Bytef * buf,
z_size_t len )

◆ deflate()

ZEXTERN int ZEXPORT deflate ( z_streamp strm,
int flush )

Definition at line 950 of file deflate.c.

950 {
951 int old_flush; /* value of flush param for previous deflate call */
952 deflate_state *s;
953
954 if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
955 return Z_STREAM_ERROR;
956 }
957 s = strm->state;
958
959 if (strm->next_out == Z_NULL ||
960 (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
961 (s->status == FINISH_STATE && flush != Z_FINISH)) {
963 }
964 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
965
966 old_flush = s->last_flush;
967 s->last_flush = flush;
968
969 /* Flush as much pending output as possible */
970 if (s->pending != 0) {
971 flush_pending(strm);
972 if (strm->avail_out == 0) {
973 /* Since avail_out is 0, deflate will be called again with
974 * more output space, but possibly with both pending and
975 * avail_in equal to zero. There won't be anything to do,
976 * but this is not an error situation so make sure we
977 * return OK instead of BUF_ERROR at next call of deflate:
978 */
979 s->last_flush = -1;
980 return Z_OK;
981 }
982
983 /* Make sure there is something to do and avoid duplicate consecutive
984 * flushes. For repeated and useless calls with Z_FINISH, we keep
985 * returning Z_STREAM_END instead of Z_BUF_ERROR.
986 */
987 } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
988 flush != Z_FINISH) {
989 ERR_RETURN(strm, Z_BUF_ERROR);
990 }
991
992 /* User must not provide more input after the first FINISH: */
993 if (s->status == FINISH_STATE && strm->avail_in != 0) {
994 ERR_RETURN(strm, Z_BUF_ERROR);
995 }
996
997 /* Write the header */
998 if (s->status == INIT_STATE && s->wrap == 0)
999 s->status = BUSY_STATE;
1000 if (s->status == INIT_STATE) {
1001 /* zlib header */
1002 uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8;
1003 uInt level_flags;
1004
1005 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
1006 level_flags = 0;
1007 else if (s->level < 6)
1008 level_flags = 1;
1009 else if (s->level == 6)
1010 level_flags = 2;
1011 else
1012 level_flags = 3;
1013 header |= (level_flags << 6);
1014 if (s->strstart != 0) header |= PRESET_DICT;
1015 header += 31 - (header % 31);
1016
1017 putShortMSB(s, header);
1018
1019 /* Save the adler32 of the preset dictionary: */
1020 if (s->strstart != 0) {
1021 putShortMSB(s, (uInt)(strm->adler >> 16));
1022 putShortMSB(s, (uInt)(strm->adler & 0xffff));
1023 }
1024 strm->adler = adler32(0L, Z_NULL, 0);
1025 s->status = BUSY_STATE;
1026
1027 /* Compression must start with an empty pending buffer */
1028 flush_pending(strm);
1029 if (s->pending != 0) {
1030 s->last_flush = -1;
1031 return Z_OK;
1032 }
1033 }
1034#ifdef GZIP
1035 if (s->status == GZIP_STATE) {
1036 /* gzip header */
1037 strm->adler = crc32(0L, Z_NULL, 0);
1038 put_byte(s, 31);
1039 put_byte(s, 139);
1040 put_byte(s, 8);
1041 if (s->gzhead == Z_NULL) {
1042 put_byte(s, 0);
1043 put_byte(s, 0);
1044 put_byte(s, 0);
1045 put_byte(s, 0);
1046 put_byte(s, 0);
1047 put_byte(s, s->level == 9 ? 2 :
1048 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
1049 4 : 0));
1050 put_byte(s, OS_CODE);
1051 s->status = BUSY_STATE;
1052
1053 /* Compression must start with an empty pending buffer */
1054 flush_pending(strm);
1055 if (s->pending != 0) {
1056 s->last_flush = -1;
1057 return Z_OK;
1058 }
1059 }
1060 else {
1061 put_byte(s, (s->gzhead->text ? 1 : 0) +
1062 (s->gzhead->hcrc ? 2 : 0) +
1063 (s->gzhead->extra == Z_NULL ? 0 : 4) +
1064 (s->gzhead->name == Z_NULL ? 0 : 8) +
1065 (s->gzhead->comment == Z_NULL ? 0 : 16)
1066 );
1067 put_byte(s, (Byte)(s->gzhead->time & 0xff));
1068 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
1069 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
1070 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
1071 put_byte(s, s->level == 9 ? 2 :
1072 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
1073 4 : 0));
1074 put_byte(s, s->gzhead->os & 0xff);
1075 if (s->gzhead->extra != Z_NULL) {
1076 put_byte(s, s->gzhead->extra_len & 0xff);
1077 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
1078 }
1079 if (s->gzhead->hcrc)
1080 strm->adler = crc32(strm->adler, s->pending_buf,
1081 s->pending);
1082 s->gzindex = 0;
1083 s->status = EXTRA_STATE;
1084 }
1085 }
1086 if (s->status == EXTRA_STATE) {
1087 if (s->gzhead->extra != Z_NULL) {
1088 ulg beg = s->pending; /* start of bytes to update crc */
1089 uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
1090 while (s->pending + left > s->pending_buf_size) {
1091 uInt copy = s->pending_buf_size - s->pending;
1092 zmemcpy(s->pending_buf + s->pending,
1093 s->gzhead->extra + s->gzindex, copy);
1094 s->pending = s->pending_buf_size;
1095 HCRC_UPDATE(beg);
1096 s->gzindex += copy;
1097 flush_pending(strm);
1098 if (s->pending != 0) {
1099 s->last_flush = -1;
1100 return Z_OK;
1101 }
1102 beg = 0;
1103 left -= copy;
1104 }
1105 zmemcpy(s->pending_buf + s->pending,
1106 s->gzhead->extra + s->gzindex, left);
1107 s->pending += left;
1108 HCRC_UPDATE(beg);
1109 s->gzindex = 0;
1110 }
1111 s->status = NAME_STATE;
1112 }
1113 if (s->status == NAME_STATE) {
1114 if (s->gzhead->name != Z_NULL) {
1115 ulg beg = s->pending; /* start of bytes to update crc */
1116 int val;
1117 do {
1118 if (s->pending == s->pending_buf_size) {
1119 HCRC_UPDATE(beg);
1120 flush_pending(strm);
1121 if (s->pending != 0) {
1122 s->last_flush = -1;
1123 return Z_OK;
1124 }
1125 beg = 0;
1126 }
1127 val = s->gzhead->name[s->gzindex++];
1128 put_byte(s, val);
1129 } while (val != 0);
1130 HCRC_UPDATE(beg);
1131 s->gzindex = 0;
1132 }
1133 s->status = COMMENT_STATE;
1134 }
1135 if (s->status == COMMENT_STATE) {
1136 if (s->gzhead->comment != Z_NULL) {
1137 ulg beg = s->pending; /* start of bytes to update crc */
1138 int val;
1139 do {
1140 if (s->pending == s->pending_buf_size) {
1141 HCRC_UPDATE(beg);
1142 flush_pending(strm);
1143 if (s->pending != 0) {
1144 s->last_flush = -1;
1145 return Z_OK;
1146 }
1147 beg = 0;
1148 }
1149 val = s->gzhead->comment[s->gzindex++];
1150 put_byte(s, val);
1151 } while (val != 0);
1152 HCRC_UPDATE(beg);
1153 }
1154 s->status = HCRC_STATE;
1155 }
1156 if (s->status == HCRC_STATE) {
1157 if (s->gzhead->hcrc) {
1158 if (s->pending + 2 > s->pending_buf_size) {
1159 flush_pending(strm);
1160 if (s->pending != 0) {
1161 s->last_flush = -1;
1162 return Z_OK;
1163 }
1164 }
1165 put_byte(s, (Byte)(strm->adler & 0xff));
1166 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1167 strm->adler = crc32(0L, Z_NULL, 0);
1168 }
1169 s->status = BUSY_STATE;
1170
1171 /* Compression must start with an empty pending buffer */
1172 flush_pending(strm);
1173 if (s->pending != 0) {
1174 s->last_flush = -1;
1175 return Z_OK;
1176 }
1177 }
1178#endif
1179
1180 /* Start a new block or continue the current one.
1181 */
1182 if (strm->avail_in != 0 || s->lookahead != 0 ||
1183 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
1184 block_state bstate;
1185
1186 bstate = s->level == 0 ? deflate_stored(s, flush) :
1187 s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
1188 s->strategy == Z_RLE ? deflate_rle(s, flush) :
1189 (*(configuration_table[s->level].func))(s, flush);
1190
1191 if (bstate == finish_started || bstate == finish_done) {
1192 s->status = FINISH_STATE;
1193 }
1194 if (bstate == need_more || bstate == finish_started) {
1195 if (strm->avail_out == 0) {
1196 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
1197 }
1198 return Z_OK;
1199 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
1200 * of deflate should use the same flush parameter to make sure
1201 * that the flush is complete. So we don't have to output an
1202 * empty block here, this will be done at next call. This also
1203 * ensures that for a very small output buffer, we emit at most
1204 * one empty block.
1205 */
1206 }
1207 if (bstate == block_done) {
1208 if (flush == Z_PARTIAL_FLUSH) {
1209 _tr_align(s);
1210 } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
1211 _tr_stored_block(s, (char*)0, 0L, 0);
1212 /* For a full flush, this empty block will be recognized
1213 * as a special marker by inflate_sync().
1214 */
1215 if (flush == Z_FULL_FLUSH) {
1216 CLEAR_HASH(s); /* forget history */
1217 if (s->lookahead == 0) {
1218 s->strstart = 0;
1219 s->block_start = 0L;
1220 s->insert = 0;
1221 }
1222 }
1223 }
1224 flush_pending(strm);
1225 if (strm->avail_out == 0) {
1226 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
1227 return Z_OK;
1228 }
1229 }
1230 }
1231
1232 if (flush != Z_FINISH) return Z_OK;
1233 if (s->wrap <= 0) return Z_STREAM_END;
1234
1235 /* Write the trailer */
1236#ifdef GZIP
1237 if (s->wrap == 2) {
1238 put_byte(s, (Byte)(strm->adler & 0xff));
1239 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1240 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
1241 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
1242 put_byte(s, (Byte)(strm->total_in & 0xff));
1243 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
1244 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
1245 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
1246 }
1247 else
1248#endif
1249 {
1250 putShortMSB(s, (uInt)(strm->adler >> 16));
1251 putShortMSB(s, (uInt)(strm->adler & 0xffff));
1252 }
1253 flush_pending(strm);
1254 /* If avail_out is zero, the application will call deflate again
1255 * to flush the rest.
1256 */
1257 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
1258 return s->pending != 0 ? Z_OK : Z_STREAM_END;
1259}
block_state
Definition deflate.c:63
@ finish_started
Definition deflate.c:66
@ block_done
Definition deflate.c:65
@ need_more
Definition deflate.c:64
@ finish_done
Definition deflate.c:67
#define HCRC_UPDATE(beg)
Definition deflate.c:942
local block_state deflate_huff(deflate_state *s, int flush)
Definition deflate.c:2113
local block_state deflate_stored(deflate_state *s, int flush)
Definition deflate.c:1631
local void putShortMSB(deflate_state *s, uInt b)
Definition deflate.c:908
local int deflateStateCheck(z_streamp strm)
Definition deflate.c:533
local const config configuration_table[10]
Definition deflate.c:112
#define RANK(f)
Definition deflate.c:133
local void flush_pending(z_streamp strm)
Definition deflate.c:919
local block_state deflate_rle(deflate_state *s, int flush)
Definition deflate.c:2042
#define CLEAR_HASH(s)
Definition deflate.c:170
#define FINISH_STATE
Definition deflate.h:67
#define COMMENT_STATE
Definition deflate.h:64
#define HCRC_STATE
Definition deflate.h:65
#define GZIP_STATE
Definition deflate.h:60
#define BUSY_STATE
Definition deflate.h:66
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition trees.c:858
#define put_byte(s, c)
Definition deflate.h:287
#define INIT_STATE
Definition deflate.h:58
void ZLIB_INTERNAL _tr_align(deflate_state *s)
Definition trees.c:886
#define NAME_STATE
Definition deflate.h:63
struct internal_state deflate_state
#define EXTRA_STATE
Definition deflate.h:62
void copy(G4double dst[], const G4double src[], std::size_t size=G4FieldTrack::ncompSVEC)
#define Z_HUFFMAN_ONLY
Definition zlib.h:197
#define Z_DEFLATED
Definition zlib.h:209
ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition adler32.c:128
#define Z_BUF_ERROR
Definition zlib.h:184
#define Z_BLOCK
Definition zlib.h:173
ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len)
#define Z_STREAM_ERROR
Definition zlib.h:181
#define Z_PARTIAL_FLUSH
Definition zlib.h:169
#define Z_FULL_FLUSH
Definition zlib.h:171
#define Z_RLE
Definition zlib.h:198
#define ERR_RETURN(strm, err)
Definition zutil.h:61
#define PRESET_DICT
Definition zutil.h:88
#define OS_CODE
Definition zutil.h:177
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition zutil.c:145
unsigned long ulg
Definition zutil.h:43

Referenced by compress2(), deflateParams(), and gz_comp().

◆ deflateBound()

ZEXTERN uLong ZEXPORT deflateBound ( z_streamp strm,
uLong sourceLen )

Definition at line 838 of file deflate.c.

838 {
839 deflate_state *s;
840 uLong fixedlen, storelen, wraplen;
841
842 /* upper bound for fixed blocks with 9-bit literals and length 255
843 (memLevel == 2, which is the lowest that may not use stored blocks) --
844 ~13% overhead plus a small constant */
845 fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) +
846 (sourceLen >> 9) + 4;
847
848 /* upper bound for stored blocks with length 127 (memLevel == 1) --
849 ~4% overhead plus a small constant */
850 storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) +
851 (sourceLen >> 11) + 7;
852
853 /* if can't get parameters, return larger bound plus a zlib wrapper */
854 if (deflateStateCheck(strm))
855 return (fixedlen > storelen ? fixedlen : storelen) + 6;
856
857 /* compute wrapper length */
858 s = strm->state;
859 switch (s->wrap) {
860 case 0: /* raw deflate */
861 wraplen = 0;
862 break;
863 case 1: /* zlib wrapper */
864 wraplen = 6 + (s->strstart ? 4 : 0);
865 break;
866#ifdef GZIP
867 case 2: /* gzip wrapper */
868 wraplen = 18;
869 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
870 Bytef *str;
871 if (s->gzhead->extra != Z_NULL)
872 wraplen += 2 + s->gzhead->extra_len;
873 str = s->gzhead->name;
874 if (str != Z_NULL)
875 do {
876 wraplen++;
877 } while (*str++);
878 str = s->gzhead->comment;
879 if (str != Z_NULL)
880 do {
881 wraplen++;
882 } while (*str++);
883 if (s->gzhead->hcrc)
884 wraplen += 2;
885 }
886 break;
887#endif
888 default: /* for compiler happiness */
889 wraplen = 6;
890 }
891
892 /* if not default parameters, return one of the conservative bounds */
893 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
894 return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +
895 wraplen;
896
897 /* default settings: return tight bound for that case -- ~0.03% overhead
898 plus a small constant */
899 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
900 (sourceLen >> 25) + 13 - 6 + wraplen;
901}

◆ deflateCopy()

ZEXTERN int ZEXPORT deflateCopy ( z_streamp dest,
z_streamp source )

Definition at line 1286 of file deflate.c.

1286 {
1287#ifdef MAXSEG_64K
1288 (void)dest;
1289 (void)source;
1290 return Z_STREAM_ERROR;
1291#else
1292 deflate_state *ds;
1293 deflate_state *ss;
1294
1295
1296 if (deflateStateCheck(source) || dest == Z_NULL) {
1297 return Z_STREAM_ERROR;
1298 }
1299
1300 ss = source->state;
1301
1302 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1303
1304 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
1305 if (ds == Z_NULL) return Z_MEM_ERROR;
1306 dest->state = (struct internal_state FAR *) ds;
1307 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
1308 ds->strm = dest;
1309
1310 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1311 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1312 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1313 ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);
1314
1315 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1316 ds->pending_buf == Z_NULL) {
1317 deflateEnd (dest);
1318 return Z_MEM_ERROR;
1319 }
1320 /* following zmemcpy do not work for 16-bit MSDOS */
1321 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1322 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1323 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1324 zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS);
1325
1326 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1327#ifdef LIT_MEM
1328 ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1));
1329 ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2);
1330#else
1331 ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
1332#endif
1333
1334 ds->l_desc.dyn_tree = ds->dyn_ltree;
1335 ds->d_desc.dyn_tree = ds->dyn_dtree;
1336 ds->bl_desc.dyn_tree = ds->bl_tree;
1337
1338 return Z_OK;
1339#endif /* MAXSEG_64K */
1340}
int ZEXPORT deflateEnd(z_streamp strm)
Definition deflate.c:1262
Pos FAR Posf
Definition deflate.h:97
ush Pos
Definition deflate.h:96
#define LIT_BUFS
Definition deflate.h:229
#define Z_MEM_ERROR
Definition zlib.h:183
#define ZALLOC(strm, items, size)
Definition zutil.h:241
uch FAR uchf
Definition zutil.h:40
ush FAR ushf
Definition zutil.h:42

◆ deflateEnd()

ZEXTERN int ZEXPORT deflateEnd ( z_streamp strm)

Definition at line 1262 of file deflate.c.

1262 {
1263 int status;
1264
1265 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
1266
1267 status = strm->state->status;
1268
1269 /* Deallocate in reverse order of allocations: */
1270 TRY_FREE(strm, strm->state->pending_buf);
1271 TRY_FREE(strm, strm->state->head);
1272 TRY_FREE(strm, strm->state->prev);
1273 TRY_FREE(strm, strm->state->window);
1274
1275 ZFREE(strm, strm->state);
1276 strm->state = Z_NULL;
1277
1278 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
1279}
#define Z_DATA_ERROR
Definition zlib.h:182
#define ZFREE(strm, addr)
Definition zutil.h:243
#define TRY_FREE(s, p)
Definition zutil.h:244

Referenced by compress2(), deflateCopy(), deflateInit2_(), and gzclose_w().

◆ deflateGetDictionary()

ZEXTERN int ZEXPORT deflateGetDictionary ( z_streamp strm,
Bytef * dictionary,
uInt * dictLength )

Definition at line 620 of file deflate.c.

621 {
622 deflate_state *s;
623 uInt len;
624
625 if (deflateStateCheck(strm))
626 return Z_STREAM_ERROR;
627 s = strm->state;
628 len = s->strstart + s->lookahead;
629 if (len > s->w_size)
630 len = s->w_size;
631 if (dictionary != Z_NULL && len)
632 zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
633 if (dictLength != Z_NULL)
634 *dictLength = len;
635 return Z_OK;
636}

◆ deflateInit2_()

ZEXTERN int ZEXPORT deflateInit2_ ( z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy,
const char * version,
int stream_size )

Definition at line 379 of file deflate.c.

381 {
382 deflate_state *s;
383 int wrap = 1;
384 static const char my_version[] = ZLIB_VERSION;
385
386 if (version == Z_NULL || version[0] != my_version[0] ||
387 stream_size != sizeof(z_stream)) {
388 return Z_VERSION_ERROR;
389 }
390 if (strm == Z_NULL) return Z_STREAM_ERROR;
391
392 strm->msg = Z_NULL;
393 if (strm->zalloc == (alloc_func)0) {
394#ifdef Z_SOLO
395 return Z_STREAM_ERROR;
396#else
397 strm->zalloc = zcalloc;
398 strm->opaque = (voidpf)0;
399#endif
400 }
401 if (strm->zfree == (free_func)0)
402#ifdef Z_SOLO
403 return Z_STREAM_ERROR;
404#else
405 strm->zfree = zcfree;
406#endif
407
408#ifdef FASTEST
409 if (level != 0) level = 1;
410#else
411 if (level == Z_DEFAULT_COMPRESSION) level = 6;
412#endif
413
414 if (windowBits < 0) { /* suppress zlib wrapper */
415 wrap = 0;
416 if (windowBits < -15)
417 return Z_STREAM_ERROR;
418 windowBits = -windowBits;
419 }
420#ifdef GZIP
421 else if (windowBits > 15) {
422 wrap = 2; /* write gzip wrapper instead */
423 windowBits -= 16;
424 }
425#endif
426 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
427 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
428 strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
429 return Z_STREAM_ERROR;
430 }
431 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
432 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
433 if (s == Z_NULL) return Z_MEM_ERROR;
434 strm->state = (struct internal_state FAR *)s;
435 s->strm = strm;
436 s->status = INIT_STATE; /* to pass state test in deflateReset() */
437
438 s->wrap = wrap;
439 s->gzhead = Z_NULL;
440 s->w_bits = (uInt)windowBits;
441 s->w_size = 1 << s->w_bits;
442 s->w_mask = s->w_size - 1;
443
444 s->hash_bits = (uInt)memLevel + 7;
445 s->hash_size = 1 << s->hash_bits;
446 s->hash_mask = s->hash_size - 1;
447 s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
448
449 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
450 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
451 /* Avoid use of uninitialized value, see:
452 * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11360
453 */
454 zmemzero(s->prev, s->w_size * sizeof(Pos));
455 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
456
457 s->high_water = 0; /* nothing written to s->window yet */
458
459 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
460
461 /* We overlay pending_buf and sym_buf. This works since the average size
462 * for length/distance pairs over any compressed block is assured to be 31
463 * bits or less.
464 *
465 * Analysis: The longest fixed codes are a length code of 8 bits plus 5
466 * extra bits, for lengths 131 to 257. The longest fixed distance codes are
467 * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
468 * possible fixed-codes length/distance pair is then 31 bits total.
469 *
470 * sym_buf starts one-fourth of the way into pending_buf. So there are
471 * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
472 * in sym_buf is three bytes -- two for the distance and one for the
473 * literal/length. As each symbol is consumed, the pointer to the next
474 * sym_buf value to read moves forward three bytes. From that symbol, up to
475 * 31 bits are written to pending_buf. The closest the written pending_buf
476 * bits gets to the next sym_buf symbol to read is just before the last
477 * code is written. At that time, 31*(n - 2) bits have been written, just
478 * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at
479 * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1
480 * symbols are written.) The closest the writing gets to what is unread is
481 * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and
482 * can range from 128 to 32768.
483 *
484 * Therefore, at a minimum, there are 142 bits of space between what is
485 * written and what is read in the overlain buffers, so the symbols cannot
486 * be overwritten by the compressed data. That space is actually 139 bits,
487 * due to the three-bit fixed-code block header.
488 *
489 * That covers the case where either Z_FIXED is specified, forcing fixed
490 * codes, or when the use of fixed codes is chosen, because that choice
491 * results in a smaller compressed block than dynamic codes. That latter
492 * condition then assures that the above analysis also covers all dynamic
493 * blocks. A dynamic-code block will only be chosen to be emitted if it has
494 * fewer bits than a fixed-code block would for the same set of symbols.
495 * Therefore its average symbol length is assured to be less than 31. So
496 * the compressed data for a dynamic block also cannot overwrite the
497 * symbols from which it is being constructed.
498 */
499
500 s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS);
501 s->pending_buf_size = (ulg)s->lit_bufsize * 4;
502
503 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
504 s->pending_buf == Z_NULL) {
505 s->status = FINISH_STATE;
506 strm->msg = ERR_MSG(Z_MEM_ERROR);
508 return Z_MEM_ERROR;
509 }
510#ifdef LIT_MEM
511 s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1));
512 s->l_buf = s->pending_buf + (s->lit_bufsize << 2);
513 s->sym_end = s->lit_bufsize - 1;
514#else
515 s->sym_buf = s->pending_buf + s->lit_bufsize;
516 s->sym_end = (s->lit_bufsize - 1) * 3;
517#endif
518 /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
519 * on 16 bit machines and because stored blocks are restricted to
520 * 64K-1 bytes.
521 */
522
523 s->level = level;
524 s->strategy = strategy;
525 s->method = (Byte)method;
526
527 return deflateReset(strm);
528}
int ZEXPORT deflateReset(z_streamp strm)
Definition deflate.c:699
z_streamp strm
Definition deflate.h:105
#define Z_VERSION_ERROR
Definition zlib.h:185
#define Z_FIXED
Definition zlib.h:199
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
Definition zutil.c:292
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition zutil.c:286
#define ERR_MSG(err)
Definition zutil.h:59
#define MIN_MATCH
Definition zutil.h:84
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
Definition zutil.c:161

Referenced by deflateInit_().

◆ deflateInit_()

ZEXTERN int ZEXPORT deflateInit_ ( z_streamp strm,
int level,
const char * version,
int stream_size )

Definition at line 371 of file deflate.c.

372 {
373 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
374 Z_DEFAULT_STRATEGY, version, stream_size);
375 /* To do: ignore strm->next_in if we use it as window */
376}
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
Definition deflate.c:379
#define DEF_MEM_LEVEL
Definition gzguts.h:150
#define Z_DEFAULT_STRATEGY
Definition zlib.h:200

◆ deflateParams()

ZEXTERN int ZEXPORT deflateParams ( z_streamp strm,
int level,
int strategy )

Definition at line 756 of file deflate.c.

756 {
757 deflate_state *s;
758 compress_func func;
759
760 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
761 s = strm->state;
762
763#ifdef FASTEST
764 if (level != 0) level = 1;
765#else
766 if (level == Z_DEFAULT_COMPRESSION) level = 6;
767#endif
768 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
769 return Z_STREAM_ERROR;
770 }
771 func = configuration_table[s->level].func;
772
773 if ((strategy != s->strategy || func != configuration_table[level].func) &&
774 s->last_flush != -2) {
775 /* Flush the last buffer: */
776 int err = deflate(strm, Z_BLOCK);
777 if (err == Z_STREAM_ERROR)
778 return err;
779 if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
780 return Z_BUF_ERROR;
781 }
782 if (s->level != level) {
783 if (s->level == 0 && s->matches != 0) {
784 if (s->matches == 1)
785 slide_hash(s);
786 else
787 CLEAR_HASH(s);
788 s->matches = 0;
789 }
790 s->level = level;
791 s->max_lazy_match = configuration_table[level].max_lazy;
792 s->good_match = configuration_table[level].good_length;
793 s->nice_match = configuration_table[level].nice_length;
794 s->max_chain_length = configuration_table[level].max_chain;
795 }
796 s->strategy = strategy;
797 return Z_OK;
798}
block_state(* compress_func)(deflate_state *s, int flush)
Definition deflate.c:70
local void slide_hash(deflate_state *s)
Definition deflate.c:187
int ZEXPORT deflate(z_streamp strm, int flush)
Definition deflate.c:950

Referenced by gzsetparams().

◆ deflatePending()

ZEXTERN int ZEXPORT deflatePending ( z_streamp strm,
unsigned * pending,
int * bits )

Definition at line 717 of file deflate.c.

717 {
718 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
719 if (pending != Z_NULL)
720 *pending = strm->state->pending;
721 if (bits != Z_NULL)
722 *bits = strm->state->bi_valid;
723 return Z_OK;
724}

◆ deflatePrime()

ZEXTERN int ZEXPORT deflatePrime ( z_streamp strm,
int bits,
int value )

Definition at line 727 of file deflate.c.

727 {
728 deflate_state *s;
729 int put;
730
731 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
732 s = strm->state;
733#ifdef LIT_MEM
734 if (bits < 0 || bits > 16 ||
735 (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3))
736 return Z_BUF_ERROR;
737#else
738 if (bits < 0 || bits > 16 ||
739 s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
740 return Z_BUF_ERROR;
741#endif
742 do {
743 put = Buf_size - s->bi_valid;
744 if (put > bits)
745 put = bits;
746 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
747 s->bi_valid += put;
749 value >>= put;
750 bits -= put;
751 } while (bits);
752 return Z_OK;
753}
#define Buf_size
Definition deflate.h:55
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
Definition trees.c:878
unsigned short ush
Definition zutil.h:41

◆ deflateReset()

ZEXTERN int ZEXPORT deflateReset ( z_streamp strm)

Definition at line 699 of file deflate.c.

699 {
700 int ret;
701
702 ret = deflateResetKeep(strm);
703 if (ret == Z_OK)
704 lm_init(strm->state);
705 return ret;
706}
local void lm_init(deflate_state *s)
Definition deflate.c:677
int ZEXPORT deflateResetKeep(z_streamp strm)
Definition deflate.c:639

Referenced by deflateInit2_(), and gz_comp().

◆ deflateResetKeep()

ZEXTERN int ZEXPORT deflateResetKeep ( z_streamp strm)

Definition at line 639 of file deflate.c.

639 {
640 deflate_state *s;
641
642 if (deflateStateCheck(strm)) {
643 return Z_STREAM_ERROR;
644 }
645
646 strm->total_in = strm->total_out = 0;
647 strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
648 strm->data_type = Z_UNKNOWN;
649
650 s = (deflate_state *)strm->state;
651 s->pending = 0;
652 s->pending_out = s->pending_buf;
653
654 if (s->wrap < 0) {
655 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
656 }
657 s->status =
658#ifdef GZIP
659 s->wrap == 2 ? GZIP_STATE :
660#endif
662 strm->adler =
663#ifdef GZIP
664 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
665#endif
666 adler32(0L, Z_NULL, 0);
667 s->last_flush = -2;
668
669 _tr_init(s);
670
671 return Z_OK;
672}
void ZLIB_INTERNAL _tr_init(deflate_state *s)
Definition trees.c:455
#define Z_UNKNOWN
Definition zlib.h:206

Referenced by deflateReset().

◆ deflateSetDictionary()

ZEXTERN int ZEXPORT deflateSetDictionary ( z_streamp strm,
const Bytef * dictionary,
uInt dictLength )

Definition at line 554 of file deflate.c.

555 {
556 deflate_state *s;
557 uInt str, n;
558 int wrap;
559 unsigned avail;
560 z_const unsigned char *next;
561
562 if (deflateStateCheck(strm) || dictionary == Z_NULL)
563 return Z_STREAM_ERROR;
564 s = strm->state;
565 wrap = s->wrap;
566 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
567 return Z_STREAM_ERROR;
568
569 /* when using zlib wrappers, compute Adler-32 for provided dictionary */
570 if (wrap == 1)
571 strm->adler = adler32(strm->adler, dictionary, dictLength);
572 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
573
574 /* if dictionary would fill window, just replace the history */
575 if (dictLength >= s->w_size) {
576 if (wrap == 0) { /* already empty otherwise */
577 CLEAR_HASH(s);
578 s->strstart = 0;
579 s->block_start = 0L;
580 s->insert = 0;
581 }
582 dictionary += dictLength - s->w_size; /* use the tail */
583 dictLength = s->w_size;
584 }
585
586 /* insert dictionary into window and hash */
587 avail = strm->avail_in;
588 next = strm->next_in;
589 strm->avail_in = dictLength;
590 strm->next_in = (z_const Bytef *)dictionary;
591 fill_window(s);
592 while (s->lookahead >= MIN_MATCH) {
593 str = s->strstart;
594 n = s->lookahead - (MIN_MATCH-1);
595 do {
596 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
597#ifndef FASTEST
598 s->prev[str & s->w_mask] = s->head[s->ins_h];
599#endif
600 s->head[s->ins_h] = (Pos)str;
601 str++;
602 } while (--n);
603 s->strstart = str;
604 s->lookahead = MIN_MATCH-1;
605 fill_window(s);
606 }
607 s->strstart += s->lookahead;
608 s->block_start = (long)s->strstart;
609 s->insert = s->lookahead;
610 s->lookahead = 0;
611 s->match_length = s->prev_length = MIN_MATCH-1;
612 s->match_available = 0;
613 strm->next_in = next;
614 strm->avail_in = avail;
615 s->wrap = wrap;
616 return Z_OK;
617}
#define UPDATE_HASH(s, h, c)
Definition deflate.c:141
local void fill_window(deflate_state *s)
Definition deflate.c:251

◆ deflateSetHeader()

ZEXTERN int ZEXPORT deflateSetHeader ( z_streamp strm,
gz_headerp head )

Definition at line 709 of file deflate.c.

709 {
710 if (deflateStateCheck(strm) || strm->state->wrap != 2)
711 return Z_STREAM_ERROR;
712 strm->state->gzhead = head;
713 return Z_OK;
714}

◆ deflateTune()

ZEXTERN int ZEXPORT deflateTune ( z_streamp strm,
int good_length,
int max_lazy,
int nice_length,
int max_chain )

Definition at line 801 of file deflate.c.

802 {
803 deflate_state *s;
804
805 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
806 s = strm->state;
807 s->good_match = (uInt)good_length;
808 s->max_lazy_match = (uInt)max_lazy;
809 s->nice_match = nice_length;
810 s->max_chain_length = (uInt)max_chain;
811 return Z_OK;
812}

◆ get_crc_table()

ZEXTERN const z_crc_t FAR *ZEXPORT get_crc_table ( void )

Definition at line 549 of file crc32.c.

549 {
550#ifdef DYNAMIC_CRC_TABLE
551 once(&made, make_crc_table);
552#endif /* DYNAMIC_CRC_TABLE */
553 return (const z_crc_t FAR *)crc_table;
554}
local const z_crc_t FAR crc_table[]
Definition crc32.h:5

◆ gzbuffer()

ZEXTERN int ZEXPORT gzbuffer ( gzFile file,
unsigned size )

Definition at line 294 of file gzlib.c.

294 {
295 gz_statep state;
296
297 /* get internal structure and check integrity */
298 if (file == NULL)
299 return -1;
300 state = (gz_statep)file;
301 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
302 return -1;
303
304 /* make sure we haven't already allocated memory */
305 if (state->size != 0)
306 return -1;
307
308 /* check and set requested size */
309 if ((size << 1) < size)
310 return -1; /* need to be able to double it */
311 if (size < 8)
312 size = 8; /* needed to behave well with flushing */
313 state->want = size;
314 return 0;
315}
gz_state FAR * gz_statep
Definition gzguts.h:202
#define GZ_WRITE
Definition gzguts.h:160
#define GZ_READ
Definition gzguts.h:159

◆ gzclearerr()

ZEXTERN void ZEXPORT gzclearerr ( gzFile file)

Definition at line 505 of file gzlib.c.

505 {
506 gz_statep state;
507
508 /* get internal structure and check integrity */
509 if (file == NULL)
510 return;
511 state = (gz_statep)file;
512 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
513 return;
514
515 /* clear error and end-of-file */
516 if (state->mode == GZ_READ) {
517 state->eof = 0;
518 state->past = 0;
519 }
520 gz_error(state, Z_OK, NULL);
521}
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
Definition gzlib.c:529

◆ gzclose()

ZEXTERN int ZEXPORT gzclose ( gzFile file)

Definition at line 11 of file gzclose.c.

11 {
12#ifndef NO_GZCOMPRESS
13 gz_statep state;
14
15 if (file == NULL)
16 return Z_STREAM_ERROR;
17 state = (gz_statep)file;
18
19 return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
20#else
21 return gzclose_r(file);
22#endif
23}
ZEXTERN int ZEXPORT gzclose_r(gzFile file)
Definition gzread.c:577
ZEXTERN int ZEXPORT gzclose_w(gzFile file)
Definition gzwrite.c:595

◆ gzclose_r()

ZEXTERN int ZEXPORT gzclose_r ( gzFile file)

Definition at line 577 of file gzread.c.

577 {
578 int ret, err;
579 gz_statep state;
580
581 /* get internal structure */
582 if (file == NULL)
583 return Z_STREAM_ERROR;
584 state = (gz_statep)file;
585
586 /* check that we're reading */
587 if (state->mode != GZ_READ)
588 return Z_STREAM_ERROR;
589
590 /* free memory and close file */
591 if (state->size) {
592 inflateEnd(&(state->strm));
593 free(state->out);
594 free(state->in);
595 }
596 err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
597 gz_error(state, Z_OK, NULL);
598 free(state->path);
599 ret = close(state->fd);
600 free(state);
601 return ret ? Z_ERRNO : err;
602}
void free(voidpf ptr)
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *)
Definition gzlib.c:529
#define Z_ERRNO
Definition zlib.h:180
ZEXTERN int ZEXPORT inflateEnd(z_streamp strm)
Definition inflate.c:1266

Referenced by gzclose().

◆ gzclose_w()

ZEXTERN int ZEXPORT gzclose_w ( gzFile file)

Definition at line 595 of file gzwrite.c.

595 {
596 int ret = Z_OK;
597 gz_statep state;
598
599 /* get internal structure */
600 if (file == NULL)
601 return Z_STREAM_ERROR;
602 state = (gz_statep)file;
603
604 /* check that we're writing */
605 if (state->mode != GZ_WRITE)
606 return Z_STREAM_ERROR;
607
608 /* check for seek request */
609 if (state->seek) {
610 state->seek = 0;
611 if (gz_zero(state, state->skip) == -1)
612 ret = state->err;
613 }
614
615 /* flush, free memory, and close file */
616 if (gz_comp(state, Z_FINISH) == -1)
617 ret = state->err;
618 if (state->size) {
619 if (!state->direct) {
620 (void)deflateEnd(&(state->strm));
621 free(state->out);
622 }
623 free(state->in);
624 }
625 gz_error(state, Z_OK, NULL);
626 free(state->path);
627 if (close(state->fd) == -1)
628 ret = Z_ERRNO;
629 free(state);
630 return ret;
631}
local int gz_comp(gz_statep state, int flush)
Definition gzwrite.c:65
local int gz_zero(gz_statep state, z_off64_t len)
Definition gzwrite.c:143

Referenced by gzclose().

◆ gzdirect()

ZEXTERN int ZEXPORT gzdirect ( gzFile file)

Definition at line 559 of file gzread.c.

559 {
560 gz_statep state;
561
562 /* get internal structure */
563 if (file == NULL)
564 return 0;
565 state = (gz_statep)file;
566
567 /* if the state is not known, but we can find out, then do so (this is
568 mainly for right after a gzopen() or gzdopen()) */
569 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
570 (void)gz_look(state);
571
572 /* return 1 if transparent, 0 if processing a gzip stream */
573 return state->direct;
574}
#define LOOK
Definition gzguts.h:164
local int gz_look(gz_statep state)
Definition gzread.c:76

◆ gzdopen()

ZEXTERN gzFile ZEXPORT gzdopen ( int fd,
const char * mode )

Definition at line 270 of file gzlib.c.

270 {
271 char *path; /* identifier for error messages */
272 gzFile gz;
273
274 if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
275 return NULL;
276#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
277 (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
278#else
279 sprintf(path, "<fd:%d>", fd); /* for debugging */
280#endif
281 gz = gz_open(path, fd, mode);
282 free(path);
283 return gz;
284}
voidp malloc(uInt size)
local gzFile gz_open(const void *path, int fd, const char *mode)
Definition gzlib.c:85
struct gzFile_s * gzFile
Definition zlib.h:1305

◆ gzeof()

ZEXTERN int ZEXPORT gzeof ( gzFile file)

Definition at line 472 of file gzlib.c.

472 {
473 gz_statep state;
474
475 /* get internal structure and check integrity */
476 if (file == NULL)
477 return 0;
478 state = (gz_statep)file;
479 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
480 return 0;
481
482 /* return end-of-file state */
483 return state->mode == GZ_READ ? state->past : 0;
484}

◆ gzerror()

ZEXTERN const char *ZEXPORT gzerror ( gzFile file,
int * errnum )

Definition at line 487 of file gzlib.c.

487 {
488 gz_statep state;
489
490 /* get internal structure and check integrity */
491 if (file == NULL)
492 return NULL;
493 state = (gz_statep)file;
494 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
495 return NULL;
496
497 /* return error information */
498 if (errnum != NULL)
499 *errnum = state->err;
500 return state->err == Z_MEM_ERROR ? "out of memory" :
501 (state->msg == NULL ? "" : state->msg);
502}

◆ gzflush()

ZEXTERN int ZEXPORT gzflush ( gzFile file,
int flush )

Definition at line 528 of file gzwrite.c.

528 {
529 gz_statep state;
530
531 /* get internal structure */
532 if (file == NULL)
533 return Z_STREAM_ERROR;
534 state = (gz_statep)file;
535
536 /* check that we're writing and that there's no error */
537 if (state->mode != GZ_WRITE || state->err != Z_OK)
538 return Z_STREAM_ERROR;
539
540 /* check flush parameter */
541 if (flush < 0 || flush > Z_FINISH)
542 return Z_STREAM_ERROR;
543
544 /* check for seek request */
545 if (state->seek) {
546 state->seek = 0;
547 if (gz_zero(state, state->skip) == -1)
548 return state->err;
549 }
550
551 /* compress remaining data with requested flush */
552 (void)gz_comp(state, flush);
553 return state->err;
554}

◆ gzfread()

ZEXTERN z_size_t ZEXPORT gzfread ( voidp buf,
z_size_t size,
z_size_t nitems,
gzFile file )

Definition at line 377 of file gzread.c.

377 {
378 z_size_t len;
379 gz_statep state;
380
381 /* get internal structure */
382 if (file == NULL)
383 return 0;
384 state = (gz_statep)file;
385
386 /* check that we're reading and that there's no (serious) error */
387 if (state->mode != GZ_READ ||
388 (state->err != Z_OK && state->err != Z_BUF_ERROR))
389 return 0;
390
391 /* compute bytes to read -- error on overflow */
392 len = nitems * size;
393 if (size && len / size != nitems) {
394 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
395 return 0;
396 }
397
398 /* read len or fewer bytes to buf, return the number of full items read */
399 return len ? gz_read(state, buf, len) / size : 0;
400}
local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len)
Definition gzread.c:268

◆ gzfwrite()

ZEXTERN z_size_t ZEXPORT gzfwrite ( voidpc buf,
z_size_t size,
z_size_t nitems,
gzFile file )

Definition at line 261 of file gzwrite.c.

262 {
263 z_size_t len;
264 gz_statep state;
265
266 /* get internal structure */
267 if (file == NULL)
268 return 0;
269 state = (gz_statep)file;
270
271 /* check that we're writing and that there's no error */
272 if (state->mode != GZ_WRITE || state->err != Z_OK)
273 return 0;
274
275 /* compute bytes to read -- error on overflow */
276 len = nitems * size;
277 if (size && len / size != nitems) {
278 gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
279 return 0;
280 }
281
282 /* write len bytes to buf, return the number of full items written */
283 return len ? gz_write(state, buf, len) / size : 0;
284}
local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len)
Definition gzwrite.c:173

◆ gzgetc()

ZEXTERN int ZEXPORT gzgetc ( gzFile file)

Definition at line 408 of file gzread.c.

408 {
409 unsigned char buf[1];
410 gz_statep state;
411
412 /* get internal structure */
413 if (file == NULL)
414 return -1;
415 state = (gz_statep)file;
416
417 /* check that we're reading and that there's no (serious) error */
418 if (state->mode != GZ_READ ||
419 (state->err != Z_OK && state->err != Z_BUF_ERROR))
420 return -1;
421
422 /* try output buffer (no need to check for skip request) */
423 if (state->x.have) {
424 state->x.have--;
425 state->x.pos++;
426 return *(state->x.next)++;
427 }
428
429 /* nothing there -- try gz_read() */
430 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
431}

◆ gzgetc_()

ZEXTERN int ZEXPORT gzgetc_ ( gzFile file)

Definition at line 433 of file gzread.c.

433 {
434 return gzgetc(file);
435}

◆ gzgets()

ZEXTERN char *ZEXPORT gzgets ( gzFile file,
char * buf,
int len )

Definition at line 499 of file gzread.c.

499 {
500 unsigned left, n;
501 char *str;
502 unsigned char *eol;
503 gz_statep state;
504
505 /* check parameters and get internal structure */
506 if (file == NULL || buf == NULL || len < 1)
507 return NULL;
508 state = (gz_statep)file;
509
510 /* check that we're reading and that there's no (serious) error */
511 if (state->mode != GZ_READ ||
512 (state->err != Z_OK && state->err != Z_BUF_ERROR))
513 return NULL;
514
515 /* process a skip request */
516 if (state->seek) {
517 state->seek = 0;
518 if (gz_skip(state, state->skip) == -1)
519 return NULL;
520 }
521
522 /* copy output bytes up to new line or len - 1, whichever comes first --
523 append a terminating zero to the string (we don't check for a zero in
524 the contents, let the user worry about that) */
525 str = buf;
526 left = (unsigned)len - 1;
527 if (left) do {
528 /* assure that something is in the output buffer */
529 if (state->x.have == 0 && gz_fetch(state) == -1)
530 return NULL; /* error */
531 if (state->x.have == 0) { /* end of file */
532 state->past = 1; /* read past end */
533 break; /* return what we have */
534 }
535
536 /* look for end-of-line in current output buffer */
537 n = state->x.have > left ? left : state->x.have;
538 eol = (unsigned char *)memchr(state->x.next, '\n', n);
539 if (eol != NULL)
540 n = (unsigned)(eol - state->x.next) + 1;
541
542 /* copy through end-of-line, or remainder if not found */
543 memcpy(buf, state->x.next, n);
544 state->x.have -= n;
545 state->x.next += n;
546 state->x.pos += n;
547 left -= n;
548 buf += n;
549 } while (left && eol == NULL);
550
551 /* return terminated string, or if nothing, end of file */
552 if (buf == str)
553 return NULL;
554 buf[0] = 0;
555 return str;
556}
local int gz_fetch(gz_statep state)
Definition gzread.c:208
local int gz_skip(gz_statep state, z_off64_t len)
Definition gzread.c:236

◆ gzoffset()

ZEXTERN z_off_t ZEXPORT gzoffset ( gzFile file)

Definition at line 464 of file gzlib.c.

464 {
465 z_off64_t ret;
466
467 ret = gzoffset64(file);
468 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
469}
z_off64_t ZEXPORT gzoffset64(gzFile file)
Definition gzlib.c:443

◆ gzopen()

ZEXTERN gzFile ZEXPORT gzopen ( const char * path,
const char * mode )

Definition at line 260 of file gzlib.c.

260 {
261 return gz_open(path, -1, mode);
262}

◆ gzprintf()

ZEXTERN int ZEXPORTVA gzprintf ( gzFile file,
const char * format,
... )

◆ gzputc()

ZEXTERN int ZEXPORT gzputc ( gzFile file,
int c )

Definition at line 287 of file gzwrite.c.

287 {
288 unsigned have;
289 unsigned char buf[1];
290 gz_statep state;
291 z_streamp strm;
292
293 /* get internal structure */
294 if (file == NULL)
295 return -1;
296 state = (gz_statep)file;
297 strm = &(state->strm);
298
299 /* check that we're writing and that there's no error */
300 if (state->mode != GZ_WRITE || state->err != Z_OK)
301 return -1;
302
303 /* check for seek request */
304 if (state->seek) {
305 state->seek = 0;
306 if (gz_zero(state, state->skip) == -1)
307 return -1;
308 }
309
310 /* try writing to input buffer for speed (state->size == 0 if buffer not
311 initialized) */
312 if (state->size) {
313 if (strm->avail_in == 0)
314 strm->next_in = state->in;
315 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
316 if (have < state->size) {
317 state->in[have] = (unsigned char)c;
318 strm->avail_in++;
319 state->x.pos++;
320 return c & 0xff;
321 }
322 }
323
324 /* no room in buffer or not initialized, use gz_write() */
325 buf[0] = (unsigned char)c;
326 if (gz_write(state, buf, 1) != 1)
327 return -1;
328 return c & 0xff;
329}
z_stream FAR * z_streamp
Definition zlib.h:108

◆ gzputs()

ZEXTERN int ZEXPORT gzputs ( gzFile file,
const char * s )

Definition at line 332 of file gzwrite.c.

332 {
333 z_size_t len, put;
334 gz_statep state;
335
336 /* get internal structure */
337 if (file == NULL)
338 return -1;
339 state = (gz_statep)file;
340
341 /* check that we're writing and that there's no error */
342 if (state->mode != GZ_WRITE || state->err != Z_OK)
343 return -1;
344
345 /* write string */
346 len = strlen(s);
347 if ((int)len < 0 || (unsigned)len != len) {
348 gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
349 return -1;
350 }
351 put = gz_write(state, s, len);
352 return put < len ? -1 : (int)len;
353}

◆ gzread()

ZEXTERN int ZEXPORT gzread ( gzFile file,
voidp buf,
unsigned len )

Definition at line 345 of file gzread.c.

345 {
346 gz_statep state;
347
348 /* get internal structure */
349 if (file == NULL)
350 return -1;
351 state = (gz_statep)file;
352
353 /* check that we're reading and that there's no (serious) error */
354 if (state->mode != GZ_READ ||
355 (state->err != Z_OK && state->err != Z_BUF_ERROR))
356 return -1;
357
358 /* since an int is returned, make sure len fits in one, otherwise return
359 with an error (this avoids a flaw in the interface) */
360 if ((int)len < 0) {
361 gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
362 return -1;
363 }
364
365 /* read len or fewer bytes to buf */
366 len = (unsigned)gz_read(state, buf, len);
367
368 /* check for an error */
369 if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
370 return -1;
371
372 /* return the number of bytes read (this is assured to fit in an int) */
373 return (int)len;
374}

◆ gzrewind()

ZEXTERN int ZEXPORT gzrewind ( gzFile file)

Definition at line 318 of file gzlib.c.

318 {
319 gz_statep state;
320
321 /* get internal structure */
322 if (file == NULL)
323 return -1;
324 state = (gz_statep)file;
325
326 /* check that we're reading and that there's no error */
327 if (state->mode != GZ_READ ||
328 (state->err != Z_OK && state->err != Z_BUF_ERROR))
329 return -1;
330
331 /* back up and start over */
332 if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
333 return -1;
334 gz_reset(state);
335 return 0;
336}
#define LSEEK
Definition gzlib.c:14
local void gz_reset(gz_statep state)
Definition gzlib.c:69

Referenced by gzseek64().

◆ gzseek()

ZEXTERN z_off_t ZEXPORT gzseek ( gzFile file,
z_off_t offset,
int whence )

Definition at line 412 of file gzlib.c.

412 {
413 z_off64_t ret;
414
415 ret = gzseek64(file, (z_off64_t)offset, whence);
416 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
417}
G4ThreadLocal T * G4GeomSplitter< T >::offset
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
Definition gzlib.c:339

◆ gzsetparams()

ZEXTERN int ZEXPORT gzsetparams ( gzFile file,
int level,
int strategy )

Definition at line 557 of file gzwrite.c.

557 {
558 gz_statep state;
559 z_streamp strm;
560
561 /* get internal structure */
562 if (file == NULL)
563 return Z_STREAM_ERROR;
564 state = (gz_statep)file;
565 strm = &(state->strm);
566
567 /* check that we're writing and that there's no error */
568 if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
569 return Z_STREAM_ERROR;
570
571 /* if no change is requested, then do nothing */
572 if (level == state->level && strategy == state->strategy)
573 return Z_OK;
574
575 /* check for seek request */
576 if (state->seek) {
577 state->seek = 0;
578 if (gz_zero(state, state->skip) == -1)
579 return state->err;
580 }
581
582 /* change compression parameters for subsequent input */
583 if (state->size) {
584 /* flush previous input with previous parameters before changing */
585 if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
586 return state->err;
587 deflateParams(strm, level, strategy);
588 }
589 state->level = level;
590 state->strategy = strategy;
591 return Z_OK;
592}
ZEXTERN int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
Definition deflate.c:756

◆ gztell()

ZEXTERN z_off_t ZEXPORT gztell ( gzFile file)

Definition at line 435 of file gzlib.c.

435 {
436 z_off64_t ret;
437
438 ret = gztell64(file);
439 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
440}
z_off64_t ZEXPORT gztell64(gzFile file)
Definition gzlib.c:420

◆ gzungetc()

ZEXTERN int ZEXPORT gzungetc ( int c,
gzFile file )

Definition at line 438 of file gzread.c.

438 {
439 gz_statep state;
440
441 /* get internal structure */
442 if (file == NULL)
443 return -1;
444 state = (gz_statep)file;
445
446 /* in case this was just opened, set up the input buffer */
447 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
448 (void)gz_look(state);
449
450 /* check that we're reading and that there's no (serious) error */
451 if (state->mode != GZ_READ ||
452 (state->err != Z_OK && state->err != Z_BUF_ERROR))
453 return -1;
454
455 /* process a skip request */
456 if (state->seek) {
457 state->seek = 0;
458 if (gz_skip(state, state->skip) == -1)
459 return -1;
460 }
461
462 /* can't push EOF */
463 if (c < 0)
464 return -1;
465
466 /* if output buffer empty, put byte at end (allows more pushing) */
467 if (state->x.have == 0) {
468 state->x.have = 1;
469 state->x.next = state->out + (state->size << 1) - 1;
470 state->x.next[0] = (unsigned char)c;
471 state->x.pos--;
472 state->past = 0;
473 return c;
474 }
475
476 /* if no room, give up (must have already done a gzungetc()) */
477 if (state->x.have == (state->size << 1)) {
478 gz_error(state, Z_DATA_ERROR, "out of room to push characters");
479 return -1;
480 }
481
482 /* slide output data if needed and insert byte before existing data */
483 if (state->x.next == state->out) {
484 unsigned char *src = state->out + state->x.have;
485 unsigned char *dest = state->out + (state->size << 1);
486 while (src > state->out)
487 *--dest = *--src;
488 state->x.next = dest;
489 }
490 state->x.have++;
491 state->x.next--;
492 state->x.next[0] = (unsigned char)c;
493 state->x.pos--;
494 state->past = 0;
495 return c;
496}

◆ gzwrite()

ZEXTERN int ZEXPORT gzwrite ( gzFile file,
voidpc buf,
unsigned len )

Definition at line 237 of file gzwrite.c.

237 {
238 gz_statep state;
239
240 /* get internal structure */
241 if (file == NULL)
242 return 0;
243 state = (gz_statep)file;
244
245 /* check that we're writing and that there's no error */
246 if (state->mode != GZ_WRITE || state->err != Z_OK)
247 return 0;
248
249 /* since an int is returned, make sure len fits in one, otherwise return
250 with an error (this avoids a flaw in the interface) */
251 if ((int)len < 0) {
252 gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
253 return 0;
254 }
255
256 /* write len bytes from buf (the return value will fit in an int) */
257 return (int)gz_write(state, buf, len);
258}

◆ inflate()

ZEXTERN int ZEXPORT inflate ( z_streamp strm,
int flush )

Definition at line 590 of file inflate.c.

590 {
591 struct inflate_state FAR *state;
592 z_const unsigned char FAR *next; /* next input */
593 unsigned char FAR *put; /* next output */
594 unsigned have, left; /* available input and output */
595 unsigned long hold; /* bit buffer */
596 unsigned bits; /* bits in bit buffer */
597 unsigned in, out; /* save starting available input and output */
598 unsigned copy; /* number of stored or match bytes to copy */
599 unsigned char FAR *from; /* where to copy match bytes from */
600 code here; /* current decoding table entry */
601 code last; /* parent table entry */
602 unsigned len; /* length to copy for repeats, bits to drop */
603 int ret; /* return code */
604#ifdef GUNZIP
605 unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
606#endif
607 static const unsigned short order[19] = /* permutation of code lengths */
608 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
609
610 if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
611 (strm->next_in == Z_NULL && strm->avail_in != 0))
612 return Z_STREAM_ERROR;
613
614 state = (struct inflate_state FAR *)strm->state;
615 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
616 LOAD();
617 in = have;
618 out = left;
619 ret = Z_OK;
620 for (;;)
621 switch (state->mode) {
622 case HEAD:
623 if (state->wrap == 0) {
624 state->mode = TYPEDO;
625 break;
626 }
627 NEEDBITS(16);
628#ifdef GUNZIP
629 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
630 if (state->wbits == 0)
631 state->wbits = 15;
632 state->check = crc32(0L, Z_NULL, 0);
633 CRC2(state->check, hold);
634 INITBITS();
635 state->mode = FLAGS;
636 break;
637 }
638 if (state->head != Z_NULL)
639 state->head->done = -1;
640 if (!(state->wrap & 1) || /* check if zlib header allowed */
641#else
642 if (
643#endif
644 ((BITS(8) << 8) + (hold >> 8)) % 31) {
645 strm->msg = (char *)"incorrect header check";
646 state->mode = BAD;
647 break;
648 }
649 if (BITS(4) != Z_DEFLATED) {
650 strm->msg = (char *)"unknown compression method";
651 state->mode = BAD;
652 break;
653 }
654 DROPBITS(4);
655 len = BITS(4) + 8;
656 if (state->wbits == 0)
657 state->wbits = len;
658 if (len > 15 || len > state->wbits) {
659 strm->msg = (char *)"invalid window size";
660 state->mode = BAD;
661 break;
662 }
663 state->dmax = 1U << len;
664 state->flags = 0; /* indicate zlib header */
665 Tracev((stderr, "inflate: zlib header ok\n"));
666 strm->adler = state->check = adler32(0L, Z_NULL, 0);
667 state->mode = hold & 0x200 ? DICTID : TYPE;
668 INITBITS();
669 break;
670#ifdef GUNZIP
671 case FLAGS:
672 NEEDBITS(16);
673 state->flags = (int)(hold);
674 if ((state->flags & 0xff) != Z_DEFLATED) {
675 strm->msg = (char *)"unknown compression method";
676 state->mode = BAD;
677 break;
678 }
679 if (state->flags & 0xe000) {
680 strm->msg = (char *)"unknown header flags set";
681 state->mode = BAD;
682 break;
683 }
684 if (state->head != Z_NULL)
685 state->head->text = (int)((hold >> 8) & 1);
686 if ((state->flags & 0x0200) && (state->wrap & 4))
687 CRC2(state->check, hold);
688 INITBITS();
689 state->mode = TIME;
690 /* fallthrough */
691 case TIME:
692 NEEDBITS(32);
693 if (state->head != Z_NULL)
694 state->head->time = hold;
695 if ((state->flags & 0x0200) && (state->wrap & 4))
696 CRC4(state->check, hold);
697 INITBITS();
698 state->mode = OS;
699 /* fallthrough */
700 case OS:
701 NEEDBITS(16);
702 if (state->head != Z_NULL) {
703 state->head->xflags = (int)(hold & 0xff);
704 state->head->os = (int)(hold >> 8);
705 }
706 if ((state->flags & 0x0200) && (state->wrap & 4))
707 CRC2(state->check, hold);
708 INITBITS();
709 state->mode = EXLEN;
710 /* fallthrough */
711 case EXLEN:
712 if (state->flags & 0x0400) {
713 NEEDBITS(16);
714 state->length = (unsigned)(hold);
715 if (state->head != Z_NULL)
716 state->head->extra_len = (unsigned)hold;
717 if ((state->flags & 0x0200) && (state->wrap & 4))
718 CRC2(state->check, hold);
719 INITBITS();
720 }
721 else if (state->head != Z_NULL)
722 state->head->extra = Z_NULL;
723 state->mode = EXTRA;
724 /* fallthrough */
725 case EXTRA:
726 if (state->flags & 0x0400) {
727 copy = state->length;
728 if (copy > have) copy = have;
729 if (copy) {
730 if (state->head != Z_NULL &&
731 state->head->extra != Z_NULL &&
732 (len = state->head->extra_len - state->length) <
733 state->head->extra_max) {
734 zmemcpy(state->head->extra + len, next,
735 len + copy > state->head->extra_max ?
736 state->head->extra_max - len : copy);
737 }
738 if ((state->flags & 0x0200) && (state->wrap & 4))
739 state->check = crc32(state->check, next, copy);
740 have -= copy;
741 next += copy;
742 state->length -= copy;
743 }
744 if (state->length) goto inf_leave;
745 }
746 state->length = 0;
747 state->mode = NAME;
748 /* fallthrough */
749 case NAME:
750 if (state->flags & 0x0800) {
751 if (have == 0) goto inf_leave;
752 copy = 0;
753 do {
754 len = (unsigned)(next[copy++]);
755 if (state->head != Z_NULL &&
756 state->head->name != Z_NULL &&
757 state->length < state->head->name_max)
758 state->head->name[state->length++] = (Bytef)len;
759 } while (len && copy < have);
760 if ((state->flags & 0x0200) && (state->wrap & 4))
761 state->check = crc32(state->check, next, copy);
762 have -= copy;
763 next += copy;
764 if (len) goto inf_leave;
765 }
766 else if (state->head != Z_NULL)
767 state->head->name = Z_NULL;
768 state->length = 0;
769 state->mode = COMMENT;
770 /* fallthrough */
771 case COMMENT:
772 if (state->flags & 0x1000) {
773 if (have == 0) goto inf_leave;
774 copy = 0;
775 do {
776 len = (unsigned)(next[copy++]);
777 if (state->head != Z_NULL &&
778 state->head->comment != Z_NULL &&
779 state->length < state->head->comm_max)
780 state->head->comment[state->length++] = (Bytef)len;
781 } while (len && copy < have);
782 if ((state->flags & 0x0200) && (state->wrap & 4))
783 state->check = crc32(state->check, next, copy);
784 have -= copy;
785 next += copy;
786 if (len) goto inf_leave;
787 }
788 else if (state->head != Z_NULL)
789 state->head->comment = Z_NULL;
790 state->mode = HCRC;
791 /* fallthrough */
792 case HCRC:
793 if (state->flags & 0x0200) {
794 NEEDBITS(16);
795 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
796 strm->msg = (char *)"header crc mismatch";
797 state->mode = BAD;
798 break;
799 }
800 INITBITS();
801 }
802 if (state->head != Z_NULL) {
803 state->head->hcrc = (int)((state->flags >> 9) & 1);
804 state->head->done = 1;
805 }
806 strm->adler = state->check = crc32(0L, Z_NULL, 0);
807 state->mode = TYPE;
808 break;
809#endif
810 case DICTID:
811 NEEDBITS(32);
812 strm->adler = state->check = ZSWAP32(hold);
813 INITBITS();
814 state->mode = DICT;
815 /* fallthrough */
816 case DICT:
817 if (state->havedict == 0) {
818 RESTORE();
819 return Z_NEED_DICT;
820 }
821 strm->adler = state->check = adler32(0L, Z_NULL, 0);
822 state->mode = TYPE;
823 /* fallthrough */
824 case TYPE:
825 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
826 /* fallthrough */
827 case TYPEDO:
828 if (state->last) {
829 BYTEBITS();
830 state->mode = CHECK;
831 break;
832 }
833 NEEDBITS(3);
834 state->last = BITS(1);
835 DROPBITS(1);
836 switch (BITS(2)) {
837 case 0: /* stored block */
838 Tracev((stderr, "inflate: stored block%s\n",
839 state->last ? " (last)" : ""));
840 state->mode = STORED;
841 break;
842 case 1: /* fixed block */
843 fixedtables(state);
844 Tracev((stderr, "inflate: fixed codes block%s\n",
845 state->last ? " (last)" : ""));
846 state->mode = LEN_; /* decode codes */
847 if (flush == Z_TREES) {
848 DROPBITS(2);
849 goto inf_leave;
850 }
851 break;
852 case 2: /* dynamic block */
853 Tracev((stderr, "inflate: dynamic codes block%s\n",
854 state->last ? " (last)" : ""));
855 state->mode = TABLE;
856 break;
857 case 3:
858 strm->msg = (char *)"invalid block type";
859 state->mode = BAD;
860 }
861 DROPBITS(2);
862 break;
863 case STORED:
864 BYTEBITS(); /* go to byte boundary */
865 NEEDBITS(32);
866 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
867 strm->msg = (char *)"invalid stored block lengths";
868 state->mode = BAD;
869 break;
870 }
871 state->length = (unsigned)hold & 0xffff;
872 Tracev((stderr, "inflate: stored length %u\n",
873 state->length));
874 INITBITS();
875 state->mode = COPY_;
876 if (flush == Z_TREES) goto inf_leave;
877 /* fallthrough */
878 case COPY_:
879 state->mode = COPY;
880 /* fallthrough */
881 case COPY:
882 copy = state->length;
883 if (copy) {
884 if (copy > have) copy = have;
885 if (copy > left) copy = left;
886 if (copy == 0) goto inf_leave;
887 zmemcpy(put, next, copy);
888 have -= copy;
889 next += copy;
890 left -= copy;
891 put += copy;
892 state->length -= copy;
893 break;
894 }
895 Tracev((stderr, "inflate: stored end\n"));
896 state->mode = TYPE;
897 break;
898 case TABLE:
899 NEEDBITS(14);
900 state->nlen = BITS(5) + 257;
901 DROPBITS(5);
902 state->ndist = BITS(5) + 1;
903 DROPBITS(5);
904 state->ncode = BITS(4) + 4;
905 DROPBITS(4);
906#ifndef PKZIP_BUG_WORKAROUND
907 if (state->nlen > 286 || state->ndist > 30) {
908 strm->msg = (char *)"too many length or distance symbols";
909 state->mode = BAD;
910 break;
911 }
912#endif
913 Tracev((stderr, "inflate: table sizes ok\n"));
914 state->have = 0;
915 state->mode = LENLENS;
916 /* fallthrough */
917 case LENLENS:
918 while (state->have < state->ncode) {
919 NEEDBITS(3);
920 state->lens[order[state->have++]] = (unsigned short)BITS(3);
921 DROPBITS(3);
922 }
923 while (state->have < 19)
924 state->lens[order[state->have++]] = 0;
925 state->next = state->codes;
926 state->lencode = (const code FAR *)(state->next);
927 state->lenbits = 7;
928 ret = inflate_table(CODES, state->lens, 19, &(state->next),
929 &(state->lenbits), state->work);
930 if (ret) {
931 strm->msg = (char *)"invalid code lengths set";
932 state->mode = BAD;
933 break;
934 }
935 Tracev((stderr, "inflate: code lengths ok\n"));
936 state->have = 0;
937 state->mode = CODELENS;
938 /* fallthrough */
939 case CODELENS:
940 while (state->have < state->nlen + state->ndist) {
941 for (;;) {
942 here = state->lencode[BITS(state->lenbits)];
943 if ((unsigned)(here.bits) <= bits) break;
944 PULLBYTE();
945 }
946 if (here.val < 16) {
947 DROPBITS(here.bits);
948 state->lens[state->have++] = here.val;
949 }
950 else {
951 if (here.val == 16) {
952 NEEDBITS(here.bits + 2);
953 DROPBITS(here.bits);
954 if (state->have == 0) {
955 strm->msg = (char *)"invalid bit length repeat";
956 state->mode = BAD;
957 break;
958 }
959 len = state->lens[state->have - 1];
960 copy = 3 + BITS(2);
961 DROPBITS(2);
962 }
963 else if (here.val == 17) {
964 NEEDBITS(here.bits + 3);
965 DROPBITS(here.bits);
966 len = 0;
967 copy = 3 + BITS(3);
968 DROPBITS(3);
969 }
970 else {
971 NEEDBITS(here.bits + 7);
972 DROPBITS(here.bits);
973 len = 0;
974 copy = 11 + BITS(7);
975 DROPBITS(7);
976 }
977 if (state->have + copy > state->nlen + state->ndist) {
978 strm->msg = (char *)"invalid bit length repeat";
979 state->mode = BAD;
980 break;
981 }
982 while (copy--)
983 state->lens[state->have++] = (unsigned short)len;
984 }
985 }
986
987 /* handle error breaks in while */
988 if (state->mode == BAD) break;
989
990 /* check for end-of-block code (better have one) */
991 if (state->lens[256] == 0) {
992 strm->msg = (char *)"invalid code -- missing end-of-block";
993 state->mode = BAD;
994 break;
995 }
996
997 /* build code tables -- note: do not change the lenbits or distbits
998 values here (9 and 6) without reading the comments in inftrees.h
999 concerning the ENOUGH constants, which depend on those values */
1000 state->next = state->codes;
1001 state->lencode = (const code FAR *)(state->next);
1002 state->lenbits = 9;
1003 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1004 &(state->lenbits), state->work);
1005 if (ret) {
1006 strm->msg = (char *)"invalid literal/lengths set";
1007 state->mode = BAD;
1008 break;
1009 }
1010 state->distcode = (const code FAR *)(state->next);
1011 state->distbits = 6;
1012 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1013 &(state->next), &(state->distbits), state->work);
1014 if (ret) {
1015 strm->msg = (char *)"invalid distances set";
1016 state->mode = BAD;
1017 break;
1018 }
1019 Tracev((stderr, "inflate: codes ok\n"));
1020 state->mode = LEN_;
1021 if (flush == Z_TREES) goto inf_leave;
1022 /* fallthrough */
1023 case LEN_:
1024 state->mode = LEN;
1025 /* fallthrough */
1026 case LEN:
1027 if (have >= 6 && left >= 258) {
1028 RESTORE();
1029 inflate_fast(strm, out);
1030 LOAD();
1031 if (state->mode == TYPE)
1032 state->back = -1;
1033 break;
1034 }
1035 state->back = 0;
1036 for (;;) {
1037 here = state->lencode[BITS(state->lenbits)];
1038 if ((unsigned)(here.bits) <= bits) break;
1039 PULLBYTE();
1040 }
1041 if (here.op && (here.op & 0xf0) == 0) {
1042 last = here;
1043 for (;;) {
1044 here = state->lencode[last.val +
1045 (BITS(last.bits + last.op) >> last.bits)];
1046 if ((unsigned)(last.bits + here.bits) <= bits) break;
1047 PULLBYTE();
1048 }
1049 DROPBITS(last.bits);
1050 state->back += last.bits;
1051 }
1052 DROPBITS(here.bits);
1053 state->back += here.bits;
1054 state->length = (unsigned)here.val;
1055 if ((int)(here.op) == 0) {
1056 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1057 "inflate: literal '%c'\n" :
1058 "inflate: literal 0x%02x\n", here.val));
1059 state->mode = LIT;
1060 break;
1061 }
1062 if (here.op & 32) {
1063 Tracevv((stderr, "inflate: end of block\n"));
1064 state->back = -1;
1065 state->mode = TYPE;
1066 break;
1067 }
1068 if (here.op & 64) {
1069 strm->msg = (char *)"invalid literal/length code";
1070 state->mode = BAD;
1071 break;
1072 }
1073 state->extra = (unsigned)(here.op) & 15;
1074 state->mode = LENEXT;
1075 /* fallthrough */
1076 case LENEXT:
1077 if (state->extra) {
1078 NEEDBITS(state->extra);
1079 state->length += BITS(state->extra);
1080 DROPBITS(state->extra);
1081 state->back += state->extra;
1082 }
1083 Tracevv((stderr, "inflate: length %u\n", state->length));
1084 state->was = state->length;
1085 state->mode = DIST;
1086 /* fallthrough */
1087 case DIST:
1088 for (;;) {
1089 here = state->distcode[BITS(state->distbits)];
1090 if ((unsigned)(here.bits) <= bits) break;
1091 PULLBYTE();
1092 }
1093 if ((here.op & 0xf0) == 0) {
1094 last = here;
1095 for (;;) {
1096 here = state->distcode[last.val +
1097 (BITS(last.bits + last.op) >> last.bits)];
1098 if ((unsigned)(last.bits + here.bits) <= bits) break;
1099 PULLBYTE();
1100 }
1101 DROPBITS(last.bits);
1102 state->back += last.bits;
1103 }
1104 DROPBITS(here.bits);
1105 state->back += here.bits;
1106 if (here.op & 64) {
1107 strm->msg = (char *)"invalid distance code";
1108 state->mode = BAD;
1109 break;
1110 }
1111 state->offset = (unsigned)here.val;
1112 state->extra = (unsigned)(here.op) & 15;
1113 state->mode = DISTEXT;
1114 /* fallthrough */
1115 case DISTEXT:
1116 if (state->extra) {
1117 NEEDBITS(state->extra);
1118 state->offset += BITS(state->extra);
1119 DROPBITS(state->extra);
1120 state->back += state->extra;
1121 }
1122#ifdef INFLATE_STRICT
1123 if (state->offset > state->dmax) {
1124 strm->msg = (char *)"invalid distance too far back";
1125 state->mode = BAD;
1126 break;
1127 }
1128#endif
1129 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1130 state->mode = MATCH;
1131 /* fallthrough */
1132 case MATCH:
1133 if (left == 0) goto inf_leave;
1134 copy = out - left;
1135 if (state->offset > copy) { /* copy from window */
1136 copy = state->offset - copy;
1137 if (copy > state->whave) {
1138 if (state->sane) {
1139 strm->msg = (char *)"invalid distance too far back";
1140 state->mode = BAD;
1141 break;
1142 }
1143#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1144 Trace((stderr, "inflate.c too far\n"));
1145 copy -= state->whave;
1146 if (copy > state->length) copy = state->length;
1147 if (copy > left) copy = left;
1148 left -= copy;
1149 state->length -= copy;
1150 do {
1151 *put++ = 0;
1152 } while (--copy);
1153 if (state->length == 0) state->mode = LEN;
1154 break;
1155#endif
1156 }
1157 if (copy > state->wnext) {
1158 copy -= state->wnext;
1159 from = state->window + (state->wsize - copy);
1160 }
1161 else
1162 from = state->window + (state->wnext - copy);
1163 if (copy > state->length) copy = state->length;
1164 }
1165 else { /* copy from output */
1166 from = put - state->offset;
1167 copy = state->length;
1168 }
1169 if (copy > left) copy = left;
1170 left -= copy;
1171 state->length -= copy;
1172 do {
1173 *put++ = *from++;
1174 } while (--copy);
1175 if (state->length == 0) state->mode = LEN;
1176 break;
1177 case LIT:
1178 if (left == 0) goto inf_leave;
1179 *put++ = (unsigned char)(state->length);
1180 left--;
1181 state->mode = LEN;
1182 break;
1183 case CHECK:
1184 if (state->wrap) {
1185 NEEDBITS(32);
1186 out -= left;
1187 strm->total_out += out;
1188 state->total += out;
1189 if ((state->wrap & 4) && out)
1190 strm->adler = state->check =
1191 UPDATE_CHECK(state->check, put - out, out);
1192 out = left;
1193 if ((state->wrap & 4) && (
1194#ifdef GUNZIP
1195 state->flags ? hold :
1196#endif
1197 ZSWAP32(hold)) != state->check) {
1198 strm->msg = (char *)"incorrect data check";
1199 state->mode = BAD;
1200 break;
1201 }
1202 INITBITS();
1203 Tracev((stderr, "inflate: check matches trailer\n"));
1204 }
1205#ifdef GUNZIP
1206 state->mode = LENGTH;
1207 /* fallthrough */
1208 case LENGTH:
1209 if (state->wrap && state->flags) {
1210 NEEDBITS(32);
1211 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1212 strm->msg = (char *)"incorrect length check";
1213 state->mode = BAD;
1214 break;
1215 }
1216 INITBITS();
1217 Tracev((stderr, "inflate: length matches trailer\n"));
1218 }
1219#endif
1220 state->mode = DONE;
1221 /* fallthrough */
1222 case DONE:
1223 ret = Z_STREAM_END;
1224 goto inf_leave;
1225 case BAD:
1226 ret = Z_DATA_ERROR;
1227 goto inf_leave;
1228 case MEM:
1229 return Z_MEM_ERROR;
1230 case SYNC:
1231 /* fallthrough */
1232 default:
1233 return Z_STREAM_ERROR;
1234 }
1235
1236 /*
1237 Return from inflate(), updating the total counts and the check value.
1238 If there was no progress during the inflate() call, return a buffer
1239 error. Call updatewindow() to create and/or update the window state.
1240 Note: a memory error from inflate() is non-recoverable.
1241 */
1242 inf_leave:
1243 RESTORE();
1244 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1245 (state->mode < CHECK || flush != Z_FINISH)))
1246 if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1247 state->mode = MEM;
1248 return Z_MEM_ERROR;
1249 }
1250 in -= strm->avail_in;
1251 out -= strm->avail_out;
1252 strm->total_in += in;
1253 strm->total_out += out;
1254 state->total += out;
1255 if ((state->wrap & 4) && out)
1256 strm->adler = state->check =
1257 UPDATE_CHECK(state->check, strm->next_out - out, out);
1258 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1259 (state->mode == TYPE ? 128 : 0) +
1260 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1261 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1262 ret = Z_BUF_ERROR;
1263 return ret;
1264}
#define COPY
Definition gzguts.h:165
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
Definition inffast.c:50
#define LOAD()
Definition inflate.c:444
local int inflateStateCheck(z_streamp strm)
Definition inflate.c:94
#define INITBITS()
Definition inflate.c:466
local void fixedtables(struct inflate_state FAR *state)
Definition inflate.c:252
#define BITS(n)
Definition inflate.c:491
#define DROPBITS(n)
Definition inflate.c:495
#define BYTEBITS()
Definition inflate.c:502
#define NEEDBITS(n)
Definition inflate.c:484
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
Definition inflate.c:368
#define PULLBYTE()
Definition inflate.c:474
#define UPDATE_CHECK(check, buf, len)
Definition inflate.c:421
#define RESTORE()
Definition inflate.c:455
@ HEAD
Definition inflate.h:21
@ MATCH
Definition inflate.h:45
@ DICT
Definition inflate.h:31
@ TABLE
Definition inflate.h:37
@ LENGTH
Definition inflate.h:48
@ FLAGS
Definition inflate.h:22
@ LIT
Definition inflate.h:46
@ SYNC
Definition inflate.h:52
@ OS
Definition inflate.h:24
@ EXLEN
Definition inflate.h:25
@ MEM
Definition inflate.h:51
@ NAME
Definition inflate.h:27
@ STORED
Definition inflate.h:34
@ CODELENS
Definition inflate.h:39
@ DICTID
Definition inflate.h:30
@ DONE
Definition inflate.h:49
@ TYPEDO
Definition inflate.h:33
@ COMMENT
Definition inflate.h:28
@ LENLENS
Definition inflate.h:38
@ TYPE
Definition inflate.h:32
@ LEN_
Definition inflate.h:40
@ COPY_
Definition inflate.h:35
@ DIST
Definition inflate.h:43
@ LENEXT
Definition inflate.h:42
@ HCRC
Definition inflate.h:29
@ TIME
Definition inflate.h:23
@ CHECK
Definition inflate.h:47
@ DISTEXT
Definition inflate.h:44
@ BAD
Definition inflate.h:50
@ LEN
Definition inflate.h:41
@ EXTRA
Definition inflate.h:26
#define GUNZIP
Definition inflate.h:16
@ CODES
Definition inftrees.h:55
@ LENS
Definition inftrees.h:56
@ DISTS
Definition inftrees.h:57
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
Definition inftrees.c:32
unsigned char op
Definition inftrees.h:25
unsigned char bits
Definition inftrees.h:26
unsigned short val
Definition inftrees.h:27
unsigned was
Definition inflate.h:125
code const FAR * distcode
Definition inflate.h:111
unsigned wnext
Definition inflate.h:99
unsigned lenbits
Definition inflate.h:112
unsigned ndist
Definition inflate.h:117
code const FAR * lencode
Definition inflate.h:110
unsigned nlen
Definition inflate.h:116
unsigned have
Definition inflate.h:118
unsigned length
Definition inflate.h:105
unsigned long hold
Definition inflate.h:102
unsigned extra
Definition inflate.h:108
unsigned ncode
Definition inflate.h:115
z_streamp strm
Definition inflate.h:83
unsigned whave
Definition inflate.h:98
unsigned wbits
Definition inflate.h:96
unsigned short work[288]
Definition inflate.h:121
code FAR * next
Definition inflate.h:119
unsigned distbits
Definition inflate.h:113
inflate_mode mode
Definition inflate.h:84
unsigned char FAR * window
Definition inflate.h:100
unsigned short lens[320]
Definition inflate.h:120
gz_headerp head
Definition inflate.h:94
unsigned bits
Definition inflate.h:103
unsigned wsize
Definition inflate.h:97
unsigned dmax
Definition inflate.h:91
unsigned long check
Definition inflate.h:92
unsigned offset
Definition inflate.h:106
code codes[ENOUGH]
Definition inflate.h:122
unsigned long total
Definition inflate.h:93
#define Z_TREES
Definition zlib.h:174
#define Z_NEED_DICT
Definition zlib.h:179
#define Tracev(x)
Definition zutil.h:229
#define Trace(x)
Definition zutil.h:228
#define ZSWAP32(q)
Definition zutil.h:247
#define Tracevv(x)
Definition zutil.h:230

Referenced by gz_decomp(), and uncompress2().

◆ inflateBack()

ZEXTERN int ZEXPORT inflateBack ( z_streamp strm,
in_func in,
void FAR * in_desc,
out_func out,
void FAR * out_desc )

Definition at line 242 of file infback.c.

243 {
244 struct inflate_state FAR *state;
245 z_const unsigned char FAR *next; /* next input */
246 unsigned char FAR *put; /* next output */
247 unsigned have, left; /* available input and output */
248 unsigned long hold; /* bit buffer */
249 unsigned bits; /* bits in bit buffer */
250 unsigned copy; /* number of stored or match bytes to copy */
251 unsigned char FAR *from; /* where to copy match bytes from */
252 code here; /* current decoding table entry */
253 code last; /* parent table entry */
254 unsigned len; /* length to copy for repeats, bits to drop */
255 int ret; /* return code */
256 static const unsigned short order[19] = /* permutation of code lengths */
257 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
258
259 /* Check that the strm exists and that the state was initialized */
260 if (strm == Z_NULL || strm->state == Z_NULL)
261 return Z_STREAM_ERROR;
262 state = (struct inflate_state FAR *)strm->state;
263
264 /* Reset the state */
265 strm->msg = Z_NULL;
266 state->mode = TYPE;
267 state->last = 0;
268 state->whave = 0;
269 next = strm->next_in;
270 have = next != Z_NULL ? strm->avail_in : 0;
271 hold = 0;
272 bits = 0;
273 put = state->window;
274 left = state->wsize;
275
276 /* Inflate until end of block marked as last */
277 for (;;)
278 switch (state->mode) {
279 case TYPE:
280 /* determine and dispatch block type */
281 if (state->last) {
282 BYTEBITS();
283 state->mode = DONE;
284 break;
285 }
286 NEEDBITS(3);
287 state->last = BITS(1);
288 DROPBITS(1);
289 switch (BITS(2)) {
290 case 0: /* stored block */
291 Tracev((stderr, "inflate: stored block%s\n",
292 state->last ? " (last)" : ""));
293 state->mode = STORED;
294 break;
295 case 1: /* fixed block */
296 fixedtables(state);
297 Tracev((stderr, "inflate: fixed codes block%s\n",
298 state->last ? " (last)" : ""));
299 state->mode = LEN; /* decode codes */
300 break;
301 case 2: /* dynamic block */
302 Tracev((stderr, "inflate: dynamic codes block%s\n",
303 state->last ? " (last)" : ""));
304 state->mode = TABLE;
305 break;
306 case 3:
307 strm->msg = (char *)"invalid block type";
308 state->mode = BAD;
309 }
310 DROPBITS(2);
311 break;
312
313 case STORED:
314 /* get and verify stored block length */
315 BYTEBITS(); /* go to byte boundary */
316 NEEDBITS(32);
317 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
318 strm->msg = (char *)"invalid stored block lengths";
319 state->mode = BAD;
320 break;
321 }
322 state->length = (unsigned)hold & 0xffff;
323 Tracev((stderr, "inflate: stored length %u\n",
324 state->length));
325 INITBITS();
326
327 /* copy stored block from input to output */
328 while (state->length != 0) {
329 copy = state->length;
330 PULL();
331 ROOM();
332 if (copy > have) copy = have;
333 if (copy > left) copy = left;
334 zmemcpy(put, next, copy);
335 have -= copy;
336 next += copy;
337 left -= copy;
338 put += copy;
339 state->length -= copy;
340 }
341 Tracev((stderr, "inflate: stored end\n"));
342 state->mode = TYPE;
343 break;
344
345 case TABLE:
346 /* get dynamic table entries descriptor */
347 NEEDBITS(14);
348 state->nlen = BITS(5) + 257;
349 DROPBITS(5);
350 state->ndist = BITS(5) + 1;
351 DROPBITS(5);
352 state->ncode = BITS(4) + 4;
353 DROPBITS(4);
354#ifndef PKZIP_BUG_WORKAROUND
355 if (state->nlen > 286 || state->ndist > 30) {
356 strm->msg = (char *)"too many length or distance symbols";
357 state->mode = BAD;
358 break;
359 }
360#endif
361 Tracev((stderr, "inflate: table sizes ok\n"));
362
363 /* get code length code lengths (not a typo) */
364 state->have = 0;
365 while (state->have < state->ncode) {
366 NEEDBITS(3);
367 state->lens[order[state->have++]] = (unsigned short)BITS(3);
368 DROPBITS(3);
369 }
370 while (state->have < 19)
371 state->lens[order[state->have++]] = 0;
372 state->next = state->codes;
373 state->lencode = (code const FAR *)(state->next);
374 state->lenbits = 7;
375 ret = inflate_table(CODES, state->lens, 19, &(state->next),
376 &(state->lenbits), state->work);
377 if (ret) {
378 strm->msg = (char *)"invalid code lengths set";
379 state->mode = BAD;
380 break;
381 }
382 Tracev((stderr, "inflate: code lengths ok\n"));
383
384 /* get length and distance code code lengths */
385 state->have = 0;
386 while (state->have < state->nlen + state->ndist) {
387 for (;;) {
388 here = state->lencode[BITS(state->lenbits)];
389 if ((unsigned)(here.bits) <= bits) break;
390 PULLBYTE();
391 }
392 if (here.val < 16) {
393 DROPBITS(here.bits);
394 state->lens[state->have++] = here.val;
395 }
396 else {
397 if (here.val == 16) {
398 NEEDBITS(here.bits + 2);
399 DROPBITS(here.bits);
400 if (state->have == 0) {
401 strm->msg = (char *)"invalid bit length repeat";
402 state->mode = BAD;
403 break;
404 }
405 len = (unsigned)(state->lens[state->have - 1]);
406 copy = 3 + BITS(2);
407 DROPBITS(2);
408 }
409 else if (here.val == 17) {
410 NEEDBITS(here.bits + 3);
411 DROPBITS(here.bits);
412 len = 0;
413 copy = 3 + BITS(3);
414 DROPBITS(3);
415 }
416 else {
417 NEEDBITS(here.bits + 7);
418 DROPBITS(here.bits);
419 len = 0;
420 copy = 11 + BITS(7);
421 DROPBITS(7);
422 }
423 if (state->have + copy > state->nlen + state->ndist) {
424 strm->msg = (char *)"invalid bit length repeat";
425 state->mode = BAD;
426 break;
427 }
428 while (copy--)
429 state->lens[state->have++] = (unsigned short)len;
430 }
431 }
432
433 /* handle error breaks in while */
434 if (state->mode == BAD) break;
435
436 /* check for end-of-block code (better have one) */
437 if (state->lens[256] == 0) {
438 strm->msg = (char *)"invalid code -- missing end-of-block";
439 state->mode = BAD;
440 break;
441 }
442
443 /* build code tables -- note: do not change the lenbits or distbits
444 values here (9 and 6) without reading the comments in inftrees.h
445 concerning the ENOUGH constants, which depend on those values */
446 state->next = state->codes;
447 state->lencode = (code const FAR *)(state->next);
448 state->lenbits = 9;
449 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
450 &(state->lenbits), state->work);
451 if (ret) {
452 strm->msg = (char *)"invalid literal/lengths set";
453 state->mode = BAD;
454 break;
455 }
456 state->distcode = (code const FAR *)(state->next);
457 state->distbits = 6;
458 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
459 &(state->next), &(state->distbits), state->work);
460 if (ret) {
461 strm->msg = (char *)"invalid distances set";
462 state->mode = BAD;
463 break;
464 }
465 Tracev((stderr, "inflate: codes ok\n"));
466 state->mode = LEN;
467 /* fallthrough */
468
469 case LEN:
470 /* use inflate_fast() if we have enough input and output */
471 if (have >= 6 && left >= 258) {
472 RESTORE();
473 if (state->whave < state->wsize)
474 state->whave = state->wsize - left;
475 inflate_fast(strm, state->wsize);
476 LOAD();
477 break;
478 }
479
480 /* get a literal, length, or end-of-block code */
481 for (;;) {
482 here = state->lencode[BITS(state->lenbits)];
483 if ((unsigned)(here.bits) <= bits) break;
484 PULLBYTE();
485 }
486 if (here.op && (here.op & 0xf0) == 0) {
487 last = here;
488 for (;;) {
489 here = state->lencode[last.val +
490 (BITS(last.bits + last.op) >> last.bits)];
491 if ((unsigned)(last.bits + here.bits) <= bits) break;
492 PULLBYTE();
493 }
494 DROPBITS(last.bits);
495 }
496 DROPBITS(here.bits);
497 state->length = (unsigned)here.val;
498
499 /* process literal */
500 if (here.op == 0) {
501 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
502 "inflate: literal '%c'\n" :
503 "inflate: literal 0x%02x\n", here.val));
504 ROOM();
505 *put++ = (unsigned char)(state->length);
506 left--;
507 state->mode = LEN;
508 break;
509 }
510
511 /* process end of block */
512 if (here.op & 32) {
513 Tracevv((stderr, "inflate: end of block\n"));
514 state->mode = TYPE;
515 break;
516 }
517
518 /* invalid code */
519 if (here.op & 64) {
520 strm->msg = (char *)"invalid literal/length code";
521 state->mode = BAD;
522 break;
523 }
524
525 /* length code -- get extra bits, if any */
526 state->extra = (unsigned)(here.op) & 15;
527 if (state->extra != 0) {
528 NEEDBITS(state->extra);
529 state->length += BITS(state->extra);
530 DROPBITS(state->extra);
531 }
532 Tracevv((stderr, "inflate: length %u\n", state->length));
533
534 /* get distance code */
535 for (;;) {
536 here = state->distcode[BITS(state->distbits)];
537 if ((unsigned)(here.bits) <= bits) break;
538 PULLBYTE();
539 }
540 if ((here.op & 0xf0) == 0) {
541 last = here;
542 for (;;) {
543 here = state->distcode[last.val +
544 (BITS(last.bits + last.op) >> last.bits)];
545 if ((unsigned)(last.bits + here.bits) <= bits) break;
546 PULLBYTE();
547 }
548 DROPBITS(last.bits);
549 }
550 DROPBITS(here.bits);
551 if (here.op & 64) {
552 strm->msg = (char *)"invalid distance code";
553 state->mode = BAD;
554 break;
555 }
556 state->offset = (unsigned)here.val;
557
558 /* get distance extra bits, if any */
559 state->extra = (unsigned)(here.op) & 15;
560 if (state->extra != 0) {
561 NEEDBITS(state->extra);
562 state->offset += BITS(state->extra);
563 DROPBITS(state->extra);
564 }
565 if (state->offset > state->wsize - (state->whave < state->wsize ?
566 left : 0)) {
567 strm->msg = (char *)"invalid distance too far back";
568 state->mode = BAD;
569 break;
570 }
571 Tracevv((stderr, "inflate: distance %u\n", state->offset));
572
573 /* copy match from window to output */
574 do {
575 ROOM();
576 copy = state->wsize - state->offset;
577 if (copy < left) {
578 from = put + copy;
579 copy = left - copy;
580 }
581 else {
582 from = put - state->offset;
583 copy = left;
584 }
585 if (copy > state->length) copy = state->length;
586 state->length -= copy;
587 left -= copy;
588 do {
589 *put++ = *from++;
590 } while (--copy);
591 } while (state->length != 0);
592 break;
593
594 case DONE:
595 /* inflate stream terminated properly */
596 ret = Z_STREAM_END;
597 goto inf_leave;
598
599 case BAD:
600 ret = Z_DATA_ERROR;
601 goto inf_leave;
602
603 default:
604 /* can't happen, but makes compilers happy */
605 ret = Z_STREAM_ERROR;
606 goto inf_leave;
607 }
608
609 /* Write leftover output and return unused input */
610 inf_leave:
611 if (left < state->wsize) {
612 if (out(out_desc, state->window, state->wsize - left) &&
613 ret == Z_STREAM_END)
614 ret = Z_BUF_ERROR;
615 }
616 strm->next_in = next;
617 strm->avail_in = have;
618 return ret;
619}
#define LOAD()
Definition infback.c:120
#define PULL()
Definition infback.c:150
#define INITBITS()
Definition infback.c:142
local void fixedtables(struct inflate_state FAR *state)
Definition infback.c:76
#define BITS(n)
Definition infback.c:182
#define DROPBITS(n)
Definition infback.c:186
#define BYTEBITS()
Definition infback.c:193
#define ROOM()
Definition infback.c:202
#define NEEDBITS(n)
Definition infback.c:175
#define PULLBYTE()
Definition infback.c:164
#define RESTORE()
Definition infback.c:131

◆ inflateBackEnd()

ZEXTERN int ZEXPORT inflateBackEnd ( z_streamp strm)

Definition at line 621 of file infback.c.

621 {
622 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
623 return Z_STREAM_ERROR;
624 ZFREE(strm, strm->state);
625 strm->state = Z_NULL;
626 Tracev((stderr, "inflate: end\n"));
627 return Z_OK;
628}

◆ inflateBackInit_()

ZEXTERN int ZEXPORT inflateBackInit_ ( z_streamp strm,
int windowBits,
unsigned char FAR * window,
const char * version,
int stream_size )

Definition at line 25 of file infback.c.

27 {
28 struct inflate_state FAR *state;
29
30 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
31 stream_size != (int)(sizeof(z_stream)))
32 return Z_VERSION_ERROR;
33 if (strm == Z_NULL || window == Z_NULL ||
34 windowBits < 8 || windowBits > 15)
35 return Z_STREAM_ERROR;
36 strm->msg = Z_NULL; /* in case we return an error */
37 if (strm->zalloc == (alloc_func)0) {
38#ifdef Z_SOLO
39 return Z_STREAM_ERROR;
40#else
41 strm->zalloc = zcalloc;
42 strm->opaque = (voidpf)0;
43#endif
44 }
45 if (strm->zfree == (free_func)0)
46#ifdef Z_SOLO
47 return Z_STREAM_ERROR;
48#else
49 strm->zfree = zcfree;
50#endif
51 state = (struct inflate_state FAR *)ZALLOC(strm, 1,
52 sizeof(struct inflate_state));
53 if (state == Z_NULL) return Z_MEM_ERROR;
54 Tracev((stderr, "inflate: allocated\n"));
55 strm->state = (struct internal_state FAR *)state;
56 state->dmax = 32768U;
57 state->wbits = (uInt)windowBits;
58 state->wsize = 1U << windowBits;
59 state->window = window;
60 state->wnext = 0;
61 state->whave = 0;
62 state->sane = 1;
63 return Z_OK;
64}
Bytef * window
Definition deflate.h:123

◆ inflateCodesUsed()

ZEXTERN unsigned long ZEXPORT inflateCodesUsed ( z_streamp strm)

Definition at line 1521 of file inflate.c.

1521 {
1522 struct inflate_state FAR *state;
1523 if (inflateStateCheck(strm)) return (unsigned long)-1;
1524 state = (struct inflate_state FAR *)strm->state;
1525 return (unsigned long)(state->next - state->codes);
1526}

◆ inflateCopy()

ZEXTERN int ZEXPORT inflateCopy ( z_streamp dest,
z_streamp source )

Definition at line 1439 of file inflate.c.

1439 {
1440 struct inflate_state FAR *state;
1441 struct inflate_state FAR *copy;
1442 unsigned char FAR *window;
1443 unsigned wsize;
1444
1445 /* check input */
1446 if (inflateStateCheck(source) || dest == Z_NULL)
1447 return Z_STREAM_ERROR;
1448 state = (struct inflate_state FAR *)source->state;
1449
1450 /* allocate space */
1451 copy = (struct inflate_state FAR *)
1452 ZALLOC(source, 1, sizeof(struct inflate_state));
1453 if (copy == Z_NULL) return Z_MEM_ERROR;
1454 window = Z_NULL;
1455 if (state->window != Z_NULL) {
1456 window = (unsigned char FAR *)
1457 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1458 if (window == Z_NULL) {
1459 ZFREE(source, copy);
1460 return Z_MEM_ERROR;
1461 }
1462 }
1463
1464 /* copy state */
1465 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1466 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1467 copy->strm = dest;
1468 if (state->lencode >= state->codes &&
1469 state->lencode <= state->codes + ENOUGH - 1) {
1470 copy->lencode = copy->codes + (state->lencode - state->codes);
1471 copy->distcode = copy->codes + (state->distcode - state->codes);
1472 }
1473 copy->next = copy->codes + (state->next - state->codes);
1474 if (window != Z_NULL) {
1475 wsize = 1U << state->wbits;
1476 zmemcpy(window, state->window, wsize);
1477 }
1478 copy->window = window;
1479 dest->state = (struct internal_state FAR *)copy;
1480 return Z_OK;
1481}
#define ENOUGH
Definition inftrees.h:51

◆ inflateEnd()

ZEXTERN int ZEXPORT inflateEnd ( z_streamp strm)

Definition at line 1266 of file inflate.c.

1266 {
1267 struct inflate_state FAR *state;
1269 return Z_STREAM_ERROR;
1270 state = (struct inflate_state FAR *)strm->state;
1271 if (state->window != Z_NULL) ZFREE(strm, state->window);
1272 ZFREE(strm, strm->state);
1273 strm->state = Z_NULL;
1274 Tracev((stderr, "inflate: end\n"));
1275 return Z_OK;
1276}

Referenced by gzclose_r(), and uncompress2().

◆ inflateGetDictionary()

ZEXTERN int ZEXPORT inflateGetDictionary ( z_streamp strm,
Bytef * dictionary,
uInt * dictLength )

Definition at line 1278 of file inflate.c.

1279 {
1280 struct inflate_state FAR *state;
1281
1282 /* check state */
1284 state = (struct inflate_state FAR *)strm->state;
1285
1286 /* copy dictionary */
1287 if (state->whave && dictionary != Z_NULL) {
1288 zmemcpy(dictionary, state->window + state->wnext,
1289 state->whave - state->wnext);
1290 zmemcpy(dictionary + state->whave - state->wnext,
1291 state->window, state->wnext);
1292 }
1293 if (dictLength != Z_NULL)
1294 *dictLength = state->whave;
1295 return Z_OK;
1296}

◆ inflateGetHeader()

ZEXTERN int ZEXPORT inflateGetHeader ( z_streamp strm,
gz_headerp head )

Definition at line 1330 of file inflate.c.

1330 {
1331 struct inflate_state FAR *state;
1332
1333 /* check state */
1335 state = (struct inflate_state FAR *)strm->state;
1336 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1337
1338 /* save header structure */
1339 state->head = head;
1340 head->done = 0;
1341 return Z_OK;
1342}

◆ inflateInit2_()

ZEXTERN int ZEXPORT inflateInit2_ ( z_streamp strm,
int windowBits,
const char * version,
int stream_size )

Definition at line 178 of file inflate.c.

179 {
180 int ret;
181 struct inflate_state FAR *state;
182
183 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
184 stream_size != (int)(sizeof(z_stream)))
185 return Z_VERSION_ERROR;
186 if (strm == Z_NULL) return Z_STREAM_ERROR;
187 strm->msg = Z_NULL; /* in case we return an error */
188 if (strm->zalloc == (alloc_func)0) {
189#ifdef Z_SOLO
190 return Z_STREAM_ERROR;
191#else
192 strm->zalloc = zcalloc;
193 strm->opaque = (voidpf)0;
194#endif
195 }
196 if (strm->zfree == (free_func)0)
197#ifdef Z_SOLO
198 return Z_STREAM_ERROR;
199#else
200 strm->zfree = zcfree;
201#endif
202 state = (struct inflate_state FAR *)
203 ZALLOC(strm, 1, sizeof(struct inflate_state));
204 if (state == Z_NULL) return Z_MEM_ERROR;
205 Tracev((stderr, "inflate: allocated\n"));
206 strm->state = (struct internal_state FAR *)state;
207 state->strm = strm;
208 state->window = Z_NULL;
209 state->mode = HEAD; /* to pass state test in inflateReset2() */
210 ret = inflateReset2(strm, windowBits);
211 if (ret != Z_OK) {
212 ZFREE(strm, state);
213 strm->state = Z_NULL;
214 }
215 return ret;
216}
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
Definition inflate.c:141

Referenced by inflateInit_().

◆ inflateInit_()

ZEXTERN int ZEXPORT inflateInit_ ( z_streamp strm,
const char * version,
int stream_size )

Definition at line 218 of file inflate.c.

219 {
220 return inflateInit2_(strm, DEF_WBITS, version, stream_size);
221}
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
Definition inflate.c:178
#define DEF_WBITS
Definition zutil.h:68

◆ inflateMark()

ZEXTERN long ZEXPORT inflateMark ( z_streamp strm)

Definition at line 1510 of file inflate.c.

1510 {
1511 struct inflate_state FAR *state;
1512
1514 return -(1L << 16);
1515 state = (struct inflate_state FAR *)strm->state;
1516 return (long)(((unsigned long)((long)state->back)) << 16) +
1517 (state->mode == COPY ? state->length :
1518 (state->mode == MATCH ? state->was - state->length : 0));
1519}

◆ inflatePrime()

ZEXTERN int ZEXPORT inflatePrime ( z_streamp strm,
int bits,
int value )

Definition at line 223 of file inflate.c.

223 {
224 struct inflate_state FAR *state;
225
227 if (bits == 0)
228 return Z_OK;
229 state = (struct inflate_state FAR *)strm->state;
230 if (bits < 0) {
231 state->hold = 0;
232 state->bits = 0;
233 return Z_OK;
234 }
235 if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
236 value &= (1L << bits) - 1;
237 state->hold += (unsigned)value << state->bits;
238 state->bits += (uInt)bits;
239 return Z_OK;
240}

◆ inflateReset()

ZEXTERN int ZEXPORT inflateReset ( z_streamp strm)

Definition at line 130 of file inflate.c.

130 {
131 struct inflate_state FAR *state;
132
134 state = (struct inflate_state FAR *)strm->state;
135 state->wsize = 0;
136 state->whave = 0;
137 state->wnext = 0;
138 return inflateResetKeep(strm);
139}
int ZEXPORT inflateResetKeep(z_streamp strm)
Definition inflate.c:106

Referenced by gz_look(), inflateReset2(), and inflateSync().

◆ inflateReset2()

ZEXTERN int ZEXPORT inflateReset2 ( z_streamp strm,
int windowBits )

Definition at line 141 of file inflate.c.

141 {
142 int wrap;
143 struct inflate_state FAR *state;
144
145 /* get the state */
147 state = (struct inflate_state FAR *)strm->state;
148
149 /* extract wrap request from windowBits parameter */
150 if (windowBits < 0) {
151 if (windowBits < -15)
152 return Z_STREAM_ERROR;
153 wrap = 0;
154 windowBits = -windowBits;
155 }
156 else {
157 wrap = (windowBits >> 4) + 5;
158#ifdef GUNZIP
159 if (windowBits < 48)
160 windowBits &= 15;
161#endif
162 }
163
164 /* set number of window bits, free window if different */
165 if (windowBits && (windowBits < 8 || windowBits > 15))
166 return Z_STREAM_ERROR;
167 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
168 ZFREE(strm, state->window);
169 state->window = Z_NULL;
170 }
171
172 /* update state and reset the rest of it */
173 state->wrap = wrap;
174 state->wbits = (unsigned)windowBits;
175 return inflateReset(strm);
176}
int ZEXPORT inflateReset(z_streamp strm)
Definition inflate.c:130

Referenced by inflateInit2_().

◆ inflateResetKeep()

ZEXTERN int ZEXPORT inflateResetKeep ( z_streamp strm)

Definition at line 106 of file inflate.c.

106 {
107 struct inflate_state FAR *state;
108
110 state = (struct inflate_state FAR *)strm->state;
111 strm->total_in = strm->total_out = state->total = 0;
112 strm->msg = Z_NULL;
113 if (state->wrap) /* to support ill-conceived Java test suite */
114 strm->adler = state->wrap & 1;
115 state->mode = HEAD;
116 state->last = 0;
117 state->havedict = 0;
118 state->flags = -1;
119 state->dmax = 32768U;
120 state->head = Z_NULL;
121 state->hold = 0;
122 state->bits = 0;
123 state->lencode = state->distcode = state->next = state->codes;
124 state->sane = 1;
125 state->back = -1;
126 Tracev((stderr, "inflate: reset\n"));
127 return Z_OK;
128}

Referenced by inflateReset().

◆ inflateSetDictionary()

ZEXTERN int ZEXPORT inflateSetDictionary ( z_streamp strm,
const Bytef * dictionary,
uInt dictLength )

Definition at line 1298 of file inflate.c.

1299 {
1300 struct inflate_state FAR *state;
1301 unsigned long dictid;
1302 int ret;
1303
1304 /* check state */
1306 state = (struct inflate_state FAR *)strm->state;
1307 if (state->wrap != 0 && state->mode != DICT)
1308 return Z_STREAM_ERROR;
1309
1310 /* check for correct dictionary identifier */
1311 if (state->mode == DICT) {
1312 dictid = adler32(0L, Z_NULL, 0);
1313 dictid = adler32(dictid, dictionary, dictLength);
1314 if (dictid != state->check)
1315 return Z_DATA_ERROR;
1316 }
1317
1318 /* copy dictionary to window using updatewindow(), which will amend the
1319 existing dictionary if appropriate */
1320 ret = updatewindow(strm, dictionary + dictLength, dictLength);
1321 if (ret) {
1322 state->mode = MEM;
1323 return Z_MEM_ERROR;
1324 }
1325 state->havedict = 1;
1326 Tracev((stderr, "inflate: dictionary set\n"));
1327 return Z_OK;
1328}

◆ inflateSync()

ZEXTERN int ZEXPORT inflateSync ( z_streamp strm)

Definition at line 1375 of file inflate.c.

1375 {
1376 unsigned len; /* number of bytes to look at or looked at */
1377 int flags; /* temporary to save header status */
1378 unsigned long in, out; /* temporary to save total_in and total_out */
1379 unsigned char buf[4]; /* to restore bit buffer to byte string */
1380 struct inflate_state FAR *state;
1381
1382 /* check parameters */
1384 state = (struct inflate_state FAR *)strm->state;
1385 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1386
1387 /* if first time, start search in bit buffer */
1388 if (state->mode != SYNC) {
1389 state->mode = SYNC;
1390 state->hold >>= state->bits & 7;
1391 state->bits -= state->bits & 7;
1392 len = 0;
1393 while (state->bits >= 8) {
1394 buf[len++] = (unsigned char)(state->hold);
1395 state->hold >>= 8;
1396 state->bits -= 8;
1397 }
1398 state->have = 0;
1399 syncsearch(&(state->have), buf, len);
1400 }
1401
1402 /* search available input */
1403 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1404 strm->avail_in -= len;
1405 strm->next_in += len;
1406 strm->total_in += len;
1407
1408 /* return no joy or set up to restart inflate() on a new block */
1409 if (state->have != 4) return Z_DATA_ERROR;
1410 if (state->flags == -1)
1411 state->wrap = 0; /* if no header yet, treat as raw */
1412 else
1413 state->wrap &= ~4; /* no point in computing a check value now */
1414 flags = state->flags;
1415 in = strm->total_in; out = strm->total_out;
1417 strm->total_in = in; strm->total_out = out;
1418 state->flags = flags;
1419 state->mode = TYPE;
1420 return Z_OK;
1421}
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
Definition inflate.c:1355

◆ inflateSyncPoint()

ZEXTERN int ZEXPORT inflateSyncPoint ( z_streamp strm)

Definition at line 1431 of file inflate.c.

1431 {
1432 struct inflate_state FAR *state;
1433
1435 state = (struct inflate_state FAR *)strm->state;
1436 return state->mode == STORED && state->bits == 0;
1437}

◆ inflateUndermine()

ZEXTERN int ZEXPORT inflateUndermine ( z_streamp strm,
int subvert )

Definition at line 1483 of file inflate.c.

1483 {
1484 struct inflate_state FAR *state;
1485
1487 state = (struct inflate_state FAR *)strm->state;
1488#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1489 state->sane = !subvert;
1490 return Z_OK;
1491#else
1492 (void)subvert;
1493 state->sane = 1;
1494 return Z_DATA_ERROR;
1495#endif
1496}

◆ inflateValidate()

ZEXTERN int ZEXPORT inflateValidate ( z_streamp strm,
int check )

Definition at line 1498 of file inflate.c.

1498 {
1499 struct inflate_state FAR *state;
1500
1502 state = (struct inflate_state FAR *)strm->state;
1503 if (check && state->wrap)
1504 state->wrap |= 4;
1505 else
1506 state->wrap &= ~4;
1507 return Z_OK;
1508}

◆ uncompress()

ZEXTERN int ZEXPORT uncompress ( Bytef * dest,
uLongf * destLen,
const Bytef * source,
uLong sourceLen )

Definition at line 82 of file uncompr.c.

83 {
84 return uncompress2(dest, destLen, source, &sourceLen);
85}
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
Definition uncompr.c:27

Referenced by G4ParticleHPManager::GetDataStream(), and G4OpticalSurface::ReadCompressedFile().

◆ uncompress2()

ZEXTERN int ZEXPORT uncompress2 ( Bytef * dest,
uLongf * destLen,
const Bytef * source,
uLong * sourceLen )

Definition at line 27 of file uncompr.c.

28 {
29 z_stream stream;
30 int err;
31 const uInt max = (uInt)-1;
32 uLong len, left;
33 Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
34
35 len = *sourceLen;
36 if (*destLen) {
37 left = *destLen;
38 *destLen = 0;
39 }
40 else {
41 left = 1;
42 dest = buf;
43 }
44
45 stream.next_in = (z_const Bytef *)source;
46 stream.avail_in = 0;
47 stream.zalloc = (alloc_func)0;
48 stream.zfree = (free_func)0;
49 stream.opaque = (voidpf)0;
50
51 err = inflateInit(&stream);
52 if (err != Z_OK) return err;
53
54 stream.next_out = dest;
55 stream.avail_out = 0;
56
57 do {
58 if (stream.avail_out == 0) {
59 stream.avail_out = left > (uLong)max ? max : (uInt)left;
60 left -= stream.avail_out;
61 }
62 if (stream.avail_in == 0) {
63 stream.avail_in = len > (uLong)max ? max : (uInt)len;
64 len -= stream.avail_in;
65 }
66 err = inflate(&stream, Z_NO_FLUSH);
67 } while (err == Z_OK);
68
69 *sourceLen -= len + stream.avail_in;
70 if (dest != buf)
71 *destLen = stream.total_out;
72 else if (stream.total_out && err == Z_BUF_ERROR)
73 left = 1;
74
75 inflateEnd(&stream);
76 return err == Z_STREAM_END ? Z_OK :
77 err == Z_NEED_DICT ? Z_DATA_ERROR :
78 err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
79 err;
80}
ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush)
Definition inflate.c:590
#define inflateInit(strm)
Definition zlib.h:1815

Referenced by uncompress().

◆ zError()

ZEXTERN const char *ZEXPORT zError ( int err)

Definition at line 131 of file zutil.c.

131 {
132 return ERR_MSG(err);
133}

◆ zlibCompileFlags()

ZEXTERN uLong ZEXPORT zlibCompileFlags ( void )

Definition at line 31 of file zutil.c.

31 {
32 uLong flags;
33
34 flags = 0;
35 switch ((int)(sizeof(uInt))) {
36 case 2: break;
37 case 4: flags += 1; break;
38 case 8: flags += 2; break;
39 default: flags += 3;
40 }
41 switch ((int)(sizeof(uLong))) {
42 case 2: break;
43 case 4: flags += 1 << 2; break;
44 case 8: flags += 2 << 2; break;
45 default: flags += 3 << 2;
46 }
47 switch ((int)(sizeof(voidpf))) {
48 case 2: break;
49 case 4: flags += 1 << 4; break;
50 case 8: flags += 2 << 4; break;
51 default: flags += 3 << 4;
52 }
53 switch ((int)(sizeof(z_off_t))) {
54 case 2: break;
55 case 4: flags += 1 << 6; break;
56 case 8: flags += 2 << 6; break;
57 default: flags += 3 << 6;
58 }
59#ifdef ZLIB_DEBUG
60 flags += 1 << 8;
61#endif
62 /*
63#if defined(ASMV) || defined(ASMINF)
64 flags += 1 << 9;
65#endif
66 */
67#ifdef ZLIB_WINAPI
68 flags += 1 << 10;
69#endif
70#ifdef BUILDFIXED
71 flags += 1 << 12;
72#endif
73#ifdef DYNAMIC_CRC_TABLE
74 flags += 1 << 13;
75#endif
76#ifdef NO_GZCOMPRESS
77 flags += 1L << 16;
78#endif
79#ifdef NO_GZIP
80 flags += 1L << 17;
81#endif
82#ifdef PKZIP_BUG_WORKAROUND
83 flags += 1L << 20;
84#endif
85#ifdef FASTEST
86 flags += 1L << 21;
87#endif
88#if defined(STDC) || defined(Z_HAVE_STDARG_H)
89# ifdef NO_vsnprintf
90 flags += 1L << 25;
91# ifdef HAS_vsprintf_void
92 flags += 1L << 26;
93# endif
94# else
95# ifdef HAS_vsnprintf_void
96 flags += 1L << 26;
97# endif
98# endif
99#else
100 flags += 1L << 24;
101# ifdef NO_snprintf
102 flags += 1L << 25;
103# ifdef HAS_sprintf_void
104 flags += 1L << 26;
105# endif
106# else
107# ifdef HAS_snprintf_void
108 flags += 1L << 26;
109# endif
110# endif
111#endif
112 return flags;
113}

◆ zlibVersion()

ZEXTERN const char *ZEXPORT zlibVersion ( void )

Definition at line 27 of file zutil.c.

27 {
28 return ZLIB_VERSION;
29}