summaryrefslogtreecommitdiffstats
path: root/lib/libz
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libz')
-rw-r--r--lib/libz/Makefile175
-rw-r--r--lib/libz/adler32.c2
-rw-r--r--lib/libz/algorithm.doc105
-rw-r--r--lib/libz/compress.c2
-rw-r--r--lib/libz/crc32.c2
-rw-r--r--lib/libz/deflate.c10
-rw-r--r--lib/libz/deflate.h8
-rw-r--r--lib/libz/example.c30
-rw-r--r--lib/libz/gzio.c39
-rw-r--r--lib/libz/minigzip.c19
-rw-r--r--lib/libz/trees.c54
-rw-r--r--lib/libz/uncompr.c2
-rw-r--r--lib/libz/zconf.h73
-rw-r--r--lib/libz/zutil.c10
-rw-r--r--lib/libz/zutil.h23
15 files changed, 142 insertions, 412 deletions
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
index 772bc31..8b8e6cf 100644
--- a/lib/libz/Makefile
+++ b/lib/libz/Makefile
@@ -1,158 +1,37 @@
-# Makefile for zlib
-# Copyright (C) 1995-1998 Jean-loup Gailly.
-# For conditions of distribution and use, see copyright notice in zlib.h
+#
+# $Id: Makefile,v 1.8 1998/04/17 07:26:51 phk Exp $
+#
-# To compile and test, type:
-# ./configure; make test
-# The call of configure is optional if you don't have special requirements
-# If you wish to build zlib as a shared library, use: ./configure -s
+MAINTAINER=peter@FreeBSD.org
-# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
-# make install
-# To install in $HOME instead of /usr/local, use:
-# make install prefix=$HOME
+LIB= z
+MAN3= zlib.3
-CC=cc
+#CFLAGS+= -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
+#CFLAGS+= -g -DDEBUG
+#CFLAGS+= -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
+# -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS=-O
-#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
-#CFLAGS=-g -DDEBUG
-#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
-# -Wstrict-prototypes -Wmissing-prototypes
+CLEANFILES+= example.o example foo.gz minigzip.o minigzip
-LDFLAGS=-L. -lz
-LDSHARED=$(CC)
+SRCS = adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \
+ zutil.c inflate.c infblock.c inftrees.c infcodes.c infutil.c inffast.c
-VER=1.1.1
-LIBS=libz.a
-SHAREDLIB=libz.so
+beforeinstall:
+.for hdr in zconf.h zlib.h
+ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/${hdr} \
+ ${DESTDIR}/usr/include
+.endfor
-AR=ar rc
-RANLIB=ranlib
-TAR=tar
-SHELL=/bin/sh
+minigzip: all minigzip.o
+ $(CC) -o minigzip minigzip.o -L. -lz
-prefix=/usr/local
-exec_prefix = $(prefix)
+example: all example.o
+ $(CC) -o example example.o -L. -lz
-OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
- zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
+test: example minigzip
+ (export LD_LIBRARY_PATH=. ; ./example )
+ (export LD_LIBRARY_PATH=. ; \
+ echo hello world | ./minigzip | ./minigzip -d )
-TEST_OBJS = example.o minigzip.o
-
-DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \
- algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \
- nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \
- contrib/asm386/*.asm contrib/asm386/*.c \
- contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/iostream/*.cpp \
- contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \
- contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32
-
-all: example minigzip
-
-test: all
- @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
- echo hello world | ./minigzip | ./minigzip -d || \
- echo ' *** minigzip test FAILED ***' ; \
- if ./example; then \
- echo ' *** zlib test OK ***'; \
- else \
- echo ' *** zlib test FAILED ***'; \
- fi
-
-libz.a: $(OBJS)
- $(AR) $@ $(OBJS)
- -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
-
-$(SHAREDLIB).$(VER): $(OBJS)
- $(LDSHARED) -o $@ $(OBJS)
- rm -f $(SHAREDLIB) $(SHAREDLIB).1
- ln -s $@ $(SHAREDLIB)
- ln -s $@ $(SHAREDLIB).1
-
-example: example.o $(LIBS)
- $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
-
-minigzip: minigzip.o $(LIBS)
- $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
-
-install: $(LIBS)
- -@if [ ! -d $(prefix)/include ]; then mkdir $(prefix)/include; fi
- -@if [ ! -d $(exec_prefix)/lib ]; then mkdir $(exec_prefix)/lib; fi
- cp zlib.h zconf.h $(prefix)/include
- chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h
- cp $(LIBS) $(exec_prefix)/lib
- cd $(exec_prefix)/lib; chmod 755 $(LIBS)
- -@(cd $(exec_prefix)/lib; $(RANLIB) libz.a || true) >/dev/null 2>&1
- cd $(exec_prefix)/lib; if test -f $(SHAREDLIB).$(VER); then \
- rm -f $(SHAREDLIB) $(SHAREDLIB).1; \
- ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \
- ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \
- (ldconfig || true) >/dev/null 2>&1; \
- fi
-# The ranlib in install is needed on NeXTSTEP which checks file times
-# ldconfig is for Linux
-
-uninstall:
- cd $(prefix)/include; \
- v=$(VER); \
- if test -f zlib.h; then \
- v=`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`; \
- rm -f zlib.h zconf.h; \
- fi; \
- cd $(exec_prefix)/lib; rm -f libz.a; \
- if test -f $(SHAREDLIB).$$v; then \
- rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \
- fi
-
-clean:
- rm -f *.o *~ example minigzip libz.a libz.so* foo.gz
-
-distclean: clean
-
-zip:
- mv Makefile Makefile~; cp -p Makefile.in Makefile
- rm -f test.c ztest*.c
- v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
- zip -ul9 zlib$$v $(DISTFILES)
- mv Makefile~ Makefile
-
-dist:
- mv Makefile Makefile~; cp -p Makefile.in Makefile
- rm -f test.c ztest*.c
- d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\
- rm -f $$d.tar.gz; \
- if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \
- files=""; \
- for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \
- cd ..; \
- GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \
- if test ! -d $$d; then rm -f $$d; fi
- mv Makefile~ Makefile
-
-tags:
- etags *.[ch]
-
-depend:
- makedepend -- $(CFLAGS) -- *.[ch]
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-adler32.o: zlib.h zconf.h
-compress.o: zlib.h zconf.h
-crc32.o: zlib.h zconf.h
-deflate.o: deflate.h zutil.h zlib.h zconf.h
-example.o: zlib.h zconf.h
-gzio.o: zutil.h zlib.h zconf.h
-infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h
-infcodes.o: zutil.h zlib.h zconf.h
-infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h
-inffast.o: zutil.h zlib.h zconf.h inftrees.h
-inffast.o: infblock.h infcodes.h infutil.h inffast.h
-inflate.o: zutil.h zlib.h zconf.h infblock.h
-inftrees.o: zutil.h zlib.h zconf.h inftrees.h
-infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
-minigzip.o: zlib.h zconf.h
-trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
-uncompr.o: zlib.h zconf.h
-zutil.o: zutil.h zlib.h zconf.h
+.include <bsd.lib.mk>
diff --git a/lib/libz/adler32.c b/lib/libz/adler32.c
index 16cf9a7..b1f71ce 100644
--- a/lib/libz/adler32.c
+++ b/lib/libz/adler32.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "zlib.h"
diff --git a/lib/libz/algorithm.doc b/lib/libz/algorithm.doc
deleted file mode 100644
index 01902af..0000000
--- a/lib/libz/algorithm.doc
+++ /dev/null
@@ -1,105 +0,0 @@
-1. Compression algorithm (deflate)
-
-The deflation algorithm used by zlib (also zip and gzip) is a variation of
-LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
-the input data. The second occurrence of a string is replaced by a
-pointer to the previous string, in the form of a pair (distance,
-length). Distances are limited to 32K bytes, and lengths are limited
-to 258 bytes. When a string does not occur anywhere in the previous
-32K bytes, it is emitted as a sequence of literal bytes. (In this
-description, `string' must be taken as an arbitrary sequence of bytes,
-and is not restricted to printable characters.)
-
-Literals or match lengths are compressed with one Huffman tree, and
-match distances are compressed with another tree. The trees are stored
-in a compact form at the start of each block. The blocks can have any
-size (except that the compressed data for one block must fit in
-available memory). A block is terminated when deflate() determines that
-it would be useful to start another block with fresh trees. (This is
-somewhat similar to the behavior of LZW-based _compress_.)
-
-Duplicated strings are found using a hash table. All input strings of
-length 3 are inserted in the hash table. A hash index is computed for
-the next 3 bytes. If the hash chain for this index is not empty, all
-strings in the chain are compared with the current input string, and
-the longest match is selected.
-
-The hash chains are searched starting with the most recent strings, to
-favor small distances and thus take advantage of the Huffman encoding.
-The hash chains are singly linked. There are no deletions from the
-hash chains, the algorithm simply discards matches that are too old.
-
-To avoid a worst-case situation, very long hash chains are arbitrarily
-truncated at a certain length, determined by a runtime option (level
-parameter of deflateInit). So deflate() does not always find the longest
-possible match but generally finds a match which is long enough.
-
-deflate() also defers the selection of matches with a lazy evaluation
-mechanism. After a match of length N has been found, deflate() searches for a
-longer match at the next input byte. If a longer match is found, the
-previous match is truncated to a length of one (thus producing a single
-literal byte) and the longer match is emitted afterwards. Otherwise,
-the original match is kept, and the next match search is attempted only
-N steps later.
-
-The lazy match evaluation is also subject to a runtime parameter. If
-the current match is long enough, deflate() reduces the search for a longer
-match, thus speeding up the whole process. If compression ratio is more
-important than speed, deflate() attempts a complete second search even if
-the first match is already long enough.
-
-The lazy match evaluation is not performed for the fastest compression
-modes (level parameter 1 to 3). For these fast modes, new strings
-are inserted in the hash table only when no match was found, or
-when the match is not too long. This degrades the compression ratio
-but saves time since there are both fewer insertions and fewer searches.
-
-
-2. Decompression algorithm (inflate)
-
-The real question is, given a Huffman tree, how to decode fast. The most
-important realization is that shorter codes are much more common than
-longer codes, so pay attention to decoding the short codes fast, and let
-the long codes take longer to decode.
-
-inflate() sets up a first level table that covers some number of bits of
-input less than the length of longest code. It gets that many bits from the
-stream, and looks it up in the table. The table will tell if the next
-code is that many bits or less and how many, and if it is, it will tell
-the value, else it will point to the next level table for which inflate()
-grabs more bits and tries to decode a longer code.
-
-How many bits to make the first lookup is a tradeoff between the time it
-takes to decode and the time it takes to build the table. If building the
-table took no time (and if you had infinite memory), then there would only
-be a first level table to cover all the way to the longest code. However,
-building the table ends up taking a lot longer for more bits since short
-codes are replicated many times in such a table. What inflate() does is
-simply to make the number of bits in the first table a variable, and set it
-for the maximum speed.
-
-inflate() sends new trees relatively often, so it is possibly set for a
-smaller first level table than an application that has only one tree for
-all the data. For inflate, which has 286 possible codes for the
-literal/length tree, the size of the first table is nine bits. Also the
-distance trees have 30 possible values, and the size of the first table is
-six bits. Note that for each of those cases, the table ended up one bit
-longer than the ``average'' code length, i.e. the code length of an
-approximately flat code which would be a little more than eight bits for
-286 symbols and a little less than five bits for 30 symbols. It would be
-interesting to see if optimizing the first level table for other
-applications gave values within a bit or two of the flat code size.
-
-
-Jean-loup Gailly Mark Adler
-gzip@prep.ai.mit.edu madler@alumni.caltech.edu
-
-
-References:
-
-[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
-Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
-pp. 337-343.
-
-``DEFLATE Compressed Data Format Specification'' available in
-ftp://ds.internic.net/rfc/rfc1951.txt
diff --git a/lib/libz/compress.c b/lib/libz/compress.c
index 1cee470..31c51e6 100644
--- a/lib/libz/compress.c
+++ b/lib/libz/compress.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "zlib.h"
diff --git a/lib/libz/crc32.c b/lib/libz/crc32.c
index a91101a..2e98580 100644
--- a/lib/libz/crc32.c
+++ b/lib/libz/crc32.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "zlib.h"
diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c
index 25d5818..dc8c76c 100644
--- a/lib/libz/deflate.c
+++ b/lib/libz/deflate.c
@@ -47,12 +47,12 @@
*
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "deflate.h"
const char deflate_copyright[] =
- " deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly ";
+ " deflate 1.1.1 Copyright 1995-1998 Jean-loup Gailly ";
/*
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
@@ -608,13 +608,11 @@ int ZEXPORT deflateCopy (dest, source)
deflate_state *ss;
ushf *overlay;
+ ss = source->state;
- if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ if (source == Z_NULL || dest == Z_NULL || ss == Z_NULL) {
return Z_STREAM_ERROR;
}
-
- ss = source->state;
-
*dest = *source;
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h
index 962676d..5cf65ec 100644
--- a/lib/libz/deflate.h
+++ b/lib/libz/deflate.h
@@ -8,7 +8,7 @@
subject to change. Applications should only use zlib.h.
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#ifndef _DEFLATE_H
#define _DEFLATE_H
@@ -230,12 +230,12 @@ typedef struct internal_state {
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
+ ulg compressed_len; /* total bit length of compressed file */
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
#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 */
+ ulg bits_sent; /* bit length of the compressed data */
#endif
ush bi_buf;
@@ -268,7 +268,7 @@ typedef struct internal_state {
/* in trees.c */
void _tr_init OF((deflate_state *s));
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
-void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ulg _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof));
void _tr_align OF((deflate_state *s));
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
diff --git a/lib/libz/example.c b/lib/libz/example.c
index 8307c84..e313c55 100644
--- a/lib/libz/example.c
+++ b/lib/libz/example.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include <stdio.h>
#include "zlib.h"
@@ -15,12 +15,6 @@
extern void exit OF((int));
#endif
-#if defined(VMS) || defined(RISCOS)
-# define TESTFILE "foo-gz"
-#else
-# define TESTFILE "foo.gz"
-#endif
-
#define CHECK_ERR(err, msg) { \
if (err != Z_OK) { \
fprintf(stderr, "%s error: %d\n", msg, err); \
@@ -77,7 +71,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
fprintf(stderr, "bad uncompress\n");
exit(1);
} else {
- printf("uncompress(): %s\n", (char *)uncompr);
+ printf("uncompress(): %s\n", uncompr);
}
}
@@ -85,8 +79,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 */
+ const char *out; /* output file */
+ const char *in; /* input file */
Byte *uncompr;
int uncomprLen;
{
@@ -127,13 +121,13 @@ void test_gzio(out, in, uncompr, uncomprLen)
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
exit(1);
} else {
- printf("gzread(): %s\n", (char *)uncompr);
+ printf("gzread(): %s\n", uncompr);
}
pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
- (long)pos, (long)gztell(file));
+ pos, gztell(file));
exit(1);
}
@@ -152,7 +146,7 @@ void test_gzio(out, in, uncompr, uncomprLen)
fprintf(stderr, "bad gzgets after gzseek\n");
exit(1);
} else {
- printf("gzgets() after gzseek: %s\n", (char *)uncompr);
+ printf("gzgets() after gzseek: %s\n", uncompr);
}
gzclose(file);
@@ -233,7 +227,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
fprintf(stderr, "bad inflate\n");
exit(1);
} else {
- printf("inflate(): %s\n", (char *)uncompr);
+ printf("inflate(): %s\n", uncompr);
}
}
@@ -412,7 +406,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
- printf("after inflateSync(): hel%s\n", (char *)uncompr);
+ printf("after inflateSync(): hel%s\n", uncompr);
}
/* ===========================================================================
@@ -498,7 +492,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
fprintf(stderr, "bad inflate with dict\n");
exit(1);
} else {
- printf("inflate with dictionary: %s\n", (char *)uncompr);
+ printf("inflate with dictionary: %s\n", uncompr);
}
}
@@ -534,8 +528,8 @@ int main(argc, argv)
}
test_compress(compr, comprLen, uncompr, uncomprLen);
- test_gzio((argc > 1 ? argv[1] : TESTFILE),
- (argc > 2 ? argv[2] : TESTFILE),
+ test_gzio((argc > 1 ? argv[1] : "foo.gz"),
+ (argc > 2 ? argv[2] : "foo.gz"),
uncompr, (int)uncomprLen);
test_deflate(compr, comprLen);
diff --git a/lib/libz/gzio.c b/lib/libz/gzio.c
index f7c336a..e3782d5 100644
--- a/lib/libz/gzio.c
+++ b/lib/libz/gzio.c
@@ -5,7 +5,7 @@
* Compile this file with -DNO_DEFLATE to avoid the compression code.
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include <stdio.h>
@@ -13,16 +13,8 @@
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
-# define Z_BUFSIZE 16384
-# endif
-#endif
-#ifndef Z_PRINTF_BUFSIZE
-# define Z_PRINTF_BUFSIZE 4096
-#endif
+#define Z_BUFSIZE 16384
+#define Z_PRINTF_BUFSIZE 4096
#define ALLOC(size) malloc(size)
#define TRYFREE(p) {if (p) free(p);}
@@ -140,12 +132,8 @@ local gzFile gz_open (path, mode, fd)
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.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
- * present after the compressed stream.
- */
+ /* windowBits is passed < 0 to tell that there is no zlib header */
+
if (err != Z_OK || s->inbuf == Z_NULL) {
return destroy(s), (gzFile)Z_NULL;
}
@@ -391,7 +379,6 @@ int ZEXPORT gzread (file, buf, len)
len -= s->stream.avail_out;
s->stream.total_in += (uLong)len;
s->stream.total_out += (uLong)len;
- if (len == 0) s->z_eof = 1;
return (int)len;
}
if (s->stream.avail_in == 0 && !s->z_eof) {
@@ -414,14 +401,10 @@ int ZEXPORT gzread (file, buf, len)
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
start = s->stream.next_out;
- if (getLong(s) != s->crc) {
+ if (getLong(s) != s->crc || getLong(s) != s->stream.total_out) {
s->z_err = Z_DATA_ERROR;
} else {
- (void)getLong(s);
- /* The uncompressed length returned by above getlong() may
- * be different from s->stream.total_out) in case of
- * concatenated .gz files. Check for such files:
- */
+ /* Check for concatenated .gz files: */
check_header(s);
if (s->z_err == Z_OK) {
uLong total_in = s->stream.total_in;
@@ -589,7 +572,7 @@ int ZEXPORT gzputs(file, s)
gzFile file;
const char *s;
{
- return gzwrite(file, (char*)s, (unsigned)strlen(s));
+ return gzwrite(file, (const voidp)s, (unsigned)strlen(s));
}
@@ -674,7 +657,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
return -1L;
#else
if (whence == SEEK_SET) {
- offset -= s->stream.total_in;
+ offset -= s->stream.total_out;
}
if (offset < 0) return -1L;
@@ -749,7 +732,6 @@ int ZEXPORT gzrewind (file)
s->z_eof = 0;
s->stream.avail_in = 0;
s->stream.next_in = s->inbuf;
- s->crc = crc32(0L, Z_NULL, 0);
if (s->startpos == 0) { /* not a compressed file */
rewind(s->file);
@@ -798,8 +780,7 @@ local void putLong (file, x)
}
/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets z_err in case
- of error.
+ Reads a long in LSB order from the given gz_stream. Sets
*/
local uLong getLong (s)
gz_stream *s;
diff --git a/lib/libz/minigzip.c b/lib/libz/minigzip.c
index 7215eae..487632e 100644
--- a/lib/libz/minigzip.c
+++ b/lib/libz/minigzip.c
@@ -13,7 +13,7 @@
* or in pipe mode.
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include <stdio.h>
#include "zlib.h"
@@ -48,9 +48,6 @@
# define GZ_SUFFIX "-gz"
# define fileno(file) file->__file
#endif
-#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-# include <unix.h> /* for fileno */
-#endif
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
extern int unlink OF((const char *));
@@ -273,15 +270,25 @@ int main(argc, argv)
{
int uncompr = 0;
gzFile file;
- char outmode[20];
+ char *bname, outmode[20];
strcpy(outmode, "wb6 ");
prog = argv[0];
+ bname = strrchr(argv[0], '/');
+ if (bname)
+ bname++;
+ else
+ bname = argv[0];
argc--, argv++;
+ if (!strcmp(bname, "gunzip") || !strcmp(bname, "zcat"))
+ uncompr = 1;
+
while (argc > 0) {
- if (strcmp(*argv, "-d") == 0)
+ if (strcmp(*argv, "-c") == 0)
+ ; /* Just for compatability with gzip */
+ else if (strcmp(*argv, "-d") == 0)
uncompr = 1;
else if (strcmp(*argv, "-f") == 0)
outmode[3] = 'f';
diff --git a/lib/libz/trees.c b/lib/libz/trees.c
index f01fb30..2497001 100644
--- a/lib/libz/trees.c
+++ b/lib/libz/trees.c
@@ -29,7 +29,7 @@
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
/* #define GEN_TREES_H */
@@ -250,13 +250,6 @@ local void tr_static_init()
if (static_init_done) return;
- /* For some embedded targets, global variables are not initialized: */
- static_l_desc.static_tree = static_ltree;
- static_l_desc.extra_bits = extra_lbits;
- static_d_desc.static_tree = static_dtree;
- static_d_desc.extra_bits = extra_dbits;
- static_bl_desc.extra_bits = extra_blbits;
-
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) {
@@ -385,6 +378,8 @@ void _tr_init(s)
{
tr_static_init();
+ s->compressed_len = 0L;
+
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
@@ -398,7 +393,6 @@ void _tr_init(s)
s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG
- s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
@@ -871,10 +865,9 @@ void _tr_stored_block(s, buf, stored_len, eof)
int eof; /* true if this is the last block for a file */
{
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
-#ifdef DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
-#endif
+
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
@@ -894,9 +887,7 @@ void _tr_align(s)
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
-#endif
bi_flush(s);
/* Of the 10 bits for the empty block, we have already sent
* (10 - bi_valid) bits. The lookahead for the last real code (before
@@ -906,9 +897,7 @@ void _tr_align(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);
-#ifdef DEBUG
s->compressed_len += 10L;
-#endif
bi_flush(s);
}
s->last_eob_len = 7;
@@ -916,9 +905,10 @@ void _tr_align(s)
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file.
+ * trees or store, and output the encoded block to the zip file. This function
+ * returns the total compressed length for the file so far.
*/
-void _tr_flush_block(s, buf, stored_len, eof)
+ulg _tr_flush_block(s, buf, stored_len, eof)
deflate_state *s;
charf *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */
@@ -965,6 +955,25 @@ void _tr_flush_block(s, buf, stored_len, eof)
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
+ /* If compression failed and this is the first and last block,
+ * and if the .zip file can be seeked (to rewrite the local header),
+ * the whole file is transformed into a stored file:
+ */
+#ifdef STORED_FILE_OK
+# ifdef FORCE_STORED_FILE
+ if (eof && s->compressed_len == 0L) { /* force stored file */
+# else
+ if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
+# endif
+ /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
+ if (buf == (charf*)0) error ("block vanished");
+
+ copy_block(buf, (unsigned)stored_len, 0); /* without header */
+ s->compressed_len = stored_len << 3;
+ s->method = STORED;
+ } else
+#endif /* STORED_FILE_OK */
+
#ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */
#else
@@ -986,32 +995,25 @@ void _tr_flush_block(s, buf, stored_len, eof)
#endif
send_bits(s, (STATIC_TREES<<1)+eof, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
-#ifdef DEBUG
s->compressed_len += 3 + s->static_len;
-#endif
} else {
send_bits(s, (DYN_TREES<<1)+eof, 3);
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);
-#ifdef DEBUG
s->compressed_len += 3 + s->opt_len;
-#endif
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
- /* The above check is made mod 2^32, for files larger than 512 MB
- * and uLong implemented on 32 bits.
- */
init_block(s);
if (eof) {
bi_windup(s);
-#ifdef DEBUG
s->compressed_len += 7; /* align on byte boundary */
-#endif
}
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*eof));
+
+ return s->compressed_len >> 3;
}
/* ===========================================================================
diff --git a/lib/libz/uncompr.c b/lib/libz/uncompr.c
index d103321..b1bd9fc 100644
--- a/lib/libz/uncompr.c
+++ b/lib/libz/uncompr.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "zlib.h"
diff --git a/lib/libz/zconf.h b/lib/libz/zconf.h
index 6d450fc..5b71e4b 100644
--- a/lib/libz/zconf.h
+++ b/lib/libz/zconf.h
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#ifndef _ZCONF_H
#define _ZCONF_H
@@ -91,8 +91,8 @@
# define NO_DUMMY_DECL
#endif
-/* Old Borland C incorrectly complains about missing returns: */
-#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
+/* Borland C incorrectly complains about missing returns: */
+#if defined(__BORLANDC__)
# define NEED_DUMMY_RETURN
#endif
@@ -148,7 +148,7 @@
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
-# define FAR _far
+# define FAR __far
# else
# define FAR far
# endif
@@ -156,68 +156,42 @@
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
-# define FAR _far
+# define FAR __far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
-#if defined(ZLIB_DLL)
-# if defined(_WINDOWS) || defined(WINDOWS)
-# ifdef FAR
-# undef FAR
-# endif
-# include <windows.h>
-# define ZEXPORT WINAPI
-# ifdef WIN32
-# define ZEXPORTVA WINAPIV
-# else
-# define ZEXPORTVA FAR _cdecl _export
-# endif
+#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
+# ifdef FAR
+# undef FAR
# endif
-# if defined (__BORLANDC__)
-# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
-# include <windows.h>
-# define ZEXPORT __declspec(dllexport) WINAPI
-# define ZEXPORTRVA __declspec(dllexport) WINAPIV
-# else
-# if defined (_Windows) && defined (__DLL__)
-# define ZEXPORT _export
-# define ZEXPORTVA _export
-# endif
-# endif
-# endif
-#endif
-
-#if defined (__BEOS__)
-# if defined (ZLIB_DLL)
-# define ZEXTERN extern __declspec(dllexport)
+# include <windows.h>
+# define ZEXPORT WINAPI
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
# else
-# define ZEXTERN extern __declspec(dllimport)
+# define ZEXPORTVA FAR _cdecl _export
# endif
-#endif
-
-#ifndef ZEXPORT
-# define ZEXPORT
-#endif
-#ifndef ZEXPORTVA
-# define ZEXPORTVA
-#endif
-#ifndef ZEXTERN
-# define ZEXTERN extern
+#else
+# if defined (__BORLANDC__) && defined (_Windows) && defined (__DLL__)
+# define ZEXPORT _export
+# define ZEXPORTVA _export
+# else
+# define ZEXPORT
+# define ZEXPORTVA
+# endif
#endif
#ifndef FAR
# define FAR
#endif
-#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
-#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
-#ifdef SMALL_MEDIUM
- /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
+ /* Borland C/C++ ignores FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
@@ -243,7 +217,6 @@ typedef uLong FAR uLongf;
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
-# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c
index b3de4e8..0d12b55 100644
--- a/lib/libz/zutil.c
+++ b/lib/libz/zutil.c
@@ -3,7 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#include "zutil.h"
@@ -60,7 +60,7 @@ const char * ZEXPORT zError(err)
void zmemcpy(dest, source, len)
Bytef* dest;
- const Bytef* source;
+ Bytef* source;
uInt len;
{
if (len == 0) return;
@@ -70,8 +70,8 @@ void zmemcpy(dest, source, len)
}
int zmemcmp(s1, s2, len)
- const Bytef* s1;
- const Bytef* s2;
+ Bytef* s1;
+ Bytef* s2;
uInt len;
{
uInt j;
@@ -178,7 +178,7 @@ void zcfree (voidpf opaque, voidpf ptr)
# define MY_ZCALLOC
-#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
+#if (!defined(_MSC_VER) || (_MSC_VER < 600))
# define _halloc halloc
# define _hfree hfree
#endif
diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h
index 6f2cb97..3843e0d 100644
--- a/lib/libz/zutil.h
+++ b/lib/libz/zutil.h
@@ -8,7 +8,7 @@
subject to change. Applications should only use zlib.h.
*/
-/* @(#) $Id$ */
+/* $FreeBSD$ */
#ifndef _Z_UTIL_H
#define _Z_UTIL_H
@@ -75,7 +75,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef MSDOS
# define OS_CODE 0x00
-# if defined(__TURBOC__) || defined(__BORLANDC__)
+# ifdef __TURBOC__
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block );
@@ -112,12 +112,13 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-# include <unix.h> /* for fdopen */
-# else
-# ifndef fdopen
-# define fdopen(fd,mode) NULL /* No fdopen() */
-# endif
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
+#endif
+#if defined(__MWERKS__) && !defined(fdopen)
+# if __dest_os != __be_os && __dest_os != __win32_os
+# define fdopen(fd,mode) NULL
# endif
#endif
@@ -133,7 +134,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
-#if (defined(_MSC_VER) && (_MSC_VER > 600))
+#if (defined(_MSC_VER) && (_MSC_VER >= 600))
# define fdopen(fd,type) _fdopen(fd,type)
#endif
@@ -181,8 +182,8 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len)
# endif
#else
- extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
- extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
+ extern void zmemcpy OF((Bytef* dest, Bytef* source, uInt len));
+ extern int zmemcmp OF((Bytef* s1, Bytef* s2, uInt len));
extern void zmemzero OF((Bytef* dest, uInt len));
#endif
OpenPOWER on IntegriCloud