100 void makefixed
OF((
void));
110 strm->zalloc == (alloc_func)0 ||
strm->zfree == (free_func)0)
134 state->
dmax = 32768U;
141 Tracev((stderr,
"inflate: reset\n"));
170 if (windowBits < 0) {
171 if (windowBits < -15)
174 windowBits = -windowBits;
177 wrap = (windowBits >> 4) + 5;
185 if (windowBits && (windowBits < 8 || windowBits > 15))
194 state->
wbits = (unsigned)windowBits;
208 stream_size != (
int)(
sizeof(
z_stream)))
212 if (
strm->zalloc == (alloc_func)0) {
217 strm->opaque = (voidpf)0;
220 if (
strm->zfree == (free_func)0)
229 Tracev((stderr,
"inflate: allocated\n"));
265 value &= (1L <<
bits) - 1;
266 state->
hold += (unsigned)value << state->
bits;
285 static int virgin = 1;
286 static code *lenfix, *distfix;
287 static code fixed[544];
296 while (sym < 144) state->
lens[sym++] = 8;
297 while (sym < 256) state->
lens[sym++] = 9;
298 while (sym < 280) state->
lens[sym++] = 7;
299 while (sym < 288) state->
lens[sym++] = 8;
307 while (sym < 32) state->
lens[sym++] = 5;
351 puts(
" /* inffixed.h -- table for decoding fixed codes");
352 puts(
" * Generated automatically by makefixed().");
355 puts(
" /* WARNING: this file should *not* be used by applications.");
356 puts(
" It is part of the implementation of this library and is");
357 puts(
" subject to change. Applications should only use zlib.h.");
361 printf(
" static const code lenfix[%u] = {", size);
364 if ((low % 7) == 0) printf(
"\n ");
365 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.
lencode[low].
op,
367 if (++low == size)
break;
372 printf(
"\n static const code distfix[%u] = {", size);
375 if ((low % 6) == 0) printf(
"\n ");
378 if (++low == size)
break;
411 state->
window = (
unsigned char FAR *)
413 sizeof(
unsigned char));
418 if (state->
wsize == 0) {
425 if (copy >= state->
wsize) {
432 if (dist > copy) dist = copy;
441 state->
wnext += dist;
453# define UPDATE_CHECK(check, buf, len) \
454 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
456# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
461# define CRC2(check, word) \
463 hbuf[0] = (unsigned char)(word); \
464 hbuf[1] = (unsigned char)((word) >> 8); \
465 check = crc32(check, hbuf, 2); \
468# define CRC4(check, word) \
470 hbuf[0] = (unsigned char)(word); \
471 hbuf[1] = (unsigned char)((word) >> 8); \
472 hbuf[2] = (unsigned char)((word) >> 16); \
473 hbuf[3] = (unsigned char)((word) >> 24); \
474 check = crc32(check, hbuf, 4); \
481 put = strm->next_out; \
482 left = strm->avail_out; \
483 next = strm->next_in; \
484 have = strm->avail_in; \
485 hold = state->hold; \
486 bits = state->bits; \
492 strm->next_out = put; \
493 strm->avail_out = left; \
494 strm->next_in = next; \
495 strm->avail_in = have; \
496 state->hold = hold; \
497 state->bits = bits; \
511 if (have == 0) goto inf_leave; \
513 hold += (unsigned long)(*next++) << bits; \
521 while (bits < (unsigned)(n)) \
527 ((unsigned)hold & ((1U << (n)) - 1))
533 bits -= (unsigned)(n); \
630 z_const
unsigned char FAR *
next;
631 unsigned char FAR *put;
637 unsigned char FAR *from;
643 unsigned char hbuf[4];
645 static const unsigned short order[19] =
646 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
659 switch (state->
mode) {
661 if (state->
wrap == 0) {
667 if ((state->
wrap & 2) &&
hold == 0x8b1f) {
668 if (state->
wbits == 0)
677 state->
head->done = -1;
678 if (!(state->
wrap & 1) ||
682 ((
BITS(8) << 8) + (
hold >> 8)) % 31) {
683 strm->msg = (
char *)
"incorrect header check";
688 strm->msg = (
char *)
"unknown compression method";
694 if (state->
wbits == 0)
696 if (len > 15 || len > state->
wbits) {
697 strm->msg = (
char *)
"invalid window size";
701 state->
dmax = 1U << len;
703 Tracev((stderr,
"inflate: zlib header ok\n"));
713 strm->msg = (
char *)
"unknown compression method";
717 if (state->
flags & 0xe000) {
718 strm->msg = (
char *)
"unknown header flags set";
723 state->
head->text = (int)((
hold >> 8) & 1);
724 if ((state->
flags & 0x0200) && (state->
wrap & 4))
733 if ((state->
flags & 0x0200) && (state->
wrap & 4))
741 state->
head->xflags = (int)(
hold & 0xff);
744 if ((state->
flags & 0x0200) && (state->
wrap & 4))
750 if (state->
flags & 0x0400) {
754 state->
head->extra_len = (unsigned)
hold;
755 if ((state->
flags & 0x0200) && (state->
wrap & 4))
764 if (state->
flags & 0x0400) {
770 (len = state->
head->extra_len - state->
length) <
771 state->
head->extra_max) {
773 len + copy > state->
head->extra_max ?
774 state->
head->extra_max - len : copy);
776 if ((state->
flags & 0x0200) && (state->
wrap & 4))
782 if (state->
length)
goto inf_leave;
788 if (state->
flags & 0x0800) {
789 if (
have == 0)
goto inf_leave;
792 len = (unsigned)(
next[copy++]);
796 state->
head->name[state->
length++] = (Bytef)len;
797 }
while (len && copy <
have);
798 if ((state->
flags & 0x0200) && (state->
wrap & 4))
802 if (len)
goto inf_leave;
810 if (state->
flags & 0x1000) {
811 if (
have == 0)
goto inf_leave;
814 len = (unsigned)(
next[copy++]);
818 state->
head->comment[state->
length++] = (Bytef)len;
819 }
while (len && copy <
have);
820 if ((state->
flags & 0x0200) && (state->
wrap & 4))
824 if (len)
goto inf_leave;
831 if (state->
flags & 0x0200) {
834 strm->msg = (
char *)
"header crc mismatch";
841 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
842 state->
head->done = 1;
876 Tracev((stderr,
"inflate: stored block%s\n",
877 state->
last ?
" (last)" :
""));
882 Tracev((stderr,
"inflate: fixed codes block%s\n",
883 state->
last ?
" (last)" :
""));
891 Tracev((stderr,
"inflate: dynamic codes block%s\n",
892 state->
last ?
" (last)" :
""));
896 strm->msg = (
char *)
"invalid block type";
904 if ((
hold & 0xffff) != ((
hold >> 16) ^ 0xffff)) {
905 strm->msg = (
char *)
"invalid stored block lengths";
910 Tracev((stderr,
"inflate: stored length %u\n",
914 if (flush ==
Z_TREES)
goto inf_leave;
923 if (copy > left) copy = left;
924 if (copy == 0)
goto inf_leave;
933 Tracev((stderr,
"inflate: stored end\n"));
944#ifndef PKZIP_BUG_WORKAROUND
945 if (state->
nlen > 286 || state->
ndist > 30) {
946 strm->msg = (
char *)
"too many length or distance symbols";
951 Tracev((stderr,
"inflate: table sizes ok\n"));
958 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
961 while (state->
have < 19)
962 state->
lens[order[state->
have++]] = 0;
969 strm->msg = (
char *)
"invalid code lengths set";
973 Tracev((stderr,
"inflate: code lengths ok\n"));
981 if ((
unsigned)(here.
bits) <=
bits)
break;
989 if (here.
val == 16) {
992 if (state->
have == 0) {
993 strm->msg = (
char *)
"invalid bit length repeat";
1001 else if (here.
val == 17) {
1012 copy = 11 +
BITS(7);
1016 strm->msg = (
char *)
"invalid bit length repeat";
1021 state->
lens[state->
have++] = (
unsigned short)len;
1026 if (state->
mode ==
BAD)
break;
1029 if (state->
lens[256] == 0) {
1030 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1044 strm->msg = (
char *)
"invalid literal/lengths set";
1053 strm->msg = (
char *)
"invalid distances set";
1057 Tracev((stderr,
"inflate: codes ok\n"));
1059 if (flush ==
Z_TREES)
goto inf_leave;
1065 if (
have >= 6 && left >= 258) {
1076 if ((
unsigned)(here.
bits) <=
bits)
break;
1079 if (here.
op && (here.
op & 0xf0) == 0) {
1093 if ((
int)(here.
op) == 0) {
1095 "inflate: literal '%c'\n" :
1096 "inflate: literal 0x%02x\n", here.
val));
1101 Tracevv((stderr,
"inflate: end of block\n"));
1107 strm->msg = (
char *)
"invalid literal/length code";
1111 state->
extra = (unsigned)(here.
op) & 15;
1128 if ((
unsigned)(here.
bits) <=
bits)
break;
1131 if ((here.
op & 0xf0) == 0) {
1145 strm->msg = (
char *)
"invalid distance code";
1150 state->
extra = (unsigned)(here.
op) & 15;
1160#ifdef INFLATE_STRICT
1162 strm->msg = (
char *)
"invalid distance too far back";
1171 if (left == 0)
goto inf_leave;
1173 if (state->
offset > copy) {
1174 copy = state->
offset - copy;
1175 if (copy > state->
whave) {
1177 strm->msg = (
char *)
"invalid distance too far back";
1181#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1182 Trace((stderr,
"inflate.c too far\n"));
1183 copy -= state->
whave;
1185 if (copy > left) copy = left;
1195 if (copy > state->
wnext) {
1196 copy -= state->
wnext;
1204 from = put - state->
offset;
1207 if (copy > left) copy = left;
1216 if (left == 0)
goto inf_leave;
1217 *put++ = (
unsigned char)(state->
length);
1225 strm->total_out += out;
1226 state->
total += out;
1227 if ((state->
wrap & 4) && out)
1231 if ((state->
wrap & 4) && (
1236 strm->msg = (
char *)
"incorrect data check";
1241 Tracev((stderr,
"inflate: check matches trailer\n"));
1249 if ((state->
wrap & 4) &&
hold != (state->
total & 0xffffffff)) {
1250 strm->msg = (
char *)
"incorrect length check";
1255 Tracev((stderr,
"inflate: length matches trailer\n"));
1288 in -=
strm->avail_in;
1289 out -=
strm->avail_out;
1290 strm->total_in += in;
1291 strm->total_out += out;
1292 state->
total += out;
1293 if ((state->
wrap & 4) && out)
1296 strm->data_type = (int)state->
bits + (state->
last ? 64 : 0) +
1299 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1314 Tracev((stderr,
"inflate: end\n"));
1336 if (dictLength !=
Z_NULL)
1337 *dictLength = state->
whave;
1343const Bytef *dictionary;
1347 unsigned long dictid;
1359 dictid =
adler32(dictid, dictionary, dictLength);
1360 if (dictid != state->
check)
1372 Tracev((stderr,
"inflate: dictionary set\n"));
1406const unsigned char FAR *buf;
1414 while (
next < len && got < 4) {
1415 if ((
int)(buf[
next]) == (got < 2 ? 0 : 0xff))
1432 unsigned long in, out;
1433 unsigned char buf[4];
1447 while (state->
bits >= 8) {
1448 buf[len++] = (
unsigned char)(state->
hold);
1458 strm->avail_in -= len;
1459 strm->next_in += len;
1460 strm->total_in += len;
1464 if (state->
flags == -1)
1469 in =
strm->total_in; out =
strm->total_out;
1471 strm->total_in = in;
strm->total_out = out;
1501 unsigned char FAR *
window;
1515 window = (
unsigned char FAR *)
1516 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1518 ZFREE(source, copy);
1529 copy->lencode = copy->codes + (state->
lencode - state->
codes);
1530 copy->distcode = copy->codes + (state->
distcode - state->
codes);
1532 copy->next = copy->codes + (state->
next - state->
codes);
1550#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1551 state->
sane = !subvert;
1583 return (
long)(((
unsigned long)((long)state->
back)) << 16) +
1594 return (
unsigned long)(state->
next - state->
codes);
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
long ZEXPORT inflateMark(z_streamp strm)
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
local int inflateStateCheck(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateSyncPoint(z_streamp strm)
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
int ZEXPORT inflateSync(z_streamp strm)
int ZEXPORT inflateResetKeep(z_streamp strm)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
int ZEXPORT inflateReset(z_streamp strm)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
#define UPDATE_CHECK(check, buf, len)
int ZEXPORT inflateValidate(z_streamp strm, int check)
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
code const FAR * distcode
unsigned char FAR * window
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
gz_header FAR * gz_headerp
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
#define ZALLOC(strm, items, size)
#define ZFREE(strm, addr)