zlib 1.2.3.6
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* gun.c -- simple gunzip to give an example of the use of inflateBack()
|
||||
* Copyright (C) 2003, 2005 Mark Adler
|
||||
* Copyright (C) 2003, 2005, 2008, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
Version 1.3 12 June 2005 Mark Adler */
|
||||
Version 1.6 17 January 2010 Mark Adler */
|
||||
|
||||
/* Version history:
|
||||
1.0 16 Feb 2003 First version for testing of inflateBack()
|
||||
@@ -15,6 +15,9 @@
|
||||
1.2 20 Mar 2005 Add Unix compress (LZW) decompression
|
||||
Copy file attributes from input file to output file
|
||||
1.3 12 Jun 2005 Add casts for error messages [Oberhumer]
|
||||
1.4 8 Dec 2006 LZW decompression speed improvements
|
||||
1.5 9 Feb 2008 Avoid warning in latest version of gcc
|
||||
1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -197,14 +200,14 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
|
||||
int outfile, z_stream *strm)
|
||||
{
|
||||
int last; /* last byte read by NEXT(), or -1 if EOF */
|
||||
int chunk; /* bytes left in current chunk */
|
||||
unsigned chunk; /* bytes left in current chunk */
|
||||
int left; /* bits left in rem */
|
||||
unsigned rem; /* unused bits from input */
|
||||
int bits; /* current bits per code */
|
||||
unsigned code; /* code, table traversal index */
|
||||
unsigned mask; /* mask for current bits codes */
|
||||
int max; /* maximum bits per code for this stream */
|
||||
int flags; /* compress flags, then block compress flag */
|
||||
unsigned flags; /* compress flags, then block compress flag */
|
||||
unsigned end; /* last valid entry in prefix/suffix tables */
|
||||
unsigned temp; /* current code */
|
||||
unsigned prev; /* previous code */
|
||||
@@ -212,6 +215,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
|
||||
unsigned stack; /* next position for reversed string */
|
||||
unsigned outcnt; /* bytes in output buffer */
|
||||
struct outd outd; /* output structure */
|
||||
unsigned char *p;
|
||||
|
||||
/* set up output */
|
||||
outd.outfile = outfile;
|
||||
@@ -322,10 +326,12 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
|
||||
}
|
||||
|
||||
/* walk through linked list to generate output in reverse order */
|
||||
p = match + stack;
|
||||
while (code >= 256) {
|
||||
match[stack++] = suffix[code];
|
||||
*p++ = suffix[code];
|
||||
code = prefix[code];
|
||||
}
|
||||
stack = p - match;
|
||||
match[stack++] = (unsigned char)code;
|
||||
final = code;
|
||||
|
||||
@@ -349,9 +355,11 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
|
||||
}
|
||||
outcnt = 0;
|
||||
}
|
||||
p = match + stack;
|
||||
do {
|
||||
outbuf[outcnt++] = match[--stack];
|
||||
} while (stack);
|
||||
outbuf[outcnt++] = *--p;
|
||||
} while (p > match);
|
||||
stack = 0;
|
||||
|
||||
/* loop for next code with final and prev as the last match, rem and
|
||||
left provide the first 0..7 bits of the next code, end is the last
|
||||
@@ -375,7 +383,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
|
||||
{
|
||||
int ret, first, last;
|
||||
unsigned have, flags, len;
|
||||
unsigned char *next;
|
||||
unsigned char *next = NULL;
|
||||
struct ind ind, *indp;
|
||||
struct outd outd;
|
||||
|
||||
@@ -471,10 +479,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
|
||||
|
||||
/* check trailer */
|
||||
ret = Z_BUF_ERROR;
|
||||
if (NEXT() != (outd.crc & 0xff) ||
|
||||
NEXT() != ((outd.crc >> 8) & 0xff) ||
|
||||
NEXT() != ((outd.crc >> 16) & 0xff) ||
|
||||
NEXT() != ((outd.crc >> 24) & 0xff)) {
|
||||
if (NEXT() != (int)(outd.crc & 0xff) ||
|
||||
NEXT() != (int)((outd.crc >> 8) & 0xff) ||
|
||||
NEXT() != (int)((outd.crc >> 16) & 0xff) ||
|
||||
NEXT() != (int)((outd.crc >> 24) & 0xff)) {
|
||||
/* crc error */
|
||||
if (last != -1) {
|
||||
strm->msg = (char *)"incorrect data check";
|
||||
@@ -482,10 +490,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (NEXT() != (outd.total & 0xff) ||
|
||||
NEXT() != ((outd.total >> 8) & 0xff) ||
|
||||
NEXT() != ((outd.total >> 16) & 0xff) ||
|
||||
NEXT() != ((outd.total >> 24) & 0xff)) {
|
||||
if (NEXT() != (int)(outd.total & 0xff) ||
|
||||
NEXT() != (int)((outd.total >> 8) & 0xff) ||
|
||||
NEXT() != (int)((outd.total >> 16) & 0xff) ||
|
||||
NEXT() != (int)((outd.total >> 24) & 0xff)) {
|
||||
/* length error */
|
||||
if (last != -1) {
|
||||
strm->msg = (char *)"incorrect length check";
|
||||
@@ -642,8 +650,8 @@ int main(int argc, char **argv)
|
||||
argv++;
|
||||
test = 0;
|
||||
if (argc && strcmp(*argv, "-h") == 0) {
|
||||
fprintf(stderr, "gun 1.3 (12 Jun 2005)\n");
|
||||
fprintf(stderr, "Copyright (c) 2005 Mark Adler\n");
|
||||
fprintf(stderr, "gun 1.6 (17 Jan 2010)\n");
|
||||
fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n");
|
||||
fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user