Chris@43: /* infback.c -- inflate using a call-back interface Chris@43: * Copyright (C) 1995-2011 Mark Adler Chris@43: * For conditions of distribution and use, see copyright notice in zlib.h Chris@43: */ Chris@43: Chris@43: /* Chris@43: This code is largely copied from inflate.c. Normally either infback.o or Chris@43: inflate.o would be linked into an application--not both. The interface Chris@43: with inffast.c is retained so that optimized assembler-coded versions of Chris@43: inflate_fast() can be used with either inflate.c or infback.c. Chris@43: */ Chris@43: Chris@43: #include "zutil.h" Chris@43: #include "inftrees.h" Chris@43: #include "inflate.h" Chris@43: #include "inffast.h" Chris@43: Chris@43: /* function prototypes */ Chris@43: local void fixedtables OF((struct inflate_state FAR *state)); Chris@43: Chris@43: /* Chris@43: strm provides memory allocation functions in zalloc and zfree, or Chris@43: Z_NULL to use the library memory allocation functions. Chris@43: Chris@43: windowBits is in the range 8..15, and window is a user-supplied Chris@43: window and output buffer that is 2**windowBits bytes. Chris@43: */ Chris@43: int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) Chris@43: z_streamp strm; Chris@43: int windowBits; Chris@43: unsigned char FAR *window; Chris@43: const char *version; Chris@43: int stream_size; Chris@43: { Chris@43: struct inflate_state FAR *state; Chris@43: Chris@43: if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || Chris@43: stream_size != (int)(sizeof(z_stream))) Chris@43: return Z_VERSION_ERROR; Chris@43: if (strm == Z_NULL || window == Z_NULL || Chris@43: windowBits < 8 || windowBits > 15) Chris@43: return Z_STREAM_ERROR; Chris@43: strm->msg = Z_NULL; /* in case we return an error */ Chris@43: if (strm->zalloc == (alloc_func)0) { Chris@43: #ifdef Z_SOLO Chris@43: return Z_STREAM_ERROR; Chris@43: #else Chris@43: strm->zalloc = zcalloc; Chris@43: strm->opaque = (voidpf)0; Chris@43: #endif Chris@43: } Chris@43: if (strm->zfree == (free_func)0) Chris@43: #ifdef Z_SOLO Chris@43: return Z_STREAM_ERROR; Chris@43: #else Chris@43: strm->zfree = zcfree; Chris@43: #endif Chris@43: state = (struct inflate_state FAR *)ZALLOC(strm, 1, Chris@43: sizeof(struct inflate_state)); Chris@43: if (state == Z_NULL) return Z_MEM_ERROR; Chris@43: Tracev((stderr, "inflate: allocated\n")); Chris@43: strm->state = (struct internal_state FAR *)state; Chris@43: state->dmax = 32768U; Chris@43: state->wbits = windowBits; Chris@43: state->wsize = 1U << windowBits; Chris@43: state->window = window; Chris@43: state->wnext = 0; Chris@43: state->whave = 0; Chris@43: return Z_OK; Chris@43: } Chris@43: Chris@43: /* Chris@43: Return state with length and distance decoding tables and index sizes set to Chris@43: fixed code decoding. Normally this returns fixed tables from inffixed.h. Chris@43: If BUILDFIXED is defined, then instead this routine builds the tables the Chris@43: first time it's called, and returns those tables the first time and Chris@43: thereafter. This reduces the size of the code by about 2K bytes, in Chris@43: exchange for a little execution time. However, BUILDFIXED should not be Chris@43: used for threaded applications, since the rewriting of the tables and virgin Chris@43: may not be thread-safe. Chris@43: */ Chris@43: local void fixedtables(state) Chris@43: struct inflate_state FAR *state; Chris@43: { Chris@43: #ifdef BUILDFIXED Chris@43: static int virgin = 1; Chris@43: static code *lenfix, *distfix; Chris@43: static code fixed[544]; Chris@43: Chris@43: /* build fixed huffman tables if first call (may not be thread safe) */ Chris@43: if (virgin) { Chris@43: unsigned sym, bits; Chris@43: static code *next; Chris@43: Chris@43: /* literal/length table */ Chris@43: sym = 0; Chris@43: while (sym < 144) state->lens[sym++] = 8; Chris@43: while (sym < 256) state->lens[sym++] = 9; Chris@43: while (sym < 280) state->lens[sym++] = 7; Chris@43: while (sym < 288) state->lens[sym++] = 8; Chris@43: next = fixed; Chris@43: lenfix = next; Chris@43: bits = 9; Chris@43: inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); Chris@43: Chris@43: /* distance table */ Chris@43: sym = 0; Chris@43: while (sym < 32) state->lens[sym++] = 5; Chris@43: distfix = next; Chris@43: bits = 5; Chris@43: inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); Chris@43: Chris@43: /* do this just once */ Chris@43: virgin = 0; Chris@43: } Chris@43: #else /* !BUILDFIXED */ Chris@43: # include "inffixed.h" Chris@43: #endif /* BUILDFIXED */ Chris@43: state->lencode = lenfix; Chris@43: state->lenbits = 9; Chris@43: state->distcode = distfix; Chris@43: state->distbits = 5; Chris@43: } Chris@43: Chris@43: /* Macros for inflateBack(): */ Chris@43: Chris@43: /* Load returned state from inflate_fast() */ Chris@43: #define LOAD() \ Chris@43: do { \ Chris@43: put = strm->next_out; \ Chris@43: left = strm->avail_out; \ Chris@43: next = strm->next_in; \ Chris@43: have = strm->avail_in; \ Chris@43: hold = state->hold; \ Chris@43: bits = state->bits; \ Chris@43: } while (0) Chris@43: Chris@43: /* Set state from registers for inflate_fast() */ Chris@43: #define RESTORE() \ Chris@43: do { \ Chris@43: strm->next_out = put; \ Chris@43: strm->avail_out = left; \ Chris@43: strm->next_in = next; \ Chris@43: strm->avail_in = have; \ Chris@43: state->hold = hold; \ Chris@43: state->bits = bits; \ Chris@43: } while (0) Chris@43: Chris@43: /* Clear the input bit accumulator */ Chris@43: #define INITBITS() \ Chris@43: do { \ Chris@43: hold = 0; \ Chris@43: bits = 0; \ Chris@43: } while (0) Chris@43: Chris@43: /* Assure that some input is available. If input is requested, but denied, Chris@43: then return a Z_BUF_ERROR from inflateBack(). */ Chris@43: #define PULL() \ Chris@43: do { \ Chris@43: if (have == 0) { \ Chris@43: have = in(in_desc, &next); \ Chris@43: if (have == 0) { \ Chris@43: next = Z_NULL; \ Chris@43: ret = Z_BUF_ERROR; \ Chris@43: goto inf_leave; \ Chris@43: } \ Chris@43: } \ Chris@43: } while (0) Chris@43: Chris@43: /* Get a byte of input into the bit accumulator, or return from inflateBack() Chris@43: with an error if there is no input available. */ Chris@43: #define PULLBYTE() \ Chris@43: do { \ Chris@43: PULL(); \ Chris@43: have--; \ Chris@43: hold += (unsigned long)(*next++) << bits; \ Chris@43: bits += 8; \ Chris@43: } while (0) Chris@43: Chris@43: /* Assure that there are at least n bits in the bit accumulator. If there is Chris@43: not enough available input to do that, then return from inflateBack() with Chris@43: an error. */ Chris@43: #define NEEDBITS(n) \ Chris@43: do { \ Chris@43: while (bits < (unsigned)(n)) \ Chris@43: PULLBYTE(); \ Chris@43: } while (0) Chris@43: Chris@43: /* Return the low n bits of the bit accumulator (n < 16) */ Chris@43: #define BITS(n) \ Chris@43: ((unsigned)hold & ((1U << (n)) - 1)) Chris@43: Chris@43: /* Remove n bits from the bit accumulator */ Chris@43: #define DROPBITS(n) \ Chris@43: do { \ Chris@43: hold >>= (n); \ Chris@43: bits -= (unsigned)(n); \ Chris@43: } while (0) Chris@43: Chris@43: /* Remove zero to seven bits as needed to go to a byte boundary */ Chris@43: #define BYTEBITS() \ Chris@43: do { \ Chris@43: hold >>= bits & 7; \ Chris@43: bits -= bits & 7; \ Chris@43: } while (0) Chris@43: Chris@43: /* Assure that some output space is available, by writing out the window Chris@43: if it's full. If the write fails, return from inflateBack() with a Chris@43: Z_BUF_ERROR. */ Chris@43: #define ROOM() \ Chris@43: do { \ Chris@43: if (left == 0) { \ Chris@43: put = state->window; \ Chris@43: left = state->wsize; \ Chris@43: state->whave = left; \ Chris@43: if (out(out_desc, put, left)) { \ Chris@43: ret = Z_BUF_ERROR; \ Chris@43: goto inf_leave; \ Chris@43: } \ Chris@43: } \ Chris@43: } while (0) Chris@43: Chris@43: /* Chris@43: strm provides the memory allocation functions and window buffer on input, Chris@43: and provides information on the unused input on return. For Z_DATA_ERROR Chris@43: returns, strm will also provide an error message. Chris@43: Chris@43: in() and out() are the call-back input and output functions. When Chris@43: inflateBack() needs more input, it calls in(). When inflateBack() has Chris@43: filled the window with output, or when it completes with data in the Chris@43: window, it calls out() to write out the data. The application must not Chris@43: change the provided input until in() is called again or inflateBack() Chris@43: returns. The application must not change the window/output buffer until Chris@43: inflateBack() returns. Chris@43: Chris@43: in() and out() are called with a descriptor parameter provided in the Chris@43: inflateBack() call. This parameter can be a structure that provides the Chris@43: information required to do the read or write, as well as accumulated Chris@43: information on the input and output such as totals and check values. Chris@43: Chris@43: in() should return zero on failure. out() should return non-zero on Chris@43: failure. If either in() or out() fails, than inflateBack() returns a Chris@43: Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it Chris@43: was in() or out() that caused in the error. Otherwise, inflateBack() Chris@43: returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format Chris@43: error, or Z_MEM_ERROR if it could not allocate memory for the state. Chris@43: inflateBack() can also return Z_STREAM_ERROR if the input parameters Chris@43: are not correct, i.e. strm is Z_NULL or the state was not initialized. Chris@43: */ Chris@43: int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) Chris@43: z_streamp strm; Chris@43: in_func in; Chris@43: void FAR *in_desc; Chris@43: out_func out; Chris@43: void FAR *out_desc; Chris@43: { Chris@43: struct inflate_state FAR *state; Chris@43: z_const unsigned char FAR *next; /* next input */ Chris@43: unsigned char FAR *put; /* next output */ Chris@43: unsigned have, left; /* available input and output */ Chris@43: unsigned long hold; /* bit buffer */ Chris@43: unsigned bits; /* bits in bit buffer */ Chris@43: unsigned copy; /* number of stored or match bytes to copy */ Chris@43: unsigned char FAR *from; /* where to copy match bytes from */ Chris@43: code here; /* current decoding table entry */ Chris@43: code last; /* parent table entry */ Chris@43: unsigned len; /* length to copy for repeats, bits to drop */ Chris@43: int ret; /* return code */ Chris@43: static const unsigned short order[19] = /* permutation of code lengths */ Chris@43: {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; Chris@43: Chris@43: /* Check that the strm exists and that the state was initialized */ Chris@43: if (strm == Z_NULL || strm->state == Z_NULL) Chris@43: return Z_STREAM_ERROR; Chris@43: state = (struct inflate_state FAR *)strm->state; Chris@43: Chris@43: /* Reset the state */ Chris@43: strm->msg = Z_NULL; Chris@43: state->mode = TYPE; Chris@43: state->last = 0; Chris@43: state->whave = 0; Chris@43: next = strm->next_in; Chris@43: have = next != Z_NULL ? strm->avail_in : 0; Chris@43: hold = 0; Chris@43: bits = 0; Chris@43: put = state->window; Chris@43: left = state->wsize; Chris@43: Chris@43: /* Inflate until end of block marked as last */ Chris@43: for (;;) Chris@43: switch (state->mode) { Chris@43: case TYPE: Chris@43: /* determine and dispatch block type */ Chris@43: if (state->last) { Chris@43: BYTEBITS(); Chris@43: state->mode = DONE; Chris@43: break; Chris@43: } Chris@43: NEEDBITS(3); Chris@43: state->last = BITS(1); Chris@43: DROPBITS(1); Chris@43: switch (BITS(2)) { Chris@43: case 0: /* stored block */ Chris@43: Tracev((stderr, "inflate: stored block%s\n", Chris@43: state->last ? " (last)" : "")); Chris@43: state->mode = STORED; Chris@43: break; Chris@43: case 1: /* fixed block */ Chris@43: fixedtables(state); Chris@43: Tracev((stderr, "inflate: fixed codes block%s\n", Chris@43: state->last ? " (last)" : "")); Chris@43: state->mode = LEN; /* decode codes */ Chris@43: break; Chris@43: case 2: /* dynamic block */ Chris@43: Tracev((stderr, "inflate: dynamic codes block%s\n", Chris@43: state->last ? " (last)" : "")); Chris@43: state->mode = TABLE; Chris@43: break; Chris@43: case 3: Chris@43: strm->msg = (char *)"invalid block type"; Chris@43: state->mode = BAD; Chris@43: } Chris@43: DROPBITS(2); Chris@43: break; Chris@43: Chris@43: case STORED: Chris@43: /* get and verify stored block length */ Chris@43: BYTEBITS(); /* go to byte boundary */ Chris@43: NEEDBITS(32); Chris@43: if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { Chris@43: strm->msg = (char *)"invalid stored block lengths"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: state->length = (unsigned)hold & 0xffff; Chris@43: Tracev((stderr, "inflate: stored length %u\n", Chris@43: state->length)); Chris@43: INITBITS(); Chris@43: Chris@43: /* copy stored block from input to output */ Chris@43: while (state->length != 0) { Chris@43: copy = state->length; Chris@43: PULL(); Chris@43: ROOM(); Chris@43: if (copy > have) copy = have; Chris@43: if (copy > left) copy = left; Chris@43: zmemcpy(put, next, copy); Chris@43: have -= copy; Chris@43: next += copy; Chris@43: left -= copy; Chris@43: put += copy; Chris@43: state->length -= copy; Chris@43: } Chris@43: Tracev((stderr, "inflate: stored end\n")); Chris@43: state->mode = TYPE; Chris@43: break; Chris@43: Chris@43: case TABLE: Chris@43: /* get dynamic table entries descriptor */ Chris@43: NEEDBITS(14); Chris@43: state->nlen = BITS(5) + 257; Chris@43: DROPBITS(5); Chris@43: state->ndist = BITS(5) + 1; Chris@43: DROPBITS(5); Chris@43: state->ncode = BITS(4) + 4; Chris@43: DROPBITS(4); Chris@43: #ifndef PKZIP_BUG_WORKAROUND Chris@43: if (state->nlen > 286 || state->ndist > 30) { Chris@43: strm->msg = (char *)"too many length or distance symbols"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: #endif Chris@43: Tracev((stderr, "inflate: table sizes ok\n")); Chris@43: Chris@43: /* get code length code lengths (not a typo) */ Chris@43: state->have = 0; Chris@43: while (state->have < state->ncode) { Chris@43: NEEDBITS(3); Chris@43: state->lens[order[state->have++]] = (unsigned short)BITS(3); Chris@43: DROPBITS(3); Chris@43: } Chris@43: while (state->have < 19) Chris@43: state->lens[order[state->have++]] = 0; Chris@43: state->next = state->codes; Chris@43: state->lencode = (code const FAR *)(state->next); Chris@43: state->lenbits = 7; Chris@43: ret = inflate_table(CODES, state->lens, 19, &(state->next), Chris@43: &(state->lenbits), state->work); Chris@43: if (ret) { Chris@43: strm->msg = (char *)"invalid code lengths set"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: Tracev((stderr, "inflate: code lengths ok\n")); Chris@43: Chris@43: /* get length and distance code code lengths */ Chris@43: state->have = 0; Chris@43: while (state->have < state->nlen + state->ndist) { Chris@43: for (;;) { Chris@43: here = state->lencode[BITS(state->lenbits)]; Chris@43: if ((unsigned)(here.bits) <= bits) break; Chris@43: PULLBYTE(); Chris@43: } Chris@43: if (here.val < 16) { Chris@43: DROPBITS(here.bits); Chris@43: state->lens[state->have++] = here.val; Chris@43: } Chris@43: else { Chris@43: if (here.val == 16) { Chris@43: NEEDBITS(here.bits + 2); Chris@43: DROPBITS(here.bits); Chris@43: if (state->have == 0) { Chris@43: strm->msg = (char *)"invalid bit length repeat"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: len = (unsigned)(state->lens[state->have - 1]); Chris@43: copy = 3 + BITS(2); Chris@43: DROPBITS(2); Chris@43: } Chris@43: else if (here.val == 17) { Chris@43: NEEDBITS(here.bits + 3); Chris@43: DROPBITS(here.bits); Chris@43: len = 0; Chris@43: copy = 3 + BITS(3); Chris@43: DROPBITS(3); Chris@43: } Chris@43: else { Chris@43: NEEDBITS(here.bits + 7); Chris@43: DROPBITS(here.bits); Chris@43: len = 0; Chris@43: copy = 11 + BITS(7); Chris@43: DROPBITS(7); Chris@43: } Chris@43: if (state->have + copy > state->nlen + state->ndist) { Chris@43: strm->msg = (char *)"invalid bit length repeat"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: while (copy--) Chris@43: state->lens[state->have++] = (unsigned short)len; Chris@43: } Chris@43: } Chris@43: Chris@43: /* handle error breaks in while */ Chris@43: if (state->mode == BAD) break; Chris@43: Chris@43: /* check for end-of-block code (better have one) */ Chris@43: if (state->lens[256] == 0) { Chris@43: strm->msg = (char *)"invalid code -- missing end-of-block"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: Chris@43: /* build code tables -- note: do not change the lenbits or distbits Chris@43: values here (9 and 6) without reading the comments in inftrees.h Chris@43: concerning the ENOUGH constants, which depend on those values */ Chris@43: state->next = state->codes; Chris@43: state->lencode = (code const FAR *)(state->next); Chris@43: state->lenbits = 9; Chris@43: ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), Chris@43: &(state->lenbits), state->work); Chris@43: if (ret) { Chris@43: strm->msg = (char *)"invalid literal/lengths set"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: state->distcode = (code const FAR *)(state->next); Chris@43: state->distbits = 6; Chris@43: ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, Chris@43: &(state->next), &(state->distbits), state->work); Chris@43: if (ret) { Chris@43: strm->msg = (char *)"invalid distances set"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: Tracev((stderr, "inflate: codes ok\n")); Chris@43: state->mode = LEN; Chris@43: Chris@43: case LEN: Chris@43: /* use inflate_fast() if we have enough input and output */ Chris@43: if (have >= 6 && left >= 258) { Chris@43: RESTORE(); Chris@43: if (state->whave < state->wsize) Chris@43: state->whave = state->wsize - left; Chris@43: inflate_fast(strm, state->wsize); Chris@43: LOAD(); Chris@43: break; Chris@43: } Chris@43: Chris@43: /* get a literal, length, or end-of-block code */ Chris@43: for (;;) { Chris@43: here = state->lencode[BITS(state->lenbits)]; Chris@43: if ((unsigned)(here.bits) <= bits) break; Chris@43: PULLBYTE(); Chris@43: } Chris@43: if (here.op && (here.op & 0xf0) == 0) { Chris@43: last = here; Chris@43: for (;;) { Chris@43: here = state->lencode[last.val + Chris@43: (BITS(last.bits + last.op) >> last.bits)]; Chris@43: if ((unsigned)(last.bits + here.bits) <= bits) break; Chris@43: PULLBYTE(); Chris@43: } Chris@43: DROPBITS(last.bits); Chris@43: } Chris@43: DROPBITS(here.bits); Chris@43: state->length = (unsigned)here.val; Chris@43: Chris@43: /* process literal */ Chris@43: if (here.op == 0) { Chris@43: Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Chris@43: "inflate: literal '%c'\n" : Chris@43: "inflate: literal 0x%02x\n", here.val)); Chris@43: ROOM(); Chris@43: *put++ = (unsigned char)(state->length); Chris@43: left--; Chris@43: state->mode = LEN; Chris@43: break; Chris@43: } Chris@43: Chris@43: /* process end of block */ Chris@43: if (here.op & 32) { Chris@43: Tracevv((stderr, "inflate: end of block\n")); Chris@43: state->mode = TYPE; Chris@43: break; Chris@43: } Chris@43: Chris@43: /* invalid code */ Chris@43: if (here.op & 64) { Chris@43: strm->msg = (char *)"invalid literal/length code"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: Chris@43: /* length code -- get extra bits, if any */ Chris@43: state->extra = (unsigned)(here.op) & 15; Chris@43: if (state->extra != 0) { Chris@43: NEEDBITS(state->extra); Chris@43: state->length += BITS(state->extra); Chris@43: DROPBITS(state->extra); Chris@43: } Chris@43: Tracevv((stderr, "inflate: length %u\n", state->length)); Chris@43: Chris@43: /* get distance code */ Chris@43: for (;;) { Chris@43: here = state->distcode[BITS(state->distbits)]; Chris@43: if ((unsigned)(here.bits) <= bits) break; Chris@43: PULLBYTE(); Chris@43: } Chris@43: if ((here.op & 0xf0) == 0) { Chris@43: last = here; Chris@43: for (;;) { Chris@43: here = state->distcode[last.val + Chris@43: (BITS(last.bits + last.op) >> last.bits)]; Chris@43: if ((unsigned)(last.bits + here.bits) <= bits) break; Chris@43: PULLBYTE(); Chris@43: } Chris@43: DROPBITS(last.bits); Chris@43: } Chris@43: DROPBITS(here.bits); Chris@43: if (here.op & 64) { Chris@43: strm->msg = (char *)"invalid distance code"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: state->offset = (unsigned)here.val; Chris@43: Chris@43: /* get distance extra bits, if any */ Chris@43: state->extra = (unsigned)(here.op) & 15; Chris@43: if (state->extra != 0) { Chris@43: NEEDBITS(state->extra); Chris@43: state->offset += BITS(state->extra); Chris@43: DROPBITS(state->extra); Chris@43: } Chris@43: if (state->offset > state->wsize - (state->whave < state->wsize ? Chris@43: left : 0)) { Chris@43: strm->msg = (char *)"invalid distance too far back"; Chris@43: state->mode = BAD; Chris@43: break; Chris@43: } Chris@43: Tracevv((stderr, "inflate: distance %u\n", state->offset)); Chris@43: Chris@43: /* copy match from window to output */ Chris@43: do { Chris@43: ROOM(); Chris@43: copy = state->wsize - state->offset; Chris@43: if (copy < left) { Chris@43: from = put + copy; Chris@43: copy = left - copy; Chris@43: } Chris@43: else { Chris@43: from = put - state->offset; Chris@43: copy = left; Chris@43: } Chris@43: if (copy > state->length) copy = state->length; Chris@43: state->length -= copy; Chris@43: left -= copy; Chris@43: do { Chris@43: *put++ = *from++; Chris@43: } while (--copy); Chris@43: } while (state->length != 0); Chris@43: break; Chris@43: Chris@43: case DONE: Chris@43: /* inflate stream terminated properly -- write leftover output */ Chris@43: ret = Z_STREAM_END; Chris@43: if (left < state->wsize) { Chris@43: if (out(out_desc, state->window, state->wsize - left)) Chris@43: ret = Z_BUF_ERROR; Chris@43: } Chris@43: goto inf_leave; Chris@43: Chris@43: case BAD: Chris@43: ret = Z_DATA_ERROR; Chris@43: goto inf_leave; Chris@43: Chris@43: default: /* can't happen, but makes compilers happy */ Chris@43: ret = Z_STREAM_ERROR; Chris@43: goto inf_leave; Chris@43: } Chris@43: Chris@43: /* Return unused input */ Chris@43: inf_leave: Chris@43: strm->next_in = next; Chris@43: strm->avail_in = have; Chris@43: return ret; Chris@43: } Chris@43: Chris@43: int ZEXPORT inflateBackEnd(strm) Chris@43: z_streamp strm; Chris@43: { Chris@43: if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) Chris@43: return Z_STREAM_ERROR; Chris@43: ZFREE(strm, strm->state); Chris@43: strm->state = Z_NULL; Chris@43: Tracev((stderr, "inflate: end\n")); Chris@43: return Z_OK; Chris@43: }