Lines Matching refs:state

5 local void fixedtables OF((struct inflate_state FAR *state));
10 struct inflate_state FAR *state; in inflateReset() local
12 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; in inflateReset()
13 state = (struct inflate_state FAR *)strm->state; in inflateReset()
14 strm->total_in = strm->total_out = state->total = 0; in inflateReset()
17 state->mode = HEAD; in inflateReset()
18 state->last = 0; in inflateReset()
19 state->havedict = 0; in inflateReset()
20 state->dmax = 32768U; in inflateReset()
21 state->head = Z_NULL; in inflateReset()
22 state->wsize = 0; in inflateReset()
23 state->whave = 0; in inflateReset()
24 state->write = 0; in inflateReset()
25 state->hold = 0; in inflateReset()
26 state->bits = 0; in inflateReset()
27 state->lencode = state->distcode = state->next = state->codes; in inflateReset()
36 struct inflate_state FAR *state; in inflateInit2_() local
48 state = (struct inflate_state FAR *) in inflateInit2_()
50 if (state == Z_NULL) return Z_MEM_ERROR; in inflateInit2_()
52 strm->state = (struct internal_state FAR *)state; in inflateInit2_()
54 state->wrap = 0; in inflateInit2_()
58 state->wrap = (windowBits >> 4) + 1; in inflateInit2_()
64 ZFREE(strm, state); in inflateInit2_()
65 strm->state = Z_NULL; in inflateInit2_()
68 state->wbits = (unsigned)windowBits; in inflateInit2_()
69 state->window = Z_NULL; in inflateInit2_()
78 local void fixedtables(struct inflate_state FAR *state) in fixedtables() argument
80 state->lencode = lenfix; in fixedtables()
81 state->lenbits = 9; in fixedtables()
82 state->distcode = distfix; in fixedtables()
83 state->distbits = 5; in fixedtables()
102 struct inflate_state FAR *state; in updatewindow() local
105 state = (struct inflate_state FAR *)strm->state; in updatewindow()
108 if (state->window == Z_NULL) { in updatewindow()
109 state->window = (unsigned char FAR *) in updatewindow()
110 ZALLOC(strm, 1U << state->wbits, in updatewindow()
112 if (state->window == Z_NULL) return 1; in updatewindow()
116 if (state->wsize == 0) { in updatewindow()
117 state->wsize = 1U << state->wbits; in updatewindow()
118 state->write = 0; in updatewindow()
119 state->whave = 0; in updatewindow()
124 if (copy >= state->wsize) { in updatewindow()
125 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); in updatewindow()
126 state->write = 0; in updatewindow()
127 state->whave = state->wsize; in updatewindow()
130 dist = state->wsize - state->write; in updatewindow()
132 zmemcpy(state->window + state->write, strm->next_out - copy, dist); in updatewindow()
135 zmemcpy(state->window, strm->next_out - copy, copy); in updatewindow()
136 state->write = copy; in updatewindow()
137 state->whave = state->wsize; in updatewindow()
140 state->write += dist; in updatewindow()
141 if (state->write == state->wsize) state->write = 0; in updatewindow()
142 if (state->whave < state->wsize) state->whave += dist; in updatewindow()
153 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
184 hold = state->hold; \
185 bits = state->bits; \
195 state->hold = hold; \
196 state->bits = bits; \
330 struct inflate_state FAR *state; in inflate() local
349 if (strm == Z_NULL || strm->state == Z_NULL || in inflate()
353 state = (struct inflate_state FAR *)strm->state; in inflate()
354 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ in inflate()
360 switch (state->mode) { in inflate()
362 if (state->wrap == 0) { in inflate()
363 state->mode = TYPEDO; in inflate()
368 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ in inflate()
369 state->check = crc32(0L, Z_NULL, 0); in inflate()
370 CRC2(state->check, hold); in inflate()
372 state->mode = FLAGS; in inflate()
375 state->flags = 0; /* expect zlib header */ in inflate()
376 if (state->head != Z_NULL) in inflate()
377 state->head->done = -1; in inflate()
378 if (!(state->wrap & 1) || /* check if zlib header allowed */ in inflate()
384 state->mode = BAD; in inflate()
389 state->mode = BAD; in inflate()
394 if (len > state->wbits) { in inflate()
396 state->mode = BAD; in inflate()
399 state->dmax = 1U << len; in inflate()
401 strm->adler = state->check = adler32(0L, Z_NULL, 0); in inflate()
402 state->mode = hold & 0x200 ? DICTID : TYPE; in inflate()
408 state->flags = (int)(hold); in inflate()
409 if ((state->flags & 0xff) != Z_DEFLATED) { in inflate()
411 state->mode = BAD; in inflate()
414 if (state->flags & 0xe000) { in inflate()
416 state->mode = BAD; in inflate()
419 if (state->head != Z_NULL) in inflate()
420 state->head->text = (int)((hold >> 8) & 1); in inflate()
421 if (state->flags & 0x0200) CRC2(state->check, hold); in inflate()
423 state->mode = TIME; in inflate()
426 if (state->head != Z_NULL) in inflate()
427 state->head->time = hold; in inflate()
428 if (state->flags & 0x0200) CRC4(state->check, hold); in inflate()
430 state->mode = OS; in inflate()
433 if (state->head != Z_NULL) { in inflate()
434 state->head->xflags = (int)(hold & 0xff); in inflate()
435 state->head->os = (int)(hold >> 8); in inflate()
437 if (state->flags & 0x0200) CRC2(state->check, hold); in inflate()
439 state->mode = EXLEN; in inflate()
441 if (state->flags & 0x0400) { in inflate()
443 state->length = (unsigned)(hold); in inflate()
444 if (state->head != Z_NULL) in inflate()
445 state->head->extra_len = (unsigned)hold; in inflate()
446 if (state->flags & 0x0200) CRC2(state->check, hold); in inflate()
449 else if (state->head != Z_NULL) in inflate()
450 state->head->extra = Z_NULL; in inflate()
451 state->mode = EXTRA; in inflate()
453 if (state->flags & 0x0400) { in inflate()
454 copy = state->length; in inflate()
457 if (state->head != Z_NULL && in inflate()
458 state->head->extra != Z_NULL) { in inflate()
459 len = state->head->extra_len - state->length; in inflate()
460 zmemcpy(state->head->extra + len, next, in inflate()
461 len + copy > state->head->extra_max ? in inflate()
462 state->head->extra_max - len : copy); in inflate()
464 if (state->flags & 0x0200) in inflate()
465 state->check = crc32(state->check, next, copy); in inflate()
468 state->length -= copy; in inflate()
470 if (state->length) goto inf_leave; in inflate()
472 state->length = 0; in inflate()
473 state->mode = NAME; in inflate()
475 if (state->flags & 0x0800) { in inflate()
480 if (state->head != Z_NULL && in inflate()
481 state->head->name != Z_NULL && in inflate()
482 state->length < state->head->name_max) in inflate()
483 state->head->name[state->length++] = len; in inflate()
485 if (state->flags & 0x0200) in inflate()
486 state->check = crc32(state->check, next, copy); in inflate()
491 else if (state->head != Z_NULL) in inflate()
492 state->head->name = Z_NULL; in inflate()
493 state->length = 0; in inflate()
494 state->mode = COMMENT; in inflate()
496 if (state->flags & 0x1000) { in inflate()
501 if (state->head != Z_NULL && in inflate()
502 state->head->comment != Z_NULL && in inflate()
503 state->length < state->head->comm_max) in inflate()
504 state->head->comment[state->length++] = len; in inflate()
506 if (state->flags & 0x0200) in inflate()
507 state->check = crc32(state->check, next, copy); in inflate()
512 else if (state->head != Z_NULL) in inflate()
513 state->head->comment = Z_NULL; in inflate()
514 state->mode = HCRC; in inflate()
516 if (state->flags & 0x0200) { in inflate()
518 if (hold != (state->check & 0xffff)) { in inflate()
520 state->mode = BAD; in inflate()
525 if (state->head != Z_NULL) { in inflate()
526 state->head->hcrc = (int)((state->flags >> 9) & 1); in inflate()
527 state->head->done = 1; in inflate()
529 strm->adler = state->check = crc32(0L, Z_NULL, 0); in inflate()
530 state->mode = TYPE; in inflate()
535 strm->adler = state->check = REVERSE(hold); in inflate()
537 state->mode = DICT; in inflate()
539 if (state->havedict == 0) { in inflate()
543 strm->adler = state->check = adler32(0L, Z_NULL, 0); in inflate()
544 state->mode = TYPE; in inflate()
549 if (state->last) { in inflate()
551 state->mode = CHECK; in inflate()
555 state->last = BITS(1); in inflate()
560 state->last ? " (last)" : "")); in inflate()
561 state->mode = STORED; in inflate()
564 fixedtables(state); in inflate()
566 state->last ? " (last)" : "")); in inflate()
567 state->mode = LEN; /* decode codes */ in inflate()
571 state->last ? " (last)" : "")); in inflate()
572 state->mode = TABLE; in inflate()
576 state->mode = BAD; in inflate()
585 state->mode = BAD; in inflate()
588 state->length = (unsigned)hold & 0xffff; in inflate()
590 state->length)); in inflate()
592 state->mode = COPY; in inflate()
594 copy = state->length; in inflate()
604 state->length -= copy; in inflate()
608 state->mode = TYPE; in inflate()
612 state->nlen = BITS(5) + 257; in inflate()
614 state->ndist = BITS(5) + 1; in inflate()
616 state->ncode = BITS(4) + 4; in inflate()
619 if (state->nlen > 286 || state->ndist > 30) { in inflate()
621 state->mode = BAD; in inflate()
626 state->have = 0; in inflate()
627 state->mode = LENLENS; in inflate()
629 while (state->have < state->ncode) { in inflate()
631 state->lens[order[state->have++]] = (unsigned short)BITS(3); in inflate()
634 while (state->have < 19) in inflate()
635 state->lens[order[state->have++]] = 0; in inflate()
636 state->next = state->codes; in inflate()
637 state->lencode = (code const FAR *)(state->next); in inflate()
638 state->lenbits = 7; in inflate()
639 ret = inflate_table(CODES, state->lens, 19, &(state->next), in inflate()
640 &(state->lenbits), state->work); in inflate()
643 state->mode = BAD; in inflate()
647 state->have = 0; in inflate()
648 state->mode = CODELENS; in inflate()
650 while (state->have < state->nlen + state->ndist) { in inflate()
652 this = state->lencode[BITS(state->lenbits)]; in inflate()
659 state->lens[state->have++] = this.val; in inflate()
665 if (state->have == 0) { in inflate()
667 state->mode = BAD; in inflate()
670 len = state->lens[state->have - 1]; in inflate()
688 if (state->have + copy > state->nlen + state->ndist) { in inflate()
690 state->mode = BAD; in inflate()
694 state->lens[state->have++] = (unsigned short)len; in inflate()
699 if (state->mode == BAD) break; in inflate()
702 state->next = state->codes; in inflate()
703 state->lencode = (code const FAR *)(state->next); in inflate()
704 state->lenbits = 9; in inflate()
705 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), in inflate()
706 &(state->lenbits), state->work); in inflate()
709 state->mode = BAD; in inflate()
712 state->distcode = (code const FAR *)(state->next); in inflate()
713 state->distbits = 6; in inflate()
714 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, in inflate()
715 &(state->next), &(state->distbits), state->work); in inflate()
718 state->mode = BAD; in inflate()
722 state->mode = LEN; in inflate()
732 this = state->lencode[BITS(state->lenbits)]; in inflate()
739 this = state->lencode[last.val + in inflate()
747 state->length = (unsigned)this.val; in inflate()
752 state->mode = LIT; in inflate()
757 state->mode = TYPE; in inflate()
762 state->mode = BAD; in inflate()
765 state->extra = (unsigned)(this.op) & 15; in inflate()
766 state->mode = LENEXT; in inflate()
768 if (state->extra) { in inflate()
769 NEEDBITS(state->extra); in inflate()
770 state->length += BITS(state->extra); in inflate()
771 DROPBITS(state->extra); in inflate()
773 Tracevv((stderr, "inflate: length %u\n", state->length)); in inflate()
774 state->mode = DIST; in inflate()
777 this = state->distcode[BITS(state->distbits)]; in inflate()
784 this = state->distcode[last.val + in inflate()
794 state->mode = BAD; in inflate()
797 state->offset = (unsigned)this.val; in inflate()
798 state->extra = (unsigned)(this.op) & 15; in inflate()
799 state->mode = DISTEXT; in inflate()
801 if (state->extra) { in inflate()
802 NEEDBITS(state->extra); in inflate()
803 state->offset += BITS(state->extra); in inflate()
804 DROPBITS(state->extra); in inflate()
807 if (state->offset > state->dmax) { in inflate()
809 state->mode = BAD; in inflate()
813 if (state->offset > state->whave + out - left) { in inflate()
815 state->mode = BAD; in inflate()
818 Tracevv((stderr, "inflate: distance %u\n", state->offset)); in inflate()
819 state->mode = MATCH; in inflate()
823 if (state->offset > copy) { /* copy from window */ in inflate()
824 copy = state->offset - copy; in inflate()
825 if (copy > state->write) { in inflate()
826 copy -= state->write; in inflate()
827 from = state->window + (state->wsize - copy); in inflate()
830 from = state->window + (state->write - copy); in inflate()
831 if (copy > state->length) copy = state->length; in inflate()
834 from = put - state->offset; in inflate()
835 copy = state->length; in inflate()
839 state->length -= copy; in inflate()
843 if (state->length == 0) state->mode = LEN; in inflate()
847 *put++ = (unsigned char)(state->length); in inflate()
849 state->mode = LEN; in inflate()
852 if (state->wrap) { in inflate()
856 state->total += out; in inflate()
858 strm->adler = state->check = in inflate()
859 UPDATE(state->check, put - out, out); in inflate()
863 state->flags ? hold : in inflate()
865 REVERSE(hold)) != state->check) { in inflate()
867 state->mode = BAD; in inflate()
874 state->mode = LENGTH; in inflate()
876 if (state->wrap && state->flags) { in inflate()
878 if (hold != (state->total & 0xffffffffUL)) { in inflate()
880 state->mode = BAD; in inflate()
887 state->mode = DONE; in inflate()
909 if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) in inflate()
911 state->mode = MEM; in inflate()
918 state->total += out; in inflate()
919 if (state->wrap && out) in inflate()
920 strm->adler = state->check = in inflate()
921 UPDATE(state->check, strm->next_out - out, out); in inflate()
922 strm->data_type = state->bits + (state->last ? 64 : 0) + in inflate()
923 (state->mode == TYPE ? 128 : 0); in inflate()
931 struct inflate_state FAR *state; in inflateEnd() local
932 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) in inflateEnd()
934 state = (struct inflate_state FAR *)strm->state; in inflateEnd()
935 if (state->window != Z_NULL) { in inflateEnd()
937 ZFREE(strm, state->window); in inflateEnd()
939 ZFREE(strm, strm->state); in inflateEnd()
940 strm->state = Z_NULL; in inflateEnd()