Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d004b04783 | ||
|
|
f6194ef39a | ||
|
|
639be99788 | ||
|
|
d6231142d2 |
177
CMakeLists.txt
Normal file
177
CMakeLists.txt
Normal file
@@ -0,0 +1,177 @@
|
||||
cmake_minimum_required(VERSION 2.4.4)
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
|
||||
|
||||
project(zlib C)
|
||||
|
||||
if(NOT DEFINED BUILD_SHARED_LIBS)
|
||||
option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
|
||||
endif()
|
||||
|
||||
include(CheckTypeSize)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
enable_testing()
|
||||
|
||||
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||
check_include_file(stdint.h HAVE_STDINT_H)
|
||||
check_include_file(stddef.h HAVE_STDDEF_H)
|
||||
|
||||
#
|
||||
# Check to see if we have large file support
|
||||
#
|
||||
set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
|
||||
|
||||
# We add these other definitions here because CheckTypeSize.cmake
|
||||
# in CMake 2.4.x does not automatically do so and we want
|
||||
# compatibility with CMake 2.4.x.
|
||||
if(HAVE_SYS_TYPES_H)
|
||||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
|
||||
endif()
|
||||
if(HAVE_STDINT_H)
|
||||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
|
||||
endif()
|
||||
if(HAVE_STDDEF_H)
|
||||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
|
||||
endif()
|
||||
|
||||
check_type_size(off64_t OFF64_T)
|
||||
|
||||
if(HAVE_OFF64_T)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE)
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
|
||||
|
||||
#
|
||||
# Check for fseeko
|
||||
#
|
||||
check_function_exists(fseeko HAVE_FSEEKO)
|
||||
if(NOT HAVE_FSEEKO)
|
||||
add_definitions(-DNO_FSEEKO)
|
||||
endif()
|
||||
|
||||
#
|
||||
# Check for unistd.h
|
||||
#
|
||||
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||
|
||||
#
|
||||
# Check for errno.h
|
||||
check_include_file(errno.h HAVE_ERRNO_H)
|
||||
if(NOT HAVE_ERRNO_H)
|
||||
add_definitions(-DNO_ERRNO_H)
|
||||
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.
|
||||
# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead
|
||||
# of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h
|
||||
# is shipped with zlib in the source tree.
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h)
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_DEBUG_POSTFIX "D")
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
endif()
|
||||
|
||||
#============================================================================
|
||||
# zlib
|
||||
#============================================================================
|
||||
|
||||
set(ZLIB_PUBLIC_HDRS
|
||||
zconf.h
|
||||
zlib.h
|
||||
zlibdefs.h
|
||||
)
|
||||
set(ZLIB_PRIVATE_HDRS
|
||||
crc32.h
|
||||
deflate.h
|
||||
gzguts.h
|
||||
inffast.h
|
||||
inffixed.h
|
||||
inflate.h
|
||||
inftrees.h
|
||||
trees.h
|
||||
zutil.h
|
||||
)
|
||||
set(ZLIB_SRCS
|
||||
adler32.c
|
||||
compress.c
|
||||
crc32.c
|
||||
deflate.c
|
||||
gzclose.c
|
||||
gzio.c
|
||||
gzlib.c
|
||||
gzread.c
|
||||
gzwrite.c
|
||||
inflate.c
|
||||
infback.c
|
||||
inftrees.c
|
||||
inffast.c
|
||||
trees.c
|
||||
uncompr.c
|
||||
zutil.c
|
||||
)
|
||||
|
||||
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 VERSION 1.2.3.4)
|
||||
set_target_properties(zlib PROPERTIES SOVERSION 1)
|
||||
if(UNIX)
|
||||
# On unix like platforms the library is almost always called libz
|
||||
set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
|
||||
endif()
|
||||
|
||||
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
|
||||
install(TARGETS zlib
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib )
|
||||
endif()
|
||||
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
|
||||
install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
|
||||
endif()
|
||||
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
|
||||
install(FILES zlib.3 DESTINATION share/man/man3)
|
||||
endif()
|
||||
|
||||
#============================================================================
|
||||
# Example binaries
|
||||
#============================================================================
|
||||
|
||||
add_executable(example example.c)
|
||||
target_link_libraries(example zlib)
|
||||
add_test(example example)
|
||||
|
||||
add_executable(minigzip minigzip.c)
|
||||
target_link_libraries(minigzip zlib)
|
||||
|
||||
if(HAVE_OFF64_T)
|
||||
add_executable(example64 example.c)
|
||||
target_link_libraries(example64 zlib)
|
||||
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
add_test(example64 example64)
|
||||
|
||||
add_executable(minigzip64 minigzip.c)
|
||||
target_link_libraries(minigzip64 zlib)
|
||||
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
endif()
|
||||
105
ChangeLog
105
ChangeLog
@@ -1,6 +1,111 @@
|
||||
|
||||
ChangeLog file for zlib
|
||||
|
||||
Changes in 1.2.3.5 (8 Jan 2010)
|
||||
- Add space after #if in zutil.h for some compilers
|
||||
- Fix relatively harmless bug in deflate_fast() [Exarevsky]
|
||||
- Fix same problem in deflate_slow()
|
||||
- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
|
||||
- Add deflate_rle() for faster Z_RLE strategy run-length encoding
|
||||
- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
|
||||
- Change name of "write" variable in inffast.c to avoid library collisions
|
||||
- Fix premature EOF from gzread() in gzio.c [Brown]
|
||||
- Use zlib header window size if windowBits is 0 in inflateInit2()
|
||||
- Remove compressBound() call in deflate.c to avoid linking compress.o
|
||||
- Replace use of errno in gz* with functions, support WinCE [Alves]
|
||||
- Provide alternative to perror() in minigzip.c for WinCE [Alves]
|
||||
- Don't use _vsnprintf on later versions of MSVC [Lowman]
|
||||
- Add CMake build script and input file [Lowman]
|
||||
- Update contrib/minizip to 1.1 [Svensson, Vollant]
|
||||
- Moved nintendods directory from contrib to .
|
||||
- Replace gzio.c with a new set of routines with the same functionality
|
||||
- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
|
||||
- Update contrib/minizip to 1.1b
|
||||
|
||||
Changes in 1.2.3.4 (21 Dec 2009)
|
||||
- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
|
||||
- Update comments in configure and Makefile.in for default --shared
|
||||
- Fix test -z's in configure [Marquess]
|
||||
- Build examplesh and minigzipsh when not testing
|
||||
- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
|
||||
- Import LDFLAGS from the environment in configure
|
||||
- Fix configure to populate SFLAGS with discovered CFLAGS options
|
||||
- Adapt make_vms.com to the new Makefile.in [Zinser]
|
||||
- Add zlib2ansi script for C++ compilation [Marquess]
|
||||
- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
|
||||
- Add AMD64 assembler code for longest match to contrib [Teterin]
|
||||
- Include options from $SFLAGS when doing $LDSHARED
|
||||
- Simplify 64-bit file support by introducing z_off64_t type
|
||||
- Make shared object files in objs directory to work around old Sun cc
|
||||
- Use only three-part version number for Darwin shared compiles
|
||||
- Add rc option to ar in Makefile.in for when ./configure not run
|
||||
- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
|
||||
- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
|
||||
- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
|
||||
- Rename Makefile.in targets allstatic to static and allshared to shared
|
||||
- Fix static and shared Makefile.in targets to be independent
|
||||
- Correct error return bug in gz_open() by setting state [Brown]
|
||||
- Put spaces before ;;'s in configure for better sh compatibility
|
||||
- Add pigz.c (parallel implementation of gzip) to examples/
|
||||
- Correct constant in crc32.c to UL [Leventhal]
|
||||
- Reject negative lengths in crc32_combine()
|
||||
- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
|
||||
- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
|
||||
- Correct typo in doc/algorithm.txt [Janik]
|
||||
- Fix bug in adler32_combine() [Zhu]
|
||||
- Catch missing-end-of-block-code error in all inflates and in puff
|
||||
Assures that random input to inflate eventually results in an error
|
||||
- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
|
||||
- Update ENOUGH and its usage to reflect discovered bounds
|
||||
- Fix gzerror() error report on empty input file [Brown]
|
||||
- Add ush casts in trees.c to avoid pedantic runtime errors
|
||||
- Fix typo in zlib.h uncompress() description [Reiss]
|
||||
- Correct inflate() comments with regard to automatic header detection
|
||||
- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
|
||||
- Put new version of gzlog (2.0) in examples with interruption recovery
|
||||
- Add puff compile option to permit invalid distance-too-far streams
|
||||
- Add puff TEST command options, ability to read piped input
|
||||
- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
|
||||
_LARGEFILE64_SOURCE not defined
|
||||
- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
|
||||
- Fix deflateSetDictionary() to use all 32K for output consistency
|
||||
- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
|
||||
- Clear bytes after deflate lookahead to avoid use of uninitialized data
|
||||
- Change a limit in inftrees.c to be more transparent to Coverity Prevent
|
||||
- Update win32/zlib.def with exported symbols from zlib.h
|
||||
- Correct spelling error in zlib.h [Willem]
|
||||
- Allow Z_BLOCK for deflate() to force a new block
|
||||
- Allow negative bits in inflatePrime() to delete existing bit buffer
|
||||
- Add Z_TREES flush option to inflate() to return at end of trees
|
||||
- Add inflateMark() to return current state information for random access
|
||||
- Add Makefile for NintendoDS to contrib [Costa]
|
||||
- Add -w in configure compile tests to avoid spurious warnings [Beucler]
|
||||
- Fix typos in zlib.h comments for deflateSetDictionary()
|
||||
- Fix EOF detection in transparent gzread() [Maier]
|
||||
|
||||
Changes in 1.2.3.3 (2 October 2006)
|
||||
- Make --shared the default for configure, add a --static option
|
||||
- Add compile option to permit invalid distance-too-far streams
|
||||
- Add inflateUndermine() function which is required to enable above
|
||||
- Remove use of "this" variable name for C++ compatibility [Marquess]
|
||||
- Add testing of shared library in make test, if shared library built
|
||||
- Use ftello() and fseeko() if available instead of ftell() and fseek()
|
||||
- Provide two versions of all functions that use the z_off_t type for
|
||||
binary compatibility -- a normal version and a 64-bit offset version,
|
||||
per the Large File Support Extension when _LARGEFILE64_SOURCE is
|
||||
defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
|
||||
is defined to be 64
|
||||
- Add a --uname= option to configure to perhaps help with cross-compiling
|
||||
|
||||
Changes in 1.2.3.2 (3 September 2006)
|
||||
- Turn off silly Borland warnings [Hay]
|
||||
- Use off64_t and define _LARGEFILE64_SOURCE when present
|
||||
- Fix missing dependency on inffixed.h in Makefile.in
|
||||
- Rig configure --shared to build both shared and static [Teredesai, Truta]
|
||||
- Remove zconf.in.h and instead create a new zlibdefs.h file
|
||||
- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
|
||||
- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
|
||||
|
||||
Changes in 1.2.3.1 (16 August 2006)
|
||||
- Add watcom directory with OpenWatcom make files [Daniel]
|
||||
- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
|
||||
|
||||
15
INDEX
15
INDEX
@@ -1,3 +1,4 @@
|
||||
CMakeLists.txt cmake build file
|
||||
ChangeLog history of changes
|
||||
FAQ Frequently Asked Questions about zlib
|
||||
INDEX this file
|
||||
@@ -6,26 +7,29 @@ Makefile.in makefile for Unix (template for configure)
|
||||
README guess what
|
||||
configure configure script for Unix
|
||||
make_vms.com makefile for VMS
|
||||
zconf.in.h template for zconf.h (used by configure)
|
||||
treebuild.xml XML description of source file dependencies
|
||||
zlib.3 Man page for zlib
|
||||
zlib.map Linux symbol information
|
||||
zlib.pc.in ??
|
||||
zlib.pc.in Template for pkg-config descriptor
|
||||
zlib2ansi perl script to convert source files for C++ compilation
|
||||
|
||||
amiga/ makefiles for Amiga SAS C
|
||||
as400/ makefiles for IBM AS/400
|
||||
doc/ documentation for formats and algorithms
|
||||
msdos/ makefiles for MSDOS
|
||||
nintendods/ makefile for Nintendo DS
|
||||
old/ makefiles for various architectures and zlib documentation
|
||||
files that have not yet been updated for zlib 1.2.x
|
||||
projects/ projects for various Integrated Development Environments
|
||||
qnx/ makefiles for QNX
|
||||
todo/ works in progress
|
||||
watcom/ makefiles for OpenWatcom
|
||||
win32/ makefiles for Windows
|
||||
zlibdefs.h.cmakein input file for cmake build
|
||||
|
||||
zlib public header files (required for library use):
|
||||
zconf.h
|
||||
zlib.h
|
||||
zlibdefs.h
|
||||
|
||||
private source files used to build the zlib library:
|
||||
adler32.c
|
||||
@@ -34,7 +38,12 @@ crc32.c
|
||||
crc32.h
|
||||
deflate.c
|
||||
deflate.h
|
||||
gzclose.c
|
||||
gzguts.h
|
||||
gzio.c
|
||||
gzlib.c
|
||||
gzread.c
|
||||
gzwrite.c
|
||||
infback.c
|
||||
inffast.c
|
||||
inffast.h
|
||||
|
||||
164
Makefile
164
Makefile
@@ -4,8 +4,8 @@
|
||||
|
||||
# To compile and test, type:
|
||||
# ./configure; make test
|
||||
# The call of configure is optional if you don't have special requirements
|
||||
# If you wish to build zlib as a shared library, use: ./configure -s
|
||||
# Normally configure builds both a static and a shared library.
|
||||
# If you want to build just a static library, use: ./configure --static
|
||||
|
||||
# To use the asm code, type:
|
||||
# cp contrib/asm?86/match.S ./match.S
|
||||
@@ -24,16 +24,19 @@ CFLAGS=-O
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
LDFLAGS=libz.a
|
||||
SFLAGS=-O
|
||||
|
||||
LDFLAGS=-L. libz.a
|
||||
LDSHARED=$(CC)
|
||||
CPP=$(CC) -E
|
||||
|
||||
LIBS=libz.a
|
||||
STATICLIB=libz.a
|
||||
SHAREDLIB=libz.so
|
||||
SHAREDLIBV=libz.so.1.2.3.1
|
||||
SHAREDLIBV=libz.so.1.2.3.5
|
||||
SHAREDLIBM=libz.so.1
|
||||
LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
|
||||
|
||||
AR=ar
|
||||
AR=ar rc
|
||||
RANLIB=ranlib
|
||||
TAR=tar
|
||||
SHELL=/bin/sh
|
||||
@@ -47,20 +50,34 @@ mandir = ${prefix}/share/man
|
||||
man3dir = ${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \
|
||||
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
|
||||
PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzio.lo gzlib.lo gzread.lo \
|
||||
gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo
|
||||
|
||||
# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
|
||||
OBJA =
|
||||
# to use the asm code: make OBJA=match.o
|
||||
PIC_OBJA =
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
OBJS = $(OBJC) $(OBJA)
|
||||
|
||||
all: example$(EXE) minigzip$(EXE)
|
||||
PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
|
||||
|
||||
all: static shared
|
||||
|
||||
static: example$(EXE) minigzip$(EXE)
|
||||
|
||||
shared: examplesh$(EXE) minigzipsh$(EXE)
|
||||
|
||||
all64: example64$(EXE) minigzip64$(EXE)
|
||||
|
||||
check: test
|
||||
test: all
|
||||
@LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
echo hello world | ./minigzip | ./minigzip -d || \
|
||||
|
||||
test: all teststatic testshared
|
||||
|
||||
teststatic: static
|
||||
@echo hello world | ./minigzip | ./minigzip -d || \
|
||||
echo ' *** minigzip test FAILED ***' ; \
|
||||
if ./example; then \
|
||||
echo ' *** zlib test OK ***'; \
|
||||
@@ -68,8 +85,30 @@ test: all
|
||||
echo ' *** zlib test FAILED ***'; \
|
||||
fi
|
||||
|
||||
libz.a: $(OBJS) $(OBJA)
|
||||
$(AR) $@ $(OBJS) $(OBJA)
|
||||
testshared: shared
|
||||
@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
|
||||
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
|
||||
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
|
||||
echo hello world | ./minigzipsh | ./minigzipsh -d || \
|
||||
echo ' *** minigzip shared test FAILED ***' ; \
|
||||
if ./examplesh; then \
|
||||
echo ' *** zlib shared test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib shared test FAILED ***'; \
|
||||
fi
|
||||
|
||||
test64: all64
|
||||
@echo hello world | ./minigzip64 | ./minigzip64 -d || \
|
||||
echo ' *** minigzip 64-bit test FAILED ***' ; \
|
||||
if ./example64; then \
|
||||
echo ' *** zlib 64-bit test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib 64-bit test FAILED ***'; \
|
||||
fi
|
||||
|
||||
libz.a: $(OBJS)
|
||||
$(AR) $@ $(OBJS)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
match.o: match.S
|
||||
@@ -78,26 +117,55 @@ match.o: match.S
|
||||
mv _match.o match.o
|
||||
rm -f _match.s
|
||||
|
||||
$(SHAREDLIBV): $(OBJS)
|
||||
$(LDSHARED) -o $@ $(OBJS)
|
||||
match.lo: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c -fPIC _match.s
|
||||
mv _match.o match.lo
|
||||
rm -f _match.s
|
||||
|
||||
example64.o: example.c zlib.h zconf.h zlibdefs.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $<
|
||||
|
||||
minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $<
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
.c.lo:
|
||||
-@if [ ! -d objs ]; then mkdir objs; fi
|
||||
$(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
|
||||
-@mv objs/$*.o $@
|
||||
|
||||
$(SHAREDLIBV): $(PIC_OBJS)
|
||||
$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) -lc
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIBM)
|
||||
-@rmdir objs
|
||||
|
||||
example$(EXE): example.o $(LIBS)
|
||||
example$(EXE): example.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
|
||||
|
||||
minigzip$(EXE): minigzip.o $(LIBS)
|
||||
minigzip$(EXE): minigzip.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
|
||||
|
||||
install: $(LIBS)
|
||||
examplesh$(EXE): example.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
|
||||
|
||||
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
|
||||
|
||||
example64$(EXE): example64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example64.o $(LDFLAGS)
|
||||
|
||||
minigzip64$(EXE): minigzip64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip64.o $(LDFLAGS)
|
||||
|
||||
install-libs: $(LIBS)
|
||||
-@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
|
||||
cp zlib.h zconf.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
|
||||
cp $(LIBS) $(DESTDIR)$(libdir)
|
||||
cd $(DESTDIR)$(libdir); chmod 755 $(LIBS)
|
||||
-@(cd $(DESTDIR)$(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
|
||||
@@ -114,8 +182,13 @@ install: $(LIBS)
|
||||
# The ranlib in install is needed on NeXTSTEP which checks file times
|
||||
# ldconfig is for Linux
|
||||
|
||||
install: install-libs
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
cp zlib.h zconf.h zlibdefs.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h $(DESTDIR)$(includedir)/zlibdefs.h
|
||||
|
||||
uninstall:
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h zlibdefs.h
|
||||
cd $(DESTDIR)$(libdir); rm -f libz.a; \
|
||||
if test -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
@@ -125,14 +198,18 @@ uninstall:
|
||||
|
||||
mostlyclean: clean
|
||||
clean:
|
||||
rm -f *.o *~ example$(EXE) minigzip$(EXE) \
|
||||
rm -f *.o *.lo *~ \
|
||||
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
|
||||
example64$(EXE) minigzip64$(EXE) \
|
||||
libz.* foo.gz so_locations \
|
||||
_match.s maketree contrib/infback9/*.o
|
||||
rm -rf objs
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean
|
||||
cp -p Makefile.in Makefile
|
||||
cp -p zconf.in.h zconf.h
|
||||
rm zlibdefs.h
|
||||
touch -r configure zlibdefs.h
|
||||
rm -f zlib.pc .DS_Store
|
||||
|
||||
tags:
|
||||
@@ -143,17 +220,22 @@ depend:
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
adler32.o: zlib.h zconf.h
|
||||
compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
uncompr.o: zlib.h zconf.h
|
||||
zutil.o: zutil.h zlib.h zconf.h
|
||||
adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h
|
||||
gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h
|
||||
crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
infback.o inflate.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h
|
||||
|
||||
adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h
|
||||
gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h
|
||||
crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h
|
||||
deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
infback.lo inflate.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h
|
||||
inftrees.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
|
||||
trees.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h
|
||||
|
||||
164
Makefile.in
164
Makefile.in
@@ -4,8 +4,8 @@
|
||||
|
||||
# To compile and test, type:
|
||||
# ./configure; make test
|
||||
# The call of configure is optional if you don't have special requirements
|
||||
# If you wish to build zlib as a shared library, use: ./configure -s
|
||||
# Normally configure builds both a static and a shared library.
|
||||
# If you want to build just a static library, use: ./configure --static
|
||||
|
||||
# To use the asm code, type:
|
||||
# cp contrib/asm?86/match.S ./match.S
|
||||
@@ -24,16 +24,19 @@ CFLAGS=-O
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
LDFLAGS=libz.a
|
||||
SFLAGS=-O
|
||||
|
||||
LDFLAGS=-L. libz.a
|
||||
LDSHARED=$(CC)
|
||||
CPP=$(CC) -E
|
||||
|
||||
LIBS=libz.a
|
||||
STATICLIB=libz.a
|
||||
SHAREDLIB=libz.so
|
||||
SHAREDLIBV=libz.so.1.2.3.1
|
||||
SHAREDLIBV=libz.so.1.2.3.5
|
||||
SHAREDLIBM=libz.so.1
|
||||
LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)
|
||||
|
||||
AR=ar
|
||||
AR=ar rc
|
||||
RANLIB=ranlib
|
||||
TAR=tar
|
||||
SHELL=/bin/sh
|
||||
@@ -47,20 +50,34 @@ mandir = ${prefix}/share/man
|
||||
man3dir = ${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \
|
||||
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
|
||||
PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzio.lo gzlib.lo gzread.lo \
|
||||
gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo
|
||||
|
||||
# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
|
||||
OBJA =
|
||||
# to use the asm code: make OBJA=match.o
|
||||
PIC_OBJA =
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
OBJS = $(OBJC) $(OBJA)
|
||||
|
||||
all: example$(EXE) minigzip$(EXE)
|
||||
PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
|
||||
|
||||
all: static shared
|
||||
|
||||
static: example$(EXE) minigzip$(EXE)
|
||||
|
||||
shared: examplesh$(EXE) minigzipsh$(EXE)
|
||||
|
||||
all64: example64$(EXE) minigzip64$(EXE)
|
||||
|
||||
check: test
|
||||
test: all
|
||||
@LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
echo hello world | ./minigzip | ./minigzip -d || \
|
||||
|
||||
test: all teststatic testshared
|
||||
|
||||
teststatic: static
|
||||
@echo hello world | ./minigzip | ./minigzip -d || \
|
||||
echo ' *** minigzip test FAILED ***' ; \
|
||||
if ./example; then \
|
||||
echo ' *** zlib test OK ***'; \
|
||||
@@ -68,8 +85,30 @@ test: all
|
||||
echo ' *** zlib test FAILED ***'; \
|
||||
fi
|
||||
|
||||
libz.a: $(OBJS) $(OBJA)
|
||||
$(AR) $@ $(OBJS) $(OBJA)
|
||||
testshared: shared
|
||||
@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
|
||||
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
|
||||
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
|
||||
echo hello world | ./minigzipsh | ./minigzipsh -d || \
|
||||
echo ' *** minigzip shared test FAILED ***' ; \
|
||||
if ./examplesh; then \
|
||||
echo ' *** zlib shared test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib shared test FAILED ***'; \
|
||||
fi
|
||||
|
||||
test64: all64
|
||||
@echo hello world | ./minigzip64 | ./minigzip64 -d || \
|
||||
echo ' *** minigzip 64-bit test FAILED ***' ; \
|
||||
if ./example64; then \
|
||||
echo ' *** zlib 64-bit test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib 64-bit test FAILED ***'; \
|
||||
fi
|
||||
|
||||
libz.a: $(OBJS)
|
||||
$(AR) $@ $(OBJS)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
match.o: match.S
|
||||
@@ -78,26 +117,55 @@ match.o: match.S
|
||||
mv _match.o match.o
|
||||
rm -f _match.s
|
||||
|
||||
$(SHAREDLIBV): $(OBJS)
|
||||
$(LDSHARED) -o $@ $(OBJS)
|
||||
match.lo: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c -fPIC _match.s
|
||||
mv _match.o match.lo
|
||||
rm -f _match.s
|
||||
|
||||
example64.o: example.c zlib.h zconf.h zlibdefs.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $<
|
||||
|
||||
minigzip64.o: minigzip.c zlib.h zconf.h zlibdefs.h
|
||||
$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ $<
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
.c.lo:
|
||||
-@if [ ! -d objs ]; then mkdir objs; fi
|
||||
$(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
|
||||
-@mv objs/$*.o $@
|
||||
|
||||
$(SHAREDLIBV): $(PIC_OBJS)
|
||||
$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) -lc
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIBM)
|
||||
-@rmdir objs
|
||||
|
||||
example$(EXE): example.o $(LIBS)
|
||||
example$(EXE): example.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
|
||||
|
||||
minigzip$(EXE): minigzip.o $(LIBS)
|
||||
minigzip$(EXE): minigzip.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
|
||||
|
||||
install: $(LIBS)
|
||||
examplesh$(EXE): example.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
|
||||
|
||||
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
|
||||
|
||||
example64$(EXE): example64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example64.o $(LDFLAGS)
|
||||
|
||||
minigzip64$(EXE): minigzip64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip64.o $(LDFLAGS)
|
||||
|
||||
install-libs: $(LIBS)
|
||||
-@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
|
||||
cp zlib.h zconf.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
|
||||
cp $(LIBS) $(DESTDIR)$(libdir)
|
||||
cd $(DESTDIR)$(libdir); chmod 755 $(LIBS)
|
||||
-@(cd $(DESTDIR)$(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
|
||||
@@ -114,8 +182,13 @@ install: $(LIBS)
|
||||
# The ranlib in install is needed on NeXTSTEP which checks file times
|
||||
# ldconfig is for Linux
|
||||
|
||||
install: install-libs
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
cp zlib.h zconf.h zlibdefs.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h $(DESTDIR)$(includedir)/zlibdefs.h
|
||||
|
||||
uninstall:
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h zlibdefs.h
|
||||
cd $(DESTDIR)$(libdir); rm -f libz.a; \
|
||||
if test -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
@@ -125,14 +198,18 @@ uninstall:
|
||||
|
||||
mostlyclean: clean
|
||||
clean:
|
||||
rm -f *.o *~ example$(EXE) minigzip$(EXE) \
|
||||
rm -f *.o *.lo *~ \
|
||||
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
|
||||
example64$(EXE) minigzip64$(EXE) \
|
||||
libz.* foo.gz so_locations \
|
||||
_match.s maketree contrib/infback9/*.o
|
||||
rm -rf objs
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean
|
||||
cp -p Makefile.in Makefile
|
||||
cp -p zconf.in.h zconf.h
|
||||
rm zlibdefs.h
|
||||
touch -r configure zlibdefs.h
|
||||
rm -f zlib.pc .DS_Store
|
||||
|
||||
tags:
|
||||
@@ -143,17 +220,22 @@ depend:
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
adler32.o: zlib.h zconf.h
|
||||
compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
uncompr.o: zlib.h zconf.h
|
||||
zutil.o: zutil.h zlib.h zconf.h
|
||||
adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h
|
||||
gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h
|
||||
crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
infback.o inflate.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h
|
||||
|
||||
adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h
|
||||
gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h
|
||||
crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h
|
||||
deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
infback.lo inflate.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h inflate.h inffast.h
|
||||
inftrees.lo: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
|
||||
trees.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h
|
||||
|
||||
4
README
4
README
@@ -1,6 +1,6 @@
|
||||
ZLIB DATA COMPRESSION LIBRARY
|
||||
|
||||
zlib 1.2.3.1 is a general purpose data compression library. All the code is
|
||||
zlib 1.2.3.5 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
|
||||
(Request for Comments) 1950 to 1952 in the files
|
||||
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
|
||||
issue of Dr. Dobb's Journal; a copy of the article is available in
|
||||
http://dogma.net/markn/articles/zlibtool/zlibtool.htm
|
||||
|
||||
The changes made in version 1.2.3.1 are documented in the file ChangeLog.
|
||||
The changes made in version 1.2.3.5 are documented in the file ChangeLog.
|
||||
|
||||
Unsupported third party contributions are provided in directory "contrib".
|
||||
|
||||
|
||||
38
adler32.c
38
adler32.c
@@ -1,12 +1,15 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2004 Mark Adler
|
||||
* Copyright (C) 1995-2007 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
#include "zutil.h"
|
||||
|
||||
#define local static
|
||||
|
||||
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
||||
|
||||
#define BASE 65521UL /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
@@ -125,10 +128,10 @@ uLong ZEXPORT adler32(adler, buf, len)
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
local uLong adler32_combine_(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off_t len2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
@@ -141,9 +144,26 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
MOD(sum2);
|
||||
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||
if (sum1 > BASE) sum1 -= BASE;
|
||||
if (sum1 > BASE) sum1 -= BASE;
|
||||
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
|
||||
if (sum2 > BASE) sum2 -= BASE;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
|
||||
if (sum2 >= BASE) sum2 -= BASE;
|
||||
return sum1 | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
|
||||
uLong adler1;
|
||||
uLong adler2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ LDFLAGS = -o
|
||||
LDLIBS = LIB:scppc.a LIB:end.o
|
||||
RM = delete quiet
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \
|
||||
uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
@@ -55,7 +55,11 @@ compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzclose.o: zlib.h zconf.h gzguts.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
gzlib.o: zlib.h zconf.h gzguts.h
|
||||
gzread.o: zlib.h zconf.h gzguts.h
|
||||
gzwrite.o: zlib.h zconf.h gzguts.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
|
||||
@@ -13,8 +13,8 @@ SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \
|
||||
NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \
|
||||
DEF=POSTINC
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \
|
||||
uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
@@ -54,7 +54,11 @@ compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzclose.o: zlib.h zconf.h gzguts.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
gzlib.o: zlib.h zconf.h gzguts.h
|
||||
gzread.o: zlib.h zconf.h gzguts.h
|
||||
gzwrite.o: zlib.h zconf.h gzguts.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
* ZLIB.INC - Interface to the general purpose compression library
|
||||
*
|
||||
* ILE RPG400 version by Patrick Monnerat, DATASPHERE.
|
||||
* Version 1.2.3.1
|
||||
* Version 1.2.3.5
|
||||
*
|
||||
*
|
||||
* WARNING:
|
||||
@@ -22,8 +22,8 @@
|
||||
*
|
||||
* Versioning information.
|
||||
*
|
||||
D ZLIB_VERSION C '1.2.3.1'
|
||||
D ZLIB_VERNUM C X'1231'
|
||||
D ZLIB_VERSION C '1.2.3.5'
|
||||
D ZLIB_VERNUM C X'1235'
|
||||
*
|
||||
* Other equates.
|
||||
*
|
||||
|
||||
200
configure
vendored
200
configure
vendored
@@ -1,26 +1,22 @@
|
||||
#!/bin/sh
|
||||
# configure script for zlib. This script is needed only if
|
||||
# you wish to build a shared library and your system supports them,
|
||||
# of if you need special compiler, flags or install directory.
|
||||
# Otherwise, you can just use directly "make test; make install"
|
||||
# configure script for zlib.
|
||||
#
|
||||
# To create a shared library, use "configure --shared"; by default a static
|
||||
# library is created. If the primitive shared library support provided here
|
||||
# does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz
|
||||
# Normally configure builds both a static and a shared library.
|
||||
# If you want to build just a static library, use: ./configure --static
|
||||
#
|
||||
# To impose specific compiler or flags or install directory, use for example:
|
||||
# prefix=$HOME CC=cc CFLAGS="-O4" ./configure
|
||||
# or for csh/tcsh users:
|
||||
# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
|
||||
# LDSHARED is the command to be used to create a shared library
|
||||
|
||||
# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
|
||||
# If you have problems, try without defining CC and CFLAGS before reporting
|
||||
# an error.
|
||||
|
||||
LIBS=libz.a
|
||||
LDFLAGS="-L. ${LIBS}"
|
||||
STATICLIB=libz.a
|
||||
LDFLAGS="${LDFLAGS} -L. ${STATICLIB}"
|
||||
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
|
||||
VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
|
||||
VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
|
||||
VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
|
||||
AR=${AR-"ar"}
|
||||
@@ -32,7 +28,7 @@ libdir=${libdir-'${exec_prefix}/lib'}
|
||||
includedir=${includedir-'${prefix}/include'}
|
||||
mandir=${mandir-'${prefix}/share/man'}
|
||||
shared_ext='.so'
|
||||
shared=0
|
||||
shared=1
|
||||
zprefix=0
|
||||
gcc=0
|
||||
old_cc="$CC"
|
||||
@@ -45,20 +41,22 @@ case "$1" in
|
||||
echo 'usage:'
|
||||
echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]'
|
||||
echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR] [--zprefix]'
|
||||
exit 0;;
|
||||
-p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
|
||||
-e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
|
||||
-l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
|
||||
-i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;;
|
||||
-p* | --prefix) prefix="$2"; shift; shift;;
|
||||
-e* | --eprefix) exec_prefix="$2"; shift; shift;;
|
||||
-l* | --libdir) libdir="$2"; shift; shift;;
|
||||
-i* | --includedir) includedir="$2"; shift; shift;;
|
||||
-s* | --shared | --enable-shared) shared=1; shift;;
|
||||
-z* | --zprefix) zprefix=1; shift;;
|
||||
--sysconfdir=*) echo "ignored option: --sysconfdir"; shift;;
|
||||
--localstatedir=*) echo "ignored option: --localstatedir"; shift;;
|
||||
*) echo "unknown option: $1"; echo "$0 --help for help"; exit 1;;
|
||||
exit 0 ;;
|
||||
-p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
|
||||
-e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
|
||||
-l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
|
||||
-i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
|
||||
-u*=* | --uname=*) uname=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
|
||||
-p* | --prefix) prefix="$2"; shift; shift ;;
|
||||
-e* | --eprefix) exec_prefix="$2"; shift; shift ;;
|
||||
-l* | --libdir) libdir="$2"; shift; shift ;;
|
||||
-i* | --includedir) includedir="$2"; shift; shift ;;
|
||||
-s* | --shared | --enable-shared) shared=1; shift ;;
|
||||
-t | --static) shared=0; shift ;;
|
||||
-z* | --zprefix) zprefix=1; shift ;;
|
||||
--sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
|
||||
--localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
|
||||
*) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -73,41 +71,47 @@ cc=${CC-gcc}
|
||||
cflags=${CFLAGS-"-O3"}
|
||||
# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
|
||||
case "$cc" in
|
||||
*gcc*) gcc=1;;
|
||||
*gcc*) gcc=1 ;;
|
||||
esac
|
||||
|
||||
if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
|
||||
CC="$cc"
|
||||
SFLAGS="${CFLAGS-"-O3"} -fPIC"
|
||||
CFLAGS="$cflags"
|
||||
case `(uname -s || echo unknown) 2>/dev/null` in
|
||||
Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"};;
|
||||
CFLAGS="${CFLAGS-"-O3"}"
|
||||
if test -z "$uname"; then
|
||||
uname=`(uname -s || echo unknown) 2>/dev/null`
|
||||
fi
|
||||
case "$uname" in
|
||||
Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
|
||||
CYGWIN* | Cygwin* | cygwin* | OS/2* )
|
||||
EXE='.exe';;
|
||||
EXE='.exe' ;;
|
||||
QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
|
||||
# (alain.bonnefoy@icbt.com)
|
||||
LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};;
|
||||
LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
|
||||
HP-UX*)
|
||||
LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
|
||||
case `(uname -m || echo unknown) 2>/dev/null` in
|
||||
ia64)
|
||||
shared_ext='.so'
|
||||
SHAREDLIB='libz.so';;
|
||||
SHAREDLIB='libz.so' ;;
|
||||
*)
|
||||
shared_ext='.sl'
|
||||
SHAREDLIB='libz.sl';;
|
||||
esac;;
|
||||
SHAREDLIB='libz.sl' ;;
|
||||
esac ;;
|
||||
Darwin*) shared_ext='.dylib'
|
||||
SHAREDLIB=libz$shared_ext
|
||||
SHAREDLIBV=libz.$VER$shared_ext
|
||||
SHAREDLIBM=libz.$VER1$shared_ext
|
||||
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
|
||||
*) LDSHARED=${LDSHARED-"$cc -shared"};;
|
||||
LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
|
||||
*) LDSHARED=${LDSHARED-"$cc -shared"} ;;
|
||||
esac
|
||||
else
|
||||
# find system name and corresponding cc options
|
||||
CC=${CC-cc}
|
||||
case `(uname -sr || echo unknown) 2>/dev/null` in
|
||||
if test -z "$uname"; then
|
||||
uname=`(uname -sr || echo unknown) 2>/dev/null`
|
||||
fi
|
||||
case "$uname" in
|
||||
HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
|
||||
CFLAGS=${CFLAGS-"-O"}
|
||||
# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
|
||||
@@ -115,63 +119,64 @@ else
|
||||
case `(uname -m || echo unknown) 2>/dev/null` in
|
||||
ia64)
|
||||
shared_ext='.so'
|
||||
SHAREDLIB='libz.so';;
|
||||
SHAREDLIB='libz.so' ;;
|
||||
*)
|
||||
shared_ext='.sl'
|
||||
SHAREDLIB='libz.sl';;
|
||||
esac;;
|
||||
SHAREDLIB='libz.sl' ;;
|
||||
esac ;;
|
||||
IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
|
||||
CFLAGS=${CFLAGS-"-ansi -O2"}
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"};;
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
|
||||
OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
|
||||
CFLAGS=${CFLAGS-"-O -std1"}
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
|
||||
LDFLAGS="${LDFLAGS} -Wl,-rpath,."
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
|
||||
OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
|
||||
CFLAGS=${CFLAGS-"-O -std1"}
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"};;
|
||||
LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
|
||||
QNX*) SFLAGS=${CFLAGS-"-4 -O"}
|
||||
CFLAGS=${CFLAGS-"-4 -O"}
|
||||
LDSHARED=${LDSHARED-"cc"}
|
||||
RANLIB=${RANLIB-"true"}
|
||||
AR_RC="cc -A";;
|
||||
AR_RC="cc -A" ;;
|
||||
SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
|
||||
CFLAGS=${CFLAGS-"-O3"}
|
||||
LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
|
||||
LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
|
||||
SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
|
||||
case `(uname -m || echo unknown) 2>/dev/null` in
|
||||
i86*)
|
||||
SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
|
||||
CFLAGS=${CFLAGS-"-xpentium -fast"};;
|
||||
CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
|
||||
*)
|
||||
SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
|
||||
CFLAGS=${CFLAGS-"-fast -xcg92"};;
|
||||
esac;;
|
||||
CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
|
||||
esac ;;
|
||||
SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
|
||||
CFLAGS=${CFLAGS-"-O2"}
|
||||
LDSHARED=${LDSHARED-"ld"};;
|
||||
LDSHARED=${LDSHARED-"ld"} ;;
|
||||
SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
|
||||
CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
|
||||
LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
|
||||
LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
|
||||
UNIX_System_V\ 4.2.0)
|
||||
SFLAGS=${CFLAGS-"-KPIC -O"}
|
||||
CFLAGS=${CFLAGS-"-O"}
|
||||
LDSHARED=${LDSHARED-"cc -G"};;
|
||||
LDSHARED=${LDSHARED-"cc -G"} ;;
|
||||
UNIX_SV\ 4.2MP)
|
||||
SFLAGS=${CFLAGS-"-Kconform_pic -O"}
|
||||
CFLAGS=${CFLAGS-"-O"}
|
||||
LDSHARED=${LDSHARED-"cc -G"};;
|
||||
LDSHARED=${LDSHARED-"cc -G"} ;;
|
||||
OpenUNIX\ 5)
|
||||
SFLAGS=${CFLAGS-"-KPIC -O"}
|
||||
CFLAGS=${CFLAGS-"-O"}
|
||||
LDSHARED=${LDSHARED-"cc -G"};;
|
||||
LDSHARED=${LDSHARED-"cc -G"} ;;
|
||||
AIX*) # Courtesy of dbakker@arrayasolutions.com
|
||||
SFLAGS=${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
|
||||
*) SFLAGS=${CFLAGS-"-O"}
|
||||
CFLAGS=${CFLAGS-"-O"}
|
||||
LDSHARED=${LDSHARED-"cc -shared"};;
|
||||
LDSHARED=${LDSHARED-"cc -shared"} ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -182,17 +187,15 @@ SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
|
||||
if test $shared -eq 1; then
|
||||
echo Checking for shared library support...
|
||||
# we must test in two steps (cc then ld), required at least on SunOS 4.x
|
||||
if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
|
||||
if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
|
||||
test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
|
||||
CFLAGS="$SFLAGS"
|
||||
LIBS="$SHAREDLIBV"
|
||||
echo Building shared library $SHAREDLIBV with $CC.
|
||||
elif test -z "$old_cc" -a -z "$old_cflags"; then
|
||||
echo No shared library support.
|
||||
shared=0;
|
||||
else
|
||||
echo Tested $CC -c $SFLAGS $test.c
|
||||
$CC -c $SFLAGS $test.c
|
||||
echo Tested $CC -w -c $SFLAGS $test.c
|
||||
$CC -w -c $SFLAGS $test.c
|
||||
echo Tested $LDSHARED -o $test$shared_ext $test.o
|
||||
$LDSHARED -o $test$shared_ext $test.o
|
||||
echo 'No shared library support; try without defining CC and CFLAGS'
|
||||
@@ -201,9 +204,49 @@ if test $shared -eq 1; then
|
||||
fi
|
||||
if test $shared -eq 0; then
|
||||
LDSHARED="$CC"
|
||||
echo Building static library $LIBS version $VER with $CC.
|
||||
ALL="static"
|
||||
TEST="all teststatic"
|
||||
echo Building static library $STATICLIB version $VER with $CC.
|
||||
else
|
||||
LDFLAGS="-L. ${SHAREDLIBV}"
|
||||
ALL="static shared"
|
||||
TEST="all teststatic testshared"
|
||||
fi
|
||||
|
||||
cat > zlibdefs.h << EOF
|
||||
/* zlibdefs.h -- compile-time definitions for the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
EOF
|
||||
|
||||
cat > $test.c <<EOF
|
||||
#include <sys/types.h>
|
||||
off64_t dummy = 0;
|
||||
EOF
|
||||
if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
|
||||
CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
|
||||
SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
|
||||
ALL="${ALL} all64"
|
||||
TEST="${TEST} test64"
|
||||
echo "Checking for off64_t... Yes."
|
||||
echo "Checking for fseeko... Yes."
|
||||
else
|
||||
echo "Checking for off64_t... No."
|
||||
cat > $test.c <<EOF
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
fseeko(NULL, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
|
||||
echo "Checking for fseeko... Yes."
|
||||
else
|
||||
CFLAGS="${CFLAGS} -DNO_FSEEKO"
|
||||
SFLAGS="${SFLAGS} -DNO_FSEEKO"
|
||||
echo "Checking for fseeko... No."
|
||||
fi
|
||||
fi
|
||||
|
||||
cat > $test.c <<EOF
|
||||
@@ -211,10 +254,18 @@ cat > $test.c <<EOF
|
||||
int main() { return 0; }
|
||||
EOF
|
||||
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h
|
||||
cat >> zlibdefs.h <<EOF
|
||||
#include <sys/types.h> /* for off_t */
|
||||
#include <unistd.h> /* for SEEK_* and off_t */
|
||||
#ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
EOF
|
||||
echo "Checking for unistd.h... Yes."
|
||||
else
|
||||
cp -p zconf.in.h zconf.h
|
||||
echo "Checking for unistd.h... No."
|
||||
fi
|
||||
|
||||
@@ -292,6 +343,7 @@ EOF
|
||||
echo "Checking for return value of vsnprintf()... Yes."
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
|
||||
echo "Checking for return value of vsnprintf()... No."
|
||||
echo " WARNING: apparently vsnprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
@@ -299,6 +351,7 @@ EOF
|
||||
fi
|
||||
else
|
||||
CFLAGS="$CFLAGS -DNO_vsnprintf"
|
||||
SFLAGS="$SFLAGS -DNO_vsnprintf"
|
||||
echo "Checking for vsnprintf() in stdio.h... No."
|
||||
echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
|
||||
echo " can build but will be open to possible buffer-overflow security"
|
||||
@@ -330,6 +383,7 @@ EOF
|
||||
echo "Checking for return value of vsprintf()... Yes."
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_vsprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_vsprintf_void"
|
||||
echo "Checking for return value of vsprintf()... No."
|
||||
echo " WARNING: apparently vsprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
@@ -379,6 +433,7 @@ EOF
|
||||
echo "Checking for return value of snprintf()... Yes."
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_snprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_snprintf_void"
|
||||
echo "Checking for return value of snprintf()... No."
|
||||
echo " WARNING: apparently snprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
@@ -386,6 +441,7 @@ EOF
|
||||
fi
|
||||
else
|
||||
CFLAGS="$CFLAGS -DNO_snprintf"
|
||||
SFLAGS="$SFLAGS -DNO_snprintf"
|
||||
echo "Checking for snprintf() in stdio.h... No."
|
||||
echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
|
||||
echo " can build but will be open to possible buffer-overflow security"
|
||||
@@ -411,6 +467,7 @@ EOF
|
||||
echo "Checking for return value of sprintf()... Yes."
|
||||
else
|
||||
CFLAGS="$CFLAGS -DHAS_sprintf_void"
|
||||
SFLAGS="$SFLAGS -DHAS_sprintf_void"
|
||||
echo "Checking for return value of sprintf()... No."
|
||||
echo " WARNING: apparently sprintf() does not return a value. zlib"
|
||||
echo " can build but will be open to possible string-format security"
|
||||
@@ -428,6 +485,7 @@ if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
|
||||
else
|
||||
echo "Checking for errno.h... No."
|
||||
CFLAGS="$CFLAGS -DNO_ERRNO_H"
|
||||
SFLAGS="$SFLAGS -DNO_ERRNO_H"
|
||||
fi
|
||||
|
||||
cat > $test.c <<EOF
|
||||
@@ -440,6 +498,7 @@ caddr_t hello() {
|
||||
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.
|
||||
@@ -453,7 +512,7 @@ case $CFLAGS in
|
||||
echo Checking for underline in external names... No.
|
||||
else
|
||||
echo Checking for underline in external names... Yes.
|
||||
fi;;
|
||||
fi ;;
|
||||
esac
|
||||
|
||||
rm -f $test.[co] $test $test$shared_ext
|
||||
@@ -462,9 +521,11 @@ rm -f $test.[co] $test $test$shared_ext
|
||||
sed < Makefile.in "
|
||||
/^CC *=/s#=.*#=$CC#
|
||||
/^CFLAGS *=/s#=.*#=$CFLAGS#
|
||||
/^CPP *=/s#=.*#=$CPP#
|
||||
/^SFLAGS *=/s#=.*#=$SFLAGS#
|
||||
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
|
||||
/^LDSHARED *=/s#=.*#=$LDSHARED#
|
||||
/^LIBS *=/s#=.*#=$LIBS#
|
||||
/^CPP *=/s#=.*#=$CPP#
|
||||
/^STATICLIB *=/s#=.*#=$STATICLIB#
|
||||
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
|
||||
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
|
||||
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
|
||||
@@ -476,7 +537,8 @@ sed < Makefile.in "
|
||||
/^libdir *=/s#=.*#=$libdir#
|
||||
/^includedir *=/s#=.*#=$includedir#
|
||||
/^mandir *=/s#=.*#=$mandir#
|
||||
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
|
||||
/^all: */s#:.*#: $ALL#
|
||||
/^test: */s#:.*#: $TEST#
|
||||
" > Makefile
|
||||
|
||||
sed < zlib.pc.in "
|
||||
@@ -484,7 +546,7 @@ sed < zlib.pc.in "
|
||||
/^CFLAGS *=/s#=.*#=$CFLAGS#
|
||||
/^CPP *=/s#=.*#=$CPP#
|
||||
/^LDSHARED *=/s#=.*#=$LDSHARED#
|
||||
/^LIBS *=/s#=.*#=$LIBS#
|
||||
/^STATICLIB *=/s#=.*#=$STATICLIB#
|
||||
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
|
||||
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
|
||||
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
|
||||
|
||||
@@ -8,6 +8,10 @@ ada/ by Dmitriy Anisimkov <anisimkov@yahoo.com>
|
||||
Support for Ada
|
||||
See http://zlib-ada.sourceforge.net/
|
||||
|
||||
amd64/ by Mikhail Teterin <mi@ALDAN.algebra.com>
|
||||
asm code for AMD64
|
||||
See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393
|
||||
|
||||
asm586/
|
||||
asm686/ by Brian Raiter <breadbox@muppetlabs.com>
|
||||
asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax
|
||||
@@ -52,6 +56,7 @@ masmx86/ by Gilles Vollant <info@winimage.com>
|
||||
|
||||
minizip/ by Gilles Vollant <info@winimage.com>
|
||||
Mini zip and unzip based on zlib
|
||||
Includes Zip64 support by Mathias Svensson <mathias@result42.com>
|
||||
See http://www.winimage.com/zLibDll/unzip.html
|
||||
|
||||
pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al.
|
||||
|
||||
357
contrib/amd64/amd64-match.S
Normal file
357
contrib/amd64/amd64-match.S
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* match.S -- optimized version of longest_match()
|
||||
* based on the similar work by Gilles Vollant, and Brian Raiter, written 1998
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the BSD License. Use by owners of Che Guevarra
|
||||
* parafernalia is prohibited, where possible, and highly discouraged
|
||||
* elsewhere.
|
||||
*/
|
||||
|
||||
#ifndef NO_UNDERLINE
|
||||
# define match_init _match_init
|
||||
# define longest_match _longest_match
|
||||
#endif
|
||||
|
||||
#define scanend ebx
|
||||
#define scanendw bx
|
||||
#define chainlenwmask edx /* high word: current chain len low word: s->wmask */
|
||||
#define curmatch rsi
|
||||
#define curmatchd esi
|
||||
#define windowbestlen r8
|
||||
#define scanalign r9
|
||||
#define scanalignd r9d
|
||||
#define window r10
|
||||
#define bestlen r11
|
||||
#define bestlend r11d
|
||||
#define scanstart r12d
|
||||
#define scanstartw r12w
|
||||
#define scan r13
|
||||
#define nicematch r14d
|
||||
#define limit r15
|
||||
#define limitd r15d
|
||||
#define prev rcx
|
||||
|
||||
/*
|
||||
* The 258 is a "magic number, not a parameter -- changing it
|
||||
* breaks the hell loose
|
||||
*/
|
||||
#define MAX_MATCH (258)
|
||||
#define MIN_MATCH (3)
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
|
||||
#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7)
|
||||
|
||||
/* stack frame offsets */
|
||||
#define LocalVarsSize (112)
|
||||
#define _chainlenwmask ( 8-LocalVarsSize)(%rsp)
|
||||
#define _windowbestlen (16-LocalVarsSize)(%rsp)
|
||||
#define save_r14 (24-LocalVarsSize)(%rsp)
|
||||
#define save_rsi (32-LocalVarsSize)(%rsp)
|
||||
#define save_rbx (40-LocalVarsSize)(%rsp)
|
||||
#define save_r12 (56-LocalVarsSize)(%rsp)
|
||||
#define save_r13 (64-LocalVarsSize)(%rsp)
|
||||
#define save_r15 (80-LocalVarsSize)(%rsp)
|
||||
|
||||
/*
|
||||
* On AMD64 the first argument of a function (in our case -- the pointer to
|
||||
* deflate_state structure) is passed in %rdi, hence our offsets below are
|
||||
* all off of that.
|
||||
*/
|
||||
#ifndef STRUCT_OFFSET
|
||||
# define STRUCT_OFFSET (0)
|
||||
#endif
|
||||
#define dsWSize ( 56 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsWMask ( 64 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsWindow ( 72 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsPrev ( 88 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsMatchLen (136 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsPrevMatch (140 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsStrStart (148 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsMatchStart (152 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsLookahead (156 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsPrevLen (160 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsMaxChainLen (164 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsGoodMatch (180 + STRUCT_OFFSET)(%rdi)
|
||||
#define dsNiceMatch (184 + STRUCT_OFFSET)(%rdi)
|
||||
|
||||
.globl match_init, longest_match
|
||||
|
||||
.text
|
||||
|
||||
/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
|
||||
|
||||
longest_match:
|
||||
/*
|
||||
* Retrieve the function arguments. %curmatch will hold cur_match
|
||||
* throughout the entire function (passed via rsi on amd64).
|
||||
* rdi will hold the pointer to the deflate_state (first arg on amd64)
|
||||
*/
|
||||
mov %rsi, save_rsi
|
||||
mov %rbx, save_rbx
|
||||
mov %r12, save_r12
|
||||
mov %r13, save_r13
|
||||
mov %r14, save_r14
|
||||
mov %r15, save_r15
|
||||
|
||||
/* uInt wmask = s->w_mask; */
|
||||
/* unsigned chain_length = s->max_chain_length; */
|
||||
/* if (s->prev_length >= s->good_match) { */
|
||||
/* chain_length >>= 2; */
|
||||
/* } */
|
||||
|
||||
movl dsPrevLen, %eax
|
||||
movl dsGoodMatch, %ebx
|
||||
cmpl %ebx, %eax
|
||||
movl dsWMask, %eax
|
||||
movl dsMaxChainLen, %chainlenwmask
|
||||
jl LastMatchGood
|
||||
shrl $2, %chainlenwmask
|
||||
LastMatchGood:
|
||||
|
||||
/* chainlen is decremented once beforehand so that the function can */
|
||||
/* use the sign flag instead of the zero flag for the exit test. */
|
||||
/* It is then shifted into the high word, to make room for the wmask */
|
||||
/* value, which it will always accompany. */
|
||||
|
||||
decl %chainlenwmask
|
||||
shll $16, %chainlenwmask
|
||||
orl %eax, %chainlenwmask
|
||||
|
||||
/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */
|
||||
|
||||
movl dsNiceMatch, %eax
|
||||
movl dsLookahead, %ebx
|
||||
cmpl %eax, %ebx
|
||||
jl LookaheadLess
|
||||
movl %eax, %ebx
|
||||
LookaheadLess: movl %ebx, %nicematch
|
||||
|
||||
/* register Bytef *scan = s->window + s->strstart; */
|
||||
|
||||
mov dsWindow, %window
|
||||
movl dsStrStart, %limitd
|
||||
lea (%limit, %window), %scan
|
||||
|
||||
/* Determine how many bytes the scan ptr is off from being */
|
||||
/* dword-aligned. */
|
||||
|
||||
mov %scan, %scanalign
|
||||
negl %scanalignd
|
||||
andl $3, %scanalignd
|
||||
|
||||
/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */
|
||||
/* s->strstart - (IPos)MAX_DIST(s) : NIL; */
|
||||
|
||||
movl dsWSize, %eax
|
||||
subl $MIN_LOOKAHEAD, %eax
|
||||
xorl %ecx, %ecx
|
||||
subl %eax, %limitd
|
||||
cmovng %ecx, %limitd
|
||||
|
||||
/* int best_len = s->prev_length; */
|
||||
|
||||
movl dsPrevLen, %bestlend
|
||||
|
||||
/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory. */
|
||||
|
||||
lea (%window, %bestlen), %windowbestlen
|
||||
mov %windowbestlen, _windowbestlen
|
||||
|
||||
/* register ush scan_start = *(ushf*)scan; */
|
||||
/* register ush scan_end = *(ushf*)(scan+best_len-1); */
|
||||
/* Posf *prev = s->prev; */
|
||||
|
||||
movzwl (%scan), %scanstart
|
||||
movzwl -1(%scan, %bestlen), %scanend
|
||||
mov dsPrev, %prev
|
||||
|
||||
/* Jump into the main loop. */
|
||||
|
||||
movl %chainlenwmask, _chainlenwmask
|
||||
jmp LoopEntry
|
||||
|
||||
.balign 16
|
||||
|
||||
/* do {
|
||||
* match = s->window + cur_match;
|
||||
* if (*(ushf*)(match+best_len-1) != scan_end ||
|
||||
* *(ushf*)match != scan_start) continue;
|
||||
* [...]
|
||||
* } while ((cur_match = prev[cur_match & wmask]) > limit
|
||||
* && --chain_length != 0);
|
||||
*
|
||||
* Here is the inner loop of the function. The function will spend the
|
||||
* majority of its time in this loop, and majority of that time will
|
||||
* be spent in the first ten instructions.
|
||||
*/
|
||||
LookupLoop:
|
||||
andl %chainlenwmask, %curmatchd
|
||||
movzwl (%prev, %curmatch, 2), %curmatchd
|
||||
cmpl %limitd, %curmatchd
|
||||
jbe LeaveNow
|
||||
subl $0x00010000, %chainlenwmask
|
||||
js LeaveNow
|
||||
LoopEntry: cmpw -1(%windowbestlen, %curmatch), %scanendw
|
||||
jne LookupLoop
|
||||
cmpw %scanstartw, (%window, %curmatch)
|
||||
jne LookupLoop
|
||||
|
||||
/* Store the current value of chainlen. */
|
||||
movl %chainlenwmask, _chainlenwmask
|
||||
|
||||
/* %scan is the string under scrutiny, and %prev to the string we */
|
||||
/* are hoping to match it up with. In actuality, %esi and %edi are */
|
||||
/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */
|
||||
/* initialized to -(MAX_MATCH_8 - scanalign). */
|
||||
|
||||
mov $(-MAX_MATCH_8), %rdx
|
||||
lea (%curmatch, %window), %windowbestlen
|
||||
lea MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen
|
||||
lea MAX_MATCH_8(%scan, %scanalign), %prev
|
||||
|
||||
/* the prefetching below makes very little difference... */
|
||||
prefetcht1 (%windowbestlen, %rdx)
|
||||
prefetcht1 (%prev, %rdx)
|
||||
|
||||
/*
|
||||
* Test the strings for equality, 8 bytes at a time. At the end,
|
||||
* adjust %rdx so that it is offset to the exact byte that mismatched.
|
||||
*
|
||||
* It should be confessed that this loop usually does not represent
|
||||
* much of the total running time. Replacing it with a more
|
||||
* straightforward "rep cmpsb" would not drastically degrade
|
||||
* performance -- unrolling it, for example, makes no difference.
|
||||
*/
|
||||
#undef USE_SSE /* works, but is 6-7% slower, than non-SSE... */
|
||||
LoopCmps:
|
||||
#ifdef USE_SSE
|
||||
/* Preload the SSE registers */
|
||||
movdqu (%windowbestlen, %rdx), %xmm1
|
||||
movdqu (%prev, %rdx), %xmm2
|
||||
pcmpeqb %xmm2, %xmm1
|
||||
movdqu 16(%windowbestlen, %rdx), %xmm3
|
||||
movdqu 16(%prev, %rdx), %xmm4
|
||||
pcmpeqb %xmm4, %xmm3
|
||||
movdqu 32(%windowbestlen, %rdx), %xmm5
|
||||
movdqu 32(%prev, %rdx), %xmm6
|
||||
pcmpeqb %xmm6, %xmm5
|
||||
movdqu 48(%windowbestlen, %rdx), %xmm7
|
||||
movdqu 48(%prev, %rdx), %xmm8
|
||||
pcmpeqb %xmm8, %xmm7
|
||||
|
||||
/* Check the comparisions' results */
|
||||
pmovmskb %xmm1, %rax
|
||||
notw %ax
|
||||
bsfw %ax, %ax
|
||||
jnz LeaveLoopCmps
|
||||
add $16, %rdx
|
||||
pmovmskb %xmm3, %rax
|
||||
notw %ax
|
||||
bsfw %ax, %ax
|
||||
jnz LeaveLoopCmps
|
||||
add $16, %rdx
|
||||
pmovmskb %xmm5, %rax
|
||||
notw %ax
|
||||
bsfw %ax, %ax
|
||||
jnz LeaveLoopCmps
|
||||
add $16, %rdx
|
||||
pmovmskb %xmm7, %rax
|
||||
notw %ax
|
||||
bsfw %ax, %ax
|
||||
jnz LeaveLoopCmps
|
||||
add $16, %rdx
|
||||
jmp LoopCmps
|
||||
LeaveLoopCmps: add %rax, %rdx
|
||||
#else
|
||||
mov (%windowbestlen, %rdx), %rax
|
||||
xor (%prev, %rdx), %rax
|
||||
jnz LeaveLoopCmps
|
||||
add $8, %rdx
|
||||
jnz LoopCmps
|
||||
jmp LenMaximum
|
||||
# if 0
|
||||
/*
|
||||
* This three-liner is tantalizingly simple, but bsf is a slow instruction,
|
||||
* and the complicated alternative down below is quite a bit faster. Sad...
|
||||
*/
|
||||
LeaveLoopCmps: bsf %rax, %rax /* find the first non-zero bit */
|
||||
shrl $3, %eax /* divide by 8 to get the byte */
|
||||
add %rax, %rdx
|
||||
# else
|
||||
LeaveLoopCmps: testl $0xFFFFFFFF, %eax /* Check the first 4 bytes */
|
||||
jnz Check16
|
||||
add $4, %rdx
|
||||
shr $32, %rax
|
||||
Check16: testw $0xFFFF, %ax
|
||||
jnz LenLower
|
||||
add $2, %rdx
|
||||
shrl $16, %eax
|
||||
LenLower: subb $1, %al
|
||||
adc $0, %rdx
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Calculate the length of the match. If it is longer than MAX_MATCH, */
|
||||
/* then automatically accept it as the best possible match and leave. */
|
||||
|
||||
lea (%prev, %rdx), %rax
|
||||
sub %scan, %rax
|
||||
cmpl $MAX_MATCH, %eax
|
||||
jge LenMaximum
|
||||
|
||||
/* If the length of the match is not longer than the best match we */
|
||||
/* have so far, then forget it and return to the lookup loop. */
|
||||
|
||||
cmpl %bestlend, %eax
|
||||
jg LongerMatch
|
||||
mov _windowbestlen, %windowbestlen
|
||||
mov dsPrev, %prev
|
||||
movl _chainlenwmask, %edx
|
||||
jmp LookupLoop
|
||||
|
||||
/* s->match_start = cur_match; */
|
||||
/* best_len = len; */
|
||||
/* if (len >= nice_match) break; */
|
||||
/* scan_end = *(ushf*)(scan+best_len-1); */
|
||||
|
||||
LongerMatch:
|
||||
movl %eax, %bestlend
|
||||
movl %curmatchd, dsMatchStart
|
||||
cmpl %nicematch, %eax
|
||||
jge LeaveNow
|
||||
|
||||
lea (%window, %bestlen), %windowbestlen
|
||||
mov %windowbestlen, _windowbestlen
|
||||
|
||||
movzwl -1(%scan, %rax), %scanend
|
||||
mov dsPrev, %prev
|
||||
movl _chainlenwmask, %chainlenwmask
|
||||
jmp LookupLoop
|
||||
|
||||
/* Accept the current string, with the maximum possible length. */
|
||||
|
||||
LenMaximum:
|
||||
movl $MAX_MATCH, %bestlend
|
||||
movl %curmatchd, dsMatchStart
|
||||
|
||||
/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */
|
||||
/* return s->lookahead; */
|
||||
|
||||
LeaveNow:
|
||||
movl dsLookahead, %eax
|
||||
cmpl %eax, %bestlend
|
||||
cmovngl %bestlend, %eax
|
||||
LookaheadRet:
|
||||
|
||||
/* Restore the registers and return from whence we came. */
|
||||
|
||||
mov save_rsi, %rsi
|
||||
mov save_rbx, %rbx
|
||||
mov save_r12, %r12
|
||||
mov save_r13, %r13
|
||||
mov save_r14, %r14
|
||||
mov save_r15, %r15
|
||||
|
||||
ret
|
||||
|
||||
match_init: ret
|
||||
@@ -18,10 +18,10 @@ LDFLAGS =
|
||||
# variables
|
||||
ZLIB_LIB = zlib.lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
|
||||
OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
|
||||
OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
|
||||
|
||||
# targets
|
||||
@@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* infback9.c -- inflate deflate64 data using a call-back interface
|
||||
* Copyright (C) 1995-2003 Mark Adler
|
||||
* Copyright (C) 1995-2008 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -242,7 +242,7 @@ void FAR *out_desc;
|
||||
code const FAR *distcode; /* starting table for distance codes */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
code this; /* current decoding table entry */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
@@ -384,19 +384,19 @@ void FAR *out_desc;
|
||||
state->have = 0;
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
this = lencode[BITS(lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = lencode[BITS(lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.val < 16) {
|
||||
NEEDBITS(this.bits);
|
||||
DROPBITS(this.bits);
|
||||
state->lens[state->have++] = this.val;
|
||||
if (here.val < 16) {
|
||||
NEEDBITS(here.bits);
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
else {
|
||||
if (this.val == 16) {
|
||||
NEEDBITS(this.bits + 2);
|
||||
DROPBITS(this.bits);
|
||||
if (here.val == 16) {
|
||||
NEEDBITS(here.bits + 2);
|
||||
DROPBITS(here.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
mode = BAD;
|
||||
@@ -406,16 +406,16 @@ void FAR *out_desc;
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (this.val == 17) {
|
||||
NEEDBITS(this.bits + 3);
|
||||
DROPBITS(this.bits);
|
||||
else if (here.val == 17) {
|
||||
NEEDBITS(here.bits + 3);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
NEEDBITS(this.bits + 7);
|
||||
DROPBITS(this.bits);
|
||||
NEEDBITS(here.bits + 7);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 11 + BITS(7);
|
||||
DROPBITS(7);
|
||||
@@ -433,7 +433,16 @@ void FAR *out_desc;
|
||||
/* handle error breaks in while */
|
||||
if (mode == BAD) break;
|
||||
|
||||
/* build code tables */
|
||||
/* check for end-of-block code (better have one) */
|
||||
if (state->lens[256] == 0) {
|
||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
||||
mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (9 and 6) without reading the comments in inftree9.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
lencode = (code const FAR *)(state->next);
|
||||
lenbits = 9;
|
||||
@@ -460,28 +469,28 @@ void FAR *out_desc;
|
||||
case LEN:
|
||||
/* get a literal, length, or end-of-block code */
|
||||
for (;;) {
|
||||
this = lencode[BITS(lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = lencode[BITS(lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.op && (this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if (here.op && (here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = lencode[last.val +
|
||||
here = lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
length = (unsigned)this.val;
|
||||
DROPBITS(here.bits);
|
||||
length = (unsigned)here.val;
|
||||
|
||||
/* process literal */
|
||||
if (this.op == 0) {
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
if (here.op == 0) {
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
ROOM();
|
||||
*put++ = (unsigned char)(length);
|
||||
left--;
|
||||
@@ -490,21 +499,21 @@ void FAR *out_desc;
|
||||
}
|
||||
|
||||
/* process end of block */
|
||||
if (this.op & 32) {
|
||||
if (here.op & 32) {
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
mode = TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* invalid code */
|
||||
if (this.op & 64) {
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* length code -- get extra bits, if any */
|
||||
extra = (unsigned)(this.op) & 31;
|
||||
extra = (unsigned)(here.op) & 31;
|
||||
if (extra != 0) {
|
||||
NEEDBITS(extra);
|
||||
length += BITS(extra);
|
||||
@@ -514,30 +523,30 @@ void FAR *out_desc;
|
||||
|
||||
/* get distance code */
|
||||
for (;;) {
|
||||
this = distcode[BITS(distbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = distcode[BITS(distbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if ((here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = distcode[last.val +
|
||||
here = distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
if (this.op & 64) {
|
||||
DROPBITS(here.bits);
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
mode = BAD;
|
||||
break;
|
||||
}
|
||||
offset = (unsigned)this.val;
|
||||
offset = (unsigned)here.val;
|
||||
|
||||
/* get distance extra bits, if any */
|
||||
extra = (unsigned)(this.op) & 15;
|
||||
extra = (unsigned)(here.op) & 15;
|
||||
if (extra != 0) {
|
||||
NEEDBITS(extra);
|
||||
offset += BITS(extra);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* inftree9.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* Copyright (C) 1995-2008 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define MAXBITS 15
|
||||
|
||||
const char inflate9_copyright[] =
|
||||
" inflate9 1.2.3.1 Copyright 1995-2005 Mark Adler ";
|
||||
" inflate9 1.2.3.5 Copyright 1995-2009 Mark Adler ";
|
||||
/*
|
||||
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
|
||||
@@ -64,7 +64,7 @@ unsigned short FAR *work;
|
||||
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
||||
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
|
||||
130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
|
||||
133, 133, 133, 133, 144, 74, 196};
|
||||
133, 133, 133, 133, 144, 69, 199};
|
||||
static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
|
||||
65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
|
||||
@@ -160,11 +160,10 @@ unsigned short FAR *work;
|
||||
entered in the tables.
|
||||
|
||||
used keeps track of how many table entries have been allocated from the
|
||||
provided *table space. It is checked when a LENS table is being made
|
||||
against the space in *table, ENOUGH, minus the maximum space needed by
|
||||
the worst case distance code, MAXD. This should never happen, but the
|
||||
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
|
||||
This assumes that when type == LENS, bits == 9.
|
||||
provided *table space. It is checked for LENS and DIST tables against
|
||||
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
|
||||
the initial root table size constants. See the comments in inftree9.h
|
||||
for more information.
|
||||
|
||||
sym increments through all symbols, and the loop terminates when
|
||||
all codes of length max, i.e. all codes, have been processed. This
|
||||
@@ -203,7 +202,8 @@ unsigned short FAR *work;
|
||||
mask = used - 1; /* mask for comparing low */
|
||||
|
||||
/* check available table space */
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* process all codes and make table entries */
|
||||
@@ -270,7 +270,8 @@ unsigned short FAR *work;
|
||||
|
||||
/* check for enough space */
|
||||
used += 1U << curr;
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* inftree9.h -- header to use inftree9.c
|
||||
* Copyright (C) 1995-2003 Mark Adler
|
||||
* Copyright (C) 1995-2008 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -35,15 +35,21 @@ typedef struct {
|
||||
01000000 - invalid code
|
||||
*/
|
||||
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1444 code structures (852 for length/literals
|
||||
and 592 for distances, the latter actually the result of an
|
||||
exhaustive search). The true maximum is not known, but the value
|
||||
below is more than safe. */
|
||||
#define ENOUGH 2048
|
||||
#define MAXD 592
|
||||
/* Maximum size of the dynamic table. The maximum number of code structures is
|
||||
1446, which is the sum of 852 for literal/length codes and 594 for distance
|
||||
codes. These values were found by exhaustive searches using the program
|
||||
examples/enough.c found in the zlib distribtution. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns returns 852, and "enough 32 6 15" for distance codes returns 594.
|
||||
The initial root table size (9 or 6) is found in the fifth argument of the
|
||||
inflate_table() calls in infback9.c. If the root table size is changed,
|
||||
then these maximum sizes would be need to be recalculated and updated. */
|
||||
#define ENOUGH_LENS 852
|
||||
#define ENOUGH_DISTS 594
|
||||
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
|
||||
|
||||
/* Type of code to build for inftable() */
|
||||
/* Type of code to build for inflate_table9() */
|
||||
typedef enum {
|
||||
CODES,
|
||||
LENS,
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
Change in 1.01e (12 feb 05)
|
||||
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
|
||||
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
|
||||
|
||||
Change in 1.01b (20 may 04)
|
||||
- Integrate patch from Debian package (submited by Mark Brown)
|
||||
- Add tools mztools from Xavier Roche
|
||||
|
||||
Change in 1.01 (8 may 04)
|
||||
- fix buffer overrun risk in unzip.c (Xavier Roche)
|
||||
- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
|
||||
|
||||
Change in 1.00: (10 sept 03)
|
||||
- rename to 1.00
|
||||
- cosmetic code change
|
||||
|
||||
Change in 0.22: (19 May 03)
|
||||
- crypting support (unless you define NOCRYPT)
|
||||
- append file in existing zipfile
|
||||
|
||||
Change in 0.21: (10 Mar 03)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.17: (27 Jan 02)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.16: (19 Jan 02)
|
||||
- Support of ioapi for virtualize zip file access
|
||||
|
||||
Change in 0.15: (19 Mar 98)
|
||||
- fix memory leak in minizip.c
|
||||
|
||||
Change in 0.14: (10 Mar 98)
|
||||
- fix bugs in minizip.c sample for zipping big file
|
||||
- fix problem in month in date handling
|
||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
|
||||
comment handling
|
||||
|
||||
Change in 0.13: (6 Mar 98)
|
||||
- fix bugs in zip.c
|
||||
- add real minizip sample
|
||||
|
||||
Change in 0.12: (4 Mar 98)
|
||||
- add zip.c and zip.h for creates .zip file
|
||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
|
||||
- fix miniunz.c for file without specific record for directory
|
||||
|
||||
Change in 0.11: (3 Mar 98)
|
||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment
|
||||
- enhance miniunz sample, remove the bad unztst.c sample
|
||||
|
||||
Change in 0.10: (2 Mar 98)
|
||||
- fix bug in unzReadCurrentFile
|
||||
- rename unzip* to unz* function and structure
|
||||
- remove Windows-like hungary notation variable name
|
||||
- modify some structure in unzip.h
|
||||
- add somes comment in source
|
||||
- remove unzipGetcCurrentFile function
|
||||
- replace ZUNZEXPORT by ZEXPORT
|
||||
- add unzGetLocalExtrafield for get the local extrafield info
|
||||
- add a new sample, miniunz.c
|
||||
|
||||
Change in 0.4: (25 Feb 98)
|
||||
- suppress the type unzipFileInZip.
|
||||
Only on file in the zipfile can be open at the same time
|
||||
- fix somes typo in code
|
||||
- added tm_unz structure in unzip_file_info (date/time in readable format)
|
||||
@@ -1,25 +1,25 @@
|
||||
CC=cc
|
||||
CFLAGS=-O -I../..
|
||||
|
||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
all: miniunz minizip
|
||||
|
||||
miniunz: $(UNZ_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||
|
||||
minizip: $(ZIP_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||
|
||||
test: miniunz minizip
|
||||
./minizip test readme.txt
|
||||
./miniunz -l test.zip
|
||||
mv readme.txt readme.old
|
||||
./miniunz test.zip
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o *~ minizip miniunz
|
||||
CC=cc
|
||||
CFLAGS=-O -I../..
|
||||
|
||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
all: miniunz minizip
|
||||
|
||||
miniunz: $(UNZ_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||
|
||||
minizip: $(ZIP_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||
|
||||
test: miniunz minizip
|
||||
./minizip test readme.txt
|
||||
./miniunz -l test.zip
|
||||
mv readme.txt readme.old
|
||||
./miniunz test.zip
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o *~ minizip miniunz
|
||||
|
||||
7
contrib/minizip/MiniZip64_Changes.txt
Normal file
7
contrib/minizip/MiniZip64_Changes.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
MiniZip64 was derrived from MiniZip at version 1.01f
|
||||
|
||||
Change in 1.0 (Okt 2009)
|
||||
- **TODO - Add history**
|
||||
|
||||
|
||||
79
contrib/minizip/MiniZip64_info.txt
Normal file
79
contrib/minizip/MiniZip64_info.txt
Normal file
@@ -0,0 +1,79 @@
|
||||
MiniZip64 - Copyright (c) 2009-2010 - Mathias Svensson - Built from MiniZip by Gilles Vollant
|
||||
|
||||
Introduction
|
||||
---------------------
|
||||
MiniZip64 is built from MiniZip by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
When adding ZIP64 support into minizip it would result into breaking compatibility with current minizip.
|
||||
And since breaking compatibility in minizip is not wanted. I decided to create a fork of minizip
|
||||
and create minizip64.
|
||||
|
||||
Even though MiniZip64 is build from MiniZip, all functions and struct's have changed name so that it
|
||||
would not collide with each other.
|
||||
|
||||
|
||||
Background
|
||||
---------------------
|
||||
When adding ZIP64 support I found that Even Rouault have added ZIP64 support for unzip.c into minizip
|
||||
for a open source project called gdal ( http://www.gdal.org/ )
|
||||
|
||||
That was used as a starting point. And after that ZIP64 support was added to zip.c
|
||||
some refactoring and code cleanup was also done.
|
||||
|
||||
|
||||
Changed from MiniZip to MiniZip64
|
||||
-------------------------------------
|
||||
* Filenames has got a '64' at the end of them . eg unzip.c is now called unzip64.c
|
||||
* Added ZIP64 support for unzip ( by Even Rouault )
|
||||
* Added ZIP64 support for zip ( by Mathias Svensson )
|
||||
* Reverted some changed that Even Rouault did.
|
||||
* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users.
|
||||
* Added unzip patch for BZIP Compression method (patch create by Daniel Borca)
|
||||
* Added BZIP Compress method for zip
|
||||
* Did some refactoring and code cleanup
|
||||
|
||||
|
||||
Credits
|
||||
|
||||
Gilles Vollant - Original MiniZip author
|
||||
Even Rouault - ZIP64 unzip Support
|
||||
Daniel Borca - BZip Compression method support in unzip
|
||||
Mathias Svensson - ZIP64 zip support
|
||||
Mathias Svensson - BZip Compression method support in zip
|
||||
|
||||
Resources
|
||||
|
||||
ZipLayout http://result42.com/projects/ZipFileLayout
|
||||
Command line tool for Windows that shows the layout and information of the headers in a zip archive.
|
||||
Used when debugging and validating the creation of zip files using MiniZip64
|
||||
|
||||
|
||||
ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
||||
Zip File specification
|
||||
|
||||
|
||||
Notes.
|
||||
* To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined.
|
||||
|
||||
License
|
||||
----------------------------------------------------------
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
----------------------------------------------------------
|
||||
|
||||
@@ -87,13 +87,12 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
static int crypthead(const char* passwd, /* password string */
|
||||
unsigned char* buf, /* where to write header */
|
||||
int bufSize,
|
||||
unsigned long* pkeys,
|
||||
const unsigned long* pcrc_32_tab,
|
||||
unsigned long crcForCrypting)
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
@@ -124,8 +123,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +1,86 @@
|
||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if (defined(_WIN32))
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
|
||||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
|
||||
else
|
||||
{
|
||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
|
||||
}
|
||||
}
|
||||
|
||||
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
||||
else
|
||||
{
|
||||
uLong offsetTruncated = (uLong)offset;
|
||||
if (offsetTruncated != offset)
|
||||
return -1;
|
||||
else
|
||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
||||
}
|
||||
}
|
||||
|
||||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
||||
else
|
||||
{
|
||||
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
||||
if ((tell_uLong) == ((uLong)-1))
|
||||
return (ZPOS64_T)-1;
|
||||
else
|
||||
return tell_uLong;
|
||||
}
|
||||
}
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
|
||||
{
|
||||
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
||||
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
||||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
||||
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
||||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
||||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
||||
}
|
||||
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
|
||||
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
|
||||
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
|
||||
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
|
||||
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK fread_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK ftell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK fseek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK fclose_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK ferror_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
@@ -86,44 +98,55 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||
return file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||
file = fopen64((const char*)filename, mode_fopen);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
long ret;
|
||||
ret = ftell((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
|
||||
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
ZPOS64_T ret;
|
||||
ret = ftello64((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
|
||||
{
|
||||
int fseek_origin=0;
|
||||
long ret;
|
||||
@@ -141,22 +164,45 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||
default: return -1;
|
||||
}
|
||||
ret = 0;
|
||||
fseek((FILE *)stream, offset, fseek_origin);
|
||||
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
int fseek_origin=0;
|
||||
long ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
if(fseeko64((FILE *)stream, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
int ret;
|
||||
ret = fclose((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
int ret;
|
||||
ret = ferror((FILE *)stream);
|
||||
@@ -175,3 +221,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,98 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
Changes
|
||||
|
||||
Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
|
||||
Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
|
||||
More if/def section may be needed to support other platforms
|
||||
Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
|
||||
(but you should use iowin32.c for windows instead)
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
#ifndef _ZLIBIOAPI64_H
|
||||
#define _ZLIBIOAPI64_H
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
// Linux needs this to support file operation on files larger then 4+GB
|
||||
// But might need better if/def to select just the platforms that needs them.
|
||||
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#define __USE_FILE_OFFSET64
|
||||
#endif
|
||||
#ifndef __USE_LARGEFILE64
|
||||
#define __USE_LARGEFILE64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
#ifndef _FILE_OFFSET_BIT
|
||||
#define _FILE_OFFSET_BIT 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define fopen64 fopen
|
||||
#if _MSC_VER >= 1400
|
||||
#define ftello64 _ftelli64
|
||||
#define fseeko64 _fseeki64
|
||||
#else // old MSC
|
||||
#define ftello64 ftell
|
||||
#define fseeko64 fseek
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef ZPOS64_T
|
||||
#ifdef _WIN32
|
||||
#define ZPOS64_T fpos_t
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#define ZPOS64_T uint64_t
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef HAVE_MINIZIP64_CONF_H
|
||||
#include "mz64conf.h"
|
||||
#endif
|
||||
|
||||
/* a type choosen by DEFINE */
|
||||
#ifdef HAVE_64BIT_INT_CUSTOM
|
||||
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
|
||||
#else
|
||||
#ifdef HAS_STDINT_H
|
||||
#include "stdint.h"
|
||||
typedef uint64_t ZPOS64_T;
|
||||
#else
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ZPOS64_T;
|
||||
#else
|
||||
typedef unsigned long long int ZPOS64_T;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
@@ -23,26 +108,27 @@
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
|
||||
|
||||
/* here is the "old" 32 bits structure structure */
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
@@ -55,21 +141,54 @@ typedef struct zlib_filefunc_def_s
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
|
||||
|
||||
typedef struct zlib_filefunc64_def_s
|
||||
{
|
||||
open64_file_func zopen64_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell64_file_func ztell64_file;
|
||||
seek64_file_func zseek64_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc64_def;
|
||||
|
||||
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
/* now internal definition, only for zip.c and unzip.h */
|
||||
typedef struct zlib_filefunc64_32_def_s
|
||||
{
|
||||
zlib_filefunc64_def zfile_func64;
|
||||
open_file_func zopen32_file;
|
||||
tell_file_func ztell32_file;
|
||||
seek_file_func zseek32_file;
|
||||
} zlib_filefunc64_32_def;
|
||||
|
||||
|
||||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
|
||||
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
|
||||
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
|
||||
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
|
||||
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
|
||||
|
||||
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
|
||||
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
|
||||
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
Version 1.1, January 7th, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -21,40 +25,13 @@
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK win32_tell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK win32_seek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK win32_close_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK win32_error_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
|
||||
uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
|
||||
long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
|
||||
int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -62,69 +39,121 @@ typedef struct
|
||||
int error;
|
||||
} WIN32FILE_IOWIN;
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = 0;
|
||||
voidpf ret=NULL;
|
||||
|
||||
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
|
||||
static void win32_translate_open_mode(int mode,
|
||||
DWORD* lpdwDesiredAccess,
|
||||
DWORD* lpdwCreationDisposition,
|
||||
DWORD* lpdwShareMode,
|
||||
DWORD* lpdwFlagsAndAttributes)
|
||||
{
|
||||
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
|
||||
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
dwShareMode = FILE_SHARE_READ;
|
||||
*lpdwDesiredAccess = GENERIC_READ;
|
||||
*lpdwCreationDisposition = OPEN_EXISTING;
|
||||
*lpdwShareMode = FILE_SHARE_READ;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
*lpdwCreationDisposition = OPEN_EXISTING;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = CREATE_ALWAYS;
|
||||
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
*lpdwCreationDisposition = CREATE_ALWAYS;
|
||||
}
|
||||
}
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
static voidpf win32_build_iowin(HANDLE hFile)
|
||||
{
|
||||
voidpf ret=NULL;
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
hFile = NULL;
|
||||
|
||||
if (hFile != NULL)
|
||||
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
|
||||
{
|
||||
WIN32FILE_IOWIN w32fiow;
|
||||
w32fiow.hf = hFile;
|
||||
w32fiow.error = 0;
|
||||
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
||||
|
||||
if (ret==NULL)
|
||||
CloseHandle(hFile);
|
||||
else *((WIN32FILE_IOWIN*)ret) = w32fiow;
|
||||
else
|
||||
*((WIN32FILE_IOWIN*)ret) = w32fiow;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
return win32_build_iowin(hFile);
|
||||
}
|
||||
|
||||
|
||||
voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
return win32_build_iowin(hFile);
|
||||
}
|
||||
|
||||
|
||||
voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
return win32_build_iowin(hFile);
|
||||
}
|
||||
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
return win32_build_iowin(hFile);
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
|
||||
if (hFile != NULL)
|
||||
{
|
||||
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
@@ -132,23 +161,21 @@ uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
|
||||
if (hFile !=NULL)
|
||||
if (hFile != NULL)
|
||||
{
|
||||
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
@@ -156,13 +183,12 @@ uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_tell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
|
||||
{
|
||||
long ret=-1;
|
||||
HANDLE hFile = NULL;
|
||||
@@ -183,11 +209,32 @@ long ZCALLBACK win32_tell_file_func (opaque, stream)
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
ZPOS64_T ret= (ZPOS64_T)-1;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
||||
|
||||
if (hFile)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = 0;
|
||||
li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT);
|
||||
if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = (ZPOS64_T)-1;
|
||||
}
|
||||
else
|
||||
ret=li.QuadPart;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
|
||||
{
|
||||
DWORD dwMoveMethod=0xFFFFFFFF;
|
||||
HANDLE hFile = NULL;
|
||||
@@ -224,9 +271,46 @@ long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_close_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
|
||||
{
|
||||
DWORD dwMoveMethod=0xFFFFFFFF;
|
||||
HANDLE hFile = NULL;
|
||||
long ret=-1;
|
||||
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
dwMoveMethod = FILE_CURRENT;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
dwMoveMethod = FILE_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
dwMoveMethod = FILE_BEGIN;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
|
||||
if (hFile)
|
||||
{
|
||||
LARGE_INTEGER* li = (LARGE_INTEGER*)&offset;
|
||||
DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod);
|
||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
int ret=-1;
|
||||
|
||||
@@ -244,9 +328,7 @@ int ZCALLBACK win32_close_file_func (opaque, stream)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_error_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
|
||||
{
|
||||
int ret=-1;
|
||||
if (stream!=NULL)
|
||||
@@ -256,8 +338,7 @@ int ZCALLBACK win32_error_file_func (opaque, stream)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_win32_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
@@ -266,5 +347,43 @@ void fill_win32_filefunc (pzlib_filefunc_def)
|
||||
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque=NULL;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
|
||||
void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
Version 1.1, January 7th, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
@@ -15,6 +19,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
/*
|
||||
miniunz.c
|
||||
Version 1.01e, February 12th, 2005
|
||||
Version 1.1, January 7th, 2010
|
||||
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
|
||||
Modifications for Zip64 support on both zip and unzip
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#define __USE_FILE_OFFSET64
|
||||
#endif
|
||||
#ifndef __USE_LARGEFILE64
|
||||
#define __USE_LARGEFILE64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
#ifndef _FILE_OFFSET_BIT
|
||||
#define _FILE_OFFSET_BIT 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -27,7 +48,7 @@
|
||||
#define WRITEBUFFERSIZE (8192)
|
||||
#define MAXFILENAME (256)
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#define USEWIN32IOAPI
|
||||
#include "iowin32.h"
|
||||
#endif
|
||||
@@ -51,11 +72,11 @@ void change_file_date(filename,dosdate,tmu_date)
|
||||
uLong dosdate;
|
||||
tm_unz tmu_date;
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
HANDLE hFile;
|
||||
FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
|
||||
|
||||
hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE,
|
||||
hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
|
||||
0,NULL,OPEN_EXISTING,0,NULL);
|
||||
GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
|
||||
DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
|
||||
@@ -91,8 +112,8 @@ int mymkdir(dirname)
|
||||
const char* dirname;
|
||||
{
|
||||
int ret=0;
|
||||
#ifdef WIN32
|
||||
ret = mkdir(dirname);
|
||||
#ifdef _WIN32
|
||||
ret = _mkdir(dirname);
|
||||
#else
|
||||
#ifdef unix
|
||||
ret = mkdir (dirname,0775);
|
||||
@@ -112,6 +133,11 @@ int makedir (newdir)
|
||||
return 0;
|
||||
|
||||
buffer = (char*)malloc(len+1);
|
||||
if (buffer==NULL)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
return UNZ_INTERNALERROR;
|
||||
}
|
||||
strcpy(buffer,newdir);
|
||||
|
||||
if (buffer[len-1] == '/') {
|
||||
@@ -164,34 +190,61 @@ void do_help()
|
||||
" -p extract crypted file using password\n\n");
|
||||
}
|
||||
|
||||
void Display64BitsSize(ZPOS64_T n, int size_char)
|
||||
{
|
||||
/* to avoid compatibility problem , we do here the conversion */
|
||||
char number[21];
|
||||
int offset=19;
|
||||
int pos_string = 19;
|
||||
number[20]=0;
|
||||
for (;;) {
|
||||
number[offset]=(char)((n%10)+'0');
|
||||
if (number[offset] != '0')
|
||||
pos_string=offset;
|
||||
n/=10;
|
||||
if (offset==0)
|
||||
break;
|
||||
offset--;
|
||||
}
|
||||
{
|
||||
int size_display_string = 19-pos_string;
|
||||
while (size_char > size_display_string)
|
||||
{
|
||||
size_char--;
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s",&number[pos_string]);
|
||||
}
|
||||
|
||||
int do_list(uf)
|
||||
unzFile uf;
|
||||
{
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
unz_global_info64 gi;
|
||||
int err;
|
||||
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
err = unzGetGlobalInfo64(uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
|
||||
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
|
||||
for (i=0;i<gi.number_entry;i++)
|
||||
{
|
||||
char filename_inzip[256];
|
||||
unz_file_info file_info;
|
||||
unz_file_info64 file_info;
|
||||
uLong ratio=0;
|
||||
const char *string_method;
|
||||
char charCrypt=' ';
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
break;
|
||||
}
|
||||
if (file_info.uncompressed_size>0)
|
||||
ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
|
||||
ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
|
||||
|
||||
/* display a '*' if the file is crypted */
|
||||
if ((file_info.flag & 1) != 0)
|
||||
@@ -210,13 +263,18 @@ int do_list(uf)
|
||||
else if ((iLevel==2) || (iLevel==3))
|
||||
string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
|
||||
}
|
||||
else
|
||||
if (file_info.compression_method==Z_BZIP2ED)
|
||||
{
|
||||
string_method="BZip2 ";
|
||||
}
|
||||
else
|
||||
string_method="Unkn. ";
|
||||
|
||||
printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
|
||||
file_info.uncompressed_size,string_method,
|
||||
charCrypt,
|
||||
file_info.compressed_size,
|
||||
Display64BitsSize(file_info.uncompressed_size,7);
|
||||
printf(" %6s%c",string_method,charCrypt);
|
||||
Display64BitsSize(file_info.compressed_size,7);
|
||||
printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
|
||||
ratio,
|
||||
(uLong)file_info.tmu_date.tm_mon + 1,
|
||||
(uLong)file_info.tmu_date.tm_mday,
|
||||
@@ -252,9 +310,9 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
|
||||
void* buf;
|
||||
uInt size_buf;
|
||||
|
||||
unz_file_info file_info;
|
||||
unz_file_info64 file_info;
|
||||
uLong ratio=0;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
@@ -306,7 +364,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
|
||||
{
|
||||
char rep=0;
|
||||
FILE* ftestexist;
|
||||
ftestexist = fopen(write_filename,"rb");
|
||||
ftestexist = fopen64(write_filename,"rb");
|
||||
if (ftestexist!=NULL)
|
||||
{
|
||||
fclose(ftestexist);
|
||||
@@ -337,7 +395,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
|
||||
|
||||
if ((skip==0) && (err==UNZ_OK))
|
||||
{
|
||||
fout=fopen(write_filename,"wb");
|
||||
fout=fopen64(write_filename,"wb");
|
||||
|
||||
/* some zipfile don't contain directory alone before file */
|
||||
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||
@@ -347,7 +405,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
|
||||
*(filename_withoutpath-1)='\0';
|
||||
makedir(write_filename);
|
||||
*(filename_withoutpath-1)=c;
|
||||
fout=fopen(write_filename,"wb");
|
||||
fout=fopen64(write_filename,"wb");
|
||||
}
|
||||
|
||||
if (fout==NULL)
|
||||
@@ -409,11 +467,11 @@ int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
|
||||
const char* password;
|
||||
{
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
unz_global_info64 gi;
|
||||
int err;
|
||||
FILE* fout=NULL;
|
||||
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
err = unzGetGlobalInfo64(uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
|
||||
@@ -470,6 +528,7 @@ int main(argc,argv)
|
||||
const char *password=NULL;
|
||||
char filename_try[MAXFILENAME+16] = "";
|
||||
int i;
|
||||
int ret_value=0;
|
||||
int opt_do_list=0;
|
||||
int opt_do_extract=1;
|
||||
int opt_do_extract_withoutpath=0;
|
||||
@@ -532,7 +591,7 @@ int main(argc,argv)
|
||||
{
|
||||
|
||||
# ifdef USEWIN32IOAPI
|
||||
zlib_filefunc_def ffunc;
|
||||
zlib_filefunc64_def ffunc;
|
||||
# endif
|
||||
|
||||
strncpy(filename_try, zipfilename,MAXFILENAME-1);
|
||||
@@ -540,18 +599,18 @@ int main(argc,argv)
|
||||
filename_try[ MAXFILENAME ] = '\0';
|
||||
|
||||
# ifdef USEWIN32IOAPI
|
||||
fill_win32_filefunc(&ffunc);
|
||||
uf = unzOpen2(zipfilename,&ffunc);
|
||||
fill_win32_filefunc64A(&ffunc);
|
||||
uf = unzOpen2_64(zipfilename,&ffunc);
|
||||
# else
|
||||
uf = unzOpen(zipfilename);
|
||||
uf = unzOpen64(zipfilename);
|
||||
# endif
|
||||
if (uf==NULL)
|
||||
{
|
||||
strcat(filename_try,".zip");
|
||||
# ifdef USEWIN32IOAPI
|
||||
uf = unzOpen2(filename_try,&ffunc);
|
||||
uf = unzOpen2_64(filename_try,&ffunc);
|
||||
# else
|
||||
uf = unzOpen(filename_try);
|
||||
uf = unzOpen64(filename_try);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
@@ -564,22 +623,26 @@ int main(argc,argv)
|
||||
printf("%s opened\n",filename_try);
|
||||
|
||||
if (opt_do_list==1)
|
||||
return do_list(uf);
|
||||
ret_value = do_list(uf);
|
||||
else if (opt_do_extract==1)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (opt_extractdir && _chdir(dirname))
|
||||
#else
|
||||
if (opt_extractdir && chdir(dirname))
|
||||
#endif
|
||||
{
|
||||
printf("Error changing into %s, aborting\n", dirname);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (filename_to_extract == NULL)
|
||||
return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
|
||||
ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
|
||||
else
|
||||
return do_extract_onefile(uf,filename_to_extract,
|
||||
opt_do_extract_withoutpath,opt_overwrite,password);
|
||||
ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
|
||||
}
|
||||
unzCloseCurrentFile(uf);
|
||||
|
||||
return 0;
|
||||
unzClose(uf);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
/*
|
||||
minizip.c
|
||||
Version 1.01e, February 12th, 2005
|
||||
Version 1.1, January 7th, 2010
|
||||
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
|
||||
Modifications for Zip64 support on both zip and unzip
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#define __USE_FILE_OFFSET64
|
||||
#endif
|
||||
#ifndef __USE_LARGEFILE64
|
||||
#define __USE_LARGEFILE64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
#ifndef _FILE_OFFSET_BIT
|
||||
#define _FILE_OFFSET_BIT 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -24,9 +47,9 @@
|
||||
|
||||
#include "zip.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define USEWIN32IOAPI
|
||||
#include "iowin32.h"
|
||||
#ifdef _WIN32
|
||||
#define USEWIN32IOAPI
|
||||
#include "iowin32.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,7 +57,7 @@
|
||||
#define WRITEBUFFERSIZE (16384)
|
||||
#define MAXFILENAME (256)
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
@@ -44,9 +67,9 @@ uLong filetime(f, tmzip, dt)
|
||||
{
|
||||
FILETIME ftLocal;
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATA ff32;
|
||||
WIN32_FIND_DATAA ff32;
|
||||
|
||||
hFind = FindFirstFile(f,&ff32);
|
||||
hFind = FindFirstFileA(f,&ff32);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
||||
@@ -119,7 +142,7 @@ int check_exist_file(filename)
|
||||
{
|
||||
FILE* ftestexist;
|
||||
int ret = 1;
|
||||
ftestexist = fopen(filename,"rb");
|
||||
ftestexist = fopen64(filename,"rb");
|
||||
if (ftestexist==NULL)
|
||||
ret = 0;
|
||||
else
|
||||
@@ -129,18 +152,20 @@ int check_exist_file(filename)
|
||||
|
||||
void do_banner()
|
||||
{
|
||||
printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n");
|
||||
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
|
||||
printf("MiniZip64 1.0, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
|
||||
printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
|
||||
printf("more info on MiniZip64 at http://result42.com/projects/MiniZip64\n\n");
|
||||
}
|
||||
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
|
||||
" -o Overwrite existing file.zip\n" \
|
||||
" -a Append to existing file.zip\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n\n");
|
||||
" -9 Compress better\n\n" \
|
||||
" -j exclude path. store only the file name.\n\n");
|
||||
}
|
||||
|
||||
/* calculate the CRC32 of a file,
|
||||
@@ -149,7 +174,7 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne
|
||||
{
|
||||
unsigned long calculate_crc=0;
|
||||
int err=ZIP_OK;
|
||||
FILE * fin = fopen(filenameinzip,"rb");
|
||||
FILE * fin = fopen64(filenameinzip,"rb");
|
||||
unsigned long size_read = 0;
|
||||
unsigned long total_read = 0;
|
||||
if (fin==NULL)
|
||||
@@ -179,10 +204,33 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne
|
||||
fclose(fin);
|
||||
|
||||
*result_crc=calculate_crc;
|
||||
printf("file %s crc %x\n",filenameinzip,calculate_crc);
|
||||
printf("file %s crc %lx\n", filenameinzip, calculate_crc);
|
||||
return err;
|
||||
}
|
||||
|
||||
int isLargeFile(const char* filename)
|
||||
{
|
||||
int largeFile = 0;
|
||||
ZPOS64_T pos = 0;
|
||||
FILE* pFile = fopen64(filename, "rb");
|
||||
|
||||
if(pFile != NULL)
|
||||
{
|
||||
int n = fseeko64(pFile, 0, SEEK_END);
|
||||
|
||||
pos = ftello64(pFile);
|
||||
|
||||
printf("File : %s is %lld bytes\n", filename, pos);
|
||||
|
||||
if(pos >= 0xffffffff)
|
||||
largeFile = 1;
|
||||
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
return largeFile;
|
||||
}
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
@@ -190,6 +238,7 @@ int main(argc,argv)
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||
int opt_exclude_path=0;
|
||||
int zipfilenamearg = 0;
|
||||
char filename_try[MAXFILENAME+16];
|
||||
int zipok;
|
||||
@@ -222,6 +271,8 @@ int main(argc,argv)
|
||||
opt_overwrite = 2;
|
||||
if ((c>='0') && (c<='9'))
|
||||
opt_compress_level = c-'0';
|
||||
if ((c=='j') || (c=='J'))
|
||||
opt_exclude_path = 1;
|
||||
|
||||
if (((c=='p') || (c=='P')) && (i+1<argc))
|
||||
{
|
||||
@@ -231,8 +282,12 @@ int main(argc,argv)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (zipfilenamearg == 0)
|
||||
{
|
||||
zipfilenamearg = i ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +300,9 @@ int main(argc,argv)
|
||||
}
|
||||
|
||||
if (zipfilenamearg==0)
|
||||
{
|
||||
zipok=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i,len;
|
||||
@@ -302,11 +359,11 @@ int main(argc,argv)
|
||||
zipFile zf;
|
||||
int errclose;
|
||||
# ifdef USEWIN32IOAPI
|
||||
zlib_filefunc_def ffunc;
|
||||
fill_win32_filefunc(&ffunc);
|
||||
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
||||
zlib_filefunc64_def ffunc;
|
||||
fill_win32_filefunc64A(&ffunc);
|
||||
zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
||||
# else
|
||||
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
|
||||
zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
|
||||
# endif
|
||||
|
||||
if (zf == NULL)
|
||||
@@ -329,8 +386,10 @@ int main(argc,argv)
|
||||
FILE * fin;
|
||||
int size_read;
|
||||
const char* filenameinzip = argv[i];
|
||||
const char *savefilenameinzip;
|
||||
zip_fileinfo zi;
|
||||
unsigned long crcFile=0;
|
||||
int zip64 = 0;
|
||||
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||
@@ -347,20 +406,49 @@ int main(argc,argv)
|
||||
*/
|
||||
if ((password != NULL) && (err==ZIP_OK))
|
||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||
|
||||
zip64 = isLargeFile(filenameinzip);
|
||||
|
||||
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
|
||||
/* The path name saved, should not include a leading slash. */
|
||||
/*if it did, windows/xp and dynazip couldn't read the zip file. */
|
||||
savefilenameinzip = filenameinzip;
|
||||
while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
|
||||
{
|
||||
savefilenameinzip++;
|
||||
}
|
||||
|
||||
/*should the zip file contain any path at all?*/
|
||||
if( opt_exclude_path )
|
||||
{
|
||||
const char *tmpptr;
|
||||
const char *lastslash = 0;
|
||||
for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
|
||||
{
|
||||
if( *tmpptr == '\\' || *tmpptr == '/')
|
||||
{
|
||||
lastslash = tmpptr;
|
||||
}
|
||||
}
|
||||
if( lastslash != NULL )
|
||||
{
|
||||
savefilenameinzip = lastslash+1; // base filename follows last slash.
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL /* comment*/,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level,0,
|
||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
password,crcFile);
|
||||
password,crcFile, zip64);
|
||||
|
||||
if (err != ZIP_OK)
|
||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||
else
|
||||
{
|
||||
fin = fopen(filenameinzip,"rb");
|
||||
fin = fopen64(filenameinzip,"rb");
|
||||
if (fin==NULL)
|
||||
{
|
||||
err=ZIP_ERRNO;
|
||||
|
||||
@@ -1,281 +1,281 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
/* Code */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zlib.h"
|
||||
#include "unzip.h"
|
||||
|
||||
#define READ_8(adr) ((unsigned char)*(adr))
|
||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||
|
||||
#define WRITE_8(buff, n) do { \
|
||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||
} while(0)
|
||||
#define WRITE_16(buff, n) do { \
|
||||
WRITE_8((unsigned char*)(buff), n); \
|
||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||
} while(0)
|
||||
#define WRITE_32(buff, n) do { \
|
||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||
} while(0)
|
||||
|
||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||
const char* file;
|
||||
const char* fileOut;
|
||||
const char* fileOutTmp;
|
||||
uLong* nRecovered;
|
||||
uLong* bytesRecovered;
|
||||
{
|
||||
int err = Z_OK;
|
||||
FILE* fpZip = fopen(file, "rb");
|
||||
FILE* fpOut = fopen(fileOut, "wb");
|
||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||
if (fpZip != NULL && fpOut != NULL) {
|
||||
int entries = 0;
|
||||
uLong totalBytes = 0;
|
||||
char header[30];
|
||||
char filename[256];
|
||||
char extra[1024];
|
||||
int offset = 0;
|
||||
int offsetCD = 0;
|
||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||
int currentOffset = offset;
|
||||
|
||||
/* File entry */
|
||||
if (READ_32(header) == 0x04034b50) {
|
||||
unsigned int version = READ_16(header + 4);
|
||||
unsigned int gpflag = READ_16(header + 6);
|
||||
unsigned int method = READ_16(header + 8);
|
||||
unsigned int filetime = READ_16(header + 10);
|
||||
unsigned int filedate = READ_16(header + 12);
|
||||
unsigned int crc = READ_32(header + 14); /* crc */
|
||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||
filename[0] = extra[0] = '\0';
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||
offset += 30;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||
offset += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||
offset += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Data */
|
||||
{
|
||||
int dataSize = cpsize;
|
||||
if (dataSize == 0) {
|
||||
dataSize = uncpsize;
|
||||
}
|
||||
if (dataSize > 0) {
|
||||
char* data = malloc(dataSize);
|
||||
if (data != NULL) {
|
||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||
offset += dataSize;
|
||||
totalBytes += dataSize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
free(data);
|
||||
if (err != Z_OK) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_MEM_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Central directory entry */
|
||||
{
|
||||
char header[46];
|
||||
char* comment = "";
|
||||
int comsize = (int) strlen(comment);
|
||||
WRITE_32(header, 0x02014b50);
|
||||
WRITE_16(header + 4, version);
|
||||
WRITE_16(header + 6, version);
|
||||
WRITE_16(header + 8, gpflag);
|
||||
WRITE_16(header + 10, method);
|
||||
WRITE_16(header + 12, filetime);
|
||||
WRITE_16(header + 14, filedate);
|
||||
WRITE_32(header + 16, crc);
|
||||
WRITE_32(header + 20, cpsize);
|
||||
WRITE_32(header + 24, uncpsize);
|
||||
WRITE_16(header + 28, fnsize);
|
||||
WRITE_16(header + 30, extsize);
|
||||
WRITE_16(header + 32, comsize);
|
||||
WRITE_16(header + 34, 0); /* disk # */
|
||||
WRITE_16(header + 36, 0); /* int attrb */
|
||||
WRITE_32(header + 38, 0); /* ext attrb */
|
||||
WRITE_32(header + 42, currentOffset);
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||
offsetCD += 46;
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||
offsetCD += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||
offsetCD += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||
offsetCD += comsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success */
|
||||
entries++;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final central directory */
|
||||
{
|
||||
int entriesZip = entries;
|
||||
char header[22];
|
||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||
int comsize = (int) strlen(comment);
|
||||
if (entriesZip > 0xffff) {
|
||||
entriesZip = 0xffff;
|
||||
}
|
||||
WRITE_32(header, 0x06054b50);
|
||||
WRITE_16(header + 4, 0); /* disk # */
|
||||
WRITE_16(header + 6, 0); /* disk # */
|
||||
WRITE_16(header + 8, entriesZip); /* hack */
|
||||
WRITE_16(header + 10, entriesZip); /* hack */
|
||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||
WRITE_32(header + 16, offset); /* offset to CD */
|
||||
WRITE_16(header + 20, comsize); /* comment */
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final merge (file + central directory) */
|
||||
fclose(fpOutCD);
|
||||
if (err == Z_OK) {
|
||||
fpOutCD = fopen(fileOutTmp, "rb");
|
||||
if (fpOutCD != NULL) {
|
||||
int nRead;
|
||||
char buffer[8192];
|
||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fpOutCD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close */
|
||||
fclose(fpZip);
|
||||
fclose(fpOut);
|
||||
|
||||
/* Wipe temporary file */
|
||||
(void)remove(fileOutTmp);
|
||||
|
||||
/* Number of recovered entries */
|
||||
if (err == Z_OK) {
|
||||
if (nRecovered != NULL) {
|
||||
*nRecovered = entries;
|
||||
}
|
||||
if (bytesRecovered != NULL) {
|
||||
*bytesRecovered = totalBytes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
/* Code */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zlib.h"
|
||||
#include "unzip.h"
|
||||
|
||||
#define READ_8(adr) ((unsigned char)*(adr))
|
||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||
|
||||
#define WRITE_8(buff, n) do { \
|
||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||
} while(0)
|
||||
#define WRITE_16(buff, n) do { \
|
||||
WRITE_8((unsigned char*)(buff), n); \
|
||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||
} while(0)
|
||||
#define WRITE_32(buff, n) do { \
|
||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||
} while(0)
|
||||
|
||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||
const char* file;
|
||||
const char* fileOut;
|
||||
const char* fileOutTmp;
|
||||
uLong* nRecovered;
|
||||
uLong* bytesRecovered;
|
||||
{
|
||||
int err = Z_OK;
|
||||
FILE* fpZip = fopen(file, "rb");
|
||||
FILE* fpOut = fopen(fileOut, "wb");
|
||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||
if (fpZip != NULL && fpOut != NULL) {
|
||||
int entries = 0;
|
||||
uLong totalBytes = 0;
|
||||
char header[30];
|
||||
char filename[256];
|
||||
char extra[1024];
|
||||
int offset = 0;
|
||||
int offsetCD = 0;
|
||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||
int currentOffset = offset;
|
||||
|
||||
/* File entry */
|
||||
if (READ_32(header) == 0x04034b50) {
|
||||
unsigned int version = READ_16(header + 4);
|
||||
unsigned int gpflag = READ_16(header + 6);
|
||||
unsigned int method = READ_16(header + 8);
|
||||
unsigned int filetime = READ_16(header + 10);
|
||||
unsigned int filedate = READ_16(header + 12);
|
||||
unsigned int crc = READ_32(header + 14); /* crc */
|
||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||
filename[0] = extra[0] = '\0';
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||
offset += 30;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||
offset += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||
offset += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Data */
|
||||
{
|
||||
int dataSize = cpsize;
|
||||
if (dataSize == 0) {
|
||||
dataSize = uncpsize;
|
||||
}
|
||||
if (dataSize > 0) {
|
||||
char* data = malloc(dataSize);
|
||||
if (data != NULL) {
|
||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||
offset += dataSize;
|
||||
totalBytes += dataSize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
free(data);
|
||||
if (err != Z_OK) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_MEM_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Central directory entry */
|
||||
{
|
||||
char header[46];
|
||||
char* comment = "";
|
||||
int comsize = (int) strlen(comment);
|
||||
WRITE_32(header, 0x02014b50);
|
||||
WRITE_16(header + 4, version);
|
||||
WRITE_16(header + 6, version);
|
||||
WRITE_16(header + 8, gpflag);
|
||||
WRITE_16(header + 10, method);
|
||||
WRITE_16(header + 12, filetime);
|
||||
WRITE_16(header + 14, filedate);
|
||||
WRITE_32(header + 16, crc);
|
||||
WRITE_32(header + 20, cpsize);
|
||||
WRITE_32(header + 24, uncpsize);
|
||||
WRITE_16(header + 28, fnsize);
|
||||
WRITE_16(header + 30, extsize);
|
||||
WRITE_16(header + 32, comsize);
|
||||
WRITE_16(header + 34, 0); /* disk # */
|
||||
WRITE_16(header + 36, 0); /* int attrb */
|
||||
WRITE_32(header + 38, 0); /* ext attrb */
|
||||
WRITE_32(header + 42, currentOffset);
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||
offsetCD += 46;
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||
offsetCD += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||
offsetCD += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||
offsetCD += comsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success */
|
||||
entries++;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final central directory */
|
||||
{
|
||||
int entriesZip = entries;
|
||||
char header[22];
|
||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||
int comsize = (int) strlen(comment);
|
||||
if (entriesZip > 0xffff) {
|
||||
entriesZip = 0xffff;
|
||||
}
|
||||
WRITE_32(header, 0x06054b50);
|
||||
WRITE_16(header + 4, 0); /* disk # */
|
||||
WRITE_16(header + 6, 0); /* disk # */
|
||||
WRITE_16(header + 8, entriesZip); /* hack */
|
||||
WRITE_16(header + 10, entriesZip); /* hack */
|
||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||
WRITE_32(header + 16, offset); /* offset to CD */
|
||||
WRITE_16(header + 20, comsize); /* comment */
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final merge (file + central directory) */
|
||||
fclose(fpOutCD);
|
||||
if (err == Z_OK) {
|
||||
fpOutCD = fopen(fileOutTmp, "rb");
|
||||
if (fpOutCD != NULL) {
|
||||
int nRead;
|
||||
char buffer[8192];
|
||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fpOutCD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close */
|
||||
fclose(fpZip);
|
||||
fclose(fpOut);
|
||||
|
||||
/* Wipe temporary file */
|
||||
(void)remove(fileOutTmp);
|
||||
|
||||
/* Number of recovered entries */
|
||||
if (err == Z_OK) {
|
||||
if (nRecovered != NULL) {
|
||||
*nRecovered = entries;
|
||||
}
|
||||
if (bytesRecovered != NULL) {
|
||||
*bytesRecovered = totalBytes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,20 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
Version 1.1, January 7th, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
Modifications for Zip64 support on both zip and unzip
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -32,18 +32,16 @@
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
Changes
|
||||
|
||||
See header of unzip64.c
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
#ifndef _unz64_H
|
||||
#define _unz64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -53,10 +51,16 @@ extern "C" {
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
#define Z_BZIP2ED 12
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
@@ -89,15 +93,42 @@ typedef struct tm_unz_s
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info64_s
|
||||
{
|
||||
ZPOS64_T number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info64;
|
||||
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info64_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
ZPOS64_T compressed_size; /* compressed size 8 bytes */
|
||||
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info64;
|
||||
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
@@ -133,6 +164,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
extern unzFile ZEXPORT unzOpen64 OF((const void *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
@@ -141,8 +173,14 @@ extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
the "64" function take a const void* pointer, because the path is just the
|
||||
value passed to the open64_file_func callback.
|
||||
Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
|
||||
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
|
||||
does not describe the reality
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
@@ -150,6 +188,13 @@ extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
|
||||
zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unz64Open, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
@@ -159,6 +204,9 @@ extern int ZEXPORT unzClose OF((unzFile file));
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
|
||||
unz_global_info64 *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
@@ -221,8 +269,31 @@ extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
typedef struct unz64_file_pos_s
|
||||
{
|
||||
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
|
||||
ZPOS64_T num_of_file; /* # of file */
|
||||
} unz64_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos64(
|
||||
unzFile file,
|
||||
unz64_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos64(
|
||||
unzFile file,
|
||||
const unz64_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
|
||||
unz_file_info64 *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
@@ -244,6 +315,14 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
|
||||
/** Addition for GDAL : START */
|
||||
|
||||
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
|
||||
|
||||
/** Addition for GDAL : END */
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
@@ -312,6 +391,8 @@ extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
|
||||
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
@@ -340,9 +421,11 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
@@ -351,4 +434,4 @@ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
||||
#endif /* _unz64_H */
|
||||
|
||||
332
contrib/minizip/zconf.h
Normal file
332
contrib/minizip/zconf.h
Normal file
@@ -0,0 +1,332 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define zError z_zError
|
||||
|
||||
# define alloc_func z_alloc_func
|
||||
# define free_func z_free_func
|
||||
# define in_func z_in_func
|
||||
# define out_func z_out_func
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(deflateBound,"DEBND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(compressBound,"CMBND")
|
||||
# pragma map(inflate_table,"INTABL")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -11,115 +11,52 @@
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
* Even better than compiling with -DZ_PREFIX would be to use configure to set
|
||||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
# define _tr_tally z__tr_tally
|
||||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define deflate z_deflate
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgets z_gzgets
|
||||
# define gzopen z_gzopen
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define inflateBackInit_ z_inflateBackInit_
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define zError z_zError
|
||||
# define z_errmsg z_z_errmsg
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
# define Byte z_Byte
|
||||
# define Bytef z_Bytef
|
||||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# define gzFile z_gzFile
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
# define intf z_intf
|
||||
# define out_func z_out_func
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uIntf z_uIntf
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidp z_voidp
|
||||
# define voidp z_voidp
|
||||
# define voidpc z_voidpc
|
||||
# define voidpc z_voidpc
|
||||
# define voidpf z_voidpf
|
||||
# define voidpf z_voidpf
|
||||
# define z_stream z_z_stream
|
||||
# define z_streamp z_z_streamp
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
# define gz_header_s z_gz_header_s
|
||||
# define internal_state z_internal_state
|
||||
# define z_stream_s z_z_stream_s
|
||||
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
@@ -306,10 +243,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VISIBILITY_PRAGMA
|
||||
# define ZEXTERN __attribute__((visibility ("default"))) extern
|
||||
#endif
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
@@ -374,6 +307,9 @@ typedef uLong FAR uLongf;
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,15 @@
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
/* zip.h -- IO on .zip files using zlib
|
||||
Version 1.1, January 7th, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
@@ -33,23 +29,23 @@
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Changes
|
||||
|
||||
See header of zip.h
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
#ifndef _zip12_H
|
||||
#define _zip12_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#define HAVE_BZIP2
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
@@ -58,6 +54,12 @@ extern "C" {
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
#define Z_BZIP2ED 12
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
@@ -112,6 +114,7 @@ typedef const char* zipcharpc;
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||
@@ -136,6 +139,11 @@ extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
@@ -146,6 +154,19 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int zip64));
|
||||
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
@@ -157,6 +178,9 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
|
||||
this MUST be '1' if the uncompressed size is >= 0xffffffff.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -172,6 +196,19 @@ extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int zip64));
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
@@ -191,13 +228,79 @@ extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCtypting));
|
||||
uLong crcForCrypting));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
int zip64
|
||||
));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCtypting : crc of file to compress (needed for crypting)
|
||||
crcForCrypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
uLong versionMadeBy,
|
||||
uLong flagBase
|
||||
));
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
uLong versionMadeBy,
|
||||
uLong flagBase,
|
||||
int zip64
|
||||
));
|
||||
/*
|
||||
Same than zipOpenNewFileInZip4, except
|
||||
versionMadeBy : value for Version made by field
|
||||
flag : value for flag field (compression level info will be added)
|
||||
*/
|
||||
|
||||
|
||||
@@ -216,8 +319,13 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
|
||||
ZPOS64_T uncompressed_size,
|
||||
uLong crc32));
|
||||
|
||||
/*
|
||||
Close the current file in the zipfile, for fiel opened with
|
||||
Close the current file in the zipfile, for file opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
@@ -228,8 +336,27 @@ extern int ZEXPORT zipClose OF((zipFile file,
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
|
||||
/*
|
||||
zipRemoveExtraInfoBlock - Added by Mathias Svensson
|
||||
|
||||
Remove extra information block from a extra information data for the local file header or central directory header
|
||||
|
||||
It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
|
||||
|
||||
0x0001 is the signature header for the ZIP64 extra information blocks
|
||||
|
||||
usage.
|
||||
Remove ZIP64 Extra information from a central director extra field data
|
||||
zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
|
||||
|
||||
Remove ZIP64 Extra information from a Local File Header extra field data
|
||||
zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
||||
#endif /* _zip64_H */
|
||||
|
||||
@@ -18,10 +18,10 @@ LDFLAGS =
|
||||
# variables
|
||||
ZLIB_LIB = zlib.lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
|
||||
OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
|
||||
OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
|
||||
|
||||
# targets
|
||||
@@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
BIN
contrib/puff/puff
Executable file
BIN
contrib/puff/puff
Executable file
Binary file not shown.
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* puff.c
|
||||
* Copyright (C) 2002-2004 Mark Adler
|
||||
* Copyright (C) 2002-2008 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in puff.h
|
||||
* version 1.8, 9 Jan 2004
|
||||
* version 2.0, 25 Jul 2008
|
||||
*
|
||||
* puff.c is a simple inflate written to be an unambiguous way to specify the
|
||||
* deflate format. It is not written for speed but rather simplicity. As a
|
||||
@@ -61,6 +61,12 @@
|
||||
* 1.7 3 Mar 2003 - Added test code for distribution
|
||||
* - Added zlib-like license
|
||||
* 1.8 9 Jan 2004 - Added some comments on no distance codes case
|
||||
* 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland]
|
||||
* - Catch missing end-of-block symbol error
|
||||
* 2.0 25 Jul 2008 - Add #define to permit distance too far back
|
||||
* - Add option in TEST code for puff to write the data
|
||||
* - Add option in TEST code to skip input bytes
|
||||
* - Allow TEST code to read from piped stdin
|
||||
*/
|
||||
|
||||
#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
|
||||
@@ -194,7 +200,7 @@ struct huffman {
|
||||
* Decode a code from the stream s using huffman table h. Return the symbol or
|
||||
* a negative value if there is an error. If all of the lengths are zero, i.e.
|
||||
* an empty code, or if the code is incomplete and an invalid code is received,
|
||||
* then -9 is returned after reading MAXBITS bits.
|
||||
* then -10 is returned after reading MAXBITS bits.
|
||||
*
|
||||
* Format notes:
|
||||
*
|
||||
@@ -226,14 +232,14 @@ local int decode(struct state *s, struct huffman *h)
|
||||
for (len = 1; len <= MAXBITS; len++) {
|
||||
code |= bits(s, 1); /* get next bit */
|
||||
count = h->count[len];
|
||||
if (code < first + count) /* if length len, return symbol */
|
||||
if (code - count < first) /* if length len, return symbol */
|
||||
return h->symbol[index + (code - first)];
|
||||
index += count; /* else update for next length */
|
||||
first += count;
|
||||
first <<= 1;
|
||||
code <<= 1;
|
||||
}
|
||||
return -9; /* ran out of codes */
|
||||
return -10; /* ran out of codes */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -263,7 +269,7 @@ local int decode(struct state *s, struct huffman *h)
|
||||
code |= bitbuf & 1;
|
||||
bitbuf >>= 1;
|
||||
count = *next++;
|
||||
if (code < first + count) { /* if length len, return symbol */
|
||||
if (code - count < first) { /* if length len, return symbol */
|
||||
s->bitbuf = bitbuf;
|
||||
s->bitcnt = (s->bitcnt - len) & 7;
|
||||
return h->symbol[index + (code - first)];
|
||||
@@ -280,7 +286,7 @@ local int decode(struct state *s, struct huffman *h)
|
||||
bitbuf = s->in[s->incnt++];
|
||||
if (left > 8) left = 8;
|
||||
}
|
||||
return -9; /* ran out of codes */
|
||||
return -10; /* ran out of codes */
|
||||
}
|
||||
#endif /* SLOW */
|
||||
|
||||
@@ -448,21 +454,27 @@ local int codes(struct state *s,
|
||||
else if (symbol > 256) { /* length */
|
||||
/* get and compute length */
|
||||
symbol -= 257;
|
||||
if (symbol >= 29) return -9; /* invalid fixed code */
|
||||
if (symbol >= 29) return -10; /* invalid fixed code */
|
||||
len = lens[symbol] + bits(s, lext[symbol]);
|
||||
|
||||
/* get and check distance */
|
||||
symbol = decode(s, distcode);
|
||||
if (symbol < 0) return symbol; /* invalid symbol */
|
||||
dist = dists[symbol] + bits(s, dext[symbol]);
|
||||
#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
if (dist > s->outcnt)
|
||||
return -10; /* distance too far back */
|
||||
return -11; /* distance too far back */
|
||||
#endif
|
||||
|
||||
/* copy length bytes from distance bytes back */
|
||||
if (s->out != NIL) {
|
||||
if (s->outcnt + len > s->outlen) return 1;
|
||||
while (len--) {
|
||||
s->out[s->outcnt] = s->out[s->outcnt - dist];
|
||||
s->out[s->outcnt] =
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
dist > s->outcnt ? 0 :
|
||||
#endif
|
||||
s->out[s->outcnt - dist];
|
||||
s->outcnt++;
|
||||
}
|
||||
}
|
||||
@@ -680,6 +692,10 @@ local int dynamic(struct state *s)
|
||||
}
|
||||
}
|
||||
|
||||
/* check for end-of-block code -- there better be one! */
|
||||
if (lengths[256] == 0)
|
||||
return -9;
|
||||
|
||||
/* build huffman table for literal/length codes */
|
||||
err = construct(&lencode, lengths, nlen);
|
||||
if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1))
|
||||
@@ -724,8 +740,9 @@ local int dynamic(struct state *s)
|
||||
* -6: dynamic block code description: repeat more than specified lengths
|
||||
* -7: dynamic block code description: invalid literal/length code lengths
|
||||
* -8: dynamic block code description: invalid distance code lengths
|
||||
* -9: invalid literal/length or distance code in fixed or dynamic block
|
||||
* -10: distance is too far back in fixed or dynamic block
|
||||
* -9: dynamic block code description: missing end-of-block code
|
||||
* -10: invalid literal/length or distance code in fixed or dynamic block
|
||||
* -11: distance is too far back in fixed or dynamic block
|
||||
*
|
||||
* Format notes:
|
||||
*
|
||||
@@ -783,54 +800,142 @@ int puff(unsigned char *dest, /* pointer to destination pointer */
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
/* Example of how to use puff() */
|
||||
/* Examples of how to use puff().
|
||||
|
||||
Usage: puff [-w] [-nnn] file
|
||||
... | puff [-w] [-nnn]
|
||||
|
||||
where file is the input file with deflate data, nnn is the number of bytes
|
||||
of input to skip before inflating (e.g. to skip a zlib or gzip header), and
|
||||
-w is used to write the decompressed data to stdout */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
local unsigned char *yank(char *name, unsigned long *len)
|
||||
/* Return size times approximately the cube root of 2, keeping the result as 1,
|
||||
3, or 5 times a power of 2 -- the result is always > size, until the result
|
||||
is the maximum value of an unsigned long, where it remains. This is useful
|
||||
to keep reallocations less than ~33% over the actual data. */
|
||||
local size_t bythirds(size_t size)
|
||||
{
|
||||
unsigned long size;
|
||||
unsigned char *buf;
|
||||
int n;
|
||||
size_t m;
|
||||
|
||||
m = size;
|
||||
for (n = 0; m; n++)
|
||||
m >>= 1;
|
||||
if (n < 3)
|
||||
return size + 1;
|
||||
n -= 3;
|
||||
m = size >> n;
|
||||
m += m == 6 ? 2 : 1;
|
||||
m <<= n;
|
||||
return m > size ? m : (size_t)(-1);
|
||||
}
|
||||
|
||||
/* Read the input file *name, or stdin if name is NULL, into allocated memory.
|
||||
Reallocate to larger buffers until the entire file is read in. Return a
|
||||
pointer to the allocated data, or NULL if there was a memory allocation
|
||||
failure. *len is the number of bytes of data read from the input file (even
|
||||
if load() returns NULL). If the input file was empty or could not be opened
|
||||
or read, *len is zero. */
|
||||
local void *load(char *name, size_t *len)
|
||||
{
|
||||
size_t size;
|
||||
void *buf, *swap;
|
||||
FILE *in;
|
||||
struct stat s;
|
||||
|
||||
*len = 0;
|
||||
if (stat(name, &s)) return NULL;
|
||||
if ((s.st_mode & S_IFMT) != S_IFREG) return NULL;
|
||||
size = (unsigned long)(s.st_size);
|
||||
if (size == 0 || (off_t)size != s.st_size) return NULL;
|
||||
in = fopen(name, "r");
|
||||
if (in == NULL) return NULL;
|
||||
buf = malloc(size);
|
||||
if (buf != NULL && fread(buf, 1, size, in) != size) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
buf = malloc(size = 4096);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
in = name == NULL ? stdin : fopen(name, "rb");
|
||||
if (in != NULL) {
|
||||
for (;;) {
|
||||
*len += fread((char *)buf + *len, 1, size - *len, in);
|
||||
if (*len < size) break;
|
||||
size = bythirds(size);
|
||||
if (size == *len || (swap = realloc(buf, size)) == NULL) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
break;
|
||||
}
|
||||
buf = swap;
|
||||
}
|
||||
fclose(in);
|
||||
}
|
||||
fclose(in);
|
||||
*len = size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
unsigned char *source;
|
||||
unsigned long len, sourcelen, destlen;
|
||||
int ret, skip = 0, put = 0;
|
||||
char *arg, *name = NULL;
|
||||
unsigned char *source = NULL, *dest;
|
||||
size_t len = 0;
|
||||
unsigned long sourcelen, destlen;
|
||||
|
||||
if (argc < 2) return 2;
|
||||
source = yank(argv[1], &len);
|
||||
if (source == NULL) return 2;
|
||||
sourcelen = len;
|
||||
ret = puff(NIL, &destlen, source, &sourcelen);
|
||||
if (ret)
|
||||
printf("puff() failed with return code %d\n", ret);
|
||||
else {
|
||||
printf("puff() succeeded uncompressing %lu bytes\n", destlen);
|
||||
if (sourcelen < len) printf("%lu compressed bytes unused\n",
|
||||
len - sourcelen);
|
||||
/* process arguments */
|
||||
while (arg = *++argv, --argc)
|
||||
if (arg[0] == '-') {
|
||||
if (arg[1] == 'w' && arg[2] == 0)
|
||||
put = 1;
|
||||
else if (arg[1] >= '0' && arg[1] <= '9')
|
||||
skip = atoi(arg + 1);
|
||||
else {
|
||||
fprintf(stderr, "invalid option %s\n", arg);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
else if (name != NULL) {
|
||||
fprintf(stderr, "only one file name allowed\n");
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
name = arg;
|
||||
source = load(name, &len);
|
||||
if (source == NULL) {
|
||||
fprintf(stderr, "memory allocation failure\n");
|
||||
return 4;
|
||||
}
|
||||
if (len == 0) {
|
||||
fprintf(stderr, "could not read %s, or it was empty\n",
|
||||
name == NULL ? "<stdin>" : name);
|
||||
free(source);
|
||||
return 3;
|
||||
}
|
||||
if (skip >= len) {
|
||||
fprintf(stderr, "skip request of %d leaves no input\n", skip);
|
||||
free(source);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* test inflate data with offset skip */
|
||||
len -= skip;
|
||||
sourcelen = (unsigned long)len;
|
||||
ret = puff(NIL, &destlen, source + skip, &sourcelen);
|
||||
if (ret)
|
||||
fprintf(stderr, "puff() failed with return code %d\n", ret);
|
||||
else {
|
||||
fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen);
|
||||
if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n",
|
||||
len - sourcelen);
|
||||
}
|
||||
|
||||
/* if requested, inflate again and write decompressd data to stdout */
|
||||
if (put) {
|
||||
dest = malloc(destlen);
|
||||
if (dest == NULL) {
|
||||
fprintf(stderr, "memory allocation failure\n");
|
||||
free(source);
|
||||
return 4;
|
||||
}
|
||||
puff(dest, &destlen, source + skip, &sourcelen);
|
||||
fwrite(dest, 1, destlen, stdout);
|
||||
free(dest);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
free(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* puff.h
|
||||
Copyright (C) 2002, 2003 Mark Adler, all rights reserved
|
||||
version 1.7, 3 Mar 2002
|
||||
Copyright (C) 2002-2008 Mark Adler, all rights reserved
|
||||
version 1.9, 10 Jan 2008
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#define IDR_VERSION1 1
|
||||
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
|
||||
FILEVERSION 1,2,3,1
|
||||
PRODUCTVERSION 1,2,3,1
|
||||
FILEVERSION 1,2,3,5
|
||||
PRODUCTVERSION 1,2,3,5
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
FILEFLAGS 0
|
||||
FILEOS VOS_DOS_WINDOWS32
|
||||
@@ -17,12 +17,12 @@ BEGIN
|
||||
|
||||
BEGIN
|
||||
VALUE "FileDescription", "zlib data compression library\0"
|
||||
VALUE "FileVersion", "1.2.3.1\0"
|
||||
VALUE "FileVersion", "1.2.3.5\0"
|
||||
VALUE "InternalName", "zlib\0"
|
||||
VALUE "OriginalFilename", "zlib.dll\0"
|
||||
VALUE "ProductName", "ZLib.DLL\0"
|
||||
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
|
||||
VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
|
||||
VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
@@ -200,9 +200,21 @@
|
||||
<File
|
||||
RelativePath="..\..\masmx86\gvmat32c.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzclose.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzread.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzwrite.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\infback.c">
|
||||
</File>
|
||||
|
||||
@@ -347,9 +347,21 @@
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzclose.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzread.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzwrite.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\infback.c">
|
||||
</File>
|
||||
|
||||
@@ -760,8 +760,19 @@
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c"
|
||||
>
|
||||
RelativePath="..\..\..\gzclose.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzread.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzwrite.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\infback.c"
|
||||
|
||||
@@ -1005,8 +1005,19 @@
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c"
|
||||
>
|
||||
RelativePath="..\..\..\gzclose.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzio.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzread.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\gzwrite.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\infback.c"
|
||||
|
||||
33
crc32.c
33
crc32.c
@@ -1,5 +1,5 @@
|
||||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* Copyright (C) 1995-2006 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
/* Definitions for doing the crc four data bytes at a time. */
|
||||
#ifdef BYFOUR
|
||||
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
|
||||
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
|
||||
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
||||
local unsigned long crc32_little OF((unsigned long,
|
||||
const unsigned char FAR *, unsigned));
|
||||
@@ -68,6 +68,8 @@
|
||||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||
unsigned long vec));
|
||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
|
||||
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
@@ -367,22 +369,22 @@ local void gf2_matrix_square(square, mat)
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||
local uLong crc32_combine_(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off_t len2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
int n;
|
||||
unsigned long row;
|
||||
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||
|
||||
/* degenerate case */
|
||||
if (len2 == 0)
|
||||
/* degenerate case (also disallow negative lengths) */
|
||||
if (len2 <= 0)
|
||||
return crc1;
|
||||
|
||||
/* put operator for one zero bit in odd */
|
||||
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
|
||||
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
|
||||
row = 1;
|
||||
for (n = 1; n < GF2_DIM; n++) {
|
||||
odd[n] = row;
|
||||
@@ -421,3 +423,20 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||
crc1 ^= crc2;
|
||||
return crc1;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off_t len2;
|
||||
{
|
||||
return crc32_combine_(crc1, crc2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
|
||||
uLong crc1;
|
||||
uLong crc2;
|
||||
z_off64_t len2;
|
||||
{
|
||||
return crc32_combine_(crc1, crc2, len2);
|
||||
}
|
||||
|
||||
210
deflate.c
210
deflate.c
@@ -1,5 +1,5 @@
|
||||
/* deflate.c -- compress data using the deflation algorithm
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
#include "deflate.h"
|
||||
|
||||
const char deflate_copyright[] =
|
||||
" deflate 1.2.3.1 Copyright 1995-2005 Jean-loup Gailly ";
|
||||
" deflate 1.2.3.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
|
||||
/*
|
||||
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
|
||||
@@ -79,19 +79,18 @@ local block_state deflate_fast OF((deflate_state *s, int flush));
|
||||
#ifndef FASTEST
|
||||
local block_state deflate_slow OF((deflate_state *s, int flush));
|
||||
#endif
|
||||
local block_state deflate_rle OF((deflate_state *s, int flush));
|
||||
local block_state deflate_huff OF((deflate_state *s, int flush));
|
||||
local void lm_init OF((deflate_state *s));
|
||||
local void putShortMSB OF((deflate_state *s, uInt b));
|
||||
local void flush_pending OF((z_streamp strm));
|
||||
local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
|
||||
#ifndef FASTEST
|
||||
#ifdef ASMV
|
||||
void match_init OF((void)); /* asm code initialization */
|
||||
uInt longest_match OF((deflate_state *s, IPos cur_match));
|
||||
#else
|
||||
local uInt longest_match OF((deflate_state *s, IPos cur_match));
|
||||
#endif
|
||||
#endif
|
||||
local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
|
||||
|
||||
#ifdef DEBUG
|
||||
local void check_match OF((deflate_state *s, IPos start, IPos match,
|
||||
@@ -110,11 +109,6 @@ local void check_match OF((deflate_state *s, IPos start, IPos match,
|
||||
#endif
|
||||
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
/* Values for max_lazy_match, good_match and max_chain_length, depending on
|
||||
* the desired pack level (0..9). The values given below have been tuned to
|
||||
* exclude worst case performance for pathological files. Better values may be
|
||||
@@ -288,6 +282,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
|
||||
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
|
||||
|
||||
s->high_water = 0; /* nothing written to s->window yet */
|
||||
|
||||
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
||||
|
||||
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
|
||||
@@ -332,8 +328,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
||||
strm->adler = adler32(strm->adler, dictionary, dictLength);
|
||||
|
||||
if (length < MIN_MATCH) return Z_OK;
|
||||
if (length > MAX_DIST(s)) {
|
||||
length = MAX_DIST(s);
|
||||
if (length > s->w_size) {
|
||||
length = s->w_size;
|
||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||
}
|
||||
zmemcpy(s->window, dictionary, length);
|
||||
@@ -435,9 +431,10 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
||||
}
|
||||
func = configuration_table[s->level].func;
|
||||
|
||||
if (func != configuration_table[level].func && strm->total_in != 0) {
|
||||
if ((strategy != s->strategy || func != configuration_table[level].func) &&
|
||||
strm->total_in != 0) {
|
||||
/* Flush the last buffer: */
|
||||
err = deflate(strm, Z_PARTIAL_FLUSH);
|
||||
err = deflate(strm, Z_BLOCK);
|
||||
}
|
||||
if (s->level != level) {
|
||||
s->level = level;
|
||||
@@ -513,16 +510,16 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
|
||||
break;
|
||||
case 2: /* gzip wrapper */
|
||||
wraplen = 18;
|
||||
if (s->gzhead != NULL) { /* user-supplied gzip header */
|
||||
if (s->gzhead->extra != NULL)
|
||||
if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
|
||||
if (s->gzhead->extra != Z_NULL)
|
||||
wraplen += 2 + s->gzhead->extra_len;
|
||||
str = s->gzhead->name;
|
||||
if (str != NULL)
|
||||
if (str != Z_NULL)
|
||||
do {
|
||||
wraplen++;
|
||||
} while (*str++);
|
||||
str = s->gzhead->comment;
|
||||
if (str != NULL)
|
||||
if (str != Z_NULL)
|
||||
do {
|
||||
wraplen++;
|
||||
} while (*str++);
|
||||
@@ -539,7 +536,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
|
||||
return complen + wraplen;
|
||||
|
||||
/* default settings: return tight bound for that case */
|
||||
return compressBound(sourceLen) - 6 + wraplen;
|
||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||
(sourceLen >> 25) + 13 - 6 + wraplen;
|
||||
}
|
||||
|
||||
/* =========================================================================
|
||||
@@ -589,7 +587,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
deflate_state *s;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL ||
|
||||
flush > Z_FINISH || flush < 0) {
|
||||
flush > Z_BLOCK || flush < 0) {
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
s = strm->state;
|
||||
@@ -613,7 +611,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
put_byte(s, 31);
|
||||
put_byte(s, 139);
|
||||
put_byte(s, 8);
|
||||
if (s->gzhead == NULL) {
|
||||
if (s->gzhead == Z_NULL) {
|
||||
put_byte(s, 0);
|
||||
put_byte(s, 0);
|
||||
put_byte(s, 0);
|
||||
@@ -640,7 +638,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
||||
4 : 0));
|
||||
put_byte(s, s->gzhead->os & 0xff);
|
||||
if (s->gzhead->extra != NULL) {
|
||||
if (s->gzhead->extra != Z_NULL) {
|
||||
put_byte(s, s->gzhead->extra_len & 0xff);
|
||||
put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
|
||||
}
|
||||
@@ -682,7 +680,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
}
|
||||
#ifdef GZIP
|
||||
if (s->status == EXTRA_STATE) {
|
||||
if (s->gzhead->extra != NULL) {
|
||||
if (s->gzhead->extra != Z_NULL) {
|
||||
uInt beg = s->pending; /* start of bytes to update crc */
|
||||
|
||||
while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
|
||||
@@ -710,7 +708,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
s->status = NAME_STATE;
|
||||
}
|
||||
if (s->status == NAME_STATE) {
|
||||
if (s->gzhead->name != NULL) {
|
||||
if (s->gzhead->name != Z_NULL) {
|
||||
uInt beg = s->pending; /* start of bytes to update crc */
|
||||
int val;
|
||||
|
||||
@@ -741,7 +739,7 @@ int ZEXPORT deflate (strm, flush)
|
||||
s->status = COMMENT_STATE;
|
||||
}
|
||||
if (s->status == COMMENT_STATE) {
|
||||
if (s->gzhead->comment != NULL) {
|
||||
if (s->gzhead->comment != Z_NULL) {
|
||||
uInt beg = s->pending; /* start of bytes to update crc */
|
||||
int val;
|
||||
|
||||
@@ -819,7 +817,9 @@ int ZEXPORT deflate (strm, flush)
|
||||
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
|
||||
block_state bstate;
|
||||
|
||||
bstate = (*(configuration_table[s->level].func))(s, flush);
|
||||
bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
|
||||
(s->strategy == Z_RLE ? deflate_rle(s, flush) :
|
||||
(*(configuration_table[s->level].func))(s, flush));
|
||||
|
||||
if (bstate == finish_started || bstate == finish_done) {
|
||||
s->status = FINISH_STATE;
|
||||
@@ -840,13 +840,17 @@ int ZEXPORT deflate (strm, flush)
|
||||
if (bstate == block_done) {
|
||||
if (flush == Z_PARTIAL_FLUSH) {
|
||||
_tr_align(s);
|
||||
} else { /* FULL_FLUSH or SYNC_FLUSH */
|
||||
} else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
|
||||
_tr_stored_block(s, (char*)0, 0L, 0);
|
||||
/* For a full flush, this empty block will be recognized
|
||||
* as a special marker by inflate_sync().
|
||||
*/
|
||||
if (flush == Z_FULL_FLUSH) {
|
||||
CLEAR_HASH(s); /* forget history */
|
||||
if (s->lookahead == 0) {
|
||||
s->strstart = 0;
|
||||
s->block_start = 0L;
|
||||
}
|
||||
}
|
||||
}
|
||||
flush_pending(strm);
|
||||
@@ -1199,12 +1203,13 @@ local uInt longest_match(s, cur_match)
|
||||
return s->lookahead;
|
||||
}
|
||||
#endif /* ASMV */
|
||||
#endif /* FASTEST */
|
||||
|
||||
#else /* FASTEST */
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Optimized version for level == 1 or strategy == Z_RLE only
|
||||
* Optimized version for FASTEST only
|
||||
*/
|
||||
local uInt longest_match_fast(s, cur_match)
|
||||
local uInt longest_match(s, cur_match)
|
||||
deflate_state *s;
|
||||
IPos cur_match; /* current match */
|
||||
{
|
||||
@@ -1257,6 +1262,8 @@ local uInt longest_match_fast(s, cur_match)
|
||||
return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
|
||||
}
|
||||
|
||||
#endif /* FASTEST */
|
||||
|
||||
#ifdef DEBUG
|
||||
/* ===========================================================================
|
||||
* Check that the match at match_start is indeed a match.
|
||||
@@ -1335,7 +1342,6 @@ local void fill_window(s)
|
||||
later. (Using level 0 permanently is not an optimal usage of
|
||||
zlib, so we don't care about this pathological case.)
|
||||
*/
|
||||
/* %%% avoid this when Z_RLE */
|
||||
n = s->hash_size;
|
||||
p = &s->head[n];
|
||||
do {
|
||||
@@ -1387,6 +1393,40 @@ local void fill_window(s)
|
||||
*/
|
||||
|
||||
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
|
||||
|
||||
/* If the WIN_INIT bytes after the end of the current data have never been
|
||||
* written, then zero those bytes in order to avoid memory check reports of
|
||||
* the use of uninitialized (or uninitialised as Julian writes) bytes by
|
||||
* the longest match routines. Update the high water mark for the next
|
||||
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
|
||||
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
|
||||
*/
|
||||
if (s->high_water < s->window_size) {
|
||||
ulg curr = s->strstart + (ulg)(s->lookahead);
|
||||
ulg init;
|
||||
|
||||
if (s->high_water < curr) {
|
||||
/* Previous high water mark below current data -- zero WIN_INIT
|
||||
* bytes or up to end of window, whichever is less.
|
||||
*/
|
||||
init = s->window_size - curr;
|
||||
if (init > WIN_INIT)
|
||||
init = WIN_INIT;
|
||||
zmemzero(s->window + curr, (unsigned)init);
|
||||
s->high_water = curr + init;
|
||||
}
|
||||
else if (s->high_water < (ulg)curr + WIN_INIT) {
|
||||
/* High water mark at or above current data, but below current data
|
||||
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
|
||||
* to end of window, whichever is less.
|
||||
*/
|
||||
init = (ulg)curr + WIN_INIT - s->high_water;
|
||||
if (init > s->window_size - s->high_water)
|
||||
init = s->window_size - s->high_water;
|
||||
zmemzero(s->window + s->high_water, (unsigned)init);
|
||||
s->high_water += init;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1481,7 +1521,7 @@ local block_state deflate_fast(s, flush)
|
||||
deflate_state *s;
|
||||
int flush;
|
||||
{
|
||||
IPos hash_head = NIL; /* head of the hash chain */
|
||||
IPos hash_head; /* head of the hash chain */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
|
||||
for (;;) {
|
||||
@@ -1501,6 +1541,7 @@ local block_state deflate_fast(s, flush)
|
||||
/* Insert the string window[strstart .. strstart+2] in the
|
||||
* dictionary, and set hash_head to the head of the hash chain:
|
||||
*/
|
||||
hash_head = NIL;
|
||||
if (s->lookahead >= MIN_MATCH) {
|
||||
INSERT_STRING(s, s->strstart, hash_head);
|
||||
}
|
||||
@@ -1513,19 +1554,8 @@ local block_state deflate_fast(s, flush)
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
#ifdef FASTEST
|
||||
if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
|
||||
(s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
|
||||
s->match_length = longest_match_fast (s, hash_head);
|
||||
}
|
||||
#else
|
||||
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
||||
s->match_length = longest_match_fast (s, hash_head);
|
||||
}
|
||||
#endif
|
||||
/* longest_match() or longest_match_fast() sets match_start */
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
/* longest_match() sets match_start */
|
||||
}
|
||||
if (s->match_length >= MIN_MATCH) {
|
||||
check_match(s, s->strstart, s->match_start, s->match_length);
|
||||
@@ -1587,7 +1617,7 @@ local block_state deflate_slow(s, flush)
|
||||
deflate_state *s;
|
||||
int flush;
|
||||
{
|
||||
IPos hash_head = NIL; /* head of hash chain */
|
||||
IPos hash_head; /* head of hash chain */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
|
||||
/* Process the input block. */
|
||||
@@ -1608,6 +1638,7 @@ local block_state deflate_slow(s, flush)
|
||||
/* Insert the string window[strstart .. strstart+2] in the
|
||||
* dictionary, and set hash_head to the head of the hash chain:
|
||||
*/
|
||||
hash_head = NIL;
|
||||
if (s->lookahead >= MIN_MATCH) {
|
||||
INSERT_STRING(s, s->strstart, hash_head);
|
||||
}
|
||||
@@ -1623,12 +1654,8 @@ local block_state deflate_slow(s, flush)
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
||||
s->match_length = longest_match_fast (s, hash_head);
|
||||
}
|
||||
/* longest_match() or longest_match_fast() sets match_start */
|
||||
s->match_length = longest_match (s, hash_head);
|
||||
/* longest_match() sets match_start */
|
||||
|
||||
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
|
||||
#if TOO_FAR <= 32767
|
||||
@@ -1706,7 +1733,6 @@ local block_state deflate_slow(s, flush)
|
||||
}
|
||||
#endif /* FASTEST */
|
||||
|
||||
#if 0
|
||||
/* ===========================================================================
|
||||
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
||||
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
||||
@@ -1716,11 +1742,9 @@ local block_state deflate_rle(s, flush)
|
||||
deflate_state *s;
|
||||
int flush;
|
||||
{
|
||||
int bflush; /* set if current block must be flushed */
|
||||
uInt run; /* length of run */
|
||||
uInt max; /* maximum length of run */
|
||||
uInt prev; /* byte at distance one to match */
|
||||
Bytef *scan; /* scan for end of run */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
uInt prev; /* byte at distance one to match */
|
||||
Bytef *scan, *strend; /* scan goes up to strend for length of run */
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
@@ -1736,23 +1760,33 @@ local block_state deflate_rle(s, flush)
|
||||
}
|
||||
|
||||
/* See how many times the previous byte repeats */
|
||||
run = 0;
|
||||
if (s->strstart > 0) { /* if there is a previous byte, that is */
|
||||
max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
|
||||
s->match_length = 0;
|
||||
if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
|
||||
scan = s->window + s->strstart - 1;
|
||||
prev = *scan++;
|
||||
do {
|
||||
if (*scan++ != prev)
|
||||
break;
|
||||
} while (++run < max);
|
||||
prev = *scan;
|
||||
if (prev == *++scan && prev == *++scan && prev == *++scan) {
|
||||
strend = s->window + s->strstart + MAX_MATCH;
|
||||
do {
|
||||
} while (prev == *++scan && prev == *++scan &&
|
||||
prev == *++scan && prev == *++scan &&
|
||||
prev == *++scan && prev == *++scan &&
|
||||
prev == *++scan && prev == *++scan &&
|
||||
scan < strend);
|
||||
s->match_length = MAX_MATCH - (int)(strend - scan);
|
||||
if (s->match_length > s->lookahead)
|
||||
s->match_length = s->lookahead;
|
||||
}
|
||||
}
|
||||
|
||||
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
||||
if (run >= MIN_MATCH) {
|
||||
check_match(s, s->strstart, s->strstart - 1, run);
|
||||
_tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
|
||||
s->lookahead -= run;
|
||||
s->strstart += run;
|
||||
if (s->match_length >= MIN_MATCH) {
|
||||
check_match(s, s->strstart, s->strstart - 1, s->match_length);
|
||||
|
||||
_tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
|
||||
|
||||
s->lookahead -= s->match_length;
|
||||
s->strstart += s->match_length;
|
||||
s->match_length = 0;
|
||||
} else {
|
||||
/* No match, output a literal byte */
|
||||
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||
@@ -1765,4 +1799,36 @@ local block_state deflate_rle(s, flush)
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
|
||||
* (It will be regenerated if this run of deflate switches away from Huffman.)
|
||||
*/
|
||||
local block_state deflate_huff(s, flush)
|
||||
deflate_state *s;
|
||||
int flush;
|
||||
{
|
||||
int bflush; /* set if current block must be flushed */
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we have a literal to write. */
|
||||
if (s->lookahead == 0) {
|
||||
fill_window(s);
|
||||
if (s->lookahead == 0) {
|
||||
if (flush == Z_NO_FLUSH)
|
||||
return need_more;
|
||||
break; /* flush the current block */
|
||||
}
|
||||
}
|
||||
|
||||
/* Output a literal byte */
|
||||
s->match_length = 0;
|
||||
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||
_tr_tally_lit (s, s->window[s->strstart], bflush);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
}
|
||||
|
||||
13
deflate.h
13
deflate.h
@@ -1,5 +1,5 @@
|
||||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly
|
||||
* Copyright (C) 1995-2009 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -260,6 +260,13 @@ typedef struct internal_state {
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
ulg high_water;
|
||||
/* High water mark offset in window for initialized bytes -- bytes above
|
||||
* this are set to zero in order to avoid memory check warnings when
|
||||
* longest match routines access bytes past the input. This is then
|
||||
* updated to the new high water mark.
|
||||
*/
|
||||
|
||||
} FAR deflate_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
@@ -278,6 +285,10 @@ typedef struct internal_state {
|
||||
* distances are limited to MAX_DIST instead of WSIZE.
|
||||
*/
|
||||
|
||||
#define WIN_INIT MAX_MATCH
|
||||
/* Number of bytes after end of data in window to initialize in order to avoid
|
||||
memory checker errors from longest match routines */
|
||||
|
||||
/* in trees.c */
|
||||
void _tr_init OF((deflate_state *s));
|
||||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
|
||||
@@ -121,7 +121,7 @@ At least for deflate's output that generates new trees every several 10's of
|
||||
kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
|
||||
would take too long if you're only decoding several thousand symbols. At the
|
||||
other extreme, you could make a new table for every bit in the code. In fact,
|
||||
that's essentially a Huffman tree. But then you spend two much time
|
||||
that's essentially a Huffman tree. But then you spend too much time
|
||||
traversing the tree while decoding, even for short symbols.
|
||||
|
||||
So the number of bits for the first lookup table is a trade of the time to
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
This directory contains examples of the use of zlib.
|
||||
This directory contains examples of the use of zlib and other relevant
|
||||
programs and documentation.
|
||||
|
||||
enough.c
|
||||
calculation and justification of ENOUGH parameter in inftrees.h
|
||||
- calculates the maximum table space used in inflate tree
|
||||
construction over all possible Huffman codes
|
||||
|
||||
fitblk.c
|
||||
compress just enough input to nearly fill a requested output size
|
||||
@@ -23,9 +29,16 @@ gzjoin.c
|
||||
|
||||
gzlog.c
|
||||
gzlog.h
|
||||
efficiently maintain a message log file in gzip format
|
||||
- illustrates use of raw deflate and Z_SYNC_FLUSH
|
||||
- illustrates use of gzip header extra field
|
||||
efficiently and robustly maintain a message log file in gzip format
|
||||
- illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(),
|
||||
and deflateSetDictionary()
|
||||
- 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
|
||||
painfully comprehensive description of zpipe.c (see below)
|
||||
|
||||
569
examples/enough.c
Normal file
569
examples/enough.c
Normal file
@@ -0,0 +1,569 @@
|
||||
/* enough.c -- determine the maximum size of inflate's Huffman code tables over
|
||||
* all possible valid and complete Huffman codes, subject to a length limit.
|
||||
* Copyright (C) 2007, 2008 Mark Adler
|
||||
* Version 1.3 17 February 2008 Mark Adler
|
||||
*/
|
||||
|
||||
/* Version history:
|
||||
1.0 3 Jan 2007 First version (derived from codecount.c version 1.4)
|
||||
1.1 4 Jan 2007 Use faster incremental table usage computation
|
||||
Prune examine() search on previously visited states
|
||||
1.2 5 Jan 2007 Comments clean up
|
||||
As inflate does, decrease root for short codes
|
||||
Refuse cases where inflate would increase root
|
||||
1.3 17 Feb 2008 Add argument for initial root table size
|
||||
Fix bug for initial root table size == max - 1
|
||||
Use a macro to compute the history index
|
||||
*/
|
||||
|
||||
/*
|
||||
Examine all possible Huffman codes for a given number of symbols and a
|
||||
maximum code length in bits to determine the maximum table size for zilb's
|
||||
inflate. Only complete Huffman codes are counted.
|
||||
|
||||
Two codes are considered distinct if the vectors of the number of codes per
|
||||
length are not identical. So permutations of the symbol assignments result
|
||||
in the same code for the counting, as do permutations of the assignments of
|
||||
the bit values to the codes (i.e. only canonical codes are counted).
|
||||
|
||||
We build a code from shorter to longer lengths, determining how many symbols
|
||||
are coded at each length. At each step, we have how many symbols remain to
|
||||
be coded, what the last code length used was, and how many bit patterns of
|
||||
that length remain unused. Then we add one to the code length and double the
|
||||
number of unused patterns to graduate to the next code length. We then
|
||||
assign all portions of the remaining symbols to that code length that
|
||||
preserve the properties of a correct and eventually complete code. Those
|
||||
properties are: we cannot use more bit patterns than are available; and when
|
||||
all the symbols are used, there are exactly zero possible bit patterns
|
||||
remaining.
|
||||
|
||||
The inflate Huffman decoding algorithm uses two-level lookup tables for
|
||||
speed. There is a single first-level table to decode codes up to root bits
|
||||
in length (root == 9 in the current inflate implementation). The table
|
||||
has 1 << root entries and is indexed by the next root bits of input. Codes
|
||||
shorter than root bits have replicated table entries, so that the correct
|
||||
entry is pointed to regardless of the bits that follow the short code. If
|
||||
the code is longer than root bits, then the table entry points to a second-
|
||||
level table. The size of that table is determined by the longest code with
|
||||
that root-bit prefix. If that longest code has length len, then the table
|
||||
has size 1 << (len - root), to index the remaining bits in that set of
|
||||
codes. Each subsequent root-bit prefix then has its own sub-table. The
|
||||
total number of table entries required by the code is calculated
|
||||
incrementally as the number of codes at each bit length is populated. When
|
||||
all of the codes are shorter than root bits, then root is reduced to the
|
||||
longest code length, resulting in a single, smaller, one-level table.
|
||||
|
||||
The inflate algorithm also provides for small values of root (relative to
|
||||
the log2 of the number of symbols), where the shortest code has more bits
|
||||
than root. In that case, root is increased to the length of the shortest
|
||||
code. This program, by design, does not handle that case, so it is verified
|
||||
that the number of symbols is less than 2^(root + 1).
|
||||
|
||||
In order to speed up the examination (by about ten orders of magnitude for
|
||||
the default arguments), the intermediate states in the build-up of a code
|
||||
are remembered and previously visited branches are pruned. The memory
|
||||
required for this will increase rapidly with the total number of symbols and
|
||||
the maximum code length in bits. However this is a very small price to pay
|
||||
for the vast speedup.
|
||||
|
||||
First, all of the possible Huffman codes are counted, and reachable
|
||||
intermediate states are noted by a non-zero count in a saved-results array.
|
||||
Second, the intermediate states that lead to (root + 1) bit or longer codes
|
||||
are used to look at all sub-codes from those junctures for their inflate
|
||||
memory usage. (The amount of memory used is not affected by the number of
|
||||
codes of root bits or less in length.) Third, the visited states in the
|
||||
construction of those sub-codes and the associated calculation of the table
|
||||
size is recalled in order to avoid recalculating from the same juncture.
|
||||
Beginning the code examination at (root + 1) bit codes, which is enabled by
|
||||
identifying the reachable nodes, accounts for about six of the orders of
|
||||
magnitude of improvement for the default arguments. About another four
|
||||
orders of magnitude come from not revisiting previous states. Out of
|
||||
approximately 2x10^16 possible Huffman codes, only about 2x10^6 sub-codes
|
||||
need to be examined to cover all of the possible table memory usage cases
|
||||
for the default arguments of 286 symbols limited to 15-bit codes.
|
||||
|
||||
Note that an unsigned long long type is used for counting. It is quite easy
|
||||
to exceed the capacity of an eight-byte integer with a large number of
|
||||
symbols and a large maximum code length, so multiple-precision arithmetic
|
||||
would need to replace the unsigned long long arithmetic in that case. This
|
||||
program will abort if an overflow occurs. The big_t type identifies where
|
||||
the counting takes place.
|
||||
|
||||
An unsigned long long type is also used for calculating the number of
|
||||
possible codes remaining at the maximum length. This limits the maximum
|
||||
code length to the number of bits in a long long minus the number of bits
|
||||
needed to represent the symbols in a flat code. The code_t type identifies
|
||||
where the bit pattern counting takes place.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define local static
|
||||
|
||||
/* special data types */
|
||||
typedef unsigned long long big_t; /* type for code counting */
|
||||
typedef unsigned long long code_t; /* type for bit pattern counting */
|
||||
struct tab { /* type for been here check */
|
||||
size_t len; /* length of bit vector in char's */
|
||||
char *vec; /* allocated bit vector */
|
||||
};
|
||||
|
||||
/* The array for saving results, num[], is indexed with this triplet:
|
||||
|
||||
syms: number of symbols remaining to code
|
||||
left: number of available bit patterns at length len
|
||||
len: number of bits in the codes currently being assigned
|
||||
|
||||
Those indices are constrained thusly when saving results:
|
||||
|
||||
syms: 3..totsym (totsym == total symbols to code)
|
||||
left: 2..syms - 1, but only the evens (so syms == 8 -> 2, 4, 6)
|
||||
len: 1..max - 1 (max == maximum code length in bits)
|
||||
|
||||
syms == 2 is not saved since that immediately leads to a single code. left
|
||||
must be even, since it represents the number of available bit patterns at
|
||||
the current length, which is double the number at the previous length.
|
||||
left ends at syms-1 since left == syms immediately results in a single code.
|
||||
(left > sym is not allowed since that would result in an incomplete code.)
|
||||
len is less than max, since the code completes immediately when len == max.
|
||||
|
||||
The offset into the array is calculated for the three indices with the
|
||||
first one (syms) being outermost, and the last one (len) being innermost.
|
||||
We build the array with length max-1 lists for the len index, with syms-3
|
||||
of those for each symbol. There are totsym-2 of those, with each one
|
||||
varying in length as a function of sym. See the calculation of index in
|
||||
count() for the index, and the calculation of size in main() for the size
|
||||
of the array.
|
||||
|
||||
For the deflate example of 286 symbols limited to 15-bit codes, the array
|
||||
has 284,284 entries, taking up 2.17 MB for an 8-byte big_t. More than
|
||||
half of the space allocated for saved results is actually used -- not all
|
||||
possible triplets are reached in the generation of valid Huffman codes.
|
||||
*/
|
||||
|
||||
/* The array for tracking visited states, done[], is itself indexed identically
|
||||
to the num[] array as described above for the (syms, left, len) triplet.
|
||||
Each element in the array is further indexed by the (mem, rem) doublet,
|
||||
where mem is the amount of inflate table space used so far, and rem is the
|
||||
remaining unused entries in the current inflate sub-table. Each indexed
|
||||
element is simply one bit indicating whether the state has been visited or
|
||||
not. Since the ranges for mem and rem are not known a priori, each bit
|
||||
vector is of a variable size, and grows as needed to accommodate the visited
|
||||
states. mem and rem are used to calculate a single index in a triangular
|
||||
array. Since the range of mem is expected in the default case to be about
|
||||
ten times larger than the range of rem, the array is skewed to reduce the
|
||||
memory usage, with eight times the range for mem than for rem. See the
|
||||
calculations for offset and bit in beenhere() for the details.
|
||||
|
||||
For the deflate example of 286 symbols limited to 15-bit codes, the bit
|
||||
vectors grow to total approximately 21 MB, in addition to the 4.3 MB done[]
|
||||
array itself.
|
||||
*/
|
||||
|
||||
/* Globals to avoid propagating constants or constant pointers recursively */
|
||||
local int max; /* maximum allowed bit length for the codes */
|
||||
local int root; /* size of base code table in bits */
|
||||
local int large; /* largest code table so far */
|
||||
local size_t size; /* number of elements in num and done */
|
||||
local int *code; /* number of symbols assigned to each bit length */
|
||||
local big_t *num; /* saved results array for code counting */
|
||||
local struct tab *done; /* states already evaluated array */
|
||||
|
||||
/* Index function for num[] and done[] */
|
||||
#define INDEX(i,j,k) (((size_t)((i-1)>>1)*((i-2)>>1)+(j>>1)-1)*(max-1)+k-1)
|
||||
|
||||
/* Free allocated space. Uses globals code, num, and done. */
|
||||
local void cleanup(void)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
if (done != NULL) {
|
||||
for (n = 0; n < size; n++)
|
||||
if (done[n].len)
|
||||
free(done[n].vec);
|
||||
free(done);
|
||||
}
|
||||
if (num != NULL)
|
||||
free(num);
|
||||
if (code != NULL)
|
||||
free(code);
|
||||
}
|
||||
|
||||
/* Return the number of possible Huffman codes using bit patterns of lengths
|
||||
len through max inclusive, coding syms symbols, with left bit patterns of
|
||||
length len unused -- return -1 if there is an overflow in the counting.
|
||||
Keep a record of previous results in num to prevent repeating the same
|
||||
calculation. Uses the globals max and num. */
|
||||
local big_t count(int syms, int len, int left)
|
||||
{
|
||||
big_t sum; /* number of possible codes from this juncture */
|
||||
big_t got; /* value returned from count() */
|
||||
int least; /* least number of syms to use at this juncture */
|
||||
int most; /* most number of syms to use at this juncture */
|
||||
int use; /* number of bit patterns to use in next call */
|
||||
size_t index; /* index of this case in *num */
|
||||
|
||||
/* see if only one possible code */
|
||||
if (syms == left)
|
||||
return 1;
|
||||
|
||||
/* note and verify the expected state */
|
||||
assert(syms > left && left > 0 && len < max);
|
||||
|
||||
/* see if we've done this one already */
|
||||
index = INDEX(syms, left, len);
|
||||
got = num[index];
|
||||
if (got)
|
||||
return got; /* we have -- return the saved result */
|
||||
|
||||
/* we need to use at least this many bit patterns so that the code won't be
|
||||
incomplete at the next length (more bit patterns than symbols) */
|
||||
least = (left << 1) - syms;
|
||||
if (least < 0)
|
||||
least = 0;
|
||||
|
||||
/* we can use at most this many bit patterns, lest there not be enough
|
||||
available for the remaining symbols at the maximum length (if there were
|
||||
no limit to the code length, this would become: most = left - 1) */
|
||||
most = (((code_t)left << (max - len)) - syms) /
|
||||
(((code_t)1 << (max - len)) - 1);
|
||||
|
||||
/* count all possible codes from this juncture and add them up */
|
||||
sum = 0;
|
||||
for (use = least; use <= most; use++) {
|
||||
got = count(syms - use, len + 1, (left - use) << 1);
|
||||
sum += got;
|
||||
if (got == -1 || sum < got) /* overflow */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* verify that all recursive calls are productive */
|
||||
assert(sum != 0);
|
||||
|
||||
/* save the result and return it */
|
||||
num[index] = sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* Return true if we've been here before, set to true if not. Set a bit in a
|
||||
bit vector to indicate visiting this state. Each (syms,len,left) state
|
||||
has a variable size bit vector indexed by (mem,rem). The bit vector is
|
||||
lengthened if needed to allow setting the (mem,rem) bit. */
|
||||
local int beenhere(int syms, int len, int left, int mem, int rem)
|
||||
{
|
||||
size_t index; /* index for this state's bit vector */
|
||||
size_t offset; /* offset in this state's bit vector */
|
||||
int bit; /* mask for this state's bit */
|
||||
size_t length; /* length of the bit vector in bytes */
|
||||
char *vector; /* new or enlarged bit vector */
|
||||
|
||||
/* point to vector for (syms,left,len), bit in vector for (mem,rem) */
|
||||
index = INDEX(syms, left, len);
|
||||
mem -= 1 << root;
|
||||
offset = (mem >> 3) + rem;
|
||||
offset = ((offset * (offset + 1)) >> 1) + rem;
|
||||
bit = 1 << (mem & 7);
|
||||
|
||||
/* see if we've been here */
|
||||
length = done[index].len;
|
||||
if (offset < length && (done[index].vec[offset] & bit) != 0)
|
||||
return 1; /* done this! */
|
||||
|
||||
/* we haven't been here before -- set the bit to show we have now */
|
||||
|
||||
/* see if we need to lengthen the vector in order to set the bit */
|
||||
if (length <= offset) {
|
||||
/* if we have one already, enlarge it, zero out the appended space */
|
||||
if (length) {
|
||||
do {
|
||||
length <<= 1;
|
||||
} while (length <= offset);
|
||||
vector = realloc(done[index].vec, length);
|
||||
if (vector != NULL)
|
||||
memset(vector + done[index].len, 0, length - done[index].len);
|
||||
}
|
||||
|
||||
/* otherwise we need to make a new vector and zero it out */
|
||||
else {
|
||||
length = 1 << (len - root);
|
||||
while (length <= offset)
|
||||
length <<= 1;
|
||||
vector = calloc(length, sizeof(char));
|
||||
}
|
||||
|
||||
/* in either case, bail if we can't get the memory */
|
||||
if (vector == NULL) {
|
||||
fputs("abort: unable to allocate enough memory\n", stderr);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* install the new vector */
|
||||
done[index].len = length;
|
||||
done[index].vec = vector;
|
||||
}
|
||||
|
||||
/* set the bit */
|
||||
done[index].vec[offset] |= bit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Examine all possible codes from the given node (syms, len, left). Compute
|
||||
the amount of memory required to build inflate's decoding tables, where the
|
||||
number of code structures used so far is mem, and the number remaining in
|
||||
the current sub-table is rem. Uses the globals max, code, root, large, and
|
||||
done. */
|
||||
local void examine(int syms, int len, int left, int mem, int rem)
|
||||
{
|
||||
int least; /* least number of syms to use at this juncture */
|
||||
int most; /* most number of syms to use at this juncture */
|
||||
int use; /* number of bit patterns to use in next call */
|
||||
|
||||
/* see if we have a complete code */
|
||||
if (syms == left) {
|
||||
/* set the last code entry */
|
||||
code[len] = left;
|
||||
|
||||
/* complete computation of memory used by this code */
|
||||
while (rem < left) {
|
||||
left -= rem;
|
||||
rem = 1 << (len - root);
|
||||
mem += rem;
|
||||
}
|
||||
assert(rem == left);
|
||||
|
||||
/* if this is a new maximum, show the entries used and the sub-code */
|
||||
if (mem > large) {
|
||||
large = mem;
|
||||
printf("max %d: ", mem);
|
||||
for (use = root + 1; use <= max; use++)
|
||||
if (code[use])
|
||||
printf("%d[%d] ", code[use], use);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* remove entries as we drop back down in the recursion */
|
||||
code[len] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* prune the tree if we can */
|
||||
if (beenhere(syms, len, left, mem, rem))
|
||||
return;
|
||||
|
||||
/* we need to use at least this many bit patterns so that the code won't be
|
||||
incomplete at the next length (more bit patterns than symbols) */
|
||||
least = (left << 1) - syms;
|
||||
if (least < 0)
|
||||
least = 0;
|
||||
|
||||
/* we can use at most this many bit patterns, lest there not be enough
|
||||
available for the remaining symbols at the maximum length (if there were
|
||||
no limit to the code length, this would become: most = left - 1) */
|
||||
most = (((code_t)left << (max - len)) - syms) /
|
||||
(((code_t)1 << (max - len)) - 1);
|
||||
|
||||
/* occupy least table spaces, creating new sub-tables as needed */
|
||||
use = least;
|
||||
while (rem < use) {
|
||||
use -= rem;
|
||||
rem = 1 << (len - root);
|
||||
mem += rem;
|
||||
}
|
||||
rem -= use;
|
||||
|
||||
/* examine codes from here, updating table space as we go */
|
||||
for (use = least; use <= most; use++) {
|
||||
code[len] = use;
|
||||
examine(syms - use, len + 1, (left - use) << 1,
|
||||
mem + (rem ? 1 << (len - root) : 0), rem << 1);
|
||||
if (rem == 0) {
|
||||
rem = 1 << (len - root);
|
||||
mem += rem;
|
||||
}
|
||||
rem--;
|
||||
}
|
||||
|
||||
/* remove entries as we drop back down in the recursion */
|
||||
code[len] = 0;
|
||||
}
|
||||
|
||||
/* Look at all sub-codes starting with root + 1 bits. Look at only the valid
|
||||
intermediate code states (syms, left, len). For each completed code,
|
||||
calculate the amount of memory required by inflate to build the decoding
|
||||
tables. Find the maximum amount of memory required and show the code that
|
||||
requires that maximum. Uses the globals max, root, and num. */
|
||||
local void enough(int syms)
|
||||
{
|
||||
int n; /* number of remaing symbols for this node */
|
||||
int left; /* number of unused bit patterns at this length */
|
||||
size_t index; /* index of this case in *num */
|
||||
|
||||
/* clear code */
|
||||
for (n = 0; n <= max; n++)
|
||||
code[n] = 0;
|
||||
|
||||
/* look at all (root + 1) bit and longer codes */
|
||||
large = 1 << root; /* base table */
|
||||
if (root < max) /* otherwise, there's only a base table */
|
||||
for (n = 3; n <= syms; n++)
|
||||
for (left = 2; left < n; left += 2)
|
||||
{
|
||||
/* look at all reachable (root + 1) bit nodes, and the
|
||||
resulting codes (complete at root + 2 or more) */
|
||||
index = INDEX(n, left, root + 1);
|
||||
if (root + 1 < max && num[index]) /* reachable node */
|
||||
examine(n, root + 1, left, 1 << root, 0);
|
||||
|
||||
/* also look at root bit codes with completions at root + 1
|
||||
bits (not saved in num, since complete), just in case */
|
||||
if (num[index - 1] && n <= left << 1)
|
||||
examine((n - left) << 1, root + 1, (n - left) << 1,
|
||||
1 << root, 0);
|
||||
}
|
||||
|
||||
/* done */
|
||||
printf("done: maximum of %d table entries\n", large);
|
||||
}
|
||||
|
||||
/*
|
||||
Examine and show the total number of possible Huffman codes for a given
|
||||
maximum number of symbols, initial root table size, and maximum code length
|
||||
in bits -- those are the command arguments in that order. The default
|
||||
values are 286, 9, and 15 respectively, for the deflate literal/length code.
|
||||
The possible codes are counted for each number of coded symbols from two to
|
||||
the maximum. The counts for each of those and the total number of codes are
|
||||
shown. The maximum number of inflate table entires is then calculated
|
||||
across all possible codes. Each new maximum number of table entries and the
|
||||
associated sub-code (starting at root + 1 == 10 bits) is shown.
|
||||
|
||||
To count and examine Huffman codes that are not length-limited, provide a
|
||||
maximum length equal to the number of symbols minus one.
|
||||
|
||||
For the deflate literal/length code, use "enough". For the deflate distance
|
||||
code, use "enough 30 6".
|
||||
|
||||
This uses the %llu printf format to print big_t numbers, which assumes that
|
||||
big_t is an unsigned long long. If the big_t type is changed (for example
|
||||
to a multiple precision type), the method of printing will also need to be
|
||||
updated.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int syms; /* total number of symbols to code */
|
||||
int n; /* number of symbols to code for this run */
|
||||
big_t got; /* return value of count() */
|
||||
big_t sum; /* accumulated number of codes over n */
|
||||
|
||||
/* set up globals for cleanup() */
|
||||
code = NULL;
|
||||
num = NULL;
|
||||
done = NULL;
|
||||
|
||||
/* get arguments -- default to the deflate literal/length code */
|
||||
syms = 286;
|
||||
root = 9;
|
||||
max = 15;
|
||||
if (argc > 1) {
|
||||
syms = atoi(argv[1]);
|
||||
if (argc > 2) {
|
||||
root = atoi(argv[2]);
|
||||
if (argc > 3)
|
||||
max = atoi(argv[3]);
|
||||
}
|
||||
}
|
||||
if (argc > 4 || syms < 2 || root < 1 || max < 1) {
|
||||
fputs("invalid arguments, need: [sym >= 2 [root >= 1 [max >= 1]]]\n",
|
||||
stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* if not restricting the code length, the longest is syms - 1 */
|
||||
if (max > syms - 1)
|
||||
max = syms - 1;
|
||||
|
||||
/* determine the number of bits in a code_t */
|
||||
n = 0;
|
||||
while (((code_t)1 << n) != 0)
|
||||
n++;
|
||||
|
||||
/* make sure that the calculation of most will not overflow */
|
||||
if (max > n || syms - 2 >= (((code_t)0 - 1) >> (max - 1))) {
|
||||
fputs("abort: code length too long for internal types\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* reject impossible code requests */
|
||||
if (syms - 1 > ((code_t)1 << max) - 1) {
|
||||
fprintf(stderr, "%d symbols cannot be coded in %d bits\n",
|
||||
syms, max);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* allocate code vector */
|
||||
code = calloc(max + 1, sizeof(int));
|
||||
if (code == NULL) {
|
||||
fputs("abort: unable to allocate enough memory\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* determine size of saved results array, checking for overflows,
|
||||
allocate and clear the array (set all to zero with calloc()) */
|
||||
if (syms == 2) /* iff max == 1 */
|
||||
num = NULL; /* won't be saving any results */
|
||||
else {
|
||||
size = syms >> 1;
|
||||
if (size > ((size_t)0 - 1) / (n = (syms - 1) >> 1) ||
|
||||
(size *= n, size > ((size_t)0 - 1) / (n = max - 1)) ||
|
||||
(size *= n, size > ((size_t)0 - 1) / sizeof(big_t)) ||
|
||||
(num = calloc(size, sizeof(big_t))) == NULL) {
|
||||
fputs("abort: unable to allocate enough memory\n", stderr);
|
||||
cleanup();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* count possible codes for all numbers of symbols, add up counts */
|
||||
sum = 0;
|
||||
for (n = 2; n <= syms; n++) {
|
||||
got = count(n, 1, 2);
|
||||
sum += got;
|
||||
if (got == -1 || sum < got) { /* overflow */
|
||||
fputs("abort: can't count that high!\n", stderr);
|
||||
cleanup();
|
||||
return 1;
|
||||
}
|
||||
printf("%llu %d-codes\n", got, n);
|
||||
}
|
||||
printf("%llu total codes for 2 to %d symbols", sum, syms);
|
||||
if (max < syms - 1)
|
||||
printf(" (%d-bit length limit)\n", max);
|
||||
else
|
||||
puts(" (no length limit)");
|
||||
|
||||
/* allocate and clear done array for beenhere() */
|
||||
if (syms == 2)
|
||||
done = NULL;
|
||||
else if (size > ((size_t)0 - 1) / sizeof(struct tab) ||
|
||||
(done = calloc(size, sizeof(struct tab))) == NULL) {
|
||||
fputs("abort: unable to allocate enough memory\n", stderr);
|
||||
cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* find and show maximum inflate table usage */
|
||||
if (root > max) /* reduce root to max length */
|
||||
root = max;
|
||||
if (syms < ((code_t)1 << (root + 1)))
|
||||
enough(syms);
|
||||
else
|
||||
puts("cannot handle minimum code lengths > root");
|
||||
|
||||
/* done */
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
1345
examples/gzlog.c
1345
examples/gzlog.c
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/* gzlog.h
|
||||
Copyright (C) 2004 Mark Adler, all rights reserved
|
||||
version 1.0, 26 Nov 2004
|
||||
Copyright (C) 2004, 2008 Mark Adler, all rights reserved
|
||||
version 2.0, 25 Apr 2008
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
@@ -21,38 +21,69 @@
|
||||
Mark Adler madler@alumni.caltech.edu
|
||||
*/
|
||||
|
||||
/* Version History:
|
||||
1.0 26 Nov 2004 First version
|
||||
2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations
|
||||
Interface changed slightly in that now path is a prefix
|
||||
Compression now occurs as needed during gzlog_write()
|
||||
gzlog_write() now always leaves the log file as valid gzip
|
||||
*/
|
||||
|
||||
/*
|
||||
The gzlog object allows writing short messages to a gzipped log file,
|
||||
opening the log file locked for small bursts, and then closing it. The log
|
||||
object works by appending stored data to the gzip file until 1 MB has been
|
||||
accumulated. At that time, the stored data is compressed, and replaces the
|
||||
uncompressed data in the file. The log file is truncated to its new size at
|
||||
that time. After closing, the log file is always valid gzip file that can
|
||||
decompressed to recover what was written.
|
||||
object works by appending stored (uncompressed) data to the gzip file until
|
||||
1 MB has been accumulated. At that time, the stored data is compressed, and
|
||||
replaces the uncompressed data in the file. The log file is truncated to
|
||||
its new size at that time. After each write operation, the log file is a
|
||||
valid gzip file that can decompressed to recover what was written.
|
||||
|
||||
A gzip header "extra" field contains two file offsets for appending. The
|
||||
first points to just after the last compressed data. The second points to
|
||||
the last stored block in the deflate stream, which is empty. All of the
|
||||
data between those pointers is uncompressed.
|
||||
The gzlog operations can be interupted at any point due to an application or
|
||||
system crash, and the log file will be recovered the next time the log is
|
||||
opened with gzlog_open().
|
||||
*/
|
||||
|
||||
#ifndef GZLOG_H
|
||||
#define GZLOG_H
|
||||
|
||||
/* gzlog object type */
|
||||
typedef void gzlog;
|
||||
|
||||
/* Open a gzlog object, creating the log file if it does not exist. Return
|
||||
NULL on error. Note that gzlog_open() could take a long time to return if
|
||||
there is difficulty in locking the file. */
|
||||
void *gzlog_open(char *path);
|
||||
NULL on error. Note that gzlog_open() could take a while to complete if it
|
||||
has to wait to verify that a lock is stale (possibly for five minutes), or
|
||||
if there is significant contention with other instantiations of this object
|
||||
when locking the resource. path is the prefix of the file names created by
|
||||
this object. If path is "foo", then the log file will be "foo.gz", and
|
||||
other auxiliary files will be created and destroyed during the process:
|
||||
"foo.dict" for a compression dictionary, "foo.temp" for a temporary (next)
|
||||
dictionary, "foo.add" for data being added or compressed, "foo.lock" for the
|
||||
lock file, and "foo.repairs" to log recovery operations performed due to
|
||||
interrupted gzlog operations. A gzlog_open() followed by a gzlog_close()
|
||||
will recover a previously interrupted operation, if any. */
|
||||
gzlog *gzlog_open(char *path);
|
||||
|
||||
/* Write to a gzlog object. Return non-zero on error. This function will
|
||||
simply write data to the file uncompressed. Compression of the data
|
||||
will not occur until gzlog_close() is called. It is expected that
|
||||
gzlog_write() is used for a short message, and then gzlog_close() is
|
||||
called. If a large amount of data is to be written, then the application
|
||||
should write no more than 1 MB at a time with gzlog_write() before
|
||||
calling gzlog_close() and then gzlog_open() again. */
|
||||
int gzlog_write(void *log, char *data, size_t len);
|
||||
/* Write to a gzlog object. Return zero on success, -1 if there is a file i/o
|
||||
error on any of the gzlog files (this should not happen if gzlog_open()
|
||||
succeeded, unless the device has run out of space or leftover auxiliary
|
||||
files have permissions or ownership that prevent their use), -2 if there is
|
||||
a memory allocation failure, or -3 if the log argument is invalid (e.g. if
|
||||
it was not created by gzlog_open()). This function will write data to the
|
||||
file uncompressed, until 1 MB has been accumulated, at which time that data
|
||||
will be compressed. The log file will be a valid gzip file upon successful
|
||||
return. */
|
||||
int gzlog_write(gzlog *log, void *data, size_t len);
|
||||
|
||||
/* Close a gzlog object. Return non-zero on error. The log file is locked
|
||||
until this function is called. This function will compress stored data
|
||||
at the end of the gzip file if at least 1 MB has been accumulated. Note
|
||||
that the file will not be a valid gzip file until this function completes.
|
||||
*/
|
||||
int gzlog_close(void *log);
|
||||
/* Force compression of any uncompressed data in the log. This should be used
|
||||
sparingly, if at all. The main application would be when a log file will
|
||||
not be appended to again. If this is used to compress frequently while
|
||||
appending, it will both significantly increase the execution time and
|
||||
reduce the compression ratio. The return codes are the same as for
|
||||
gzlog_write(). */
|
||||
int gzlog_compress(gzlog *log);
|
||||
|
||||
/* Close a gzlog object. Return zero on success, -3 if the log argument is
|
||||
invalid. The log object is freed, and so cannot be referenced again. */
|
||||
int gzlog_close(gzlog *log);
|
||||
|
||||
#endif
|
||||
|
||||
452
examples/pigz.c
Normal file
452
examples/pigz.c
Normal file
@@ -0,0 +1,452 @@
|
||||
/* 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;
|
||||
}
|
||||
29
gzclose.c
Normal file
29
gzclose.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* gzclose.c -- zlib gzclose() function
|
||||
* Copyright (C) 2004, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef OLD_GZIO
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
||||
That way the other gzclose functions can be used instead to avoid linking in
|
||||
unneeded compression or decompression routines. */
|
||||
int ZEXPORT gzclose(file)
|
||||
gzFile file;
|
||||
{
|
||||
#ifndef NO_GZCOMPRESS
|
||||
gz_statep state;
|
||||
|
||||
if (file == NULL)
|
||||
return EOF;
|
||||
state = (gz_statep)file;
|
||||
|
||||
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
|
||||
#else
|
||||
return gzclose_r(file);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !OLD_GZIO */
|
||||
109
gzguts.h
Normal file
109
gzguts.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# ifndef _LARGEFILE_SOURCE
|
||||
# define _LARGEFILE_SOURCE
|
||||
# endif
|
||||
# ifdef _FILE_OFFSET_BITS
|
||||
# undef _FILE_OFFSET_BITS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||
# define NO_GZCOMPRESS
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# include <io.h>
|
||||
# define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||
|
||||
/* gz* functions always use library allocation functions */
|
||||
#ifndef STDC
|
||||
extern voidp malloc OF((uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
/* get errno and strerror definition */
|
||||
#if defined UNDER_CE && defined NO_ERRNO_H
|
||||
# define zstrerror(errnum) strwinerror((DWORD)errnum)
|
||||
#else
|
||||
# ifdef STDC
|
||||
# include <errno.h>
|
||||
# define zstrerror() strerror(errno)
|
||||
# else
|
||||
# define zstrerror() "stdio error (consult errno)"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS fdopen() */
|
||||
#ifdef __MVS__
|
||||
# pragma map (fdopen , "\174\174FDOPEN")
|
||||
FILE *fdopen(int, const char *);
|
||||
#endif
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
/* default i/o buffer size -- double this for output when reading */
|
||||
#define GZBUFSIZE 8192
|
||||
|
||||
/* gzip modes, also provide a little integrity check on the passed structure */
|
||||
#define GZ_NONE 0
|
||||
#define GZ_READ 7247
|
||||
#define GZ_WRITE 31153
|
||||
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
||||
|
||||
/* internal gzip file state data structure */
|
||||
typedef struct {
|
||||
/* used for both reading and writing */
|
||||
int mode; /* see gzip modes above */
|
||||
int fd; /* file descriptor */
|
||||
char *path; /* path or fd for error messages */
|
||||
z_off64_t pos; /* current position in uncompressed data */
|
||||
unsigned size; /* buffer size, zero if not allocated yet */
|
||||
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
||||
unsigned char *in; /* input buffer */
|
||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||
unsigned char *next; /* next output data to deliver or write */
|
||||
/* just for reading */
|
||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||
unsigned have; /* amount of output data unused */
|
||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||
z_off64_t raw; /* where the raw data started, for seeking */
|
||||
int eof; /* true if end of input file reached */
|
||||
/* just for writing */
|
||||
int level; /* compression level */
|
||||
int strategy; /* compression strategy */
|
||||
/* seek request */
|
||||
int seek; /* true if seek request pending */
|
||||
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
||||
/* error information */
|
||||
int err; /* error code */
|
||||
char *msg; /* error message */
|
||||
/* zlib inflate or deflate stream */
|
||||
z_stream strm; /* stream structure in-place (not a pointer) */
|
||||
} gz_state;
|
||||
typedef gz_state FAR *gz_statep;
|
||||
|
||||
/* shared functions */
|
||||
ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *));
|
||||
265
gzio.c
265
gzio.c
@@ -1,5 +1,5 @@
|
||||
/* gzio.c -- IO on .gz files
|
||||
* 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
|
||||
*
|
||||
* Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
|
||||
@@ -7,6 +7,17 @@
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifdef OLD_GZIO
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# ifndef _LARGEFILE_SOURCE
|
||||
# define _LARGEFILE_SOURCE
|
||||
# endif
|
||||
# ifdef _FILE_OFFSET_BITS
|
||||
# undef _FILE_OFFSET_BITS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "zutil.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -29,6 +40,60 @@ struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
# define Z_PRINTF_BUFSIZE 4096
|
||||
#endif
|
||||
|
||||
#if defined UNDER_CE && defined NO_ERRNO_H
|
||||
# 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.
|
||||
|
||||
The string pointed to shall not be modified by the application,
|
||||
but may be overwritten by a subsequent call to strwinerror
|
||||
|
||||
The strwinerror function does not change the current setting
|
||||
of GetLastError. */
|
||||
|
||||
local char *strwinerror (error)
|
||||
DWORD error;
|
||||
{
|
||||
static char buf[1024];
|
||||
|
||||
wchar_t *msgbuf;
|
||||
DWORD lasterr = GetLastError();
|
||||
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
NULL,
|
||||
error,
|
||||
0, /* Default language */
|
||||
(LPVOID)&msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
if (chars != 0) {
|
||||
/* If there is an \r\n appended, zap it. */
|
||||
if (chars >= 2
|
||||
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
||||
chars -= 2;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
if (chars > sizeof (buf) - 1) {
|
||||
chars = sizeof (buf) - 1;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
wcstombs(buf, msgbuf, chars + 1);
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "unknown win32 error (%ld)", error);
|
||||
}
|
||||
|
||||
SetLastError(lasterr);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* UNDER_CE && NO_ERRNO_H */
|
||||
|
||||
#ifdef __MVS__
|
||||
# pragma map (fdopen , "\174\174FDOPEN")
|
||||
FILE *fdopen(int, const char *);
|
||||
@@ -39,6 +104,14 @@ extern voidp malloc OF((uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
#ifdef NO_FSEEKO
|
||||
# define FSEEK fseek
|
||||
# define FTELL ftell
|
||||
#else
|
||||
# define FSEEK fseeko
|
||||
# define FTELL ftello
|
||||
#endif
|
||||
|
||||
#define ALLOC(size) malloc(size)
|
||||
#define TRYFREE(p) {if (p) free(p);}
|
||||
|
||||
@@ -54,31 +127,32 @@ static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
|
||||
typedef struct gz_stream {
|
||||
z_stream stream;
|
||||
int z_err; /* error code for last stream operation */
|
||||
int z_eof; /* set if end of input file */
|
||||
FILE *file; /* .gz file */
|
||||
Byte *inbuf; /* input buffer */
|
||||
Byte *outbuf; /* output buffer */
|
||||
uLong crc; /* crc32 of uncompressed data */
|
||||
char *msg; /* error message */
|
||||
char *path; /* path name for debugging only */
|
||||
int transparent; /* 1 if input file is not a .gz file */
|
||||
char mode; /* 'w' or 'r' */
|
||||
z_off_t start; /* start of compressed data in file (header skipped) */
|
||||
z_off_t in; /* bytes into deflate or inflate */
|
||||
z_off_t out; /* bytes out of deflate or inflate */
|
||||
int back; /* one character push-back */
|
||||
int last; /* true if push-back is last character */
|
||||
int z_err; /* error code for last stream operation */
|
||||
int z_eof; /* set if end of input file */
|
||||
FILE *file; /* .gz file */
|
||||
Byte *inbuf; /* input buffer */
|
||||
Byte *outbuf; /* output buffer */
|
||||
uLong crc; /* crc32 of uncompressed data */
|
||||
char *msg; /* error message */
|
||||
char *path; /* path name for debugging only */
|
||||
int transparent; /* 1 if input file is not a .gz file */
|
||||
char mode; /* 'w' or 'r' */
|
||||
z_off64_t start; /* start of compressed data in file */
|
||||
z_off64_t in; /* bytes into deflate or inflate */
|
||||
z_off64_t out; /* bytes out of deflate or inflate */
|
||||
int back; /* one character push-back */
|
||||
int last; /* true if push-back is last character */
|
||||
} gz_stream;
|
||||
|
||||
|
||||
local gzFile gz_open OF((const char *path, const char *mode, int fd));
|
||||
local int do_flush OF((gzFile file, int flush));
|
||||
local int get_byte OF((gz_stream *s));
|
||||
local void check_header OF((gz_stream *s));
|
||||
local int destroy OF((gz_stream *s));
|
||||
local void putLong OF((FILE *file, uLong x));
|
||||
local uLong getLong OF((gz_stream *s));
|
||||
local gzFile gz_open OF((const char *, const char *, int, int));
|
||||
local z_off64_t gz_seek OF((gzFile, z_off64_t, int, int));
|
||||
local int do_flush OF((gzFile, int));
|
||||
local int get_byte OF((gz_stream *));
|
||||
local void check_header OF((gz_stream *));
|
||||
local int destroy OF((gz_stream *));
|
||||
local void putLong OF((FILE *, uLong));
|
||||
local uLong getLong OF((gz_stream *));
|
||||
|
||||
/* ===========================================================================
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
@@ -89,10 +163,11 @@ local uLong getLong OF((gz_stream *s));
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR).
|
||||
*/
|
||||
local gzFile gz_open (path, mode, fd)
|
||||
local gzFile gz_open (path, mode, fd, use64)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
int fd;
|
||||
int use64;
|
||||
{
|
||||
int err;
|
||||
int level = Z_DEFAULT_COMPRESSION; /* compression level */
|
||||
@@ -113,6 +188,7 @@ local gzFile gz_open (path, mode, fd)
|
||||
s->stream.next_in = s->inbuf = Z_NULL;
|
||||
s->stream.next_out = s->outbuf = Z_NULL;
|
||||
s->stream.avail_in = s->stream.avail_out = 0;
|
||||
s->stream.state = Z_NULL;
|
||||
s->file = NULL;
|
||||
s->z_err = Z_OK;
|
||||
s->z_eof = 0;
|
||||
@@ -164,20 +240,17 @@ local gzFile gz_open (path, mode, fd)
|
||||
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
|
||||
err = inflateInit2(&(s->stream), -MAX_WBITS);
|
||||
/* windowBits is passed < 0 to tell that there is no zlib header.
|
||||
* Note that in this case inflate *requires* an extra "dummy" byte
|
||||
* after the compressed stream in order to complete decompression and
|
||||
* return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
|
||||
* present after the compressed stream.
|
||||
*/
|
||||
/* windowBits is passed < 0 to tell that there is no zlib header */
|
||||
if (err != Z_OK || s->inbuf == Z_NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
|
||||
errno = 0;
|
||||
s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
|
||||
zseterrno(0);
|
||||
s->file = fd == -1 ?
|
||||
(use64 ? F_OPEN64(path, fmode) : F_OPEN(path, fmode)) :
|
||||
(FILE*)fdopen(fd, fmode);
|
||||
|
||||
if (s->file == NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
@@ -198,7 +271,7 @@ local gzFile gz_open (path, mode, fd)
|
||||
*/
|
||||
} else {
|
||||
check_header(s); /* skip the .gz header */
|
||||
s->start = ftell(s->file) - s->stream.avail_in;
|
||||
s->start = FTELL(s->file) - s->stream.avail_in;
|
||||
}
|
||||
|
||||
return (gzFile)s;
|
||||
@@ -211,7 +284,17 @@ gzFile ZEXPORT gzopen (path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open (path, mode, -1);
|
||||
return gz_open (path, mode, -1, 0);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Opens a gzip (.gz) file for reading or writing for 64-bit offsets
|
||||
*/
|
||||
gzFile ZEXPORT gzopen64 (path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open (path, mode, -1, 1);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -224,10 +307,10 @@ gzFile ZEXPORT gzdopen (fd, mode)
|
||||
{
|
||||
char name[46]; /* allow for up to 128-bit integers */
|
||||
|
||||
if (fd < 0) return (gzFile)Z_NULL;
|
||||
if (fd == -1) return (gzFile)Z_NULL;
|
||||
sprintf(name, "<fd:%d>", fd); /* for debugging */
|
||||
|
||||
return gz_open (name, mode, fd);
|
||||
return gz_open (name, mode, fd, 0);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -265,7 +348,7 @@ local int get_byte(s)
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
zseterrno(0);
|
||||
s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
@@ -301,7 +384,7 @@ local void check_header(s)
|
||||
len = s->stream.avail_in;
|
||||
if (len < 2) {
|
||||
if (len) s->inbuf[0] = s->stream.next_in[0];
|
||||
errno = 0;
|
||||
zseterrno(0);
|
||||
len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
|
||||
if (len == 0) s->z_eof = 1;
|
||||
if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
@@ -377,7 +460,7 @@ local int destroy (s)
|
||||
}
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
#ifdef ESPIPE
|
||||
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
if (zerrno() != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
#endif
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
@@ -446,12 +529,12 @@ int ZEXPORT gzread (file, buf, len)
|
||||
len -= s->stream.avail_out;
|
||||
s->in += len;
|
||||
s->out += len;
|
||||
if (len == 0) s->z_eof = 1;
|
||||
if (len == 0 && feof(s->file)) s->z_eof = 1;
|
||||
return (int)len;
|
||||
}
|
||||
if (s->stream.avail_in == 0 && !s->z_eof) {
|
||||
|
||||
errno = 0;
|
||||
zseterrno(0);
|
||||
s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
@@ -767,10 +850,11 @@ int ZEXPORT gzflush (file, flush)
|
||||
SEEK_END is not implemented, returns error.
|
||||
In this version of the library, gzseek can be extremely slow.
|
||||
*/
|
||||
z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
local z_off64_t gz_seek (file, offset, whence, use64)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
z_off64_t offset;
|
||||
int whence;
|
||||
int use64;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
@@ -819,7 +903,13 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
s->back = EOF;
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
if ((use64 ? fseeko64(s->file, offset, SEEK_SET) :
|
||||
FSEEK(s->file, offset, SEEK_SET)) < 0)
|
||||
return -1L;
|
||||
#else
|
||||
if (FSEEK(s->file, offset, SEEK_SET) < 0) return -1L;
|
||||
#endif
|
||||
|
||||
s->in = s->out = offset;
|
||||
return offset;
|
||||
@@ -854,6 +944,29 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
return s->out;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Define external functions gzseek() and gzseek64() using local gz_seek().
|
||||
*/
|
||||
z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
int whence;
|
||||
{
|
||||
return (z_off_t)gz_seek(file, offset, whence, 0);
|
||||
}
|
||||
|
||||
z_off64_t ZEXPORT gzseek64 (file, offset, whence)
|
||||
gzFile file;
|
||||
z_off64_t offset;
|
||||
int whence;
|
||||
{
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
return gz_seek(file, offset, whence, 1);
|
||||
#else
|
||||
return gz_seek(file, offset, whence, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Rewinds input file.
|
||||
*/
|
||||
@@ -873,7 +986,7 @@ int ZEXPORT gzrewind (file)
|
||||
if (!s->transparent) (void)inflateReset(&s->stream);
|
||||
s->in = 0;
|
||||
s->out = 0;
|
||||
return fseek(s->file, s->start, SEEK_SET);
|
||||
return FSEEK(s->file, s->start, SEEK_SET);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -887,6 +1000,15 @@ z_off_t ZEXPORT gztell (file)
|
||||
return gzseek(file, 0L, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
64-bit version
|
||||
*/
|
||||
z_off64_t ZEXPORT gztell64 (file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzseek64(file, 0L, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
@@ -974,10 +1096,14 @@ int ZEXPORT gzclose (file)
|
||||
return destroy((gz_stream*)file);
|
||||
}
|
||||
|
||||
#if defined(STDC) && !defined(_WIN32_WCE)
|
||||
# define zstrerror(errnum) strerror(errnum)
|
||||
#if defined UNDER_CE && defined NO_ERRNO_H
|
||||
# define zstrerror(errnum) strwinerror((DWORD)errnum)
|
||||
#else
|
||||
# define zstrerror(errnum) ""
|
||||
# if defined (STDC)
|
||||
# define zstrerror(errnum) strerror(errnum)
|
||||
# else
|
||||
# define zstrerror(errnum) ""
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1001,7 +1127,7 @@ const char * ZEXPORT gzerror (file, errnum)
|
||||
*errnum = s->z_err;
|
||||
if (*errnum == Z_OK) return (const char*)"";
|
||||
|
||||
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
|
||||
m = (char*)(*errnum == Z_ERRNO ? zstrerror(zerrno()) : s->stream.msg);
|
||||
|
||||
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
|
||||
|
||||
@@ -1027,3 +1153,44 @@ void ZEXPORT gzclearerr (file)
|
||||
s->z_eof = 0;
|
||||
clearerr(s->file);
|
||||
}
|
||||
|
||||
/* new functions in gzlib, but only partially implemented here */
|
||||
|
||||
int ZEXPORT gzbuffer (file, size)
|
||||
gzFile file;
|
||||
unsigned size;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
z_off_t ZEXPORT gzoffset (file)
|
||||
gzFile file;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
z_off64_t ZEXPORT gzoffset64 (file)
|
||||
gzFile file;
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ZEXPORT gzclose_r (file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzclose(file);
|
||||
}
|
||||
|
||||
int ZEXPORT gzclose_w (file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzclose(file);
|
||||
}
|
||||
|
||||
int gzio_old = 1;
|
||||
|
||||
#else /* !OLD_GZIO */
|
||||
|
||||
int gzio_old = 0;
|
||||
|
||||
#endif /* OLD_GZIO */
|
||||
|
||||
513
gzlib.c
Normal file
513
gzlib.c
Normal file
@@ -0,0 +1,513 @@
|
||||
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
||||
* Copyright (C) 2004, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef OLD_GZIO
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# define LSEEK lseek64
|
||||
#else
|
||||
# define LSEEK lseek
|
||||
#endif
|
||||
|
||||
/* Local functions */
|
||||
local void gz_reset OF((gz_statep));
|
||||
local gzFile gz_open OF((const char *, int, const char *, int));
|
||||
|
||||
#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.
|
||||
|
||||
The string pointed to shall not be modified by the application,
|
||||
but may be overwritten by a subsequent call to strwinerror
|
||||
|
||||
The strwinerror function does not change the current setting
|
||||
of GetLastError. */
|
||||
|
||||
local char *strwinerror (error)
|
||||
DWORD error;
|
||||
{
|
||||
static char buf[1024];
|
||||
|
||||
wchar_t *msgbuf;
|
||||
DWORD lasterr = GetLastError();
|
||||
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
NULL,
|
||||
error,
|
||||
0, /* Default language */
|
||||
(LPVOID)&msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
if (chars != 0) {
|
||||
/* If there is an \r\n appended, zap it. */
|
||||
if (chars >= 2
|
||||
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
||||
chars -= 2;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
if (chars > sizeof (buf) - 1) {
|
||||
chars = sizeof (buf) - 1;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
wcstombs(buf, msgbuf, chars + 1);
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "unknown win32 error (%ld)", error);
|
||||
}
|
||||
|
||||
SetLastError(lasterr);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* UNDER_CE && NO_ERRNO_H */
|
||||
|
||||
/* Reset gzip file state */
|
||||
local void gz_reset(state)
|
||||
gz_statep state;
|
||||
{
|
||||
state->how = 0; /* look for gzip header */
|
||||
if (state->mode == GZ_READ) { /* for reading ... */
|
||||
state->have = 0; /* no output data available */
|
||||
state->eof = 0; /* not at end of file */
|
||||
}
|
||||
state->seek = 0; /* no seek request pending */
|
||||
gz_error(state, Z_OK, NULL); /* clear error */
|
||||
state->pos = 0; /* no uncompressed data yet */
|
||||
state->strm.avail_in = 0; /* no input data yet */
|
||||
}
|
||||
|
||||
/* Open a gzip file either by name or file descriptor. */
|
||||
local gzFile gz_open(path, fd, mode, use64)
|
||||
const char *path;
|
||||
int fd;
|
||||
const char *mode;
|
||||
int use64;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* allocate gzFile structure to return */
|
||||
state = malloc(sizeof(gz_state));
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
state->size = 0; /* no buffers allocated yet */
|
||||
state->want = GZBUFSIZE; /* requested buffer size */
|
||||
state->msg = NULL; /* no error message yet */
|
||||
|
||||
/* interpret mode */
|
||||
state->mode = GZ_NONE;
|
||||
state->level = Z_DEFAULT_COMPRESSION;
|
||||
state->strategy = Z_DEFAULT_STRATEGY;
|
||||
while (*mode) {
|
||||
if (*mode >= '0' && *mode <= '9')
|
||||
state->level = *mode - '0';
|
||||
else
|
||||
switch (*mode) {
|
||||
case 'r':
|
||||
state->mode = GZ_READ;
|
||||
break;
|
||||
#ifndef NO_GZCOMPRESS
|
||||
case 'w':
|
||||
state->mode = GZ_WRITE;
|
||||
break;
|
||||
case 'a':
|
||||
state->mode = GZ_APPEND;
|
||||
break;
|
||||
#endif
|
||||
case '+': /* can't read and write at the same time */
|
||||
free(state);
|
||||
return NULL;
|
||||
case 'b': /* ignore -- will request binary anyway */
|
||||
break;
|
||||
case 'f':
|
||||
state->strategy = Z_FILTERED;
|
||||
break;
|
||||
case 'h':
|
||||
state->strategy = Z_HUFFMAN_ONLY;
|
||||
break;
|
||||
case 'R':
|
||||
state->strategy = Z_RLE;
|
||||
break;
|
||||
case 'F':
|
||||
state->strategy = Z_FIXED;
|
||||
default: /* could consider as an error, but just ignore */
|
||||
;
|
||||
}
|
||||
mode++;
|
||||
}
|
||||
|
||||
/* must provide an "r", "w", or "a" */
|
||||
if (state->mode == GZ_NONE) {
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* open the file with the appropriate mode (or just use fd) */
|
||||
state->fd = fd != -1 ? fd :
|
||||
open(path,
|
||||
#ifdef O_LARGEFILE
|
||||
(use64 ? O_LARGEFILE : 0) |
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
O_BINARY |
|
||||
#endif
|
||||
(state->mode == GZ_READ ?
|
||||
O_RDONLY :
|
||||
(O_WRONLY | O_CREAT | (
|
||||
state->mode == GZ_WRITE ?
|
||||
O_TRUNC :
|
||||
O_APPEND))),
|
||||
0666);
|
||||
if (state->fd == -1) {
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
if (state->mode == GZ_APPEND)
|
||||
state->mode = GZ_WRITE; /* simplify later checks */
|
||||
|
||||
/* save the path name for error messages */
|
||||
state->path = malloc(strlen(path) + 1);
|
||||
strcpy(state->path, path);
|
||||
|
||||
/* save the current position for rewinding (only if reading) */
|
||||
if (state->mode == GZ_READ) {
|
||||
state->start = LSEEK(state->fd, 0, SEEK_CUR);
|
||||
if (state->start == -1) state->start = 0;
|
||||
}
|
||||
|
||||
/* initialize stream */
|
||||
gz_reset(state);
|
||||
|
||||
/* return stream */
|
||||
return (gzFile)state;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode, 0);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen64(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode, 1);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzdopen(fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
char path[46]; /* allow up to 128-bit integers, so don't worry --
|
||||
the sprintf() is safe */
|
||||
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
sprintf(path, "<fd:%d>", fd); /* for error messages */
|
||||
return gz_open(path, fd, mode, 1);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzbuffer(file, size)
|
||||
gzFile file;
|
||||
unsigned size;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
/* make sure we haven't already allocated memory */
|
||||
if (state->size != 0)
|
||||
return -1;
|
||||
|
||||
/* check and set requested size */
|
||||
if (size == 0)
|
||||
return -1;
|
||||
state->want = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzrewind(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* back up and start over */
|
||||
if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
|
||||
return -1;
|
||||
gz_reset(state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
||||
gzFile file;
|
||||
z_off64_t offset;
|
||||
int whence;
|
||||
{
|
||||
unsigned n;
|
||||
z_off64_t ret;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
/* check that there's no error */
|
||||
if (state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* can only seek from start or relative to current position */
|
||||
if (whence != SEEK_SET && whence != SEEK_CUR)
|
||||
return -1;
|
||||
|
||||
/* normalize offset to a SEEK_CUR specification */
|
||||
if (whence == SEEK_SET)
|
||||
offset -= state->pos;
|
||||
|
||||
/* if within raw area while reading, just go there */
|
||||
if (state->mode == GZ_READ && state->how == 1 &&
|
||||
state->pos + offset >= state->raw) {
|
||||
ret = LSEEK(state->fd, offset, SEEK_CUR);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
state->have = 0;
|
||||
state->eof = 0;
|
||||
state->seek = 0;
|
||||
gz_error(state, Z_OK, NULL);
|
||||
state->strm.avail_in = 0;
|
||||
state->pos += offset;
|
||||
return state->pos;
|
||||
}
|
||||
|
||||
/* calculate skip amount, rewinding if needed for back seek when reading */
|
||||
if (offset < 0) {
|
||||
if (state->mode != GZ_READ) /* writing -- can't go backwards */
|
||||
return -1;
|
||||
offset += state->pos;
|
||||
if (offset < 0) /* before start of file! */
|
||||
return -1;
|
||||
if (gzrewind(file) == -1) /* rewind, then skip to offset */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if reading, skip what's in output buffer (one less gz_getc() check) */
|
||||
if (state->mode == GZ_READ) {
|
||||
n = state->have > offset ? (unsigned)offset : state->have;
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
offset -= n;
|
||||
}
|
||||
|
||||
/* request skip (if not zero) */
|
||||
if (offset) {
|
||||
state->seek = 1;
|
||||
state->skip = offset;
|
||||
}
|
||||
return state->pos + offset;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzseek(file, offset, whence)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
int whence;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzseek64(file, (z_off64_t)offset, whence);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gztell64(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
/* return position */
|
||||
return state->pos + (state->seek ? state->skip : 0);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gztell(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gztell64(file);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzoffset64(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t offset;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
/* compute and return effective offset in file */
|
||||
offset = LSEEK(state->fd, 0, SEEK_CUR);
|
||||
if (offset == -1)
|
||||
return -1;
|
||||
if (state->mode == GZ_READ) /* reading */
|
||||
offset -= state->strm.avail_in; /* don't count buffered input */
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzoffset(file)
|
||||
gzFile file;
|
||||
{
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzoffset64(file);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzeof(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
/* return end-of-file state */
|
||||
return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
const char * ZEXPORT gzerror(file, errnum)
|
||||
gzFile file;
|
||||
int *errnum;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return NULL;
|
||||
|
||||
/* return error information */
|
||||
*errnum = state->err;
|
||||
return state->msg == NULL ? "" : state->msg;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
void ZEXPORT gzclearerr(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return;
|
||||
state = (gz_statep)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return;
|
||||
|
||||
/* clear error and end-of-file */
|
||||
if (state->mode == GZ_READ)
|
||||
state->eof = 0;
|
||||
gz_error(state, Z_OK, NULL);
|
||||
}
|
||||
|
||||
/* Create an error message in allocated memory and set state->err and
|
||||
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
|
||||
memory). Simply save the error message as a static string. If there is
|
||||
an allocation failure constructing the error message, then convert the
|
||||
error to out of memory. */
|
||||
void ZEXPORT gz_error(state, err, msg)
|
||||
gz_statep state;
|
||||
int err;
|
||||
char *msg;
|
||||
{
|
||||
/* free previously allocated message and clear */
|
||||
if (state->msg != NULL) {
|
||||
if (state->err != Z_MEM_ERROR)
|
||||
free(state->msg);
|
||||
state->msg = NULL;
|
||||
}
|
||||
|
||||
/* set error code, and if no message, then done */
|
||||
state->err = err;
|
||||
if (msg == NULL)
|
||||
return;
|
||||
|
||||
/* for an out of memory error, save as static string */
|
||||
if (err == Z_MEM_ERROR) {
|
||||
state->msg = msg;
|
||||
return;
|
||||
}
|
||||
|
||||
/* construct error message with path */
|
||||
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
|
||||
state->err = Z_MEM_ERROR;
|
||||
state->msg = "out of memory";
|
||||
return;
|
||||
}
|
||||
strcpy(state->msg, state->path);
|
||||
strcat(state->msg, ": ");
|
||||
strcat(state->msg, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* !OLD_GZIO */
|
||||
632
gzread.c
Normal file
632
gzread.c
Normal file
@@ -0,0 +1,632 @@
|
||||
/* gzread.c -- zlib functions for reading gzip files
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef OLD_GZIO
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
|
||||
local int gz_avail OF((gz_statep));
|
||||
local int gz_next4 OF((gz_statep, unsigned long *));
|
||||
local int gz_head OF((gz_statep));
|
||||
local int gz_decomp OF((gz_statep));
|
||||
local int gz_make OF((gz_statep));
|
||||
local int gz_skip OF((gz_statep, z_off_t));
|
||||
|
||||
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||
state->fd, and update state->eof, state->err, and state->msg as appropriate.
|
||||
This function needs to loop on read(), since read() is not guaranteed to
|
||||
read the number of bytes requested, depending on the type of descriptor. */
|
||||
local int gz_load(state, buf, len, have)
|
||||
gz_statep state;
|
||||
unsigned char *buf;
|
||||
unsigned len;
|
||||
unsigned *have;
|
||||
{
|
||||
int ret;
|
||||
|
||||
*have = 0;
|
||||
do {
|
||||
ret = read(state->fd, buf + *have, len - *have);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
*have += ret;
|
||||
} while (*have < len);
|
||||
if (ret < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0)
|
||||
state->eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Load up input buffer and set eof flag if last data loaded -- return -1 on
|
||||
error, 0 otherwise. Note that the eof flag is set when the end of the input
|
||||
file is reached, even though there may be unused data in the buffer. Once
|
||||
that data has been used, no more attempts will be made to read the file.
|
||||
gz_avail() assumes that strm->avail_in == 0. */
|
||||
local int gz_avail(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
if (state->err != Z_OK)
|
||||
return -1;
|
||||
if (state->eof == 0) {
|
||||
if (gz_load(state, state->in, state->size, &(strm->avail_in)) == -1)
|
||||
return -1;
|
||||
strm->next_in = state->in;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get next byte from input, or -1 if end or error. */
|
||||
#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
|
||||
(strm->avail_in == 0 ? -1 : \
|
||||
(strm->avail_in--, *(strm->next_in)++)))
|
||||
|
||||
/* Get a four-byte little-endian integer and return 0 on success and the
|
||||
value in *ret. Otherwise -1 is returned and *ret is not modified. */
|
||||
local int gz_next4(state, ret)
|
||||
gz_statep state;
|
||||
unsigned long *ret;
|
||||
{
|
||||
int ch;
|
||||
unsigned long val;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
val = NEXT();
|
||||
val += (unsigned)NEXT() << 8;
|
||||
val += (unsigned long)NEXT() << 16;
|
||||
ch = NEXT();
|
||||
if (ch == -1)
|
||||
return -1;
|
||||
val += (unsigned long)ch << 24;
|
||||
*ret = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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
|
||||
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
|
||||
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,
|
||||
then leftover input data from the input buffer will be copied to the output
|
||||
buffer. In that case, all further file reads will be directly to either the
|
||||
output buffer or a user buffer. If decompressing, the inflate state and the
|
||||
check value will be initialized. gz_head() will return 0 on success or -1
|
||||
on failure. Failures may include read errors or gzip header errors. */
|
||||
local int gz_head(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
int flags;
|
||||
unsigned len;
|
||||
|
||||
/* allocate read buffers and inflate memory */
|
||||
if (state->size == 0) {
|
||||
/* allocate buffers */
|
||||
state->in = malloc(state->want);
|
||||
state->out = malloc(state->want << 1);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
if (state->out != NULL)
|
||||
free(state->out);
|
||||
if (state->in != NULL)
|
||||
free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
state->size = state->want;
|
||||
|
||||
/* allocate inflate memory */
|
||||
state->strm.zalloc = Z_NULL;
|
||||
state->strm.zfree = Z_NULL;
|
||||
state->strm.opaque = Z_NULL;
|
||||
state->strm.avail_in = 0;
|
||||
state->strm.next_in = Z_NULL;
|
||||
if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
state->size = 0;
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* get some data in the input buffer */
|
||||
if (strm->avail_in == 0) {
|
||||
if (gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* look for the gzip magic header bytes 31 and 139 */
|
||||
if (strm->next_in[0] == 31) {
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in && strm->next_in[0] == 139) {
|
||||
/* we have a gzip header, woo hoo! */
|
||||
strm->avail_in--;
|
||||
strm->next_in++;
|
||||
|
||||
/* skip rest of header */
|
||||
if (NEXT() != 8) { /* compression method */
|
||||
gz_error(state, Z_DATA_ERROR, "unknown compression method");
|
||||
return -1;
|
||||
}
|
||||
flags = NEXT();
|
||||
if (flags & 0xe0) { /* reserved flag bits */
|
||||
gz_error(state, Z_DATA_ERROR, "unknown header flags set");
|
||||
return -1;
|
||||
}
|
||||
NEXT(); /* modification time */
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT();
|
||||
NEXT(); /* extra flags */
|
||||
NEXT(); /* operating system */
|
||||
if (flags & 4) { /* extra field */
|
||||
len = (unsigned)NEXT();
|
||||
len += (unsigned)NEXT() << 8;
|
||||
while (len--)
|
||||
if (NEXT() < 0)
|
||||
break;
|
||||
}
|
||||
if (flags & 8) /* file name */
|
||||
while (NEXT() > 0)
|
||||
;
|
||||
if (flags & 16) /* comment */
|
||||
while (NEXT() > 0)
|
||||
;
|
||||
if (flags & 2) { /* header crc */
|
||||
NEXT();
|
||||
NEXT();
|
||||
}
|
||||
|
||||
/* set up for decompression */
|
||||
inflateReset(strm);
|
||||
strm->adler = crc32(0L, Z_NULL, 0);
|
||||
state->how = 2;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
/* not a gzip file -- save first byte (31) and fall to raw i/o */
|
||||
state->out[0] = 31;
|
||||
state->have = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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
|
||||
the input buffer */
|
||||
state->raw = state->pos;
|
||||
state->next = state->out;
|
||||
if (strm->avail_in) {
|
||||
memcpy(state->next + state->have, strm->next_in, strm->avail_in);
|
||||
state->have += strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
}
|
||||
state->how = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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
|
||||
check value and length (modulo 2^32). state->have and state->next are
|
||||
set 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
|
||||
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
|
||||
trailer verification. */
|
||||
local int gz_decomp(state)
|
||||
gz_statep state;
|
||||
{
|
||||
int ret;
|
||||
unsigned had;
|
||||
unsigned long crc, len;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* fill output buffer up to end of deflate stream */
|
||||
had = strm->avail_out;
|
||||
do {
|
||||
/* get more input for inflate() */
|
||||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0) {
|
||||
gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* decompress and handle errors */
|
||||
ret = inflate(strm, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
||||
gz_error(state, Z_STREAM_ERROR,
|
||||
"internal error: inflate stream corrupt");
|
||||
return -1;
|
||||
}
|
||||
if (ret == Z_MEM_ERROR) {
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
|
||||
gz_error(state, Z_DATA_ERROR,
|
||||
strm->msg == NULL ? "compressed data error" : strm->msg);
|
||||
return -1;
|
||||
}
|
||||
} while (strm->avail_out && ret != Z_STREAM_END);
|
||||
|
||||
/* update available output and crc check value */
|
||||
state->have = had - strm->avail_out;
|
||||
state->next = strm->next_out - state->have;
|
||||
strm->adler = crc32(strm->adler, state->next, state->have);
|
||||
|
||||
/* check gzip trailer if at end of deflate stream */
|
||||
if (ret == Z_STREAM_END) {
|
||||
if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
|
||||
gz_error(state, Z_DATA_ERROR, "unexpected end of file");
|
||||
return -1;
|
||||
}
|
||||
if (crc != strm->adler) {
|
||||
gz_error(state, Z_DATA_ERROR, "incorrect data check");
|
||||
return -1;
|
||||
}
|
||||
if (len != (strm->total_out & 0xffffffffL)) {
|
||||
gz_error(state, Z_DATA_ERROR, "incorrect length check");
|
||||
return -1;
|
||||
}
|
||||
state->how = 0; /* ready for next stream, once have is 0 */
|
||||
}
|
||||
|
||||
/* good decompression */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make data and put in the output buffer. Assumes that state->have == 0.
|
||||
Data is either copied from the input file or decompressed from the input
|
||||
file depending on state->how. If state->how is zero, then a gzip header is
|
||||
looked for (and skipped if found) to determine wither to copy or decompress.
|
||||
Returns -1 on error, otherwise 0. gz_make() will leave state->have non-zero
|
||||
unless the end of the input file has been reached and all data has been
|
||||
processed. */
|
||||
local int gz_make(state)
|
||||
gz_statep state;
|
||||
{
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
if (state->how == 0) { /* look for gzip header */
|
||||
if (gz_head(state) == -1)
|
||||
return -1;
|
||||
if (state->have) /* got some data from gz_head() */
|
||||
return 0;
|
||||
}
|
||||
if (state->how == 1) { /* straight copy */
|
||||
if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
|
||||
return -1;
|
||||
state->next = state->out;
|
||||
}
|
||||
else if (state->how == 2) { /* decompress */
|
||||
strm->avail_out = state->size << 1;
|
||||
strm->next_out = state->out;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
|
||||
local int gz_skip(state, len)
|
||||
gz_statep state;
|
||||
z_off_t len;
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||
while (len)
|
||||
/* skip over whatever is in output buffer */
|
||||
if (state->have) {
|
||||
n = state->have > len ? (unsigned)len : state->have;
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
len -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && state->strm.avail_in == 0)
|
||||
break;
|
||||
|
||||
/* need more data to skip -- load up output buffer */
|
||||
else {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_make(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzread(file, buf, len)
|
||||
gzFile file;
|
||||
voidp buf;
|
||||
unsigned len;
|
||||
{
|
||||
unsigned got, n;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get len bytes to buf, or less than len if at the end */
|
||||
got = 0;
|
||||
while (len) {
|
||||
|
||||
/* first just try copying data from the output buffer */
|
||||
if (state->have) {
|
||||
n = state->have > len ? len : state->have;
|
||||
memcpy(buf, state->next, n);
|
||||
state->next += n;
|
||||
state->have -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && strm->avail_in == 0)
|
||||
break;
|
||||
|
||||
/* need output data -- for small len or new stream load up our output
|
||||
buffer */
|
||||
else if (state->how == 0 || len < (state->size << 1)) {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_make(state) == -1)
|
||||
return -1;
|
||||
continue; /* no progress yet -- go back to memcpy() above */
|
||||
}
|
||||
|
||||
/* large len -- read directly into user buffer */
|
||||
else if (state->how == 1) { /* read directly */
|
||||
if (gz_load(state, buf, len, &n) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* large len -- decompress directly into user buffer */
|
||||
else { /* state->how == 2 */
|
||||
strm->avail_out = len;
|
||||
strm->next_out = buf;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
n = state->have;
|
||||
state->have = 0;
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
len -= n;
|
||||
buf += n;
|
||||
got += n;
|
||||
state->pos += n;
|
||||
}
|
||||
|
||||
/* return number of bytes read into user buffer */
|
||||
return (int)got; /* len had better fit in int -- interface flaw */
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzgetc(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[1];
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* try output buffer */
|
||||
if (state->have) {
|
||||
state->have--;
|
||||
state->pos++;
|
||||
return *(state->next)++;
|
||||
}
|
||||
|
||||
/* nothing there -- try gzread() */
|
||||
ret = gzread(file, buf, 1);
|
||||
return ret < 1 ? -1 : buf[0];
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzungetc(c, file)
|
||||
int c;
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* can't push EOF */
|
||||
if (c < 0)
|
||||
return -1;
|
||||
|
||||
/* if output buffer empty, put byte at end (allows more pushing) */
|
||||
if (state->have == 0) {
|
||||
state->have = 1;
|
||||
state->next = state->out + (state->size << 1) - 1;
|
||||
state->next[0] = c;
|
||||
state->pos--;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* if no room, give up (must have already done a gz_ungetc()) */
|
||||
if (state->have == (state->size << 1))
|
||||
return -1;
|
||||
|
||||
/* slide output data if needed and insert byte before existing data */
|
||||
if (state->next == state->out) {
|
||||
unsigned char *src = state->out + state->have;
|
||||
unsigned char *dest = state->out + (state->size << 1);
|
||||
while (src > state->out)
|
||||
*--dest = *--src;
|
||||
state->next = dest;
|
||||
}
|
||||
state->have++;
|
||||
state->next--;
|
||||
state->next[0] = c;
|
||||
state->pos--;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
char * ZEXPORT gzgets(file, buf, len)
|
||||
gzFile file;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
unsigned left, n;
|
||||
char *str;
|
||||
unsigned char *eol;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ || state->err != Z_OK)
|
||||
return NULL;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* check for a dumb length */
|
||||
if (len < 2)
|
||||
return NULL;
|
||||
|
||||
/* copy output bytes up to new line or len - 1, whichever comes first --
|
||||
append a terminating zero to the string (we don't check for a zero in
|
||||
the contents, let the user worry about that) */
|
||||
str = buf;
|
||||
left = (unsigned)len - 1;
|
||||
do {
|
||||
/* assure that something is in the output buffer */
|
||||
if (state->have == 0) {
|
||||
if (gz_make(state) == -1)
|
||||
return NULL; /* error */
|
||||
if (state->have == 0) { /* end of file */
|
||||
if (buf == str) /* got bupkus */
|
||||
return NULL;
|
||||
break; /* got something -- return it */
|
||||
}
|
||||
}
|
||||
|
||||
/* look for end-of-line in current output buffer */
|
||||
n = state->have > left ? left : state->have;
|
||||
eol = memchr(state->next, '\n', n);
|
||||
if (eol != NULL)
|
||||
n = (eol - state->next) + 1;
|
||||
|
||||
/* copy through end-of-line, or remainder if not found */
|
||||
memcpy(buf, state->next, n);
|
||||
state->have -= n;
|
||||
state->next += n;
|
||||
state->pos += n;
|
||||
left -= n;
|
||||
buf += n;
|
||||
} while (left && eol == NULL);
|
||||
|
||||
/* found end-of-line or out of space -- terminate string and return it */
|
||||
buf[0] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzdirect(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading */
|
||||
if (state->mode != GZ_READ)
|
||||
return 0;
|
||||
|
||||
/* return true if reading without decompression */
|
||||
return state->how == 1;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzclose_r(file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're reading */
|
||||
if (state->mode != GZ_READ)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* free memory and close file */
|
||||
if (state->size) {
|
||||
inflateEnd(&(state->strm));
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
}
|
||||
gz_error(state, Z_OK, NULL);
|
||||
close(state->fd);
|
||||
free(state);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
#endif /* !OLD_GZIO */
|
||||
529
gzwrite.c
Normal file
529
gzwrite.c
Normal file
@@ -0,0 +1,529 @@
|
||||
/* gzwrite.c -- zlib functions for writing gzip files
|
||||
* Copyright (C) 2004, 2005, 2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef OLD_GZIO
|
||||
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
local int gz_init OF((gz_statep));
|
||||
local int gz_comp OF((gz_statep, int));
|
||||
local int gz_zero OF((gz_statep, z_off_t));
|
||||
|
||||
/* Initialize state for writing a gzip file. Mark initialization by setting
|
||||
state->size to non-zero. Return -1 on failure or 0 on success. */
|
||||
local int gz_init(state)
|
||||
gz_statep state;
|
||||
{
|
||||
int ret;
|
||||
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 */
|
||||
state->in = malloc(state->want);
|
||||
state->out = malloc(state->want);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
if (state->out != NULL)
|
||||
free(state->out);
|
||||
if (state->in != NULL)
|
||||
free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate deflate memory, set up for gzip compression */
|
||||
strm->zalloc = Z_NULL;
|
||||
strm->zfree = Z_NULL;
|
||||
strm->opaque = Z_NULL;
|
||||
ret = deflateInit2(strm, state->level, Z_DEFLATED,
|
||||
15 + 16, 8, state->strategy);
|
||||
if (ret != Z_OK) {
|
||||
free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mark state as initialized */
|
||||
state->size = state->want;
|
||||
|
||||
/* initialize write buffer */
|
||||
strm->avail_out = state->size;
|
||||
strm->next_out = state->out;
|
||||
state->next = strm->next_out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compress whatever is at avail_in and next_in and write to the output file.
|
||||
Return -1 if there is an error writing to the output file, otherwise 0.
|
||||
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
|
||||
then the deflate() state is reset to start a new gzip stream. */
|
||||
local int gz_comp(state, flush)
|
||||
gz_statep state;
|
||||
int flush;
|
||||
{
|
||||
int ret;
|
||||
unsigned have;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* allocate memory if this is the first time through */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return -1;
|
||||
|
||||
/* run deflate() on provided input until it produces no more output */
|
||||
ret = Z_OK;
|
||||
do {
|
||||
/* write out current buffer contents if full, or if flushing, but if
|
||||
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
||||
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||
have = strm->next_out - state->next;
|
||||
if (have && write(state->fd, state->next, have) != have) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
if (strm->avail_out == 0) {
|
||||
strm->avail_out = state->size;
|
||||
strm->next_out = state->out;
|
||||
}
|
||||
state->next = strm->next_out;
|
||||
}
|
||||
|
||||
/* compress */
|
||||
have = strm->avail_out;
|
||||
ret = deflate(strm, flush);
|
||||
if (ret == Z_STREAM_ERROR) {
|
||||
gz_error(state, Z_STREAM_ERROR,
|
||||
"internal error: deflate stream corrupt");
|
||||
return -1;
|
||||
}
|
||||
have -= strm->avail_out;
|
||||
} while (have);
|
||||
|
||||
/* if that completed a deflate stream, allow another to start */
|
||||
if (flush == Z_FINISH)
|
||||
deflateReset(strm);
|
||||
|
||||
/* all done, no errors */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compress len zeros to output. Return -1 on error, 0 on success. */
|
||||
local int gz_zero(state, len)
|
||||
gz_statep state;
|
||||
z_off_t len;
|
||||
{
|
||||
int first;
|
||||
unsigned n;
|
||||
z_streamp strm = &(state->strm);
|
||||
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
|
||||
/* compress len zeros */
|
||||
first = 1;
|
||||
while (len) {
|
||||
n = len < state->size ? (unsigned)len : state->size;
|
||||
if (first) {
|
||||
memset(state->in, 0, n);
|
||||
first = 0;
|
||||
}
|
||||
strm->avail_in = n;
|
||||
strm->next_in = state->in;
|
||||
state->pos += n;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
len -= n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzwrite(file, buf, len)
|
||||
gzFile file;
|
||||
voidpc buf;
|
||||
unsigned len;
|
||||
{
|
||||
unsigned put = len;
|
||||
unsigned n;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* allocate memory if this is the first time through */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return -1;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* for small len, copy to input buffer, otherwise compress directly */
|
||||
if (len < state->size) {
|
||||
/* copy to input buffer, compress when full */
|
||||
while (len) {
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
n = state->size - strm->avail_in;
|
||||
if (n > len)
|
||||
n = len;
|
||||
memcpy(strm->next_in + strm->avail_in, buf, n);
|
||||
strm->avail_in += n;
|
||||
state->pos += n;
|
||||
buf += n;
|
||||
len -= n;
|
||||
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
|
||||
/* directly compress user buffer to file */
|
||||
strm->avail_in = len;
|
||||
strm->next_in = (voidp)buf;
|
||||
state->pos += len;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* input was all buffered or compressed */
|
||||
return (int)put;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputc(file, c)
|
||||
gzFile file;
|
||||
int c;
|
||||
{
|
||||
unsigned char buf[1];
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return -1;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* try writing to input buffer for speed (state->size == 0 if buffer not
|
||||
initialized) */
|
||||
if (strm->avail_in < state->size) {
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
strm->next_in[strm->avail_in++] = c;
|
||||
state->pos++;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* no room in buffer or not initialized, use gz_write() */
|
||||
buf[0] = c;
|
||||
if (gzwrite(file, buf, 1) != 1)
|
||||
return -1;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputs(file, str)
|
||||
gzFile file;
|
||||
const char *str;
|
||||
{
|
||||
/* write string */
|
||||
return gzwrite(file, str, strlen(str));
|
||||
}
|
||||
|
||||
#ifdef STDC
|
||||
#include <stdarg.h>
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
|
||||
{
|
||||
int size, len;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
va_list va;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
||||
/* make sure we have some buffer space */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return 0;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
|
||||
/* do the printf() into the input buffer, put length in len */
|
||||
size = (int)(state->size);
|
||||
state->in[size - 1] = 0;
|
||||
va_start(va, format);
|
||||
#ifdef NO_vsnprintf
|
||||
# ifdef HAS_vsprintf_void
|
||||
(void)vsprintf(state->in, format, va);
|
||||
va_end(va);
|
||||
for (len = 0; len < state->in; len++)
|
||||
if (state->in[len] == 0) break;
|
||||
# else
|
||||
len = vsprintf(state->in, format, va);
|
||||
va_end(va);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_vsnprintf_void
|
||||
(void)vsnprintf(state->in, size, format, va);
|
||||
va_end(va);
|
||||
len = strlen(state->in);
|
||||
# else
|
||||
len = vsnprintf((char *)(state->in), size, format, va);
|
||||
va_end(va);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* check that printf() results fit in buffer */
|
||||
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
|
||||
return 0;
|
||||
|
||||
/* write out result of printf() */
|
||||
strm->avail_in = (unsigned)len;
|
||||
strm->next_in = state->in;
|
||||
state->pos += len;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
#else /* !STDC */
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
gzFile file;
|
||||
const char *format;
|
||||
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
||||
{
|
||||
int size, len;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return 0;
|
||||
|
||||
/* make sure we have some buffer space */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return 0;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
|
||||
/* do the printf() into the input buffer, put length in len */
|
||||
size = (int)(state->size);
|
||||
state->in[size - 1] = 0;
|
||||
#ifdef NO_snprintf
|
||||
# ifdef HAS_sprintf_void
|
||||
sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
for (len = 0; len < size; len++)
|
||||
if (state->in[len] == 0) break;
|
||||
# else
|
||||
len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_snprintf_void
|
||||
snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
len = strlen(state->in);
|
||||
# else
|
||||
len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* check that printf() results fit in buffer */
|
||||
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
|
||||
return 0;
|
||||
|
||||
/* write out result of printf() */
|
||||
strm->avail_in = (unsigned)len;
|
||||
strm->next_in = state->in;
|
||||
state->pos += len;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzflush(file, flush)
|
||||
gzFile file;
|
||||
int flush;
|
||||
{
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE|| state->err != Z_OK)
|
||||
|
||||
/* check flush parameter */
|
||||
if (flush < 0 || flush > Z_FINISH)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* compress remaining data with requested flush */
|
||||
gz_comp(state, flush);
|
||||
return state->err;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzsetparams(file, level, strategy)
|
||||
gzFile file;
|
||||
int level;
|
||||
int strategy;
|
||||
{
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* if no change is requested, then do nothing */
|
||||
if (level == state->level && strategy == state->strategy)
|
||||
return Z_OK;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* change compression parameters for subsequent input */
|
||||
if (state->size) {
|
||||
/* flush previous input with previous parameters before changing */
|
||||
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
|
||||
return state->err;
|
||||
deflateParams(strm, level, strategy);
|
||||
}
|
||||
state->level = level;
|
||||
state->strategy = strategy;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzclose_w(file)
|
||||
gzFile file;
|
||||
{
|
||||
int ret;
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
|
||||
/* check that we're writing */
|
||||
if (state->mode != GZ_WRITE)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* flush, free memory, and close file */
|
||||
ret = gz_comp(state, Z_FINISH);
|
||||
deflateEnd(&(state->strm));
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
ret += close(state->fd);
|
||||
gz_error(state, Z_OK, NULL);
|
||||
free(state);
|
||||
return ret ? Z_ERRNO : Z_OK;
|
||||
}
|
||||
|
||||
#endif /* !OLD_GZIO */
|
||||
93
infback.c
93
infback.c
@@ -1,5 +1,5 @@
|
||||
/* infback.c -- inflate using a call-back interface
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* Copyright (C) 1995-2009 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,7 @@ int stream_size;
|
||||
state->wbits = windowBits;
|
||||
state->wsize = 1U << windowBits;
|
||||
state->window = window;
|
||||
state->write = 0;
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void FAR *out_desc;
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
code this; /* current decoding table entry */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
@@ -389,19 +389,19 @@ void FAR *out_desc;
|
||||
state->have = 0;
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.val < 16) {
|
||||
NEEDBITS(this.bits);
|
||||
DROPBITS(this.bits);
|
||||
state->lens[state->have++] = this.val;
|
||||
if (here.val < 16) {
|
||||
NEEDBITS(here.bits);
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
else {
|
||||
if (this.val == 16) {
|
||||
NEEDBITS(this.bits + 2);
|
||||
DROPBITS(this.bits);
|
||||
if (here.val == 16) {
|
||||
NEEDBITS(here.bits + 2);
|
||||
DROPBITS(here.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
@@ -411,16 +411,16 @@ void FAR *out_desc;
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (this.val == 17) {
|
||||
NEEDBITS(this.bits + 3);
|
||||
DROPBITS(this.bits);
|
||||
else if (here.val == 17) {
|
||||
NEEDBITS(here.bits + 3);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
NEEDBITS(this.bits + 7);
|
||||
DROPBITS(this.bits);
|
||||
NEEDBITS(here.bits + 7);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 11 + BITS(7);
|
||||
DROPBITS(7);
|
||||
@@ -438,7 +438,16 @@ void FAR *out_desc;
|
||||
/* handle error breaks in while */
|
||||
if (state->mode == BAD) break;
|
||||
|
||||
/* build code tables */
|
||||
/* check for end-of-block code (better have one) */
|
||||
if (state->lens[256] == 0) {
|
||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
@@ -474,28 +483,28 @@ void FAR *out_desc;
|
||||
|
||||
/* get a literal, length, or end-of-block code */
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.op && (this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if (here.op && (here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = state->lencode[last.val +
|
||||
here = state->lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
state->length = (unsigned)this.val;
|
||||
DROPBITS(here.bits);
|
||||
state->length = (unsigned)here.val;
|
||||
|
||||
/* process literal */
|
||||
if (this.op == 0) {
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
if (here.op == 0) {
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
ROOM();
|
||||
*put++ = (unsigned char)(state->length);
|
||||
left--;
|
||||
@@ -504,21 +513,21 @@ void FAR *out_desc;
|
||||
}
|
||||
|
||||
/* process end of block */
|
||||
if (this.op & 32) {
|
||||
if (here.op & 32) {
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* invalid code */
|
||||
if (this.op & 64) {
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* length code -- get extra bits, if any */
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->length += BITS(state->extra);
|
||||
@@ -528,30 +537,30 @@ void FAR *out_desc;
|
||||
|
||||
/* get distance code */
|
||||
for (;;) {
|
||||
this = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if ((here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = state->distcode[last.val +
|
||||
here = state->distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
if (this.op & 64) {
|
||||
DROPBITS(here.bits);
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->offset = (unsigned)this.val;
|
||||
state->offset = (unsigned)here.val;
|
||||
|
||||
/* get distance extra bits, if any */
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
NEEDBITS(state->extra);
|
||||
state->offset += BITS(state->extra);
|
||||
|
||||
78
inffast.c
78
inffast.c
@@ -1,5 +1,5 @@
|
||||
/* inffast.c -- fast decoding
|
||||
* Copyright (C) 1995-2004 Mark Adler
|
||||
* Copyright (C) 1995-2008 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
#endif
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned write; /* window write index */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||
unsigned long hold; /* local strm->hold */
|
||||
unsigned bits; /* local strm->bits */
|
||||
@@ -87,7 +87,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
code const FAR *dcode; /* local strm->distcode */
|
||||
unsigned lmask; /* mask for first level of length codes */
|
||||
unsigned dmask; /* mask for first level of distance codes */
|
||||
code this; /* retrieved table entry */
|
||||
code here; /* retrieved table entry */
|
||||
unsigned op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
unsigned len; /* match length, unused bytes */
|
||||
@@ -106,7 +106,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
#endif
|
||||
wsize = state->wsize;
|
||||
whave = state->whave;
|
||||
write = state->write;
|
||||
wnext = state->wnext;
|
||||
window = state->window;
|
||||
hold = state->hold;
|
||||
bits = state->bits;
|
||||
@@ -124,20 +124,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
this = lcode[hold & lmask];
|
||||
here = lcode[hold & lmask];
|
||||
dolen:
|
||||
op = (unsigned)(this.bits);
|
||||
op = (unsigned)(here.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(this.op);
|
||||
op = (unsigned)(here.op);
|
||||
if (op == 0) { /* literal */
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
PUP(out) = (unsigned char)(this.val);
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
PUP(out) = (unsigned char)(here.val);
|
||||
}
|
||||
else if (op & 16) { /* length base */
|
||||
len = (unsigned)(this.val);
|
||||
len = (unsigned)(here.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (op) {
|
||||
if (bits < op) {
|
||||
@@ -155,14 +155,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
bits += 8;
|
||||
}
|
||||
this = dcode[hold & dmask];
|
||||
here = dcode[hold & dmask];
|
||||
dodist:
|
||||
op = (unsigned)(this.bits);
|
||||
op = (unsigned)(here.bits);
|
||||
hold >>= op;
|
||||
bits -= op;
|
||||
op = (unsigned)(this.op);
|
||||
op = (unsigned)(here.op);
|
||||
if (op & 16) { /* distance base */
|
||||
dist = (unsigned)(this.val);
|
||||
dist = (unsigned)(here.val);
|
||||
op &= 15; /* number of extra bits */
|
||||
if (bits < op) {
|
||||
hold += (unsigned long)(PUP(in)) << bits;
|
||||
@@ -187,12 +187,34 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
if (state->sane) {
|
||||
strm->msg =
|
||||
(char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
if (len <= op - whave) {
|
||||
do {
|
||||
PUP(out) = 0;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
len -= op - whave;
|
||||
do {
|
||||
PUP(out) = 0;
|
||||
} while (--op > whave);
|
||||
if (op == 0) {
|
||||
from = out - dist;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
from = window - OFF;
|
||||
if (write == 0) { /* very common case */
|
||||
if (wnext == 0) { /* very common case */
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
@@ -202,17 +224,17 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
from = out - dist; /* rest from output */
|
||||
}
|
||||
}
|
||||
else if (write < op) { /* wrap around window */
|
||||
from += wsize + write - op;
|
||||
op -= write;
|
||||
else if (wnext < op) { /* wrap around window */
|
||||
from += wsize + wnext - op;
|
||||
op -= wnext;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
} while (--op);
|
||||
from = window - OFF;
|
||||
if (write < len) { /* some from start of window */
|
||||
op = write;
|
||||
if (wnext < len) { /* some from start of window */
|
||||
op = wnext;
|
||||
len -= op;
|
||||
do {
|
||||
PUP(out) = PUP(from);
|
||||
@@ -222,7 +244,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
}
|
||||
}
|
||||
else { /* contiguous in window */
|
||||
from += write - op;
|
||||
from += wnext - op;
|
||||
if (op < len) { /* some from window */
|
||||
len -= op;
|
||||
do {
|
||||
@@ -259,7 +281,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||
this = dcode[this.val + (hold & ((1U << op) - 1))];
|
||||
here = dcode[here.val + (hold & ((1U << op) - 1))];
|
||||
goto dodist;
|
||||
}
|
||||
else {
|
||||
@@ -269,7 +291,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
}
|
||||
}
|
||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||
this = lcode[this.val + (hold & ((1U << op) - 1))];
|
||||
here = lcode[here.val + (hold & ((1U << op) - 1))];
|
||||
goto dolen;
|
||||
}
|
||||
else if (op & 32) { /* end-of-block */
|
||||
@@ -305,7 +327,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||
- Using bit fields for code structure
|
||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||
- Three separate decoding do-loops for direct, window, and write == 0
|
||||
- Three separate decoding do-loops for direct, window, and wnext == 0
|
||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||
- Explicit branch predictions (based on measured branch probabilities)
|
||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||
|
||||
282
inflate.c
282
inflate.c
@@ -1,5 +1,5 @@
|
||||
/* inflate.c -- zlib decompression
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* Copyright (C) 1995-2009 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
* - Rearrange window copies in inflate_fast() for speed and simplification
|
||||
* - Unroll last copy for window match in inflate_fast()
|
||||
* - Use local copies of window variables in inflate_fast() for speed
|
||||
* - Pull out common write == 0 case for speed in inflate_fast()
|
||||
* - Pull out common wnext == 0 case for speed in inflate_fast()
|
||||
* - Make op and len in inflate_fast() unsigned for consistency
|
||||
* - Add FAR to lcode and dcode declarations in inflate_fast()
|
||||
* - Simplified bad distance check in inflate_fast()
|
||||
@@ -117,28 +117,52 @@ z_streamp strm;
|
||||
state->head = Z_NULL;
|
||||
state->wsize = 0;
|
||||
state->whave = 0;
|
||||
state->write = 0;
|
||||
state->wnext = 0;
|
||||
state->hold = 0;
|
||||
state->bits = 0;
|
||||
state->lencode = state->distcode = state->next = state->codes;
|
||||
state->sane = 1;
|
||||
state->back = -1;
|
||||
Tracev((stderr, "inflate: reset\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflatePrime(strm, bits, value)
|
||||
int ZEXPORT inflateReset2(strm, windowBits)
|
||||
z_streamp strm;
|
||||
int bits;
|
||||
int value;
|
||||
int windowBits;
|
||||
{
|
||||
int wrap;
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
/* get the state */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
|
||||
value &= (1L << bits) - 1;
|
||||
state->hold += value << state->bits;
|
||||
state->bits += bits;
|
||||
return Z_OK;
|
||||
|
||||
/* extract wrap request from windowBits parameter */
|
||||
if (windowBits < 0) {
|
||||
wrap = 0;
|
||||
windowBits = -windowBits;
|
||||
}
|
||||
else {
|
||||
wrap = (windowBits >> 4) + 1;
|
||||
#ifdef GUNZIP
|
||||
if (windowBits < 48)
|
||||
windowBits &= 15;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* set number of window bits, free window if different */
|
||||
if (windowBits && (windowBits < 8 || windowBits > 15))
|
||||
return Z_STREAM_ERROR;
|
||||
if (state->wbits != windowBits && state->window != Z_NULL) {
|
||||
ZFREE(strm, state->window);
|
||||
state->window = Z_NULL;
|
||||
}
|
||||
|
||||
/* update state and reset the rest of it */
|
||||
state->wrap = wrap;
|
||||
state->wbits = (unsigned)windowBits;
|
||||
return inflateReset(strm);
|
||||
}
|
||||
|
||||
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
|
||||
@@ -147,6 +171,7 @@ int windowBits;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
int ret;
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
@@ -164,24 +189,13 @@ int stream_size;
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
strm->state = (struct internal_state FAR *)state;
|
||||
if (windowBits < 0) {
|
||||
state->wrap = 0;
|
||||
windowBits = -windowBits;
|
||||
}
|
||||
else {
|
||||
state->wrap = (windowBits >> 4) + 1;
|
||||
#ifdef GUNZIP
|
||||
if (windowBits < 48) windowBits &= 15;
|
||||
#endif
|
||||
}
|
||||
if (windowBits < 8 || windowBits > 15) {
|
||||
state->window = Z_NULL;
|
||||
ret = inflateReset2(strm, windowBits);
|
||||
if (ret != Z_OK) {
|
||||
ZFREE(strm, state);
|
||||
strm->state = Z_NULL;
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
state->wbits = (unsigned)windowBits;
|
||||
state->window = Z_NULL;
|
||||
return inflateReset(strm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateInit_(strm, version, stream_size)
|
||||
@@ -192,6 +206,27 @@ int stream_size;
|
||||
return inflateInit2_(strm, DEF_WBITS, version, stream_size);
|
||||
}
|
||||
|
||||
int ZEXPORT inflatePrime(strm, bits, value)
|
||||
z_streamp strm;
|
||||
int bits;
|
||||
int value;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
if (bits < 0) {
|
||||
state->hold = 0;
|
||||
state->bits = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
|
||||
value &= (1L << bits) - 1;
|
||||
state->hold += value << state->bits;
|
||||
state->bits += bits;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
Return state with length and distance decoding tables and index sizes set to
|
||||
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
||||
@@ -340,7 +375,7 @@ unsigned out;
|
||||
/* if window not in use yet, initialize */
|
||||
if (state->wsize == 0) {
|
||||
state->wsize = 1U << state->wbits;
|
||||
state->write = 0;
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
}
|
||||
|
||||
@@ -348,22 +383,22 @@ unsigned out;
|
||||
copy = out - strm->avail_out;
|
||||
if (copy >= state->wsize) {
|
||||
zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
|
||||
state->write = 0;
|
||||
state->wnext = 0;
|
||||
state->whave = state->wsize;
|
||||
}
|
||||
else {
|
||||
dist = state->wsize - state->write;
|
||||
dist = state->wsize - state->wnext;
|
||||
if (dist > copy) dist = copy;
|
||||
zmemcpy(state->window + state->write, strm->next_out - copy, dist);
|
||||
zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
|
||||
copy -= dist;
|
||||
if (copy) {
|
||||
zmemcpy(state->window, strm->next_out - copy, copy);
|
||||
state->write = copy;
|
||||
state->wnext = copy;
|
||||
state->whave = state->wsize;
|
||||
}
|
||||
else {
|
||||
state->write += dist;
|
||||
if (state->write == state->wsize) state->write = 0;
|
||||
state->wnext += dist;
|
||||
if (state->wnext == state->wsize) state->wnext = 0;
|
||||
if (state->whave < state->wsize) state->whave += dist;
|
||||
}
|
||||
}
|
||||
@@ -564,7 +599,7 @@ int flush;
|
||||
unsigned in, out; /* save starting available input and output */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
code this; /* current decoding table entry */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
@@ -619,7 +654,9 @@ int flush;
|
||||
}
|
||||
DROPBITS(4);
|
||||
len = BITS(4) + 8;
|
||||
if (len > state->wbits) {
|
||||
if (state->wbits == 0)
|
||||
state->wbits = len;
|
||||
else if (len > state->wbits) {
|
||||
strm->msg = (char *)"invalid window size";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
@@ -771,7 +808,7 @@ int flush;
|
||||
strm->adler = state->check = adler32(0L, Z_NULL, 0);
|
||||
state->mode = TYPE;
|
||||
case TYPE:
|
||||
if (flush == Z_BLOCK) goto inf_leave;
|
||||
if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
|
||||
case TYPEDO:
|
||||
if (state->last) {
|
||||
BYTEBITS();
|
||||
@@ -791,7 +828,11 @@ int flush;
|
||||
fixedtables(state);
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
state->mode = LEN; /* decode codes */
|
||||
state->mode = LEN_; /* decode codes */
|
||||
if (flush == Z_TREES) {
|
||||
DROPBITS(2);
|
||||
goto inf_leave;
|
||||
}
|
||||
break;
|
||||
case 2: /* dynamic block */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
@@ -816,6 +857,9 @@ int flush;
|
||||
Tracev((stderr, "inflate: stored length %u\n",
|
||||
state->length));
|
||||
INITBITS();
|
||||
state->mode = COPY_;
|
||||
if (flush == Z_TREES) goto inf_leave;
|
||||
case COPY_:
|
||||
state->mode = COPY;
|
||||
case COPY:
|
||||
copy = state->length;
|
||||
@@ -876,19 +920,19 @@ int flush;
|
||||
case CODELENS:
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.val < 16) {
|
||||
NEEDBITS(this.bits);
|
||||
DROPBITS(this.bits);
|
||||
state->lens[state->have++] = this.val;
|
||||
if (here.val < 16) {
|
||||
NEEDBITS(here.bits);
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
else {
|
||||
if (this.val == 16) {
|
||||
NEEDBITS(this.bits + 2);
|
||||
DROPBITS(this.bits);
|
||||
if (here.val == 16) {
|
||||
NEEDBITS(here.bits + 2);
|
||||
DROPBITS(here.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
@@ -898,16 +942,16 @@ int flush;
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (this.val == 17) {
|
||||
NEEDBITS(this.bits + 3);
|
||||
DROPBITS(this.bits);
|
||||
else if (here.val == 17) {
|
||||
NEEDBITS(here.bits + 3);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
NEEDBITS(this.bits + 7);
|
||||
DROPBITS(this.bits);
|
||||
NEEDBITS(here.bits + 7);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 11 + BITS(7);
|
||||
DROPBITS(7);
|
||||
@@ -925,7 +969,16 @@ int flush;
|
||||
/* handle error breaks in while */
|
||||
if (state->mode == BAD) break;
|
||||
|
||||
/* build code tables */
|
||||
/* check for end-of-block code (better have one) */
|
||||
if (state->lens[256] == 0) {
|
||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
@@ -946,88 +999,102 @@ int flush;
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: codes ok\n"));
|
||||
state->mode = LEN_;
|
||||
if (flush == Z_TREES) goto inf_leave;
|
||||
case LEN_:
|
||||
state->mode = LEN;
|
||||
case LEN:
|
||||
if (have >= 6 && left >= 258) {
|
||||
RESTORE();
|
||||
inflate_fast(strm, out);
|
||||
LOAD();
|
||||
if (state->mode == TYPE)
|
||||
state->back = -1;
|
||||
break;
|
||||
}
|
||||
state->back = 0;
|
||||
for (;;) {
|
||||
this = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (this.op && (this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if (here.op && (here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = state->lencode[last.val +
|
||||
here = state->lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
state->back += last.bits;
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
state->length = (unsigned)this.val;
|
||||
if ((int)(this.op) == 0) {
|
||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||
DROPBITS(here.bits);
|
||||
state->back += here.bits;
|
||||
state->length = (unsigned)here.val;
|
||||
if ((int)(here.op) == 0) {
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", this.val));
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
state->mode = LIT;
|
||||
break;
|
||||
}
|
||||
if (this.op & 32) {
|
||||
if (here.op & 32) {
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->back = -1;
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
if (this.op & 64) {
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
state->mode = LENEXT;
|
||||
case LENEXT:
|
||||
if (state->extra) {
|
||||
NEEDBITS(state->extra);
|
||||
state->length += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
state->back += state->extra;
|
||||
}
|
||||
Tracevv((stderr, "inflate: length %u\n", state->length));
|
||||
state->was = state->length;
|
||||
state->mode = DIST;
|
||||
case DIST:
|
||||
for (;;) {
|
||||
this = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(this.bits) <= bits) break;
|
||||
here = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((this.op & 0xf0) == 0) {
|
||||
last = this;
|
||||
if ((here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
this = state->distcode[last.val +
|
||||
here = state->distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + this.bits) <= bits) break;
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
state->back += last.bits;
|
||||
}
|
||||
DROPBITS(this.bits);
|
||||
if (this.op & 64) {
|
||||
DROPBITS(here.bits);
|
||||
state->back += here.bits;
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
state->offset = (unsigned)this.val;
|
||||
state->extra = (unsigned)(this.op) & 15;
|
||||
state->offset = (unsigned)here.val;
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
state->mode = DISTEXT;
|
||||
case DISTEXT:
|
||||
if (state->extra) {
|
||||
NEEDBITS(state->extra);
|
||||
state->offset += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
state->back += state->extra;
|
||||
}
|
||||
#ifdef INFLATE_STRICT
|
||||
if (state->offset > state->dmax) {
|
||||
@@ -1036,11 +1103,6 @@ int flush;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (state->offset > state->whave + out - left) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
Tracevv((stderr, "inflate: distance %u\n", state->offset));
|
||||
state->mode = MATCH;
|
||||
case MATCH:
|
||||
@@ -1048,12 +1110,32 @@ int flush;
|
||||
copy = out - left;
|
||||
if (state->offset > copy) { /* copy from window */
|
||||
copy = state->offset - copy;
|
||||
if (copy > state->write) {
|
||||
copy -= state->write;
|
||||
if (copy > state->whave) {
|
||||
if (state->sane) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
break;
|
||||
}
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
Trace((stderr, "inflate.c too far\n"));
|
||||
copy -= state->whave;
|
||||
if (copy > state->length) copy = state->length;
|
||||
if (copy > left) copy = left;
|
||||
left -= copy;
|
||||
state->length -= copy;
|
||||
do {
|
||||
*put++ = 0;
|
||||
} while (--copy);
|
||||
if (state->length == 0) state->mode = LEN;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (copy > state->wnext) {
|
||||
copy -= state->wnext;
|
||||
from = state->window + (state->wsize - copy);
|
||||
}
|
||||
else
|
||||
from = state->window + (state->write - copy);
|
||||
from = state->window + (state->wnext - copy);
|
||||
if (copy > state->length) copy = state->length;
|
||||
}
|
||||
else { /* copy from output */
|
||||
@@ -1146,7 +1228,8 @@ int flush;
|
||||
strm->adler = state->check =
|
||||
UPDATE(state->check, strm->next_out - out, out);
|
||||
strm->data_type = state->bits + (state->last ? 64 : 0) +
|
||||
(state->mode == TYPE ? 128 : 0);
|
||||
(state->mode == TYPE ? 128 : 0) +
|
||||
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
|
||||
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
|
||||
ret = Z_BUF_ERROR;
|
||||
return ret;
|
||||
@@ -1366,3 +1449,32 @@ z_streamp source;
|
||||
dest->state = (struct internal_state FAR *)copy;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateUndermine(strm, subvert)
|
||||
z_streamp strm;
|
||||
int subvert;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
state->sane = !subvert;
|
||||
return Z_OK;
|
||||
#else
|
||||
state->sane = 1;
|
||||
return Z_DATA_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
long ZEXPORT inflateMark(strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
return ((long)(state->back) << 16) +
|
||||
(state->mode == COPY ? state->length :
|
||||
(state->mode == MATCH ? state->was - state->length : 0));
|
||||
}
|
||||
|
||||
29
inflate.h
29
inflate.h
@@ -1,5 +1,5 @@
|
||||
/* inflate.h -- internal inflate state definition
|
||||
* Copyright (C) 1995-2006 Mark Adler
|
||||
* Copyright (C) 1995-2009 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -32,11 +32,13 @@ typedef enum {
|
||||
TYPE, /* i: waiting for type bits, including last-flag bit */
|
||||
TYPEDO, /* i: same, but skip check to exit inflate on new block */
|
||||
STORED, /* i: waiting for stored size (length and complement) */
|
||||
COPY_, /* i/o: same as COPY below, but only first time in */
|
||||
COPY, /* i/o: waiting for input or output to copy stored block */
|
||||
TABLE, /* i: waiting for dynamic block table lengths */
|
||||
LENLENS, /* i: waiting for code length code lengths */
|
||||
CODELENS, /* i: waiting for length/lit and distance code lengths */
|
||||
LEN, /* i: waiting for length/lit code */
|
||||
LEN_, /* i: same as LEN below, but only first time in */
|
||||
LEN, /* i: waiting for length/lit/eob code */
|
||||
LENEXT, /* i: waiting for length extra bits */
|
||||
DIST, /* i: waiting for distance code */
|
||||
DISTEXT, /* i: waiting for distance extra bits */
|
||||
@@ -53,19 +55,21 @@ typedef enum {
|
||||
/*
|
||||
State transitions between above modes -
|
||||
|
||||
(most modes can go to the BAD or MEM mode -- not shown for clarity)
|
||||
(most modes can go to BAD or MEM on error -- not shown for clarity)
|
||||
|
||||
Process header:
|
||||
HEAD -> (gzip) or (zlib)
|
||||
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
|
||||
NAME -> COMMENT -> HCRC -> TYPE
|
||||
HEAD -> (gzip) or (zlib) or (raw)
|
||||
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
|
||||
HCRC -> TYPE
|
||||
(zlib) -> DICTID or TYPE
|
||||
DICTID -> DICT -> TYPE
|
||||
(raw) -> TYPEDO
|
||||
Read deflate blocks:
|
||||
TYPE -> STORED or TABLE or LEN or CHECK
|
||||
STORED -> COPY -> TYPE
|
||||
TABLE -> LENLENS -> CODELENS -> LEN
|
||||
Read deflate codes:
|
||||
TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
|
||||
STORED -> COPY_ -> COPY -> TYPE
|
||||
TABLE -> LENLENS -> CODELENS -> LEN_
|
||||
LEN_ -> LEN
|
||||
Read deflate codes in fixed or dynamic block:
|
||||
LEN -> LENEXT or LIT or TYPE
|
||||
LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
|
||||
LIT -> LEN
|
||||
@@ -88,7 +92,7 @@ struct inflate_state {
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned write; /* window write index */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
@@ -112,4 +116,7 @@ struct inflate_state {
|
||||
unsigned short lens[320]; /* temporary storage for code lengths */
|
||||
unsigned short work[288]; /* work area for code table building */
|
||||
code codes[ENOUGH]; /* space for code tables */
|
||||
int sane; /* if false, allow invalid distance too far */
|
||||
int back; /* bits back of last unprocessed length/lit */
|
||||
unsigned was; /* initial length of match */
|
||||
};
|
||||
|
||||
61
inftrees.c
61
inftrees.c
@@ -1,5 +1,5 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2005 Mark Adler
|
||||
* Copyright (C) 1995-2010 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define MAXBITS 15
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.2.3.1 Copyright 1995-2005 Mark Adler ";
|
||||
" inflate 1.2.3.5 Copyright 1995-2010 Mark Adler ";
|
||||
/*
|
||||
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
|
||||
@@ -50,7 +50,7 @@ unsigned short FAR *work;
|
||||
unsigned fill; /* index for replicating entries */
|
||||
unsigned low; /* low bits for current root entry */
|
||||
unsigned mask; /* mask for low root bits */
|
||||
code this; /* table entry for duplication */
|
||||
code here; /* table entry for duplication */
|
||||
code FAR *next; /* next available space in table */
|
||||
const unsigned short FAR *base; /* base value table to use */
|
||||
const unsigned short FAR *extra; /* extra bits table to use */
|
||||
@@ -62,7 +62,7 @@ unsigned short FAR *work;
|
||||
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 */
|
||||
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, 74, 196};
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 69, 199};
|
||||
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,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
@@ -115,15 +115,15 @@ unsigned short FAR *work;
|
||||
if (count[max] != 0) break;
|
||||
if (root > max) root = max;
|
||||
if (max == 0) { /* no symbols to code at all */
|
||||
this.op = (unsigned char)64; /* invalid code marker */
|
||||
this.bits = (unsigned char)1;
|
||||
this.val = (unsigned short)0;
|
||||
*(*table)++ = this; /* make a table to force an error */
|
||||
*(*table)++ = this;
|
||||
here.op = (unsigned char)64; /* invalid code marker */
|
||||
here.bits = (unsigned char)1;
|
||||
here.val = (unsigned short)0;
|
||||
*(*table)++ = here; /* make a table to force an error */
|
||||
*(*table)++ = here;
|
||||
*bits = 1;
|
||||
return 0; /* no symbols, but wait for decoding to report error */
|
||||
}
|
||||
for (min = 1; min <= MAXBITS; min++)
|
||||
for (min = 1; min < max; min++)
|
||||
if (count[min] != 0) break;
|
||||
if (root < min) root = min;
|
||||
|
||||
@@ -166,11 +166,10 @@ unsigned short FAR *work;
|
||||
entered in the tables.
|
||||
|
||||
used keeps track of how many table entries have been allocated from the
|
||||
provided *table space. It is checked when a LENS table is being made
|
||||
against the space in *table, ENOUGH, minus the maximum space needed by
|
||||
the worst case distance code, MAXD. This should never happen, but the
|
||||
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
|
||||
This assumes that when type == LENS, bits == 9.
|
||||
provided *table space. It is checked for LENS and DIST tables against
|
||||
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
|
||||
the initial root table size constants. See the comments in inftrees.h
|
||||
for more information.
|
||||
|
||||
sym increments through all symbols, and the loop terminates when
|
||||
all codes of length max, i.e. all codes, have been processed. This
|
||||
@@ -209,24 +208,25 @@ unsigned short FAR *work;
|
||||
mask = used - 1; /* mask for comparing low */
|
||||
|
||||
/* check available table space */
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* process all codes and make table entries */
|
||||
for (;;) {
|
||||
/* create table entry */
|
||||
this.bits = (unsigned char)(len - drop);
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
if ((int)(work[sym]) < end) {
|
||||
this.op = (unsigned char)0;
|
||||
this.val = work[sym];
|
||||
here.op = (unsigned char)0;
|
||||
here.val = work[sym];
|
||||
}
|
||||
else if ((int)(work[sym]) > end) {
|
||||
this.op = (unsigned char)(extra[work[sym]]);
|
||||
this.val = base[work[sym]];
|
||||
here.op = (unsigned char)(extra[work[sym]]);
|
||||
here.val = base[work[sym]];
|
||||
}
|
||||
else {
|
||||
this.op = (unsigned char)(32 + 64); /* end of block */
|
||||
this.val = 0;
|
||||
here.op = (unsigned char)(32 + 64); /* end of block */
|
||||
here.val = 0;
|
||||
}
|
||||
|
||||
/* replicate for those indices with low len bits equal to huff */
|
||||
@@ -235,7 +235,7 @@ unsigned short FAR *work;
|
||||
min = fill; /* save offset to next table */
|
||||
do {
|
||||
fill -= incr;
|
||||
next[(huff >> drop) + fill] = this;
|
||||
next[(huff >> drop) + fill] = here;
|
||||
} while (fill != 0);
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
@@ -277,7 +277,8 @@ unsigned short FAR *work;
|
||||
|
||||
/* check for enough space */
|
||||
used += 1U << curr;
|
||||
if (type == LENS && used >= ENOUGH - MAXD)
|
||||
if ((type == LENS && used >= ENOUGH_LENS) ||
|
||||
(type == DISTS && used >= ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
@@ -295,20 +296,20 @@ unsigned short FAR *work;
|
||||
through high index bits. When the current sub-table is filled, the loop
|
||||
drops back to the root table to fill in any remaining entries there.
|
||||
*/
|
||||
this.op = (unsigned char)64; /* invalid code marker */
|
||||
this.bits = (unsigned char)(len - drop);
|
||||
this.val = (unsigned short)0;
|
||||
here.op = (unsigned char)64; /* invalid code marker */
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
here.val = (unsigned short)0;
|
||||
while (huff != 0) {
|
||||
/* when done with sub-table, drop back to root table */
|
||||
if (drop != 0 && (huff & mask) != low) {
|
||||
drop = 0;
|
||||
len = root;
|
||||
next = *table;
|
||||
this.bits = (unsigned char)len;
|
||||
here.bits = (unsigned char)len;
|
||||
}
|
||||
|
||||
/* put invalid code marker in table */
|
||||
next[huff >> drop] = this;
|
||||
next[huff >> drop] = here;
|
||||
|
||||
/* backwards increment the len-bit code huff */
|
||||
incr = 1U << (len - 1);
|
||||
|
||||
23
inftrees.h
23
inftrees.h
@@ -35,15 +35,22 @@ typedef struct {
|
||||
01000000 - invalid code
|
||||
*/
|
||||
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1444 code structures (852 for length/literals
|
||||
and 592 for distances, the latter actually the result of an
|
||||
exhaustive search). The true maximum is not known, but the value
|
||||
below is more than safe. */
|
||||
#define ENOUGH 2048
|
||||
#define MAXD 592
|
||||
/* Maximum size of the dynamic table. The maximum number of code structures is
|
||||
1444, which is the sum of 852 for literal/length codes and 592 for distance
|
||||
codes. These values were found by exhaustive searches using the program
|
||||
examples/enough.c found in the zlib distribtution. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns returns 852, and "enough 30 6 15" for distance codes returns 592.
|
||||
The initial root table size (9 or 6) is found in the fifth argument of the
|
||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||
changed, then these maximum sizes would be need to be recalculated and
|
||||
updated. */
|
||||
#define ENOUGH_LENS 852
|
||||
#define ENOUGH_DISTS 592
|
||||
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
|
||||
|
||||
/* Type of code to build for inftable() */
|
||||
/* Type of code to build for inflate_table() */
|
||||
typedef enum {
|
||||
CODES,
|
||||
LENS,
|
||||
|
||||
63
make_vms.com
63
make_vms.com
@@ -10,6 +10,7 @@ $!
|
||||
$!------------------------------------------------------------------------------
|
||||
$! Version history
|
||||
$! 0.01 20060120 First version to receive a number
|
||||
$! 0.02 20061008 Adapt to new Makefile.in
|
||||
$!
|
||||
$ on error then goto err_exit
|
||||
$!
|
||||
@@ -77,40 +78,48 @@ $ if make.eqs.""
|
||||
$ then
|
||||
$ dele example.obj;*,minigzip.obj;*
|
||||
$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" -
|
||||
adler32.c zlib.h zconf.h
|
||||
adler32.c zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" -
|
||||
compress.c zlib.h zconf.h
|
||||
compress.c zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" -
|
||||
crc32.c zlib.h zconf.h
|
||||
crc32.c zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" -
|
||||
deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" -
|
||||
gzclose.c zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
$ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" -
|
||||
gzio.c zutil.h zlib.h zconf.h
|
||||
gzio.c zutil.h zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" -
|
||||
gzlib.c zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" -
|
||||
gzread.c zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" -
|
||||
gzwrite.c zlib.h zconf.h zlibdefs.h gzguts.h
|
||||
$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" -
|
||||
infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" -
|
||||
inffast.c zutil.h zlib.h zconf.h inffast.h
|
||||
inffast.c zutil.h zlib.h zconf.h zlibdefs.h inffast.h
|
||||
$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" -
|
||||
inflate.c zutil.h zlib.h zconf.h infblock.h
|
||||
inflate.c zutil.h zlib.h zconf.h zlibdefs.h infblock.h
|
||||
$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" -
|
||||
inftrees.c zutil.h zlib.h zconf.h inftrees.h
|
||||
inftrees.c zutil.h zlib.h zconf.h zlibdefs.h inftrees.h
|
||||
$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" -
|
||||
trees.c deflate.h zutil.h zlib.h zconf.h
|
||||
trees.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" -
|
||||
uncompr.c zlib.h zconf.h
|
||||
uncompr.c zlib.h zconf.h zlibdefs.h
|
||||
$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" -
|
||||
zutil.c zutil.h zlib.h zconf.h
|
||||
zutil.c zutil.h zlib.h zconf.h zlibdefs.h
|
||||
$ write sys$output "Building Zlib ..."
|
||||
$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ
|
||||
$ write sys$output "Building example..."
|
||||
$ CALL MAKE example.OBJ "CC ''CCOPT' example" -
|
||||
example.c zlib.h zconf.h
|
||||
example.c zlib.h zconf.h zlibdefs.h
|
||||
$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb
|
||||
$ if f$search("x11vms:xvmsutils.olb") .nes. ""
|
||||
$ then
|
||||
$ write sys$output "Building minigzip..."
|
||||
$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" -
|
||||
minigzip.c zlib.h zconf.h
|
||||
minigzip.c zlib.h zconf.h zlibdefs.h
|
||||
$ call make minigzip.exe -
|
||||
"LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" -
|
||||
minigzip.obj libz.olb
|
||||
@@ -328,19 +337,19 @@ clean :
|
||||
|
||||
|
||||
# Other dependencies.
|
||||
adler32.obj : adler32.c zutil.h zlib.h zconf.h
|
||||
compress.obj : compress.c zlib.h zconf.h
|
||||
crc32.obj : crc32.c zutil.h zlib.h zconf.h
|
||||
deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
example.obj : example.c zlib.h zconf.h
|
||||
gzio.obj : gzio.c zutil.h zlib.h zconf.h
|
||||
inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h
|
||||
inflate.obj : inflate.c zutil.h zlib.h zconf.h
|
||||
inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.obj : minigzip.c zlib.h zconf.h
|
||||
trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h
|
||||
uncompr.obj : uncompr.c zlib.h zconf.h
|
||||
zutil.obj : zutil.c zutil.h zlib.h zconf.h
|
||||
adler32.obj : adler32.c zutil.h zlib.h zconf.h zlibdefs.h
|
||||
compress.obj : compress.c 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
|
||||
example.obj : example.c zlib.h zconf.h zlibdefs.h
|
||||
gzio.obj : gzio.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
|
||||
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
|
||||
minigzip.obj : minigzip.c zlib.h zconf.h zlibdefs.h
|
||||
trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h
|
||||
uncompr.obj : uncompr.c zlib.h zconf.h zlibdefs.h
|
||||
zutil.obj : zutil.c zutil.h zlib.h zconf.h zlibdefs.h
|
||||
infback.obj : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
$ eod
|
||||
$ close out
|
||||
@@ -353,7 +362,7 @@ $!
|
||||
$CREA_OLIST:
|
||||
$ open/read min makefile.in
|
||||
$ open/write mod modules.opt
|
||||
$ src_check = "OBJS ="
|
||||
$ src_check = "OBJC ="
|
||||
$MRLOOP:
|
||||
$ read/end=mrdone min rec
|
||||
$ if (f$extract(0,6,rec) .nes. src_check) then goto mrloop
|
||||
|
||||
66
minigzip.c
66
minigzip.c
@@ -1,5 +1,5 @@
|
||||
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2006, 2010 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -54,6 +54,70 @@
|
||||
extern int unlink OF((const char *));
|
||||
#endif
|
||||
|
||||
#if defined(UNDER_CE) && defined(NO_ERRNO_H)
|
||||
# include <windows.h>
|
||||
# define perror(s) pwinerror(s)
|
||||
|
||||
/* 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.
|
||||
|
||||
The string pointed to shall not be modified by the application,
|
||||
but may be overwritten by a subsequent call to strwinerror
|
||||
|
||||
The strwinerror function does not change the current setting
|
||||
of GetLastError. */
|
||||
|
||||
static char *strwinerror (error)
|
||||
DWORD error;
|
||||
{
|
||||
static char buf[1024];
|
||||
|
||||
wchar_t *msgbuf;
|
||||
DWORD lasterr = GetLastError();
|
||||
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
NULL,
|
||||
error,
|
||||
0, /* Default language */
|
||||
(LPVOID)&msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
if (chars != 0) {
|
||||
/* If there is an \r\n appended, zap it. */
|
||||
if (chars >= 2
|
||||
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
||||
chars -= 2;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
if (chars > sizeof (buf) - 1) {
|
||||
chars = sizeof (buf) - 1;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
wcstombs(buf, msgbuf, chars + 1);
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "unknown win32 error (%ld)", error);
|
||||
}
|
||||
|
||||
SetLastError(lasterr);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void pwinerror (s)
|
||||
const char *s;
|
||||
{
|
||||
if (s && *s)
|
||||
fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ()));
|
||||
else
|
||||
fprintf(stderr, "%s\n", strwinerror(GetLastError ()));
|
||||
}
|
||||
|
||||
#endif /* UNDER_CE && NO_ERRNO_H */
|
||||
|
||||
#ifndef GZ_SUFFIX
|
||||
# define GZ_SUFFIX ".gz"
|
||||
#endif
|
||||
|
||||
@@ -41,10 +41,10 @@ LDFLAGS=-m$(MODEL) -f-
|
||||
# variables
|
||||
ZLIB_LIB = zlib_$(MODEL).lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
|
||||
OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
|
||||
OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
|
||||
|
||||
# targets
|
||||
@@ -61,8 +61,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ AR=ar rcs
|
||||
prefix=/usr/local
|
||||
exec_prefix = $(prefix)
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \
|
||||
uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
|
||||
OBJA =
|
||||
# to use the asm code: make OBJA=match.o
|
||||
|
||||
@@ -33,8 +33,8 @@ AR=ar rcs
|
||||
prefix=/usr/local
|
||||
exec_prefix = $(prefix)
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \
|
||||
uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode
|
||||
# variables
|
||||
ZLIB_LIB = zlib_$(MODEL).lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
|
||||
|
||||
# targets
|
||||
@@ -55,8 +55,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ LDFLAGS=-m$(MODEL) -f-
|
||||
# variables
|
||||
ZLIB_LIB = zlib_$(MODEL).lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
|
||||
OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
|
||||
OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
|
||||
|
||||
# targets
|
||||
@@ -46,8 +46,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
126
nintendods/Makefile
Normal file
126
nintendods/Makefile
Normal file
@@ -0,0 +1,126 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(shell basename $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := ../../
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb -mthumb-interwork
|
||||
|
||||
CFLAGS := -Wall -O2\
|
||||
-march=armv5te -mtune=arm946e-s \
|
||||
-fomit-frame-pointer -ffast-math \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM9
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := $(ARCH) -march=armv5te -mtune=arm946e-s
|
||||
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/lib/libz.a
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
@[ -d $@ ] || mkdir -p include
|
||||
@cp ../../*.h include
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
$(BUILD): lib
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) lib
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
5
nintendods/README
Normal file
5
nintendods/README
Normal file
@@ -0,0 +1,5 @@
|
||||
This Makefile requires devkitARM (http://www.devkitpro.org/category/devkitarm/) and works inside "contrib/nds". It is based on a devkitARM template.
|
||||
|
||||
Eduardo Costa <eduardo.m.costa@gmail.com>
|
||||
January 3, 2009
|
||||
|
||||
@@ -298,10 +298,26 @@ SOURCE=..\..\deflate.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\gzclose.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\gzio.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\gzlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\gzread.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\gzwrite.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\infback.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
<QPG:Files>
|
||||
<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="../libz.so.1.2.3.1" 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.1"/>
|
||||
<QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.1"/>
|
||||
<QPG:Add file="../libz.so.1.2.3.1" install="/opt/lib/" component="slib"/>
|
||||
<QPG:Add file="../libz.so.1.2.3.5" 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.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.5"/>
|
||||
<QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" component="slib"/>
|
||||
</QPG:Files>
|
||||
|
||||
<QPG:PackageFilter>
|
||||
@@ -63,7 +63,7 @@
|
||||
</QPM:ProductDescription>
|
||||
|
||||
<QPM:ReleaseDescription>
|
||||
<QPM:ReleaseVersion>1.2.3.1</QPM:ReleaseVersion>
|
||||
<QPM:ReleaseVersion>1.2.3.5</QPM:ReleaseVersion>
|
||||
<QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
|
||||
<QPM:ReleaseStability>Stable</QPM:ReleaseStability>
|
||||
<QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
# Makefile for zlib
|
||||
# Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
# To compile and test, type:
|
||||
# ./configure; make test
|
||||
# The call of configure is optional if you don't have special requirements
|
||||
# If you wish to build zlib as a shared library, use: ./configure -s
|
||||
|
||||
# To use the asm code, type:
|
||||
# cp contrib/asm?86/match.S ./match.S
|
||||
# make LOC=-DASMV OBJA=match.o
|
||||
|
||||
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
|
||||
# make install
|
||||
# To install in $HOME instead of /usr/local, use:
|
||||
# make install prefix=$HOME
|
||||
|
||||
CC=cc
|
||||
|
||||
CFLAGS=-O
|
||||
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
|
||||
#CFLAGS=-g -DDEBUG
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
SFLAGS=$(CFLAGS)
|
||||
#SFLAGS=$(CFLAGS) -fPIC
|
||||
|
||||
LD=$(CC)
|
||||
LDFLAGS=libz.a
|
||||
LDSHARED=$(CC)
|
||||
CPP=$(CC) -E
|
||||
|
||||
STATICLIB=libz.a
|
||||
SHAREDLIB=libz.so
|
||||
SHAREDLIBV=libz.so.1.2.3
|
||||
SHAREDLIBM=libz.so.1
|
||||
EXE=
|
||||
|
||||
LIBS=$(STATICLIB) $(SHAREDLIBV)
|
||||
|
||||
AR=ar rc
|
||||
RANLIB=ranlib
|
||||
TAR=tar
|
||||
SHELL=/bin/sh
|
||||
|
||||
prefix=/usr/local
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
mandir=${prefix}/share/man
|
||||
man3dir=${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
|
||||
OBJA =
|
||||
#OBJA = match.o
|
||||
# to use the asm code: make OBJA=match.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
OBJS_PIC = $(OBJS:.o=.pic.o)
|
||||
OBJA_PIC = $(OBJA:.o=.pic.o)
|
||||
|
||||
.SUFFIXES: .c .o .pic.o
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) -o $@ $*.c
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(SFLAGS) -o $@ $*.c
|
||||
|
||||
all: $(STATICLIB) example$(EXE) minigzip$(EXE)
|
||||
#all: $(STATICLIB) $(SHAREDLIBV) example$(EXE) minigzip$(EXE)
|
||||
|
||||
check: test
|
||||
test: all
|
||||
@LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
echo hello world | ./minigzip | ./minigzip -d || \
|
||||
echo ' *** minigzip test FAILED ***' ; \
|
||||
if ./example; then \
|
||||
echo ' *** zlib test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib test FAILED ***'; \
|
||||
fi
|
||||
|
||||
match.o: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c _match.s
|
||||
mv _match.o match.o
|
||||
rm -f _match.s
|
||||
|
||||
match.pic.o: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c -fPIC _match.s
|
||||
mv _match.o match.pic.o
|
||||
rm -f _match.s
|
||||
|
||||
$(STATICLIB): $(OBJS) $(OBJA)
|
||||
$(AR) $@ $(OBJS) $(OBJA)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
$(SHAREDLIBV): $(OBJS_PIC) $(OBJA_PIC)
|
||||
$(LDSHARED) -o $@ $(OBJS_PIC) $(OBJA_PIC)
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIBM)
|
||||
|
||||
example$(EXE): example.o $(STATICLIB)
|
||||
$(LD) -o $@ example.o $(LDFLAGS)
|
||||
|
||||
minigzip$(EXE): minigzip.o $(STATICLIB)
|
||||
$(LD) -o $@ minigzip.o $(LDFLAGS)
|
||||
|
||||
install: $(LIBS)
|
||||
mkdir -p $(DESTDIR)$(exec_prefix)
|
||||
mkdir -p $(DESTDIR)$(includedir)
|
||||
mkdir -p $(DESTDIR)$(libdir)
|
||||
mkdir -p $(DESTDIR)$(man3dir)
|
||||
mkdir -p $(DESTDIR)$(pkgconfigdir)
|
||||
cp zlib.h zconf.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
|
||||
cp $(LIBS) $(DESTDIR)$(libdir)
|
||||
cd $(DESTDIR)$(libdir); chmod 755 $(LIBS)
|
||||
-@(cd $(DESTDIR)$(libdir); $(RANLIB) $(STATICLIB) || true) >/dev/null 2>&1
|
||||
cd $(DESTDIR)$(libdir); if test -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
ln -s $(SHAREDLIBV) $(SHAREDLIB); \
|
||||
ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
|
||||
(ldconfig || true) >/dev/null 2>&1; \
|
||||
fi
|
||||
cp zlib.3 $(DESTDIR)$(man3dir)
|
||||
chmod 644 $(DESTDIR)$(man3dir)/zlib.3
|
||||
cp zlib.pc $(DESTDIR)$(pkgconfigdir)
|
||||
chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
|
||||
# The ranlib in install is needed on NeXTSTEP which checks file times
|
||||
# ldconfig is for Linux
|
||||
|
||||
uninstall:
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(libdir); rm -f $(STATICLIB); \
|
||||
if test -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
fi
|
||||
cd $(DESTDIR)$(man3dir); rm -f zlib.3
|
||||
cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
|
||||
|
||||
mostlyclean: clean
|
||||
clean:
|
||||
rm -f *.o *~ example$(EXE) minigzip$(EXE) \
|
||||
libz.* foo.gz so_locations \
|
||||
_match.s maketree contrib/infback9/*.o
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean
|
||||
cp -p Makefile.in Makefile
|
||||
cp -p zconf.in.h zconf.h
|
||||
rm -f zlib.pc .DS_Store
|
||||
|
||||
tags:
|
||||
etags *.[ch]
|
||||
|
||||
depend:
|
||||
makedepend -- $(CFLAGS) -- *.[ch]
|
||||
|
||||
# "fake" targets: not real filenames and no deps (else "touch clean" defeats)
|
||||
.PHONY: install uninstall clean tags depend
|
||||
|
||||
# DO NOT DELETE THIS LINE -- "make depend" depends on it.
|
||||
|
||||
adler32.o: zlib.h zconf.h
|
||||
adler32.pic.o: zlib.h zconf.h
|
||||
compress.o: zlib.h zconf.h
|
||||
compress.pic.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
crc32.pic.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
deflate.pic.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
example.pic.o: zlib.h zconf.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
gzio.pic.o: zutil.h zlib.h zconf.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inffast.pic.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.pic.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.pic.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
inftrees.pic.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
minigzip.pic.o: zlib.h zconf.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
trees.pic.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
uncompr.o: zlib.h zconf.h
|
||||
uncompr.pic.o: zlib.h zconf.h
|
||||
zutil.o: zutil.h zlib.h zconf.h
|
||||
zutil.pic.o: zutil.h zlib.h zconf.h
|
||||
@@ -1 +0,0 @@
|
||||
This "todo" directory contains works in progress. Nothing in here works, so don't try to use it!
|
||||
138
treebuild.xml
Normal file
138
treebuild.xml
Normal file
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" ?>
|
||||
<package name="zlib" version="1.2.3">
|
||||
<library name="zlib" dlversion="1.2.3" dlname="z">
|
||||
<property name="description"> zip compression library </property>
|
||||
<property name="include-target-dir" value="$(@PACKAGE/install-includedir)" />
|
||||
|
||||
<!-- fixme: not implemented yet -->
|
||||
<property name="compiler/c/inline" value="yes" />
|
||||
|
||||
<include-file name="zlib.h" scope="public" mode="644" />
|
||||
<include-file name="zconf.h" scope="public" mode="644" />
|
||||
<include-file name="zlibdefs.h" scope="public" mode="644" />
|
||||
|
||||
<source name="adler32.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
</source>
|
||||
<source name="compress.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
</source>
|
||||
<source name="crc32.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="crc32.h" />
|
||||
</source>
|
||||
<source name="gzclose.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="gzguts.h" />
|
||||
</source>
|
||||
<source name="gzio.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
</source>
|
||||
<source name="gzlib.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="gzguts.h" />
|
||||
</source>
|
||||
<source name="gzread.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="gzguts.h" />
|
||||
</source>
|
||||
<source name="gzwrite.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="gzguts.h" />
|
||||
</source>
|
||||
<source name="uncompr.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
</source>
|
||||
<source name="deflate.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="deflate.h" />
|
||||
</source>
|
||||
<source name="trees.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="deflate.h" />
|
||||
<depend name="trees.h" />
|
||||
</source>
|
||||
<source name="zutil.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
</source>
|
||||
<source name="inflate.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="inftrees.h" />
|
||||
<depend name="inflate.h" />
|
||||
<depend name="inffast.h" />
|
||||
</source>
|
||||
<source name="infback.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="inftrees.h" />
|
||||
<depend name="inflate.h" />
|
||||
<depend name="inffast.h" />
|
||||
</source>
|
||||
<source name="inftrees.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="inftrees.h" />
|
||||
</source>
|
||||
<source name="inffast.c">
|
||||
<depend name="zlib.h" />
|
||||
<depend name="zconf.h" />
|
||||
<depend name="zlibdefs.h" />
|
||||
<depend name="zutil.h" />
|
||||
<depend name="inftrees.h" />
|
||||
<depend name="inflate.h" />
|
||||
<depend name="inffast.h" />
|
||||
</source>
|
||||
</library>
|
||||
</package>
|
||||
|
||||
<!--
|
||||
CFLAGS=-O
|
||||
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
|
||||
#CFLAGS=-g -DDEBUG
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
# OBJA =
|
||||
# to use the asm code: make OBJA=match.o
|
||||
#
|
||||
match.o: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c _match.s
|
||||
mv _match.o match.o
|
||||
rm -f _match.s
|
||||
-->
|
||||
10
trees.c
10
trees.c
@@ -1,5 +1,5 @@
|
||||
/* trees.c -- output deflated data using Huffman coding
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly
|
||||
* Copyright (C) 1995-2009 Jean-loup Gailly
|
||||
* detect_data_type() function provided freely by Cosmin Truta, 2006
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
@@ -204,12 +204,12 @@ local void send_bits(s, value, length)
|
||||
* unused bits in value.
|
||||
*/
|
||||
if (s->bi_valid > (int)Buf_size - length) {
|
||||
s->bi_buf |= (value << s->bi_valid);
|
||||
s->bi_buf |= (ush)value << s->bi_valid;
|
||||
put_short(s, s->bi_buf);
|
||||
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
|
||||
s->bi_valid += length - Buf_size;
|
||||
} else {
|
||||
s->bi_buf |= value << s->bi_valid;
|
||||
s->bi_buf |= (ush)value << s->bi_valid;
|
||||
s->bi_valid += length;
|
||||
}
|
||||
}
|
||||
@@ -219,12 +219,12 @@ local void send_bits(s, value, length)
|
||||
{ int len = length;\
|
||||
if (s->bi_valid > (int)Buf_size - len) {\
|
||||
int val = value;\
|
||||
s->bi_buf |= (val << s->bi_valid);\
|
||||
s->bi_buf |= (ush)val << s->bi_valid;\
|
||||
put_short(s, s->bi_buf);\
|
||||
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
|
||||
s->bi_valid += len - Buf_size;\
|
||||
} else {\
|
||||
s->bi_buf |= (value) << s->bi_valid;\
|
||||
s->bi_buf |= (ush)(value) << s->bi_valid;\
|
||||
s->bi_valid += len;\
|
||||
}\
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
# To use, do "wmake -f watcom_f.mak"
|
||||
|
||||
C_SOURCE = adler32.c compress.c crc32.c deflate.c &
|
||||
gzclose.c gzlib.c gzread.c gzwrite.c &
|
||||
gzio.c infback.c inffast.c inflate.c &
|
||||
inftrees.c trees.c uncompr.c zutil.c
|
||||
|
||||
OBJS = adler32.obj compress.obj crc32.obj deflate.obj &
|
||||
gzclose.obj gzlib.obj gzread.obj gzwrite.obj &
|
||||
gzio.obj infback.obj inffast.obj inflate.obj &
|
||||
inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
|
||||
@@ -24,6 +26,7 @@ all: $(ZLIB_LIB) example.exe minigzip.exe
|
||||
|
||||
$(ZLIB_LIB): $(OBJS)
|
||||
wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
# To use, do "wmake -f watcom_l.mak"
|
||||
|
||||
C_SOURCE = adler32.c compress.c crc32.c deflate.c &
|
||||
gzclose.c gzlib.c gzread.c gzwrite.c &
|
||||
gzio.c infback.c inffast.c inflate.c &
|
||||
inftrees.c trees.c uncompr.c zutil.c
|
||||
|
||||
OBJS = adler32.obj compress.obj crc32.obj deflate.obj &
|
||||
gzclose.obj gzlib.obj gzread.obj gzwrite.obj &
|
||||
gzio.obj infback.obj inffast.obj inflate.obj &
|
||||
inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
|
||||
@@ -24,6 +26,7 @@ all: $(ZLIB_LIB) example.exe minigzip.exe
|
||||
|
||||
$(ZLIB_LIB): $(OBJS)
|
||||
wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj
|
||||
wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj
|
||||
|
||||
@@ -24,11 +24,11 @@ LDFLAGS = $(LOC)
|
||||
# variables
|
||||
ZLIB_LIB = zlib.lib
|
||||
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
|
||||
OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj
|
||||
OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
#OBJA =
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
|
||||
OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj
|
||||
OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
|
||||
#OBJPA=
|
||||
|
||||
|
||||
@@ -49,8 +49,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ AR=ar rcs
|
||||
prefix=/usr/local
|
||||
exec_prefix = $(prefix)
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infback.o inftrees.o inffast.o
|
||||
OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \
|
||||
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ ARFLAGS = rcs
|
||||
RC = windres
|
||||
RCFLAGS = --define GCC_WINDRES
|
||||
|
||||
STRIP = strip
|
||||
|
||||
CP = cp -fp
|
||||
# If GNU install is available, replace $(CP) with install.
|
||||
INSTALL = $(CP)
|
||||
@@ -53,17 +55,17 @@ RM = rm -f
|
||||
prefix = /usr/local
|
||||
exec_prefix = $(prefix)
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
|
||||
inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \
|
||||
gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
OBJA =
|
||||
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example minigzip example_d minigzip_d
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe
|
||||
|
||||
test: example minigzip
|
||||
test: example.exe minigzip.exe
|
||||
./example
|
||||
echo hello world | ./minigzip | ./minigzip -d
|
||||
|
||||
testdll: example_d minigzip_d
|
||||
testdll: example_d.exe minigzip_d.exe
|
||||
./example_d
|
||||
echo hello world | ./minigzip_d | ./minigzip_d -d
|
||||
|
||||
@@ -79,20 +81,20 @@ $(STATICLIB): $(OBJS) $(OBJA)
|
||||
$(IMPLIB): $(SHAREDLIB)
|
||||
|
||||
$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
|
||||
dllwrap --driver-name $(CC) --def win32/zlib.def \
|
||||
--implib $(IMPLIB) -o $@ $(OBJS) $(OBJA) zlibrc.o
|
||||
strip $@
|
||||
$(CC) -shared -Wl,--out-implib,$(IMPLIB) \
|
||||
-o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
|
||||
$(STRIP) $@
|
||||
|
||||
example: example.o $(STATICLIB)
|
||||
example.exe: example.o $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
|
||||
|
||||
minigzip: minigzip.o $(STATICLIB)
|
||||
minigzip.exe: minigzip.o $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
|
||||
|
||||
example_d: example.o $(IMPLIB)
|
||||
example_d.exe: example.o $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
|
||||
|
||||
minigzip_d: minigzip.o $(IMPLIB)
|
||||
minigzip_d.exe: minigzip.o $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
|
||||
|
||||
zlibrc.o: win32/zlib1.rc
|
||||
@@ -130,7 +132,11 @@ compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzclose.o: zlib.h zconf.h gzguts.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
gzlib.o: zlib.h zconf.h gzguts.h
|
||||
gzread.o: zlib.h zconf.h gzguts.h
|
||||
gzwrite.o: zlib.h zconf.h gzguts.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
|
||||
141
win32/Makefile.gcc.old
Normal file
141
win32/Makefile.gcc.old
Normal file
@@ -0,0 +1,141 @@
|
||||
# Makefile for zlib, derived from Makefile.dj2.
|
||||
# Modified for mingw32 by C. Spieler, 6/16/98.
|
||||
# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
|
||||
# Last updated: 1-Aug-2003.
|
||||
# Tested under Cygwin and MinGW.
|
||||
|
||||
# Copyright (C) 1995-2003 Jean-loup Gailly.
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
# To compile, or to compile and test, type:
|
||||
#
|
||||
# make -fmakefile.gcc; make test testdll -fmakefile.gcc
|
||||
#
|
||||
# To use the asm code, type:
|
||||
# cp contrib/asm?86/match.S ./match.S
|
||||
# make LOC=-DASMV OBJA=match.o -fmakefile.gcc
|
||||
#
|
||||
# To install libz.a, zconf.h and zlib.h in the system directories, type:
|
||||
#
|
||||
# make install -fmakefile.gcc
|
||||
|
||||
# Note:
|
||||
# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN),
|
||||
# the DLL name should be changed from "zlib1.dll".
|
||||
|
||||
STATICLIB = libz.a
|
||||
SHAREDLIB = zlib1.dll
|
||||
IMPLIB = libzdll.a
|
||||
|
||||
#LOC = -DASMV
|
||||
#LOC = -DDEBUG -g
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = $(LOC) -O3 -Wall
|
||||
|
||||
AS = $(CC)
|
||||
ASFLAGS = $(LOC) -Wall
|
||||
|
||||
LD = $(CC)
|
||||
LDFLAGS = $(LOC) -s
|
||||
|
||||
AR = ar
|
||||
ARFLAGS = rcs
|
||||
|
||||
RC = windres
|
||||
RCFLAGS = --define GCC_WINDRES
|
||||
|
||||
CP = cp -fp
|
||||
# If GNU install is available, replace $(CP) with install.
|
||||
INSTALL = $(CP)
|
||||
RM = rm -f
|
||||
|
||||
prefix = /usr/local
|
||||
exec_prefix = $(prefix)
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
|
||||
inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||
OBJA =
|
||||
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example minigzip example_d minigzip_d
|
||||
|
||||
test: example minigzip
|
||||
./example
|
||||
echo hello world | ./minigzip | ./minigzip -d
|
||||
|
||||
testdll: example_d minigzip_d
|
||||
./example_d
|
||||
echo hello world | ./minigzip_d | ./minigzip_d -d
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
.S.o:
|
||||
$(AS) $(ASFLAGS) -c -o $@ $<
|
||||
|
||||
$(STATICLIB): $(OBJS) $(OBJA)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA)
|
||||
|
||||
$(IMPLIB): $(SHAREDLIB)
|
||||
|
||||
$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
|
||||
dllwrap --driver-name $(CC) --def win32/zlib.def \
|
||||
--implib $(IMPLIB) -o $@ $(OBJS) $(OBJA) zlibrc.o
|
||||
strip $@
|
||||
|
||||
example: example.o $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
|
||||
|
||||
minigzip: minigzip.o $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
|
||||
|
||||
example_d: example.o $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
|
||||
|
||||
minigzip_d: minigzip.o $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
|
||||
|
||||
zlibrc.o: win32/zlib1.rc
|
||||
$(RC) $(RCFLAGS) -o $@ win32/zlib1.rc
|
||||
|
||||
|
||||
# INCLUDE_PATH and LIBRARY_PATH must be set.
|
||||
|
||||
.PHONY: install uninstall clean
|
||||
|
||||
install: zlib.h zconf.h $(LIB)
|
||||
-@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH)
|
||||
-@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH)
|
||||
-$(INSTALL) zlib.h $(INCLUDE_PATH)
|
||||
-$(INSTALL) zconf.h $(INCLUDE_PATH)
|
||||
-$(INSTALL) $(STATICLIB) $(LIBRARY_PATH)
|
||||
-$(INSTALL) $(IMPLIB) $(LIBRARY_PATH)
|
||||
|
||||
uninstall:
|
||||
-$(RM) $(INCLUDE_PATH)/zlib.h
|
||||
-$(RM) $(INCLUDE_PATH)/zconf.h
|
||||
-$(RM) $(LIBRARY_PATH)/$(STATICLIB)
|
||||
-$(RM) $(LIBRARY_PATH)/$(IMPLIB)
|
||||
|
||||
clean:
|
||||
-$(RM) $(STATICLIB)
|
||||
-$(RM) $(SHAREDLIB)
|
||||
-$(RM) $(IMPLIB)
|
||||
-$(RM) *.o
|
||||
-$(RM) *.exe
|
||||
-$(RM) foo.gz
|
||||
|
||||
adler32.o: zlib.h zconf.h
|
||||
compress.o: zlib.h zconf.h
|
||||
crc32.o: crc32.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
uncompr.o: zlib.h zconf.h
|
||||
zutil.o: zutil.h zlib.h zconf.h
|
||||
@@ -28,8 +28,8 @@ LDFLAGS = -nologo -debug -release
|
||||
ARFLAGS = -nologo
|
||||
RCFLAGS = /dWIN32 /r
|
||||
|
||||
OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \
|
||||
inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj \
|
||||
gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJA =
|
||||
|
||||
|
||||
@@ -82,8 +82,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h
|
||||
|
||||
deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
|
||||
|
||||
gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzio.obj: gzio.c zutil.h zlib.h zconf.h
|
||||
|
||||
gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzread.obj: gzread.c zlib.h zconf.h gzguts.h
|
||||
|
||||
gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h
|
||||
|
||||
infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
|
||||
inffast.h inffixed.h
|
||||
|
||||
|
||||
@@ -13,12 +13,18 @@ EXPORTS
|
||||
deflateCopy
|
||||
deflateReset
|
||||
deflateParams
|
||||
deflateTune
|
||||
deflateBound
|
||||
deflatePrime
|
||||
deflateSetHeader
|
||||
inflateSetDictionary
|
||||
inflateSync
|
||||
inflateCopy
|
||||
inflateReset
|
||||
inflateReset2
|
||||
inflatePrime
|
||||
inflateMark
|
||||
inflateGetHeader
|
||||
inflateBack
|
||||
inflateBackEnd
|
||||
zlibCompileFlags
|
||||
@@ -29,6 +35,7 @@ EXPORTS
|
||||
uncompress
|
||||
gzopen
|
||||
gzdopen
|
||||
gzbuffer
|
||||
gzsetparams
|
||||
gzread
|
||||
gzwrite
|
||||
@@ -42,15 +49,18 @@ EXPORTS
|
||||
gzseek
|
||||
gzrewind
|
||||
gztell
|
||||
gzoffset
|
||||
gzeof
|
||||
gzdirect
|
||||
gzclose
|
||||
gzclose_r
|
||||
gzclose_w
|
||||
gzerror
|
||||
gzclearerr
|
||||
; checksum functions
|
||||
adler32
|
||||
adler32_combine
|
||||
crc32
|
||||
adler32_combine
|
||||
crc32_combine
|
||||
; various hacks, don't look :)
|
||||
deflateInit_
|
||||
@@ -58,6 +68,13 @@ EXPORTS
|
||||
inflateInit_
|
||||
inflateInit2_
|
||||
inflateBackInit_
|
||||
gzopen64
|
||||
gzseek64
|
||||
gztell64
|
||||
gzoffset64
|
||||
adler32_combine64
|
||||
crc32_combine64
|
||||
zError
|
||||
inflateSyncPoint
|
||||
get_crc_table
|
||||
zError
|
||||
inflateUndermine
|
||||
|
||||
20
zconf.h
20
zconf.h
@@ -1,5 +1,5 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2007 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -45,8 +45,11 @@
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
@@ -54,6 +57,7 @@
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzopen z_gzopen
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
@@ -74,8 +78,10 @@
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflateMark z_inflateMark
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
@@ -351,14 +357,12 @@ typedef uLong FAR uLongf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#include "zlibdefs.h" /* created by configure */
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
|
||||
6
zlib.3
6
zlib.3
@@ -1,4 +1,4 @@
|
||||
.TH ZLIB 3 "16 August 2006"
|
||||
.TH ZLIB 3 "8 January 2010"
|
||||
.SH NAME
|
||||
zlib \- compression/decompression library
|
||||
.SH SYNOPSIS
|
||||
@@ -133,8 +133,8 @@ before asking for help.
|
||||
Send questions and/or comments to zlib@gzip.org,
|
||||
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
|
||||
.SH AUTHORS
|
||||
Version 1.2.3.1
|
||||
Copyright (C) 1995-2005 Jean-loup Gailly (jloup@gzip.org)
|
||||
Version 1.2.3.5
|
||||
Copyright (C) 1995-2009 Jean-loup Gailly (jloup@gzip.org)
|
||||
and Mark Adler (madler@alumni.caltech.edu).
|
||||
.LP
|
||||
This software is provided "as-is,"
|
||||
|
||||
293
zlib.h
293
zlib.h
@@ -1,7 +1,7 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.2.3.1, August 16th, 2006
|
||||
version 1.2.3.5, Jan 8th, 2010
|
||||
|
||||
Copyright (C) 1995-2006 Jean-loup Gailly and Mark Adler
|
||||
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -37,8 +37,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.2.3.1"
|
||||
#define ZLIB_VERNUM 0x1231
|
||||
#define ZLIB_VERSION "1.2.3.5"
|
||||
#define ZLIB_VERNUM 0x1235
|
||||
#define ZLIB_VER_MAJOR 1
|
||||
#define ZLIB_VER_MINOR 2
|
||||
#define ZLIB_VER_REVISION 3
|
||||
@@ -163,11 +163,12 @@ typedef gz_header FAR *gz_headerp;
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define Z_PARTIAL_FLUSH 1
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
#define Z_BLOCK 5
|
||||
#define Z_TREES 6
|
||||
/* Allowed flush values; see deflate() and inflate() below for details */
|
||||
|
||||
#define Z_OK 0
|
||||
@@ -273,7 +274,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
|
||||
decide how much data to accumualte before producing output, in order to
|
||||
decide how much data to accumulate before producing output, in order to
|
||||
maximize compression.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
@@ -281,7 +282,26 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
avail_in is zero after the call if enough output space has been provided
|
||||
before the call.) Flushing may degrade compression for some compression
|
||||
algorithms and so it should be used only when necessary.
|
||||
algorithms and so it should be used only when necessary. This completes the
|
||||
current deflate block and follows it with an empty stored block 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
|
||||
output buffer, but the output is not aligned to a byte boundary. All of the
|
||||
input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
|
||||
This completes the current deflate block and follows it with an empty fixed
|
||||
codes block that is 10 bits long. This assures that enough bytes are output
|
||||
in order for the decompressor to finish the block before the empty fixed code
|
||||
block.
|
||||
|
||||
If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
|
||||
for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
|
||||
seven bits of the current block are held to be written as the next byte after
|
||||
the next deflate block is completed. In this case, the decompressor may not
|
||||
be provided enough bits at this point in order to complete decompression of
|
||||
the data provided so far to the compressor. It may need to wait for the next
|
||||
block to be emitted. This is for advanced applications that need to control
|
||||
the emission of deflate blocks.
|
||||
|
||||
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
|
||||
@@ -321,7 +341,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
processed or more output produced), Z_STREAM_END if all input has been
|
||||
consumed and all output has been produced (only when flush is set to
|
||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
||||
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
|
||||
fatal, and deflate() can be called again with more input and more output
|
||||
space to continue compressing.
|
||||
@@ -396,8 +416,8 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
||||
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
||||
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
|
||||
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
||||
if and when it gets to the next deflate block boundary. When decoding the
|
||||
zlib or gzip format, this will cause inflate() to return immediately after
|
||||
@@ -415,7 +435,16 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
uncompressed data from that block has been written to strm->next_out. The
|
||||
number of unused bits may in general be greater than seven, except when
|
||||
bit 7 of data_type is set, in which case the number of unused bits will be
|
||||
less than eight.
|
||||
less than eight. data_type is set as noted here every time inflate()
|
||||
returns for all flush options, and so can be used to determine the amount
|
||||
of currently consumed input in bits.
|
||||
|
||||
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
|
||||
block is decoded. This allows the caller to determine the length of the
|
||||
deflate block header for later use in random access within a deflate block.
|
||||
256 is added to the value of strm->data_type when inflate() returns
|
||||
immediately after reaching the end of the deflate block header.
|
||||
|
||||
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
|
||||
@@ -432,7 +461,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
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
|
||||
is on the return value of inflate(), as noted below, or when it returns early
|
||||
because Z_BLOCK is used.
|
||||
because Z_BLOCK or Z_TREES is used.
|
||||
|
||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||
@@ -443,12 +472,12 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
checksum is equal to that saved by the compressor and returns Z_STREAM_END
|
||||
only if the checksum is correct.
|
||||
|
||||
inflate() will decompress and check either zlib-wrapped or gzip-wrapped
|
||||
deflate data. The header type is detected automatically. Any information
|
||||
contained in the gzip header is not retained, so applications that need that
|
||||
information should instead use raw inflate, see inflateInit2() below, or
|
||||
inflateBack() and perform their own processing of the gzip header and
|
||||
trailer.
|
||||
inflate() can decompress and check either zlib-wrapped or gzip-wrapped
|
||||
deflate data. The header type is detected automatically, if requested when
|
||||
initializing with inflateInit2(). Any information contained in the gzip
|
||||
header is not retained, so applications that need that information should
|
||||
instead use raw inflate, see inflateInit2() below, or inflateBack() and
|
||||
perform their own processing of the gzip header and trailer.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
@@ -456,7 +485,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect check
|
||||
value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
|
||||
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
|
||||
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
|
||||
@@ -529,12 +558,12 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
random distribution. In this case, the compression algorithm is tuned to
|
||||
compress them better. The effect of Z_FILTERED is to force more Huffman
|
||||
coding and less string matching; it is somewhat intermediate between
|
||||
Z_DEFAULT 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 strategy
|
||||
parameter only affects the compression ratio but not the 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 decoder for special
|
||||
applications.
|
||||
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
|
||||
strategy parameter only affects the compression ratio but not the
|
||||
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
|
||||
decoder for special applications.
|
||||
|
||||
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
|
||||
@@ -561,11 +590,11 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
|
||||
Depending on the size of the compression data structures selected by
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front. In addition, the
|
||||
current implementation of deflate will use at most the window size minus
|
||||
262 bytes of the provided dictionary.
|
||||
discarded, for example if the dictionary is larger than the window size
|
||||
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
|
||||
addition, the current implementation of deflate will use at most the window
|
||||
size minus 262 bytes of the provided dictionary.
|
||||
|
||||
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
|
||||
@@ -575,7 +604,7 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
adler32 value is not computed and strm->adler is not set.
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) 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
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
@@ -595,7 +624,7 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
|
||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
(such as zalloc being Z_NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
@@ -607,7 +636,7 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
|
||||
that may have been set by deflateInit2.
|
||||
|
||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
stream state was inconsistent (such as zalloc or state being Z_NULL).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
@@ -715,6 +744,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
size is given as input, inflate() will return with the error code
|
||||
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
|
||||
the zlib header of the compressed stream.
|
||||
|
||||
windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
|
||||
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
|
||||
@@ -760,7 +792,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
dictionary that was used for compression is provided.
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) 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
|
||||
expected one (incorrect adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
@@ -794,7 +826,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
|
||||
|
||||
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
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
(such as zalloc being Z_NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
@@ -805,7 +837,19 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
stream state was inconsistent (such as zalloc or state being Z_NULL).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
/*
|
||||
This function is the same as inflateReset, but it also permits changing
|
||||
the wrap and window size requests. The windowBits parameter is
|
||||
interpreted the same as it is for inflateInit2.
|
||||
|
||||
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
|
||||
the windowBits parameter is invalid.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
||||
@@ -820,10 +864,43 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
||||
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.
|
||||
|
||||
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
|
||||
to clear out bits leftover after feeding inflate a block description prior
|
||||
to feeding inflate codes.
|
||||
|
||||
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
|
||||
/*
|
||||
This function returns two values, one in the lower 16 bits of the return
|
||||
value, and the other in the remaining upper bits, obtained by shifting the
|
||||
return value down 16 bits. If the upper value is -1 and the lower value is
|
||||
zero, then inflate() is currently decoding information outside of a block.
|
||||
If the upper value is -1 and the lower value is non-zero, then inflate is in
|
||||
the middle of a stored block, with the lower value equaling the number of
|
||||
bytes from the input remaining to copy. If the upper value is not -1, then
|
||||
it is the number of bits back from the current bit position in the input of
|
||||
the code (literal or length/distance pair) currently being processed. In
|
||||
that case the lower value is the number of bytes already emitted for that
|
||||
code.
|
||||
|
||||
A code is being processed if inflate is waiting for more input to complete
|
||||
decoding of the code, or if it has completed decoding but is waiting for
|
||||
more output space to write the literal or match data.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
source stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
|
||||
gz_headerp head));
|
||||
/*
|
||||
@@ -833,9 +910,9 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
|
||||
As inflate() processes the gzip stream, head->done is zero until the header
|
||||
is completed, at which time head->done is set to one. If a zlib stream is
|
||||
being decoded, then head->done is set to -1 to indicate that there will be
|
||||
no gzip header information forthcoming. Note that Z_BLOCK can be used to
|
||||
force inflate() to return immediately after header processing is complete
|
||||
and before any actual data is decompressed.
|
||||
no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
|
||||
used to force inflate() to return immediately after header processing is
|
||||
complete and before any actual data is decompressed.
|
||||
|
||||
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
|
||||
@@ -952,7 +1029,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
||||
nature of the error), or Z_STREAM_ERROR if the stream was not properly
|
||||
initialized. In the case of Z_BUF_ERROR, an input or output error can be
|
||||
distinguished using strm->next_in which will be Z_NULL only if in() returned
|
||||
an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
|
||||
an error. If strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to
|
||||
out() returning non-zero. (in() will always be called before out(), so
|
||||
strm->next_in is assured to be defined if out() returns non-zero.) Note
|
||||
that inflateBack() cannot return Z_OK.
|
||||
@@ -1065,7 +1142,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
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.
|
||||
Upon exit, destLen 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.
|
||||
|
||||
@@ -1074,11 +1151,19 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 "gz". The gzip format is different from the zlib format. gzip is a
|
||||
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||
|
||||
*/
|
||||
|
||||
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
|
||||
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
|
||||
@@ -1094,7 +1179,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR). */
|
||||
|
||||
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
@@ -1107,6 +1192,20 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
|
||||
/*
|
||||
Set the internal buffer size used by this library's functions. The default
|
||||
buffer size is 8192 bytes. This function must be called after gz_open() or
|
||||
gz_dopen(), and before any other calls that read or write the file. The
|
||||
buffer memory allocation is always deferred to the first read or write. Two
|
||||
buffers are allocated, either both of the specified size when writing, or
|
||||
one of the specified size and the other twice that size when reading. A
|
||||
larger buffer size of, for example, 64K or 128K bytes will noticeably
|
||||
increase the speed of decompression (reading).
|
||||
gz_buffer() returns 0 on success, or -1 on failure, such as being called
|
||||
too late.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level or strategy. See the description
|
||||
@@ -1115,7 +1214,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||
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.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
@@ -1123,25 +1222,26 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
voidpc buf, unsigned len));
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
voidpc buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
/*
|
||||
Converts, formats, and writes the args 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
|
||||
uncompressed bytes actually written (0 in case of error). The number of
|
||||
uncompressed bytes written is limited to 4095. The caller should assure that
|
||||
this limit is not exceeded. If it is exceeded, then gzprintf() will return
|
||||
return an error (0) with nothing written. In this case, there may also be a
|
||||
buffer overflow with unpredictable consequences, which is possible only if
|
||||
zlib was compiled with the insecure functions sprintf() or vsprintf()
|
||||
because the secure snprintf() or vsnprintf() functions were not available.
|
||||
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
|
||||
size given to gz_buffer(). The caller should assure that this limit is not
|
||||
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
|
||||
unpredictable consequences, which is possible only if zlib was compiled
|
||||
with the insecure functions sprintf() or vsprintf() because the secure
|
||||
snprintf() or vsnprintf() functions were not available.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
|
||||
@@ -1182,7 +1282,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
|
||||
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
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
@@ -1192,9 +1292,10 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
/*
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
|
||||
Sets the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
@@ -1217,15 +1318,28 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
|
||||
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
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
uncompressed data stream, and is zero when starting, even if appending
|
||||
or reading a gzip stream from the middle of a file using gz_dopen().
|
||||
|
||||
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
|
||||
|
||||
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
|
||||
appending or when using gz_dopen() for reading. When reading, the offset
|
||||
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.
|
||||
On error, gz_offset() returns -1.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||
/*
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
@@ -1242,10 +1356,22 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number. Note that once file is close, 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.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose_r 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
|
||||
gz_close_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
|
||||
decompression code that is not used when only reading or only writing
|
||||
respectively. If gz_close() is used, then both compression and
|
||||
decompression code will be included the application when linking to a
|
||||
static zlib library.
|
||||
*/
|
||||
|
||||
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
@@ -1276,7 +1402,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
|
||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
return the updated checksum. If buf is Z_NULL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
@@ -1289,9 +1415,10 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
||||
z_off_t len2));
|
||||
/*
|
||||
|
||||
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||
@@ -1301,7 +1428,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
||||
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
|
||||
updated CRC-32. If buf is NULL, this function returns the required initial
|
||||
updated CRC-32. If buf is Z_NULL, this function returns the required initial
|
||||
value for the 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:
|
||||
@@ -1314,9 +1441,9 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
|
||||
|
||||
/*
|
||||
Combine two CRC-32 check values into one. For two sequences of bytes,
|
||||
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
|
||||
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
|
||||
@@ -1357,13 +1484,47 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
||||
inflateBackInit_((strm), (windowBits), (window), \
|
||||
ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN off64_t ZEXPORT gzseek64 OF((gzFile, off64_t, int));
|
||||
ZEXTERN off64_t ZEXPORT gztell64 OF((gzFile));
|
||||
ZEXTERN off64_t ZEXPORT gzoffset64 OF((gzFile));
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off64_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off64_t));
|
||||
#endif
|
||||
|
||||
#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS == 64
|
||||
# define gzopen gzopen64
|
||||
# define gzseek gzseek64
|
||||
# define gztell gztell64
|
||||
# define gzoffset gzoffset64
|
||||
# define adler32_combine adler32_combine64
|
||||
# define crc32_combine crc32_combine64
|
||||
# ifndef _LARGEFILE64_SOURCE
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN off_t ZEXPORT gzseek64 OF((gzFile, off_t, int));
|
||||
ZEXTERN off_t ZEXPORT gztell64 OF((gzFile));
|
||||
ZEXTERN off_t ZEXPORT gzoffset64 OF((gzFile));
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off_t));
|
||||
# endif
|
||||
#else
|
||||
ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
|
||||
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
|
||||
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
|
||||
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
|
||||
#endif
|
||||
|
||||
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
ZEXTERN const char * ZEXPORT zError OF((int));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
9
zlib.map
9
zlib.map
@@ -42,3 +42,12 @@ ZLIB_1.2.2.3 {
|
||||
ZLIB_1.2.2.4 {
|
||||
inflatePrime;
|
||||
} ZLIB_1.2.2.3;
|
||||
|
||||
ZLIB_1.2.3.3 {
|
||||
inflateUndermine;
|
||||
} ZLIB_1.2.2.4;
|
||||
|
||||
ZLIB_1.2.3.4 {
|
||||
inflateReset2;
|
||||
inflateMark;
|
||||
} ZLIB_1.2.3.3;
|
||||
|
||||
152
zlib2ansi
Executable file
152
zlib2ansi
Executable file
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Transform K&R C function definitions into ANSI equivalent.
|
||||
#
|
||||
# Author: Paul Marquess
|
||||
# Version: 1.0
|
||||
# Date: 3 October 2006
|
||||
|
||||
# TODO
|
||||
#
|
||||
# Asumes no function pointer parameters. unless they are typedefed.
|
||||
# Assumes no literal strings that look like function definitions
|
||||
# Assumes functions start at the beginning of a line
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
local $/;
|
||||
$_ = <>;
|
||||
|
||||
my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
|
||||
|
||||
my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
|
||||
my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
|
||||
my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
|
||||
|
||||
|
||||
while (s/^
|
||||
( # Start $1
|
||||
( # Start $2
|
||||
.*? # Minimal eat content
|
||||
( ^ \w [\w\s\*]+ ) # $3 -- function name
|
||||
\s* # optional whitespace
|
||||
) # $2 - Matched up to before parameter list
|
||||
|
||||
\( \s* # Literal "(" + optional whitespace
|
||||
( [^\)]+ ) # $4 - one or more anythings except ")"
|
||||
\s* \) # optional whitespace surrounding a Literal ")"
|
||||
|
||||
( (?: $dList )+ ) # $5
|
||||
|
||||
$sp ^ { # literal "{" at start of line
|
||||
) # Remember to $1
|
||||
//xsom
|
||||
)
|
||||
{
|
||||
my $all = $1 ;
|
||||
my $prefix = $2;
|
||||
my $param_list = $4 ;
|
||||
my $params = $5;
|
||||
|
||||
StripComments($params);
|
||||
StripComments($param_list);
|
||||
$param_list =~ s/^\s+//;
|
||||
$param_list =~ s/\s+$//;
|
||||
|
||||
my $i = 0 ;
|
||||
my %pList = map { $_ => $i++ }
|
||||
split /\s*,\s*/, $param_list;
|
||||
my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
|
||||
|
||||
my @params = split /\s*;\s*/, $params;
|
||||
my @outParams = ();
|
||||
foreach my $p (@params)
|
||||
{
|
||||
if ($p =~ /,/)
|
||||
{
|
||||
my @bits = split /\s*,\s*/, $p;
|
||||
my $first = shift @bits;
|
||||
$first =~ s/^\s*//;
|
||||
push @outParams, $first;
|
||||
$first =~ /^(\w+\s*)/;
|
||||
my $type = $1 ;
|
||||
push @outParams, map { $type . $_ } @bits;
|
||||
}
|
||||
else
|
||||
{
|
||||
$p =~ s/^\s+//;
|
||||
push @outParams, $p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
my %tmp = map { /$pMatch/; $_ => $pList{$1} }
|
||||
@outParams ;
|
||||
|
||||
@outParams = map { " $_" }
|
||||
sort { $tmp{$a} <=> $tmp{$b} }
|
||||
@outParams ;
|
||||
|
||||
print $prefix ;
|
||||
print "(\n" . join(",\n", @outParams) . ")\n";
|
||||
print "{" ;
|
||||
|
||||
}
|
||||
|
||||
# Output any trailing code.
|
||||
print ;
|
||||
exit 0;
|
||||
|
||||
|
||||
sub StripComments
|
||||
{
|
||||
|
||||
no warnings;
|
||||
|
||||
# Strip C & C++ coments
|
||||
# From the perlfaq
|
||||
$_[0] =~
|
||||
|
||||
s{
|
||||
/\* ## Start of /* ... */ comment
|
||||
[^*]*\*+ ## Non-* followed by 1-or-more *'s
|
||||
(
|
||||
[^/*][^*]*\*+
|
||||
)* ## 0-or-more things which don't start with /
|
||||
## but do end with '*'
|
||||
/ ## End of /* ... */ comment
|
||||
|
||||
| ## OR C++ Comment
|
||||
// ## Start of C++ comment //
|
||||
[^\n]* ## followed by 0-or-more non end of line characters
|
||||
|
||||
| ## OR various things which aren't comments:
|
||||
|
||||
(
|
||||
" ## Start of " ... " string
|
||||
(
|
||||
\\. ## Escaped char
|
||||
| ## OR
|
||||
[^"\\] ## Non "\
|
||||
)*
|
||||
" ## End of " ... " string
|
||||
|
||||
| ## OR
|
||||
|
||||
' ## Start of ' ... ' string
|
||||
(
|
||||
\\. ## Escaped char
|
||||
| ## OR
|
||||
[^'\\] ## Non '\
|
||||
)*
|
||||
' ## End of ' ... ' string
|
||||
|
||||
| ## OR
|
||||
|
||||
. ## Anything other char
|
||||
[^/"'\\]* ## Chars which doesn't start a comment, string or escape
|
||||
)
|
||||
}{$2}gxs;
|
||||
|
||||
}
|
||||
0
zlibdefs.h
Normal file
0
zlibdefs.h
Normal file
16
zlibdefs.h.cmakein
Normal file
16
zlibdefs.h.cmakein
Normal file
@@ -0,0 +1,16 @@
|
||||
/* zlibdefs.h -- compile-time definitions for the zlib compression library
|
||||
* Copyright (C) 1995-2006 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <sys/types.h> /* for off_t */
|
||||
#include <unistd.h> /* for SEEK_* and off_t */
|
||||
#ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#endif
|
||||
50
zutil.h
50
zutil.h
@@ -1,5 +1,5 @@
|
||||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -17,24 +17,24 @@
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef _WIN32_WCE
|
||||
# if !(defined(_WIN32_WCE) && defined(_MSV_VER))
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#if defined(NO_ERRNO_H) || defined(_WIN32_WCE)
|
||||
# ifdef _WIN32_WCE
|
||||
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
||||
* errno. We define it as a global variable to simplify porting.
|
||||
* Its value is always 0 and should not be used. We rename it to
|
||||
* avoid conflict with other libraries that use the same workaround.
|
||||
*/
|
||||
# define errno z_errno
|
||||
# endif
|
||||
extern int errno;
|
||||
|
||||
#if defined(UNDER_CE) && defined(NO_ERRNO_H)
|
||||
# define zseterrno(ERR) SetLastError((DWORD)(ERR))
|
||||
# define zerrno() ((int)GetLastError())
|
||||
#else
|
||||
# include <errno.h>
|
||||
# ifdef NO_ERRNO_H
|
||||
extern int errno;
|
||||
# else
|
||||
# include <errno.h>
|
||||
# endif
|
||||
# define zseterrno(ERR) do { errno = (ERR); } while (0)
|
||||
# define zerrno() errno
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
@@ -87,7 +87,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||
# define OS_CODE 0x00
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
@@ -159,6 +159,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
# else
|
||||
# define fdopen(fd,type) _fdopen(fd,type)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma warn -8004
|
||||
#pragma warn -8008
|
||||
#pragma warn -8066
|
||||
#endif
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
/* common defaults */
|
||||
@@ -169,6 +181,12 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
# define F_OPEN64(name, mode) fopen64((name), (mode))
|
||||
#else
|
||||
# define F_OPEN64(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
/* functions */
|
||||
@@ -195,7 +213,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# define vsnprintf _vsnprintf
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
|
||||
Reference in New Issue
Block a user