summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt58
-rw-r--r--ChangeLog22
-rw-r--r--Makefile8
-rw-r--r--Makefile.in8
-rw-r--r--README4
-rw-r--r--as400/zlib.inc6
-rwxr-xr-xconfigure25
-rw-r--r--contrib/infback9/inftree9.c6
-rw-r--r--contrib/minizip/make_vms.com25
-rw-r--r--contrib/vstudio/vc7/zlib.rc8
-rw-r--r--deflate.c2
-rw-r--r--examples/README.examples6
-rw-r--r--examples/gun.c44
-rw-r--r--examples/pigz.c452
-rw-r--r--gzguts.h18
-rw-r--r--gzio.c2
-rw-r--r--gzlib.c69
-rw-r--r--gzread.c48
-rw-r--r--gzwrite.c36
-rw-r--r--inflate.c4
-rw-r--r--inftrees.c4
-rw-r--r--make_vms.com385
-rw-r--r--old/zlib.html971
-rw-r--r--qnx/package.qpg10
-rw-r--r--uncompr.c4
-rw-r--r--zconf.h26
-rw-r--r--zlib.37
-rw-r--r--zlib.h887
-rw-r--r--zlib.map10
-rw-r--r--zutil.c8
-rw-r--r--zutil.h8
31 files changed, 1061 insertions, 2110 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19deaa5..5ce81be 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,6 @@ check_include_file(stddef.h HAVE_STDDEF_H)
21# Check to see if we have large file support 21# Check to see if we have large file support
22# 22#
23set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE) 23set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
24
25# We add these other definitions here because CheckTypeSize.cmake 24# We add these other definitions here because CheckTypeSize.cmake
26# in CMake 2.4.x does not automatically do so and we want 25# in CMake 2.4.x does not automatically do so and we want
27# compatibility with CMake 2.4.x. 26# compatibility with CMake 2.4.x.
@@ -34,9 +33,7 @@ endif()
34if(HAVE_STDDEF_H) 33if(HAVE_STDDEF_H)
35 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) 34 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
36endif() 35endif()
37
38check_type_size(off64_t OFF64_T) 36check_type_size(off64_t OFF64_T)
39
40if(HAVE_OFF64_T) 37if(HAVE_OFF64_T)
41 add_definitions(-D_LARGEFILE64_SOURCE) 38 add_definitions(-D_LARGEFILE64_SOURCE)
42endif() 39endif()
@@ -63,23 +60,6 @@ if(NOT HAVE_ERRNO_H)
63endif() 60endif()
64 61
65# 62#
66# Check for mmap support
67#
68set(mmap_test_code "
69#include <sys/types.h>
70#include <sys/mman.h>
71#include <sys/stat.h>
72caddr_t hello() {
73 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
74}
75int main() { return 0; }
76")
77check_c_source_compiles("${mmap_test_code}" USE_MMAP)
78if(USE_MMAP)
79 add_definitions(-DUSE_MMAP)
80endif()
81
82#
83# Create the zlibdefs.h file. 63# Create the zlibdefs.h file.
84# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead 64# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead
85# of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h 65# of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h
@@ -88,7 +68,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein
88 ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h) 68 ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h)
89 69
90if(MSVC) 70if(MSVC)
91 set(CMAKE_DEBUG_POSTFIX "D") 71 set(CMAKE_DEBUG_POSTFIX "d")
92 add_definitions(-D_CRT_SECURE_NO_DEPRECATE) 72 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
93 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) 73 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
94endif() 74endif()
@@ -130,15 +110,47 @@ set(ZLIB_SRCS
130 trees.c 110 trees.c
131 uncompr.c 111 uncompr.c
132 zutil.c 112 zutil.c
113 win32/zlib1.rc
133) 114)
134 115
116# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
117file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
118string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
119 "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
120
121if(MINGW)
122 # This gets us DLL resource information when compiling on MinGW.
123 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
124 COMMAND windres.exe
125 -D GCC_WINDRES
126 -I ${CMAKE_CURRENT_SOURCE_DIR}
127 -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
128 -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
129 set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
130endif(MINGW)
131
135add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 132add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
136set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) 133set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
137set_target_properties(zlib PROPERTIES VERSION 1.2.3.4) 134
138set_target_properties(zlib PROPERTIES SOVERSION 1) 135set_target_properties(zlib PROPERTIES SOVERSION 1)
136
137if(NOT CYGWIN)
138 # This property causes shared libraries on Linux to have the full version
139 # encoded into their final filename. We disable this on Cygwin because
140 # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
141 # seems to be the default.
142 #
143 # This has no effect with MSVC, on that platform the version info for
144 # the DLL comes from the resource file win32/zlib1.rc
145 set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
146endif()
147
139if(UNIX) 148if(UNIX)
140 # On unix like platforms the library is almost always called libz 149 # On unix-like platforms the library is almost always called libz
141 set_target_properties(zlib PROPERTIES OUTPUT_NAME z) 150 set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
151elseif(BUILD_SHARED_LIBS AND WIN32)
152 # Creates zlib1.dll when building shared library version
153 set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
142endif() 154endif()
143 155
144if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) 156if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
diff --git a/ChangeLog b/ChangeLog
index 6e8ff5c..87e4339 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,27 @@
1 1
2 ChangeLog file for zlib 2 ChangeLog file for zlib
3 3
4Changes in 1.2.3.6 (17 Jan 2010)
5- Avoid void * arithmetic in gzread.c and gzwrite.c
6- Make compilers happier with const char * for gz_error message
7- Avoid unused parameter warning in inflate.c
8- Avoid signed-unsigned comparison warning in inflate.c
9- Indent #pragma's for traditional C
10- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
11- Correct email address in configure for system options
12- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
13- Update zlib.map [Brown]
14- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk]
15- Apply various fixes to CMakeLists.txt [Lowman]
16- Add checks on len in gzread() and gzwrite()
17- Add error message for no more room for gzungetc()
18- Remove zlib version check in gzwrite()
19- Defer compression of gzprintf() result until need to
20- Use snprintf() in gzdopen() if available
21- Remove USE_MMAP configuration determination (only used by minigzip)
22- Remove examples/pigz.c (available separately)
23- Update examples/gun.c to 1.6
24
4Changes in 1.2.3.5 (8 Jan 2010) 25Changes in 1.2.3.5 (8 Jan 2010)
5- Add space after #if in zutil.h for some compilers 26- Add space after #if in zutil.h for some compilers
6- Fix relatively harmless bug in deflate_fast() [Exarevsky] 27- Fix relatively harmless bug in deflate_fast() [Exarevsky]
@@ -21,6 +42,7 @@ Changes in 1.2.3.5 (8 Jan 2010)
21- Replace gzio.c with a new set of routines with the same functionality 42- Replace gzio.c with a new set of routines with the same functionality
22- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above 43- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
23- Update contrib/minizip to 1.1b 44- Update contrib/minizip to 1.1b
45- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
24 46
25Changes in 1.2.3.4 (21 Dec 2009) 47Changes in 1.2.3.4 (21 Dec 2009)
26- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility 48- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
diff --git a/Makefile b/Makefile
index 0941228..9b81f23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
1# Makefile for zlib 1# Makefile for zlib
2# Copyright (C) 1995-2006 Jean-loup Gailly. 2# Copyright (C) 1995-2010 Jean-loup Gailly.
3# For conditions of distribution and use, see copyright notice in zlib.h 3# For conditions of distribution and use, see copyright notice in zlib.h
4 4
5# To compile and test, type: 5# To compile and test, type:
@@ -32,7 +32,7 @@ CPP=$(CC) -E
32 32
33STATICLIB=libz.a 33STATICLIB=libz.a
34SHAREDLIB=libz.so 34SHAREDLIB=libz.so
35SHAREDLIBV=libz.so.1.2.3.5 35SHAREDLIBV=libz.so.1.2.3.6
36SHAREDLIBM=libz.so.1 36SHAREDLIBM=libz.so.1
37LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) 37LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
38 38
@@ -124,10 +124,10 @@ match.lo: match.S
124 rm -f _match.s 124 rm -f _match.s
125 125
126example64.o: example.c zlib.h zconf.h zlibdefs.h 126example64.o: example.c zlib.h zconf.h zlibdefs.h
127 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< 127 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
128 128
129minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h 129minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
130 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< 130 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
131 131
132.SUFFIXES: .lo 132.SUFFIXES: .lo
133 133
diff --git a/Makefile.in b/Makefile.in
index 0941228..9b81f23 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,5 +1,5 @@
1# Makefile for zlib 1# Makefile for zlib
2# Copyright (C) 1995-2006 Jean-loup Gailly. 2# Copyright (C) 1995-2010 Jean-loup Gailly.
3# For conditions of distribution and use, see copyright notice in zlib.h 3# For conditions of distribution and use, see copyright notice in zlib.h
4 4
5# To compile and test, type: 5# To compile and test, type:
@@ -32,7 +32,7 @@ CPP=$(CC) -E
32 32
33STATICLIB=libz.a 33STATICLIB=libz.a
34SHAREDLIB=libz.so 34SHAREDLIB=libz.so
35SHAREDLIBV=libz.so.1.2.3.5 35SHAREDLIBV=libz.so.1.2.3.6
36SHAREDLIBM=libz.so.1 36SHAREDLIBM=libz.so.1
37LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) 37LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
38 38
@@ -124,10 +124,10 @@ match.lo: match.S
124 rm -f _match.s 124 rm -f _match.s
125 125
126example64.o: example.c zlib.h zconf.h zlibdefs.h 126example64.o: example.c zlib.h zconf.h zlibdefs.h
127 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< 127 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
128 128
129minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h 129minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
130 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< 130 $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
131 131
132.SUFFIXES: .lo 132.SUFFIXES: .lo
133 133
diff --git a/README b/README
index e3a2170..741e000 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
1ZLIB DATA COMPRESSION LIBRARY 1ZLIB DATA COMPRESSION LIBRARY
2 2
3zlib 1.2.3.5 is a general purpose data compression library. All the code is 3zlib 1.2.3.6 is a general purpose data compression library. All the code is
4thread safe. The data format used by the zlib library is described by RFCs 4thread safe. The data format used by the zlib library is described by RFCs
5(Request for Comments) 1950 to 1952 in the files 5(Request for Comments) 1950 to 1952 in the files
6http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) 6http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
@@ -33,7 +33,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
33issue of Dr. Dobb's Journal; a copy of the article is available in 33issue of Dr. Dobb's Journal; a copy of the article is available in
34http://dogma.net/markn/articles/zlibtool/zlibtool.htm 34http://dogma.net/markn/articles/zlibtool/zlibtool.htm
35 35
36The changes made in version 1.2.3.5 are documented in the file ChangeLog. 36The changes made in version 1.2.3.6 are documented in the file ChangeLog.
37 37
38Unsupported third party contributions are provided in directory "contrib". 38Unsupported third party contributions are provided in directory "contrib".
39 39
diff --git a/as400/zlib.inc b/as400/zlib.inc
index 38c47ac..7ecea98 100644
--- a/as400/zlib.inc
+++ b/as400/zlib.inc
@@ -1,7 +1,7 @@
1 * ZLIB.INC - Interface to the general purpose compression library 1 * ZLIB.INC - Interface to the general purpose compression library
2 * 2 *
3 * ILE RPG400 version by Patrick Monnerat, DATASPHERE. 3 * ILE RPG400 version by Patrick Monnerat, DATASPHERE.
4 * Version 1.2.3.5 4 * Version 1.2.3.6
5 * 5 *
6 * 6 *
7 * WARNING: 7 * WARNING:
@@ -22,8 +22,8 @@
22 * 22 *
23 * Versioning information. 23 * Versioning information.
24 * 24 *
25 D ZLIB_VERSION C '1.2.3.5' 25 D ZLIB_VERSION C '1.2.3.6'
26 D ZLIB_VERNUM C X'1235' 26 D ZLIB_VERNUM C X'1236'
27 * 27 *
28 * Other equates. 28 * Other equates.
29 * 29 *
diff --git a/configure b/configure
index b87dddc..261efa9 100755
--- a/configure
+++ b/configure
@@ -78,6 +78,9 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
78 CC="$cc" 78 CC="$cc"
79 SFLAGS="${CFLAGS-"-O3"} -fPIC" 79 SFLAGS="${CFLAGS-"-O3"} -fPIC"
80 CFLAGS="${CFLAGS-"-O3"}" 80 CFLAGS="${CFLAGS-"-O3"}"
81 if test "${ZLIBGCCWARN}" = "YES"; then
82 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
83 fi
81 if test -z "$uname"; then 84 if test -z "$uname"; then
82 uname=`(uname -s || echo unknown) 2>/dev/null` 85 uname=`(uname -s || echo unknown) 2>/dev/null`
83 fi 86 fi
@@ -154,8 +157,8 @@ else
154 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} 157 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
155 CFLAGS=${CFLAGS-"-O2"} 158 CFLAGS=${CFLAGS-"-O2"}
156 LDSHARED=${LDSHARED-"ld"} ;; 159 LDSHARED=${LDSHARED-"ld"} ;;
157 SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} 160 SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
158 CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"} 161 CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
159 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; 162 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
160 UNIX_System_V\ 4.2.0) 163 UNIX_System_V\ 4.2.0)
161 SFLAGS=${CFLAGS-"-KPIC -O"} 164 SFLAGS=${CFLAGS-"-KPIC -O"}
@@ -173,7 +176,7 @@ else
173 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 176 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
174 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 177 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
175 LDSHARED=${LDSHARED-"xlc -G"} ;; 178 LDSHARED=${LDSHARED-"xlc -G"} ;;
176 # send working options for other systems to support@gzip.org 179 # send working options for other systems to zlib@gzip.org
177 *) SFLAGS=${CFLAGS-"-O"} 180 *) SFLAGS=${CFLAGS-"-O"}
178 CFLAGS=${CFLAGS-"-O"} 181 CFLAGS=${CFLAGS-"-O"}
179 LDSHARED=${LDSHARED-"cc -shared"} ;; 182 LDSHARED=${LDSHARED-"cc -shared"} ;;
@@ -488,22 +491,6 @@ else
488 SFLAGS="$SFLAGS -DNO_ERRNO_H" 491 SFLAGS="$SFLAGS -DNO_ERRNO_H"
489fi 492fi
490 493
491cat > $test.c <<EOF
492#include <sys/types.h>
493#include <sys/mman.h>
494#include <sys/stat.h>
495caddr_t hello() {
496 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
497}
498EOF
499if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
500 CFLAGS="$CFLAGS -DUSE_MMAP"
501 SFLAGS="$SFLAGS -DUSE_MMAP"
502 echo Checking for mmap support... Yes.
503else
504 echo Checking for mmap support... No.
505fi
506
507CPP=${CPP-"$CC -E"} 494CPP=${CPP-"$CC -E"}
508case $CFLAGS in 495case $CFLAGS in
509 *ASMV*) 496 *ASMV*)
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c
index 9b0f46c..2d42f72 100644
--- a/contrib/infback9/inftree9.c
+++ b/contrib/infback9/inftree9.c
@@ -1,5 +1,5 @@
1/* inftree9.c -- generate Huffman trees for efficient decoding 1/* inftree9.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2008 Mark Adler 2 * Copyright (C) 1995-2010 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate9_copyright[] = 11const char inflate9_copyright[] =
12 " inflate9 1.2.3.5 Copyright 1995-2009 Mark Adler "; 12 " inflate9 1.2.3.6 Copyright 1995-2010 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot 15 in the documentation of your product. If for some reason you cannot
@@ -64,7 +64,7 @@ unsigned short FAR *work;
64 static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
65 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 65 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
66 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, 66 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
67 133, 133, 133, 133, 144, 69, 199}; 67 133, 133, 133, 133, 144, 199, 70};
68 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ 68 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
69 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 69 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
70 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 70 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
diff --git a/contrib/minizip/make_vms.com b/contrib/minizip/make_vms.com
new file mode 100644
index 0000000..548ee29
--- /dev/null
+++ b/contrib/minizip/make_vms.com
@@ -0,0 +1,25 @@
1$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig
2$ open/write zdef vmsdefs.h
3$ copy sys$input: zdef
4$ deck
5#define unix
6#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from
7#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator
8#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord
9#define Write_EndOfCentralDirectoryRecord Write_EoDRecord
10$ eod
11$ close zdef
12$ copy vmsdefs.h,ioapi.h_orig ioapi.h
13$ cc/include=[--]/prefix=all ioapi.c
14$ cc/include=[--]/prefix=all miniunz.c
15$ cc/include=[--]/prefix=all unzip.c
16$ cc/include=[--]/prefix=all minizip.c
17$ cc/include=[--]/prefix=all zip.c
18$ link miniunz,unzip,ioapi,[--]libz.olb/lib
19$ link minizip,zip,ioapi,[--]libz.olb/lib
20$ mcr []minizip test minizip64_info.txt
21$ mcr []miniunz -l test.zip
22$ rename minizip64_info.txt; minizip64_info.txt_old
23$ mcr []miniunz test.zip
24$ delete test.zip;*
25$exit
diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc
index 7bb4bb7..418eb7a 100644
--- a/contrib/vstudio/vc7/zlib.rc
+++ b/contrib/vstudio/vc7/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,2,3,5 5 FILEVERSION 1,2,3,6
6 PRODUCTVERSION 1,2,3,5 6 PRODUCTVERSION 1,2,3,6
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,12 +17,12 @@ 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.2.3.5\0" 20 VALUE "FileVersion", "1.2.3.6\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"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" 24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0" 25 VALUE "LegalCopyright", "(C) 1995-2010 Jean-loup Gailly & Mark Adler\0"
26 END 26 END
27 END 27 END
28 BLOCK "VarFileInfo" 28 BLOCK "VarFileInfo"
diff --git a/deflate.c b/deflate.c
index d34e1ad..c010a89 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.2.3.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; 55 " deflate 1.2.3.6 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
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
diff --git a/examples/README.examples b/examples/README.examples
index 146919c..56a3171 100644
--- a/examples/README.examples
+++ b/examples/README.examples
@@ -34,12 +34,6 @@ gzlog.h
34 and deflateSetDictionary() 34 and deflateSetDictionary()
35 - illustrates use of a gzip header extra field 35 - illustrates use of a gzip header extra field
36 36
37pigz.c
38 parallel implementation of gzip compression
39 - uses pthreads to speed up compression on multiple core machines
40 - illustrates the use of deflateSetDictionary() with raw deflate
41 - illustrates the use of crc32_combine()
42
43zlib_how.html 37zlib_how.html
44 painfully comprehensive description of zpipe.c (see below) 38 painfully comprehensive description of zpipe.c (see below)
45 - describes in excruciating detail the use of deflate() and inflate() 39 - describes in excruciating detail the use of deflate() and inflate()
diff --git a/examples/gun.c b/examples/gun.c
index bfec590..72b0882 100644
--- a/examples/gun.c
+++ b/examples/gun.c
@@ -1,7 +1,7 @@
1/* gun.c -- simple gunzip to give an example of the use of inflateBack() 1/* gun.c -- simple gunzip to give an example of the use of inflateBack()
2 * Copyright (C) 2003, 2005 Mark Adler 2 * Copyright (C) 2003, 2005, 2008, 2010 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 Version 1.3 12 June 2005 Mark Adler */ 4 Version 1.6 17 January 2010 Mark Adler */
5 5
6/* Version history: 6/* Version history:
7 1.0 16 Feb 2003 First version for testing of inflateBack() 7 1.0 16 Feb 2003 First version for testing of inflateBack()
@@ -15,6 +15,9 @@
15 1.2 20 Mar 2005 Add Unix compress (LZW) decompression 15 1.2 20 Mar 2005 Add Unix compress (LZW) decompression
16 Copy file attributes from input file to output file 16 Copy file attributes from input file to output file
17 1.3 12 Jun 2005 Add casts for error messages [Oberhumer] 17 1.3 12 Jun 2005 Add casts for error messages [Oberhumer]
18 1.4 8 Dec 2006 LZW decompression speed improvements
19 1.5 9 Feb 2008 Avoid warning in latest version of gcc
20 1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings
18 */ 21 */
19 22
20/* 23/*
@@ -197,14 +200,14 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
197 int outfile, z_stream *strm) 200 int outfile, z_stream *strm)
198{ 201{
199 int last; /* last byte read by NEXT(), or -1 if EOF */ 202 int last; /* last byte read by NEXT(), or -1 if EOF */
200 int chunk; /* bytes left in current chunk */ 203 unsigned chunk; /* bytes left in current chunk */
201 int left; /* bits left in rem */ 204 int left; /* bits left in rem */
202 unsigned rem; /* unused bits from input */ 205 unsigned rem; /* unused bits from input */
203 int bits; /* current bits per code */ 206 int bits; /* current bits per code */
204 unsigned code; /* code, table traversal index */ 207 unsigned code; /* code, table traversal index */
205 unsigned mask; /* mask for current bits codes */ 208 unsigned mask; /* mask for current bits codes */
206 int max; /* maximum bits per code for this stream */ 209 int max; /* maximum bits per code for this stream */
207 int flags; /* compress flags, then block compress flag */ 210 unsigned flags; /* compress flags, then block compress flag */
208 unsigned end; /* last valid entry in prefix/suffix tables */ 211 unsigned end; /* last valid entry in prefix/suffix tables */
209 unsigned temp; /* current code */ 212 unsigned temp; /* current code */
210 unsigned prev; /* previous code */ 213 unsigned prev; /* previous code */
@@ -212,6 +215,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
212 unsigned stack; /* next position for reversed string */ 215 unsigned stack; /* next position for reversed string */
213 unsigned outcnt; /* bytes in output buffer */ 216 unsigned outcnt; /* bytes in output buffer */
214 struct outd outd; /* output structure */ 217 struct outd outd; /* output structure */
218 unsigned char *p;
215 219
216 /* set up output */ 220 /* set up output */
217 outd.outfile = outfile; 221 outd.outfile = outfile;
@@ -322,10 +326,12 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
322 } 326 }
323 327
324 /* walk through linked list to generate output in reverse order */ 328 /* walk through linked list to generate output in reverse order */
329 p = match + stack;
325 while (code >= 256) { 330 while (code >= 256) {
326 match[stack++] = suffix[code]; 331 *p++ = suffix[code];
327 code = prefix[code]; 332 code = prefix[code];
328 } 333 }
334 stack = p - match;
329 match[stack++] = (unsigned char)code; 335 match[stack++] = (unsigned char)code;
330 final = code; 336 final = code;
331 337
@@ -349,9 +355,11 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
349 } 355 }
350 outcnt = 0; 356 outcnt = 0;
351 } 357 }
358 p = match + stack;
352 do { 359 do {
353 outbuf[outcnt++] = match[--stack]; 360 outbuf[outcnt++] = *--p;
354 } while (stack); 361 } while (p > match);
362 stack = 0;
355 363
356 /* loop for next code with final and prev as the last match, rem and 364 /* loop for next code with final and prev as the last match, rem and
357 left provide the first 0..7 bits of the next code, end is the last 365 left provide the first 0..7 bits of the next code, end is the last
@@ -375,7 +383,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
375{ 383{
376 int ret, first, last; 384 int ret, first, last;
377 unsigned have, flags, len; 385 unsigned have, flags, len;
378 unsigned char *next; 386 unsigned char *next = NULL;
379 struct ind ind, *indp; 387 struct ind ind, *indp;
380 struct outd outd; 388 struct outd outd;
381 389
@@ -471,10 +479,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
471 479
472 /* check trailer */ 480 /* check trailer */
473 ret = Z_BUF_ERROR; 481 ret = Z_BUF_ERROR;
474 if (NEXT() != (outd.crc & 0xff) || 482 if (NEXT() != (int)(outd.crc & 0xff) ||
475 NEXT() != ((outd.crc >> 8) & 0xff) || 483 NEXT() != (int)((outd.crc >> 8) & 0xff) ||
476 NEXT() != ((outd.crc >> 16) & 0xff) || 484 NEXT() != (int)((outd.crc >> 16) & 0xff) ||
477 NEXT() != ((outd.crc >> 24) & 0xff)) { 485 NEXT() != (int)((outd.crc >> 24) & 0xff)) {
478 /* crc error */ 486 /* crc error */
479 if (last != -1) { 487 if (last != -1) {
480 strm->msg = (char *)"incorrect data check"; 488 strm->msg = (char *)"incorrect data check";
@@ -482,10 +490,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
482 } 490 }
483 break; 491 break;
484 } 492 }
485 if (NEXT() != (outd.total & 0xff) || 493 if (NEXT() != (int)(outd.total & 0xff) ||
486 NEXT() != ((outd.total >> 8) & 0xff) || 494 NEXT() != (int)((outd.total >> 8) & 0xff) ||
487 NEXT() != ((outd.total >> 16) & 0xff) || 495 NEXT() != (int)((outd.total >> 16) & 0xff) ||
488 NEXT() != ((outd.total >> 24) & 0xff)) { 496 NEXT() != (int)((outd.total >> 24) & 0xff)) {
489 /* length error */ 497 /* length error */
490 if (last != -1) { 498 if (last != -1) {
491 strm->msg = (char *)"incorrect length check"; 499 strm->msg = (char *)"incorrect length check";
@@ -642,8 +650,8 @@ int main(int argc, char **argv)
642 argv++; 650 argv++;
643 test = 0; 651 test = 0;
644 if (argc && strcmp(*argv, "-h") == 0) { 652 if (argc && strcmp(*argv, "-h") == 0) {
645 fprintf(stderr, "gun 1.3 (12 Jun 2005)\n"); 653 fprintf(stderr, "gun 1.6 (17 Jan 2010)\n");
646 fprintf(stderr, "Copyright (c) 2005 Mark Adler\n"); 654 fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n");
647 fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); 655 fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n");
648 return 0; 656 return 0;
649 } 657 }
diff --git a/examples/pigz.c b/examples/pigz.c
deleted file mode 100644
index 42794d0..0000000
--- a/examples/pigz.c
+++ /dev/null
@@ -1,452 +0,0 @@
1/* pigz.c -- parallel implementation of gzip
2 * Copyright (C) 2007 Mark Adler
3 * Version 1.1 28 January 2007 Mark Adler
4 */
5
6/* Version history:
7 1.0 17 Jan 2007 First version
8 1.1 28 Jan 2007 Avoid void * arithmetic (some compilers don't get that)
9 Add note about requiring zlib 1.2.3
10 Allow compression level 0 (no compression)
11 Completely rewrite parallelism -- add a write thread
12 Use deflateSetDictionary() to make use of history
13 Tune argument defaults to best performance on four cores
14 */
15
16/*
17 pigz compresses from stdin to stdout using threads to make use of multiple
18 processors and cores. The input is broken up into 128 KB chunks, and each
19 is compressed separately. The CRC for each chunk is also calculated
20 separately. The compressed chunks are written in order to the output,
21 and the overall CRC is calculated from the CRC's of the chunks.
22
23 The compressed data format generated is the gzip format using the deflate
24 compression method. First a gzip header is written, followed by raw deflate
25 partial streams. They are partial, in that they do not have a terminating
26 block. At the end, the deflate stream is terminated with a final empty
27 static block, and lastly a gzip trailer is written with the CRC and the
28 number of input bytes.
29
30 Each raw deflate partial stream is terminated by an empty stored block
31 (using the Z_SYNC_FLUSH option of zlib), in order to end that partial
32 bit stream at a byte boundary. That allows the partial streams to be
33 concantenated simply as sequences of bytes. This adds a very small four
34 or five byte overhead to the output for each input chunk.
35
36 zlib's crc32_combine() routine allows the calcuation of the CRC of the
37 entire input using the independent CRC's of the chunks. pigz requires zlib
38 version 1.2.3 or later, since that is the first version that provides the
39 crc32_combine() function.
40
41 pigz uses the POSIX pthread library for thread control and communication.
42 */
43
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include <pthread.h>
48#include <sys/types.h>
49#include <sys/uio.h>
50#include <unistd.h>
51#include "zlib.h"
52
53#define local static
54
55/* exit with error */
56local void bail(char *msg)
57{
58 fprintf(stderr, "pigz abort: %s\n", msg);
59 exit(1);
60}
61
62/* read up to len bytes into buf, repeating read() calls as needed */
63local size_t readn(int desc, unsigned char *buf, size_t len)
64{
65 ssize_t ret;
66 size_t got;
67
68 got = 0;
69 while (len) {
70 ret = read(desc, buf, len);
71 if (ret < 0)
72 bail("read error");
73 if (ret == 0)
74 break;
75 buf += ret;
76 len -= ret;
77 got += ret;
78 }
79 return got;
80}
81
82/* write len bytes, repeating write() calls as needed */
83local void writen(int desc, unsigned char *buf, size_t len)
84{
85 ssize_t ret;
86
87 while (len) {
88 ret = write(desc, buf, len);
89 if (ret < 1)
90 bail("write error");
91 buf += ret;
92 len -= ret;
93 }
94}
95
96/* a flag variable for communication between two threads */
97struct flag {
98 int value; /* value of flag */
99 pthread_mutex_t lock; /* lock for checking and changing flag */
100 pthread_cond_t cond; /* condition for signaling on flag change */
101};
102
103/* initialize a flag for use, starting with value val */
104local void flag_init(struct flag *me, int val)
105{
106 me->value = val;
107 pthread_mutex_init(&(me->lock), NULL);
108 pthread_cond_init(&(me->cond), NULL);
109}
110
111/* set the flag to val, signal another process that may be waiting for it */
112local void flag_set(struct flag *me, int val)
113{
114 pthread_mutex_lock(&(me->lock));
115 me->value = val;
116 pthread_cond_signal(&(me->cond));
117 pthread_mutex_unlock(&(me->lock));
118}
119
120/* if it isn't already, wait for some other thread to set the flag to val */
121local void flag_wait(struct flag *me, int val)
122{
123 pthread_mutex_lock(&(me->lock));
124 while (me->value != val)
125 pthread_cond_wait(&(me->cond), &(me->lock));
126 pthread_mutex_unlock(&(me->lock));
127}
128
129/* if flag is equal to val, wait for some other thread to change it */
130local void flag_wait_not(struct flag *me, int val)
131{
132 pthread_mutex_lock(&(me->lock));
133 while (me->value == val)
134 pthread_cond_wait(&(me->cond), &(me->lock));
135 pthread_mutex_unlock(&(me->lock));
136}
137
138/* clean up the flag when done with it */
139local void flag_done(struct flag *me)
140{
141 pthread_cond_destroy(&(me->cond));
142 pthread_mutex_destroy(&(me->lock));
143}
144
145/* a unit of work to feed to compress_thread() -- it is assumed that the out
146 buffer is large enough to hold the maximum size len bytes could deflate to,
147 plus five bytes for the final sync marker */
148struct work {
149 size_t len; /* length of input */
150 unsigned long crc; /* crc of input */
151 unsigned char *buf; /* input */
152 unsigned char *out; /* space for output (guaranteed big enough) */
153 z_stream strm; /* pre-initialized z_stream */
154 struct flag busy; /* busy flag indicating work unit in use */
155 pthread_t comp; /* this compression thread */
156};
157
158/* busy flag values */
159#define IDLE 0 /* compress and writing done -- can start compress */
160#define COMP 1 /* compress -- input and output buffers in use */
161#define WRITE 2 /* compress done, writing output -- can read input */
162
163/* read-only globals (set by main/read thread before others started) */
164local int ind; /* input file descriptor */
165local int outd; /* output file descriptor */
166local int level; /* compression level */
167local int procs; /* number of compression threads (>= 2) */
168local size_t size; /* uncompressed input size per thread (>= 32K) */
169local struct work *jobs; /* work units: jobs[0..procs-1] */
170
171/* next and previous jobs[] indices */
172#define NEXT(n) ((n) == procs - 1 ? 0 : (n) + 1)
173#define PREV(n) ((n) == 0 ? procs - 1 : (n) - 1)
174
175/* sliding dictionary size for deflate */
176#define DICT 32768U
177
178/* largest power of 2 that fits in an unsigned int -- used to limit requests
179 to zlib functions that use unsigned int lengths */
180#define MAX ((((unsigned)-1) >> 1) + 1)
181
182/* compress thread: compress the input in the provided work unit and compute
183 its crc -- assume that the amount of space at job->out is guaranteed to be
184 enough for the compressed output, as determined by the maximum expansion
185 of deflate compression -- use the input in the previous work unit (if there
186 is one) to set the deflate dictionary for better compression */
187local void *compress_thread(void *arg)
188{
189 size_t len; /* input length for this work unit */
190 unsigned long crc; /* crc of input data */
191 struct work *prev; /* previous work unit */
192 struct work *job = arg; /* work unit for this thread */
193 z_stream *strm = &(job->strm); /* zlib stream for this work unit */
194
195 /* reset state for a new compressed stream */
196 (void)deflateReset(strm);
197
198 /* initialize input, output, and crc */
199 strm->next_in = job->buf;
200 strm->next_out = job->out;
201 len = job->len;
202 crc = crc32(0L, Z_NULL, 0);
203
204 /* set dictionary if this isn't the first work unit, and if we will be
205 compressing something (the read thread assures that the dictionary
206 data in the previous work unit is still there) */
207 prev = jobs + PREV(job - jobs);
208 if (prev->buf != NULL && len != 0)
209 deflateSetDictionary(strm, prev->buf + (size - DICT), DICT);
210
211 /* run MAX-sized amounts of input through deflate and crc32 -- this loop
212 is needed for those cases where the integer type is smaller than the
213 size_t type, or when len is close to the limit of the size_t type */
214 while (len > MAX) {
215 strm->avail_in = MAX;
216 strm->avail_out = (unsigned)-1;
217 crc = crc32(crc, strm->next_in, strm->avail_in);
218 (void)deflate(strm, Z_NO_FLUSH);
219 len -= MAX;
220 }
221
222 /* run last piece through deflate and crc32, follow with a sync marker */
223 if (len) {
224 strm->avail_in = len;
225 strm->avail_out = (unsigned)-1;
226 crc = crc32(crc, strm->next_in, strm->avail_in);
227 (void)deflate(strm, Z_SYNC_FLUSH);
228 }
229
230 /* don't need to Z_FINISH, since we'd delete the last two bytes anyway */
231
232 /* return result */
233 job->crc = crc;
234 return NULL;
235}
236
237/* put a 4-byte integer into a byte array in LSB order */
238#define PUT4(a,b) (*(a)=(b),(a)[1]=(b)>>8,(a)[2]=(b)>>16,(a)[3]=(b)>>24)
239
240/* write thread: wait for compression threads to complete, write output in
241 order, also write gzip header and trailer around the compressed data */
242local void *write_thread(void *arg)
243{
244 int n; /* compress thread index */
245 size_t len; /* length of input processed */
246 unsigned long tot; /* total uncompressed size (overflow ok) */
247 unsigned long crc; /* CRC-32 of uncompressed data */
248 unsigned char wrap[10]; /* gzip header or trailer */
249
250 /* write simple gzip header */
251 memcpy(wrap, "\037\213\10\0\0\0\0\0\0\3", 10);
252 wrap[8] = level == 9 ? 2 : (level == 1 ? 4 : 0);
253 writen(outd, wrap, 10);
254
255 /* process output of compress threads until end of input */
256 tot = 0;
257 crc = crc32(0L, Z_NULL, 0);
258 n = 0;
259 do {
260 /* wait for compress thread to start, then wait to complete */
261 flag_wait(&(jobs[n].busy), COMP);
262 pthread_join(jobs[n].comp, NULL);
263
264 /* now that compress is done, allow read thread to use input buffer */
265 flag_set(&(jobs[n].busy), WRITE);
266
267 /* write compressed data and update length and crc */
268 writen(outd, jobs[n].out, jobs[n].strm.next_out - jobs[n].out);
269 len = jobs[n].len;
270 tot += len;
271 crc = crc32_combine(crc, jobs[n].crc, len);
272
273 /* release this work unit and go to the next work unit */
274 flag_set(&(jobs[n].busy), IDLE);
275 n = NEXT(n);
276
277 /* an input buffer less than size in length indicates end of input */
278 } while (len == size);
279
280 /* write final static block and gzip trailer (crc and len mod 2^32) */
281 wrap[0] = 3; wrap[1] = 0;
282 PUT4(wrap + 2, crc);
283 PUT4(wrap + 6, tot);
284 writen(outd, wrap, 10);
285 return NULL;
286}
287
288/* one-time initialization of a work unit -- this is where we set the deflate
289 compression level and request raw deflate, and also where we set the size
290 of the output buffer to guarantee enough space for a worst-case deflate
291 ending with a Z_SYNC_FLUSH */
292local void job_init(struct work *job)
293{
294 int ret; /* deflateInit2() return value */
295
296 job->buf = malloc(size);
297 job->out = malloc(size + (size >> 11) + 10);
298 job->strm.zfree = Z_NULL;
299 job->strm.zalloc = Z_NULL;
300 job->strm.opaque = Z_NULL;
301 ret = deflateInit2(&(job->strm), level, Z_DEFLATED, -15, 8,
302 Z_DEFAULT_STRATEGY);
303 if (job->buf == NULL || job->out == NULL || ret != Z_OK)
304 bail("not enough memory");
305}
306
307/* compress ind to outd in the gzip format, using multiple threads for the
308 compression and crc calculation and another thread for writing the output --
309 the read thread is the main thread */
310local void read_thread(void)
311{
312 int n; /* general index */
313 size_t got; /* amount read */
314 pthread_attr_t attr; /* thread attributes (left at defaults) */
315 pthread_t write; /* write thread */
316
317 /* set defaults (not all pthread implementations default to joinable) */
318 pthread_attr_init(&attr);
319 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
320
321 /* allocate and set up work list (individual work units will be initialized
322 as needed, in case the input is short), assure that allocation size
323 arithmetic does not overflow */
324 if (size + (size >> 11) + 10 < (size >> 11) + 10 ||
325 (ssize_t)(size + (size >> 11) + 10) < 0 ||
326 ((size_t)0 - 1) / procs <= sizeof(struct work) ||
327 (jobs = malloc(procs * sizeof(struct work))) == NULL)
328 bail("not enough memory");
329 for (n = 0; n < procs; n++) {
330 jobs[n].buf = NULL;
331 flag_init(&(jobs[n].busy), IDLE);
332 }
333
334 /* start write thread */
335 pthread_create(&write, &attr, write_thread, NULL);
336
337 /* read from input and start compress threads (write thread will pick up
338 the output of the compress threads) */
339 n = 0;
340 do {
341 /* initialize this work unit if it's the first time it's used */
342 if (jobs[n].buf == NULL)
343 job_init(jobs + n);
344
345 /* read input data, but wait for last compress on this work unit to be
346 done, and wait for the dictionary to be used by the last compress on
347 the next work unit */
348 flag_wait_not(&(jobs[n].busy), COMP);
349 flag_wait_not(&(jobs[NEXT(n)].busy), COMP);
350 got = readn(ind, jobs[n].buf, size);
351
352 /* start compress thread, but wait for write to be done first */
353 flag_wait(&(jobs[n].busy), IDLE);
354 jobs[n].len = got;
355 pthread_create(&(jobs[n].comp), &attr, compress_thread, jobs + n);
356
357 /* mark work unit so write thread knows compress was started */
358 flag_set(&(jobs[n].busy), COMP);
359
360 /* go to the next work unit */
361 n = NEXT(n);
362
363 /* do until end of input, indicated by a read less than size */
364 } while (got == size);
365
366 /* wait for the write thread to complete -- the write thread will join with
367 all of the compress threads, so this waits for all of the threads to
368 complete */
369 pthread_join(write, NULL);
370
371 /* free up all requested resources and return */
372 for (n = procs - 1; n >= 0; n--) {
373 flag_done(&(jobs[n].busy));
374 (void)deflateEnd(&(jobs[n].strm));
375 free(jobs[n].out);
376 free(jobs[n].buf);
377 }
378 free(jobs);
379 pthread_attr_destroy(&attr);
380}
381
382/* Process arguments for level, size, and procs, compress from stdin to
383 stdout in the gzip format. Note that procs must be at least two in
384 order to provide a dictionary in one work unit for the other work
385 unit, and that size must be at least 32K to store a full dictionary. */
386int main(int argc, char **argv)
387{
388 int n; /* general index */
389 int get; /* command line parameters to get */
390 char *arg; /* command line argument */
391
392 /* set defaults -- 32 processes and 128K buffers was found to provide
393 good utilization of four cores (about 97%) and balanced the overall
394 execution time impact of more threads against more dictionary
395 processing for a fixed amount of memory -- the memory usage for these
396 settings and full use of all work units (at least 4 MB of input) is
397 16.2 MB
398 */
399 level = Z_DEFAULT_COMPRESSION;
400 procs = 32;
401 size = 131072UL;
402
403 /* process command-line arguments */
404 get = 0;
405 for (n = 1; n < argc; n++) {
406 arg = argv[n];
407 if (*arg == '-') {
408 while (*++arg)
409 if (*arg >= '0' && *arg <= '9') /* compression level */
410 level = *arg - '0';
411 else if (*arg == 'b') /* chunk size in K */
412 get |= 1;
413 else if (*arg == 'p') /* number of processes */
414 get |= 2;
415 else if (*arg == 'h') { /* help */
416 fputs("usage: pigz [-0..9] [-b blocksizeinK]", stderr);
417 fputs(" [-p processes] < foo > foo.gz\n", stderr);
418 return 0;
419 }
420 else
421 bail("invalid option");
422 }
423 else if (get & 1) {
424 if (get & 2)
425 bail("you need to separate the -b and -p options");
426 size = (size_t)(atol(arg)) << 10; /* chunk size */
427 if (size < DICT)
428 bail("invalid option");
429 get = 0;
430 }
431 else if (get & 2) {
432 procs = atoi(arg); /* processes */
433 if (procs < 2)
434 bail("invalid option");
435 get = 0;
436 }
437 else
438 bail("invalid option (you need to pipe input and output)");
439 }
440 if (get)
441 bail("missing option argument");
442
443 /* do parallel compression from stdin to stdout (the read thread starts up
444 the write thread and the compression threads, and they all join before
445 the read thread returns) */
446 ind = 0;
447 outd = 1;
448 read_thread();
449
450 /* done */
451 return 0;
452}
diff --git a/gzguts.h b/gzguts.h
index 429c21b..8b7914d 100644
--- a/gzguts.h
+++ b/gzguts.h
@@ -15,10 +15,12 @@
15#define ZLIB_INTERNAL 15#define ZLIB_INTERNAL
16 16
17#include <stdio.h> 17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <fcntl.h>
21#include "zlib.h" 18#include "zlib.h"
19#ifdef STDC
20# include <string.h>
21# include <stdlib.h>
22#endif
23#include <fcntl.h>
22 24
23#ifdef NO_DEFLATE /* for compatibility with old definition */ 25#ifdef NO_DEFLATE /* for compatibility with old definition */
24# define NO_GZCOMPRESS 26# define NO_GZCOMPRESS
@@ -42,7 +44,8 @@
42 44
43/* get errno and strerror definition */ 45/* get errno and strerror definition */
44#if defined UNDER_CE && defined NO_ERRNO_H 46#if defined UNDER_CE && defined NO_ERRNO_H
45# define zstrerror(errnum) strwinerror((DWORD)errnum) 47# include <windows.h>
48# define zstrerror() gz_strwinerror((DWORD)GetLastError())
46#else 49#else
47# ifdef STDC 50# ifdef STDC
48# include <errno.h> 51# include <errno.h>
@@ -54,7 +57,7 @@
54 57
55/* MVS fdopen() */ 58/* MVS fdopen() */
56#ifdef __MVS__ 59#ifdef __MVS__
57# pragma map (fdopen , "\174\174FDOPEN") 60 #pragma map (fdopen , "\174\174FDOPEN")
58 FILE *fdopen(int, const char *); 61 FILE *fdopen(int, const char *);
59#endif 62#endif
60 63
@@ -106,4 +109,7 @@ typedef struct {
106typedef gz_state FAR *gz_statep; 109typedef gz_state FAR *gz_statep;
107 110
108/* shared functions */ 111/* shared functions */
109ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *)); 112ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, const char *));
113#if defined UNDER_CE && defined NO_ERRNO_H
114ZEXTERN char ZEXPORT *gz_strwinerror OF((DWORD error));
115#endif
diff --git a/gzio.c b/gzio.c
index f9afc10..72b6287 100644
--- a/gzio.c
+++ b/gzio.c
@@ -95,7 +95,7 @@ local char *strwinerror (error)
95#endif /* UNDER_CE && NO_ERRNO_H */ 95#endif /* UNDER_CE && NO_ERRNO_H */
96 96
97#ifdef __MVS__ 97#ifdef __MVS__
98# pragma map (fdopen , "\174\174FDOPEN") 98 #pragma map (fdopen , "\174\174FDOPEN")
99 FILE *fdopen(int, const char *); 99 FILE *fdopen(int, const char *);
100#endif 100#endif
101 101
diff --git a/gzlib.c b/gzlib.c
index bcef6c2..c9a82dc 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -18,21 +18,17 @@ local void gz_reset OF((gz_statep));
18local gzFile gz_open OF((const char *, int, const char *, int)); 18local gzFile gz_open OF((const char *, int, const char *, int));
19 19
20#if defined UNDER_CE && defined NO_ERRNO_H 20#if defined UNDER_CE && defined NO_ERRNO_H
21local char *strwinerror OF((DWORD error));
22 21
23# include <windows.h> 22/* Map the Windows error number in ERROR to a locale-dependent error message
23 string and return a pointer to it. Typically, the values for ERROR come
24 from GetLastError.
24 25
25/* Map the Windows error number in ERROR to a locale-dependent error 26 The string pointed to shall not be modified by the application, but may be
26 message string and return a pointer to it. Typically, the values 27 overwritten by a subsequent call to gz_strwinerror
27 for ERROR come from GetLastError.
28 28
29 The string pointed to shall not be modified by the application, 29 The gz_strwinerror function does not change the current setting of
30 but may be overwritten by a subsequent call to strwinerror 30 GetLastError. */
31 31char ZEXPORT *gz_strwinerror (error)
32 The strwinerror function does not change the current setting
33 of GetLastError. */
34
35local char *strwinerror (error)
36 DWORD error; 32 DWORD error;
37{ 33{
38 static char buf[1024]; 34 static char buf[1024];
@@ -82,18 +78,18 @@ local void gz_reset(state)
82 state->have = 0; /* no output data available */ 78 state->have = 0; /* no output data available */
83 state->eof = 0; /* not at end of file */ 79 state->eof = 0; /* not at end of file */
84 } 80 }
85 state->seek = 0; /* no seek request pending */ 81 state->seek = 0; /* no seek request pending */
86 gz_error(state, Z_OK, NULL); /* clear error */ 82 gz_error(state, Z_OK, NULL); /* clear error */
87 state->pos = 0; /* no uncompressed data yet */ 83 state->pos = 0; /* no uncompressed data yet */
88 state->strm.avail_in = 0; /* no input data yet */ 84 state->strm.avail_in = 0; /* no input data yet */
89} 85}
90 86
91/* Open a gzip file either by name or file descriptor. */ 87/* Open a gzip file either by name or file descriptor. */
92local gzFile gz_open(path, fd, mode, use64) 88local gzFile gz_open(path, fd, mode, large)
93 const char *path; 89 const char *path;
94 int fd; 90 int fd;
95 const char *mode; 91 const char *mode;
96 int use64; 92 int large;
97{ 93{
98 gz_statep state; 94 gz_statep state;
99 95
@@ -156,9 +152,13 @@ local gzFile gz_open(path, fd, mode, use64)
156 /* open the file with the appropriate mode (or just use fd) */ 152 /* open the file with the appropriate mode (or just use fd) */
157 state->fd = fd != -1 ? fd : 153 state->fd = fd != -1 ? fd :
158 open(path, 154 open(path,
155 (large ?
159#ifdef O_LARGEFILE 156#ifdef O_LARGEFILE
160 (use64 ? O_LARGEFILE : 0) | 157 O_LARGEFILE
158#else
159 0
161#endif 160#endif
161 : 0) |
162#ifdef O_BINARY 162#ifdef O_BINARY
163 O_BINARY | 163 O_BINARY |
164#endif 164#endif
@@ -214,13 +214,16 @@ gzFile ZEXPORT gzdopen(fd, mode)
214 int fd; 214 int fd;
215 const char *mode; 215 const char *mode;
216{ 216{
217 char path[46]; /* allow up to 128-bit integers, so don't worry -- 217 char path[46]; /* identifier for error messages */
218 the sprintf() is safe */
219 218
220 if (fd < 0) 219 if (fd < 0)
221 return NULL; 220 return NULL;
222 sprintf(path, "<fd:%d>", fd); /* for error messages */ 221#ifdef NO_snprintf
223 return gz_open(path, fd, mode, 1); 222 sprintf(path, "<fd:%d>", fd); /* big enough for 128-bit integers */
223#else
224 snprintf(path, sizeof(path), "<fd:%d>", fd);
225#endif
226 return gz_open(path, fd, mode, 0);
224} 227}
225 228
226/* -- see zlib.h -- */ 229/* -- see zlib.h -- */
@@ -325,7 +328,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
325 return -1; 328 return -1;
326 } 329 }
327 330
328 /* if reading, skip what's in output buffer (one less gz_getc() check) */ 331 /* if reading, skip what's in output buffer (one less gzgetc() check) */
329 if (state->mode == GZ_READ) { 332 if (state->mode == GZ_READ) {
330 n = state->have > offset ? (unsigned)offset : state->have; 333 n = state->have > offset ? (unsigned)offset : state->have;
331 state->have -= n; 334 state->have -= n;
@@ -422,10 +425,10 @@ int ZEXPORT gzeof(file)
422 425
423 /* get internal structure and check integrity */ 426 /* get internal structure and check integrity */
424 if (file == NULL) 427 if (file == NULL)
425 return -1; 428 return 0;
426 state = (gz_statep)file; 429 state = (gz_statep)file;
427 if (state->mode != GZ_READ && state->mode != GZ_WRITE) 430 if (state->mode != GZ_READ && state->mode != GZ_WRITE)
428 return -1; 431 return 0;
429 432
430 /* return end-of-file state */ 433 /* return end-of-file state */
431 return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; 434 return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0;
@@ -470,15 +473,15 @@ void ZEXPORT gzclearerr(file)
470} 473}
471 474
472/* Create an error message in allocated memory and set state->err and 475/* Create an error message in allocated memory and set state->err and
473 state->msg accordingly. Free any previous error message already there. Do 476 state->msg accordingly. Free any previous error message already there. Do
474 not try to free or allocate space if the error is Z_MEM_ERROR (out of 477 not try to free or allocate space if the error is Z_MEM_ERROR (out of
475 memory). Simply save the error message as a static string. If there is 478 memory). Simply save the error message as a static string. If there is an
476 an allocation failure constructing the error message, then convert the 479 allocation failure constructing the error message, then convert the error to
477 error to out of memory. */ 480 out of memory. */
478void ZEXPORT gz_error(state, err, msg) 481void ZEXPORT gz_error(state, err, msg)
479 gz_statep state; 482 gz_statep state;
480 int err; 483 int err;
481 char *msg; 484 const char *msg;
482{ 485{
483 /* free previously allocated message and clear */ 486 /* free previously allocated message and clear */
484 if (state->msg != NULL) { 487 if (state->msg != NULL) {
@@ -494,14 +497,14 @@ void ZEXPORT gz_error(state, err, msg)
494 497
495 /* for an out of memory error, save as static string */ 498 /* for an out of memory error, save as static string */
496 if (err == Z_MEM_ERROR) { 499 if (err == Z_MEM_ERROR) {
497 state->msg = msg; 500 state->msg = (char *)msg;
498 return; 501 return;
499 } 502 }
500 503
501 /* construct error message with path */ 504 /* construct error message with path */
502 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { 505 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
503 state->err = Z_MEM_ERROR; 506 state->err = Z_MEM_ERROR;
504 state->msg = "out of memory"; 507 state->msg = (char *)"out of memory";
505 return; 508 return;
506 } 509 }
507 strcpy(state->msg, state->path); 510 strcpy(state->msg, state->path);
diff --git a/gzread.c b/gzread.c
index 836c57c..74bdc7b 100644
--- a/gzread.c
+++ b/gzread.c
@@ -69,8 +69,8 @@ local int gz_avail(state)
69 (strm->avail_in == 0 ? -1 : \ 69 (strm->avail_in == 0 ? -1 : \
70 (strm->avail_in--, *(strm->next_in)++))) 70 (strm->avail_in--, *(strm->next_in)++)))
71 71
72/* Get a four-byte little-endian integer and return 0 on success and the 72/* Get a four-byte little-endian integer and return 0 on success and the value
73 value in *ret. Otherwise -1 is returned and *ret is not modified. */ 73 in *ret. Otherwise -1 is returned and *ret is not modified. */
74local int gz_next4(state, ret) 74local int gz_next4(state, ret)
75 gz_statep state; 75 gz_statep state;
76 unsigned long *ret; 76 unsigned long *ret;
@@ -93,7 +93,7 @@ local int gz_next4(state, ret)
93/* Look for gzip header, set up for inflate or copy. state->have must be zero. 93/* Look for gzip header, set up for inflate or copy. state->have must be zero.
94 If this is the first time in, allocate required memory. state->how will be 94 If this is the first time in, allocate required memory. state->how will be
95 left unchanged if there is no more input data available, will be set to 1 if 95 left unchanged if there is no more input data available, will be set to 1 if
96 there is no gzip header and direct copying will be performned, or it will be 96 there is no gzip header and direct copying will be performed, or it will be
97 set to 2 for decompression, and the gzip header will be skipped so that the 97 set to 2 for decompression, and the gzip header will be skipped so that the
98 next available input data is the raw deflate stream. If direct copying, 98 next available input data is the raw deflate stream. If direct copying,
99 then leftover input data from the input buffer will be copied to the output 99 then leftover input data from the input buffer will be copied to the output
@@ -190,6 +190,8 @@ local int gz_head(state)
190 NEXT(); 190 NEXT();
191 NEXT(); 191 NEXT();
192 } 192 }
193 /* an unexpected end of file is not checked for here -- it will be
194 noticed on the first request for uncompressed data */
193 195
194 /* set up for decompression */ 196 /* set up for decompression */
195 inflateReset(strm); 197 inflateReset(strm);
@@ -206,7 +208,7 @@ local int gz_head(state)
206 208
207 /* doing raw i/o, save start of raw data for seeking, copy any leftover 209 /* doing raw i/o, save start of raw data for seeking, copy any leftover
208 input to output -- this assumes that the output buffer is larger than 210 input to output -- this assumes that the output buffer is larger than
209 the input buffer */ 211 the input buffer, which also assures space for gzungetc() */
210 state->raw = state->pos; 212 state->raw = state->pos;
211 state->next = state->out; 213 state->next = state->out;
212 if (strm->avail_in) { 214 if (strm->avail_in) {
@@ -220,10 +222,10 @@ local int gz_head(state)
220 222
221/* Decompress from input to the provided next_out and avail_out in the state. 223/* Decompress from input to the provided next_out and avail_out in the state.
222 If the end of the compressed data is reached, then verify the gzip trailer 224 If the end of the compressed data is reached, then verify the gzip trailer
223 check value and length (modulo 2^32). state->have and state->next are 225 check value and length (modulo 2^32). state->have and state->next are set
224 set to point to the just decompressed data, and the crc is updated. If the 226 to point to the just decompressed data, and the crc is updated. If the
225 trailer is verified, state->how is reset to zero to look for the next gzip 227 trailer is verified, state->how is reset to zero to look for the next gzip
226 stream or raw data, once state->have is depleted. Returns 0 on success, -1 228 stream or raw data, once state->have is depleted. Returns 0 on success, -1
227 on failure. Failures may include invalid compressed data or a failed gzip 229 on failure. Failures may include invalid compressed data or a failed gzip
228 trailer verification. */ 230 trailer verification. */
229local int gz_decomp(state) 231local int gz_decomp(state)
@@ -372,6 +374,17 @@ int ZEXPORT gzread(file, buf, len)
372 if (state->mode != GZ_READ || state->err != Z_OK) 374 if (state->mode != GZ_READ || state->err != Z_OK)
373 return -1; 375 return -1;
374 376
377 /* since an int is returned, make sure len fits in one, otherwise return
378 with an error (this avoids the flaw in the interface) */
379 if ((int)len < 0) {
380 gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
381 return -1;
382 }
383
384 /* if len is zero, avoid unnecessary operations */
385 if (len == 0)
386 return 0;
387
375 /* process a skip request */ 388 /* process a skip request */
376 if (state->seek) { 389 if (state->seek) {
377 state->seek = 0; 390 state->seek = 0;
@@ -381,8 +394,7 @@ int ZEXPORT gzread(file, buf, len)
381 394
382 /* get len bytes to buf, or less than len if at the end */ 395 /* get len bytes to buf, or less than len if at the end */
383 got = 0; 396 got = 0;
384 while (len) { 397 do {
385
386 /* first just try copying data from the output buffer */ 398 /* first just try copying data from the output buffer */
387 if (state->have) { 399 if (state->have) {
388 n = state->have > len ? len : state->have; 400 n = state->have > len ? len : state->have;
@@ -402,6 +414,8 @@ int ZEXPORT gzread(file, buf, len)
402 if (gz_make(state) == -1) 414 if (gz_make(state) == -1)
403 return -1; 415 return -1;
404 continue; /* no progress yet -- go back to memcpy() above */ 416 continue; /* no progress yet -- go back to memcpy() above */
417 /* the copy above assures that we will leave with space in the
418 output buffer, allowing at least one gzungetc() to succeed */
405 } 419 }
406 420
407 /* large len -- read directly into user buffer */ 421 /* large len -- read directly into user buffer */
@@ -422,13 +436,13 @@ int ZEXPORT gzread(file, buf, len)
422 436
423 /* update progress */ 437 /* update progress */
424 len -= n; 438 len -= n;
425 buf += n; 439 buf = (char *)buf + n;
426 got += n; 440 got += n;
427 state->pos += n; 441 state->pos += n;
428 } 442 } while (len);
429 443
430 /* return number of bytes read into user buffer */ 444 /* return number of bytes read into user buffer (will fit in int) */
431 return (int)got; /* len had better fit in int -- interface flaw */ 445 return (int)got;
432} 446}
433 447
434/* -- see zlib.h -- */ 448/* -- see zlib.h -- */
@@ -448,7 +462,7 @@ int ZEXPORT gzgetc(file)
448 if (state->mode != GZ_READ || state->err != Z_OK) 462 if (state->mode != GZ_READ || state->err != Z_OK)
449 return -1; 463 return -1;
450 464
451 /* try output buffer */ 465 /* try output buffer (no need to check for skip request) */
452 if (state->have) { 466 if (state->have) {
453 state->have--; 467 state->have--;
454 state->pos++; 468 state->pos++;
@@ -496,9 +510,11 @@ int ZEXPORT gzungetc(c, file)
496 return c; 510 return c;
497 } 511 }
498 512
499 /* if no room, give up (must have already done a gz_ungetc()) */ 513 /* if no room, give up (must have already done a gzungetc()) */
500 if (state->have == (state->size << 1)) 514 if (state->have == (state->size << 1)) {
515 gz_error(state, Z_BUF_ERROR, "out of room to push characters");
501 return -1; 516 return -1;
517 }
502 518
503 /* slide output data if needed and insert byte before existing data */ 519 /* slide output data if needed and insert byte before existing data */
504 if (state->next == state->out) { 520 if (state->next == state->out) {
diff --git a/gzwrite.c b/gzwrite.c
index 65a13c3..c7c033a 100644
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -20,15 +20,6 @@ local int gz_init(state)
20 int ret; 20 int ret;
21 z_streamp strm = &(state->strm); 21 z_streamp strm = &(state->strm);
22 22
23 /* check version of zlib -- need 1.2.1 or later for gzip deflate() */
24#ifdef ZLIB_VERNUM
25 if (ZLIB_VERNUM < 0x1210)
26#endif
27 {
28 gz_error(state, Z_VERSION_ERROR, "need zlib 1.2.1 or later");
29 return -1;
30 }
31
32 /* allocate input and output buffers */ 23 /* allocate input and output buffers */
33 state->in = malloc(state->want); 24 state->in = malloc(state->want);
34 state->out = malloc(state->want); 25 state->out = malloc(state->want);
@@ -169,6 +160,17 @@ int ZEXPORT gzwrite(file, buf, len)
169 if (state->mode != GZ_WRITE || state->err != Z_OK) 160 if (state->mode != GZ_WRITE || state->err != Z_OK)
170 return -1; 161 return -1;
171 162
163 /* since an int is returned, make sure len fits in one, otherwise return
164 with an error (this avoids the flaw in the interface) */
165 if ((int)len < 0) {
166 gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
167 return -1;
168 }
169
170 /* if len is zero, avoid unnecessary operations */
171 if (len == 0)
172 return 0;
173
172 /* allocate memory if this is the first time through */ 174 /* allocate memory if this is the first time through */
173 if (state->size == 0 && gz_init(state) == -1) 175 if (state->size == 0 && gz_init(state) == -1)
174 return -1; 176 return -1;
@@ -183,7 +185,7 @@ int ZEXPORT gzwrite(file, buf, len)
183 /* for small len, copy to input buffer, otherwise compress directly */ 185 /* for small len, copy to input buffer, otherwise compress directly */
184 if (len < state->size) { 186 if (len < state->size) {
185 /* copy to input buffer, compress when full */ 187 /* copy to input buffer, compress when full */
186 while (len) { 188 do {
187 if (strm->avail_in == 0) 189 if (strm->avail_in == 0)
188 strm->next_in = state->in; 190 strm->next_in = state->in;
189 n = state->size - strm->avail_in; 191 n = state->size - strm->avail_in;
@@ -192,11 +194,11 @@ int ZEXPORT gzwrite(file, buf, len)
192 memcpy(strm->next_in + strm->avail_in, buf, n); 194 memcpy(strm->next_in + strm->avail_in, buf, n);
193 strm->avail_in += n; 195 strm->avail_in += n;
194 state->pos += n; 196 state->pos += n;
195 buf += n; 197 buf = (char *)buf + n;
196 len -= n; 198 len -= n;
197 if (len && gz_comp(state, Z_NO_FLUSH) == -1) 199 if (len && gz_comp(state, Z_NO_FLUSH) == -1)
198 return -1; 200 return -1;
199 } 201 } while (len);
200 } 202 }
201 else { 203 else {
202 /* consume whatever's left in the input buffer */ 204 /* consume whatever's left in the input buffer */
@@ -211,7 +213,7 @@ int ZEXPORT gzwrite(file, buf, len)
211 return -1; 213 return -1;
212 } 214 }
213 215
214 /* input was all buffered or compressed */ 216 /* input was all buffered or compressed (put will fit in int) */
215 return (int)put; 217 return (int)put;
216} 218}
217 219
@@ -332,12 +334,10 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
332 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 334 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
333 return 0; 335 return 0;
334 336
335 /* write out result of printf() */ 337 /* update buffer and position, defer compression until needed */
336 strm->avail_in = (unsigned)len; 338 strm->avail_in = (unsigned)len;
337 strm->next_in = state->in; 339 strm->next_in = state->in;
338 state->pos += len; 340 state->pos += len;
339 if (gz_comp(state, Z_NO_FLUSH) == -1)
340 return 0;
341 return len; 341 return len;
342} 342}
343 343
@@ -408,12 +408,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
408 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 408 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
409 return 0; 409 return 0;
410 410
411 /* write out result of printf() */ 411 /* update buffer and position, defer compression until needed */
412 strm->avail_in = (unsigned)len; 412 strm->avail_in = (unsigned)len;
413 strm->next_in = state->in; 413 strm->next_in = state->in;
414 state->pos += len; 414 state->pos += len;
415 if (gz_comp(state, Z_NO_FLUSH) == -1)
416 return 0;
417 return len; 415 return len;
418} 416}
419 417
diff --git a/inflate.c b/inflate.c
index e7f3cdd..40c0ec8 100644
--- a/inflate.c
+++ b/inflate.c
@@ -154,7 +154,7 @@ int windowBits;
154 /* set number of window bits, free window if different */ 154 /* set number of window bits, free window if different */
155 if (windowBits && (windowBits < 8 || windowBits > 15)) 155 if (windowBits && (windowBits < 8 || windowBits > 15))
156 return Z_STREAM_ERROR; 156 return Z_STREAM_ERROR;
157 if (state->wbits != windowBits && state->window != Z_NULL) { 157 if (state->wbits != (unsigned)windowBits && state->window != Z_NULL) {
158 ZFREE(strm, state->window); 158 ZFREE(strm, state->window);
159 state->window = Z_NULL; 159 state->window = Z_NULL;
160 } 160 }
@@ -1458,8 +1458,8 @@ int subvert;
1458 1458
1459 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1459 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1460 state = (struct inflate_state FAR *)strm->state; 1460 state = (struct inflate_state FAR *)strm->state;
1461#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1462 state->sane = !subvert; 1461 state->sane = !subvert;
1462#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1463 return Z_OK; 1463 return Z_OK;
1464#else 1464#else
1465 state->sane = 1; 1465 state->sane = 1;
diff --git a/inftrees.c b/inftrees.c
index 21f4dfb..ae89d97 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate_copyright[] = 11const char inflate_copyright[] =
12 " inflate 1.2.3.5 Copyright 1995-2010 Mark Adler "; 12 " inflate 1.2.3.6 Copyright 1995-2010 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot 15 in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 69, 199}; 65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 70};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
diff --git a/make_vms.com b/make_vms.com
index e3e8740..fc5fd0c 100644
--- a/make_vms.com
+++ b/make_vms.com
@@ -11,15 +11,18 @@ $!------------------------------------------------------------------------------
11$! Version history 11$! Version history
12$! 0.01 20060120 First version to receive a number 12$! 0.01 20060120 First version to receive a number
13$! 0.02 20061008 Adapt to new Makefile.in 13$! 0.02 20061008 Adapt to new Makefile.in
14$! 0.03 20091224 Add support for large file check
15$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite
14$! 16$!
15$ on error then goto err_exit 17$ on error then goto err_exit
16$! 18$!
17$!
18$! Just some general constants...
19$!
20$ true = 1 19$ true = 1
21$ false = 0 20$ false = 0
22$ tmpnam = "temp_" + f$getjpi("","pid") 21$ tmpnam = "temp_" + f$getjpi("","pid")
22$ tt = tmpnam + ".txt"
23$ tc = tmpnam + ".c"
24$ th = tmpnam + ".h"
25$ define/nolog tconfig 'th'
23$ its_decc = false 26$ its_decc = false
24$ its_vaxc = false 27$ its_vaxc = false
25$ its_gnuc = false 28$ its_gnuc = false
@@ -27,17 +30,25 @@ $ s_case = False
27$! 30$!
28$! Setup variables holding "config" information 31$! Setup variables holding "config" information
29$! 32$!
30$ Make = "" 33$ Make = ""
31$ name = "Zlib" 34$ name = "Zlib"
32$ version = "?.?.?" 35$ version = "?.?.?"
33$ v_string = "ZLIB_VERSION" 36$ v_string = "ZLIB_VERSION"
34$ v_file = "zlib.h" 37$ v_file = "zlib.h"
35$ ccopt = "" 38$ ccopt = ""
36$ lopts = "" 39$ lopts = ""
37$ dnsrl = "" 40$ dnsrl = ""
41$ aconf_in_file = "config.hin"
42$ conf_check_string = ""
38$ linkonly = false 43$ linkonly = false
39$ optfile = name + ".opt" 44$ optfile = name + ".opt"
40$ axp = f$getsyi("HW_MODEL").ge.1024 45$ libdefs = ""
46$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096
47$!
48$ whoami = f$parse(f$enviornment("Procedure"),,,,"NO_CONCEAL")
49$ mydef = F$parse(whoami,,,"DEVICE")
50$ mydir = f$parse(whoami,,,"DIRECTORY") - "]["
51$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type")
41$! 52$!
42$! Check for MMK/MMS 53$! Check for MMK/MMS
43$! 54$!
@@ -47,11 +58,16 @@ $!
47$! 58$!
48$ gosub find_version 59$ gosub find_version
49$! 60$!
61$ open/write topt tmp.opt
62$ open/write optf 'optfile'
63$!
50$ gosub check_opts 64$ gosub check_opts
51$! 65$!
52$! Look for the compiler used 66$! Look for the compiler used
53$! 67$!
54$ gosub check_compiler 68$ gosub check_compiler
69$ close topt
70$!
55$ if its_decc 71$ if its_decc
56$ then 72$ then
57$ ccopt = "/prefix=all" + ccopt 73$ ccopt = "/prefix=all" + ccopt
@@ -71,6 +87,49 @@ $ then
71$ if f$trnlnm("SYS").eqs."" then define sys sys$library: 87$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
72$ endif 88$ endif
73$! 89$!
90$! Build a fake configure input header
91$!
92$ open/write conf_hin config.hin
93$ write conf_hin "#undef _LARGEFILE64_SOURCE"
94$ close conf_hin
95$!
96$!
97$ i = 0
98$FIND_ACONF:
99$ fname = f$element(i,"#",aconf_in_file)
100$ if fname .eqs. "#" then goto AMISS_ERR
101$ if f$search(fname) .eqs. ""
102$ then
103$ i = i + 1
104$ goto find_aconf
105$ endif
106$ open/read/err=aconf_err aconf_in 'fname'
107$ open/write aconf zlibdefs.h
108$ACONF_LOOP:
109$ read/end_of_file=aconf_exit aconf_in line
110$ work = f$edit(line, "compress,trim")
111$ if f$extract(0,6,work) .nes. "#undef"
112$ then
113$ write aconf line
114$ else
115$ cdef = f$element(1," ",work)
116$ gosub check_config
117$ endif
118$ goto aconf_loop
119$ACONF_EXIT:
120$ write aconf "#define VMS 1"
121$ write aconf "#include <unistd.h>"
122$ write aconf "#include <unixio.h>"
123$ write aconf "#ifdef _LARGEFILE"
124$ write aconf "#define off64_t __off64_t"
125$ write aconf "#define fopen64 fopen"
126$ write aconf "#define fseeko64 fseeko"
127$ write aconf "#define lseek64 lseek"
128$ write aconf "#define ftello64 ftell"
129$ write aconf "#endif"
130$ close aconf_in
131$ close aconf
132$ delete 'th';*
74$! Build the thing plain or with mms 133$! Build the thing plain or with mms
75$! 134$!
76$ write sys$output "Compiling Zlib sources ..." 135$ write sys$output "Compiling Zlib sources ..."
@@ -86,15 +145,15 @@ $ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
86$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - 145$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
87 deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h 146 deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
88$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - 147$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" -
89 gzclose.c zlib.h zconf.h zlibdefs.h gzguts.h 148 gzclose.c zutil.h zlib.h zconf.h zlibdefs.h
90$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" - 149$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" -
91 gzio.c zutil.h zlib.h zconf.h zlibdefs.h 150 gzio.c zutil.h zlib.h zconf.h zlibdefs.h
92$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - 151$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" -
93 gzlib.c zlib.h zconf.h zlibdefs.h gzguts.h 152 gzlib.c zutil.h zlib.h zconf.h zlibdefs.h
94$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - 153$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" -
95 gzread.c zlib.h zconf.h zlibdefs.h gzguts.h 154 gzread.c zutil.h zlib.h zconf.h zlibdefs.h
96$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - 155$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" -
97 gzwrite.c zlib.h zconf.h zlibdefs.h gzguts.h 156 gzwrite.c zutil.h zlib.h zconf.h zlibdefs.h
98$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - 157$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" -
99 infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h 158 infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
100$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - 159$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
@@ -153,6 +212,14 @@ $ goto err_exit
153$ERR_EXIT: 212$ERR_EXIT:
154$ set message/facil/ident/sever/text 213$ set message/facil/ident/sever/text
155$ close/nolog optf 214$ close/nolog optf
215$ close/nolog topt
216$ close/nolog conf_hin
217$ close/nolog aconf_in
218$ close/nolog aconf
219$ close/nolog out
220$ close/nolog min
221$ close/nolog mod
222$ close/nolog h_in
156$ write sys$output "Exiting..." 223$ write sys$output "Exiting..."
157$ exit 2 224$ exit 2
158$! 225$!
@@ -200,61 +267,72 @@ $!------------------------------------------------------------------------------
200$! 267$!
201$! Check command line options and set symbols accordingly 268$! Check command line options and set symbols accordingly
202$! 269$!
270$!------------------------------------------------------------------------------
271$! Version history
272$! 0.01 20041206 First version to receive a number
273$! 0.02 20060126 Add new "HELP" target
203$ CHECK_OPTS: 274$ CHECK_OPTS:
204$ i = 1 275$ i = 1
205$ OPT_LOOP: 276$ OPT_LOOP:
206$ if i .lt. 9 277$ if i .lt. 9
207$ then 278$ then
208$ cparm = f$edit(p'i',"upcase") 279$ cparm = f$edit(p'i',"upcase")
209$ if cparm .eqs. "DEBUG" 280$!
210$ then 281$! Check if parameter actually contains something
211$ ccopt = ccopt + "/noopt/deb" 282$!
212$ lopts = lopts + "/deb" 283$ if f$edit(cparm,"trim") .nes. ""
213$ endif
214$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
215$ then
216$ start = f$locate("=",cparm) + 1
217$ len = f$length(cparm) - start
218$ ccopt = ccopt + f$extract(start,len,cparm)
219$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
220 then s_case = true
221$ endif
222$ if cparm .eqs. "LINK" then linkonly = true
223$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
224$ then
225$ start = f$locate("=",cparm) + 1
226$ len = f$length(cparm) - start
227$ lopts = lopts + f$extract(start,len,cparm)
228$ endif
229$ if f$locate("CC=",cparm) .lt. f$length(cparm)
230$ then 284$ then
231$ start = f$locate("=",cparm) + 1 285$ if cparm .eqs. "DEBUG"
232$ len = f$length(cparm) - start
233$ cc_com = f$extract(start,len,cparm)
234 if (cc_com .nes. "DECC") .and. -
235 (cc_com .nes. "VAXC") .and. -
236 (cc_com .nes. "GNUC")
237$ then 286$ then
238$ write sys$output "Unsupported compiler choice ''cc_com' ignored" 287$ ccopt = ccopt + "/noopt/deb"
239$ write sys$output "Use DECC, VAXC, or GNUC instead" 288$ lopts = lopts + "/deb"
240$ else
241$ if cc_com .eqs. "DECC" then its_decc = true
242$ if cc_com .eqs. "VAXC" then its_vaxc = true
243$ if cc_com .eqs. "GNUC" then its_gnuc = true
244$ endif 289$ endif
245$ endif 290$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
246$ if f$locate("MAKE=",cparm) .lt. f$length(cparm)
247$ then
248$ start = f$locate("=",cparm) + 1
249$ len = f$length(cparm) - start
250$ mmks = f$extract(start,len,cparm)
251$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
252$ then 291$ then
253$ make = mmks 292$ start = f$locate("=",cparm) + 1
254$ else 293$ len = f$length(cparm) - start
255$ write sys$output "Unsupported make choice ''mmks' ignored" 294$ ccopt = ccopt + f$extract(start,len,cparm)
256$ write sys$output "Use MMK or MMS instead" 295$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
296 then s_case = true
297$ endif
298$ if cparm .eqs. "LINK" then linkonly = true
299$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
300$ then
301$ start = f$locate("=",cparm) + 1
302$ len = f$length(cparm) - start
303$ lopts = lopts + f$extract(start,len,cparm)
304$ endif
305$ if f$locate("CC=",cparm) .lt. f$length(cparm)
306$ then
307$ start = f$locate("=",cparm) + 1
308$ len = f$length(cparm) - start
309$ cc_com = f$extract(start,len,cparm)
310 if (cc_com .nes. "DECC") .and. -
311 (cc_com .nes. "VAXC") .and. -
312 (cc_com .nes. "GNUC")
313$ then
314$ write sys$output "Unsupported compiler choice ''cc_com' ignored"
315$ write sys$output "Use DECC, VAXC, or GNUC instead"
316$ else
317$ if cc_com .eqs. "DECC" then its_decc = true
318$ if cc_com .eqs. "VAXC" then its_vaxc = true
319$ if cc_com .eqs. "GNUC" then its_gnuc = true
320$ endif
257$ endif 321$ endif
322$ if f$locate("MAKE=",cparm) .lt. f$length(cparm)
323$ then
324$ start = f$locate("=",cparm) + 1
325$ len = f$length(cparm) - start
326$ mmks = f$extract(start,len,cparm)
327$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
328$ then
329$ make = mmks
330$ else
331$ write sys$output "Unsupported make choice ''mmks' ignored"
332$ write sys$output "Use MMK or MMS instead"
333$ endif
334$ endif
335$ if cparm .eqs. "HELP" then gosub bhelp
258$ endif 336$ endif
259$ i = i + 1 337$ i = i + 1
260$ goto opt_loop 338$ goto opt_loop
@@ -267,6 +345,8 @@ $!
267$! Version history 345$! Version history
268$! 0.01 20040223 First version to receive a number 346$! 0.01 20040223 First version to receive a number
269$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists 347$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists
348$! 0.03 20060202 Extend handling of GNU C
349$! 0.04 20090402 Compaq -> hp
270$CHECK_COMPILER: 350$CHECK_COMPILER:
271$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) 351$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
272$ then 352$ then
@@ -282,15 +362,21 @@ $ then goto CC_ERR
282$ else 362$ else
283$ if its_decc 363$ if its_decc
284$ then 364$ then
285$ write sys$output "CC compiler check ... Compaq C" 365$ write sys$output "CC compiler check ... hp C"
286$ if f$trnlnm("decc$no_rooted_search_lists") .nes. "" 366$ if f$trnlnm("decc$no_rooted_search_lists") .nes. ""
287$ then 367$ then
288$ dnrsl = f$trnlnm("decc$no_rooted_search_lists") 368$ dnrsl = f$trnlnm("decc$no_rooted_search_lists")
289$ endif 369$ endif
290$ define decc$no_rooted_search_lists 1 370$ define/nolog decc$no_rooted_search_lists 1
291$ else 371$ else
292$ if its_vaxc then write sys$output "CC compiler check ... VAX C" 372$ if its_vaxc then write sys$output "CC compiler check ... VAX C"
293$ if its_gnuc then write sys$output "CC compiler check ... GNU C" 373$ if its_gnuc
374$ then
375$ write sys$output "CC compiler check ... GNU C"
376$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib"
377$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib"
378$ cc = "gcc"
379$ endif
294$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share" 380$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share"
295$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share" 381$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share"
296$ endif 382$ endif
@@ -310,7 +396,8 @@ $ deck
310# written by Martin P.J. Zinser 396# written by Martin P.J. Zinser
311# <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com> 397# <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com>
312 398
313OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj, infback.obj\ 399OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzio.obj, gzlib.obj\
400 gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\
314 deflate.obj, trees.obj, zutil.obj, inflate.obj, \ 401 deflate.obj, trees.obj, zutil.obj, inflate.obj, \
315 inftrees.obj, inffast.obj 402 inftrees.obj, inffast.obj
316 403
@@ -342,7 +429,11 @@ compress.obj : compress.c zlib.h zconf.h zlibdefs.h
342crc32.obj : crc32.c zutil.h zlib.h zconf.h zlibdefs.h 429crc32.obj : crc32.c zutil.h zlib.h zconf.h zlibdefs.h
343deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h 430deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
344example.obj : example.c zlib.h zconf.h zlibdefs.h 431example.obj : example.c zlib.h zconf.h zlibdefs.h
432gzclose.obj : gzclose.c zutil.h zlib.h zconf.h zlibdefs.h
345gzio.obj : gzio.c zutil.h zlib.h zconf.h zlibdefs.h 433gzio.obj : gzio.c zutil.h zlib.h zconf.h zlibdefs.h
434gzlib.obj : gzlib.c zutil.h zlib.h zconf.h zlibdefs.h
435gzread.obj : gzread.c zutil.h zlib.h zconf.h zlibdefs.h
436gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h zlibdefs.h
346inffast.obj : inffast.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inffast.h 437inffast.obj : inffast.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inffast.h
347inflate.obj : inflate.c zutil.h zlib.h zconf.h zlibdefs.h 438inflate.obj : inflate.c zutil.h zlib.h zconf.h zlibdefs.h
348inftrees.obj : inftrees.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h 439inftrees.obj : inftrees.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
@@ -416,6 +507,169 @@ $ close h_in
416$ return 507$ return
417$!------------------------------------------------------------------------------ 508$!------------------------------------------------------------------------------
418$! 509$!
510$CHECK_CONFIG:
511$!
512$ in_ldef = f$locate(cdef,libdefs)
513$ if (in_ldef .lt. f$length(libdefs))
514$ then
515$ write aconf "#define ''cdef' 1"
516$ libdefs = f$extract(0,in_ldef,libdefs) + -
517 f$extract(in_ldef + f$length(cdef) + 1, -
518 f$length(libdefs) - in_ldef - f$length(cdef) - 1, -
519 libdefs)
520$ else
521$ if (f$type('cdef') .eqs. "INTEGER")
522$ then
523$ write aconf "#define ''cdef' ", 'cdef'
524$ else
525$ if (f$type('cdef') .eqs. "STRING")
526$ then
527$ write aconf "#define ''cdef' ", """", '''cdef'', """"
528$ else
529$ gosub check_cc_def
530$ endif
531$ endif
532$ endif
533$ return
534$!------------------------------------------------------------------------------
535$!
536$! Check if this is a define relating to the properties of the C/C++
537$! compiler
538$!
539$ CHECK_CC_DEF:
540$ if (cdef .eqs. "_LARGEFILE64_SOURCE")
541$ then
542$ copy sys$input: 'tc'
543$ deck
544#include "tconfig"
545#define _LARGEFILE
546#include <stdio.h>
547
548int main(){
549FILE *fp;
550 fp = fopen("temp.txt","r");
551 fseeko(fp,1,SEEK_SET);
552 fclose(fp);
553}
554
555$ eod
556$ test_inv = false
557$ comm_h = false
558$ gosub cc_prop_check
559$ return
560$ endif
561$ write aconf "/* ", line, " */"
562$ return
563$!------------------------------------------------------------------------------
564$!
565$! Check for properties of C/C++ compiler
566$!
567$! Version history
568$! 0.01 20031020 First version to receive a number
569$! 0.02 20031022 Added logic for defines with value
570$! 0.03 20040309 Make sure local config file gets not deleted
571$! 0.04 20041230 Also write include for configure run
572$! 0.05 20050103 Add processing of "comment defines"
573$CC_PROP_CHECK:
574$ cc_prop = true
575$ is_need = false
576$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true)
577$ if f$search(th) .eqs. "" then create 'th'
578$ set message/nofac/noident/nosever/notext
579$ on error then continue
580$ cc 'tmpnam'
581$ if .not. ($status) then cc_prop = false
582$ on error then continue
583$! The headers might lie about the capabilities of the RTL
584$ link 'tmpnam',tmp.opt/opt
585$ if .not. ($status) then cc_prop = false
586$ set message/fac/ident/sever/text
587$ on error then goto err_exit
588$ delete/nolog 'tmpnam'.*;*/exclude='th'
589$ if (cc_prop .and. .not. is_need) .or. -
590 (.not. cc_prop .and. is_need)
591$ then
592$ write sys$output "Checking for ''cdef'... yes"
593$ if f$type('cdef_val'_yes) .nes. ""
594$ then
595$ if f$type('cdef_val'_yes) .eqs. "INTEGER" -
596 then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes)
597$ if f$type('cdef_val'_yes) .eqs. "STRING" -
598 then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes)
599$ else
600$ call write_config f$fao("#define !AS 1",cdef)
601$ endif
602$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. -
603 (cdef .eqs. "_LARGEFILE64_SOURCE") then -
604 call write_config f$string("#define _LARGEFILE 1")
605$ else
606$ write sys$output "Checking for ''cdef'... no"
607$ if (comm_h)
608$ then
609 call write_config f$fao("/* !AS */",line)
610$ else
611$ if f$type('cdef_val'_no) .nes. ""
612$ then
613$ if f$type('cdef_val'_no) .eqs. "INTEGER" -
614 then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no)
615$ if f$type('cdef_val'_no) .eqs. "STRING" -
616 then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no)
617$ else
618$ call write_config f$fao("#undef !AS",cdef)
619$ endif
620$ endif
621$ endif
622$ return
623$!------------------------------------------------------------------------------
624$!
625$! Check for properties of C/C++ compiler with multiple result values
626$!
627$! Version history
628$! 0.01 20040127 First version
629$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05
630$CC_MPROP_CHECK:
631$ cc_prop = true
632$ i = 1
633$ idel = 1
634$ MT_LOOP:
635$ if f$type(result_'i') .eqs. "STRING"
636$ then
637$ set message/nofac/noident/nosever/notext
638$ on error then continue
639$ cc 'tmpnam'_'i'
640$ if .not. ($status) then cc_prop = false
641$ on error then continue
642$! The headers might lie about the capabilities of the RTL
643$ link 'tmpnam'_'i',tmp.opt/opt
644$ if .not. ($status) then cc_prop = false
645$ set message/fac/ident/sever/text
646$ on error then goto err_exit
647$ delete/nolog 'tmpnam'_'i'.*;*
648$ if (cc_prop)
649$ then
650$ write sys$output "Checking for ''cdef'... ", mdef_'i'
651$ if f$type(mdef_'i') .eqs. "INTEGER" -
652 then call write_config f$fao("#define !AS !UL",cdef,mdef_'i')
653$ if f$type('cdef_val'_yes) .eqs. "STRING" -
654 then call write_config f$fao("#define !AS !AS",cdef,mdef_'i')
655$ goto msym_clean
656$ else
657$ i = i + 1
658$ goto mt_loop
659$ endif
660$ endif
661$ write sys$output "Checking for ''cdef'... no"
662$ call write_config f$fao("#undef !AS",cdef)
663$ MSYM_CLEAN:
664$ if (idel .le. msym_max)
665$ then
666$ delete/sym mdef_'idel'
667$ idel = idel + 1
668$ goto msym_clean
669$ endif
670$ return
671$!------------------------------------------------------------------------------
672$!
419$! Analyze Object files for OpenVMS AXP to extract Procedure and Data 673$! Analyze Object files for OpenVMS AXP to extract Procedure and Data
420$! information to build a symbol vector for a shareable image 674$! information to build a symbol vector for a shareable image
421$! All the "brains" of this logic was suggested by Hartmut Becker 675$! All the "brains" of this logic was suggested by Hartmut Becker
@@ -533,3 +787,16 @@ $ EXIT_AA:
533$ if V then set verify 787$ if V then set verify
534$ endsubroutine 788$ endsubroutine
535$!------------------------------------------------------------------------------ 789$!------------------------------------------------------------------------------
790$!
791$! Write configuration to both permanent and temporary config file
792$!
793$! Version history
794$! 0.01 20031029 First version to receive a number
795$!
796$WRITE_CONFIG: SUBROUTINE
797$ write aconf 'p1'
798$ open/append confh 'th'
799$ write confh 'p1'
800$ close confh
801$ENDSUBROUTINE
802$!------------------------------------------------------------------------------
diff --git a/old/zlib.html b/old/zlib.html
deleted file mode 100644
index 8c1b190..0000000
--- a/old/zlib.html
+++ /dev/null
@@ -1,971 +0,0 @@
1<html>
2<head>
3 <title>
4 zlib general purpose compression library version 1.1.4
5 </title>
6</head>
7<body bgcolor="White" text="Black" vlink="Red" alink="Navy" link="Red">
8<!-- background="zlibbg.gif" -->
9
10<h1> zlib 1.1.4 Manual </h1>
11<hr>
12<a name="Contents"><h2>Contents</h2>
13<ol type="I">
14<li> <a href="#Prologue">Prologue</a>
15<li> <a href="#Introduction">Introduction</a>
16<li> <a href="#Utility functions">Utility functions</a>
17<li> <a href="#Basic functions">Basic functions</a>
18<li> <a href="#Advanced functions">Advanced functions</a>
19<li> <a href="#Constants">Constants</a>
20<li> <a href="#struct z_stream_s">struct z_stream_s</a>
21<li> <a href="#Checksum functions">Checksum functions</a>
22<li> <a href="#Misc">Misc</a>
23</ol>
24<hr>
25<a name="Prologue"><h2> Prologue </h2>
26 'zlib' general purpose compression library version 1.1.4, March 11th, 2002
27 <p>
28 Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
29 <p>
30 This software is provided 'as-is', without any express or implied
31 warranty. In no event will the authors be held liable for any damages
32 arising from the use of this software.
33 <p>
34 Permission is granted to anyone to use this software for any purpose,
35 including commercial applications, and to alter it and redistribute it
36 freely, subject to the following restrictions:
37 <ol>
38 <li> The origin of this software must not be misrepresented ; you must not
39 claim that you wrote the original software. If you use this software
40 in a product, an acknowledgment in the product documentation would be
41 appreciated but is not required.
42 <li> Altered source versions must be plainly marked as such, and must not be
43 misrepresented as being the original software.
44 <li> This notice may not be removed or altered from any source distribution.
45 </ol>
46
47 <dl>
48 <dt>Jean-loup Gailly
49 <dd><a href="mailto:jloup@gzip.org">jloup@gzip.org</a>
50 <dt>Mark Adler
51 <dd><a href="mailto:madler@alumni.caltech.edu">madler@alumni.caltech.edu</a>
52 </dl>
53
54 The data format used by the zlib library is described by RFCs (Request for
55 Comments) 1950 to 1952 in the files
56 <a href="ftp://ds.internic.net/rfc/rfc1950.txt">
57 ftp://ds.internic.net/rfc/rfc1950.txt </a>
58 (zlib format),
59 <a href="ftp://ds.internic.net/rfc/rfc1951.txt">
60 rfc1951.txt </a>
61 (<a href="#deflate">deflate</a> format) and
62 <a href="ftp://ds.internic.net/rfc/rfc1952.txt">
63 rfc1952.txt </a>
64 (gzip format).
65 <p>
66 This manual is converted from zlib.h by
67 <a href="mailto:piaip@csie.ntu.edu.tw"> piaip </a>
68 <p>
69 Visit <a href="http://ftp.cdrom.com/pub/infozip/zlib/">
70 http://ftp.cdrom.com/pub/infozip/zlib/</a>
71 for the official zlib web page.
72 <p>
73
74<hr>
75<a name="Introduction"><h2> Introduction </h2>
76 The 'zlib' compression library provides in-memory compression and
77 decompression functions, including integrity checks of the uncompressed
78 data. This version of the library supports only one compression method
79 (deflation) but other algorithms will be added later and will have the same
80 stream interface.
81 <p>
82
83 Compression can be done in a single step if the buffers are large
84 enough (for example if an input file is mmap'ed), or can be done by
85 repeated calls of the compression function. In the latter case, the
86 application must provide more input and/or consume the output
87 (providing more output space) before each call.
88 <p>
89
90 The library also supports reading and writing files in gzip (.gz) format
91 with an interface similar to that of stdio.
92 <p>
93
94 The library does not install any signal handler. The decoder checks
95 the consistency of the compressed data, so the library should never
96 crash even in case of corrupted input.
97 <p>
98
99<hr>
100<a name="Utility functions"><h2> Utility functions </h2>
101 The following utility functions are implemented on top of the
102 <a href="#Basic functions">basic stream-oriented functions</a>.
103 To simplify the interface, some
104 default options are assumed (compression level and memory usage,
105 standard memory allocation functions). The source code of these
106 utility functions can easily be modified if you need special options.
107<h3> Function list </h3>
108<ul>
109<li> int <a href="#compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
110<li> int <a href="#compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);
111<li> int <a href="#uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
112<li> typedef voidp gzFile;
113<li> gzFile <a href="#gzopen">gzopen</a> (const char *path, const char *mode);
114<li> gzFile <a href="#gzdopen">gzdopen</a> (int fd, const char *mode);
115<li> int <a href="#gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);
116<li> int <a href="#gzread">gzread</a> (gzFile file, voidp buf, unsigned len);
117<li> int <a href="#gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);
118<li> int VA <a href="#gzprintf">gzprintf</a> (gzFile file, const char *format, ...);
119<li> int <a href="#gzputs">gzputs</a> (gzFile file, const char *s);
120<li> char * <a href="#gzgets">gzgets</a> (gzFile file, char *buf, int len);
121<li> int <a href="#gzputc">gzputc</a> (gzFile file, int c);
122<li> int <a href="#gzgetc">gzgetc</a> (gzFile file);
123<li> int <a href="#gzflush">gzflush</a> (gzFile file, int flush);
124<li> z_off_t <a href="#gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);
125<li> z_off_t <a href="#gztell">gztell</a> (gzFile file);
126<li> int <a href="#gzrewind">gzrewind</a> (gzFile file);
127<li> int <a href="#gzeof">gzeof</a> (gzFile file);
128<li> int <a href="#gzclose">gzclose</a> (gzFile file);
129<li> const char * <a href="#gzerror">gzerror</a> (gzFile file, int *errnum);
130</ul>
131<h3> Function description </h3>
132<dl>
133<font color="Blue"><dt> int <a name="compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
134<dd>
135 Compresses the source buffer into the destination buffer. sourceLen is
136 the byte length of the source buffer. Upon entry, destLen is the total
137 size of the destination buffer, which must be at least 0.1% larger than
138 sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
139 compressed buffer.<p>
140 This function can be used to <a href="#compress">compress</a> a whole file at once if the
141 input file is mmap'ed.<p>
142 <a href="#compress">compress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
143 enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
144 buffer.<p>
145
146<font color="Blue"><dt> int <a name="compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);</font>
147<dd>
148 Compresses the source buffer into the destination buffer. The level
149 parameter has the same meaning as in <a href="#deflateInit">deflateInit</a>. sourceLen is the byte
150 length of the source buffer. Upon entry, destLen is the total size of the
151 destination buffer, which must be at least 0.1% larger than sourceLen plus
152 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
153 <p>
154
155 <a href="#compress2">compress2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
156 memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer,
157 <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the level parameter is invalid.
158 <p>
159
160<font color="Blue"><dt> int <a name="uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
161<dd>
162 Decompresses the source buffer into the destination buffer. sourceLen is
163 the byte length of the source buffer. Upon entry, destLen is the total
164 size of the destination buffer, which must be large enough to hold the
165 entire uncompressed data. (The size of the uncompressed data must have
166 been saved previously by the compressor and transmitted to the decompressor
167 by some mechanism outside the scope of this compression library.)
168 Upon exit, destLen is the actual size of the compressed buffer. <p>
169 This function can be used to decompress a whole file at once if the
170 input file is mmap'ed.
171 <p>
172
173 <a href="#uncompress">uncompress</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
174 enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
175 buffer, or <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted.
176 <p>
177
178<dt> typedef voidp gzFile;
179<dd> <p>
180
181<font color="Blue"><dt> gzFile <a name="gzopen">gzopen</a> (const char *path, const char *mode);</font>
182<dd>
183 Opens a gzip (.gz) file for reading or writing. The mode parameter
184 is as in fopen ("rb" or "wb") but can also include a compression level
185 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
186 Huffman only compression as in "wb1h". (See the description
187 of <a href="#deflateInit2">deflateInit2</a> for more information about the strategy parameter.)
188 <p>
189
190 <a href="#gzopen">gzopen</a> can be used to read a file which is not in gzip format ; in this
191 case <a href="#gzread">gzread</a> will directly read from the file without decompression.
192 <p>
193
194 <a href="#gzopen">gzopen</a> returns NULL if the file could not be opened or if there was
195 insufficient memory to allocate the (de)compression <a href="#state">state</a> ; errno
196 can be checked to distinguish the two cases (if errno is zero, the
197 zlib error is <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a>).
198 <p>
199
200<font color="Blue"><dt> gzFile <a name="gzdopen">gzdopen</a> (int fd, const char *mode);</font>
201<dd>
202 <a href="#gzdopen">gzdopen</a>() associates a gzFile with the file descriptor fd. File
203 descriptors are obtained from calls like open, dup, creat, pipe or
204 fileno (in the file has been previously opened with fopen).
205 The mode parameter is as in <a href="#gzopen">gzopen</a>.
206 <p>
207 The next call of <a href="#gzclose">gzclose</a> on the returned gzFile will also close the
208 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
209 descriptor fd. If you want to keep fd open, use <a href="#gzdopen">gzdopen</a>(dup(fd), mode).
210 <p>
211 <a href="#gzdopen">gzdopen</a> returns NULL if there was insufficient memory to allocate
212 the (de)compression <a href="#state">state</a>.
213 <p>
214
215<font color="Blue"><dt> int <a name="gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);</font>
216<dd>
217 Dynamically update the compression level or strategy. See the description
218 of <a href="#deflateInit2">deflateInit2</a> for the meaning of these parameters.
219 <p>
220 <a href="#gzsetparams">gzsetparams</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the file was not
221 opened for writing.
222 <p>
223
224<font color="Blue"><dt> int <a name="gzread">gzread</a> (gzFile file, voidp buf, unsigned len);</font>
225<dd>
226 Reads the given number of uncompressed bytes from the compressed file.
227 If the input file was not in gzip format, <a href="#gzread">gzread</a> copies the given number
228 of bytes into the buffer.
229 <p>
230 <a href="#gzread">gzread</a> returns the number of uncompressed bytes actually read (0 for
231 end of file, -1 for error).
232 <p>
233
234<font color="Blue"><dt> int <a name="gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);</font>
235<dd>
236 Writes the given number of uncompressed bytes into the compressed file.
237 <a href="#gzwrite">gzwrite</a> returns the number of uncompressed bytes actually written
238 (0 in case of error).
239 <p>
240
241<font color="Blue"><dt> int VA <a name="gzprintf">gzprintf</a> (gzFile file, const char *format, ...);</font>
242<dd>
243 Converts, formats, and writes the args to the compressed file under
244 control of the format string, as in fprintf. <a href="#gzprintf">gzprintf</a> returns the number of
245 uncompressed bytes actually written (0 in case of error).
246 <p>
247
248<font color="Blue"><dt> int <a name="gzputs">gzputs</a> (gzFile file, const char *s);</font>
249<dd>
250 Writes the given null-terminated string to the compressed file, excluding
251 the terminating null character.
252 <p>
253 <a href="#gzputs">gzputs</a> returns the number of characters written, or -1 in case of error.
254 <p>
255
256<font color="Blue"><dt> char * <a name="gzgets">gzgets</a> (gzFile file, char *buf, int len);</font>
257<dd>
258 Reads bytes from the compressed file until len-1 characters are read, or
259 a newline character is read and transferred to buf, or an end-of-file
260 condition is encountered. The string is then terminated with a null
261 character.
262 <p>
263 <a href="#gzgets">gzgets</a> returns buf, or <a href="#Z_NULL">Z_NULL</a> in case of error.
264 <p>
265
266<font color="Blue"><dt> int <a name="gzputc">gzputc</a> (gzFile file, int c);</font>
267<dd>
268 Writes c, converted to an unsigned char, into the compressed file.
269 <a href="#gzputc">gzputc</a> returns the value that was written, or -1 in case of error.
270 <p>
271
272<font color="Blue"><dt> int <a name="gzgetc">gzgetc</a> (gzFile file);</font>
273<dd>
274 Reads one byte from the compressed file. <a href="#gzgetc">gzgetc</a> returns this byte
275 or -1 in case of end of file or error.
276 <p>
277
278<font color="Blue"><dt> int <a name="gzflush">gzflush</a> (gzFile file, int flush);</font>
279<dd>
280 Flushes all pending output into the compressed file. The parameter
281 flush is as in the <a href="#deflate">deflate</a>() function. The return value is the zlib
282 error number (see function <a href="#gzerror">gzerror</a> below). <a href="#gzflush">gzflush</a> returns <a href="#Z_OK">Z_OK</a> if
283 the flush parameter is <a href="#Z_FINISH">Z_FINISH</a> and all output could be flushed.
284 <p>
285 <a href="#gzflush">gzflush</a> should be called only when strictly necessary because it can
286 degrade compression.
287 <p>
288
289<font color="Blue"><dt> z_off_t <a name="gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);</font>
290<dd>
291 Sets the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
292 given compressed file. The offset represents a number of bytes in the
293 uncompressed data stream. The whence parameter is defined as in lseek(2);
294 the value SEEK_END is not supported.
295 <p>
296 If the file is opened for reading, this function is emulated but can be
297 extremely slow. If the file is opened for writing, only forward seeks are
298 supported ; <a href="#gzseek">gzseek</a> then compresses a sequence of zeroes up to the new
299 starting position.
300 <p>
301 <a href="#gzseek">gzseek</a> returns the resulting offset location as measured in bytes from
302 the beginning of the uncompressed stream, or -1 in case of error, in
303 particular if the file is opened for writing and the new starting position
304 would be before the current position.
305 <p>
306
307<font color="Blue"><dt> int <a name="gzrewind">gzrewind</a> (gzFile file);</font>
308<dd>
309 Rewinds the given file. This function is supported only for reading.
310 <p>
311 <a href="#gzrewind">gzrewind</a>(file) is equivalent to (int)<a href="#gzseek">gzseek</a>(file, 0L, SEEK_SET)
312 <p>
313
314<font color="Blue"><dt> z_off_t <a name="gztell">gztell</a> (gzFile file);</font>
315<dd>
316 Returns the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
317 given compressed file. This position represents a number of bytes in the
318 uncompressed data stream.
319 <p>
320
321 <a href="#gztell">gztell</a>(file) is equivalent to <a href="#gzseek">gzseek</a>(file, 0L, SEEK_CUR)
322 <p>
323
324<font color="Blue"><dt> int <a name="gzeof">gzeof</a> (gzFile file);</font>
325<dd>
326 Returns 1 when EOF has previously been detected reading the given
327 input stream, otherwise zero.
328 <p>
329
330<font color="Blue"><dt> int <a name="gzclose">gzclose</a> (gzFile file);</font>
331<dd>
332 Flushes all pending output if necessary, closes the compressed file
333 and deallocates all the (de)compression <a href="#state">state</a>. The return value is the zlib
334 error number (see function <a href="#gzerror">gzerror</a> below).
335 <p>
336
337<font color="Blue"><dt> const char * <a name="gzerror">gzerror</a> (gzFile file, int *errnum);</font>
338<dd>
339 Returns the error message for the last error which occurred on the
340 given compressed file. errnum is set to zlib error number. If an
341 error occurred in the file system and not in the compression library,
342 errnum is set to <a href="#Z_ERRNO">Z_ERRNO</a> and the application may consult errno
343 to get the exact error code.
344 <p>
345</dl>
346<hr>
347<a name="Basic functions"><h2> Basic functions </h2>
348<h3> Function list </h3>
349<ul>
350<li> const char * <a href="#zlibVersion">zlibVersion</a> (void);
351<li> int <a href="#deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);
352<li> int <a href="#deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
353<li> int <a href="#deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
354<li> int <a href="#inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);
355<li> int <a href="#inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
356<li> int <a href="#inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
357</ul>
358
359<h3> Function description </h3>
360<dl>
361<font color="Blue"><dt> const char * <a name="zlibVersion">zlibVersion</a> (void);</font>
362<dd> The application can compare <a href="#zlibVersion">zlibVersion</a> and ZLIB_VERSION for consistency.
363 If the first character differs, the library code actually used is
364 not compatible with the zlib.h header file used by the application.
365 This check is automatically made by <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a>.
366 <p>
367
368<font color="Blue"><dt> int <a name="deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);</font>
369<dd>
370 Initializes the internal stream <a href="#state">state</a> for compression. The fields
371 <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by the caller.
372 If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#deflateInit">deflateInit</a> updates them to
373 use default allocation functions.
374 <p>
375
376 The compression level must be <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a>, or between 0 and 9:
377 1 gives best speed, 9 gives best compression, 0 gives no compression at
378 all (the input data is simply copied a block at a time).
379 <p>
380
381 <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> requests a default compromise between speed and
382 compression (currently equivalent to level 6).
383 <p>
384
385 <a href="#deflateInit">deflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
386 enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if level is not a valid compression level,
387 <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version (<a href="#zlib_version">zlib_version</a>) is incompatible
388 with the version assumed by the caller (ZLIB_VERSION).
389 <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit">deflateInit</a> does not
390 perform any compression: this will be done by <a href="#deflate">deflate</a>().
391 <p>
392
393<font color="Blue"><dt> int <a name="deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
394<dd>
395 <a href="#deflate">deflate</a> compresses as much data as possible, and stops when the input
396 buffer becomes empty or the output buffer becomes full. It may introduce some
397 output latency (reading input without producing any output) except when
398 forced to flush.<p>
399
400 The detailed semantics are as follows. <a href="#deflate">deflate</a> performs one or both of the
401 following actions:
402
403 <ul>
404 <li> Compress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
405 accordingly. If not all input can be processed (because there is not
406 enough room in the output buffer), <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> are updated and
407 processing will resume at this point for the next call of <a href="#deflate">deflate</a>().
408
409 <li>
410 Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a>
411 accordingly. This action is forced if the parameter flush is non zero.
412 Forcing flush frequently degrades the compression ratio, so this parameter
413 should be set only when necessary (in interactive applications).
414 Some output may be provided even if flush is not set.
415 </ul> <p>
416
417 Before the call of <a href="#deflate">deflate</a>(), the application should ensure that at least
418 one of the actions is possible, by providing more input and/or consuming
419 more output, and updating <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> accordingly ; <a href="#avail_out">avail_out</a>
420 should never be zero before the call. The application can consume the
421 compressed output when it wants, for example when the output buffer is full
422 (<a href="#avail_out">avail_out</a> == 0), or after each call of <a href="#deflate">deflate</a>(). If <a href="#deflate">deflate</a> returns <a href="#Z_OK">Z_OK</a>
423 and with zero <a href="#avail_out">avail_out</a>, it must be called again after making room in the
424 output buffer because there might be more output pending.
425 <p>
426
427 If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, all pending output is
428 flushed to the output buffer and the output is aligned on a byte boundary, so
429 that the decompressor can get all input data available so far. (In particular
430 <a href="#avail_in">avail_in</a> is zero after the call if enough output space has been provided
431 before the call.) Flushing may degrade compression for some compression
432 algorithms and so it should be used only when necessary.
433 <p>
434
435 If flush is set to <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>, all output is flushed as with
436 <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, and the compression <a href="#state">state</a> is reset so that decompression can
437 restart from this point if previous compressed data has been damaged or if
438 random access is desired. Using <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a> too often can seriously degrade
439 the compression.
440 <p>
441
442 If <a href="#deflate">deflate</a> returns with <a href="#avail_out">avail_out</a> == 0, this function must be called again
443 with the same value of the flush parameter and more output space (updated
444 <a href="#avail_out">avail_out</a>), until the flush is complete (<a href="#deflate">deflate</a> returns with non-zero
445 <a href="#avail_out">avail_out</a>).
446 <p>
447
448 If the parameter flush is set to <a href="#Z_FINISH">Z_FINISH</a>, pending input is processed,
449 pending output is flushed and <a href="#deflate">deflate</a> returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> if there
450 was enough output space ; if <a href="#deflate">deflate</a> returns with <a href="#Z_OK">Z_OK</a>, this function must be
451 called again with <a href="#Z_FINISH">Z_FINISH</a> and more output space (updated <a href="#avail_out">avail_out</a>) but no
452 more input data, until it returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. After
453 <a href="#deflate">deflate</a> has returned <a href="#Z_STREAM_END">Z_STREAM_END</a>, the only possible operations on the
454 stream are <a href="#deflateReset">deflateReset</a> or <a href="#deflateEnd">deflateEnd</a>.
455 <p>
456
457 <a href="#Z_FINISH">Z_FINISH</a> can be used immediately after <a href="#deflateInit">deflateInit</a> if all the compression
458 is to be done in a single step. In this case, <a href="#avail_out">avail_out</a> must be at least
459 0.1% larger than <a href="#avail_in">avail_in</a> plus 12 bytes. If <a href="#deflate">deflate</a> does not return
460 <a href="#Z_STREAM_END">Z_STREAM_END</a>, then it must be called again as described above.
461 <p>
462
463 <a href="#deflate">deflate</a>() sets strm-&gt <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all input read
464 so far (that is, <a href="#total_in">total_in</a> bytes).
465 <p>
466
467 <a href="#deflate">deflate</a>() may update <a href="#data_type">data_type</a> if it can make a good guess about
468 the input data type (<a href="#Z_ASCII">Z_ASCII</a> or <a href="#Z_BINARY">Z_BINARY</a>). In doubt, the data is considered
469 binary. This field is only for information purposes and does not affect
470 the compression algorithm in any manner.
471 <p>
472
473 <a href="#deflate">deflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input
474 processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if all input has been
475 consumed and all output has been produced (only when flush is set to
476 <a href="#Z_FINISH">Z_FINISH</a>), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a> was inconsistent (for example
477 if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible
478 (for example <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> was zero).
479 <p>
480
481<font color="Blue"><dt> int <a name="deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
482<dd>
483 All dynamically allocated data structures for this stream are freed.
484 This function discards any unprocessed input and does not flush any
485 pending output.
486 <p>
487
488 <a href="#deflateEnd">deflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the
489 stream <a href="#state">state</a> was inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the stream was freed
490 prematurely (some input or output was discarded). In the error case,
491 <a href="#msg">msg</a> may be set but then points to a static string (which must not be
492 deallocated).
493 <p>
494
495<font color="Blue"><dt> int <a name="inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
496<dd>
497 Initializes the internal stream <a href="#state">state</a> for decompression. The fields
498 <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
499 the caller. If <a href="#next_in">next_in</a> is not <a href="#Z_NULL">Z_NULL</a> and <a href="#avail_in">avail_in</a> is large enough (the exact
500 value depends on the compression method), <a href="#inflateInit">inflateInit</a> determines the
501 compression method from the zlib header and allocates all data structures
502 accordingly ; otherwise the allocation will be deferred to the first call of
503 <a href="#inflate">inflate</a>. If <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> are set to <a href="#Z_NULL">Z_NULL</a>, <a href="#inflateInit">inflateInit</a> updates them to
504 use default allocation functions.
505 <p>
506
507 <a href="#inflateInit">inflateInit</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
508 memory, <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version is incompatible with the
509 version assumed by the caller. <a href="#msg">msg</a> is set to null if there is no error
510 message. <a href="#inflateInit">inflateInit</a> does not perform any decompression apart from reading
511 the zlib header if present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and
512 <a href="#avail_in">avail_in</a> may be modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)
513 <p>
514
515<font color="Blue"><dt> int <a name="inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
516<dd>
517 <a href="#inflate">inflate</a> decompresses as much data as possible, and stops when the input
518 buffer becomes empty or the output buffer becomes full. It may some
519 introduce some output latency (reading input without producing any output)
520 except when forced to flush.
521 <p>
522
523 The detailed semantics are as follows. <a href="#inflate">inflate</a> performs one or both of the
524 following actions:
525
526 <ul>
527 <li> Decompress more input starting at <a href="#next_in">next_in</a> and update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a>
528 accordingly. If not all input can be processed (because there is not
529 enough room in the output buffer), <a href="#next_in">next_in</a> is updated and processing
530 will resume at this point for the next call of <a href="#inflate">inflate</a>().
531
532 <li> Provide more output starting at <a href="#next_out">next_out</a> and update <a href="#next_out">next_out</a> and
533 <a href="#avail_out">avail_out</a> accordingly. <a href="#inflate">inflate</a>() provides as much output as possible,
534 until there is no more input data or no more space in the output buffer
535 (see below about the flush parameter).
536 </ul> <p>
537
538 Before the call of <a href="#inflate">inflate</a>(), the application should ensure that at least
539 one of the actions is possible, by providing more input and/or consuming
540 more output, and updating the next_* and avail_* values accordingly.
541 The application can consume the uncompressed output when it wants, for
542 example when the output buffer is full (<a href="#avail_out">avail_out</a> == 0), or after each
543 call of <a href="#inflate">inflate</a>(). If <a href="#inflate">inflate</a> returns <a href="#Z_OK">Z_OK</a> and with zero <a href="#avail_out">avail_out</a>, it
544 must be called again after making room in the output buffer because there
545 might be more output pending.
546 <p>
547
548 If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, <a href="#inflate">inflate</a> flushes as much
549 output as possible to the output buffer. The flushing behavior of <a href="#inflate">inflate</a> is
550 not specified for values of the flush parameter other than <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>
551 and <a href="#Z_FINISH">Z_FINISH</a>, but the current implementation actually flushes as much output
552 as possible anyway.
553 <p>
554
555 <a href="#inflate">inflate</a>() should normally be called until it returns <a href="#Z_STREAM_END">Z_STREAM_END</a> or an
556 error. However if all decompression is to be performed in a single step
557 (a single call of <a href="#inflate">inflate</a>), the parameter flush should be set to
558 <a href="#Z_FINISH">Z_FINISH</a>. In this case all pending input is processed and all pending
559 output is flushed ; <a href="#avail_out">avail_out</a> must be large enough to hold all the
560 uncompressed data. (The size of the uncompressed data may have been saved
561 by the compressor for this purpose.) The next operation on this stream must
562 be <a href="#inflateEnd">inflateEnd</a> to deallocate the decompression <a href="#state">state</a>. The use of <a href="#Z_FINISH">Z_FINISH</a>
563 is never required, but can be used to inform <a href="#inflate">inflate</a> that a faster routine
564 may be used for the single <a href="#inflate">inflate</a>() call.
565 <p>
566
567 If a preset dictionary is needed at this point (see <a href="#inflateSetDictionary">inflateSetDictionary</a>
568 below), <a href="#inflate">inflate</a> sets strm-<a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of the
569 dictionary chosen by the compressor and returns <a href="#Z_NEED_DICT">Z_NEED_DICT</a> ; otherwise
570 it sets strm-&gt <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all output produced
571 so far (that is, <a href="#total_out">total_out</a> bytes) and returns <a href="#Z_OK">Z_OK</a>, <a href="#Z_STREAM_END">Z_STREAM_END</a> or
572 an error code as described below. At the end of the stream, <a href="#inflate">inflate</a>()
573 checks that its computed <a href="#adler32">adler32</a> checksum is equal to that saved by the
574 compressor and returns <a href="#Z_STREAM_END">Z_STREAM_END</a> only if the checksum is correct.
575 <p>
576
577 <a href="#inflate">inflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed
578 or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if the end of the compressed data has
579 been reached and all uncompressed output has been produced, <a href="#Z_NEED_DICT">Z_NEED_DICT</a> if a
580 preset dictionary is needed at this point, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was
581 corrupted (input stream not conforming to the zlib format or incorrect
582 <a href="#adler32">adler32</a> checksum), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent
583 (for example if <a href="#next_in">next_in</a> or <a href="#next_out">next_out</a> was NULL), <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
584 enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible or if there was not
585 enough room in the output buffer when <a href="#Z_FINISH">Z_FINISH</a> is used. In the <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a>
586 case, the application may then call <a href="#inflateSync">inflateSync</a> to look for a good
587 compression block.
588 <p>
589
590<font color="Blue"><dt> int <a name="inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
591<dd>
592 All dynamically allocated data structures for this stream are freed.
593 This function discards any unprocessed input and does not flush any
594 pending output.
595 <p>
596
597 <a href="#inflateEnd">inflateEnd</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream <a href="#state">state</a>
598 was inconsistent. In the error case, <a href="#msg">msg</a> may be set but then points to a
599 static string (which must not be deallocated).
600</dl>
601<hr>
602<a name="Advanced functions"><h2> Advanced functions </h2>
603 The following functions are needed only in some special applications.
604<h3> Function list </h3>
605<ul>
606<li> int <a href="#deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm,
607<li> int <a href="#deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
608<li> int <a href="#deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);
609<li> int <a href="#deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
610<li> int <a href="#deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);
611<li> int <a href="#inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);
612<li> int <a href="#inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
613<li> int <a href="#inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);
614<li> int <a href="#inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
615
616</ul>
617<h3> Function description </h3>
618<dl>
619<font color="Blue"><dt> int <a name="deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int method, int windowBits, int memLevel, int strategy);</font>
620
621<dd> This is another version of <a href="#deflateInit">deflateInit</a> with more compression options. The
622 fields <a href="#next_in">next_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by
623 the caller.<p>
624
625 The method parameter is the compression method. It must be <a href="#Z_DEFLATED">Z_DEFLATED</a> in
626 this version of the library.<p>
627
628 The windowBits parameter is the base two logarithm of the window size
629 (the size of the history buffer). It should be in the range 8..15 for this
630 version of the library. Larger values of this parameter result in better
631 compression at the expense of memory usage. The default value is 15 if
632 <a href="#deflateInit">deflateInit</a> is used instead.<p>
633
634 The memLevel parameter specifies how much memory should be allocated
635 for the internal compression <a href="#state">state</a>. memLevel=1 uses minimum memory but
636 is slow and reduces compression ratio ; memLevel=9 uses maximum memory
637 for optimal speed. The default value is 8. See zconf.h for total memory
638 usage as a function of windowBits and memLevel.<p>
639
640 The strategy parameter is used to tune the compression algorithm. Use the
641 value <a href="#Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> for normal data, <a href="#Z_FILTERED">Z_FILTERED</a> for data produced by a
642 filter (or predictor), or <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> to force Huffman encoding only (no
643 string match). Filtered data consists mostly of small values with a
644 somewhat random distribution. In this case, the compression algorithm is
645 tuned to <a href="#compress">compress</a> them better. The effect of <a href="#Z_FILTERED">Z_FILTERED</a> is to force more
646 Huffman coding and less string matching ; it is somewhat intermediate
647 between Z_DEFAULT and <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a>. The strategy parameter only affects
648 the compression ratio but not the correctness of the compressed output even
649 if it is not set appropriately.<p>
650
651 <a href="#deflateInit2">deflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
652 memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as an invalid
653 method). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit2">deflateInit2</a> does
654 not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
655
656<font color="Blue"><dt> int <a name="deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
657<dd>
658 Initializes the compression dictionary from the given byte sequence
659 without producing any compressed output. This function must be called
660 immediately after <a href="#deflateInit">deflateInit</a>, <a href="#deflateInit2">deflateInit2</a> or <a href="#deflateReset">deflateReset</a>, before any
661 call of <a href="#deflate">deflate</a>. The compressor and decompressor must use exactly the same
662 dictionary (see <a href="#inflateSetDictionary">inflateSetDictionary</a>).<p>
663
664 The dictionary should consist of strings (byte sequences) that are likely
665 to be encountered later in the data to be compressed, with the most commonly
666 used strings preferably put towards the end of the dictionary. Using a
667 dictionary is most useful when the data to be compressed is short and can be
668 predicted with good accuracy ; the data can then be compressed better than
669 with the default empty dictionary.<p>
670
671 Depending on the size of the compression data structures selected by
672 <a href="#deflateInit">deflateInit</a> or <a href="#deflateInit2">deflateInit2</a>, a part of the dictionary may in effect be
673 discarded, for example if the dictionary is larger than the window size in
674 <a href="#deflate">deflate</a> or deflate2. Thus the strings most likely to be useful should be
675 put at the end of the dictionary, not at the front.<p>
676
677 Upon return of this function, strm-&gt <a href="#adler">adler</a> is set to the Adler32 value
678 of the dictionary ; the decompressor may later use this value to determine
679 which dictionary has been used by the compressor. (The Adler32 value
680 applies to the whole dictionary even if only a subset of the dictionary is
681 actually used by the compressor.)<p>
682
683 <a href="#deflateSetDictionary">deflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
684 parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
685 inconsistent (for example if <a href="#deflate">deflate</a> has already been called for this stream
686 or if the compression method is bsort). <a href="#deflateSetDictionary">deflateSetDictionary</a> does not
687 perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
688
689<font color="Blue"><dt> int <a name="deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);</font>
690<dd>
691 Sets the destination stream as a complete copy of the source stream.<p>
692
693 This function can be useful when several compression strategies will be
694 tried, for example when there are several ways of pre-processing the input
695 data with a filter. The streams that will be discarded should then be freed
696 by calling <a href="#deflateEnd">deflateEnd</a>. Note that <a href="#deflateCopy">deflateCopy</a> duplicates the internal
697 compression <a href="#state">state</a> which can be quite large, so this strategy is slow and
698 can consume lots of memory.<p>
699
700 <a href="#deflateCopy">deflateCopy</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not
701 enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent
702 (such as <a href="#zalloc">zalloc</a> being NULL). <a href="#msg">msg</a> is left unchanged in both source and
703 destination.<p>
704
705<font color="Blue"><dt> int <a name="deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
706<dd> This function is equivalent to <a href="#deflateEnd">deflateEnd</a> followed by <a href="#deflateInit">deflateInit</a>,
707 but does not free and reallocate all the internal compression <a href="#state">state</a>.
708 The stream will keep the same compression level and any other attributes
709 that may have been set by <a href="#deflateInit2">deflateInit2</a>.<p>
710
711 <a href="#deflateReset">deflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
712 stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).<p>
713
714<font color="Blue"><dt> int <a name="deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);</font>
715<dd>
716 Dynamically update the compression level and compression strategy. The
717 interpretation of level and strategy is as in <a href="#deflateInit2">deflateInit2</a>. This can be
718 used to switch between compression and straight copy of the input data, or
719 to switch to a different kind of input data requiring a different
720 strategy. If the compression level is changed, the input available so far
721 is compressed with the old level (and may be flushed); the new level will
722 take effect only at the next call of <a href="#deflate">deflate</a>().<p>
723
724 Before the call of <a href="#deflateParams">deflateParams</a>, the stream <a href="#state">state</a> must be set as for
725 a call of <a href="#deflate">deflate</a>(), since the currently available input may have to
726 be compressed and flushed. In particular, strm-&gt <a href="#avail_out">avail_out</a> must be
727 non-zero.<p>
728
729 <a href="#deflateParams">deflateParams</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
730 stream <a href="#state">state</a> was inconsistent or if a parameter was invalid, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
731 if strm-&gtavail_out was zero.<p>
732
733<font color="Blue"><dt> int <a name="inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);</font>
734
735<dd> This is another version of <a href="#inflateInit">inflateInit</a> with an extra parameter. The
736 fields <a href="#next_in">next_in</a>, <a href="#avail_in">avail_in</a>, <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized
737 before by the caller.<p>
738
739 The windowBits parameter is the base two logarithm of the maximum window
740 size (the size of the history buffer). It should be in the range 8..15 for
741 this version of the library. The default value is 15 if <a href="#inflateInit">inflateInit</a> is used
742 instead. If a compressed stream with a larger window size is given as
743 input, <a href="#inflate">inflate</a>() will return with the error code <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> instead of
744 trying to allocate a larger window.<p>
745
746 <a href="#inflateInit2">inflateInit2</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a> if there was not enough
747 memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as a negative
748 memLevel). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit2">inflateInit2</a>
749 does not perform any decompression apart from reading the zlib header if
750 present: this will be done by <a href="#inflate">inflate</a>(). (So <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> may be
751 modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)<p>
752
753<font color="Blue"><dt> int <a name="inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
754<dd>
755 Initializes the decompression dictionary from the given uncompressed byte
756 sequence. This function must be called immediately after a call of <a href="#inflate">inflate</a>
757 if this call returned <a href="#Z_NEED_DICT">Z_NEED_DICT</a>. The dictionary chosen by the compressor
758 can be determined from the Adler32 value returned by this call of
759 <a href="#inflate">inflate</a>. The compressor and decompressor must use exactly the same
760 dictionary (see <a href="#deflateSetDictionary">deflateSetDictionary</a>).<p>
761
762 <a href="#inflateSetDictionary">inflateSetDictionary</a> returns <a href="#Z_OK">Z_OK</a> if success, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a
763 parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
764 inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the given dictionary doesn't match the
765 expected one (incorrect Adler32 value). <a href="#inflateSetDictionary">inflateSetDictionary</a> does not
766 perform any decompression: this will be done by subsequent calls of
767 <a href="#inflate">inflate</a>().<p>
768
769<font color="Blue"><dt> int <a name="inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
770
771<dd> Skips invalid compressed data until a full flush point (see above the
772 description of <a href="#deflate">deflate</a> with <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>) can be found, or until all
773 available input is skipped. No output is provided.<p>
774
775 <a href="#inflateSync">inflateSync</a> returns <a href="#Z_OK">Z_OK</a> if a full flush point has been found, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
776 if no more input was provided, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if no flush point has been found,
777 or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent. In the success
778 case, the application may save the current current value of <a href="#total_in">total_in</a> which
779 indicates where valid compressed data was found. In the error case, the
780 application may repeatedly call <a href="#inflateSync">inflateSync</a>, providing more input each time,
781 until success or end of the input data.<p>
782
783<font color="Blue"><dt> int <a name="inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
784<dd>
785 This function is equivalent to <a href="#inflateEnd">inflateEnd</a> followed by <a href="#inflateInit">inflateInit</a>,
786 but does not free and reallocate all the internal decompression <a href="#state">state</a>.
787 The stream will keep attributes that may have been set by <a href="#inflateInit2">inflateInit2</a>.
788 <p>
789
790 <a href="#inflateReset">inflateReset</a> returns <a href="#Z_OK">Z_OK</a> if success, or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source
791 stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).
792 <p>
793</dl>
794
795<hr>
796<a name="Checksum functions"><h2> Checksum functions </h2>
797 These functions are not related to compression but are exported
798 anyway because they might be useful in applications using the
799 compression library.
800<h3> Function list </h3>
801<ul>
802<li> uLong <a href="#adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);
803<li> uLong <a href="#crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);
804</ul>
805<h3> Function description </h3>
806<dl>
807<font color="Blue"><dt> uLong <a name="adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);</font>
808<dd>
809 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
810 return the updated checksum. If buf is NULL, this function returns
811 the required initial value for the checksum.
812 <p>
813 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
814 much faster. Usage example:
815 <pre>
816
817 uLong <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
818
819 while (read_buffer(buffer, length) != EOF) {
820 <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(<a href="#adler">adler</a>, buffer, length);
821 }
822 if (<a href="#adler">adler</a> != original_adler) error();
823 </pre>
824
825<font color="Blue"><dt> uLong <a name="crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</font>
826<dd>
827 Update a running crc with the bytes buf[0..len-1] and return the updated
828 crc. If buf is NULL, this function returns the required initial value
829 for the crc. Pre- and post-conditioning (one's complement) is performed
830 within this function so it shouldn't be done by the application.
831 Usage example:
832 <pre>
833
834 uLong crc = <a href="#crc32">crc32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
835
836 while (read_buffer(buffer, length) != EOF) {
837 crc = <a href="#crc32">crc32</a>(crc, buffer, length);
838 }
839 if (crc != original_crc) error();
840 </pre>
841</dl>
842<hr>
843<a name="struct z_stream_s"><h2> struct z_stream_s </h2>
844<font color="Blue">
845<a name="z_stream_s">
846<pre>
847typedef struct z_stream_s {
848 Bytef *<a name="next_in">next_in</a>; /* next input byte */
849 uInt <a name="avail_in">avail_in</a>; /* number of bytes available at <a href="#next_in">next_in</a> */
850 uLong <a name="total_in">total_in</a>; /* total nb of input bytes read so far */
851
852 Bytef *<a name="next_out">next_out</a>; /* next output byte should be put there */
853 uInt <a name="avail_out">avail_out</a>; /* remaining free space at <a href="#next_out">next_out</a> */
854 uLong <a name="total_out">total_out</a>; /* total nb of bytes output so far */
855
856 char *<a name="msg">msg</a>; /* last error message, NULL if no error */
857 struct internal_state FAR *<a name="state">state</a>; /* not visible by applications */
858
859 alloc_func <a name="zalloc">zalloc</a>; /* used to allocate the internal <a href="#state">state</a> */
860 free_func <a name="zfree">zfree</a>; /* used to free the internal <a href="#state">state</a> */
861 voidpf <a name="opaque">opaque</a>; /* private data object passed to <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> */
862
863 int <a name="data_type">data_type</a>; /* best guess about the data type: ascii or binary */
864 uLong <a name="adler">adler</a>; /* <a href="#adler32">adler32</a> value of the uncompressed data */
865 uLong <a name="reserved">reserved</a>; /* <a href="#reserved">reserved</a> for future use */
866} <a href="#z_stream_s">z_stream</a> ;
867
868typedef <a href="#z_stream_s">z_stream</a> FAR * <a name="z_streamp">z_streamp</a>; ÿ
869</pre>
870</font>
871 The application must update <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> when <a href="#avail_in">avail_in</a> has
872 dropped to zero. It must update <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> when <a href="#avail_out">avail_out</a>
873 has dropped to zero. The application must initialize <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and
874 <a href="#opaque">opaque</a> before calling the init function. All other fields are set by the
875 compression library and must not be updated by the application. <p>
876
877 The <a href="#opaque">opaque</a> value provided by the application will be passed as the first
878 parameter for calls of <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a>. This can be useful for custom
879 memory management. The compression library attaches no meaning to the
880 <a href="#opaque">opaque</a> value. <p>
881
882 <a href="#zalloc">zalloc</a> must return <a href="#Z_NULL">Z_NULL</a> if there is not enough memory for the object.
883 If zlib is used in a multi-threaded application, <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be
884 thread safe. <p>
885
886 On 16-bit systems, the functions <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be able to allocate
887 exactly 65536 bytes, but will not be required to allocate more than this
888 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
889 pointers returned by <a href="#zalloc">zalloc</a> for objects of exactly 65536 bytes *must*
890 have their offset normalized to zero. The default allocation function
891 provided by this library ensures this (see zutil.c). To reduce memory
892 requirements and avoid any allocation of 64K objects, at the expense of
893 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
894 <p>
895
896 The fields <a href="#total_in">total_in</a> and <a href="#total_out">total_out</a> can be used for statistics or
897 progress reports. After compression, <a href="#total_in">total_in</a> holds the total size of
898 the uncompressed data and may be saved for use in the decompressor
899 (particularly if the decompressor wants to decompress everything in
900 a single step). <p>
901
902<hr>
903<a name="Constants"><h2> Constants </h2>
904<font color="Blue">
905<pre>
906#define <a name="Z_NO_FLUSH">Z_NO_FLUSH</a> 0
907#define <a name="Z_PARTIAL_FLUSH">Z_PARTIAL_FLUSH</a> 1
908 /* will be removed, use <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> instead */
909#define <a name="Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> 2
910#define <a name="Z_FULL_FLUSH">Z_FULL_FLUSH</a> 3
911#define <a name="Z_FINISH">Z_FINISH</a> 4
912/* Allowed flush values ; see <a href="#deflate">deflate</a>() below for details */
913
914#define <a name="Z_OK">Z_OK</a> 0
915#define <a name="Z_STREAM_END">Z_STREAM_END</a> 1
916#define <a name="Z_NEED_DICT">Z_NEED_DICT</a> 2
917#define <a name="Z_ERRNO">Z_ERRNO</a> (-1)
918#define <a name="Z_STREAM_ERROR">Z_STREAM_ERROR</a> (-2)
919#define <a name="Z_DATA_ERROR">Z_DATA_ERROR</a> (-3)
920#define <a name="Z_MEM_ERROR">Z_MEM_ERROR</a> (-4)
921#define <a name="Z_BUF_ERROR">Z_BUF_ERROR</a> (-5)
922#define <a name="Z_VERSION_ERROR">Z_VERSION_ERROR</a> (-6)
923/* Return codes for the compression/decompression functions. Negative
924 * values are errors, positive values are used for special but normal events.
925 */
926
927#define <a name="Z_NO_COMPRESSION">Z_NO_COMPRESSION</a> 0
928#define <a name="Z_BEST_SPEED">Z_BEST_SPEED</a> 1
929#define <a name="Z_BEST_COMPRESSION">Z_BEST_COMPRESSION</a> 9
930#define <a name="Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> (-1)
931/* compression levels */
932
933#define <a name="Z_FILTERED">Z_FILTERED</a> 1
934#define <a name="Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> 2
935#define <a name="Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> 0
936/* compression strategy ; see <a href="#deflateInit2">deflateInit2</a>() below for details */
937
938#define <a name="Z_BINARY">Z_BINARY</a> 0
939#define <a name="Z_ASCII">Z_ASCII</a> 1
940#define <a name="Z_UNKNOWN">Z_UNKNOWN</a> 2
941/* Possible values of the <a href="#data_type">data_type</a> field */
942
943#define <a name="Z_DEFLATED">Z_DEFLATED</a> 8
944/* The <a href="#deflate">deflate</a> compression method (the only one supported in this version) */
945
946#define <a name="Z_NULL">Z_NULL</a> 0 /* for initializing <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a>, <a href="#opaque">opaque</a> */
947
948#define <a name="zlib_version">zlib_version</a> <a href="#zlibVersion">zlibVersion</a>()
949/* for compatibility with versions less than 1.0.2 */
950</pre>
951</font>
952
953<hr>
954<a name="Misc"><h2> Misc </h2>
955 <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a> are macros to allow checking the zlib version
956 and the compiler's view of <a href="#z_stream_s">z_stream</a>.
957 <p>
958 Other functions:
959 <dl>
960 <font color="Blue"><dt> const char * <a name="zError">zError</a> (int err);</font>
961 <font color="Blue"><dt> int <a name="inflateSyncPoint">inflateSyncPoint</a> (<a href="#z_streamp">z_streamp</a> z);</font>
962 <font color="Blue"><dt> const uLongf * <a name="get_crc_table">get_crc_table</a> (void);</font>
963 </dl>
964 <hr>
965 <font size="-1">
966 Last update: Wed Oct 13 20:42:34 1999<br>
967 piapi@csie.ntu.edu.tw
968 </font>
969
970</body>
971</html>
diff --git a/qnx/package.qpg b/qnx/package.qpg
index a4872b0..384bcf2 100644
--- a/qnx/package.qpg
+++ b/qnx/package.qpg
@@ -25,10 +25,10 @@
25 <QPG:Files> 25 <QPG:Files>
26 <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/> 26 <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
27 <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/> 27 <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
28 <QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" user="root:bin" permission="644"/> 28 <QPG:Add file="../libz.so.1.2.3.6" install="/opt/lib/" user="root:bin" permission="644"/>
29 <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.5"/> 29 <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.6"/>
30 <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.5"/> 30 <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.6"/>
31 <QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" component="slib"/> 31 <QPG:Add file="../libz.so.1.2.3.6" install="/opt/lib/" component="slib"/>
32 </QPG:Files> 32 </QPG:Files>
33 33
34 <QPG:PackageFilter> 34 <QPG:PackageFilter>
@@ -63,7 +63,7 @@
63 </QPM:ProductDescription> 63 </QPM:ProductDescription>
64 64
65 <QPM:ReleaseDescription> 65 <QPM:ReleaseDescription>
66 <QPM:ReleaseVersion>1.2.3.5</QPM:ReleaseVersion> 66 <QPM:ReleaseVersion>1.2.3.6</QPM:ReleaseVersion>
67 <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency> 67 <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
68 <QPM:ReleaseStability>Stable</QPM:ReleaseStability> 68 <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
69 <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor> 69 <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
diff --git a/uncompr.c b/uncompr.c
index b59e3d0..ad98be3 100644
--- a/uncompr.c
+++ b/uncompr.c
@@ -1,5 +1,5 @@
1/* uncompr.c -- decompress a memory buffer 1/* uncompr.c -- decompress a memory buffer
2 * Copyright (C) 1995-2003 Jean-loup Gailly. 2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
@@ -16,8 +16,6 @@
16 been saved previously by the compressor and transmitted to the decompressor 16 been saved previously by the compressor and transmitted to the decompressor
17 by some mechanism outside the scope of this compression library.) 17 by some mechanism outside the scope of this compression library.)
18 Upon exit, destLen is the actual size of the compressed buffer. 18 Upon exit, destLen is the actual size of the compressed buffer.
19 This function can be used to decompress a whole file at once if the
20 input file is mmap'ed.
21 19
22 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 20 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
23 enough memory, Z_BUF_ERROR if there was not enough room in the output 21 enough memory, Z_BUF_ERROR if there was not enough room in the output
diff --git a/zconf.h b/zconf.h
index 5a2d1ef..0661898 100644
--- a/zconf.h
+++ b/zconf.h
@@ -382,19 +382,19 @@ typedef uLong FAR uLongf;
382 382
383/* MVS linker does not support external names larger than 8 bytes */ 383/* MVS linker does not support external names larger than 8 bytes */
384#if defined(__MVS__) 384#if defined(__MVS__)
385# pragma map(deflateInit_,"DEIN") 385 #pragma map(deflateInit_,"DEIN")
386# pragma map(deflateInit2_,"DEIN2") 386 #pragma map(deflateInit2_,"DEIN2")
387# pragma map(deflateEnd,"DEEND") 387 #pragma map(deflateEnd,"DEEND")
388# pragma map(deflateBound,"DEBND") 388 #pragma map(deflateBound,"DEBND")
389# pragma map(inflateInit_,"ININ") 389 #pragma map(inflateInit_,"ININ")
390# pragma map(inflateInit2_,"ININ2") 390 #pragma map(inflateInit2_,"ININ2")
391# pragma map(inflateEnd,"INEND") 391 #pragma map(inflateEnd,"INEND")
392# pragma map(inflateSync,"INSY") 392 #pragma map(inflateSync,"INSY")
393# pragma map(inflateSetDictionary,"INSEDI") 393 #pragma map(inflateSetDictionary,"INSEDI")
394# pragma map(compressBound,"CMBND") 394 #pragma map(compressBound,"CMBND")
395# pragma map(inflate_table,"INTABL") 395 #pragma map(inflate_table,"INTABL")
396# pragma map(inflate_fast,"INFA") 396 #pragma map(inflate_fast,"INFA")
397# pragma map(inflate_copyright,"INCOPY") 397 #pragma map(inflate_copyright,"INCOPY")
398#endif 398#endif
399 399
400#endif /* ZCONF_H */ 400#endif /* ZCONF_H */
diff --git a/zlib.3 b/zlib.3
index db44e9d..802db88 100644
--- a/zlib.3
+++ b/zlib.3
@@ -1,4 +1,4 @@
1.TH ZLIB 3 "8 January 2010" 1.TH ZLIB 3 "17 January 2010"
2.SH NAME 2.SH NAME
3zlib \- compression/decompression library 3zlib \- compression/decompression library
4.SH SYNOPSIS 4.SH SYNOPSIS
@@ -17,7 +17,6 @@ but other algorithms will be added later
17and will have the same stream interface. 17and will have the same stream interface.
18.LP 18.LP
19Compression can be done in a single step if the buffers are large enough 19Compression can be done in a single step if the buffers are large enough
20(for example if an input file is mmap'ed),
21or can be done by repeated calls of the compression function. 20or can be done by repeated calls of the compression function.
22In the latter case, 21In the latter case,
23the application must provide more input and/or consume the output 22the application must provide more input and/or consume the output
@@ -133,8 +132,8 @@ before asking for help.
133Send questions and/or comments to zlib@gzip.org, 132Send questions and/or comments to zlib@gzip.org,
134or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). 133or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
135.SH AUTHORS 134.SH AUTHORS
136Version 1.2.3.5 135Version 1.2.3.6
137Copyright (C) 1995-2009 Jean-loup Gailly (jloup@gzip.org) 136Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
138and Mark Adler (madler@alumni.caltech.edu). 137and Mark Adler (madler@alumni.caltech.edu).
139.LP 138.LP
140This software is provided "as-is," 139This software is provided "as-is,"
diff --git a/zlib.h b/zlib.h
index 11d6902..a751b30 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.2.3.5, Jan 8th, 2010 2 version 1.2.3.6, Jan 17th, 2010
3 3
4 Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
5 5
@@ -37,44 +37,43 @@
37extern "C" { 37extern "C" {
38#endif 38#endif
39 39
40#define ZLIB_VERSION "1.2.3.5" 40#define ZLIB_VERSION "1.2.3.6"
41#define ZLIB_VERNUM 0x1235 41#define ZLIB_VERNUM 0x1236
42#define ZLIB_VER_MAJOR 1 42#define ZLIB_VER_MAJOR 1
43#define ZLIB_VER_MINOR 2 43#define ZLIB_VER_MINOR 2
44#define ZLIB_VER_REVISION 3 44#define ZLIB_VER_REVISION 3
45 45
46/* 46/*
47 The 'zlib' compression library provides in-memory compression and 47 The 'zlib' compression library provides in-memory compression and
48 decompression functions, including integrity checks of the uncompressed 48 decompression functions, including integrity checks of the uncompressed data.
49 data. This version of the library supports only one compression method 49 This version of the library supports only one compression method (deflation)
50 (deflation) but other algorithms will be added later and will have the same 50 but other algorithms will be added later and will have the same stream
51 stream interface. 51 interface.
52 52
53 Compression can be done in a single step if the buffers are large 53 Compression can be done in a single step if the buffers are large enough,
54 enough (for example if an input file is mmap'ed), or can be done by 54 or can be done by repeated calls of the compression function. In the latter
55 repeated calls of the compression function. In the latter case, the 55 case, the application must provide more input and/or consume the output
56 application must provide more input and/or consume the output
57 (providing more output space) before each call. 56 (providing more output space) before each call.
58 57
59 The compressed data format used by default by the in-memory functions is 58 The compressed data format used by default by the in-memory functions is
60 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 59 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61 around a deflate stream, which is itself documented in RFC 1951. 60 around a deflate stream, which is itself documented in RFC 1951.
62 61
63 The library also supports reading and writing files in gzip (.gz) format 62 The library also supports reading and writing files in gzip (.gz) format
64 with an interface similar to that of stdio using the functions that start 63 with an interface similar to that of stdio using the functions that start
65 with "gz". The gzip format is different from the zlib format. gzip is a 64 with "gz". The gzip format is different from the zlib format. gzip is a
66 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 65 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67 66
68 This library can optionally read and write gzip streams in memory as well. 67 This library can optionally read and write gzip streams in memory as well.
69 68
70 The zlib format was designed to be compact and fast for use in memory 69 The zlib format was designed to be compact and fast for use in memory
71 and on communications channels. The gzip format was designed for single- 70 and on communications channels. The gzip format was designed for single-
72 file compression on file systems, has a larger header than zlib to maintain 71 file compression on file systems, has a larger header than zlib to maintain
73 directory information, and uses a different, slower check method than zlib. 72 directory information, and uses a different, slower check method than zlib.
74 73
75 The library does not install any signal handler. The decoder checks 74 The library does not install any signal handler. The decoder checks
76 the consistency of the compressed data, so the library should never 75 the consistency of the compressed data, so the library should never crash
77 crash even in case of corrupted input. 76 even in case of corrupted input.
78*/ 77*/
79 78
80typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 79typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
@@ -129,35 +128,34 @@ typedef struct gz_header_s {
129typedef gz_header FAR *gz_headerp; 128typedef gz_header FAR *gz_headerp;
130 129
131/* 130/*
132 The application must update next_in and avail_in when avail_in has 131 The application must update next_in and avail_in when avail_in has dropped
133 dropped to zero. It must update next_out and avail_out when avail_out 132 to zero. It must update next_out and avail_out when avail_out has dropped
134 has dropped to zero. The application must initialize zalloc, zfree and 133 to zero. The application must initialize zalloc, zfree and opaque before
135 opaque before calling the init function. All other fields are set by the 134 calling the init function. All other fields are set by the compression
136 compression library and must not be updated by the application. 135 library and must not be updated by the application.
137 136
138 The opaque value provided by the application will be passed as the first 137 The opaque value provided by the application will be passed as the first
139 parameter for calls of zalloc and zfree. This can be useful for custom 138 parameter for calls of zalloc and zfree. This can be useful for custom
140 memory management. The compression library attaches no meaning to the 139 memory management. The compression library attaches no meaning to the
141 opaque value. 140 opaque value.
142 141
143 zalloc must return Z_NULL if there is not enough memory for the object. 142 zalloc must return Z_NULL if there is not enough memory for the object.
144 If zlib is used in a multi-threaded application, zalloc and zfree must be 143 If zlib is used in a multi-threaded application, zalloc and zfree must be
145 thread safe. 144 thread safe.
146 145
147 On 16-bit systems, the functions zalloc and zfree must be able to allocate 146 On 16-bit systems, the functions zalloc and zfree must be able to allocate
148 exactly 65536 bytes, but will not be required to allocate more than this 147 exactly 65536 bytes, but will not be required to allocate more than this if
149 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, 148 the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
150 pointers returned by zalloc for objects of exactly 65536 bytes *must* 149 returned by zalloc for objects of exactly 65536 bytes *must* have their
151 have their offset normalized to zero. The default allocation function 150 offset normalized to zero. The default allocation function provided by this
152 provided by this library ensures this (see zutil.c). To reduce memory 151 library ensures this (see zutil.c). To reduce memory requirements and avoid
153 requirements and avoid any allocation of 64K objects, at the expense of 152 any allocation of 64K objects, at the expense of compression ratio, compile
154 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). 153 the library with -DMAX_WBITS=14 (see zconf.h).
155 154
156 The fields total_in and total_out can be used for statistics or 155 The fields total_in and total_out can be used for statistics or progress
157 progress reports. After compression, total_in holds the total size of 156 reports. After compression, total_in holds the total size of the
158 the uncompressed data and may be saved for use in the decompressor 157 uncompressed data and may be saved for use in the decompressor (particularly
159 (particularly if the decompressor wants to decompress everything in 158 if the decompressor wants to decompress everything in a single step).
160 a single step).
161*/ 159*/
162 160
163 /* constants */ 161 /* constants */
@@ -180,8 +178,8 @@ typedef gz_header FAR *gz_headerp;
180#define Z_MEM_ERROR (-4) 178#define Z_MEM_ERROR (-4)
181#define Z_BUF_ERROR (-5) 179#define Z_BUF_ERROR (-5)
182#define Z_VERSION_ERROR (-6) 180#define Z_VERSION_ERROR (-6)
183/* Return codes for the compression/decompression functions. Negative 181/* Return codes for the compression/decompression functions. Negative values
184 * values are errors, positive values are used for special but normal events. 182 * are errors, positive values are used for special but normal events.
185 */ 183 */
186 184
187#define Z_NO_COMPRESSION 0 185#define Z_NO_COMPRESSION 0
@@ -215,63 +213,63 @@ typedef gz_header FAR *gz_headerp;
215 213
216ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 214ZEXTERN const char * ZEXPORT zlibVersion OF((void));
217/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 215/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
218 If the first character differs, the library code actually used is 216 If the first character differs, the library code actually used is not
219 not compatible with the zlib.h header file used by the application. 217 compatible with the zlib.h header file used by the application. This check
220 This check is automatically made by deflateInit and inflateInit. 218 is automatically made by deflateInit and inflateInit.
221 */ 219 */
222 220
223/* 221/*
224ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 222ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
225 223
226 Initializes the internal stream state for compression. The fields 224 Initializes the internal stream state for compression. The fields
227 zalloc, zfree and opaque must be initialized before by the caller. 225 zalloc, zfree and opaque must be initialized before by the caller. If
228 If zalloc and zfree are set to Z_NULL, deflateInit updates them to 226 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
229 use default allocation functions. 227 allocation functions.
230 228
231 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 229 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
232 1 gives best speed, 9 gives best compression, 0 gives no compression at 230 1 gives best speed, 9 gives best compression, 0 gives no compression at all
233 all (the input data is simply copied a block at a time). 231 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
234 Z_DEFAULT_COMPRESSION requests a default compromise between speed and 232 requests a default compromise between speed and compression (currently
235 compression (currently equivalent to level 6). 233 equivalent to level 6).
236 234
237 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not 235 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
238 enough memory, Z_STREAM_ERROR if level is not a valid compression level, 236 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
239 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 237 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
240 with the version assumed by the caller (ZLIB_VERSION). 238 with the version assumed by the caller (ZLIB_VERSION). msg is set to null
241 msg is set to null if there is no error message. deflateInit does not 239 if there is no error message. deflateInit does not perform any compression:
242 perform any compression: this will be done by deflate(). 240 this will be done by deflate().
243*/ 241*/
244 242
245 243
246ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 244ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
247/* 245/*
248 deflate compresses as much data as possible, and stops when the input 246 deflate compresses as much data as possible, and stops when the input
249 buffer becomes empty or the output buffer becomes full. It may introduce some 247 buffer becomes empty or the output buffer becomes full. It may introduce
250 output latency (reading input without producing any output) except when 248 some output latency (reading input without producing any output) except when
251 forced to flush. 249 forced to flush.
252 250
253 The detailed semantics are as follows. deflate performs one or both of the 251 The detailed semantics are as follows. deflate performs one or both of the
254 following actions: 252 following actions:
255 253
256 - Compress more input starting at next_in and update next_in and avail_in 254 - Compress more input starting at next_in and update next_in and avail_in
257 accordingly. If not all input can be processed (because there is not 255 accordingly. If not all input can be processed (because there is not
258 enough room in the output buffer), next_in and avail_in are updated and 256 enough room in the output buffer), next_in and avail_in are updated and
259 processing will resume at this point for the next call of deflate(). 257 processing will resume at this point for the next call of deflate().
260 258
261 - Provide more output starting at next_out and update next_out and avail_out 259 - Provide more output starting at next_out and update next_out and avail_out
262 accordingly. This action is forced if the parameter flush is non zero. 260 accordingly. This action is forced if the parameter flush is non zero.
263 Forcing flush frequently degrades the compression ratio, so this parameter 261 Forcing flush frequently degrades the compression ratio, so this parameter
264 should be set only when necessary (in interactive applications). 262 should be set only when necessary (in interactive applications). Some
265 Some output may be provided even if flush is not set. 263 output may be provided even if flush is not set.
266 264
267 Before the call of deflate(), the application should ensure that at least 265 Before the call of deflate(), the application should ensure that at least
268 one of the actions is possible, by providing more input and/or consuming 266 one of the actions is possible, by providing more input and/or consuming more
269 more output, and updating avail_in or avail_out accordingly; avail_out 267 output, and updating avail_in or avail_out accordingly; avail_out should
270 should never be zero before the call. The application can consume the 268 never be zero before the call. The application can consume the compressed
271 compressed output when it wants, for example when the output buffer is full 269 output when it wants, for example when the output buffer is full (avail_out
272 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK 270 == 0), or after each call of deflate(). If deflate returns Z_OK and with
273 and with zero avail_out, it must be called again after making room in the 271 zero avail_out, it must be called again after making room in the output
274 output buffer because there might be more output pending. 272 buffer because there might be more output pending.
275 273
276 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 274 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
277 decide how much data to accumulate before producing output, in order to 275 decide how much data to accumulate before producing output, in order to
@@ -279,12 +277,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
279 277
280 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 278 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
281 flushed to the output buffer and the output is aligned on a byte boundary, so 279 flushed to the output buffer and the output is aligned on a byte boundary, so
282 that the decompressor can get all input data available so far. (In particular 280 that the decompressor can get all input data available so far. (In
283 avail_in is zero after the call if enough output space has been provided 281 particular avail_in is zero after the call if enough output space has been
284 before the call.) Flushing may degrade compression for some compression 282 provided before the call.) Flushing may degrade compression for some
285 algorithms and so it should be used only when necessary. This completes the 283 compression algorithms and so it should be used only when necessary. This
286 current deflate block and follows it with an empty stored block that is three 284 completes the current deflate block and follows it with an empty stored block
287 bits plus filler bits to the next byte, followed by four bytes (00 00 ff ff). 285 that is three bits plus filler bits to the next byte, followed by four bytes
286 (00 00 ff ff).
288 287
289 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 288 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
290 output buffer, but the output is not aligned to a byte boundary. All of the 289 output buffer, but the output is not aligned to a byte boundary. All of the
@@ -306,43 +305,43 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
306 If flush is set to Z_FULL_FLUSH, all output is flushed as with 305 If flush is set to Z_FULL_FLUSH, all output is flushed as with
307 Z_SYNC_FLUSH, and the compression state is reset so that decompression can 306 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
308 restart from this point if previous compressed data has been damaged or if 307 restart from this point if previous compressed data has been damaged or if
309 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 308 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
310 compression. 309 compression.
311 310
312 If deflate returns with avail_out == 0, this function must be called again 311 If deflate returns with avail_out == 0, this function must be called again
313 with the same value of the flush parameter and more output space (updated 312 with the same value of the flush parameter and more output space (updated
314 avail_out), until the flush is complete (deflate returns with non-zero 313 avail_out), until the flush is complete (deflate returns with non-zero
315 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 314 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
316 avail_out is greater than six to avoid repeated flush markers due to 315 avail_out is greater than six to avoid repeated flush markers due to
317 avail_out == 0 on return. 316 avail_out == 0 on return.
318 317
319 If the parameter flush is set to Z_FINISH, pending input is processed, 318 If the parameter flush is set to Z_FINISH, pending input is processed,
320 pending output is flushed and deflate returns with Z_STREAM_END if there 319 pending output is flushed and deflate returns with Z_STREAM_END if there was
321 was enough output space; if deflate returns with Z_OK, this function must be 320 enough output space; if deflate returns with Z_OK, this function must be
322 called again with Z_FINISH and more output space (updated avail_out) but no 321 called again with Z_FINISH and more output space (updated avail_out) but no
323 more input data, until it returns with Z_STREAM_END or an error. After 322 more input data, until it returns with Z_STREAM_END or an error. After
324 deflate has returned Z_STREAM_END, the only possible operations on the 323 deflate has returned Z_STREAM_END, the only possible operations on the stream
325 stream are deflateReset or deflateEnd. 324 are deflateReset or deflateEnd.
326 325
327 Z_FINISH can be used immediately after deflateInit if all the compression 326 Z_FINISH can be used immediately after deflateInit if all the compression
328 is to be done in a single step. In this case, avail_out must be at least 327 is to be done in a single step. In this case, avail_out must be at least the
329 the value returned by deflateBound (see below). If deflate does not return 328 value returned by deflateBound (see below). If deflate does not return
330 Z_STREAM_END, then it must be called again as described above. 329 Z_STREAM_END, then it must be called again as described above.
331 330
332 deflate() sets strm->adler to the adler32 checksum of all input read 331 deflate() sets strm->adler to the adler32 checksum of all input read
333 so far (that is, total_in bytes). 332 so far (that is, total_in bytes).
334 333
335 deflate() may update strm->data_type if it can make a good guess about 334 deflate() may update strm->data_type if it can make a good guess about
336 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 335 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
337 binary. This field is only for information purposes and does not affect 336 binary. This field is only for information purposes and does not affect the
338 the compression algorithm in any manner. 337 compression algorithm in any manner.
339 338
340 deflate() returns Z_OK if some progress has been made (more input 339 deflate() returns Z_OK if some progress has been made (more input
341 processed or more output produced), Z_STREAM_END if all input has been 340 processed or more output produced), Z_STREAM_END if all input has been
342 consumed and all output has been produced (only when flush is set to 341 consumed and all output has been produced (only when flush is set to
343 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 342 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
344 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible 343 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
345 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 344 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
346 fatal, and deflate() can be called again with more input and more output 345 fatal, and deflate() can be called again with more input and more output
347 space to continue compressing. 346 space to continue compressing.
348*/ 347*/
@@ -351,13 +350,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
351ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 350ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
352/* 351/*
353 All dynamically allocated data structures for this stream are freed. 352 All dynamically allocated data structures for this stream are freed.
354 This function discards any unprocessed input and does not flush any 353 This function discards any unprocessed input and does not flush any pending
355 pending output. 354 output.
356 355
357 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 356 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
358 stream state was inconsistent, Z_DATA_ERROR if the stream was freed 357 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
359 prematurely (some input or output was discarded). In the error case, 358 prematurely (some input or output was discarded). In the error case, msg
360 msg may be set but then points to a static string (which must not be 359 may be set but then points to a static string (which must not be
361 deallocated). 360 deallocated).
362*/ 361*/
363 362
@@ -365,10 +364,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
365/* 364/*
366ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 365ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
367 366
368 Initializes the internal stream state for decompression. The fields 367 Initializes the internal stream state for decompression. The fields
369 next_in, avail_in, zalloc, zfree and opaque must be initialized before by 368 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
370 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact 369 the caller. If next_in is not Z_NULL and avail_in is large enough (the
371 value depends on the compression method), inflateInit determines the 370 exact value depends on the compression method), inflateInit determines the
372 compression method from the zlib header and allocates all data structures 371 compression method from the zlib header and allocates all data structures
373 accordingly; otherwise the allocation will be deferred to the first call of 372 accordingly; otherwise the allocation will be deferred to the first call of
374 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 373 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
@@ -378,66 +377,66 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
378 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 377 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
379 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 378 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
380 invalid, such as a null pointer to the structure. msg is set to null if 379 invalid, such as a null pointer to the structure. msg is set to null if
381 there is no error message. inflateInit does not perform any decompression 380 there is no error message. inflateInit does not perform any decompression
382 apart from possibly reading the zlib header if present: actual decompression 381 apart from possibly reading the zlib header if present: actual decompression
383 will be done by inflate(). (So next_in and avail_in may be modified, but 382 will be done by inflate(). (So next_in and avail_in may be modified, but
384 next_out and avail_out are unused and unchanged.) The current 383 next_out and avail_out are unused and unchanged.) The current implementation
385 implementation of inflateInit() does not process any header information -- 384 of inflateInit() does not process any header information -- that is deferred
386 that is deferred until inflate() is called. 385 until inflate() is called.
387*/ 386*/
388 387
389 388
390ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 389ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
391/* 390/*
392 inflate decompresses as much data as possible, and stops when the input 391 inflate decompresses as much data as possible, and stops when the input
393 buffer becomes empty or the output buffer becomes full. It may introduce 392 buffer becomes empty or the output buffer becomes full. It may introduce
394 some output latency (reading input without producing any output) except when 393 some output latency (reading input without producing any output) except when
395 forced to flush. 394 forced to flush.
396 395
397 The detailed semantics are as follows. inflate performs one or both of the 396 The detailed semantics are as follows. inflate performs one or both of the
398 following actions: 397 following actions:
399 398
400 - Decompress more input starting at next_in and update next_in and avail_in 399 - Decompress more input starting at next_in and update next_in and avail_in
401 accordingly. If not all input can be processed (because there is not 400 accordingly. If not all input can be processed (because there is not
402 enough room in the output buffer), next_in is updated and processing 401 enough room in the output buffer), next_in is updated and processing will
403 will resume at this point for the next call of inflate(). 402 resume at this point for the next call of inflate().
404 403
405 - Provide more output starting at next_out and update next_out and avail_out 404 - Provide more output starting at next_out and update next_out and avail_out
406 accordingly. inflate() provides as much output as possible, until there 405 accordingly. inflate() provides as much output as possible, until there is
407 is no more input data or no more space in the output buffer (see below 406 no more input data or no more space in the output buffer (see below about
408 about the flush parameter). 407 the flush parameter).
409 408
410 Before the call of inflate(), the application should ensure that at least 409 Before the call of inflate(), the application should ensure that at least
411 one of the actions is possible, by providing more input and/or consuming 410 one of the actions is possible, by providing more input and/or consuming more
412 more output, and updating the next_* and avail_* values accordingly. 411 output, and updating the next_* and avail_* values accordingly. The
413 The application can consume the uncompressed output when it wants, for 412 application can consume the uncompressed output when it wants, for example
414 example when the output buffer is full (avail_out == 0), or after each 413 when the output buffer is full (avail_out == 0), or after each call of
415 call of inflate(). If inflate returns Z_OK and with zero avail_out, it 414 inflate(). If inflate returns Z_OK and with zero avail_out, it must be
416 must be called again after making room in the output buffer because there 415 called again after making room in the output buffer because there might be
417 might be more output pending. 416 more output pending.
418 417
419 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 418 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
420 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 419 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
421 output as possible to the output buffer. Z_BLOCK requests that inflate() stop 420 output as possible to the output buffer. Z_BLOCK requests that inflate()
422 if and when it gets to the next deflate block boundary. When decoding the 421 stop if and when it gets to the next deflate block boundary. When decoding
423 zlib or gzip format, this will cause inflate() to return immediately after 422 the zlib or gzip format, this will cause inflate() to return immediately
424 the header and before the first block. When doing a raw inflate, inflate() 423 after the header and before the first block. When doing a raw inflate,
425 will go ahead and process the first block, and will return when it gets to 424 inflate() will go ahead and process the first block, and will return when it
426 the end of that block, or when it runs out of data. 425 gets to the end of that block, or when it runs out of data.
427 426
428 The Z_BLOCK option assists in appending to or combining deflate streams. 427 The Z_BLOCK option assists in appending to or combining deflate streams.
429 Also to assist in this, on return inflate() will set strm->data_type to the 428 Also to assist in this, on return inflate() will set strm->data_type to the
430 number of unused bits in the last byte taken from strm->next_in, plus 64 429 number of unused bits in the last byte taken from strm->next_in, plus 64 if
431 if inflate() is currently decoding the last block in the deflate stream, 430 inflate() is currently decoding the last block in the deflate stream, plus
432 plus 128 if inflate() returned immediately after decoding an end-of-block 431 128 if inflate() returned immediately after decoding an end-of-block code or
433 code or decoding the complete header up to just before the first byte of the 432 decoding the complete header up to just before the first byte of the deflate
434 deflate stream. The end-of-block will not be indicated until all of the 433 stream. The end-of-block will not be indicated until all of the uncompressed
435 uncompressed data from that block has been written to strm->next_out. The 434 data from that block has been written to strm->next_out. The number of
436 number of unused bits may in general be greater than seven, except when 435 unused bits may in general be greater than seven, except when bit 7 of
437 bit 7 of data_type is set, in which case the number of unused bits will be 436 data_type is set, in which case the number of unused bits will be less than
438 less than eight. data_type is set as noted here every time inflate() 437 eight. data_type is set as noted here every time inflate() returns for all
439 returns for all flush options, and so can be used to determine the amount 438 flush options, and so can be used to determine the amount of currently
440 of currently consumed input in bits. 439 consumed input in bits.
441 440
442 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 441 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
443 end of each deflate block header is reached, before any actual data in that 442 end of each deflate block header is reached, before any actual data in that
@@ -447,19 +446,19 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
447 immediately after reaching the end of the deflate block header. 446 immediately after reaching the end of the deflate block header.
448 447
449 inflate() should normally be called until it returns Z_STREAM_END or an 448 inflate() should normally be called until it returns Z_STREAM_END or an
450 error. However if all decompression is to be performed in a single step 449 error. However if all decompression is to be performed in a single step (a
451 (a single call of inflate), the parameter flush should be set to 450 single call of inflate), the parameter flush should be set to Z_FINISH. In
452 Z_FINISH. In this case all pending input is processed and all pending 451 this case all pending input is processed and all pending output is flushed;
453 output is flushed; avail_out must be large enough to hold all the 452 avail_out must be large enough to hold all the uncompressed data. (The size
454 uncompressed data. (The size of the uncompressed data may have been saved 453 of the uncompressed data may have been saved by the compressor for this
455 by the compressor for this purpose.) The next operation on this stream must 454 purpose.) The next operation on this stream must be inflateEnd to deallocate
456 be inflateEnd to deallocate the decompression state. The use of Z_FINISH 455 the decompression state. The use of Z_FINISH is never required, but can be
457 is never required, but can be used to inform inflate that a faster approach 456 used to inform inflate that a faster approach may be used for the single
458 may be used for the single inflate() call. 457 inflate() call.
459 458
460 In this implementation, inflate() always flushes as much output as 459 In this implementation, inflate() always flushes as much output as
461 possible to the output buffer, and always uses the faster approach on the 460 possible to the output buffer, and always uses the faster approach on the
462 first call. So the only effect of the flush parameter in this implementation 461 first call. So the only effect of the flush parameter in this implementation
463 is on the return value of inflate(), as noted below, or when it returns early 462 is on the return value of inflate(), as noted below, or when it returns early
464 because Z_BLOCK or Z_TREES is used. 463 because Z_BLOCK or Z_TREES is used.
465 464
@@ -468,7 +467,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
468 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 467 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
469 strm->adler to the adler32 checksum of all output produced so far (that is, 468 strm->adler to the adler32 checksum of all output produced so far (that is,
470 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 469 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
471 below. At the end of the stream, inflate() checks that its computed adler32 470 below. At the end of the stream, inflate() checks that its computed adler32
472 checksum is equal to that saved by the compressor and returns Z_STREAM_END 471 checksum is equal to that saved by the compressor and returns Z_STREAM_END
473 only if the checksum is correct. 472 only if the checksum is correct.
474 473
@@ -487,22 +486,22 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
487 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 486 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
488 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, 487 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
489 Z_BUF_ERROR if no progress is possible or if there was not enough room in the 488 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
490 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 489 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
491 inflate() can be called again with more input and more output space to 490 inflate() can be called again with more input and more output space to
492 continue decompressing. If Z_DATA_ERROR is returned, the application may then 491 continue decompressing. If Z_DATA_ERROR is returned, the application may
493 call inflateSync() to look for a good compression block if a partial recovery 492 then call inflateSync() to look for a good compression block if a partial
494 of the data is desired. 493 recovery of the data is desired.
495*/ 494*/
496 495
497 496
498ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 497ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
499/* 498/*
500 All dynamically allocated data structures for this stream are freed. 499 All dynamically allocated data structures for this stream are freed.
501 This function discards any unprocessed input and does not flush any 500 This function discards any unprocessed input and does not flush any pending
502 pending output. 501 output.
503 502
504 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 503 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
505 was inconsistent. In the error case, msg may be set but then points to a 504 was inconsistent. In the error case, msg may be set but then points to a
506 static string (which must not be deallocated). 505 static string (which must not be deallocated).
507*/ 506*/
508 507
@@ -520,55 +519,55 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
520 int memLevel, 519 int memLevel,
521 int strategy)); 520 int strategy));
522 521
523 This is another version of deflateInit with more compression options. The 522 This is another version of deflateInit with more compression options. The
524 fields next_in, zalloc, zfree and opaque must be initialized before by 523 fields next_in, zalloc, zfree and opaque must be initialized before by the
525 the caller. 524 caller.
526 525
527 The method parameter is the compression method. It must be Z_DEFLATED in 526 The method parameter is the compression method. It must be Z_DEFLATED in
528 this version of the library. 527 this version of the library.
529 528
530 The windowBits parameter is the base two logarithm of the window size 529 The windowBits parameter is the base two logarithm of the window size
531 (the size of the history buffer). It should be in the range 8..15 for this 530 (the size of the history buffer). It should be in the range 8..15 for this
532 version of the library. Larger values of this parameter result in better 531 version of the library. Larger values of this parameter result in better
533 compression at the expense of memory usage. The default value is 15 if 532 compression at the expense of memory usage. The default value is 15 if
534 deflateInit is used instead. 533 deflateInit is used instead.
535 534
536 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 535 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
537 determines the window size. deflate() will then generate raw deflate data 536 determines the window size. deflate() will then generate raw deflate data
538 with no zlib header or trailer, and will not compute an adler32 check value. 537 with no zlib header or trailer, and will not compute an adler32 check value.
539 538
540 windowBits can also be greater than 15 for optional gzip encoding. Add 539 windowBits can also be greater than 15 for optional gzip encoding. Add
541 16 to windowBits to write a simple gzip header and trailer around the 540 16 to windowBits to write a simple gzip header and trailer around the
542 compressed data instead of a zlib wrapper. The gzip header will have no 541 compressed data instead of a zlib wrapper. The gzip header will have no
543 file name, no extra data, no comment, no modification time (set to zero), 542 file name, no extra data, no comment, no modification time (set to zero), no
544 no header crc, and the operating system will be set to 255 (unknown). If a 543 header crc, and the operating system will be set to 255 (unknown). If a
545 gzip stream is being written, strm->adler is a crc32 instead of an adler32. 544 gzip stream is being written, strm->adler is a crc32 instead of an adler32.
546 545
547 The memLevel parameter specifies how much memory should be allocated 546 The memLevel parameter specifies how much memory should be allocated
548 for the internal compression state. memLevel=1 uses minimum memory but 547 for the internal compression state. memLevel=1 uses minimum memory but is
549 is slow and reduces compression ratio; memLevel=9 uses maximum memory 548 slow and reduces compression ratio; memLevel=9 uses maximum memory for
550 for optimal speed. The default value is 8. See zconf.h for total memory 549 optimal speed. The default value is 8. See zconf.h for total memory usage
551 usage as a function of windowBits and memLevel. 550 as a function of windowBits and memLevel.
552 551
553 The strategy parameter is used to tune the compression algorithm. Use the 552 The strategy parameter is used to tune the compression algorithm. Use the
554 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 553 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
555 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 554 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
556 string match), or Z_RLE to limit match distances to one (run-length 555 string match), or Z_RLE to limit match distances to one (run-length
557 encoding). Filtered data consists mostly of small values with a somewhat 556 encoding). Filtered data consists mostly of small values with a somewhat
558 random distribution. In this case, the compression algorithm is tuned to 557 random distribution. In this case, the compression algorithm is tuned to
559 compress them better. The effect of Z_FILTERED is to force more Huffman 558 compress them better. The effect of Z_FILTERED is to force more Huffman
560 coding and less string matching; it is somewhat intermediate between 559 coding and less string matching; it is somewhat intermediate between
561 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 560 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
562 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 561 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
563 strategy parameter only affects the compression ratio but not the 562 strategy parameter only affects the compression ratio but not the
564 correctness of the compressed output even if it is not set appropriately. 563 correctness of the compressed output even if it is not set appropriately.
565 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 564 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
566 decoder for special applications. 565 decoder for special applications.
567 566
568 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 567 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
569 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 568 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
570 method). msg is set to null if there is no error message. deflateInit2 does 569 method). msg is set to null if there is no error message. deflateInit2
571 not perform any compression: this will be done by deflate(). 570 does not perform any compression: this will be done by deflate().
572*/ 571*/
573 572
574ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 573ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
@@ -576,14 +575,14 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
576 uInt dictLength)); 575 uInt dictLength));
577/* 576/*
578 Initializes the compression dictionary from the given byte sequence 577 Initializes the compression dictionary from the given byte sequence
579 without producing any compressed output. This function must be called 578 without producing any compressed output. This function must be called
580 immediately after deflateInit, deflateInit2 or deflateReset, before any 579 immediately after deflateInit, deflateInit2 or deflateReset, before any call
581 call of deflate. The compressor and decompressor must use exactly the same 580 of deflate. The compressor and decompressor must use exactly the same
582 dictionary (see inflateSetDictionary). 581 dictionary (see inflateSetDictionary).
583 582
584 The dictionary should consist of strings (byte sequences) that are likely 583 The dictionary should consist of strings (byte sequences) that are likely
585 to be encountered later in the data to be compressed, with the most commonly 584 to be encountered later in the data to be compressed, with the most commonly
586 used strings preferably put towards the end of the dictionary. Using a 585 used strings preferably put towards the end of the dictionary. Using a
587 dictionary is most useful when the data to be compressed is short and can be 586 dictionary is most useful when the data to be compressed is short and can be
588 predicted with good accuracy; the data can then be compressed better than 587 predicted with good accuracy; the data can then be compressed better than
589 with the default empty dictionary. 588 with the default empty dictionary.
@@ -591,22 +590,22 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
591 Depending on the size of the compression data structures selected by 590 Depending on the size of the compression data structures selected by
592 deflateInit or deflateInit2, a part of the dictionary may in effect be 591 deflateInit or deflateInit2, a part of the dictionary may in effect be
593 discarded, for example if the dictionary is larger than the window size 592 discarded, for example if the dictionary is larger than the window size
594 provided in deflateInit or deflateInit2. Thus the strings most likely to be 593 provided in deflateInit or deflateInit2. Thus the strings most likely to be
595 useful should be put at the end of the dictionary, not at the front. In 594 useful should be put at the end of the dictionary, not at the front. In
596 addition, the current implementation of deflate will use at most the window 595 addition, the current implementation of deflate will use at most the window
597 size minus 262 bytes of the provided dictionary. 596 size minus 262 bytes of the provided dictionary.
598 597
599 Upon return of this function, strm->adler is set to the adler32 value 598 Upon return of this function, strm->adler is set to the adler32 value
600 of the dictionary; the decompressor may later use this value to determine 599 of the dictionary; the decompressor may later use this value to determine
601 which dictionary has been used by the compressor. (The adler32 value 600 which dictionary has been used by the compressor. (The adler32 value
602 applies to the whole dictionary even if only a subset of the dictionary is 601 applies to the whole dictionary even if only a subset of the dictionary is
603 actually used by the compressor.) If a raw deflate was requested, then the 602 actually used by the compressor.) If a raw deflate was requested, then the
604 adler32 value is not computed and strm->adler is not set. 603 adler32 value is not computed and strm->adler is not set.
605 604
606 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 605 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
607 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 606 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
608 inconsistent (for example if deflate has already been called for this stream 607 inconsistent (for example if deflate has already been called for this stream
609 or if the compression method is bsort). deflateSetDictionary does not 608 or if the compression method is bsort). deflateSetDictionary does not
610 perform any compression: this will be done by deflate(). 609 perform any compression: this will be done by deflate().
611*/ 610*/
612 611
@@ -617,25 +616,25 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
617 616
618 This function can be useful when several compression strategies will be 617 This function can be useful when several compression strategies will be
619 tried, for example when there are several ways of pre-processing the input 618 tried, for example when there are several ways of pre-processing the input
620 data with a filter. The streams that will be discarded should then be freed 619 data with a filter. The streams that will be discarded should then be freed
621 by calling deflateEnd. Note that deflateCopy duplicates the internal 620 by calling deflateEnd. Note that deflateCopy duplicates the internal
622 compression state which can be quite large, so this strategy is slow and 621 compression state which can be quite large, so this strategy is slow and can
623 can consume lots of memory. 622 consume lots of memory.
624 623
625 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 624 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
626 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 625 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
627 (such as zalloc being Z_NULL). msg is left unchanged in both source and 626 (such as zalloc being Z_NULL). msg is left unchanged in both source and
628 destination. 627 destination.
629*/ 628*/
630 629
631ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 630ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
632/* 631/*
633 This function is equivalent to deflateEnd followed by deflateInit, 632 This function is equivalent to deflateEnd followed by deflateInit,
634 but does not free and reallocate all the internal compression state. 633 but does not free and reallocate all the internal compression state. The
635 The stream will keep the same compression level and any other attributes 634 stream will keep the same compression level and any other attributes that
636 that may have been set by deflateInit2. 635 may have been set by deflateInit2.
637 636
638 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 637 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
639 stream state was inconsistent (such as zalloc or state being Z_NULL). 638 stream state was inconsistent (such as zalloc or state being Z_NULL).
640*/ 639*/
641 640
@@ -646,18 +645,18 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
646 Dynamically update the compression level and compression strategy. The 645 Dynamically update the compression level and compression strategy. The
647 interpretation of level and strategy is as in deflateInit2. This can be 646 interpretation of level and strategy is as in deflateInit2. This can be
648 used to switch between compression and straight copy of the input data, or 647 used to switch between compression and straight copy of the input data, or
649 to switch to a different kind of input data requiring a different 648 to switch to a different kind of input data requiring a different strategy.
650 strategy. If the compression level is changed, the input available so far 649 If the compression level is changed, the input available so far is
651 is compressed with the old level (and may be flushed); the new level will 650 compressed with the old level (and may be flushed); the new level will take
652 take effect only at the next call of deflate(). 651 effect only at the next call of deflate().
653 652
654 Before the call of deflateParams, the stream state must be set as for 653 Before the call of deflateParams, the stream state must be set as for
655 a call of deflate(), since the currently available input may have to 654 a call of deflate(), since the currently available input may have to be
656 be compressed and flushed. In particular, strm->avail_out must be non-zero. 655 compressed and flushed. In particular, strm->avail_out must be non-zero.
657 656
658 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 657 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
659 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 658 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
660 if strm->avail_out was zero. 659 strm->avail_out was zero.
661*/ 660*/
662 661
663ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 662ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
@@ -692,21 +691,21 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
692 int value)); 691 int value));
693/* 692/*
694 deflatePrime() inserts bits in the deflate output stream. The intent 693 deflatePrime() inserts bits in the deflate output stream. The intent
695 is that this function is used to start off the deflate output with the 694 is that this function is used to start off the deflate output with the bits
696 bits leftover from a previous deflate stream when appending to it. As such, 695 leftover from a previous deflate stream when appending to it. As such, this
697 this function can only be used for raw deflate, and must be used before the 696 function can only be used for raw deflate, and must be used before the first
698 first deflate() call after a deflateInit2() or deflateReset(). bits must be 697 deflate() call after a deflateInit2() or deflateReset(). bits must be less
699 less than or equal to 16, and that many of the least significant bits of 698 than or equal to 16, and that many of the least significant bits of value
700 value will be inserted in the output. 699 will be inserted in the output.
701 700
702 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 701 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
703 stream state was inconsistent. 702 stream state was inconsistent.
704*/ 703*/
705 704
706ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 705ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
707 gz_headerp head)); 706 gz_headerp head));
708/* 707/*
709 deflateSetHeader() provides gzip header information for when a gzip 708 deflateSetHeader() provides gzip header information for when a gzip
710 stream is requested by deflateInit2(). deflateSetHeader() may be called 709 stream is requested by deflateInit2(). deflateSetHeader() may be called
711 after deflateInit2() or deflateReset() and before the first call of 710 after deflateInit2() or deflateReset() and before the first call of
712 deflate(). The text, time, os, extra field, name, and comment information 711 deflate(). The text, time, os, extra field, name, and comment information
@@ -719,11 +718,11 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
719 1.3.x) do not support header crc's, and will report that it is a "multi-part 718 1.3.x) do not support header crc's, and will report that it is a "multi-part
720 gzip file" and give up. 719 gzip file" and give up.
721 720
722 If deflateSetHeader is not used, the default gzip header has text false, 721 If deflateSetHeader is not used, the default gzip header has text false,
723 the time set to zero, and os set to 255, with no extra, name, or comment 722 the time set to zero, and os set to 255, with no extra, name, or comment
724 fields. The gzip header is returned to the default state by deflateReset(). 723 fields. The gzip header is returned to the default state by deflateReset().
725 724
726 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 725 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
727 stream state was inconsistent. 726 stream state was inconsistent.
728*/ 727*/
729 728
@@ -731,50 +730,50 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
731ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 730ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
732 int windowBits)); 731 int windowBits));
733 732
734 This is another version of inflateInit with an extra parameter. The 733 This is another version of inflateInit with an extra parameter. The
735 fields next_in, avail_in, zalloc, zfree and opaque must be initialized 734 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
736 before by the caller. 735 before by the caller.
737 736
738 The windowBits parameter is the base two logarithm of the maximum window 737 The windowBits parameter is the base two logarithm of the maximum window
739 size (the size of the history buffer). It should be in the range 8..15 for 738 size (the size of the history buffer). It should be in the range 8..15 for
740 this version of the library. The default value is 15 if inflateInit is used 739 this version of the library. The default value is 15 if inflateInit is used
741 instead. windowBits must be greater than or equal to the windowBits value 740 instead. windowBits must be greater than or equal to the windowBits value
742 provided to deflateInit2() while compressing, or it must be equal to 15 if 741 provided to deflateInit2() while compressing, or it must be equal to 15 if
743 deflateInit2() was not used. If a compressed stream with a larger window 742 deflateInit2() was not used. If a compressed stream with a larger window
744 size is given as input, inflate() will return with the error code 743 size is given as input, inflate() will return with the error code
745 Z_DATA_ERROR instead of trying to allocate a larger window. 744 Z_DATA_ERROR instead of trying to allocate a larger window.
746 745
747 windowBits can also be zero to request that inflate use the window size in 746 windowBits can also be zero to request that inflate use the window size in
748 the zlib header of the compressed stream. 747 the zlib header of the compressed stream.
749 748
750 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 749 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
751 determines the window size. inflate() will then process raw deflate data, 750 determines the window size. inflate() will then process raw deflate data,
752 not looking for a zlib or gzip header, not generating a check value, and not 751 not looking for a zlib or gzip header, not generating a check value, and not
753 looking for any check values for comparison at the end of the stream. This 752 looking for any check values for comparison at the end of the stream. This
754 is for use with other formats that use the deflate compressed data format 753 is for use with other formats that use the deflate compressed data format
755 such as zip. Those formats provide their own check values. If a custom 754 such as zip. Those formats provide their own check values. If a custom
756 format is developed using the raw deflate format for compressed data, it is 755 format is developed using the raw deflate format for compressed data, it is
757 recommended that a check value such as an adler32 or a crc32 be applied to 756 recommended that a check value such as an adler32 or a crc32 be applied to
758 the uncompressed data as is done in the zlib, gzip, and zip formats. For 757 the uncompressed data as is done in the zlib, gzip, and zip formats. For
759 most applications, the zlib format should be used as is. Note that comments 758 most applications, the zlib format should be used as is. Note that comments
760 above on the use in deflateInit2() applies to the magnitude of windowBits. 759 above on the use in deflateInit2() applies to the magnitude of windowBits.
761 760
762 windowBits can also be greater than 15 for optional gzip decoding. Add 761 windowBits can also be greater than 15 for optional gzip decoding. Add
763 32 to windowBits to enable zlib and gzip decoding with automatic header 762 32 to windowBits to enable zlib and gzip decoding with automatic header
764 detection, or add 16 to decode only the gzip format (the zlib format will 763 detection, or add 16 to decode only the gzip format (the zlib format will
765 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is 764 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
766 a crc32 instead of an adler32. 765 crc32 instead of an adler32.
767 766
768 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 767 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
769 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 768 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
770 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 769 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
771 invalid, such as a null pointer to the structure. msg is set to null if 770 invalid, such as a null pointer to the structure. msg is set to null if
772 there is no error message. inflateInit2 does not perform any decompression 771 there is no error message. inflateInit2 does not perform any decompression
773 apart from possibly reading the zlib header if present: actual decompression 772 apart from possibly reading the zlib header if present: actual decompression
774 will be done by inflate(). (So next_in and avail_in may be modified, but 773 will be done by inflate(). (So next_in and avail_in may be modified, but
775 next_out and avail_out are unused and unchanged.) The current 774 next_out and avail_out are unused and unchanged.) The current implementation
776 implementation of inflateInit2() does not process any header information -- 775 of inflateInit2() does not process any header information -- that is
777 that is deferred until inflate() is called. 776 deferred until inflate() is called.
778*/ 777*/
779 778
780ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 779ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
@@ -782,8 +781,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
782 uInt dictLength)); 781 uInt dictLength));
783/* 782/*
784 Initializes the decompression dictionary from the given uncompressed byte 783 Initializes the decompression dictionary from the given uncompressed byte
785 sequence. This function must be called immediately after a call of inflate, 784 sequence. This function must be called immediately after a call of inflate,
786 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 785 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
787 can be determined from the adler32 value returned by that call of inflate. 786 can be determined from the adler32 value returned by that call of inflate.
788 The compressor and decompressor must use exactly the same dictionary (see 787 The compressor and decompressor must use exactly the same dictionary (see
789 deflateSetDictionary). For raw inflate, this function can be called 788 deflateSetDictionary). For raw inflate, this function can be called
@@ -792,26 +791,26 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
792 dictionary that was used for compression is provided. 791 dictionary that was used for compression is provided.
793 792
794 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 793 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
795 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 794 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
796 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 795 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
797 expected one (incorrect adler32 value). inflateSetDictionary does not 796 expected one (incorrect adler32 value). inflateSetDictionary does not
798 perform any decompression: this will be done by subsequent calls of 797 perform any decompression: this will be done by subsequent calls of
799 inflate(). 798 inflate().
800*/ 799*/
801 800
802ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 801ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
803/* 802/*
804 Skips invalid compressed data until a full flush point (see above the 803 Skips invalid compressed data until a full flush point (see above the
805 description of deflate with Z_FULL_FLUSH) can be found, or until all 804 description of deflate with Z_FULL_FLUSH) can be found, or until all
806 available input is skipped. No output is provided. 805 available input is skipped. No output is provided.
807 806
808 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 807 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
809 if no more input was provided, Z_DATA_ERROR if no flush point has been found, 808 if no more input was provided, Z_DATA_ERROR if no flush point has been
810 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 809 found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
811 case, the application may save the current current value of total_in which 810 success case, the application may save the current current value of total_in
812 indicates where valid compressed data was found. In the error case, the 811 which indicates where valid compressed data was found. In the error case,
813 application may repeatedly call inflateSync, providing more input each time, 812 the application may repeatedly call inflateSync, providing more input each
814 until success or end of the input data. 813 time, until success or end of the input data.
815*/ 814*/
816 815
817ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 816ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@@ -826,17 +825,17 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
826 825
827 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 826 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
828 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 827 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
829 (such as zalloc being Z_NULL). msg is left unchanged in both source and 828 (such as zalloc being Z_NULL). msg is left unchanged in both source and
830 destination. 829 destination.
831*/ 830*/
832 831
833ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 832ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
834/* 833/*
835 This function is equivalent to inflateEnd followed by inflateInit, 834 This function is equivalent to inflateEnd followed by inflateInit,
836 but does not free and reallocate all the internal decompression state. 835 but does not free and reallocate all the internal decompression state. The
837 The stream will keep attributes that may have been set by inflateInit2. 836 stream will keep attributes that may have been set by inflateInit2.
838 837
839 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 838 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
840 stream state was inconsistent (such as zalloc or state being Z_NULL). 839 stream state was inconsistent (such as zalloc or state being Z_NULL).
841*/ 840*/
842 841
@@ -844,10 +843,10 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
844 int windowBits)); 843 int windowBits));
845/* 844/*
846 This function is the same as inflateReset, but it also permits changing 845 This function is the same as inflateReset, but it also permits changing
847 the wrap and window size requests. The windowBits parameter is 846 the wrap and window size requests. The windowBits parameter is interpreted
848 interpreted the same as it is for inflateInit2. 847 the same as it is for inflateInit2.
849 848
850 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 849 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
851 stream state was inconsistent (such as zalloc or state being Z_NULL), or if 850 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
852 the windowBits parameter is invalid. 851 the windowBits parameter is invalid.
853*/ 852*/
@@ -857,19 +856,19 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
857 int value)); 856 int value));
858/* 857/*
859 This function inserts bits in the inflate input stream. The intent is 858 This function inserts bits in the inflate input stream. The intent is
860 that this function is used to start inflating at a bit position in the 859 that this function is used to start inflating at a bit position in the
861 middle of a byte. The provided bits will be used before any bytes are used 860 middle of a byte. The provided bits will be used before any bytes are used
862 from next_in. This function should only be used with raw inflate, and 861 from next_in. This function should only be used with raw inflate, and
863 should be used before the first inflate() call after inflateInit2() or 862 should be used before the first inflate() call after inflateInit2() or
864 inflateReset(). bits must be less than or equal to 16, and that many of the 863 inflateReset(). bits must be less than or equal to 16, and that many of the
865 least significant bits of value will be inserted in the input. 864 least significant bits of value will be inserted in the input.
866 865
867 If bits is negative, then the input stream bit buffer is emptied. Then 866 If bits is negative, then the input stream bit buffer is emptied. Then
868 inflatePrime() can be called again to put bits in the buffer. This is used 867 inflatePrime() can be called again to put bits in the buffer. This is used
869 to clear out bits leftover after feeding inflate a block description prior 868 to clear out bits leftover after feeding inflate a block description prior
870 to feeding inflate codes. 869 to feeding inflate codes.
871 870
872 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 871 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
873 stream state was inconsistent. 872 stream state was inconsistent.
874*/ 873*/
875 874
@@ -891,20 +890,20 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
891 decoding of the code, or if it has completed decoding but is waiting for 890 decoding of the code, or if it has completed decoding but is waiting for
892 more output space to write the literal or match data. 891 more output space to write the literal or match data.
893 892
894 inflateMark() is used to mark locations in the input data for random 893 inflateMark() is used to mark locations in the input data for random
895 access, which may be at bit positions, and to note those cases where the 894 access, which may be at bit positions, and to note those cases where the
896 output of a code may span boundaries of random access blocks. The current 895 output of a code may span boundaries of random access blocks. The current
897 location in the input stream can be determined from avail_in and data_type 896 location in the input stream can be determined from avail_in and data_type
898 as noted in the description for the Z_BLOCK flush parameter for inflate. 897 as noted in the description for the Z_BLOCK flush parameter for inflate.
899 898
900 inflateMark returns the value noted above or -1 << 16 if the provided 899 inflateMark returns the value noted above or -1 << 16 if the provided
901 source stream state was inconsistent. 900 source stream state was inconsistent.
902*/ 901*/
903 902
904ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 903ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
905 gz_headerp head)); 904 gz_headerp head));
906/* 905/*
907 inflateGetHeader() requests that gzip header information be stored in the 906 inflateGetHeader() requests that gzip header information be stored in the
908 provided gz_header structure. inflateGetHeader() may be called after 907 provided gz_header structure. inflateGetHeader() may be called after
909 inflateInit2() or inflateReset(), and before the first call of inflate(). 908 inflateInit2() or inflateReset(), and before the first call of inflate().
910 As inflate() processes the gzip stream, head->done is zero until the header 909 As inflate() processes the gzip stream, head->done is zero until the header
@@ -914,30 +913,30 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
914 used to force inflate() to return immediately after header processing is 913 used to force inflate() to return immediately after header processing is
915 complete and before any actual data is decompressed. 914 complete and before any actual data is decompressed.
916 915
917 The text, time, xflags, and os fields are filled in with the gzip header 916 The text, time, xflags, and os fields are filled in with the gzip header
918 contents. hcrc is set to true if there is a header CRC. (The header CRC 917 contents. hcrc is set to true if there is a header CRC. (The header CRC
919 was valid if done is set to one.) If extra is not Z_NULL, then extra_max 918 was valid if done is set to one.) If extra is not Z_NULL, then extra_max
920 contains the maximum number of bytes to write to extra. Once done is true, 919 contains the maximum number of bytes to write to extra. Once done is true,
921 extra_len contains the actual extra field length, and extra contains the 920 extra_len contains the actual extra field length, and extra contains the
922 extra field, or that field truncated if extra_max is less than extra_len. 921 extra field, or that field truncated if extra_max is less than extra_len.
923 If name is not Z_NULL, then up to name_max characters are written there, 922 If name is not Z_NULL, then up to name_max characters are written there,
924 terminated with a zero unless the length is greater than name_max. If 923 terminated with a zero unless the length is greater than name_max. If
925 comment is not Z_NULL, then up to comm_max characters are written there, 924 comment is not Z_NULL, then up to comm_max characters are written there,
926 terminated with a zero unless the length is greater than comm_max. When 925 terminated with a zero unless the length is greater than comm_max. When any
927 any of extra, name, or comment are not Z_NULL and the respective field is 926 of extra, name, or comment are not Z_NULL and the respective field is not
928 not present in the header, then that field is set to Z_NULL to signal its 927 present in the header, then that field is set to Z_NULL to signal its
929 absence. This allows the use of deflateSetHeader() with the returned 928 absence. This allows the use of deflateSetHeader() with the returned
930 structure to duplicate the header. However if those fields are set to 929 structure to duplicate the header. However if those fields are set to
931 allocated memory, then the application will need to save those pointers 930 allocated memory, then the application will need to save those pointers
932 elsewhere so that they can be eventually freed. 931 elsewhere so that they can be eventually freed.
933 932
934 If inflateGetHeader is not used, then the header information is simply 933 If inflateGetHeader is not used, then the header information is simply
935 discarded. The header is always checked for validity, including the header 934 discarded. The header is always checked for validity, including the header
936 CRC if present. inflateReset() will reset the process to discard the header 935 CRC if present. inflateReset() will reset the process to discard the header
937 information. The application would need to call inflateGetHeader() again to 936 information. The application would need to call inflateGetHeader() again to
938 retrieve the header from the next gzip stream. 937 retrieve the header from the next gzip stream.
939 938
940 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 939 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
941 stream state was inconsistent. 940 stream state was inconsistent.
942*/ 941*/
943 942
@@ -958,9 +957,9 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
958 See inflateBack() for the usage of these routines. 957 See inflateBack() for the usage of these routines.
959 958
960 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 959 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
961 the paramaters are invalid, Z_MEM_ERROR if the internal state could not 960 the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
962 be allocated, or Z_VERSION_ERROR if the version of the library does not 961 allocated, or Z_VERSION_ERROR if the version of the library does not match
963 match the version of the header file. 962 the version of the header file.
964*/ 963*/
965 964
966typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 965typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
@@ -980,15 +979,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
980 inflateBackInit() must be called first to allocate the internal state 979 inflateBackInit() must be called first to allocate the internal state
981 and to initialize the state with the user-provided window buffer. 980 and to initialize the state with the user-provided window buffer.
982 inflateBack() may then be used multiple times to inflate a complete, raw 981 inflateBack() may then be used multiple times to inflate a complete, raw
983 deflate stream with each call. inflateBackEnd() is then called to free 982 deflate stream with each call. inflateBackEnd() is then called to free the
984 the allocated state. 983 allocated state.
985 984
986 A raw deflate stream is one with no zlib or gzip header or trailer. 985 A raw deflate stream is one with no zlib or gzip header or trailer.
987 This routine would normally be used in a utility that reads zip or gzip 986 This routine would normally be used in a utility that reads zip or gzip
988 files and writes out uncompressed files. The utility would decode the 987 files and writes out uncompressed files. The utility would decode the
989 header and process the trailer on its own, hence this routine expects 988 header and process the trailer on its own, hence this routine expects only
990 only the raw deflate stream to decompress. This is different from the 989 the raw deflate stream to decompress. This is different from the normal
991 normal behavior of inflate(), which expects either a zlib or gzip header and 990 behavior of inflate(), which expects either a zlib or gzip header and
992 trailer around the deflate stream. 991 trailer around the deflate stream.
993 992
994 inflateBack() uses two subroutines supplied by the caller that are then 993 inflateBack() uses two subroutines supplied by the caller that are then
@@ -1014,7 +1013,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1014 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 1013 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1015 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 1014 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1016 must also be initialized, and then if strm->avail_in is not zero, input will 1015 must also be initialized, and then if strm->avail_in is not zero, input will
1017 initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 1016 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1018 1017
1019 The in_desc and out_desc parameters of inflateBack() is passed as the 1018 The in_desc and out_desc parameters of inflateBack() is passed as the
1020 first parameter of in() and out() respectively when they are called. These 1019 first parameter of in() and out() respectively when they are called. These
@@ -1024,15 +1023,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1024 On return, inflateBack() will set strm->next_in and strm->avail_in to 1023 On return, inflateBack() will set strm->next_in and strm->avail_in to
1025 pass back any unused input that was provided by the last in() call. The 1024 pass back any unused input that was provided by the last in() call. The
1026 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 1025 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
1027 if in() or out() returned an error, Z_DATA_ERROR if there was a format 1026 if in() or out() returned an error, Z_DATA_ERROR if there was a format error
1028 error in the deflate stream (in which case strm->msg is set to indicate the 1027 in the deflate stream (in which case strm->msg is set to indicate the nature
1029 nature of the error), or Z_STREAM_ERROR if the stream was not properly 1028 of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
1030 initialized. In the case of Z_BUF_ERROR, an input or output error can be 1029 In the case of Z_BUF_ERROR, an input or output error can be distinguished
1031 distinguished using strm->next_in which will be Z_NULL only if in() returned 1030 using strm->next_in which will be Z_NULL only if in() returned an error. If
1032 an error. If strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to 1031 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1033 out() returning non-zero. (in() will always be called before out(), so 1032 non-zero. (in() will always be called before out(), so strm->next_in is
1034 strm->next_in is assured to be defined if out() returns non-zero.) Note 1033 assured to be defined if out() returns non-zero.) Note that inflateBack()
1035 that inflateBack() cannot return Z_OK. 1034 cannot return Z_OK.
1036*/ 1035*/
1037 1036
1038ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 1037ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
@@ -1089,22 +1088,21 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1089 1088
1090/* 1089/*
1091 The following utility functions are implemented on top of the 1090 The following utility functions are implemented on top of the
1092 basic stream-oriented functions. To simplify the interface, some 1091 basic stream-oriented functions. To simplify the interface, some default
1093 default options are assumed (compression level and memory usage, 1092 options are assumed (compression level and memory usage, standard memory
1094 standard memory allocation functions). The source code of these 1093 allocation functions). The source code of these utility functions can
1095 utility functions can easily be modified if you need special options. 1094 easily be modified if you need special options.
1096*/ 1095*/
1097 1096
1098ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1097ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1099 const Bytef *source, uLong sourceLen)); 1098 const Bytef *source, uLong sourceLen));
1100/* 1099/*
1101 Compresses the source buffer into the destination buffer. sourceLen is 1100 Compresses the source buffer into the destination buffer. sourceLen is
1102 the byte length of the source buffer. Upon entry, destLen is the total 1101 the byte length of the source buffer. Upon entry, destLen is the total size
1103 size of the destination buffer, which must be at least the value returned 1102 of the destination buffer, which must be at least the value returned by
1104 by compressBound(sourceLen). Upon exit, destLen is the actual size of the 1103 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1105 compressed buffer. 1104 compressed buffer.
1106 This function can be used to compress a whole file at once if the 1105
1107 input file is mmap'ed.
1108 compress returns Z_OK if success, Z_MEM_ERROR if there was not 1106 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1109 enough memory, Z_BUF_ERROR if there was not enough room in the output 1107 enough memory, Z_BUF_ERROR if there was not enough room in the output
1110 buffer. 1108 buffer.
@@ -1114,11 +1112,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1114 const Bytef *source, uLong sourceLen, 1112 const Bytef *source, uLong sourceLen,
1115 int level)); 1113 int level));
1116/* 1114/*
1117 Compresses the source buffer into the destination buffer. The level 1115 Compresses the source buffer into the destination buffer. The level
1118 parameter has the same meaning as in deflateInit. sourceLen is the byte 1116 parameter has the same meaning as in deflateInit. sourceLen is the byte
1119 length of the source buffer. Upon entry, destLen is the total size of the 1117 length of the source buffer. Upon entry, destLen is the total size of the
1120 destination buffer, which must be at least the value returned by 1118 destination buffer, which must be at least the value returned by
1121 compressBound(sourceLen). Upon exit, destLen is the actual size of the 1119 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1122 compressed buffer. 1120 compressed buffer.
1123 1121
1124 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1122 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
@@ -1129,22 +1127,20 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1129ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1127ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1130/* 1128/*
1131 compressBound() returns an upper bound on the compressed size after 1129 compressBound() returns an upper bound on the compressed size after
1132 compress() or compress2() on sourceLen bytes. It would be used before 1130 compress() or compress2() on sourceLen bytes. It would be used before a
1133 a compress() or compress2() call to allocate the destination buffer. 1131 compress() or compress2() call to allocate the destination buffer.
1134*/ 1132*/
1135 1133
1136ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1134ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1137 const Bytef *source, uLong sourceLen)); 1135 const Bytef *source, uLong sourceLen));
1138/* 1136/*
1139 Decompresses the source buffer into the destination buffer. sourceLen is 1137 Decompresses the source buffer into the destination buffer. sourceLen is
1140 the byte length of the source buffer. Upon entry, destLen is the total 1138 the byte length of the source buffer. Upon entry, destLen is the total size
1141 size of the destination buffer, which must be large enough to hold the 1139 of the destination buffer, which must be large enough to hold the entire
1142 entire uncompressed data. (The size of the uncompressed data must have 1140 uncompressed data. (The size of the uncompressed data must have been saved
1143 been saved previously by the compressor and transmitted to the decompressor 1141 previously by the compressor and transmitted to the decompressor by some
1144 by some mechanism outside the scope of this compression library.) 1142 mechanism outside the scope of this compression library.) Upon exit, destLen
1145 Upon exit, destLen is the actual size of the uncompressed buffer. 1143 is the actual size of the uncompressed buffer.
1146 This function can be used to decompress a whole file at once if the
1147 input file is mmap'ed.
1148 1144
1149 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1145 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1150 enough memory, Z_BUF_ERROR if there was not enough room in the output 1146 enough memory, Z_BUF_ERROR if there was not enough room in the output
@@ -1153,10 +1149,9 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1153 1149
1154/* 1150/*
1155 This library supports reading and writing files in gzip (.gz) format 1151 This library supports reading and writing files in gzip (.gz) format
1156 with an interface similar to that of stdio using the functions that start 1152 with an interface similar to that of stdio using the functions that start
1157 with "gz". The gzip format is different from the zlib format. gzip is a 1153 with "gz". The gzip format is different from the zlib format. gzip is a
1158 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 1154 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
1159
1160*/ 1155*/
1161 1156
1162typedef voidp gzFile; 1157typedef voidp gzFile;
@@ -1164,148 +1159,174 @@ typedef voidp gzFile;
1164/* 1159/*
1165ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1160ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1166 1161
1167 Opens a gzip (.gz) file for reading or writing. The mode parameter 1162 Opens a gzip (.gz) file for reading or writing. The mode parameter is as
1168 is as in fopen ("rb" or "wb") but can also include a compression level 1163 in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
1169 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 1164 a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
1170 Huffman only compression as in "wb1h", or 'R' for run-length encoding 1165 compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
1171 as in "wb1R". (See the description of deflateInit2 for more information 1166 for fixed code compression as in "wb9F". (See the description of
1172 about the strategy parameter.) 1167 deflateInit2 for more information about the strategy parameter.) Also "a"
1168 can be used instead of "w" to request that the gzip stream that will be
1169 written be appended to the file. "+" will result in an error, since reading
1170 and writing to the same gzip file is not supported.
1173 1171
1174 gzopen can be used to read a file which is not in gzip format; in this 1172 gzopen can be used to read a file which is not in gzip format; in this
1175 case gzread will directly read from the file without decompression. 1173 case gzread will directly read from the file without decompression.
1176 1174
1177 gzopen returns NULL if the file could not be opened or if there was 1175 gzopen returns NULL if the file could not be opened or if there was
1178 insufficient memory to allocate the (de)compression state; errno 1176 insufficient memory to allocate the (de)compression state; errno can be
1179 can be checked to distinguish the two cases (if errno is zero, the 1177 checked to distinguish the two cases (if errno is zero, the zlib error is
1180 zlib error is Z_MEM_ERROR). */ 1178 Z_MEM_ERROR).
1179*/
1181 1180
1182ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1181ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1183/* 1182/*
1184 gzdopen() associates a gzFile with the file descriptor fd. File 1183 gzdopen() associates a gzFile with the file descriptor fd. File
1185 descriptors are obtained from calls like open, dup, creat, pipe or 1184 descriptors are obtained from calls like open, dup, creat, pipe or fileno
1186 fileno (in the file has been previously opened with fopen). 1185 (in the file has been previously opened with fopen). The mode parameter is
1187 The mode parameter is as in gzopen. 1186 as in gzopen.
1188 The next call of gzclose on the returned gzFile will also close the 1187
1189 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file 1188 The next call of gzclose on the returned gzFile will also close the file
1190 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). 1189 descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor
1191 gzdopen returns NULL if there was insufficient memory to allocate 1190 fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
1192 the (de)compression state. 1191
1192 gzdopen returns NULL if there was insufficient memory to allocate the
1193 (de)compression state.
1193*/ 1194*/
1194 1195
1195ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); 1196ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1196/* 1197/*
1197 Set the internal buffer size used by this library's functions. The default 1198 Set the internal buffer size used by this library's functions. The
1198 buffer size is 8192 bytes. This function must be called after gz_open() or 1199 default buffer size is 8192 bytes. This function must be called after
1199 gz_dopen(), and before any other calls that read or write the file. The 1200 gzopen() or gzdopen(), and before any other calls that read or write the
1200 buffer memory allocation is always deferred to the first read or write. Two 1201 file. The buffer memory allocation is always deferred to the first read or
1201 buffers are allocated, either both of the specified size when writing, or 1202 write. Two buffers are allocated, either both of the specified size when
1202 one of the specified size and the other twice that size when reading. A 1203 writing, or one of the specified size and the other twice that size when
1203 larger buffer size of, for example, 64K or 128K bytes will noticeably 1204 reading. A larger buffer size of, for example, 64K or 128K bytes will
1204 increase the speed of decompression (reading). 1205 noticeably increase the speed of decompression (reading).
1205 gz_buffer() returns 0 on success, or -1 on failure, such as being called 1206
1207 The new buffer size also affects the maximum length for gzprintf().
1208
1209 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1206 too late. 1210 too late.
1207*/ 1211*/
1208 1212
1209ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1213ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1210/* 1214/*
1211 Dynamically update the compression level or strategy. See the description 1215 Dynamically update the compression level or strategy. See the description
1212 of deflateInit2 for the meaning of these parameters. 1216 of deflateInit2 for the meaning of these parameters.
1217
1213 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 1218 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1214 opened for writing. 1219 opened for writing.
1215*/ 1220*/
1216 1221
1217ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1222ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1218/* 1223/*
1219 Reads the given number of uncompressed bytes from the compressed file. 1224 Reads the given number of uncompressed bytes from the compressed file. If
1220 If the input file was not in gzip format, gzread copies the given number 1225 the input file was not in gzip format, gzread copies the given number of
1221 of bytes into the buffer. 1226 bytes into the buffer.
1222 gzread returns the number of uncompressed bytes actually read (0 for 1227
1223 end of file, -1 for error). */ 1228 After reaching the end of a gzip stream in the input, gzread will continue
1229 to read, looking for another gzip stream, or failing that, reading the rest
1230 of the input file directly without decompression. The entire input file
1231 will be read if gzread is called until it returns less than the requested
1232 len.
1233
1234 gzread returns the number of uncompressed bytes actually read (less than
1235 len for end of file, -1 for error).
1236*/
1224 1237
1225ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 1238ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1226 voidpc buf, unsigned len)); 1239 voidpc buf, unsigned len));
1227/* 1240/*
1228 Writes the given number of uncompressed bytes into the compressed file. 1241 Writes the given number of uncompressed bytes into the compressed file.
1229 gzwrite returns the number of uncompressed bytes actually written 1242 gzwrite returns the number of uncompressed bytes actually written (0 in case
1230 (0 in case of error). 1243 of error).
1231*/ 1244*/
1232 1245
1233ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); 1246ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
1234/* 1247/*
1235 Converts, formats, and writes the arguments to the compressed file under 1248 Converts, formats, and writes the arguments to the compressed file under
1236 control of the format string, as in fprintf. gzprintf returns the number of 1249 control of the format string, as in fprintf. gzprintf returns the number of
1237 uncompressed bytes actually written, or 0 in case of error. The number of 1250 uncompressed bytes actually written, or 0 in case of error. The number of
1238 uncompressed bytes written is limited to 8191, or one less than the buffer 1251 uncompressed bytes written is limited to 8191, or one less than the buffer
1239 size given to gz_buffer(). The caller should assure that this limit is not 1252 size given to gzbuffer(). The caller should assure that this limit is not
1240 exceeded. If it is exceeded, then gzprintf() will return an error (0) with 1253 exceeded. If it is exceeded, then gzprintf() will return an error (0) with
1241 nothing written. In this case, there may also be a buffer overflow with 1254 nothing written. In this case, there may also be a buffer overflow with
1242 unpredictable consequences, which is possible only if zlib was compiled 1255 unpredictable consequences, which is possible only if zlib was compiled with
1243 with the insecure functions sprintf() or vsprintf() because the secure 1256 the insecure functions sprintf() or vsprintf() because the secure snprintf()
1244 snprintf() or vsnprintf() functions were not available. 1257 or vsnprintf() functions were not available. This can be checked for using
1258 zlibCompileFlags().
1245*/ 1259*/
1246 1260
1247ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1261ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1248/* 1262/*
1249 Writes the given null-terminated string to the compressed file, excluding 1263 Writes the given null-terminated string to the compressed file, excluding
1250 the terminating null character. 1264 the terminating null character.
1251 gzputs returns the number of characters written, or -1 in case of error. 1265
1266 gzputs returns the number of characters written, or -1 in case of error.
1252*/ 1267*/
1253 1268
1254ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1269ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1255/* 1270/*
1256 Reads bytes from the compressed file until len-1 characters are read, or 1271 Reads bytes from the compressed file until len-1 characters are read, or
1257 a newline character is read and transferred to buf, or an end-of-file 1272 a newline character is read and transferred to buf, or an end-of-file
1258 condition is encountered. The string is then terminated with a null 1273 condition is encountered. The string is then terminated with a null
1259 character. 1274 character.
1260 gzgets returns buf, or Z_NULL in case of error. 1275
1276 gzgets returns buf, or Z_NULL in case of error.
1261*/ 1277*/
1262 1278
1263ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1279ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1264/* 1280/*
1265 Writes c, converted to an unsigned char, into the compressed file. 1281 Writes c, converted to an unsigned char, into the compressed file. gzputc
1266 gzputc returns the value that was written, or -1 in case of error. 1282 returns the value that was written, or -1 in case of error.
1267*/ 1283*/
1268 1284
1269ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1285ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1270/* 1286/*
1271 Reads one byte from the compressed file. gzgetc returns this byte 1287 Reads one byte from the compressed file. gzgetc returns this byte or -1
1272 or -1 in case of end of file or error. 1288 in case of end of file or error.
1273*/ 1289*/
1274 1290
1275ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1291ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1276/* 1292/*
1277 Push one character back onto the stream to be read again later. 1293 Push one character back onto the stream to be read again later. At least
1278 Only one character of push-back is allowed. gzungetc() returns the 1294 one character of push-back is allowed. gzungetc() returns the character
1279 character pushed, or -1 on failure. gzungetc() will fail if a 1295 pushed, or -1 on failure. gzungetc() will fail if c is -1, and may fail if
1280 character has been pushed but not read yet, or if c is -1. The pushed 1296 a character has been pushed but not read yet. The pushed character will be
1281 character will be discarded if the stream is repositioned with gzseek() 1297 discarded if the stream is repositioned with gzseek() or gzrewind().
1282 or gzrewind().
1283*/ 1298*/
1284 1299
1285ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1300ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1286/* 1301/*
1287 Flushes all pending output into the compressed file. The parameter 1302 Flushes all pending output into the compressed file. The parameter flush
1288 flush is as in the deflate() function. The return value is the zlib 1303 is as in the deflate() function. The return value is the zlib error number
1289 error number (see function gzerror below). gzflush returns Z_OK if 1304 (see function gzerror below).
1290 the flush parameter is Z_FINISH and all output could be flushed. 1305
1291 gzflush should be called only when strictly necessary because it can 1306 If the flush parameter is Z_FINISH, the remaining data is written and the
1292 degrade compression. 1307 gzip stream is completed in the output. If gzwrite() is called again, a new
1308 gzip stream will be started in the output. gzread() is able to read such
1309 concatented gzip streams.
1310
1311 gzflush should be called only when strictly necessary because it will
1312 degrade compression if called too often.
1293*/ 1313*/
1294 1314
1295/* 1315/*
1296ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1316ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1297 z_off_t offset, int whence)); 1317 z_off_t offset, int whence));
1298 1318
1299 Sets the starting position for the next gzread or gzwrite on the 1319 Sets the starting position for the next gzread or gzwrite on the given
1300 given compressed file. The offset represents a number of bytes in the 1320 compressed file. The offset represents a number of bytes in the
1301 uncompressed data stream. The whence parameter is defined as in lseek(2); 1321 uncompressed data stream. The whence parameter is defined as in lseek(2);
1302 the value SEEK_END is not supported. 1322 the value SEEK_END is not supported.
1323
1303 If the file is opened for reading, this function is emulated but can be 1324 If the file is opened for reading, this function is emulated but can be
1304 extremely slow. If the file is opened for writing, only forward seeks are 1325 extremely slow. If the file is opened for writing, only forward seeks are
1305 supported; gzseek then compresses a sequence of zeroes up to the new 1326 supported; gzseek then compresses a sequence of zeroes up to the new
1306 starting position. 1327 starting position.
1307 1328
1308 gzseek returns the resulting offset location as measured in bytes from 1329 gzseek returns the resulting offset location as measured in bytes from
1309 the beginning of the uncompressed stream, or -1 in case of error, in 1330 the beginning of the uncompressed stream, or -1 in case of error, in
1310 particular if the file is opened for writing and the new starting position 1331 particular if the file is opened for writing and the new starting position
1311 would be before the current position. 1332 would be before the current position.
@@ -1315,47 +1336,50 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1315/* 1336/*
1316 Rewinds the given file. This function is supported only for reading. 1337 Rewinds the given file. This function is supported only for reading.
1317 1338
1318 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 1339 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1319*/ 1340*/
1320 1341
1321/* 1342/*
1322ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1343ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1323 1344
1324 Returns the starting position for the next gzread or gzwrite on the 1345 Returns the starting position for the next gzread or gzwrite on the given
1325 given compressed file. This position represents a number of bytes in the 1346 compressed file. This position represents a number of bytes in the
1326 uncompressed data stream, and is zero when starting, even if appending 1347 uncompressed data stream, and is zero when starting, even if appending or
1327 or reading a gzip stream from the middle of a file using gz_dopen(). 1348 reading a gzip stream from the middle of a file using gzdopen().
1328 1349
1329 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1350 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1330*/ 1351*/
1331 1352
1332/* 1353/*
1333ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); 1354ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1334 1355
1335 Returns the current offset in the file being read or written. This offset 1356 Returns the current offset in the file being read or written. This offset
1336 includes the count of bytes that precede the gzip stream, for example when 1357 includes the count of bytes that precede the gzip stream, for example when
1337 appending or when using gz_dopen() for reading. When reading, the offset 1358 appending or when using gzdopen() for reading. When reading, the offset
1338 includes data that has been used to generate what has been provided as 1359 includes data that has been used to generate what has been provided as
1339 uncompressed data so far, but does not include as yet unused buffered input. 1360 uncompressed data so far, but does not include as yet unused buffered input.
1340 On error, gz_offset() returns -1. 1361 On error, gzoffset() returns -1.
1341*/ 1362*/
1342 1363
1343ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1364ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1344/* 1365/*
1345 Returns 1 when EOF has previously been detected reading the given 1366 Returns 1 when EOF has previously been detected reading the given input
1346 input stream, otherwise zero. 1367 stream, otherwise zero.
1347*/ 1368*/
1348 1369
1349ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1370ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1350/* 1371/*
1351 Returns 1 if file is being read directly without decompression, otherwise 1372 Returns 1 if file is being read directly without decompression, otherwise
1352 zero. 1373 zero. gzdirect() called immediately after gzopen() will always return zero,
1374 since nothing has been read yet. Whether to read the file with
1375 decompression or not is not determined until after the first read operation
1376 (e.g. gzread(), gzgetc(), etc.).
1353*/ 1377*/
1354 1378
1355ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1379ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1356/* 1380/*
1357 Flushes all pending output if necessary, closes the compressed file 1381 Flushes all pending output if necessary, closes the compressed file and
1358 and deallocates all the (de)compression state. The return value is the zlib 1382 deallocates all the (de)compression state. The return value is the zlib
1359 error number. Note that once file is closed, you cannot call gzerror with 1383 error number. Note that once file is closed, you cannot call gzerror with
1360 file, since its structures have been deallocated. 1384 file, since its structures have been deallocated.
1361*/ 1385*/
@@ -1363,31 +1387,31 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1363ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); 1387ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1364ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); 1388ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1365/* 1389/*
1366 Same as gz_close(), but gz_close_r() is only for use when reading, and 1390 Same as gzclose(), but gzclose_r() is only for use when reading, and
1367 gz_close_w() is only for use when writing. The advantage to using these 1391 gzclose_w() is only for use when writing. The advantage to using these
1368 instead of gz_close() is that they avoid linking in zlib compression or 1392 instead of gzclose() is that they avoid linking in zlib compression or
1369 decompression code that is not used when only reading or only writing 1393 decompression code that is not used when only reading or only writing
1370 respectively. If gz_close() is used, then both compression and 1394 respectively. If gzclose() is used, then both compression and decompression
1371 decompression code will be included the application when linking to a 1395 code will be included the application when linking to a static zlib library.
1372 static zlib library.
1373*/ 1396*/
1374 1397
1375ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1398ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1376/* 1399/*
1377 Returns the error message for the last error which occurred on the 1400 Returns the error message for the last error which occurred on the given
1378 given compressed file. errnum is set to zlib error number. If an 1401 compressed file. errnum is set to zlib error number. If an error occurred
1379 error occurred in the file system and not in the compression library, 1402 in the file system and not in the compression library, errnum is set to
1380 errnum is set to Z_ERRNO and the application may consult errno 1403 Z_ERRNO and the application may consult errno to get the exact error code.
1381 to get the exact error code.
1382 1404
1383 The application must not modify the returned string and future calls to 1405 The application must not modify the returned string. Future calls to
1384 this function may invalidate the returned string. 1406 this function may invalidate the previously returned string. If file is
1407 closed, then the string previously returned by gzerror will no longer be
1408 available.
1385*/ 1409*/
1386 1410
1387ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1411ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1388/* 1412/*
1389 Clears the error and end-of-file flags for file. This is analogous to the 1413 Clears the error and end-of-file flags for file. This is analogous to the
1390 clearerr() function in stdio. This is useful for continuing to read a gzip 1414 clearerr() function in stdio. This is useful for continuing to read a gzip
1391 file that is being written concurrently. 1415 file that is being written concurrently.
1392*/ 1416*/
1393 1417
@@ -1395,17 +1419,20 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1395 1419
1396/* 1420/*
1397 These functions are not related to compression but are exported 1421 These functions are not related to compression but are exported
1398 anyway because they might be useful in applications using the 1422 anyway because they might be useful in applications using the compression
1399 compression library. 1423 library.
1400*/ 1424*/
1401 1425
1402ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 1426ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1403/* 1427/*
1404 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 1428 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1405 return the updated checksum. If buf is Z_NULL, this function returns 1429 return the updated checksum. If buf is Z_NULL, this function returns the
1406 the required initial value for the checksum. 1430 required initial value for the checksum.
1407 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1431
1408 much faster. Usage example: 1432 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1433 much faster.
1434
1435 Usage example:
1409 1436
1410 uLong adler = adler32(0L, Z_NULL, 0); 1437 uLong adler = adler32(0L, Z_NULL, 0);
1411 1438
@@ -1428,9 +1455,11 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1428ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 1455ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1429/* 1456/*
1430 Update a running CRC-32 with the bytes buf[0..len-1] and return the 1457 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1431 updated CRC-32. If buf is Z_NULL, this function returns the required initial 1458 updated CRC-32. If buf is Z_NULL, this function returns the required
1432 value for the for the crc. Pre- and post-conditioning (one's complement) is 1459 initial value for the for the crc. Pre- and post-conditioning (one's
1433 performed within this function so it shouldn't be done by the application. 1460 complement) is performed within this function so it shouldn't be done by the
1461 application.
1462
1434 Usage example: 1463 Usage example:
1435 1464
1436 uLong crc = crc32(0L, Z_NULL, 0); 1465 uLong crc = crc32(0L, Z_NULL, 0);
diff --git a/zlib.map b/zlib.map
index 499213d..c99e973 100644
--- a/zlib.map
+++ b/zlib.map
@@ -14,6 +14,8 @@ ZLIB_1.2.0 {
14 zcalloc; 14 zcalloc;
15 zcfree; 15 zcfree;
16 z_errmsg; 16 z_errmsg;
17 gz_error;
18 gzio_old;
17 _*; 19 _*;
18}; 20};
19 21
@@ -51,3 +53,11 @@ ZLIB_1.2.3.4 {
51 inflateReset2; 53 inflateReset2;
52 inflateMark; 54 inflateMark;
53} ZLIB_1.2.3.3; 55} ZLIB_1.2.3.3;
56
57ZLIB_1.2.3.5 {
58 gzbuffer;
59 gzoffset;
60 gzoffset64;
61 gzclose_r;
62 gzclose_w;
63} ZLIB_1.2.3.4;
diff --git a/zutil.c b/zutil.c
index d55f594..98a55a8 100644
--- a/zutil.c
+++ b/zutil.c
@@ -34,25 +34,25 @@ uLong ZEXPORT zlibCompileFlags()
34 uLong flags; 34 uLong flags;
35 35
36 flags = 0; 36 flags = 0;
37 switch (sizeof(uInt)) { 37 switch ((int)(sizeof(uInt))) {
38 case 2: break; 38 case 2: break;
39 case 4: flags += 1; break; 39 case 4: flags += 1; break;
40 case 8: flags += 2; break; 40 case 8: flags += 2; break;
41 default: flags += 3; 41 default: flags += 3;
42 } 42 }
43 switch (sizeof(uLong)) { 43 switch ((int)(sizeof(uLong))) {
44 case 2: break; 44 case 2: break;
45 case 4: flags += 1 << 2; break; 45 case 4: flags += 1 << 2; break;
46 case 8: flags += 2 << 2; break; 46 case 8: flags += 2 << 2; break;
47 default: flags += 3 << 2; 47 default: flags += 3 << 2;
48 } 48 }
49 switch (sizeof(voidpf)) { 49 switch ((int)(sizeof(voidpf))) {
50 case 2: break; 50 case 2: break;
51 case 4: flags += 1 << 4; break; 51 case 4: flags += 1 << 4; break;
52 case 8: flags += 2 << 4; break; 52 case 8: flags += 2 << 4; break;
53 default: flags += 3 << 4; 53 default: flags += 3 << 4;
54 } 54 }
55 switch (sizeof(z_off_t)) { 55 switch ((int)(sizeof(z_off_t))) {
56 case 2: break; 56 case 2: break;
57 case 4: flags += 1 << 6; break; 57 case 4: flags += 1 << 6; break;
58 case 8: flags += 2 << 6; break; 58 case 8: flags += 2 << 6; break;
diff --git a/zutil.h b/zutil.h
index 18a13cf..93d6553 100644
--- a/zutil.h
+++ b/zutil.h
@@ -116,7 +116,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
116#ifdef OS2 116#ifdef OS2
117# define OS_CODE 0x06 117# define OS_CODE 0x06
118# ifdef M_I86 118# ifdef M_I86
119 #include <malloc.h> 119# include <malloc.h>
120# endif 120# endif
121#endif 121#endif
122 122
@@ -162,9 +162,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
162#endif 162#endif
163 163
164#if defined(__BORLANDC__) 164#if defined(__BORLANDC__)
165#pragma warn -8004 165 #pragma warn -8004
166#pragma warn -8008 166 #pragma warn -8008
167#pragma warn -8066 167 #pragma warn -8066
168#endif 168#endif
169 169
170#ifdef _LARGEFILE64_SOURCE 170#ifdef _LARGEFILE64_SOURCE