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) {
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;
318 state->lencode = lenfix;
320 state->distcode = distfix;
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,
366 state.lencode[low].bits,
state.lencode[low].val);
367 if (++low ==
size)
break;
372 printf(
"\n static const code distfix[%u] = {",
size);
375 if ((low % 6) == 0) printf(
"\n ");
376 printf(
"{%u,%u,%d}",
state.distcode[low].op,
state.distcode[low].bits,
377 state.distcode[low].val);
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); \
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)
697 strm->msg = (
char *)
"invalid window size";
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";
724 if ((
state->flags & 0x0200) && (
state->wrap & 4))
733 if ((
state->flags & 0x0200) && (
state->wrap & 4))
744 if ((
state->flags & 0x0200) && (
state->wrap & 4))
750 if (
state->flags & 0x0400) {
755 if ((
state->flags & 0x0200) && (
state->wrap & 4))
764 if (
state->flags & 0x0400) {
765 copy =
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))
780 state->length -= copy;
782 if (
state->length)
goto inf_leave;
788 if (
state->flags & 0x0800) {
789 if (
have == 0)
goto inf_leave;
792 len = (unsigned)(
next[copy++]);
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++]);
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";
842 state->head->done = 1;
855 if (
state->havedict == 0) {
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;
920 copy =
state->length;
923 if (copy > left) copy = left;
924 if (copy == 0)
goto inf_leave;
930 state->length -= copy;
933 Tracev((stderr,
"inflate: stored end\n"));
944#ifndef PKZIP_BUG_WORKAROUND
946 strm->msg = (
char *)
"too many length or distance symbols";
951 Tracev((stderr,
"inflate: table sizes ok\n"));
961 while (
state->have < 19)
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";
1029 if (
state->lens[256] == 0) {
1030 strm->msg = (
char *)
"invalid code -- missing end-of-block";
1044 strm->msg = (
char *)
"invalid literal/lengths set";
1049 state->distbits = 6;
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) {
1092 state->length = (unsigned)here.
val;
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;
1121 Tracevv((stderr,
"inflate: length %u\n",
state->length));
1128 if ((
unsigned)(here.
bits) <=
bits)
break;
1131 if ((here.
op & 0xf0) == 0) {
1145 strm->msg = (
char *)
"invalid distance code";
1149 state->offset = (unsigned)here.
val;
1150 state->extra = (
unsigned)(here.
op) & 15;
1160#ifdef INFLATE_STRICT
1162 strm->msg = (
char *)
"invalid distance too far back";
1167 Tracevv((stderr,
"inflate: distance %u\n",
state->offset));
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;
1184 if (copy >
state->length) copy =
state->length;
1185 if (copy > left) copy = left;
1187 state->length -= copy;
1195 if (copy >
state->wnext) {
1196 copy -=
state->wnext;
1197 from =
state->window + (
state->wsize - copy);
1200 from =
state->window + (
state->wnext - copy);
1201 if (copy >
state->length) copy =
state->length;
1204 from = put -
state->offset;
1205 copy =
state->length;
1207 if (copy > left) copy = left;
1209 state->length -= copy;
1216 if (left == 0)
goto inf_leave;
1217 *put++ = (
unsigned char)(
state->length);
1231 if ((
state->wrap & 4) && (
1236 strm->msg = (
char *)
"incorrect data check";
1241 Tracev((stderr,
"inflate: check matches trailer\n"));
1250 strm->msg = (
char *)
"incorrect length check";
1255 Tracev((stderr,
"inflate: length matches trailer\n"));
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)
1371 state->havedict = 1;
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) {
1464 if (
state->flags == -1)
1516 ZALLOC(source, 1U <<
state->wbits,
sizeof(
unsigned char));
1518 ZFREE(source, copy);
1550#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1551 state->sane = !subvert;
1583 return (
long)(((
unsigned long)((
long)
state->back)) << 16) +
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
int bits(struct state *s, int need)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
unsigned in(void *in_desc, z_const unsigned char **buf)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
void fixedtables(struct inflate_state FAR *state)
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
#define CRC2(check, word)
long ZEXPORT inflateMark(z_streamp strm)
int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
int ZEXPORT inflateSyncPoint(z_streamp strm)
#define CRC4(check, word)
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 inflateStateCheck(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)
int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
int ZEXPORT inflateReset(z_streamp strm)
unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
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)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
int fixed(struct state *s)
code const FAR * distcode
unsigned char FAR * window
if((ID)(DISPID) nameid !=nameid)
gz_header FAR * gz_headerp
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
#define ZALLOC(strm, items, size)
#define ZFREE(strm, addr)