98 void makefixed
OF((
void));
110 strm->total_in = strm->total_out = state->
total = 0;
116 state->
dmax = 32768U;
124 Tracev((stderr,
"inflate: reset\n"));
138 value &= (1L <<
bits) - 1;
139 state->
hold += value << state->
bits;
153 stream_size != (
int)(
sizeof(
z_stream)))
157 if (strm->zalloc == (alloc_func)0) {
161 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
165 Tracev((stderr,
"inflate: allocated\n"));
167 if (windowBits < 0) {
169 windowBits = -windowBits;
172 state->
wrap = (windowBits >> 4) + 1;
174 if (windowBits < 48) windowBits &= 15;
177 if (windowBits < 8 || windowBits > 15) {
182 state->
wbits = (unsigned)windowBits;
209 static int virgin = 1;
211 static code fixed[544];
220 while (sym < 144) state->lens[sym++] = 8;
221 while (sym < 256) state->lens[sym++] = 9;
222 while (sym < 280) state->lens[sym++] = 7;
223 while (sym < 288) state->lens[sym++] = 8;
231 while (sym < 32) state->lens[sym++] = 5;
275 puts(
" /* inffixed.h -- table for decoding fixed codes");
276 puts(
" * Generated automatically by makefixed().");
279 puts(
" /* WARNING: this file should *not* be used by applications.");
280 puts(
" It is part of the implementation of this library and is");
281 puts(
" subject to change. Applications should only use zlib.h.");
285 printf(
" static const code lenfix[%u] = {", size);
288 if ((low % 7) == 0) printf(
"\n ");
291 if (++low == size)
break;
296 printf(
"\n static const code distfix[%u] = {", size);
299 if ((low % 6) == 0) printf(
"\n ");
302 if (++low == size)
break;
334 state->
window = (
unsigned char FAR *)
336 sizeof(
unsigned char));
341 if (state->
wsize == 0) {
348 copy = out - strm->avail_out;
349 if (copy >= state->
wsize) {
356 if (dist > copy) dist = copy;
365 state->
write += dist;
377 # define UPDATE(check, buf, len) \ 378 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) 380 # define UPDATE(check, buf, len) adler32(check, buf, len) 385 # define CRC2(check, word) \ 387 hbuf[0] = (unsigned char)(word); \ 388 hbuf[1] = (unsigned char)((word) >> 8); \ 389 check = crc32(check, hbuf, 2); \ 392 # define CRC4(check, word) \ 394 hbuf[0] = (unsigned char)(word); \ 395 hbuf[1] = (unsigned char)((word) >> 8); \ 396 hbuf[2] = (unsigned char)((word) >> 16); \ 397 hbuf[3] = (unsigned char)((word) >> 24); \ 398 check = crc32(check, hbuf, 4); \ 405 put = strm->next_out; \ 406 left = strm->avail_out; \ 407 next = strm->next_in; \ 408 have = strm->avail_in; \ 409 hold = state->hold; \ 410 bits = state->bits; \ 416 strm->next_out = put; \ 417 strm->avail_out = left; \ 418 strm->next_in = next; \ 419 strm->avail_in = have; \ 420 state->hold = hold; \ 421 state->bits = bits; \ 435 if (have == 0) goto inf_leave; \ 437 hold += (unsigned long)(*next++) << bits; \ 443 #define NEEDBITS(n) \ 445 while (bits < (unsigned)(n)) \ 451 ((unsigned)hold & ((1U << (n)) - 1)) 454 #define DROPBITS(n) \ 457 bits -= (unsigned)(n); \ 469 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 470 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 559 unsigned char FAR *
next;
560 unsigned char FAR *put;
566 unsigned char FAR *from;
572 unsigned char hbuf[4];
574 static const unsigned short order[19] =
575 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
578 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
588 switch (state->
mode) {
590 if (state->
wrap == 0) {
596 if ((state->
wrap & 2) && hold == 0x8b1f) {
605 state->
head->done = -1;
606 if (!(state->
wrap & 1) ||
610 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
611 strm->msg = (
char *)
"incorrect header check";
616 strm->msg = (
char *)
"unknown compression method";
622 if (len > state->
wbits) {
623 strm->msg = (
char *)
"invalid window size";
627 state->
dmax = 1U << len;
628 Tracev((stderr,
"inflate: zlib header ok\n"));
638 strm->msg = (
char *)
"unknown compression method";
642 if (state->
flags & 0xe000) {
643 strm->msg = (
char *)
"unknown header flags set";
648 state->
head->text = (
int)((hold >> 8) & 1);
662 state->
head->xflags = (
int)(hold & 0xff);
663 state->
head->os = (
int)(hold >> 8);
669 if (state->
flags & 0x0400) {
671 state->
length = (unsigned)(hold);
673 state->
head->extra_len = (unsigned)hold;
681 if (state->
flags & 0x0400) {
683 if (copy > have) copy =
have;
689 len + copy > state->
head->extra_max ?
690 state->
head->extra_max - len : copy);
692 if (state->
flags & 0x0200)
698 if (state->
length)
goto inf_leave;
703 if (state->
flags & 0x0800) {
704 if (have == 0)
goto inf_leave;
707 len = (unsigned)(next[copy++]);
712 }
while (len && copy < have);
713 if (state->
flags & 0x0200)
717 if (len)
goto inf_leave;
724 if (state->
flags & 0x1000) {
725 if (have == 0)
goto inf_leave;
728 len = (unsigned)(next[copy++]);
733 }
while (len && copy < have);
734 if (state->
flags & 0x0200)
738 if (len)
goto inf_leave;
744 if (state->
flags & 0x0200) {
746 if (hold != (state->
check & 0xffff)) {
747 strm->msg = (
char *)
"header crc mismatch";
755 state->
head->done = 1;
774 if (flush ==
Z_BLOCK)
goto inf_leave;
786 Tracev((stderr,
"inflate: stored block%s\n",
787 state->
last ?
" (last)" :
""));
792 Tracev((stderr,
"inflate: fixed codes block%s\n",
793 state->
last ?
" (last)" :
""));
797 Tracev((stderr,
"inflate: dynamic codes block%s\n",
798 state->
last ?
" (last)" :
""));
802 strm->msg = (
char *)
"invalid block type";
810 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
811 strm->msg = (
char *)
"invalid stored block lengths";
815 state->
length = (unsigned)hold & 0xffff;
816 Tracev((stderr,
"inflate: stored length %u\n",
823 if (copy > have) copy =
have;
824 if (copy > left) copy = left;
825 if (copy == 0)
goto inf_leave;
834 Tracev((stderr,
"inflate: stored end\n"));
845 #ifndef PKZIP_BUG_WORKAROUND 846 if (state->
nlen > 286 || state->
ndist > 30) {
847 strm->msg = (
char *)
"too many length or distance symbols";
852 Tracev((stderr,
"inflate: table sizes ok\n"));
858 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
861 while (state->
have < 19)
862 state->
lens[order[state->
have++]] = 0;
869 strm->msg = (
char *)
"invalid code lengths set";
873 Tracev((stderr,
"inflate: code lengths ok\n"));
880 if ((
unsigned)(this.bits) <= bits)
break;
889 if (this.
val == 16) {
892 if (state->
have == 0) {
893 strm->msg = (
char *)
"invalid bit length repeat";
901 else if (this.
val == 17) {
916 strm->msg = (
char *)
"invalid bit length repeat";
921 state->
lens[state->
have++] = (
unsigned short)len;
935 strm->msg = (
char *)
"invalid literal/lengths set";
944 strm->msg = (
char *)
"invalid distances set";
948 Tracev((stderr,
"inflate: codes ok\n"));
951 if (have >= 6 && left >= 258) {
959 if ((
unsigned)(this.bits) <= bits)
break;
962 if (this.op && (this.op & 0xf0) == 0) {
967 if ((
unsigned)(last.
bits + this.
bits) <= bits)
break;
974 if ((
int)(this.op) == 0) {
976 "inflate: literal '%c'\n" :
977 "inflate: literal 0x%02x\n", this.
val));
982 Tracevv((stderr,
"inflate: end of block\n"));
987 strm->msg = (
char *)
"invalid literal/length code";
991 state->
extra = (unsigned)(this.op) & 15;
1004 if ((
unsigned)(this.bits) <= bits)
break;
1007 if ((this.op & 0xf0) == 0) {
1012 if ((
unsigned)(last.
bits + this.
bits) <= bits)
break;
1019 strm->msg = (
char *)
"invalid distance code";
1024 state->
extra = (unsigned)(this.op) & 15;
1032 #ifdef INFLATE_STRICT 1034 strm->msg = (
char *)
"invalid distance too far back";
1040 strm->msg = (
char *)
"invalid distance too far back";
1047 if (left == 0)
goto inf_leave;
1049 if (state->
offset > copy) {
1050 copy = state->
offset - copy;
1051 if (copy > state->
write) {
1052 copy -= state->
write;
1060 from = put - state->
offset;
1063 if (copy > left) copy = left;
1072 if (left == 0)
goto inf_leave;
1073 *put++ = (
unsigned char)(state->
length);
1081 strm->total_out += out;
1082 state->
total += out;
1084 strm->adler = state->
check =
1089 state->
flags ? hold :
1092 strm->msg = (
char *)
"incorrect data check";
1097 Tracev((stderr,
"inflate: check matches trailer\n"));
1104 if (hold != (state->
total & 0xffffffffUL)) {
1105 strm->msg = (
char *)
"incorrect length check";
1110 Tracev((stderr,
"inflate: length matches trailer\n"));
1135 if (state->
wsize || (state->
mode <
CHECK && out != strm->avail_out))
1140 in -= strm->avail_in;
1141 out -= strm->avail_out;
1142 strm->total_in += in;
1143 strm->total_out += out;
1144 state->
total += out;
1145 if (state->
wrap && out)
1146 strm->adler = state->
check =
1148 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1150 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1159 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
1163 ZFREE(strm, strm->state);
1165 Tracev((stderr,
"inflate: end\n"));
1186 id =
adler32(
id, dictionary, dictLength);
1187 if (
id != state->
check)
1196 if (dictLength > state->
wsize) {
1204 state->
whave = dictLength;
1207 Tracev((stderr,
"inflate: dictionary set\n"));
1249 while (next < len && got < 4) {
1250 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1266 unsigned long in, out;
1267 unsigned char buf[4];
1281 while (state->
bits >= 8) {
1282 buf[len++] = (
unsigned char)(state->
hold);
1292 strm->avail_in -= len;
1293 strm->next_in += len;
1294 strm->total_in += len;
1298 in = strm->total_in; out = strm->total_out;
1300 strm->total_in = in; strm->total_out = out;
1329 unsigned char FAR *
window;
1334 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1344 window = (
unsigned char FAR *)
1345 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1347 ZFREE(source, copy);
1362 wsize = 1U << state->
wbits;
local unsigned syncsearch(unsigned FAR *have, unsigned char FAR *buf, unsigned len)
void zcfree(voidpf opaque, voidpf ptr)
int ZEXPORT inflateReset(z_streamp strm)
void zmemcpy(Bytef *dest, const Bytef *source, uInt len)
local void fixedtables(struct inflate_state FAR *state)
code const FAR * distcode
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
static const code lenfix[512]
gz_header FAR * gz_headerp
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT inflateSyncPoint(z_streamp strm)
#define ZALLOC(strm, items, size)
int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
#define CRC2(check, word)
static const code distfix[32]
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, unsigned len)
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
#define ZFREE(strm, addr)
local int updatewindow(z_streamp strm, unsigned out)
#define UPDATE(check, buf, len)
int ZEXPORT inflateSync(z_streamp strm)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
unsigned char FAR * window
int ZEXPORT inflate(z_streamp strm, int flush)
void inflate_fast(z_streamp strm, unsigned start)
local void fixedtables OF((struct inflate_state FAR *state))
#define CRC4(check, word)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
int ZEXPORT inflateEnd(z_streamp strm)