1592N/A/*
1592N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1592N/A *
1592N/A * This code is free software; you can redistribute it and/or modify it
1592N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1592N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1592N/A *
1592N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1592N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1592N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1592N/A * version 2 for more details (a copy is included in the LICENSE file that
1592N/A * accompanied this code).
1592N/A *
1592N/A * You should have received a copy of the GNU General Public License version
1592N/A * 2 along with this work; if not, write to the Free Software Foundation,
1592N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1592N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1592N/A */
1592N/A
1592N/A/* infback.c -- inflate using a call-back interface
1592N/A * Copyright (C) 1995-2005 Mark Adler
1592N/A * For conditions of distribution and use, see copyright notice in zlib.h
1592N/A */
1592N/A
1592N/A/*
1592N/A This code is largely copied from inflate.c. Normally either infback.o or
1592N/A inflate.o would be linked into an application--not both. The interface
1592N/A with inffast.c is retained so that optimized assembler-coded versions of
1592N/A inflate_fast() can be used with either inflate.c or infback.c.
1592N/A */
1592N/A
1592N/A#include "zutil.h"
1592N/A#include "inftrees.h"
1592N/A#include "inflate.h"
1592N/A#include "inffast.h"
1592N/A
1592N/A/* function prototypes */
1592N/Alocal void fixedtables OF((struct inflate_state FAR *state));
1592N/A
1592N/A/*
1592N/A strm provides memory allocation functions in zalloc and zfree, or
1592N/A Z_NULL to use the library memory allocation functions.
1592N/A
1592N/A windowBits is in the range 8..15, and window is a user-supplied
1592N/A window and output buffer that is 2**windowBits bytes.
1592N/A */
1592N/Aint ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
1592N/Az_streamp strm;
1592N/Aint windowBits;
1592N/Aunsigned char FAR *window;
1592N/Aconst char *version;
1592N/Aint stream_size;
1592N/A{
1592N/A struct inflate_state FAR *state;
1592N/A
1592N/A if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
1592N/A stream_size != (int)(sizeof(z_stream)))
1592N/A return Z_VERSION_ERROR;
1592N/A if (strm == Z_NULL || window == Z_NULL ||
1592N/A windowBits < 8 || windowBits > 15)
1592N/A return Z_STREAM_ERROR;
1592N/A strm->msg = Z_NULL; /* in case we return an error */
1592N/A if (strm->zalloc == (alloc_func)0) {
1592N/A strm->zalloc = zcalloc;
1592N/A strm->opaque = (voidpf)0;
1592N/A }
1592N/A if (strm->zfree == (free_func)0) strm->zfree = zcfree;
1592N/A state = (struct inflate_state FAR *)ZALLOC(strm, 1,
1592N/A sizeof(struct inflate_state));
1592N/A if (state == Z_NULL) return Z_MEM_ERROR;
1592N/A Tracev((stderr, "inflate: allocated\n"));
1592N/A strm->state = (struct internal_state FAR *)state;
1592N/A state->dmax = 32768U;
1592N/A state->wbits = windowBits;
1592N/A state->wsize = 1U << windowBits;
1592N/A state->window = window;
1592N/A state->write = 0;
1592N/A state->whave = 0;
1592N/A return Z_OK;
1592N/A}
1592N/A
1592N/A/*
1592N/A Return state with length and distance decoding tables and index sizes set to
1592N/A fixed code decoding. Normally this returns fixed tables from inffixed.h.
1592N/A If BUILDFIXED is defined, then instead this routine builds the tables the
1592N/A first time it's called, and returns those tables the first time and
1592N/A thereafter. This reduces the size of the code by about 2K bytes, in
1592N/A exchange for a little execution time. However, BUILDFIXED should not be
1592N/A used for threaded applications, since the rewriting of the tables and virgin
1592N/A may not be thread-safe.
1592N/A */
1592N/Alocal void fixedtables(state)
1592N/Astruct inflate_state FAR *state;
1592N/A{
1592N/A#ifdef BUILDFIXED
1592N/A static int virgin = 1;
1592N/A static code *lenfix, *distfix;
1592N/A static code fixed[544];
1592N/A
1592N/A /* build fixed huffman tables if first call (may not be thread safe) */
1592N/A if (virgin) {
1592N/A unsigned sym, bits;
1592N/A static code *next;
1592N/A
1592N/A /* literal/length table */
1592N/A sym = 0;
1592N/A while (sym < 144) state->lens[sym++] = 8;
1592N/A while (sym < 256) state->lens[sym++] = 9;
1592N/A while (sym < 280) state->lens[sym++] = 7;
1592N/A while (sym < 288) state->lens[sym++] = 8;
1592N/A next = fixed;
1592N/A lenfix = next;
1592N/A bits = 9;
1592N/A inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
1592N/A
1592N/A /* distance table */
1592N/A sym = 0;
1592N/A while (sym < 32) state->lens[sym++] = 5;
1592N/A distfix = next;
1592N/A bits = 5;
1592N/A inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
1592N/A
1592N/A /* do this just once */
1592N/A virgin = 0;
1592N/A }
1592N/A#else /* !BUILDFIXED */
1592N/A# include "inffixed.h"
1592N/A#endif /* BUILDFIXED */
1592N/A state->lencode = lenfix;
1592N/A state->lenbits = 9;
1592N/A state->distcode = distfix;
1592N/A state->distbits = 5;
1592N/A}
1592N/A
1592N/A/* Macros for inflateBack(): */
1592N/A
1592N/A/* Load returned state from inflate_fast() */
1592N/A#define LOAD() \
1592N/A do { \
1592N/A put = strm->next_out; \
1592N/A left = strm->avail_out; \
1592N/A next = strm->next_in; \
1592N/A have = strm->avail_in; \
1592N/A hold = state->hold; \
1592N/A bits = state->bits; \
1592N/A } while (0)
1592N/A
1592N/A/* Set state from registers for inflate_fast() */
1592N/A#define RESTORE() \
1592N/A do { \
1592N/A strm->next_out = put; \
1592N/A strm->avail_out = left; \
1592N/A strm->next_in = next; \
1592N/A strm->avail_in = have; \
1592N/A state->hold = hold; \
1592N/A state->bits = bits; \
1592N/A } while (0)
1592N/A
1592N/A/* Clear the input bit accumulator */
1592N/A#define INITBITS() \
1592N/A do { \
1592N/A hold = 0; \
1592N/A bits = 0; \
1592N/A } while (0)
1592N/A
1592N/A/* Assure that some input is available. If input is requested, but denied,
1592N/A then return a Z_BUF_ERROR from inflateBack(). */
1592N/A#define PULL() \
1592N/A do { \
1592N/A if (have == 0) { \
1592N/A have = in(in_desc, &next); \
1592N/A if (have == 0) { \
1592N/A next = Z_NULL; \
1592N/A ret = Z_BUF_ERROR; \
1592N/A goto inf_leave; \
1592N/A } \
1592N/A } \
1592N/A } while (0)
1592N/A
1592N/A/* Get a byte of input into the bit accumulator, or return from inflateBack()
1592N/A with an error if there is no input available. */
1592N/A#define PULLBYTE() \
1592N/A do { \
1592N/A PULL(); \
1592N/A have--; \
1592N/A hold += (unsigned long)(*next++) << bits; \
1592N/A bits += 8; \
1592N/A } while (0)
1592N/A
1592N/A/* Assure that there are at least n bits in the bit accumulator. If there is
1592N/A not enough available input to do that, then return from inflateBack() with
1592N/A an error. */
1592N/A#define NEEDBITS(n) \
1592N/A do { \
1592N/A while (bits < (unsigned)(n)) \
1592N/A PULLBYTE(); \
1592N/A } while (0)
1592N/A
1592N/A/* Return the low n bits of the bit accumulator (n < 16) */
1592N/A#define BITS(n) \
1592N/A ((unsigned)hold & ((1U << (n)) - 1))
1592N/A
1592N/A/* Remove n bits from the bit accumulator */
1592N/A#define DROPBITS(n) \
1592N/A do { \
1592N/A hold >>= (n); \
1592N/A bits -= (unsigned)(n); \
1592N/A } while (0)
1592N/A
1592N/A/* Remove zero to seven bits as needed to go to a byte boundary */
1592N/A#define BYTEBITS() \
1592N/A do { \
1592N/A hold >>= bits & 7; \
1592N/A bits -= bits & 7; \
1592N/A } while (0)
1592N/A
1592N/A/* Assure that some output space is available, by writing out the window
1592N/A if it's full. If the write fails, return from inflateBack() with a
1592N/A Z_BUF_ERROR. */
1592N/A#define ROOM() \
1592N/A do { \
1592N/A if (left == 0) { \
1592N/A put = state->window; \
1592N/A left = state->wsize; \
1592N/A state->whave = left; \
1592N/A if (out(out_desc, put, left)) { \
1592N/A ret = Z_BUF_ERROR; \
1592N/A goto inf_leave; \
1592N/A } \
1592N/A } \
1592N/A } while (0)
1592N/A
1592N/A/*
1592N/A strm provides the memory allocation functions and window buffer on input,
1592N/A and provides information on the unused input on return. For Z_DATA_ERROR
1592N/A returns, strm will also provide an error message.
1592N/A
1592N/A in() and out() are the call-back input and output functions. When
1592N/A inflateBack() needs more input, it calls in(). When inflateBack() has
1592N/A filled the window with output, or when it completes with data in the
1592N/A window, it calls out() to write out the data. The application must not
1592N/A change the provided input until in() is called again or inflateBack()
1592N/A returns. The application must not change the window/output buffer until
1592N/A inflateBack() returns.
1592N/A
1592N/A in() and out() are called with a descriptor parameter provided in the
1592N/A inflateBack() call. This parameter can be a structure that provides the
1592N/A information required to do the read or write, as well as accumulated
1592N/A information on the input and output such as totals and check values.
1592N/A
1592N/A in() should return zero on failure. out() should return non-zero on
1592N/A failure. If either in() or out() fails, than inflateBack() returns a
1592N/A Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
1592N/A was in() or out() that caused in the error. Otherwise, inflateBack()
1592N/A returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
1592N/A error, or Z_MEM_ERROR if it could not allocate memory for the state.
1592N/A inflateBack() can also return Z_STREAM_ERROR if the input parameters
1592N/A are not correct, i.e. strm is Z_NULL or the state was not initialized.
1592N/A */
1592N/Aint ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
1592N/Az_streamp strm;
1592N/Ain_func in;
1592N/Avoid FAR *in_desc;
1592N/Aout_func out;
1592N/Avoid FAR *out_desc;
1592N/A{
1592N/A struct inflate_state FAR *state;
1592N/A unsigned char FAR *next; /* next input */
1592N/A unsigned char FAR *put; /* next output */
1592N/A unsigned have, left; /* available input and output */
1592N/A unsigned long hold; /* bit buffer */
1592N/A unsigned bits; /* bits in bit buffer */
1592N/A unsigned copy; /* number of stored or match bytes to copy */
1592N/A unsigned char FAR *from; /* where to copy match bytes from */
1592N/A code this; /* current decoding table entry */
1592N/A code last; /* parent table entry */
1592N/A unsigned len; /* length to copy for repeats, bits to drop */
1592N/A int ret; /* return code */
1592N/A static const unsigned short order[19] = /* permutation of code lengths */
1592N/A {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
1592N/A
1592N/A /* Check that the strm exists and that the state was initialized */
1592N/A if (strm == Z_NULL || strm->state == Z_NULL)
1592N/A return Z_STREAM_ERROR;
1592N/A state = (struct inflate_state FAR *)strm->state;
1592N/A
1592N/A /* Reset the state */
1592N/A strm->msg = Z_NULL;
1592N/A state->mode = TYPE;
1592N/A state->last = 0;
1592N/A state->whave = 0;
1592N/A next = strm->next_in;
1592N/A have = next != Z_NULL ? strm->avail_in : 0;
1592N/A hold = 0;
1592N/A bits = 0;
1592N/A put = state->window;
1592N/A left = state->wsize;
1592N/A
1592N/A /* Inflate until end of block marked as last */
1592N/A for (;;)
1592N/A switch (state->mode) {
1592N/A case TYPE:
1592N/A /* determine and dispatch block type */
1592N/A if (state->last) {
1592N/A BYTEBITS();
1592N/A state->mode = DONE;
1592N/A break;
1592N/A }
1592N/A NEEDBITS(3);
1592N/A state->last = BITS(1);
1592N/A DROPBITS(1);
1592N/A switch (BITS(2)) {
1592N/A case 0: /* stored block */
1592N/A Tracev((stderr, "inflate: stored block%s\n",
1592N/A state->last ? " (last)" : ""));
1592N/A state->mode = STORED;
1592N/A break;
1592N/A case 1: /* fixed block */
1592N/A fixedtables(state);
1592N/A Tracev((stderr, "inflate: fixed codes block%s\n",
1592N/A state->last ? " (last)" : ""));
1592N/A state->mode = LEN; /* decode codes */
1592N/A break;
1592N/A case 2: /* dynamic block */
1592N/A Tracev((stderr, "inflate: dynamic codes block%s\n",
1592N/A state->last ? " (last)" : ""));
1592N/A state->mode = TABLE;
1592N/A break;
1592N/A case 3:
1592N/A strm->msg = (char *)"invalid block type";
1592N/A state->mode = BAD;
1592N/A }
1592N/A DROPBITS(2);
1592N/A break;
1592N/A
1592N/A case STORED:
1592N/A /* get and verify stored block length */
1592N/A BYTEBITS(); /* go to byte boundary */
1592N/A NEEDBITS(32);
1592N/A if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
1592N/A strm->msg = (char *)"invalid stored block lengths";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A state->length = (unsigned)hold & 0xffff;
1592N/A Tracev((stderr, "inflate: stored length %u\n",
1592N/A state->length));
1592N/A INITBITS();
1592N/A
1592N/A /* copy stored block from input to output */
1592N/A while (state->length != 0) {
1592N/A copy = state->length;
1592N/A PULL();
1592N/A ROOM();
1592N/A if (copy > have) copy = have;
1592N/A if (copy > left) copy = left;
1592N/A zmemcpy(put, next, copy);
1592N/A have -= copy;
1592N/A next += copy;
1592N/A left -= copy;
1592N/A put += copy;
1592N/A state->length -= copy;
1592N/A }
1592N/A Tracev((stderr, "inflate: stored end\n"));
1592N/A state->mode = TYPE;
1592N/A break;
1592N/A
1592N/A case TABLE:
1592N/A /* get dynamic table entries descriptor */
1592N/A NEEDBITS(14);
1592N/A state->nlen = BITS(5) + 257;
1592N/A DROPBITS(5);
1592N/A state->ndist = BITS(5) + 1;
1592N/A DROPBITS(5);
1592N/A state->ncode = BITS(4) + 4;
1592N/A DROPBITS(4);
1592N/A#ifndef PKZIP_BUG_WORKAROUND
1592N/A if (state->nlen > 286 || state->ndist > 30) {
1592N/A strm->msg = (char *)"too many length or distance symbols";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A#endif
1592N/A Tracev((stderr, "inflate: table sizes ok\n"));
1592N/A
1592N/A /* get code length code lengths (not a typo) */
1592N/A state->have = 0;
1592N/A while (state->have < state->ncode) {
1592N/A NEEDBITS(3);
1592N/A state->lens[order[state->have++]] = (unsigned short)BITS(3);
1592N/A DROPBITS(3);
1592N/A }
1592N/A while (state->have < 19)
1592N/A state->lens[order[state->have++]] = 0;
1592N/A state->next = state->codes;
1592N/A state->lencode = (code const FAR *)(state->next);
1592N/A state->lenbits = 7;
1592N/A ret = inflate_table(CODES, state->lens, 19, &(state->next),
1592N/A &(state->lenbits), state->work);
1592N/A if (ret) {
1592N/A strm->msg = (char *)"invalid code lengths set";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A Tracev((stderr, "inflate: code lengths ok\n"));
1592N/A
1592N/A /* get length and distance code code lengths */
1592N/A state->have = 0;
1592N/A while (state->have < state->nlen + state->ndist) {
1592N/A for (;;) {
1592N/A this = state->lencode[BITS(state->lenbits)];
1592N/A if ((unsigned)(this.bits) <= bits) break;
1592N/A PULLBYTE();
1592N/A }
1592N/A if (this.val < 16) {
1592N/A NEEDBITS(this.bits);
1592N/A DROPBITS(this.bits);
1592N/A state->lens[state->have++] = this.val;
1592N/A }
1592N/A else {
1592N/A if (this.val == 16) {
1592N/A NEEDBITS(this.bits + 2);
1592N/A DROPBITS(this.bits);
1592N/A if (state->have == 0) {
1592N/A strm->msg = (char *)"invalid bit length repeat";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A len = (unsigned)(state->lens[state->have - 1]);
1592N/A copy = 3 + BITS(2);
1592N/A DROPBITS(2);
1592N/A }
1592N/A else if (this.val == 17) {
1592N/A NEEDBITS(this.bits + 3);
1592N/A DROPBITS(this.bits);
1592N/A len = 0;
1592N/A copy = 3 + BITS(3);
1592N/A DROPBITS(3);
1592N/A }
1592N/A else {
1592N/A NEEDBITS(this.bits + 7);
1592N/A DROPBITS(this.bits);
1592N/A len = 0;
1592N/A copy = 11 + BITS(7);
1592N/A DROPBITS(7);
1592N/A }
1592N/A if (state->have + copy > state->nlen + state->ndist) {
1592N/A strm->msg = (char *)"invalid bit length repeat";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A while (copy--)
1592N/A state->lens[state->have++] = (unsigned short)len;
1592N/A }
1592N/A }
1592N/A
1592N/A /* handle error breaks in while */
1592N/A if (state->mode == BAD) break;
1592N/A
1592N/A /* build code tables */
1592N/A state->next = state->codes;
1592N/A state->lencode = (code const FAR *)(state->next);
1592N/A state->lenbits = 9;
1592N/A ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1592N/A &(state->lenbits), state->work);
1592N/A if (ret) {
1592N/A strm->msg = (char *)"invalid literal/lengths set";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A state->distcode = (code const FAR *)(state->next);
1592N/A state->distbits = 6;
1592N/A ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1592N/A &(state->next), &(state->distbits), state->work);
1592N/A if (ret) {
1592N/A strm->msg = (char *)"invalid distances set";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A Tracev((stderr, "inflate: codes ok\n"));
1592N/A state->mode = LEN;
1592N/A
1592N/A case LEN:
1592N/A /* use inflate_fast() if we have enough input and output */
1592N/A if (have >= 6 && left >= 258) {
1592N/A RESTORE();
1592N/A if (state->whave < state->wsize)
1592N/A state->whave = state->wsize - left;
1592N/A inflate_fast(strm, state->wsize);
1592N/A LOAD();
1592N/A break;
1592N/A }
1592N/A
1592N/A /* get a literal, length, or end-of-block code */
1592N/A for (;;) {
1592N/A this = state->lencode[BITS(state->lenbits)];
1592N/A if ((unsigned)(this.bits) <= bits) break;
1592N/A PULLBYTE();
1592N/A }
1592N/A if (this.op && (this.op & 0xf0) == 0) {
1592N/A last = this;
1592N/A for (;;) {
1592N/A this = state->lencode[last.val +
1592N/A (BITS(last.bits + last.op) >> last.bits)];
1592N/A if ((unsigned)(last.bits + this.bits) <= bits) break;
1592N/A PULLBYTE();
1592N/A }
1592N/A DROPBITS(last.bits);
1592N/A }
1592N/A DROPBITS(this.bits);
1592N/A state->length = (unsigned)this.val;
1592N/A
1592N/A /* process literal */
1592N/A if (this.op == 0) {
1592N/A Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
1592N/A "inflate: literal '%c'\n" :
1592N/A "inflate: literal 0x%02x\n", this.val));
1592N/A ROOM();
1592N/A *put++ = (unsigned char)(state->length);
1592N/A left--;
1592N/A state->mode = LEN;
1592N/A break;
1592N/A }
1592N/A
1592N/A /* process end of block */
1592N/A if (this.op & 32) {
1592N/A Tracevv((stderr, "inflate: end of block\n"));
1592N/A state->mode = TYPE;
1592N/A break;
1592N/A }
1592N/A
1592N/A /* invalid code */
1592N/A if (this.op & 64) {
1592N/A strm->msg = (char *)"invalid literal/length code";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A
1592N/A /* length code -- get extra bits, if any */
1592N/A state->extra = (unsigned)(this.op) & 15;
1592N/A if (state->extra != 0) {
1592N/A NEEDBITS(state->extra);
1592N/A state->length += BITS(state->extra);
1592N/A DROPBITS(state->extra);
1592N/A }
1592N/A Tracevv((stderr, "inflate: length %u\n", state->length));
1592N/A
1592N/A /* get distance code */
1592N/A for (;;) {
1592N/A this = state->distcode[BITS(state->distbits)];
1592N/A if ((unsigned)(this.bits) <= bits) break;
1592N/A PULLBYTE();
1592N/A }
1592N/A if ((this.op & 0xf0) == 0) {
1592N/A last = this;
1592N/A for (;;) {
1592N/A this = state->distcode[last.val +
1592N/A (BITS(last.bits + last.op) >> last.bits)];
1592N/A if ((unsigned)(last.bits + this.bits) <= bits) break;
1592N/A PULLBYTE();
1592N/A }
1592N/A DROPBITS(last.bits);
1592N/A }
1592N/A DROPBITS(this.bits);
1592N/A if (this.op & 64) {
1592N/A strm->msg = (char *)"invalid distance code";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A state->offset = (unsigned)this.val;
1592N/A
1592N/A /* get distance extra bits, if any */
1592N/A state->extra = (unsigned)(this.op) & 15;
1592N/A if (state->extra != 0) {
1592N/A NEEDBITS(state->extra);
1592N/A state->offset += BITS(state->extra);
1592N/A DROPBITS(state->extra);
1592N/A }
1592N/A if (state->offset > state->wsize - (state->whave < state->wsize ?
1592N/A left : 0)) {
1592N/A strm->msg = (char *)"invalid distance too far back";
1592N/A state->mode = BAD;
1592N/A break;
1592N/A }
1592N/A Tracevv((stderr, "inflate: distance %u\n", state->offset));
1592N/A
1592N/A /* copy match from window to output */
1592N/A do {
1592N/A ROOM();
1592N/A copy = state->wsize - state->offset;
1592N/A if (copy < left) {
1592N/A from = put + copy;
1592N/A copy = left - copy;
1592N/A }
1592N/A else {
1592N/A from = put - state->offset;
1592N/A copy = left;
1592N/A }
1592N/A if (copy > state->length) copy = state->length;
1592N/A state->length -= copy;
1592N/A left -= copy;
1592N/A do {
1592N/A *put++ = *from++;
1592N/A } while (--copy);
1592N/A } while (state->length != 0);
1592N/A break;
1592N/A
1592N/A case DONE:
1592N/A /* inflate stream terminated properly -- write leftover output */
1592N/A ret = Z_STREAM_END;
1592N/A if (left < state->wsize) {
1592N/A if (out(out_desc, state->window, state->wsize - left))
1592N/A ret = Z_BUF_ERROR;
1592N/A }
1592N/A goto inf_leave;
1592N/A
1592N/A case BAD:
1592N/A ret = Z_DATA_ERROR;
1592N/A goto inf_leave;
1592N/A
1592N/A default: /* can't happen, but makes compilers happy */
1592N/A ret = Z_STREAM_ERROR;
1592N/A goto inf_leave;
1592N/A }
1592N/A
1592N/A /* Return unused input */
1592N/A inf_leave:
1592N/A strm->next_in = next;
1592N/A strm->avail_in = have;
1592N/A return ret;
1592N/A}
1592N/A
1592N/Aint ZEXPORT inflateBackEnd(strm)
1592N/Az_streamp strm;
1592N/A{
1592N/A if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1592N/A return Z_STREAM_ERROR;
1592N/A ZFREE(strm, strm->state);
1592N/A strm->state = Z_NULL;
1592N/A Tracev((stderr, "inflate: end\n"));
1592N/A return Z_OK;
1592N/A}