1592N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1592N/A * Copyright (C) 1995-2005 Mark Adler 1592N/A * For conditions of distribution and use, see copyright notice in zlib.h 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 strm provides memory allocation functions in zalloc and zfree, or 1592N/A Z_NULL to use the library memory allocation functions. 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 Return state with length and distance decoding tables and index sizes set to 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 /* build fixed huffman tables if first call (may not be thread safe) */ 1592N/A/* Macros for inflateBack(): */ 1592N/A/* Load returned state from inflate_fast() */ 1592N/A/* Set state from registers for inflate_fast() */ 1592N/A/* Clear the input bit accumulator */ 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/* 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/* 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/* Return the low n bits of the bit accumulator (n < 16) */ 1592N/A/* Remove n bits from the bit accumulator */ 1592N/A/* Remove zero to seven bits as needed to go to a byte boundary */ 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 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 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 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 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 unsigned copy;
/* number of stored or match bytes to copy */ 1592N/A unsigned len;
/* length to copy for repeats, bits to drop */ 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 /* Check that the strm exists and that the state was initialized */ 1592N/A /* Inflate until end of block marked as last */ 1592N/A /* determine and dispatch block type */ 1592N/A case 2:
/* dynamic block */ 1592N/A /* get and verify stored block length */ 1592N/A /* copy stored block from input to output */ 1592N/A /* get dynamic table entries descriptor */ 1592N/A /* get code length code lengths (not a typo) */ 1592N/A /* get length and distance code code lengths */ 1592N/A /* handle error breaks in while */ 1592N/A /* use inflate_fast() if we have enough input and output */ 1592N/A /* get a literal, length, or end-of-block code */ 1592N/A "inflate: literal '%c'\n" :
1592N/A /* length code -- get extra bits, if any */ 1592N/A /* get distance extra bits, if any */ 1592N/A /* copy match from window to output */ 1592N/A /* inflate stream terminated properly -- write leftover output */ 1592N/A default:
/* can't happen, but makes compilers happy */