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