diff options
author | jbj <devnull@localhost> | 2002-03-17 15:46:23 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-03-17 15:46:23 +0000 |
commit | a7266b73948b535e38fe0ba29e05912209a45ff9 (patch) | |
tree | b515296500e1aadd60af25e0b7dd193cbe96cfb4 | |
parent | 3212547cb597483f131e7f53204d87fe3a9f72f9 (diff) | |
download | librpm-tizen-a7266b73948b535e38fe0ba29e05912209a45ff9.tar.gz librpm-tizen-a7266b73948b535e38fe0ba29e05912209a45ff9.tar.bz2 librpm-tizen-a7266b73948b535e38fe0ba29e05912209a45ff9.zip |
Bail on mmap/rsync fiddles for now.
CVS patchset: 5361
CVS date: 2002/03/17 15:46:23
-rw-r--r-- | zlib/Makefile.am | 8 | ||||
-rw-r--r-- | zlib/Makefile.in | 25 | ||||
-rw-r--r-- | zlib/aclocal.m4 | 8 | ||||
-rw-r--r-- | zlib/adler32.c | 3 | ||||
-rw-r--r-- | zlib/compress.c | 19 | ||||
-rw-r--r-- | zlib/configure.in | 2 | ||||
-rw-r--r-- | zlib/crc32.c | 40 | ||||
-rw-r--r-- | zlib/deflate.c | 200 | ||||
-rw-r--r-- | zlib/deflate.h | 44 | ||||
-rw-r--r-- | zlib/example.c | 53 | ||||
-rw-r--r-- | zlib/gzio.c | 388 | ||||
-rw-r--r-- | zlib/infblock.c | 336 | ||||
-rw-r--r-- | zlib/infblock.h | 18 | ||||
-rw-r--r-- | zlib/infcodes.c | 243 | ||||
-rw-r--r-- | zlib/infcodes.h | 54 | ||||
-rw-r--r-- | zlib/inffast.c | 159 | ||||
-rw-r--r-- | zlib/inffast.h | 10 | ||||
-rw-r--r-- | zlib/inffixed.h | 10 | ||||
-rw-r--r-- | zlib/inflate.c | 94 | ||||
-rw-r--r-- | zlib/inftrees.c | 156 | ||||
-rw-r--r-- | zlib/inftrees.h | 50 | ||||
-rw-r--r-- | zlib/infutil.c | 49 | ||||
-rw-r--r-- | zlib/infutil.h | 51 | ||||
-rw-r--r-- | zlib/ltmain.sh | 33 | ||||
-rw-r--r-- | zlib/maketree.c | 7 | ||||
-rw-r--r-- | zlib/minigzip.c | 38 | ||||
-rw-r--r-- | zlib/trees.c | 168 | ||||
-rw-r--r-- | zlib/trees.h | 11 | ||||
-rw-r--r-- | zlib/uncompr.c | 52 | ||||
-rw-r--r-- | zlib/zconf.h | 13 | ||||
-rw-r--r-- | zlib/zlib.h | 1416 | ||||
-rw-r--r-- | zlib/zutil.c | 23 | ||||
-rw-r--r-- | zlib/zutil.h | 56 |
33 files changed, 1464 insertions, 2373 deletions
diff --git a/zlib/Makefile.am b/zlib/Makefile.am index 154fcfb82..43ad82565 100644 --- a/zlib/Makefile.am +++ b/zlib/Makefile.am @@ -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 diff --git a/zlib/Makefile.in b/zlib/Makefile.in index 91201c7f9..9c1e417a2 100644 --- a/zlib/Makefile.in +++ b/zlib/Makefile.in @@ -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@ diff --git a/zlib/aclocal.m4 b/zlib/aclocal.m4 index 326729c3c..5f523addf 100644 --- a/zlib/aclocal.m4 +++ b/zlib/aclocal.m4 @@ -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` ;; diff --git a/zlib/adler32.c b/zlib/adler32.c index 4dd542c6d..d40185ac1 100644 --- a/zlib/adler32.c +++ b/zlib/adler32.c @@ -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 @@ -22,7 +21,7 @@ #define DO16(buf) DO8(buf,0); DO8(buf,8); /* ========================================================================= */ -uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) +uLong ZEXPORT adler32(uLong adler, const Bytef * buf, uInt len) { unsigned long s1 = adler & 0xffff; unsigned long s2 = (adler >> 16) & 0xffff; diff --git a/zlib/compress.c b/zlib/compress.c index ba5d51a5a..3a78cc1fa 100644 --- a/zlib/compress.c +++ b/zlib/compress.c @@ -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); } diff --git a/zlib/configure.in b/zlib/configure.in index fdaf04d21..3f2833876 100644 --- a/zlib/configure.in +++ b/zlib/configure.in @@ -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 diff --git a/zlib/crc32.c b/zlib/crc32.c index 4087cbbf8..32924b871 100644 --- a/zlib/crc32.c +++ b/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 @@ -49,7 +46,7 @@ local void make_crc_table OF((void)) * The table is simply the CRC of all possible eight bit values. This is all * the information needed to generate CRC's on data a byte at a time for all * combinations of CRC register values and incoming bytes. - */ +*/ local void make_crc_table(void) { uLong c; @@ -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,39 +140,12 @@ 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); #define DO4(buf) DO2(buf); DO2(buf); #define DO8(buf) DO4(buf); DO4(buf); - + /* ========================================================================= */ uLong ZEXPORT crc32(uLong crc, const Bytef * buf, uInt len) { @@ -194,7 +164,5 @@ uLong ZEXPORT crc32(uLong crc, const Bytef * buf, uInt len) DO1(buf); } while (--len); return crc ^ 0xffffffffL; - } - -#endif /* !__i386__ */ +} /*@=globs@*/ diff --git a/zlib/deflate.c b/zlib/deflate.c index adba3d669..ecaa5dc9d 100644 --- a/zlib/deflate.c +++ b/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,8 +225,9 @@ 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, - const char *version, int stream_size) +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; int noheader = 0; @@ -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@*/ /* ========================================================================= */ /** @@ -430,7 +414,7 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB (deflate_state *s, uInt b) +local void putShortMSB (deflate_state * s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); @@ -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@*/ /* ========================================================================= */ /** @@ -713,7 +669,7 @@ int ZEXPORT deflateCopy (z_streamp dest, z_streamp source) * allocating a large strm->next_in buffer and copying from it. * (See also flush_pending()). */ -local int read_buf(z_streamp strm, Bytef *buf, unsigned size) +local int read_buf(z_streamp strm, Bytef * buf, unsigned size) { unsigned len = strm->avail_in; @@ -736,8 +692,7 @@ 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) +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@*/ /* ========================================================================= */ /** @@ -784,7 +731,7 @@ local void lm_init (deflate_state *s) * match.S. The code will be functionally equivalent. */ #ifndef FASTEST -local uInt longest_match(deflate_state *s, IPos cur_match) +local uInt longest_match(deflate_state * s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ @@ -924,7 +871,7 @@ local uInt longest_match(deflate_state *s, IPos cur_match) /* --------------------------------------------------------------------------- * Optimized version for level == 1 only */ -local uInt longest_match(deflate_state *s, IPos cur_match) +local uInt longest_match(deflate_state * s, IPos cur_match) { register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ @@ -982,7 +929,7 @@ local uInt longest_match(deflate_state *s, IPos cur_match) /** * Check that the match at match_start is indeed a match. */ -local void check_match(deflate_state *s, IPos start, IPos match, int length) +local void check_match(deflate_state * s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ if (zmemcmp(s->window + match, @@ -1014,7 +961,7 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) * performed for at least two bytes (required for the zip translate_eol * option -- not supported here). */ -local void fill_window(deflate_state *s) +local void fill_window(deflate_state * s) { register unsigned n, m; register Posf *p; @@ -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); \ @@ -1181,18 +1082,13 @@ local void rsync_roll(deflate_state *s, unsigned num) * NOTE: this function should be optimized to avoid extra copying from * window to pending_buf. */ -local block_state deflate_stored(deflate_state *s, int flush) +local block_state deflate_stored(deflate_state * s, int flush) { /* Stored blocks are limited to 0xffff bytes, pending_buf is limited * to pending_buf_size, and each stored block has a 5 byte header: */ 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) +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) +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,13 +1315,7 @@ 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); + if (bflush) FLUSH_BLOCK(s, 0); } else if (s->match_available) { /* If there was no match at the previous position, output a @@ -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); + FLUSH_BLOCK_ONLY(s, 0); + } 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@*/ diff --git a/zlib/deflate.h b/zlib/deflate.h index c86bf6ea1..b95050103 100644 --- a/zlib/deflate.h +++ b/zlib/deflate.h @@ -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) \ diff --git a/zlib/example.c b/zlib/example.c index 0d7524da3..821ebb032 100644 --- a/zlib/example.c +++ b/zlib/example.c @@ -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 */ diff --git a/zlib/gzio.c b/zlib/gzio.c index 0fb3876db..3b42fdbf0 100644 --- a/zlib/gzio.c +++ b/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,47 +42,38 @@ 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 @*/; local int do_flush OF((gzFile file, int flush)) - /*@globals fileSystem@*/ + /*@globals fileSystem @*/ /*@modifies fileSystem @*/; local int get_byte OF((gz_stream *s)) /*@globals errno, fileSystem @*/ /*@modifies s, errno, fileSystem @*/; local void check_header OF((gz_stream *s)) - /*@globals fileSystem@*/ + /*@globals fileSystem @*/ /*@modifies s, fileSystem @*/; -local int destroy OF((/*@only@*/ /*@out@*/ gz_stream *s)) - /*@globals fileSystem@*/ +local int destroy OF((gz_stream *s)) + /*@globals fileSystem @*/ /*@modifies s, fileSystem @*/; local void putLong OF((FILE *file, uLong x)) - /*@globals fileSystem@*/ + /*@globals fileSystem @*/ /*@modifies file, fileSystem @*/; local uLong getLong OF((gz_stream *s)) - /*@globals fileSystem@*/ + /*@globals fileSystem @*/ /*@modifies s, fileSystem @*/; /* ========================================================================= */ @@ -111,8 +86,7 @@ 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) +local gzFile gz_open (const char * path, const char * mode, int fd) { int err; int level = Z_DEFAULT_COMPRESSION; /* compression level */ @@ -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; + s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); -#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->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,23 +184,17 @@ 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@*/ + s->startpos = (ftell(s->file) - s->stream.avail_in); } return (gzFile)s; } -/*@=compmempass =compdef@*/ /* ========================================================================= */ /** * Opens a gzip (.gz) file for reading or writing. */ -gzFile ZEXPORT gzopen (const char *path, const char *mode) +gzFile ZEXPORT gzopen (const char * path, const char * mode) { return gz_open (path, mode, -1); } @@ -285,7 +204,7 @@ gzFile ZEXPORT gzopen (const char *path, const char *mode) * Associate a gzFile with the file descriptor fd. fd is not dup'ed here * to mimic the behavio(u)r of fdopen. */ -gzFile ZEXPORT gzdopen (int fd, const char *mode) +gzFile ZEXPORT gzdopen (int fd, const char * mode) { char name[20]; @@ -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,97 +225,40 @@ 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; if (ferror(s->file)) s->z_err = Z_ERRNO; - return EOF; + return EOF; } s->stream.next_in = s->inbuf; -#endif } -/*@=branchstate@*/ s->stream.avail_in--; return *(s->stream.next_in)++; } -/*@=compmempass@*/ /* ========================================================================= */ /** @@ -405,10 +267,10 @@ local inline int get_byte(gz_stream *s) * to Z_DATA_ERROR if the magic header is present but the rest of the header * is incorrect. * IN assertion: the stream s has already been created sucessfully; - * s->stream.avail_in is zero for the first time, but may be non-zero - * for concatenated .gz files. + * s->stream.avail_in is zero for the first time, but may be non-zero + * for concatenated .gz files. */ -local void check_header(gz_stream *s) +local void check_header(gz_stream * s) { int method; /* method byte */ int flags; /* flags byte */ @@ -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,8 +323,7 @@ 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) +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,39 +404,24 @@ 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; + 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; break; } - } - s->stream.next_in = s->inbuf; -#endif + } + s->stream.next_in = s->inbuf; } s->z_err = inflate(&(s->stream), Z_NO_FLUSH); if (s->z_err == Z_STREAM_END) { /* Check CRC and original size */ - -#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)); + s->crc = crc32(s->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@*/ /* ========================================================================= */ @@ -662,16 +468,16 @@ int ZEXPORT gzgetc(gzFile file) * read, or a newline character is read and transferred to buf, or an * end-of-file condition is encountered. The string is then terminated * with a null character. - * gzgets returns buf, or Z_NULL in case of error. + * gzgets returns buf, or Z_NULL in case of error. * - * The current implementation is not optimized at all. + * The current implementation is not optimized at all. */ -char * ZEXPORT gzgets(gzFile file, char *buf, int len) +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; @@ -789,9 +587,9 @@ int ZEXPORT gzputc(gzFile file, int c) /** * Writes the given null-terminated string to the compressed file, excluding * the terminating null character. - * gzputs returns the number of characters written, or -1 in case of error. + * gzputs returns the number of characters written, or -1 in case of error. */ -int ZEXPORT gzputs(gzFile file, const char *s) +int ZEXPORT gzputs(gzFile file, const char * s) { return gzwrite(file, (char*)s, (unsigned)strlen(s)); } @@ -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; } @@ -856,10 +652,10 @@ int ZEXPORT gzflush (gzFile file, int flush) /** * Sets the starting position for the next gzread or gzwrite on the given * compressed file. The offset represents a number of bytes in the - * gzseek returns the resulting offset location as measured in bytes from + * gzseek returns the resulting offset location as measured in bytes from * the beginning of the uncompressed stream, or -1 in case of error. - * SEEK_END is not implemented, returns error. - * In this version of the library, gzseek can be extremely slow. + * SEEK_END is not implemented, returns error. + * In this version of the library, gzseek can be extremely slow. */ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence) { @@ -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); @@ -1011,7 +798,7 @@ local void putLong (FILE * file, uLong x) * Reads a long in LSB order from the given gz_stream. Sets z_err in case * of error. */ -local uLong getLong (gz_stream *s) +local uLong getLong (gz_stream * s) { uLong x = (uLong)get_byte(s); int c; @@ -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,8 +845,7 @@ 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) +const char* ZEXPORT gzerror (gzFile file, int * errnum) { char *m; gz_stream *s = (gz_stream*)file; @@ -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@*/ diff --git a/zlib/infblock.c b/zlib/infblock.c index fc4624707..377e7fb33 100644 --- a/zlib/infblock.c +++ b/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}; @@ -74,18 +73,14 @@ local const uInt border[] = { /* Order of the bit length code lengths */ */ -void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLongf *c) +void inflate_blocks_reset(inflate_blocks_statef * s, z_streamp z, uLongf * c) { if (c != Z_NULL) *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; @@ -96,7 +91,7 @@ void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLongf *c) } -inflate_blocks_statef *inflate_blocks_new(z_streamp z, check_func c, uInt w) +inflate_blocks_statef * inflate_blocks_new(z_streamp z, check_func c, uInt w) { inflate_blocks_statef *s; @@ -124,8 +119,7 @@ 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) +int inflate_blocks(inflate_blocks_statef * s, z_streamp z, int r) { uInt t; /* temporary storage */ uLong b; /* bit buffer */ @@ -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) { - ZFREE(z, s->sub.trees.blens); -/*@-type@*/ + if (r == Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); 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) { - ZFREE(z, s->sub.trees.blens); -/*@-type@*/ + if (t == (uInt)Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); 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,36 +347,28 @@ 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: - LEAVE } -/*@=compmempass@*/ -int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z) +int inflate_blocks_free(inflate_blocks_statef * s, z_streamp z) { inflate_blocks_reset(s, z, Z_NULL); ZFREE(z, s->window); @@ -410,11 +379,9 @@ int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z) } -void inflate_set_dictionary(inflate_blocks_statef *s, const Bytef *d, uInt n) +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; } @@ -423,222 +390,7 @@ void inflate_set_dictionary(inflate_blocks_statef *s, const Bytef *d, uInt n) * by Z_SYNC_FLUSH or Z_FULL_FLUSH. * IN assertion: s != Z_NULL */ -int inflate_blocks_sync_point(inflate_blocks_statef *s) +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")); -} diff --git a/zlib/infblock.h b/zlib/infblock.h index 9d8dea349..c3cc86955 100644 --- a/zlib/infblock.h +++ b/zlib/infblock.h @@ -19,30 +19,30 @@ 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 @*/; extern int inflate_blocks OF(( - inflate_blocks_statef *s, + inflate_blocks_statef * s, z_streamp z, - int r)) /* initial return code */ + int r)) /* initial return code */ /*@modifies s, z @*/; extern void inflate_blocks_reset OF(( - inflate_blocks_statef *s, + 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(( - /*@only@*/ inflate_blocks_statef *s, - z_streamp z)) + /*@only@*/ inflate_blocks_statef * s, + z_streamp z)) /*@modifies s, z @*/; extern void inflate_set_dictionary OF(( - inflate_blocks_statef *s, - const Bytef *d, /* dictionary */ + inflate_blocks_statef * s, + const Bytef * d, /* dictionary */ uInt n)) /* dictionary length */ /*@modifies s @*/; diff --git a/zlib/infcodes.c b/zlib/infcodes.c new file mode 100644 index 000000000..dc1aca9c1 --- /dev/null +++ b/zlib/infcodes.c @@ -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")); +} diff --git a/zlib/infcodes.h b/zlib/infcodes.h index adcbcf2db..7ecca7fe7 100644 --- a/zlib/infcodes.h +++ b/zlib/infcodes.h @@ -7,72 +7,28 @@ * \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)) /*@*/; extern int inflate_codes OF(( - inflate_blocks_statef *s, + inflate_blocks_statef * s, z_streamp z, int r)) /*@modifies s, z @*/; extern void inflate_codes_free OF(( - /*@only@*/ inflate_codes_statef *s, + /*@only@*/ inflate_codes_statef * s, z_streamp z)) /*@*/; - diff --git a/zlib/inffast.c b/zlib/inffast.c index 8dac29ce9..ae7da3d36 100644 --- a/zlib/inffast.c +++ b/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,32 +94,23 @@ int ret; /* do the copy */ m -= c; -#if 1 /* { */ - r = q - d; - if (r < s->window) /* wrap if needed */ - { - do { - r += s->end - s->window; /* force pointer in window */ - } while (r < s->window); /* covers invalid distances */ - e = s->end - r; - if (c > e) + r = q - d; + if (r < s->window) /* wrap if needed */ + { + do { + r += s->end - s->window; /* force pointer in window */ + } while (r < s->window); /* covers invalid distances */ + e = s->end - r; + 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 + c -= e; /* wrapped copy */ 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; + break; } else if ((e & 64) == 0) { t += t->base; e = (t += ((uInt)b & inflate_mask[e]))->exop; - /*@innercontinue@*/ continue; } else - goto inv_dist_code; + { + z->msg = (char*)"invalid distance code"; + UNGRAB + UPDATE + return Z_DATA_ERROR; + } } while (1); -/*@-unreachable@*/ - /*@innerbreak@*/ break; -/*@=unreachable@*/ + break; } -if (!(e & 64)) { - + if ((e & 64) == 0) + { t += t->base; - if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) != 0) - /*@innercontinue@*/ continue; - 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; -} - } while (1); - } while (m >= 258 && n >= 10); - - /* not enough input or output--restore pointers and return */ - ret = Z_OK; - -ungrab: + 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--; + break; + } + } + else if (e & 32) + { + Tracevv((stderr, "inflate: * end of block\n")); UNGRAB UPDATE - return ret; - -data_error: - { - z->msg = "invalid literal/length code"; - ret = Z_DATA_ERROR; - goto ungrab; + return Z_STREAM_END; } - -stream_end: + else { - Tracevv((stderr, "inflate: * end of block\n")); - ret = Z_STREAM_END; - goto ungrab; + z->msg = (char*)"invalid literal/length code"; + UNGRAB + UPDATE + return Z_DATA_ERROR; } + } while (1); + } while (m >= 258 && n >= 10); -inv_dist_code: - { - z->msg = "invalid distance code"; - ret = Z_DATA_ERROR; - goto ungrab; - } + /* not enough input or output--restore pointers and return */ + UNGRAB + UPDATE + return Z_OK; } diff --git a/zlib/inffast.h b/zlib/inffast.h index 7e3ebb534..304c2f07e 100644 --- a/zlib/inffast.h +++ b/zlib/inffast.h @@ -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 )); diff --git a/zlib/inffixed.h b/zlib/inffixed.h index 7b71e5eaa..77f7e7631 100644 --- a/zlib/inffixed.h +++ b/zlib/inffixed.h @@ -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}, diff --git a/zlib/inflate.c b/zlib/inflate.c index e1cd615fa..767a89a78 100644 --- a/zlib/inflate.c +++ b/zlib/inflate.c @@ -7,30 +7,31 @@ * \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 */ - FLAG, /*!< waiting for flag byte */ - DICT4, /*!< four dictionary check bytes to go */ - DICT3, /*!< three dictionary check bytes to go */ - DICT2, /*!< two dictionary check bytes to go */ - DICT1, /*!< one dictionary check byte to go */ - DICT0, /*!< waiting for inflateSetDictionary */ - BLOCKS, /*!< decompressing blocks */ - CHECK4, /*!< four check bytes to go */ - CHECK3, /*!< three check bytes to go */ - CHECK2, /*!< two check bytes to go */ - CHECK1, /*!< one check byte to go */ - DONE, /*!< finished check, done */ - BAD /*!< got an error--stay here */ -} inflate_mode; + METHOD, /*!< waiting for method byte */ + FLAG, /*!< waiting for flag byte */ + DICT4, /*!< four dictionary check bytes to go */ + DICT3, /*!< three dictionary check bytes to go */ + DICT2, /*!< two dictionary check bytes to go */ + DICT1, /*!< one dictionary check byte to go */ + DICT0, /*!< waiting for inflateSetDictionary */ + BLOCKS, /*!< decompressing blocks */ + CHECK4, /*!< four check bytes to go */ + CHECK3, /*!< three check bytes to go */ + CHECK2, /*!< two check bytes to go */ + CHECK1, /*!< one check byte to go */ + DONE, /*!< finished check, done */ + 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 */ @@ -141,23 +136,22 @@ int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_si } -int ZEXPORT inflateInit_(z_streamp z, const char *version, int stream_size) +int ZEXPORT inflateInit_(z_streamp z, const char * version, int stream_size) { return inflateInit2_(z, DEF_WBITS, version, 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@*/ /** diff --git a/zlib/inftrees.c b/zlib/inftrees.c index 2ac53c7d3..ceb8a3580 100644 --- a/zlib/inftrees.c +++ b/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) @@ -109,10 +107,9 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */ * @param hn hufts used in space * @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 @*/ +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) { 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) @@ -313,8 +302,8 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, * @param hp space for trees * @param z for messages */ -int inflate_trees_bits( uIntf *c, uIntf *bb, inflate_huft * FAR *tb, - inflate_huft *hp, z_streamp z) +int inflate_trees_bits(uIntf * c, uIntf * bb, inflate_huft * FAR * tb, + inflate_huft * hp, z_streamp z) { int r; uInt hn = 0; /* hufts used in space */ @@ -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,9 +335,9 @@ 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, - inflate_huft *hp, z_streamp z) +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; uInt hn = 0; /* hufts used in space */ @@ -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); @@ -425,8 +413,8 @@ local inflate_huft *fixed_td; * @param td distance tree result * @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) +int inflate_trees_fixed(uIntf * bl, uIntf * bd, inflate_huft * FAR * tl, + inflate_huft * FAR * td, z_streamp z) { #ifdef BUILDFIXED /* build fixed tables if not already */ diff --git a/zlib/inftrees.h b/zlib/inftrees.h index 8e7da9336..7ffeb8b16 100644 --- a/zlib/inftrees.h +++ b/zlib/inftrees.h @@ -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. @@ -24,7 +25,7 @@ struct inflate_huft_s { Byte Bits; /*!< number of bits in this code or subcode */ } what; uInt pad; /*!< pad structure to a power of 2 (4 bytes for */ - } word; /*!< 16-bit, 8 bytes for 32-bit int's) */ + } word; /*!< 16-bit, 8 bytes for 32-bit int's) */ uInt base; /*!< literal, length base, distance base, or table offset */ }; @@ -39,35 +40,26 @@ struct inflate_huft_s { #define MANY 1440 extern int inflate_trees_bits OF(( - uIntf *c, /* 19 code lengths */ - 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 @*/; + uIntf * c, /* 19 code lengths */ + 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 */ extern int inflate_trees_dynamic OF(( - uInt nl, /* number of literal/length codes */ - uInt nd, /* number of distance codes */ - 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 @*/; + uInt nl, /* number of literal/length codes */ + uInt nd, /* number of distance codes */ + uIntf * c, /* that many (total) code lengths */ + uIntf * bl, /* literal desired/actual bit depth */ + uIntf * bd, /* distance desired/actual bit depth */ + inflate_huft * FAR * tl, /* literal/length tree result */ + inflate_huft * FAR * td, /* distance tree result */ + inflate_huft * hp, /* space for trees */ + 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 @*/; + uIntf * bl, /* literal desired/actual bit depth */ + uIntf * bd, /* distance desired/actual bit depth */ + inflate_huft * FAR * tl, /* literal/length tree result */ + inflate_huft * FAR * td, /* distance tree result */ + z_streamp z)); /* for memory allocation */ diff --git a/zlib/infutil.c b/zlib/infutil.c index 2640de095..a1b372b98 100644 --- a/zlib/infutil.c +++ b/zlib/infutil.c @@ -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,10 +19,8 @@ uInt inflate_mask[17] = { }; -/** - * 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) +/* 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; Bytef *p; @@ -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; } diff --git a/zlib/infutil.h b/zlib/infutil.h index 2a824c248..6d3355af3 100644 --- a/zlib/infutil.h +++ b/zlib/infutil.h @@ -17,19 +17,17 @@ #define _INFUTIL_H typedef enum { - TYPE, /*!< get type bits (3, including end bit) */ - LENS, /*!< get lengths for stored */ - STORED, /*!< processing stored block */ - TABLE, /*!< get table lengths */ - BTREE, /*!< get bit lengths tree for a dynamic block */ - 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; + TYPE, /*!< get type bits (3, including end bit) */ + LENS, /*!< get lengths for stored */ + STORED, /*!< processing stored block */ + TABLE, /*!< get table lengths */ + BTREE, /*!< get bit lengths tree for a dynamic block */ + DTREE, /*!< get length, distance trees for a dynamic block */ + CODES, /*!< processing fixed or dynamic block */ + DRY, /*!< output remaining window bytes */ + DONE, /*!< finished last block, done */ + 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(( - inflate_blocks_statef *s, +/** 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 diff --git a/zlib/ltmain.sh b/zlib/ltmain.sh index 1113682d7..7b739c807 100644 --- a/zlib/ltmain.sh +++ b/zlib/ltmain.sh @@ -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 ;; diff --git a/zlib/maketree.c b/zlib/maketree.c index f7516beb0..a16d4b146 100644 --- a/zlib/maketree.c +++ b/zlib/maketree.c @@ -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. diff --git a/zlib/minigzip.c b/zlib/minigzip.c index a217d15af..fecde450a 100644 --- a/zlib/minigzip.c +++ b/zlib/minigzip.c @@ -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; diff --git a/zlib/trees.c b/zlib/trees.c index 3717412a6..584ee4ef2 100644 --- a/zlib/trees.c +++ b/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) +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,14 +442,12 @@ 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) +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,24 +479,24 @@ 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 */ -local void pqdownheap(deflate_state *s, ct_data *tree, int k) +local void pqdownheap(deflate_state * s, ct_data * tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ @@ -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,11 +528,8 @@ 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) +local void gen_bitlen(deflate_state * s, tree_desc * desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; @@ -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,12 +614,11 @@ 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 + * @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 */ -local void gen_codes (ct_data *tree, int max_code, ushf *bl_count) +local void gen_codes (ct_data * tree, int max_code, ushf * bl_count) { ush next_code[MAX_BITS+1]; /* next code value for each bit length */ ush code = 0; /* running code value */ @@ -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,11 +657,8 @@ 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) +local void build_tree(deflate_state * s, tree_desc * desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; @@ -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,17 +787,16 @@ 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 + * @param tree the tree to be scanned + * @param max_code and its largest code of non zero frequency */ -local void send_tree (deflate_state *s, ct_data *tree, int max_code) +local void send_tree (deflate_state * s, ct_data * tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ @@ -854,13 +840,12 @@ 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) +local int build_bl_tree(deflate_state * s) { int max_blindex; /* index of last bit length code of non zero freq */ @@ -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,18 +904,18 @@ 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 * @param eof true if this is the last block for a file */ -void _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int eof) +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 @@ -953,11 +934,11 @@ void _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int eof) * To simplify the code, we assume the worst case of last real code encoded * on one bit only. */ -void _tr_align(deflate_state *s) +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,31 +1051,23 @@ 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) + * @param lc match length-MIN_MATCH or unmatched char (if dist==0) */ -/*@-compmempass@*/ -int _tr_tally (deflate_state *s, unsigned dist, unsigned lc) +int _tr_tally (deflate_state * s, unsigned dist, unsigned lc) { s->d_buf[s->last_lit] = (ush)dist; s->l_buf[s->last_lit++] = (uch)lc; @@ -1139,16 +1110,15 @@ 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 */ -local void compress_block(deflate_state *s, ct_data *ltree, ct_data *dtree) +local void compress_block(deflate_state * s, ct_data * ltree, ct_data * dtree) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ @@ -1192,15 +1162,14 @@ 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) +local void set_data_type(deflate_state * s) { int n = 0; unsigned ascii_freq = 0; @@ -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 */ @@ -1234,7 +1202,7 @@ local unsigned bi_reverse(unsigned code, int len) /** * Flush the bit buffer, keeping at most 7 bits in it. */ -local void bi_flush(deflate_state *s) +local void bi_flush(deflate_state * s) { if (s->bi_valid == 16) { put_short(s, s->bi_buf); @@ -1251,7 +1219,7 @@ local void bi_flush(deflate_state *s) /** * Flush the bit buffer and align the output on a byte boundary */ -local void bi_windup(deflate_state *s) +local void bi_windup(deflate_state * s) { if (s->bi_valid > 8) { put_short(s, s->bi_buf); @@ -1269,13 +1237,12 @@ 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 * @param header true if block header must be written */ -local void copy_block(deflate_state *s, charf *buf, unsigned len, int header) +local void copy_block(deflate_state * s, charf * buf, unsigned len, int header) { bi_windup(s); /* align on byte boundary */ s->last_eob_len = 8; /* enough lookahead for inflate */ @@ -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++); } diff --git a/zlib/trees.h b/zlib/trees.h index bb8f62e2f..72facf900 100644 --- a/zlib/trees.h +++ b/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, diff --git a/zlib/uncompr.c b/zlib/uncompr.c index d7eaf2e4c..54e3a63b7 100644 --- a/zlib/uncompr.c +++ b/zlib/uncompr.c @@ -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. - * - * 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) + +/* =========================================================================== + 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. +*/ +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; diff --git a/zlib/zconf.h b/zlib/zconf.h index b57a0c265..eb0ae2e1a 100644 --- a/zlib/zconf.h +++ b/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 */ diff --git a/zlib/zlib.h b/zlib/zlib.h index a36adb06c..52cb529f6 100644 --- a/zlib/zlib.h +++ b/zlib/zlib.h @@ -1,57 +1,35 @@ -/** - * \file zlib.h - * Interface of the 'zlib' general purpose compression library. - * version 1.1.4, March 11th, 2002 - * - * Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - * Jean-loup Gailly Mark Adler - * jloup@gzip.org madler@alumni.caltech.edu - * - * - * The data format used by the zlib library is described by RFCs (Request for - * Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt - * (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). - * - * The 'zlib' compression library provides in-memory compression and - * decompression functions, including integrity checks of the uncompressed - * data. This version of the library supports only one compression method - * (deflation) but other algorithms will be added later and will have the same - * stream interface. - * - * Compression can be done in a single step if the buffers are large - * enough (for example if an input file is mmap'ed), or can be done by - * repeated calls of the compression function. In the latter case, the - * application must provide more input and/or consume the output - * (providing more output space) before each call. - * - * The library also supports reading and writing files in gzip (.gz) format - * with an interface similar to that of stdio. - * - * The library does not install any signal handler. The decoder checks - * the consistency of the compressed data, so the library should never - * crash even in case of corrupted input. - */ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.1.4, March 11th, 2002 + + Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ #ifndef _ZLIB_H #define _ZLIB_H -/*@-declundef -fcnuse @*/ #include "zconf.h" @@ -61,67 +39,86 @@ extern "C" { #define ZLIB_VERSION "1.1.4" -typedef /*@only@*/ voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)) - /*@*/; -typedef void (*free_func) OF((voidpf opaque, /*@only@*/ voidpf address)) - /*@*/; +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms will be added later and will have the same + stream interface. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never + crash even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); struct internal_state; -/** - * The application must update next_in and avail_in when avail_in has - * dropped to zero. It must update next_out and avail_out when avail_out - * has dropped to zero. The application must initialize zalloc, zfree and - * opaque before calling the init function. All other fields are set by the - * compression library and must not be updated by the application. - * - * The opaque value provided by the application will be passed as the first - * parameter for calls of zalloc and zfree. This can be useful for custom - * memory management. The compression library attaches no meaning to the - * opaque value. - * - * zalloc must return Z_NULL if there is not enough memory for the object. - * If zlib is used in a multi-threaded application, zalloc and zfree must be - * thread safe. - * - * On 16-bit systems, the functions zalloc and zfree must be able to allocate - * exactly 65536 bytes, but will not be required to allocate more than this - * if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - * pointers returned by zalloc for objects of exactly 65536 bytes *must* - * have their offset normalized to zero. The default allocation function - * provided by this library ensures this (see zutil.c). To reduce memory - * requirements and avoid any allocation of 64K objects, at the expense of - * compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - * - * The fields total_in and total_out can be used for statistics or - * progress reports. After compression, total_in holds the total size of - * the uncompressed data and may be saved for use in the decompressor - * (particularly if the decompressor wants to decompress everything in - * a single step). - */ typedef struct z_stream_s { - Bytef *next_in; /*!< next input byte */ - uInt avail_in; /*!< number of bytes available at next_in */ - uLong total_in; /*!< total nb of input bytes read so far */ + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ - Bytef *next_out; /*!< next output byte should be put there */ - uInt avail_out; /*!< remaining free space at next_out */ - uLong total_out; /*!< total nb of bytes output so far */ + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ -/*@observer@*/ /*@null@*/ - const char *msg; /*!< last error message, NULL if no error */ - struct internal_state FAR *state; /*!< not visible by applications */ + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ - alloc_func zalloc; /*!< used to allocate the internal state */ - free_func zfree; /*!< used to free the internal state */ - voidpf opaque; /*!< private data object passed to zalloc and zfree */ + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ - int data_type; /*!< best guess about the data type: ascii or binary */ - uLong adler; /*!< adler32 value of the uncompressed data */ - uLong crc; /*!< crc32 as updated during decompression */ + int data_type; /* best guess about the data type: ascii or binary */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ } z_stream; -typedef /*@abstract@*/ z_stream FAR *z_streamp; +typedef z_stream FAR *z_streamp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ /* constants */ @@ -164,24 +161,23 @@ typedef /*@abstract@*/ z_stream FAR *z_streamp; #define Z_DEFLATED 8 /* The deflate compression method (the only one supported in this version) */ -#define Z_NULL NULL /* for initializing zalloc, zfree, opaque */ +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ #define zlib_version zlibVersion() /* for compatibility with versions < 1.0.2 */ /* basic functions */ -/** - * The application can compare zlibVersion and ZLIB_VERSION for consistency. - * If the first character differs, the library code actually used is - * not compatible with the zlib.h header file used by the application. - * This check is automatically made by deflateInit and inflateInit. +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. */ -/*@observer@*/ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)) - /*@*/; /* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to @@ -199,104 +195,104 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)) with the version assumed by the caller (ZLIB_VERSION). msg is set to null if there is no error message. deflateInit does not perform any compression: this will be done by deflate(). +*/ -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce some + output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In particular + avail_in is zero after the call if enough output space has been provided + before the call.) Flushing may degrade compression for some compression + algorithms and so it should be used only when necessary. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + the compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + 0.1% larger than avail_in plus 12 bytes. If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update data_type if it can make a good guess about + the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). */ -/** - * deflate compresses as much data as possible, and stops when the input - * buffer becomes empty or the output buffer becomes full. It may introduce some - * output latency (reading input without producing any output) except when - * forced to flush. - * - * The detailed semantics are as follows. deflate performs one or both of the - * following actions: - * - * - Compress more input starting at next_in and update next_in and avail_in - * accordingly. If not all input can be processed (because there is not - * enough room in the output buffer), next_in and avail_in are updated and - * processing will resume at this point for the next call of deflate(). - * - * - Provide more output starting at next_out and update next_out and avail_out - * accordingly. This action is forced if the parameter flush is non zero. - * Forcing flush frequently degrades the compression ratio, so this parameter - * should be set only when necessary (in interactive applications). - * Some output may be provided even if flush is not set. - * - * Before the call of deflate(), the application should ensure that at least - * one of the actions is possible, by providing more input and/or consuming - * more output, and updating avail_in or avail_out accordingly; avail_out - * should never be zero before the call. The application can consume the - * compressed output when it wants, for example when the output buffer is full - * (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - * and with zero avail_out, it must be called again after making room in the - * output buffer because there might be more output pending. - * - * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - * flushed to the output buffer and the output is aligned on a byte boundary, so - * that the decompressor can get all input data available so far. (In particular - * avail_in is zero after the call if enough output space has been provided - * before the call.) Flushing may degrade compression for some compression - * algorithms and so it should be used only when necessary. - * - * If flush is set to Z_FULL_FLUSH, all output is flushed as with - * Z_SYNC_FLUSH, and the compression state is reset so that decompression can - * restart from this point if previous compressed data has been damaged or if - * random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - * the compression. - * - * If deflate returns with avail_out == 0, this function must be called again - * with the same value of the flush parameter and more output space (updated - * avail_out), until the flush is complete (deflate returns with non-zero - * avail_out). - * - * If the parameter flush is set to Z_FINISH, pending input is processed, - * pending output is flushed and deflate returns with Z_STREAM_END if there - * was enough output space; if deflate returns with Z_OK, this function must be - * called again with Z_FINISH and more output space (updated avail_out) but no - * more input data, until it returns with Z_STREAM_END or an error. After - * deflate has returned Z_STREAM_END, the only possible operations on the - * stream are deflateReset or deflateEnd. - * - * Z_FINISH can be used immediately after deflateInit if all the compression - * is to be done in a single step. In this case, avail_out must be at least - * 0.1% larger than avail_in plus 12 bytes. If deflate does not return - * Z_STREAM_END, then it must be called again as described above. - * - * deflate() sets strm->adler to the adler32 checksum of all input read - * so far (that is, total_in bytes). - * - * deflate() may update data_type if it can make a good guess about - * the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - * binary. This field is only for information purposes and does not affect - * the compression algorithm in any manner. - * - * deflate() returns Z_OK if some progress has been made (more input - * processed or more output produced), Z_STREAM_END if all input has been - * consumed and all output has been produced (only when flush is set to - * Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - * if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - * (for example avail_in or avail_out was zero). - */ -ZEXTERN int ZEXPORT deflate OF((/*@dependent@*/ /*@null@*/ z_streamp strm, int flush)) - /*@modifies strm @*/; - - -/** - * All dynamically allocated data structures for this stream are freed. - * This function discards any unprocessed input and does not flush any - * pending output. - * - * deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - * stream state was inconsistent, Z_DATA_ERROR if the stream was freed - * prematurely (some input or output was discarded). In the error case, - * msg may be set but then points to a static string (which must not be - * deallocated). + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)) - /*@modifies strm @*/; + /* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. If next_in is not Z_NULL and avail_in is large enough (the exact @@ -312,91 +308,88 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)) message. inflateInit does not perform any decompression apart from reading the zlib header if present: this will be done by inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unchanged.) +*/ -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may some + introduce some output latency (reading input without producing any output) + except when forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much + output as possible to the output buffer. The flushing behavior of inflate is + not specified for values of the flush parameter other than Z_SYNC_FLUSH + and Z_FINISH, but the current implementation actually flushes as much output + as possible anyway. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster routine + may be used for the single inflate() call. + + If a preset dictionary is needed at this point (see inflateSetDictionary + below), inflate sets strm-adler to the adler32 checksum of the + dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise + it sets strm->adler to the adler32 checksum of all output produced + so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or + an error code as described below. At the end of the stream, inflate() + checks that its computed adler32 checksum is equal to that saved by the + compressor and returns Z_STREAM_END only if the checksum is correct. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect + adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent + (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if no progress is possible or if there was not + enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR + case, the application may then call inflateSync to look for a good + compression block. */ -/** - * inflate decompresses as much data as possible, and stops when the input - * buffer becomes empty or the output buffer becomes full. It may some - * introduce some output latency (reading input without producing any output) - * except when forced to flush. - * - * The detailed semantics are as follows. inflate performs one or both of the - * following actions: - * - * - Decompress more input starting at next_in and update next_in and avail_in - * accordingly. If not all input can be processed (because there is not - * enough room in the output buffer), next_in is updated and processing - * will resume at this point for the next call of inflate(). - * - * - Provide more output starting at next_out and update next_out and avail_out - * accordingly. inflate() provides as much output as possible, until there - * is no more input data or no more space in the output buffer (see below - * about the flush parameter). - * - * Before the call of inflate(), the application should ensure that at least - * one of the actions is possible, by providing more input and/or consuming - * more output, and updating the next_* and avail_* values accordingly. - * The application can consume the uncompressed output when it wants, for - * example when the output buffer is full (avail_out == 0), or after each - * call of inflate(). If inflate returns Z_OK and with zero avail_out, it - * must be called again after making room in the output buffer because there - * might be more output pending. - * - * If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much - * output as possible to the output buffer. The flushing behavior of inflate is - * not specified for values of the flush parameter other than Z_SYNC_FLUSH - * and Z_FINISH, but the current implementation actually flushes as much output - * as possible anyway. - * - * inflate() should normally be called until it returns Z_STREAM_END or an - * error. However if all decompression is to be performed in a single step - * (a single call of inflate), the parameter flush should be set to - * Z_FINISH. In this case all pending input is processed and all pending - * output is flushed; avail_out must be large enough to hold all the - * uncompressed data. (The size of the uncompressed data may have been saved - * by the compressor for this purpose.) The next operation on this stream must - * be inflateEnd to deallocate the decompression state. The use of Z_FINISH - * is never required, but can be used to inform inflate that a faster routine - * may be used for the single inflate() call. - * - * If a preset dictionary is needed at this point (see inflateSetDictionary - * below), inflate sets strm-adler to the adler32 checksum of the - * dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise - * it sets strm->adler to the adler32 checksum of all output produced - * so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or - * an error code as described below. At the end of the stream, inflate() - * checks that its computed adler32 checksum is equal to that saved by the - * compressor and returns Z_STREAM_END only if the checksum is correct. - * - * inflate() returns Z_OK if some progress has been made (more input processed - * or more output produced), Z_STREAM_END if the end of the compressed data has - * been reached and all uncompressed output has been produced, Z_NEED_DICT if a - * preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - * corrupted (input stream not conforming to the zlib format or incorrect - * adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent - * (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not - * enough memory, Z_BUF_ERROR if no progress is possible or if there was not - * enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR - * case, the application may then call inflateSync to look for a good - * compression block. +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)) - /*@modifies strm @*/; - -/** - * All dynamically allocated data structures for this stream are freed. - * This function discards any unprocessed input and does not flush any - * pending output. - * - * inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - * was inconsistent. In the error case, msg may be set but then points to a - * static string (which must not be deallocated). - */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)) - /*@modifies strm @*/; /* Advanced functions */ @@ -405,6 +398,13 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)) */ /* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + This is another version of deflateInit with more compression options. The fields next_in, zalloc, zfree and opaque must be initialized before by the caller. @@ -439,107 +439,98 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)) memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid method). msg is set to null if there is no error message. deflateInit2 does not perform any compression: this will be done by deflate(). - -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - */ -/** - * Initializes the compression dictionary from the given byte sequence - * without producing any compressed output. This function must be called - * immediately after deflateInit, deflateInit2 or deflateReset, before any - * call of deflate. The compressor and decompressor must use exactly the same - * dictionary (see inflateSetDictionary). - * - * The dictionary should consist of strings (byte sequences) that are likely - * to be encountered later in the data to be compressed, with the most commonly - * used strings preferably put towards the end of the dictionary. Using a - * dictionary is most useful when the data to be compressed is short and can be - * predicted with good accuracy; the data can then be compressed better than - * with the default empty dictionary. - * - * Depending on the size of the compression data structures selected by - * deflateInit or deflateInit2, a part of the dictionary may in effect be - * discarded, for example if the dictionary is larger than the window size in - * deflate or deflate2. Thus the strings most likely to be useful should be - * put at the end of the dictionary, not at the front. - * - * Upon return of this function, strm->adler is set to the Adler32 value - * of the dictionary; the decompressor may later use this value to determine - * which dictionary has been used by the compressor. (The Adler32 value - * applies to the whole dictionary even if only a subset of the dictionary is - * actually used by the compressor.) - * - * deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - * parameter is invalid (such as NULL dictionary) or the stream state is - * inconsistent (for example if deflate has already been called for this stream - * or if the compression method is bsort). deflateSetDictionary does not - * perform any compression: this will be done by deflate(). - */ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, - uInt dictLength)) - /*@modifies strm @*/; - -/** - * Sets the destination stream as a complete copy of the source stream. - * - * This function can be useful when several compression strategies will be - * tried, for example when there are several ways of pre-processing the input - * data with a filter. The streams that will be discarded should then be freed - * by calling deflateEnd. Note that deflateCopy duplicates the internal - * compression state which can be quite large, so this strategy is slow and - * can consume lots of memory. - * - * deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - * enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - * (such as zalloc being NULL). msg is left unchanged in both source and - * destination. - */ -ZEXTERN int ZEXPORT deflateCopy OF((/*@dependent@*/ z_streamp dest, - z_streamp source)) - /*@modifies dest, source @*/; - -/** - * This function is equivalent to deflateEnd followed by deflateInit, - * but does not free and reallocate all the internal compression state. - * The stream will keep the same compression level and any other attributes - * that may have been set by deflateInit2. - * - * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - * stream state was inconsistent (such as zalloc or state being NULL). - */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)) - /*@modifies strm @*/; - -/** - * Dynamically update the compression level and compression strategy. The - * interpretation of level and strategy is as in deflateInit2. This can be - * used to switch between compression and straight copy of the input data, or - * to switch to a different kind of input data requiring a different - * strategy. If the compression level is changed, the input available so far - * is compressed with the old level (and may be flushed); the new level will - * take effect only at the next call of deflate(). - - * Before the call of deflateParams, the stream state must be set as for - * a call of deflate(), since the currently available input may have to - * be compressed and flushed. In particular, strm->avail_out must be non-zero. - - * deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - * stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - * if strm->avail_out was zero. - */ -ZEXTERN int ZEXPORT deflateParams OF((/*@dependent@*/ /*@null@*/ z_streamp strm, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any + call of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size in + deflate or deflate2. Thus the strings most likely to be useful should be + put at the end of the dictionary, not at the front. + + Upon return of this function, strm->adler is set to the Adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, int level, - int strategy)) - /*@modifies strm @*/; + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different + strategy. If the compression level is changed, the input available so far + is compressed with the old level (and may be flushed); the new level will + take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ /* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. @@ -557,58 +548,51 @@ ZEXTERN int ZEXPORT deflateParams OF((/*@dependent@*/ /*@null@*/ z_streamp strm, does not perform any decompression apart from reading the zlib header if present: this will be done by inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unchanged.) - -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - */ -/** - * Initializes the decompression dictionary from the given uncompressed byte - * sequence. This function must be called immediately after a call of inflate - * if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - * can be determined from the Adler32 value returned by this call of - * inflate. The compressor and decompressor must use exactly the same - * dictionary (see deflateSetDictionary). - * - * inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - * parameter is invalid (such as NULL dictionary) or the stream state is - * inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - * expected one (incorrect Adler32 value). inflateSetDictionary does not - * perform any decompression: this will be done by subsequent calls of - * inflate(). - */ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, - uInt dictLength)) - /*@modifies strm @*/; - -/** - * Skips invalid compressed data until a full flush point (see above the - * description of deflate with Z_FULL_FLUSH) can be found, or until all - * available input is skipped. No output is provided. - * - * inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - * if no more input was provided, Z_DATA_ERROR if no flush point has been found, - * or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - * case, the application may save the current current value of total_in which - * indicates where valid compressed data was found. In the error case, the - * application may repeatedly call inflateSync, providing more input each time, - * until success or end of the input data. - */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)) - /*@modifies strm @*/; - -/** - * This function is equivalent to inflateEnd followed by inflateInit, - * but does not free and reallocate all the internal decompression state. - * The stream will keep attributes that may have been set by inflateInit2. - * - * inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - * stream state was inconsistent (such as zalloc or state being NULL). - */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)) - /*@modifies strm @*/; + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate + if this call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the Adler32 value returned by this call of + inflate. The compressor and decompressor must use exactly the same + dictionary (see deflateSetDictionary). + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect Adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been found, + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success + case, the application may save the current current value of total_in which + indicates where valid compressed data was found. In the error case, the + application may repeatedly call inflateSync, providing more input each time, + until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. + The stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ /* utility functions */ @@ -621,384 +605,268 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)) utility functions can easily be modified if you need special options. */ -/** - * Compresses 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 at least 0.1% larger than - * sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the - * compressed buffer. - * This function can be used to compress a whole file at once if the - * input file is mmap'ed. - * compress 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. - */ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)) - /*@modifies *dest, *destLen @*/; - -/** - * Compresses the source buffer into the destination buffer. The level - * parameter has the same meaning as in deflateInit. sourceLen is the byte - * length of the source buffer. Upon entry, destLen is the total size of the - * destination buffer, which must be at least 0.1% larger than sourceLen plus - * 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - * - * compress2 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, - * Z_STREAM_ERROR if the level parameter is invalid. - */ + const Bytef *source, uLong sourceLen)); +/* + Compresses 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 at least 0.1% larger than + sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the + compressed buffer. + This function can be used to compress a whole file at once if the + input file is mmap'ed. + compress 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. +*/ + ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, - int level)) - /*@modifies *dest, *destLen @*/; - -/** - * 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. - */ + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 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, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)) - /*@modifies *dest, *destLen @*/; + const Bytef *source, uLong sourceLen)); +/* + 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. +*/ typedef voidp gzFile; -/** - * Opens a gzip (.gz) file for reading or writing. The mode parameter - * is as in fopen ("rb" or "wb") but can also include a compression level - * ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - * Huffman only compression as in "wb1h". (See the description - * of deflateInit2 for more information about the strategy parameter.) - * - * gzopen can be used to read a file which is not in gzip format; in this - * case gzread will directly read from the file without decompression. - * - * gzopen returns NULL if the file could not be opened or if there was - * insufficient memory to allocate the (de)compression state; errno - * can be checked to distinguish the two cases (if errno is zero, the - * zlib error is Z_MEM_ERROR). - * - * @param path file name - * @param mode file open mode - * @return compressed stream - */ -/*@null@*/ -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)) - /*@globals fileSystem @*/ - /*@modifies fileSystem @*/; - -/** - * gzdopen() associates a gzFile with the file descriptor fd. File - * descriptors are obtained from calls like open, dup, creat, pipe or - * fileno (in the file has been previously opened with fopen). - * The mode parameter is as in gzopen. - * The next call of gzclose on the returned gzFile will also close the - * file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - * descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - * gzdopen returns NULL if there was insufficient memory to allocate - * the (de)compression state. - * - * @param fd file descriptor - * @param mode file open mode - * @return compressed stream - */ -/*@null@*/ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)) - /*@globals fileSystem @*/ - /*@modifies fileSystem @*/; - -/** - * Dynamically update the compression level or strategy. See the description - * of deflateInit2 for the meaning of these parameters. - * gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - * opened for writing. - * - * @param file compressed stream - * @param level - * @param strategy - * @return Z_OK on success - */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Reads the given number of uncompressed bytes from the compressed file. - * If the input file was not in gzip format, gzread copies the given number - * of bytes into the buffer. - * gzread returns the number of uncompressed bytes actually read (0 for - * end of file, -1 for error). - * - * @param file compressed stream - * @param buf - * @param len - * @return no. of bytes read, 0 on EOF, -1 on error - */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, /*@out@*/ voidp buf, unsigned len)) - /*@globals errno, fileSystem @*/ - /*@modifies file, *buf, errno, fileSystem @*/; - -/** - * Writes the given number of uncompressed bytes into the compressed file. - * gzwrite returns the number of uncompressed bytes actually written - * (0 in case of error). - * - * @param file compressed stream - * @param buf - * @param len - * @return no. of bytes written, 0 on error - */ +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb") but can also include a compression level + ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for + Huffman only compression as in "wb1h". (See the description + of deflateInit2 for more information about the strategy parameter.) + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). */ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen() associates a gzFile with the file descriptor fd. File + descriptors are obtained from calls like open, dup, creat, pipe or + fileno (in the file has been previously opened with fopen). + The mode parameter is as in gzopen. + The next call of gzclose on the returned gzFile will also close the + file descriptor fd, just like fclose(fdopen(fd), mode) closes the file + descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). + gzdopen returns NULL if there was insufficient memory to allocate + the (de)compression state. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. + If the input file was not in gzip format, gzread copies the given number + of bytes into the buffer. + gzread returns the number of uncompressed bytes actually read (0 for + end of file, -1 for error). */ + ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - const voidp buf, unsigned len)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Converts, formats, and writes the args to the compressed file under - * control of the format string, as in fprintf. gzprintf returns the number of - * uncompressed bytes actually written (0 in case of error). - * - * @param file compressed stream - * @param format - * @return no. of bytes written, 0 on error - */ -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Writes the given null-terminated string to the compressed file, excluding - * the terminating null character. - * gzputs returns the number of characters written, or -1 in case of error. - * - * @param file compressed stream - * @param s - * @return no. of bytes written, -1 on error - */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Reads bytes from the compressed file until len-1 characters are read, or - * a newline character is read and transferred to buf, or an end-of-file - * condition is encountered. The string is then terminated with a null - * character. - * gzgets returns buf, or Z_NULL in case of error. - * - * @param file compressed stream - * @param buf - * @param len - * @return buf, Z_NULL on error - */ -/*@null@*/ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)) - /*@globals fileSystem @*/ - /*@modifies file, buf, fileSystem @*/; - -/** - * Writes c, converted to an unsigned char, into the compressed file. - * gzputc returns the value that was written, or -1 in case of error. - * - * @param file compressed stream - * @param c - * @return -1 on error - */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Reads one byte from the compressed file. gzgetc returns this byte - * or -1 in case of end of file or error. - * - * @param file compressed stream - * @return -1 on eof/error - */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Flushes all pending output into the compressed file. The parameter - * flush is as in the deflate() function. The return value is the zlib - * error number (see function gzerror below). gzflush returns Z_OK if - * the flush parameter is Z_FINISH and all output could be flushed. - * gzflush should be called only when strictly necessary because it can - * degrade compression. - * - * @param file compressed stream - * @return Z_OK on success - */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Sets the starting position for the next gzread or gzwrite on the - * given compressed file. The offset represents a number of bytes in the - * uncompressed data stream. The whence parameter is defined as in lseek(2); - * the value SEEK_END is not supported. - * If the file is opened for reading, this function is emulated but can be - * extremely slow. If the file is opened for writing, only forward seeks are - * supported; gzseek then compresses a sequence of zeroes up to the new - * starting position. - * - * gzseek returns the resulting offset location as measured in bytes from - * the beginning of the uncompressed stream, or -1 in case of error, in - * particular if the file is opened for writing and the new starting position - * would be before the current position. - * - * @param file compressed stream - * @param offset - * @param whence - * @return -1 on error - */ + const voidp buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes actually written + (0 in case of error). +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or + a newline character is read and transferred to buf, or an end-of-file + condition is encountered. The string is then terminated with a null + character. + gzgets returns buf, or Z_NULL in case of error. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. The return value is the zlib + error number (see function gzerror below). gzflush returns Z_OK if + the flush parameter is Z_FINISH and all output could be flushed. + gzflush should be called only when strictly necessary because it can + degrade compression. +*/ + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Rewinds the given file. This function is supported only for reading. - * - * gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) - * - * @param file compressed stream - * @return - */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Returns the starting position for the next gzread or gzwrite on the - * given compressed file. This position represents a number of bytes in the - * uncompressed data stream. - * - * gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) - * - * @param file compressed stream - * @return - */ -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Returns 1 when EOF has previously been detected reading the given - * input stream, otherwise zero. - * - * @param file compressed stream - * @return - */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)) - /*@*/; - -/** - * Flushes all pending output if necessary, closes the compressed file - * and deallocates all the (de)compression state. The return value is the zlib - * error number (see function gzerror below). - * - * @param file compressed stream - * @return - */ -ZEXTERN int ZEXPORT gzclose OF((/*@only@*/ gzFile file)) - /*@globals fileSystem @*/ - /*@modifies file, fileSystem @*/; - -/** - * Returns the error message for the last error which occurred on the - * given compressed file. errnum is set to zlib error number. If an - * error occurred in the file system and not in the compression library, - * errnum is set to Z_ERRNO and the application may consult errno - * to get the exact error code. - * - * @param file compressed stream - * @param errnum - * @return - */ -/*@observer@*/ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)) - /*@modifies *errnum @*/; + z_off_t offset, int whence)); +/* + Sets the starting position for the next gzread or gzwrite on the + given compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +/* + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. The return value is the zlib + error number (see function gzerror below). +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ /* checksum functions */ /* - * These functions are not related to compression but are exported - * anyway because they might be useful in applications using the - * compression library. - */ + These functions are not related to compression but are exported + anyway because they might be useful in applications using the + compression library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); + +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: -/** - * Update a running Adler-32 checksum with the bytes buf[0..len-1] and - * return the updated checksum. If buf is NULL, this function returns - * the required initial value for the checksum. - * An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - * much faster. Usage example: -\code uLong adler = adler32(0L, Z_NULL, 0); while (read_buffer(buffer, length) != EOF) { adler = adler32(adler, buffer, length); } if (adler != original_adler) error(); -\endcode - */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)) - /*@*/; - -/** - * Update a running crc with the bytes buf[0..len-1] and return the updated - * crc. If buf is NULL, this function returns the required initial value - * for the crc. Pre- and post-conditioning (one's complement) is performed - * within this function so it shouldn't be done by the application. - * Usage example: -\code +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running crc with the bytes buf[0..len-1] and return the updated + crc. If buf is NULL, this function returns the required initial value + for the crc. Pre- and post-conditioning (one's complement) is performed + within this function so it shouldn't be done by the application. + Usage example: + uLong crc = crc32(0L, Z_NULL, 0); while (read_buffer(buffer, length) != EOF) { crc = crc32(crc, buffer, length); } if (crc != original_crc) error(); -\endcode - */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)) - /*@*/; +*/ + /* various hacks, don't look :) */ /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((/*@dependent@*/ /*@null@*/ z_streamp strm, - int level, - const char *version, int stream_size)) - /*@modifies strm @*/; +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)) - /*@modifies strm @*/; -ZEXTERN int ZEXPORT deflateInit2_ OF((/*@dependent@*/ /*@null@*/ z_streamp strm, - int level, int method, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, - int stream_size)) - /*@modifies strm @*/; + int stream_size)); ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)) - /*@modifies strm @*/; + const char *version, int stream_size)); #define deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) #define inflateInit(strm) \ @@ -1010,20 +878,16 @@ ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) -/*@observer@*/ -ZEXTERN const char * ZEXPORT zError OF((int err)) - /*@*/; - -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)) - /*@modifies z @*/; +#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; /* hack for buggy compilers */ +#endif -/*@observer@*/ -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)) - /*@*/; +ZEXTERN const char * ZEXPORT zError OF((int err)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); #ifdef __cplusplus } #endif -/*@=declundef =fcnuse @*/ #endif /* _ZLIB_H */ diff --git a/zlib/zutil.c b/zlib/zutil.c index 7a3022138..e55360a51 100644 --- a/zlib/zutil.c +++ b/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 */ @@ -41,7 +38,7 @@ const char * ZEXPORT zlibVersion(void) # endif int z_verbose = verbose; -void z_error (char *m) +void z_error (char * m) { fprintf(stderr, "%s\n", m); exit(1); @@ -51,17 +48,15 @@ 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 -void zmemcpy(Bytef *dest, const Bytef *source, uInt len) +void zmemcpy(Bytef * dest, const Bytef * source, uInt len) { if (len == 0) return; do { @@ -69,7 +64,7 @@ void zmemcpy(Bytef *dest, const Bytef *source, uInt len) } while (--len != 0); } -int zmemcmp(const Bytef *s1, const Bytef *s2, uInt len) +int zmemcmp(const Bytef * s1, const Bytef * s2, uInt len) { uInt j; @@ -79,7 +74,7 @@ int zmemcmp(const Bytef *s1, const Bytef *s2, uInt len) return 0; } -void zmemzero(Bytef *dest, uInt len) +void zmemzero(Bytef * dest, uInt len) { if (len == 0) return; do { @@ -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 diff --git a/zlib/zutil.h b/zlib/zutil.h index 2d53d185a..718ebc15b 100644 --- a/zlib/zutil.h +++ b/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 */ |