Bail on mmap/rsync fiddles for now.
CVS patchset: 5361 CVS date: 2002/03/17 15:46:23
This commit is contained in:
parent
3212547cb5
commit
a7266b7394
|
@ -6,15 +6,17 @@ EXTRA_DIST = algorithm.txt ChangeLog Doxyfile FAQ INDEX README \
|
|||
|
||||
BUILT_SOURCES = Doxyfile
|
||||
|
||||
# crc32.h
|
||||
noinst_HEADERS = \
|
||||
crc32.h deflate.h infblock.h infcodes.h inffast.h inffixed.h \
|
||||
deflate.h infblock.h infcodes.h inffast.h inffixed.h \
|
||||
inftrees.h infutil.h trees.h zconf.h zlib.h zutil.h
|
||||
|
||||
noinst_LTLIBRARIES = libz.la
|
||||
|
||||
libz_la_SOURCES = \
|
||||
adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \
|
||||
zutil.c inflate.c infblock.c inftrees.c infutil.c inffast.c
|
||||
adler32.c compress.c crc32.c deflate.c gzio.c \
|
||||
infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c \
|
||||
trees.c uncompr.c zutil.c
|
||||
|
||||
noinst_PROGRAMS = example minigzip
|
||||
|
||||
|
|
|
@ -91,16 +91,18 @@ EXTRA_DIST = algorithm.txt ChangeLog Doxyfile FAQ INDEX README \
|
|||
|
||||
BUILT_SOURCES = Doxyfile
|
||||
|
||||
# crc32.h
|
||||
noinst_HEADERS = \
|
||||
crc32.h deflate.h infblock.h infcodes.h inffast.h inffixed.h \
|
||||
deflate.h infblock.h infcodes.h inffast.h inffixed.h \
|
||||
inftrees.h infutil.h trees.h zconf.h zlib.h zutil.h
|
||||
|
||||
|
||||
noinst_LTLIBRARIES = libz.la
|
||||
|
||||
libz_la_SOURCES = \
|
||||
adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \
|
||||
zutil.c inflate.c infblock.c inftrees.c infutil.c inffast.c
|
||||
adler32.c compress.c crc32.c deflate.c gzio.c \
|
||||
infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c \
|
||||
trees.c uncompr.c zutil.c
|
||||
|
||||
|
||||
noinst_PROGRAMS = example minigzip
|
||||
|
@ -118,9 +120,9 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
|
|||
|
||||
libz_la_LDFLAGS =
|
||||
libz_la_LIBADD =
|
||||
am_libz_la_OBJECTS = adler32.lo compress.lo crc32.lo gzio.lo uncompr.lo \
|
||||
deflate.lo trees.lo zutil.lo inflate.lo infblock.lo inftrees.lo \
|
||||
infutil.lo inffast.lo
|
||||
am_libz_la_OBJECTS = adler32.lo compress.lo crc32.lo deflate.lo gzio.lo \
|
||||
infblock.lo infcodes.lo inffast.lo inflate.lo inftrees.lo \
|
||||
infutil.lo trees.lo uncompr.lo zutil.lo
|
||||
libz_la_OBJECTS = $(am_libz_la_OBJECTS)
|
||||
noinst_PROGRAMS = example$(EXEEXT) minigzip$(EXEEXT)
|
||||
PROGRAMS = $(noinst_PROGRAMS)
|
||||
|
@ -143,11 +145,11 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp
|
|||
@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/adler32.Plo $(DEPDIR)/compress.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/crc32.Plo $(DEPDIR)/deflate.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/example.Po $(DEPDIR)/gzio.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/infblock.Plo $(DEPDIR)/inffast.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/inflate.Plo $(DEPDIR)/inftrees.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/infutil.Plo $(DEPDIR)/minigzip.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/trees.Plo $(DEPDIR)/uncompr.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/zutil.Plo
|
||||
@AMDEP_TRUE@ $(DEPDIR)/infblock.Plo $(DEPDIR)/infcodes.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/inffast.Plo $(DEPDIR)/inflate.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/inftrees.Plo $(DEPDIR)/infutil.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/minigzip.Po $(DEPDIR)/trees.Plo \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/uncompr.Plo $(DEPDIR)/zutil.Plo
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
|
||||
|
@ -224,6 +226,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/example.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/gzio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/infblock.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/infcodes.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/inffast.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/inflate.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/inftrees.Plo@am__quote@
|
||||
|
|
|
@ -3782,7 +3782,13 @@ irix5* | irix6*)
|
|||
|
||||
# This must be Linux ELF.
|
||||
linux-gnu*)
|
||||
lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
|
||||
case $host_cpu in
|
||||
alpha* | hppa* | i*86 | powerpc* | sparc* | ia64* | s390* )
|
||||
lt_cv_deplibs_check_method=pass_all ;;
|
||||
*)
|
||||
# glibc up to 2.1.1 does not perform some relocations on ARM
|
||||
lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' ;;
|
||||
esac
|
||||
lt_cv_file_magic_test_file=`echo /lib/libc.so* /lib/libc-*.so`
|
||||
;;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: adler32.c,v 1.3 2001/12/27 21:00:17 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: compress.c,v 1.4 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
@ -10,11 +9,10 @@
|
|||
*/
|
||||
|
||||
#include "zlib.h"
|
||||
#include "zutil.h" /* XXX for zmemzero() */
|
||||
|
||||
/*@access z_streamp@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/* ========================================================================== */
|
||||
/**
|
||||
* Compresses the source buffer into the destination buffer. The level
|
||||
* parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
|
@ -26,12 +24,12 @@
|
|||
* memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
* Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
|
||||
int ZEXPORT compress2 (Bytef * dest, uLongf * destLen, const Bytef * source,
|
||||
uLong sourceLen, int level)
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
zmemzero(&stream, sizeof(stream));
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
#ifdef MAXSEG_64K
|
||||
|
@ -42,9 +40,9 @@ int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
|
|||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)NULL;
|
||||
stream.zfree = (free_func)NULL;
|
||||
stream.opaque = (voidpf)NULL;
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&stream, level);
|
||||
if (err != Z_OK) return err;
|
||||
|
@ -60,8 +58,9 @@ int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
|
|||
return err;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
|
||||
/* ========================================================================== */
|
||||
int ZEXPORT compress (Bytef * dest, uLongf * destLen, const Bytef * source,
|
||||
uLong sourceLen)
|
||||
{
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
AC_INIT(gzio.c)
|
||||
AC_CANONICAL_SYSTEM
|
||||
AM_INIT_AUTOMAKE(zlib, 1.1.3)
|
||||
AM_INIT_AUTOMAKE(zlib, 1.1.4)
|
||||
|
||||
dnl Check for programs.
|
||||
AC_PROG_CC
|
||||
|
|
34
zlib/crc32.c
34
zlib/crc32.c
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: crc32.c,v 1.6 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*@-globs@*/
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
|
@ -12,8 +11,6 @@
|
|||
|
||||
#include "zlib.h"
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
#define local static
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
@ -76,7 +73,7 @@ local void make_crc_table(void)
|
|||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by make_crc_table)
|
||||
*/
|
||||
/*local*/ const uLongf crc_table[256] = {
|
||||
local const uLongf crc_table[256] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
|
@ -143,33 +140,6 @@ const uLongf * ZEXPORT get_crc_table(void)
|
|||
return (const uLongf *)crc_table;
|
||||
}
|
||||
|
||||
#if defined(__i386__)
|
||||
|
||||
uLong partial_crc32_copy(uLong crc, const Bytef *buf, uInt len, Bytef *dst)
|
||||
{
|
||||
/*@-sysunrecog@*/
|
||||
return __partial_crc32(crc, buf, len, 1, dst);
|
||||
/*@=sysunrecog@*/
|
||||
}
|
||||
|
||||
extern uLong partial_crc32(uLong crc, const Bytef *buf, uInt len)
|
||||
{
|
||||
/*@-sysunrecog@*/
|
||||
return __partial_crc32(crc, buf, len, 0, 0);
|
||||
/*@=sysunrecog@*/
|
||||
}
|
||||
|
||||
uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len)
|
||||
{
|
||||
if (buf != Z_NULL)
|
||||
/*@-sysunrecog@*/
|
||||
return __partial_crc32(crc ^ 0xffffffffL, buf, len, 0, 0) ^ 0xffffffffL;
|
||||
/*@=sysunrecog@*/
|
||||
return 0L;
|
||||
}
|
||||
|
||||
#else /* !__i386__ */
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
||||
#define DO2(buf) DO1(buf); DO1(buf);
|
||||
|
@ -195,6 +165,4 @@ uLong ZEXPORT crc32(uLong crc, const Bytef * buf, uInt len)
|
|||
} while (--len);
|
||||
return crc ^ 0xffffffffL;
|
||||
}
|
||||
|
||||
#endif /* !__i386__ */
|
||||
/*@=globs@*/
|
||||
|
|
172
zlib/deflate.c
172
zlib/deflate.c
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: deflate.c,v 1.5 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
@ -8,6 +7,7 @@
|
|||
* \file deflate.c
|
||||
* Compress data using the deflation algorithm.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ALGORITHM
|
||||
*
|
||||
|
@ -52,7 +52,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "deflate.h"
|
||||
|
||||
/*@-exportheadervar@*/
|
||||
|
@ -103,10 +102,10 @@ local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size))
|
|||
void match_init OF((void)) /* asm code initialization */
|
||||
/*@*/;
|
||||
uInt longest_match OF((deflate_state *s, IPos cur_match))
|
||||
/*@modifies s @*/;
|
||||
/*@modifies *s @*/;
|
||||
#else
|
||||
local uInt longest_match OF((deflate_state *s, IPos cur_match))
|
||||
/*@modifies s @*/;
|
||||
/*@modifies *s @*/;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -135,20 +134,6 @@ local void check_match OF((deflate_state *s, IPos start, IPos match,
|
|||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
/*@unchecked@*/
|
||||
local int rsync = 0;
|
||||
/* Perform rsync padding? */
|
||||
|
||||
#ifndef RSYNC_WIN
|
||||
# define RSYNC_WIN 4096
|
||||
#endif
|
||||
/* Size of rsync window, must be < MAX_DIST */
|
||||
|
||||
#define RSYNC_SUM_MATCH(s) (((s)->rsync_sum % (s)->rsync_win) == 0)
|
||||
/* Whether window sum matches magic value */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Values for max_lazy_match, good_match and max_chain_length, depending on
|
||||
* the desired pack level (0..9). The values given below have been tuned to
|
||||
|
@ -186,6 +171,8 @@ local const config configuration_table[10] = {
|
|||
#define EQUAL 0
|
||||
/* result of memcmp for equal strings */
|
||||
|
||||
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Update a hash value with the given input byte.
|
||||
|
@ -229,7 +216,8 @@ local const config configuration_table[10] = {
|
|||
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
|
||||
int ZEXPORT deflateInit_(z_streamp strm, int level, const char * version,
|
||||
int stream_size)
|
||||
{
|
||||
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
|
||||
Z_DEFAULT_STRATEGY, version, stream_size);
|
||||
|
@ -237,7 +225,8 @@ int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int str
|
|||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy,
|
||||
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel, int strategy,
|
||||
const char * version, int stream_size)
|
||||
{
|
||||
deflate_state *s;
|
||||
|
@ -304,9 +293,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits,
|
|||
|
||||
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
|
||||
s->pending_buf == Z_NULL) {
|
||||
/*@-assignexpose@*/
|
||||
strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
|
||||
/*@=assignexpose@*/
|
||||
deflateEnd (strm);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
@ -321,7 +308,8 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits,
|
|||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
|
||||
int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef * dictionary,
|
||||
uInt dictLength)
|
||||
{
|
||||
deflate_state *s;
|
||||
uInt length = dictLength;
|
||||
|
@ -341,9 +329,7 @@ int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt
|
|||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||
#endif
|
||||
}
|
||||
/*@-mayaliasunique@*/ /* FIX: dictionary may alias s->window */
|
||||
zmemcpy(s->window, dictionary, length);
|
||||
/*@=mayaliasunique@*/
|
||||
s->strstart = length;
|
||||
s->block_start = (long)length;
|
||||
|
||||
|
@ -390,7 +376,6 @@ int ZEXPORT deflateReset (z_streamp strm)
|
|||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/*@-compmempass@*/
|
||||
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
|
||||
{
|
||||
deflate_state *s;
|
||||
|
@ -422,7 +407,6 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
|
|||
s->strategy = strategy;
|
||||
return err;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -462,7 +446,6 @@ local void flush_pending(z_streamp strm)
|
|||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/*@-compmempass@*/
|
||||
int ZEXPORT deflate (z_streamp strm, int flush)
|
||||
{
|
||||
int old_flush; /* value of flush param for previous deflate call */
|
||||
|
@ -477,15 +460,9 @@ int ZEXPORT deflate (z_streamp strm, int flush)
|
|||
if (strm->next_out == Z_NULL ||
|
||||
(strm->next_in == Z_NULL && strm->avail_in != 0) ||
|
||||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
|
||||
/*@-assignexpose@*/
|
||||
ERR_RETURN(strm, Z_STREAM_ERROR);
|
||||
/*@=assignexpose@*/
|
||||
}
|
||||
/*@-mods@*/
|
||||
/*@-assignexpose@*/
|
||||
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
/*@=assignexpose@*/
|
||||
/*@=mods@*/
|
||||
|
||||
s->strm = strm; /* just in case */
|
||||
old_flush = s->last_flush;
|
||||
|
@ -533,20 +510,12 @@ int ZEXPORT deflate (z_streamp strm, int flush)
|
|||
*/
|
||||
} else if (strm->avail_in == 0 && flush <= old_flush &&
|
||||
flush != Z_FINISH) {
|
||||
/*@-mods@*/
|
||||
/*@-assignexpose@*/
|
||||
ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
/*@=assignexpose@*/
|
||||
/*@=mods@*/
|
||||
}
|
||||
|
||||
/* User must not provide more input after the first FINISH: */
|
||||
if (s->status == FINISH_STATE && strm->avail_in != 0) {
|
||||
/*@-mods@*/
|
||||
/*@-assignexpose@*/
|
||||
ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
/*@=assignexpose@*/
|
||||
/*@=mods@*/
|
||||
}
|
||||
|
||||
/* Start a new block or continue the current one.
|
||||
|
@ -607,7 +576,6 @@ int ZEXPORT deflate (z_streamp strm, int flush)
|
|||
s->noheader = -1; /* write the trailer only once! */
|
||||
return s->pending != 0 ? Z_OK : Z_STREAM_END;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateEnd (z_streamp strm)
|
||||
|
@ -640,7 +608,6 @@ int ZEXPORT deflateEnd (z_streamp strm)
|
|||
* To simplify the source, this is not supported for 16-bit MSDOS (which
|
||||
* doesn't have enough memory anyway to duplicate compression states).
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
|
||||
{
|
||||
#ifdef MAXSEG_64K
|
||||
|
@ -657,18 +624,12 @@ int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
|
|||
|
||||
ss = source->state;
|
||||
|
||||
/*@-assignexpose@*/
|
||||
*dest = *source; /* structure assignment */
|
||||
/*@=assignexpose@*/
|
||||
|
||||
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
||||
/*@-usereleased -compdef@*/ /* FIX: structure copy above? @*/
|
||||
if (ds == Z_NULL) return Z_MEM_ERROR;
|
||||
/*@=usereleased =compdef@*/
|
||||
dest->state = (struct internal_state FAR *) ds;
|
||||
/*@-usereleased -compdef@*/ /* FIX: structure copy above? @*/
|
||||
*ds = *ss; /* structure assignment */
|
||||
/*@=usereleased =compdef@*/
|
||||
*ds = *ss;
|
||||
ds->strm = dest;
|
||||
|
||||
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
||||
|
@ -680,9 +641,7 @@ int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
|
|||
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
|
||||
ds->pending_buf == Z_NULL) {
|
||||
deflateEnd (dest);
|
||||
/*@-usereleased -compdef@*/ /* FIX: structure copy above? @*/
|
||||
return Z_MEM_ERROR;
|
||||
/*@=usereleased =compdef@*/
|
||||
}
|
||||
/* following zmemcpy do not work for 16-bit MSDOS */
|
||||
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
||||
|
@ -698,12 +657,9 @@ int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
|
|||
ds->d_desc.dyn_tree = ds->dyn_dtree;
|
||||
ds->bl_desc.dyn_tree = ds->bl_tree;
|
||||
|
||||
/*@-usereleased -compdef@*/ /* FIX: structure copy above? @*/
|
||||
return Z_OK;
|
||||
/*@=usereleased =compdef@*/
|
||||
#endif
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -736,7 +692,6 @@ local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
|
|||
/**
|
||||
* Initialize the "longest match" routines for a new zlib stream
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local void lm_init (deflate_state * s)
|
||||
{
|
||||
s->window_size = (ulg)2L*s->w_size;
|
||||
|
@ -759,15 +714,7 @@ local void lm_init (deflate_state *s)
|
|||
#ifdef ASMV
|
||||
match_init(); /* initialize the asm code */
|
||||
#endif
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
/* rsync params */
|
||||
s->rsync_chunk_end = 0xFFFFFFFFUL;
|
||||
s->rsync_sum = 0;
|
||||
s->rsync_win = RSYNC_WIN;
|
||||
#endif
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -1039,18 +986,11 @@ local void fill_window(deflate_state *s)
|
|||
*/
|
||||
} else if (s->strstart >= wsize+MAX_DIST(s)) {
|
||||
|
||||
/*@-aliasunique@*/
|
||||
zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
|
||||
/*@=aliasunique@*/
|
||||
s->match_start -= wsize;
|
||||
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
|
||||
s->block_start -= (long) wsize;
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
if (s->rsync_chunk_end != 0xFFFFFFFFUL)
|
||||
s->rsync_chunk_end -= wsize;
|
||||
#endif
|
||||
|
||||
/* Slide the hash table (could be avoided with 32 bit values
|
||||
at the expense of memory usage). We slide even when level == 0
|
||||
to keep the hash table consistent if we switch back to level > 0
|
||||
|
@ -1110,44 +1050,6 @@ local void fill_window(deflate_state *s)
|
|||
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
|
||||
}
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
local void rsync_roll(deflate_state *s, unsigned num)
|
||||
/*@modifies *s @*/
|
||||
{
|
||||
unsigned start = s->strstart;
|
||||
unsigned i;
|
||||
|
||||
if (start < s->rsync_win) {
|
||||
/* before window fills. */
|
||||
for (i = start; i < s->rsync_win; i++) {
|
||||
if (i == start + num) return;
|
||||
s->rsync_sum += (ulg)s->window[i];
|
||||
}
|
||||
num -= (s->rsync_win - start);
|
||||
start = s->rsync_win;
|
||||
}
|
||||
|
||||
/* buffer after window full */
|
||||
for (i = start; i < start+num; i++) {
|
||||
/* New character in */
|
||||
s->rsync_sum += (ulg)s->window[i];
|
||||
/* Old character out */
|
||||
s->rsync_sum -= (ulg)s->window[i - s->rsync_win];
|
||||
if (s->rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(s))
|
||||
s->rsync_chunk_end = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Set rsync_chunk_end if window sum matches magic value.
|
||||
*/
|
||||
#define RSYNC_ROLL(s, num) \
|
||||
do { if (rsync) rsync_roll((s), (num)); } while(0)
|
||||
#else /* WITH_RSYNC_PAD */
|
||||
#define RSYNC_ROLL(s, num)
|
||||
#endif /* WITH_RSYNC_PAD */
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Flush the current block, with given end-of-file flag.
|
||||
|
@ -1158,7 +1060,6 @@ local void rsync_roll(deflate_state *s, unsigned num)
|
|||
(charf *)&s->window[(unsigned)s->block_start] : \
|
||||
(charf *)Z_NULL), \
|
||||
(ulg)((long)s->strstart - s->block_start), \
|
||||
bflush-1, \
|
||||
(eof)); \
|
||||
s->block_start = s->strstart; \
|
||||
flush_pending(s->strm); \
|
||||
|
@ -1188,11 +1089,6 @@ local block_state deflate_stored(deflate_state *s, int flush)
|
|||
*/
|
||||
ulg max_block_size = 0xffff;
|
||||
ulg max_start;
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
int bflush = (rsync ? 2 : 1);
|
||||
#else
|
||||
int bflush = 1;
|
||||
#endif
|
||||
|
||||
if (max_block_size > s->pending_buf_size - 5) {
|
||||
max_block_size = s->pending_buf_size - 5;
|
||||
|
@ -1213,7 +1109,6 @@ local block_state deflate_stored(deflate_state *s, int flush)
|
|||
}
|
||||
Assert(s->block_start >= 0L, "block gone");
|
||||
|
||||
RSYNC_ROLL(s, s->lookahead);
|
||||
s->strstart += s->lookahead;
|
||||
s->lookahead = 0;
|
||||
|
||||
|
@ -1244,11 +1139,10 @@ local block_state deflate_stored(deflate_state *s, int flush)
|
|||
* new strings in the dictionary only for unmatched strings or for short
|
||||
* matches. It is used only for the fast compression options.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local block_state deflate_fast(deflate_state * s, int flush)
|
||||
{
|
||||
IPos hash_head = NIL; /* head of the hash chain */
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
|
@ -1280,7 +1174,7 @@ local block_state deflate_fast(deflate_state *s, int flush)
|
|||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
if (s->strategy != Z_HUFFMAN_ONLY) {
|
||||
/*@i@*/ s->match_length = longest_match (s, hash_head);
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
}
|
||||
/* longest_match() sets match_start */
|
||||
}
|
||||
|
@ -1292,7 +1186,6 @@ local block_state deflate_fast(deflate_state *s, int flush)
|
|||
|
||||
s->lookahead -= s->match_length;
|
||||
|
||||
RSYNC_ROLL(s, s->match_length);
|
||||
/* Insert new strings in the hash table only if the match length
|
||||
* is not too large. This saves time but degrades compression.
|
||||
*/
|
||||
|
@ -1326,22 +1219,14 @@ local block_state deflate_fast(deflate_state *s, int flush)
|
|||
/* No match, output a literal byte */
|
||||
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||
_tr_tally_lit (s, s->window[s->strstart], bflush);
|
||||
RSYNC_ROLL(s, 1);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
}
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
if (rsync && s->strstart > s->rsync_chunk_end) {
|
||||
s->rsync_chunk_end = 0xFFFFFFFFUL;
|
||||
bflush = 2;
|
||||
}
|
||||
#endif
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -1349,11 +1234,10 @@ local block_state deflate_fast(deflate_state *s, int flush)
|
|||
* evaluation for matches: a match is finally adopted only if there is
|
||||
* no better match at the next window position.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local block_state deflate_slow(deflate_state * s, int flush)
|
||||
{
|
||||
IPos hash_head = NIL; /* head of hash chain */
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
|
||||
/* Process the input block. */
|
||||
for (;;) {
|
||||
|
@ -1389,7 +1273,7 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
if (s->strategy != Z_HUFFMAN_ONLY) {
|
||||
/*@i@*/ s->match_length = longest_match (s, hash_head);
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
}
|
||||
/* longest_match() sets match_start */
|
||||
|
||||
|
@ -1422,7 +1306,6 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
*/
|
||||
s->lookahead -= s->prev_length-1;
|
||||
s->prev_length -= 2;
|
||||
RSYNC_ROLL(s, s->prev_length+1);
|
||||
do {
|
||||
if (++s->strstart <= max_insert) {
|
||||
INSERT_STRING(s, s->strstart, hash_head);
|
||||
|
@ -1432,12 +1315,6 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
s->match_length = MIN_MATCH-1;
|
||||
s->strstart++;
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
if (rsync && s->strstart > s->rsync_chunk_end) {
|
||||
s->rsync_chunk_end = 0xFFFFFFFFUL;
|
||||
bflush = 2;
|
||||
}
|
||||
#endif
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
|
||||
} else if (s->match_available) {
|
||||
|
@ -1447,16 +1324,9 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
*/
|
||||
Tracevv((stderr,"%c", s->window[s->strstart-1]));
|
||||
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
if (rsync && s->strstart > s->rsync_chunk_end) {
|
||||
s->rsync_chunk_end = 0xFFFFFFFFUL;
|
||||
bflush = 2;
|
||||
}
|
||||
#endif
|
||||
if (bflush) {
|
||||
FLUSH_BLOCK_ONLY(s, 0);
|
||||
}
|
||||
RSYNC_ROLL(s, 1);
|
||||
s->strstart++;
|
||||
s->lookahead--;
|
||||
if (s->strm->avail_out == 0) return need_more;
|
||||
|
@ -1464,16 +1334,7 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
/* There is no previous match to compare with, wait for
|
||||
* the next step to decide.
|
||||
*/
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
if (rsync && s->strstart > s->rsync_chunk_end) {
|
||||
/* Reset huffman tree */
|
||||
s->rsync_chunk_end = 0xFFFFFFFFUL;
|
||||
bflush = 2;
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
#endif
|
||||
s->match_available = 1;
|
||||
RSYNC_ROLL(s, 1);
|
||||
s->strstart++;
|
||||
s->lookahead--;
|
||||
}
|
||||
|
@ -1487,4 +1348,3 @@ local block_state deflate_slow(deflate_state *s, int flush)
|
|||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: deflate.h,v 1.5 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
@ -47,7 +46,7 @@
|
|||
#define INIT_STATE 42
|
||||
#define BUSY_STATE 113
|
||||
#define FINISH_STATE 666
|
||||
/* Stream status */
|
||||
/*!< Stream status */
|
||||
|
||||
|
||||
/** Data structure describing a single value and its code string. */
|
||||
|
@ -84,13 +83,10 @@ typedef unsigned IPos;
|
|||
*/
|
||||
|
||||
typedef struct internal_state {
|
||||
/*@dependent@*/
|
||||
z_streamp strm; /*!< pointer back to this zlib stream */
|
||||
int status; /*!< as the name implies */
|
||||
/*@owned@*/
|
||||
Bytef *pending_buf; /*!< output still pending */
|
||||
ulg pending_buf_size; /*!< size of pending_buf */
|
||||
/*@dependent@*/
|
||||
Bytef *pending_out; /*!< next pending byte to output to the stream */
|
||||
int pending; /*!< nb of bytes in the pending buffer */
|
||||
int noheader; /*!< suppress zlib header and adler32 */
|
||||
|
@ -104,12 +100,11 @@ typedef struct internal_state {
|
|||
uInt w_bits; /*!< log2(w_size) (8..16) */
|
||||
uInt w_mask; /*!< w_size - 1 */
|
||||
|
||||
/*@owned@*/
|
||||
Bytef *window;
|
||||
/*!< Sliding window. Input bytes are read into the second half of the
|
||||
* window, and move to the first half later to keep a dictionary of at
|
||||
* least wSize bytes. With this organization, matches are limited to a
|
||||
* distance of wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
/*!< Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
* performed with a length multiple of the block size. Also, it limits
|
||||
* the window size to 64K, which is quite useful on MSDOS.
|
||||
* To do: use the user input buffer as sliding window.
|
||||
|
@ -120,14 +115,12 @@ typedef struct internal_state {
|
|||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
/*@owned@*/
|
||||
Posf *prev;
|
||||
/*!< Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
/*@owned@*/
|
||||
Posf *head; /*!< Heads of the hash chains or NIL. */
|
||||
|
||||
uInt ins_h; /*!< hash index of string to be inserted */
|
||||
|
@ -155,8 +148,8 @@ typedef struct internal_state {
|
|||
uInt lookahead; /*!< number of valid bytes ahead in window */
|
||||
|
||||
uInt prev_length;
|
||||
/*!< Length of the best match at previous step. Matches not greater than
|
||||
* this are discarded. This is used in the lazy match evaluation.
|
||||
/*!< Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uInt max_chain_length;
|
||||
|
@ -186,11 +179,8 @@ typedef struct internal_state {
|
|||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to supress compiler warning */
|
||||
/*@only@*/
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /*!< literal and length tree */
|
||||
/*@only@*/
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /*!< distance tree */
|
||||
/*@only@*/
|
||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /*!< Huffman tree for bit lengths */
|
||||
|
||||
struct tree_desc_s l_desc; /*!< desc. for literal tree */
|
||||
|
@ -203,7 +193,7 @@ typedef struct internal_state {
|
|||
int heap[2*L_CODES+1]; /*!< heap used to build the Huffman trees */
|
||||
int heap_len; /*!< number of elements in the heap */
|
||||
int heap_max; /*!< element of largest frequency */
|
||||
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
||||
/*!< The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
|
@ -211,7 +201,6 @@ typedef struct internal_state {
|
|||
/*!< Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
/*@dependent@*/
|
||||
uchf *l_buf; /*!< buffer for literals or lengths */
|
||||
|
||||
uInt lit_bufsize;
|
||||
|
@ -247,7 +236,7 @@ typedef struct internal_state {
|
|||
uInt matches; /*!< number of string matches in current block */
|
||||
int last_eob_len; /*!< bit length of EOB code for last block */
|
||||
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
ulg compressed_len; /*!< total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /*!< bit length of compressed data sent mod 2^32 */
|
||||
#endif
|
||||
|
@ -261,13 +250,6 @@ typedef struct internal_state {
|
|||
* are always zero.
|
||||
*/
|
||||
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
/* rsync params */
|
||||
ulg rsync_chunk_end;
|
||||
ulg rsync_sum;
|
||||
int rsync_win;
|
||||
#endif
|
||||
|
||||
} FAR deflate_state;
|
||||
|
||||
/**
|
||||
|
@ -278,7 +260,7 @@ typedef struct internal_state {
|
|||
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/*!< Minimum amount of lookahead, except at the end of the input file.
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
|
@ -293,12 +275,12 @@ void _tr_init OF((deflate_state *s))
|
|||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc))
|
||||
/*@modifies *s @*/;
|
||||
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int pad, int eof))
|
||||
int eof))
|
||||
/*@modifies *s @*/;
|
||||
void _tr_align OF((deflate_state *s))
|
||||
/*@modifies *s @*/;
|
||||
void _tr_stored_block OF((deflate_state *s, /*@null@*/ charf *buf,
|
||||
ulg stored_len, int eof))
|
||||
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof))
|
||||
/*@modifies *s @*/;
|
||||
|
||||
#define d_code(dist) \
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: example.c,v 1.2 2001/12/27 21:00:18 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
@ -62,9 +61,8 @@ int main OF((int argc, char *argv[]));
|
|||
/* ===========================================================================
|
||||
* Test compress() and uncompress()
|
||||
*/
|
||||
void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_compress(Byte * compr, uLong comprLen,
|
||||
Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
int err;
|
||||
uLong len = strlen(hello)+1;
|
||||
|
@ -88,11 +86,8 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test read/write of .gz files
|
||||
*/
|
||||
void test_gzio(out, in, uncompr, uncomprLen)
|
||||
const char *out; /* compressed output file */
|
||||
const char *in; /* compressed input file */
|
||||
Byte *uncompr;
|
||||
int uncomprLen;
|
||||
void test_gzio(const char * out, const char * in, Byte * uncompr,
|
||||
int uncomprLen)
|
||||
{
|
||||
int err;
|
||||
int len = strlen(hello)+1;
|
||||
|
@ -165,9 +160,7 @@ void test_gzio(out, in, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test deflate() with small buffers
|
||||
*/
|
||||
void test_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
void test_deflate(Byte * compr, uLong comprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
@ -203,9 +196,8 @@ void test_deflate(compr, comprLen)
|
|||
/* ===========================================================================
|
||||
* Test inflate() with small buffers
|
||||
*/
|
||||
void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_inflate(Byte * compr, uLong comprLen,
|
||||
Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
@ -244,9 +236,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test deflate() with large buffers and dynamic change of compression level
|
||||
*/
|
||||
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_large_deflate(Byte * compr, uLong comprLen,
|
||||
Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
@ -299,9 +290,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test inflate() with large buffers
|
||||
*/
|
||||
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_large_inflate(Byte * compr, uLong comprLen,
|
||||
Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
@ -340,9 +330,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test deflate() with full flush
|
||||
*/
|
||||
void test_flush(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong *comprLen;
|
||||
void test_flush(Byte * compr, uLong * comprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
@ -378,9 +366,7 @@ void test_flush(compr, comprLen)
|
|||
/* ===========================================================================
|
||||
* Test inflateSync()
|
||||
*/
|
||||
void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_sync(Byte * compr, uLong comprLen, Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
@ -422,9 +408,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
|
|||
/* ===========================================================================
|
||||
* Test deflate() with preset dictionary
|
||||
*/
|
||||
void test_dict_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
void test_dict_deflate(Byte * compr, uLong comprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
@ -459,9 +443,8 @@ void test_dict_deflate(compr, comprLen)
|
|||
/* ===========================================================================
|
||||
* Test inflate() with a preset dictionary
|
||||
*/
|
||||
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
void test_dict_inflate(Byte * compr, uLong comprLen,
|
||||
Byte * uncompr, uLong uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
@ -510,9 +493,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
|||
* Usage: example [output.gz [input.gz]]
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
|
||||
|
|
324
zlib/gzio.c
324
zlib/gzio.c
|
@ -1,50 +1,34 @@
|
|||
/* @(#) $Id: gzio.c,v 1.7 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
/* gzio.c -- IO on .gz files
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file gzio.c
|
||||
* I/O on .gz files.
|
||||
*
|
||||
* Compile this file with -DNO_DEFLATE to avoid the compression code.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#ifndef Z_BUFSIZE
|
||||
# ifdef MAXSEG_64K
|
||||
# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
|
||||
# else
|
||||
#if defined(__i386__)
|
||||
# define Z_BUFSIZE (16 * 1024 * 1024) /*262144 16384*/
|
||||
#else
|
||||
# define Z_BUFSIZE (256 * 1024) /*262144 16384*/
|
||||
#endif
|
||||
# define Z_BUFSIZE 16384
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_PRINTF_BUFSIZE
|
||||
# define Z_PRINTF_BUFSIZE 4096
|
||||
#endif
|
||||
|
||||
/*@unchecked@*/
|
||||
static int z_bufsize = Z_BUFSIZE;
|
||||
|
||||
#define ALLOC(size) malloc(size)
|
||||
#define TRYFREE(p) {if (p) free(p);}
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
static int gz_magic[2] = {0x1f, 0x8b}; /*!< gzip magic header */
|
||||
static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
|
||||
/* gzip flag byte */
|
||||
#define ASCII_FLAG 0x01 /*!< bit 0 set: file probably ascii text */
|
||||
|
@ -58,27 +42,18 @@ typedef struct gz_stream {
|
|||
z_stream stream;
|
||||
int z_err; /*!< error code for last stream operation */
|
||||
int z_eof; /*!< set if end of input file */
|
||||
/*@dependent@*/
|
||||
FILE *file; /*!< .gz file */
|
||||
/*@owned@*/
|
||||
Byte *inbuf; /*!< input buffer */
|
||||
/*@owned@*/
|
||||
Byte *outbuf; /*!< output buffer */
|
||||
/*@owned@*/
|
||||
uLong crc; /*!< crc32 of uncompressed data */
|
||||
char *msg; /*!< error message */
|
||||
/*@only@*/
|
||||
char *path; /*!< path name for debugging only */
|
||||
int transparent; /*!< 1 if input file is not a .gz file */
|
||||
char mode; /*!< 'w' or 'r' */
|
||||
char mmap_mode;
|
||||
long startpos; /*!< start of compressed data in file (header skipped) */
|
||||
off_t mmap_pos;
|
||||
off_t mmap_end;
|
||||
int fd;
|
||||
} gz_stream;
|
||||
|
||||
|
||||
/*@null@*/
|
||||
local gzFile gz_open OF((const char *path, const char *mode, int fd))
|
||||
/*@globals errno, fileSystem @*/
|
||||
/*@modifies errno, fileSystem @*/;
|
||||
|
@ -91,7 +66,7 @@ local int get_byte OF((gz_stream *s))
|
|||
local void check_header OF((gz_stream *s))
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies s, fileSystem @*/;
|
||||
local int destroy OF((/*@only@*/ /*@out@*/ gz_stream *s))
|
||||
local int destroy OF((gz_stream *s))
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies s, fileSystem @*/;
|
||||
local void putLong OF((FILE *file, uLong x))
|
||||
|
@ -111,7 +86,6 @@ local uLong getLong OF((gz_stream *s))
|
|||
* can be checked to distinguish the two cases (if errno is zero, the
|
||||
* zlib error is Z_MEM_ERROR).
|
||||
*/
|
||||
/*@-compmempass -compdef@*/
|
||||
local gzFile gz_open (const char * path, const char * mode, int fd)
|
||||
{
|
||||
int err;
|
||||
|
@ -126,26 +100,19 @@ local gzFile gz_open (const char *path, const char *mode, int fd)
|
|||
|
||||
s = (gz_stream *)ALLOC(sizeof(gz_stream));
|
||||
if (!s) return Z_NULL;
|
||||
zmemzero(s, sizeof(*s));
|
||||
|
||||
s->stream.zalloc = (alloc_func)NULL;
|
||||
s->stream.zfree = (free_func)NULL;
|
||||
s->stream.opaque = (voidpf)NULL;
|
||||
s->stream.zalloc = (alloc_func)0;
|
||||
s->stream.zfree = (free_func)0;
|
||||
s->stream.opaque = (voidpf)0;
|
||||
s->stream.next_in = s->inbuf = Z_NULL;
|
||||
s->stream.next_out = s->outbuf = Z_NULL;
|
||||
s->stream.avail_in = s->stream.avail_out = 0;
|
||||
s->file = NULL;
|
||||
s->z_err = Z_OK;
|
||||
s->z_eof = 0;
|
||||
s->stream.crc = /*crc32(0L, Z_NULL, 0)*/0;
|
||||
#if defined(__i386__)
|
||||
/*@-unrecog@*/
|
||||
partial_crc32_prep(&s->stream.crc);
|
||||
/*@=unrecog@*/
|
||||
#endif
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
s->msg = NULL;
|
||||
s->transparent = 0;
|
||||
s->mmap_mode = 0;
|
||||
|
||||
s->path = (char*)ALLOC(strlen(path)+1);
|
||||
if (s->path == NULL) {
|
||||
|
@ -177,13 +144,13 @@ local gzFile gz_open (const char *path, const char *mode, int fd)
|
|||
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
|
||||
/* windowBits is passed < 0 to suppress zlib header */
|
||||
|
||||
s->stream.next_out = s->outbuf = (Byte*)ALLOC(z_bufsize);
|
||||
s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
#endif
|
||||
if (err != Z_OK || s->outbuf == Z_NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
} else {
|
||||
s->stream.next_in = s->inbuf = (Byte*)ALLOC(z_bufsize);
|
||||
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
|
||||
err = inflateInit2(&(s->stream), -MAX_WBITS);
|
||||
/* windowBits is passed < 0 to tell that there is no zlib header.
|
||||
|
@ -196,61 +163,19 @@ local gzFile gz_open (const char *path, const char *mode, int fd)
|
|||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
}
|
||||
s->stream.avail_out = z_bufsize;
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
|
||||
errno = 0;
|
||||
|
||||
#if defined(__i386__)
|
||||
if ((fd >= 0) && (s->mode == 'r')) {
|
||||
struct stat stat;
|
||||
if (!fstat(fd, &stat) && S_ISREG(stat.st_mode)
|
||||
&& (lseek(fd, 0, SEEK_CUR) != -1))
|
||||
{
|
||||
char *test = mmap(0, z_bufsize, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (test != (char *)-1) {
|
||||
long n;
|
||||
off_t pos;
|
||||
s->mmap_mode = 1;
|
||||
s->fd = fd;
|
||||
TRYFREE(s->inbuf);
|
||||
munmap(test, z_bufsize);
|
||||
pos = lseek(fd, 0, SEEK_CUR);
|
||||
s->mmap_end = lseek(fd, 0, SEEK_END);
|
||||
(void) lseek(fd, 0, SEEK_SET);
|
||||
|
||||
s->mmap_pos = pos & ~(off_t)(z_bufsize - 1);
|
||||
s->inbuf = mmap(0, z_bufsize, PROT_READ, MAP_SHARED, fd, s->mmap_pos);
|
||||
#if defined(MADV_SEQUENTIAL)
|
||||
(void) madvise(s->inbuf, z_bufsize, MADV_SEQUENTIAL);
|
||||
#endif
|
||||
s->mmap_pos += z_bufsize;
|
||||
s->stream.next_in = s->inbuf + (pos & (z_bufsize - 1));
|
||||
s->stream.avail_in = s->mmap_end - pos;
|
||||
if (s->stream.avail_in > (s->mmap_pos - pos))
|
||||
s->stream.avail_in = s->mmap_pos - pos;
|
||||
for (n=0; n<s->stream.avail_in; n+=4096)
|
||||
((volatile char *)s->inbuf)[n];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!s->mmap_mode) {
|
||||
/*@-abstract@*/
|
||||
s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
|
||||
/*@=abstract@*/
|
||||
|
||||
if (s->file == NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
}
|
||||
if (s->mode == 'w') {
|
||||
/* Write a very simple .gz header:
|
||||
*/
|
||||
/*@-nullpass@*/ /* FIX: s->file may be NULL */
|
||||
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
|
||||
Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
|
||||
/*@=nullpass@*/
|
||||
s->startpos = 10L;
|
||||
/* We use 10L instead of ftell(s->file) to because ftell causes an
|
||||
* fflush on some systems. This version of the library doesn't use
|
||||
|
@ -259,17 +184,11 @@ local gzFile gz_open (const char *path, const char *mode, int fd)
|
|||
*/
|
||||
} else {
|
||||
check_header(s); /* skip the .gz header */
|
||||
if (s->mmap_mode)
|
||||
s->startpos = s->mmap_pos - s->stream.avail_in;
|
||||
else
|
||||
/*@-nullpass@*/ /* FIX: s->file may be NULL */
|
||||
s->startpos = (ftell(s->file) - s->stream.avail_in);
|
||||
/*@=nullpass@*/
|
||||
}
|
||||
|
||||
return (gzFile)s;
|
||||
}
|
||||
/*@=compmempass =compdef@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -297,7 +216,7 @@ gzFile ZEXPORT gzdopen (int fd, const char *mode)
|
|||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Update the compression level and strategy
|
||||
* Update the compression level and strategy.
|
||||
*/
|
||||
int ZEXPORT gzsetparams (gzFile file, int level, int strategy)
|
||||
{
|
||||
|
@ -306,83 +225,29 @@ int ZEXPORT gzsetparams (gzFile file, int level, int strategy)
|
|||
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
|
||||
|
||||
/* Make room to allow flushing */
|
||||
/*@-branchstate@*/
|
||||
if (s->stream.avail_out == 0) {
|
||||
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, z_bufsize, s->file) != z_bufsize) {
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
}
|
||||
s->stream.avail_out = z_bufsize;
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
return deflateParams (&(s->stream), level, strategy);
|
||||
}
|
||||
|
||||
#if defined(__i386__)
|
||||
static inline int gz_refill_inbuf(gz_stream *s)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *s, fileSystem @*/
|
||||
{
|
||||
if (s->mmap_mode) {
|
||||
long n;
|
||||
s->stream.avail_in = 0;
|
||||
if (s->mmap_pos >= s->mmap_end) {
|
||||
s->z_eof = 1;
|
||||
return 0;
|
||||
}
|
||||
if (s->inbuf)
|
||||
munmap(s->inbuf, z_bufsize);
|
||||
s->inbuf = mmap(s->inbuf, z_bufsize, PROT_READ, MAP_SHARED|MAP_FIXED, s->fd, s->mmap_pos);
|
||||
if (s->inbuf == (Byte *)-1) {
|
||||
s->inbuf = NULL;
|
||||
s->z_err = errno;
|
||||
return 1;
|
||||
}
|
||||
#if defined(MADV_SEQUENTIAL)
|
||||
(void) madvise(s->inbuf, z_bufsize, MADV_SEQUENTIAL);
|
||||
#endif
|
||||
s->stream.next_in = s->inbuf;
|
||||
s->stream.avail_in = z_bufsize;
|
||||
s->mmap_pos += z_bufsize;
|
||||
if (s->mmap_pos > s->mmap_end)
|
||||
s->stream.avail_in = s->mmap_end - s->mmap_pos + z_bufsize;
|
||||
for (n=0; n<s->stream.avail_in; n+=4096)
|
||||
((volatile char *)s->inbuf)[n];
|
||||
return 0;
|
||||
}
|
||||
|
||||
s->stream.avail_in = fread(s->inbuf, 1, z_bufsize, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) {
|
||||
s->z_err = Z_ERRNO;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Read a byte from a gz_stream; update next_in and avail_in. Return EOF
|
||||
* for end of file.
|
||||
* IN assertion: the stream s has been sucessfully opened for reading.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local inline int get_byte(gz_stream *s)
|
||||
local int get_byte(gz_stream * s)
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
/*@-branchstate@*/
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
#if defined(__i386__)
|
||||
if(gz_refill_inbuf(s))
|
||||
return EOF;
|
||||
#else
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
|
@ -390,13 +255,10 @@ local inline int get_byte(gz_stream *s)
|
|||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
#endif
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
s->stream.avail_in--;
|
||||
return *(s->stream.next_in)++;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
|
@ -442,13 +304,13 @@ local void check_header(gz_stream *s)
|
|||
len = (uInt)get_byte(s);
|
||||
len += ((uInt)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) {};
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) {};
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) {};
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
|
@ -461,7 +323,6 @@ local void check_header(gz_stream *s)
|
|||
* Cleanup then free the given gz_stream. Return a zlib error code.
|
||||
* Try freeing in the reverse order of allocations.
|
||||
*/
|
||||
/*@-compdef@*/
|
||||
local int destroy (gz_stream * s)
|
||||
{
|
||||
int err = Z_OK;
|
||||
|
@ -470,17 +331,6 @@ local int destroy (gz_stream *s)
|
|||
|
||||
TRYFREE(s->msg);
|
||||
|
||||
#if defined(__i386__)
|
||||
if (s->mmap_mode) {
|
||||
if (s->inbuf)
|
||||
munmap(s->inbuf, z_bufsize);
|
||||
s->inbuf = NULL;
|
||||
close(s->fd);
|
||||
s->mmap_mode = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*@-branchstate@*/
|
||||
if (s->stream.state != NULL) {
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
|
@ -492,7 +342,6 @@ local int destroy (gz_stream *s)
|
|||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
#ifdef ESPIPE
|
||||
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
|
@ -504,20 +353,15 @@ local int destroy (gz_stream *s)
|
|||
TRYFREE(s->inbuf);
|
||||
TRYFREE(s->outbuf);
|
||||
TRYFREE(s->path);
|
||||
/*@-branchstate@*/
|
||||
TRYFREE(s);
|
||||
/*@=branchstate@*/
|
||||
return err;
|
||||
}
|
||||
/*@=compdef@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Reads the given number of uncompressed bytes from the compressed file.
|
||||
* gzread returns the number of bytes actually read (0 for end of file).
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
/*@-compdef@*/
|
||||
int ZEXPORT gzread (gzFile file, voidp buf, unsigned len)
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
@ -530,21 +374,14 @@ int ZEXPORT gzread (gzFile file, voidp buf, unsigned len)
|
|||
if (s->z_err == Z_STREAM_END) return 0; /* EOF */
|
||||
|
||||
next_out = (Byte*)buf;
|
||||
/*@-temptrans@*/
|
||||
s->stream.next_out = (Bytef*)buf;
|
||||
/*@=temptrans@*/
|
||||
s->stream.avail_out = len;
|
||||
|
||||
/*@-branchstate@*/
|
||||
while (s->stream.avail_out != 0) {
|
||||
|
||||
if (s->transparent) {
|
||||
/* Copy first the lookahead bytes: */
|
||||
uInt n;
|
||||
#if defined(__i386__)
|
||||
again:
|
||||
#endif
|
||||
n = s->stream.avail_in;
|
||||
uInt n = s->stream.avail_in;
|
||||
if (n > s->stream.avail_out) n = s->stream.avail_out;
|
||||
if (n > 0) {
|
||||
zmemcpy(s->stream.next_out, s->stream.next_in, n);
|
||||
|
@ -555,13 +392,8 @@ again:
|
|||
s->stream.avail_in -= n;
|
||||
}
|
||||
if (s->stream.avail_out > 0) {
|
||||
#if defined(__i386__)
|
||||
if (!s->stream.avail_in && !gz_refill_inbuf(s))
|
||||
goto again;
|
||||
#else
|
||||
s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
|
||||
s->file);
|
||||
#endif
|
||||
}
|
||||
len -= s->stream.avail_out;
|
||||
s->stream.total_in += (uLong)len;
|
||||
|
@ -572,10 +404,6 @@ again:
|
|||
if (s->stream.avail_in == 0 && !s->z_eof) {
|
||||
|
||||
errno = 0;
|
||||
#if defined(__i386__)
|
||||
if (gz_refill_inbuf(s))
|
||||
break;
|
||||
#else
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
|
@ -585,26 +413,15 @@ again:
|
|||
}
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
#endif
|
||||
}
|
||||
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
|
||||
|
||||
if (s->z_err == Z_STREAM_END) {
|
||||
/* Check CRC and original size */
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
start = s->stream.next_out;
|
||||
|
||||
#if defined(__i386__)
|
||||
start = s->stream.next_out;
|
||||
/*@-unrecog@*/
|
||||
if (getLong(s) != get_crc_from_partial(&s->stream.crc))
|
||||
/*@=unrecog@*/
|
||||
#else
|
||||
s->stream.crc = crc32(s->stream.crc, start, (uInt)(s->stream.next_out - start));
|
||||
start = s->stream.next_out;
|
||||
/*@-evalorder@*/
|
||||
if (getLong(s) != s->stream.crc)
|
||||
/*@=evalorder@*/
|
||||
#endif
|
||||
{
|
||||
if (getLong(s) != s->crc) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
} else {
|
||||
(void)getLong(s);
|
||||
|
@ -620,27 +437,16 @@ again:
|
|||
inflateReset(&(s->stream));
|
||||
s->stream.total_in = total_in;
|
||||
s->stream.total_out = total_out;
|
||||
s->stream.crc = /*crc32(0L, Z_NULL, 0)*/0;
|
||||
#if defined(__i386__)
|
||||
/*@-unrecog@*/
|
||||
partial_crc32_prep(&s->stream.crc);
|
||||
/*@=unrecog@*/
|
||||
#endif
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s->z_err != Z_OK || s->z_eof) break;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
#if !defined(__i386__)
|
||||
s->stream.crc = crc32(s->stream.crc, start, (uInt)(s->stream.next_out - start));
|
||||
#endif
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
|
||||
return (int)(len - s->stream.avail_out);
|
||||
}
|
||||
/*@=compdef@*/
|
||||
/*@=compmempass@*/
|
||||
|
||||
|
||||
/* ========================================================================= */
|
||||
|
@ -671,7 +477,7 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len)
|
|||
char *b = buf;
|
||||
if (buf == Z_NULL || len <= 0) return Z_NULL;
|
||||
|
||||
while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') {};
|
||||
while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
|
||||
*buf = '\0';
|
||||
return b == buf && len > 0 ? Z_NULL : b;
|
||||
}
|
||||
|
@ -689,34 +495,24 @@ int ZEXPORT gzwrite (gzFile file, const voidp buf, unsigned len)
|
|||
|
||||
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
|
||||
|
||||
/*@-temptrans@*/
|
||||
s->stream.next_in = (Bytef*)buf;
|
||||
/*@=temptrans@*/
|
||||
s->stream.avail_in = len;
|
||||
|
||||
/*@-infloops@*/
|
||||
/*@-branchstate@*/
|
||||
while (s->stream.avail_in != 0) {
|
||||
|
||||
if (s->stream.avail_out == 0) {
|
||||
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, z_bufsize, s->file) != z_bufsize) {
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
s->stream.avail_out = z_bufsize;
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
|
||||
if (s->z_err != Z_OK) break;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
/*@=infloops@*/
|
||||
#if defined(__i386__)
|
||||
s->stream.crc = partial_crc32(s->stream.crc, (const Bytef *)buf, len);
|
||||
#else
|
||||
s->stream.crc = crc32(s->stream.crc, (const Bytef *)buf, len);
|
||||
#endif
|
||||
s->crc = crc32(s->crc, (const Bytef *)buf, len);
|
||||
|
||||
return (int)(len - s->stream.avail_in);
|
||||
}
|
||||
|
@ -750,13 +546,16 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
|
|||
}
|
||||
#else /* not ANSI C */
|
||||
|
||||
int ZEXPORTVA gzprintf (gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10,
|
||||
int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
gzFile file;
|
||||
const char *format;
|
||||
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
||||
{
|
||||
char buf[Z_PRINTF_BUFSIZE];
|
||||
int len;
|
||||
|
||||
/*@-formatconst@*/
|
||||
#ifdef HAS_snprintf
|
||||
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
|
@ -764,7 +563,6 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, int a1, int a2, int a3,
|
|||
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
#endif
|
||||
/*@=formatconst@*/
|
||||
len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
|
||||
if (len <= 0) return 0;
|
||||
|
||||
|
@ -812,9 +610,8 @@ local int do_flush (gzFile file, int flush)
|
|||
|
||||
s->stream.avail_in = 0; /* should be zero already anyway */
|
||||
|
||||
/*@-branchstate@*/
|
||||
for (;;) {
|
||||
len = z_bufsize - s->stream.avail_out;
|
||||
len = Z_BUFSIZE - s->stream.avail_out;
|
||||
|
||||
if (len != 0) {
|
||||
if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
|
||||
|
@ -822,7 +619,7 @@ local int do_flush (gzFile file, int flush)
|
|||
return Z_ERRNO;
|
||||
}
|
||||
s->stream.next_out = s->outbuf;
|
||||
s->stream.avail_out = z_bufsize;
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
if (done) break;
|
||||
s->z_err = deflate(&(s->stream), flush);
|
||||
|
@ -837,7 +634,6 @@ local int do_flush (gzFile file, int flush)
|
|||
|
||||
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
|
||||
}
|
||||
|
||||
|
@ -881,18 +677,14 @@ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence)
|
|||
|
||||
/* At this point, offset is the number of zero bytes to write. */
|
||||
if (s->inbuf == Z_NULL) {
|
||||
s->inbuf = (Byte*)ALLOC(z_bufsize); /* for seeking */
|
||||
/*@-nullpass@*/ /* FIX: s->inbuf may be NULL */
|
||||
zmemzero(s->inbuf, z_bufsize);
|
||||
/*@=nullpass@*/
|
||||
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
|
||||
zmemzero(s->inbuf, Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
uInt size = z_bufsize;
|
||||
if (offset < z_bufsize) size = (uInt)offset;
|
||||
uInt size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (uInt)offset;
|
||||
|
||||
/*@-nullpass@*/ /* FIX: s->inbuf may be NULL */
|
||||
size = gzwrite(file, s->inbuf, size);
|
||||
/*@=nullpass@*/
|
||||
if (size == 0) return -1L;
|
||||
|
||||
offset -= size;
|
||||
|
@ -927,15 +719,13 @@ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence)
|
|||
/* offset is now the number of bytes to skip. */
|
||||
|
||||
if (offset != 0 && s->outbuf == Z_NULL) {
|
||||
s->outbuf = (Byte*)ALLOC(z_bufsize);
|
||||
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
int size = z_bufsize;
|
||||
if (offset < z_bufsize) size = (int)offset;
|
||||
int size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (int)offset;
|
||||
|
||||
/*@-nullpass@*/ /* FIX: s->outbuf may be NULL */
|
||||
size = gzread(file, s->outbuf, (uInt)size);
|
||||
/*@=nullpass@*/
|
||||
if (size <= 0) return -1L;
|
||||
offset -= size;
|
||||
}
|
||||
|
@ -956,10 +746,7 @@ int ZEXPORT gzrewind (gzFile file)
|
|||
s->z_eof = 0;
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
s->stream.crc = /*crc32(0L, Z_NULL, 0)*/0;
|
||||
#if defined(__i386__)
|
||||
partial_crc32_prep(&s->stream.crc);
|
||||
#endif
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
if (s->startpos == 0) { /* not a compressed file */
|
||||
rewind(s->file);
|
||||
|
@ -1043,12 +830,7 @@ int ZEXPORT gzclose (gzFile file)
|
|||
err = do_flush (file, Z_FINISH);
|
||||
if (err != Z_OK) return destroy((gz_stream*)file);
|
||||
|
||||
#if defined(__i386__)
|
||||
putLong (s->file, get_crc_from_partial(&s->stream.crc));
|
||||
#else
|
||||
putLong (s->file, s->stream.crc);
|
||||
#endif
|
||||
|
||||
putLong (s->file, s->crc);
|
||||
putLong (s->file, s->stream.total_in);
|
||||
#endif
|
||||
}
|
||||
|
@ -1063,7 +845,6 @@ int ZEXPORT gzclose (gzFile file)
|
|||
* errnum is set to Z_ERRNO and the application may consult errno
|
||||
* to get the exact error code.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
const char* ZEXPORT gzerror (gzFile file, int * errnum)
|
||||
{
|
||||
char *m;
|
||||
|
@ -1078,19 +859,12 @@ const char* ZEXPORT gzerror (gzFile file, int *errnum)
|
|||
|
||||
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
|
||||
|
||||
/*@-branchstate@*/
|
||||
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
|
||||
/*@=branchstate@*/
|
||||
|
||||
TRYFREE(s->msg);
|
||||
s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
|
||||
if (s->msg == NULL) {
|
||||
*errnum = Z_MEM_ERROR;
|
||||
return (const char*)ERR_MSG(Z_MEM_ERROR);
|
||||
}
|
||||
strcpy(s->msg, s->path);
|
||||
strcat(s->msg, ": ");
|
||||
strcat(s->msg, m);
|
||||
return (const char*)s->msg;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
|
316
zlib/infblock.c
316
zlib/infblock.c
|
@ -14,16 +14,15 @@
|
|||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
//#include "infutil.c"
|
||||
#include "inffast.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* Table for deflate from PKZIP's appnote.txt. */
|
||||
/** Table for deflate from PKZIP's appnote.txt. */
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const uInt border[] = { /* Order of the bit length code lengths */
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
@ -80,12 +79,8 @@ void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLongf *c)
|
|||
*c = s->check;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES) {
|
||||
/*@-noeffect@*/
|
||||
if (s->mode == CODES)
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
/*@=noeffect@*/
|
||||
s->sub.decode.codes = NULL;
|
||||
}
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
|
@ -124,7 +119,6 @@ inflate_blocks_statef *inflate_blocks_new(z_streamp z, check_func c, uInt w)
|
|||
}
|
||||
|
||||
|
||||
/*@-compmempass@*/
|
||||
int inflate_blocks(inflate_blocks_statef * s, z_streamp z, int r)
|
||||
{
|
||||
uInt t; /* temporary storage */
|
||||
|
@ -154,7 +148,7 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
t = k & 7; /* go to byte boundary */
|
||||
DUMPBITS(t)
|
||||
s->mode = LENS; /* get length of stored block */
|
||||
/*@innerbreak@*/ break;
|
||||
break;
|
||||
case 1: /* fixed */
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
|
@ -167,47 +161,43 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
/*@innerbreak@*/ break;
|
||||
break;
|
||||
case 2: /* dynamic */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
s->mode = TABLE;
|
||||
/*@innerbreak@*/ break;
|
||||
break;
|
||||
case 3: /* illegal */
|
||||
DUMPBITS(3)
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
z->msg = "invalid block type";
|
||||
z->msg = (char*)"invalid block type";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
case LENS:
|
||||
NEEDBITS(32)
|
||||
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
|
||||
{
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
z->msg = "invalid stored block lengths";
|
||||
z->msg = (char*)"invalid stored block lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.left = (uInt)b & 0xffff;
|
||||
b = k = 0; /* dump bits */
|
||||
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
||||
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
case STORED:
|
||||
if (n == 0)
|
||||
goto leave;
|
||||
LEAVE
|
||||
NEEDOUT
|
||||
t = s->sub.left;
|
||||
if (t > n) t = n;
|
||||
|
@ -216,37 +206,34 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((s->sub.left -= t) != 0)
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
s->mode = s->last ? DRY : TYPE;
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
case TABLE:
|
||||
NEEDBITS(14)
|
||||
s->sub.trees.table = t = (uInt)b & 0x3fff;
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
|
||||
{
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
z->msg = "too many length or distance symbols";
|
||||
z->msg = (char*)"too many length or distance symbols";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
#endif
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
DUMPBITS(14)
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
s->mode = BTREE;
|
||||
/*@fallthrough@*/
|
||||
case BTREE:
|
||||
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
|
||||
{
|
||||
|
@ -262,18 +249,16 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
if (t != Z_OK)
|
||||
{
|
||||
r = t;
|
||||
if (r == Z_DATA_ERROR) {
|
||||
if (r == Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
}
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: bits tree ok\n"));
|
||||
s->mode = DTREE;
|
||||
/*@fallthrough@*/
|
||||
case DTREE:
|
||||
while (t = s->sub.trees.table,
|
||||
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
|
||||
|
@ -305,12 +290,10 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
(c == 16 && i < 1))
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
z->msg = "invalid bit length repeat";
|
||||
z->msg = (char*)"invalid bit length repeat";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
|
||||
do {
|
||||
|
@ -333,36 +316,30 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
if (t == (uInt)Z_DATA_ERROR) {
|
||||
if (t == (uInt)Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
/*@-type@*/
|
||||
s->mode = BAD;
|
||||
/*@=type@*/
|
||||
}
|
||||
r = t;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
Tracev((stderr, "inflate: trees ok\n"));
|
||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.codes = c;
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = CODES;
|
||||
/*@fallthrough@*/
|
||||
case CODES:
|
||||
UPDATE
|
||||
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
||||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
/*@-noeffect@*/
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
/*@=noeffect@*/
|
||||
s->sub.decode.codes = NULL;
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
|
@ -370,33 +347,25 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
if (!s->last)
|
||||
{
|
||||
s->mode = TYPE;
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
s->mode = DRY;
|
||||
/*@fallthrough@*/
|
||||
case DRY:
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
goto leave;
|
||||
/*@-type@*/
|
||||
LEAVE
|
||||
s->mode = DONE;
|
||||
/*@=type@*/
|
||||
/*@fallthrough@*/
|
||||
case DONE:
|
||||
r = Z_STREAM_END;
|
||||
goto leave;
|
||||
LEAVE
|
||||
case BAD:
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
leave:
|
||||
LEAVE
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
}
|
||||
|
||||
|
||||
int inflate_blocks_free(inflate_blocks_statef * s, z_streamp z)
|
||||
|
@ -412,9 +381,7 @@ int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z)
|
|||
|
||||
void inflate_set_dictionary(inflate_blocks_statef * s, const Bytef * d, uInt n)
|
||||
{
|
||||
/*@-mayaliasunique@*/ /* FIX: d may alias s->window */
|
||||
zmemcpy(s->window, d, n);
|
||||
/*@=mayaliasunique@*/
|
||||
s->read = s->write = s->window + n;
|
||||
}
|
||||
|
||||
|
@ -427,218 +394,3 @@ int inflate_blocks_sync_point(inflate_blocks_statef *s)
|
|||
{
|
||||
return s->mode == LENS;
|
||||
}
|
||||
|
||||
/*********************************infcodes.c*********************/
|
||||
|
||||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
|
||||
inflate_codes_statef *inflate_codes_new(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z)
|
||||
{
|
||||
inflate_codes_statef *c;
|
||||
|
||||
if ((c = (inflate_codes_statef *)
|
||||
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
||||
{
|
||||
c->mode = START;
|
||||
c->lbits = (Byte)bl;
|
||||
c->dbits = (Byte)bd;
|
||||
c->ltree = tl;
|
||||
c->dtree = td;
|
||||
Tracev((stderr, "inflate: codes new\n"));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/*@-compmempass@*/
|
||||
int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r)
|
||||
{
|
||||
uInt j; /* temporary storage */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
Bytef *f; /* pointer to copy strings from */
|
||||
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input and output based on current state */
|
||||
while (1) switch (c->mode)
|
||||
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
case START: /* x: set up for LEN */
|
||||
#ifndef SLOW
|
||||
/*@-branchstate@*/
|
||||
if (m >= 258 && n >= 10)
|
||||
{
|
||||
UPDATE
|
||||
r = inflate_fast(/*c->lbits, c->dbits, c->ltree, c->dtree,*/ s, z);
|
||||
LOAD
|
||||
if (r != Z_OK)
|
||||
{
|
||||
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
#endif /* !SLOW */
|
||||
c->sub.code.need = c->lbits;
|
||||
c->sub.code.tree = c->ltree;
|
||||
c->mode = LEN;
|
||||
/*@fallthrough@*/
|
||||
case LEN: /* i: get length/literal/eob next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e == 0) /* literal */
|
||||
{
|
||||
c->sub.lit = t->base;
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", t->base));
|
||||
c->mode = LIT;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
if (e & 16) /* length */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->len = t->base;
|
||||
c->mode = LENEXT;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
if (e & 32) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = "invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
case LENEXT: /* i: getting length extra (have base) */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->len += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
c->sub.code.need = c->dbits;
|
||||
c->sub.code.tree = c->dtree;
|
||||
Tracevv((stderr, "inflate: length %u\n", c->len));
|
||||
c->mode = DIST;
|
||||
/*@fallthrough@*/
|
||||
case DIST: /* i: get distance next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e & 16) /* distance */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->sub.copy.dist = t->base;
|
||||
c->mode = DISTEXT;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = "invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
case DISTEXT: /* i: getting distance extra */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
||||
c->mode = COPY;
|
||||
/*@fallthrough@*/
|
||||
case COPY: /* o: copying bytes in window, waiting for space */
|
||||
#ifndef __TURBOC__ /* Turbo C bug for following expression */
|
||||
f = (uInt)(q - s->window) < c->sub.copy.dist ?
|
||||
s->end - (c->sub.copy.dist - (q - s->window)) :
|
||||
q - c->sub.copy.dist;
|
||||
#else
|
||||
f = q - c->sub.copy.dist;
|
||||
if ((uInt)(q - s->window) < c->sub.copy.dist)
|
||||
f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
|
||||
#endif
|
||||
while (c->len)
|
||||
{
|
||||
NEEDOUT
|
||||
OUTBYTE(*f++)
|
||||
if (f == s->end)
|
||||
f = s->window;
|
||||
c->len--;
|
||||
}
|
||||
c->mode = START;
|
||||
/*@switchbreak@*/ break;
|
||||
case LIT: /* o: got literal, waiting for output space */
|
||||
NEEDOUT
|
||||
OUTBYTE(c->sub.lit)
|
||||
c->mode = START;
|
||||
/*@switchbreak@*/ break;
|
||||
case WASH: /* o: got eob, possibly more output */
|
||||
if (k > 7) /* return unused byte, if any */
|
||||
{
|
||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; /* can always return one */
|
||||
}
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
goto leave;
|
||||
c->mode = END;
|
||||
/*@fallthrough@*/
|
||||
case END:
|
||||
r = Z_STREAM_END;
|
||||
goto leave;
|
||||
case BADCODE: /* x: got error */
|
||||
r = Z_DATA_ERROR;
|
||||
goto leave;
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
goto leave;
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
|
||||
leave:
|
||||
LEAVE
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
|
||||
void inflate_codes_free(inflate_codes_statef *c, z_streamp z)
|
||||
{
|
||||
ZFREE(z, c);
|
||||
Tracev((stderr, "inflate: codes free\n"));
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ typedef struct inflate_blocks_state FAR inflate_blocks_statef;
|
|||
/*@null@*/
|
||||
extern inflate_blocks_statef * inflate_blocks_new OF((
|
||||
z_streamp z,
|
||||
/*@null@*/ check_func c, /* check function */
|
||||
check_func c, /* check function */
|
||||
uInt w)) /* window size */
|
||||
/*@modifies z @*/;
|
||||
|
||||
|
@ -32,7 +32,7 @@ extern int inflate_blocks OF((
|
|||
extern void inflate_blocks_reset OF((
|
||||
inflate_blocks_statef * s,
|
||||
z_streamp z,
|
||||
/*@null@*/ uLongf *c)) /* check value on output */
|
||||
uLongf * c)) /* check value on output */
|
||||
/*@modifies s, *c, z @*/;
|
||||
|
||||
extern int inflate_blocks_free OF((
|
||||
|
|
|
@ -0,0 +1,243 @@
|
|||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "infblock.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
#include "inffast.h"
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
START, /* x: set up for LEN */
|
||||
LEN, /* i: get length/literal/eob next */
|
||||
LENEXT, /* i: getting length extra (have base) */
|
||||
DIST, /* i: get distance next */
|
||||
DISTEXT, /* i: getting distance extra */
|
||||
COPY, /* o: copying bytes in window, waiting for space */
|
||||
LIT, /* o: got literal, waiting for output space */
|
||||
WASH, /* o: got eob, possibly still output waiting */
|
||||
END, /* x: got eob and all data flushed */
|
||||
BADCODE} /* x: got error */
|
||||
inflate_codes_mode;
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
inflate_codes_mode mode; /* current inflate_codes mode */
|
||||
|
||||
/* mode dependent information */
|
||||
uInt len;
|
||||
union {
|
||||
struct {
|
||||
inflate_huft *tree; /* pointer into tree */
|
||||
uInt need; /* bits needed */
|
||||
} code; /* if LEN or DIST, where in tree */
|
||||
uInt lit; /* if LIT, literal */
|
||||
struct {
|
||||
uInt get; /* bits to get for extra */
|
||||
uInt dist; /* distance back to copy from */
|
||||
} copy; /* if EXT or COPY, where and how much */
|
||||
} sub; /* submode */
|
||||
|
||||
/* mode independent information */
|
||||
Byte lbits; /* ltree bits decoded per branch */
|
||||
Byte dbits; /* dtree bits decoder per branch */
|
||||
inflate_huft *ltree; /* literal/length/eob tree */
|
||||
inflate_huft *dtree; /* distance tree */
|
||||
|
||||
};
|
||||
|
||||
|
||||
inflate_codes_statef *inflate_codes_new(uInt bl, uInt bd,
|
||||
inflate_huft * tl, inflate_huft * td, z_streamp z)
|
||||
{
|
||||
inflate_codes_statef *c;
|
||||
|
||||
if ((c = (inflate_codes_statef *)
|
||||
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
||||
{
|
||||
c->mode = START;
|
||||
c->lbits = (Byte)bl;
|
||||
c->dbits = (Byte)bd;
|
||||
c->ltree = tl;
|
||||
c->dtree = td;
|
||||
Tracev((stderr, "inflate: codes new\n"));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int inflate_codes(inflate_blocks_statef * s, z_streamp z, int r)
|
||||
{
|
||||
uInt j; /* temporary storage */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
Bytef *f; /* pointer to copy strings from */
|
||||
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input and output based on current state */
|
||||
while (1) switch (c->mode)
|
||||
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
case START: /* x: set up for LEN */
|
||||
#ifndef SLOW
|
||||
if (m >= 258 && n >= 10)
|
||||
{
|
||||
UPDATE
|
||||
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
|
||||
LOAD
|
||||
if (r != Z_OK)
|
||||
{
|
||||
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !SLOW */
|
||||
c->sub.code.need = c->lbits;
|
||||
c->sub.code.tree = c->ltree;
|
||||
c->mode = LEN;
|
||||
case LEN: /* i: get length/literal/eob next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e == 0) /* literal */
|
||||
{
|
||||
c->sub.lit = t->base;
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", t->base));
|
||||
c->mode = LIT;
|
||||
break;
|
||||
}
|
||||
if (e & 16) /* length */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->len = t->base;
|
||||
c->mode = LENEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
if (e & 32) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case LENEXT: /* i: getting length extra (have base) */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->len += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
c->sub.code.need = c->dbits;
|
||||
c->sub.code.tree = c->dtree;
|
||||
Tracevv((stderr, "inflate: length %u\n", c->len));
|
||||
c->mode = DIST;
|
||||
case DIST: /* i: get distance next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e & 16) /* distance */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->sub.copy.dist = t->base;
|
||||
c->mode = DISTEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case DISTEXT: /* i: getting distance extra */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
||||
c->mode = COPY;
|
||||
case COPY: /* o: copying bytes in window, waiting for space */
|
||||
f = q - c->sub.copy.dist;
|
||||
while (f < s->window) /* modulo window size-"while" instead */
|
||||
f += s->end - s->window; /* of "if" handles invalid distances */
|
||||
while (c->len)
|
||||
{
|
||||
NEEDOUT
|
||||
OUTBYTE(*f++)
|
||||
if (f == s->end)
|
||||
f = s->window;
|
||||
c->len--;
|
||||
}
|
||||
c->mode = START;
|
||||
break;
|
||||
case LIT: /* o: got literal, waiting for output space */
|
||||
NEEDOUT
|
||||
OUTBYTE(c->sub.lit)
|
||||
c->mode = START;
|
||||
break;
|
||||
case WASH: /* o: got eob, possibly more output */
|
||||
if (k > 7) /* return unused byte, if any */
|
||||
{
|
||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; /* can always return one */
|
||||
}
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
LEAVE
|
||||
c->mode = END;
|
||||
case END:
|
||||
r = Z_STREAM_END;
|
||||
LEAVE
|
||||
case BADCODE: /* x: got error */
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void inflate_codes_free(inflate_codes_statef * c, z_streamp z)
|
||||
{
|
||||
ZFREE(z, c);
|
||||
Tracev((stderr, "inflate: codes free\n"));
|
||||
}
|
|
@ -7,61 +7,18 @@
|
|||
* \file infcodes.h
|
||||
* Header to use infcodes.c.
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
START, /*!< x: set up for LEN */
|
||||
LEN, /*!< i: get length/literal/eob next */
|
||||
LENEXT, /*!< i: getting length extra (have base) */
|
||||
DIST, /*!< i: get distance next */
|
||||
DISTEXT, /*!< i: getting distance extra */
|
||||
COPY, /*!< o: copying bytes in window, waiting for space */
|
||||
LIT, /*!< o: got literal, waiting for output space */
|
||||
WASH, /*!< o: got eob, possibly still output waiting */
|
||||
END, /*!< x: got eob and all data flushed */
|
||||
BADCODE /*!< x: got error */
|
||||
} inflate_codes_mode;
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
inflate_codes_mode mode; /*!< current inflate_codes mode */
|
||||
|
||||
/* mode dependent information */
|
||||
uInt len;
|
||||
union {
|
||||
struct {
|
||||
/*@dependent@*/
|
||||
inflate_huft *tree; /*!< pointer into tree */
|
||||
uInt need; /*!< bits needed */
|
||||
} code; /*!< if LEN or DIST, where in tree */
|
||||
uInt lit; /*!< if LIT, literal */
|
||||
struct {
|
||||
uInt get; /*!< bits to get for extra */
|
||||
uInt dist; /*!< distance back to copy from */
|
||||
} copy; /*!< if EXT or COPY, where and how much */
|
||||
} sub; /*!< submode */
|
||||
|
||||
/* mode independent information */
|
||||
Byte lbits; /*!< ltree bits decoded per branch */
|
||||
Byte dbits; /*!< dtree bits decoder per branch */
|
||||
/*@dependent@*/
|
||||
inflate_huft *ltree; /*!< literal/length/eob tree */
|
||||
/*@dependent@*/
|
||||
inflate_huft *dtree; /*!< distance tree */
|
||||
|
||||
};
|
||||
|
||||
struct inflate_codes_state;
|
||||
typedef struct inflate_codes_state FAR inflate_codes_statef;
|
||||
|
||||
/*@null@*/
|
||||
extern inflate_codes_statef *inflate_codes_new OF((
|
||||
uInt bl, uInt bd,
|
||||
/*@dependent@*/ inflate_huft *tl, /*@dependent@*/ inflate_huft *td,
|
||||
inflate_huft * tl, inflate_huft * td,
|
||||
z_streamp z))
|
||||
/*@*/;
|
||||
|
||||
|
@ -75,4 +32,3 @@ extern void inflate_codes_free OF((
|
|||
/*@only@*/ inflate_codes_statef * s,
|
||||
z_streamp z))
|
||||
/*@*/;
|
||||
|
||||
|
|
127
zlib/inffast.c
127
zlib/inffast.c
|
@ -14,18 +14,15 @@
|
|||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
#include "inffast.h"
|
||||
#include "crc32.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* macros for bit input with no checking and for returning unused bytes */
|
||||
#define GRABBITS(j) {\
|
||||
if (k+8 < (j)) { b |= NEXTSHORT << k; k += 16; } \
|
||||
if (k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
|
||||
|
||||
/* Called with number of bytes left to write in window at least 258
|
||||
|
@ -33,12 +30,9 @@
|
|||
at least ten. The ten bytes are six bytes for the longest length/
|
||||
distance pair plus four bytes for overloading the bit buffer. */
|
||||
|
||||
int inflate_fast(inflate_blocks_statef *s, z_streamp z)
|
||||
int inflate_fast(uInt bl, uInt bd, inflate_huft * tl, inflate_huft * td,
|
||||
inflate_blocks_statef * s, z_streamp z)
|
||||
{
|
||||
inflate_codes_statef *sc = s->sub.decode.codes;
|
||||
uInt bl = sc->lbits, bd = sc->dbits;
|
||||
inflate_huft *tl = sc->ltree;
|
||||
inflate_huft *td = sc->dtree; /* need separate declaration for Borland C++ */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
|
@ -52,17 +46,10 @@ inflate_huft *td = sc->dtree; /* need separate declaration for Borland C++ */
|
|||
uInt c; /* bytes to copy */
|
||||
uInt d; /* distance back to copy from */
|
||||
Bytef *r; /* copy source pointer */
|
||||
int ret;
|
||||
|
||||
/* load input, output, bit values */
|
||||
LOAD
|
||||
|
||||
#if defined(__i386__)
|
||||
/*@-unrecog@*/
|
||||
PREFETCH(p);
|
||||
PREFETCH(p+32);
|
||||
/*@=unrecog@*/
|
||||
#endif
|
||||
/* initialize masks */
|
||||
ml = inflate_mask[bl];
|
||||
md = inflate_mask[bd];
|
||||
|
@ -70,11 +57,6 @@ int ret;
|
|||
/* do until not enough input or output space for fast loop */
|
||||
do { /* assume called with m >= 258 && n >= 10 */
|
||||
/* get literal/length code */
|
||||
#if defined(__i386__)
|
||||
/*@-unrecog@*/
|
||||
PREFETCH(p+64);
|
||||
/*@=unrecog@*/
|
||||
#endif
|
||||
GRABBITS(20) /* max bits for literal/length code */
|
||||
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
|
||||
{
|
||||
|
@ -82,7 +64,8 @@ int ret;
|
|||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
OUTBYTE((Byte)t->base);
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
|
@ -111,7 +94,6 @@ int ret;
|
|||
|
||||
/* do the copy */
|
||||
m -= c;
|
||||
#if 1 /* { */
|
||||
r = q - d;
|
||||
if (r < s->window) /* wrap if needed */
|
||||
{
|
||||
|
@ -122,21 +104,13 @@ int ret;
|
|||
if (c > e)
|
||||
{
|
||||
c -= e; /* wrapped copy */
|
||||
#ifdef __i386__
|
||||
{ int delta = (int)q - (int)r;
|
||||
if (delta <= 0 || delta > 3) {
|
||||
quickmemcpy(q, r, e);
|
||||
q += e;
|
||||
e = 0;
|
||||
goto rest;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--e);
|
||||
rest:
|
||||
r = s->window;
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
else /* normal copy */
|
||||
{
|
||||
|
@ -155,81 +129,56 @@ rest:
|
|||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
#ifdef __i386__
|
||||
{ int delta = (int)q - (int)r;
|
||||
if (delta <= 0 || delta > 3) {
|
||||
quickmemcpy(q, r, c);
|
||||
q += c;
|
||||
r += c;
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* } */
|
||||
/*@innerbreak@*/ break;
|
||||
}
|
||||
else if ((e & 64) == 0)
|
||||
{
|
||||
t += t->base;
|
||||
e = (t += ((uInt)b & inflate_mask[e]))->exop;
|
||||
/*@innercontinue@*/ continue;
|
||||
}
|
||||
else
|
||||
goto inv_dist_code;
|
||||
} while (1);
|
||||
/*@-unreachable@*/
|
||||
/*@innerbreak@*/ break;
|
||||
/*@=unreachable@*/
|
||||
{
|
||||
z->msg = (char*)"invalid distance code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
if (!(e & 64)) {
|
||||
|
||||
} while (1);
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0)
|
||||
{
|
||||
t += t->base;
|
||||
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) != 0)
|
||||
/*@innercontinue@*/ continue;
|
||||
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
|
||||
{
|
||||
DUMPBITS(t->bits)
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
/*@innerbreak@*/ break;
|
||||
} else
|
||||
{ uInt temp = e & 96;
|
||||
if (temp == 96)
|
||||
goto stream_end;
|
||||
if (temp == 64)
|
||||
goto data_error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (e & 32)
|
||||
{
|
||||
Tracevv((stderr, "inflate: * end of block\n"));
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_STREAM_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
z->msg = (char*)"invalid literal/length code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
} while (1);
|
||||
} while (m >= 258 && n >= 10);
|
||||
|
||||
/* not enough input or output--restore pointers and return */
|
||||
ret = Z_OK;
|
||||
|
||||
ungrab:
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return ret;
|
||||
|
||||
data_error:
|
||||
{
|
||||
z->msg = "invalid literal/length code";
|
||||
ret = Z_DATA_ERROR;
|
||||
goto ungrab;
|
||||
}
|
||||
|
||||
stream_end:
|
||||
{
|
||||
Tracevv((stderr, "inflate: * end of block\n"));
|
||||
ret = Z_STREAM_END;
|
||||
goto ungrab;
|
||||
}
|
||||
|
||||
inv_dist_code:
|
||||
{
|
||||
z->msg = "invalid distance code";
|
||||
ret = Z_DATA_ERROR;
|
||||
goto ungrab;
|
||||
}
|
||||
return Z_OK;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,16 @@
|
|||
* \file inffast.h
|
||||
* Header to use inffast.c.
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
extern int inflate_fast OF((
|
||||
inflate_blocks_statef * s,
|
||||
z_streamp z)) // __attribute__((regparm(3)));
|
||||
/*@modifies s, z @*/;
|
||||
uInt,
|
||||
uInt,
|
||||
inflate_huft *,
|
||||
inflate_huft *,
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ));
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
/**
|
||||
* \file inffixed.h
|
||||
* Table for decoding fixed codes.
|
||||
* Generated automatically by the maketree.c program.
|
||||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by the maketree.c program
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
@ -9,11 +7,8 @@
|
|||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/*@unchecked@*/
|
||||
local uInt fixed_bl = 9;
|
||||
/*@unchecked@*/
|
||||
local uInt fixed_bd = 5;
|
||||
/*@unchecked@*/
|
||||
local inflate_huft fixed_tl[] = {
|
||||
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
|
||||
|
@ -144,7 +139,6 @@ local inflate_huft fixed_tl[] = {
|
|||
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
|
||||
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
|
||||
};
|
||||
/*@unchecked@*/
|
||||
local inflate_huft fixed_td[] = {
|
||||
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
|
||||
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
* \file inflate.c
|
||||
* zlib interface to inflate modules.
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
typedef enum {
|
||||
METHOD, /*!< waiting for method byte */
|
||||
|
@ -26,11 +28,10 @@ typedef enum {
|
|||
CHECK2, /*!< two check bytes to go */
|
||||
CHECK1, /*!< one check byte to go */
|
||||
DONE, /*!< finished check, done */
|
||||
BAD /*!< got an error--stay here */
|
||||
} inflate_mode;
|
||||
BAD} /*!< got an error--stay here */
|
||||
inflate_mode;
|
||||
|
||||
/** inflate private state */
|
||||
/*@-redef@*/ /* FIX: deflate.h has duplicate */
|
||||
struct internal_state {
|
||||
|
||||
/* mode */
|
||||
|
@ -53,7 +54,6 @@ struct internal_state {
|
|||
*blocks; /*!< current inflate_blocks state */
|
||||
|
||||
};
|
||||
/*@=redef@*/
|
||||
|
||||
|
||||
int ZEXPORT inflateReset(z_streamp z)
|
||||
|
@ -73,12 +73,8 @@ int ZEXPORT inflateEnd(z_streamp z)
|
|||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
/*@-usereleased@*/
|
||||
/*@-compdef@*/ /* FIX: z->state->blocks may be undefined */
|
||||
if (z->state->blocks != Z_NULL)
|
||||
inflate_blocks_free(z->state->blocks, z);
|
||||
/*@=compdef@*/
|
||||
/*@=usereleased@*/
|
||||
ZFREE(z, z->state);
|
||||
z->state = Z_NULL;
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
|
@ -86,7 +82,8 @@ int ZEXPORT inflateEnd(z_streamp z)
|
|||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_size)
|
||||
int ZEXPORT inflateInit2_(z_streamp z, int w, const char * version,
|
||||
int stream_size)
|
||||
{
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != sizeof(z_stream))
|
||||
|
@ -124,7 +121,6 @@ int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_si
|
|||
z->state->wbits = (uInt)w;
|
||||
|
||||
/* create inflate_blocks state */
|
||||
/*@-evalorder -type@*/
|
||||
if ((z->state->blocks =
|
||||
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
|
||||
== Z_NULL)
|
||||
|
@ -132,7 +128,6 @@ int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_si
|
|||
inflateEnd(z);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
/*@=evalorder =type@*/
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
|
||||
/* reset state */
|
||||
|
@ -147,17 +142,16 @@ int ZEXPORT inflateInit_(z_streamp z, const char *version, int stream_size)
|
|||
}
|
||||
|
||||
|
||||
#define NEEDBYTE {if(z->avail_in==0)goto out_NEEDBYTE;r=f;}
|
||||
#define NEXTBYTE (z->avail_in--,/*z->total_in++,*/ *z->next_in++)
|
||||
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
|
||||
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
|
||||
|
||||
int ZEXPORT inflate(z_streamp z, int f)
|
||||
{
|
||||
int r;
|
||||
uInt b;
|
||||
#if 0
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
#endif
|
||||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||
r = Z_BUF_ERROR;
|
||||
while (1) switch (z->state->mode)
|
||||
|
@ -167,52 +161,47 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = "unknown compression method";
|
||||
z->msg = (char*)"unknown compression method";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = "invalid window size";
|
||||
z->msg = (char*)"invalid window size";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
z->state->mode = FLAG;
|
||||
/*@fallthrough@*/
|
||||
case FLAG:
|
||||
NEEDBYTE
|
||||
b = NEXTBYTE;
|
||||
if (((z->state->sub.method << 8) + b) % 31)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = "incorrect header check";
|
||||
z->msg = (char*)"incorrect header check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||
if (!(b & PRESET_DICT))
|
||||
{
|
||||
z->state->mode = BLOCKS;
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
z->state->mode = DICT4;
|
||||
/*@fallthrough@*/
|
||||
case DICT4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = DICT3;
|
||||
/*@fallthrough@*/
|
||||
case DICT3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = DICT2;
|
||||
/*@fallthrough@*/
|
||||
case DICT2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = DICT1;
|
||||
/*@fallthrough@*/
|
||||
case DICT1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
|
@ -221,7 +210,7 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
return Z_NEED_DICT;
|
||||
case DICT0:
|
||||
z->state->mode = BAD;
|
||||
z->msg = "need dictionary";
|
||||
z->msg = (char*)"need dictionary";
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
return Z_STREAM_ERROR;
|
||||
case BLOCKS:
|
||||
|
@ -230,7 +219,7 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
{
|
||||
z->state->mode = BAD;
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
if (r == Z_OK)
|
||||
r = f;
|
||||
|
@ -241,25 +230,21 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
if (z->state->nowrap)
|
||||
{
|
||||
z->state->mode = DONE;
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
z->state->mode = CHECK4;
|
||||
/*@fallthrough@*/
|
||||
case CHECK4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = CHECK3;
|
||||
/*@fallthrough@*/
|
||||
case CHECK3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = CHECK2;
|
||||
/*@fallthrough@*/
|
||||
case CHECK2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = CHECK1;
|
||||
/*@fallthrough@*/
|
||||
case CHECK1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
|
@ -267,13 +252,12 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
if (z->state->sub.check.was != z->state->sub.check.need)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = "incorrect data check";
|
||||
z->msg = (char*)"incorrect data check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
/*@switchbreak@*/ break;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib check ok\n"));
|
||||
z->state->mode = DONE;
|
||||
/*@fallthrough@*/
|
||||
case DONE:
|
||||
return Z_STREAM_END;
|
||||
case BAD:
|
||||
|
@ -284,13 +268,11 @@ int ZEXPORT inflate(z_streamp z, int f)
|
|||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
|
||||
out_NEEDBYTE:
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dictLength)
|
||||
int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef * dictionary,
|
||||
uInt dictLength)
|
||||
{
|
||||
uInt length = dictLength;
|
||||
|
||||
|
@ -311,7 +293,6 @@ int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dict
|
|||
}
|
||||
|
||||
|
||||
/*@-compmempass@*/
|
||||
int ZEXPORT inflateSync(z_streamp z)
|
||||
{
|
||||
uInt n; /* number of bytes to look at */
|
||||
|
@ -360,7 +341,6 @@ int ZEXPORT inflateSync(z_streamp z)
|
|||
z->state->mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
|
||||
/**
|
||||
|
|
146
zlib/inftrees.c
146
zlib/inftrees.c
|
@ -1,94 +1,92 @@
|
|||
/*
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file inftrees.c
|
||||
* Generate Huffman trees for efficient decoding.
|
||||
*
|
||||
* Huffman code decoding is performed using a multi-level table lookup.
|
||||
* The fastest way to decode is to simply build a lookup table whose
|
||||
* size is determined by the longest code. However, the time it takes
|
||||
* to build this table can also be a factor if the data being decoded
|
||||
* is not very long. The most common codes are necessarily the
|
||||
* shortest codes, so those codes dominate the decoding time, and hence
|
||||
* the speed. The idea is you can have a shorter table that decodes the
|
||||
* shorter, more probable codes, and then point to subsidiary tables for
|
||||
* the longer codes. The time it costs to decode the longer codes is
|
||||
* then traded against the time it takes to make longer tables.
|
||||
*
|
||||
* This results of this trade are in the variables lbits and dbits
|
||||
* below. lbits is the number of bits the first level table for literal/
|
||||
* length codes can decode in one step, and dbits is the same thing for
|
||||
* the distance codes. Subsequent tables are also less than or equal to
|
||||
* those sizes. These values may be adjusted either when all of the
|
||||
* codes are shorter than that, in which case the longest code length in
|
||||
* bits is used, or when the shortest code is *longer* than the requested
|
||||
* table size, in which case the length of the shortest code in bits is
|
||||
* used.
|
||||
*
|
||||
* There are two different values for the two tables, since they code a
|
||||
* different number of possibilities each. The literal/length table
|
||||
* codes 286 possible values, or in a flat code, a little over eight
|
||||
* bits. The distance table codes 30 possible values, or a little less
|
||||
* than five bits, flat. The optimum values for speed end up being
|
||||
* about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||
* The optimum values may differ though from machine to machine, and
|
||||
* possibly even between compilers. Your mileage may vary.
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
|
||||
#if !defined(BUILDFIXED) && !defined(STDC)
|
||||
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* If you use the zlib library in a product, an acknowledgment is welcome
|
||||
* in the documentation of your product. If for some reason you cannot
|
||||
* include such an acknowledgment, I would appreciate that you keep this
|
||||
* copyright string in the executable of your product.
|
||||
*/
|
||||
/*@-exportheadervar@*/
|
||||
/*@unused@*/ /*@observer@*/
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
|
||||
/*@=exportheadervar@*/
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
include such an acknowledgment, I would appreciate that you keep this
|
||||
copyright string in the executable of your product.
|
||||
*/
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
local int huft_build(uIntf *b, uInt n, uInt s, /*@null@*/ const uIntf *d,
|
||||
/*@null@*/ const uIntf *e, /*@out@*/ inflate_huft * FAR *t,
|
||||
uIntf *m, inflate_huft *hp, uInt *hn, uIntf *v)
|
||||
/*@modifies *t, *m, *hp, *hn, *v @*/;
|
||||
|
||||
local int huft_build OF((
|
||||
uIntf *, /* code lengths in bits */
|
||||
uInt, /* number of codes */
|
||||
uInt, /* number of "simple" codes */
|
||||
const uIntf *, /* list of base values for non-simple codes */
|
||||
const uIntf *, /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR*,/* result: starting table */
|
||||
uIntf *, /* maximum lookup bits (returns actual) */
|
||||
inflate_huft *, /* space for trees */
|
||||
uInt *, /* hufts used in space */
|
||||
uIntf * )); /* space for values */
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
|
||||
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};
|
||||
/* see note #13 above about 258 */
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
|
||||
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, 112, 112}; /* 112==invalid */
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
|
||||
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,
|
||||
8193, 12289, 16385, 24577};
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
||||
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};
|
||||
|
||||
/*
|
||||
Huffman code decoding is performed using a multi-level table lookup.
|
||||
The fastest way to decode is to simply build a lookup table whose
|
||||
size is determined by the longest code. However, the time it takes
|
||||
to build this table can also be a factor if the data being decoded
|
||||
is not very long. The most common codes are necessarily the
|
||||
shortest codes, so those codes dominate the decoding time, and hence
|
||||
the speed. The idea is you can have a shorter table that decodes the
|
||||
shorter, more probable codes, and then point to subsidiary tables for
|
||||
the longer codes. The time it costs to decode the longer codes is
|
||||
then traded against the time it takes to make longer tables.
|
||||
|
||||
This results of this trade are in the variables lbits and dbits
|
||||
below. lbits is the number of bits the first level table for literal/
|
||||
length codes can decode in one step, and dbits is the same thing for
|
||||
the distance codes. Subsequent tables are also less than or equal to
|
||||
those sizes. These values may be adjusted either when all of the
|
||||
codes are shorter than that, in which case the longest code length in
|
||||
bits is used, or when the shortest code is *longer* than the requested
|
||||
table size, in which case the length of the shortest code in bits is
|
||||
used.
|
||||
|
||||
There are two different values for the two tables, since they code a
|
||||
different number of possibilities each. The literal/length table
|
||||
codes 286 possible values, or in a flat code, a little over eight
|
||||
bits. The distance table codes 30 possible values, or a little less
|
||||
than five bits, flat. The optimum values for speed end up being
|
||||
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||
The optimum values may differ though from machine to machine, and
|
||||
possibly even between compilers. Your mileage may vary.
|
||||
*/
|
||||
|
||||
|
||||
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
|
||||
#define BMAX 15 /* maximum bit length of any code */
|
||||
|
||||
|
@ -96,7 +94,7 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
|||
* Given a list of code lengths and a maximum table size, make a set of
|
||||
* tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
* if the given code set is incomplete (the tables are still built in this
|
||||
* case), or Z_DATA_ERROR if the input is invalid. */
|
||||
* case), or Z_DATA_ERROR if the input is invalid.
|
||||
*
|
||||
* @param b code lengths in bits (all assumed <= BMAX)
|
||||
* @param n number of codes (assumed <= 288)
|
||||
|
@ -110,9 +108,8 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
|||
* @param v working area: values in order of bit length
|
||||
*/
|
||||
local int huft_build(uIntf * b, uInt n, uInt s, const uIntf * d,
|
||||
const uIntf *e, inflate_huft * FAR *t, uIntf *m,
|
||||
inflate_huft *hp, uInt *hn, uIntf *v)
|
||||
/*@modifies *t, *m, *hp, *hn, *v @*/
|
||||
const uIntf * e, inflate_huft * FAR * t,
|
||||
uIntf * m, inflate_huft * hp, uInt * hn, uIntf * v)
|
||||
{
|
||||
|
||||
uInt a; /* counter for codes of length k */
|
||||
|
@ -172,13 +169,11 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d,
|
|||
|
||||
|
||||
/* Adjust last length count to fill out codes, if needed */
|
||||
/*@-unsignedcompare@*/
|
||||
for (y = 1 << j; j < i; j++, y <<= 1)
|
||||
if ((y -= c[j]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
if ((y -= c[i]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
/*@=unsignedcompare@*/
|
||||
c[i] += y;
|
||||
|
||||
|
||||
|
@ -232,7 +227,7 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d,
|
|||
while (++j < z) /* try smaller tables up to z bits */
|
||||
{
|
||||
if ((f <<= 1) <= *++xp)
|
||||
/*@innerbreak@*/ break; /* enough codes to use up j bits */
|
||||
break; /* enough codes to use up j bits */
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
|
@ -269,20 +264,14 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d,
|
|||
}
|
||||
else
|
||||
{
|
||||
/*@-nullderef@*/ /* FIX: d and e might be NULL */
|
||||
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
|
||||
r.base = d[*p++ - s];
|
||||
/*@=nullderef@*/
|
||||
}
|
||||
|
||||
/* fill code-like entries with r */
|
||||
f = 1 << (k - w);
|
||||
/*@-nullderef@*/ /* FIX: q might be NULL */
|
||||
/*@-compdef@*/ /* FIX: r.base may be undefined */
|
||||
for (j = i >> w; j < z; j += f)
|
||||
q[j] = r;
|
||||
/*@=compdef@*/
|
||||
/*@=nullderef@*/
|
||||
|
||||
/* backwards increment the k-bit code i */
|
||||
for (j = 1 << (k - 1); i & j; j >>= 1)
|
||||
|
@ -325,10 +314,10 @@ int inflate_trees_bits( uIntf *c, uIntf *bb, inflate_huft * FAR *tb,
|
|||
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
|
||||
tb, bb, hp, &hn, v);
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = "oversubscribed dynamic bit lengths tree";
|
||||
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
|
||||
else if (r == Z_BUF_ERROR || *bb == 0)
|
||||
{
|
||||
z->msg = "incomplete dynamic bit lengths tree";
|
||||
z->msg = (char*)"incomplete dynamic bit lengths tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
|
@ -337,7 +326,6 @@ int inflate_trees_bits( uIntf *c, uIntf *bb, inflate_huft * FAR *tb,
|
|||
|
||||
|
||||
/**
|
||||
* @param nl number of literal/length codes
|
||||
* @param nd number of distance codes
|
||||
* @param c that many (total) code lengths
|
||||
* @param bl literal desired/actual bit depth
|
||||
|
@ -347,8 +335,8 @@ int inflate_trees_bits( uIntf *c, uIntf *bb, inflate_huft * FAR *tb,
|
|||
* @param hp space for trees
|
||||
* @param z for messages
|
||||
*/
|
||||
int inflate_trees_dynamic( uInt nl, uInt nd, uIntf *c, uIntf *bl,
|
||||
uIntf *bd, inflate_huft * FAR *tl, inflate_huft * FAR *td,
|
||||
int inflate_trees_dynamic(uInt nl, uInt nd, uIntf * c, uIntf * bl, uIntf * bd,
|
||||
inflate_huft * FAR * tl, inflate_huft * FAR * td,
|
||||
inflate_huft * hp, z_streamp z)
|
||||
{
|
||||
int r;
|
||||
|
@ -364,10 +352,10 @@ int inflate_trees_dynamic( uInt nl, uInt nd, uIntf *c, uIntf *bl,
|
|||
if (r != Z_OK || *bl == 0)
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = "oversubscribed literal/length tree";
|
||||
z->msg = (char*)"oversubscribed literal/length tree";
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = "incomplete literal/length tree";
|
||||
z->msg = (char*)"incomplete literal/length tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
|
@ -379,18 +367,18 @@ int inflate_trees_dynamic( uInt nl, uInt nd, uIntf *c, uIntf *bl,
|
|||
if (r != Z_OK || (*bd == 0 && nl > 257))
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = "oversubscribed distance tree";
|
||||
z->msg = (char*)"oversubscribed distance tree";
|
||||
else if (r == Z_BUF_ERROR) {
|
||||
#ifdef PKZIP_BUG_WORKAROUND
|
||||
r = Z_OK;
|
||||
}
|
||||
#else
|
||||
z->msg = "incomplete distance tree";
|
||||
z->msg = (char*)"incomplete distance tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = "empty distance tree with lengths";
|
||||
z->msg = (char*)"empty distance tree with lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
|
@ -426,7 +414,7 @@ local inflate_huft *fixed_td;
|
|||
* @param z for memory allocation
|
||||
*/
|
||||
int inflate_trees_fixed(uIntf * bl, uIntf * bd, inflate_huft * FAR * tl,
|
||||
inflate_huft * FAR *td, /*@unused@*/ z_streamp z)
|
||||
inflate_huft * FAR * td, z_streamp z)
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
/* build fixed tables if not already */
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* \file inftrees.h
|
||||
* Header to use inftrees.c.
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
|
@ -43,8 +44,7 @@ extern int inflate_trees_bits OF((
|
|||
uIntf * bb, /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR * tb, /* bits tree result */
|
||||
inflate_huft * hp, /* space for trees */
|
||||
z_streamp z)) /* for messages */
|
||||
/*@modifies *bb, *tb, *hp, z @*/;
|
||||
z_streamp z)); /* for messages */
|
||||
|
||||
extern int inflate_trees_dynamic OF((
|
||||
uInt nl, /* number of literal/length codes */
|
||||
|
@ -52,22 +52,14 @@ extern int inflate_trees_dynamic OF((
|
|||
uIntf * c, /* that many (total) code lengths */
|
||||
uIntf * bl, /* literal desired/actual bit depth */
|
||||
uIntf * bd, /* distance desired/actual bit depth */
|
||||
/*@out@*/
|
||||
inflate_huft * FAR * tl, /* literal/length tree result */
|
||||
/*@out@*/
|
||||
inflate_huft * FAR * td, /* distance tree result */
|
||||
inflate_huft * hp, /* space for trees */
|
||||
z_streamp z)) /* for messages */
|
||||
/*@modifies *bl, *bd, *tl, *td, *hp, z @*/;
|
||||
z_streamp z)); /* for messages */
|
||||
|
||||
extern int inflate_trees_fixed OF((
|
||||
/*@out@*/
|
||||
uIntf * bl, /* literal desired/actual bit depth */
|
||||
/*@out@*/
|
||||
uIntf * bd, /* distance desired/actual bit depth */
|
||||
/*@out@*/
|
||||
inflate_huft * FAR * tl, /* literal/length tree result */
|
||||
/*@out@*/
|
||||
inflate_huft * FAR * td, /* distance tree result */
|
||||
z_streamp z)) /* for memory allocation */
|
||||
/*@modifies *bl, *bd, *tl, *td, z @*/;
|
||||
z_streamp z)); /* for memory allocation */
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
/*
|
||||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file infutil.c
|
||||
* Data and routines common to blocks and codes.
|
||||
*/
|
||||
#if 1
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
#include "inftrees.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
#endif
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
/*@access z_streamp@*/
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* And'ing with mask[n] masks the lower n bits */
|
||||
uInt inflate_mask[17] = {
|
||||
|
@ -27,9 +19,7 @@ uInt inflate_mask[17] = {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Copy as much as possible from the sliding window to the output area.
|
||||
*/
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
int inflate_flush(inflate_blocks_statef * s, z_streamp z, int r)
|
||||
{
|
||||
uInt n;
|
||||
|
@ -50,25 +40,11 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
/*@-moduncon@*/
|
||||
#if defined(__i386__)
|
||||
if (s->checkfn == Z_NULL)
|
||||
z->crc = partial_crc32_copy(z->crc, q, n, p);
|
||||
else if (s->checkfn != Z_NULL) {
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
/*@=moduncon@*/
|
||||
|
||||
/* copy as far as end of window */
|
||||
zmemcpy(p, q, n);
|
||||
}
|
||||
#else
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy as far as end of window */
|
||||
zmemcpy(p, q, n);
|
||||
#endif
|
||||
|
||||
p += n;
|
||||
q += n;
|
||||
|
||||
|
@ -90,28 +66,11 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
|
|||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
#if defined(__i386__)
|
||||
/*@-moduncon@*/
|
||||
if (!s->checkfn)
|
||||
z->crc = partial_crc32_copy(z->crc, q, n, p);
|
||||
else if (s->checkfn != Z_NULL) {
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
/*@=moduncon@*/
|
||||
/* copy */
|
||||
/*@-aliasunique@*/
|
||||
zmemcpy(p, q, n);
|
||||
/*@=aliasunique@*/
|
||||
}
|
||||
#else
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy */
|
||||
/*@-aliasunique@*/
|
||||
zmemcpy(p, q, n);
|
||||
/*@=aliasunique@*/
|
||||
#endif
|
||||
|
||||
p += n;
|
||||
q += n;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,9 @@ typedef enum {
|
|||
DTREE, /*!< get length, distance trees for a dynamic block */
|
||||
CODES, /*!< processing fixed or dynamic block */
|
||||
DRY, /*!< output remaining window bytes */
|
||||
/*@-redef@*/ /* FIX: inflate .c has duplicates */
|
||||
DONE, /*!< finished last block, done */
|
||||
BAD /*!< got a data error--stuck here */
|
||||
/*@=redef@*/
|
||||
} inflate_block_mode;
|
||||
BAD} /*!< got a data error--stuck here */
|
||||
inflate_block_mode;
|
||||
|
||||
/* inflate blocks semi-private state */
|
||||
struct inflate_blocks_state {
|
||||
|
@ -57,17 +55,11 @@ struct inflate_blocks_state {
|
|||
/* mode independent information */
|
||||
uInt bitk; /*!< bits in bit buffer */
|
||||
uLong bitb; /*!< bit buffer */
|
||||
/*@only@*/
|
||||
inflate_huft *hufts; /*!< single malloc for tree space */
|
||||
/*@owned@*/
|
||||
Bytef *window; /*!< sliding window */
|
||||
/*@dependent@*/
|
||||
Bytef *end; /*!< one byte after sliding window */
|
||||
/*@dependent@*/
|
||||
Bytef *read; /*!< window read pointer */
|
||||
/*@dependent@*/
|
||||
Bytef *write; /*!< window write pointer */
|
||||
/*@null@*/
|
||||
check_func checkfn; /*!< check function */
|
||||
uLong check; /*!< check on output */
|
||||
|
||||
|
@ -85,11 +77,6 @@ struct inflate_blocks_state {
|
|||
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
|
||||
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
|
||||
#define NEXTBYTE (n--,*p++)
|
||||
#ifdef __i386__
|
||||
#define NEXTSHORT (n-=2, p+=2, (uLong)((unsigned short *)p)[-1])
|
||||
#else
|
||||
#define NEXTSHORT (n-=2, p+=2, (uLong)p[-2] | ((uLong)p[-1] << 8))
|
||||
#endif
|
||||
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define DUMPBITS(j) {b>>=(j);k-=(j);}
|
||||
/* output bytes */
|
||||
|
@ -102,18 +89,16 @@ struct inflate_blocks_state {
|
|||
/* load local pointers */
|
||||
#define LOAD {LOADIN LOADOUT}
|
||||
|
||||
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
||||
/** masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
||||
/*@unchecked@*/
|
||||
extern uInt inflate_mask[17];
|
||||
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
int inflate_flush OF((
|
||||
/** copy as much as possible from the sliding window to the output area */
|
||||
extern int inflate_flush OF((
|
||||
inflate_blocks_statef * s,
|
||||
z_streamp z,
|
||||
int r))
|
||||
#if defined(__i386__)
|
||||
__attribute__((regparm(3)))
|
||||
#endif
|
||||
/*@modifies s, z @*/;
|
||||
int r));
|
||||
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2492,7 +2492,7 @@ EOF
|
|||
for i in $deplibs; do
|
||||
name="`expr $i : '-l\(.*\)'`"
|
||||
# If $name is empty we are operating on a -L argument.
|
||||
if test "$name" != "" -a "$name" -ne "0"; then
|
||||
if test -n "$name" && test "$name" != "0"; then
|
||||
libname=`eval \\$echo \"$libname_spec\"`
|
||||
deplib_matches=`eval \\$echo \"$library_names_spec\"`
|
||||
set dummy $deplib_matches
|
||||
|
@ -2517,7 +2517,7 @@ EOF
|
|||
for i in $deplibs; do
|
||||
name="`expr $i : '-l\(.*\)'`"
|
||||
# If $name is empty we are operating on a -L argument.
|
||||
if test "$name" != "" -a "$name" != "0"; then
|
||||
if test -n "$name" && test "$name" != "0"; then
|
||||
$rm conftest
|
||||
$CC -o conftest conftest.c $i
|
||||
# Did it work?
|
||||
|
@ -2557,7 +2557,7 @@ EOF
|
|||
for a_deplib in $deplibs; do
|
||||
name="`expr $a_deplib : '-l\(.*\)'`"
|
||||
# If $name is empty we are operating on a -L argument.
|
||||
if test "$name" != "" -a "$name" != "0"; then
|
||||
if test -n "$name" && test "$name" != "0"; then
|
||||
libname=`eval \\$echo \"$libname_spec\"`
|
||||
for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
|
||||
potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
|
||||
|
@ -2580,13 +2580,6 @@ EOF
|
|||
*) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
|
||||
esac
|
||||
done
|
||||
# It is ok to link against an archive when
|
||||
# building a shared library.
|
||||
if $AR -t $potlib > /dev/null 2>&1; then
|
||||
newdeplibs="$newdeplibs $a_deplib"
|
||||
a_deplib=""
|
||||
break 2
|
||||
fi
|
||||
if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \
|
||||
| sed 10q \
|
||||
| egrep "$file_magic_regex" > /dev/null; then
|
||||
|
@ -4744,23 +4737,9 @@ relink_command=\"$relink_command\""
|
|||
;;
|
||||
|
||||
*.lo)
|
||||
# Possibly a libtool object, so verify it.
|
||||
if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
|
||||
|
||||
# Read the .lo file
|
||||
. $dir/$name
|
||||
|
||||
# Add PIC object to the list of files to remove.
|
||||
if test -n "$pic_object" \
|
||||
&& test "$pic_object" != none; then
|
||||
rmfiles="$rmfiles $dir/$pic_object"
|
||||
fi
|
||||
|
||||
# Add non-PIC object to the list of files to remove.
|
||||
if test -n "$non_pic_object" \
|
||||
&& test "$non_pic_object" != none; then
|
||||
rmfiles="$rmfiles $dir/$non_pic_object"
|
||||
fi
|
||||
if test "$build_old_libs" = yes; then
|
||||
oldobj=`$echo "X$name" | $Xsed -e "$lo2o"`
|
||||
rmfiles="$rmfiles $dir/$oldobj"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
/*
|
||||
/* maketree.c -- make inffixed.h table for decoding fixed codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file maketree.c
|
||||
* Make inffixed.h table for decoding fixed codes.
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
/* @(#) $Id: minigzip.c,v 1.3 2001/12/27 21:00:18 jbj Exp $ */
|
||||
/*
|
||||
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file minigzip.c
|
||||
* Simulate gzip using the zlib compression library.
|
||||
*
|
||||
/*
|
||||
* minigzip is a minimal implementation of the gzip utility. This is
|
||||
* only an example of using zlib and isn't meant to replace the
|
||||
* full-featured gzip. No attempt is made to deal with file systems
|
||||
|
@ -17,6 +13,8 @@
|
|||
* or in pipe mode.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
|
||||
|
@ -63,7 +61,7 @@
|
|||
#endif
|
||||
#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
|
||||
|
||||
#define BUFLEN (16384 * 2)
|
||||
#define BUFLEN 16384
|
||||
#define MAX_NAME_LEN 1024
|
||||
|
||||
#ifdef MAXSEG_64K
|
||||
|
@ -88,8 +86,7 @@ int main OF((int argc, char *argv[]));
|
|||
/* ===========================================================================
|
||||
* Display error message and exit
|
||||
*/
|
||||
void error(msg)
|
||||
const char *msg;
|
||||
void error(const char * msg)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", prog, msg);
|
||||
exit(1);
|
||||
|
@ -99,9 +96,7 @@ void error(msg)
|
|||
* Compress input to output then close both files.
|
||||
*/
|
||||
|
||||
void gz_compress(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
void gz_compress(FILE * in, gzFile out)
|
||||
{
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
|
@ -132,9 +127,7 @@ void gz_compress(in, out)
|
|||
/* Try compressing the input file at once using mmap. Return Z_OK if
|
||||
* if success, Z_ERRNO otherwise.
|
||||
*/
|
||||
int gz_compress_mmap(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
int gz_compress_mmap(FILE * in, gzFile out)
|
||||
{
|
||||
int len;
|
||||
int err;
|
||||
|
@ -167,9 +160,7 @@ int gz_compress_mmap(in, out)
|
|||
/* ===========================================================================
|
||||
* Uncompress input to output then close both files.
|
||||
*/
|
||||
void gz_uncompress(in, out)
|
||||
gzFile in;
|
||||
FILE *out;
|
||||
void gz_uncompress(gzFile in, FILE * out)
|
||||
{
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
|
@ -194,9 +185,7 @@ void gz_uncompress(in, out)
|
|||
* Compress the given file: create a corresponding .gz file and remove the
|
||||
* original.
|
||||
*/
|
||||
void file_compress(file, mode)
|
||||
char *file;
|
||||
char *mode;
|
||||
void file_compress(char * file, char * mode)
|
||||
{
|
||||
local char outfile[MAX_NAME_LEN];
|
||||
FILE *in;
|
||||
|
@ -224,8 +213,7 @@ void file_compress(file, mode)
|
|||
/* ===========================================================================
|
||||
* Uncompress the given file and remove the original.
|
||||
*/
|
||||
void file_uncompress(file)
|
||||
char *file;
|
||||
void file_uncompress(char * file)
|
||||
{
|
||||
local char buf[MAX_NAME_LEN];
|
||||
char *infile, *outfile;
|
||||
|
@ -269,9 +257,7 @@ void file_uncompress(file)
|
|||
* -1 to -9 : compression level
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int uncompr = 0;
|
||||
gzFile file;
|
||||
|
|
124
zlib/trees.c
124
zlib/trees.c
|
@ -1,4 +1,3 @@
|
|||
/* @(#) $Id: trees.c,v 1.6 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
@ -8,6 +7,7 @@
|
|||
* \file trees.c
|
||||
* Output deflated data using Huffman coding.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ALGORITHM
|
||||
*
|
||||
|
@ -34,6 +34,8 @@
|
|||
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
/* #define GEN_TREES_H */
|
||||
|
||||
#include "deflate.h"
|
||||
|
@ -42,7 +44,8 @@
|
|||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
|
@ -85,11 +88,12 @@ local const uch bl_order[BL_CODES]
|
|||
* more than 16 bits on some systems.)
|
||||
*/
|
||||
|
||||
/* ===========================================================================
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Local data. These are initialized only once.
|
||||
*/
|
||||
|
||||
#define DIST_CODE_LEN 512 /*!< see definition of array dist_code below */
|
||||
#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
/* non ANSI compilers may not accept trees.h */
|
||||
|
@ -149,7 +153,8 @@ local static_tree_desc static_d_desc =
|
|||
local static_tree_desc static_bl_desc =
|
||||
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
|
||||
|
||||
/* ===========================================================================
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Local (static) routines in this file.
|
||||
*/
|
||||
|
||||
|
@ -185,8 +190,8 @@ local void bi_windup OF((deflate_state *s))
|
|||
/*@modifies *s @*/;
|
||||
local void bi_flush OF((deflate_state *s))
|
||||
/*@modifies *s @*/;
|
||||
local void copy_block OF((deflate_state *s, /*@null@*/ charf *buf,
|
||||
unsigned len, int header))
|
||||
local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
|
||||
int header))
|
||||
/*@modifies *s @*/;
|
||||
|
||||
#ifdef GEN_TREES_H
|
||||
|
@ -220,13 +225,9 @@ local void gen_trees_header OF((void))
|
|||
* IN assertion: length <= 16 and value fits in length bits.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
local void send_bits OF((deflate_state *s, int value, int length))
|
||||
/*@*/;
|
||||
local void send_bits OF((deflate_state *s, int value, int length));
|
||||
|
||||
local void send_bits(s, value, length)
|
||||
deflate_state *s;
|
||||
int value; /* value to send */
|
||||
int length; /* number of bits */
|
||||
local void send_bits(deflate_state * s, int value, int length)
|
||||
{
|
||||
Tracevv((stderr," l %2d v %4x ", length, value));
|
||||
Assert(length > 0 && length <= 15, "invalid length");
|
||||
|
@ -271,7 +272,7 @@ local void send_bits(s, value, length)
|
|||
/**
|
||||
* Initialize the various 'constant' tables.
|
||||
*/
|
||||
local void tr_static_init()
|
||||
local void tr_static_init(void)
|
||||
{
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
static int static_init_done = 0;
|
||||
|
@ -353,7 +354,7 @@ local void tr_static_init()
|
|||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Genererate the file trees.h describing the static trees.
|
||||
* Generate the file trees.h describing the static trees.
|
||||
*/
|
||||
#ifdef GEN_TREES_H
|
||||
# ifndef DEBUG
|
||||
|
@ -364,7 +365,7 @@ local void tr_static_init()
|
|||
((i) == (last)? "\n};\n\n" : \
|
||||
((i) % (width) == (width)-1 ? ",\n" : ", "))
|
||||
|
||||
void gen_trees_header()
|
||||
void gen_trees_header(void)
|
||||
{
|
||||
FILE *header = fopen("trees.h", "w");
|
||||
int i;
|
||||
|
@ -417,14 +418,10 @@ void gen_trees_header()
|
|||
/**
|
||||
* Initialize the tree data structures for a new zlib stream.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
void _tr_init(deflate_state * s)
|
||||
{
|
||||
/*@-noeffect@*/
|
||||
tr_static_init();
|
||||
/*@=noeffect@*/
|
||||
|
||||
/*@-immediatetrans@*/
|
||||
s->l_desc.dyn_tree = s->dyn_ltree;
|
||||
s->l_desc.stat_desc = &static_l_desc;
|
||||
|
||||
|
@ -433,12 +430,11 @@ void _tr_init(deflate_state *s)
|
|||
|
||||
s->bl_desc.dyn_tree = s->bl_tree;
|
||||
s->bl_desc.stat_desc = &static_bl_desc;
|
||||
/*@=immediatetrans@*/
|
||||
|
||||
s->bi_buf = 0;
|
||||
s->bi_valid = 0;
|
||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len = 0L;
|
||||
s->bits_sent = 0L;
|
||||
#endif
|
||||
|
@ -446,13 +442,11 @@ void _tr_init(deflate_state *s)
|
|||
/* Initialize the first block of the first file: */
|
||||
init_block(s);
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Initialize a new block.
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local void init_block(deflate_state * s)
|
||||
{
|
||||
int n; /* iterates over tree elements */
|
||||
|
@ -466,7 +460,6 @@ local void init_block(deflate_state *s)
|
|||
s->opt_len = s->static_len = 0L;
|
||||
s->last_lit = s->matches = 0;
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
#define SMALLEST 1
|
||||
/* Index within the heap array of least frequent node in the Huffman tree */
|
||||
|
@ -486,19 +479,19 @@ local void init_block(deflate_state *s)
|
|||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Compares two subtrees, using the tree depth as tie breaker when
|
||||
* Compares to subtrees, using the tree depth as tie breaker when
|
||||
* the subtrees have equal frequency. This minimizes the worst case length.
|
||||
*/
|
||||
#define smaller(tree, n, m, depth) \
|
||||
(tree[n].Freq < tree[m].Freq || \
|
||||
(tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Restore the heap property by moving down the tree starting at node k,
|
||||
* exchanging a node with the smallest of its two sons if necessary, stopping
|
||||
* when the heap property is re-established (each father smaller than its
|
||||
* two sons).
|
||||
*
|
||||
* @param s
|
||||
* @param tree the tree to restore
|
||||
* @param k node to move down
|
||||
|
@ -525,6 +518,7 @@ local void pqdownheap(deflate_state *s, ct_data *tree, int k)
|
|||
s->heap[k] = v;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Compute the optimal bit lengths for a tree and update the total bit length
|
||||
* for the current block.
|
||||
|
@ -534,9 +528,6 @@ local void pqdownheap(deflate_state *s, ct_data *tree, int k)
|
|||
* array bl_count contains the frequencies for each bit length.
|
||||
* The length opt_len is updated; static_len is also updated if stree is
|
||||
* not null.
|
||||
*
|
||||
* @param s
|
||||
* @param desc the tree descriptor
|
||||
*/
|
||||
local void gen_bitlen(deflate_state * s, tree_desc * desc)
|
||||
{
|
||||
|
@ -571,9 +562,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc)
|
|||
|
||||
s->bl_count[bits]++;
|
||||
xbits = 0;
|
||||
/*@-nullderef@*/ /* FIX: extra may be NULL */
|
||||
if (n >= base) xbits = extra[n-base];
|
||||
/*@=nullderef@*/
|
||||
f = tree[n].Freq;
|
||||
s->opt_len += (ulg)f * (bits + xbits);
|
||||
if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
|
||||
|
@ -605,7 +594,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc)
|
|||
n = s->bl_count[bits];
|
||||
while (n != 0) {
|
||||
m = s->heap[--h];
|
||||
if (m > max_code) /*@innercontinue@*/ continue;
|
||||
if (m > max_code) continue;
|
||||
if (tree[m].Len != (unsigned) bits) {
|
||||
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
|
||||
s->opt_len += ((long)bits - (long)tree[m].Len)
|
||||
|
@ -617,6 +606,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc)
|
|||
}
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Generate the codes for a given tree and bit counts (which need not be
|
||||
* optimal).
|
||||
|
@ -624,7 +614,6 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc)
|
|||
* the given tree and the field len is set for all tree elements.
|
||||
* OUT assertion: the field code is set for all tree elements of non
|
||||
* zero code length.
|
||||
*
|
||||
* @param tree the tree to decorate
|
||||
* @param max_code largest code with non zero frequency
|
||||
* @param bl_count number of codes at each bit length
|
||||
|
@ -660,6 +649,7 @@ local void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
|
|||
}
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Construct one Huffman tree and assigns the code bit strings and lengths.
|
||||
* Update the total bit length for the current block.
|
||||
|
@ -667,9 +657,6 @@ local void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
|
|||
* OUT assertions: the fields len and code are set to the optimal bit length
|
||||
* and corresponding code. The length opt_len is updated; static_len is
|
||||
* also updated if stree is not null. The field max_code is set.
|
||||
*
|
||||
* @param s
|
||||
* @param desc the tree descriptor
|
||||
*/
|
||||
local void build_tree(deflate_state * s, tree_desc * desc)
|
||||
{
|
||||
|
@ -728,9 +715,7 @@ local void build_tree(deflate_state *s, tree_desc *desc)
|
|||
/* Create a new node father of n and m */
|
||||
tree[node].Freq = tree[n].Freq + tree[m].Freq;
|
||||
s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
|
||||
/*@-evalorder@*/
|
||||
tree[n].Dad = tree[m].Dad = (ush)node;
|
||||
/*@=evalorder@*/
|
||||
#ifdef DUMP_BL_TREE
|
||||
if (tree == s->bl_tree) {
|
||||
fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
|
||||
|
@ -754,16 +739,18 @@ local void build_tree(deflate_state *s, tree_desc *desc)
|
|||
gen_codes ((ct_data *)tree, max_code, s->bl_count);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Scan a literal or distance tree to determine the frequencies of the codes
|
||||
* in the bit length tree.
|
||||
*
|
||||
* @param s
|
||||
* @param tree the tree to be scanned
|
||||
* @param max_code and its largest code of non zero frequency
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
local void scan_tree (deflate_state *s, ct_data *tree, int max_code)
|
||||
local void scan_tree (s, tree, max_code)
|
||||
deflate_state *s;
|
||||
ct_data *tree; /* the tree to be scanned */
|
||||
int max_code; /* and its largest code of non zero frequency */
|
||||
{
|
||||
int n; /* iterates over all tree elements */
|
||||
int prevlen = -1; /* last emitted length */
|
||||
|
@ -800,12 +787,11 @@ local void scan_tree (deflate_state *s, ct_data *tree, int max_code)
|
|||
}
|
||||
}
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Send a literal or distance tree in compressed form, using the codes in
|
||||
* bl_tree.
|
||||
*
|
||||
* @param s
|
||||
* @param tree the tree to be scanned
|
||||
* @param max_code and its largest code of non zero frequency
|
||||
|
@ -854,11 +840,10 @@ local void send_tree (deflate_state *s, ct_data *tree, int max_code)
|
|||
}
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Construct the Huffman tree for the bit lengths and return the index in
|
||||
* bl_order of the last bit length code to send.
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
local int build_bl_tree(deflate_state * s)
|
||||
{
|
||||
|
@ -889,15 +874,11 @@ local int build_bl_tree(deflate_state *s)
|
|||
return max_blindex;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Send the header for a block using dynamic Huffman trees: the counts, the
|
||||
* lengths of the bit length codes, the literal tree and the distance tree.
|
||||
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
|
||||
*
|
||||
* @param s
|
||||
* @param lcodes number of codes
|
||||
* @param dcodes number of codes
|
||||
* @param blcodes number of codes
|
||||
*/
|
||||
local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
|
||||
{
|
||||
|
@ -923,9 +904,9 @@ local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
|
|||
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Send a stored block
|
||||
*
|
||||
* @param s
|
||||
* @param buf input block
|
||||
* @param stored_len length of input block
|
||||
|
@ -934,7 +915,7 @@ local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
|
|||
void _tr_stored_block(deflate_state * s, charf * buf, ulg stored_len, int eof)
|
||||
{
|
||||
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
|
||||
s->compressed_len += (stored_len + 4) << 3;
|
||||
#endif
|
||||
|
@ -957,7 +938,7 @@ void _tr_align(deflate_state *s)
|
|||
{
|
||||
send_bits(s, STATIC_TREES<<1, 3);
|
||||
send_code(s, END_BLOCK, static_ltree);
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
|
||||
#endif
|
||||
bi_flush(s);
|
||||
|
@ -969,7 +950,7 @@ void _tr_align(deflate_state *s)
|
|||
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
|
||||
send_bits(s, STATIC_TREES<<1, 3);
|
||||
send_code(s, END_BLOCK, static_ltree);
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 10L;
|
||||
#endif
|
||||
bi_flush(s);
|
||||
|
@ -977,18 +958,16 @@ void _tr_align(deflate_state *s)
|
|||
s->last_eob_len = 7;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Determine the best encoding for the current block: dynamic trees, static
|
||||
* trees or store, and output the encoded block to the zip file.
|
||||
*
|
||||
* @param s
|
||||
* @param buf input block, of NULL if too old
|
||||
* @param buf input block, or NULL if too old
|
||||
* @param stored_len length of input block
|
||||
* @param pad true if block is to be rsync padded
|
||||
* @param eof true if this is the last block for a file
|
||||
*/
|
||||
void _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
|
||||
int pad, int eof)
|
||||
void _tr_flush_block(deflate_state * s, charf * buf, ulg stored_len, int eof)
|
||||
{
|
||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
int max_blindex = 0; /* index of last bit length code of non zero freq */
|
||||
|
@ -1052,7 +1031,7 @@ void _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
|
|||
#endif
|
||||
send_bits(s, (STATIC_TREES<<1)+eof, 3);
|
||||
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 3 + s->static_len;
|
||||
#endif
|
||||
} else {
|
||||
|
@ -1060,7 +1039,7 @@ void _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
|
|||
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
|
||||
max_blindex+1);
|
||||
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 3 + s->opt_len;
|
||||
#endif
|
||||
}
|
||||
|
@ -1072,30 +1051,22 @@ void _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
|
|||
|
||||
if (eof) {
|
||||
bi_windup(s);
|
||||
#if defined(WITH_RSYNC_PAD) || defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
s->compressed_len += 7; /* align on byte boundary */
|
||||
#endif
|
||||
}
|
||||
#if defined(WITH_RSYNC_PAD)
|
||||
else if (pad && (s->compressed_len % 8) != 0) {
|
||||
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
|
||||
s->compressed_len = (s->compressed_len + 3 + 7) & ~7L;
|
||||
copy_block(s, buf, 0, 1); /* with header */
|
||||
}
|
||||
#endif
|
||||
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
|
||||
s->compressed_len-7*eof));
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Save the match info and tally the frequency counts. Return true if
|
||||
* the current block must be flushed.
|
||||
*
|
||||
* @param s
|
||||
* @param dist distance of matched string
|
||||
* @param lc match length-MIN_MATCH or unmatched char (if dist==0)
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
int _tr_tally (deflate_state * s, unsigned dist, unsigned lc)
|
||||
{
|
||||
s->d_buf[s->last_lit] = (ush)dist;
|
||||
|
@ -1139,11 +1110,10 @@ int _tr_tally (deflate_state *s, unsigned dist, unsigned lc)
|
|||
* 64K-1 bytes.
|
||||
*/
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Send the block data compressed using the given Huffman trees
|
||||
*
|
||||
* @param s
|
||||
* @param ltree literal tree
|
||||
* @param dtree distance tree
|
||||
|
@ -1192,13 +1162,12 @@ local void compress_block(deflate_state *s, ct_data *ltree, ct_data *dtree)
|
|||
s->last_eob_len = ltree[END_BLOCK].Len;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Set the data type to ASCII or BINARY, using a crude approximation:
|
||||
* binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
|
||||
* IN assertion: the fields freq of dyn_ltree are set and the total of all
|
||||
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
local void set_data_type(deflate_state * s)
|
||||
{
|
||||
|
@ -1216,7 +1185,6 @@ local void set_data_type(deflate_state *s)
|
|||
* Reverse the first len bits of a code, using straightforward code (a faster
|
||||
* method would use a table)
|
||||
* IN assertion: 1 <= len <= 15
|
||||
*
|
||||
* @param code the value to invert
|
||||
* @param len its bit length
|
||||
*/
|
||||
|
@ -1269,7 +1237,6 @@ local void bi_windup(deflate_state *s)
|
|||
/**
|
||||
* Copy a stored block, storing first the length and its
|
||||
* one's complement if requested.
|
||||
*
|
||||
* @param s
|
||||
* @param buf the input data
|
||||
* @param len its length
|
||||
|
@ -1290,7 +1257,6 @@ local void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
|
|||
#ifdef DEBUG
|
||||
s->bits_sent += (ulg)len<<3;
|
||||
#endif
|
||||
if (buf != NULL)
|
||||
while (len--) {
|
||||
put_byte(s, *buf++);
|
||||
}
|
||||
|
|
11
zlib/trees.h
11
zlib/trees.h
|
@ -1,9 +1,5 @@
|
|||
/**
|
||||
* \file trees.h
|
||||
* Header created automatically with -DGEN_TREES_H
|
||||
*/
|
||||
/* header created automatically with -DGEN_TREES_H */
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
|
||||
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
|
||||
|
@ -65,7 +61,6 @@ local const ct_data static_ltree[L_CODES+2] = {
|
|||
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
|
||||
};
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
|
||||
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
|
||||
|
@ -75,7 +70,6 @@ local const ct_data static_dtree[D_CODES] = {
|
|||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||
};
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
const uch _dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
|
@ -105,7 +99,6 @@ const uch _dist_code[DIST_CODE_LEN] = {
|
|||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
|
@ -122,13 +115,11 @@ const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
|||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
local const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
|
|
|
@ -1,41 +1,33 @@
|
|||
/* @(#) $Id: uncompr.c,v 1.4 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
/* uncompr.c -- decompress a memory buffer
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uncompr.c
|
||||
* Decompress a memory buffer.
|
||||
*/
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zlib.h"
|
||||
#include "zutil.h" /* XXX for zmemzero() */
|
||||
|
||||
/*@access z_streamp@*/
|
||||
/* ===========================================================================
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
/* ========================================================================= */
|
||||
/**
|
||||
* Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
* the byte length of the source buffer. Upon entry, destLen is the total
|
||||
* size of the destination buffer, which must be large enough to hold the
|
||||
* entire uncompressed data. (The size of the uncompressed data must have
|
||||
* been saved previously by the compressor and transmitted to the decompressor
|
||||
* by some mechanism outside the scope of this compression library.)
|
||||
* Upon exit, destLen is the actual size of the compressed buffer.
|
||||
* This function can be used to decompress a whole file at once if the
|
||||
* input file is mmap'ed.
|
||||
*
|
||||
* uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
* enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
* buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
|
||||
int ZEXPORT uncompress (Bytef * dest, uLongf * destLen, const Bytef * source,
|
||||
uLong sourceLen)
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
zmemzero(&stream, sizeof(stream));
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
|
@ -45,8 +37,8 @@ int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
|
|||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)NULL;
|
||||
stream.zfree = (free_func)NULL;
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
|
||||
err = inflateInit(&stream);
|
||||
if (err != Z_OK) return err;
|
||||
|
|
13
zlib/zconf.h
13
zlib/zconf.h
|
@ -1,17 +1,12 @@
|
|||
/* @(#) $Id: zconf.h,v 1.4 2001/12/27 21:00:18 jbj Exp $ */
|
||||
/*
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file zconf.h
|
||||
* Configuration of the zlib compression library.
|
||||
*/
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
/*@-constuse -typeuse@*/
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
|
@ -134,9 +129,6 @@
|
|||
*/
|
||||
|
||||
/* Type declarations */
|
||||
#ifdef __LCLINT__
|
||||
# define OF(args) args
|
||||
#endif
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
|
@ -284,5 +276,4 @@ typedef uLong FAR uLongf;
|
|||
# pragma map(inflate_trees_free,"INTRFR")
|
||||
#endif
|
||||
|
||||
/*@=constuse =typeuse@*/
|
||||
#endif /* _ZCONF_H */
|
||||
|
|
1320
zlib/zlib.h
1320
zlib/zlib.h
File diff suppressed because it is too large
Load Diff
15
zlib/zutil.c
15
zlib/zutil.c
|
@ -1,21 +1,18 @@
|
|||
/* @(#) $Id: zutil.c,v 1.4 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
/* zutil.c -- target dependent utility functions for the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file zutil.c
|
||||
* Target dependent utility functions for the compression library.
|
||||
*/
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#ifndef STDC
|
||||
extern void exit OF((int));
|
||||
#endif
|
||||
|
||||
/*@observer@*/ /*@readonly@*/
|
||||
const char *z_errmsg[10] = {
|
||||
"need dictionary", /* Z_NEED_DICT 2 */
|
||||
"stream end", /* Z_STREAM_END 1 */
|
||||
|
@ -51,12 +48,10 @@ void z_error (char *m)
|
|||
/* exported to allow conversion of error code to string for compress() and
|
||||
* uncompress()
|
||||
*/
|
||||
/*@-compmempass@*/
|
||||
const char * ZEXPORT zError(int err)
|
||||
{
|
||||
return ERR_MSG(err);
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
@ -112,7 +107,7 @@ typedef struct ptr_table_s {
|
|||
} ptr_table;
|
||||
|
||||
local ptr_table table[MAX_PTR];
|
||||
/*!< This table is used to remember the original form of pointers
|
||||
/* This table is used to remember the original form of pointers
|
||||
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||
* protected from concurrent access. This hack doesn't work anyway on
|
||||
|
|
56
zlib/zutil.h
56
zlib/zutil.h
|
@ -1,18 +1,15 @@
|
|||
/* @(#) $Id: zutil.h,v 1.5 2002/02/10 16:50:06 jbj Exp $ */
|
||||
/*
|
||||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file zutil.h
|
||||
* Internal interface and configuration of the compression library.
|
||||
*/
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef _Z_UTIL_H
|
||||
#define _Z_UTIL_H
|
||||
|
||||
|
@ -40,7 +37,6 @@ typedef unsigned short ush;
|
|||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
|
@ -180,11 +176,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
#ifdef __i386__
|
||||
#define zmemcpy(to,from,n) quickmemcpy(to, from, n)
|
||||
#else
|
||||
# define zmemcpy memcpy
|
||||
#endif
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
|
@ -216,49 +208,13 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||
|
||||
|
||||
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||
uInt len))
|
||||
/*@*/;
|
||||
/*@only@*/ /*@null@*/
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size))
|
||||
/*@*/;
|
||||
void zcfree OF((voidpf opaque, /*@only@*/ voidpf ptr))
|
||||
/*@modifies ptr @*/;
|
||||
uInt len));
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
#ifdef __i386__
|
||||
/* This function comes from Linus Torvalds' memcpy:
|
||||
* NO Copyright (C) 1991, 1992 Linus Torvalds,
|
||||
* consider these trivial functions to be PD.
|
||||
*/
|
||||
#define quickmemcpy(to, from, n) \
|
||||
do { \
|
||||
int d0, d1, d2; \
|
||||
__asm__ __volatile__( \
|
||||
"cld\n" \
|
||||
"rep ; movsl\n\t" \
|
||||
"testb $2,%b4\n\t" \
|
||||
"je 1f\n\t" \
|
||||
"movsw\n" \
|
||||
"1:\ttestb $1,%b4\n\t" \
|
||||
"je 2f\n\t" \
|
||||
"movsb\n" \
|
||||
"2:" \
|
||||
: "=&c" (d0), "=&D" (d1), "=&S" (d2) \
|
||||
:"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) \
|
||||
: "memory"); \
|
||||
} while(0)
|
||||
#else
|
||||
static __inline__ void quickmemcpy(void *_to, const void *_from, long n)
|
||||
/*@*/
|
||||
{
|
||||
const char *from = _from;
|
||||
char *to = _to;
|
||||
while (n-- > 0)
|
||||
*to++ = *from++;
|
||||
}
|
||||
#endif
|
||||
#endif /* _Z_UTIL_H */
|
||||
|
|
Loading…
Reference in New Issue