提交 dc5a43eb 编写于 作者: M Mark Adler

zlib 1.2.3.6

上级 d004b047
...@@ -21,7 +21,6 @@ check_include_file(stddef.h HAVE_STDDEF_H) ...@@ -21,7 +21,6 @@ check_include_file(stddef.h HAVE_STDDEF_H)
# Check to see if we have large file support # Check to see if we have large file support
# #
set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE) set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
# We add these other definitions here because CheckTypeSize.cmake # We add these other definitions here because CheckTypeSize.cmake
# in CMake 2.4.x does not automatically do so and we want # in CMake 2.4.x does not automatically do so and we want
# compatibility with CMake 2.4.x. # compatibility with CMake 2.4.x.
...@@ -34,9 +33,7 @@ endif() ...@@ -34,9 +33,7 @@ endif()
if(HAVE_STDDEF_H) if(HAVE_STDDEF_H)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
endif() endif()
check_type_size(off64_t OFF64_T) check_type_size(off64_t OFF64_T)
if(HAVE_OFF64_T) if(HAVE_OFF64_T)
add_definitions(-D_LARGEFILE64_SOURCE) add_definitions(-D_LARGEFILE64_SOURCE)
endif() endif()
...@@ -62,23 +59,6 @@ if(NOT HAVE_ERRNO_H) ...@@ -62,23 +59,6 @@ if(NOT HAVE_ERRNO_H)
add_definitions(-DNO_ERRNO_H) add_definitions(-DNO_ERRNO_H)
endif() endif()
#
# Check for mmap support
#
set(mmap_test_code "
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
caddr_t hello() {
return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
}
int main() { return 0; }
")
check_c_source_compiles("${mmap_test_code}" USE_MMAP)
if(USE_MMAP)
add_definitions(-DUSE_MMAP)
endif()
# #
# Create the zlibdefs.h file. # Create the zlibdefs.h file.
# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead # Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead
...@@ -88,7 +68,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein ...@@ -88,7 +68,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein
${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h) ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h)
if(MSVC) if(MSVC)
set(CMAKE_DEBUG_POSTFIX "D") set(CMAKE_DEBUG_POSTFIX "d")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
endif() endif()
...@@ -130,15 +110,47 @@ set(ZLIB_SRCS ...@@ -130,15 +110,47 @@ set(ZLIB_SRCS
trees.c trees.c
uncompr.c uncompr.c
zutil.c zutil.c
win32/zlib1.rc
) )
# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
if(MINGW)
# This gets us DLL resource information when compiling on MinGW.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
COMMAND windres.exe
-D GCC_WINDRES
-I ${CMAKE_CURRENT_SOURCE_DIR}
-o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
endif(MINGW)
add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
set_target_properties(zlib PROPERTIES VERSION 1.2.3.4)
set_target_properties(zlib PROPERTIES SOVERSION 1) set_target_properties(zlib PROPERTIES SOVERSION 1)
if(NOT CYGWIN)
# This property causes shared libraries on Linux to have the full version
# encoded into their final filename. We disable this on Cygwin because
# it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
# seems to be the default.
#
# This has no effect with MSVC, on that platform the version info for
# the DLL comes from the resource file win32/zlib1.rc
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
endif()
if(UNIX) if(UNIX)
# On unix like platforms the library is almost always called libz # On unix-like platforms the library is almost always called libz
set_target_properties(zlib PROPERTIES OUTPUT_NAME z) set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
elseif(BUILD_SHARED_LIBS AND WIN32)
# Creates zlib1.dll when building shared library version
set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
endif() endif()
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
......
ChangeLog file for zlib ChangeLog file for zlib
Changes in 1.2.3.6 (17 Jan 2010)
- Avoid void * arithmetic in gzread.c and gzwrite.c
- Make compilers happier with const char * for gz_error message
- Avoid unused parameter warning in inflate.c
- Avoid signed-unsigned comparison warning in inflate.c
- Indent #pragma's for traditional C
- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
- Correct email address in configure for system options
- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
- Update zlib.map [Brown]
- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Tšršk]
- Apply various fixes to CMakeLists.txt [Lowman]
- Add checks on len in gzread() and gzwrite()
- Add error message for no more room for gzungetc()
- Remove zlib version check in gzwrite()
- Defer compression of gzprintf() result until need to
- Use snprintf() in gzdopen() if available
- Remove USE_MMAP configuration determination (only used by minigzip)
- Remove examples/pigz.c (available separately)
- Update examples/gun.c to 1.6
Changes in 1.2.3.5 (8 Jan 2010) Changes in 1.2.3.5 (8 Jan 2010)
- Add space after #if in zutil.h for some compilers - Add space after #if in zutil.h for some compilers
- Fix relatively harmless bug in deflate_fast() [Exarevsky] - Fix relatively harmless bug in deflate_fast() [Exarevsky]
...@@ -21,6 +42,7 @@ Changes in 1.2.3.5 (8 Jan 2010) ...@@ -21,6 +42,7 @@ Changes in 1.2.3.5 (8 Jan 2010)
- Replace gzio.c with a new set of routines with the same functionality - Replace gzio.c with a new set of routines with the same functionality
- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above - Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
- Update contrib/minizip to 1.1b - Update contrib/minizip to 1.1b
- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
Changes in 1.2.3.4 (21 Dec 2009) Changes in 1.2.3.4 (21 Dec 2009)
- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility - Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
......
# Makefile for zlib # Makefile for zlib
# Copyright (C) 1995-2006 Jean-loup Gailly. # Copyright (C) 1995-2010 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h # For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type: # To compile and test, type:
...@@ -32,7 +32,7 @@ CPP=$(CC) -E ...@@ -32,7 +32,7 @@ CPP=$(CC) -E
STATICLIB=libz.a STATICLIB=libz.a
SHAREDLIB=libz.so SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.3.5 SHAREDLIBV=libz.so.1.2.3.6
SHAREDLIBM=libz.so.1 SHAREDLIBM=libz.so.1
LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
...@@ -124,10 +124,10 @@ match.lo: match.S ...@@ -124,10 +124,10 @@ match.lo: match.S
rm -f _match.s rm -f _match.s
example64.o: example.c zlib.h zconf.h zlibdefs.h example64.o: example.c zlib.h zconf.h zlibdefs.h
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
.SUFFIXES: .lo .SUFFIXES: .lo
......
# Makefile for zlib # Makefile for zlib
# Copyright (C) 1995-2006 Jean-loup Gailly. # Copyright (C) 1995-2010 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h # For conditions of distribution and use, see copyright notice in zlib.h
# To compile and test, type: # To compile and test, type:
...@@ -32,7 +32,7 @@ CPP=$(CC) -E ...@@ -32,7 +32,7 @@ CPP=$(CC) -E
STATICLIB=libz.a STATICLIB=libz.a
SHAREDLIB=libz.so SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.3.5 SHAREDLIBV=libz.so.1.2.3.6
SHAREDLIBM=libz.so.1 SHAREDLIBM=libz.so.1
LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
...@@ -124,10 +124,10 @@ match.lo: match.S ...@@ -124,10 +124,10 @@ match.lo: match.S
rm -f _match.s rm -f _match.s
example64.o: example.c zlib.h zconf.h zlibdefs.h example64.o: example.c zlib.h zconf.h zlibdefs.h
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $< $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
.SUFFIXES: .lo .SUFFIXES: .lo
......
ZLIB DATA COMPRESSION LIBRARY ZLIB DATA COMPRESSION LIBRARY
zlib 1.2.3.5 is a general purpose data compression library. All the code is zlib 1.2.3.6 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs thread safe. The data format used by the zlib library is described by RFCs
(Request for Comments) 1950 to 1952 in the files (Request for Comments) 1950 to 1952 in the files
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) http://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 ...@@ -33,7 +33,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available in issue of Dr. Dobb's Journal; a copy of the article is available in
http://dogma.net/markn/articles/zlibtool/zlibtool.htm http://dogma.net/markn/articles/zlibtool/zlibtool.htm
The changes made in version 1.2.3.5 are documented in the file ChangeLog. The changes made in version 1.2.3.6 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory "contrib". Unsupported third party contributions are provided in directory "contrib".
......
* ZLIB.INC - Interface to the general purpose compression library * ZLIB.INC - Interface to the general purpose compression library
* *
* ILE RPG400 version by Patrick Monnerat, DATASPHERE. * ILE RPG400 version by Patrick Monnerat, DATASPHERE.
* Version 1.2.3.5 * Version 1.2.3.6
* *
* *
* WARNING: * WARNING:
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
* *
* Versioning information. * Versioning information.
* *
D ZLIB_VERSION C '1.2.3.5' D ZLIB_VERSION C '1.2.3.6'
D ZLIB_VERNUM C X'1235' D ZLIB_VERNUM C X'1236'
* *
* Other equates. * Other equates.
* *
......
...@@ -78,6 +78,9 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then ...@@ -78,6 +78,9 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
CC="$cc" CC="$cc"
SFLAGS="${CFLAGS-"-O3"} -fPIC" SFLAGS="${CFLAGS-"-O3"} -fPIC"
CFLAGS="${CFLAGS-"-O3"}" CFLAGS="${CFLAGS-"-O3"}"
if test "${ZLIBGCCWARN}" = "YES"; then
CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
fi
if test -z "$uname"; then if test -z "$uname"; then
uname=`(uname -s || echo unknown) 2>/dev/null` uname=`(uname -s || echo unknown) 2>/dev/null`
fi fi
...@@ -154,8 +157,8 @@ else ...@@ -154,8 +157,8 @@ else
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
CFLAGS=${CFLAGS-"-O2"} CFLAGS=${CFLAGS-"-O2"}
LDSHARED=${LDSHARED-"ld"} ;; LDSHARED=${LDSHARED-"ld"} ;;
SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"} CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
UNIX_System_V\ 4.2.0) UNIX_System_V\ 4.2.0)
SFLAGS=${CFLAGS-"-KPIC -O"} SFLAGS=${CFLAGS-"-KPIC -O"}
...@@ -173,7 +176,7 @@ else ...@@ -173,7 +176,7 @@ else
SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
LDSHARED=${LDSHARED-"xlc -G"} ;; LDSHARED=${LDSHARED-"xlc -G"} ;;
# send working options for other systems to support@gzip.org # send working options for other systems to zlib@gzip.org
*) SFLAGS=${CFLAGS-"-O"} *) SFLAGS=${CFLAGS-"-O"}
CFLAGS=${CFLAGS-"-O"} CFLAGS=${CFLAGS-"-O"}
LDSHARED=${LDSHARED-"cc -shared"} ;; LDSHARED=${LDSHARED-"cc -shared"} ;;
...@@ -488,22 +491,6 @@ else ...@@ -488,22 +491,6 @@ else
SFLAGS="$SFLAGS -DNO_ERRNO_H" SFLAGS="$SFLAGS -DNO_ERRNO_H"
fi fi
cat > $test.c <<EOF
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
caddr_t hello() {
return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
CFLAGS="$CFLAGS -DUSE_MMAP"
SFLAGS="$SFLAGS -DUSE_MMAP"
echo Checking for mmap support... Yes.
else
echo Checking for mmap support... No.
fi
CPP=${CPP-"$CC -E"} CPP=${CPP-"$CC -E"}
case $CFLAGS in case $CFLAGS in
*ASMV*) *ASMV*)
......
/* inftree9.c -- generate Huffman trees for efficient decoding /* inftree9.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2008 Mark Adler * Copyright (C) 1995-2010 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate9_copyright[] = const char inflate9_copyright[] =
" inflate9 1.2.3.5 Copyright 1995-2009 Mark Adler "; " inflate9 1.2.3.6 Copyright 1995-2010 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
...@@ -64,7 +64,7 @@ unsigned short FAR *work; ...@@ -64,7 +64,7 @@ unsigned short FAR *work;
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
133, 133, 133, 133, 144, 69, 199}; 133, 133, 133, 133, 144, 199, 70};
static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
......
$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig
$ open/write zdef vmsdefs.h
$ copy sys$input: zdef
$ deck
#define unix
#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from
#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator
#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord
#define Write_EndOfCentralDirectoryRecord Write_EoDRecord
$ eod
$ close zdef
$ copy vmsdefs.h,ioapi.h_orig ioapi.h
$ cc/include=[--]/prefix=all ioapi.c
$ cc/include=[--]/prefix=all miniunz.c
$ cc/include=[--]/prefix=all unzip.c
$ cc/include=[--]/prefix=all minizip.c
$ cc/include=[--]/prefix=all zip.c
$ link miniunz,unzip,ioapi,[--]libz.olb/lib
$ link minizip,zip,ioapi,[--]libz.olb/lib
$ mcr []minizip test minizip64_info.txt
$ mcr []miniunz -l test.zip
$ rename minizip64_info.txt; minizip64_info.txt_old
$ mcr []miniunz test.zip
$ delete test.zip;*
$exit
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#define IDR_VERSION1 1 #define IDR_VERSION1 1
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
FILEVERSION 1,2,3,5 FILEVERSION 1,2,3,6
PRODUCTVERSION 1,2,3,5 PRODUCTVERSION 1,2,3,6
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0 FILEFLAGS 0
FILEOS VOS_DOS_WINDOWS32 FILEOS VOS_DOS_WINDOWS32
...@@ -17,12 +17,12 @@ BEGIN ...@@ -17,12 +17,12 @@ BEGIN
BEGIN BEGIN
VALUE "FileDescription", "zlib data compression library\0" VALUE "FileDescription", "zlib data compression library\0"
VALUE "FileVersion", "1.2.3.5\0" VALUE "FileVersion", "1.2.3.6\0"
VALUE "InternalName", "zlib\0" VALUE "InternalName", "zlib\0"
VALUE "OriginalFilename", "zlib.dll\0" VALUE "OriginalFilename", "zlib.dll\0"
VALUE "ProductName", "ZLib.DLL\0" VALUE "ProductName", "ZLib.DLL\0"
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0" VALUE "LegalCopyright", "(C) 1995-2010 Jean-loup Gailly & Mark Adler\0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#include "deflate.h" #include "deflate.h"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.2.3.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; " deflate 1.2.3.6 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
......
...@@ -34,12 +34,6 @@ gzlog.h ...@@ -34,12 +34,6 @@ gzlog.h
and deflateSetDictionary() and deflateSetDictionary()
- illustrates use of a gzip header extra field - illustrates use of a gzip header extra field
pigz.c
parallel implementation of gzip compression
- uses pthreads to speed up compression on multiple core machines
- illustrates the use of deflateSetDictionary() with raw deflate
- illustrates the use of crc32_combine()
zlib_how.html zlib_how.html
painfully comprehensive description of zpipe.c (see below) painfully comprehensive description of zpipe.c (see below)
- describes in excruciating detail the use of deflate() and inflate() - describes in excruciating detail the use of deflate() and inflate()
......
/* gun.c -- simple gunzip to give an example of the use of inflateBack() /* gun.c -- simple gunzip to give an example of the use of inflateBack()
* Copyright (C) 2003, 2005 Mark Adler * Copyright (C) 2003, 2005, 2008, 2010 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
Version 1.3 12 June 2005 Mark Adler */ Version 1.6 17 January 2010 Mark Adler */
/* Version history: /* Version history:
1.0 16 Feb 2003 First version for testing of inflateBack() 1.0 16 Feb 2003 First version for testing of inflateBack()
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
1.2 20 Mar 2005 Add Unix compress (LZW) decompression 1.2 20 Mar 2005 Add Unix compress (LZW) decompression
Copy file attributes from input file to output file Copy file attributes from input file to output file
1.3 12 Jun 2005 Add casts for error messages [Oberhumer] 1.3 12 Jun 2005 Add casts for error messages [Oberhumer]
1.4 8 Dec 2006 LZW decompression speed improvements
1.5 9 Feb 2008 Avoid warning in latest version of gcc
1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings
*/ */
/* /*
...@@ -197,14 +200,14 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, ...@@ -197,14 +200,14 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
int outfile, z_stream *strm) int outfile, z_stream *strm)
{ {
int last; /* last byte read by NEXT(), or -1 if EOF */ int last; /* last byte read by NEXT(), or -1 if EOF */
int chunk; /* bytes left in current chunk */ unsigned chunk; /* bytes left in current chunk */
int left; /* bits left in rem */ int left; /* bits left in rem */
unsigned rem; /* unused bits from input */ unsigned rem; /* unused bits from input */
int bits; /* current bits per code */ int bits; /* current bits per code */
unsigned code; /* code, table traversal index */ unsigned code; /* code, table traversal index */
unsigned mask; /* mask for current bits codes */ unsigned mask; /* mask for current bits codes */
int max; /* maximum bits per code for this stream */ int max; /* maximum bits per code for this stream */
int flags; /* compress flags, then block compress flag */ unsigned flags; /* compress flags, then block compress flag */
unsigned end; /* last valid entry in prefix/suffix tables */ unsigned end; /* last valid entry in prefix/suffix tables */
unsigned temp; /* current code */ unsigned temp; /* current code */
unsigned prev; /* previous code */ unsigned prev; /* previous code */
...@@ -212,6 +215,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, ...@@ -212,6 +215,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
unsigned stack; /* next position for reversed string */ unsigned stack; /* next position for reversed string */
unsigned outcnt; /* bytes in output buffer */ unsigned outcnt; /* bytes in output buffer */
struct outd outd; /* output structure */ struct outd outd; /* output structure */
unsigned char *p;
/* set up output */ /* set up output */
outd.outfile = outfile; outd.outfile = outfile;
...@@ -322,10 +326,12 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, ...@@ -322,10 +326,12 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
} }
/* walk through linked list to generate output in reverse order */ /* walk through linked list to generate output in reverse order */
p = match + stack;
while (code >= 256) { while (code >= 256) {
match[stack++] = suffix[code]; *p++ = suffix[code];
code = prefix[code]; code = prefix[code];
} }
stack = p - match;
match[stack++] = (unsigned char)code; match[stack++] = (unsigned char)code;
final = code; final = code;
...@@ -349,9 +355,11 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, ...@@ -349,9 +355,11 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp,
} }
outcnt = 0; outcnt = 0;
} }
p = match + stack;
do { do {
outbuf[outcnt++] = match[--stack]; outbuf[outcnt++] = *--p;
} while (stack); } while (p > match);
stack = 0;
/* loop for next code with final and prev as the last match, rem and /* loop for next code with final and prev as the last match, rem and
left provide the first 0..7 bits of the next code, end is the last 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,7 +383,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
{ {
int ret, first, last; int ret, first, last;
unsigned have, flags, len; unsigned have, flags, len;
unsigned char *next; unsigned char *next = NULL;
struct ind ind, *indp; struct ind ind, *indp;
struct outd outd; struct outd outd;
...@@ -471,10 +479,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile) ...@@ -471,10 +479,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
/* check trailer */ /* check trailer */
ret = Z_BUF_ERROR; ret = Z_BUF_ERROR;
if (NEXT() != (outd.crc & 0xff) || if (NEXT() != (int)(outd.crc & 0xff) ||
NEXT() != ((outd.crc >> 8) & 0xff) || NEXT() != (int)((outd.crc >> 8) & 0xff) ||
NEXT() != ((outd.crc >> 16) & 0xff) || NEXT() != (int)((outd.crc >> 16) & 0xff) ||
NEXT() != ((outd.crc >> 24) & 0xff)) { NEXT() != (int)((outd.crc >> 24) & 0xff)) {
/* crc error */ /* crc error */
if (last != -1) { if (last != -1) {
strm->msg = (char *)"incorrect data check"; strm->msg = (char *)"incorrect data check";
...@@ -482,10 +490,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile) ...@@ -482,10 +490,10 @@ local int gunpipe(z_stream *strm, int infile, int outfile)
} }
break; break;
} }
if (NEXT() != (outd.total & 0xff) || if (NEXT() != (int)(outd.total & 0xff) ||
NEXT() != ((outd.total >> 8) & 0xff) || NEXT() != (int)((outd.total >> 8) & 0xff) ||
NEXT() != ((outd.total >> 16) & 0xff) || NEXT() != (int)((outd.total >> 16) & 0xff) ||
NEXT() != ((outd.total >> 24) & 0xff)) { NEXT() != (int)((outd.total >> 24) & 0xff)) {
/* length error */ /* length error */
if (last != -1) { if (last != -1) {
strm->msg = (char *)"incorrect length check"; strm->msg = (char *)"incorrect length check";
...@@ -642,8 +650,8 @@ int main(int argc, char **argv) ...@@ -642,8 +650,8 @@ int main(int argc, char **argv)
argv++; argv++;
test = 0; test = 0;
if (argc && strcmp(*argv, "-h") == 0) { if (argc && strcmp(*argv, "-h") == 0) {
fprintf(stderr, "gun 1.3 (12 Jun 2005)\n"); fprintf(stderr, "gun 1.6 (17 Jan 2010)\n");
fprintf(stderr, "Copyright (c) 2005 Mark Adler\n"); fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n");
fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n");
return 0; return 0;
} }
......
/* pigz.c -- parallel implementation of gzip
* Copyright (C) 2007 Mark Adler
* Version 1.1 28 January 2007 Mark Adler
*/
/* Version history:
1.0 17 Jan 2007 First version
1.1 28 Jan 2007 Avoid void * arithmetic (some compilers don't get that)
Add note about requiring zlib 1.2.3
Allow compression level 0 (no compression)
Completely rewrite parallelism -- add a write thread
Use deflateSetDictionary() to make use of history
Tune argument defaults to best performance on four cores
*/
/*
pigz compresses from stdin to stdout using threads to make use of multiple
processors and cores. The input is broken up into 128 KB chunks, and each
is compressed separately. The CRC for each chunk is also calculated
separately. The compressed chunks are written in order to the output,
and the overall CRC is calculated from the CRC's of the chunks.
The compressed data format generated is the gzip format using the deflate
compression method. First a gzip header is written, followed by raw deflate
partial streams. They are partial, in that they do not have a terminating
block. At the end, the deflate stream is terminated with a final empty
static block, and lastly a gzip trailer is written with the CRC and the
number of input bytes.
Each raw deflate partial stream is terminated by an empty stored block
(using the Z_SYNC_FLUSH option of zlib), in order to end that partial
bit stream at a byte boundary. That allows the partial streams to be
concantenated simply as sequences of bytes. This adds a very small four
or five byte overhead to the output for each input chunk.
zlib's crc32_combine() routine allows the calcuation of the CRC of the
entire input using the independent CRC's of the chunks. pigz requires zlib
version 1.2.3 or later, since that is the first version that provides the
crc32_combine() function.
pigz uses the POSIX pthread library for thread control and communication.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include "zlib.h"
#define local static
/* exit with error */
local void bail(char *msg)
{
fprintf(stderr, "pigz abort: %s\n", msg);
exit(1);
}
/* read up to len bytes into buf, repeating read() calls as needed */
local size_t readn(int desc, unsigned char *buf, size_t len)
{
ssize_t ret;
size_t got;
got = 0;
while (len) {
ret = read(desc, buf, len);
if (ret < 0)
bail("read error");
if (ret == 0)
break;
buf += ret;
len -= ret;
got += ret;
}
return got;
}
/* write len bytes, repeating write() calls as needed */
local void writen(int desc, unsigned char *buf, size_t len)
{
ssize_t ret;
while (len) {
ret = write(desc, buf, len);
if (ret < 1)
bail("write error");
buf += ret;
len -= ret;
}
}
/* a flag variable for communication between two threads */
struct flag {
int value; /* value of flag */
pthread_mutex_t lock; /* lock for checking and changing flag */
pthread_cond_t cond; /* condition for signaling on flag change */
};
/* initialize a flag for use, starting with value val */
local void flag_init(struct flag *me, int val)
{
me->value = val;
pthread_mutex_init(&(me->lock), NULL);
pthread_cond_init(&(me->cond), NULL);
}
/* set the flag to val, signal another process that may be waiting for it */
local void flag_set(struct flag *me, int val)
{
pthread_mutex_lock(&(me->lock));
me->value = val;
pthread_cond_signal(&(me->cond));
pthread_mutex_unlock(&(me->lock));
}
/* if it isn't already, wait for some other thread to set the flag to val */
local void flag_wait(struct flag *me, int val)
{
pthread_mutex_lock(&(me->lock));
while (me->value != val)
pthread_cond_wait(&(me->cond), &(me->lock));
pthread_mutex_unlock(&(me->lock));
}
/* if flag is equal to val, wait for some other thread to change it */
local void flag_wait_not(struct flag *me, int val)
{
pthread_mutex_lock(&(me->lock));
while (me->value == val)
pthread_cond_wait(&(me->cond), &(me->lock));
pthread_mutex_unlock(&(me->lock));
}
/* clean up the flag when done with it */
local void flag_done(struct flag *me)
{
pthread_cond_destroy(&(me->cond));
pthread_mutex_destroy(&(me->lock));
}
/* a unit of work to feed to compress_thread() -- it is assumed that the out
buffer is large enough to hold the maximum size len bytes could deflate to,
plus five bytes for the final sync marker */
struct work {
size_t len; /* length of input */
unsigned long crc; /* crc of input */
unsigned char *buf; /* input */
unsigned char *out; /* space for output (guaranteed big enough) */
z_stream strm; /* pre-initialized z_stream */
struct flag busy; /* busy flag indicating work unit in use */
pthread_t comp; /* this compression thread */
};
/* busy flag values */
#define IDLE 0 /* compress and writing done -- can start compress */
#define COMP 1 /* compress -- input and output buffers in use */
#define WRITE 2 /* compress done, writing output -- can read input */
/* read-only globals (set by main/read thread before others started) */
local int ind; /* input file descriptor */
local int outd; /* output file descriptor */
local int level; /* compression level */
local int procs; /* number of compression threads (>= 2) */
local size_t size; /* uncompressed input size per thread (>= 32K) */
local struct work *jobs; /* work units: jobs[0..procs-1] */
/* next and previous jobs[] indices */
#define NEXT(n) ((n) == procs - 1 ? 0 : (n) + 1)
#define PREV(n) ((n) == 0 ? procs - 1 : (n) - 1)
/* sliding dictionary size for deflate */
#define DICT 32768U
/* largest power of 2 that fits in an unsigned int -- used to limit requests
to zlib functions that use unsigned int lengths */
#define MAX ((((unsigned)-1) >> 1) + 1)
/* compress thread: compress the input in the provided work unit and compute
its crc -- assume that the amount of space at job->out is guaranteed to be
enough for the compressed output, as determined by the maximum expansion
of deflate compression -- use the input in the previous work unit (if there
is one) to set the deflate dictionary for better compression */
local void *compress_thread(void *arg)
{
size_t len; /* input length for this work unit */
unsigned long crc; /* crc of input data */
struct work *prev; /* previous work unit */
struct work *job = arg; /* work unit for this thread */
z_stream *strm = &(job->strm); /* zlib stream for this work unit */
/* reset state for a new compressed stream */
(void)deflateReset(strm);
/* initialize input, output, and crc */
strm->next_in = job->buf;
strm->next_out = job->out;
len = job->len;
crc = crc32(0L, Z_NULL, 0);
/* set dictionary if this isn't the first work unit, and if we will be
compressing something (the read thread assures that the dictionary
data in the previous work unit is still there) */
prev = jobs + PREV(job - jobs);
if (prev->buf != NULL && len != 0)
deflateSetDictionary(strm, prev->buf + (size - DICT), DICT);
/* run MAX-sized amounts of input through deflate and crc32 -- this loop
is needed for those cases where the integer type is smaller than the
size_t type, or when len is close to the limit of the size_t type */
while (len > MAX) {
strm->avail_in = MAX;
strm->avail_out = (unsigned)-1;
crc = crc32(crc, strm->next_in, strm->avail_in);
(void)deflate(strm, Z_NO_FLUSH);
len -= MAX;
}
/* run last piece through deflate and crc32, follow with a sync marker */
if (len) {
strm->avail_in = len;
strm->avail_out = (unsigned)-1;
crc = crc32(crc, strm->next_in, strm->avail_in);
(void)deflate(strm, Z_SYNC_FLUSH);
}
/* don't need to Z_FINISH, since we'd delete the last two bytes anyway */
/* return result */
job->crc = crc;
return NULL;
}
/* put a 4-byte integer into a byte array in LSB order */
#define PUT4(a,b) (*(a)=(b),(a)[1]=(b)>>8,(a)[2]=(b)>>16,(a)[3]=(b)>>24)
/* write thread: wait for compression threads to complete, write output in
order, also write gzip header and trailer around the compressed data */
local void *write_thread(void *arg)
{
int n; /* compress thread index */
size_t len; /* length of input processed */
unsigned long tot; /* total uncompressed size (overflow ok) */
unsigned long crc; /* CRC-32 of uncompressed data */
unsigned char wrap[10]; /* gzip header or trailer */
/* write simple gzip header */
memcpy(wrap, "\037\213\10\0\0\0\0\0\0\3", 10);
wrap[8] = level == 9 ? 2 : (level == 1 ? 4 : 0);
writen(outd, wrap, 10);
/* process output of compress threads until end of input */
tot = 0;
crc = crc32(0L, Z_NULL, 0);
n = 0;
do {
/* wait for compress thread to start, then wait to complete */
flag_wait(&(jobs[n].busy), COMP);
pthread_join(jobs[n].comp, NULL);
/* now that compress is done, allow read thread to use input buffer */
flag_set(&(jobs[n].busy), WRITE);
/* write compressed data and update length and crc */
writen(outd, jobs[n].out, jobs[n].strm.next_out - jobs[n].out);
len = jobs[n].len;
tot += len;
crc = crc32_combine(crc, jobs[n].crc, len);
/* release this work unit and go to the next work unit */
flag_set(&(jobs[n].busy), IDLE);
n = NEXT(n);
/* an input buffer less than size in length indicates end of input */
} while (len == size);
/* write final static block and gzip trailer (crc and len mod 2^32) */
wrap[0] = 3; wrap[1] = 0;
PUT4(wrap + 2, crc);
PUT4(wrap + 6, tot);
writen(outd, wrap, 10);
return NULL;
}
/* one-time initialization of a work unit -- this is where we set the deflate
compression level and request raw deflate, and also where we set the size
of the output buffer to guarantee enough space for a worst-case deflate
ending with a Z_SYNC_FLUSH */
local void job_init(struct work *job)
{
int ret; /* deflateInit2() return value */
job->buf = malloc(size);
job->out = malloc(size + (size >> 11) + 10);
job->strm.zfree = Z_NULL;
job->strm.zalloc = Z_NULL;
job->strm.opaque = Z_NULL;
ret = deflateInit2(&(job->strm), level, Z_DEFLATED, -15, 8,
Z_DEFAULT_STRATEGY);
if (job->buf == NULL || job->out == NULL || ret != Z_OK)
bail("not enough memory");
}
/* compress ind to outd in the gzip format, using multiple threads for the
compression and crc calculation and another thread for writing the output --
the read thread is the main thread */
local void read_thread(void)
{
int n; /* general index */
size_t got; /* amount read */
pthread_attr_t attr; /* thread attributes (left at defaults) */
pthread_t write; /* write thread */
/* set defaults (not all pthread implementations default to joinable) */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
/* allocate and set up work list (individual work units will be initialized
as needed, in case the input is short), assure that allocation size
arithmetic does not overflow */
if (size + (size >> 11) + 10 < (size >> 11) + 10 ||
(ssize_t)(size + (size >> 11) + 10) < 0 ||
((size_t)0 - 1) / procs <= sizeof(struct work) ||
(jobs = malloc(procs * sizeof(struct work))) == NULL)
bail("not enough memory");
for (n = 0; n < procs; n++) {
jobs[n].buf = NULL;
flag_init(&(jobs[n].busy), IDLE);
}
/* start write thread */
pthread_create(&write, &attr, write_thread, NULL);
/* read from input and start compress threads (write thread will pick up
the output of the compress threads) */
n = 0;
do {
/* initialize this work unit if it's the first time it's used */
if (jobs[n].buf == NULL)
job_init(jobs + n);
/* read input data, but wait for last compress on this work unit to be
done, and wait for the dictionary to be used by the last compress on
the next work unit */
flag_wait_not(&(jobs[n].busy), COMP);
flag_wait_not(&(jobs[NEXT(n)].busy), COMP);
got = readn(ind, jobs[n].buf, size);
/* start compress thread, but wait for write to be done first */
flag_wait(&(jobs[n].busy), IDLE);
jobs[n].len = got;
pthread_create(&(jobs[n].comp), &attr, compress_thread, jobs + n);
/* mark work unit so write thread knows compress was started */
flag_set(&(jobs[n].busy), COMP);
/* go to the next work unit */
n = NEXT(n);
/* do until end of input, indicated by a read less than size */
} while (got == size);
/* wait for the write thread to complete -- the write thread will join with
all of the compress threads, so this waits for all of the threads to
complete */
pthread_join(write, NULL);
/* free up all requested resources and return */
for (n = procs - 1; n >= 0; n--) {
flag_done(&(jobs[n].busy));
(void)deflateEnd(&(jobs[n].strm));
free(jobs[n].out);
free(jobs[n].buf);
}
free(jobs);
pthread_attr_destroy(&attr);
}
/* Process arguments for level, size, and procs, compress from stdin to
stdout in the gzip format. Note that procs must be at least two in
order to provide a dictionary in one work unit for the other work
unit, and that size must be at least 32K to store a full dictionary. */
int main(int argc, char **argv)
{
int n; /* general index */
int get; /* command line parameters to get */
char *arg; /* command line argument */
/* set defaults -- 32 processes and 128K buffers was found to provide
good utilization of four cores (about 97%) and balanced the overall
execution time impact of more threads against more dictionary
processing for a fixed amount of memory -- the memory usage for these
settings and full use of all work units (at least 4 MB of input) is
16.2 MB
*/
level = Z_DEFAULT_COMPRESSION;
procs = 32;
size = 131072UL;
/* process command-line arguments */
get = 0;
for (n = 1; n < argc; n++) {
arg = argv[n];
if (*arg == '-') {
while (*++arg)
if (*arg >= '0' && *arg <= '9') /* compression level */
level = *arg - '0';
else if (*arg == 'b') /* chunk size in K */
get |= 1;
else if (*arg == 'p') /* number of processes */
get |= 2;
else if (*arg == 'h') { /* help */
fputs("usage: pigz [-0..9] [-b blocksizeinK]", stderr);
fputs(" [-p processes] < foo > foo.gz\n", stderr);
return 0;
}
else
bail("invalid option");
}
else if (get & 1) {
if (get & 2)
bail("you need to separate the -b and -p options");
size = (size_t)(atol(arg)) << 10; /* chunk size */
if (size < DICT)
bail("invalid option");
get = 0;
}
else if (get & 2) {
procs = atoi(arg); /* processes */
if (procs < 2)
bail("invalid option");
get = 0;
}
else
bail("invalid option (you need to pipe input and output)");
}
if (get)
bail("missing option argument");
/* do parallel compression from stdin to stdout (the read thread starts up
the write thread and the compression threads, and they all join before
the read thread returns) */
ind = 0;
outd = 1;
read_thread();
/* done */
return 0;
}
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "zlib.h" #include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#include <fcntl.h>
#ifdef NO_DEFLATE /* for compatibility with old definition */ #ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS # define NO_GZCOMPRESS
...@@ -42,7 +44,8 @@ ...@@ -42,7 +44,8 @@
/* get errno and strerror definition */ /* get errno and strerror definition */
#if defined UNDER_CE && defined NO_ERRNO_H #if defined UNDER_CE && defined NO_ERRNO_H
# define zstrerror(errnum) strwinerror((DWORD)errnum) # include <windows.h>
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else #else
# ifdef STDC # ifdef STDC
# include <errno.h> # include <errno.h>
...@@ -54,7 +57,7 @@ ...@@ -54,7 +57,7 @@
/* MVS fdopen() */ /* MVS fdopen() */
#ifdef __MVS__ #ifdef __MVS__
# pragma map (fdopen , "\174\174FDOPEN") #pragma map (fdopen , "\174\174FDOPEN")
FILE *fdopen(int, const char *); FILE *fdopen(int, const char *);
#endif #endif
...@@ -106,4 +109,7 @@ typedef struct { ...@@ -106,4 +109,7 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *)); ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, const char *));
#if defined UNDER_CE && defined NO_ERRNO_H
ZEXTERN char ZEXPORT *gz_strwinerror OF((DWORD error));
#endif
...@@ -95,7 +95,7 @@ local char *strwinerror (error) ...@@ -95,7 +95,7 @@ local char *strwinerror (error)
#endif /* UNDER_CE && NO_ERRNO_H */ #endif /* UNDER_CE && NO_ERRNO_H */
#ifdef __MVS__ #ifdef __MVS__
# pragma map (fdopen , "\174\174FDOPEN") #pragma map (fdopen , "\174\174FDOPEN")
FILE *fdopen(int, const char *); FILE *fdopen(int, const char *);
#endif #endif
......
...@@ -18,21 +18,17 @@ local void gz_reset OF((gz_statep)); ...@@ -18,21 +18,17 @@ local void gz_reset OF((gz_statep));
local gzFile gz_open OF((const char *, int, const char *, int)); local gzFile gz_open OF((const char *, int, const char *, int));
#if defined UNDER_CE && defined NO_ERRNO_H #if defined UNDER_CE && defined NO_ERRNO_H
local char *strwinerror OF((DWORD error));
# include <windows.h> /* Map the Windows error number in ERROR to a locale-dependent error message
string and return a pointer to it. Typically, the values for ERROR come
from GetLastError.
/* Map the Windows error number in ERROR to a locale-dependent error The string pointed to shall not be modified by the application, but may be
message string and return a pointer to it. Typically, the values overwritten by a subsequent call to gz_strwinerror
for ERROR come from GetLastError.
The string pointed to shall not be modified by the application, The gz_strwinerror function does not change the current setting of
but may be overwritten by a subsequent call to strwinerror GetLastError. */
char ZEXPORT *gz_strwinerror (error)
The strwinerror function does not change the current setting
of GetLastError. */
local char *strwinerror (error)
DWORD error; DWORD error;
{ {
static char buf[1024]; static char buf[1024];
...@@ -82,18 +78,18 @@ local void gz_reset(state) ...@@ -82,18 +78,18 @@ local void gz_reset(state)
state->have = 0; /* no output data available */ state->have = 0; /* no output data available */
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
} }
state->seek = 0; /* no seek request pending */ state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */ gz_error(state, Z_OK, NULL); /* clear error */
state->pos = 0; /* no uncompressed data yet */ state->pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */ state->strm.avail_in = 0; /* no input data yet */
} }
/* Open a gzip file either by name or file descriptor. */ /* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(path, fd, mode, use64) local gzFile gz_open(path, fd, mode, large)
const char *path; const char *path;
int fd; int fd;
const char *mode; const char *mode;
int use64; int large;
{ {
gz_statep state; gz_statep state;
...@@ -156,9 +152,13 @@ local gzFile gz_open(path, fd, mode, use64) ...@@ -156,9 +152,13 @@ local gzFile gz_open(path, fd, mode, use64)
/* open the file with the appropriate mode (or just use fd) */ /* open the file with the appropriate mode (or just use fd) */
state->fd = fd != -1 ? fd : state->fd = fd != -1 ? fd :
open(path, open(path,
(large ?
#ifdef O_LARGEFILE #ifdef O_LARGEFILE
(use64 ? O_LARGEFILE : 0) | O_LARGEFILE
#else
0
#endif #endif
: 0) |
#ifdef O_BINARY #ifdef O_BINARY
O_BINARY | O_BINARY |
#endif #endif
...@@ -214,13 +214,16 @@ gzFile ZEXPORT gzdopen(fd, mode) ...@@ -214,13 +214,16 @@ gzFile ZEXPORT gzdopen(fd, mode)
int fd; int fd;
const char *mode; const char *mode;
{ {
char path[46]; /* allow up to 128-bit integers, so don't worry -- char path[46]; /* identifier for error messages */
the sprintf() is safe */
if (fd < 0) if (fd < 0)
return NULL; return NULL;
sprintf(path, "<fd:%d>", fd); /* for error messages */ #ifdef NO_snprintf
return gz_open(path, fd, mode, 1); sprintf(path, "<fd:%d>", fd); /* big enough for 128-bit integers */
#else
snprintf(path, sizeof(path), "<fd:%d>", fd);
#endif
return gz_open(path, fd, mode, 0);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
...@@ -325,7 +328,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence) ...@@ -325,7 +328,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
return -1; return -1;
} }
/* if reading, skip what's in output buffer (one less gz_getc() check) */ /* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ) {
n = state->have > offset ? (unsigned)offset : state->have; n = state->have > offset ? (unsigned)offset : state->have;
state->have -= n; state->have -= n;
...@@ -422,10 +425,10 @@ int ZEXPORT gzeof(file) ...@@ -422,10 +425,10 @@ int ZEXPORT gzeof(file)
/* get internal structure and check integrity */ /* get internal structure and check integrity */
if (file == NULL) if (file == NULL)
return -1; return 0;
state = (gz_statep)file; state = (gz_statep)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE) if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1; return 0;
/* return end-of-file state */ /* return end-of-file state */
return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0;
...@@ -470,15 +473,15 @@ void ZEXPORT gzclearerr(file) ...@@ -470,15 +473,15 @@ void ZEXPORT gzclearerr(file)
} }
/* Create an error message in allocated memory and set state->err and /* Create an error message in allocated memory and set state->err and
state->msg accordingly. Free any previous error message already there. Do state->msg accordingly. Free any previous error message already there. Do
not try to free or allocate space if the error is Z_MEM_ERROR (out of not try to free or allocate space if the error is Z_MEM_ERROR (out of
memory). Simply save the error message as a static string. If there is memory). Simply save the error message as a static string. If there is an
an allocation failure constructing the error message, then convert the allocation failure constructing the error message, then convert the error to
error to out of memory. */ out of memory. */
void ZEXPORT gz_error(state, err, msg) void ZEXPORT gz_error(state, err, msg)
gz_statep state; gz_statep state;
int err; int err;
char *msg; const char *msg;
{ {
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL) {
...@@ -494,14 +497,14 @@ void ZEXPORT gz_error(state, err, msg) ...@@ -494,14 +497,14 @@ void ZEXPORT gz_error(state, err, msg)
/* for an out of memory error, save as static string */ /* for an out of memory error, save as static string */
if (err == Z_MEM_ERROR) { if (err == Z_MEM_ERROR) {
state->msg = msg; state->msg = (char *)msg;
return; return;
} }
/* construct error message with path */ /* construct error message with path */
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
state->err = Z_MEM_ERROR; state->err = Z_MEM_ERROR;
state->msg = "out of memory"; state->msg = (char *)"out of memory";
return; return;
} }
strcpy(state->msg, state->path); strcpy(state->msg, state->path);
......
...@@ -69,8 +69,8 @@ local int gz_avail(state) ...@@ -69,8 +69,8 @@ local int gz_avail(state)
(strm->avail_in == 0 ? -1 : \ (strm->avail_in == 0 ? -1 : \
(strm->avail_in--, *(strm->next_in)++))) (strm->avail_in--, *(strm->next_in)++)))
/* Get a four-byte little-endian integer and return 0 on success and the /* Get a four-byte little-endian integer and return 0 on success and the value
value in *ret. Otherwise -1 is returned and *ret is not modified. */ in *ret. Otherwise -1 is returned and *ret is not modified. */
local int gz_next4(state, ret) local int gz_next4(state, ret)
gz_statep state; gz_statep state;
unsigned long *ret; unsigned long *ret;
...@@ -93,7 +93,7 @@ local int gz_next4(state, ret) ...@@ -93,7 +93,7 @@ local int gz_next4(state, ret)
/* Look for gzip header, set up for inflate or copy. state->have must be zero. /* Look for gzip header, set up for inflate or copy. state->have must be zero.
If this is the first time in, allocate required memory. state->how will be If this is the first time in, allocate required memory. state->how will be
left unchanged if there is no more input data available, will be set to 1 if left unchanged if there is no more input data available, will be set to 1 if
there is no gzip header and direct copying will be performned, or it will be there is no gzip header and direct copying will be performed, or it will be
set to 2 for decompression, and the gzip header will be skipped so that the set to 2 for decompression, and the gzip header will be skipped so that the
next available input data is the raw deflate stream. If direct copying, next available input data is the raw deflate stream. If direct copying,
then leftover input data from the input buffer will be copied to the output then leftover input data from the input buffer will be copied to the output
...@@ -190,6 +190,8 @@ local int gz_head(state) ...@@ -190,6 +190,8 @@ local int gz_head(state)
NEXT(); NEXT();
NEXT(); NEXT();
} }
/* an unexpected end of file is not checked for here -- it will be
noticed on the first request for uncompressed data */
/* set up for decompression */ /* set up for decompression */
inflateReset(strm); inflateReset(strm);
...@@ -206,7 +208,7 @@ local int gz_head(state) ...@@ -206,7 +208,7 @@ local int gz_head(state)
/* doing raw i/o, save start of raw data for seeking, copy any leftover /* doing raw i/o, save start of raw data for seeking, copy any leftover
input to output -- this assumes that the output buffer is larger than input to output -- this assumes that the output buffer is larger than
the input buffer */ the input buffer, which also assures space for gzungetc() */
state->raw = state->pos; state->raw = state->pos;
state->next = state->out; state->next = state->out;
if (strm->avail_in) { if (strm->avail_in) {
...@@ -220,10 +222,10 @@ local int gz_head(state) ...@@ -220,10 +222,10 @@ local int gz_head(state)
/* Decompress from input to the provided next_out and avail_out in the state. /* Decompress from input to the provided next_out and avail_out in the state.
If the end of the compressed data is reached, then verify the gzip trailer If the end of the compressed data is reached, then verify the gzip trailer
check value and length (modulo 2^32). state->have and state->next are check value and length (modulo 2^32). state->have and state->next are set
set to point to the just decompressed data, and the crc is updated. If the to point to the just decompressed data, and the crc is updated. If the
trailer is verified, state->how is reset to zero to look for the next gzip trailer is verified, state->how is reset to zero to look for the next gzip
stream or raw data, once state->have is depleted. Returns 0 on success, -1 stream or raw data, once state->have is depleted. Returns 0 on success, -1
on failure. Failures may include invalid compressed data or a failed gzip on failure. Failures may include invalid compressed data or a failed gzip
trailer verification. */ trailer verification. */
local int gz_decomp(state) local int gz_decomp(state)
...@@ -372,6 +374,17 @@ int ZEXPORT gzread(file, buf, len) ...@@ -372,6 +374,17 @@ int ZEXPORT gzread(file, buf, len)
if (state->mode != GZ_READ || state->err != Z_OK) if (state->mode != GZ_READ || state->err != Z_OK)
return -1; return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
return -1;
}
/* if len is zero, avoid unnecessary operations */
if (len == 0)
return 0;
/* process a skip request */ /* process a skip request */
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
...@@ -381,8 +394,7 @@ int ZEXPORT gzread(file, buf, len) ...@@ -381,8 +394,7 @@ int ZEXPORT gzread(file, buf, len)
/* get len bytes to buf, or less than len if at the end */ /* get len bytes to buf, or less than len if at the end */
got = 0; got = 0;
while (len) { do {
/* first just try copying data from the output buffer */ /* first just try copying data from the output buffer */
if (state->have) { if (state->have) {
n = state->have > len ? len : state->have; n = state->have > len ? len : state->have;
...@@ -402,6 +414,8 @@ int ZEXPORT gzread(file, buf, len) ...@@ -402,6 +414,8 @@ int ZEXPORT gzread(file, buf, len)
if (gz_make(state) == -1) if (gz_make(state) == -1)
return -1; return -1;
continue; /* no progress yet -- go back to memcpy() above */ continue; /* no progress yet -- go back to memcpy() above */
/* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */
} }
/* large len -- read directly into user buffer */ /* large len -- read directly into user buffer */
...@@ -422,13 +436,13 @@ int ZEXPORT gzread(file, buf, len) ...@@ -422,13 +436,13 @@ int ZEXPORT gzread(file, buf, len)
/* update progress */ /* update progress */
len -= n; len -= n;
buf += n; buf = (char *)buf + n;
got += n; got += n;
state->pos += n; state->pos += n;
} } while (len);
/* return number of bytes read into user buffer */ /* return number of bytes read into user buffer (will fit in int) */
return (int)got; /* len had better fit in int -- interface flaw */ return (int)got;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
...@@ -448,7 +462,7 @@ int ZEXPORT gzgetc(file) ...@@ -448,7 +462,7 @@ int ZEXPORT gzgetc(file)
if (state->mode != GZ_READ || state->err != Z_OK) if (state->mode != GZ_READ || state->err != Z_OK)
return -1; return -1;
/* try output buffer */ /* try output buffer (no need to check for skip request) */
if (state->have) { if (state->have) {
state->have--; state->have--;
state->pos++; state->pos++;
...@@ -496,9 +510,11 @@ int ZEXPORT gzungetc(c, file) ...@@ -496,9 +510,11 @@ int ZEXPORT gzungetc(c, file)
return c; return c;
} }
/* if no room, give up (must have already done a gz_ungetc()) */ /* if no room, give up (must have already done a gzungetc()) */
if (state->have == (state->size << 1)) if (state->have == (state->size << 1)) {
gz_error(state, Z_BUF_ERROR, "out of room to push characters");
return -1; return -1;
}
/* slide output data if needed and insert byte before existing data */ /* slide output data if needed and insert byte before existing data */
if (state->next == state->out) { if (state->next == state->out) {
......
...@@ -20,15 +20,6 @@ local int gz_init(state) ...@@ -20,15 +20,6 @@ local int gz_init(state)
int ret; int ret;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* check version of zlib -- need 1.2.1 or later for gzip deflate() */
#ifdef ZLIB_VERNUM
if (ZLIB_VERNUM < 0x1210)
#endif
{
gz_error(state, Z_VERSION_ERROR, "need zlib 1.2.1 or later");
return -1;
}
/* allocate input and output buffers */ /* allocate input and output buffers */
state->in = malloc(state->want); state->in = malloc(state->want);
state->out = malloc(state->want); state->out = malloc(state->want);
...@@ -169,6 +160,17 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -169,6 +160,17 @@ int ZEXPORT gzwrite(file, buf, len)
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK)
return -1; return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
return -1;
}
/* if len is zero, avoid unnecessary operations */
if (len == 0)
return 0;
/* allocate memory if this is the first time through */ /* allocate memory if this is the first time through */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return -1; return -1;
...@@ -183,7 +185,7 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -183,7 +185,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* for small len, copy to input buffer, otherwise compress directly */ /* for small len, copy to input buffer, otherwise compress directly */
if (len < state->size) { if (len < state->size) {
/* copy to input buffer, compress when full */ /* copy to input buffer, compress when full */
while (len) { do {
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
n = state->size - strm->avail_in; n = state->size - strm->avail_in;
...@@ -192,11 +194,11 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -192,11 +194,11 @@ int ZEXPORT gzwrite(file, buf, len)
memcpy(strm->next_in + strm->avail_in, buf, n); memcpy(strm->next_in + strm->avail_in, buf, n);
strm->avail_in += n; strm->avail_in += n;
state->pos += n; state->pos += n;
buf += n; buf = (char *)buf + n;
len -= n; len -= n;
if (len && gz_comp(state, Z_NO_FLUSH) == -1) if (len && gz_comp(state, Z_NO_FLUSH) == -1)
return -1; return -1;
} } while (len);
} }
else { else {
/* consume whatever's left in the input buffer */ /* consume whatever's left in the input buffer */
...@@ -211,7 +213,7 @@ int ZEXPORT gzwrite(file, buf, len) ...@@ -211,7 +213,7 @@ int ZEXPORT gzwrite(file, buf, len)
return -1; return -1;
} }
/* input was all buffered or compressed */ /* input was all buffered or compressed (put will fit in int) */
return (int)put; return (int)put;
} }
...@@ -332,12 +334,10 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) ...@@ -332,12 +334,10 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
return 0; return 0;
/* write out result of printf() */ /* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len; strm->avail_in = (unsigned)len;
strm->next_in = state->in; strm->next_in = state->in;
state->pos += len; state->pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
return len; return len;
} }
...@@ -408,12 +408,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, ...@@ -408,12 +408,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
return 0; return 0;
/* write out result of printf() */ /* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len; strm->avail_in = (unsigned)len;
strm->next_in = state->in; strm->next_in = state->in;
state->pos += len; state->pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
return len; return len;
} }
......
...@@ -154,7 +154,7 @@ int windowBits; ...@@ -154,7 +154,7 @@ int windowBits;
/* set number of window bits, free window if different */ /* set number of window bits, free window if different */
if (windowBits && (windowBits < 8 || windowBits > 15)) if (windowBits && (windowBits < 8 || windowBits > 15))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
if (state->wbits != windowBits && state->window != Z_NULL) { if (state->wbits != (unsigned)windowBits && state->window != Z_NULL) {
ZFREE(strm, state->window); ZFREE(strm, state->window);
state->window = Z_NULL; state->window = Z_NULL;
} }
...@@ -1458,8 +1458,8 @@ int subvert; ...@@ -1458,8 +1458,8 @@ int subvert;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
state->sane = !subvert; state->sane = !subvert;
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
return Z_OK; return Z_OK;
#else #else
state->sane = 1; state->sane = 1;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.3.5 Copyright 1995-2010 Mark Adler "; " inflate 1.2.3.6 Copyright 1995-2010 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
...@@ -62,7 +62,7 @@ unsigned short FAR *work; ...@@ -62,7 +62,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 69, 199}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 70};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
......
...@@ -11,15 +11,18 @@ $!------------------------------------------------------------------------------ ...@@ -11,15 +11,18 @@ $!------------------------------------------------------------------------------
$! Version history $! Version history
$! 0.01 20060120 First version to receive a number $! 0.01 20060120 First version to receive a number
$! 0.02 20061008 Adapt to new Makefile.in $! 0.02 20061008 Adapt to new Makefile.in
$! 0.03 20091224 Add support for large file check
$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite
$! $!
$ on error then goto err_exit $ on error then goto err_exit
$! $!
$!
$! Just some general constants...
$!
$ true = 1 $ true = 1
$ false = 0 $ false = 0
$ tmpnam = "temp_" + f$getjpi("","pid") $ tmpnam = "temp_" + f$getjpi("","pid")
$ tt = tmpnam + ".txt"
$ tc = tmpnam + ".c"
$ th = tmpnam + ".h"
$ define/nolog tconfig 'th'
$ its_decc = false $ its_decc = false
$ its_vaxc = false $ its_vaxc = false
$ its_gnuc = false $ its_gnuc = false
...@@ -27,17 +30,25 @@ $ s_case = False ...@@ -27,17 +30,25 @@ $ s_case = False
$! $!
$! Setup variables holding "config" information $! Setup variables holding "config" information
$! $!
$ Make = "" $ Make = ""
$ name = "Zlib" $ name = "Zlib"
$ version = "?.?.?" $ version = "?.?.?"
$ v_string = "ZLIB_VERSION" $ v_string = "ZLIB_VERSION"
$ v_file = "zlib.h" $ v_file = "zlib.h"
$ ccopt = "" $ ccopt = ""
$ lopts = "" $ lopts = ""
$ dnsrl = "" $ dnsrl = ""
$ aconf_in_file = "config.hin"
$ conf_check_string = ""
$ linkonly = false $ linkonly = false
$ optfile = name + ".opt" $ optfile = name + ".opt"
$ axp = f$getsyi("HW_MODEL").ge.1024 $ libdefs = ""
$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096
$!
$ whoami = f$parse(f$enviornment("Procedure"),,,,"NO_CONCEAL")
$ mydef = F$parse(whoami,,,"DEVICE")
$ mydir = f$parse(whoami,,,"DIRECTORY") - "]["
$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type")
$! $!
$! Check for MMK/MMS $! Check for MMK/MMS
$! $!
...@@ -47,11 +58,16 @@ $! ...@@ -47,11 +58,16 @@ $!
$! $!
$ gosub find_version $ gosub find_version
$! $!
$ open/write topt tmp.opt
$ open/write optf 'optfile'
$!
$ gosub check_opts $ gosub check_opts
$! $!
$! Look for the compiler used $! Look for the compiler used
$! $!
$ gosub check_compiler $ gosub check_compiler
$ close topt
$!
$ if its_decc $ if its_decc
$ then $ then
$ ccopt = "/prefix=all" + ccopt $ ccopt = "/prefix=all" + ccopt
...@@ -71,6 +87,49 @@ $ then ...@@ -71,6 +87,49 @@ $ then
$ if f$trnlnm("SYS").eqs."" then define sys sys$library: $ if f$trnlnm("SYS").eqs."" then define sys sys$library:
$ endif $ endif
$! $!
$! Build a fake configure input header
$!
$ open/write conf_hin config.hin
$ write conf_hin "#undef _LARGEFILE64_SOURCE"
$ close conf_hin
$!
$!
$ i = 0
$FIND_ACONF:
$ fname = f$element(i,"#",aconf_in_file)
$ if fname .eqs. "#" then goto AMISS_ERR
$ if f$search(fname) .eqs. ""
$ then
$ i = i + 1
$ goto find_aconf
$ endif
$ open/read/err=aconf_err aconf_in 'fname'
$ open/write aconf zlibdefs.h
$ACONF_LOOP:
$ read/end_of_file=aconf_exit aconf_in line
$ work = f$edit(line, "compress,trim")
$ if f$extract(0,6,work) .nes. "#undef"
$ then
$ write aconf line
$ else
$ cdef = f$element(1," ",work)
$ gosub check_config
$ endif
$ goto aconf_loop
$ACONF_EXIT:
$ write aconf "#define VMS 1"
$ write aconf "#include <unistd.h>"
$ write aconf "#include <unixio.h>"
$ write aconf "#ifdef _LARGEFILE"
$ write aconf "#define off64_t __off64_t"
$ write aconf "#define fopen64 fopen"
$ write aconf "#define fseeko64 fseeko"
$ write aconf "#define lseek64 lseek"
$ write aconf "#define ftello64 ftell"
$ write aconf "#endif"
$ close aconf_in
$ close aconf
$ delete 'th';*
$! Build the thing plain or with mms $! Build the thing plain or with mms
$! $!
$ write sys$output "Compiling Zlib sources ..." $ write sys$output "Compiling Zlib sources ..."
...@@ -86,15 +145,15 @@ $ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - ...@@ -86,15 +145,15 @@ $ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - $ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - $ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" -
gzclose.c zlib.h zconf.h zlibdefs.h gzguts.h gzclose.c zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" - $ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" -
gzio.c zutil.h zlib.h zconf.h zlibdefs.h gzio.c zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - $ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" -
gzlib.c zlib.h zconf.h zlibdefs.h gzguts.h gzlib.c zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - $ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" -
gzread.c zlib.h zconf.h zlibdefs.h gzguts.h gzread.c zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - $ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" -
gzwrite.c zlib.h zconf.h zlibdefs.h gzguts.h gzwrite.c zutil.h zlib.h zconf.h zlibdefs.h
$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - $ CALL MAKE infback.OBJ "CC ''CCOPT' infback" -
infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - $ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
...@@ -153,6 +212,14 @@ $ goto err_exit ...@@ -153,6 +212,14 @@ $ goto err_exit
$ERR_EXIT: $ERR_EXIT:
$ set message/facil/ident/sever/text $ set message/facil/ident/sever/text
$ close/nolog optf $ close/nolog optf
$ close/nolog topt
$ close/nolog conf_hin
$ close/nolog aconf_in
$ close/nolog aconf
$ close/nolog out
$ close/nolog min
$ close/nolog mod
$ close/nolog h_in
$ write sys$output "Exiting..." $ write sys$output "Exiting..."
$ exit 2 $ exit 2
$! $!
...@@ -200,61 +267,72 @@ $!------------------------------------------------------------------------------ ...@@ -200,61 +267,72 @@ $!------------------------------------------------------------------------------
$! $!
$! Check command line options and set symbols accordingly $! Check command line options and set symbols accordingly
$! $!
$!------------------------------------------------------------------------------
$! Version history
$! 0.01 20041206 First version to receive a number
$! 0.02 20060126 Add new "HELP" target
$ CHECK_OPTS: $ CHECK_OPTS:
$ i = 1 $ i = 1
$ OPT_LOOP: $ OPT_LOOP:
$ if i .lt. 9 $ if i .lt. 9
$ then $ then
$ cparm = f$edit(p'i',"upcase") $ cparm = f$edit(p'i',"upcase")
$ if cparm .eqs. "DEBUG" $!
$ then $! Check if parameter actually contains something
$ ccopt = ccopt + "/noopt/deb" $!
$ lopts = lopts + "/deb" $ if f$edit(cparm,"trim") .nes. ""
$ endif
$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ ccopt = ccopt + f$extract(start,len,cparm)
$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
then s_case = true
$ endif
$ if cparm .eqs. "LINK" then linkonly = true
$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ lopts = lopts + f$extract(start,len,cparm)
$ endif
$ if f$locate("CC=",cparm) .lt. f$length(cparm)
$ then $ then
$ start = f$locate("=",cparm) + 1 $ if cparm .eqs. "DEBUG"
$ len = f$length(cparm) - start
$ cc_com = f$extract(start,len,cparm)
if (cc_com .nes. "DECC") .and. -
(cc_com .nes. "VAXC") .and. -
(cc_com .nes. "GNUC")
$ then $ then
$ write sys$output "Unsupported compiler choice ''cc_com' ignored" $ ccopt = ccopt + "/noopt/deb"
$ write sys$output "Use DECC, VAXC, or GNUC instead" $ lopts = lopts + "/deb"
$ else
$ if cc_com .eqs. "DECC" then its_decc = true
$ if cc_com .eqs. "VAXC" then its_vaxc = true
$ if cc_com .eqs. "GNUC" then its_gnuc = true
$ endif $ endif
$ endif $ if f$locate("CCOPT=",cparm) .lt. f$length(cparm)
$ if f$locate("MAKE=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ mmks = f$extract(start,len,cparm)
$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
$ then $ then
$ make = mmks $ start = f$locate("=",cparm) + 1
$ else $ len = f$length(cparm) - start
$ write sys$output "Unsupported make choice ''mmks' ignored" $ ccopt = ccopt + f$extract(start,len,cparm)
$ write sys$output "Use MMK or MMS instead" $ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) -
then s_case = true
$ endif
$ if cparm .eqs. "LINK" then linkonly = true
$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ lopts = lopts + f$extract(start,len,cparm)
$ endif
$ if f$locate("CC=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ cc_com = f$extract(start,len,cparm)
if (cc_com .nes. "DECC") .and. -
(cc_com .nes. "VAXC") .and. -
(cc_com .nes. "GNUC")
$ then
$ write sys$output "Unsupported compiler choice ''cc_com' ignored"
$ write sys$output "Use DECC, VAXC, or GNUC instead"
$ else
$ if cc_com .eqs. "DECC" then its_decc = true
$ if cc_com .eqs. "VAXC" then its_vaxc = true
$ if cc_com .eqs. "GNUC" then its_gnuc = true
$ endif
$ endif $ endif
$ if f$locate("MAKE=",cparm) .lt. f$length(cparm)
$ then
$ start = f$locate("=",cparm) + 1
$ len = f$length(cparm) - start
$ mmks = f$extract(start,len,cparm)
$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS")
$ then
$ make = mmks
$ else
$ write sys$output "Unsupported make choice ''mmks' ignored"
$ write sys$output "Use MMK or MMS instead"
$ endif
$ endif
$ if cparm .eqs. "HELP" then gosub bhelp
$ endif $ endif
$ i = i + 1 $ i = i + 1
$ goto opt_loop $ goto opt_loop
...@@ -267,6 +345,8 @@ $! ...@@ -267,6 +345,8 @@ $!
$! Version history $! Version history
$! 0.01 20040223 First version to receive a number $! 0.01 20040223 First version to receive a number
$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists $! 0.02 20040229 Save/set value of decc$no_rooted_search_lists
$! 0.03 20060202 Extend handling of GNU C
$! 0.04 20090402 Compaq -> hp
$CHECK_COMPILER: $CHECK_COMPILER:
$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) $ if (.not. (its_decc .or. its_vaxc .or. its_gnuc))
$ then $ then
...@@ -282,15 +362,21 @@ $ then goto CC_ERR ...@@ -282,15 +362,21 @@ $ then goto CC_ERR
$ else $ else
$ if its_decc $ if its_decc
$ then $ then
$ write sys$output "CC compiler check ... Compaq C" $ write sys$output "CC compiler check ... hp C"
$ if f$trnlnm("decc$no_rooted_search_lists") .nes. "" $ if f$trnlnm("decc$no_rooted_search_lists") .nes. ""
$ then $ then
$ dnrsl = f$trnlnm("decc$no_rooted_search_lists") $ dnrsl = f$trnlnm("decc$no_rooted_search_lists")
$ endif $ endif
$ define decc$no_rooted_search_lists 1 $ define/nolog decc$no_rooted_search_lists 1
$ else $ else
$ if its_vaxc then write sys$output "CC compiler check ... VAX C" $ if its_vaxc then write sys$output "CC compiler check ... VAX C"
$ if its_gnuc then write sys$output "CC compiler check ... GNU C" $ if its_gnuc
$ then
$ write sys$output "CC compiler check ... GNU C"
$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib"
$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib"
$ cc = "gcc"
$ endif
$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share" $ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share"
$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share" $ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share"
$ endif $ endif
...@@ -310,7 +396,8 @@ $ deck ...@@ -310,7 +396,8 @@ $ deck
# written by Martin P.J. Zinser # written by Martin P.J. Zinser
# <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com> # <zinser@zinser.no-ip.info or zinser@sysdev.deutsche-boerse.com>
OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj, infback.obj\ OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzio.obj, gzlib.obj\
gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\
deflate.obj, trees.obj, zutil.obj, inflate.obj, \ deflate.obj, trees.obj, zutil.obj, inflate.obj, \
inftrees.obj, inffast.obj inftrees.obj, inffast.obj
...@@ -342,7 +429,11 @@ compress.obj : compress.c zlib.h zconf.h zlibdefs.h ...@@ -342,7 +429,11 @@ compress.obj : compress.c zlib.h zconf.h zlibdefs.h
crc32.obj : crc32.c zutil.h zlib.h zconf.h zlibdefs.h crc32.obj : crc32.c zutil.h zlib.h zconf.h zlibdefs.h
deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
example.obj : example.c zlib.h zconf.h zlibdefs.h example.obj : example.c zlib.h zconf.h zlibdefs.h
gzclose.obj : gzclose.c zutil.h zlib.h zconf.h zlibdefs.h
gzio.obj : gzio.c zutil.h zlib.h zconf.h zlibdefs.h gzio.obj : gzio.c zutil.h zlib.h zconf.h zlibdefs.h
gzlib.obj : gzlib.c zutil.h zlib.h zconf.h zlibdefs.h
gzread.obj : gzread.c zutil.h zlib.h zconf.h zlibdefs.h
gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h zlibdefs.h
inffast.obj : inffast.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inffast.h inffast.obj : inffast.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inffast.h
inflate.obj : inflate.c zutil.h zlib.h zconf.h zlibdefs.h inflate.obj : inflate.c zutil.h zlib.h zconf.h zlibdefs.h
inftrees.obj : inftrees.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inftrees.obj : inftrees.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
...@@ -416,6 +507,169 @@ $ close h_in ...@@ -416,6 +507,169 @@ $ close h_in
$ return $ return
$!------------------------------------------------------------------------------ $!------------------------------------------------------------------------------
$! $!
$CHECK_CONFIG:
$!
$ in_ldef = f$locate(cdef,libdefs)
$ if (in_ldef .lt. f$length(libdefs))
$ then
$ write aconf "#define ''cdef' 1"
$ libdefs = f$extract(0,in_ldef,libdefs) + -
f$extract(in_ldef + f$length(cdef) + 1, -
f$length(libdefs) - in_ldef - f$length(cdef) - 1, -
libdefs)
$ else
$ if (f$type('cdef') .eqs. "INTEGER")
$ then
$ write aconf "#define ''cdef' ", 'cdef'
$ else
$ if (f$type('cdef') .eqs. "STRING")
$ then
$ write aconf "#define ''cdef' ", """", '''cdef'', """"
$ else
$ gosub check_cc_def
$ endif
$ endif
$ endif
$ return
$!------------------------------------------------------------------------------
$!
$! Check if this is a define relating to the properties of the C/C++
$! compiler
$!
$ CHECK_CC_DEF:
$ if (cdef .eqs. "_LARGEFILE64_SOURCE")
$ then
$ copy sys$input: 'tc'
$ deck
#include "tconfig"
#define _LARGEFILE
#include <stdio.h>
int main(){
FILE *fp;
fp = fopen("temp.txt","r");
fseeko(fp,1,SEEK_SET);
fclose(fp);
}
$ eod
$ test_inv = false
$ comm_h = false
$ gosub cc_prop_check
$ return
$ endif
$ write aconf "/* ", line, " */"
$ return
$!------------------------------------------------------------------------------
$!
$! Check for properties of C/C++ compiler
$!
$! Version history
$! 0.01 20031020 First version to receive a number
$! 0.02 20031022 Added logic for defines with value
$! 0.03 20040309 Make sure local config file gets not deleted
$! 0.04 20041230 Also write include for configure run
$! 0.05 20050103 Add processing of "comment defines"
$CC_PROP_CHECK:
$ cc_prop = true
$ is_need = false
$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true)
$ if f$search(th) .eqs. "" then create 'th'
$ set message/nofac/noident/nosever/notext
$ on error then continue
$ cc 'tmpnam'
$ if .not. ($status) then cc_prop = false
$ on error then continue
$! The headers might lie about the capabilities of the RTL
$ link 'tmpnam',tmp.opt/opt
$ if .not. ($status) then cc_prop = false
$ set message/fac/ident/sever/text
$ on error then goto err_exit
$ delete/nolog 'tmpnam'.*;*/exclude='th'
$ if (cc_prop .and. .not. is_need) .or. -
(.not. cc_prop .and. is_need)
$ then
$ write sys$output "Checking for ''cdef'... yes"
$ if f$type('cdef_val'_yes) .nes. ""
$ then
$ if f$type('cdef_val'_yes) .eqs. "INTEGER" -
then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes)
$ if f$type('cdef_val'_yes) .eqs. "STRING" -
then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes)
$ else
$ call write_config f$fao("#define !AS 1",cdef)
$ endif
$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. -
(cdef .eqs. "_LARGEFILE64_SOURCE") then -
call write_config f$string("#define _LARGEFILE 1")
$ else
$ write sys$output "Checking for ''cdef'... no"
$ if (comm_h)
$ then
call write_config f$fao("/* !AS */",line)
$ else
$ if f$type('cdef_val'_no) .nes. ""
$ then
$ if f$type('cdef_val'_no) .eqs. "INTEGER" -
then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no)
$ if f$type('cdef_val'_no) .eqs. "STRING" -
then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no)
$ else
$ call write_config f$fao("#undef !AS",cdef)
$ endif
$ endif
$ endif
$ return
$!------------------------------------------------------------------------------
$!
$! Check for properties of C/C++ compiler with multiple result values
$!
$! Version history
$! 0.01 20040127 First version
$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05
$CC_MPROP_CHECK:
$ cc_prop = true
$ i = 1
$ idel = 1
$ MT_LOOP:
$ if f$type(result_'i') .eqs. "STRING"
$ then
$ set message/nofac/noident/nosever/notext
$ on error then continue
$ cc 'tmpnam'_'i'
$ if .not. ($status) then cc_prop = false
$ on error then continue
$! The headers might lie about the capabilities of the RTL
$ link 'tmpnam'_'i',tmp.opt/opt
$ if .not. ($status) then cc_prop = false
$ set message/fac/ident/sever/text
$ on error then goto err_exit
$ delete/nolog 'tmpnam'_'i'.*;*
$ if (cc_prop)
$ then
$ write sys$output "Checking for ''cdef'... ", mdef_'i'
$ if f$type(mdef_'i') .eqs. "INTEGER" -
then call write_config f$fao("#define !AS !UL",cdef,mdef_'i')
$ if f$type('cdef_val'_yes) .eqs. "STRING" -
then call write_config f$fao("#define !AS !AS",cdef,mdef_'i')
$ goto msym_clean
$ else
$ i = i + 1
$ goto mt_loop
$ endif
$ endif
$ write sys$output "Checking for ''cdef'... no"
$ call write_config f$fao("#undef !AS",cdef)
$ MSYM_CLEAN:
$ if (idel .le. msym_max)
$ then
$ delete/sym mdef_'idel'
$ idel = idel + 1
$ goto msym_clean
$ endif
$ return
$!------------------------------------------------------------------------------
$!
$! Analyze Object files for OpenVMS AXP to extract Procedure and Data $! Analyze Object files for OpenVMS AXP to extract Procedure and Data
$! information to build a symbol vector for a shareable image $! information to build a symbol vector for a shareable image
$! All the "brains" of this logic was suggested by Hartmut Becker $! All the "brains" of this logic was suggested by Hartmut Becker
...@@ -533,3 +787,16 @@ $ EXIT_AA: ...@@ -533,3 +787,16 @@ $ EXIT_AA:
$ if V then set verify $ if V then set verify
$ endsubroutine $ endsubroutine
$!------------------------------------------------------------------------------ $!------------------------------------------------------------------------------
$!
$! Write configuration to both permanent and temporary config file
$!
$! Version history
$! 0.01 20031029 First version to receive a number
$!
$WRITE_CONFIG: SUBROUTINE
$ write aconf 'p1'
$ open/append confh 'th'
$ write confh 'p1'
$ close confh
$ENDSUBROUTINE
$!------------------------------------------------------------------------------
<html>
<head>
<title>
zlib general purpose compression library version 1.1.4
</title>
</head>
<body bgcolor="White" text="Black" vlink="Red" alink="Navy" link="Red">
<!-- background="zlibbg.gif" -->
<h1> zlib 1.1.4 Manual </h1>
<hr>
<a name="Contents"><h2>Contents</h2>
<ol type="I">
<li> <a href="#Prologue">Prologue</a>
<li> <a href="#Introduction">Introduction</a>
<li> <a href="#Utility functions">Utility functions</a>
<li> <a href="#Basic functions">Basic functions</a>
<li> <a href="#Advanced functions">Advanced functions</a>
<li> <a href="#Constants">Constants</a>
<li> <a href="#struct z_stream_s">struct z_stream_s</a>
<li> <a href="#Checksum functions">Checksum functions</a>
<li> <a href="#Misc">Misc</a>
</ol>
<hr>
<a name="Prologue"><h2> Prologue </h2>
'zlib' general purpose compression library version 1.1.4, March 11th, 2002
<p>
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
<p>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
<p>
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
<ol>
<li> The origin of this software must not be misrepresented ; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
<li> Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
<li> This notice may not be removed or altered from any source distribution.
</ol>
<dl>
<dt>Jean-loup Gailly
<dd><a href="mailto:jloup@gzip.org">jloup@gzip.org</a>
<dt>Mark Adler
<dd><a href="mailto:madler@alumni.caltech.edu">madler@alumni.caltech.edu</a>
</dl>
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files
<a href="ftp://ds.internic.net/rfc/rfc1950.txt">
ftp://ds.internic.net/rfc/rfc1950.txt </a>
(zlib format),
<a href="ftp://ds.internic.net/rfc/rfc1951.txt">
rfc1951.txt </a>
(<a href="#deflate">deflate</a> format) and
<a href="ftp://ds.internic.net/rfc/rfc1952.txt">
rfc1952.txt </a>
(gzip format).
<p>
This manual is converted from zlib.h by
<a href="mailto:piaip@csie.ntu.edu.tw"> piaip </a>
<p>
Visit <a href="http://ftp.cdrom.com/pub/infozip/zlib/">
http://ftp.cdrom.com/pub/infozip/zlib/</a>
for the official zlib web page.
<p>
<hr>
<a name="Introduction"><h2> Introduction </h2>
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
<p>
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
<p>
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio.
<p>
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
<p>
<hr>
<a name="Utility functions"><h2> Utility functions </h2>
The following utility functions are implemented on top of the
<a href="#Basic functions">basic stream-oriented functions</a>.
To simplify the interface, some
default options are assumed (compression level and memory usage,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
<h3> Function list </h3>
<ul>
<li> int <a href="#compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
<li> int <a href="#compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);
<li> int <a href="#uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
<li> typedef voidp gzFile;
<li> gzFile <a href="#gzopen">gzopen</a> (const char *path, const char *mode);
<li> gzFile <a href="#gzdopen">gzdopen</a> (int fd, const char *mode);
<li> int <a href="#gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);
<li> int <a href="#gzread">gzread</a> (gzFile file, voidp buf, unsigned len);
<li> int <a href="#gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);
<li> int VA <a href="#gzprintf">gzprintf</a> (gzFile file, const char *format, ...);
<li> int <a href="#gzputs">gzputs</a> (gzFile file, const char *s);
<li> char * <a href="#gzgets">gzgets</a> (gzFile file, char *buf, int len);
<li> int <a href="#gzputc">gzputc</a> (gzFile file, int c);
<li> int <a href="#gzgetc">gzgetc</a> (gzFile file);
<li> int <a href="#gzflush">gzflush</a> (gzFile file, int flush);
<li> z_off_t <a href="#gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);
<li> z_off_t <a href="#gztell">gztell</a> (gzFile file);
<li> int <a href="#gzrewind">gzrewind</a> (gzFile file);
<li> int <a href="#gzeof">gzeof</a> (gzFile file);
<li> int <a href="#gzclose">gzclose</a> (gzFile file);
<li> const char * <a href="#gzerror">gzerror</a> (gzFile file, int *errnum);
</ul>
<h3> Function description </h3>
<dl>
<font color="Blue"><dt> int <a name="compress">compress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
<dd>
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.<p>
This function can be used to <a href="#compress">compress</a> a whole file at once if the
input file is mmap'ed.<p>
<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
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
buffer.<p>
<font color="Blue"><dt> int <a name="compress2">compress2</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level);</font>
<dd>
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in <a href="#deflateInit">deflateInit</a>. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
<p>
<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
memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output buffer,
<a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the level parameter is invalid.
<p>
<font color="Blue"><dt> int <a name="uncompress">uncompress</a> (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);</font>
<dd>
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer. <p>
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
<p>
<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
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if there was not enough room in the output
buffer, or <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was corrupted.
<p>
<dt> typedef voidp gzFile;
<dd> <p>
<font color="Blue"><dt> gzFile <a name="gzopen">gzopen</a> (const char *path, const char *mode);</font>
<dd>
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
Huffman only compression as in "wb1h". (See the description
of <a href="#deflateInit2">deflateInit2</a> for more information about the strategy parameter.)
<p>
<a href="#gzopen">gzopen</a> can be used to read a file which is not in gzip format ; in this
case <a href="#gzread">gzread</a> will directly read from the file without decompression.
<p>
<a href="#gzopen">gzopen</a> returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression <a href="#state">state</a> ; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is <a href="#Z_MEM_ERROR">Z_MEM_ERROR</a>).
<p>
<font color="Blue"><dt> gzFile <a name="gzdopen">gzdopen</a> (int fd, const char *mode);</font>
<dd>
<a href="#gzdopen">gzdopen</a>() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in <a href="#gzopen">gzopen</a>.
<p>
The next call of <a href="#gzclose">gzclose</a> on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use <a href="#gzdopen">gzdopen</a>(dup(fd), mode).
<p>
<a href="#gzdopen">gzdopen</a> returns NULL if there was insufficient memory to allocate
the (de)compression <a href="#state">state</a>.
<p>
<font color="Blue"><dt> int <a name="gzsetparams">gzsetparams</a> (gzFile file, int level, int strategy);</font>
<dd>
Dynamically update the compression level or strategy. See the description
of <a href="#deflateInit2">deflateInit2</a> for the meaning of these parameters.
<p>
<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
opened for writing.
<p>
<font color="Blue"><dt> int <a name="gzread">gzread</a> (gzFile file, voidp buf, unsigned len);</font>
<dd>
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, <a href="#gzread">gzread</a> copies the given number
of bytes into the buffer.
<p>
<a href="#gzread">gzread</a> returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error).
<p>
<font color="Blue"><dt> int <a name="gzwrite">gzwrite</a> (gzFile file, const voidp buf, unsigned len);</font>
<dd>
Writes the given number of uncompressed bytes into the compressed file.
<a href="#gzwrite">gzwrite</a> returns the number of uncompressed bytes actually written
(0 in case of error).
<p>
<font color="Blue"><dt> int VA <a name="gzprintf">gzprintf</a> (gzFile file, const char *format, ...);</font>
<dd>
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. <a href="#gzprintf">gzprintf</a> returns the number of
uncompressed bytes actually written (0 in case of error).
<p>
<font color="Blue"><dt> int <a name="gzputs">gzputs</a> (gzFile file, const char *s);</font>
<dd>
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
<p>
<a href="#gzputs">gzputs</a> returns the number of characters written, or -1 in case of error.
<p>
<font color="Blue"><dt> char * <a name="gzgets">gzgets</a> (gzFile file, char *buf, int len);</font>
<dd>
Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null
character.
<p>
<a href="#gzgets">gzgets</a> returns buf, or <a href="#Z_NULL">Z_NULL</a> in case of error.
<p>
<font color="Blue"><dt> int <a name="gzputc">gzputc</a> (gzFile file, int c);</font>
<dd>
Writes c, converted to an unsigned char, into the compressed file.
<a href="#gzputc">gzputc</a> returns the value that was written, or -1 in case of error.
<p>
<font color="Blue"><dt> int <a name="gzgetc">gzgetc</a> (gzFile file);</font>
<dd>
Reads one byte from the compressed file. <a href="#gzgetc">gzgetc</a> returns this byte
or -1 in case of end of file or error.
<p>
<font color="Blue"><dt> int <a name="gzflush">gzflush</a> (gzFile file, int flush);</font>
<dd>
Flushes all pending output into the compressed file. The parameter
flush is as in the <a href="#deflate">deflate</a>() function. The return value is the zlib
error number (see function <a href="#gzerror">gzerror</a> below). <a href="#gzflush">gzflush</a> returns <a href="#Z_OK">Z_OK</a> if
the flush parameter is <a href="#Z_FINISH">Z_FINISH</a> and all output could be flushed.
<p>
<a href="#gzflush">gzflush</a> should be called only when strictly necessary because it can
degrade compression.
<p>
<font color="Blue"><dt> z_off_t <a name="gzseek">gzseek</a> (gzFile file, z_off_t offset, int whence);</font>
<dd>
Sets the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
<p>
If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are
supported ; <a href="#gzseek">gzseek</a> then compresses a sequence of zeroes up to the new
starting position.
<p>
<a href="#gzseek">gzseek</a> returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
<p>
<font color="Blue"><dt> int <a name="gzrewind">gzrewind</a> (gzFile file);</font>
<dd>
Rewinds the given file. This function is supported only for reading.
<p>
<a href="#gzrewind">gzrewind</a>(file) is equivalent to (int)<a href="#gzseek">gzseek</a>(file, 0L, SEEK_SET)
<p>
<font color="Blue"><dt> z_off_t <a name="gztell">gztell</a> (gzFile file);</font>
<dd>
Returns the starting position for the next <a href="#gzread">gzread</a> or <a href="#gzwrite">gzwrite</a> on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
<p>
<a href="#gztell">gztell</a>(file) is equivalent to <a href="#gzseek">gzseek</a>(file, 0L, SEEK_CUR)
<p>
<font color="Blue"><dt> int <a name="gzeof">gzeof</a> (gzFile file);</font>
<dd>
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
<p>
<font color="Blue"><dt> int <a name="gzclose">gzclose</a> (gzFile file);</font>
<dd>
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression <a href="#state">state</a>. The return value is the zlib
error number (see function <a href="#gzerror">gzerror</a> below).
<p>
<font color="Blue"><dt> const char * <a name="gzerror">gzerror</a> (gzFile file, int *errnum);</font>
<dd>
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to <a href="#Z_ERRNO">Z_ERRNO</a> and the application may consult errno
to get the exact error code.
<p>
</dl>
<hr>
<a name="Basic functions"><h2> Basic functions </h2>
<h3> Function list </h3>
<ul>
<li> const char * <a href="#zlibVersion">zlibVersion</a> (void);
<li> int <a href="#deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);
<li> int <a href="#deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
<li> int <a href="#deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
<li> int <a href="#inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);
<li> int <a href="#inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);
<li> int <a href="#inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);
</ul>
<h3> Function description </h3>
<dl>
<font color="Blue"><dt> const char * <a name="zlibVersion">zlibVersion</a> (void);</font>
<dd> The application can compare <a href="#zlibVersion">zlibVersion</a> and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by <a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a>.
<p>
<font color="Blue"><dt> int <a name="deflateInit">deflateInit</a> (<a href="#z_streamp">z_streamp</a> strm, int level);</font>
<dd>
Initializes the internal stream <a href="#state">state</a> for compression. The fields
<a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and <a href="#opaque">opaque</a> must be initialized before by the caller.
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
use default allocation functions.
<p>
The compression level must be <a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a>, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
<p>
<a href="#Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> requests a default compromise between speed and
compression (currently equivalent to level 6).
<p>
<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
enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if level is not a valid compression level,
<a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version (<a href="#zlib_version">zlib_version</a>) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
<a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit">deflateInit</a> does not
perform any compression: this will be done by <a href="#deflate">deflate</a>().
<p>
<font color="Blue"><dt> int <a name="deflate">deflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
<dd>
<a href="#deflate">deflate</a> compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.<p>
The detailed semantics are as follows. <a href="#deflate">deflate</a> performs one or both of the
following actions:
<ul>
<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>
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), <a href="#next_in">next_in</a> and <a href="#avail_in">avail_in</a> are updated and
processing will resume at this point for the next call of <a href="#deflate">deflate</a>().
<li>
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>
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
</ul> <p>
Before the call of <a href="#deflate">deflate</a>(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
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>
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(<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>
and with zero <a href="#avail_out">avail_out</a>, it must be called again after making room in the
output buffer because there might be more output pending.
<p>
If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
<a href="#avail_in">avail_in</a> is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
<p>
If flush is set to <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>, all output is flushed as with
<a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, and the compression <a href="#state">state</a> is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a> too often can seriously degrade
the compression.
<p>
If <a href="#deflate">deflate</a> returns with <a href="#avail_out">avail_out</a> == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
<a href="#avail_out">avail_out</a>), until the flush is complete (<a href="#deflate">deflate</a> returns with non-zero
<a href="#avail_out">avail_out</a>).
<p>
If the parameter flush is set to <a href="#Z_FINISH">Z_FINISH</a>, pending input is processed,
pending output is flushed and <a href="#deflate">deflate</a> returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> if there
was enough output space ; if <a href="#deflate">deflate</a> returns with <a href="#Z_OK">Z_OK</a>, this function must be
called again with <a href="#Z_FINISH">Z_FINISH</a> and more output space (updated <a href="#avail_out">avail_out</a>) but no
more input data, until it returns with <a href="#Z_STREAM_END">Z_STREAM_END</a> or an error. After
<a href="#deflate">deflate</a> has returned <a href="#Z_STREAM_END">Z_STREAM_END</a>, the only possible operations on the
stream are <a href="#deflateReset">deflateReset</a> or <a href="#deflateEnd">deflateEnd</a>.
<p>
<a href="#Z_FINISH">Z_FINISH</a> can be used immediately after <a href="#deflateInit">deflateInit</a> if all the compression
is to be done in a single step. In this case, <a href="#avail_out">avail_out</a> must be at least
0.1% larger than <a href="#avail_in">avail_in</a> plus 12 bytes. If <a href="#deflate">deflate</a> does not return
<a href="#Z_STREAM_END">Z_STREAM_END</a>, then it must be called again as described above.
<p>
<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
so far (that is, <a href="#total_in">total_in</a> bytes).
<p>
<a href="#deflate">deflate</a>() may update <a href="#data_type">data_type</a> if it can make a good guess about
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
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
<p>
<a href="#deflate">deflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input
processed or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if all input has been
consumed and all output has been produced (only when flush is set to
<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
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
(for example <a href="#avail_in">avail_in</a> or <a href="#avail_out">avail_out</a> was zero).
<p>
<font color="Blue"><dt> int <a name="deflateEnd">deflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd>
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
<p>
<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
stream <a href="#state">state</a> was inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the stream was freed
prematurely (some input or output was discarded). In the error case,
<a href="#msg">msg</a> may be set but then points to a static string (which must not be
deallocated).
<p>
<font color="Blue"><dt> int <a name="inflateInit">inflateInit</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd>
Initializes the internal stream <a href="#state">state</a> for decompression. The 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 before by
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
value depends on the compression method), <a href="#inflateInit">inflateInit</a> determines the
compression method from the zlib header and allocates all data structures
accordingly ; otherwise the allocation will be deferred to the first call of
<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
use default allocation functions.
<p>
<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
memory, <a href="#Z_VERSION_ERROR">Z_VERSION_ERROR</a> if the zlib library version is incompatible with the
version assumed by the caller. <a href="#msg">msg</a> is set to null if there is no error
message. <a href="#inflateInit">inflateInit</a> does not perform any decompression apart from reading
the zlib header if 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 modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)
<p>
<font color="Blue"><dt> int <a name="inflate">inflate</a> (<a href="#z_streamp">z_streamp</a> strm, int flush);</font>
<dd>
<a href="#inflate">inflate</a> decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may some
introduce some output latency (reading input without producing any output)
except when forced to flush.
<p>
The detailed semantics are as follows. <a href="#inflate">inflate</a> performs one or both of the
following actions:
<ul>
<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>
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), <a href="#next_in">next_in</a> is updated and processing
will resume at this point for the next call of <a href="#inflate">inflate</a>().
<li> 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> accordingly. <a href="#inflate">inflate</a>() provides as much output as possible,
until there is no more input data or no more space in the output buffer
(see below about the flush parameter).
</ul> <p>
Before the call of <a href="#inflate">inflate</a>(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (<a href="#avail_out">avail_out</a> == 0), or after each
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
must be called again after making room in the output buffer because there
might be more output pending.
<p>
If the parameter flush is set to <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>, <a href="#inflate">inflate</a> flushes as much
output as possible to the output buffer. The flushing behavior of <a href="#inflate">inflate</a> is
not specified for values of the flush parameter other than <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a>
and <a href="#Z_FINISH">Z_FINISH</a>, but the current implementation actually flushes as much output
as possible anyway.
<p>
<a href="#inflate">inflate</a>() should normally be called until it returns <a href="#Z_STREAM_END">Z_STREAM_END</a> or an
error. However if all decompression is to be performed in a single step
(a single call of <a href="#inflate">inflate</a>), the parameter flush should be set to
<a href="#Z_FINISH">Z_FINISH</a>. In this case all pending input is processed and all pending
output is flushed ; <a href="#avail_out">avail_out</a> must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be <a href="#inflateEnd">inflateEnd</a> to deallocate the decompression <a href="#state">state</a>. The use of <a href="#Z_FINISH">Z_FINISH</a>
is never required, but can be used to inform <a href="#inflate">inflate</a> that a faster routine
may be used for the single <a href="#inflate">inflate</a>() call.
<p>
If a preset dictionary is needed at this point (see <a href="#inflateSetDictionary">inflateSetDictionary</a>
below), <a href="#inflate">inflate</a> sets strm-<a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of the
dictionary chosen by the compressor and returns <a href="#Z_NEED_DICT">Z_NEED_DICT</a> ; otherwise
it sets strm-&gt <a href="#adler">adler</a> to the <a href="#adler32">adler32</a> checksum of all output produced
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
an error code as described below. At the end of the stream, <a href="#inflate">inflate</a>()
checks that its computed <a href="#adler32">adler32</a> checksum is equal to that saved by the
compressor and returns <a href="#Z_STREAM_END">Z_STREAM_END</a> only if the checksum is correct.
<p>
<a href="#inflate">inflate</a>() returns <a href="#Z_OK">Z_OK</a> if some progress has been made (more input processed
or more output produced), <a href="#Z_STREAM_END">Z_STREAM_END</a> if the end of the compressed data has
been reached and all uncompressed output has been produced, <a href="#Z_NEED_DICT">Z_NEED_DICT</a> if a
preset dictionary is needed at this point, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the input data was
corrupted (input stream not conforming to the zlib format or incorrect
<a href="#adler32">adler32</a> checksum), <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent
(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
enough memory, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a> if no progress is possible or if there was not
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>
case, the application may then call <a href="#inflateSync">inflateSync</a> to look for a good
compression block.
<p>
<font color="Blue"><dt> int <a name="inflateEnd">inflateEnd</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd>
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
<p>
<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>
was inconsistent. In the error case, <a href="#msg">msg</a> may be set but then points to a
static string (which must not be deallocated).
</dl>
<hr>
<a name="Advanced functions"><h2> Advanced functions </h2>
The following functions are needed only in some special applications.
<h3> Function list </h3>
<ul>
<li> int <a href="#deflateInit2">deflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm,
<li> int <a href="#deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
<li> int <a href="#deflateCopy">deflateCopy</a> (<a href="#z_streamp">z_streamp</a> dest, <a href="#z_streamp">z_streamp</a> source);
<li> int <a href="#deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
<li> int <a href="#deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);
<li> int <a href="#inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);
<li> int <a href="#inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);
<li> int <a href="#inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);
<li> int <a href="#inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);
</ul>
<h3> Function description </h3>
<dl>
<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>
<dd> This is another version of <a href="#deflateInit">deflateInit</a> with more compression options. The
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
the caller.<p>
The method parameter is the compression method. It must be <a href="#Z_DEFLATED">Z_DEFLATED</a> in
this version of the library.<p>
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
<a href="#deflateInit">deflateInit</a> is used instead.<p>
The memLevel parameter specifies how much memory should be allocated
for the internal compression <a href="#state">state</a>. memLevel=1 uses minimum memory but
is slow and reduces compression ratio ; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.<p>
The strategy parameter is used to tune the compression algorithm. Use the
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
filter (or predictor), or <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to <a href="#compress">compress</a> them better. The effect of <a href="#Z_FILTERED">Z_FILTERED</a> is to force more
Huffman coding and less string matching ; it is somewhat intermediate
between Z_DEFAULT and <a href="#Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a>. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.<p>
<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
memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as an invalid
method). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#deflateInit2">deflateInit2</a> does
not perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
<font color="Blue"><dt> int <a name="deflateSetDictionary">deflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
<dd>
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after <a href="#deflateInit">deflateInit</a>, <a href="#deflateInit2">deflateInit2</a> or <a href="#deflateReset">deflateReset</a>, before any
call of <a href="#deflate">deflate</a>. The compressor and decompressor must use exactly the same
dictionary (see <a href="#inflateSetDictionary">inflateSetDictionary</a>).<p>
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy ; the data can then be compressed better than
with the default empty dictionary.<p>
Depending on the size of the compression data structures selected by
<a href="#deflateInit">deflateInit</a> or <a href="#deflateInit2">deflateInit2</a>, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
<a href="#deflate">deflate</a> or deflate2. Thus the strings most likely to be useful should be
put at the end of the dictionary, not at the front.<p>
Upon return of this function, strm-&gt <a href="#adler">adler</a> is set to the Adler32 value
of the dictionary ; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)<p>
<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
parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
inconsistent (for example if <a href="#deflate">deflate</a> has already been called for this stream
or if the compression method is bsort). <a href="#deflateSetDictionary">deflateSetDictionary</a> does not
perform any compression: this will be done by <a href="#deflate">deflate</a>().<p>
<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>
<dd>
Sets the destination stream as a complete copy of the source stream.<p>
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling <a href="#deflateEnd">deflateEnd</a>. Note that <a href="#deflateCopy">deflateCopy</a> duplicates the internal
compression <a href="#state">state</a> which can be quite large, so this strategy is slow and
can consume lots of memory.<p>
<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
enough memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the source stream <a href="#state">state</a> was inconsistent
(such as <a href="#zalloc">zalloc</a> being NULL). <a href="#msg">msg</a> is left unchanged in both source and
destination.<p>
<font color="Blue"><dt> int <a name="deflateReset">deflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd> This function is equivalent to <a href="#deflateEnd">deflateEnd</a> followed by <a href="#deflateInit">deflateInit</a>,
but does not free and reallocate all the internal compression <a href="#state">state</a>.
The stream will keep the same compression level and any other attributes
that may have been set by <a href="#deflateInit2">deflateInit2</a>.<p>
<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
stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).<p>
<font color="Blue"><dt> int <a name="deflateParams">deflateParams</a> (<a href="#z_streamp">z_streamp</a> strm, int level, int strategy);</font>
<dd>
Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in <a href="#deflateInit2">deflateInit2</a>. This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of <a href="#deflate">deflate</a>().<p>
Before the call of <a href="#deflateParams">deflateParams</a>, the stream <a href="#state">state</a> must be set as for
a call of <a href="#deflate">deflate</a>(), since the currently available input may have to
be compressed and flushed. In particular, strm-&gt <a href="#avail_out">avail_out</a> must be
non-zero.<p>
<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
stream <a href="#state">state</a> was inconsistent or if a parameter was invalid, <a href="#Z_BUF_ERROR">Z_BUF_ERROR</a>
if strm-&gtavail_out was zero.<p>
<font color="Blue"><dt> int <a name="inflateInit2">inflateInit2</a> (<a href="#z_streamp">z_streamp</a> strm, int windowBits);</font>
<dd> This is another version of <a href="#inflateInit">inflateInit</a> with an extra parameter. The
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
before by the caller.<p>
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if <a href="#inflateInit">inflateInit</a> is used
instead. If a compressed stream with a larger window size is given as
input, <a href="#inflate">inflate</a>() will return with the error code <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> instead of
trying to allocate a larger window.<p>
<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
memory, <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if a parameter is invalid (such as a negative
memLevel). <a href="#msg">msg</a> is set to null if there is no error message. <a href="#inflateInit2">inflateInit2</a>
does not perform any decompression apart from reading the zlib header if
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
modified, but <a href="#next_out">next_out</a> and <a href="#avail_out">avail_out</a> are unchanged.)<p>
<font color="Blue"><dt> int <a name="inflateSetDictionary">inflateSetDictionary</a> (<a href="#z_streamp">z_streamp</a> strm, const Bytef *dictionary, uInt dictLength);</font>
<dd>
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of <a href="#inflate">inflate</a>
if this call returned <a href="#Z_NEED_DICT">Z_NEED_DICT</a>. The dictionary chosen by the compressor
can be determined from the Adler32 value returned by this call of
<a href="#inflate">inflate</a>. The compressor and decompressor must use exactly the same
dictionary (see <a href="#deflateSetDictionary">deflateSetDictionary</a>).<p>
<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
parameter is invalid (such as NULL dictionary) or the stream <a href="#state">state</a> is
inconsistent, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if the given dictionary doesn't match the
expected one (incorrect Adler32 value). <a href="#inflateSetDictionary">inflateSetDictionary</a> does not
perform any decompression: this will be done by subsequent calls of
<a href="#inflate">inflate</a>().<p>
<font color="Blue"><dt> int <a name="inflateSync">inflateSync</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd> Skips invalid compressed data until a full flush point (see above the
description of <a href="#deflate">deflate</a> with <a href="#Z_FULL_FLUSH">Z_FULL_FLUSH</a>) can be found, or until all
available input is skipped. No output is provided.<p>
<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>
if no more input was provided, <a href="#Z_DATA_ERROR">Z_DATA_ERROR</a> if no flush point has been found,
or <a href="#Z_STREAM_ERROR">Z_STREAM_ERROR</a> if the stream structure was inconsistent. In the success
case, the application may save the current current value of <a href="#total_in">total_in</a> which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call <a href="#inflateSync">inflateSync</a>, providing more input each time,
until success or end of the input data.<p>
<font color="Blue"><dt> int <a name="inflateReset">inflateReset</a> (<a href="#z_streamp">z_streamp</a> strm);</font>
<dd>
This function is equivalent to <a href="#inflateEnd">inflateEnd</a> followed by <a href="#inflateInit">inflateInit</a>,
but does not free and reallocate all the internal decompression <a href="#state">state</a>.
The stream will keep attributes that may have been set by <a href="#inflateInit2">inflateInit2</a>.
<p>
<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
stream <a href="#state">state</a> was inconsistent (such as <a href="#zalloc">zalloc</a> or <a href="#state">state</a> being NULL).
<p>
</dl>
<hr>
<a name="Checksum functions"><h2> Checksum functions </h2>
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
<h3> Function list </h3>
<ul>
<li> uLong <a href="#adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);
<li> uLong <a href="#crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);
</ul>
<h3> Function description </h3>
<dl>
<font color="Blue"><dt> uLong <a name="adler32">adler32</a> (uLong <a href="#adler">adler</a>, const Bytef *buf, uInt len);</font>
<dd>
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
<p>
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
<pre>
uLong <a href="#adler">adler</a> = <a href="#adler32">adler32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
while (read_buffer(buffer, length) != EOF) {
<a href="#adler">adler</a> = <a href="#adler32">adler32</a>(<a href="#adler">adler</a>, buffer, length);
}
if (<a href="#adler">adler</a> != original_adler) error();
</pre>
<font color="Blue"><dt> uLong <a name="crc32">crc32</a> (uLong crc, const Bytef *buf, uInt len);</font>
<dd>
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
<pre>
uLong crc = <a href="#crc32">crc32</a>(0L, <a href="#Z_NULL">Z_NULL</a>, 0);
while (read_buffer(buffer, length) != EOF) {
crc = <a href="#crc32">crc32</a>(crc, buffer, length);
}
if (crc != original_crc) error();
</pre>
</dl>
<hr>
<a name="struct z_stream_s"><h2> struct z_stream_s </h2>
<font color="Blue">
<a name="z_stream_s">
<pre>
typedef struct z_stream_s {
Bytef *<a name="next_in">next_in</a>; /* next input byte */
uInt <a name="avail_in">avail_in</a>; /* number of bytes available at <a href="#next_in">next_in</a> */
uLong <a name="total_in">total_in</a>; /* total nb of input bytes read so far */
Bytef *<a name="next_out">next_out</a>; /* next output byte should be put there */
uInt <a name="avail_out">avail_out</a>; /* remaining free space at <a href="#next_out">next_out</a> */
uLong <a name="total_out">total_out</a>; /* total nb of bytes output so far */
char *<a name="msg">msg</a>; /* last error message, NULL if no error */
struct internal_state FAR *<a name="state">state</a>; /* not visible by applications */
alloc_func <a name="zalloc">zalloc</a>; /* used to allocate the internal <a href="#state">state</a> */
free_func <a name="zfree">zfree</a>; /* used to free the internal <a href="#state">state</a> */
voidpf <a name="opaque">opaque</a>; /* private data object passed to <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> */
int <a name="data_type">data_type</a>; /* best guess about the data type: ascii or binary */
uLong <a name="adler">adler</a>; /* <a href="#adler32">adler32</a> value of the uncompressed data */
uLong <a name="reserved">reserved</a>; /* <a href="#reserved">reserved</a> for future use */
} <a href="#z_stream_s">z_stream</a> ;
typedef <a href="#z_stream_s">z_stream</a> FAR * <a name="z_streamp">z_streamp</a>; ÿ
</pre>
</font>
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
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>
has dropped to zero. The application must initialize <a href="#zalloc">zalloc</a>, <a href="#zfree">zfree</a> and
<a href="#opaque">opaque</a> before calling the init function. All other fields are set by the
compression library and must not be updated by the application. <p>
The <a href="#opaque">opaque</a> value provided by the application will be passed as the first
parameter for calls of <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a>. This can be useful for custom
memory management. The compression library attaches no meaning to the
<a href="#opaque">opaque</a> value. <p>
<a href="#zalloc">zalloc</a> must return <a href="#Z_NULL">Z_NULL</a> if there is not enough memory for the object.
If zlib is used in a multi-threaded application, <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be
thread safe. <p>
On 16-bit systems, the functions <a href="#zalloc">zalloc</a> and <a href="#zfree">zfree</a> must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by <a href="#zalloc">zalloc</a> for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
<p>
The fields <a href="#total_in">total_in</a> and <a href="#total_out">total_out</a> can be used for statistics or
progress reports. After compression, <a href="#total_in">total_in</a> holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step). <p>
<hr>
<a name="Constants"><h2> Constants </h2>
<font color="Blue">
<pre>
#define <a name="Z_NO_FLUSH">Z_NO_FLUSH</a> 0
#define <a name="Z_PARTIAL_FLUSH">Z_PARTIAL_FLUSH</a> 1
/* will be removed, use <a href="#Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> instead */
#define <a name="Z_SYNC_FLUSH">Z_SYNC_FLUSH</a> 2
#define <a name="Z_FULL_FLUSH">Z_FULL_FLUSH</a> 3
#define <a name="Z_FINISH">Z_FINISH</a> 4
/* Allowed flush values ; see <a href="#deflate">deflate</a>() below for details */
#define <a name="Z_OK">Z_OK</a> 0
#define <a name="Z_STREAM_END">Z_STREAM_END</a> 1
#define <a name="Z_NEED_DICT">Z_NEED_DICT</a> 2
#define <a name="Z_ERRNO">Z_ERRNO</a> (-1)
#define <a name="Z_STREAM_ERROR">Z_STREAM_ERROR</a> (-2)
#define <a name="Z_DATA_ERROR">Z_DATA_ERROR</a> (-3)
#define <a name="Z_MEM_ERROR">Z_MEM_ERROR</a> (-4)
#define <a name="Z_BUF_ERROR">Z_BUF_ERROR</a> (-5)
#define <a name="Z_VERSION_ERROR">Z_VERSION_ERROR</a> (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define <a name="Z_NO_COMPRESSION">Z_NO_COMPRESSION</a> 0
#define <a name="Z_BEST_SPEED">Z_BEST_SPEED</a> 1
#define <a name="Z_BEST_COMPRESSION">Z_BEST_COMPRESSION</a> 9
#define <a name="Z_DEFAULT_COMPRESSION">Z_DEFAULT_COMPRESSION</a> (-1)
/* compression levels */
#define <a name="Z_FILTERED">Z_FILTERED</a> 1
#define <a name="Z_HUFFMAN_ONLY">Z_HUFFMAN_ONLY</a> 2
#define <a name="Z_DEFAULT_STRATEGY">Z_DEFAULT_STRATEGY</a> 0
/* compression strategy ; see <a href="#deflateInit2">deflateInit2</a>() below for details */
#define <a name="Z_BINARY">Z_BINARY</a> 0
#define <a name="Z_ASCII">Z_ASCII</a> 1
#define <a name="Z_UNKNOWN">Z_UNKNOWN</a> 2
/* Possible values of the <a href="#data_type">data_type</a> field */
#define <a name="Z_DEFLATED">Z_DEFLATED</a> 8
/* The <a href="#deflate">deflate</a> compression method (the only one supported in this version) */
#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> */
#define <a name="zlib_version">zlib_version</a> <a href="#zlibVersion">zlibVersion</a>()
/* for compatibility with versions less than 1.0.2 */
</pre>
</font>
<hr>
<a name="Misc"><h2> Misc </h2>
<a href="#deflateInit">deflateInit</a> and <a href="#inflateInit">inflateInit</a> are macros to allow checking the zlib version
and the compiler's view of <a href="#z_stream_s">z_stream</a>.
<p>
Other functions:
<dl>
<font color="Blue"><dt> const char * <a name="zError">zError</a> (int err);</font>
<font color="Blue"><dt> int <a name="inflateSyncPoint">inflateSyncPoint</a> (<a href="#z_streamp">z_streamp</a> z);</font>
<font color="Blue"><dt> const uLongf * <a name="get_crc_table">get_crc_table</a> (void);</font>
</dl>
<hr>
<font size="-1">
Last update: Wed Oct 13 20:42:34 1999<br>
piapi@csie.ntu.edu.tw
</font>
</body>
</html>
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
<QPG:Files> <QPG:Files>
<QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/> <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
<QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/> <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
<QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" user="root:bin" permission="644"/> <QPG:Add file="../libz.so.1.2.3.6" install="/opt/lib/" user="root:bin" permission="644"/>
<QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.5"/> <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.6"/>
<QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.5"/> <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.6"/>
<QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" component="slib"/> <QPG:Add file="../libz.so.1.2.3.6" install="/opt/lib/" component="slib"/>
</QPG:Files> </QPG:Files>
<QPG:PackageFilter> <QPG:PackageFilter>
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
</QPM:ProductDescription> </QPM:ProductDescription>
<QPM:ReleaseDescription> <QPM:ReleaseDescription>
<QPM:ReleaseVersion>1.2.3.5</QPM:ReleaseVersion> <QPM:ReleaseVersion>1.2.3.6</QPM:ReleaseVersion>
<QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency> <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
<QPM:ReleaseStability>Stable</QPM:ReleaseStability> <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
<QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor> <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
......
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
been saved previously by the compressor and transmitted to the decompressor been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.) by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer. Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output enough memory, Z_BUF_ERROR if there was not enough room in the output
......
...@@ -382,19 +382,19 @@ typedef uLong FAR uLongf; ...@@ -382,19 +382,19 @@ typedef uLong FAR uLongf;
/* MVS linker does not support external names larger than 8 bytes */ /* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__) #if defined(__MVS__)
# pragma map(deflateInit_,"DEIN") #pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2") #pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND") #pragma map(deflateEnd,"DEEND")
# pragma map(deflateBound,"DEBND") #pragma map(deflateBound,"DEBND")
# pragma map(inflateInit_,"ININ") #pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2") #pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND") #pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY") #pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI") #pragma map(inflateSetDictionary,"INSEDI")
# pragma map(compressBound,"CMBND") #pragma map(compressBound,"CMBND")
# pragma map(inflate_table,"INTABL") #pragma map(inflate_table,"INTABL")
# pragma map(inflate_fast,"INFA") #pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY") #pragma map(inflate_copyright,"INCOPY")
#endif #endif
#endif /* ZCONF_H */ #endif /* ZCONF_H */
.TH ZLIB 3 "8 January 2010" .TH ZLIB 3 "17 January 2010"
.SH NAME .SH NAME
zlib \- compression/decompression library zlib \- compression/decompression library
.SH SYNOPSIS .SH SYNOPSIS
...@@ -17,7 +17,6 @@ but other algorithms will be added later ...@@ -17,7 +17,6 @@ but other algorithms will be added later
and will have the same stream interface. and will have the same stream interface.
.LP .LP
Compression can be done in a single step if the buffers are large enough Compression can be done in a single step if the buffers are large enough
(for example if an input file is mmap'ed),
or can be done by repeated calls of the compression function. or can be done by repeated calls of the compression function.
In the latter case, In the latter case,
the application must provide more input and/or consume the output the application must provide more input and/or consume the output
...@@ -133,8 +132,8 @@ before asking for help. ...@@ -133,8 +132,8 @@ before asking for help.
Send questions and/or comments to zlib@gzip.org, Send questions and/or comments to zlib@gzip.org,
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
.SH AUTHORS .SH AUTHORS
Version 1.2.3.5 Version 1.2.3.6
Copyright (C) 1995-2009 Jean-loup Gailly (jloup@gzip.org) Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
and Mark Adler (madler@alumni.caltech.edu). and Mark Adler (madler@alumni.caltech.edu).
.LP .LP
This software is provided "as-is," This software is provided "as-is,"
......
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.3.5, Jan 8th, 2010 version 1.2.3.6, Jan 17th, 2010
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
...@@ -37,44 +37,43 @@ ...@@ -37,44 +37,43 @@
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.2.3.5" #define ZLIB_VERSION "1.2.3.6"
#define ZLIB_VERNUM 0x1235 #define ZLIB_VERNUM 0x1236
#define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2 #define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 3 #define ZLIB_VER_REVISION 3
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed decompression functions, including integrity checks of the uncompressed data.
data. This version of the library supports only one compression method This version of the library supports only one compression method (deflation)
(deflation) but other algorithms will be added later and will have the same but other algorithms will be added later and will have the same stream
stream interface. interface.
Compression can be done in a single step if the buffers are large Compression can be done in a single step if the buffers are large enough,
enough (for example if an input file is mmap'ed), or can be done by or can be done by repeated calls of the compression function. In the latter
repeated calls of the compression function. In the latter case, the case, the application must provide more input and/or consume the output
application must provide more input and/or consume the output
(providing more output space) before each call. (providing more output space) before each call.
The compressed data format used by default by the in-memory functions is The compressed data format used by default by the in-memory functions is
the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
around a deflate stream, which is itself documented in RFC 1951. around a deflate stream, which is itself documented in RFC 1951.
The library also supports reading and writing files in gzip (.gz) format The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio using the functions that start with an interface similar to that of stdio using the functions that start
with "gz". The gzip format is different from the zlib format. gzip is a with "gz". The gzip format is different from the zlib format. gzip is a
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
This library can optionally read and write gzip streams in memory as well. This library can optionally read and write gzip streams in memory as well.
The zlib format was designed to be compact and fast for use in memory The zlib format was designed to be compact and fast for use in memory
and on communications channels. The gzip format was designed for single- and on communications channels. The gzip format was designed for single-
file compression on file systems, has a larger header than zlib to maintain file compression on file systems, has a larger header than zlib to maintain
directory information, and uses a different, slower check method than zlib. directory information, and uses a different, slower check method than zlib.
The library does not install any signal handler. The decoder checks The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never the consistency of the compressed data, so the library should never crash
crash even in case of corrupted input. even in case of corrupted input.
*/ */
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
...@@ -129,35 +128,34 @@ typedef struct gz_header_s { ...@@ -129,35 +128,34 @@ typedef struct gz_header_s {
typedef gz_header FAR *gz_headerp; typedef gz_header FAR *gz_headerp;
/* /*
The application must update next_in and avail_in when avail_in has The application must update next_in and avail_in when avail_in has dropped
dropped to zero. It must update next_out and avail_out when avail_out to zero. It must update next_out and avail_out when avail_out has dropped
has dropped to zero. The application must initialize zalloc, zfree and to zero. The application must initialize zalloc, zfree and opaque before
opaque before calling the init function. All other fields are set by the calling the init function. All other fields are set by the compression
compression library and must not be updated by the application. library and must not be updated by the application.
The opaque value provided by the application will be passed as the first The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the memory management. The compression library attaches no meaning to the
opaque value. opaque value.
zalloc must return Z_NULL if there is not enough memory for the object. zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe. thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this exactly 65536 bytes, but will not be required to allocate more than this if
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
pointers returned by zalloc for objects of exactly 65536 bytes *must* returned by zalloc for objects of exactly 65536 bytes *must* have their
have their offset normalized to zero. The default allocation function offset normalized to zero. The default allocation function provided by this
provided by this library ensures this (see zutil.c). To reduce memory library ensures this (see zutil.c). To reduce memory requirements and avoid
requirements and avoid any allocation of 64K objects, at the expense of any allocation of 64K objects, at the expense of compression ratio, compile
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or The fields total_in and total_out can be used for statistics or progress
progress reports. After compression, total_in holds the total size of reports. After compression, total_in holds the total size of the
the uncompressed data and may be saved for use in the decompressor uncompressed data and may be saved for use in the decompressor (particularly
(particularly if the decompressor wants to decompress everything in if the decompressor wants to decompress everything in a single step).
a single step).
*/ */
/* constants */ /* constants */
...@@ -180,8 +178,8 @@ typedef gz_header FAR *gz_headerp; ...@@ -180,8 +178,8 @@ typedef gz_header FAR *gz_headerp;
#define Z_MEM_ERROR (-4) #define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5) #define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6) #define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative /* Return codes for the compression/decompression functions. Negative values
* values are errors, positive values are used for special but normal events. * are errors, positive values are used for special but normal events.
*/ */
#define Z_NO_COMPRESSION 0 #define Z_NO_COMPRESSION 0
...@@ -215,63 +213,63 @@ typedef gz_header FAR *gz_headerp; ...@@ -215,63 +213,63 @@ typedef gz_header FAR *gz_headerp;
ZEXTERN const char * ZEXPORT zlibVersion OF((void)); ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is If the first character differs, the library code actually used is not
not compatible with the zlib.h header file used by the application. compatible with the zlib.h header file used by the application. This check
This check is automatically made by deflateInit and inflateInit. is automatically made by deflateInit and inflateInit.
*/ */
/* /*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller. zalloc, zfree and opaque must be initialized before by the caller. If
If zalloc and zfree are set to Z_NULL, deflateInit updates them to zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
use default allocation functions. allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at 1 gives best speed, 9 gives best compression, 0 gives no compression at all
all (the input data is simply copied a block at a time). (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
Z_DEFAULT_COMPRESSION requests a default compromise between speed and requests a default compromise between speed and compression (currently
compression (currently equivalent to level 6). equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level, enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION). with the version assumed by the caller (ZLIB_VERSION). msg is set to null
msg is set to null if there is no error message. deflateInit does not if there is no error message. deflateInit does not perform any compression:
perform any compression: this will be done by deflate(). this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/* /*
deflate compresses as much data as possible, and stops when the input deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some buffer becomes empty or the output buffer becomes full. It may introduce
output latency (reading input without producing any output) except when some output latency (reading input without producing any output) except when
forced to flush. forced to flush.
The detailed semantics are as follows. deflate performs one or both of the The detailed semantics are as follows. deflate performs one or both of the
following actions: following actions:
- Compress more input starting at next_in and update next_in and avail_in - Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate(). processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out - Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero. accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications). should be set only when necessary (in interactive applications). Some
Some output may be provided even if flush is not set. output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming one of the actions is possible, by providing more input and/or consuming more
more output, and updating avail_in or avail_out accordingly; avail_out output, and updating avail_in or avail_out accordingly; avail_out should
should never be zero before the call. The application can consume the never be zero before the call. The application can consume the compressed
compressed output when it wants, for example when the output buffer is full output when it wants, for example when the output buffer is full (avail_out
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK == 0), or after each call of deflate(). If deflate returns Z_OK and with
and with zero avail_out, it must be called again after making room in the zero avail_out, it must be called again after making room in the output
output buffer because there might be more output pending. buffer because there might be more output pending.
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
decide how much data to accumulate before producing output, in order to 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,12 +277,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular that the decompressor can get all input data available so far. (In
avail_in is zero after the call if enough output space has been provided particular avail_in is zero after the call if enough output space has been
before the call.) Flushing may degrade compression for some compression provided before the call.) Flushing may degrade compression for some
algorithms and so it should be used only when necessary. This completes the compression algorithms and so it should be used only when necessary. This
current deflate block and follows it with an empty stored block that is three completes the current deflate block and follows it with an empty stored block
bits plus filler bits to the next byte, followed by four bytes (00 00 ff ff). that is three bits plus filler bits to the next byte, followed by four bytes
(00 00 ff ff).
If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
output buffer, but the output is not aligned to a byte boundary. All of the 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,43 +305,43 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
If flush is set to Z_FULL_FLUSH, all output is flushed as with If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
compression. compression.
If deflate returns with avail_out == 0, this function must be called again If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero avail_out), until the flush is complete (deflate returns with non-zero
avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
avail_out is greater than six to avoid repeated flush markers due to avail_out is greater than six to avoid repeated flush markers due to
avail_out == 0 on return. avail_out == 0 on return.
If the parameter flush is set to Z_FINISH, pending input is processed, If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there pending output is flushed and deflate returns with Z_STREAM_END if there was
was enough output space; if deflate returns with Z_OK, this function must be enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the deflate has returned Z_STREAM_END, the only possible operations on the stream
stream are deflateReset or deflateEnd. are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least is to be done in a single step. In this case, avail_out must be at least the
the value returned by deflateBound (see below). If deflate does not return value returned by deflateBound (see below). If deflate does not return
Z_STREAM_END, then it must be called again as described above. Z_STREAM_END, then it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes). so far (that is, total_in bytes).
deflate() may update strm->data_type if it can make a good guess about deflate() may update strm->data_type if it can make a good guess about
the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
binary. This field is only for information purposes and does not affect binary. This field is only for information purposes and does not affect the
the compression algorithm in any manner. compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
(for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
fatal, and deflate() can be called again with more input and more output fatal, and deflate() can be called again with more input and more output
space to continue compressing. space to continue compressing.
*/ */
...@@ -351,13 +350,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); ...@@ -351,13 +350,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any This function discards any unprocessed input and does not flush any pending
pending output. output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case, prematurely (some input or output was discarded). In the error case, msg
msg may be set but then points to a static string (which must not be may be set but then points to a static string (which must not be
deallocated). deallocated).
*/ */
...@@ -365,10 +364,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); ...@@ -365,10 +364,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/* /*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact the caller. If next_in is not Z_NULL and avail_in is large enough (the
value depends on the compression method), inflateInit determines the exact value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 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,66 +377,66 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller, or Z_STREAM_ERROR if the parameters are version assumed by the caller, or Z_STREAM_ERROR if the parameters are
invalid, such as a null pointer to the structure. msg is set to null if invalid, such as a null pointer to the structure. msg is set to null if
there is no error message. inflateInit does not perform any decompression there is no error message. inflateInit does not perform any decompression
apart from possibly reading the zlib header if present: actual decompression apart from possibly reading the zlib header if present: actual decompression
will be done by inflate(). (So next_in and avail_in may be modified, but will be done by inflate(). (So next_in and avail_in may be modified, but
next_out and avail_out are unused and unchanged.) The current next_out and avail_out are unused and unchanged.) The current implementation
implementation of inflateInit() does not process any header information -- of inflateInit() does not process any header information -- that is deferred
that is deferred until inflate() is called. until inflate() is called.
*/ */
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/* /*
inflate decompresses as much data as possible, and stops when the input inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce buffer becomes empty or the output buffer becomes full. It may introduce
some output latency (reading input without producing any output) except when some output latency (reading input without producing any output) except when
forced to flush. forced to flush.
The detailed semantics are as follows. inflate performs one or both of the The detailed semantics are as follows. inflate performs one or both of the
following actions: following actions:
- Decompress more input starting at next_in and update next_in and avail_in - Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing enough room in the output buffer), next_in is updated and processing will
will resume at this point for the next call of inflate(). resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out - Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there accordingly. inflate() provides as much output as possible, until there is
is no more input data or no more space in the output buffer (see below no more input data or no more space in the output buffer (see below about
about the flush parameter). the flush parameter).
Before the call of inflate(), the application should ensure that at least Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming one of the actions is possible, by providing more input and/or consuming more
more output, and updating the next_* and avail_* values accordingly. output, and updating the next_* and avail_* values accordingly. The
The application can consume the uncompressed output when it wants, for application can consume the uncompressed output when it wants, for example
example when the output buffer is full (avail_out == 0), or after each when the output buffer is full (avail_out == 0), or after each call of
call of inflate(). If inflate returns Z_OK and with zero avail_out, it inflate(). If inflate returns Z_OK and with zero avail_out, it must be
must be called again after making room in the output buffer because there called again after making room in the output buffer because there might be
might be more output pending. more output pending.
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
output as possible to the output buffer. Z_BLOCK requests that inflate() stop output as possible to the output buffer. Z_BLOCK requests that inflate()
if and when it gets to the next deflate block boundary. When decoding the stop if and when it gets to the next deflate block boundary. When decoding
zlib or gzip format, this will cause inflate() to return immediately after the zlib or gzip format, this will cause inflate() to return immediately
the header and before the first block. When doing a raw inflate, inflate() after the header and before the first block. When doing a raw inflate,
will go ahead and process the first block, and will return when it gets to inflate() will go ahead and process the first block, and will return when it
the end of that block, or when it runs out of data. gets to the end of that block, or when it runs out of data.
The Z_BLOCK option assists in appending to or combining deflate streams. The Z_BLOCK option assists in appending to or combining deflate streams.
Also to assist in this, on return inflate() will set strm->data_type to the Also to assist in this, on return inflate() will set strm->data_type to the
number of unused bits in the last byte taken from strm->next_in, plus 64 number of unused bits in the last byte taken from strm->next_in, plus 64 if
if inflate() is currently decoding the last block in the deflate stream, inflate() is currently decoding the last block in the deflate stream, plus
plus 128 if inflate() returned immediately after decoding an end-of-block 128 if inflate() returned immediately after decoding an end-of-block code or
code or decoding the complete header up to just before the first byte of the decoding the complete header up to just before the first byte of the deflate
deflate stream. The end-of-block will not be indicated until all of the stream. The end-of-block will not be indicated until all of the uncompressed
uncompressed data from that block has been written to strm->next_out. The data from that block has been written to strm->next_out. The number of
number of unused bits may in general be greater than seven, except when unused bits may in general be greater than seven, except when bit 7 of
bit 7 of data_type is set, in which case the number of unused bits will be data_type is set, in which case the number of unused bits will be less than
less than eight. data_type is set as noted here every time inflate() eight. data_type is set as noted here every time inflate() returns for all
returns for all flush options, and so can be used to determine the amount flush options, and so can be used to determine the amount of currently
of currently consumed input in bits. consumed input in bits.
The Z_TREES option behaves as Z_BLOCK does, but it also returns when the The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
end of each deflate block header is reached, before any actual data in that 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,19 +446,19 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
immediately after reaching the end of the deflate block header. immediately after reaching the end of the deflate block header.
inflate() should normally be called until it returns Z_STREAM_END or an inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step error. However if all decompression is to be performed in a single step (a
(a single call of inflate), the parameter flush should be set to single call of inflate), the parameter flush should be set to Z_FINISH. In
Z_FINISH. In this case all pending input is processed and all pending this case all pending input is processed and all pending output is flushed;
output is flushed; avail_out must be large enough to hold all the avail_out must be large enough to hold all the uncompressed data. (The size
uncompressed data. (The size of the uncompressed data may have been saved of the uncompressed data may have been saved by the compressor for this
by the compressor for this purpose.) The next operation on this stream must purpose.) The next operation on this stream must be inflateEnd to deallocate
be inflateEnd to deallocate the decompression state. The use of Z_FINISH the decompression state. The use of Z_FINISH is never required, but can be
is never required, but can be used to inform inflate that a faster approach used to inform inflate that a faster approach may be used for the single
may be used for the single inflate() call. inflate() call.
In this implementation, inflate() always flushes as much output as In this implementation, inflate() always flushes as much output as
possible to the output buffer, and always uses the faster approach on the possible to the output buffer, and always uses the faster approach on the
first call. So the only effect of the flush parameter in this implementation first call. So the only effect of the flush parameter in this implementation
is on the return value of inflate(), as noted below, or when it returns early is on the return value of inflate(), as noted below, or when it returns early
because Z_BLOCK or Z_TREES is used. because Z_BLOCK or Z_TREES is used.
...@@ -468,7 +467,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); ...@@ -468,7 +467,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
strm->adler to the adler32 checksum of all output produced so far (that is, strm->adler to the adler32 checksum of all output produced so far (that is,
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
below. At the end of the stream, inflate() checks that its computed adler32 below. At the end of the stream, inflate() checks that its computed adler32
checksum is equal to that saved by the compressor and returns Z_STREAM_END checksum is equal to that saved by the compressor and returns Z_STREAM_END
only if the checksum is correct. only if the checksum is correct.
...@@ -487,22 +486,22 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); ...@@ -487,22 +486,22 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
value), Z_STREAM_ERROR if the stream structure was inconsistent (for example value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
Z_BUF_ERROR if no progress is possible or if there was not enough room in the Z_BUF_ERROR if no progress is possible or if there was not enough room in the
output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
inflate() can be called again with more input and more output space to inflate() can be called again with more input and more output space to
continue decompressing. If Z_DATA_ERROR is returned, the application may then continue decompressing. If Z_DATA_ERROR is returned, the application may
call inflateSync() to look for a good compression block if a partial recovery then call inflateSync() to look for a good compression block if a partial
of the data is desired. recovery of the data is desired.
*/ */
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/* /*
All dynamically allocated data structures for this stream are freed. All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any This function discards any unprocessed input and does not flush any pending
pending output. output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated). static string (which must not be deallocated).
*/ */
...@@ -520,55 +519,55 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, ...@@ -520,55 +519,55 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int memLevel, int memLevel,
int strategy)); int strategy));
This is another version of deflateInit with more compression options. The This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by fields next_in, zalloc, zfree and opaque must be initialized before by the
the caller. caller.
The method parameter is the compression method. It must be Z_DEFLATED in The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library. this version of the library.
The windowBits parameter is the base two logarithm of the window size The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this (the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead. deflateInit is used instead.
windowBits can also be -8..-15 for raw deflate. In this case, -windowBits windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
determines the window size. deflate() will then generate raw deflate data determines the window size. deflate() will then generate raw deflate data
with no zlib header or trailer, and will not compute an adler32 check value. with no zlib header or trailer, and will not compute an adler32 check value.
windowBits can also be greater than 15 for optional gzip encoding. Add windowBits can also be greater than 15 for optional gzip encoding. Add
16 to windowBits to write a simple gzip header and trailer around the 16 to windowBits to write a simple gzip header and trailer around the
compressed data instead of a zlib wrapper. The gzip header will have no compressed data instead of a zlib wrapper. The gzip header will have no
file name, no extra data, no comment, no modification time (set to zero), file name, no extra data, no comment, no modification time (set to zero), no
no header crc, and the operating system will be set to 255 (unknown). If a header crc, and the operating system will be set to 255 (unknown). If a
gzip stream is being written, strm->adler is a crc32 instead of an adler32. gzip stream is being written, strm->adler is a crc32 instead of an adler32.
The memLevel parameter specifies how much memory should be allocated The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but for the internal compression state. memLevel=1 uses minimum memory but is
is slow and reduces compression ratio; memLevel=9 uses maximum memory slow and reduces compression ratio; memLevel=9 uses maximum memory for
for optimal speed. The default value is 8. See zconf.h for total memory optimal speed. The default value is 8. See zconf.h for total memory usage
usage as a function of windowBits and memLevel. as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match), or Z_RLE to limit match distances to one (run-length string match), or Z_RLE to limit match distances to one (run-length
encoding). Filtered data consists mostly of small values with a somewhat encoding). Filtered data consists mostly of small values with a somewhat
random distribution. In this case, the compression algorithm is tuned to random distribution. In this case, the compression algorithm is tuned to
compress them better. The effect of Z_FILTERED is to force more Huffman compress them better. The effect of Z_FILTERED is to force more Huffman
coding and less string matching; it is somewhat intermediate between coding and less string matching; it is somewhat intermediate between
Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
strategy parameter only affects the compression ratio but not the strategy parameter only affects the compression ratio but not the
correctness of the compressed output even if it is not set appropriately. correctness of the compressed output even if it is not set appropriately.
Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
decoder for special applications. decoder for special applications.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does method). msg is set to null if there is no error message. deflateInit2
not perform any compression: this will be done by deflate(). does not perform any compression: this will be done by deflate().
*/ */
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
...@@ -576,14 +575,14 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, ...@@ -576,14 +575,14 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
uInt dictLength)); uInt dictLength));
/* /*
Initializes the compression dictionary from the given byte sequence Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any immediately after deflateInit, deflateInit2 or deflateReset, before any call
call of deflate. The compressor and decompressor must use exactly the same of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary). dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary. with the default empty dictionary.
...@@ -591,22 +590,22 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, ...@@ -591,22 +590,22 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
Depending on the size of the compression data structures selected by Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size discarded, for example if the dictionary is larger than the window size
provided in deflateInit or deflateInit2. Thus the strings most likely to be provided in deflateInit or deflateInit2. Thus the strings most likely to be
useful should be put at the end of the dictionary, not at the front. In useful should be put at the end of the dictionary, not at the front. In
addition, the current implementation of deflate will use at most the window addition, the current implementation of deflate will use at most the window
size minus 262 bytes of the provided dictionary. size minus 262 bytes of the provided dictionary.
Upon return of this function, strm->adler is set to the adler32 value Upon return of this function, strm->adler is set to the adler32 value
of the dictionary; the decompressor may later use this value to determine of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The adler32 value which dictionary has been used by the compressor. (The adler32 value
applies to the whole dictionary even if only a subset of the dictionary is applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.) If a raw deflate was requested, then the actually used by the compressor.) If a raw deflate was requested, then the
adler32 value is not computed and strm->adler is not set. adler32 value is not computed and strm->adler is not set.
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent (for example if deflate has already been called for this stream inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate(). perform any compression: this will be done by deflate().
*/ */
...@@ -617,25 +616,25 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, ...@@ -617,25 +616,25 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
This function can be useful when several compression strategies will be This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and compression state which can be quite large, so this strategy is slow and can
can consume lots of memory. consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being Z_NULL). msg is left unchanged in both source and (such as zalloc being Z_NULL). msg is left unchanged in both source and
destination. destination.
*/ */
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/* /*
This function is equivalent to deflateEnd followed by deflateInit, This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state. but does not free and reallocate all the internal compression state. The
The stream will keep the same compression level and any other attributes stream will keep the same compression level and any other attributes that
that may have been set by deflateInit2. may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
...@@ -646,18 +645,18 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, ...@@ -646,18 +645,18 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
Dynamically update the compression level and compression strategy. The Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2. This can be interpretation of level and strategy is as in deflateInit2. This can be
used to switch between compression and straight copy of the input data, or used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different to switch to a different kind of input data requiring a different strategy.
strategy. If the compression level is changed, the input available so far If the compression level is changed, the input available so far is
is compressed with the old level (and may be flushed); the new level will compressed with the old level (and may be flushed); the new level will take
take effect only at the next call of deflate(). effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to a call of deflate(), since the currently available input may have to be
be compressed and flushed. In particular, strm->avail_out must be non-zero. compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
if strm->avail_out was zero. strm->avail_out was zero.
*/ */
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
...@@ -692,21 +691,21 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, ...@@ -692,21 +691,21 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int value)); int value));
/* /*
deflatePrime() inserts bits in the deflate output stream. The intent deflatePrime() inserts bits in the deflate output stream. The intent
is that this function is used to start off the deflate output with the is that this function is used to start off the deflate output with the bits
bits leftover from a previous deflate stream when appending to it. As such, leftover from a previous deflate stream when appending to it. As such, this
this function can only be used for raw deflate, and must be used before the function can only be used for raw deflate, and must be used before the first
first deflate() call after a deflateInit2() or deflateReset(). bits must be deflate() call after a deflateInit2() or deflateReset(). bits must be less
less than or equal to 16, and that many of the least significant bits of than or equal to 16, and that many of the least significant bits of value
value will be inserted in the output. will be inserted in the output.
deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
gz_headerp head)); gz_headerp head));
/* /*
deflateSetHeader() provides gzip header information for when a gzip deflateSetHeader() provides gzip header information for when a gzip
stream is requested by deflateInit2(). deflateSetHeader() may be called stream is requested by deflateInit2(). deflateSetHeader() may be called
after deflateInit2() or deflateReset() and before the first call of after deflateInit2() or deflateReset() and before the first call of
deflate(). The text, time, os, extra field, name, and comment information deflate(). The text, time, os, extra field, name, and comment information
...@@ -719,11 +718,11 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ...@@ -719,11 +718,11 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
1.3.x) do not support header crc's, and will report that it is a "multi-part 1.3.x) do not support header crc's, and will report that it is a "multi-part
gzip file" and give up. gzip file" and give up.
If deflateSetHeader is not used, the default gzip header has text false, If deflateSetHeader is not used, the default gzip header has text false,
the time set to zero, and os set to 255, with no extra, name, or comment the time set to zero, and os set to 255, with no extra, name, or comment
fields. The gzip header is returned to the default state by deflateReset(). fields. The gzip header is returned to the default state by deflateReset().
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
...@@ -731,50 +730,50 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, ...@@ -731,50 +730,50 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits)); int windowBits));
This is another version of inflateInit with an extra parameter. The This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller. before by the caller.
The windowBits parameter is the base two logarithm of the maximum window The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used this version of the library. The default value is 15 if inflateInit is used
instead. windowBits must be greater than or equal to the windowBits value instead. windowBits must be greater than or equal to the windowBits value
provided to deflateInit2() while compressing, or it must be equal to 15 if provided to deflateInit2() while compressing, or it must be equal to 15 if
deflateInit2() was not used. If a compressed stream with a larger window deflateInit2() was not used. If a compressed stream with a larger window
size is given as input, inflate() will return with the error code size is given as input, inflate() will return with the error code
Z_DATA_ERROR instead of trying to allocate a larger window. Z_DATA_ERROR instead of trying to allocate a larger window.
windowBits can also be zero to request that inflate use the window size in windowBits can also be zero to request that inflate use the window size in
the zlib header of the compressed stream. the zlib header of the compressed stream.
windowBits can also be -8..-15 for raw inflate. In this case, -windowBits windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
determines the window size. inflate() will then process raw deflate data, determines the window size. inflate() will then process raw deflate data,
not looking for a zlib or gzip header, not generating a check value, and not not looking for a zlib or gzip header, not generating a check value, and not
looking for any check values for comparison at the end of the stream. This looking for any check values for comparison at the end of the stream. This
is for use with other formats that use the deflate compressed data format is for use with other formats that use the deflate compressed data format
such as zip. Those formats provide their own check values. If a custom such as zip. Those formats provide their own check values. If a custom
format is developed using the raw deflate format for compressed data, it is format is developed using the raw deflate format for compressed data, it is
recommended that a check value such as an adler32 or a crc32 be applied to recommended that a check value such as an adler32 or a crc32 be applied to
the uncompressed data as is done in the zlib, gzip, and zip formats. For the uncompressed data as is done in the zlib, gzip, and zip formats. For
most applications, the zlib format should be used as is. Note that comments most applications, the zlib format should be used as is. Note that comments
above on the use in deflateInit2() applies to the magnitude of windowBits. above on the use in deflateInit2() applies to the magnitude of windowBits.
windowBits can also be greater than 15 for optional gzip decoding. Add windowBits can also be greater than 15 for optional gzip decoding. Add
32 to windowBits to enable zlib and gzip decoding with automatic header 32 to windowBits to enable zlib and gzip decoding with automatic header
detection, or add 16 to decode only the gzip format (the zlib format will detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
a crc32 instead of an adler32. crc32 instead of an adler32.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller, or Z_STREAM_ERROR if the parameters are version assumed by the caller, or Z_STREAM_ERROR if the parameters are
invalid, such as a null pointer to the structure. msg is set to null if invalid, such as a null pointer to the structure. msg is set to null if
there is no error message. inflateInit2 does not perform any decompression there is no error message. inflateInit2 does not perform any decompression
apart from possibly reading the zlib header if present: actual decompression apart from possibly reading the zlib header if present: actual decompression
will be done by inflate(). (So next_in and avail_in may be modified, but will be done by inflate(). (So next_in and avail_in may be modified, but
next_out and avail_out are unused and unchanged.) The current next_out and avail_out are unused and unchanged.) The current implementation
implementation of inflateInit2() does not process any header information -- of inflateInit2() does not process any header information -- that is
that is deferred until inflate() is called. deferred until inflate() is called.
*/ */
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
...@@ -782,8 +781,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ...@@ -782,8 +781,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
uInt dictLength)); uInt dictLength));
/* /*
Initializes the decompression dictionary from the given uncompressed byte Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate, sequence. This function must be called immediately after a call of inflate,
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the adler32 value returned by that call of inflate. can be determined from the adler32 value returned by that call of inflate.
The compressor and decompressor must use exactly the same dictionary (see The compressor and decompressor must use exactly the same dictionary (see
deflateSetDictionary). For raw inflate, this function can be called deflateSetDictionary). For raw inflate, this function can be called
...@@ -792,26 +791,26 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ...@@ -792,26 +791,26 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
dictionary that was used for compression is provided. dictionary that was used for compression is provided.
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect adler32 value). inflateSetDictionary does not expected one (incorrect adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of perform any decompression: this will be done by subsequent calls of
inflate(). inflate().
*/ */
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/* /*
Skips invalid compressed data until a full flush point (see above the Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided. available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found, if no more input was provided, Z_DATA_ERROR if no flush point has been
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
case, the application may save the current current value of total_in which success case, the application may save the current current value of total_in
indicates where valid compressed data was found. In the error case, the which indicates where valid compressed data was found. In the error case,
application may repeatedly call inflateSync, providing more input each time, the application may repeatedly call inflateSync, providing more input each
until success or end of the input data. time, until success or end of the input data.
*/ */
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
...@@ -826,17 +825,17 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, ...@@ -826,17 +825,17 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being Z_NULL). msg is left unchanged in both source and (such as zalloc being Z_NULL). msg is left unchanged in both source and
destination. destination.
*/ */
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/* /*
This function is equivalent to inflateEnd followed by inflateInit, This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state. but does not free and reallocate all the internal decompression state. The
The stream will keep attributes that may have been set by inflateInit2. stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL). stream state was inconsistent (such as zalloc or state being Z_NULL).
*/ */
...@@ -844,10 +843,10 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, ...@@ -844,10 +843,10 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
int windowBits)); int windowBits));
/* /*
This function is the same as inflateReset, but it also permits changing This function is the same as inflateReset, but it also permits changing
the wrap and window size requests. The windowBits parameter is the wrap and window size requests. The windowBits parameter is interpreted
interpreted the same as it is for inflateInit2. the same as it is for inflateInit2.
inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being Z_NULL), or if stream state was inconsistent (such as zalloc or state being Z_NULL), or if
the windowBits parameter is invalid. the windowBits parameter is invalid.
*/ */
...@@ -857,19 +856,19 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, ...@@ -857,19 +856,19 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
int value)); int value));
/* /*
This function inserts bits in the inflate input stream. The intent is This function inserts bits in the inflate input stream. The intent is
that this function is used to start inflating at a bit position in the that this function is used to start inflating at a bit position in the
middle of a byte. The provided bits will be used before any bytes are used middle of a byte. The provided bits will be used before any bytes are used
from next_in. This function should only be used with raw inflate, and from next_in. This function should only be used with raw inflate, and
should be used before the first inflate() call after inflateInit2() or should be used before the first inflate() call after inflateInit2() or
inflateReset(). bits must be less than or equal to 16, and that many of the inflateReset(). bits must be less than or equal to 16, and that many of the
least significant bits of value will be inserted in the input. least significant bits of value will be inserted in the input.
If bits is negative, then the input stream bit buffer is emptied. Then If bits is negative, then the input stream bit buffer is emptied. Then
inflatePrime() can be called again to put bits in the buffer. This is used inflatePrime() can be called again to put bits in the buffer. This is used
to clear out bits leftover after feeding inflate a block description prior to clear out bits leftover after feeding inflate a block description prior
to feeding inflate codes. to feeding inflate codes.
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
...@@ -891,20 +890,20 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); ...@@ -891,20 +890,20 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
decoding of the code, or if it has completed decoding but is waiting for decoding of the code, or if it has completed decoding but is waiting for
more output space to write the literal or match data. more output space to write the literal or match data.
inflateMark() is used to mark locations in the input data for random inflateMark() is used to mark locations in the input data for random
access, which may be at bit positions, and to note those cases where the access, which may be at bit positions, and to note those cases where the
output of a code may span boundaries of random access blocks. The current output of a code may span boundaries of random access blocks. The current
location in the input stream can be determined from avail_in and data_type location in the input stream can be determined from avail_in and data_type
as noted in the description for the Z_BLOCK flush parameter for inflate. as noted in the description for the Z_BLOCK flush parameter for inflate.
inflateMark returns the value noted above or -1 << 16 if the provided inflateMark returns the value noted above or -1 << 16 if the provided
source stream state was inconsistent. source stream state was inconsistent.
*/ */
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
gz_headerp head)); gz_headerp head));
/* /*
inflateGetHeader() requests that gzip header information be stored in the inflateGetHeader() requests that gzip header information be stored in the
provided gz_header structure. inflateGetHeader() may be called after provided gz_header structure. inflateGetHeader() may be called after
inflateInit2() or inflateReset(), and before the first call of inflate(). inflateInit2() or inflateReset(), and before the first call of inflate().
As inflate() processes the gzip stream, head->done is zero until the header 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,30 +913,30 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
used to force inflate() to return immediately after header processing is used to force inflate() to return immediately after header processing is
complete and before any actual data is decompressed. complete and before any actual data is decompressed.
The text, time, xflags, and os fields are filled in with the gzip header The text, time, xflags, and os fields are filled in with the gzip header
contents. hcrc is set to true if there is a header CRC. (The header CRC contents. hcrc is set to true if there is a header CRC. (The header CRC
was valid if done is set to one.) If extra is not Z_NULL, then extra_max was valid if done is set to one.) If extra is not Z_NULL, then extra_max
contains the maximum number of bytes to write to extra. Once done is true, contains the maximum number of bytes to write to extra. Once done is true,
extra_len contains the actual extra field length, and extra contains the extra_len contains the actual extra field length, and extra contains the
extra field, or that field truncated if extra_max is less than extra_len. extra field, or that field truncated if extra_max is less than extra_len.
If name is not Z_NULL, then up to name_max characters are written there, If name is not Z_NULL, then up to name_max characters are written there,
terminated with a zero unless the length is greater than name_max. If terminated with a zero unless the length is greater than name_max. If
comment is not Z_NULL, then up to comm_max characters are written there, comment is not Z_NULL, then up to comm_max characters are written there,
terminated with a zero unless the length is greater than comm_max. When terminated with a zero unless the length is greater than comm_max. When any
any of extra, name, or comment are not Z_NULL and the respective field is of extra, name, or comment are not Z_NULL and the respective field is not
not present in the header, then that field is set to Z_NULL to signal its present in the header, then that field is set to Z_NULL to signal its
absence. This allows the use of deflateSetHeader() with the returned absence. This allows the use of deflateSetHeader() with the returned
structure to duplicate the header. However if those fields are set to structure to duplicate the header. However if those fields are set to
allocated memory, then the application will need to save those pointers allocated memory, then the application will need to save those pointers
elsewhere so that they can be eventually freed. elsewhere so that they can be eventually freed.
If inflateGetHeader is not used, then the header information is simply If inflateGetHeader is not used, then the header information is simply
discarded. The header is always checked for validity, including the header discarded. The header is always checked for validity, including the header
CRC if present. inflateReset() will reset the process to discard the header CRC if present. inflateReset() will reset the process to discard the header
information. The application would need to call inflateGetHeader() again to information. The application would need to call inflateGetHeader() again to
retrieve the header from the next gzip stream. retrieve the header from the next gzip stream.
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent. stream state was inconsistent.
*/ */
...@@ -958,9 +957,9 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, ...@@ -958,9 +957,9 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
See inflateBack() for the usage of these routines. See inflateBack() for the usage of these routines.
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
the paramaters are invalid, Z_MEM_ERROR if the internal state could not the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
be allocated, or Z_VERSION_ERROR if the version of the library does not allocated, or Z_VERSION_ERROR if the version of the library does not match
match the version of the header file. the version of the header file.
*/ */
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
...@@ -980,15 +979,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, ...@@ -980,15 +979,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
inflateBackInit() must be called first to allocate the internal state inflateBackInit() must be called first to allocate the internal state
and to initialize the state with the user-provided window buffer. and to initialize the state with the user-provided window buffer.
inflateBack() may then be used multiple times to inflate a complete, raw inflateBack() may then be used multiple times to inflate a complete, raw
deflate stream with each call. inflateBackEnd() is then called to free deflate stream with each call. inflateBackEnd() is then called to free the
the allocated state. allocated state.
A raw deflate stream is one with no zlib or gzip header or trailer. A raw deflate stream is one with no zlib or gzip header or trailer.
This routine would normally be used in a utility that reads zip or gzip This routine would normally be used in a utility that reads zip or gzip
files and writes out uncompressed files. The utility would decode the files and writes out uncompressed files. The utility would decode the
header and process the trailer on its own, hence this routine expects header and process the trailer on its own, hence this routine expects only
only the raw deflate stream to decompress. This is different from the the raw deflate stream to decompress. This is different from the normal
normal behavior of inflate(), which expects either a zlib or gzip header and behavior of inflate(), which expects either a zlib or gzip header and
trailer around the deflate stream. trailer around the deflate stream.
inflateBack() uses two subroutines supplied by the caller that are then inflateBack() uses two subroutines supplied by the caller that are then
...@@ -1014,7 +1013,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, ...@@ -1014,7 +1013,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
must also be initialized, and then if strm->avail_in is not zero, input will must also be initialized, and then if strm->avail_in is not zero, input will
initially be taken from strm->next_in[0 .. strm->avail_in - 1]. initially be taken from strm->next_in[0 .. strm->avail_in - 1].
The in_desc and out_desc parameters of inflateBack() is passed as the The in_desc and out_desc parameters of inflateBack() is passed as the
first parameter of in() and out() respectively when they are called. These 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,15 +1023,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
On return, inflateBack() will set strm->next_in and strm->avail_in to On return, inflateBack() will set strm->next_in and strm->avail_in to
pass back any unused input that was provided by the last in() call. The pass back any unused input that was provided by the last in() call. The
return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
if in() or out() returned an error, Z_DATA_ERROR if there was a format if in() or out() returned an error, Z_DATA_ERROR if there was a format error
error in the deflate stream (in which case strm->msg is set to indicate the in the deflate stream (in which case strm->msg is set to indicate the nature
nature of the error), or Z_STREAM_ERROR if the stream was not properly of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
initialized. In the case of Z_BUF_ERROR, an input or output error can be In the case of Z_BUF_ERROR, an input or output error can be distinguished
distinguished using strm->next_in which will be Z_NULL only if in() returned using strm->next_in which will be Z_NULL only if in() returned an error. If
an error. If strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
out() returning non-zero. (in() will always be called before out(), so non-zero. (in() will always be called before out(), so strm->next_in is
strm->next_in is assured to be defined if out() returns non-zero.) Note assured to be defined if out() returns non-zero.) Note that inflateBack()
that inflateBack() cannot return Z_OK. cannot return Z_OK.
*/ */
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
...@@ -1089,22 +1088,21 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); ...@@ -1089,22 +1088,21 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
/* /*
The following utility functions are implemented on top of the The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some basic stream-oriented functions. To simplify the interface, some default
default options are assumed (compression level and memory usage, options are assumed (compression level and memory usage, standard memory
standard memory allocation functions). The source code of these allocation functions). The source code of these utility functions can
utility functions can easily be modified if you need special options. easily be modified if you need special options.
*/ */
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)); const Bytef *source, uLong sourceLen));
/* /*
Compresses the source buffer into the destination buffer. sourceLen is Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, destLen is the total size
size of the destination buffer, which must be at least the value returned of the destination buffer, which must be at least the value returned by
by compressBound(sourceLen). Upon exit, destLen is the actual size of the compressBound(sourceLen). Upon exit, destLen is the actual size of the
compressed buffer. compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer. buffer.
...@@ -1114,11 +1112,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, ...@@ -1114,11 +1112,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen, const Bytef *source, uLong sourceLen,
int level)); int level));
/* /*
Compresses the source buffer into the destination buffer. The level Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least the value returned by destination buffer, which must be at least the value returned by
compressBound(sourceLen). Upon exit, destLen is the actual size of the compressBound(sourceLen). Upon exit, destLen is the actual size of the
compressed buffer. compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 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, ...@@ -1129,22 +1127,20 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/* /*
compressBound() returns an upper bound on the compressed size after compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before compress() or compress2() on sourceLen bytes. It would be used before a
a compress() or compress2() call to allocate the destination buffer. compress() or compress2() call to allocate the destination buffer.
*/ */
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)); const Bytef *source, uLong sourceLen));
/* /*
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, destLen is the total size
size of the destination buffer, which must be large enough to hold the of the destination buffer, which must be large enough to hold the entire
entire uncompressed data. (The size of the uncompressed data must have uncompressed data. (The size of the uncompressed data must have been saved
been saved previously by the compressor and transmitted to the decompressor previously by the compressor and transmitted to the decompressor by some
by some mechanism outside the scope of this compression library.) mechanism outside the scope of this compression library.) Upon exit, destLen
Upon exit, destLen is the actual size of the uncompressed buffer. is the actual size of the uncompressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output 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,10 +1149,9 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
/* /*
This library supports reading and writing files in gzip (.gz) format This library supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio using the functions that start with an interface similar to that of stdio using the functions that start
with "gz". The gzip format is different from the zlib format. gzip is a with "gz". The gzip format is different from the zlib format. gzip is a
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
*/ */
typedef voidp gzFile; typedef voidp gzFile;
...@@ -1164,148 +1159,174 @@ typedef voidp gzFile; ...@@ -1164,148 +1159,174 @@ typedef voidp gzFile;
/* /*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
Opens a gzip (.gz) file for reading or writing. The mode parameter Opens a gzip (.gz) file for reading or writing. The mode parameter is as
is as in fopen ("rb" or "wb") but can also include a compression level in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
Huffman only compression as in "wb1h", or 'R' for run-length encoding compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
as in "wb1R". (See the description of deflateInit2 for more information for fixed code compression as in "wb9F". (See the description of
about the strategy parameter.) deflateInit2 for more information about the strategy parameter.) Also "a"
can be used instead of "w" to request that the gzip stream that will be
written be appended to the file. "+" will result in an error, since reading
and writing to the same gzip file is not supported.
gzopen can be used to read a file which is not in gzip format; in this gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression. case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno insufficient memory to allocate the (de)compression state; errno can be
can be checked to distinguish the two cases (if errno is zero, the checked to distinguish the two cases (if errno is zero, the zlib error is
zlib error is Z_MEM_ERROR). */ Z_MEM_ERROR).
*/
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/* /*
gzdopen() associates a gzFile with the file descriptor fd. File gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or descriptors are obtained from calls like open, dup, creat, pipe or fileno
fileno (in the file has been previously opened with fopen). (in the file has been previously opened with fopen). The mode parameter is
The mode parameter is as in gzopen. as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file The next call of gzclose on the returned gzFile will also close the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor
gzdopen returns NULL if there was insufficient memory to allocate fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
the (de)compression state.
gzdopen returns NULL if there was insufficient memory to allocate the
(de)compression state.
*/ */
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
/* /*
Set the internal buffer size used by this library's functions. The default Set the internal buffer size used by this library's functions. The
buffer size is 8192 bytes. This function must be called after gz_open() or default buffer size is 8192 bytes. This function must be called after
gz_dopen(), and before any other calls that read or write the file. The gzopen() or gzdopen(), and before any other calls that read or write the
buffer memory allocation is always deferred to the first read or write. Two file. The buffer memory allocation is always deferred to the first read or
buffers are allocated, either both of the specified size when writing, or write. Two buffers are allocated, either both of the specified size when
one of the specified size and the other twice that size when reading. A writing, or one of the specified size and the other twice that size when
larger buffer size of, for example, 64K or 128K bytes will noticeably reading. A larger buffer size of, for example, 64K or 128K bytes will
increase the speed of decompression (reading). noticeably increase the speed of decompression (reading).
gz_buffer() returns 0 on success, or -1 on failure, such as being called
The new buffer size also affects the maximum length for gzprintf().
gzbuffer() returns 0 on success, or -1 on failure, such as being called
too late. too late.
*/ */
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/* /*
Dynamically update the compression level or strategy. See the description Dynamically update the compression level or strategy. See the description
of deflateInit2 for the meaning of these parameters. of deflateInit2 for the meaning of these parameters.
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing. opened for writing.
*/ */
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/* /*
Reads the given number of uncompressed bytes from the compressed file. Reads the given number of uncompressed bytes from the compressed file. If
If the input file was not in gzip format, gzread copies the given number the input file was not in gzip format, gzread copies the given number of
of bytes into the buffer. bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */ After reaching the end of a gzip stream in the input, gzread will continue
to read, looking for another gzip stream, or failing that, reading the rest
of the input file directly without decompression. The entire input file
will be read if gzread is called until it returns less than the requested
len.
gzread returns the number of uncompressed bytes actually read (less than
len for end of file, -1 for error).
*/
ZEXTERN int ZEXPORT gzwrite OF((gzFile file, ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
voidpc buf, unsigned len)); voidpc buf, unsigned len));
/* /*
Writes the given number of uncompressed bytes into the compressed file. Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written gzwrite returns the number of uncompressed bytes actually written (0 in case
(0 in case of error). of error).
*/ */
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/* /*
Converts, formats, and writes the arguments to the compressed file under Converts, formats, and writes the arguments to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written, or 0 in case of error. The number of uncompressed bytes actually written, or 0 in case of error. The number of
uncompressed bytes written is limited to 8191, or one less than the buffer uncompressed bytes written is limited to 8191, or one less than the buffer
size given to gz_buffer(). The caller should assure that this limit is not size given to gzbuffer(). The caller should assure that this limit is not
exceeded. If it is exceeded, then gzprintf() will return an error (0) with exceeded. If it is exceeded, then gzprintf() will return an error (0) with
nothing written. In this case, there may also be a buffer overflow with nothing written. In this case, there may also be a buffer overflow with
unpredictable consequences, which is possible only if zlib was compiled unpredictable consequences, which is possible only if zlib was compiled with
with the insecure functions sprintf() or vsprintf() because the secure the insecure functions sprintf() or vsprintf() because the secure snprintf()
snprintf() or vsnprintf() functions were not available. or vsnprintf() functions were not available. This can be checked for using
zlibCompileFlags().
*/ */
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/* /*
Writes the given null-terminated string to the compressed file, excluding Writes the given null-terminated string to the compressed file, excluding
the terminating null character. the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
gzputs returns the number of characters written, or -1 in case of error.
*/ */
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/* /*
Reads bytes from the compressed file until len-1 characters are read, or Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null condition is encountered. The string is then terminated with a null
character. character.
gzgets returns buf, or Z_NULL in case of error.
gzgets returns buf, or Z_NULL in case of error.
*/ */
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/* /*
Writes c, converted to an unsigned char, into the compressed file. Writes c, converted to an unsigned char, into the compressed file. gzputc
gzputc returns the value that was written, or -1 in case of error. returns the value that was written, or -1 in case of error.
*/ */
ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/* /*
Reads one byte from the compressed file. gzgetc returns this byte Reads one byte from the compressed file. gzgetc returns this byte or -1
or -1 in case of end of file or error. in case of end of file or error.
*/ */
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/* /*
Push one character back onto the stream to be read again later. Push one character back onto the stream to be read again later. At least
Only one character of push-back is allowed. gzungetc() returns the one character of push-back is allowed. gzungetc() returns the character
character pushed, or -1 on failure. gzungetc() will fail if a pushed, or -1 on failure. gzungetc() will fail if c is -1, and may fail if
character has been pushed but not read yet, or if c is -1. The pushed a character has been pushed but not read yet. The pushed character will be
character will be discarded if the stream is repositioned with gzseek() discarded if the stream is repositioned with gzseek() or gzrewind().
or gzrewind().
*/ */
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/* /*
Flushes all pending output into the compressed file. The parameter Flushes all pending output into the compressed file. The parameter flush
flush is as in the deflate() function. The return value is the zlib is as in the deflate() function. The return value is the zlib error number
error number (see function gzerror below). gzflush returns Z_OK if (see function gzerror below).
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can If the flush parameter is Z_FINISH, the remaining data is written and the
degrade compression. gzip stream is completed in the output. If gzwrite() is called again, a new
gzip stream will be started in the output. gzread() is able to read such
concatented gzip streams.
gzflush should be called only when strictly necessary because it will
degrade compression if called too often.
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence)); z_off_t offset, int whence));
Sets the starting position for the next gzread or gzwrite on the Sets the starting position for the next gzread or gzwrite on the given
given compressed file. The offset represents a number of bytes in the compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2); uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported. the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new supported; gzseek then compresses a sequence of zeroes up to the new
starting position. starting position.
gzseek returns the resulting offset location as measured in bytes from gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position particular if the file is opened for writing and the new starting position
would be before the current position. would be before the current position.
...@@ -1315,47 +1336,50 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); ...@@ -1315,47 +1336,50 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/* /*
Rewinds the given file. This function is supported only for reading. Rewinds the given file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
Returns the starting position for the next gzread or gzwrite on the Returns the starting position for the next gzread or gzwrite on the given
given compressed file. This position represents a number of bytes in the compressed file. This position represents a number of bytes in the
uncompressed data stream, and is zero when starting, even if appending uncompressed data stream, and is zero when starting, even if appending or
or reading a gzip stream from the middle of a file using gz_dopen(). reading a gzip stream from the middle of a file using gzdopen().
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/ */
/* /*
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
Returns the current offset in the file being read or written. This offset Returns the current offset in the file being read or written. This offset
includes the count of bytes that precede the gzip stream, for example when includes the count of bytes that precede the gzip stream, for example when
appending or when using gz_dopen() for reading. When reading, the offset appending or when using gzdopen() for reading. When reading, the offset
includes data that has been used to generate what has been provided as includes data that has been used to generate what has been provided as
uncompressed data so far, but does not include as yet unused buffered input. uncompressed data so far, but does not include as yet unused buffered input.
On error, gz_offset() returns -1. On error, gzoffset() returns -1.
*/ */
ZEXTERN int ZEXPORT gzeof OF((gzFile file)); ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/* /*
Returns 1 when EOF has previously been detected reading the given Returns 1 when EOF has previously been detected reading the given input
input stream, otherwise zero. stream, otherwise zero.
*/ */
ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/* /*
Returns 1 if file is being read directly without decompression, otherwise Returns 1 if file is being read directly without decompression, otherwise
zero. zero. gzdirect() called immediately after gzopen() will always return zero,
since nothing has been read yet. Whether to read the file with
decompression or not is not determined until after the first read operation
(e.g. gzread(), gzgetc(), etc.).
*/ */
ZEXTERN int ZEXPORT gzclose OF((gzFile file)); ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/* /*
Flushes all pending output if necessary, closes the compressed file Flushes all pending output if necessary, closes the compressed file and
and deallocates all the (de)compression state. The return value is the zlib deallocates all the (de)compression state. The return value is the zlib
error number. Note that once file is closed, you cannot call gzerror with error number. Note that once file is closed, you cannot call gzerror with
file, since its structures have been deallocated. file, since its structures have been deallocated.
*/ */
...@@ -1363,31 +1387,31 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); ...@@ -1363,31 +1387,31 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
/* /*
Same as gz_close(), but gz_close_r() is only for use when reading, and Same as gzclose(), but gzclose_r() is only for use when reading, and
gz_close_w() is only for use when writing. The advantage to using these gzclose_w() is only for use when writing. The advantage to using these
instead of gz_close() is that they avoid linking in zlib compression or instead of gzclose() is that they avoid linking in zlib compression or
decompression code that is not used when only reading or only writing decompression code that is not used when only reading or only writing
respectively. If gz_close() is used, then both compression and respectively. If gzclose() is used, then both compression and decompression
decompression code will be included the application when linking to a code will be included the application when linking to a static zlib library.
static zlib library.
*/ */
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/* /*
Returns the error message for the last error which occurred on the Returns the error message for the last error which occurred on the given
given compressed file. errnum is set to zlib error number. If an compressed file. errnum is set to zlib error number. If an error occurred
error occurred in the file system and not in the compression library, in the file system and not in the compression library, errnum is set to
errnum is set to Z_ERRNO and the application may consult errno Z_ERRNO and the application may consult errno to get the exact error code.
to get the exact error code.
The application must not modify the returned string and future calls to The application must not modify the returned string. Future calls to
this function may invalidate the returned string. this function may invalidate the previously returned string. If file is
closed, then the string previously returned by gzerror will no longer be
available.
*/ */
ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/* /*
Clears the error and end-of-file flags for file. This is analogous to the Clears the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip clearerr() function in stdio. This is useful for continuing to read a gzip
file that is being written concurrently. file that is being written concurrently.
*/ */
...@@ -1395,17 +1419,20 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); ...@@ -1395,17 +1419,20 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/* /*
These functions are not related to compression but are exported These functions are not related to compression but are exported
anyway because they might be useful in applications using the anyway because they might be useful in applications using the compression
compression library. library.
*/ */
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/* /*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is Z_NULL, this function returns return the updated checksum. If buf is Z_NULL, this function returns the
the required initial value for the checksum. required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example: An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster.
Usage example:
uLong adler = adler32(0L, Z_NULL, 0); uLong adler = adler32(0L, Z_NULL, 0);
...@@ -1428,9 +1455,11 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, ...@@ -1428,9 +1455,11 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/* /*
Update a running CRC-32 with the bytes buf[0..len-1] and return the Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required initial updated CRC-32. If buf is Z_NULL, this function returns the required
value for the for the crc. Pre- and post-conditioning (one's complement) is initial value for the for the crc. Pre- and post-conditioning (one's
performed within this function so it shouldn't be done by the application. complement) is performed within this function so it shouldn't be done by the
application.
Usage example: Usage example:
uLong crc = crc32(0L, Z_NULL, 0); uLong crc = crc32(0L, Z_NULL, 0);
......
...@@ -14,6 +14,8 @@ ZLIB_1.2.0 { ...@@ -14,6 +14,8 @@ ZLIB_1.2.0 {
zcalloc; zcalloc;
zcfree; zcfree;
z_errmsg; z_errmsg;
gz_error;
gzio_old;
_*; _*;
}; };
...@@ -51,3 +53,11 @@ ZLIB_1.2.3.4 { ...@@ -51,3 +53,11 @@ ZLIB_1.2.3.4 {
inflateReset2; inflateReset2;
inflateMark; inflateMark;
} ZLIB_1.2.3.3; } ZLIB_1.2.3.3;
ZLIB_1.2.3.5 {
gzbuffer;
gzoffset;
gzoffset64;
gzclose_r;
gzclose_w;
} ZLIB_1.2.3.4;
...@@ -34,25 +34,25 @@ uLong ZEXPORT zlibCompileFlags() ...@@ -34,25 +34,25 @@ uLong ZEXPORT zlibCompileFlags()
uLong flags; uLong flags;
flags = 0; flags = 0;
switch (sizeof(uInt)) { switch ((int)(sizeof(uInt))) {
case 2: break; case 2: break;
case 4: flags += 1; break; case 4: flags += 1; break;
case 8: flags += 2; break; case 8: flags += 2; break;
default: flags += 3; default: flags += 3;
} }
switch (sizeof(uLong)) { switch ((int)(sizeof(uLong))) {
case 2: break; case 2: break;
case 4: flags += 1 << 2; break; case 4: flags += 1 << 2; break;
case 8: flags += 2 << 2; break; case 8: flags += 2 << 2; break;
default: flags += 3 << 2; default: flags += 3 << 2;
} }
switch (sizeof(voidpf)) { switch ((int)(sizeof(voidpf))) {
case 2: break; case 2: break;
case 4: flags += 1 << 4; break; case 4: flags += 1 << 4; break;
case 8: flags += 2 << 4; break; case 8: flags += 2 << 4; break;
default: flags += 3 << 4; default: flags += 3 << 4;
} }
switch (sizeof(z_off_t)) { switch ((int)(sizeof(z_off_t))) {
case 2: break; case 2: break;
case 4: flags += 1 << 6; break; case 4: flags += 1 << 6; break;
case 8: flags += 2 << 6; break; case 8: flags += 2 << 6; break;
......
...@@ -116,7 +116,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ ...@@ -116,7 +116,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef OS2 #ifdef OS2
# define OS_CODE 0x06 # define OS_CODE 0x06
# ifdef M_I86 # ifdef M_I86
#include <malloc.h> # include <malloc.h>
# endif # endif
#endif #endif
...@@ -162,9 +162,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ ...@@ -162,9 +162,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#if defined(__BORLANDC__) #if defined(__BORLANDC__)
#pragma warn -8004 #pragma warn -8004
#pragma warn -8008 #pragma warn -8008
#pragma warn -8066 #pragma warn -8066
#endif #endif
#ifdef _LARGEFILE64_SOURCE #ifdef _LARGEFILE64_SOURCE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册