summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:19:55 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:19:55 -0700
commit965fe72aed580d518c979c9a33b49e7df28205f7 (patch)
treed2471c968f71224c415a9b6cb3b4ca01bd0a94ab
parentb8c9ecb0765fc39423c07613d909c5193378bdfd (diff)
downloadzlib-965fe72aed580d518c979c9a33b49e7df28205f7.tar.gz
zlib-965fe72aed580d518c979c9a33b49e7df28205f7.tar.bz2
zlib-965fe72aed580d518c979c9a33b49e7df28205f7.zip
zlib 1.1.0v1.1.0
-rw-r--r--ChangeLog11
-rw-r--r--Makefile2
-rw-r--r--Makefile.in2
-rw-r--r--README31
-rwxr-xr-xconfigure19
-rw-r--r--deflate.c93
-rw-r--r--deflate.h42
-rw-r--r--gzio.c7
-rw-r--r--inflate.c4
-rw-r--r--inftrees.c2
-rw-r--r--minigzip.c66
-rw-r--r--msdos/zlib.def2
-rw-r--r--msdos/zlib.rc6
-rw-r--r--trees.c31
-rw-r--r--trees.h4
-rw-r--r--zlib.34
-rw-r--r--zlib.h4
17 files changed, 262 insertions, 68 deletions
diff --git a/ChangeLog b/ChangeLog
index e4d8871..8160d28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,17 @@
1 1
2 ChangeLog file for zlib 2 ChangeLog file for zlib
3 3
4Changes in 1.1 (24 Feb 98)
5- do not return STREAM_END prematurely in inflate (John Bowler)
6- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
7- compile with -DFASTEST to get compression code optimized for speed only
8- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
9- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
10 on Sun but significant on HP)
11
12- add a pointer to experimental unzip library in README (Gilles Vollant)
13- initialize variable gcc in configure (Chris Herborth)
14
4Changes in 1.0.9 (17 Feb 1998) 15Changes in 1.0.9 (17 Feb 1998)
5- added gzputs and gzgets functions 16- added gzputs and gzgets functions
6- do not clear eof flag in gzseek (Mark Diekhans) 17- do not clear eof flag in gzseek (Mark Diekhans)
diff --git a/Makefile b/Makefile
index f6c3ca7..257f394 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ CFLAGS=-O
23LDFLAGS=-L. -lz 23LDFLAGS=-L. -lz
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25 25
26VER=1.0.9 26VER=1.1.0
27LIBS=libz.a 27LIBS=libz.a
28SHAREDLIB=libz.so 28SHAREDLIB=libz.so
29 29
diff --git a/Makefile.in b/Makefile.in
index f6c3ca7..257f394 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -23,7 +23,7 @@ CFLAGS=-O
23LDFLAGS=-L. -lz 23LDFLAGS=-L. -lz
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25 25
26VER=1.0.9 26VER=1.1.0
27LIBS=libz.a 27LIBS=libz.a
28SHAREDLIB=libz.so 28SHAREDLIB=libz.so
29 29
diff --git a/README b/README
index c1d217f..5aacb53 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
1zlib 1.0.9 is a general purpose data compression library. All the code 1zlib 1.1.0 is a general purpose data compression library. All the code
2is thread safe. The data format used by the zlib library 2is thread safe. The data format used by the zlib library
3is described by RFCs (Request for Comments) 1950 to 1952 in the files 3is described by RFCs (Request for Comments) 1950 to 1952 in the files
4ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate 4ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
@@ -25,21 +25,15 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of
25Dr. Dobb's Journal; a copy of the article is available in 25Dr. Dobb's Journal; a copy of the article is available in
26http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm 26http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
27 27
28The changes made in version 1.0.9 are documented in the file ChangeLog. 28The changes made in version 1.1.0 are documented in the file ChangeLog.
29The main changes since 1.0.8 are: 29The main changes since 1.0.9 are:
30 30
31- added gzputs and gzgets functions 31- do not return STREAM_END prematurely in inflate (John Bowler)
32- do not clear eof flag in gzseek (Mark Diekhans) 32- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
33- fix gzseek for files in transparent mode (Mark Diekhans) 33- compile with -DFASTEST to get compression code optimized for speed only
34- do not assume that vsprintf returns the number of bytes written (Jens Krinke) 34- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
35- replace EXPORT with ZEXPORT to avoid conflict with other programs 35- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
36- added compress2 in zconf.h, zlib.def, zlib.dnt 36 on Sun but significant on HP)
37- new asm code from Gilles Vollant in contrib/asm386
38- simplify the inflate code (Mark):
39 . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
40 . ZALLOC the length list in inflate_trees_fixed() instead of using stack
41 . ZALLOC the value area for huft_build() instead of using stack
42 . Simplify Z_FINISH check in inflate()
43 37
44 38
45Unsupported third party contributions are provided in directory "contrib". 39Unsupported third party contributions are provided in directory "contrib".
@@ -56,6 +50,11 @@ A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
56is available from the Python Software Association sites, such as: 50is available from the Python Software Association sites, such as:
57ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz 51ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
58 52
53An experimental package to read files in .zip format, written on top of
54zlib by Gilles Vollant <info@winimage.com>, is available at
55http://www.winimage.com/zLibDll/unzip.html
56
57
59Notes for some targets: 58Notes for some targets:
60 59
61- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc 60- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
@@ -83,7 +82,7 @@ Notes for some targets:
83 writes to pointers are atomic. Also the functions zalloc and zfree passed 82 writes to pointers are atomic. Also the functions zalloc and zfree passed
84 to deflateInit must be multi-threaded in this case. 83 to deflateInit must be multi-threaded in this case.
85 84
86- gzdopen is not supported on RISCOS, BEOS and Mac 85- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
87 86
88- For Turbo C the small model is supported only with reduced performance to 87- For Turbo C the small model is supported only with reduced performance to
89 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 88 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
diff --git a/configure b/configure
index bde53b1..43fc26b 100755
--- a/configure
+++ b/configure
@@ -27,6 +27,7 @@ prefix=${prefix-/usr/local}
27exec_prefix=${exec_prefix-$prefix} 27exec_prefix=${exec_prefix-$prefix}
28shared_ext='.so' 28shared_ext='.so'
29shared=0 29shared=0
30gcc=0
30old_cc="$CC" 31old_cc="$CC"
31old_cflags="$CFLAGS" 32old_cflags="$CFLAGS"
32 33
@@ -114,7 +115,6 @@ if test $shared -eq 0; then
114 LDSHARED="$CC" 115 LDSHARED="$CC"
115 echo Building static library $LIBS version $VER with $CC. 116 echo Building static library $LIBS version $VER with $CC.
116fi 117fi
117rm -f $test.[co] $test$shared_ext
118 118
119if test -f /usr/include/unistd.h; then 119if test -f /usr/include/unistd.h; then
120 CFLAGS="$CFLAGS -DHAVE_UNISTD_H" 120 CFLAGS="$CFLAGS -DHAVE_UNISTD_H"
@@ -124,6 +124,23 @@ if test ! -f /usr/include/errno.h; then
124 CFLAGS="$CFLAGS -DNO_ERRNO_H" 124 CFLAGS="$CFLAGS -DNO_ERRNO_H"
125fi 125fi
126 126
127cat > $test.c <<EOF
128#include <sys/types.h>
129#include <sys/mman.h>
130#include <sys/stat.h>
131caddr_t hello() {
132 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
133}
134EOF
135if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
136 CFLAGS="$CFLAGS -DUSE_MMAP"
137 echo Checking for mmap support... Yes.
138else
139 echo Checking for mmap support... No.
140fi
141
142rm -f $test.[co] $test$shared_ext
143
127# udpate Makefile 144# udpate Makefile
128sed < Makefile.in " 145sed < Makefile.in "
129/^CC *=/s%=.*%=$CC% 146/^CC *=/s%=.*%=$CC%
diff --git a/deflate.c b/deflate.c
index e9c14d7..dc60299 100644
--- a/deflate.c
+++ b/deflate.c
@@ -52,7 +52,7 @@
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.0.9 Copyright 1995-1998 Jean-loup Gailly "; 55 " deflate 1.1.0 Copyright 1995-1998 Jean-loup Gailly ";
56/* 56/*
57 If you use the zlib library in a product, an acknowledgment is welcome 57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot 58 in the documentation of your product. If for some reason you cannot
@@ -160,14 +160,23 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
160 * Insert string str in the dictionary and set match_head to the previous head 160 * Insert string str in the dictionary and set match_head to the previous head
161 * of the hash chain (the most recent string with same hash key). Return 161 * of the hash chain (the most recent string with same hash key). Return
162 * the previous length of the hash chain. 162 * the previous length of the hash chain.
163 * If this file is compiled with -DFASTEST, the compression level is forced
164 * to 1, and no hash chains are maintained.
163 * IN assertion: all calls to to INSERT_STRING are made with consecutive 165 * IN assertion: all calls to to INSERT_STRING are made with consecutive
164 * input characters and the first MIN_MATCH bytes of str are valid 166 * input characters and the first MIN_MATCH bytes of str are valid
165 * (except for the last MIN_MATCH-1 bytes of the input file). 167 * (except for the last MIN_MATCH-1 bytes of the input file).
166 */ 168 */
169#ifdef FASTEST
170#define INSERT_STRING(s, str, match_head) \
171 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
172 match_head = s->head[s->ins_h], \
173 s->head[s->ins_h] = (Pos)(str))
174#else
167#define INSERT_STRING(s, str, match_head) \ 175#define INSERT_STRING(s, str, match_head) \
168 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ 176 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
169 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ 177 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
170 s->head[s->ins_h] = (Pos)(str)) 178 s->head[s->ins_h] = (Pos)(str))
179#endif
171 180
172/* =========================================================================== 181/* ===========================================================================
173 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 182 * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
@@ -224,6 +233,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
224 if (strm->zfree == Z_NULL) strm->zfree = zcfree; 233 if (strm->zfree == Z_NULL) strm->zfree = zcfree;
225 234
226 if (level == Z_DEFAULT_COMPRESSION) level = 6; 235 if (level == Z_DEFAULT_COMPRESSION) level = 6;
236#ifdef FASTEST
237 level = 1;
238#endif
227 239
228 if (windowBits < 0) { /* undocumented feature: suppress zlib header */ 240 if (windowBits < 0) { /* undocumented feature: suppress zlib header */
229 noheader = 1; 241 noheader = 1;
@@ -708,6 +720,7 @@ local void lm_init (s)
708/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 720/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
709 * match.S. The code will be functionally equivalent. 721 * match.S. The code will be functionally equivalent.
710 */ 722 */
723#ifndef FASTEST
711local uInt longest_match(s, cur_match) 724local uInt longest_match(s, cur_match)
712 deflate_state *s; 725 deflate_state *s;
713 IPos cur_match; /* current match */ 726 IPos cur_match; /* current match */
@@ -845,6 +858,64 @@ local uInt longest_match(s, cur_match)
845 if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 858 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
846 return s->lookahead; 859 return s->lookahead;
847} 860}
861
862#else /* FASTEST */
863/* ---------------------------------------------------------------------------
864 * Optimized version for level == 1 only
865 */
866local uInt longest_match(s, cur_match)
867 deflate_state *s;
868 IPos cur_match; /* current match */
869{
870 register Bytef *scan = s->window + s->strstart; /* current string */
871 register Bytef *match; /* matched string */
872 register int len; /* length of current match */
873 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
874
875 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
876 * It is easy to get rid of this optimization if necessary.
877 */
878 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
879
880 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
881
882 Assert(cur_match < s->strstart, "no future");
883
884 match = s->window + cur_match;
885
886 /* Return failure if the match length is less than 2:
887 */
888 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
889
890 /* The check at best_len-1 can be removed because it will be made
891 * again later. (This heuristic is not always a win.)
892 * It is not necessary to compare scan[2] and match[2] since they
893 * are always equal when the other bytes match, given that
894 * the hash keys are equal and that HASH_BITS >= 8.
895 */
896 scan += 2, match += 2;
897 Assert(*scan == *match, "match[2]?");
898
899 /* We check for insufficient lookahead only every 8th comparison;
900 * the 256th check will be made at strstart+258.
901 */
902 do {
903 } while (*++scan == *++match && *++scan == *++match &&
904 *++scan == *++match && *++scan == *++match &&
905 *++scan == *++match && *++scan == *++match &&
906 *++scan == *++match && *++scan == *++match &&
907 scan < strend);
908
909 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
910
911 len = MAX_MATCH - (int)(strend - scan);
912
913 if (len < MIN_MATCH) return MIN_MATCH - 1;
914
915 s->match_start = cur_match;
916 return len <= s->lookahead ? len : s->lookahead;
917}
918#endif /* FASTEST */
848#endif /* ASMV */ 919#endif /* ASMV */
849 920
850#ifdef DEBUG 921#ifdef DEBUG
@@ -930,6 +1001,7 @@ local void fill_window(s)
930 } while (--n); 1001 } while (--n);
931 1002
932 n = wsize; 1003 n = wsize;
1004#ifndef FASTEST
933 p = &s->prev[n]; 1005 p = &s->prev[n];
934 do { 1006 do {
935 m = *--p; 1007 m = *--p;
@@ -938,6 +1010,7 @@ local void fill_window(s)
938 * its value will never be used. 1010 * its value will never be used.
939 */ 1011 */
940 } while (--n); 1012 } while (--n);
1013#endif
941 more += wsize; 1014 more += wsize;
942 } 1015 }
943 if (s->strm->avail_in == 0) return; 1016 if (s->strm->avail_in == 0) return;
@@ -1105,14 +1178,15 @@ local block_state deflate_fast(s, flush)
1105 if (s->match_length >= MIN_MATCH) { 1178 if (s->match_length >= MIN_MATCH) {
1106 check_match(s, s->strstart, s->match_start, s->match_length); 1179 check_match(s, s->strstart, s->match_start, s->match_length);
1107 1180
1108 bflush = _tr_tally(s, s->strstart - s->match_start, 1181 _tr_tally_dist(s, s->strstart - s->match_start,
1109 s->match_length - MIN_MATCH); 1182 s->match_length - MIN_MATCH, bflush);
1110 1183
1111 s->lookahead -= s->match_length; 1184 s->lookahead -= s->match_length;
1112 1185
1113 /* Insert new strings in the hash table only if the match length 1186 /* Insert new strings in the hash table only if the match length
1114 * is not too large. This saves time but degrades compression. 1187 * is not too large. This saves time but degrades compression.
1115 */ 1188 */
1189#ifndef FASTEST
1116 if (s->match_length <= s->max_insert_length && 1190 if (s->match_length <= s->max_insert_length &&
1117 s->lookahead >= MIN_MATCH) { 1191 s->lookahead >= MIN_MATCH) {
1118 s->match_length--; /* string at strstart already in hash table */ 1192 s->match_length--; /* string at strstart already in hash table */
@@ -1124,7 +1198,9 @@ local block_state deflate_fast(s, flush)
1124 */ 1198 */
1125 } while (--s->match_length != 0); 1199 } while (--s->match_length != 0);
1126 s->strstart++; 1200 s->strstart++;
1127 } else { 1201 } else
1202#endif
1203 {
1128 s->strstart += s->match_length; 1204 s->strstart += s->match_length;
1129 s->match_length = 0; 1205 s->match_length = 0;
1130 s->ins_h = s->window[s->strstart]; 1206 s->ins_h = s->window[s->strstart];
@@ -1139,7 +1215,7 @@ local block_state deflate_fast(s, flush)
1139 } else { 1215 } else {
1140 /* No match, output a literal byte */ 1216 /* No match, output a literal byte */
1141 Tracevv((stderr,"%c", s->window[s->strstart])); 1217 Tracevv((stderr,"%c", s->window[s->strstart]));
1142 bflush = _tr_tally (s, 0, s->window[s->strstart]); 1218 _tr_tally_lit (s, s->window[s->strstart], bflush);
1143 s->lookahead--; 1219 s->lookahead--;
1144 s->strstart++; 1220 s->strstart++;
1145 } 1221 }
@@ -1219,7 +1295,7 @@ local block_state deflate_slow(s, flush)
1219 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1295 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1220 1296
1221 bflush = _tr_tally(s, s->strstart -1 - s->prev_match, 1297 bflush = _tr_tally(s, s->strstart -1 - s->prev_match,
1222 s->prev_length - MIN_MATCH); 1298 s->prev_length - MIN_MATCH);
1223 1299
1224 /* Insert in hash table all strings up to the end of the match. 1300 /* Insert in hash table all strings up to the end of the match.
1225 * strstart-1 and strstart are already inserted. If there is not 1301 * strstart-1 and strstart are already inserted. If there is not
@@ -1245,7 +1321,8 @@ local block_state deflate_slow(s, flush)
1245 * is longer, truncate the previous match to a single literal. 1321 * is longer, truncate the previous match to a single literal.
1246 */ 1322 */
1247 Tracevv((stderr,"%c", s->window[s->strstart-1])); 1323 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1248 if (_tr_tally (s, 0, s->window[s->strstart-1])) { 1324 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1325 if (bflush) {
1249 FLUSH_BLOCK_ONLY(s, 0); 1326 FLUSH_BLOCK_ONLY(s, 0);
1250 } 1327 }
1251 s->strstart++; 1328 s->strstart++;
@@ -1263,7 +1340,7 @@ local block_state deflate_slow(s, flush)
1263 Assert (flush != Z_NO_FLUSH, "no flush?"); 1340 Assert (flush != Z_NO_FLUSH, "no flush?");
1264 if (s->match_available) { 1341 if (s->match_available) {
1265 Tracevv((stderr,"%c", s->window[s->strstart-1])); 1342 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1266 _tr_tally (s, 0, s->window[s->strstart-1]); 1343 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1267 s->match_available = 0; 1344 s->match_available = 0;
1268 } 1345 }
1269 FLUSH_BLOCK(s, flush == Z_FINISH); 1346 FLUSH_BLOCK(s, flush == Z_FINISH);
diff --git a/deflate.h b/deflate.h
index 07272d1..34f5126 100644
--- a/deflate.h
+++ b/deflate.h
@@ -273,4 +273,46 @@ ulg _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
273void _tr_align OF((deflate_state *s)); 273void _tr_align OF((deflate_state *s));
274void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, 274void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
275 int eof)); 275 int eof));
276
277#define d_code(dist) \
278 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
279/* Mapping from a distance to a distance code. dist is the distance - 1 and
280 * must not have side effects. _dist_code[256] and _dist_code[257] are never
281 * used.
282 */
283
284#ifndef DEBUG
285/* Inline versions of _tr_tally for speed: */
286
287#if defined(GEN_TREES_H) || !defined(STDC)
288 extern uch _length_code[];
289 extern uch _dist_code[];
290#else
291 extern const uch _length_code[];
292 extern const uch _dist_code[];
293#endif
294
295# define _tr_tally_lit(s, c, flush) \
296 { uch cc = (c); \
297 s->d_buf[s->last_lit] = 0; \
298 s->l_buf[s->last_lit++] = cc; \
299 s->dyn_ltree[cc].Freq++; \
300 flush = (s->last_lit == s->lit_bufsize-1); \
301 }
302# define _tr_tally_dist(s, distance, length, flush) \
303 { uch len = (length); \
304 ush dist = (distance); \
305 s->d_buf[s->last_lit] = dist; \
306 s->l_buf[s->last_lit++] = len; \
307 dist--; \
308 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
309 s->dyn_dtree[d_code(dist)].Freq++; \
310 flush = (s->last_lit == s->lit_bufsize-1); \
311 }
312#else
313# define _tr_tally_lit(s, c, flush) _tr_tally(s, 0, c, flush)
314# define _tr_tally_dist(s, distance, length, flush) \
315 _tr_tally(s, distance, length, flush)
316#endif
317
276#endif 318#endif
diff --git a/gzio.c b/gzio.c
index b816494..bd66085 100644
--- a/gzio.c
+++ b/gzio.c
@@ -13,7 +13,8 @@
13 13
14struct internal_state {int dummy;}; /* for buggy compilers */ 14struct internal_state {int dummy;}; /* for buggy compilers */
15 15
16#define Z_BUFSIZE 4096 16#define Z_BUFSIZE 16384
17#define Z_PRINTF_BUFSIZE 4096
17 18
18#define ALLOC(size) malloc(size) 19#define ALLOC(size) malloc(size)
19#define TRYFREE(p) {if (p) free(p);} 20#define TRYFREE(p) {if (p) free(p);}
@@ -506,7 +507,7 @@ int ZEXPORT gzwrite (file, buf, len)
506 507
507int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) 508int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
508{ 509{
509 char buf[Z_BUFSIZE]; 510 char buf[Z_PRINTF_BUFSIZE];
510 va_list va; 511 va_list va;
511 int len; 512 int len;
512 513
@@ -531,7 +532,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
531 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 532 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
532 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; 533 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
533{ 534{
534 char buf[Z_BUFSIZE]; 535 char buf[Z_PRINTF_BUFSIZE];
535 int len; 536 int len;
536 537
537#ifdef HAS_snprintf 538#ifdef HAS_snprintf
diff --git a/inflate.c b/inflate.c
index 7b9bc3b..32e9b8d 100644
--- a/inflate.c
+++ b/inflate.c
@@ -229,6 +229,7 @@ int f;
229 r = f; 229 r = f;
230 if (r != Z_STREAM_END) 230 if (r != Z_STREAM_END)
231 return r; 231 return r;
232 r = f;
232 inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); 233 inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
233 if (z->state->nowrap) 234 if (z->state->nowrap)
234 { 235 {
@@ -322,7 +323,8 @@ z_streamp z;
322 /* search */ 323 /* search */
323 while (n && m < 4) 324 while (n && m < 4)
324 { 325 {
325 if (*p == (Byte)(m < 2 ? 0 : (Byte)0xff)) 326 static const Byte mark[4] = {0, 0, 0xff, 0xff};
327 if (*p == mark[m])
326 m++; 328 m++;
327 else if (*p) 329 else if (*p)
328 m = 0; 330 m = 0;
diff --git a/inftrees.c b/inftrees.c
index 282f277..205ddc5 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -7,7 +7,7 @@
7#include "inftrees.h" 7#include "inftrees.h"
8 8
9const char inflate_copyright[] = 9const char inflate_copyright[] =
10 " inflate 1.0.9 Copyright 1995-1998 Mark Adler "; 10 " inflate 1.1.0 Copyright 1995-1998 Mark Adler ";
11/* 11/*
12 If you use the zlib library in a product, an acknowledgment is welcome 12 If you use the zlib library in a product, an acknowledgment is welcome
13 in the documentation of your product. If for some reason you cannot 13 in the documentation of your product. If for some reason you cannot
diff --git a/minigzip.c b/minigzip.c
index 14d1277..c05d0ea 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -25,6 +25,11 @@
25 extern void exit OF((int)); 25 extern void exit OF((int));
26#endif 26#endif
27 27
28#ifdef USE_MMAP
29# include <sys/types.h>
30# include <sys/mman.h>
31# include <sys/stat.h>
32#endif
28 33
29#if defined(MSDOS) || defined(OS2) || defined(WIN32) 34#if defined(MSDOS) || defined(OS2) || defined(WIN32)
30# include <fcntl.h> 35# include <fcntl.h>
@@ -53,7 +58,7 @@
53#endif 58#endif
54#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) 59#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
55 60
56#define BUFLEN 4096 61#define BUFLEN 16384
57#define MAX_NAME_LEN 1024 62#define MAX_NAME_LEN 1024
58 63
59#ifdef MAXSEG_64K 64#ifdef MAXSEG_64K
@@ -65,12 +70,15 @@
65 70
66char *prog; 71char *prog;
67 72
68void error OF((const char *msg)); 73void error OF((const char *msg));
69void gz_compress OF((FILE *in, gzFile out)); 74void gz_compress OF((FILE *in, gzFile out));
70void gz_uncompress OF((gzFile in, FILE *out)); 75#ifdef USE_MMAP
71void file_compress OF((char *file, char *mode)); 76int gz_compress_mmap OF((FILE *in, gzFile out));
72void file_uncompress OF((char *file)); 77#endif
73int main OF((int argc, char *argv[])); 78void gz_uncompress OF((gzFile in, FILE *out));
79void file_compress OF((char *file, char *mode));
80void file_uncompress OF((char *file));
81int main OF((int argc, char *argv[]));
74 82
75/* =========================================================================== 83/* ===========================================================================
76 * Display error message and exit 84 * Display error message and exit
@@ -85,6 +93,7 @@ void error(msg)
85/* =========================================================================== 93/* ===========================================================================
86 * Compress input to output then close both files. 94 * Compress input to output then close both files.
87 */ 95 */
96
88void gz_compress(in, out) 97void gz_compress(in, out)
89 FILE *in; 98 FILE *in;
90 gzFile out; 99 gzFile out;
@@ -93,6 +102,12 @@ void gz_compress(in, out)
93 int len; 102 int len;
94 int err; 103 int err;
95 104
105#ifdef USE_MMAP
106 /* Try first compressing with mmap. If mmap fails (minigzip used in a
107 * pipe), use the normal fread loop.
108 */
109 if (gz_compress_mmap(in, out) == Z_OK) return;
110#endif
96 for (;;) { 111 for (;;) {
97 len = fread(buf, 1, sizeof(buf), in); 112 len = fread(buf, 1, sizeof(buf), in);
98 if (ferror(in)) { 113 if (ferror(in)) {
@@ -107,6 +122,43 @@ void gz_compress(in, out)
107 if (gzclose(out) != Z_OK) error("failed gzclose"); 122 if (gzclose(out) != Z_OK) error("failed gzclose");
108} 123}
109 124
125#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
126
127/* Try compressing the input file at once using mmap. Return Z_OK if
128 * if success, Z_ERRNO otherwise.
129 */
130int gz_compress_mmap(in, out)
131 FILE *in;
132 gzFile out;
133{
134 int len;
135 int err;
136 int ifd = fileno(in);
137 caddr_t buf; /* mmap'ed buffer for the entire input file */
138 off_t buf_len; /* length of the input file */
139 struct stat sb;
140
141 /* Determine the size of the file, needed for mmap: */
142 if (fstat(ifd, &sb) < 0) return Z_ERRNO;
143 buf_len = sb.st_size;
144 if (buf_len <= 0) return Z_ERRNO;
145
146 /* Now do the actual mmap: */
147 buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
148 if (buf == (caddr_t)(-1)) return Z_ERRNO;
149
150 /* Compress the whole file at once: */
151 len = gzwrite(out, (char *)buf, (unsigned)buf_len);
152
153 if (len != (int)buf_len) error(gzerror(out, &err));
154
155 munmap(buf, buf_len);
156 fclose(in);
157 if (gzclose(out) != Z_OK) error("failed gzclose");
158 return Z_OK;
159}
160#endif /* USE_MMAP */
161
110/* =========================================================================== 162/* ===========================================================================
111 * Uncompress input to output then close both files. 163 * Uncompress input to output then close both files.
112 */ 164 */
diff --git a/msdos/zlib.def b/msdos/zlib.def
index 89e626c..2372ab1 100644
--- a/msdos/zlib.def
+++ b/msdos/zlib.def
@@ -8,7 +8,7 @@ SUBSYSTEM WINDOWS
8 8
9STUB 'WINSTUB.EXE' 9STUB 'WINSTUB.EXE'
10 10
11VERSION 1.09 11VERSION 1.1
12 12
13CODE EXECUTE READ 13CODE EXECUTE READ
14 14
diff --git a/msdos/zlib.rc b/msdos/zlib.rc
index 86690ec..76e0ec2 100644
--- a/msdos/zlib.rc
+++ b/msdos/zlib.rc
@@ -2,8 +2,8 @@
2 2
3#define IDR_VERSION1 1 3#define IDR_VERSION1 1
4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1,0,9,0 5 FILEVERSION 1,1,0,0
6 PRODUCTVERSION 1,0,9,0 6 PRODUCTVERSION 1,1,0,0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0 8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32 9 FILEOS VOS_DOS_WINDOWS32
@@ -17,7 +17,7 @@ BEGIN
17 17
18 BEGIN 18 BEGIN
19 VALUE "FileDescription", "zlib data compression library\0" 19 VALUE "FileDescription", "zlib data compression library\0"
20 VALUE "FileVersion", "1.0.9\0" 20 VALUE "FileVersion", "1.1.0\0"
21 VALUE "InternalName", "zlib\0" 21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlib.dll\0" 22 VALUE "OriginalFilename", "zlib.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0" 23 VALUE "ProductName", "ZLib.DLL\0"
diff --git a/trees.c b/trees.c
index e2c230f..e09e94c 100644
--- a/trees.c
+++ b/trees.c
@@ -99,13 +99,13 @@ local ct_data static_dtree[D_CODES];
99 * 5 bits.) 99 * 5 bits.)
100 */ 100 */
101 101
102local uch dist_code[DIST_CODE_LEN]; 102uch _dist_code[DIST_CODE_LEN];
103/* Distance codes. The first 256 values correspond to the distances 103/* Distance codes. The first 256 values correspond to the distances
104 * 3 .. 258, the last 256 values correspond to the top 8 bits of 104 * 3 .. 258, the last 256 values correspond to the top 8 bits of
105 * the 15 bit distances. 105 * the 15 bit distances.
106 */ 106 */
107 107
108local uch length_code[MAX_MATCH-MIN_MATCH+1]; 108uch _length_code[MAX_MATCH-MIN_MATCH+1];
109/* length code for each normalized match length (0 == MIN_MATCH) */ 109/* length code for each normalized match length (0 == MIN_MATCH) */
110 110
111local int base_length[LENGTH_CODES]; 111local int base_length[LENGTH_CODES];
@@ -173,13 +173,6 @@ local void gen_trees_header OF((void));
173 send_bits(s, tree[c].Code, tree[c].Len); } 173 send_bits(s, tree[c].Code, tree[c].Len); }
174#endif 174#endif
175 175
176#define d_code(dist) \
177 ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)])
178/* Mapping from a distance to a distance code. dist is the distance - 1 and
179 * must not have side effects. dist_code[256] and dist_code[257] are never
180 * used.
181 */
182
183/* =========================================================================== 176/* ===========================================================================
184 * Output a short LSB first on the stream. 177 * Output a short LSB first on the stream.
185 * IN assertion: there is enough room in pendingBuf. 178 * IN assertion: there is enough room in pendingBuf.
@@ -262,7 +255,7 @@ local void tr_static_init()
262 for (code = 0; code < LENGTH_CODES-1; code++) { 255 for (code = 0; code < LENGTH_CODES-1; code++) {
263 base_length[code] = length; 256 base_length[code] = length;
264 for (n = 0; n < (1<<extra_lbits[code]); n++) { 257 for (n = 0; n < (1<<extra_lbits[code]); n++) {
265 length_code[length++] = (uch)code; 258 _length_code[length++] = (uch)code;
266 } 259 }
267 } 260 }
268 Assert (length == 256, "tr_static_init: length != 256"); 261 Assert (length == 256, "tr_static_init: length != 256");
@@ -270,14 +263,14 @@ local void tr_static_init()
270 * in two different ways: code 284 + 5 bits or code 285, so we 263 * in two different ways: code 284 + 5 bits or code 285, so we
271 * overwrite length_code[255] to use the best encoding: 264 * overwrite length_code[255] to use the best encoding:
272 */ 265 */
273 length_code[length-1] = (uch)code; 266 _length_code[length-1] = (uch)code;
274 267
275 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ 268 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
276 dist = 0; 269 dist = 0;
277 for (code = 0 ; code < 16; code++) { 270 for (code = 0 ; code < 16; code++) {
278 base_dist[code] = dist; 271 base_dist[code] = dist;
279 for (n = 0; n < (1<<extra_dbits[code]); n++) { 272 for (n = 0; n < (1<<extra_dbits[code]); n++) {
280 dist_code[dist++] = (uch)code; 273 _dist_code[dist++] = (uch)code;
281 } 274 }
282 } 275 }
283 Assert (dist == 256, "tr_static_init: dist != 256"); 276 Assert (dist == 256, "tr_static_init: dist != 256");
@@ -285,7 +278,7 @@ local void tr_static_init()
285 for ( ; code < D_CODES; code++) { 278 for ( ; code < D_CODES; code++) {
286 base_dist[code] = dist << 7; 279 base_dist[code] = dist << 7;
287 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { 280 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
288 dist_code[256 + dist++] = (uch)code; 281 _dist_code[256 + dist++] = (uch)code;
289 } 282 }
290 } 283 }
291 Assert (dist == 256, "tr_static_init: 256+dist != 512"); 284 Assert (dist == 256, "tr_static_init: 256+dist != 512");
@@ -349,15 +342,15 @@ void gen_trees_header()
349 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); 342 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
350 } 343 }
351 344
352 fprintf(header, "local const uch dist_code[DIST_CODE_LEN] = {\n"); 345 fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
353 for (i = 0; i < DIST_CODE_LEN; i++) { 346 for (i = 0; i < DIST_CODE_LEN; i++) {
354 fprintf(header, "%2u%s", dist_code[i], 347 fprintf(header, "%2u%s", _dist_code[i],
355 SEPARATOR(i, DIST_CODE_LEN-1, 20)); 348 SEPARATOR(i, DIST_CODE_LEN-1, 20));
356 } 349 }
357 350
358 fprintf(header, "local const uch length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); 351 fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
359 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { 352 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
360 fprintf(header, "%2u%s", length_code[i], 353 fprintf(header, "%2u%s", _length_code[i],
361 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); 354 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
362 } 355 }
363 356
@@ -1045,7 +1038,7 @@ int _tr_tally (s, dist, lc)
1045 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && 1038 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1046 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); 1039 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1047 1040
1048 s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; 1041 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1049 s->dyn_dtree[d_code(dist)].Freq++; 1042 s->dyn_dtree[d_code(dist)].Freq++;
1050 } 1043 }
1051 1044
@@ -1094,7 +1087,7 @@ local void compress_block(s, ltree, dtree)
1094 Tracecv(isgraph(lc), (stderr," '%c' ", lc)); 1087 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1095 } else { 1088 } else {
1096 /* Here, lc is the match length - MIN_MATCH */ 1089 /* Here, lc is the match length - MIN_MATCH */
1097 code = length_code[lc]; 1090 code = _length_code[lc];
1098 send_code(s, code+LITERALS+1, ltree); /* send the length code */ 1091 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1099 extra = extra_lbits[code]; 1092 extra = extra_lbits[code];
1100 if (extra != 0) { 1093 if (extra != 0) {
diff --git a/trees.h b/trees.h
index 45f9dd3..72facf9 100644
--- a/trees.h
+++ b/trees.h
@@ -70,7 +70,7 @@ local const ct_data static_dtree[D_CODES] = {
70{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 70{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
71}; 71};
72 72
73local const uch dist_code[DIST_CODE_LEN] = { 73const uch _dist_code[DIST_CODE_LEN] = {
74 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 74 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
75 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 75 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
7610, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 7610, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
@@ -99,7 +99,7 @@ local const uch dist_code[DIST_CODE_LEN] = {
9929, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 9929, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
100}; 100};
101 101
102local const uch length_code[MAX_MATCH-MIN_MATCH+1]= { 102const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
103 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 103 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
10413, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 10413, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
10517, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 10517, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
diff --git a/zlib.3 b/zlib.3
index a969834..ccde8f2 100644
--- a/zlib.3
+++ b/zlib.3
@@ -1,4 +1,4 @@
1.TH ZLIB 3 "16 February 1998" 1.TH ZLIB 3 "24 February 1998"
2.SH NAME 2.SH NAME
3zlib \- compression/decompression library 3zlib \- compression/decompression library
4.SH SYNOPSIS 4.SH SYNOPSIS
@@ -81,7 +81,7 @@ These documents are also available in other formats from:
81.IP 81.IP
82ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html 82ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
83.SH AUTHORS 83.SH AUTHORS
84Version 1.0.9. 84Version 1.1.0
85Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org) 85Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org)
86and Mark Adler (madler@alumni.caltech.edu). 86and Mark Adler (madler@alumni.caltech.edu).
87.LP 87.LP
diff --git a/zlib.h b/zlib.h
index 5bcbf12..135c2bd 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.0.9, Feb 16th, 1998 2 version 1.1.0, Feb 24th, 1998
3 3
4 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
5 5
@@ -37,7 +37,7 @@ extern "C" {
37 37
38#include "zconf.h" 38#include "zconf.h"
39 39
40#define ZLIB_VERSION "1.0.9" 40#define ZLIB_VERSION "1.1.0"
41 41
42/* 42/*
43 The 'zlib' compression library provides in-memory compression and 43 The 'zlib' compression library provides in-memory compression and