zlib 0.79

This commit is contained in:
Mark Adler
2011-09-09 22:52:17 -07:00
parent bcf78a2097
commit 913afb9174
23 changed files with 559 additions and 140 deletions

View File

@@ -25,10 +25,6 @@ struct internal_state {
ERROR} /* got an error--stay here */
mode; /* current inflate mode */
int no_header;
uInt w_size; /* LZ77 window size (32K by default) */
uInt w_bits; /* log2(w_size) (8..16) */
/* mode dependent information */
union {
uInt method; /* if FLAGS, method byte */
@@ -39,19 +35,26 @@ struct internal_state {
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
} sub; /* submode */
/* mode independent information */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
};
int inflateInit (strm)
z_stream *strm;
int inflateInit(z)
z_stream *z;
{
return inflateInit2(strm, WBITS);
return inflateInit2(z, WBITS);
}
int inflateInit2(z, windowBits)
int inflateInit2(z, w)
z_stream *z;
int windowBits;
int w;
{
/* initialize state */
if (z == Z_NULL)
return Z_STREAM_ERROR;
if (z->zalloc == Z_NULL) z->zalloc = zcalloc;
@@ -63,19 +66,22 @@ int windowBits;
return Z_MEM_ERROR;
z->state->mode = METHOD;
z->state->no_header = 0;
if (windowBits < 0) { /* undocumented feature: no zlib header */
windowBits = - windowBits;
z->state->no_header = 1;
z->state->sub.method = DEFLATED;
/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
if (w < 0)
{
w = - w;
z->state->nowrap = 1;
z->state->mode = START;
}
if (windowBits < 8 || windowBits > 15) {
/* set window size */
if (w < 8 || w > 15)
{
inflateEnd(z);
return Z_STREAM_ERROR;
}
z->state->w_bits = windowBits;
z->state->w_size = 1<<windowBits;
z->state->wbits = w;
return Z_OK;
}
@@ -103,7 +109,7 @@ int f;
z->msg = "unknown compression method";
return Z_DATA_ERROR;
}
if ((z->state->sub.method >> 4) > z->state->w_bits)
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
{
z->state->mode = ERROR;
z->msg = "invalid window size";
@@ -126,17 +132,21 @@ int f;
}
z->state->mode = START;
case START:
if ((z->state->sub.blocks = inflate_blocks_new(z,z->state->w_size))
== Z_NULL)
if ((z->state->sub.blocks = inflate_blocks_new(z,
z->state->nowrap ? Z_NULL : adler32,
1<< z->state->wbits)) == Z_NULL)
return Z_MEM_ERROR;
z->state->mode = BLOCKS;
case BLOCKS:
if ((r = inflate_blocks(z->state->sub.blocks, z, r)) != Z_STREAM_END)
return r;
inflate_blocks_free(z->state->sub.blocks, z, &c, &r);
if (z->state->no_header) {
z->state->mode = DONE;
return Z_STREAM_END;
if (z->state->nowrap)
{
if (r != -1)
z->msg = "inflate bug--took one too many bytes";
z->state->mode = r == -1 ? DONE : ERROR;
break;
}
z->state->sub.check.was = c;
if (r != -1)