Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/inflate.c view on Meta::CPAN
if ((!repeated_buf_err) && (G.dstrm.avail_in == 0)) {
/* when detecting this problem for the first time,
try to provide one fake byte beyond "EOF"... */
G.dstrm.next_in = "";
G.dstrm.avail_in = 1;
repeated_buf_err = TRUE;
} else
break;
} else if (err != Z_OK && err != Z_STREAM_END) {
Trace((stderr, "oops! (inflate(final loop) err = %d)\n", err));
DESTROYGLOBALS();
EXIT(PK_MEM3);
}
/* final flush of slide[] */
if ((retval = FLUSH(wsize - G.dstrm.avail_out)) != 0)
goto uzinflate_cleanup_exit;
Trace((stderr, "final loop: flushing %ld bytes (ptr diff = %ld)\n",
(long)(wsize - G.dstrm.avail_out),
(long)(G.dstrm.next_out-(Bytef *)redirSlide)));
G.dstrm.next_out = redirSlide;
G.dstrm.avail_out = wsize;
}
Trace((stderr, "total in = %lu, total out = %lu\n", G.dstrm.total_in,
G.dstrm.total_out));
G.inptr = (uch *)G.dstrm.next_in;
G.incnt = (G.inbuf + INBUFSIZ) - G.inptr; /* reset for other routines */
uzinflate_cleanup_exit:
err = inflateReset(&G.dstrm);
if (err != Z_OK)
Trace((stderr, "oops! (inflateReset() err = %d)\n", err));
#endif /* ?USE_ZLIB_INFLATCB */
return retval;
}
/*---------------------------------------------------------------------------*/
#else /* !USE_ZLIB */
/* Function prototypes */
#ifndef OF
# ifdef __STDC__
# define OF(a) a
# else
# define OF(a) ()
# endif
#endif /* !OF */
int inflate_codes OF((__GPRO__ struct huft *tl, struct huft *td,
unsigned bl, unsigned bd));
static int inflate_stored OF((__GPRO));
static int inflate_fixed OF((__GPRO));
static int inflate_dynamic OF((__GPRO));
static int inflate_block OF((__GPRO__ int *e));
/* The inflate algorithm uses a sliding 32K byte window on the uncompressed
stream to find repeated byte strings. This is implemented here as a
circular buffer. The index is updated simply by incrementing and then
and'ing with 0x7fff (32K-1). */
/* It is left to other modules to supply the 32K area. It is assumed
to be usable as if it were declared "uch slide[32768];" or as just
"uch *slide;" and then malloc'ed in the latter case. The definition
must be in unzip.h, included above. */
/* unsigned wp; moved to globals.h */ /* current position in slide */
/* Tables for deflate from PKZIP's appnote.txt. */
/* - Order of the bit length code lengths */
static ZCONST unsigned border[] = {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/* - Copy lengths for literal codes 257..285 */
#ifdef USE_DEFLATE64
static ZCONST ush cplens64[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 3, 0, 0};
/* For Deflate64, the code 285 is defined differently. */
#else
# define cplens32 cplens
#endif
static ZCONST ush cplens32[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
/* note: see note #13 above about the 258 in this list. */
/* - Extra bits for literal codes 257..285 */
#ifdef USE_DEFLATE64
static ZCONST uch cplext64[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 16, INVALID_CODE, INVALID_CODE};
#else
# define cplext32 cplext
#endif
static ZCONST uch cplext32[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, INVALID_CODE, INVALID_CODE};
/* - Copy offsets for distance codes 0..29 (0..31 for Deflate64) */
static ZCONST ush cpdist[] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
#if (defined(USE_DEFLATE64) || defined(PKZIP_BUG_WORKAROUND))
8193, 12289, 16385, 24577, 32769, 49153};
#else
8193, 12289, 16385, 24577};
#endif
/* - Extra bits for distance codes 0..29 (0..31 for Deflate64) */
#ifdef USE_DEFLATE64
static ZCONST uch cpdext64[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13, 14, 14};
#else
# define cpdext32 cpdext
#endif
static ZCONST uch cpdext32[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
( run in 1.622 second using v1.01-cache-2.11-cpan-97f6503c9c8 )