/* infback9.c -- inflate deflate64 data using a call-back interface
* Copyright (C) 1995-2008 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infback9.h"
#include "inftree9.h"
#include "inflate9.h"
/*
strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions.
window is a user-supplied window and output buffer that is 64K bytes.
*/
const char *version;
int stream_size;
{
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
return Z_STREAM_ERROR;
}
sizeof(struct inflate_state));
return Z_OK;
}
/*
Build and output length and distance decoding tables for fixed code
decoding.
*/
#ifdef MAKEFIXED
#include <stdio.h>
void makefixed9(void)
{
sym = 0;
bits = 9;
/* distance table */
sym = 0;
bits = 5;
/* write tables */
puts(" * Generated automatically by makefixed9().");
puts(" */");
puts("");
puts(" /* WARNING: this file should *not* be used by applications.");
puts(" It is part of the implementation of this library and is");
puts(" */");
puts("");
low = 0;
for (;;) {
putchar(',');
}
puts("\n };");
low = 0;
for (;;) {
putchar(',');
}
puts("\n };");
}
#endif /* MAKEFIXED */
/* Macros for inflateBack(): */
/* Clear the input bit accumulator */
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
/* Assure that some input is available. If input is requested, but denied,
then return a Z_BUF_ERROR from inflateBack(). */
#define PULL() \
do { \
if (have == 0) { \
if (have == 0) { \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/* Get a byte of input into the bit accumulator, or return from inflateBack()
with an error if there is no input available. */
#define PULLBYTE() \
do { \
PULL(); \
have--; \
bits += 8; \
} while (0)
/* Assure that there are at least n bits in the bit accumulator. If there is
not enough available input to do that, then return from inflateBack() with
an error. */
#define NEEDBITS(n) \
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
/* Return the low n bits of the bit accumulator (n <= 16) */
#define BITS(n) \
/* Remove n bits from the bit accumulator */
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
/* Remove zero to seven bits as needed to go to a byte boundary */
#define BYTEBITS() \
do { \
} while (0)
/* Assure that some output space is available, by writing out the window
if it's full. If the write fails, return from inflateBack() with a
Z_BUF_ERROR. */
#define ROOM() \
do { \
if (left == 0) { \
wrap = 1; \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
/*
strm provides the memory allocation functions and window buffer on input,
and provides information on the unused input on return. For Z_DATA_ERROR
returns, strm will also provide an error message.
in() and out() are the call-back input and output functions. When
inflateBack() needs more input, it calls in(). When inflateBack() has
filled the window with output, or when it completes with data in the
window, it calls out() to write out the data. The application must not
change the provided input until in() is called again or inflateBack()
inflateBack() returns.
in() and out() are called with a descriptor parameter provided in the
inflateBack() call. This parameter can be a structure that provides the
information required to do the read or write, as well as accumulated
information on the input and output such as totals and check values.
in() should return zero on failure. out() should return non-zero on
failure. If either in() or out() fails, than inflateBack() returns a
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
was in() or out() that caused in the error. Otherwise, inflateBack()
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
error, or Z_MEM_ERROR if it could not allocate memory for the state.
inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/
{
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
#include "inffix9.h"
/* Check that the strm exists and that the state was initialized */
return Z_STREAM_ERROR;
/* Reset the state */
lastblock = 0;
write = 0;
wrap = 0;
hold = 0;
bits = 0;
/* Inflate until end of block marked as last */
for (;;)
switch (mode) {
case TYPE:
/* determine and dispatch block type */
if (lastblock) {
BYTEBITS();
break;
}
NEEDBITS(3);
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
break;
case 1: /* fixed block */
lenbits = 9;
distbits = 5;
break;
case 2: /* dynamic block */
break;
case 3:
}
DROPBITS(2);
break;
case STORED:
/* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
break;
}
length));
INITBITS();
/* copy stored block from input to output */
while (length != 0) {
PULL();
ROOM();
}
break;
case TABLE:
/* get dynamic table entries descriptor */
NEEDBITS(14);
DROPBITS(5);
DROPBITS(5);
DROPBITS(4);
break;
}
/* get code length code lengths (not a typo) */
NEEDBITS(3);
DROPBITS(3);
}
lenbits = 7;
if (ret) {
break;
}
/* get length and distance code code lengths */
for (;;) {
PULLBYTE();
}
}
else {
break;
}
DROPBITS(2);
}
len = 0;
DROPBITS(3);
}
else {
len = 0;
DROPBITS(7);
}
break;
}
while (copy--)
}
}
/* handle error breaks in while */
/* check for end-of-block code (better have one) */
break;
}
/* build code tables -- note: do not change the lenbits or distbits
values here (9 and 6) without reading the comments in inftree9.h
concerning the ENOUGH constants, which depend on those values */
lenbits = 9;
if (ret) {
break;
}
distbits = 6;
if (ret) {
break;
}
case LEN:
/* get a literal, length, or end-of-block code */
for (;;) {
PULLBYTE();
}
for (;;) {
PULLBYTE();
}
}
/* process literal */
"inflate: literal '%c'\n" :
ROOM();
left--;
break;
}
/* process end of block */
break;
}
/* invalid code */
break;
}
/* length code -- get extra bits, if any */
if (extra != 0) {
}
/* get distance code */
for (;;) {
PULLBYTE();
}
for (;;) {
PULLBYTE();
}
}
break;
}
/* get distance extra bits, if any */
if (extra != 0) {
}
break;
}
/* copy match from window to output */
do {
ROOM();
}
else {
}
do {
} while (--copy);
} while (length != 0);
break;
case DONE:
/* inflate stream terminated properly -- write leftover output */
ret = Z_STREAM_END;
ret = Z_BUF_ERROR;
}
goto inf_leave;
case BAD:
ret = Z_DATA_ERROR;
goto inf_leave;
default: /* can't happen, but makes compilers happy */
goto inf_leave;
}
/* Return unused input */
return ret;
}
{
return Z_STREAM_ERROR;
return Z_OK;
}