Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch zlib Excluding Merge-Ins
This is equivalent to a diff from 77cd6e0dfb to 36734cfcf7
2012-11-27
| ||
13:21 | Add zlib sources to the tree in the compat/zlib subdirectory and use them to build Fossil on windows systems that lack a zlib library. check-in: 7ef7284d6b user: drh tags: trunk | |
09:42 | blob_to_utf8_no_bom(): the starts_with_utf16(le|be)_bom calls were swapped. check-in: d27cddf17c user: jan.nijtmans tags: trunk | |
09:10 | merge trunk check-in: 43caa73788 user: jan.nijtmans tags: convert_before_commit_v2 | |
07:03 | Modify the MinGW makefile to support building with zlib in the compat directory. Closed-Leaf check-in: 36734cfcf7 user: mistachkin tags: zlib | |
06:31 | Support building with zlib in the compat directory, phase 1. check-in: d17f4473cf user: mistachkin tags: zlib | |
00:23 | Assume that the NetSurf browser is operated by a human. check-in: 77cd6e0dfb user: drh tags: trunk | |
2012-11-26
| ||
22:51 | Merge byte-order-mark handling enhancements to trunk. check-in: 9b800ee41c user: mistachkin tags: trunk | |
Added compat/zlib/CMakeLists.txt.
1 +cmake_minimum_required(VERSION 2.4.4) 2 +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) 3 + 4 +project(zlib C) 5 + 6 +set(VERSION "1.2.7") 7 + 8 +set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") 9 +set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") 10 +set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") 11 +set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") 12 +set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") 13 + 14 +include(CheckTypeSize) 15 +include(CheckFunctionExists) 16 +include(CheckIncludeFile) 17 +include(CheckCSourceCompiles) 18 +enable_testing() 19 + 20 +check_include_file(sys/types.h HAVE_SYS_TYPES_H) 21 +check_include_file(stdint.h HAVE_STDINT_H) 22 +check_include_file(stddef.h HAVE_STDDEF_H) 23 + 24 +# 25 +# Check to see if we have large file support 26 +# 27 +set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) 28 +# We add these other definitions here because CheckTypeSize.cmake 29 +# in CMake 2.4.x does not automatically do so and we want 30 +# compatibility with CMake 2.4.x. 31 +if(HAVE_SYS_TYPES_H) 32 + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) 33 +endif() 34 +if(HAVE_STDINT_H) 35 + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) 36 +endif() 37 +if(HAVE_STDDEF_H) 38 + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) 39 +endif() 40 +check_type_size(off64_t OFF64_T) 41 +if(HAVE_OFF64_T) 42 + add_definitions(-D_LARGEFILE64_SOURCE=1) 43 +endif() 44 +set(CMAKE_REQUIRED_DEFINITIONS) # clear variable 45 + 46 +# 47 +# Check for fseeko 48 +# 49 +check_function_exists(fseeko HAVE_FSEEKO) 50 +if(NOT HAVE_FSEEKO) 51 + add_definitions(-DNO_FSEEKO) 52 +endif() 53 + 54 +# 55 +# Check for unistd.h 56 +# 57 +check_include_file(unistd.h Z_HAVE_UNISTD_H) 58 + 59 +if(MSVC) 60 + set(CMAKE_DEBUG_POSTFIX "d") 61 + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) 62 + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) 63 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 64 +endif() 65 + 66 +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) 67 + # If we're doing an out of source build and the user has a zconf.h 68 + # in their source tree... 69 + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) 70 + message(STATUS "Renaming") 71 + message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") 72 + message(STATUS "to 'zconf.h.included' because this file is included with zlib") 73 + message(STATUS "but CMake generates it automatically in the build directory.") 74 + file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) 75 + endif() 76 +endif() 77 + 78 +set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) 79 +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein 80 + ${ZLIB_PC} @ONLY) 81 +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein 82 + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) 83 +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) 84 + 85 + 86 +#============================================================================ 87 +# zlib 88 +#============================================================================ 89 + 90 +set(ZLIB_PUBLIC_HDRS 91 + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h 92 + zlib.h 93 +) 94 +set(ZLIB_PRIVATE_HDRS 95 + crc32.h 96 + deflate.h 97 + gzguts.h 98 + inffast.h 99 + inffixed.h 100 + inflate.h 101 + inftrees.h 102 + trees.h 103 + zutil.h 104 +) 105 +set(ZLIB_SRCS 106 + adler32.c 107 + compress.c 108 + crc32.c 109 + deflate.c 110 + gzclose.c 111 + gzlib.c 112 + gzread.c 113 + gzwrite.c 114 + inflate.c 115 + infback.c 116 + inftrees.c 117 + inffast.c 118 + trees.c 119 + uncompr.c 120 + zutil.c 121 +) 122 + 123 +if(NOT MINGW) 124 + set(ZLIB_SRCS ${ZLIB_SRCS} 125 + win32/zlib1.rc # If present will override custom build rule below. 126 + ) 127 +endif() 128 + 129 +# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION 130 +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) 131 +string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" 132 + "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) 133 + 134 +if(MINGW) 135 + # This gets us DLL resource information when compiling on MinGW. 136 + if(NOT CMAKE_RC_COMPILER) 137 + SET(CMAKE_RC_COMPILER windres.exe) 138 + endif() 139 + 140 + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 141 + COMMAND ${CMAKE_RC_COMPILER} 142 + -D GCC_WINDRES 143 + -I ${CMAKE_CURRENT_SOURCE_DIR} 144 + -I ${CMAKE_CURRENT_BINARY_DIR} 145 + -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 146 + -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) 147 + set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) 148 +endif(MINGW) 149 + 150 +add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 151 +add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 152 +set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) 153 +set_target_properties(zlib PROPERTIES SOVERSION 1) 154 + 155 +if(NOT CYGWIN) 156 + # This property causes shared libraries on Linux to have the full version 157 + # encoded into their final filename. We disable this on Cygwin because 158 + # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll 159 + # seems to be the default. 160 + # 161 + # This has no effect with MSVC, on that platform the version info for 162 + # the DLL comes from the resource file win32/zlib1.rc 163 + set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) 164 +endif() 165 + 166 +if(UNIX) 167 + # On unix-like platforms the library is almost always called libz 168 + set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) 169 + set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/zlib.map") 170 +elseif(BUILD_SHARED_LIBS AND WIN32) 171 + # Creates zlib1.dll when building shared library version 172 + set_target_properties(zlib PROPERTIES SUFFIX "1.dll") 173 +endif() 174 + 175 +if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) 176 + install(TARGETS zlib zlibstatic 177 + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" 178 + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" 179 + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) 180 +endif() 181 +if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) 182 + install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") 183 +endif() 184 +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) 185 + install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") 186 +endif() 187 +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) 188 + install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") 189 +endif() 190 + 191 +#============================================================================ 192 +# Example binaries 193 +#============================================================================ 194 + 195 +add_executable(example test/example.c) 196 +target_link_libraries(example zlib) 197 +add_test(example example) 198 + 199 +add_executable(minigzip test/minigzip.c) 200 +target_link_libraries(minigzip zlib) 201 + 202 +if(HAVE_OFF64_T) 203 + add_executable(example64 test/example.c) 204 + target_link_libraries(example64 zlib) 205 + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") 206 + add_test(example64 example64) 207 + 208 + add_executable(minigzip64 test/minigzip.c) 209 + target_link_libraries(minigzip64 zlib) 210 + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") 211 +endif()
Added compat/zlib/ChangeLog.
1 + 2 + ChangeLog file for zlib 3 + 4 +Changes in 1.2.7 (2 May 2012) 5 +- Replace use of memmove() with a simple copy for portability 6 +- Test for existence of strerror 7 +- Restore gzgetc_ for backward compatibility with 1.2.6 8 +- Fix build with non-GNU make on Solaris 9 +- Require gcc 4.0 or later on Mac OS X to use the hidden attribute 10 +- Include unistd.h for Watcom C 11 +- Use __WATCOMC__ instead of __WATCOM__ 12 +- Do not use the visibility attribute if NO_VIZ defined 13 +- Improve the detection of no hidden visibility attribute 14 +- Avoid using __int64 for gcc or solo compilation 15 +- Cast to char * in gzprintf to avoid warnings [Zinser] 16 +- Fix make_vms.com for VAX [Zinser] 17 +- Don't use library or built-in byte swaps 18 +- Simplify test and use of gcc hidden attribute 19 +- Fix bug in gzclose_w() when gzwrite() fails to allocate memory 20 +- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen() 21 +- Fix bug in test/minigzip.c for configure --solo 22 +- Fix contrib/vstudio project link errors [Mohanathas] 23 +- Add ability to choose the builder in make_vms.com [Schweda] 24 +- Add DESTDIR support to mingw32 win32/Makefile.gcc 25 +- Fix comments in win32/Makefile.gcc for proper usage 26 +- Allow overriding the default install locations for cmake 27 +- Generate and install the pkg-config file with cmake 28 +- Build both a static and a shared version of zlib with cmake 29 +- Include version symbols for cmake builds 30 +- If using cmake with MSVC, add the source directory to the includes 31 +- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta] 32 +- Move obsolete emx makefile to old [Truta] 33 +- Allow the use of -Wundef when compiling or using zlib 34 +- Avoid the use of the -u option with mktemp 35 +- Improve inflate() documentation on the use of Z_FINISH 36 +- Recognize clang as gcc 37 +- Add gzopen_w() in Windows for wide character path names 38 +- Rename zconf.h in CMakeLists.txt to move it out of the way 39 +- Add source directory in CMakeLists.txt for building examples 40 +- Look in build directory for zlib.pc in CMakeLists.txt 41 +- Remove gzflags from zlibvc.def in vc9 and vc10 42 +- Fix contrib/minizip compilation in the MinGW environment 43 +- Update ./configure for Solaris, support --64 [Mooney] 44 +- Remove -R. from Solaris shared build (possible security issue) 45 +- Avoid race condition for parallel make (-j) running example 46 +- Fix type mismatch between get_crc_table() and crc_table 47 +- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler] 48 +- Fix the path to zlib.map in CMakeLists.txt 49 +- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe] 50 +- Add instructions to win32/Makefile.gcc for shared install [Torri] 51 + 52 +Changes in 1.2.6.1 (12 Feb 2012) 53 +- Avoid the use of the Objective-C reserved name "id" 54 +- Include io.h in gzguts.h for Microsoft compilers 55 +- Fix problem with ./configure --prefix and gzgetc macro 56 +- Include gz_header definition when compiling zlib solo 57 +- Put gzflags() functionality back in zutil.c 58 +- Avoid library header include in crc32.c for Z_SOLO 59 +- Use name in GCC_CLASSIC as C compiler for coverage testing, if set 60 +- Minor cleanup in contrib/minizip/zip.c [Vollant] 61 +- Update make_vms.com [Zinser] 62 +- Remove unnecessary gzgetc_ function 63 +- Use optimized byte swap operations for Microsoft and GNU [Snyder] 64 +- Fix minor typo in zlib.h comments [Rzesniowiecki] 65 + 66 +Changes in 1.2.6 (29 Jan 2012) 67 +- Update the Pascal interface in contrib/pascal 68 +- Fix function numbers for gzgetc_ in zlibvc.def files 69 +- Fix configure.ac for contrib/minizip [Schiffer] 70 +- Fix large-entry detection in minizip on 64-bit systems [Schiffer] 71 +- Have ./configure use the compiler return code for error indication 72 +- Fix CMakeLists.txt for cross compilation [McClure] 73 +- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] 74 +- Fix compilation of contrib/minizip on FreeBSD [Marquez] 75 +- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] 76 +- Include io.h for Turbo C / Borland C on all platforms [Truta] 77 +- Make version explicit in contrib/minizip/configure.ac [Bosmans] 78 +- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] 79 +- Minor cleanup up contrib/minizip/unzip.c [Vollant] 80 +- Fix bug when compiling minizip with C++ [Vollant] 81 +- Protect for long name and extra fields in contrib/minizip [Vollant] 82 +- Avoid some warnings in contrib/minizip [Vollant] 83 +- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip 84 +- Add missing libs to minizip linker command 85 +- Add support for VPATH builds in contrib/minizip 86 +- Add an --enable-demos option to contrib/minizip/configure 87 +- Add the generation of configure.log by ./configure 88 +- Exit when required parameters not provided to win32/Makefile.gcc 89 +- Have gzputc return the character written instead of the argument 90 +- Use the -m option on ldconfig for BSD systems [Tobias] 91 +- Correct in zlib.map when deflateResetKeep was added 92 + 93 +Changes in 1.2.5.3 (15 Jan 2012) 94 +- Restore gzgetc function for binary compatibility 95 +- Do not use _lseeki64 under Borland C++ [Truta] 96 +- Update win32/Makefile.msc to build test/*.c [Truta] 97 +- Remove old/visualc6 given CMakefile and other alternatives 98 +- Update AS400 build files and documentation [Monnerat] 99 +- Update win32/Makefile.gcc to build test/*.c [Truta] 100 +- Permit stronger flushes after Z_BLOCK flushes 101 +- Avoid extraneous empty blocks when doing empty flushes 102 +- Permit Z_NULL arguments to deflatePending 103 +- Allow deflatePrime() to insert bits in the middle of a stream 104 +- Remove second empty static block for Z_PARTIAL_FLUSH 105 +- Write out all of the available bits when using Z_BLOCK 106 +- Insert the first two strings in the hash table after a flush 107 + 108 +Changes in 1.2.5.2 (17 Dec 2011) 109 +- fix ld error: unable to find version dependency 'ZLIB_1.2.5' 110 +- use relative symlinks for shared libs 111 +- Avoid searching past window for Z_RLE strategy 112 +- Assure that high-water mark initialization is always applied in deflate 113 +- Add assertions to fill_window() in deflate.c to match comments 114 +- Update python link in README 115 +- Correct spelling error in gzread.c 116 +- Fix bug in gzgets() for a concatenated empty gzip stream 117 +- Correct error in comment for gz_make() 118 +- Change gzread() and related to ignore junk after gzip streams 119 +- Allow gzread() and related to continue after gzclearerr() 120 +- Allow gzrewind() and gzseek() after a premature end-of-file 121 +- Simplify gzseek() now that raw after gzip is ignored 122 +- Change gzgetc() to a macro for speed (~40% speedup in testing) 123 +- Fix gzclose() to return the actual error last encountered 124 +- Always add large file support for windows 125 +- Include zconf.h for windows large file support 126 +- Include zconf.h.cmakein for windows large file support 127 +- Update zconf.h.cmakein on make distclean 128 +- Merge vestigial vsnprintf determination from zutil.h to gzguts.h 129 +- Clarify how gzopen() appends in zlib.h comments 130 +- Correct documentation of gzdirect() since junk at end now ignored 131 +- Add a transparent write mode to gzopen() when 'T' is in the mode 132 +- Update python link in zlib man page 133 +- Get inffixed.h and MAKEFIXED result to match 134 +- Add a ./config --solo option to make zlib subset with no libary use 135 +- Add undocumented inflateResetKeep() function for CAB file decoding 136 +- Add --cover option to ./configure for gcc coverage testing 137 +- Add #define ZLIB_CONST option to use const in the z_stream interface 138 +- Add comment to gzdopen() in zlib.h to use dup() when using fileno() 139 +- Note behavior of uncompress() to provide as much data as it can 140 +- Add files in contrib/minizip to aid in building libminizip 141 +- Split off AR options in Makefile.in and configure 142 +- Change ON macro to Z_ARG to avoid application conflicts 143 +- Facilitate compilation with Borland C++ for pragmas and vsnprintf 144 +- Include io.h for Turbo C / Borland C++ 145 +- Move example.c and minigzip.c to test/ 146 +- Simplify incomplete code table filling in inflate_table() 147 +- Remove code from inflate.c and infback.c that is impossible to execute 148 +- Test the inflate code with full coverage 149 +- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) 150 +- Add deflateResetKeep and fix inflateResetKeep to retain dictionary 151 +- Fix gzwrite.c to accommodate reduced memory zlib compilation 152 +- Have inflate() with Z_FINISH avoid the allocation of a window 153 +- Do not set strm->adler when doing raw inflate 154 +- Fix gzeof() to behave just like feof() when read is not past end of file 155 +- Fix bug in gzread.c when end-of-file is reached 156 +- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF 157 +- Document gzread() capability to read concurrently written files 158 +- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] 159 + 160 +Changes in 1.2.5.1 (10 Sep 2011) 161 +- Update FAQ entry on shared builds (#13) 162 +- Avoid symbolic argument to chmod in Makefile.in 163 +- Fix bug and add consts in contrib/puff [Oberhumer] 164 +- Update contrib/puff/zeros.raw test file to have all block types 165 +- Add full coverage test for puff in contrib/puff/Makefile 166 +- Fix static-only-build install in Makefile.in 167 +- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] 168 +- Add libz.a dependency to shared in Makefile.in for parallel builds 169 +- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out 170 +- Replace $(...) with `...` in configure for non-bash sh [Bowler] 171 +- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] 172 +- Add solaris* to Linux* in configure to allow gcc use [Groffen] 173 +- Add *bsd* to Linux* case in configure [Bar-Lev] 174 +- Add inffast.obj to dependencies in win32/Makefile.msc 175 +- Correct spelling error in deflate.h [Kohler] 176 +- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc 177 +- Add test to configure for GNU C looking for gcc in output of $cc -v 178 +- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] 179 +- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not 180 +- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense 181 +- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) 182 +- Make stronger test in zconf.h to include unistd.h for LFS 183 +- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] 184 +- Fix zlib.h LFS support when Z_PREFIX used 185 +- Add updated as400 support (removed from old) [Monnerat] 186 +- Avoid deflate sensitivity to volatile input data 187 +- Avoid division in adler32_combine for NO_DIVIDE 188 +- Clarify the use of Z_FINISH with deflateBound() amount of space 189 +- Set binary for output file in puff.c 190 +- Use u4 type for crc_table to avoid conversion warnings 191 +- Apply casts in zlib.h to avoid conversion warnings 192 +- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] 193 +- Improve inflateSync() documentation to note indeterminancy 194 +- Add deflatePending() function to return the amount of pending output 195 +- Correct the spelling of "specification" in FAQ [Randers-Pehrson] 196 +- Add a check in configure for stdarg.h, use for gzprintf() 197 +- Check that pointers fit in ints when gzprint() compiled old style 198 +- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] 199 +- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] 200 +- Add debug records in assmebler code [Londer] 201 +- Update RFC references to use http://tools.ietf.org/html/... [Li] 202 +- Add --archs option, use of libtool to configure for Mac OS X [Borstel] 203 + 204 +Changes in 1.2.5 (19 Apr 2010) 205 +- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] 206 +- Default to libdir as sharedlibdir in configure [Nieder] 207 +- Update copyright dates on modified source files 208 +- Update trees.c to be able to generate modified trees.h 209 +- Exit configure for MinGW, suggesting win32/Makefile.gcc 210 +- Check for NULL path in gz_open [Homurlu] 211 + 212 +Changes in 1.2.4.5 (18 Apr 2010) 213 +- Set sharedlibdir in configure [Torok] 214 +- Set LDFLAGS in Makefile.in [Bar-Lev] 215 +- Avoid mkdir objs race condition in Makefile.in [Bowler] 216 +- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays 217 +- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C 218 +- Don't use hidden attribute when it is a warning generator (e.g. Solaris) 219 + 220 +Changes in 1.2.4.4 (18 Apr 2010) 221 +- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] 222 +- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty 223 +- Try to use bash or ksh regardless of functionality of /bin/sh 224 +- Fix configure incompatibility with NetBSD sh 225 +- Remove attempt to run under bash or ksh since have better NetBSD fix 226 +- Fix win32/Makefile.gcc for MinGW [Bar-Lev] 227 +- Add diagnostic messages when using CROSS_PREFIX in configure 228 +- Added --sharedlibdir option to configure [Weigelt] 229 +- Use hidden visibility attribute when available [Frysinger] 230 + 231 +Changes in 1.2.4.3 (10 Apr 2010) 232 +- Only use CROSS_PREFIX in configure for ar and ranlib if they exist 233 +- Use CROSS_PREFIX for nm [Bar-Lev] 234 +- Assume _LARGEFILE64_SOURCE defined is equivalent to true 235 +- Avoid use of undefined symbols in #if with && and || 236 +- Make *64 prototypes in gzguts.h consistent with functions 237 +- Add -shared load option for MinGW in configure [Bowler] 238 +- Move z_off64_t to public interface, use instead of off64_t 239 +- Remove ! from shell test in configure (not portable to Solaris) 240 +- Change +0 macro tests to -0 for possibly increased portability 241 + 242 +Changes in 1.2.4.2 (9 Apr 2010) 243 +- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 244 +- Really provide prototypes for *64 functions when building without LFS 245 +- Only define unlink() in minigzip.c if unistd.h not included 246 +- Update README to point to contrib/vstudio project files 247 +- Move projects/vc6 to old/ and remove projects/ 248 +- Include stdlib.h in minigzip.c for setmode() definition under WinCE 249 +- Clean up assembler builds in win32/Makefile.msc [Rowe] 250 +- Include sys/types.h for Microsoft for off_t definition 251 +- Fix memory leak on error in gz_open() 252 +- Symbolize nm as $NM in configure [Weigelt] 253 +- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] 254 +- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined 255 +- Fix bug in gzeof() to take into account unused input data 256 +- Avoid initialization of structures with variables in puff.c 257 +- Updated win32/README-WIN32.txt [Rowe] 258 + 259 +Changes in 1.2.4.1 (28 Mar 2010) 260 +- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] 261 +- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] 262 +- Restore "for debugging" comment on sprintf() in gzlib.c 263 +- Remove fdopen for MVS from gzguts.h 264 +- Put new README-WIN32.txt in win32 [Rowe] 265 +- Add check for shell to configure and invoke another shell if needed 266 +- Fix big fat stinking bug in gzseek() on uncompressed files 267 +- Remove vestigial F_OPEN64 define in zutil.h 268 +- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE 269 +- Avoid errors on non-LFS systems when applications define LFS macros 270 +- Set EXE to ".exe" in configure for MINGW [Kahle] 271 +- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] 272 +- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] 273 +- Add DLL install in win32/makefile.gcc [Bar-Lev] 274 +- Allow Linux* or linux* from uname in configure [Bar-Lev] 275 +- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] 276 +- Add cross-compilation prefixes to configure [Bar-Lev] 277 +- Match type exactly in gz_load() invocation in gzread.c 278 +- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func 279 +- Provide prototypes for *64 functions when building zlib without LFS 280 +- Don't use -lc when linking shared library on MinGW 281 +- Remove errno.h check in configure and vestigial errno code in zutil.h 282 + 283 +Changes in 1.2.4 (14 Mar 2010) 284 +- Fix VER3 extraction in configure for no fourth subversion 285 +- Update zlib.3, add docs to Makefile.in to make .pdf out of it 286 +- Add zlib.3.pdf to distribution 287 +- Don't set error code in gzerror() if passed pointer is NULL 288 +- Apply destination directory fixes to CMakeLists.txt [Lowman] 289 +- Move #cmakedefine's to a new zconf.in.cmakein 290 +- Restore zconf.h for builds that don't use configure or cmake 291 +- Add distclean to dummy Makefile for convenience 292 +- Update and improve INDEX, README, and FAQ 293 +- Update CMakeLists.txt for the return of zconf.h [Lowman] 294 +- Update contrib/vstudio/vc9 and vc10 [Vollant] 295 +- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc 296 +- Apply license and readme changes to contrib/asm686 [Raiter] 297 +- Check file name lengths and add -c option in minigzip.c [Li] 298 +- Update contrib/amd64 and contrib/masmx86/ [Vollant] 299 +- Avoid use of "eof" parameter in trees.c to not shadow library variable 300 +- Update make_vms.com for removal of zlibdefs.h [Zinser] 301 +- Update assembler code and vstudio projects in contrib [Vollant] 302 +- Remove outdated assembler code contrib/masm686 and contrib/asm586 303 +- Remove old vc7 and vc8 from contrib/vstudio 304 +- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] 305 +- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() 306 +- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] 307 +- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) 308 +- Fix bug in void-returning vsprintf() case in gzwrite.c 309 +- Fix name change from inflate.h in contrib/inflate86/inffas86.c 310 +- Check if temporary file exists before removing in make_vms.com [Zinser] 311 +- Fix make install and uninstall for --static option 312 +- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] 313 +- Update readme.txt in contrib/masmx64 and masmx86 to assemble 314 + 315 +Changes in 1.2.3.9 (21 Feb 2010) 316 +- Expunge gzio.c 317 +- Move as400 build information to old 318 +- Fix updates in contrib/minizip and contrib/vstudio 319 +- Add const to vsnprintf test in configure to avoid warnings [Weigelt] 320 +- Delete zconf.h (made by configure) [Weigelt] 321 +- Change zconf.in.h to zconf.h.in per convention [Weigelt] 322 +- Check for NULL buf in gzgets() 323 +- Return empty string for gzgets() with len == 1 (like fgets()) 324 +- Fix description of gzgets() in zlib.h for end-of-file, NULL return 325 +- Update minizip to 1.1 [Vollant] 326 +- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c 327 +- Note in zlib.h that gzerror() should be used to distinguish from EOF 328 +- Remove use of snprintf() from gzlib.c 329 +- Fix bug in gzseek() 330 +- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] 331 +- Fix zconf.h generation in CMakeLists.txt [Lowman] 332 +- Improve comments in zconf.h where modified by configure 333 + 334 +Changes in 1.2.3.8 (13 Feb 2010) 335 +- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] 336 +- Use z_off64_t in gz_zero() and gz_skip() to match state->skip 337 +- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) 338 +- Revert to Makefile.in from 1.2.3.6 (live with the clutter) 339 +- Fix missing error return in gzflush(), add zlib.h note 340 +- Add *64 functions to zlib.map [Levin] 341 +- Fix signed/unsigned comparison in gz_comp() 342 +- Use SFLAGS when testing shared linking in configure 343 +- Add --64 option to ./configure to use -m64 with gcc 344 +- Fix ./configure --help to correctly name options 345 +- Have make fail if a test fails [Levin] 346 +- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] 347 +- Remove assembler object files from contrib 348 + 349 +Changes in 1.2.3.7 (24 Jan 2010) 350 +- Always gzopen() with O_LARGEFILE if available 351 +- Fix gzdirect() to work immediately after gzopen() or gzdopen() 352 +- Make gzdirect() more precise when the state changes while reading 353 +- Improve zlib.h documentation in many places 354 +- Catch memory allocation failure in gz_open() 355 +- Complete close operation if seek forward in gzclose_w() fails 356 +- Return Z_ERRNO from gzclose_r() if close() fails 357 +- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL 358 +- Return zero for gzwrite() errors to match zlib.h description 359 +- Return -1 on gzputs() error to match zlib.h description 360 +- Add zconf.in.h to allow recovery from configure modification [Weigelt] 361 +- Fix static library permissions in Makefile.in [Weigelt] 362 +- Avoid warnings in configure tests that hide functionality [Weigelt] 363 +- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] 364 +- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] 365 +- Avoid access of uninitialized data for first inflateReset2 call [Gomes] 366 +- Keep object files in subdirectories to reduce the clutter somewhat 367 +- Remove default Makefile and zlibdefs.h, add dummy Makefile 368 +- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ 369 +- Remove zlibdefs.h completely -- modify zconf.h instead 370 + 371 +Changes in 1.2.3.6 (17 Jan 2010) 372 +- Avoid void * arithmetic in gzread.c and gzwrite.c 373 +- Make compilers happier with const char * for gz_error message 374 +- Avoid unused parameter warning in inflate.c 375 +- Avoid signed-unsigned comparison warning in inflate.c 376 +- Indent #pragma's for traditional C 377 +- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() 378 +- Correct email address in configure for system options 379 +- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] 380 +- Update zlib.map [Brown] 381 +- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] 382 +- Apply various fixes to CMakeLists.txt [Lowman] 383 +- Add checks on len in gzread() and gzwrite() 384 +- Add error message for no more room for gzungetc() 385 +- Remove zlib version check in gzwrite() 386 +- Defer compression of gzprintf() result until need to 387 +- Use snprintf() in gzdopen() if available 388 +- Remove USE_MMAP configuration determination (only used by minigzip) 389 +- Remove examples/pigz.c (available separately) 390 +- Update examples/gun.c to 1.6 391 + 392 +Changes in 1.2.3.5 (8 Jan 2010) 393 +- Add space after #if in zutil.h for some compilers 394 +- Fix relatively harmless bug in deflate_fast() [Exarevsky] 395 +- Fix same problem in deflate_slow() 396 +- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] 397 +- Add deflate_rle() for faster Z_RLE strategy run-length encoding 398 +- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding 399 +- Change name of "write" variable in inffast.c to avoid library collisions 400 +- Fix premature EOF from gzread() in gzio.c [Brown] 401 +- Use zlib header window size if windowBits is 0 in inflateInit2() 402 +- Remove compressBound() call in deflate.c to avoid linking compress.o 403 +- Replace use of errno in gz* with functions, support WinCE [Alves] 404 +- Provide alternative to perror() in minigzip.c for WinCE [Alves] 405 +- Don't use _vsnprintf on later versions of MSVC [Lowman] 406 +- Add CMake build script and input file [Lowman] 407 +- Update contrib/minizip to 1.1 [Svensson, Vollant] 408 +- Moved nintendods directory from contrib to . 409 +- Replace gzio.c with a new set of routines with the same functionality 410 +- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above 411 +- Update contrib/minizip to 1.1b 412 +- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h 413 + 414 +Changes in 1.2.3.4 (21 Dec 2009) 415 +- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility 416 +- Update comments in configure and Makefile.in for default --shared 417 +- Fix test -z's in configure [Marquess] 418 +- Build examplesh and minigzipsh when not testing 419 +- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h 420 +- Import LDFLAGS from the environment in configure 421 +- Fix configure to populate SFLAGS with discovered CFLAGS options 422 +- Adapt make_vms.com to the new Makefile.in [Zinser] 423 +- Add zlib2ansi script for C++ compilation [Marquess] 424 +- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) 425 +- Add AMD64 assembler code for longest match to contrib [Teterin] 426 +- Include options from $SFLAGS when doing $LDSHARED 427 +- Simplify 64-bit file support by introducing z_off64_t type 428 +- Make shared object files in objs directory to work around old Sun cc 429 +- Use only three-part version number for Darwin shared compiles 430 +- Add rc option to ar in Makefile.in for when ./configure not run 431 +- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* 432 +- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile 433 +- Protect against _FILE_OFFSET_BITS being defined when compiling zlib 434 +- Rename Makefile.in targets allstatic to static and allshared to shared 435 +- Fix static and shared Makefile.in targets to be independent 436 +- Correct error return bug in gz_open() by setting state [Brown] 437 +- Put spaces before ;;'s in configure for better sh compatibility 438 +- Add pigz.c (parallel implementation of gzip) to examples/ 439 +- Correct constant in crc32.c to UL [Leventhal] 440 +- Reject negative lengths in crc32_combine() 441 +- Add inflateReset2() function to work like inflateEnd()/inflateInit2() 442 +- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] 443 +- Correct typo in doc/algorithm.txt [Janik] 444 +- Fix bug in adler32_combine() [Zhu] 445 +- Catch missing-end-of-block-code error in all inflates and in puff 446 + Assures that random input to inflate eventually results in an error 447 +- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ 448 +- Update ENOUGH and its usage to reflect discovered bounds 449 +- Fix gzerror() error report on empty input file [Brown] 450 +- Add ush casts in trees.c to avoid pedantic runtime errors 451 +- Fix typo in zlib.h uncompress() description [Reiss] 452 +- Correct inflate() comments with regard to automatic header detection 453 +- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) 454 +- Put new version of gzlog (2.0) in examples with interruption recovery 455 +- Add puff compile option to permit invalid distance-too-far streams 456 +- Add puff TEST command options, ability to read piped input 457 +- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but 458 + _LARGEFILE64_SOURCE not defined 459 +- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart 460 +- Fix deflateSetDictionary() to use all 32K for output consistency 461 +- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) 462 +- Clear bytes after deflate lookahead to avoid use of uninitialized data 463 +- Change a limit in inftrees.c to be more transparent to Coverity Prevent 464 +- Update win32/zlib.def with exported symbols from zlib.h 465 +- Correct spelling errors in zlib.h [Willem, Sobrado] 466 +- Allow Z_BLOCK for deflate() to force a new block 467 +- Allow negative bits in inflatePrime() to delete existing bit buffer 468 +- Add Z_TREES flush option to inflate() to return at end of trees 469 +- Add inflateMark() to return current state information for random access 470 +- Add Makefile for NintendoDS to contrib [Costa] 471 +- Add -w in configure compile tests to avoid spurious warnings [Beucler] 472 +- Fix typos in zlib.h comments for deflateSetDictionary() 473 +- Fix EOF detection in transparent gzread() [Maier] 474 + 475 +Changes in 1.2.3.3 (2 October 2006) 476 +- Make --shared the default for configure, add a --static option 477 +- Add compile option to permit invalid distance-too-far streams 478 +- Add inflateUndermine() function which is required to enable above 479 +- Remove use of "this" variable name for C++ compatibility [Marquess] 480 +- Add testing of shared library in make test, if shared library built 481 +- Use ftello() and fseeko() if available instead of ftell() and fseek() 482 +- Provide two versions of all functions that use the z_off_t type for 483 + binary compatibility -- a normal version and a 64-bit offset version, 484 + per the Large File Support Extension when _LARGEFILE64_SOURCE is 485 + defined; use the 64-bit versions by default when _FILE_OFFSET_BITS 486 + is defined to be 64 487 +- Add a --uname= option to configure to perhaps help with cross-compiling 488 + 489 +Changes in 1.2.3.2 (3 September 2006) 490 +- Turn off silly Borland warnings [Hay] 491 +- Use off64_t and define _LARGEFILE64_SOURCE when present 492 +- Fix missing dependency on inffixed.h in Makefile.in 493 +- Rig configure --shared to build both shared and static [Teredesai, Truta] 494 +- Remove zconf.in.h and instead create a new zlibdefs.h file 495 +- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] 496 +- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] 497 + 498 +Changes in 1.2.3.1 (16 August 2006) 499 +- Add watcom directory with OpenWatcom make files [Daniel] 500 +- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] 501 +- Update make_vms.com [Zinser] 502 +- Use -fPIC for shared build in configure [Teredesai, Nicholson] 503 +- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] 504 +- Use fdopen() (not _fdopen()) for Interix in zutil.h [B�ck] 505 +- Add some FAQ entries about the contrib directory 506 +- Update the MVS question in the FAQ 507 +- Avoid extraneous reads after EOF in gzio.c [Brown] 508 +- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] 509 +- Add comments to zlib.h about gzerror() usage [Brown] 510 +- Set extra flags in gzip header in gzopen() like deflate() does 511 +- Make configure options more compatible with double-dash conventions 512 + [Weigelt] 513 +- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] 514 +- Fix uninstall target in Makefile.in [Truta] 515 +- Add pkgconfig support [Weigelt] 516 +- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] 517 +- Replace set_data_type() with a more accurate detect_data_type() in 518 + trees.c, according to the txtvsbin.txt document [Truta] 519 +- Swap the order of #include <stdio.h> and #include "zlib.h" in 520 + gzio.c, example.c and minigzip.c [Truta] 521 +- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, 522 + Truta] (where?) 523 +- Fix target "clean" from win32/Makefile.bor [Truta] 524 +- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] 525 +- Update zlib www home address in win32/DLL_FAQ.txt [Truta] 526 +- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] 527 +- Enable browse info in the "Debug" and "ASM Debug" configurations in 528 + the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] 529 +- Add pkgconfig support [Weigelt] 530 +- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, 531 + for use in win32/zlib1.rc [Polushin, Rowe, Truta] 532 +- Add a document that explains the new text detection scheme to 533 + doc/txtvsbin.txt [Truta] 534 +- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] 535 +- Move algorithm.txt into doc/ [Truta] 536 +- Synchronize FAQ with website 537 +- Fix compressBound(), was low for some pathological cases [Fearnley] 538 +- Take into account wrapper variations in deflateBound() 539 +- Set examples/zpipe.c input and output to binary mode for Windows 540 +- Update examples/zlib_how.html with new zpipe.c (also web site) 541 +- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems 542 + that gcc became pickier in 4.0) 543 +- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain 544 + un-versioned, the patch adds versioning only for symbols introduced in 545 + zlib-1.2.0 or later. It also declares as local those symbols which are 546 + not designed to be exported." [Levin] 547 +- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure 548 +- Do not initialize global static by default in trees.c, add a response 549 + NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] 550 +- Don't use strerror() in gzio.c under WinCE [Yakimov] 551 +- Don't use errno.h in zutil.h under WinCE [Yakimov] 552 +- Move arguments for AR to its usage to allow replacing ar [Marot] 553 +- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] 554 +- Improve inflateInit() and inflateInit2() documentation 555 +- Fix structure size comment in inflate.h 556 +- Change configure help option from --h* to --help [Santos] 557 + 558 +Changes in 1.2.3 (18 July 2005) 559 +- Apply security vulnerability fixes to contrib/infback9 as well 560 +- Clean up some text files (carriage returns, trailing space) 561 +- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] 562 + 563 +Changes in 1.2.2.4 (11 July 2005) 564 +- Add inflatePrime() function for starting inflation at bit boundary 565 +- Avoid some Visual C warnings in deflate.c 566 +- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit 567 + compile 568 +- Fix some spelling errors in comments [Betts] 569 +- Correct inflateInit2() error return documentation in zlib.h 570 +- Add zran.c example of compressed data random access to examples 571 + directory, shows use of inflatePrime() 572 +- Fix cast for assignments to strm->state in inflate.c and infback.c 573 +- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] 574 +- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] 575 +- Add cast in trees.c t avoid a warning [Oberhumer] 576 +- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] 577 +- Update make_vms.com [Zinser] 578 +- Initialize state->write in inflateReset() since copied in inflate_fast() 579 +- Be more strict on incomplete code sets in inflate_table() and increase 580 + ENOUGH and MAXD -- this repairs a possible security vulnerability for 581 + invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for 582 + discovering the vulnerability and providing test cases. 583 +- Add ia64 support to configure for HP-UX [Smith] 584 +- Add error return to gzread() for format or i/o error [Levin] 585 +- Use malloc.h for OS/2 [Necasek] 586 + 587 +Changes in 1.2.2.3 (27 May 2005) 588 +- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile 589 +- Typecast fread() return values in gzio.c [Vollant] 590 +- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) 591 +- Fix crc check bug in gzread() after gzungetc() [Heiner] 592 +- Add the deflateTune() function to adjust internal compression parameters 593 +- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) 594 +- Remove an incorrect assertion in examples/zpipe.c 595 +- Add C++ wrapper in infback9.h [Donais] 596 +- Fix bug in inflateCopy() when decoding fixed codes 597 +- Note in zlib.h how much deflateSetDictionary() actually uses 598 +- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) 599 +- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] 600 +- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] 601 +- Add gzdirect() function to indicate transparent reads 602 +- Update contrib/minizip [Vollant] 603 +- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] 604 +- Add casts in crc32.c to avoid warnings [Oberhumer] 605 +- Add contrib/masmx64 [Vollant] 606 +- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] 607 + 608 +Changes in 1.2.2.2 (30 December 2004) 609 +- Replace structure assignments in deflate.c and inflate.c with zmemcpy to 610 + avoid implicit memcpy calls (portability for no-library compilation) 611 +- Increase sprintf() buffer size in gzdopen() to allow for large numbers 612 +- Add INFLATE_STRICT to check distances against zlib header 613 +- Improve WinCE errno handling and comments [Chang] 614 +- Remove comment about no gzip header processing in FAQ 615 +- Add Z_FIXED strategy option to deflateInit2() to force fixed trees 616 +- Add updated make_vms.com [Coghlan], update README 617 +- Create a new "examples" directory, move gzappend.c there, add zpipe.c, 618 + fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. 619 +- Add FAQ entry and comments in deflate.c on uninitialized memory access 620 +- Add Solaris 9 make options in configure [Gilbert] 621 +- Allow strerror() usage in gzio.c for STDC 622 +- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] 623 +- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] 624 +- Use z_off_t for adler32_combine() and crc32_combine() lengths 625 +- Make adler32() much faster for small len 626 +- Use OS_CODE in deflate() default gzip header 627 + 628 +Changes in 1.2.2.1 (31 October 2004) 629 +- Allow inflateSetDictionary() call for raw inflate 630 +- Fix inflate header crc check bug for file names and comments 631 +- Add deflateSetHeader() and gz_header structure for custom gzip headers 632 +- Add inflateGetheader() to retrieve gzip headers 633 +- Add crc32_combine() and adler32_combine() functions 634 +- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list 635 +- Use zstreamp consistently in zlib.h (inflate_back functions) 636 +- Remove GUNZIP condition from definition of inflate_mode in inflate.h 637 + and in contrib/inflate86/inffast.S [Truta, Anderson] 638 +- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] 639 +- Update projects/README.projects and projects/visualc6 [Truta] 640 +- Update win32/DLL_FAQ.txt [Truta] 641 +- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] 642 +- Deprecate Z_ASCII; use Z_TEXT instead [Truta] 643 +- Use a new algorithm for setting strm->data_type in trees.c [Truta] 644 +- Do not define an exit() prototype in zutil.c unless DEBUG defined 645 +- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] 646 +- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() 647 +- Fix Darwin build version identification [Peterson] 648 + 649 +Changes in 1.2.2 (3 October 2004) 650 +- Update zlib.h comments on gzip in-memory processing 651 +- Set adler to 1 in inflateReset() to support Java test suite [Walles] 652 +- Add contrib/dotzlib [Ravn] 653 +- Update win32/DLL_FAQ.txt [Truta] 654 +- Update contrib/minizip [Vollant] 655 +- Move contrib/visual-basic.txt to old/ [Truta] 656 +- Fix assembler builds in projects/visualc6/ [Truta] 657 + 658 +Changes in 1.2.1.2 (9 September 2004) 659 +- Update INDEX file 660 +- Fix trees.c to update strm->data_type (no one ever noticed!) 661 +- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] 662 +- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) 663 +- Add limited multitasking protection to DYNAMIC_CRC_TABLE 664 +- Add NO_vsnprintf for VMS in zutil.h [Mozilla] 665 +- Don't declare strerror() under VMS [Mozilla] 666 +- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize 667 +- Update contrib/ada [Anisimkov] 668 +- Update contrib/minizip [Vollant] 669 +- Fix configure to not hardcode directories for Darwin [Peterson] 670 +- Fix gzio.c to not return error on empty files [Brown] 671 +- Fix indentation; update version in contrib/delphi/ZLib.pas and 672 + contrib/pascal/zlibpas.pas [Truta] 673 +- Update mkasm.bat in contrib/masmx86 [Truta] 674 +- Update contrib/untgz [Truta] 675 +- Add projects/README.projects [Truta] 676 +- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] 677 +- Update win32/DLL_FAQ.txt [Truta] 678 +- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] 679 +- Remove an unnecessary assignment to curr in inftrees.c [Truta] 680 +- Add OS/2 to exe builds in configure [Poltorak] 681 +- Remove err dummy parameter in zlib.h [Kientzle] 682 + 683 +Changes in 1.2.1.1 (9 January 2004) 684 +- Update email address in README 685 +- Several FAQ updates 686 +- Fix a big fat bug in inftrees.c that prevented decoding valid 687 + dynamic blocks with only literals and no distance codes -- 688 + Thanks to "Hot Emu" for the bug report and sample file 689 +- Add a note to puff.c on no distance codes case. 690 + 691 +Changes in 1.2.1 (17 November 2003) 692 +- Remove a tab in contrib/gzappend/gzappend.c 693 +- Update some interfaces in contrib for new zlib functions 694 +- Update zlib version number in some contrib entries 695 +- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] 696 +- Support shared libraries on Hurd and KFreeBSD [Brown] 697 +- Fix error in NO_DIVIDE option of adler32.c 698 + 699 +Changes in 1.2.0.8 (4 November 2003) 700 +- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas 701 +- Add experimental NO_DIVIDE #define in adler32.c 702 + - Possibly faster on some processors (let me know if it is) 703 +- Correct Z_BLOCK to not return on first inflate call if no wrap 704 +- Fix strm->data_type on inflate() return to correctly indicate EOB 705 +- Add deflatePrime() function for appending in the middle of a byte 706 +- Add contrib/gzappend for an example of appending to a stream 707 +- Update win32/DLL_FAQ.txt [Truta] 708 +- Delete Turbo C comment in README [Truta] 709 +- Improve some indentation in zconf.h [Truta] 710 +- Fix infinite loop on bad input in configure script [Church] 711 +- Fix gzeof() for concatenated gzip files [Johnson] 712 +- Add example to contrib/visual-basic.txt [Michael B.] 713 +- Add -p to mkdir's in Makefile.in [vda] 714 +- Fix configure to properly detect presence or lack of printf functions 715 +- Add AS400 support [Monnerat] 716 +- Add a little Cygwin support [Wilson] 717 + 718 +Changes in 1.2.0.7 (21 September 2003) 719 +- Correct some debug formats in contrib/infback9 720 +- Cast a type in a debug statement in trees.c 721 +- Change search and replace delimiter in configure from % to # [Beebe] 722 +- Update contrib/untgz to 0.2 with various fixes [Truta] 723 +- Add build support for Amiga [Nikl] 724 +- Remove some directories in old that have been updated to 1.2 725 +- Add dylib building for Mac OS X in configure and Makefile.in 726 +- Remove old distribution stuff from Makefile 727 +- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X 728 +- Update links in README 729 + 730 +Changes in 1.2.0.6 (13 September 2003) 731 +- Minor FAQ updates 732 +- Update contrib/minizip to 1.00 [Vollant] 733 +- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] 734 +- Update POSTINC comment for 68060 [Nikl] 735 +- Add contrib/infback9 with deflate64 decoding (unsupported) 736 +- For MVS define NO_vsnprintf and undefine FAR [van Burik] 737 +- Add pragma for fdopen on MVS [van Burik] 738 + 739 +Changes in 1.2.0.5 (8 September 2003) 740 +- Add OF to inflateBackEnd() declaration in zlib.h 741 +- Remember start when using gzdopen in the middle of a file 742 +- Use internal off_t counters in gz* functions to properly handle seeks 743 +- Perform more rigorous check for distance-too-far in inffast.c 744 +- Add Z_BLOCK flush option to return from inflate at block boundary 745 +- Set strm->data_type on return from inflate 746 + - Indicate bits unused, if at block boundary, and if in last block 747 +- Replace size_t with ptrdiff_t in crc32.c, and check for correct size 748 +- Add condition so old NO_DEFLATE define still works for compatibility 749 +- FAQ update regarding the Windows DLL [Truta] 750 +- INDEX update: add qnx entry, remove aix entry [Truta] 751 +- Install zlib.3 into mandir [Wilson] 752 +- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] 753 +- Adapt the zlib interface to the new DLL convention guidelines [Truta] 754 +- Introduce ZLIB_WINAPI macro to allow the export of functions using 755 + the WINAPI calling convention, for Visual Basic [Vollant, Truta] 756 +- Update msdos and win32 scripts and makefiles [Truta] 757 +- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] 758 +- Add contrib/ada [Anisimkov] 759 +- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] 760 +- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] 761 +- Add contrib/masm686 [Truta] 762 +- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm 763 + [Truta, Vollant] 764 +- Update contrib/delphi; rename to contrib/pascal; add example [Truta] 765 +- Remove contrib/delphi2; add a new contrib/delphi [Truta] 766 +- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream, 767 + and fix some method prototypes [Truta] 768 +- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip 769 + [Truta] 770 +- Avoid the use of backslash (\) in contrib/minizip [Vollant] 771 +- Fix file time handling in contrib/untgz; update makefiles [Truta] 772 +- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines 773 + [Vollant] 774 +- Remove contrib/vstudio/vc15_16 [Vollant] 775 +- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] 776 +- Update README.contrib [Truta] 777 +- Invert the assignment order of match_head and s->prev[...] in 778 + INSERT_STRING [Truta] 779 +- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings 780 + [Truta] 781 +- Compare function pointers with 0, not with NULL or Z_NULL [Truta] 782 +- Fix prototype of syncsearch in inflate.c [Truta] 783 +- Introduce ASMINF macro to be enabled when using an ASM implementation 784 + of inflate_fast [Truta] 785 +- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] 786 +- Modify test_gzio in example.c to take a single file name as a 787 + parameter [Truta] 788 +- Exit the example.c program if gzopen fails [Truta] 789 +- Add type casts around strlen in example.c [Truta] 790 +- Remove casting to sizeof in minigzip.c; give a proper type 791 + to the variable compared with SUFFIX_LEN [Truta] 792 +- Update definitions of STDC and STDC99 in zconf.h [Truta] 793 +- Synchronize zconf.h with the new Windows DLL interface [Truta] 794 +- Use SYS16BIT instead of __32BIT__ to distinguish between 795 + 16- and 32-bit platforms [Truta] 796 +- Use far memory allocators in small 16-bit memory models for 797 + Turbo C [Truta] 798 +- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in 799 + zlibCompileFlags [Truta] 800 +- Cygwin has vsnprintf [Wilson] 801 +- In Windows16, OS_CODE is 0, as in MSDOS [Truta] 802 +- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] 803 + 804 +Changes in 1.2.0.4 (10 August 2003) 805 +- Minor FAQ updates 806 +- Be more strict when checking inflateInit2's windowBits parameter 807 +- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well 808 +- Add gzip wrapper option to deflateInit2 using windowBits 809 +- Add updated QNX rule in configure and qnx directory [Bonnefoy] 810 +- Make inflate distance-too-far checks more rigorous 811 +- Clean up FAR usage in inflate 812 +- Add casting to sizeof() in gzio.c and minigzip.c 813 + 814 +Changes in 1.2.0.3 (19 July 2003) 815 +- Fix silly error in gzungetc() implementation [Vollant] 816 +- Update contrib/minizip and contrib/vstudio [Vollant] 817 +- Fix printf format in example.c 818 +- Correct cdecl support in zconf.in.h [Anisimkov] 819 +- Minor FAQ updates 820 + 821 +Changes in 1.2.0.2 (13 July 2003) 822 +- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons 823 +- Attempt to avoid warnings in crc32.c for pointer-int conversion 824 +- Add AIX to configure, remove aix directory [Bakker] 825 +- Add some casts to minigzip.c 826 +- Improve checking after insecure sprintf() or vsprintf() calls 827 +- Remove #elif's from crc32.c 828 +- Change leave label to inf_leave in inflate.c and infback.c to avoid 829 + library conflicts 830 +- Remove inflate gzip decoding by default--only enable gzip decoding by 831 + special request for stricter backward compatibility 832 +- Add zlibCompileFlags() function to return compilation information 833 +- More typecasting in deflate.c to avoid warnings 834 +- Remove leading underscore from _Capital #defines [Truta] 835 +- Fix configure to link shared library when testing 836 +- Add some Windows CE target adjustments [Mai] 837 +- Remove #define ZLIB_DLL in zconf.h [Vollant] 838 +- Add zlib.3 [Rodgers] 839 +- Update RFC URL in deflate.c and algorithm.txt [Mai] 840 +- Add zlib_dll_FAQ.txt to contrib [Truta] 841 +- Add UL to some constants [Truta] 842 +- Update minizip and vstudio [Vollant] 843 +- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h 844 +- Expand use of NO_DUMMY_DECL to avoid all dummy structures 845 +- Added iostream3 to contrib [Schwardt] 846 +- Replace rewind() with fseek() for WinCE [Truta] 847 +- Improve setting of zlib format compression level flags 848 + - Report 0 for huffman and rle strategies and for level == 0 or 1 849 + - Report 2 only for level == 6 850 +- Only deal with 64K limit when necessary at compile time [Truta] 851 +- Allow TOO_FAR check to be turned off at compile time [Truta] 852 +- Add gzclearerr() function [Souza] 853 +- Add gzungetc() function 854 + 855 +Changes in 1.2.0.1 (17 March 2003) 856 +- Add Z_RLE strategy for run-length encoding [Truta] 857 + - When Z_RLE requested, restrict matches to distance one 858 + - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE 859 +- Correct FASTEST compilation to allow level == 0 860 +- Clean up what gets compiled for FASTEST 861 +- Incorporate changes to zconf.in.h [Vollant] 862 + - Refine detection of Turbo C need for dummy returns 863 + - Refine ZLIB_DLL compilation 864 + - Include additional header file on VMS for off_t typedef 865 +- Try to use _vsnprintf where it supplants vsprintf [Vollant] 866 +- Add some casts in inffast.c 867 +- Enchance comments in zlib.h on what happens if gzprintf() tries to 868 + write more than 4095 bytes before compression 869 +- Remove unused state from inflateBackEnd() 870 +- Remove exit(0) from minigzip.c, example.c 871 +- Get rid of all those darn tabs 872 +- Add "check" target to Makefile.in that does the same thing as "test" 873 +- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in 874 +- Update contrib/inflate86 [Anderson] 875 +- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] 876 +- Add msdos and win32 directories with makefiles [Truta] 877 +- More additions and improvements to the FAQ 878 + 879 +Changes in 1.2.0 (9 March 2003) 880 +- New and improved inflate code 881 + - About 20% faster 882 + - Does not allocate 32K window unless and until needed 883 + - Automatically detects and decompresses gzip streams 884 + - Raw inflate no longer needs an extra dummy byte at end 885 + - Added inflateBack functions using a callback interface--even faster 886 + than inflate, useful for file utilities (gzip, zip) 887 + - Added inflateCopy() function to record state for random access on 888 + externally generated deflate streams (e.g. in gzip files) 889 + - More readable code (I hope) 890 +- New and improved crc32() 891 + - About 50% faster, thanks to suggestions from Rodney Brown 892 +- Add deflateBound() and compressBound() functions 893 +- Fix memory leak in deflateInit2() 894 +- Permit setting dictionary for raw deflate (for parallel deflate) 895 +- Fix const declaration for gzwrite() 896 +- Check for some malloc() failures in gzio.c 897 +- Fix bug in gzopen() on single-byte file 0x1f 898 +- Fix bug in gzread() on concatenated file with 0x1f at end of buffer 899 + and next buffer doesn't start with 0x8b 900 +- Fix uncompress() to return Z_DATA_ERROR on truncated input 901 +- Free memory at end of example.c 902 +- Remove MAX #define in trees.c (conflicted with some libraries) 903 +- Fix static const's in deflate.c, gzio.c, and zutil.[ch] 904 +- Declare malloc() and free() in gzio.c if STDC not defined 905 +- Use malloc() instead of calloc() in zutil.c if int big enough 906 +- Define STDC for AIX 907 +- Add aix/ with approach for compiling shared library on AIX 908 +- Add HP-UX support for shared libraries in configure 909 +- Add OpenUNIX support for shared libraries in configure 910 +- Use $cc instead of gcc to build shared library 911 +- Make prefix directory if needed when installing 912 +- Correct Macintosh avoidance of typedef Byte in zconf.h 913 +- Correct Turbo C memory allocation when under Linux 914 +- Use libz.a instead of -lz in Makefile (assure use of compiled library) 915 +- Update configure to check for snprintf or vsnprintf functions and their 916 + return value, warn during make if using an insecure function 917 +- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that 918 + is lost when library is used--resolution is to build new zconf.h 919 +- Documentation improvements (in zlib.h): 920 + - Document raw deflate and inflate 921 + - Update RFCs URL 922 + - Point out that zlib and gzip formats are different 923 + - Note that Z_BUF_ERROR is not fatal 924 + - Document string limit for gzprintf() and possible buffer overflow 925 + - Note requirement on avail_out when flushing 926 + - Note permitted values of flush parameter of inflate() 927 +- Add some FAQs (and even answers) to the FAQ 928 +- Add contrib/inflate86/ for x86 faster inflate 929 +- Add contrib/blast/ for PKWare Data Compression Library decompression 930 +- Add contrib/puff/ simple inflate for deflate format description 931 + 932 +Changes in 1.1.4 (11 March 2002) 933 +- ZFREE was repeated on same allocation on some error conditions. 934 + This creates a security problem described in 935 + http://www.zlib.org/advisory-2002-03-11.txt 936 +- Returned incorrect error (Z_MEM_ERROR) on some invalid data 937 +- Avoid accesses before window for invalid distances with inflate window 938 + less than 32K. 939 +- force windowBits > 8 to avoid a bug in the encoder for a window size 940 + of 256 bytes. (A complete fix will be available in 1.1.5). 941 + 942 +Changes in 1.1.3 (9 July 1998) 943 +- fix "an inflate input buffer bug that shows up on rare but persistent 944 + occasions" (Mark) 945 +- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) 946 +- fix gzseek(..., SEEK_SET) in write mode 947 +- fix crc check after a gzeek (Frank Faubert) 948 +- fix miniunzip when the last entry in a zip file is itself a zip file 949 + (J Lillge) 950 +- add contrib/asm586 and contrib/asm686 (Brian Raiter) 951 + See http://www.muppetlabs.com/~breadbox/software/assembly.html 952 +- add support for Delphi 3 in contrib/delphi (Bob Dellaca) 953 +- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) 954 +- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) 955 +- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) 956 +- added a FAQ file 957 + 958 +- Support gzdopen on Mac with Metrowerks (Jason Linhart) 959 +- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) 960 +- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) 961 +- avoid some warnings with Borland C (Tom Tanner) 962 +- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) 963 +- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) 964 +- allow several arguments to configure (Tim Mooney, Frodo Looijaard) 965 +- use libdir and includedir in Makefile.in (Tim Mooney) 966 +- support shared libraries on OSF1 V4 (Tim Mooney) 967 +- remove so_locations in "make clean" (Tim Mooney) 968 +- fix maketree.c compilation error (Glenn, Mark) 969 +- Python interface to zlib now in Python 1.5 (Jeremy Hylton) 970 +- new Makefile.riscos (Rich Walker) 971 +- initialize static descriptors in trees.c for embedded targets (Nick Smith) 972 +- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) 973 +- add the OS/2 files in Makefile.in too (Andrew Zabolotny) 974 +- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) 975 +- fix maketree.c to allow clean compilation of inffixed.h (Mark) 976 +- fix parameter check in deflateCopy (Gunther Nikl) 977 +- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) 978 +- Many portability patches by Christian Spieler: 979 + . zutil.c, zutil.h: added "const" for zmem* 980 + . Make_vms.com: fixed some typos 981 + . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists 982 + . msdos/Makefile.msc: remove "default rtl link library" info from obj files 983 + . msdos/Makefile.*: use model-dependent name for the built zlib library 984 + . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: 985 + new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) 986 +- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) 987 +- replace __far with _far for better portability (Christian Spieler, Tom Lane) 988 +- fix test for errno.h in configure (Tim Newsham) 989 + 990 +Changes in 1.1.2 (19 March 98) 991 +- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) 992 + See http://www.winimage.com/zLibDll/unzip.html 993 +- preinitialize the inflate tables for fixed codes, to make the code 994 + completely thread safe (Mark) 995 +- some simplifications and slight speed-up to the inflate code (Mark) 996 +- fix gzeof on non-compressed files (Allan Schrum) 997 +- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) 998 +- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) 999 +- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) 1000 +- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) 1001 +- do not wrap extern "C" around system includes (Tom Lane) 1002 +- mention zlib binding for TCL in README (Andreas Kupries) 1003 +- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) 1004 +- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) 1005 +- allow "configure --prefix $HOME" (Tim Mooney) 1006 +- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) 1007 +- move Makefile.sas to amiga/Makefile.sas 1008 + 1009 +Changes in 1.1.1 (27 Feb 98) 1010 +- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) 1011 +- remove block truncation heuristic which had very marginal effect for zlib 1012 + (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the 1013 + compression ratio on some files. This also allows inlining _tr_tally for 1014 + matches in deflate_slow. 1015 +- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) 1016 + 1017 +Changes in 1.1.0 (24 Feb 98) 1018 +- do not return STREAM_END prematurely in inflate (John Bowler) 1019 +- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) 1020 +- compile with -DFASTEST to get compression code optimized for speed only 1021 +- in minigzip, try mmap'ing the input file first (Miguel Albrecht) 1022 +- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain 1023 + on Sun but significant on HP) 1024 + 1025 +- add a pointer to experimental unzip library in README (Gilles Vollant) 1026 +- initialize variable gcc in configure (Chris Herborth) 1027 + 1028 +Changes in 1.0.9 (17 Feb 1998) 1029 +- added gzputs and gzgets functions 1030 +- do not clear eof flag in gzseek (Mark Diekhans) 1031 +- fix gzseek for files in transparent mode (Mark Diekhans) 1032 +- do not assume that vsprintf returns the number of bytes written (Jens Krinke) 1033 +- replace EXPORT with ZEXPORT to avoid conflict with other programs 1034 +- added compress2 in zconf.h, zlib.def, zlib.dnt 1035 +- new asm code from Gilles Vollant in contrib/asm386 1036 +- simplify the inflate code (Mark): 1037 + . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() 1038 + . ZALLOC the length list in inflate_trees_fixed() instead of using stack 1039 + . ZALLOC the value area for huft_build() instead of using stack 1040 + . Simplify Z_FINISH check in inflate() 1041 + 1042 +- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 1043 +- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) 1044 +- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with 1045 + the declaration of FAR (Gilles VOllant) 1046 +- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) 1047 +- read_buf buf parameter of type Bytef* instead of charf* 1048 +- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) 1049 +- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) 1050 +- fix check for presence of directories in "make install" (Ian Willis) 1051 + 1052 +Changes in 1.0.8 (27 Jan 1998) 1053 +- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) 1054 +- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) 1055 +- added compress2() to allow setting the compression level 1056 +- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) 1057 +- use constant arrays for the static trees in trees.c instead of computing 1058 + them at run time (thanks to Ken Raeburn for this suggestion). To create 1059 + trees.h, compile with GEN_TREES_H and run "make test". 1060 +- check return code of example in "make test" and display result 1061 +- pass minigzip command line options to file_compress 1062 +- simplifying code of inflateSync to avoid gcc 2.8 bug 1063 + 1064 +- support CC="gcc -Wall" in configure -s (QingLong) 1065 +- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) 1066 +- fix test for shared library support to avoid compiler warnings 1067 +- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) 1068 +- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) 1069 +- do not use fdopen for Metrowerks on Mac (Brad Pettit)) 1070 +- add checks for gzputc and gzputc in example.c 1071 +- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) 1072 +- use const for the CRC table (Ken Raeburn) 1073 +- fixed "make uninstall" for shared libraries 1074 +- use Tracev instead of Trace in infblock.c 1075 +- in example.c use correct compressed length for test_sync 1076 +- suppress +vnocompatwarnings in configure for HPUX (not always supported) 1077 + 1078 +Changes in 1.0.7 (20 Jan 1998) 1079 +- fix gzseek which was broken in write mode 1080 +- return error for gzseek to negative absolute position 1081 +- fix configure for Linux (Chun-Chung Chen) 1082 +- increase stack space for MSC (Tim Wegner) 1083 +- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) 1084 +- define EXPORTVA for gzprintf (Gilles Vollant) 1085 +- added man page zlib.3 (Rick Rodgers) 1086 +- for contrib/untgz, fix makedir() and improve Makefile 1087 + 1088 +- check gzseek in write mode in example.c 1089 +- allocate extra buffer for seeks only if gzseek is actually called 1090 +- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) 1091 +- add inflateSyncPoint in zconf.h 1092 +- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def 1093 + 1094 +Changes in 1.0.6 (19 Jan 1998) 1095 +- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and 1096 + gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) 1097 +- Fix a deflate bug occurring only with compression level 0 (thanks to 1098 + Andy Buckler for finding this one). 1099 +- In minigzip, pass transparently also the first byte for .Z files. 1100 +- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() 1101 +- check Z_FINISH in inflate (thanks to Marc Schluper) 1102 +- Implement deflateCopy (thanks to Adam Costello) 1103 +- make static libraries by default in configure, add --shared option. 1104 +- move MSDOS or Windows specific files to directory msdos 1105 +- suppress the notion of partial flush to simplify the interface 1106 + (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) 1107 +- suppress history buffer provided by application to simplify the interface 1108 + (this feature was not implemented anyway in 1.0.4) 1109 +- next_in and avail_in must be initialized before calling inflateInit or 1110 + inflateInit2 1111 +- add EXPORT in all exported functions (for Windows DLL) 1112 +- added Makefile.nt (thanks to Stephen Williams) 1113 +- added the unsupported "contrib" directory: 1114 + contrib/asm386/ by Gilles Vollant <info@winimage.com> 1115 + 386 asm code replacing longest_match(). 1116 + contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> 1117 + A C++ I/O streams interface to the zlib gz* functions 1118 + contrib/iostream2/ by Tyge L�vset <Tyge.Lovset@cmr.no> 1119 + Another C++ I/O streams interface 1120 + contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> 1121 + A very simple tar.gz file extractor using zlib 1122 + contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl> 1123 + How to use compress(), uncompress() and the gz* functions from VB. 1124 +- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression 1125 + level) in minigzip (thanks to Tom Lane) 1126 + 1127 +- use const for rommable constants in deflate 1128 +- added test for gzseek and gztell in example.c 1129 +- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) 1130 +- add undocumented function zError to convert error code to string 1131 + (for Tim Smithers) 1132 +- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. 1133 +- Use default memcpy for Symantec MSDOS compiler. 1134 +- Add EXPORT keyword for check_func (needed for Windows DLL) 1135 +- add current directory to LD_LIBRARY_PATH for "make test" 1136 +- create also a link for libz.so.1 1137 +- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) 1138 +- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) 1139 +- added -soname for Linux in configure (Chun-Chung Chen, 1140 +- assign numbers to the exported functions in zlib.def (for Windows DLL) 1141 +- add advice in zlib.h for best usage of deflateSetDictionary 1142 +- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) 1143 +- allow compilation with ANSI keywords only enabled for TurboC in large model 1144 +- avoid "versionString"[0] (Borland bug) 1145 +- add NEED_DUMMY_RETURN for Borland 1146 +- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). 1147 +- allow compilation with CC 1148 +- defined STDC for OS/2 (David Charlap) 1149 +- limit external names to 8 chars for MVS (Thomas Lund) 1150 +- in minigzip.c, use static buffers only for 16-bit systems 1151 +- fix suffix check for "minigzip -d foo.gz" 1152 +- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) 1153 +- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) 1154 +- added makelcc.bat for lcc-win32 (Tom St Denis) 1155 +- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) 1156 +- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. 1157 +- check for unistd.h in configure (for off_t) 1158 +- remove useless check parameter in inflate_blocks_free 1159 +- avoid useless assignment of s->check to itself in inflate_blocks_new 1160 +- do not flush twice in gzclose (thanks to Ken Raeburn) 1161 +- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h 1162 +- use NO_ERRNO_H instead of enumeration of operating systems with errno.h 1163 +- work around buggy fclose on pipes for HP/UX 1164 +- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) 1165 +- fix configure if CC is already equal to gcc 1166 + 1167 +Changes in 1.0.5 (3 Jan 98) 1168 +- Fix inflate to terminate gracefully when fed corrupted or invalid data 1169 +- Use const for rommable constants in inflate 1170 +- Eliminate memory leaks on error conditions in inflate 1171 +- Removed some vestigial code in inflate 1172 +- Update web address in README 1173 + 1174 +Changes in 1.0.4 (24 Jul 96) 1175 +- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF 1176 + bit, so the decompressor could decompress all the correct data but went 1177 + on to attempt decompressing extra garbage data. This affected minigzip too. 1178 +- zlibVersion and gzerror return const char* (needed for DLL) 1179 +- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) 1180 +- use z_error only for DEBUG (avoid problem with DLLs) 1181 + 1182 +Changes in 1.0.3 (2 Jul 96) 1183 +- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS 1184 + small and medium models; this makes the library incompatible with previous 1185 + versions for these models. (No effect in large model or on other systems.) 1186 +- return OK instead of BUF_ERROR if previous deflate call returned with 1187 + avail_out as zero but there is nothing to do 1188 +- added memcmp for non STDC compilers 1189 +- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) 1190 +- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) 1191 +- better check for 16-bit mode MSC (avoids problem with Symantec) 1192 + 1193 +Changes in 1.0.2 (23 May 96) 1194 +- added Windows DLL support 1195 +- added a function zlibVersion (for the DLL support) 1196 +- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) 1197 +- Bytef is define's instead of typedef'd only for Borland C 1198 +- avoid reading uninitialized memory in example.c 1199 +- mention in README that the zlib format is now RFC1950 1200 +- updated Makefile.dj2 1201 +- added algorithm.doc 1202 + 1203 +Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] 1204 +- fix array overlay in deflate.c which sometimes caused bad compressed data 1205 +- fix inflate bug with empty stored block 1206 +- fix MSDOS medium model which was broken in 0.99 1207 +- fix deflateParams() which could generated bad compressed data. 1208 +- Bytef is define'd instead of typedef'ed (work around Borland bug) 1209 +- added an INDEX file 1210 +- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), 1211 + Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) 1212 +- speed up adler32 for modern machines without auto-increment 1213 +- added -ansi for IRIX in configure 1214 +- static_init_done in trees.c is an int 1215 +- define unlink as delete for VMS 1216 +- fix configure for QNX 1217 +- add configure branch for SCO and HPUX 1218 +- avoid many warnings (unused variables, dead assignments, etc...) 1219 +- no fdopen for BeOS 1220 +- fix the Watcom fix for 32 bit mode (define FAR as empty) 1221 +- removed redefinition of Byte for MKWERKS 1222 +- work around an MWKERKS bug (incorrect merge of all .h files) 1223 + 1224 +Changes in 0.99 (27 Jan 96) 1225 +- allow preset dictionary shared between compressor and decompressor 1226 +- allow compression level 0 (no compression) 1227 +- add deflateParams in zlib.h: allow dynamic change of compression level 1228 + and compression strategy. 1229 +- test large buffers and deflateParams in example.c 1230 +- add optional "configure" to build zlib as a shared library 1231 +- suppress Makefile.qnx, use configure instead 1232 +- fixed deflate for 64-bit systems (detected on Cray) 1233 +- fixed inflate_blocks for 64-bit systems (detected on Alpha) 1234 +- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) 1235 +- always return Z_BUF_ERROR when deflate() has nothing to do 1236 +- deflateInit and inflateInit are now macros to allow version checking 1237 +- prefix all global functions and types with z_ with -DZ_PREFIX 1238 +- make falloc completely reentrant (inftrees.c) 1239 +- fixed very unlikely race condition in ct_static_init 1240 +- free in reverse order of allocation to help memory manager 1241 +- use zlib-1.0/* instead of zlib/* inside the tar.gz 1242 +- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith 1243 + -Wconversion -Wstrict-prototypes -Wmissing-prototypes" 1244 +- allow gzread on concatenated .gz files 1245 +- deflateEnd now returns Z_DATA_ERROR if it was premature 1246 +- deflate is finally (?) fully deterministic (no matches beyond end of input) 1247 +- Document Z_SYNC_FLUSH 1248 +- add uninstall in Makefile 1249 +- Check for __cpluplus in zlib.h 1250 +- Better test in ct_align for partial flush 1251 +- avoid harmless warnings for Borland C++ 1252 +- initialize hash_head in deflate.c 1253 +- avoid warning on fdopen (gzio.c) for HP cc -Aa 1254 +- include stdlib.h for STDC compilers 1255 +- include errno.h for Cray 1256 +- ignore error if ranlib doesn't exist 1257 +- call ranlib twice for NeXTSTEP 1258 +- use exec_prefix instead of prefix for libz.a 1259 +- renamed ct_* as _tr_* to avoid conflict with applications 1260 +- clear z->msg in inflateInit2 before any error return 1261 +- initialize opaque in example.c, gzio.c, deflate.c and inflate.c 1262 +- fixed typo in zconf.h (_GNUC__ => __GNUC__) 1263 +- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) 1264 +- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) 1265 +- in fcalloc, normalize pointer if size > 65520 bytes 1266 +- don't use special fcalloc for 32 bit Borland C++ 1267 +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... 1268 +- use Z_BINARY instead of BINARY 1269 +- document that gzclose after gzdopen will close the file 1270 +- allow "a" as mode in gzopen. 1271 +- fix error checking in gzread 1272 +- allow skipping .gz extra-field on pipes 1273 +- added reference to Perl interface in README 1274 +- put the crc table in FAR data (I dislike more and more the medium model :) 1275 +- added get_crc_table 1276 +- added a dimension to all arrays (Borland C can't count). 1277 +- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast 1278 +- guard against multiple inclusion of *.h (for precompiled header on Mac) 1279 +- Watcom C pretends to be Microsoft C small model even in 32 bit mode. 1280 +- don't use unsized arrays to avoid silly warnings by Visual C++: 1281 + warning C4746: 'inflate_mask' : unsized array treated as '__far' 1282 + (what's wrong with far data in far model?). 1283 +- define enum out of inflate_blocks_state to allow compilation with C++ 1284 + 1285 +Changes in 0.95 (16 Aug 95) 1286 +- fix MSDOS small and medium model (now easier to adapt to any compiler) 1287 +- inlined send_bits 1288 +- fix the final (:-) bug for deflate with flush (output was correct but 1289 + not completely flushed in rare occasions). 1290 +- default window size is same for compression and decompression 1291 + (it's now sufficient to set MAX_WBITS in zconf.h). 1292 +- voidp -> voidpf and voidnp -> voidp (for consistency with other 1293 + typedefs and because voidnp was not near in large model). 1294 + 1295 +Changes in 0.94 (13 Aug 95) 1296 +- support MSDOS medium model 1297 +- fix deflate with flush (could sometimes generate bad output) 1298 +- fix deflateReset (zlib header was incorrectly suppressed) 1299 +- added support for VMS 1300 +- allow a compression level in gzopen() 1301 +- gzflush now calls fflush 1302 +- For deflate with flush, flush even if no more input is provided. 1303 +- rename libgz.a as libz.a 1304 +- avoid complex expression in infcodes.c triggering Turbo C bug 1305 +- work around a problem with gcc on Alpha (in INSERT_STRING) 1306 +- don't use inline functions (problem with some gcc versions) 1307 +- allow renaming of Byte, uInt, etc... with #define. 1308 +- avoid warning about (unused) pointer before start of array in deflate.c 1309 +- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c 1310 +- avoid reserved word 'new' in trees.c 1311 + 1312 +Changes in 0.93 (25 June 95) 1313 +- temporarily disable inline functions 1314 +- make deflate deterministic 1315 +- give enough lookahead for PARTIAL_FLUSH 1316 +- Set binary mode for stdin/stdout in minigzip.c for OS/2 1317 +- don't even use signed char in inflate (not portable enough) 1318 +- fix inflate memory leak for segmented architectures 1319 + 1320 +Changes in 0.92 (3 May 95) 1321 +- don't assume that char is signed (problem on SGI) 1322 +- Clear bit buffer when starting a stored block 1323 +- no memcpy on Pyramid 1324 +- suppressed inftest.c 1325 +- optimized fill_window, put longest_match inline for gcc 1326 +- optimized inflate on stored blocks. 1327 +- untabify all sources to simplify patches 1328 + 1329 +Changes in 0.91 (2 May 95) 1330 +- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h 1331 +- Document the memory requirements in zconf.h 1332 +- added "make install" 1333 +- fix sync search logic in inflateSync 1334 +- deflate(Z_FULL_FLUSH) now works even if output buffer too short 1335 +- after inflateSync, don't scare people with just "lo world" 1336 +- added support for DJGPP 1337 + 1338 +Changes in 0.9 (1 May 95) 1339 +- don't assume that zalloc clears the allocated memory (the TurboC bug 1340 + was Mark's bug after all :) 1341 +- let again gzread copy uncompressed data unchanged (was working in 0.71) 1342 +- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented 1343 +- added a test of inflateSync in example.c 1344 +- moved MAX_WBITS to zconf.h because users might want to change that. 1345 +- document explicitly that zalloc(64K) on MSDOS must return a normalized 1346 + pointer (zero offset) 1347 +- added Makefiles for Microsoft C, Turbo C, Borland C++ 1348 +- faster crc32() 1349 + 1350 +Changes in 0.8 (29 April 95) 1351 +- added fast inflate (inffast.c) 1352 +- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this 1353 + is incompatible with previous versions of zlib which returned Z_OK. 1354 +- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) 1355 + (actually that was not a compiler bug, see 0.81 above) 1356 +- gzread no longer reads one extra byte in certain cases 1357 +- In gzio destroy(), don't reference a freed structure 1358 +- avoid many warnings for MSDOS 1359 +- avoid the ERROR symbol which is used by MS Windows 1360 + 1361 +Changes in 0.71 (14 April 95) 1362 +- Fixed more MSDOS compilation problems :( There is still a bug with 1363 + TurboC large model. 1364 + 1365 +Changes in 0.7 (14 April 95) 1366 +- Added full inflate support. 1367 +- Simplified the crc32() interface. The pre- and post-conditioning 1368 + (one's complement) is now done inside crc32(). WARNING: this is 1369 + incompatible with previous versions; see zlib.h for the new usage. 1370 + 1371 +Changes in 0.61 (12 April 95) 1372 +- workaround for a bug in TurboC. example and minigzip now work on MSDOS. 1373 + 1374 +Changes in 0.6 (11 April 95) 1375 +- added minigzip.c 1376 +- added gzdopen to reopen a file descriptor as gzFile 1377 +- added transparent reading of non-gziped files in gzread. 1378 +- fixed bug in gzread (don't read crc as data) 1379 +- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). 1380 +- don't allocate big arrays in the stack (for MSDOS) 1381 +- fix some MSDOS compilation problems 1382 + 1383 +Changes in 0.5: 1384 +- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but 1385 + not yet Z_FULL_FLUSH. 1386 +- support decompression but only in a single step (forced Z_FINISH) 1387 +- added opaque object for zalloc and zfree. 1388 +- added deflateReset and inflateReset 1389 +- added a variable zlib_version for consistency checking. 1390 +- renamed the 'filter' parameter of deflateInit2 as 'strategy'. 1391 + Added Z_FILTERED and Z_HUFFMAN_ONLY constants. 1392 + 1393 +Changes in 0.4: 1394 +- avoid "zip" everywhere, use zlib instead of ziplib. 1395 +- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush 1396 + if compression method == 8. 1397 +- added adler32 and crc32 1398 +- renamed deflateOptions as deflateInit2, call one or the other but not both 1399 +- added the method parameter for deflateInit2. 1400 +- added inflateInit2 1401 +- simplied considerably deflateInit and inflateInit by not supporting 1402 + user-provided history buffer. This is supported only in deflateInit2 1403 + and inflateInit2. 1404 + 1405 +Changes in 0.3: 1406 +- prefix all macro names with Z_ 1407 +- use Z_FINISH instead of deflateEnd to finish compression. 1408 +- added Z_HUFFMAN_ONLY 1409 +- added gzerror()
Added compat/zlib/FAQ.
1 + 2 + Frequently Asked Questions about zlib 3 + 4 + 5 +If your question is not there, please check the zlib home page 6 +http://zlib.net/ which may have more recent information. 7 +The lastest zlib FAQ is at http://zlib.net/zlib_faq.html 8 + 9 + 10 + 1. Is zlib Y2K-compliant? 11 + 12 + Yes. zlib doesn't handle dates. 13 + 14 + 2. Where can I get a Windows DLL version? 15 + 16 + The zlib sources can be compiled without change to produce a DLL. See the 17 + file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the 18 + precompiled DLL are found in the zlib web site at http://zlib.net/ . 19 + 20 + 3. Where can I get a Visual Basic interface to zlib? 21 + 22 + See 23 + * http://marknelson.us/1997/01/01/zlib-engine/ 24 + * win32/DLL_FAQ.txt in the zlib distribution 25 + 26 + 4. compress() returns Z_BUF_ERROR. 27 + 28 + Make sure that before the call of compress(), the length of the compressed 29 + buffer is equal to the available size of the compressed buffer and not 30 + zero. For Visual Basic, check that this parameter is passed by reference 31 + ("as any"), not by value ("as long"). 32 + 33 + 5. deflate() or inflate() returns Z_BUF_ERROR. 34 + 35 + Before making the call, make sure that avail_in and avail_out are not zero. 36 + When setting the parameter flush equal to Z_FINISH, also make sure that 37 + avail_out is big enough to allow processing all pending input. Note that a 38 + Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be 39 + made with more input or output space. A Z_BUF_ERROR may in fact be 40 + unavoidable depending on how the functions are used, since it is not 41 + possible to tell whether or not there is more output pending when 42 + strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a 43 + heavily annotated example. 44 + 45 + 6. Where's the zlib documentation (man pages, etc.)? 46 + 47 + It's in zlib.h . Examples of zlib usage are in the files test/example.c 48 + and test/minigzip.c, with more in examples/ . 49 + 50 + 7. Why don't you use GNU autoconf or libtool or ...? 51 + 52 + Because we would like to keep zlib as a very small and simple package. 53 + zlib is rather portable and doesn't need much configuration. 54 + 55 + 8. I found a bug in zlib. 56 + 57 + Most of the time, such problems are due to an incorrect usage of zlib. 58 + Please try to reproduce the problem with a small program and send the 59 + corresponding source to us at zlib@gzip.org . Do not send multi-megabyte 60 + data files without prior agreement. 61 + 62 + 9. Why do I get "undefined reference to gzputc"? 63 + 64 + If "make test" produces something like 65 + 66 + example.o(.text+0x154): undefined reference to `gzputc' 67 + 68 + check that you don't have old files libz.* in /usr/lib, /usr/local/lib or 69 + /usr/X11R6/lib. Remove any old versions, then do "make install". 70 + 71 +10. I need a Delphi interface to zlib. 72 + 73 + See the contrib/delphi directory in the zlib distribution. 74 + 75 +11. Can zlib handle .zip archives? 76 + 77 + Not by itself, no. See the directory contrib/minizip in the zlib 78 + distribution. 79 + 80 +12. Can zlib handle .Z files? 81 + 82 + No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt 83 + the code of uncompress on your own. 84 + 85 +13. How can I make a Unix shared library? 86 + 87 + By default a shared (and a static) library is built for Unix. So: 88 + 89 + make distclean 90 + ./configure 91 + make 92 + 93 +14. How do I install a shared zlib library on Unix? 94 + 95 + After the above, then: 96 + 97 + make install 98 + 99 + However, many flavors of Unix come with a shared zlib already installed. 100 + Before going to the trouble of compiling a shared version of zlib and 101 + trying to install it, you may want to check if it's already there! If you 102 + can #include <zlib.h>, it's there. The -lz option will probably link to 103 + it. You can check the version at the top of zlib.h or with the 104 + ZLIB_VERSION symbol defined in zlib.h . 105 + 106 +15. I have a question about OttoPDF. 107 + 108 + We are not the authors of OttoPDF. The real author is on the OttoPDF web 109 + site: Joel Hainley, jhainley@myndkryme.com. 110 + 111 +16. Can zlib decode Flate data in an Adobe PDF file? 112 + 113 + Yes. See http://www.pdflib.com/ . To modify PDF forms, see 114 + http://sourceforge.net/projects/acroformtool/ . 115 + 116 +17. Why am I getting this "register_frame_info not found" error on Solaris? 117 + 118 + After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib 119 + generates an error such as: 120 + 121 + ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so: 122 + symbol __register_frame_info: referenced symbol not found 123 + 124 + The symbol __register_frame_info is not part of zlib, it is generated by 125 + the C compiler (cc or gcc). You must recompile applications using zlib 126 + which have this problem. This problem is specific to Solaris. See 127 + http://www.sunfreeware.com for Solaris versions of zlib and applications 128 + using zlib. 129 + 130 +18. Why does gzip give an error on a file I make with compress/deflate? 131 + 132 + The compress and deflate functions produce data in the zlib format, which 133 + is different and incompatible with the gzip format. The gz* functions in 134 + zlib on the other hand use the gzip format. Both the zlib and gzip formats 135 + use the same compressed data format internally, but have different headers 136 + and trailers around the compressed data. 137 + 138 +19. Ok, so why are there two different formats? 139 + 140 + The gzip format was designed to retain the directory information about a 141 + single file, such as the name and last modification date. The zlib format 142 + on the other hand was designed for in-memory and communication channel 143 + applications, and has a much more compact header and trailer and uses a 144 + faster integrity check than gzip. 145 + 146 +20. Well that's nice, but how do I make a gzip file in memory? 147 + 148 + You can request that deflate write the gzip format instead of the zlib 149 + format using deflateInit2(). You can also request that inflate decode the 150 + gzip format using inflateInit2(). Read zlib.h for more details. 151 + 152 +21. Is zlib thread-safe? 153 + 154 + Yes. However any library routines that zlib uses and any application- 155 + provided memory allocation routines must also be thread-safe. zlib's gz* 156 + functions use stdio library routines, and most of zlib's functions use the 157 + library memory allocation routines by default. zlib's *Init* functions 158 + allow for the application to provide custom memory allocation routines. 159 + 160 + Of course, you should only operate on any given zlib or gzip stream from a 161 + single thread at a time. 162 + 163 +22. Can I use zlib in my commercial application? 164 + 165 + Yes. Please read the license in zlib.h. 166 + 167 +23. Is zlib under the GNU license? 168 + 169 + No. Please read the license in zlib.h. 170 + 171 +24. The license says that altered source versions must be "plainly marked". So 172 + what exactly do I need to do to meet that requirement? 173 + 174 + You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In 175 + particular, the final version number needs to be changed to "f", and an 176 + identification string should be appended to ZLIB_VERSION. Version numbers 177 + x.x.x.f are reserved for modifications to zlib by others than the zlib 178 + maintainers. For example, if the version of the base zlib you are altering 179 + is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and 180 + ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also 181 + update the version strings in deflate.c and inftrees.c. 182 + 183 + For altered source distributions, you should also note the origin and 184 + nature of the changes in zlib.h, as well as in ChangeLog and README, along 185 + with the dates of the alterations. The origin should include at least your 186 + name (or your company's name), and an email address to contact for help or 187 + issues with the library. 188 + 189 + Note that distributing a compiled zlib library along with zlib.h and 190 + zconf.h is also a source distribution, and so you should change 191 + ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes 192 + in zlib.h as you would for a full source distribution. 193 + 194 +25. Will zlib work on a big-endian or little-endian architecture, and can I 195 + exchange compressed data between them? 196 + 197 + Yes and yes. 198 + 199 +26. Will zlib work on a 64-bit machine? 200 + 201 + Yes. It has been tested on 64-bit machines, and has no dependence on any 202 + data types being limited to 32-bits in length. If you have any 203 + difficulties, please provide a complete problem report to zlib@gzip.org 204 + 205 +27. Will zlib decompress data from the PKWare Data Compression Library? 206 + 207 + No. The PKWare DCL uses a completely different compressed data format than 208 + does PKZIP and zlib. However, you can look in zlib's contrib/blast 209 + directory for a possible solution to your problem. 210 + 211 +28. Can I access data randomly in a compressed stream? 212 + 213 + No, not without some preparation. If when compressing you periodically use 214 + Z_FULL_FLUSH, carefully write all the pending data at those points, and 215 + keep an index of those locations, then you can start decompression at those 216 + points. You have to be careful to not use Z_FULL_FLUSH too often, since it 217 + can significantly degrade compression. Alternatively, you can scan a 218 + deflate stream once to generate an index, and then use that index for 219 + random access. See examples/zran.c . 220 + 221 +29. Does zlib work on MVS, OS/390, CICS, etc.? 222 + 223 + It has in the past, but we have not heard of any recent evidence. There 224 + were working ports of zlib 1.1.4 to MVS, but those links no longer work. 225 + If you know of recent, successful applications of zlib on these operating 226 + systems, please let us know. Thanks. 227 + 228 +30. Is there some simpler, easier to read version of inflate I can look at to 229 + understand the deflate format? 230 + 231 + First off, you should read RFC 1951. Second, yes. Look in zlib's 232 + contrib/puff directory. 233 + 234 +31. Does zlib infringe on any patents? 235 + 236 + As far as we know, no. In fact, that was originally the whole point behind 237 + zlib. Look here for some more information: 238 + 239 + http://www.gzip.org/#faq11 240 + 241 +32. Can zlib work with greater than 4 GB of data? 242 + 243 + Yes. inflate() and deflate() will process any amount of data correctly. 244 + Each call of inflate() or deflate() is limited to input and output chunks 245 + of the maximum value that can be stored in the compiler's "unsigned int" 246 + type, but there is no limit to the number of chunks. Note however that the 247 + strm.total_in and strm_total_out counters may be limited to 4 GB. These 248 + counters are provided as a convenience and are not used internally by 249 + inflate() or deflate(). The application can easily set up its own counters 250 + updated after each call of inflate() or deflate() to count beyond 4 GB. 251 + compress() and uncompress() may be limited to 4 GB, since they operate in a 252 + single call. gzseek() and gztell() may be limited to 4 GB depending on how 253 + zlib is compiled. See the zlibCompileFlags() function in zlib.h. 254 + 255 + The word "may" appears several times above since there is a 4 GB limit only 256 + if the compiler's "long" type is 32 bits. If the compiler's "long" type is 257 + 64 bits, then the limit is 16 exabytes. 258 + 259 +33. Does zlib have any security vulnerabilities? 260 + 261 + The only one that we are aware of is potentially in gzprintf(). If zlib is 262 + compiled to use sprintf() or vsprintf(), then there is no protection 263 + against a buffer overflow of an 8K string space (or other value as set by 264 + gzbuffer()), other than the caller of gzprintf() assuring that the output 265 + will not exceed 8K. On the other hand, if zlib is compiled to use 266 + snprintf() or vsnprintf(), which should normally be the case, then there is 267 + no vulnerability. The ./configure script will display warnings if an 268 + insecure variation of sprintf() will be used by gzprintf(). Also the 269 + zlibCompileFlags() function will return information on what variant of 270 + sprintf() is used by gzprintf(). 271 + 272 + If you don't have snprintf() or vsnprintf() and would like one, you can 273 + find a portable implementation here: 274 + 275 + http://www.ijs.si/software/snprintf/ 276 + 277 + Note that you should be using the most recent version of zlib. Versions 278 + 1.1.3 and before were subject to a double-free vulnerability, and versions 279 + 1.2.1 and 1.2.2 were subject to an access exception when decompressing 280 + invalid compressed data. 281 + 282 +34. Is there a Java version of zlib? 283 + 284 + Probably what you want is to use zlib in Java. zlib is already included 285 + as part of the Java SDK in the java.util.zip package. If you really want 286 + a version of zlib written in the Java language, look on the zlib home 287 + page for links: http://zlib.net/ . 288 + 289 +35. I get this or that compiler or source-code scanner warning when I crank it 290 + up to maximally-pedantic. Can't you guys write proper code? 291 + 292 + Many years ago, we gave up attempting to avoid warnings on every compiler 293 + in the universe. It just got to be a waste of time, and some compilers 294 + were downright silly as well as contradicted each other. So now, we simply 295 + make sure that the code always works. 296 + 297 +36. Valgrind (or some similar memory access checker) says that deflate is 298 + performing a conditional jump that depends on an uninitialized value. 299 + Isn't that a bug? 300 + 301 + No. That is intentional for performance reasons, and the output of deflate 302 + is not affected. This only started showing up recently since zlib 1.2.x 303 + uses malloc() by default for allocations, whereas earlier versions used 304 + calloc(), which zeros out the allocated memory. Even though the code was 305 + correct, versions 1.2.4 and later was changed to not stimulate these 306 + checkers. 307 + 308 +37. Will zlib read the (insert any ancient or arcane format here) compressed 309 + data format? 310 + 311 + Probably not. Look in the comp.compression FAQ for pointers to various 312 + formats and associated software. 313 + 314 +38. How can I encrypt/decrypt zip files with zlib? 315 + 316 + zlib doesn't support encryption. The original PKZIP encryption is very 317 + weak and can be broken with freely available programs. To get strong 318 + encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib 319 + compression. For PKZIP compatible "encryption", look at 320 + http://www.info-zip.org/ 321 + 322 +39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? 323 + 324 + "gzip" is the gzip format, and "deflate" is the zlib format. They should 325 + probably have called the second one "zlib" instead to avoid confusion with 326 + the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 327 + correctly points to the zlib specification in RFC 1950 for the "deflate" 328 + transfer encoding, there have been reports of servers and browsers that 329 + incorrectly produce or expect raw deflate data per the deflate 330 + specification in RFC 1951, most notably Microsoft. So even though the 331 + "deflate" transfer encoding using the zlib format would be the more 332 + efficient approach (and in fact exactly what the zlib format was designed 333 + for), using the "gzip" transfer encoding is probably more reliable due to 334 + an unfortunate choice of name on the part of the HTTP 1.1 authors. 335 + 336 + Bottom line: use the gzip format for HTTP 1.1 encoding. 337 + 338 +40. Does zlib support the new "Deflate64" format introduced by PKWare? 339 + 340 + No. PKWare has apparently decided to keep that format proprietary, since 341 + they have not documented it as they have previous compression formats. In 342 + any case, the compression improvements are so modest compared to other more 343 + modern approaches, that it's not worth the effort to implement. 344 + 345 +41. I'm having a problem with the zip functions in zlib, can you help? 346 + 347 + There are no zip functions in zlib. You are probably using minizip by 348 + Giles Vollant, which is found in the contrib directory of zlib. It is not 349 + part of zlib. In fact none of the stuff in contrib is part of zlib. The 350 + files in there are not supported by the zlib authors. You need to contact 351 + the authors of the respective contribution for help. 352 + 353 +42. The match.asm code in contrib is under the GNU General Public License. 354 + Since it's part of zlib, doesn't that mean that all of zlib falls under the 355 + GNU GPL? 356 + 357 + No. The files in contrib are not part of zlib. They were contributed by 358 + other authors and are provided as a convenience to the user within the zlib 359 + distribution. Each item in contrib has its own license. 360 + 361 +43. Is zlib subject to export controls? What is its ECCN? 362 + 363 + zlib is not subject to export controls, and so is classified as EAR99. 364 + 365 +44. Can you please sign these lengthy legal documents and fax them back to us 366 + so that we can use your software in our product? 367 + 368 + No. Go away. Shoo.
Added compat/zlib/INDEX.
1 +CMakeLists.txt cmake build file 2 +ChangeLog history of changes 3 +FAQ Frequently Asked Questions about zlib 4 +INDEX this file 5 +Makefile dummy Makefile that tells you to ./configure 6 +Makefile.in template for Unix Makefile 7 +README guess what 8 +configure configure script for Unix 9 +make_vms.com makefile for VMS 10 +test/example.c zlib usages examples for build testing 11 +test/minigzip.c minimal gzip-like functionality for build testing 12 +test/infcover.c inf*.c code coverage for build coverage testing 13 +treebuild.xml XML description of source file dependencies 14 +zconf.h.cmakein zconf.h template for cmake 15 +zconf.h.in zconf.h template for configure 16 +zlib.3 Man page for zlib 17 +zlib.3.pdf Man page in PDF format 18 +zlib.map Linux symbol information 19 +zlib.pc.in Template for pkg-config descriptor 20 +zlib.pc.cmakein zlib.pc template for cmake 21 +zlib2ansi perl script to convert source files for C++ compilation 22 + 23 +amiga/ makefiles for Amiga SAS C 24 +as400/ makefiles for AS/400 25 +doc/ documentation for formats and algorithms 26 +msdos/ makefiles for MSDOS 27 +nintendods/ makefile for Nintendo DS 28 +old/ makefiles for various architectures and zlib documentation 29 + files that have not yet been updated for zlib 1.2.x 30 +qnx/ makefiles for QNX 31 +watcom/ makefiles for OpenWatcom 32 +win32/ makefiles for Windows 33 + 34 + zlib public header files (required for library use): 35 +zconf.h 36 +zlib.h 37 + 38 + private source files used to build the zlib library: 39 +adler32.c 40 +compress.c 41 +crc32.c 42 +crc32.h 43 +deflate.c 44 +deflate.h 45 +gzclose.c 46 +gzguts.h 47 +gzlib.c 48 +gzread.c 49 +gzwrite.c 50 +infback.c 51 +inffast.c 52 +inffast.h 53 +inffixed.h 54 +inflate.c 55 +inflate.h 56 +inftrees.c 57 +inftrees.h 58 +trees.c 59 +trees.h 60 +uncompr.c 61 +zutil.c 62 +zutil.h 63 + 64 + source files for sample programs 65 +See examples/README.examples 66 + 67 + unsupported contributions by third parties 68 +See contrib/README.contrib
Added compat/zlib/Makefile.
1 +all: 2 + -@echo "Please use ./configure first. Thank you." 3 + 4 +distclean: 5 + make -f Makefile.in distclean
Added compat/zlib/Makefile.in.
1 +# Makefile for zlib 2 +# Copyright (C) 1995-2011 Jean-loup Gailly. 3 +# For conditions of distribution and use, see copyright notice in zlib.h 4 + 5 +# To compile and test, type: 6 +# ./configure; make test 7 +# Normally configure builds both a static and a shared library. 8 +# If you want to build just a static library, use: ./configure --static 9 + 10 +# To use the asm code, type: 11 +# cp contrib/asm?86/match.S ./match.S 12 +# make LOC=-DASMV OBJA=match.o 13 + 14 +# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: 15 +# make install 16 +# To install in $HOME instead of /usr/local, use: 17 +# make install prefix=$HOME 18 + 19 +CC=cc 20 + 21 +CFLAGS=-O 22 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 23 +#CFLAGS=-g -DDEBUG 24 +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 25 +# -Wstrict-prototypes -Wmissing-prototypes 26 + 27 +SFLAGS=-O 28 +LDFLAGS= 29 +TEST_LDFLAGS=-L. libz.a 30 +LDSHARED=$(CC) 31 +CPP=$(CC) -E 32 + 33 +STATICLIB=libz.a 34 +SHAREDLIB=libz.so 35 +SHAREDLIBV=libz.so.1.2.7 36 +SHAREDLIBM=libz.so.1 37 +LIBS=$(STATICLIB) $(SHAREDLIBV) 38 + 39 +AR=ar 40 +ARFLAGS=rc 41 +RANLIB=ranlib 42 +LDCONFIG=ldconfig 43 +LDSHAREDLIBC=-lc 44 +TAR=tar 45 +SHELL=/bin/sh 46 +EXE= 47 + 48 +prefix = /usr/local 49 +exec_prefix = ${prefix} 50 +libdir = ${exec_prefix}/lib 51 +sharedlibdir = ${libdir} 52 +includedir = ${prefix}/include 53 +mandir = ${prefix}/share/man 54 +man3dir = ${mandir}/man3 55 +pkgconfigdir = ${libdir}/pkgconfig 56 + 57 +OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o 58 +OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o 59 +OBJC = $(OBJZ) $(OBJG) 60 + 61 +PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo 62 +PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo 63 +PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG) 64 + 65 +# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo 66 +OBJA = 67 +PIC_OBJA = 68 + 69 +OBJS = $(OBJC) $(OBJA) 70 + 71 +PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) 72 + 73 +all: static shared 74 + 75 +static: example$(EXE) minigzip$(EXE) 76 + 77 +shared: examplesh$(EXE) minigzipsh$(EXE) 78 + 79 +all64: example64$(EXE) minigzip64$(EXE) 80 + 81 +check: test 82 + 83 +test: all teststatic testshared 84 + 85 +teststatic: static 86 + @TMPST=`mktemp fooXXXXXX`; \ 87 + if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \ 88 + echo ' *** zlib test OK ***'; \ 89 + else \ 90 + echo ' *** zlib test FAILED ***'; false; \ 91 + fi; \ 92 + rm -f $$TMPST 93 + 94 +testshared: shared 95 + @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ 96 + LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \ 97 + DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ 98 + SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ 99 + TMPSH=`mktemp fooXXXXXX`; \ 100 + if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \ 101 + echo ' *** zlib shared test OK ***'; \ 102 + else \ 103 + echo ' *** zlib shared test FAILED ***'; false; \ 104 + fi; \ 105 + rm -f $$TMPSH 106 + 107 +test64: all64 108 + @TMP64=`mktemp fooXXXXXX`; \ 109 + if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \ 110 + echo ' *** zlib 64-bit test OK ***'; \ 111 + else \ 112 + echo ' *** zlib 64-bit test FAILED ***'; false; \ 113 + fi; \ 114 + rm -f $$TMP64 115 + 116 +infcover.o: test/infcover.c zlib.h zconf.h 117 + $(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c 118 + 119 +infcover: infcover.o libz.a 120 + $(CC) $(CFLAGS) -o $@ infcover.o libz.a 121 + 122 +cover: infcover 123 + rm -f *.gcda 124 + ./infcover 125 + gcov inf*.c 126 + 127 +libz.a: $(OBJS) 128 + $(AR) $(ARFLAGS) $@ $(OBJS) 129 + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 130 + 131 +match.o: match.S 132 + $(CPP) match.S > _match.s 133 + $(CC) -c _match.s 134 + mv _match.o match.o 135 + rm -f _match.s 136 + 137 +match.lo: match.S 138 + $(CPP) match.S > _match.s 139 + $(CC) -c -fPIC _match.s 140 + mv _match.o match.lo 141 + rm -f _match.s 142 + 143 +example.o: test/example.c zlib.h zconf.h 144 + $(CC) $(CFLAGS) -I. -c -o $@ test/example.c 145 + 146 +minigzip.o: test/minigzip.c zlib.h zconf.h 147 + $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c 148 + 149 +example64.o: test/example.c zlib.h zconf.h 150 + $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c 151 + 152 +minigzip64.o: test/minigzip.c zlib.h zconf.h 153 + $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c 154 + 155 +.SUFFIXES: .lo 156 + 157 +.c.lo: 158 + -@mkdir objs 2>/dev/null || test -d objs 159 + $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $< 160 + -@mv objs/$*.o $@ 161 + 162 +placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a 163 + $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS) 164 + rm -f $(SHAREDLIB) $(SHAREDLIBM) 165 + ln -s $@ $(SHAREDLIB) 166 + ln -s $@ $(SHAREDLIBM) 167 + -@rmdir objs 168 + 169 +example$(EXE): example.o $(STATICLIB) 170 + $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) 171 + 172 +minigzip$(EXE): minigzip.o $(STATICLIB) 173 + $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) 174 + 175 +examplesh$(EXE): example.o $(SHAREDLIBV) 176 + $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV) 177 + 178 +minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) 179 + $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV) 180 + 181 +example64$(EXE): example64.o $(STATICLIB) 182 + $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) 183 + 184 +minigzip64$(EXE): minigzip64.o $(STATICLIB) 185 + $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) 186 + 187 +install-libs: $(LIBS) 188 + -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi 189 + -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi 190 + -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi 191 + -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi 192 + -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi 193 + cp $(STATICLIB) $(DESTDIR)$(libdir) 194 + chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB) 195 + -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1 196 + -@if test -n "$(SHAREDLIBV)"; then \ 197 + cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \ 198 + echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \ 199 + chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \ 200 + echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \ 201 + rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ 202 + ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \ 203 + ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ 204 + ($(LDCONFIG) || true) >/dev/null 2>&1; \ 205 + fi 206 + cp zlib.3 $(DESTDIR)$(man3dir) 207 + chmod 644 $(DESTDIR)$(man3dir)/zlib.3 208 + cp zlib.pc $(DESTDIR)$(pkgconfigdir) 209 + chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc 210 +# The ranlib in install is needed on NeXTSTEP which checks file times 211 +# ldconfig is for Linux 212 + 213 +install: install-libs 214 + -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi 215 + cp zlib.h zconf.h $(DESTDIR)$(includedir) 216 + chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h 217 + 218 +uninstall: 219 + cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h 220 + cd $(DESTDIR)$(libdir); rm -f libz.a; \ 221 + if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \ 222 + rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \ 223 + fi 224 + cd $(DESTDIR)$(man3dir); rm -f zlib.3 225 + cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc 226 + 227 +docs: zlib.3.pdf 228 + 229 +zlib.3.pdf: zlib.3 230 + groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf 231 + 232 +zconf.h.cmakein: zconf.h.in 233 + -@ TEMPFILE=`mktemp __XXXXXX`; \ 234 + echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\ 235 + sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\ 236 + touch -r zconf.h.in zconf.h.cmakein &&\ 237 + rm $$TEMPFILE 238 + 239 +zconf: zconf.h.in 240 + cp -p zconf.h.in zconf.h 241 + 242 +mostlyclean: clean 243 +clean: 244 + rm -f *.o *.lo *~ \ 245 + example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ 246 + example64$(EXE) minigzip64$(EXE) \ 247 + infcover \ 248 + libz.* foo.gz so_locations \ 249 + _match.s maketree contrib/infback9/*.o 250 + rm -rf objs 251 + rm -f *.gcda *.gcno *.gcov 252 + rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov 253 + 254 +maintainer-clean: distclean 255 +distclean: clean zconf zconf.h.cmakein docs 256 + rm -f Makefile zlib.pc configure.log 257 + -@rm -f .DS_Store 258 + -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile 259 + -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile 260 + -@touch -r Makefile.in Makefile 261 + 262 +tags: 263 + etags *.[ch] 264 + 265 +depend: 266 + makedepend -- $(CFLAGS) -- *.[ch] 267 + 268 +# DO NOT DELETE THIS LINE -- make depend depends on it. 269 + 270 +adler32.o zutil.o: zutil.h zlib.h zconf.h 271 +gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h 272 +compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h 273 +crc32.o: zutil.h zlib.h zconf.h crc32.h 274 +deflate.o: deflate.h zutil.h zlib.h zconf.h 275 +infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h 276 +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 277 +inftrees.o: zutil.h zlib.h zconf.h inftrees.h 278 +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h 279 + 280 +adler32.lo zutil.lo: zutil.h zlib.h zconf.h 281 +gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h 282 +compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h 283 +crc32.lo: zutil.h zlib.h zconf.h crc32.h 284 +deflate.lo: deflate.h zutil.h zlib.h zconf.h 285 +infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h 286 +inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 287 +inftrees.lo: zutil.h zlib.h zconf.h inftrees.h 288 +trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h
Added compat/zlib/README.
1 +ZLIB DATA COMPRESSION LIBRARY 2 + 3 +zlib 1.2.7 is a general purpose data compression library. All the code is 4 +thread safe. The data format used by the zlib library is described by RFCs 5 +(Request for Comments) 1950 to 1952 in the files 6 +http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and 7 +rfc1952 (gzip format). 8 + 9 +All functions of the compression library are documented in the file zlib.h 10 +(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example 11 +of the library is given in the file test/example.c which also tests that 12 +the library is working correctly. Another example is given in the file 13 +test/minigzip.c. The compression library itself is composed of all source 14 +files in the root directory. 15 + 16 +To compile all files and run the test program, follow the instructions given at 17 +the top of Makefile.in. In short "./configure; make test", and if that goes 18 +well, "make install" should work for most flavors of Unix. For Windows, use 19 +one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use 20 +make_vms.com. 21 + 22 +Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant 23 +<info@winimage.com> for the Windows DLL version. The zlib home page is 24 +http://zlib.net/ . Before reporting a problem, please check this site to 25 +verify that you have the latest version of zlib; otherwise get the latest 26 +version and check whether the problem still exists or not. 27 + 28 +PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. 29 + 30 +Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997 31 +issue of Dr. Dobb's Journal; a copy of the article is available at 32 +http://marknelson.us/1997/01/01/zlib-engine/ . 33 + 34 +The changes made in version 1.2.7 are documented in the file ChangeLog. 35 + 36 +Unsupported third party contributions are provided in directory contrib/ . 37 + 38 +zlib is available in Java using the java.util.zip package, documented at 39 +http://java.sun.com/developer/technicalArticles/Programming/compression/ . 40 + 41 +A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available 42 +at CPAN (Comprehensive Perl Archive Network) sites, including 43 +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . 44 + 45 +A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is 46 +available in Python 1.5 and later versions, see 47 +http://docs.python.org/library/zlib.html . 48 + 49 +zlib is built into tcl: http://wiki.tcl.tk/4610 . 50 + 51 +An experimental package to read and write files in .zip format, written on top 52 +of zlib by Gilles Vollant <info@winimage.com>, is available in the 53 +contrib/minizip directory of zlib. 54 + 55 + 56 +Notes for some targets: 57 + 58 +- For Windows DLL versions, please see win32/DLL_FAQ.txt 59 + 60 +- For 64-bit Irix, deflate.c must be compiled without any optimization. With 61 + -O, one libpng test fails. The test works in 32 bit mode (with the -n32 62 + compiler flag). The compiler bug has been reported to SGI. 63 + 64 +- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works 65 + when compiled with cc. 66 + 67 +- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is 68 + necessary to get gzprintf working correctly. This is done by configure. 69 + 70 +- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with 71 + other compilers. Use "make test" to check your compiler. 72 + 73 +- gzdopen is not supported on RISCOS or BEOS. 74 + 75 +- For PalmOs, see http://palmzlib.sourceforge.net/ 76 + 77 + 78 +Acknowledgments: 79 + 80 + The deflate format used by zlib was defined by Phil Katz. The deflate and 81 + zlib specifications were written by L. Peter Deutsch. Thanks to all the 82 + people who reported problems and suggested various improvements in zlib; they 83 + are too numerous to cite here. 84 + 85 +Copyright notice: 86 + 87 + (C) 1995-2012 Jean-loup Gailly and Mark Adler 88 + 89 + This software is provided 'as-is', without any express or implied 90 + warranty. In no event will the authors be held liable for any damages 91 + arising from the use of this software. 92 + 93 + Permission is granted to anyone to use this software for any purpose, 94 + including commercial applications, and to alter it and redistribute it 95 + freely, subject to the following restrictions: 96 + 97 + 1. The origin of this software must not be misrepresented; you must not 98 + claim that you wrote the original software. If you use this software 99 + in a product, an acknowledgment in the product documentation would be 100 + appreciated but is not required. 101 + 2. Altered source versions must be plainly marked as such, and must not be 102 + misrepresented as being the original software. 103 + 3. This notice may not be removed or altered from any source distribution. 104 + 105 + Jean-loup Gailly Mark Adler 106 + jloup@gzip.org madler@alumni.caltech.edu 107 + 108 +If you use the zlib library in a product, we would appreciate *not* receiving 109 +lengthy legal documents to sign. The sources are provided for free but without 110 +warranty of any kind. The library has been entirely written by Jean-loup 111 +Gailly and Mark Adler; it does not include third-party code. 112 + 113 +If you redistribute modified sources, we would appreciate that you include in 114 +the file ChangeLog history information documenting your changes. Please read 115 +the FAQ for more information on the distribution of modified source versions.
Added compat/zlib/adler32.c.
1 +/* adler32.c -- compute the Adler-32 checksum of a data stream 2 + * Copyright (C) 1995-2011 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#include "zutil.h" 9 + 10 +#define local static 11 + 12 +local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 13 + 14 +#define BASE 65521 /* largest prime smaller than 65536 */ 15 +#define NMAX 5552 16 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 17 + 18 +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 19 +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 20 +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 21 +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 22 +#define DO16(buf) DO8(buf,0); DO8(buf,8); 23 + 24 +/* use NO_DIVIDE if your processor does not do division in hardware -- 25 + try it both ways to see which is faster */ 26 +#ifdef NO_DIVIDE 27 +/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 28 + (thank you to John Reiser for pointing this out) */ 29 +# define CHOP(a) \ 30 + do { \ 31 + unsigned long tmp = a >> 16; \ 32 + a &= 0xffffUL; \ 33 + a += (tmp << 4) - tmp; \ 34 + } while (0) 35 +# define MOD28(a) \ 36 + do { \ 37 + CHOP(a); \ 38 + if (a >= BASE) a -= BASE; \ 39 + } while (0) 40 +# define MOD(a) \ 41 + do { \ 42 + CHOP(a); \ 43 + MOD28(a); \ 44 + } while (0) 45 +# define MOD63(a) \ 46 + do { /* this assumes a is not negative */ \ 47 + z_off64_t tmp = a >> 32; \ 48 + a &= 0xffffffffL; \ 49 + a += (tmp << 8) - (tmp << 5) + tmp; \ 50 + tmp = a >> 16; \ 51 + a &= 0xffffL; \ 52 + a += (tmp << 4) - tmp; \ 53 + tmp = a >> 16; \ 54 + a &= 0xffffL; \ 55 + a += (tmp << 4) - tmp; \ 56 + if (a >= BASE) a -= BASE; \ 57 + } while (0) 58 +#else 59 +# define MOD(a) a %= BASE 60 +# define MOD28(a) a %= BASE 61 +# define MOD63(a) a %= BASE 62 +#endif 63 + 64 +/* ========================================================================= */ 65 +uLong ZEXPORT adler32(adler, buf, len) 66 + uLong adler; 67 + const Bytef *buf; 68 + uInt len; 69 +{ 70 + unsigned long sum2; 71 + unsigned n; 72 + 73 + /* split Adler-32 into component sums */ 74 + sum2 = (adler >> 16) & 0xffff; 75 + adler &= 0xffff; 76 + 77 + /* in case user likes doing a byte at a time, keep it fast */ 78 + if (len == 1) { 79 + adler += buf[0]; 80 + if (adler >= BASE) 81 + adler -= BASE; 82 + sum2 += adler; 83 + if (sum2 >= BASE) 84 + sum2 -= BASE; 85 + return adler | (sum2 << 16); 86 + } 87 + 88 + /* initial Adler-32 value (deferred check for len == 1 speed) */ 89 + if (buf == Z_NULL) 90 + return 1L; 91 + 92 + /* in case short lengths are provided, keep it somewhat fast */ 93 + if (len < 16) { 94 + while (len--) { 95 + adler += *buf++; 96 + sum2 += adler; 97 + } 98 + if (adler >= BASE) 99 + adler -= BASE; 100 + MOD28(sum2); /* only added so many BASE's */ 101 + return adler | (sum2 << 16); 102 + } 103 + 104 + /* do length NMAX blocks -- requires just one modulo operation */ 105 + while (len >= NMAX) { 106 + len -= NMAX; 107 + n = NMAX / 16; /* NMAX is divisible by 16 */ 108 + do { 109 + DO16(buf); /* 16 sums unrolled */ 110 + buf += 16; 111 + } while (--n); 112 + MOD(adler); 113 + MOD(sum2); 114 + } 115 + 116 + /* do remaining bytes (less than NMAX, still just one modulo) */ 117 + if (len) { /* avoid modulos if none remaining */ 118 + while (len >= 16) { 119 + len -= 16; 120 + DO16(buf); 121 + buf += 16; 122 + } 123 + while (len--) { 124 + adler += *buf++; 125 + sum2 += adler; 126 + } 127 + MOD(adler); 128 + MOD(sum2); 129 + } 130 + 131 + /* return recombined sums */ 132 + return adler | (sum2 << 16); 133 +} 134 + 135 +/* ========================================================================= */ 136 +local uLong adler32_combine_(adler1, adler2, len2) 137 + uLong adler1; 138 + uLong adler2; 139 + z_off64_t len2; 140 +{ 141 + unsigned long sum1; 142 + unsigned long sum2; 143 + unsigned rem; 144 + 145 + /* for negative len, return invalid adler32 as a clue for debugging */ 146 + if (len2 < 0) 147 + return 0xffffffffUL; 148 + 149 + /* the derivation of this formula is left as an exercise for the reader */ 150 + MOD63(len2); /* assumes len2 >= 0 */ 151 + rem = (unsigned)len2; 152 + sum1 = adler1 & 0xffff; 153 + sum2 = rem * sum1; 154 + MOD(sum2); 155 + sum1 += (adler2 & 0xffff) + BASE - 1; 156 + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 157 + if (sum1 >= BASE) sum1 -= BASE; 158 + if (sum1 >= BASE) sum1 -= BASE; 159 + if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 160 + if (sum2 >= BASE) sum2 -= BASE; 161 + return sum1 | (sum2 << 16); 162 +} 163 + 164 +/* ========================================================================= */ 165 +uLong ZEXPORT adler32_combine(adler1, adler2, len2) 166 + uLong adler1; 167 + uLong adler2; 168 + z_off_t len2; 169 +{ 170 + return adler32_combine_(adler1, adler2, len2); 171 +} 172 + 173 +uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 174 + uLong adler1; 175 + uLong adler2; 176 + z_off64_t len2; 177 +{ 178 + return adler32_combine_(adler1, adler2, len2); 179 +}
Added compat/zlib/amiga/Makefile.pup.
1 +# Amiga powerUP (TM) Makefile 2 +# makefile for libpng and SAS C V6.58/7.00 PPC compiler 3 +# Copyright (C) 1998 by Andreas R. Kleinert 4 + 5 +LIBNAME = libzip.a 6 + 7 +CC = scppc 8 +CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL \ 9 + OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 NOVER 10 +AR = ppc-amigaos-ar cr 11 +RANLIB = ppc-amigaos-ranlib 12 +LD = ppc-amigaos-ld -r 13 +LDFLAGS = -o 14 +LDLIBS = LIB:scppc.a LIB:end.o 15 +RM = delete quiet 16 + 17 +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ 18 + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o 19 + 20 +TEST_OBJS = example.o minigzip.o 21 + 22 +all: example minigzip 23 + 24 +check: test 25 +test: all 26 + example 27 + echo hello world | minigzip | minigzip -d 28 + 29 +$(LIBNAME): $(OBJS) 30 + $(AR) $@ $(OBJS) 31 + -$(RANLIB) $@ 32 + 33 +example: example.o $(LIBNAME) 34 + $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) 35 + 36 +minigzip: minigzip.o $(LIBNAME) 37 + $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) 38 + 39 +mostlyclean: clean 40 +clean: 41 + $(RM) *.o example minigzip $(LIBNAME) foo.gz 42 + 43 +zip: 44 + zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \ 45 + descrip.mms *.[ch] 46 + 47 +tgz: 48 + cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ 49 + zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch] 50 + 51 +# DO NOT DELETE THIS LINE -- make depend depends on it. 52 + 53 +adler32.o: zlib.h zconf.h 54 +compress.o: zlib.h zconf.h 55 +crc32.o: crc32.h zlib.h zconf.h 56 +deflate.o: deflate.h zutil.h zlib.h zconf.h 57 +example.o: zlib.h zconf.h 58 +gzclose.o: zlib.h zconf.h gzguts.h 59 +gzlib.o: zlib.h zconf.h gzguts.h 60 +gzread.o: zlib.h zconf.h gzguts.h 61 +gzwrite.o: zlib.h zconf.h gzguts.h 62 +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 63 +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 64 +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 65 +inftrees.o: zutil.h zlib.h zconf.h inftrees.h 66 +minigzip.o: zlib.h zconf.h 67 +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h 68 +uncompr.o: zlib.h zconf.h 69 +zutil.o: zutil.h zlib.h zconf.h
Added compat/zlib/amiga/Makefile.sas.
1 +# SMakefile for zlib 2 +# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly 3 +# Osma Ahvenlampi <Osma.Ahvenlampi@hut.fi> 4 +# Amiga, SAS/C 6.56 & Smake 5 + 6 +CC=sc 7 +CFLAGS=OPT 8 +#CFLAGS=OPT CPU=68030 9 +#CFLAGS=DEBUG=LINE 10 +LDFLAGS=LIB z.lib 11 + 12 +SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \ 13 + NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \ 14 + DEF=POSTINC 15 + 16 +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ 17 + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o 18 + 19 +TEST_OBJS = example.o minigzip.o 20 + 21 +all: SCOPTIONS example minigzip 22 + 23 +check: test 24 +test: all 25 + example 26 + echo hello world | minigzip | minigzip -d 27 + 28 +install: z.lib 29 + copy clone zlib.h zconf.h INCLUDE: 30 + copy clone z.lib LIB: 31 + 32 +z.lib: $(OBJS) 33 + oml z.lib r $(OBJS) 34 + 35 +example: example.o z.lib 36 + $(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS) 37 + 38 +minigzip: minigzip.o z.lib 39 + $(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS) 40 + 41 +mostlyclean: clean 42 +clean: 43 + -delete force quiet example minigzip *.o z.lib foo.gz *.lnk SCOPTIONS 44 + 45 +SCOPTIONS: Makefile.sas 46 + copy to $@ <from < 47 +$(SCOPTIONS) 48 +< 49 + 50 +# DO NOT DELETE THIS LINE -- make depend depends on it. 51 + 52 +adler32.o: zlib.h zconf.h 53 +compress.o: zlib.h zconf.h 54 +crc32.o: crc32.h zlib.h zconf.h 55 +deflate.o: deflate.h zutil.h zlib.h zconf.h 56 +example.o: zlib.h zconf.h 57 +gzclose.o: zlib.h zconf.h gzguts.h 58 +gzlib.o: zlib.h zconf.h gzguts.h 59 +gzread.o: zlib.h zconf.h gzguts.h 60 +gzwrite.o: zlib.h zconf.h gzguts.h 61 +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 62 +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 63 +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 64 +inftrees.o: zutil.h zlib.h zconf.h inftrees.h 65 +minigzip.o: zlib.h zconf.h 66 +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h 67 +uncompr.o: zlib.h zconf.h 68 +zutil.o: zutil.h zlib.h zconf.h
Added compat/zlib/as400/bndsrc.
1 +STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('ZLIB') 2 + 3 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 4 +/* Version 1.1.3 entry points. */ 5 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 6 + 7 +/********************************************************************/ 8 +/* *MODULE ADLER32 ZLIB 01/02/01 00:15:09 */ 9 +/********************************************************************/ 10 + 11 + EXPORT SYMBOL("adler32") 12 + 13 +/********************************************************************/ 14 +/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */ 15 +/********************************************************************/ 16 + 17 + EXPORT SYMBOL("compress") 18 + EXPORT SYMBOL("compress2") 19 + 20 +/********************************************************************/ 21 +/* *MODULE CRC32 ZLIB 01/02/01 00:15:09 */ 22 +/********************************************************************/ 23 + 24 + EXPORT SYMBOL("crc32") 25 + EXPORT SYMBOL("get_crc_table") 26 + 27 +/********************************************************************/ 28 +/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */ 29 +/********************************************************************/ 30 + 31 + EXPORT SYMBOL("deflate") 32 + EXPORT SYMBOL("deflateEnd") 33 + EXPORT SYMBOL("deflateSetDictionary") 34 + EXPORT SYMBOL("deflateCopy") 35 + EXPORT SYMBOL("deflateReset") 36 + EXPORT SYMBOL("deflateParams") 37 + EXPORT SYMBOL("deflatePrime") 38 + EXPORT SYMBOL("deflateInit_") 39 + EXPORT SYMBOL("deflateInit2_") 40 + 41 +/********************************************************************/ 42 +/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */ 43 +/********************************************************************/ 44 + 45 + EXPORT SYMBOL("gzopen") 46 + EXPORT SYMBOL("gzdopen") 47 + EXPORT SYMBOL("gzsetparams") 48 + EXPORT SYMBOL("gzread") 49 + EXPORT SYMBOL("gzwrite") 50 + EXPORT SYMBOL("gzprintf") 51 + EXPORT SYMBOL("gzputs") 52 + EXPORT SYMBOL("gzgets") 53 + EXPORT SYMBOL("gzputc") 54 + EXPORT SYMBOL("gzgetc") 55 + EXPORT SYMBOL("gzflush") 56 + EXPORT SYMBOL("gzseek") 57 + EXPORT SYMBOL("gzrewind") 58 + EXPORT SYMBOL("gztell") 59 + EXPORT SYMBOL("gzeof") 60 + EXPORT SYMBOL("gzclose") 61 + EXPORT SYMBOL("gzerror") 62 + 63 +/********************************************************************/ 64 +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ 65 +/********************************************************************/ 66 + 67 + EXPORT SYMBOL("inflate") 68 + EXPORT SYMBOL("inflateEnd") 69 + EXPORT SYMBOL("inflateSetDictionary") 70 + EXPORT SYMBOL("inflateSync") 71 + EXPORT SYMBOL("inflateReset") 72 + EXPORT SYMBOL("inflateInit_") 73 + EXPORT SYMBOL("inflateInit2_") 74 + EXPORT SYMBOL("inflateSyncPoint") 75 + 76 +/********************************************************************/ 77 +/* *MODULE UNCOMPR ZLIB 01/02/01 00:15:09 */ 78 +/********************************************************************/ 79 + 80 + EXPORT SYMBOL("uncompress") 81 + 82 +/********************************************************************/ 83 +/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */ 84 +/********************************************************************/ 85 + 86 + EXPORT SYMBOL("zlibVersion") 87 + EXPORT SYMBOL("zError") 88 + 89 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 90 +/* Version 1.2.1 additional entry points. */ 91 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 92 + 93 +/********************************************************************/ 94 +/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */ 95 +/********************************************************************/ 96 + 97 + EXPORT SYMBOL("compressBound") 98 + 99 +/********************************************************************/ 100 +/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */ 101 +/********************************************************************/ 102 + 103 + EXPORT SYMBOL("deflateBound") 104 + 105 +/********************************************************************/ 106 +/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */ 107 +/********************************************************************/ 108 + 109 + EXPORT SYMBOL("gzungetc") 110 + EXPORT SYMBOL("gzclearerr") 111 + 112 +/********************************************************************/ 113 +/* *MODULE INFBACK ZLIB 01/02/01 00:15:09 */ 114 +/********************************************************************/ 115 + 116 + EXPORT SYMBOL("inflateBack") 117 + EXPORT SYMBOL("inflateBackEnd") 118 + EXPORT SYMBOL("inflateBackInit_") 119 + 120 +/********************************************************************/ 121 +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ 122 +/********************************************************************/ 123 + 124 + EXPORT SYMBOL("inflateCopy") 125 + 126 +/********************************************************************/ 127 +/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */ 128 +/********************************************************************/ 129 + 130 + EXPORT SYMBOL("zlibCompileFlags") 131 + 132 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 133 +/* Version 1.2.5 additional entry points. */ 134 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 135 + 136 +/********************************************************************/ 137 +/* *MODULE ADLER32 ZLIB 01/02/01 00:15:09 */ 138 +/********************************************************************/ 139 + 140 + EXPORT SYMBOL("adler32_combine") 141 + EXPORT SYMBOL("adler32_combine64") 142 + 143 +/********************************************************************/ 144 +/* *MODULE CRC32 ZLIB 01/02/01 00:15:09 */ 145 +/********************************************************************/ 146 + 147 + EXPORT SYMBOL("crc32_combine") 148 + EXPORT SYMBOL("crc32_combine64") 149 + 150 +/********************************************************************/ 151 +/* *MODULE GZLIB ZLIB 01/02/01 00:15:09 */ 152 +/********************************************************************/ 153 + 154 + EXPORT SYMBOL("gzbuffer") 155 + EXPORT SYMBOL("gzoffset") 156 + EXPORT SYMBOL("gzoffset64") 157 + EXPORT SYMBOL("gzopen64") 158 + EXPORT SYMBOL("gzseek64") 159 + EXPORT SYMBOL("gztell64") 160 + 161 +/********************************************************************/ 162 +/* *MODULE GZREAD ZLIB 01/02/01 00:15:09 */ 163 +/********************************************************************/ 164 + 165 + EXPORT SYMBOL("gzclose_r") 166 + 167 +/********************************************************************/ 168 +/* *MODULE GZWRITE ZLIB 01/02/01 00:15:09 */ 169 +/********************************************************************/ 170 + 171 + EXPORT SYMBOL("gzclose_w") 172 + 173 +/********************************************************************/ 174 +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ 175 +/********************************************************************/ 176 + 177 + EXPORT SYMBOL("inflateMark") 178 + EXPORT SYMBOL("inflatePrime") 179 + EXPORT SYMBOL("inflateReset2") 180 + EXPORT SYMBOL("inflateUndermine") 181 + 182 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 183 +/* Version 1.2.6 additional entry points. */ 184 +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ 185 + 186 +/********************************************************************/ 187 +/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */ 188 +/********************************************************************/ 189 + 190 + EXPORT SYMBOL("deflateResetKeep") 191 + EXPORT SYMBOL("deflatePending") 192 + 193 +/********************************************************************/ 194 +/* *MODULE GZWRITE ZLIB 01/02/01 00:15:09 */ 195 +/********************************************************************/ 196 + 197 + EXPORT SYMBOL("gzgetc_") 198 + 199 +/********************************************************************/ 200 +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ 201 +/********************************************************************/ 202 + 203 + EXPORT SYMBOL("inflateResetKeep") 204 + 205 +ENDPGMEXP
Added compat/zlib/as400/compile.clp.
1 +/******************************************************************************/ 2 +/* */ 3 +/* ZLIB */ 4 +/* */ 5 +/* Compile sources into modules and link them into a service program. */ 6 +/* */ 7 +/******************************************************************************/ 8 + 9 + PGM 10 + 11 +/* Configuration adjustable parameters. */ 12 + 13 + DCL VAR(&SRCLIB) TYPE(*CHAR) LEN(10) + 14 + VALUE('ZLIB') /* Source library. */ 15 + DCL VAR(&SRCFILE) TYPE(*CHAR) LEN(10) + 16 + VALUE('SOURCES') /* Source member file. */ 17 + DCL VAR(&CTLFILE) TYPE(*CHAR) LEN(10) + 18 + VALUE('TOOLS') /* Control member file. */ 19 + 20 + DCL VAR(&MODLIB) TYPE(*CHAR) LEN(10) + 21 + VALUE('ZLIB') /* Module library. */ 22 + 23 + DCL VAR(&SRVLIB) TYPE(*CHAR) LEN(10) + 24 + VALUE('LGPL') /* Service program library. */ 25 + 26 + DCL VAR(&CFLAGS) TYPE(*CHAR) + 27 + VALUE('OPTIMIZE(40)') /* Compile options. */ 28 + 29 + DCL VAR(&TGTRLS) TYPE(*CHAR) + 30 + VALUE('V5R3M0') /* Target release. */ 31 + 32 + 33 +/* Working storage. */ 34 + 35 + DCL VAR(&CMDLEN) TYPE(*DEC) LEN(15 5) VALUE(300) /* Command length. */ 36 + DCL VAR(&CMD) TYPE(*CHAR) LEN(512) 37 + DCL VAR(&FIXDCMD) TYPE(*CHAR) LEN(512) 38 + 39 + 40 +/* Compile sources into modules. */ 41 + 42 + CHGVAR VAR(&FIXDCMD) VALUE('CRTCMOD' *BCAT &CFLAGS *BCAT + 43 + 'SYSIFCOPT(*IFS64IO)' *BCAT + 44 + 'DEFINE(''_LARGEFILE64_SOURCE''' *BCAT + 45 + '''_LFS64_LARGEFILE=1'') TGTRLS(' *TCAT &TGTRLS *TCAT + 46 + ') SRCFILE(' *TCAT &SRCLIB *TCAT '/' *TCAT + 47 + &SRCFILE *TCAT ') MODULE(' *TCAT &MODLIB *TCAT '/') 48 + 49 + 50 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'ADLER32)') 51 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 52 + 53 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'COMPRESS)') 54 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 55 + 56 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'CRC32)') 57 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 58 + 59 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'DEFLATE)') 60 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 61 + 62 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZCLOSE)') 63 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 64 + 65 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZLIB)') 66 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 67 + 68 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZREAD)') 69 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 70 + 71 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZWRITE)') 72 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 73 + 74 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFBACK)') 75 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 76 + 77 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFFAST)') 78 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 79 + 80 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFLATE)') 81 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 82 + 83 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFTREES)') 84 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 85 + 86 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'TREES)') 87 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 88 + 89 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'UNCOMPR)') 90 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 91 + 92 + CHGVAR VAR(&CMD) VALUE(&FIXDCMD *TCAT 'ZUTIL)') 93 + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) 94 + 95 + 96 +/* Link modules into a service program. */ 97 + 98 + CRTSRVPGM SRVPGM(&SRVLIB/ZLIB) + 99 + MODULE(&MODLIB/ADLER32 &MODLIB/COMPRESS + 100 + &MODLIB/CRC32 &MODLIB/DEFLATE + 101 + &MODLIB/GZCLOSE &MODLIB/GZLIB + 102 + &MODLIB/GZREAD &MODLIB/GZWRITE + 103 + &MODLIB/INFBACK &MODLIB/INFFAST + 104 + &MODLIB/INFLATE &MODLIB/INFTREES + 105 + &MODLIB/TREES &MODLIB/UNCOMPR + 106 + &MODLIB/ZUTIL) + 107 + SRCFILE(&SRCLIB/&CTLFILE) SRCMBR(BNDSRC) + 108 + TEXT('ZLIB 1.2.7') TGTRLS(&TGTRLS) 109 + 110 + ENDPGM
Added compat/zlib/as400/readme.txt.
1 + ZLIB version 1.2.7 for AS400 installation instructions 2 + 3 +I) From an AS400 *SAVF file: 4 + 5 +1) Unpacking archive to an AS400 save file 6 + 7 +On the AS400: 8 + 9 +_ Create the ZLIB AS400 library: 10 + 11 + CRTLIB LIB(ZLIB) TYPE(*PROD) TEXT('ZLIB compression API library') 12 + 13 +_ Create a work save file, for example: 14 + 15 + CRTSAVF FILE(ZLIB/ZLIBSAVF) 16 + 17 +On a PC connected to the target AS400: 18 + 19 +_ Unpack the save file image to a PC file "ZLIBSAVF" 20 +_ Upload this file into the save file on the AS400, for example 21 + using ftp in BINARY mode. 22 + 23 + 24 +2) Populating the ZLIB AS400 source library 25 + 26 +On the AS400: 27 + 28 +_ Extract the saved objects into the ZLIB AS400 library using: 29 + 30 +RSTOBJ OBJ(*ALL) SAVLIB(ZLIB) DEV(*SAVF) SAVF(ZLIB/ZLIBSAVF) RSTLIB(ZLIB) 31 + 32 + 33 +3) Customize installation: 34 + 35 +_ Edit CL member ZLIB/TOOLS(COMPILE) and change parameters if needed, 36 + according to the comments. 37 + 38 +_ Compile this member with: 39 + 40 + CRTCLPGM PGM(ZLIB/COMPILE) SRCFILE(ZLIB/TOOLS) SRCMBR(COMPILE) 41 + 42 + 43 +4) Compile and generate the service program: 44 + 45 +_ This can now be done by executing: 46 + 47 + CALL PGM(ZLIB/COMPILE) 48 + 49 + 50 + 51 +II) From the original source distribution: 52 + 53 +1) On the AS400, create the source library: 54 + 55 + CRTLIB LIB(ZLIB) TYPE(*PROD) TEXT('ZLIB compression API library') 56 + 57 +2) Create the source files: 58 + 59 + CRTSRCPF FILE(ZLIB/SOURCES) RCDLEN(112) TEXT('ZLIB library modules') 60 + CRTSRCPF FILE(ZLIB/H) RCDLEN(112) TEXT('ZLIB library includes') 61 + CRTSRCPF FILE(ZLIB/TOOLS) RCDLEN(112) TEXT('ZLIB library control utilities') 62 + 63 +3) From the machine hosting the distribution files, upload them (with 64 + FTP in text mode, for example) according to the following table: 65 + 66 + Original AS400 AS400 AS400 AS400 67 + file file member type description 68 + SOURCES Original ZLIB C subprogram sources 69 + adler32.c ADLER32 C ZLIB - Compute the Adler-32 checksum of a dta strm 70 + compress.c COMPRESS C ZLIB - Compress a memory buffer 71 + crc32.c CRC32 C ZLIB - Compute the CRC-32 of a data stream 72 + deflate.c DEFLATE C ZLIB - Compress data using the deflation algorithm 73 + gzclose.c GZCLOSE C ZLIB - Close .gz files 74 + gzlib.c GZLIB C ZLIB - Miscellaneous .gz files IO support 75 + gzread.c GZREAD C ZLIB - Read .gz files 76 + gzwrite.c GZWRITE C ZLIB - Write .gz files 77 + infback.c INFBACK C ZLIB - Inflate using a callback interface 78 + inffast.c INFFAST C ZLIB - Fast proc. literals & length/distance pairs 79 + inflate.c INFLATE C ZLIB - Interface to inflate modules 80 + inftrees.c INFTREES C ZLIB - Generate Huffman trees for efficient decode 81 + trees.c TREES C ZLIB - Output deflated data using Huffman coding 82 + uncompr.c UNCOMPR C ZLIB - Decompress a memory buffer 83 + zutil.c ZUTIL C ZLIB - Target dependent utility functions 84 + H Original ZLIB C and ILE/RPG include files 85 + crc32.h CRC32 C ZLIB - CRC32 tables 86 + deflate.h DEFLATE C ZLIB - Internal compression state 87 + gzguts.h GZGUTS C ZLIB - Definitions for the gzclose module 88 + inffast.h INFFAST C ZLIB - Header to use inffast.c 89 + inffixed.h INFFIXED C ZLIB - Table for decoding fixed codes 90 + inflate.h INFLATE C ZLIB - Internal inflate state definitions 91 + inftrees.h INFTREES C ZLIB - Header to use inftrees.c 92 + trees.h TREES C ZLIB - Created automatically with -DGEN_TREES_H 93 + zconf.h ZCONF C ZLIB - Compression library configuration 94 + zlib.h ZLIB C ZLIB - Compression library C user interface 95 + as400/zlib.inc ZLIB.INC RPGLE ZLIB - Compression library ILE RPG user interface 96 + zutil.h ZUTIL C ZLIB - Internal interface and configuration 97 + TOOLS Building source software & AS/400 README 98 + as400/bndsrc BNDSRC Entry point exportation list 99 + as400/compile.clp COMPILE CLP Compile sources & generate service program 100 + as400/readme.txt README TXT Installation instructions 101 + 102 +4) Continue as in I)3). 103 + 104 + 105 + 106 + 107 +Notes: For AS400 ILE RPG programmers, a /copy member defining the ZLIB 108 + API prototypes for ILE RPG can be found in ZLIB/H(ZLIB.INC). 109 + Please read comments in this member for more information. 110 + 111 + Remember that most foreign textual data are ASCII coded: this 112 + implementation does not handle conversion from/to ASCII, so 113 + text data code conversions must be done explicitely. 114 + 115 + Mainly for the reason above, always open zipped files in binary mode.
Added compat/zlib/as400/zlib.inc.
1 + * ZLIB.INC - Interface to the general purpose compression library 2 + * 3 + * ILE RPG400 version by Patrick Monnerat, DATASPHERE. 4 + * Version 1.2.7 5 + * 6 + * 7 + * WARNING: 8 + * Procedures inflateInit(), inflateInit2(), deflateInit(), 9 + * deflateInit2() and inflateBackInit() need to be called with 10 + * two additional arguments: 11 + * the package version string and the stream control structure. 12 + * size. This is needed because RPG lacks some macro feature. 13 + * Call these procedures as: 14 + * inflateInit(...: ZLIB_VERSION: %size(z_stream)) 15 + * 16 + /if not defined(ZLIB_H_) 17 + /define ZLIB_H_ 18 + * 19 + ************************************************************************** 20 + * Constants 21 + ************************************************************************** 22 + * 23 + * Versioning information. 24 + * 25 + D ZLIB_VERSION C '1.2.7' 26 + D ZLIB_VERNUM C X'1270' 27 + D ZLIB_VER_MAJOR C 1 28 + D ZLIB_VER_MINOR C 2 29 + D ZLIB_VER_REVISION... 30 + D C 7 31 + D ZLIB_VER_SUBREVISION... 32 + D C 0 33 + * 34 + * Other equates. 35 + * 36 + D Z_NO_FLUSH C 0 37 + D Z_PARTIAL_FLUSH... 38 + D C 1 39 + D Z_SYNC_FLUSH C 2 40 + D Z_FULL_FLUSH C 3 41 + D Z_FINISH C 4 42 + D Z_BLOCK C 5 43 + D Z_TREES C 6 44 + * 45 + D Z_OK C 0 46 + D Z_STREAM_END C 1 47 + D Z_NEED_DICT C 2 48 + D Z_ERRNO C -1 49 + D Z_STREAM_ERROR C -2 50 + D Z_DATA_ERROR C -3 51 + D Z_MEM_ERROR C -4 52 + D Z_BUF_ERROR C -5 53 + DZ_VERSION_ERROR C -6 54 + * 55 + D Z_NO_COMPRESSION... 56 + D C 0 57 + D Z_BEST_SPEED C 1 58 + D Z_BEST_COMPRESSION... 59 + D C 9 60 + D Z_DEFAULT_COMPRESSION... 61 + D C -1 62 + * 63 + D Z_FILTERED C 1 64 + D Z_HUFFMAN_ONLY C 2 65 + D Z_RLE C 3 66 + D Z_DEFAULT_STRATEGY... 67 + D C 0 68 + * 69 + D Z_BINARY C 0 70 + D Z_ASCII C 1 71 + D Z_UNKNOWN C 2 72 + * 73 + D Z_DEFLATED C 8 74 + * 75 + D Z_NULL C 0 76 + * 77 + ************************************************************************** 78 + * Types 79 + ************************************************************************** 80 + * 81 + D z_streamp S * Stream struct ptr 82 + D gzFile S * File pointer 83 + D z_off_t S 10i 0 Stream offsets 84 + D z_off64_t S 20i 0 Stream offsets 85 + * 86 + ************************************************************************** 87 + * Structures 88 + ************************************************************************** 89 + * 90 + * The GZIP encode/decode stream support structure. 91 + * 92 + D z_stream DS align based(z_streamp) 93 + D zs_next_in * Next input byte 94 + D zs_avail_in 10U 0 Byte cnt at next_in 95 + D zs_total_in 10U 0 Total bytes read 96 + D zs_next_out * Output buffer ptr 97 + D zs_avail_out 10U 0 Room left @ next_out 98 + D zs_total_out 10U 0 Total bytes written 99 + D zs_msg * Last errmsg or null 100 + D zs_state * Internal state 101 + D zs_zalloc * procptr Int. state allocator 102 + D zs_free * procptr Int. state dealloc. 103 + D zs_opaque * Private alloc. data 104 + D zs_data_type 10i 0 ASC/BIN best guess 105 + D zs_adler 10u 0 Uncompr. adler32 val 106 + D 10U 0 Reserved 107 + D 10U 0 Ptr. alignment 108 + * 109 + ************************************************************************** 110 + * Utility function prototypes 111 + ************************************************************************** 112 + * 113 + D compress PR 10I 0 extproc('compress') 114 + D dest 65535 options(*varsize) Destination buffer 115 + D destLen 10U 0 Destination length 116 + D source 65535 const options(*varsize) Source buffer 117 + D sourceLen 10u 0 value Source length 118 + * 119 + D compress2 PR 10I 0 extproc('compress2') 120 + D dest 65535 options(*varsize) Destination buffer 121 + D destLen 10U 0 Destination length 122 + D source 65535 const options(*varsize) Source buffer 123 + D sourceLen 10U 0 value Source length 124 + D level 10I 0 value Compression level 125 + * 126 + D compressBound PR 10U 0 extproc('compressBound') 127 + D sourceLen 10U 0 value 128 + * 129 + D uncompress PR 10I 0 extproc('uncompress') 130 + D dest 65535 options(*varsize) Destination buffer 131 + D destLen 10U 0 Destination length 132 + D source 65535 const options(*varsize) Source buffer 133 + D sourceLen 10U 0 value Source length 134 + * 135 + /if not defined(LARGE_FILES) 136 + D gzopen PR extproc('gzopen') 137 + D like(gzFile) 138 + D path * value options(*string) File pathname 139 + D mode * value options(*string) Open mode 140 + /else 141 + D gzopen PR extproc('gzopen64') 142 + D like(gzFile) 143 + D path * value options(*string) File pathname 144 + D mode * value options(*string) Open mode 145 + * 146 + D gzopen64 PR extproc('gzopen64') 147 + D like(gzFile) 148 + D path * value options(*string) File pathname 149 + D mode * value options(*string) Open mode 150 + /endif 151 + * 152 + D gzdopen PR extproc('gzdopen') 153 + D like(gzFile) 154 + D fd 10I 0 value File descriptor 155 + D mode * value options(*string) Open mode 156 + * 157 + D gzbuffer PR 10I 0 extproc('gzbuffer') 158 + D file value like(gzFile) File pointer 159 + D size 10U 0 value 160 + * 161 + D gzsetparams PR 10I 0 extproc('gzsetparams') 162 + D file value like(gzFile) File pointer 163 + D level 10I 0 value 164 + D strategy 10I 0 value 165 + * 166 + D gzread PR 10I 0 extproc('gzread') 167 + D file value like(gzFile) File pointer 168 + D buf 65535 options(*varsize) Buffer 169 + D len 10u 0 value Buffer length 170 + * 171 + D gzwrite PR 10I 0 extproc('gzwrite') 172 + D file value like(gzFile) File pointer 173 + D buf 65535 const options(*varsize) Buffer 174 + D len 10u 0 value Buffer length 175 + * 176 + D gzputs PR 10I 0 extproc('gzputs') 177 + D file value like(gzFile) File pointer 178 + D s * value options(*string) String to output 179 + * 180 + D gzgets PR * extproc('gzgets') 181 + D file value like(gzFile) File pointer 182 + D buf 65535 options(*varsize) Read buffer 183 + D len 10i 0 value Buffer length 184 + * 185 + D gzputc PR 10i 0 extproc('gzputc') 186 + D file value like(gzFile) File pointer 187 + D c 10I 0 value Character to write 188 + * 189 + D gzgetc PR 10i 0 extproc('gzgetc') 190 + D file value like(gzFile) File pointer 191 + * 192 + D gzgetc_ PR 10i 0 extproc('gzgetc_') 193 + D file value like(gzFile) File pointer 194 + * 195 + D gzungetc PR 10i 0 extproc('gzungetc') 196 + D c 10I 0 value Character to push 197 + D file value like(gzFile) File pointer 198 + * 199 + D gzflush PR 10i 0 extproc('gzflush') 200 + D file value like(gzFile) File pointer 201 + D flush 10I 0 value Type of flush 202 + * 203 + /if not defined(LARGE_FILES) 204 + D gzseek PR extproc('gzseek') 205 + D like(z_off_t) 206 + D file value like(gzFile) File pointer 207 + D offset value like(z_off_t) Offset 208 + D whence 10i 0 value Origin 209 + /else 210 + D gzseek PR extproc('gzseek64') 211 + D like(z_off_t) 212 + D file value like(gzFile) File pointer 213 + D offset value like(z_off_t) Offset 214 + D whence 10i 0 value Origin 215 + * 216 + D gzseek64 PR extproc('gzseek64') 217 + D like(z_off64_t) 218 + D file value like(gzFile) File pointer 219 + D offset value like(z_off64_t) Offset 220 + D whence 10i 0 value Origin 221 + /endif 222 + * 223 + D gzrewind PR 10i 0 extproc('gzrewind') 224 + D file value like(gzFile) File pointer 225 + * 226 + /if not defined(LARGE_FILES) 227 + D gztell PR extproc('gztell') 228 + D like(z_off_t) 229 + D file value like(gzFile) File pointer 230 + /else 231 + D gztell PR extproc('gztell64') 232 + D like(z_off_t) 233 + D file value like(gzFile) File pointer 234 + * 235 + D gztell64 PR extproc('gztell64') 236 + D like(z_off64_t) 237 + D file value like(gzFile) File pointer 238 + /endif 239 + * 240 + /if not defined(LARGE_FILES) 241 + D gzoffset PR extproc('gzoffset') 242 + D like(z_off_t) 243 + D file value like(gzFile) File pointer 244 + /else 245 + D gzoffset PR extproc('gzoffset64') 246 + D like(z_off_t) 247 + D file value like(gzFile) File pointer 248 + * 249 + D gzoffset64 PR extproc('gzoffset64') 250 + D like(z_off64_t) 251 + D file value like(gzFile) File pointer 252 + /endif 253 + * 254 + D gzeof PR 10i 0 extproc('gzeof') 255 + D file value like(gzFile) File pointer 256 + * 257 + D gzclose_r PR 10i 0 extproc('gzclose_r') 258 + D file value like(gzFile) File pointer 259 + * 260 + D gzclose_w PR 10i 0 extproc('gzclose_w') 261 + D file value like(gzFile) File pointer 262 + * 263 + D gzclose PR 10i 0 extproc('gzclose') 264 + D file value like(gzFile) File pointer 265 + * 266 + D gzerror PR * extproc('gzerror') Error string 267 + D file value like(gzFile) File pointer 268 + D errnum 10I 0 Error code 269 + * 270 + D gzclearerr PR extproc('gzclearerr') 271 + D file value like(gzFile) File pointer 272 + * 273 + ************************************************************************** 274 + * Basic function prototypes 275 + ************************************************************************** 276 + * 277 + D zlibVersion PR * extproc('zlibVersion') Version string 278 + * 279 + D deflateInit PR 10I 0 extproc('deflateInit_') Init. compression 280 + D strm like(z_stream) Compression stream 281 + D level 10I 0 value Compression level 282 + D version * value options(*string) Version string 283 + D stream_size 10i 0 value Stream struct. size 284 + * 285 + D deflate PR 10I 0 extproc('deflate') Compress data 286 + D strm like(z_stream) Compression stream 287 + D flush 10I 0 value Flush type required 288 + * 289 + D deflateEnd PR 10I 0 extproc('deflateEnd') Termin. compression 290 + D strm like(z_stream) Compression stream 291 + * 292 + D inflateInit PR 10I 0 extproc('inflateInit_') Init. expansion 293 + D strm like(z_stream) Expansion stream 294 + D version * value options(*string) Version string 295 + D stream_size 10i 0 value Stream struct. size 296 + * 297 + D inflate PR 10I 0 extproc('inflate') Expand data 298 + D strm like(z_stream) Expansion stream 299 + D flush 10I 0 value Flush type required 300 + * 301 + D inflateEnd PR 10I 0 extproc('inflateEnd') Termin. expansion 302 + D strm like(z_stream) Expansion stream 303 + * 304 + ************************************************************************** 305 + * Advanced function prototypes 306 + ************************************************************************** 307 + * 308 + D deflateInit2 PR 10I 0 extproc('deflateInit2_') Init. compression 309 + D strm like(z_stream) Compression stream 310 + D level 10I 0 value Compression level 311 + D method 10I 0 value Compression method 312 + D windowBits 10I 0 value log2(window size) 313 + D memLevel 10I 0 value Mem/cmpress tradeoff 314 + D strategy 10I 0 value Compression stategy 315 + D version * value options(*string) Version string 316 + D stream_size 10i 0 value Stream struct. size 317 + * 318 + D deflateSetDictionary... 319 + D PR 10I 0 extproc('deflateSetDictionary') Init. dictionary 320 + D strm like(z_stream) Compression stream 321 + D dictionary 65535 const options(*varsize) Dictionary bytes 322 + D dictLength 10U 0 value Dictionary length 323 + * 324 + D deflateCopy PR 10I 0 extproc('deflateCopy') Compress strm 2 strm 325 + D dest like(z_stream) Destination stream 326 + D source like(z_stream) Source stream 327 + * 328 + D deflateReset PR 10I 0 extproc('deflateReset') End and init. stream 329 + D strm like(z_stream) Compression stream 330 + * 331 + D deflateParams PR 10I 0 extproc('deflateParams') Change level & strat 332 + D strm like(z_stream) Compression stream 333 + D level 10I 0 value Compression level 334 + D strategy 10I 0 value Compression stategy 335 + * 336 + D deflateBound PR 10U 0 extproc('deflateBound') Change level & strat 337 + D strm like(z_stream) Compression stream 338 + D sourcelen 10U 0 value Compression level 339 + * 340 + D deflatePending PR 10I 0 extproc('deflatePending') Change level & strat 341 + D strm like(z_stream) Compression stream 342 + D pending 10U 0 Pending bytes 343 + D bits 10I 0 Pending bits 344 + * 345 + D deflatePrime PR 10I 0 extproc('deflatePrime') Change level & strat 346 + D strm like(z_stream) Compression stream 347 + D bits 10I 0 value # of bits to insert 348 + D value 10I 0 value Bits to insert 349 + * 350 + D inflateInit2 PR 10I 0 extproc('inflateInit2_') Init. expansion 351 + D strm like(z_stream) Expansion stream 352 + D windowBits 10I 0 value log2(window size) 353 + D version * value options(*string) Version string 354 + D stream_size 10i 0 value Stream struct. size 355 + * 356 + D inflateSetDictionary... 357 + D PR 10I 0 extproc('inflateSetDictionary') Init. dictionary 358 + D strm like(z_stream) Expansion stream 359 + D dictionary 65535 const options(*varsize) Dictionary bytes 360 + D dictLength 10U 0 value Dictionary length 361 + * 362 + D inflateSync PR 10I 0 extproc('inflateSync') Sync. expansion 363 + D strm like(z_stream) Expansion stream 364 + * 365 + D inflateCopy PR 10I 0 extproc('inflateCopy') 366 + D dest like(z_stream) Destination stream 367 + D source like(z_stream) Source stream 368 + * 369 + D inflateReset PR 10I 0 extproc('inflateReset') End and init. stream 370 + D strm like(z_stream) Expansion stream 371 + * 372 + D inflateReset2 PR 10I 0 extproc('inflateReset2') End and init. stream 373 + D strm like(z_stream) Expansion stream 374 + D windowBits 10I 0 value Log2(buffer size) 375 + * 376 + D inflatePrime PR 10I 0 extproc('inflatePrime') Insert bits 377 + D strm like(z_stream) Expansion stream 378 + D bits 10I 0 value Bit count 379 + D value 10I 0 value Bits to insert 380 + * 381 + D inflateMark PR 10I 0 extproc('inflateMark') Get inflate info 382 + D strm like(z_stream) Expansion stream 383 + * 384 + D inflateBackInit... 385 + D PR 10I 0 extproc('inflateBackInit_') 386 + D strm like(z_stream) Expansion stream 387 + D windowBits 10I 0 value Log2(buffer size) 388 + D window 65535 options(*varsize) Buffer 389 + D version * value options(*string) Version string 390 + D stream_size 10i 0 value Stream struct. size 391 + * 392 + D inflateBack PR 10I 0 extproc('inflateBack') 393 + D strm like(z_stream) Expansion stream 394 + D in * value procptr Input function 395 + D in_desc * value Input descriptor 396 + D out * value procptr Output function 397 + D out_desc * value Output descriptor 398 + * 399 + D inflateBackEnd PR 10I 0 extproc('inflateBackEnd') 400 + D strm like(z_stream) Expansion stream 401 + * 402 + D zlibCompileFlags... 403 + D PR 10U 0 extproc('zlibCompileFlags') 404 + * 405 + ************************************************************************** 406 + * Checksum function prototypes 407 + ************************************************************************** 408 + * 409 + D adler32 PR 10U 0 extproc('adler32') New checksum 410 + D adler 10U 0 value Old checksum 411 + D buf 65535 const options(*varsize) Bytes to accumulate 412 + D len 10U 0 value Buffer length 413 + * 414 + D crc32 PR 10U 0 extproc('crc32') New checksum 415 + D crc 10U 0 value Old checksum 416 + D buf 65535 const options(*varsize) Bytes to accumulate 417 + D len 10U 0 value Buffer length 418 + * 419 + ************************************************************************** 420 + * Miscellaneous function prototypes 421 + ************************************************************************** 422 + * 423 + D zError PR * extproc('zError') Error string 424 + D err 10I 0 value Error code 425 + * 426 + D inflateSyncPoint... 427 + D PR 10I 0 extproc('inflateSyncPoint') 428 + D strm like(z_stream) Expansion stream 429 + * 430 + D get_crc_table PR * extproc('get_crc_table') Ptr to ulongs 431 + * 432 + D inflateUndermine... 433 + D PR 10I 0 extproc('inflateUndermine') 434 + D strm like(z_stream) Expansion stream 435 + D arg 10I 0 value Error code 436 + * 437 + D inflateResetKeep... 438 + D PR 10I 0 extproc('inflateResetKeep') End and init. stream 439 + D strm like(z_stream) Expansion stream 440 + * 441 + D deflateResetKeep... 442 + D PR 10I 0 extproc('deflateResetKeep') End and init. stream 443 + D strm like(z_stream) Expansion stream 444 + * 445 + /endif
Added compat/zlib/compress.c.
1 +/* compress.c -- compress a memory buffer 2 + * Copyright (C) 1995-2005 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#define ZLIB_INTERNAL 9 +#include "zlib.h" 10 + 11 +/* =========================================================================== 12 + Compresses the source buffer into the destination buffer. The level 13 + parameter has the same meaning as in deflateInit. sourceLen is the byte 14 + length of the source buffer. Upon entry, destLen is the total size of the 15 + destination buffer, which must be at least 0.1% larger than sourceLen plus 16 + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 + 18 + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 + memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 + Z_STREAM_ERROR if the level parameter is invalid. 21 +*/ 22 +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 + Bytef *dest; 24 + uLongf *destLen; 25 + const Bytef *source; 26 + uLong sourceLen; 27 + int level; 28 +{ 29 + z_stream stream; 30 + int err; 31 + 32 + stream.next_in = (Bytef*)source; 33 + stream.avail_in = (uInt)sourceLen; 34 +#ifdef MAXSEG_64K 35 + /* Check for source > 64K on 16-bit machine: */ 36 + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 +#endif 38 + stream.next_out = dest; 39 + stream.avail_out = (uInt)*destLen; 40 + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 + 42 + stream.zalloc = (alloc_func)0; 43 + stream.zfree = (free_func)0; 44 + stream.opaque = (voidpf)0; 45 + 46 + err = deflateInit(&stream, level); 47 + if (err != Z_OK) return err; 48 + 49 + err = deflate(&stream, Z_FINISH); 50 + if (err != Z_STREAM_END) { 51 + deflateEnd(&stream); 52 + return err == Z_OK ? Z_BUF_ERROR : err; 53 + } 54 + *destLen = stream.total_out; 55 + 56 + err = deflateEnd(&stream); 57 + return err; 58 +} 59 + 60 +/* =========================================================================== 61 + */ 62 +int ZEXPORT compress (dest, destLen, source, sourceLen) 63 + Bytef *dest; 64 + uLongf *destLen; 65 + const Bytef *source; 66 + uLong sourceLen; 67 +{ 68 + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 +} 70 + 71 +/* =========================================================================== 72 + If the default memLevel or windowBits for deflateInit() is changed, then 73 + this function needs to be updated. 74 + */ 75 +uLong ZEXPORT compressBound (sourceLen) 76 + uLong sourceLen; 77 +{ 78 + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 + (sourceLen >> 25) + 13; 80 +}
Added compat/zlib/configure.
1 +#!/bin/sh 2 +# configure script for zlib. 3 +# 4 +# Normally configure builds both a static and a shared library. 5 +# If you want to build just a static library, use: ./configure --static 6 +# 7 +# To impose specific compiler or flags or install directory, use for example: 8 +# prefix=$HOME CC=cc CFLAGS="-O4" ./configure 9 +# or for csh/tcsh users: 10 +# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) 11 + 12 +# Incorrect settings of CC or CFLAGS may prevent creating a shared library. 13 +# If you have problems, try without defining CC and CFLAGS before reporting 14 +# an error. 15 + 16 +# start off configure.log 17 +echo -------------------- >> configure.log 18 +echo $0 $* >> configure.log 19 +date >> configure.log 20 + 21 +# set command prefix for cross-compilation 22 +if [ -n "${CHOST}" ]; then 23 + uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`" 24 + CROSS_PREFIX="${CHOST}-" 25 +fi 26 + 27 +# destination name for static library 28 +STATICLIB=libz.a 29 + 30 +# extract zlib version numbers from zlib.h 31 +VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` 32 +VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h` 33 +VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` 34 +VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` 35 + 36 +# establish commands for library building 37 +if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then 38 + AR=${AR-"${CROSS_PREFIX}ar"} 39 + test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log 40 +else 41 + AR=${AR-"ar"} 42 + test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log 43 +fi 44 +ARFLAGS=${ARFLAGS-"rc"} 45 +if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then 46 + RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"} 47 + test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log 48 +else 49 + RANLIB=${RANLIB-"ranlib"} 50 +fi 51 +if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then 52 + NM=${NM-"${CROSS_PREFIX}nm"} 53 + test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log 54 +else 55 + NM=${NM-"nm"} 56 +fi 57 + 58 +# set defaults before processing command line options 59 +LDCONFIG=${LDCONFIG-"ldconfig"} 60 +LDSHAREDLIBC="${LDSHAREDLIBC--lc}" 61 +ARCHS= 62 +prefix=${prefix-/usr/local} 63 +exec_prefix=${exec_prefix-'${prefix}'} 64 +libdir=${libdir-'${exec_prefix}/lib'} 65 +sharedlibdir=${sharedlibdir-'${libdir}'} 66 +includedir=${includedir-'${prefix}/include'} 67 +mandir=${mandir-'${prefix}/share/man'} 68 +shared_ext='.so' 69 +shared=1 70 +solo=0 71 +cover=0 72 +zprefix=0 73 +build64=0 74 +gcc=0 75 +old_cc="$CC" 76 +old_cflags="$CFLAGS" 77 +OBJC='$(OBJZ) $(OBJG)' 78 +PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)' 79 + 80 +# process command line options 81 +while test $# -ge 1 82 +do 83 +case "$1" in 84 + -h* | --help) 85 + echo 'usage:' | tee -a configure.log 86 + echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log 87 + echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log 88 + echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log 89 + exit 0 ;; 90 + -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;; 91 + -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;; 92 + -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;; 93 + --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;; 94 + -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;; 95 + -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;; 96 + -p* | --prefix) prefix="$2"; shift; shift ;; 97 + -e* | --eprefix) exec_prefix="$2"; shift; shift ;; 98 + -l* | --libdir) libdir="$2"; shift; shift ;; 99 + -i* | --includedir) includedir="$2"; shift; shift ;; 100 + -s* | --shared | --enable-shared) shared=1; shift ;; 101 + -t | --static) shared=0; shift ;; 102 + --solo) solo=1; shift ;; 103 + --cover) cover=1; shift ;; 104 + -z* | --zprefix) zprefix=1; shift ;; 105 + -6* | --64) build64=1; shift ;; 106 + -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; 107 + --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;; 108 + --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;; 109 + *) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;; 110 + esac 111 +done 112 + 113 +# define functions for testing compiler and library characteristics and logging the results 114 +test=ztest$$ 115 + 116 +show() 117 +{ 118 + case "$*" in 119 + *$test.c*) 120 + echo === $test.c === >> configure.log 121 + cat $test.c >> configure.log 122 + echo === >> configure.log;; 123 + esac 124 + echo $* >> configure.log 125 +} 126 + 127 +cat > $test.c <<EOF 128 +#error error 129 +EOF 130 +if ($CC -c $CFLAGS $test.c) 2>/dev/null; then 131 + try() 132 + { 133 + show $* 134 + test "`( $* ) 2>&1 | tee -a configure.log`" = "" 135 + } 136 + echo - using any output from compiler to indicate an error >> configure.log 137 +else 138 + try() 139 + { 140 + show $* 141 + ( $* ) >> configure.log 2>&1 142 + ret=$? 143 + if test $ret -ne 0; then 144 + echo "(exit code "$ret")" >> configure.log 145 + fi 146 + return $ret 147 + } 148 +fi 149 + 150 +tryboth() 151 +{ 152 + show $* 153 + got=`( $* ) 2>&1` 154 + ret=$? 155 + printf %s "$got" >> configure.log 156 + if test $ret -ne 0; then 157 + return $ret 158 + fi 159 + test "$got" = "" 160 +} 161 + 162 +echo >> configure.log 163 + 164 +# check for gcc vs. cc and set compile and link flags based on the system identified by uname 165 +cat > $test.c <<EOF 166 +extern int getchar(); 167 +int hello() {return getchar();} 168 +EOF 169 + 170 +test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log 171 +cc=${CC-${CROSS_PREFIX}gcc} 172 +cflags=${CFLAGS-"-O3"} 173 +# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure 174 +case "$cc" in 175 + *gcc*) gcc=1 ;; 176 + *clang*) gcc=1 ;; 177 +esac 178 +case `$cc -v 2>&1` in 179 + *gcc*) gcc=1 ;; 180 +esac 181 + 182 +show $cc -c $cflags $test.c 183 +if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then 184 + echo ... using gcc >> configure.log 185 + CC="$cc" 186 + CFLAGS="${CFLAGS--O3} ${ARCHS}" 187 + SFLAGS="${CFLAGS--O3} -fPIC" 188 + LDFLAGS="${LDFLAGS} ${ARCHS}" 189 + if test $build64 -eq 1; then 190 + CFLAGS="${CFLAGS} -m64" 191 + SFLAGS="${SFLAGS} -m64" 192 + fi 193 + if test "${ZLIBGCCWARN}" = "YES"; then 194 + CFLAGS="${CFLAGS} -Wall -Wextra -pedantic" 195 + fi 196 + if test -z "$uname"; then 197 + uname=`(uname -s || echo unknown) 2>/dev/null` 198 + fi 199 + case "$uname" in 200 + Linux* | linux* | GNU | GNU/* | solaris*) 201 + LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;; 202 + *BSD | *bsd* | DragonFly) 203 + LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} 204 + LDCONFIG="ldconfig -m" ;; 205 + CYGWIN* | Cygwin* | cygwin* | OS/2*) 206 + EXE='.exe' ;; 207 + MINGW* | mingw*) 208 +# temporary bypass 209 + rm -f $test.[co] $test $test$shared_ext 210 + echo "Please use win32/Makefile.gcc instead." | tee -a configure.log 211 + exit 1 212 + LDSHARED=${LDSHARED-"$cc -shared"} 213 + LDSHAREDLIBC="" 214 + EXE='.exe' ;; 215 + QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 216 + # (alain.bonnefoy@icbt.com) 217 + LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;; 218 + HP-UX*) 219 + LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"} 220 + case `(uname -m || echo unknown) 2>/dev/null` in 221 + ia64) 222 + shared_ext='.so' 223 + SHAREDLIB='libz.so' ;; 224 + *) 225 + shared_ext='.sl' 226 + SHAREDLIB='libz.sl' ;; 227 + esac ;; 228 + Darwin* | darwin*) 229 + shared_ext='.dylib' 230 + SHAREDLIB=libz$shared_ext 231 + SHAREDLIBV=libz.$VER$shared_ext 232 + SHAREDLIBM=libz.$VER1$shared_ext 233 + LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} 234 + AR="/usr/bin/libtool" 235 + ARFLAGS="-o" ;; 236 + *) LDSHARED=${LDSHARED-"$cc -shared"} ;; 237 + esac 238 +else 239 + # find system name and corresponding cc options 240 + CC=${CC-cc} 241 + gcc=0 242 + echo ... using $CC >> configure.log 243 + if test -z "$uname"; then 244 + uname=`(uname -sr || echo unknown) 2>/dev/null` 245 + fi 246 + case "$uname" in 247 + HP-UX*) SFLAGS=${CFLAGS-"-O +z"} 248 + CFLAGS=${CFLAGS-"-O"} 249 +# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} 250 + LDSHARED=${LDSHARED-"ld -b"} 251 + case `(uname -m || echo unknown) 2>/dev/null` in 252 + ia64) 253 + shared_ext='.so' 254 + SHAREDLIB='libz.so' ;; 255 + *) 256 + shared_ext='.sl' 257 + SHAREDLIB='libz.sl' ;; 258 + esac ;; 259 + IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} 260 + CFLAGS=${CFLAGS-"-ansi -O2"} 261 + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; 262 + OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} 263 + CFLAGS=${CFLAGS-"-O -std1"} 264 + LDFLAGS="${LDFLAGS} -Wl,-rpath,." 265 + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;; 266 + OSF1*) SFLAGS=${CFLAGS-"-O -std1"} 267 + CFLAGS=${CFLAGS-"-O -std1"} 268 + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; 269 + QNX*) SFLAGS=${CFLAGS-"-4 -O"} 270 + CFLAGS=${CFLAGS-"-4 -O"} 271 + LDSHARED=${LDSHARED-"cc"} 272 + RANLIB=${RANLIB-"true"} 273 + AR="cc" 274 + ARFLAGS="-A" ;; 275 + SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} 276 + CFLAGS=${CFLAGS-"-O3"} 277 + LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;; 278 + SunOS\ 5* | solaris*) 279 + LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"} 280 + SFLAGS=${CFLAGS-"-fast -KPIC"} 281 + CFLAGS=${CFLAGS-"-fast"} 282 + if test $build64 -eq 1; then 283 + # old versions of SunPRO/Workshop/Studio don't support -m64, 284 + # but newer ones do. Check for it. 285 + flag64=`$CC -flags | egrep -- '^-m64'` 286 + if test x"$flag64" != x"" ; then 287 + CFLAGS="${CFLAGS} -m64" 288 + SFLAGS="${SFLAGS} -m64" 289 + else 290 + case `(uname -m || echo unknown) 2>/dev/null` in 291 + i86*) 292 + SFLAGS="$SFLAGS -xarch=amd64" 293 + CFLAGS="$CFLAGS -xarch=amd64" ;; 294 + *) 295 + SFLAGS="$SFLAGS -xarch=v9" 296 + CFLAGS="$CFLAGS -xarch=v9" ;; 297 + esac 298 + fi 299 + fi 300 + ;; 301 + SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} 302 + CFLAGS=${CFLAGS-"-O2"} 303 + LDSHARED=${LDSHARED-"ld"} ;; 304 + SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} 305 + CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"} 306 + LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; 307 + UNIX_System_V\ 4.2.0) 308 + SFLAGS=${CFLAGS-"-KPIC -O"} 309 + CFLAGS=${CFLAGS-"-O"} 310 + LDSHARED=${LDSHARED-"cc -G"} ;; 311 + UNIX_SV\ 4.2MP) 312 + SFLAGS=${CFLAGS-"-Kconform_pic -O"} 313 + CFLAGS=${CFLAGS-"-O"} 314 + LDSHARED=${LDSHARED-"cc -G"} ;; 315 + OpenUNIX\ 5) 316 + SFLAGS=${CFLAGS-"-KPIC -O"} 317 + CFLAGS=${CFLAGS-"-O"} 318 + LDSHARED=${LDSHARED-"cc -G"} ;; 319 + AIX*) # Courtesy of dbakker@arrayasolutions.com 320 + SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 321 + CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 322 + LDSHARED=${LDSHARED-"xlc -G"} ;; 323 + # send working options for other systems to zlib@gzip.org 324 + *) SFLAGS=${CFLAGS-"-O"} 325 + CFLAGS=${CFLAGS-"-O"} 326 + LDSHARED=${LDSHARED-"cc -shared"} ;; 327 + esac 328 +fi 329 + 330 +# destination names for shared library if not defined above 331 +SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} 332 +SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} 333 +SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} 334 + 335 +echo >> configure.log 336 + 337 +# see if shared library build supported 338 +if test $shared -eq 1; then 339 + echo Checking for shared library support... | tee -a configure.log 340 + # we must test in two steps (cc then ld), required at least on SunOS 4.x 341 + if try $CC -w -c $SFLAGS $test.c && 342 + try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then 343 + echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log 344 + elif test -z "$old_cc" -a -z "$old_cflags"; then 345 + echo No shared library support. | tee -a configure.log 346 + shared=0; 347 + else 348 + echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log 349 + shared=0; 350 + fi 351 +fi 352 +if test $shared -eq 0; then 353 + LDSHARED="$CC" 354 + ALL="static" 355 + TEST="all teststatic" 356 + SHAREDLIB="" 357 + SHAREDLIBV="" 358 + SHAREDLIBM="" 359 + echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log 360 +else 361 + ALL="static shared" 362 + TEST="all teststatic testshared" 363 +fi 364 + 365 +echo >> configure.log 366 + 367 +# check for underscores in external names for use by assembler code 368 +CPP=${CPP-"$CC -E"} 369 +case $CFLAGS in 370 + *ASMV*) 371 + echo >> configure.log 372 + show "$NM $test.o | grep _hello" 373 + if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then 374 + CPP="$CPP -DNO_UNDERLINE" 375 + echo Checking for underline in external names... No. | tee -a configure.log 376 + else 377 + echo Checking for underline in external names... Yes. | tee -a configure.log 378 + fi ;; 379 +esac 380 + 381 +echo >> configure.log 382 + 383 +# check for large file support, and if none, check for fseeko() 384 +cat > $test.c <<EOF 385 +#include <sys/types.h> 386 +off64_t dummy = 0; 387 +EOF 388 +if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then 389 + CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1" 390 + SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1" 391 + ALL="${ALL} all64" 392 + TEST="${TEST} test64" 393 + echo "Checking for off64_t... Yes." | tee -a configure.log 394 + echo "Checking for fseeko... Yes." | tee -a configure.log 395 +else 396 + echo "Checking for off64_t... No." | tee -a configure.log 397 + echo >> configure.log 398 + cat > $test.c <<EOF 399 +#include <stdio.h> 400 +int main(void) { 401 + fseeko(NULL, 0, 0); 402 + return 0; 403 +} 404 +EOF 405 + if try $CC $CFLAGS -o $test $test.c; then 406 + echo "Checking for fseeko... Yes." | tee -a configure.log 407 + else 408 + CFLAGS="${CFLAGS} -DNO_FSEEKO" 409 + SFLAGS="${SFLAGS} -DNO_FSEEKO" 410 + echo "Checking for fseeko... No." | tee -a configure.log 411 + fi 412 +fi 413 + 414 +echo >> configure.log 415 + 416 +# check for strerror() for use by gz* functions 417 +cat > $test.c <<EOF 418 +#include <string.h> 419 +#include <errno.h> 420 +int main() { return strlen(strerror(errno)); } 421 +EOF 422 +if try $CC $CFLAGS -o $test $test.c; then 423 + echo "Checking for strerror... Yes." | tee -a configure.log 424 +else 425 + CFLAGS="${CFLAGS} -DNO_STRERROR" 426 + SFLAGS="${SFLAGS} -DNO_STRERROR" 427 + echo "Checking for strerror... No." | tee -a configure.log 428 +fi 429 + 430 +# copy clean zconf.h for subsequent edits 431 +cp -p zconf.h.in zconf.h 432 + 433 +echo >> configure.log 434 + 435 +# check for unistd.h and save result in zconf.h 436 +cat > $test.c <<EOF 437 +#include <unistd.h> 438 +int main() { return 0; } 439 +EOF 440 +if try $CC -c $CFLAGS $test.c; then 441 + sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h 442 + mv zconf.temp.h zconf.h 443 + echo "Checking for unistd.h... Yes." | tee -a configure.log 444 +else 445 + echo "Checking for unistd.h... No." | tee -a configure.log 446 +fi 447 + 448 +echo >> configure.log 449 + 450 +# check for stdarg.h and save result in zconf.h 451 +cat > $test.c <<EOF 452 +#include <stdarg.h> 453 +int main() { return 0; } 454 +EOF 455 +if try $CC -c $CFLAGS $test.c; then 456 + sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h 457 + mv zconf.temp.h zconf.h 458 + echo "Checking for stdarg.h... Yes." | tee -a configure.log 459 +else 460 + echo "Checking for stdarg.h... No." | tee -a configure.log 461 +fi 462 + 463 +# if the z_ prefix was requested, save that in zconf.h 464 +if test $zprefix -eq 1; then 465 + sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h 466 + mv zconf.temp.h zconf.h 467 + echo >> configure.log 468 + echo "Using z_ prefix on all symbols." | tee -a configure.log 469 +fi 470 + 471 +# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists 472 +if test $solo -eq 1; then 473 + sed '/#define ZCONF_H/a\ 474 +#define Z_SOLO 475 + 476 +' < zconf.h > zconf.temp.h 477 + mv zconf.temp.h zconf.h 478 +OBJC='$(OBJZ)' 479 +PIC_OBJC='$(PIC_OBJZ)' 480 +fi 481 + 482 +# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X 483 +if test $cover -eq 1; then 484 + CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" 485 + if test -n "$GCC_CLASSIC"; then 486 + CC=$GCC_CLASSIC 487 + fi 488 +fi 489 + 490 +echo >> configure.log 491 + 492 +# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions 493 +# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a 494 +# return value. The most secure result is vsnprintf() with a return value. snprintf() with a 495 +# return value is secure as well, but then gzprintf() will be limited to 20 arguments. 496 +cat > $test.c <<EOF 497 +#include <stdio.h> 498 +#include <stdarg.h> 499 +#include "zconf.h" 500 +int main() 501 +{ 502 +#ifndef STDC 503 + choke me 504 +#endif 505 + return 0; 506 +} 507 +EOF 508 +if try $CC -c $CFLAGS $test.c; then 509 + echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log 510 + 511 + echo >> configure.log 512 + cat > $test.c <<EOF 513 +#include <stdio.h> 514 +#include <stdarg.h> 515 +int mytest(const char *fmt, ...) 516 +{ 517 + char buf[20]; 518 + va_list ap; 519 + va_start(ap, fmt); 520 + vsnprintf(buf, sizeof(buf), fmt, ap); 521 + va_end(ap); 522 + return 0; 523 +} 524 +int main() 525 +{ 526 + return (mytest("Hello%d\n", 1)); 527 +} 528 +EOF 529 + if try $CC $CFLAGS -o $test $test.c; then 530 + echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log 531 + 532 + echo >> configure.log 533 + cat >$test.c <<EOF 534 +#include <stdio.h> 535 +#include <stdarg.h> 536 +int mytest(const char *fmt, ...) 537 +{ 538 + int n; 539 + char buf[20]; 540 + va_list ap; 541 + va_start(ap, fmt); 542 + n = vsnprintf(buf, sizeof(buf), fmt, ap); 543 + va_end(ap); 544 + return n; 545 +} 546 +int main() 547 +{ 548 + return (mytest("Hello%d\n", 1)); 549 +} 550 +EOF 551 + 552 + if try $CC -c $CFLAGS $test.c; then 553 + echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log 554 + else 555 + CFLAGS="$CFLAGS -DHAS_vsnprintf_void" 556 + SFLAGS="$SFLAGS -DHAS_vsnprintf_void" 557 + echo "Checking for return value of vsnprintf()... No." | tee -a configure.log 558 + echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log 559 + echo " can build but will be open to possible string-format security" | tee -a configure.log 560 + echo " vulnerabilities." | tee -a configure.log 561 + fi 562 + else 563 + CFLAGS="$CFLAGS -DNO_vsnprintf" 564 + SFLAGS="$SFLAGS -DNO_vsnprintf" 565 + echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log 566 + echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log 567 + echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log 568 + echo " vulnerabilities." | tee -a configure.log 569 + 570 + echo >> configure.log 571 + cat >$test.c <<EOF 572 +#include <stdio.h> 573 +#include <stdarg.h> 574 +int mytest(const char *fmt, ...) 575 +{ 576 + int n; 577 + char buf[20]; 578 + va_list ap; 579 + va_start(ap, fmt); 580 + n = vsprintf(buf, fmt, ap); 581 + va_end(ap); 582 + return n; 583 +} 584 +int main() 585 +{ 586 + return (mytest("Hello%d\n", 1)); 587 +} 588 +EOF 589 + 590 + if try $CC -c $CFLAGS $test.c; then 591 + echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log 592 + else 593 + CFLAGS="$CFLAGS -DHAS_vsprintf_void" 594 + SFLAGS="$SFLAGS -DHAS_vsprintf_void" 595 + echo "Checking for return value of vsprintf()... No." | tee -a configure.log 596 + echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log 597 + echo " can build but will be open to possible string-format security" | tee -a configure.log 598 + echo " vulnerabilities." | tee -a configure.log 599 + fi 600 + fi 601 +else 602 + echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log 603 + 604 + echo >> configure.log 605 + cat >$test.c <<EOF 606 +#include <stdio.h> 607 +int mytest() 608 +{ 609 + char buf[20]; 610 + snprintf(buf, sizeof(buf), "%s", "foo"); 611 + return 0; 612 +} 613 +int main() 614 +{ 615 + return (mytest()); 616 +} 617 +EOF 618 + 619 + if try $CC $CFLAGS -o $test $test.c; then 620 + echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log 621 + 622 + echo >> configure.log 623 + cat >$test.c <<EOF 624 +#include <stdio.h> 625 +int mytest() 626 +{ 627 + char buf[20]; 628 + return snprintf(buf, sizeof(buf), "%s", "foo"); 629 +} 630 +int main() 631 +{ 632 + return (mytest()); 633 +} 634 +EOF 635 + 636 + if try $CC -c $CFLAGS $test.c; then 637 + echo "Checking for return value of snprintf()... Yes." | tee -a configure.log 638 + else 639 + CFLAGS="$CFLAGS -DHAS_snprintf_void" 640 + SFLAGS="$SFLAGS -DHAS_snprintf_void" 641 + echo "Checking for return value of snprintf()... No." | tee -a configure.log 642 + echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log 643 + echo " can build but will be open to possible string-format security" | tee -a configure.log 644 + echo " vulnerabilities." | tee -a configure.log 645 + fi 646 + else 647 + CFLAGS="$CFLAGS -DNO_snprintf" 648 + SFLAGS="$SFLAGS -DNO_snprintf" 649 + echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log 650 + echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log 651 + echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log 652 + echo " vulnerabilities." | tee -a configure.log 653 + 654 + echo >> configure.log 655 + cat >$test.c <<EOF 656 +#include <stdio.h> 657 +int mytest() 658 +{ 659 + char buf[20]; 660 + return sprintf(buf, "%s", "foo"); 661 +} 662 +int main() 663 +{ 664 + return (mytest()); 665 +} 666 +EOF 667 + 668 + if try $CC -c $CFLAGS $test.c; then 669 + echo "Checking for return value of sprintf()... Yes." | tee -a configure.log 670 + else 671 + CFLAGS="$CFLAGS -DHAS_sprintf_void" 672 + SFLAGS="$SFLAGS -DHAS_sprintf_void" 673 + echo "Checking for return value of sprintf()... No." | tee -a configure.log 674 + echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log 675 + echo " can build but will be open to possible string-format security" | tee -a configure.log 676 + echo " vulnerabilities." | tee -a configure.log 677 + fi 678 + fi 679 +fi 680 + 681 +# see if we can hide zlib internal symbols that are linked between separate source files 682 +if test "$gcc" -eq 1; then 683 + echo >> configure.log 684 + cat > $test.c <<EOF 685 +#define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 686 +int ZLIB_INTERNAL foo; 687 +int main() 688 +{ 689 + return 0; 690 +} 691 +EOF 692 + if tryboth $CC -c $CFLAGS $test.c; then 693 + CFLAGS="$CFLAGS -DHAVE_HIDDEN" 694 + SFLAGS="$SFLAGS -DHAVE_HIDDEN" 695 + echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log 696 + else 697 + echo "Checking for attribute(visibility) support... No." | tee -a configure.log 698 + fi 699 +fi 700 + 701 +echo >> configure.log 702 + 703 +# find a four-byte unsiged integer type for crc calculations 704 +cat > $test.c <<EOF 705 +#include <stdio.h> 706 +#define is32(n,t) for(n=1,k=0;n;n<<=1,k++);if(k==32){puts(t);return 0;} 707 +int main() { 708 + int k; 709 + unsigned i; 710 + unsigned long l; 711 + unsigned short s; 712 + is32(i, "unsigned") 713 + is32(l, "unsigned long") 714 + is32(s, "unsigned short") 715 + return 1; 716 +} 717 +EOF 718 +Z_U4="" 719 +if try $CC $CFLAGS $test.c -o $test && Z_U4=`./$test` && test -n "$Z_U4"; then 720 + sed < zconf.h "/#define Z_U4/s/\/\* \.\/configure may/#define Z_U4 $Z_U4 \/* .\/configure put the/" > zconf.temp.h 721 + mv zconf.temp.h zconf.h 722 + echo "Looking for a four-byte integer type... Found." | tee -a configure.log 723 +else 724 + echo "Looking for a four-byte integer type... Not found." | tee -a configure.log 725 +fi 726 + 727 +# clean up files produced by running the compiler and linker 728 +rm -f $test.[co] $test $test$shared_ext $test.gcno 729 + 730 +# show the results in the log 731 +echo >> configure.log 732 +echo ALL = $ALL >> configure.log 733 +echo AR = $AR >> configure.log 734 +echo ARFLAGS = $ARFLAGS >> configure.log 735 +echo CC = $CC >> configure.log 736 +echo CFLAGS = $CFLAGS >> configure.log 737 +echo CPP = $CPP >> configure.log 738 +echo EXE = $EXE >> configure.log 739 +echo LDCONFIG = $LDCONFIG >> configure.log 740 +echo LDFLAGS = $LDFLAGS >> configure.log 741 +echo LDSHARED = $LDSHARED >> configure.log 742 +echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log 743 +echo OBJC = $OBJC >> configure.log 744 +echo PIC_OBJC = $PIC_OBJC >> configure.log 745 +echo RANLIB = $RANLIB >> configure.log 746 +echo SFLAGS = $SFLAGS >> configure.log 747 +echo SHAREDLIB = $SHAREDLIB >> configure.log 748 +echo SHAREDLIBM = $SHAREDLIBM >> configure.log 749 +echo SHAREDLIBV = $SHAREDLIBV >> configure.log 750 +echo STATICLIB = $STATICLIB >> configure.log 751 +echo TEST = $TEST >> configure.log 752 +echo VER = $VER >> configure.log 753 +echo Z_U4 = $Z_U4 >> configure.log 754 +echo exec_prefix = $exec_prefix >> configure.log 755 +echo includedir = $includedir >> configure.log 756 +echo libdir = $libdir >> configure.log 757 +echo mandir = $mandir >> configure.log 758 +echo prefix = $prefix >> configure.log 759 +echo sharedlibdir = $sharedlibdir >> configure.log 760 +echo uname = $uname >> configure.log 761 +echo -------------------- >> configure.log 762 +echo >> configure.log 763 +echo >> configure.log 764 + 765 +# udpate Makefile with the configure results 766 +sed < Makefile.in " 767 +/^CC *=/s#=.*#=$CC# 768 +/^CFLAGS *=/s#=.*#=$CFLAGS# 769 +/^SFLAGS *=/s#=.*#=$SFLAGS# 770 +/^LDFLAGS *=/s#=.*#=$LDFLAGS# 771 +/^LDSHARED *=/s#=.*#=$LDSHARED# 772 +/^CPP *=/s#=.*#=$CPP# 773 +/^STATICLIB *=/s#=.*#=$STATICLIB# 774 +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# 775 +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# 776 +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# 777 +/^AR *=/s#=.*#=$AR# 778 +/^ARFLAGS *=/s#=.*#=$ARFLAGS# 779 +/^RANLIB *=/s#=.*#=$RANLIB# 780 +/^LDCONFIG *=/s#=.*#=$LDCONFIG# 781 +/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC# 782 +/^EXE *=/s#=.*#=$EXE# 783 +/^prefix *=/s#=.*#=$prefix# 784 +/^exec_prefix *=/s#=.*#=$exec_prefix# 785 +/^libdir *=/s#=.*#=$libdir# 786 +/^sharedlibdir *=/s#=.*#=$sharedlibdir# 787 +/^includedir *=/s#=.*#=$includedir# 788 +/^mandir *=/s#=.*#=$mandir# 789 +/^OBJC *=/s#=.*#= $OBJC# 790 +/^PIC_OBJC *=/s#=.*#= $PIC_OBJC# 791 +/^all: */s#:.*#: $ALL# 792 +/^test: */s#:.*#: $TEST# 793 +" > Makefile 794 + 795 +# create zlib.pc with the configure results 796 +sed < zlib.pc.in " 797 +/^CC *=/s#=.*#=$CC# 798 +/^CFLAGS *=/s#=.*#=$CFLAGS# 799 +/^CPP *=/s#=.*#=$CPP# 800 +/^LDSHARED *=/s#=.*#=$LDSHARED# 801 +/^STATICLIB *=/s#=.*#=$STATICLIB# 802 +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# 803 +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# 804 +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# 805 +/^AR *=/s#=.*#=$AR# 806 +/^ARFLAGS *=/s#=.*#=$ARFLAGS# 807 +/^RANLIB *=/s#=.*#=$RANLIB# 808 +/^EXE *=/s#=.*#=$EXE# 809 +/^prefix *=/s#=.*#=$prefix# 810 +/^exec_prefix *=/s#=.*#=$exec_prefix# 811 +/^libdir *=/s#=.*#=$libdir# 812 +/^sharedlibdir *=/s#=.*#=$sharedlibdir# 813 +/^includedir *=/s#=.*#=$includedir# 814 +/^mandir *=/s#=.*#=$mandir# 815 +/^LDFLAGS *=/s#=.*#=$LDFLAGS# 816 +" | sed -e " 817 +s/\@VERSION\@/$VER/g; 818 +" > zlib.pc
Added compat/zlib/contrib/README.contrib.
1 +All files under this contrib directory are UNSUPPORTED. There were 2 +provided by users of zlib and were not tested by the authors of zlib. 3 +Use at your own risk. Please contact the authors of the contributions 4 +for help about these, not the zlib authors. Thanks. 5 + 6 + 7 +ada/ by Dmitriy Anisimkov <anisimkov@yahoo.com> 8 + Support for Ada 9 + See http://zlib-ada.sourceforge.net/ 10 + 11 +amd64/ by Mikhail Teterin <mi@ALDAN.algebra.com> 12 + asm code for AMD64 13 + See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393 14 + 15 +asm686/ by Brian Raiter <breadbox@muppetlabs.com> 16 + asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax 17 + See http://www.muppetlabs.com/~breadbox/software/assembly.html 18 + 19 +blast/ by Mark Adler <madler@alumni.caltech.edu> 20 + Decompressor for output of PKWare Data Compression Library (DCL) 21 + 22 +delphi/ by Cosmin Truta <cosmint@cs.ubbcluj.ro> 23 + Support for Delphi and C++ Builder 24 + 25 +dotzlib/ by Henrik Ravn <henrik@ravn.com> 26 + Support for Microsoft .Net and Visual C++ .Net 27 + 28 +gcc_gvmat64/by Gilles Vollant <info@winimage.com> 29 + GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64 30 + assembler to replace longest_match() and inflate_fast() 31 + 32 +infback9/ by Mark Adler <madler@alumni.caltech.edu> 33 + Unsupported diffs to infback to decode the deflate64 format 34 + 35 +inflate86/ by Chris Anderson <christop@charm.net> 36 + Tuned x86 gcc asm code to replace inflate_fast() 37 + 38 +iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> 39 + A C++ I/O streams interface to the zlib gz* functions 40 + 41 +iostream2/ by Tyge L�vset <Tyge.Lovset@cmr.no> 42 + Another C++ I/O streams interface 43 + 44 +iostream3/ by Ludwig Schwardt <schwardt@sun.ac.za> 45 + and Kevin Ruland <kevin@rodin.wustl.edu> 46 + Yet another C++ I/O streams interface 47 + 48 +masmx64/ by Gilles Vollant <info@winimage.com> 49 + x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to 50 + replace longest_match() and inflate_fast(), also masm x86 51 + 64-bits translation of Chris Anderson inflate_fast() 52 + 53 +masmx86/ by Gilles Vollant <info@winimage.com> 54 + x86 asm code to replace longest_match() and inflate_fast(), 55 + for Visual C++ and MASM (32 bits). 56 + Based on Brian Raiter (asm686) and Chris Anderson (inflate86) 57 + 58 +minizip/ by Gilles Vollant <info@winimage.com> 59 + Mini zip and unzip based on zlib 60 + Includes Zip64 support by Mathias Svensson <mathias@result42.com> 61 + See http://www.winimage.com/zLibDll/unzip.html 62 + 63 +pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al. 64 + Support for Pascal 65 + 66 +puff/ by Mark Adler <madler@alumni.caltech.edu> 67 + Small, low memory usage inflate. Also serves to provide an 68 + unambiguous description of the deflate format. 69 + 70 +testzlib/ by Gilles Vollant <info@winimage.com> 71 + Example of the use of zlib 72 + 73 +untgz/ by Pedro A. Aranda Gutierrez <paag@tid.es> 74 + A very simple tar.gz file extractor using zlib 75 + 76 +vstudio/ by Gilles Vollant <info@winimage.com> 77 + Building a minizip-enhanced zlib with Microsoft Visual Studio
Added compat/zlib/contrib/ada/buffer_demo.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 +-- 9 +-- $Id: buffer_demo.adb,v 1.3 2004/09/06 06:55:35 vagul Exp $ 10 + 11 +-- This demo program provided by Dr Steve Sangwine <sjs@essex.ac.uk> 12 +-- 13 +-- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer 14 +-- of exactly the correct size is used for decompressed data, and the last 15 +-- few bytes passed in to Zlib are checksum bytes. 16 + 17 +-- This program compresses a string of text, and then decompresses the 18 +-- compressed text into a buffer of the same size as the original text. 19 + 20 +with Ada.Streams; use Ada.Streams; 21 +with Ada.Text_IO; 22 + 23 +with ZLib; use ZLib; 24 + 25 +procedure Buffer_Demo is 26 + EOL : Character renames ASCII.LF; 27 + Text : constant String 28 + := "Four score and seven years ago our fathers brought forth," & EOL & 29 + "upon this continent, a new nation, conceived in liberty," & EOL & 30 + "and dedicated to the proposition that `all men are created equal'."; 31 + 32 + Source : Stream_Element_Array (1 .. Text'Length); 33 + for Source'Address use Text'Address; 34 + 35 +begin 36 + Ada.Text_IO.Put (Text); 37 + Ada.Text_IO.New_Line; 38 + Ada.Text_IO.Put_Line 39 + ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes"); 40 + 41 + declare 42 + Compressed_Data : Stream_Element_Array (1 .. Text'Length); 43 + L : Stream_Element_Offset; 44 + begin 45 + Compress : declare 46 + Compressor : Filter_Type; 47 + I : Stream_Element_Offset; 48 + begin 49 + Deflate_Init (Compressor); 50 + 51 + -- Compress the whole of T at once. 52 + 53 + Translate (Compressor, Source, I, Compressed_Data, L, Finish); 54 + pragma Assert (I = Source'Last); 55 + 56 + Close (Compressor); 57 + 58 + Ada.Text_IO.Put_Line 59 + ("Compressed size : " 60 + & Stream_Element_Offset'Image (L) & " bytes"); 61 + end Compress; 62 + 63 + -- Now we decompress the data, passing short blocks of data to Zlib 64 + -- (because this demonstrates the problem - the last block passed will 65 + -- contain checksum information and there will be no output, only a 66 + -- check inside Zlib that the checksum is correct). 67 + 68 + Decompress : declare 69 + Decompressor : Filter_Type; 70 + 71 + Uncompressed_Data : Stream_Element_Array (1 .. Text'Length); 72 + 73 + Block_Size : constant := 4; 74 + -- This makes sure that the last block contains 75 + -- only Adler checksum data. 76 + 77 + P : Stream_Element_Offset := Compressed_Data'First - 1; 78 + O : Stream_Element_Offset; 79 + begin 80 + Inflate_Init (Decompressor); 81 + 82 + loop 83 + Translate 84 + (Decompressor, 85 + Compressed_Data 86 + (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)), 87 + P, 88 + Uncompressed_Data 89 + (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last), 90 + O, 91 + No_Flush); 92 + 93 + Ada.Text_IO.Put_Line 94 + ("Total in : " & Count'Image (Total_In (Decompressor)) & 95 + ", out : " & Count'Image (Total_Out (Decompressor))); 96 + 97 + exit when P = L; 98 + end loop; 99 + 100 + Ada.Text_IO.New_Line; 101 + Ada.Text_IO.Put_Line 102 + ("Decompressed text matches original text : " 103 + & Boolean'Image (Uncompressed_Data = Source)); 104 + end Decompress; 105 + end; 106 +end Buffer_Demo;
Added compat/zlib/contrib/ada/mtest.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 +-- Continuous test for ZLib multithreading. If the test would fail 9 +-- we should provide thread safe allocation routines for the Z_Stream. 10 +-- 11 +-- $Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp $ 12 + 13 +with ZLib; 14 +with Ada.Streams; 15 +with Ada.Numerics.Discrete_Random; 16 +with Ada.Text_IO; 17 +with Ada.Exceptions; 18 +with Ada.Task_Identification; 19 + 20 +procedure MTest is 21 + use Ada.Streams; 22 + use ZLib; 23 + 24 + Stop : Boolean := False; 25 + 26 + pragma Atomic (Stop); 27 + 28 + subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; 29 + 30 + package Random_Elements is 31 + new Ada.Numerics.Discrete_Random (Visible_Symbols); 32 + 33 + task type Test_Task; 34 + 35 + task body Test_Task is 36 + Buffer : Stream_Element_Array (1 .. 100_000); 37 + Gen : Random_Elements.Generator; 38 + 39 + Buffer_First : Stream_Element_Offset; 40 + Compare_First : Stream_Element_Offset; 41 + 42 + Deflate : Filter_Type; 43 + Inflate : Filter_Type; 44 + 45 + procedure Further (Item : in Stream_Element_Array); 46 + 47 + procedure Read_Buffer 48 + (Item : out Ada.Streams.Stream_Element_Array; 49 + Last : out Ada.Streams.Stream_Element_Offset); 50 + 51 + ------------- 52 + -- Further -- 53 + ------------- 54 + 55 + procedure Further (Item : in Stream_Element_Array) is 56 + 57 + procedure Compare (Item : in Stream_Element_Array); 58 + 59 + ------------- 60 + -- Compare -- 61 + ------------- 62 + 63 + procedure Compare (Item : in Stream_Element_Array) is 64 + Next_First : Stream_Element_Offset := Compare_First + Item'Length; 65 + begin 66 + if Buffer (Compare_First .. Next_First - 1) /= Item then 67 + raise Program_Error; 68 + end if; 69 + 70 + Compare_First := Next_First; 71 + end Compare; 72 + 73 + procedure Compare_Write is new ZLib.Write (Write => Compare); 74 + begin 75 + Compare_Write (Inflate, Item, No_Flush); 76 + end Further; 77 + 78 + ----------------- 79 + -- Read_Buffer -- 80 + ----------------- 81 + 82 + procedure Read_Buffer 83 + (Item : out Ada.Streams.Stream_Element_Array; 84 + Last : out Ada.Streams.Stream_Element_Offset) 85 + is 86 + Buff_Diff : Stream_Element_Offset := Buffer'Last - Buffer_First; 87 + Next_First : Stream_Element_Offset; 88 + begin 89 + if Item'Length <= Buff_Diff then 90 + Last := Item'Last; 91 + 92 + Next_First := Buffer_First + Item'Length; 93 + 94 + Item := Buffer (Buffer_First .. Next_First - 1); 95 + 96 + Buffer_First := Next_First; 97 + else 98 + Last := Item'First + Buff_Diff; 99 + Item (Item'First .. Last) := Buffer (Buffer_First .. Buffer'Last); 100 + Buffer_First := Buffer'Last + 1; 101 + end if; 102 + end Read_Buffer; 103 + 104 + procedure Translate is new Generic_Translate 105 + (Data_In => Read_Buffer, 106 + Data_Out => Further); 107 + 108 + begin 109 + Random_Elements.Reset (Gen); 110 + 111 + Buffer := (others => 20); 112 + 113 + Main : loop 114 + for J in Buffer'Range loop 115 + Buffer (J) := Random_Elements.Random (Gen); 116 + 117 + Deflate_Init (Deflate); 118 + Inflate_Init (Inflate); 119 + 120 + Buffer_First := Buffer'First; 121 + Compare_First := Buffer'First; 122 + 123 + Translate (Deflate); 124 + 125 + if Compare_First /= Buffer'Last + 1 then 126 + raise Program_Error; 127 + end if; 128 + 129 + Ada.Text_IO.Put_Line 130 + (Ada.Task_Identification.Image 131 + (Ada.Task_Identification.Current_Task) 132 + & Stream_Element_Offset'Image (J) 133 + & ZLib.Count'Image (Total_Out (Deflate))); 134 + 135 + Close (Deflate); 136 + Close (Inflate); 137 + 138 + exit Main when Stop; 139 + end loop; 140 + end loop Main; 141 + exception 142 + when E : others => 143 + Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); 144 + Stop := True; 145 + end Test_Task; 146 + 147 + Test : array (1 .. 4) of Test_Task; 148 + 149 + pragma Unreferenced (Test); 150 + 151 + Dummy : Character; 152 + 153 +begin 154 + Ada.Text_IO.Get_Immediate (Dummy); 155 + Stop := True; 156 +end MTest;
Added compat/zlib/contrib/ada/read.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp $ 10 + 11 +-- Test/demo program for the generic read interface. 12 + 13 +with Ada.Numerics.Discrete_Random; 14 +with Ada.Streams; 15 +with Ada.Text_IO; 16 + 17 +with ZLib; 18 + 19 +procedure Read is 20 + 21 + use Ada.Streams; 22 + 23 + ------------------------------------ 24 + -- Test configuration parameters -- 25 + ------------------------------------ 26 + 27 + File_Size : Stream_Element_Offset := 100_000; 28 + 29 + Continuous : constant Boolean := False; 30 + -- If this constant is True, the test would be repeated again and again, 31 + -- with increment File_Size for every iteration. 32 + 33 + Header : constant ZLib.Header_Type := ZLib.Default; 34 + -- Do not use Header other than Default in ZLib versions 1.1.4 and older. 35 + 36 + Init_Random : constant := 8; 37 + -- We are using the same random sequence, in case of we catch bug, 38 + -- so we would be able to reproduce it. 39 + 40 + -- End -- 41 + 42 + Pack_Size : Stream_Element_Offset; 43 + Offset : Stream_Element_Offset; 44 + 45 + Filter : ZLib.Filter_Type; 46 + 47 + subtype Visible_Symbols 48 + is Stream_Element range 16#20# .. 16#7E#; 49 + 50 + package Random_Elements is new 51 + Ada.Numerics.Discrete_Random (Visible_Symbols); 52 + 53 + Gen : Random_Elements.Generator; 54 + Period : constant Stream_Element_Offset := 200; 55 + -- Period constant variable for random generator not to be very random. 56 + -- Bigger period, harder random. 57 + 58 + Read_Buffer : Stream_Element_Array (1 .. 2048); 59 + Read_First : Stream_Element_Offset; 60 + Read_Last : Stream_Element_Offset; 61 + 62 + procedure Reset; 63 + 64 + procedure Read 65 + (Item : out Stream_Element_Array; 66 + Last : out Stream_Element_Offset); 67 + -- this procedure is for generic instantiation of 68 + -- ZLib.Read 69 + -- reading data from the File_In. 70 + 71 + procedure Read is new ZLib.Read 72 + (Read, 73 + Read_Buffer, 74 + Rest_First => Read_First, 75 + Rest_Last => Read_Last); 76 + 77 + ---------- 78 + -- Read -- 79 + ---------- 80 + 81 + procedure Read 82 + (Item : out Stream_Element_Array; 83 + Last : out Stream_Element_Offset) is 84 + begin 85 + Last := Stream_Element_Offset'Min 86 + (Item'Last, 87 + Item'First + File_Size - Offset); 88 + 89 + for J in Item'First .. Last loop 90 + if J < Item'First + Period then 91 + Item (J) := Random_Elements.Random (Gen); 92 + else 93 + Item (J) := Item (J - Period); 94 + end if; 95 + 96 + Offset := Offset + 1; 97 + end loop; 98 + end Read; 99 + 100 + ----------- 101 + -- Reset -- 102 + ----------- 103 + 104 + procedure Reset is 105 + begin 106 + Random_Elements.Reset (Gen, Init_Random); 107 + Pack_Size := 0; 108 + Offset := 1; 109 + Read_First := Read_Buffer'Last + 1; 110 + Read_Last := Read_Buffer'Last; 111 + end Reset; 112 + 113 +begin 114 + Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); 115 + 116 + loop 117 + for Level in ZLib.Compression_Level'Range loop 118 + 119 + Ada.Text_IO.Put ("Level =" 120 + & ZLib.Compression_Level'Image (Level)); 121 + 122 + -- Deflate using generic instantiation. 123 + 124 + ZLib.Deflate_Init 125 + (Filter, 126 + Level, 127 + Header => Header); 128 + 129 + Reset; 130 + 131 + Ada.Text_IO.Put 132 + (Stream_Element_Offset'Image (File_Size) & " ->"); 133 + 134 + loop 135 + declare 136 + Buffer : Stream_Element_Array (1 .. 1024); 137 + Last : Stream_Element_Offset; 138 + begin 139 + Read (Filter, Buffer, Last); 140 + 141 + Pack_Size := Pack_Size + Last - Buffer'First + 1; 142 + 143 + exit when Last < Buffer'Last; 144 + end; 145 + end loop; 146 + 147 + Ada.Text_IO.Put_Line (Stream_Element_Offset'Image (Pack_Size)); 148 + 149 + ZLib.Close (Filter); 150 + end loop; 151 + 152 + exit when not Continuous; 153 + 154 + File_Size := File_Size + 1; 155 + end loop; 156 +end Read;
Added compat/zlib/contrib/ada/readme.txt.
1 + ZLib for Ada thick binding (ZLib.Ada) 2 + Release 1.3 3 + 4 +ZLib.Ada is a thick binding interface to the popular ZLib data 5 +compression library, available at http://www.gzip.org/zlib/. 6 +It provides Ada-style access to the ZLib C library. 7 + 8 + 9 + Here are the main changes since ZLib.Ada 1.2: 10 + 11 +- Attension: ZLib.Read generic routine have a initialization requirement 12 + for Read_Last parameter now. It is a bit incompartible with previous version, 13 + but extends functionality, we could use new parameters Allow_Read_Some and 14 + Flush now. 15 + 16 +- Added Is_Open routines to ZLib and ZLib.Streams packages. 17 + 18 +- Add pragma Assert to check Stream_Element is 8 bit. 19 + 20 +- Fix extraction to buffer with exact known decompressed size. Error reported by 21 + Steve Sangwine. 22 + 23 +- Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits 24 + computers. Patch provided by Pascal Obry. 25 + 26 +- Add Status_Error exception definition. 27 + 28 +- Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit. 29 + 30 + 31 + How to build ZLib.Ada under GNAT 32 + 33 +You should have the ZLib library already build on your computer, before 34 +building ZLib.Ada. Make the directory of ZLib.Ada sources current and 35 +issue the command: 36 + 37 + gnatmake test -largs -L<directory where libz.a is> -lz 38 + 39 +Or use the GNAT project file build for GNAT 3.15 or later: 40 + 41 + gnatmake -Pzlib.gpr -L<directory where libz.a is> 42 + 43 + 44 + How to build ZLib.Ada under Aonix ObjectAda for Win32 7.2.2 45 + 46 +1. Make a project with all *.ads and *.adb files from the distribution. 47 +2. Build the libz.a library from the ZLib C sources. 48 +3. Rename libz.a to z.lib. 49 +4. Add the library z.lib to the project. 50 +5. Add the libc.lib library from the ObjectAda distribution to the project. 51 +6. Build the executable using test.adb as a main procedure. 52 + 53 + 54 + How to use ZLib.Ada 55 + 56 +The source files test.adb and read.adb are small demo programs that show 57 +the main functionality of ZLib.Ada. 58 + 59 +The routines from the package specifications are commented. 60 + 61 + 62 +Homepage: http://zlib-ada.sourceforge.net/ 63 +Author: Dmitriy Anisimkov <anisimkov@yahoo.com> 64 + 65 +Contributors: Pascal Obry <pascal@obry.org>, Steve Sangwine <sjs@essex.ac.uk>
Added compat/zlib/contrib/ada/test.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: test.adb,v 1.17 2003/08/12 12:13:30 vagul Exp $ 10 + 11 +-- The program has a few aims. 12 +-- 1. Test ZLib.Ada95 thick binding functionality. 13 +-- 2. Show the example of use main functionality of the ZLib.Ada95 binding. 14 +-- 3. Build this program automatically compile all ZLib.Ada95 packages under 15 +-- GNAT Ada95 compiler. 16 + 17 +with ZLib.Streams; 18 +with Ada.Streams.Stream_IO; 19 +with Ada.Numerics.Discrete_Random; 20 + 21 +with Ada.Text_IO; 22 + 23 +with Ada.Calendar; 24 + 25 +procedure Test is 26 + 27 + use Ada.Streams; 28 + use Stream_IO; 29 + 30 + ------------------------------------ 31 + -- Test configuration parameters -- 32 + ------------------------------------ 33 + 34 + File_Size : Count := 100_000; 35 + Continuous : constant Boolean := False; 36 + 37 + Header : constant ZLib.Header_Type := ZLib.Default; 38 + -- ZLib.None; 39 + -- ZLib.Auto; 40 + -- ZLib.GZip; 41 + -- Do not use Header other then Default in ZLib versions 1.1.4 42 + -- and older. 43 + 44 + Strategy : constant ZLib.Strategy_Type := ZLib.Default_Strategy; 45 + Init_Random : constant := 10; 46 + 47 + -- End -- 48 + 49 + In_File_Name : constant String := "testzlib.in"; 50 + -- Name of the input file 51 + 52 + Z_File_Name : constant String := "testzlib.zlb"; 53 + -- Name of the compressed file. 54 + 55 + Out_File_Name : constant String := "testzlib.out"; 56 + -- Name of the decompressed file. 57 + 58 + File_In : File_Type; 59 + File_Out : File_Type; 60 + File_Back : File_Type; 61 + File_Z : ZLib.Streams.Stream_Type; 62 + 63 + Filter : ZLib.Filter_Type; 64 + 65 + Time_Stamp : Ada.Calendar.Time; 66 + 67 + procedure Generate_File; 68 + -- Generate file of spetsified size with some random data. 69 + -- The random data is repeatable, for the good compression. 70 + 71 + procedure Compare_Streams 72 + (Left, Right : in out Root_Stream_Type'Class); 73 + -- The procedure compearing data in 2 streams. 74 + -- It is for compare data before and after compression/decompression. 75 + 76 + procedure Compare_Files (Left, Right : String); 77 + -- Compare files. Based on the Compare_Streams. 78 + 79 + procedure Copy_Streams 80 + (Source, Target : in out Root_Stream_Type'Class; 81 + Buffer_Size : in Stream_Element_Offset := 1024); 82 + -- Copying data from one stream to another. It is for test stream 83 + -- interface of the library. 84 + 85 + procedure Data_In 86 + (Item : out Stream_Element_Array; 87 + Last : out Stream_Element_Offset); 88 + -- this procedure is for generic instantiation of 89 + -- ZLib.Generic_Translate. 90 + -- reading data from the File_In. 91 + 92 + procedure Data_Out (Item : in Stream_Element_Array); 93 + -- this procedure is for generic instantiation of 94 + -- ZLib.Generic_Translate. 95 + -- writing data to the File_Out. 96 + 97 + procedure Stamp; 98 + -- Store the timestamp to the local variable. 99 + 100 + procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count); 101 + -- Print the time statistic with the message. 102 + 103 + procedure Translate is new ZLib.Generic_Translate 104 + (Data_In => Data_In, 105 + Data_Out => Data_Out); 106 + -- This procedure is moving data from File_In to File_Out 107 + -- with compression or decompression, depend on initialization of 108 + -- Filter parameter. 109 + 110 + ------------------- 111 + -- Compare_Files -- 112 + ------------------- 113 + 114 + procedure Compare_Files (Left, Right : String) is 115 + Left_File, Right_File : File_Type; 116 + begin 117 + Open (Left_File, In_File, Left); 118 + Open (Right_File, In_File, Right); 119 + Compare_Streams (Stream (Left_File).all, Stream (Right_File).all); 120 + Close (Left_File); 121 + Close (Right_File); 122 + end Compare_Files; 123 + 124 + --------------------- 125 + -- Compare_Streams -- 126 + --------------------- 127 + 128 + procedure Compare_Streams 129 + (Left, Right : in out Ada.Streams.Root_Stream_Type'Class) 130 + is 131 + Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#); 132 + Left_Last, Right_Last : Stream_Element_Offset; 133 + begin 134 + loop 135 + Read (Left, Left_Buffer, Left_Last); 136 + Read (Right, Right_Buffer, Right_Last); 137 + 138 + if Left_Last /= Right_Last then 139 + Ada.Text_IO.Put_Line ("Compare error :" 140 + & Stream_Element_Offset'Image (Left_Last) 141 + & " /= " 142 + & Stream_Element_Offset'Image (Right_Last)); 143 + 144 + raise Constraint_Error; 145 + 146 + elsif Left_Buffer (0 .. Left_Last) 147 + /= Right_Buffer (0 .. Right_Last) 148 + then 149 + Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal."); 150 + raise Constraint_Error; 151 + 152 + end if; 153 + 154 + exit when Left_Last < Left_Buffer'Last; 155 + end loop; 156 + end Compare_Streams; 157 + 158 + ------------------ 159 + -- Copy_Streams -- 160 + ------------------ 161 + 162 + procedure Copy_Streams 163 + (Source, Target : in out Ada.Streams.Root_Stream_Type'Class; 164 + Buffer_Size : in Stream_Element_Offset := 1024) 165 + is 166 + Buffer : Stream_Element_Array (1 .. Buffer_Size); 167 + Last : Stream_Element_Offset; 168 + begin 169 + loop 170 + Read (Source, Buffer, Last); 171 + Write (Target, Buffer (1 .. Last)); 172 + 173 + exit when Last < Buffer'Last; 174 + end loop; 175 + end Copy_Streams; 176 + 177 + ------------- 178 + -- Data_In -- 179 + ------------- 180 + 181 + procedure Data_In 182 + (Item : out Stream_Element_Array; 183 + Last : out Stream_Element_Offset) is 184 + begin 185 + Read (File_In, Item, Last); 186 + end Data_In; 187 + 188 + -------------- 189 + -- Data_Out -- 190 + -------------- 191 + 192 + procedure Data_Out (Item : in Stream_Element_Array) is 193 + begin 194 + Write (File_Out, Item); 195 + end Data_Out; 196 + 197 + ------------------- 198 + -- Generate_File -- 199 + ------------------- 200 + 201 + procedure Generate_File is 202 + subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; 203 + 204 + package Random_Elements is 205 + new Ada.Numerics.Discrete_Random (Visible_Symbols); 206 + 207 + Gen : Random_Elements.Generator; 208 + Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10; 209 + 210 + Buffer_Count : constant Count := File_Size / Buffer'Length; 211 + -- Number of same buffers in the packet. 212 + 213 + Density : constant Count := 30; -- from 0 to Buffer'Length - 2; 214 + 215 + procedure Fill_Buffer (J, D : in Count); 216 + -- Change the part of the buffer. 217 + 218 + ----------------- 219 + -- Fill_Buffer -- 220 + ----------------- 221 + 222 + procedure Fill_Buffer (J, D : in Count) is 223 + begin 224 + for K in 0 .. D loop 225 + Buffer 226 + (Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1)) 227 + := Random_Elements.Random (Gen); 228 + 229 + end loop; 230 + end Fill_Buffer; 231 + 232 + begin 233 + Random_Elements.Reset (Gen, Init_Random); 234 + 235 + Create (File_In, Out_File, In_File_Name); 236 + 237 + Fill_Buffer (1, Buffer'Length - 2); 238 + 239 + for J in 1 .. Buffer_Count loop 240 + Write (File_In, Buffer); 241 + 242 + Fill_Buffer (J, Density); 243 + end loop; 244 + 245 + -- fill remain size. 246 + 247 + Write 248 + (File_In, 249 + Buffer 250 + (1 .. Stream_Element_Offset 251 + (File_Size - Buffer'Length * Buffer_Count))); 252 + 253 + Flush (File_In); 254 + Close (File_In); 255 + end Generate_File; 256 + 257 + --------------------- 258 + -- Print_Statistic -- 259 + --------------------- 260 + 261 + procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is 262 + use Ada.Calendar; 263 + use Ada.Text_IO; 264 + 265 + package Count_IO is new Integer_IO (ZLib.Count); 266 + 267 + Curr_Dur : Duration := Clock - Time_Stamp; 268 + begin 269 + Put (Msg); 270 + 271 + Set_Col (20); 272 + Ada.Text_IO.Put ("size ="); 273 + 274 + Count_IO.Put 275 + (Data_Size, 276 + Width => Stream_IO.Count'Image (File_Size)'Length); 277 + 278 + Put_Line (" duration =" & Duration'Image (Curr_Dur)); 279 + end Print_Statistic; 280 + 281 + ----------- 282 + -- Stamp -- 283 + ----------- 284 + 285 + procedure Stamp is 286 + begin 287 + Time_Stamp := Ada.Calendar.Clock; 288 + end Stamp; 289 + 290 +begin 291 + Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); 292 + 293 + loop 294 + Generate_File; 295 + 296 + for Level in ZLib.Compression_Level'Range loop 297 + 298 + Ada.Text_IO.Put_Line ("Level =" 299 + & ZLib.Compression_Level'Image (Level)); 300 + 301 + -- Test generic interface. 302 + Open (File_In, In_File, In_File_Name); 303 + Create (File_Out, Out_File, Z_File_Name); 304 + 305 + Stamp; 306 + 307 + -- Deflate using generic instantiation. 308 + 309 + ZLib.Deflate_Init 310 + (Filter => Filter, 311 + Level => Level, 312 + Strategy => Strategy, 313 + Header => Header); 314 + 315 + Translate (Filter); 316 + Print_Statistic ("Generic compress", ZLib.Total_Out (Filter)); 317 + ZLib.Close (Filter); 318 + 319 + Close (File_In); 320 + Close (File_Out); 321 + 322 + Open (File_In, In_File, Z_File_Name); 323 + Create (File_Out, Out_File, Out_File_Name); 324 + 325 + Stamp; 326 + 327 + -- Inflate using generic instantiation. 328 + 329 + ZLib.Inflate_Init (Filter, Header => Header); 330 + 331 + Translate (Filter); 332 + Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter)); 333 + 334 + ZLib.Close (Filter); 335 + 336 + Close (File_In); 337 + Close (File_Out); 338 + 339 + Compare_Files (In_File_Name, Out_File_Name); 340 + 341 + -- Test stream interface. 342 + 343 + -- Compress to the back stream. 344 + 345 + Open (File_In, In_File, In_File_Name); 346 + Create (File_Back, Out_File, Z_File_Name); 347 + 348 + Stamp; 349 + 350 + ZLib.Streams.Create 351 + (Stream => File_Z, 352 + Mode => ZLib.Streams.Out_Stream, 353 + Back => ZLib.Streams.Stream_Access 354 + (Stream (File_Back)), 355 + Back_Compressed => True, 356 + Level => Level, 357 + Strategy => Strategy, 358 + Header => Header); 359 + 360 + Copy_Streams 361 + (Source => Stream (File_In).all, 362 + Target => File_Z); 363 + 364 + -- Flushing internal buffers to the back stream. 365 + 366 + ZLib.Streams.Flush (File_Z, ZLib.Finish); 367 + 368 + Print_Statistic ("Write compress", 369 + ZLib.Streams.Write_Total_Out (File_Z)); 370 + 371 + ZLib.Streams.Close (File_Z); 372 + 373 + Close (File_In); 374 + Close (File_Back); 375 + 376 + -- Compare reading from original file and from 377 + -- decompression stream. 378 + 379 + Open (File_In, In_File, In_File_Name); 380 + Open (File_Back, In_File, Z_File_Name); 381 + 382 + ZLib.Streams.Create 383 + (Stream => File_Z, 384 + Mode => ZLib.Streams.In_Stream, 385 + Back => ZLib.Streams.Stream_Access 386 + (Stream (File_Back)), 387 + Back_Compressed => True, 388 + Header => Header); 389 + 390 + Stamp; 391 + Compare_Streams (Stream (File_In).all, File_Z); 392 + 393 + Print_Statistic ("Read decompress", 394 + ZLib.Streams.Read_Total_Out (File_Z)); 395 + 396 + ZLib.Streams.Close (File_Z); 397 + Close (File_In); 398 + Close (File_Back); 399 + 400 + -- Compress by reading from compression stream. 401 + 402 + Open (File_Back, In_File, In_File_Name); 403 + Create (File_Out, Out_File, Z_File_Name); 404 + 405 + ZLib.Streams.Create 406 + (Stream => File_Z, 407 + Mode => ZLib.Streams.In_Stream, 408 + Back => ZLib.Streams.Stream_Access 409 + (Stream (File_Back)), 410 + Back_Compressed => False, 411 + Level => Level, 412 + Strategy => Strategy, 413 + Header => Header); 414 + 415 + Stamp; 416 + Copy_Streams 417 + (Source => File_Z, 418 + Target => Stream (File_Out).all); 419 + 420 + Print_Statistic ("Read compress", 421 + ZLib.Streams.Read_Total_Out (File_Z)); 422 + 423 + ZLib.Streams.Close (File_Z); 424 + 425 + Close (File_Out); 426 + Close (File_Back); 427 + 428 + -- Decompress to decompression stream. 429 + 430 + Open (File_In, In_File, Z_File_Name); 431 + Create (File_Back, Out_File, Out_File_Name); 432 + 433 + ZLib.Streams.Create 434 + (Stream => File_Z, 435 + Mode => ZLib.Streams.Out_Stream, 436 + Back => ZLib.Streams.Stream_Access 437 + (Stream (File_Back)), 438 + Back_Compressed => False, 439 + Header => Header); 440 + 441 + Stamp; 442 + 443 + Copy_Streams 444 + (Source => Stream (File_In).all, 445 + Target => File_Z); 446 + 447 + Print_Statistic ("Write decompress", 448 + ZLib.Streams.Write_Total_Out (File_Z)); 449 + 450 + ZLib.Streams.Close (File_Z); 451 + Close (File_In); 452 + Close (File_Back); 453 + 454 + Compare_Files (In_File_Name, Out_File_Name); 455 + end loop; 456 + 457 + Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok."); 458 + 459 + exit when not Continuous; 460 + 461 + File_Size := File_Size + 1; 462 + end loop; 463 +end Test;
Added compat/zlib/contrib/ada/zlib-streams.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: zlib-streams.adb,v 1.10 2004/05/31 10:53:40 vagul Exp $ 10 + 11 +with Ada.Unchecked_Deallocation; 12 + 13 +package body ZLib.Streams is 14 + 15 + ----------- 16 + -- Close -- 17 + ----------- 18 + 19 + procedure Close (Stream : in out Stream_Type) is 20 + procedure Free is new Ada.Unchecked_Deallocation 21 + (Stream_Element_Array, Buffer_Access); 22 + begin 23 + if Stream.Mode = Out_Stream or Stream.Mode = Duplex then 24 + -- We should flush the data written by the writer. 25 + 26 + Flush (Stream, Finish); 27 + 28 + Close (Stream.Writer); 29 + end if; 30 + 31 + if Stream.Mode = In_Stream or Stream.Mode = Duplex then 32 + Close (Stream.Reader); 33 + Free (Stream.Buffer); 34 + end if; 35 + end Close; 36 + 37 + ------------ 38 + -- Create -- 39 + ------------ 40 + 41 + procedure Create 42 + (Stream : out Stream_Type; 43 + Mode : in Stream_Mode; 44 + Back : in Stream_Access; 45 + Back_Compressed : in Boolean; 46 + Level : in Compression_Level := Default_Compression; 47 + Strategy : in Strategy_Type := Default_Strategy; 48 + Header : in Header_Type := Default; 49 + Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset 50 + := Default_Buffer_Size; 51 + Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset 52 + := Default_Buffer_Size) 53 + is 54 + 55 + subtype Buffer_Subtype is Stream_Element_Array (1 .. Read_Buffer_Size); 56 + 57 + procedure Init_Filter 58 + (Filter : in out Filter_Type; 59 + Compress : in Boolean); 60 + 61 + ----------------- 62 + -- Init_Filter -- 63 + ----------------- 64 + 65 + procedure Init_Filter 66 + (Filter : in out Filter_Type; 67 + Compress : in Boolean) is 68 + begin 69 + if Compress then 70 + Deflate_Init 71 + (Filter, Level, Strategy, Header => Header); 72 + else 73 + Inflate_Init (Filter, Header => Header); 74 + end if; 75 + end Init_Filter; 76 + 77 + begin 78 + Stream.Back := Back; 79 + Stream.Mode := Mode; 80 + 81 + if Mode = Out_Stream or Mode = Duplex then 82 + Init_Filter (Stream.Writer, Back_Compressed); 83 + Stream.Buffer_Size := Write_Buffer_Size; 84 + else 85 + Stream.Buffer_Size := 0; 86 + end if; 87 + 88 + if Mode = In_Stream or Mode = Duplex then 89 + Init_Filter (Stream.Reader, not Back_Compressed); 90 + 91 + Stream.Buffer := new Buffer_Subtype; 92 + Stream.Rest_First := Stream.Buffer'Last + 1; 93 + Stream.Rest_Last := Stream.Buffer'Last; 94 + end if; 95 + end Create; 96 + 97 + ----------- 98 + -- Flush -- 99 + ----------- 100 + 101 + procedure Flush 102 + (Stream : in out Stream_Type; 103 + Mode : in Flush_Mode := Sync_Flush) 104 + is 105 + Buffer : Stream_Element_Array (1 .. Stream.Buffer_Size); 106 + Last : Stream_Element_Offset; 107 + begin 108 + loop 109 + Flush (Stream.Writer, Buffer, Last, Mode); 110 + 111 + Ada.Streams.Write (Stream.Back.all, Buffer (1 .. Last)); 112 + 113 + exit when Last < Buffer'Last; 114 + end loop; 115 + end Flush; 116 + 117 + ------------- 118 + -- Is_Open -- 119 + ------------- 120 + 121 + function Is_Open (Stream : Stream_Type) return Boolean is 122 + begin 123 + return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer); 124 + end Is_Open; 125 + 126 + ---------- 127 + -- Read -- 128 + ---------- 129 + 130 + procedure Read 131 + (Stream : in out Stream_Type; 132 + Item : out Stream_Element_Array; 133 + Last : out Stream_Element_Offset) 134 + is 135 + 136 + procedure Read 137 + (Item : out Stream_Element_Array; 138 + Last : out Stream_Element_Offset); 139 + 140 + ---------- 141 + -- Read -- 142 + ---------- 143 + 144 + procedure Read 145 + (Item : out Stream_Element_Array; 146 + Last : out Stream_Element_Offset) is 147 + begin 148 + Ada.Streams.Read (Stream.Back.all, Item, Last); 149 + end Read; 150 + 151 + procedure Read is new ZLib.Read 152 + (Read => Read, 153 + Buffer => Stream.Buffer.all, 154 + Rest_First => Stream.Rest_First, 155 + Rest_Last => Stream.Rest_Last); 156 + 157 + begin 158 + Read (Stream.Reader, Item, Last); 159 + end Read; 160 + 161 + ------------------- 162 + -- Read_Total_In -- 163 + ------------------- 164 + 165 + function Read_Total_In (Stream : in Stream_Type) return Count is 166 + begin 167 + return Total_In (Stream.Reader); 168 + end Read_Total_In; 169 + 170 + -------------------- 171 + -- Read_Total_Out -- 172 + -------------------- 173 + 174 + function Read_Total_Out (Stream : in Stream_Type) return Count is 175 + begin 176 + return Total_Out (Stream.Reader); 177 + end Read_Total_Out; 178 + 179 + ----------- 180 + -- Write -- 181 + ----------- 182 + 183 + procedure Write 184 + (Stream : in out Stream_Type; 185 + Item : in Stream_Element_Array) 186 + is 187 + 188 + procedure Write (Item : in Stream_Element_Array); 189 + 190 + ----------- 191 + -- Write -- 192 + ----------- 193 + 194 + procedure Write (Item : in Stream_Element_Array) is 195 + begin 196 + Ada.Streams.Write (Stream.Back.all, Item); 197 + end Write; 198 + 199 + procedure Write is new ZLib.Write 200 + (Write => Write, 201 + Buffer_Size => Stream.Buffer_Size); 202 + 203 + begin 204 + Write (Stream.Writer, Item, No_Flush); 205 + end Write; 206 + 207 + -------------------- 208 + -- Write_Total_In -- 209 + -------------------- 210 + 211 + function Write_Total_In (Stream : in Stream_Type) return Count is 212 + begin 213 + return Total_In (Stream.Writer); 214 + end Write_Total_In; 215 + 216 + --------------------- 217 + -- Write_Total_Out -- 218 + --------------------- 219 + 220 + function Write_Total_Out (Stream : in Stream_Type) return Count is 221 + begin 222 + return Total_Out (Stream.Writer); 223 + end Write_Total_Out; 224 + 225 +end ZLib.Streams;
Added compat/zlib/contrib/ada/zlib-streams.ads.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $ 10 + 11 +package ZLib.Streams is 12 + 13 + type Stream_Mode is (In_Stream, Out_Stream, Duplex); 14 + 15 + type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; 16 + 17 + type Stream_Type is 18 + new Ada.Streams.Root_Stream_Type with private; 19 + 20 + procedure Read 21 + (Stream : in out Stream_Type; 22 + Item : out Ada.Streams.Stream_Element_Array; 23 + Last : out Ada.Streams.Stream_Element_Offset); 24 + 25 + procedure Write 26 + (Stream : in out Stream_Type; 27 + Item : in Ada.Streams.Stream_Element_Array); 28 + 29 + procedure Flush 30 + (Stream : in out Stream_Type; 31 + Mode : in Flush_Mode := Sync_Flush); 32 + -- Flush the written data to the back stream, 33 + -- all data placed to the compressor is flushing to the Back stream. 34 + -- Should not be used untill necessary, becouse it is decreasing 35 + -- compression. 36 + 37 + function Read_Total_In (Stream : in Stream_Type) return Count; 38 + pragma Inline (Read_Total_In); 39 + -- Return total number of bytes read from back stream so far. 40 + 41 + function Read_Total_Out (Stream : in Stream_Type) return Count; 42 + pragma Inline (Read_Total_Out); 43 + -- Return total number of bytes read so far. 44 + 45 + function Write_Total_In (Stream : in Stream_Type) return Count; 46 + pragma Inline (Write_Total_In); 47 + -- Return total number of bytes written so far. 48 + 49 + function Write_Total_Out (Stream : in Stream_Type) return Count; 50 + pragma Inline (Write_Total_Out); 51 + -- Return total number of bytes written to the back stream. 52 + 53 + procedure Create 54 + (Stream : out Stream_Type; 55 + Mode : in Stream_Mode; 56 + Back : in Stream_Access; 57 + Back_Compressed : in Boolean; 58 + Level : in Compression_Level := Default_Compression; 59 + Strategy : in Strategy_Type := Default_Strategy; 60 + Header : in Header_Type := Default; 61 + Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset 62 + := Default_Buffer_Size; 63 + Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset 64 + := Default_Buffer_Size); 65 + -- Create the Comression/Decompression stream. 66 + -- If mode is In_Stream then Write operation is disabled. 67 + -- If mode is Out_Stream then Read operation is disabled. 68 + 69 + -- If Back_Compressed is true then 70 + -- Data written to the Stream is compressing to the Back stream 71 + -- and data read from the Stream is decompressed data from the Back stream. 72 + 73 + -- If Back_Compressed is false then 74 + -- Data written to the Stream is decompressing to the Back stream 75 + -- and data read from the Stream is compressed data from the Back stream. 76 + 77 + -- !!! When the Need_Header is False ZLib-Ada is using undocumented 78 + -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. 79 + 80 + function Is_Open (Stream : Stream_Type) return Boolean; 81 + 82 + procedure Close (Stream : in out Stream_Type); 83 + 84 +private 85 + 86 + use Ada.Streams; 87 + 88 + type Buffer_Access is access all Stream_Element_Array; 89 + 90 + type Stream_Type 91 + is new Root_Stream_Type with 92 + record 93 + Mode : Stream_Mode; 94 + 95 + Buffer : Buffer_Access; 96 + Rest_First : Stream_Element_Offset; 97 + Rest_Last : Stream_Element_Offset; 98 + -- Buffer for Read operation. 99 + -- We need to have this buffer in the record 100 + -- becouse not all read data from back stream 101 + -- could be processed during the read operation. 102 + 103 + Buffer_Size : Stream_Element_Offset; 104 + -- Buffer size for write operation. 105 + -- We do not need to have this buffer 106 + -- in the record becouse all data could be 107 + -- processed in the write operation. 108 + 109 + Back : Stream_Access; 110 + Reader : Filter_Type; 111 + Writer : Filter_Type; 112 + end record; 113 + 114 +end ZLib.Streams;
Added compat/zlib/contrib/ada/zlib-thin.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: zlib-thin.adb,v 1.8 2003/12/14 18:27:31 vagul Exp $ 10 + 11 +package body ZLib.Thin is 12 + 13 + ZLIB_VERSION : constant Chars_Ptr := zlibVersion; 14 + 15 + Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; 16 + 17 + -------------- 18 + -- Avail_In -- 19 + -------------- 20 + 21 + function Avail_In (Strm : in Z_Stream) return UInt is 22 + begin 23 + return Strm.Avail_In; 24 + end Avail_In; 25 + 26 + --------------- 27 + -- Avail_Out -- 28 + --------------- 29 + 30 + function Avail_Out (Strm : in Z_Stream) return UInt is 31 + begin 32 + return Strm.Avail_Out; 33 + end Avail_Out; 34 + 35 + ------------------ 36 + -- Deflate_Init -- 37 + ------------------ 38 + 39 + function Deflate_Init 40 + (strm : Z_Streamp; 41 + level : Int; 42 + method : Int; 43 + windowBits : Int; 44 + memLevel : Int; 45 + strategy : Int) 46 + return Int is 47 + begin 48 + return deflateInit2 49 + (strm, 50 + level, 51 + method, 52 + windowBits, 53 + memLevel, 54 + strategy, 55 + ZLIB_VERSION, 56 + Z_Stream_Size); 57 + end Deflate_Init; 58 + 59 + ------------------ 60 + -- Inflate_Init -- 61 + ------------------ 62 + 63 + function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is 64 + begin 65 + return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); 66 + end Inflate_Init; 67 + 68 + ------------------------ 69 + -- Last_Error_Message -- 70 + ------------------------ 71 + 72 + function Last_Error_Message (Strm : in Z_Stream) return String is 73 + use Interfaces.C.Strings; 74 + begin 75 + if Strm.msg = Null_Ptr then 76 + return ""; 77 + else 78 + return Value (Strm.msg); 79 + end if; 80 + end Last_Error_Message; 81 + 82 + ------------ 83 + -- Set_In -- 84 + ------------ 85 + 86 + procedure Set_In 87 + (Strm : in out Z_Stream; 88 + Buffer : in Voidp; 89 + Size : in UInt) is 90 + begin 91 + Strm.Next_In := Buffer; 92 + Strm.Avail_In := Size; 93 + end Set_In; 94 + 95 + ------------------ 96 + -- Set_Mem_Func -- 97 + ------------------ 98 + 99 + procedure Set_Mem_Func 100 + (Strm : in out Z_Stream; 101 + Opaque : in Voidp; 102 + Alloc : in alloc_func; 103 + Free : in free_func) is 104 + begin 105 + Strm.opaque := Opaque; 106 + Strm.zalloc := Alloc; 107 + Strm.zfree := Free; 108 + end Set_Mem_Func; 109 + 110 + ------------- 111 + -- Set_Out -- 112 + ------------- 113 + 114 + procedure Set_Out 115 + (Strm : in out Z_Stream; 116 + Buffer : in Voidp; 117 + Size : in UInt) is 118 + begin 119 + Strm.Next_Out := Buffer; 120 + Strm.Avail_Out := Size; 121 + end Set_Out; 122 + 123 + -------------- 124 + -- Total_In -- 125 + -------------- 126 + 127 + function Total_In (Strm : in Z_Stream) return ULong is 128 + begin 129 + return Strm.Total_In; 130 + end Total_In; 131 + 132 + --------------- 133 + -- Total_Out -- 134 + --------------- 135 + 136 + function Total_Out (Strm : in Z_Stream) return ULong is 137 + begin 138 + return Strm.Total_Out; 139 + end Total_Out; 140 + 141 +end ZLib.Thin;
Added compat/zlib/contrib/ada/zlib-thin.ads.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $ 10 + 11 +with Interfaces.C.Strings; 12 + 13 +with System; 14 + 15 +private package ZLib.Thin is 16 + 17 + -- From zconf.h 18 + 19 + MAX_MEM_LEVEL : constant := 9; -- zconf.h:105 20 + -- zconf.h:105 21 + MAX_WBITS : constant := 15; -- zconf.h:115 22 + -- 32K LZ77 window 23 + -- zconf.h:115 24 + SEEK_SET : constant := 8#0000#; -- zconf.h:244 25 + -- Seek from beginning of file. 26 + -- zconf.h:244 27 + SEEK_CUR : constant := 1; -- zconf.h:245 28 + -- Seek from current position. 29 + -- zconf.h:245 30 + SEEK_END : constant := 2; -- zconf.h:246 31 + -- Set file pointer to EOF plus "offset" 32 + -- zconf.h:246 33 + 34 + type Byte is new Interfaces.C.unsigned_char; -- 8 bits 35 + -- zconf.h:214 36 + type UInt is new Interfaces.C.unsigned; -- 16 bits or more 37 + -- zconf.h:216 38 + type Int is new Interfaces.C.int; 39 + 40 + type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more 41 + -- zconf.h:217 42 + subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; 43 + 44 + type ULong_Access is access ULong; 45 + type Int_Access is access Int; 46 + 47 + subtype Voidp is System.Address; -- zconf.h:232 48 + 49 + subtype Byte_Access is Voidp; 50 + 51 + Nul : constant Voidp := System.Null_Address; 52 + -- end from zconf 53 + 54 + Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 55 + -- zlib.h:125 56 + Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126 57 + -- will be removed, use 58 + -- Z_SYNC_FLUSH instead 59 + -- zlib.h:126 60 + Z_SYNC_FLUSH : constant := 2; -- zlib.h:127 61 + -- zlib.h:127 62 + Z_FULL_FLUSH : constant := 3; -- zlib.h:128 63 + -- zlib.h:128 64 + Z_FINISH : constant := 4; -- zlib.h:129 65 + -- zlib.h:129 66 + Z_OK : constant := 8#0000#; -- zlib.h:132 67 + -- zlib.h:132 68 + Z_STREAM_END : constant := 1; -- zlib.h:133 69 + -- zlib.h:133 70 + Z_NEED_DICT : constant := 2; -- zlib.h:134 71 + -- zlib.h:134 72 + Z_ERRNO : constant := -1; -- zlib.h:135 73 + -- zlib.h:135 74 + Z_STREAM_ERROR : constant := -2; -- zlib.h:136 75 + -- zlib.h:136 76 + Z_DATA_ERROR : constant := -3; -- zlib.h:137 77 + -- zlib.h:137 78 + Z_MEM_ERROR : constant := -4; -- zlib.h:138 79 + -- zlib.h:138 80 + Z_BUF_ERROR : constant := -5; -- zlib.h:139 81 + -- zlib.h:139 82 + Z_VERSION_ERROR : constant := -6; -- zlib.h:140 83 + -- zlib.h:140 84 + Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145 85 + -- zlib.h:145 86 + Z_BEST_SPEED : constant := 1; -- zlib.h:146 87 + -- zlib.h:146 88 + Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147 89 + -- zlib.h:147 90 + Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148 91 + -- zlib.h:148 92 + Z_FILTERED : constant := 1; -- zlib.h:151 93 + -- zlib.h:151 94 + Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152 95 + -- zlib.h:152 96 + Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153 97 + -- zlib.h:153 98 + Z_BINARY : constant := 8#0000#; -- zlib.h:156 99 + -- zlib.h:156 100 + Z_ASCII : constant := 1; -- zlib.h:157 101 + -- zlib.h:157 102 + Z_UNKNOWN : constant := 2; -- zlib.h:158 103 + -- zlib.h:158 104 + Z_DEFLATED : constant := 8; -- zlib.h:161 105 + -- zlib.h:161 106 + Z_NULL : constant := 8#0000#; -- zlib.h:164 107 + -- for initializing zalloc, zfree, opaque 108 + -- zlib.h:164 109 + type gzFile is new Voidp; -- zlib.h:646 110 + 111 + type Z_Stream is private; 112 + 113 + type Z_Streamp is access all Z_Stream; -- zlib.h:89 114 + 115 + type alloc_func is access function 116 + (Opaque : Voidp; 117 + Items : UInt; 118 + Size : UInt) 119 + return Voidp; -- zlib.h:63 120 + 121 + type free_func is access procedure (opaque : Voidp; address : Voidp); 122 + 123 + function zlibVersion return Chars_Ptr; 124 + 125 + function Deflate (strm : Z_Streamp; flush : Int) return Int; 126 + 127 + function DeflateEnd (strm : Z_Streamp) return Int; 128 + 129 + function Inflate (strm : Z_Streamp; flush : Int) return Int; 130 + 131 + function InflateEnd (strm : Z_Streamp) return Int; 132 + 133 + function deflateSetDictionary 134 + (strm : Z_Streamp; 135 + dictionary : Byte_Access; 136 + dictLength : UInt) 137 + return Int; 138 + 139 + function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int; 140 + -- zlib.h:478 141 + 142 + function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495 143 + 144 + function deflateParams 145 + (strm : Z_Streamp; 146 + level : Int; 147 + strategy : Int) 148 + return Int; -- zlib.h:506 149 + 150 + function inflateSetDictionary 151 + (strm : Z_Streamp; 152 + dictionary : Byte_Access; 153 + dictLength : UInt) 154 + return Int; -- zlib.h:548 155 + 156 + function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565 157 + 158 + function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580 159 + 160 + function compress 161 + (dest : Byte_Access; 162 + destLen : ULong_Access; 163 + source : Byte_Access; 164 + sourceLen : ULong) 165 + return Int; -- zlib.h:601 166 + 167 + function compress2 168 + (dest : Byte_Access; 169 + destLen : ULong_Access; 170 + source : Byte_Access; 171 + sourceLen : ULong; 172 + level : Int) 173 + return Int; -- zlib.h:615 174 + 175 + function uncompress 176 + (dest : Byte_Access; 177 + destLen : ULong_Access; 178 + source : Byte_Access; 179 + sourceLen : ULong) 180 + return Int; 181 + 182 + function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile; 183 + 184 + function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile; 185 + 186 + function gzsetparams 187 + (file : gzFile; 188 + level : Int; 189 + strategy : Int) 190 + return Int; 191 + 192 + function gzread 193 + (file : gzFile; 194 + buf : Voidp; 195 + len : UInt) 196 + return Int; 197 + 198 + function gzwrite 199 + (file : in gzFile; 200 + buf : in Voidp; 201 + len : in UInt) 202 + return Int; 203 + 204 + function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int; 205 + 206 + function gzputs (file : in gzFile; s : in Chars_Ptr) return Int; 207 + 208 + function gzgets 209 + (file : gzFile; 210 + buf : Chars_Ptr; 211 + len : Int) 212 + return Chars_Ptr; 213 + 214 + function gzputc (file : gzFile; char : Int) return Int; 215 + 216 + function gzgetc (file : gzFile) return Int; 217 + 218 + function gzflush (file : gzFile; flush : Int) return Int; 219 + 220 + function gzseek 221 + (file : gzFile; 222 + offset : Int; 223 + whence : Int) 224 + return Int; 225 + 226 + function gzrewind (file : gzFile) return Int; 227 + 228 + function gztell (file : gzFile) return Int; 229 + 230 + function gzeof (file : gzFile) return Int; 231 + 232 + function gzclose (file : gzFile) return Int; 233 + 234 + function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr; 235 + 236 + function adler32 237 + (adler : ULong; 238 + buf : Byte_Access; 239 + len : UInt) 240 + return ULong; 241 + 242 + function crc32 243 + (crc : ULong; 244 + buf : Byte_Access; 245 + len : UInt) 246 + return ULong; 247 + 248 + function deflateInit 249 + (strm : Z_Streamp; 250 + level : Int; 251 + version : Chars_Ptr; 252 + stream_size : Int) 253 + return Int; 254 + 255 + function deflateInit2 256 + (strm : Z_Streamp; 257 + level : Int; 258 + method : Int; 259 + windowBits : Int; 260 + memLevel : Int; 261 + strategy : Int; 262 + version : Chars_Ptr; 263 + stream_size : Int) 264 + return Int; 265 + 266 + function Deflate_Init 267 + (strm : Z_Streamp; 268 + level : Int; 269 + method : Int; 270 + windowBits : Int; 271 + memLevel : Int; 272 + strategy : Int) 273 + return Int; 274 + pragma Inline (Deflate_Init); 275 + 276 + function inflateInit 277 + (strm : Z_Streamp; 278 + version : Chars_Ptr; 279 + stream_size : Int) 280 + return Int; 281 + 282 + function inflateInit2 283 + (strm : in Z_Streamp; 284 + windowBits : in Int; 285 + version : in Chars_Ptr; 286 + stream_size : in Int) 287 + return Int; 288 + 289 + function inflateBackInit 290 + (strm : in Z_Streamp; 291 + windowBits : in Int; 292 + window : in Byte_Access; 293 + version : in Chars_Ptr; 294 + stream_size : in Int) 295 + return Int; 296 + -- Size of window have to be 2**windowBits. 297 + 298 + function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int; 299 + pragma Inline (Inflate_Init); 300 + 301 + function zError (err : Int) return Chars_Ptr; 302 + 303 + function inflateSyncPoint (z : Z_Streamp) return Int; 304 + 305 + function get_crc_table return ULong_Access; 306 + 307 + -- Interface to the available fields of the z_stream structure. 308 + -- The application must update next_in and avail_in when avail_in has 309 + -- dropped to zero. It must update next_out and avail_out when avail_out 310 + -- has dropped to zero. The application must initialize zalloc, zfree and 311 + -- opaque before calling the init function. 312 + 313 + procedure Set_In 314 + (Strm : in out Z_Stream; 315 + Buffer : in Voidp; 316 + Size : in UInt); 317 + pragma Inline (Set_In); 318 + 319 + procedure Set_Out 320 + (Strm : in out Z_Stream; 321 + Buffer : in Voidp; 322 + Size : in UInt); 323 + pragma Inline (Set_Out); 324 + 325 + procedure Set_Mem_Func 326 + (Strm : in out Z_Stream; 327 + Opaque : in Voidp; 328 + Alloc : in alloc_func; 329 + Free : in free_func); 330 + pragma Inline (Set_Mem_Func); 331 + 332 + function Last_Error_Message (Strm : in Z_Stream) return String; 333 + pragma Inline (Last_Error_Message); 334 + 335 + function Avail_Out (Strm : in Z_Stream) return UInt; 336 + pragma Inline (Avail_Out); 337 + 338 + function Avail_In (Strm : in Z_Stream) return UInt; 339 + pragma Inline (Avail_In); 340 + 341 + function Total_In (Strm : in Z_Stream) return ULong; 342 + pragma Inline (Total_In); 343 + 344 + function Total_Out (Strm : in Z_Stream) return ULong; 345 + pragma Inline (Total_Out); 346 + 347 + function inflateCopy 348 + (dest : in Z_Streamp; 349 + Source : in Z_Streamp) 350 + return Int; 351 + 352 + function compressBound (Source_Len : in ULong) return ULong; 353 + 354 + function deflateBound 355 + (Strm : in Z_Streamp; 356 + Source_Len : in ULong) 357 + return ULong; 358 + 359 + function gzungetc (C : in Int; File : in gzFile) return Int; 360 + 361 + function zlibCompileFlags return ULong; 362 + 363 +private 364 + 365 + type Z_Stream is record -- zlib.h:68 366 + Next_In : Voidp := Nul; -- next input byte 367 + Avail_In : UInt := 0; -- number of bytes available at next_in 368 + Total_In : ULong := 0; -- total nb of input bytes read so far 369 + Next_Out : Voidp := Nul; -- next output byte should be put there 370 + Avail_Out : UInt := 0; -- remaining free space at next_out 371 + Total_Out : ULong := 0; -- total nb of bytes output so far 372 + msg : Chars_Ptr; -- last error message, NULL if no error 373 + state : Voidp; -- not visible by applications 374 + zalloc : alloc_func := null; -- used to allocate the internal state 375 + zfree : free_func := null; -- used to free the internal state 376 + opaque : Voidp; -- private data object passed to 377 + -- zalloc and zfree 378 + data_type : Int; -- best guess about the data type: 379 + -- ascii or binary 380 + adler : ULong; -- adler32 value of the uncompressed 381 + -- data 382 + reserved : ULong; -- reserved for future use 383 + end record; 384 + 385 + pragma Convention (C, Z_Stream); 386 + 387 + pragma Import (C, zlibVersion, "zlibVersion"); 388 + pragma Import (C, Deflate, "deflate"); 389 + pragma Import (C, DeflateEnd, "deflateEnd"); 390 + pragma Import (C, Inflate, "inflate"); 391 + pragma Import (C, InflateEnd, "inflateEnd"); 392 + pragma Import (C, deflateSetDictionary, "deflateSetDictionary"); 393 + pragma Import (C, deflateCopy, "deflateCopy"); 394 + pragma Import (C, deflateReset, "deflateReset"); 395 + pragma Import (C, deflateParams, "deflateParams"); 396 + pragma Import (C, inflateSetDictionary, "inflateSetDictionary"); 397 + pragma Import (C, inflateSync, "inflateSync"); 398 + pragma Import (C, inflateReset, "inflateReset"); 399 + pragma Import (C, compress, "compress"); 400 + pragma Import (C, compress2, "compress2"); 401 + pragma Import (C, uncompress, "uncompress"); 402 + pragma Import (C, gzopen, "gzopen"); 403 + pragma Import (C, gzdopen, "gzdopen"); 404 + pragma Import (C, gzsetparams, "gzsetparams"); 405 + pragma Import (C, gzread, "gzread"); 406 + pragma Import (C, gzwrite, "gzwrite"); 407 + pragma Import (C, gzprintf, "gzprintf"); 408 + pragma Import (C, gzputs, "gzputs"); 409 + pragma Import (C, gzgets, "gzgets"); 410 + pragma Import (C, gzputc, "gzputc"); 411 + pragma Import (C, gzgetc, "gzgetc"); 412 + pragma Import (C, gzflush, "gzflush"); 413 + pragma Import (C, gzseek, "gzseek"); 414 + pragma Import (C, gzrewind, "gzrewind"); 415 + pragma Import (C, gztell, "gztell"); 416 + pragma Import (C, gzeof, "gzeof"); 417 + pragma Import (C, gzclose, "gzclose"); 418 + pragma Import (C, gzerror, "gzerror"); 419 + pragma Import (C, adler32, "adler32"); 420 + pragma Import (C, crc32, "crc32"); 421 + pragma Import (C, deflateInit, "deflateInit_"); 422 + pragma Import (C, inflateInit, "inflateInit_"); 423 + pragma Import (C, deflateInit2, "deflateInit2_"); 424 + pragma Import (C, inflateInit2, "inflateInit2_"); 425 + pragma Import (C, zError, "zError"); 426 + pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); 427 + pragma Import (C, get_crc_table, "get_crc_table"); 428 + 429 + -- since zlib 1.2.0: 430 + 431 + pragma Import (C, inflateCopy, "inflateCopy"); 432 + pragma Import (C, compressBound, "compressBound"); 433 + pragma Import (C, deflateBound, "deflateBound"); 434 + pragma Import (C, gzungetc, "gzungetc"); 435 + pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); 436 + 437 + pragma Import (C, inflateBackInit, "inflateBackInit_"); 438 + 439 + -- I stopped binding the inflateBack routines, becouse realize that 440 + -- it does not support zlib and gzip headers for now, and have no 441 + -- symmetric deflateBack routines. 442 + -- ZLib-Ada is symmetric regarding deflate/inflate data transformation 443 + -- and has a similar generic callback interface for the 444 + -- deflate/inflate transformation based on the regular Deflate/Inflate 445 + -- routines. 446 + 447 + -- pragma Import (C, inflateBack, "inflateBack"); 448 + -- pragma Import (C, inflateBackEnd, "inflateBackEnd"); 449 + 450 +end ZLib.Thin;
Added compat/zlib/contrib/ada/zlib.adb.
1 +---------------------------------------------------------------- 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- 5 +-- -- 6 +-- Open source license information is in the zlib.ads file. -- 7 +---------------------------------------------------------------- 8 + 9 +-- $Id: zlib.adb,v 1.31 2004/09/06 06:53:19 vagul Exp $ 10 + 11 +with Ada.Exceptions; 12 +with Ada.Unchecked_Conversion; 13 +with Ada.Unchecked_Deallocation; 14 + 15 +with Interfaces.C.Strings; 16 + 17 +with ZLib.Thin; 18 + 19 +package body ZLib is 20 + 21 + use type Thin.Int; 22 + 23 + type Z_Stream is new Thin.Z_Stream; 24 + 25 + type Return_Code_Enum is 26 + (OK, 27 + STREAM_END, 28 + NEED_DICT, 29 + ERRNO, 30 + STREAM_ERROR, 31 + DATA_ERROR, 32 + MEM_ERROR, 33 + BUF_ERROR, 34 + VERSION_ERROR); 35 + 36 + type Flate_Step_Function is access 37 + function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int; 38 + pragma Convention (C, Flate_Step_Function); 39 + 40 + type Flate_End_Function is access 41 + function (Ctrm : in Thin.Z_Streamp) return Thin.Int; 42 + pragma Convention (C, Flate_End_Function); 43 + 44 + type Flate_Type is record 45 + Step : Flate_Step_Function; 46 + Done : Flate_End_Function; 47 + end record; 48 + 49 + subtype Footer_Array is Stream_Element_Array (1 .. 8); 50 + 51 + Simple_GZip_Header : constant Stream_Element_Array (1 .. 10) 52 + := (16#1f#, 16#8b#, -- Magic header 53 + 16#08#, -- Z_DEFLATED 54 + 16#00#, -- Flags 55 + 16#00#, 16#00#, 16#00#, 16#00#, -- Time 56 + 16#00#, -- XFlags 57 + 16#03# -- OS code 58 + ); 59 + -- The simplest gzip header is not for informational, but just for 60 + -- gzip format compatibility. 61 + -- Note that some code below is using assumption 62 + -- Simple_GZip_Header'Last > Footer_Array'Last, so do not make 63 + -- Simple_GZip_Header'Last <= Footer_Array'Last. 64 + 65 + Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum 66 + := (0 => OK, 67 + 1 => STREAM_END, 68 + 2 => NEED_DICT, 69 + -1 => ERRNO, 70 + -2 => STREAM_ERROR, 71 + -3 => DATA_ERROR, 72 + -4 => MEM_ERROR, 73 + -5 => BUF_ERROR, 74 + -6 => VERSION_ERROR); 75 + 76 + Flate : constant array (Boolean) of Flate_Type 77 + := (True => (Step => Thin.Deflate'Access, 78 + Done => Thin.DeflateEnd'Access), 79 + False => (Step => Thin.Inflate'Access, 80 + Done => Thin.InflateEnd'Access)); 81 + 82 + Flush_Finish : constant array (Boolean) of Flush_Mode 83 + := (True => Finish, False => No_Flush); 84 + 85 + procedure Raise_Error (Stream : in Z_Stream); 86 + pragma Inline (Raise_Error); 87 + 88 + procedure Raise_Error (Message : in String); 89 + pragma Inline (Raise_Error); 90 + 91 + procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int); 92 + 93 + procedure Free is new Ada.Unchecked_Deallocation 94 + (Z_Stream, Z_Stream_Access); 95 + 96 + function To_Thin_Access is new Ada.Unchecked_Conversion 97 + (Z_Stream_Access, Thin.Z_Streamp); 98 + 99 + procedure Translate_GZip 100 + (Filter : in out Filter_Type; 101 + In_Data : in Ada.Streams.Stream_Element_Array; 102 + In_Last : out Ada.Streams.Stream_Element_Offset; 103 + Out_Data : out Ada.Streams.Stream_Element_Array; 104 + Out_Last : out Ada.Streams.Stream_Element_Offset; 105 + Flush : in Flush_Mode); 106 + -- Separate translate routine for make gzip header. 107 + 108 + procedure Translate_Auto 109 + (Filter : in out Filter_Type; 110 + In_Data : in Ada.Streams.Stream_Element_Array; 111 + In_Last : out Ada.Streams.Stream_Element_Offset; 112 + Out_Data : out Ada.Streams.Stream_Element_Array; 113 + Out_Last : out Ada.Streams.Stream_Element_Offset; 114 + Flush : in Flush_Mode); 115 + -- translate routine without additional headers. 116 + 117 + ----------------- 118 + -- Check_Error -- 119 + ----------------- 120 + 121 + procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is 122 + use type Thin.Int; 123 + begin 124 + if Code /= Thin.Z_OK then 125 + Raise_Error 126 + (Return_Code_Enum'Image (Return_Code (Code)) 127 + & ": " & Last_Error_Message (Stream)); 128 + end if; 129 + end Check_Error; 130 + 131 + ----------- 132 + -- Close -- 133 + ----------- 134 + 135 + procedure Close 136 + (Filter : in out Filter_Type; 137 + Ignore_Error : in Boolean := False) 138 + is 139 + Code : Thin.Int; 140 + begin 141 + if not Ignore_Error and then not Is_Open (Filter) then 142 + raise Status_Error; 143 + end if; 144 + 145 + Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm)); 146 + 147 + if Ignore_Error or else Code = Thin.Z_OK then 148 + Free (Filter.Strm); 149 + else 150 + declare 151 + Error_Message : constant String 152 + := Last_Error_Message (Filter.Strm.all); 153 + begin 154 + Free (Filter.Strm); 155 + Ada.Exceptions.Raise_Exception 156 + (ZLib_Error'Identity, 157 + Return_Code_Enum'Image (Return_Code (Code)) 158 + & ": " & Error_Message); 159 + end; 160 + end if; 161 + end Close; 162 + 163 + ----------- 164 + -- CRC32 -- 165 + ----------- 166 + 167 + function CRC32 168 + (CRC : in Unsigned_32; 169 + Data : in Ada.Streams.Stream_Element_Array) 170 + return Unsigned_32 171 + is 172 + use Thin; 173 + begin 174 + return Unsigned_32 (crc32 (ULong (CRC), 175 + Data'Address, 176 + Data'Length)); 177 + end CRC32; 178 + 179 + procedure CRC32 180 + (CRC : in out Unsigned_32; 181 + Data : in Ada.Streams.Stream_Element_Array) is 182 + begin 183 + CRC := CRC32 (CRC, Data); 184 + end CRC32; 185 + 186 + ------------------ 187 + -- Deflate_Init -- 188 + ------------------ 189 + 190 + procedure Deflate_Init 191 + (Filter : in out Filter_Type; 192 + Level : in Compression_Level := Default_Compression; 193 + Strategy : in Strategy_Type := Default_Strategy; 194 + Method : in Compression_Method := Deflated; 195 + Window_Bits : in Window_Bits_Type := Default_Window_Bits; 196 + Memory_Level : in Memory_Level_Type := Default_Memory_Level; 197 + Header : in Header_Type := Default) 198 + is 199 + use type Thin.Int; 200 + Win_Bits : Thin.Int := Thin.Int (Window_Bits); 201 + begin 202 + if Is_Open (Filter) then 203 + raise Status_Error; 204 + end if; 205 + 206 + -- We allow ZLib to make header only in case of default header type. 207 + -- Otherwise we would either do header by ourselfs, or do not do 208 + -- header at all. 209 + 210 + if Header = None or else Header = GZip then 211 + Win_Bits := -Win_Bits; 212 + end if; 213 + 214 + -- For the GZip CRC calculation and make headers. 215 + 216 + if Header = GZip then 217 + Filter.CRC := 0; 218 + Filter.Offset := Simple_GZip_Header'First; 219 + else 220 + Filter.Offset := Simple_GZip_Header'Last + 1; 221 + end if; 222 + 223 + Filter.Strm := new Z_Stream; 224 + Filter.Compression := True; 225 + Filter.Stream_End := False; 226 + Filter.Header := Header; 227 + 228 + if Thin.Deflate_Init 229 + (To_Thin_Access (Filter.Strm), 230 + Level => Thin.Int (Level), 231 + method => Thin.Int (Method), 232 + windowBits => Win_Bits, 233 + memLevel => Thin.Int (Memory_Level), 234 + strategy => Thin.Int (Strategy)) /= Thin.Z_OK 235 + then 236 + Raise_Error (Filter.Strm.all); 237 + end if; 238 + end Deflate_Init; 239 + 240 + ----------- 241 + -- Flush -- 242 + ----------- 243 + 244 + procedure Flush 245 + (Filter : in out Filter_Type; 246 + Out_Data : out Ada.Streams.Stream_Element_Array; 247 + Out_Last : out Ada.Streams.Stream_Element_Offset; 248 + Flush : in Flush_Mode) 249 + is 250 + No_Data : Stream_Element_Array := (1 .. 0 => 0); 251 + Last : Stream_Element_Offset; 252 + begin 253 + Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush); 254 + end Flush; 255 + 256 + ----------------------- 257 + -- Generic_Translate -- 258 + ----------------------- 259 + 260 + procedure Generic_Translate 261 + (Filter : in out ZLib.Filter_Type; 262 + In_Buffer_Size : in Integer := Default_Buffer_Size; 263 + Out_Buffer_Size : in Integer := Default_Buffer_Size) 264 + is 265 + In_Buffer : Stream_Element_Array 266 + (1 .. Stream_Element_Offset (In_Buffer_Size)); 267 + Out_Buffer : Stream_Element_Array 268 + (1 .. Stream_Element_Offset (Out_Buffer_Size)); 269 + Last : Stream_Element_Offset; 270 + In_Last : Stream_Element_Offset; 271 + In_First : Stream_Element_Offset; 272 + Out_Last : Stream_Element_Offset; 273 + begin 274 + Main : loop 275 + Data_In (In_Buffer, Last); 276 + 277 + In_First := In_Buffer'First; 278 + 279 + loop 280 + Translate 281 + (Filter => Filter, 282 + In_Data => In_Buffer (In_First .. Last), 283 + In_Last => In_Last, 284 + Out_Data => Out_Buffer, 285 + Out_Last => Out_Last, 286 + Flush => Flush_Finish (Last < In_Buffer'First)); 287 + 288 + if Out_Buffer'First <= Out_Last then 289 + Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last)); 290 + end if; 291 + 292 + exit Main when Stream_End (Filter); 293 + 294 + -- The end of in buffer. 295 + 296 + exit when In_Last = Last; 297 + 298 + In_First := In_Last + 1; 299 + end loop; 300 + end loop Main; 301 + 302 + end Generic_Translate; 303 + 304 + ------------------ 305 + -- Inflate_Init -- 306 + ------------------ 307 + 308 + procedure Inflate_Init 309 + (Filter : in out Filter_Type; 310 + Window_Bits : in Window_Bits_Type := Default_Window_Bits; 311 + Header : in Header_Type := Default) 312 + is 313 + use type Thin.Int; 314 + Win_Bits : Thin.Int := Thin.Int (Window_Bits); 315 + 316 + procedure Check_Version; 317 + -- Check the latest header types compatibility. 318 + 319 + procedure Check_Version is 320 + begin 321 + if Version <= "1.1.4" then 322 + Raise_Error 323 + ("Inflate header type " & Header_Type'Image (Header) 324 + & " incompatible with ZLib version " & Version); 325 + end if; 326 + end Check_Version; 327 + 328 + begin 329 + if Is_Open (Filter) then 330 + raise Status_Error; 331 + end if; 332 + 333 + case Header is 334 + when None => 335 + Check_Version; 336 + 337 + -- Inflate data without headers determined 338 + -- by negative Win_Bits. 339 + 340 + Win_Bits := -Win_Bits; 341 + when GZip => 342 + Check_Version; 343 + 344 + -- Inflate gzip data defined by flag 16. 345 + 346 + Win_Bits := Win_Bits + 16; 347 + when Auto => 348 + Check_Version; 349 + 350 + -- Inflate with automatic detection 351 + -- of gzip or native header defined by flag 32. 352 + 353 + Win_Bits := Win_Bits + 32; 354 + when Default => null; 355 + end case; 356 + 357 + Filter.Strm := new Z_Stream; 358 + Filter.Compression := False; 359 + Filter.Stream_End := False; 360 + Filter.Header := Header; 361 + 362 + if Thin.Inflate_Init 363 + (To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK 364 + then 365 + Raise_Error (Filter.Strm.all); 366 + end if; 367 + end Inflate_Init; 368 + 369 + ------------- 370 + -- Is_Open -- 371 + ------------- 372 + 373 + function Is_Open (Filter : in Filter_Type) return Boolean is 374 + begin 375 + return Filter.Strm /= null; 376 + end Is_Open; 377 + 378 + ----------------- 379 + -- Raise_Error -- 380 + ----------------- 381 + 382 + procedure Raise_Error (Message : in String) is 383 + begin 384 + Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message); 385 + end Raise_Error; 386 + 387 + procedure Raise_Error (Stream : in Z_Stream) is 388 + begin 389 + Raise_Error (Last_Error_Message (Stream)); 390 + end Raise_Error; 391 + 392 + ---------- 393 + -- Read -- 394 + ---------- 395 + 396 + procedure Read 397 + (Filter : in out Filter_Type; 398 + Item : out Ada.Streams.Stream_Element_Array; 399 + Last : out Ada.Streams.Stream_Element_Offset; 400 + Flush : in Flush_Mode := No_Flush) 401 + is 402 + In_Last : Stream_Element_Offset; 403 + Item_First : Ada.Streams.Stream_Element_Offset := Item'First; 404 + V_Flush : Flush_Mode := Flush; 405 + 406 + begin 407 + pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1); 408 + pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last); 409 + 410 + loop 411 + if Rest_Last = Buffer'First - 1 then 412 + V_Flush := Finish; 413 + 414 + elsif Rest_First > Rest_Last then 415 + Read (Buffer, Rest_Last); 416 + Rest_First := Buffer'First; 417 + 418 + if Rest_Last < Buffer'First then 419 + V_Flush := Finish; 420 + end if; 421 + end if; 422 + 423 + Translate 424 + (Filter => Filter, 425 + In_Data => Buffer (Rest_First .. Rest_Last), 426 + In_Last => In_Last, 427 + Out_Data => Item (Item_First .. Item'Last), 428 + Out_Last => Last, 429 + Flush => V_Flush); 430 + 431 + Rest_First := In_Last + 1; 432 + 433 + exit when Stream_End (Filter) 434 + or else Last = Item'Last 435 + or else (Last >= Item'First and then Allow_Read_Some); 436 + 437 + Item_First := Last + 1; 438 + end loop; 439 + end Read; 440 + 441 + ---------------- 442 + -- Stream_End -- 443 + ---------------- 444 + 445 + function Stream_End (Filter : in Filter_Type) return Boolean is 446 + begin 447 + if Filter.Header = GZip and Filter.Compression then 448 + return Filter.Stream_End 449 + and then Filter.Offset = Footer_Array'Last + 1; 450 + else 451 + return Filter.Stream_End; 452 + end if; 453 + end Stream_End; 454 + 455 + -------------- 456 + -- Total_In -- 457 + -------------- 458 + 459 + function Total_In (Filter : in Filter_Type) return Count is 460 + begin 461 + return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all)); 462 + end Total_In; 463 + 464 + --------------- 465 + -- Total_Out -- 466 + --------------- 467 + 468 + function Total_Out (Filter : in Filter_Type) return Count is 469 + begin 470 + return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all)); 471 + end Total_Out; 472 + 473 + --------------- 474 + -- Translate -- 475 + --------------- 476 + 477 + procedure Translate 478 + (Filter : in out Filter_Type; 479 + In_Data : in Ada.Streams.Stream_Element_Array; 480 + In_Last : out Ada.Streams.Stream_Element_Offset; 481 + Out_Data : out Ada.Streams.Stream_Element_Array; 482 + Out_Last : out Ada.Streams.Stream_Element_Offset; 483 + Flush : in Flush_Mode) is 484 + begin 485 + if Filter.Header = GZip and then Filter.Compression then 486 + Translate_GZip 487 + (Filter => Filter, 488 + In_Data => In_Data, 489 + In_Last => In_Last, 490 + Out_Data => Out_Data, 491 + Out_Last => Out_Last, 492 + Flush => Flush); 493 + else 494 + Translate_Auto 495 + (Filter => Filter, 496 + In_Data => In_Data, 497 + In_Last => In_Last, 498 + Out_Data => Out_Data, 499 + Out_Last => Out_Last, 500 + Flush => Flush); 501 + end if; 502 + end Translate; 503 + 504 + -------------------- 505 + -- Translate_Auto -- 506 + -------------------- 507 + 508 + procedure Translate_Auto 509 + (Filter : in out Filter_Type; 510 + In_Data : in Ada.Streams.Stream_Element_Array; 511 + In_Last : out Ada.Streams.Stream_Element_Offset; 512 + Out_Data : out Ada.Streams.Stream_Element_Array; 513 + Out_Last : out Ada.Streams.Stream_Element_Offset; 514 + Flush : in Flush_Mode) 515 + is 516 + use type Thin.Int; 517 + Code : Thin.Int; 518 + 519 + begin 520 + if not Is_Open (Filter) then 521 + raise Status_Error; 522 + end if; 523 + 524 + if Out_Data'Length = 0 and then In_Data'Length = 0 then 525 + raise Constraint_Error; 526 + end if; 527 + 528 + Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length); 529 + Set_In (Filter.Strm.all, In_Data'Address, In_Data'Length); 530 + 531 + Code := Flate (Filter.Compression).Step 532 + (To_Thin_Access (Filter.Strm), 533 + Thin.Int (Flush)); 534 + 535 + if Code = Thin.Z_STREAM_END then 536 + Filter.Stream_End := True; 537 + else 538 + Check_Error (Filter.Strm.all, Code); 539 + end if; 540 + 541 + In_Last := In_Data'Last 542 + - Stream_Element_Offset (Avail_In (Filter.Strm.all)); 543 + Out_Last := Out_Data'Last 544 + - Stream_Element_Offset (Avail_Out (Filter.Strm.all)); 545 + end Translate_Auto; 546 + 547 + -------------------- 548 + -- Translate_GZip -- 549 + -------------------- 550 + 551 + procedure Translate_GZip 552 + (Filter : in out Filter_Type; 553 + In_Data : in Ada.Streams.Stream_Element_Array; 554 + In_Last : out Ada.Streams.Stream_Element_Offset; 555 + Out_Data : out Ada.Streams.Stream_Element_Array; 556 + Out_Last : out Ada.Streams.Stream_Element_Offset; 557 + Flush : in Flush_Mode) 558 + is 559 + Out_First : Stream_Element_Offset; 560 + 561 + procedure Add_Data (Data : in Stream_Element_Array); 562 + -- Add data to stream from the Filter.Offset till necessary, 563 + -- used for add gzip headr/footer. 564 + 565 + procedure Put_32 566 + (Item : in out Stream_Element_Array; 567 + Data : in Unsigned_32); 568 + pragma Inline (Put_32); 569 + 570 + -------------- 571 + -- Add_Data -- 572 + -------------- 573 + 574 + procedure Add_Data (Data : in Stream_Element_Array) is 575 + Data_First : Stream_Element_Offset renames Filter.Offset; 576 + Data_Last : Stream_Element_Offset; 577 + Data_Len : Stream_Element_Offset; -- -1 578 + Out_Len : Stream_Element_Offset; -- -1 579 + begin 580 + Out_First := Out_Last + 1; 581 + 582 + if Data_First > Data'Last then 583 + return; 584 + end if; 585 + 586 + Data_Len := Data'Last - Data_First; 587 + Out_Len := Out_Data'Last - Out_First; 588 + 589 + if Data_Len <= Out_Len then 590 + Out_Last := Out_First + Data_Len; 591 + Data_Last := Data'Last; 592 + else 593 + Out_Last := Out_Data'Last; 594 + Data_Last := Data_First + Out_Len; 595 + end if; 596 + 597 + Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last); 598 + 599 + Data_First := Data_Last + 1; 600 + Out_First := Out_Last + 1; 601 + end Add_Data; 602 + 603 + ------------ 604 + -- Put_32 -- 605 + ------------ 606 + 607 + procedure Put_32 608 + (Item : in out Stream_Element_Array; 609 + Data : in Unsigned_32) 610 + is 611 + D : Unsigned_32 := Data; 612 + begin 613 + for J in Item'First .. Item'First + 3 loop 614 + Item (J) := Stream_Element (D and 16#FF#); 615 + D := Shift_Right (D, 8); 616 + end loop; 617 + end Put_32; 618 + 619 + begin 620 + Out_Last := Out_Data'First - 1; 621 + 622 + if not Filter.Stream_End then 623 + Add_Data (Simple_GZip_Header); 624 + 625 + Translate_Auto 626 + (Filter => Filter, 627 + In_Data => In_Data, 628 + In_Last => In_Last, 629 + Out_Data => Out_Data (Out_First .. Out_Data'Last), 630 + Out_Last => Out_Last, 631 + Flush => Flush); 632 + 633 + CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last)); 634 + end if; 635 + 636 + if Filter.Stream_End and then Out_Last <= Out_Data'Last then 637 + -- This detection method would work only when 638 + -- Simple_GZip_Header'Last > Footer_Array'Last 639 + 640 + if Filter.Offset = Simple_GZip_Header'Last + 1 then 641 + Filter.Offset := Footer_Array'First; 642 + end if; 643 + 644 + declare 645 + Footer : Footer_Array; 646 + begin 647 + Put_32 (Footer, Filter.CRC); 648 + Put_32 (Footer (Footer'First + 4 .. Footer'Last), 649 + Unsigned_32 (Total_In (Filter))); 650 + Add_Data (Footer); 651 + end; 652 + end if; 653 + end Translate_GZip; 654 + 655 + ------------- 656 + -- Version -- 657 + ------------- 658 + 659 + function Version return String is 660 + begin 661 + return Interfaces.C.Strings.Value (Thin.zlibVersion); 662 + end Version; 663 + 664 + ----------- 665 + -- Write -- 666 + ----------- 667 + 668 + procedure Write 669 + (Filter : in out Filter_Type; 670 + Item : in Ada.Streams.Stream_Element_Array; 671 + Flush : in Flush_Mode := No_Flush) 672 + is 673 + Buffer : Stream_Element_Array (1 .. Buffer_Size); 674 + In_Last : Stream_Element_Offset; 675 + Out_Last : Stream_Element_Offset; 676 + In_First : Stream_Element_Offset := Item'First; 677 + begin 678 + if Item'Length = 0 and Flush = No_Flush then 679 + return; 680 + end if; 681 + 682 + loop 683 + Translate 684 + (Filter => Filter, 685 + In_Data => Item (In_First .. Item'Last), 686 + In_Last => In_Last, 687 + Out_Data => Buffer, 688 + Out_Last => Out_Last, 689 + Flush => Flush); 690 + 691 + if Out_Last >= Buffer'First then 692 + Write (Buffer (1 .. Out_Last)); 693 + end if; 694 + 695 + exit when In_Last = Item'Last or Stream_End (Filter); 696 + 697 + In_First := In_Last + 1; 698 + end loop; 699 + end Write; 700 + 701 +end ZLib;
Added compat/zlib/contrib/ada/zlib.ads.
1 +------------------------------------------------------------------------------ 2 +-- ZLib for Ada thick binding. -- 3 +-- -- 4 +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- 5 +-- -- 6 +-- This library is free software; you can redistribute it and/or modify -- 7 +-- it under the terms of the GNU General Public License as published by -- 8 +-- the Free Software Foundation; either version 2 of the License, or (at -- 9 +-- your option) any later version. -- 10 +-- -- 11 +-- This library is distributed in the hope that it will be useful, but -- 12 +-- WITHOUT ANY WARRANTY; without even the implied warranty of -- 13 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- 14 +-- General Public License for more details. -- 15 +-- -- 16 +-- You should have received a copy of the GNU General Public License -- 17 +-- along with this library; if not, write to the Free Software Foundation, -- 18 +-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- 19 +-- -- 20 +-- As a special exception, if other files instantiate generics from this -- 21 +-- unit, or you link this unit with other files to produce an executable, -- 22 +-- this unit does not by itself cause the resulting executable to be -- 23 +-- covered by the GNU General Public License. This exception does not -- 24 +-- however invalidate any other reasons why the executable file might be -- 25 +-- covered by the GNU Public License. -- 26 +------------------------------------------------------------------------------ 27 + 28 +-- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $ 29 + 30 +with Ada.Streams; 31 + 32 +with Interfaces; 33 + 34 +package ZLib is 35 + 36 + ZLib_Error : exception; 37 + Status_Error : exception; 38 + 39 + type Compression_Level is new Integer range -1 .. 9; 40 + 41 + type Flush_Mode is private; 42 + 43 + type Compression_Method is private; 44 + 45 + type Window_Bits_Type is new Integer range 8 .. 15; 46 + 47 + type Memory_Level_Type is new Integer range 1 .. 9; 48 + 49 + type Unsigned_32 is new Interfaces.Unsigned_32; 50 + 51 + type Strategy_Type is private; 52 + 53 + type Header_Type is (None, Auto, Default, GZip); 54 + -- Header type usage have a some limitation for inflate. 55 + -- See comment for Inflate_Init. 56 + 57 + subtype Count is Ada.Streams.Stream_Element_Count; 58 + 59 + Default_Memory_Level : constant Memory_Level_Type := 8; 60 + Default_Window_Bits : constant Window_Bits_Type := 15; 61 + 62 + ---------------------------------- 63 + -- Compression method constants -- 64 + ---------------------------------- 65 + 66 + Deflated : constant Compression_Method; 67 + -- Only one method allowed in this ZLib version 68 + 69 + --------------------------------- 70 + -- Compression level constants -- 71 + --------------------------------- 72 + 73 + No_Compression : constant Compression_Level := 0; 74 + Best_Speed : constant Compression_Level := 1; 75 + Best_Compression : constant Compression_Level := 9; 76 + Default_Compression : constant Compression_Level := -1; 77 + 78 + -------------------------- 79 + -- Flush mode constants -- 80 + -------------------------- 81 + 82 + No_Flush : constant Flush_Mode; 83 + -- Regular way for compression, no flush 84 + 85 + Partial_Flush : constant Flush_Mode; 86 + -- Will be removed, use Z_SYNC_FLUSH instead 87 + 88 + Sync_Flush : constant Flush_Mode; 89 + -- All pending output is flushed to the output buffer and the output 90 + -- is aligned on a byte boundary, so that the decompressor can get all 91 + -- input data available so far. (In particular avail_in is zero after the 92 + -- call if enough output space has been provided before the call.) 93 + -- Flushing may degrade compression for some compression algorithms and so 94 + -- it should be used only when necessary. 95 + 96 + Block_Flush : constant Flush_Mode; 97 + -- Z_BLOCK requests that inflate() stop 98 + -- if and when it get to the next deflate block boundary. When decoding the 99 + -- zlib or gzip format, this will cause inflate() to return immediately 100 + -- after the header and before the first block. When doing a raw inflate, 101 + -- inflate() will go ahead and process the first block, and will return 102 + -- when it gets to the end of that block, or when it runs out of data. 103 + 104 + Full_Flush : constant Flush_Mode; 105 + -- All output is flushed as with SYNC_FLUSH, and the compression state 106 + -- is reset so that decompression can restart from this point if previous 107 + -- compressed data has been damaged or if random access is desired. Using 108 + -- Full_Flush too often can seriously degrade the compression. 109 + 110 + Finish : constant Flush_Mode; 111 + -- Just for tell the compressor that input data is complete. 112 + 113 + ------------------------------------ 114 + -- Compression strategy constants -- 115 + ------------------------------------ 116 + 117 + -- RLE stategy could be used only in version 1.2.0 and later. 118 + 119 + Filtered : constant Strategy_Type; 120 + Huffman_Only : constant Strategy_Type; 121 + RLE : constant Strategy_Type; 122 + Default_Strategy : constant Strategy_Type; 123 + 124 + Default_Buffer_Size : constant := 4096; 125 + 126 + type Filter_Type is tagged limited private; 127 + -- The filter is for compression and for decompression. 128 + -- The usage of the type is depend of its initialization. 129 + 130 + function Version return String; 131 + pragma Inline (Version); 132 + -- Return string representation of the ZLib version. 133 + 134 + procedure Deflate_Init 135 + (Filter : in out Filter_Type; 136 + Level : in Compression_Level := Default_Compression; 137 + Strategy : in Strategy_Type := Default_Strategy; 138 + Method : in Compression_Method := Deflated; 139 + Window_Bits : in Window_Bits_Type := Default_Window_Bits; 140 + Memory_Level : in Memory_Level_Type := Default_Memory_Level; 141 + Header : in Header_Type := Default); 142 + -- Compressor initialization. 143 + -- When Header parameter is Auto or Default, then default zlib header 144 + -- would be provided for compressed data. 145 + -- When Header is GZip, then gzip header would be set instead of 146 + -- default header. 147 + -- When Header is None, no header would be set for compressed data. 148 + 149 + procedure Inflate_Init 150 + (Filter : in out Filter_Type; 151 + Window_Bits : in Window_Bits_Type := Default_Window_Bits; 152 + Header : in Header_Type := Default); 153 + -- Decompressor initialization. 154 + -- Default header type mean that ZLib default header is expecting in the 155 + -- input compressed stream. 156 + -- Header type None mean that no header is expecting in the input stream. 157 + -- GZip header type mean that GZip header is expecting in the 158 + -- input compressed stream. 159 + -- Auto header type mean that header type (GZip or Native) would be 160 + -- detected automatically in the input stream. 161 + -- Note that header types parameter values None, GZip and Auto are 162 + -- supported for inflate routine only in ZLib versions 1.2.0.2 and later. 163 + -- Deflate_Init is supporting all header types. 164 + 165 + function Is_Open (Filter : in Filter_Type) return Boolean; 166 + pragma Inline (Is_Open); 167 + -- Is the filter opened for compression or decompression. 168 + 169 + procedure Close 170 + (Filter : in out Filter_Type; 171 + Ignore_Error : in Boolean := False); 172 + -- Closing the compression or decompressor. 173 + -- If stream is closing before the complete and Ignore_Error is False, 174 + -- The exception would be raised. 175 + 176 + generic 177 + with procedure Data_In 178 + (Item : out Ada.Streams.Stream_Element_Array; 179 + Last : out Ada.Streams.Stream_Element_Offset); 180 + with procedure Data_Out 181 + (Item : in Ada.Streams.Stream_Element_Array); 182 + procedure Generic_Translate 183 + (Filter : in out Filter_Type; 184 + In_Buffer_Size : in Integer := Default_Buffer_Size; 185 + Out_Buffer_Size : in Integer := Default_Buffer_Size); 186 + -- Compress/decompress data fetch from Data_In routine and pass the result 187 + -- to the Data_Out routine. User should provide Data_In and Data_Out 188 + -- for compression/decompression data flow. 189 + -- Compression or decompression depend on Filter initialization. 190 + 191 + function Total_In (Filter : in Filter_Type) return Count; 192 + pragma Inline (Total_In); 193 + -- Returns total number of input bytes read so far 194 + 195 + function Total_Out (Filter : in Filter_Type) return Count; 196 + pragma Inline (Total_Out); 197 + -- Returns total number of bytes output so far 198 + 199 + function CRC32 200 + (CRC : in Unsigned_32; 201 + Data : in Ada.Streams.Stream_Element_Array) 202 + return Unsigned_32; 203 + pragma Inline (CRC32); 204 + -- Compute CRC32, it could be necessary for make gzip format 205 + 206 + procedure CRC32 207 + (CRC : in out Unsigned_32; 208 + Data : in Ada.Streams.Stream_Element_Array); 209 + pragma Inline (CRC32); 210 + -- Compute CRC32, it could be necessary for make gzip format 211 + 212 + ------------------------------------------------- 213 + -- Below is more complex low level routines. -- 214 + ------------------------------------------------- 215 + 216 + procedure Translate 217 + (Filter : in out Filter_Type; 218 + In_Data : in Ada.Streams.Stream_Element_Array; 219 + In_Last : out Ada.Streams.Stream_Element_Offset; 220 + Out_Data : out Ada.Streams.Stream_Element_Array; 221 + Out_Last : out Ada.Streams.Stream_Element_Offset; 222 + Flush : in Flush_Mode); 223 + -- Compress/decompress the In_Data buffer and place the result into 224 + -- Out_Data. In_Last is the index of last element from In_Data accepted by 225 + -- the Filter. Out_Last is the last element of the received data from 226 + -- Filter. To tell the filter that incoming data are complete put the 227 + -- Flush parameter to Finish. 228 + 229 + function Stream_End (Filter : in Filter_Type) return Boolean; 230 + pragma Inline (Stream_End); 231 + -- Return the true when the stream is complete. 232 + 233 + procedure Flush 234 + (Filter : in out Filter_Type; 235 + Out_Data : out Ada.Streams.Stream_Element_Array; 236 + Out_Last : out Ada.Streams.Stream_Element_Offset; 237 + Flush : in Flush_Mode); 238 + pragma Inline (Flush); 239 + -- Flushing the data from the compressor. 240 + 241 + generic 242 + with procedure Write 243 + (Item : in Ada.Streams.Stream_Element_Array); 244 + -- User should provide this routine for accept 245 + -- compressed/decompressed data. 246 + 247 + Buffer_Size : in Ada.Streams.Stream_Element_Offset 248 + := Default_Buffer_Size; 249 + -- Buffer size for Write user routine. 250 + 251 + procedure Write 252 + (Filter : in out Filter_Type; 253 + Item : in Ada.Streams.Stream_Element_Array; 254 + Flush : in Flush_Mode := No_Flush); 255 + -- Compress/Decompress data from Item to the generic parameter procedure 256 + -- Write. Output buffer size could be set in Buffer_Size generic parameter. 257 + 258 + generic 259 + with procedure Read 260 + (Item : out Ada.Streams.Stream_Element_Array; 261 + Last : out Ada.Streams.Stream_Element_Offset); 262 + -- User should provide data for compression/decompression 263 + -- thru this routine. 264 + 265 + Buffer : in out Ada.Streams.Stream_Element_Array; 266 + -- Buffer for keep remaining data from the previous 267 + -- back read. 268 + 269 + Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; 270 + -- Rest_First have to be initialized to Buffer'Last + 1 271 + -- Rest_Last have to be initialized to Buffer'Last 272 + -- before usage. 273 + 274 + Allow_Read_Some : in Boolean := False; 275 + -- Is it allowed to return Last < Item'Last before end of data. 276 + 277 + procedure Read 278 + (Filter : in out Filter_Type; 279 + Item : out Ada.Streams.Stream_Element_Array; 280 + Last : out Ada.Streams.Stream_Element_Offset; 281 + Flush : in Flush_Mode := No_Flush); 282 + -- Compress/Decompress data from generic parameter procedure Read to the 283 + -- Item. User should provide Buffer and initialized Rest_First, Rest_Last 284 + -- indicators. If Allow_Read_Some is True, Read routines could return 285 + -- Last < Item'Last only at end of stream. 286 + 287 +private 288 + 289 + use Ada.Streams; 290 + 291 + pragma Assert (Ada.Streams.Stream_Element'Size = 8); 292 + pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8); 293 + 294 + type Flush_Mode is new Integer range 0 .. 5; 295 + 296 + type Compression_Method is new Integer range 8 .. 8; 297 + 298 + type Strategy_Type is new Integer range 0 .. 3; 299 + 300 + No_Flush : constant Flush_Mode := 0; 301 + Partial_Flush : constant Flush_Mode := 1; 302 + Sync_Flush : constant Flush_Mode := 2; 303 + Full_Flush : constant Flush_Mode := 3; 304 + Finish : constant Flush_Mode := 4; 305 + Block_Flush : constant Flush_Mode := 5; 306 + 307 + Filtered : constant Strategy_Type := 1; 308 + Huffman_Only : constant Strategy_Type := 2; 309 + RLE : constant Strategy_Type := 3; 310 + Default_Strategy : constant Strategy_Type := 0; 311 + 312 + Deflated : constant Compression_Method := 8; 313 + 314 + type Z_Stream; 315 + 316 + type Z_Stream_Access is access all Z_Stream; 317 + 318 + type Filter_Type is tagged limited record 319 + Strm : Z_Stream_Access; 320 + Compression : Boolean; 321 + Stream_End : Boolean; 322 + Header : Header_Type; 323 + CRC : Unsigned_32; 324 + Offset : Stream_Element_Offset; 325 + -- Offset for gzip header/footer output. 326 + end record; 327 + 328 +end ZLib;
Added compat/zlib/contrib/ada/zlib.gpr.
1 +project Zlib is 2 + 3 + for Languages use ("Ada"); 4 + for Source_Dirs use ("."); 5 + for Object_Dir use "."; 6 + for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo"); 7 + 8 + package Compiler is 9 + for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst"); 10 + end Compiler; 11 + 12 + package Linker is 13 + for Default_Switches ("ada") use ("-lz"); 14 + end Linker; 15 + 16 + package Builder is 17 + for Default_Switches ("ada") use ("-s", "-gnatQ"); 18 + end Builder; 19 + 20 +end Zlib;
Added compat/zlib/contrib/amd64/amd64-match.S.
1 +/* 2 + * match.S -- optimized version of longest_match() 3 + * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998 4 + * 5 + * This is free software; you can redistribute it and/or modify it 6 + * under the terms of the BSD License. Use by owners of Che Guevarra 7 + * parafernalia is prohibited, where possible, and highly discouraged 8 + * elsewhere. 9 + */ 10 + 11 +#ifndef NO_UNDERLINE 12 +# define match_init _match_init 13 +# define longest_match _longest_match 14 +#endif 15 + 16 +#define scanend ebx 17 +#define scanendw bx 18 +#define chainlenwmask edx /* high word: current chain len low word: s->wmask */ 19 +#define curmatch rsi 20 +#define curmatchd esi 21 +#define windowbestlen r8 22 +#define scanalign r9 23 +#define scanalignd r9d 24 +#define window r10 25 +#define bestlen r11 26 +#define bestlend r11d 27 +#define scanstart r12d 28 +#define scanstartw r12w 29 +#define scan r13 30 +#define nicematch r14d 31 +#define limit r15 32 +#define limitd r15d 33 +#define prev rcx 34 + 35 +/* 36 + * The 258 is a "magic number, not a parameter -- changing it 37 + * breaks the hell loose 38 + */ 39 +#define MAX_MATCH (258) 40 +#define MIN_MATCH (3) 41 +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) 42 +#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) 43 + 44 +/* stack frame offsets */ 45 +#define LocalVarsSize (112) 46 +#define _chainlenwmask ( 8-LocalVarsSize)(%rsp) 47 +#define _windowbestlen (16-LocalVarsSize)(%rsp) 48 +#define save_r14 (24-LocalVarsSize)(%rsp) 49 +#define save_rsi (32-LocalVarsSize)(%rsp) 50 +#define save_rbx (40-LocalVarsSize)(%rsp) 51 +#define save_r12 (56-LocalVarsSize)(%rsp) 52 +#define save_r13 (64-LocalVarsSize)(%rsp) 53 +#define save_r15 (80-LocalVarsSize)(%rsp) 54 + 55 + 56 +.globl match_init, longest_match 57 + 58 +/* 59 + * On AMD64 the first argument of a function (in our case -- the pointer to 60 + * deflate_state structure) is passed in %rdi, hence our offsets below are 61 + * all off of that. 62 + */ 63 + 64 +/* you can check the structure offset by running 65 + 66 +#include <stdlib.h> 67 +#include <stdio.h> 68 +#include "deflate.h" 69 + 70 +void print_depl() 71 +{ 72 +deflate_state ds; 73 +deflate_state *s=&ds; 74 +printf("size pointer=%u\n",(int)sizeof(void*)); 75 + 76 +printf("#define dsWSize (%3u)(%%rdi)\n",(int)(((char*)&(s->w_size))-((char*)s))); 77 +printf("#define dsWMask (%3u)(%%rdi)\n",(int)(((char*)&(s->w_mask))-((char*)s))); 78 +printf("#define dsWindow (%3u)(%%rdi)\n",(int)(((char*)&(s->window))-((char*)s))); 79 +printf("#define dsPrev (%3u)(%%rdi)\n",(int)(((char*)&(s->prev))-((char*)s))); 80 +printf("#define dsMatchLen (%3u)(%%rdi)\n",(int)(((char*)&(s->match_length))-((char*)s))); 81 +printf("#define dsPrevMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_match))-((char*)s))); 82 +printf("#define dsStrStart (%3u)(%%rdi)\n",(int)(((char*)&(s->strstart))-((char*)s))); 83 +printf("#define dsMatchStart (%3u)(%%rdi)\n",(int)(((char*)&(s->match_start))-((char*)s))); 84 +printf("#define dsLookahead (%3u)(%%rdi)\n",(int)(((char*)&(s->lookahead))-((char*)s))); 85 +printf("#define dsPrevLen (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_length))-((char*)s))); 86 +printf("#define dsMaxChainLen (%3u)(%%rdi)\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); 87 +printf("#define dsGoodMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->good_match))-((char*)s))); 88 +printf("#define dsNiceMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->nice_match))-((char*)s))); 89 +} 90 + 91 +*/ 92 + 93 + 94 +/* 95 + to compile for XCode 3.2 on MacOSX x86_64 96 + - run "gcc -g -c -DXCODE_MAC_X64_STRUCTURE amd64-match.S" 97 + */ 98 + 99 + 100 +#ifndef CURRENT_LINX_XCODE_MAC_X64_STRUCTURE 101 +#define dsWSize ( 68)(%rdi) 102 +#define dsWMask ( 76)(%rdi) 103 +#define dsWindow ( 80)(%rdi) 104 +#define dsPrev ( 96)(%rdi) 105 +#define dsMatchLen (144)(%rdi) 106 +#define dsPrevMatch (148)(%rdi) 107 +#define dsStrStart (156)(%rdi) 108 +#define dsMatchStart (160)(%rdi) 109 +#define dsLookahead (164)(%rdi) 110 +#define dsPrevLen (168)(%rdi) 111 +#define dsMaxChainLen (172)(%rdi) 112 +#define dsGoodMatch (188)(%rdi) 113 +#define dsNiceMatch (192)(%rdi) 114 + 115 +#else 116 + 117 +#ifndef STRUCT_OFFSET 118 +# define STRUCT_OFFSET (0) 119 +#endif 120 + 121 + 122 +#define dsWSize ( 56 + STRUCT_OFFSET)(%rdi) 123 +#define dsWMask ( 64 + STRUCT_OFFSET)(%rdi) 124 +#define dsWindow ( 72 + STRUCT_OFFSET)(%rdi) 125 +#define dsPrev ( 88 + STRUCT_OFFSET)(%rdi) 126 +#define dsMatchLen (136 + STRUCT_OFFSET)(%rdi) 127 +#define dsPrevMatch (140 + STRUCT_OFFSET)(%rdi) 128 +#define dsStrStart (148 + STRUCT_OFFSET)(%rdi) 129 +#define dsMatchStart (152 + STRUCT_OFFSET)(%rdi) 130 +#define dsLookahead (156 + STRUCT_OFFSET)(%rdi) 131 +#define dsPrevLen (160 + STRUCT_OFFSET)(%rdi) 132 +#define dsMaxChainLen (164 + STRUCT_OFFSET)(%rdi) 133 +#define dsGoodMatch (180 + STRUCT_OFFSET)(%rdi) 134 +#define dsNiceMatch (184 + STRUCT_OFFSET)(%rdi) 135 + 136 +#endif 137 + 138 + 139 + 140 + 141 +.text 142 + 143 +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ 144 + 145 +longest_match: 146 +/* 147 + * Retrieve the function arguments. %curmatch will hold cur_match 148 + * throughout the entire function (passed via rsi on amd64). 149 + * rdi will hold the pointer to the deflate_state (first arg on amd64) 150 + */ 151 + mov %rsi, save_rsi 152 + mov %rbx, save_rbx 153 + mov %r12, save_r12 154 + mov %r13, save_r13 155 + mov %r14, save_r14 156 + mov %r15, save_r15 157 + 158 +/* uInt wmask = s->w_mask; */ 159 +/* unsigned chain_length = s->max_chain_length; */ 160 +/* if (s->prev_length >= s->good_match) { */ 161 +/* chain_length >>= 2; */ 162 +/* } */ 163 + 164 + movl dsPrevLen, %eax 165 + movl dsGoodMatch, %ebx 166 + cmpl %ebx, %eax 167 + movl dsWMask, %eax 168 + movl dsMaxChainLen, %chainlenwmask 169 + jl LastMatchGood 170 + shrl $2, %chainlenwmask 171 +LastMatchGood: 172 + 173 +/* chainlen is decremented once beforehand so that the function can */ 174 +/* use the sign flag instead of the zero flag for the exit test. */ 175 +/* It is then shifted into the high word, to make room for the wmask */ 176 +/* value, which it will always accompany. */ 177 + 178 + decl %chainlenwmask 179 + shll $16, %chainlenwmask 180 + orl %eax, %chainlenwmask 181 + 182 +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ 183 + 184 + movl dsNiceMatch, %eax 185 + movl dsLookahead, %ebx 186 + cmpl %eax, %ebx 187 + jl LookaheadLess 188 + movl %eax, %ebx 189 +LookaheadLess: movl %ebx, %nicematch 190 + 191 +/* register Bytef *scan = s->window + s->strstart; */ 192 + 193 + mov dsWindow, %window 194 + movl dsStrStart, %limitd 195 + lea (%limit, %window), %scan 196 + 197 +/* Determine how many bytes the scan ptr is off from being */ 198 +/* dword-aligned. */ 199 + 200 + mov %scan, %scanalign 201 + negl %scanalignd 202 + andl $3, %scanalignd 203 + 204 +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ 205 +/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ 206 + 207 + movl dsWSize, %eax 208 + subl $MIN_LOOKAHEAD, %eax 209 + xorl %ecx, %ecx 210 + subl %eax, %limitd 211 + cmovng %ecx, %limitd 212 + 213 +/* int best_len = s->prev_length; */ 214 + 215 + movl dsPrevLen, %bestlend 216 + 217 +/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory. */ 218 + 219 + lea (%window, %bestlen), %windowbestlen 220 + mov %windowbestlen, _windowbestlen 221 + 222 +/* register ush scan_start = *(ushf*)scan; */ 223 +/* register ush scan_end = *(ushf*)(scan+best_len-1); */ 224 +/* Posf *prev = s->prev; */ 225 + 226 + movzwl (%scan), %scanstart 227 + movzwl -1(%scan, %bestlen), %scanend 228 + mov dsPrev, %prev 229 + 230 +/* Jump into the main loop. */ 231 + 232 + movl %chainlenwmask, _chainlenwmask 233 + jmp LoopEntry 234 + 235 +.balign 16 236 + 237 +/* do { 238 + * match = s->window + cur_match; 239 + * if (*(ushf*)(match+best_len-1) != scan_end || 240 + * *(ushf*)match != scan_start) continue; 241 + * [...] 242 + * } while ((cur_match = prev[cur_match & wmask]) > limit 243 + * && --chain_length != 0); 244 + * 245 + * Here is the inner loop of the function. The function will spend the 246 + * majority of its time in this loop, and majority of that time will 247 + * be spent in the first ten instructions. 248 + */ 249 +LookupLoop: 250 + andl %chainlenwmask, %curmatchd 251 + movzwl (%prev, %curmatch, 2), %curmatchd 252 + cmpl %limitd, %curmatchd 253 + jbe LeaveNow 254 + subl $0x00010000, %chainlenwmask 255 + js LeaveNow 256 +LoopEntry: cmpw -1(%windowbestlen, %curmatch), %scanendw 257 + jne LookupLoop 258 + cmpw %scanstartw, (%window, %curmatch) 259 + jne LookupLoop 260 + 261 +/* Store the current value of chainlen. */ 262 + movl %chainlenwmask, _chainlenwmask 263 + 264 +/* %scan is the string under scrutiny, and %prev to the string we */ 265 +/* are hoping to match it up with. In actuality, %esi and %edi are */ 266 +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ 267 +/* initialized to -(MAX_MATCH_8 - scanalign). */ 268 + 269 + mov $(-MAX_MATCH_8), %rdx 270 + lea (%curmatch, %window), %windowbestlen 271 + lea MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen 272 + lea MAX_MATCH_8(%scan, %scanalign), %prev 273 + 274 +/* the prefetching below makes very little difference... */ 275 + prefetcht1 (%windowbestlen, %rdx) 276 + prefetcht1 (%prev, %rdx) 277 + 278 +/* 279 + * Test the strings for equality, 8 bytes at a time. At the end, 280 + * adjust %rdx so that it is offset to the exact byte that mismatched. 281 + * 282 + * It should be confessed that this loop usually does not represent 283 + * much of the total running time. Replacing it with a more 284 + * straightforward "rep cmpsb" would not drastically degrade 285 + * performance -- unrolling it, for example, makes no difference. 286 + */ 287 + 288 +#undef USE_SSE /* works, but is 6-7% slower, than non-SSE... */ 289 + 290 +LoopCmps: 291 +#ifdef USE_SSE 292 + /* Preload the SSE registers */ 293 + movdqu (%windowbestlen, %rdx), %xmm1 294 + movdqu (%prev, %rdx), %xmm2 295 + pcmpeqb %xmm2, %xmm1 296 + movdqu 16(%windowbestlen, %rdx), %xmm3 297 + movdqu 16(%prev, %rdx), %xmm4 298 + pcmpeqb %xmm4, %xmm3 299 + movdqu 32(%windowbestlen, %rdx), %xmm5 300 + movdqu 32(%prev, %rdx), %xmm6 301 + pcmpeqb %xmm6, %xmm5 302 + movdqu 48(%windowbestlen, %rdx), %xmm7 303 + movdqu 48(%prev, %rdx), %xmm8 304 + pcmpeqb %xmm8, %xmm7 305 + 306 + /* Check the comparisions' results */ 307 + pmovmskb %xmm1, %rax 308 + notw %ax 309 + bsfw %ax, %ax 310 + jnz LeaveLoopCmps 311 + 312 + /* this is the only iteration of the loop with a possibility of having 313 + incremented rdx by 0x108 (each loop iteration add 16*4 = 0x40 314 + and (0x40*4)+8=0x108 */ 315 + add $8, %rdx 316 + jz LenMaximum 317 + add $8, %rdx 318 + 319 + 320 + pmovmskb %xmm3, %rax 321 + notw %ax 322 + bsfw %ax, %ax 323 + jnz LeaveLoopCmps 324 + 325 + 326 + add $16, %rdx 327 + 328 + 329 + pmovmskb %xmm5, %rax 330 + notw %ax 331 + bsfw %ax, %ax 332 + jnz LeaveLoopCmps 333 + 334 + add $16, %rdx 335 + 336 + 337 + pmovmskb %xmm7, %rax 338 + notw %ax 339 + bsfw %ax, %ax 340 + jnz LeaveLoopCmps 341 + 342 + add $16, %rdx 343 + 344 + jmp LoopCmps 345 +LeaveLoopCmps: add %rax, %rdx 346 +#else 347 + mov (%windowbestlen, %rdx), %rax 348 + xor (%prev, %rdx), %rax 349 + jnz LeaveLoopCmps 350 + 351 + mov 8(%windowbestlen, %rdx), %rax 352 + xor 8(%prev, %rdx), %rax 353 + jnz LeaveLoopCmps8 354 + 355 + mov 16(%windowbestlen, %rdx), %rax 356 + xor 16(%prev, %rdx), %rax 357 + jnz LeaveLoopCmps16 358 + 359 + add $24, %rdx 360 + jnz LoopCmps 361 + jmp LenMaximum 362 +# if 0 363 +/* 364 + * This three-liner is tantalizingly simple, but bsf is a slow instruction, 365 + * and the complicated alternative down below is quite a bit faster. Sad... 366 + */ 367 + 368 +LeaveLoopCmps: bsf %rax, %rax /* find the first non-zero bit */ 369 + shrl $3, %eax /* divide by 8 to get the byte */ 370 + add %rax, %rdx 371 +# else 372 +LeaveLoopCmps16: 373 + add $8, %rdx 374 +LeaveLoopCmps8: 375 + add $8, %rdx 376 +LeaveLoopCmps: testl $0xFFFFFFFF, %eax /* Check the first 4 bytes */ 377 + jnz Check16 378 + add $4, %rdx 379 + shr $32, %rax 380 +Check16: testw $0xFFFF, %ax 381 + jnz LenLower 382 + add $2, %rdx 383 + shrl $16, %eax 384 +LenLower: subb $1, %al 385 + adc $0, %rdx 386 +# endif 387 +#endif 388 + 389 +/* Calculate the length of the match. If it is longer than MAX_MATCH, */ 390 +/* then automatically accept it as the best possible match and leave. */ 391 + 392 + lea (%prev, %rdx), %rax 393 + sub %scan, %rax 394 + cmpl $MAX_MATCH, %eax 395 + jge LenMaximum 396 + 397 +/* If the length of the match is not longer than the best match we */ 398 +/* have so far, then forget it and return to the lookup loop. */ 399 + 400 + cmpl %bestlend, %eax 401 + jg LongerMatch 402 + mov _windowbestlen, %windowbestlen 403 + mov dsPrev, %prev 404 + movl _chainlenwmask, %edx 405 + jmp LookupLoop 406 + 407 +/* s->match_start = cur_match; */ 408 +/* best_len = len; */ 409 +/* if (len >= nice_match) break; */ 410 +/* scan_end = *(ushf*)(scan+best_len-1); */ 411 + 412 +LongerMatch: 413 + movl %eax, %bestlend 414 + movl %curmatchd, dsMatchStart 415 + cmpl %nicematch, %eax 416 + jge LeaveNow 417 + 418 + lea (%window, %bestlen), %windowbestlen 419 + mov %windowbestlen, _windowbestlen 420 + 421 + movzwl -1(%scan, %rax), %scanend 422 + mov dsPrev, %prev 423 + movl _chainlenwmask, %chainlenwmask 424 + jmp LookupLoop 425 + 426 +/* Accept the current string, with the maximum possible length. */ 427 + 428 +LenMaximum: 429 + movl $MAX_MATCH, %bestlend 430 + movl %curmatchd, dsMatchStart 431 + 432 +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ 433 +/* return s->lookahead; */ 434 + 435 +LeaveNow: 436 + movl dsLookahead, %eax 437 + cmpl %eax, %bestlend 438 + cmovngl %bestlend, %eax 439 +LookaheadRet: 440 + 441 +/* Restore the registers and return from whence we came. */ 442 + 443 + mov save_rsi, %rsi 444 + mov save_rbx, %rbx 445 + mov save_r12, %r12 446 + mov save_r13, %r13 447 + mov save_r14, %r14 448 + mov save_r15, %r15 449 + 450 + ret 451 + 452 +match_init: ret
Added compat/zlib/contrib/asm686/README.686.
1 +This is a patched version of zlib, modified to use 2 +Pentium-Pro-optimized assembly code in the deflation algorithm. The 3 +files changed/added by this patch are: 4 + 5 +README.686 6 +match.S 7 + 8 +The speedup that this patch provides varies, depending on whether the 9 +compiler used to build the original version of zlib falls afoul of the 10 +PPro's speed traps. My own tests show a speedup of around 10-20% at 11 +the default compression level, and 20-30% using -9, against a version 12 +compiled using gcc 2.7.2.3. Your mileage may vary. 13 + 14 +Note that this code has been tailored for the PPro/PII in particular, 15 +and will not perform particuarly well on a Pentium. 16 + 17 +If you are using an assembler other than GNU as, you will have to 18 +translate match.S to use your assembler's syntax. (Have fun.) 19 + 20 +Brian Raiter 21 +breadbox@muppetlabs.com 22 +April, 1998 23 + 24 + 25 +Added for zlib 1.1.3: 26 + 27 +The patches come from 28 +http://www.muppetlabs.com/~breadbox/software/assembly.html 29 + 30 +To compile zlib with this asm file, copy match.S to the zlib directory 31 +then do: 32 + 33 +CFLAGS="-O3 -DASMV" ./configure 34 +make OBJA=match.o 35 + 36 + 37 +Update: 38 + 39 +I've been ignoring these assembly routines for years, believing that 40 +gcc's generated code had caught up with it sometime around gcc 2.95 41 +and the major rearchitecting of the Pentium 4. However, I recently 42 +learned that, despite what I believed, this code still has some life 43 +in it. On the Pentium 4 and AMD64 chips, it continues to run about 8% 44 +faster than the code produced by gcc 4.1. 45 + 46 +In acknowledgement of its continuing usefulness, I've altered the 47 +license to match that of the rest of zlib. Share and Enjoy! 48 + 49 +Brian Raiter 50 +breadbox@muppetlabs.com 51 +April, 2007
Added compat/zlib/contrib/asm686/match.S.
1 +/* match.S -- x86 assembly version of the zlib longest_match() function. 2 + * Optimized for the Intel 686 chips (PPro and later). 3 + * 4 + * Copyright (C) 1998, 2007 Brian Raiter <breadbox@muppetlabs.com> 5 + * 6 + * This software is provided 'as-is', without any express or implied 7 + * warranty. In no event will the author be held liable for any damages 8 + * arising from the use of this software. 9 + * 10 + * Permission is granted to anyone to use this software for any purpose, 11 + * including commercial applications, and to alter it and redistribute it 12 + * freely, subject to the following restrictions: 13 + * 14 + * 1. The origin of this software must not be misrepresented; you must not 15 + * claim that you wrote the original software. If you use this software 16 + * in a product, an acknowledgment in the product documentation would be 17 + * appreciated but is not required. 18 + * 2. Altered source versions must be plainly marked as such, and must not be 19 + * misrepresented as being the original software. 20 + * 3. This notice may not be removed or altered from any source distribution. 21 + */ 22 + 23 +#ifndef NO_UNDERLINE 24 +#define match_init _match_init 25 +#define longest_match _longest_match 26 +#endif 27 + 28 +#define MAX_MATCH (258) 29 +#define MIN_MATCH (3) 30 +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) 31 +#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) 32 + 33 +/* stack frame offsets */ 34 + 35 +#define chainlenwmask 0 /* high word: current chain len */ 36 + /* low word: s->wmask */ 37 +#define window 4 /* local copy of s->window */ 38 +#define windowbestlen 8 /* s->window + bestlen */ 39 +#define scanstart 16 /* first two bytes of string */ 40 +#define scanend 12 /* last two bytes of string */ 41 +#define scanalign 20 /* dword-misalignment of string */ 42 +#define nicematch 24 /* a good enough match size */ 43 +#define bestlen 28 /* size of best match so far */ 44 +#define scan 32 /* ptr to string wanting match */ 45 + 46 +#define LocalVarsSize (36) 47 +/* saved ebx 36 */ 48 +/* saved edi 40 */ 49 +/* saved esi 44 */ 50 +/* saved ebp 48 */ 51 +/* return address 52 */ 52 +#define deflatestate 56 /* the function arguments */ 53 +#define curmatch 60 54 + 55 +/* All the +zlib1222add offsets are due to the addition of fields 56 + * in zlib in the deflate_state structure since the asm code was first written 57 + * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). 58 + * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). 59 + * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). 60 + */ 61 + 62 +#define zlib1222add (8) 63 + 64 +#define dsWSize (36+zlib1222add) 65 +#define dsWMask (44+zlib1222add) 66 +#define dsWindow (48+zlib1222add) 67 +#define dsPrev (56+zlib1222add) 68 +#define dsMatchLen (88+zlib1222add) 69 +#define dsPrevMatch (92+zlib1222add) 70 +#define dsStrStart (100+zlib1222add) 71 +#define dsMatchStart (104+zlib1222add) 72 +#define dsLookahead (108+zlib1222add) 73 +#define dsPrevLen (112+zlib1222add) 74 +#define dsMaxChainLen (116+zlib1222add) 75 +#define dsGoodMatch (132+zlib1222add) 76 +#define dsNiceMatch (136+zlib1222add) 77 + 78 + 79 +.file "match.S" 80 + 81 +.globl match_init, longest_match 82 + 83 +.text 84 + 85 +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ 86 +.cfi_sections .debug_frame 87 + 88 +longest_match: 89 + 90 +.cfi_startproc 91 +/* Save registers that the compiler may be using, and adjust %esp to */ 92 +/* make room for our stack frame. */ 93 + 94 + pushl %ebp 95 + .cfi_def_cfa_offset 8 96 + .cfi_offset ebp, -8 97 + pushl %edi 98 + .cfi_def_cfa_offset 12 99 + pushl %esi 100 + .cfi_def_cfa_offset 16 101 + pushl %ebx 102 + .cfi_def_cfa_offset 20 103 + subl $LocalVarsSize, %esp 104 + .cfi_def_cfa_offset LocalVarsSize+20 105 + 106 +/* Retrieve the function arguments. %ecx will hold cur_match */ 107 +/* throughout the entire function. %edx will hold the pointer to the */ 108 +/* deflate_state structure during the function's setup (before */ 109 +/* entering the main loop). */ 110 + 111 + movl deflatestate(%esp), %edx 112 + movl curmatch(%esp), %ecx 113 + 114 +/* uInt wmask = s->w_mask; */ 115 +/* unsigned chain_length = s->max_chain_length; */ 116 +/* if (s->prev_length >= s->good_match) { */ 117 +/* chain_length >>= 2; */ 118 +/* } */ 119 + 120 + movl dsPrevLen(%edx), %eax 121 + movl dsGoodMatch(%edx), %ebx 122 + cmpl %ebx, %eax 123 + movl dsWMask(%edx), %eax 124 + movl dsMaxChainLen(%edx), %ebx 125 + jl LastMatchGood 126 + shrl $2, %ebx 127 +LastMatchGood: 128 + 129 +/* chainlen is decremented once beforehand so that the function can */ 130 +/* use the sign flag instead of the zero flag for the exit test. */ 131 +/* It is then shifted into the high word, to make room for the wmask */ 132 +/* value, which it will always accompany. */ 133 + 134 + decl %ebx 135 + shll $16, %ebx 136 + orl %eax, %ebx 137 + movl %ebx, chainlenwmask(%esp) 138 + 139 +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ 140 + 141 + movl dsNiceMatch(%edx), %eax 142 + movl dsLookahead(%edx), %ebx 143 + cmpl %eax, %ebx 144 + jl LookaheadLess 145 + movl %eax, %ebx 146 +LookaheadLess: movl %ebx, nicematch(%esp) 147 + 148 +/* register Bytef *scan = s->window + s->strstart; */ 149 + 150 + movl dsWindow(%edx), %esi 151 + movl %esi, window(%esp) 152 + movl dsStrStart(%edx), %ebp 153 + lea (%esi,%ebp), %edi 154 + movl %edi, scan(%esp) 155 + 156 +/* Determine how many bytes the scan ptr is off from being */ 157 +/* dword-aligned. */ 158 + 159 + movl %edi, %eax 160 + negl %eax 161 + andl $3, %eax 162 + movl %eax, scanalign(%esp) 163 + 164 +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ 165 +/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ 166 + 167 + movl dsWSize(%edx), %eax 168 + subl $MIN_LOOKAHEAD, %eax 169 + subl %eax, %ebp 170 + jg LimitPositive 171 + xorl %ebp, %ebp 172 +LimitPositive: 173 + 174 +/* int best_len = s->prev_length; */ 175 + 176 + movl dsPrevLen(%edx), %eax 177 + movl %eax, bestlen(%esp) 178 + 179 +/* Store the sum of s->window + best_len in %esi locally, and in %esi. */ 180 + 181 + addl %eax, %esi 182 + movl %esi, windowbestlen(%esp) 183 + 184 +/* register ush scan_start = *(ushf*)scan; */ 185 +/* register ush scan_end = *(ushf*)(scan+best_len-1); */ 186 +/* Posf *prev = s->prev; */ 187 + 188 + movzwl (%edi), %ebx 189 + movl %ebx, scanstart(%esp) 190 + movzwl -1(%edi,%eax), %ebx 191 + movl %ebx, scanend(%esp) 192 + movl dsPrev(%edx), %edi 193 + 194 +/* Jump into the main loop. */ 195 + 196 + movl chainlenwmask(%esp), %edx 197 + jmp LoopEntry 198 + 199 +.balign 16 200 + 201 +/* do { 202 + * match = s->window + cur_match; 203 + * if (*(ushf*)(match+best_len-1) != scan_end || 204 + * *(ushf*)match != scan_start) continue; 205 + * [...] 206 + * } while ((cur_match = prev[cur_match & wmask]) > limit 207 + * && --chain_length != 0); 208 + * 209 + * Here is the inner loop of the function. The function will spend the 210 + * majority of its time in this loop, and majority of that time will 211 + * be spent in the first ten instructions. 212 + * 213 + * Within this loop: 214 + * %ebx = scanend 215 + * %ecx = curmatch 216 + * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) 217 + * %esi = windowbestlen - i.e., (window + bestlen) 218 + * %edi = prev 219 + * %ebp = limit 220 + */ 221 +LookupLoop: 222 + andl %edx, %ecx 223 + movzwl (%edi,%ecx,2), %ecx 224 + cmpl %ebp, %ecx 225 + jbe LeaveNow 226 + subl $0x00010000, %edx 227 + js LeaveNow 228 +LoopEntry: movzwl -1(%esi,%ecx), %eax 229 + cmpl %ebx, %eax 230 + jnz LookupLoop 231 + movl window(%esp), %eax 232 + movzwl (%eax,%ecx), %eax 233 + cmpl scanstart(%esp), %eax 234 + jnz LookupLoop 235 + 236 +/* Store the current value of chainlen. */ 237 + 238 + movl %edx, chainlenwmask(%esp) 239 + 240 +/* Point %edi to the string under scrutiny, and %esi to the string we */ 241 +/* are hoping to match it up with. In actuality, %esi and %edi are */ 242 +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ 243 +/* initialized to -(MAX_MATCH_8 - scanalign). */ 244 + 245 + movl window(%esp), %esi 246 + movl scan(%esp), %edi 247 + addl %ecx, %esi 248 + movl scanalign(%esp), %eax 249 + movl $(-MAX_MATCH_8), %edx 250 + lea MAX_MATCH_8(%edi,%eax), %edi 251 + lea MAX_MATCH_8(%esi,%eax), %esi 252 + 253 +/* Test the strings for equality, 8 bytes at a time. At the end, 254 + * adjust %edx so that it is offset to the exact byte that mismatched. 255 + * 256 + * We already know at this point that the first three bytes of the 257 + * strings match each other, and they can be safely passed over before 258 + * starting the compare loop. So what this code does is skip over 0-3 259 + * bytes, as much as necessary in order to dword-align the %edi 260 + * pointer. (%esi will still be misaligned three times out of four.) 261 + * 262 + * It should be confessed that this loop usually does not represent 263 + * much of the total running time. Replacing it with a more 264 + * straightforward "rep cmpsb" would not drastically degrade 265 + * performance. 266 + */ 267 +LoopCmps: 268 + movl (%esi,%edx), %eax 269 + xorl (%edi,%edx), %eax 270 + jnz LeaveLoopCmps 271 + movl 4(%esi,%edx), %eax 272 + xorl 4(%edi,%edx), %eax 273 + jnz LeaveLoopCmps4 274 + addl $8, %edx 275 + jnz LoopCmps 276 + jmp LenMaximum 277 +LeaveLoopCmps4: addl $4, %edx 278 +LeaveLoopCmps: testl $0x0000FFFF, %eax 279 + jnz LenLower 280 + addl $2, %edx 281 + shrl $16, %eax 282 +LenLower: subb $1, %al 283 + adcl $0, %edx 284 + 285 +/* Calculate the length of the match. If it is longer than MAX_MATCH, */ 286 +/* then automatically accept it as the best possible match and leave. */ 287 + 288 + lea (%edi,%edx), %eax 289 + movl scan(%esp), %edi 290 + subl %edi, %eax 291 + cmpl $MAX_MATCH, %eax 292 + jge LenMaximum 293 + 294 +/* If the length of the match is not longer than the best match we */ 295 +/* have so far, then forget it and return to the lookup loop. */ 296 + 297 + movl deflatestate(%esp), %edx 298 + movl bestlen(%esp), %ebx 299 + cmpl %ebx, %eax 300 + jg LongerMatch 301 + movl windowbestlen(%esp), %esi 302 + movl dsPrev(%edx), %edi 303 + movl scanend(%esp), %ebx 304 + movl chainlenwmask(%esp), %edx 305 + jmp LookupLoop 306 + 307 +/* s->match_start = cur_match; */ 308 +/* best_len = len; */ 309 +/* if (len >= nice_match) break; */ 310 +/* scan_end = *(ushf*)(scan+best_len-1); */ 311 + 312 +LongerMatch: movl nicematch(%esp), %ebx 313 + movl %eax, bestlen(%esp) 314 + movl %ecx, dsMatchStart(%edx) 315 + cmpl %ebx, %eax 316 + jge LeaveNow 317 + movl window(%esp), %esi 318 + addl %eax, %esi 319 + movl %esi, windowbestlen(%esp) 320 + movzwl -1(%edi,%eax), %ebx 321 + movl dsPrev(%edx), %edi 322 + movl %ebx, scanend(%esp) 323 + movl chainlenwmask(%esp), %edx 324 + jmp LookupLoop 325 + 326 +/* Accept the current string, with the maximum possible length. */ 327 + 328 +LenMaximum: movl deflatestate(%esp), %edx 329 + movl $MAX_MATCH, bestlen(%esp) 330 + movl %ecx, dsMatchStart(%edx) 331 + 332 +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ 333 +/* return s->lookahead; */ 334 + 335 +LeaveNow: 336 + movl deflatestate(%esp), %edx 337 + movl bestlen(%esp), %ebx 338 + movl dsLookahead(%edx), %eax 339 + cmpl %eax, %ebx 340 + jg LookaheadRet 341 + movl %ebx, %eax 342 +LookaheadRet: 343 + 344 +/* Restore the stack and return from whence we came. */ 345 + 346 + addl $LocalVarsSize, %esp 347 + .cfi_def_cfa_offset 20 348 + popl %ebx 349 + .cfi_def_cfa_offset 16 350 + popl %esi 351 + .cfi_def_cfa_offset 12 352 + popl %edi 353 + .cfi_def_cfa_offset 8 354 + popl %ebp 355 + .cfi_def_cfa_offset 4 356 +.cfi_endproc 357 +match_init: ret
Added compat/zlib/contrib/blast/Makefile.
1 +blast: blast.c blast.h 2 + cc -DTEST -o blast blast.c 3 + 4 +test: blast 5 + blast < test.pk | cmp - test.txt 6 + 7 +clean: 8 + rm -f blast blast.o
Added compat/zlib/contrib/blast/README.
1 +Read blast.h for purpose and usage. 2 + 3 +Mark Adler 4 +madler@alumni.caltech.edu
Added compat/zlib/contrib/blast/blast.c.
1 +/* blast.c 2 + * Copyright (C) 2003 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in blast.h 4 + * version 1.1, 16 Feb 2003 5 + * 6 + * blast.c decompresses data compressed by the PKWare Compression Library. 7 + * This function provides functionality similar to the explode() function of 8 + * the PKWare library, hence the name "blast". 9 + * 10 + * This decompressor is based on the excellent format description provided by 11 + * Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the 12 + * example Ben provided in the post is incorrect. The distance 110001 should 13 + * instead be 111000. When corrected, the example byte stream becomes: 14 + * 15 + * 00 04 82 24 25 8f 80 7f 16 + * 17 + * which decompresses to "AIAIAIAIAIAIA" (without the quotes). 18 + */ 19 + 20 +/* 21 + * Change history: 22 + * 23 + * 1.0 12 Feb 2003 - First version 24 + * 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data 25 + */ 26 + 27 +#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ 28 +#include "blast.h" /* prototype for blast() */ 29 + 30 +#define local static /* for local function definitions */ 31 +#define MAXBITS 13 /* maximum code length */ 32 +#define MAXWIN 4096 /* maximum window size */ 33 + 34 +/* input and output state */ 35 +struct state { 36 + /* input state */ 37 + blast_in infun; /* input function provided by user */ 38 + void *inhow; /* opaque information passed to infun() */ 39 + unsigned char *in; /* next input location */ 40 + unsigned left; /* available input at in */ 41 + int bitbuf; /* bit buffer */ 42 + int bitcnt; /* number of bits in bit buffer */ 43 + 44 + /* input limit error return state for bits() and decode() */ 45 + jmp_buf env; 46 + 47 + /* output state */ 48 + blast_out outfun; /* output function provided by user */ 49 + void *outhow; /* opaque information passed to outfun() */ 50 + unsigned next; /* index of next write location in out[] */ 51 + int first; /* true to check distances (for first 4K) */ 52 + unsigned char out[MAXWIN]; /* output buffer and sliding window */ 53 +}; 54 + 55 +/* 56 + * Return need bits from the input stream. This always leaves less than 57 + * eight bits in the buffer. bits() works properly for need == 0. 58 + * 59 + * Format notes: 60 + * 61 + * - Bits are stored in bytes from the least significant bit to the most 62 + * significant bit. Therefore bits are dropped from the bottom of the bit 63 + * buffer, using shift right, and new bytes are appended to the top of the 64 + * bit buffer, using shift left. 65 + */ 66 +local int bits(struct state *s, int need) 67 +{ 68 + int val; /* bit accumulator */ 69 + 70 + /* load at least need bits into val */ 71 + val = s->bitbuf; 72 + while (s->bitcnt < need) { 73 + if (s->left == 0) { 74 + s->left = s->infun(s->inhow, &(s->in)); 75 + if (s->left == 0) longjmp(s->env, 1); /* out of input */ 76 + } 77 + val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */ 78 + s->left--; 79 + s->bitcnt += 8; 80 + } 81 + 82 + /* drop need bits and update buffer, always zero to seven bits left */ 83 + s->bitbuf = val >> need; 84 + s->bitcnt -= need; 85 + 86 + /* return need bits, zeroing the bits above that */ 87 + return val & ((1 << need) - 1); 88 +} 89 + 90 +/* 91 + * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of 92 + * each length, which for a canonical code are stepped through in order. 93 + * symbol[] are the symbol values in canonical order, where the number of 94 + * entries is the sum of the counts in count[]. The decoding process can be 95 + * seen in the function decode() below. 96 + */ 97 +struct huffman { 98 + short *count; /* number of symbols of each length */ 99 + short *symbol; /* canonically ordered symbols */ 100 +}; 101 + 102 +/* 103 + * Decode a code from the stream s using huffman table h. Return the symbol or 104 + * a negative value if there is an error. If all of the lengths are zero, i.e. 105 + * an empty code, or if the code is incomplete and an invalid code is received, 106 + * then -9 is returned after reading MAXBITS bits. 107 + * 108 + * Format notes: 109 + * 110 + * - The codes as stored in the compressed data are bit-reversed relative to 111 + * a simple integer ordering of codes of the same lengths. Hence below the 112 + * bits are pulled from the compressed data one at a time and used to 113 + * build the code value reversed from what is in the stream in order to 114 + * permit simple integer comparisons for decoding. 115 + * 116 + * - The first code for the shortest length is all ones. Subsequent codes of 117 + * the same length are simply integer decrements of the previous code. When 118 + * moving up a length, a one bit is appended to the code. For a complete 119 + * code, the last code of the longest length will be all zeros. To support 120 + * this ordering, the bits pulled during decoding are inverted to apply the 121 + * more "natural" ordering starting with all zeros and incrementing. 122 + */ 123 +local int decode(struct state *s, struct huffman *h) 124 +{ 125 + int len; /* current number of bits in code */ 126 + int code; /* len bits being decoded */ 127 + int first; /* first code of length len */ 128 + int count; /* number of codes of length len */ 129 + int index; /* index of first code of length len in symbol table */ 130 + int bitbuf; /* bits from stream */ 131 + int left; /* bits left in next or left to process */ 132 + short *next; /* next number of codes */ 133 + 134 + bitbuf = s->bitbuf; 135 + left = s->bitcnt; 136 + code = first = index = 0; 137 + len = 1; 138 + next = h->count + 1; 139 + while (1) { 140 + while (left--) { 141 + code |= (bitbuf & 1) ^ 1; /* invert code */ 142 + bitbuf >>= 1; 143 + count = *next++; 144 + if (code < first + count) { /* if length len, return symbol */ 145 + s->bitbuf = bitbuf; 146 + s->bitcnt = (s->bitcnt - len) & 7; 147 + return h->symbol[index + (code - first)]; 148 + } 149 + index += count; /* else update for next length */ 150 + first += count; 151 + first <<= 1; 152 + code <<= 1; 153 + len++; 154 + } 155 + left = (MAXBITS+1) - len; 156 + if (left == 0) break; 157 + if (s->left == 0) { 158 + s->left = s->infun(s->inhow, &(s->in)); 159 + if (s->left == 0) longjmp(s->env, 1); /* out of input */ 160 + } 161 + bitbuf = *(s->in)++; 162 + s->left--; 163 + if (left > 8) left = 8; 164 + } 165 + return -9; /* ran out of codes */ 166 +} 167 + 168 +/* 169 + * Given a list of repeated code lengths rep[0..n-1], where each byte is a 170 + * count (high four bits + 1) and a code length (low four bits), generate the 171 + * list of code lengths. This compaction reduces the size of the object code. 172 + * Then given the list of code lengths length[0..n-1] representing a canonical 173 + * Huffman code for n symbols, construct the tables required to decode those 174 + * codes. Those tables are the number of codes of each length, and the symbols 175 + * sorted by length, retaining their original order within each length. The 176 + * return value is zero for a complete code set, negative for an over- 177 + * subscribed code set, and positive for an incomplete code set. The tables 178 + * can be used if the return value is zero or positive, but they cannot be used 179 + * if the return value is negative. If the return value is zero, it is not 180 + * possible for decode() using that table to return an error--any stream of 181 + * enough bits will resolve to a symbol. If the return value is positive, then 182 + * it is possible for decode() using that table to return an error for received 183 + * codes past the end of the incomplete lengths. 184 + */ 185 +local int construct(struct huffman *h, const unsigned char *rep, int n) 186 +{ 187 + int symbol; /* current symbol when stepping through length[] */ 188 + int len; /* current length when stepping through h->count[] */ 189 + int left; /* number of possible codes left of current length */ 190 + short offs[MAXBITS+1]; /* offsets in symbol table for each length */ 191 + short length[256]; /* code lengths */ 192 + 193 + /* convert compact repeat counts into symbol bit length list */ 194 + symbol = 0; 195 + do { 196 + len = *rep++; 197 + left = (len >> 4) + 1; 198 + len &= 15; 199 + do { 200 + length[symbol++] = len; 201 + } while (--left); 202 + } while (--n); 203 + n = symbol; 204 + 205 + /* count number of codes of each length */ 206 + for (len = 0; len <= MAXBITS; len++) 207 + h->count[len] = 0; 208 + for (symbol = 0; symbol < n; symbol++) 209 + (h->count[length[symbol]])++; /* assumes lengths are within bounds */ 210 + if (h->count[0] == n) /* no codes! */ 211 + return 0; /* complete, but decode() will fail */ 212 + 213 + /* check for an over-subscribed or incomplete set of lengths */ 214 + left = 1; /* one possible code of zero length */ 215 + for (len = 1; len <= MAXBITS; len++) { 216 + left <<= 1; /* one more bit, double codes left */ 217 + left -= h->count[len]; /* deduct count from possible codes */ 218 + if (left < 0) return left; /* over-subscribed--return negative */ 219 + } /* left > 0 means incomplete */ 220 + 221 + /* generate offsets into symbol table for each length for sorting */ 222 + offs[1] = 0; 223 + for (len = 1; len < MAXBITS; len++) 224 + offs[len + 1] = offs[len] + h->count[len]; 225 + 226 + /* 227 + * put symbols in table sorted by length, by symbol order within each 228 + * length 229 + */ 230 + for (symbol = 0; symbol < n; symbol++) 231 + if (length[symbol] != 0) 232 + h->symbol[offs[length[symbol]]++] = symbol; 233 + 234 + /* return zero for complete set, positive for incomplete set */ 235 + return left; 236 +} 237 + 238 +/* 239 + * Decode PKWare Compression Library stream. 240 + * 241 + * Format notes: 242 + * 243 + * - First byte is 0 if literals are uncoded or 1 if they are coded. Second 244 + * byte is 4, 5, or 6 for the number of extra bits in the distance code. 245 + * This is the base-2 logarithm of the dictionary size minus six. 246 + * 247 + * - Compressed data is a combination of literals and length/distance pairs 248 + * terminated by an end code. Literals are either Huffman coded or 249 + * uncoded bytes. A length/distance pair is a coded length followed by a 250 + * coded distance to represent a string that occurs earlier in the 251 + * uncompressed data that occurs again at the current location. 252 + * 253 + * - A bit preceding a literal or length/distance pair indicates which comes 254 + * next, 0 for literals, 1 for length/distance. 255 + * 256 + * - If literals are uncoded, then the next eight bits are the literal, in the 257 + * normal bit order in th stream, i.e. no bit-reversal is needed. Similarly, 258 + * no bit reversal is needed for either the length extra bits or the distance 259 + * extra bits. 260 + * 261 + * - Literal bytes are simply written to the output. A length/distance pair is 262 + * an instruction to copy previously uncompressed bytes to the output. The 263 + * copy is from distance bytes back in the output stream, copying for length 264 + * bytes. 265 + * 266 + * - Distances pointing before the beginning of the output data are not 267 + * permitted. 268 + * 269 + * - Overlapped copies, where the length is greater than the distance, are 270 + * allowed and common. For example, a distance of one and a length of 518 271 + * simply copies the last byte 518 times. A distance of four and a length of 272 + * twelve copies the last four bytes three times. A simple forward copy 273 + * ignoring whether the length is greater than the distance or not implements 274 + * this correctly. 275 + */ 276 +local int decomp(struct state *s) 277 +{ 278 + int lit; /* true if literals are coded */ 279 + int dict; /* log2(dictionary size) - 6 */ 280 + int symbol; /* decoded symbol, extra bits for distance */ 281 + int len; /* length for copy */ 282 + int dist; /* distance for copy */ 283 + int copy; /* copy counter */ 284 + unsigned char *from, *to; /* copy pointers */ 285 + static int virgin = 1; /* build tables once */ 286 + static short litcnt[MAXBITS+1], litsym[256]; /* litcode memory */ 287 + static short lencnt[MAXBITS+1], lensym[16]; /* lencode memory */ 288 + static short distcnt[MAXBITS+1], distsym[64]; /* distcode memory */ 289 + static struct huffman litcode = {litcnt, litsym}; /* length code */ 290 + static struct huffman lencode = {lencnt, lensym}; /* length code */ 291 + static struct huffman distcode = {distcnt, distsym};/* distance code */ 292 + /* bit lengths of literal codes */ 293 + static const unsigned char litlen[] = { 294 + 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8, 295 + 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5, 296 + 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12, 297 + 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27, 298 + 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45, 299 + 44, 173}; 300 + /* bit lengths of length codes 0..15 */ 301 + static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23}; 302 + /* bit lengths of distance codes 0..63 */ 303 + static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248}; 304 + static const short base[16] = { /* base for length codes */ 305 + 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264}; 306 + static const char extra[16] = { /* extra bits for length codes */ 307 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}; 308 + 309 + /* set up decoding tables (once--might not be thread-safe) */ 310 + if (virgin) { 311 + construct(&litcode, litlen, sizeof(litlen)); 312 + construct(&lencode, lenlen, sizeof(lenlen)); 313 + construct(&distcode, distlen, sizeof(distlen)); 314 + virgin = 0; 315 + } 316 + 317 + /* read header */ 318 + lit = bits(s, 8); 319 + if (lit > 1) return -1; 320 + dict = bits(s, 8); 321 + if (dict < 4 || dict > 6) return -2; 322 + 323 + /* decode literals and length/distance pairs */ 324 + do { 325 + if (bits(s, 1)) { 326 + /* get length */ 327 + symbol = decode(s, &lencode); 328 + len = base[symbol] + bits(s, extra[symbol]); 329 + if (len == 519) break; /* end code */ 330 + 331 + /* get distance */ 332 + symbol = len == 2 ? 2 : dict; 333 + dist = decode(s, &distcode) << symbol; 334 + dist += bits(s, symbol); 335 + dist++; 336 + if (s->first && dist > s->next) 337 + return -3; /* distance too far back */ 338 + 339 + /* copy length bytes from distance bytes back */ 340 + do { 341 + to = s->out + s->next; 342 + from = to - dist; 343 + copy = MAXWIN; 344 + if (s->next < dist) { 345 + from += copy; 346 + copy = dist; 347 + } 348 + copy -= s->next; 349 + if (copy > len) copy = len; 350 + len -= copy; 351 + s->next += copy; 352 + do { 353 + *to++ = *from++; 354 + } while (--copy); 355 + if (s->next == MAXWIN) { 356 + if (s->outfun(s->outhow, s->out, s->next)) return 1; 357 + s->next = 0; 358 + s->first = 0; 359 + } 360 + } while (len != 0); 361 + } 362 + else { 363 + /* get literal and write it */ 364 + symbol = lit ? decode(s, &litcode) : bits(s, 8); 365 + s->out[s->next++] = symbol; 366 + if (s->next == MAXWIN) { 367 + if (s->outfun(s->outhow, s->out, s->next)) return 1; 368 + s->next = 0; 369 + s->first = 0; 370 + } 371 + } 372 + } while (1); 373 + return 0; 374 +} 375 + 376 +/* See comments in blast.h */ 377 +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow) 378 +{ 379 + struct state s; /* input/output state */ 380 + int err; /* return value */ 381 + 382 + /* initialize input state */ 383 + s.infun = infun; 384 + s.inhow = inhow; 385 + s.left = 0; 386 + s.bitbuf = 0; 387 + s.bitcnt = 0; 388 + 389 + /* initialize output state */ 390 + s.outfun = outfun; 391 + s.outhow = outhow; 392 + s.next = 0; 393 + s.first = 1; 394 + 395 + /* return if bits() or decode() tries to read past available input */ 396 + if (setjmp(s.env) != 0) /* if came back here via longjmp(), */ 397 + err = 2; /* then skip decomp(), return error */ 398 + else 399 + err = decomp(&s); /* decompress */ 400 + 401 + /* write any leftover output and update the error code if needed */ 402 + if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0) 403 + err = 1; 404 + return err; 405 +} 406 + 407 +#ifdef TEST 408 +/* Example of how to use blast() */ 409 +#include <stdio.h> 410 +#include <stdlib.h> 411 + 412 +#define CHUNK 16384 413 + 414 +local unsigned inf(void *how, unsigned char **buf) 415 +{ 416 + static unsigned char hold[CHUNK]; 417 + 418 + *buf = hold; 419 + return fread(hold, 1, CHUNK, (FILE *)how); 420 +} 421 + 422 +local int outf(void *how, unsigned char *buf, unsigned len) 423 +{ 424 + return fwrite(buf, 1, len, (FILE *)how) != len; 425 +} 426 + 427 +/* Decompress a PKWare Compression Library stream from stdin to stdout */ 428 +int main(void) 429 +{ 430 + int ret, n; 431 + 432 + /* decompress to stdout */ 433 + ret = blast(inf, stdin, outf, stdout); 434 + if (ret != 0) fprintf(stderr, "blast error: %d\n", ret); 435 + 436 + /* see if there are any leftover bytes */ 437 + n = 0; 438 + while (getchar() != EOF) n++; 439 + if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n); 440 + 441 + /* return blast() error code */ 442 + return ret; 443 +} 444 +#endif
Added compat/zlib/contrib/blast/blast.h.
1 +/* blast.h -- interface for blast.c 2 + Copyright (C) 2003 Mark Adler 3 + version 1.1, 16 Feb 2003 4 + 5 + This software is provided 'as-is', without any express or implied 6 + warranty. In no event will the author be held liable for any damages 7 + arising from the use of this software. 8 + 9 + Permission is granted to anyone to use this software for any purpose, 10 + including commercial applications, and to alter it and redistribute it 11 + freely, subject to the following restrictions: 12 + 13 + 1. The origin of this software must not be misrepresented; you must not 14 + claim that you wrote the original software. If you use this software 15 + in a product, an acknowledgment in the product documentation would be 16 + appreciated but is not required. 17 + 2. Altered source versions must be plainly marked as such, and must not be 18 + misrepresented as being the original software. 19 + 3. This notice may not be removed or altered from any source distribution. 20 + 21 + Mark Adler madler@alumni.caltech.edu 22 + */ 23 + 24 + 25 +/* 26 + * blast() decompresses the PKWare Data Compression Library (DCL) compressed 27 + * format. It provides the same functionality as the explode() function in 28 + * that library. (Note: PKWare overused the "implode" verb, and the format 29 + * used by their library implode() function is completely different and 30 + * incompatible with the implode compression method supported by PKZIP.) 31 + */ 32 + 33 + 34 +typedef unsigned (*blast_in)(void *how, unsigned char **buf); 35 +typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); 36 +/* Definitions for input/output functions passed to blast(). See below for 37 + * what the provided functions need to do. 38 + */ 39 + 40 + 41 +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow); 42 +/* Decompress input to output using the provided infun() and outfun() calls. 43 + * On success, the return value of blast() is zero. If there is an error in 44 + * the source data, i.e. it is not in the proper format, then a negative value 45 + * is returned. If there is not enough input available or there is not enough 46 + * output space, then a positive error is returned. 47 + * 48 + * The input function is invoked: len = infun(how, &buf), where buf is set by 49 + * infun() to point to the input buffer, and infun() returns the number of 50 + * available bytes there. If infun() returns zero, then blast() returns with 51 + * an input error. (blast() only asks for input if it needs it.) inhow is for 52 + * use by the application to pass an input descriptor to infun(), if desired. 53 + * 54 + * The output function is invoked: err = outfun(how, buf, len), where the bytes 55 + * to be written are buf[0..len-1]. If err is not zero, then blast() returns 56 + * with an output error. outfun() is always called with len <= 4096. outhow 57 + * is for use by the application to pass an output descriptor to outfun(), if 58 + * desired. 59 + * 60 + * The return codes are: 61 + * 62 + * 2: ran out of input before completing decompression 63 + * 1: output error before completing decompression 64 + * 0: successful decompression 65 + * -1: literal flag not zero or one 66 + * -2: dictionary size not in 4..6 67 + * -3: distance is too far back 68 + * 69 + * At the bottom of blast.c is an example program that uses blast() that can be 70 + * compiled to produce a command-line decompression filter by defining TEST. 71 + */
Added compat/zlib/contrib/blast/test.pk.
cannot compute difference between binary files
Added compat/zlib/contrib/blast/test.txt.
1 +AIAIAIAIAIAIA
Added compat/zlib/contrib/delphi/ZLib.pas.
1 +{*******************************************************} 2 +{ } 3 +{ Borland Delphi Supplemental Components } 4 +{ ZLIB Data Compression Interface Unit } 5 +{ } 6 +{ Copyright (c) 1997,99 Borland Corporation } 7 +{ } 8 +{*******************************************************} 9 + 10 +{ Updated for zlib 1.2.x by Cosmin Truta <cosmint@cs.ubbcluj.ro> } 11 + 12 +unit ZLib; 13 + 14 +interface 15 + 16 +uses SysUtils, Classes; 17 + 18 +type 19 + TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer; cdecl; 20 + TFree = procedure (AppData, Block: Pointer); cdecl; 21 + 22 + // Internal structure. Ignore. 23 + TZStreamRec = packed record 24 + next_in: PChar; // next input byte 25 + avail_in: Integer; // number of bytes available at next_in 26 + total_in: Longint; // total nb of input bytes read so far 27 + 28 + next_out: PChar; // next output byte should be put here 29 + avail_out: Integer; // remaining free space at next_out 30 + total_out: Longint; // total nb of bytes output so far 31 + 32 + msg: PChar; // last error message, NULL if no error 33 + internal: Pointer; // not visible by applications 34 + 35 + zalloc: TAlloc; // used to allocate the internal state 36 + zfree: TFree; // used to free the internal state 37 + AppData: Pointer; // private data object passed to zalloc and zfree 38 + 39 + data_type: Integer; // best guess about the data type: ascii or binary 40 + adler: Longint; // adler32 value of the uncompressed data 41 + reserved: Longint; // reserved for future use 42 + end; 43 + 44 + // Abstract ancestor class 45 + TCustomZlibStream = class(TStream) 46 + private 47 + FStrm: TStream; 48 + FStrmPos: Integer; 49 + FOnProgress: TNotifyEvent; 50 + FZRec: TZStreamRec; 51 + FBuffer: array [Word] of Char; 52 + protected 53 + procedure Progress(Sender: TObject); dynamic; 54 + property OnProgress: TNotifyEvent read FOnProgress write FOnProgress; 55 + constructor Create(Strm: TStream); 56 + end; 57 + 58 +{ TCompressionStream compresses data on the fly as data is written to it, and 59 + stores the compressed data to another stream. 60 + 61 + TCompressionStream is write-only and strictly sequential. Reading from the 62 + stream will raise an exception. Using Seek to move the stream pointer 63 + will raise an exception. 64 + 65 + Output data is cached internally, written to the output stream only when 66 + the internal output buffer is full. All pending output data is flushed 67 + when the stream is destroyed. 68 + 69 + The Position property returns the number of uncompressed bytes of 70 + data that have been written to the stream so far. 71 + 72 + CompressionRate returns the on-the-fly percentage by which the original 73 + data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100 74 + If raw data size = 100 and compressed data size = 25, the CompressionRate 75 + is 75% 76 + 77 + The OnProgress event is called each time the output buffer is filled and 78 + written to the output stream. This is useful for updating a progress 79 + indicator when you are writing a large chunk of data to the compression 80 + stream in a single call.} 81 + 82 + 83 + TCompressionLevel = (clNone, clFastest, clDefault, clMax); 84 + 85 + TCompressionStream = class(TCustomZlibStream) 86 + private 87 + function GetCompressionRate: Single; 88 + public 89 + constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream); 90 + destructor Destroy; override; 91 + function Read(var Buffer; Count: Longint): Longint; override; 92 + function Write(const Buffer; Count: Longint): Longint; override; 93 + function Seek(Offset: Longint; Origin: Word): Longint; override; 94 + property CompressionRate: Single read GetCompressionRate; 95 + property OnProgress; 96 + end; 97 + 98 +{ TDecompressionStream decompresses data on the fly as data is read from it. 99 + 100 + Compressed data comes from a separate source stream. TDecompressionStream 101 + is read-only and unidirectional; you can seek forward in the stream, but not 102 + backwards. The special case of setting the stream position to zero is 103 + allowed. Seeking forward decompresses data until the requested position in 104 + the uncompressed data has been reached. Seeking backwards, seeking relative 105 + to the end of the stream, requesting the size of the stream, and writing to 106 + the stream will raise an exception. 107 + 108 + The Position property returns the number of bytes of uncompressed data that 109 + have been read from the stream so far. 110 + 111 + The OnProgress event is called each time the internal input buffer of 112 + compressed data is exhausted and the next block is read from the input stream. 113 + This is useful for updating a progress indicator when you are reading a 114 + large chunk of data from the decompression stream in a single call.} 115 + 116 + TDecompressionStream = class(TCustomZlibStream) 117 + public 118 + constructor Create(Source: TStream); 119 + destructor Destroy; override; 120 + function Read(var Buffer; Count: Longint): Longint; override; 121 + function Write(const Buffer; Count: Longint): Longint; override; 122 + function Seek(Offset: Longint; Origin: Word): Longint; override; 123 + property OnProgress; 124 + end; 125 + 126 + 127 + 128 +{ CompressBuf compresses data, buffer to buffer, in one call. 129 + In: InBuf = ptr to compressed data 130 + InBytes = number of bytes in InBuf 131 + Out: OutBuf = ptr to newly allocated buffer containing decompressed data 132 + OutBytes = number of bytes in OutBuf } 133 +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; 134 + out OutBuf: Pointer; out OutBytes: Integer); 135 + 136 + 137 +{ DecompressBuf decompresses data, buffer to buffer, in one call. 138 + In: InBuf = ptr to compressed data 139 + InBytes = number of bytes in InBuf 140 + OutEstimate = zero, or est. size of the decompressed data 141 + Out: OutBuf = ptr to newly allocated buffer containing decompressed data 142 + OutBytes = number of bytes in OutBuf } 143 +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; 144 + OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); 145 + 146 +{ DecompressToUserBuf decompresses data, buffer to buffer, in one call. 147 + In: InBuf = ptr to compressed data 148 + InBytes = number of bytes in InBuf 149 + Out: OutBuf = ptr to user-allocated buffer to contain decompressed data 150 + BufSize = number of bytes in OutBuf } 151 +procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; 152 + const OutBuf: Pointer; BufSize: Integer); 153 + 154 +const 155 + zlib_version = '1.2.7'; 156 + 157 +type 158 + EZlibError = class(Exception); 159 + ECompressionError = class(EZlibError); 160 + EDecompressionError = class(EZlibError); 161 + 162 +implementation 163 + 164 +uses ZLibConst; 165 + 166 +const 167 + Z_NO_FLUSH = 0; 168 + Z_PARTIAL_FLUSH = 1; 169 + Z_SYNC_FLUSH = 2; 170 + Z_FULL_FLUSH = 3; 171 + Z_FINISH = 4; 172 + 173 + Z_OK = 0; 174 + Z_STREAM_END = 1; 175 + Z_NEED_DICT = 2; 176 + Z_ERRNO = (-1); 177 + Z_STREAM_ERROR = (-2); 178 + Z_DATA_ERROR = (-3); 179 + Z_MEM_ERROR = (-4); 180 + Z_BUF_ERROR = (-5); 181 + Z_VERSION_ERROR = (-6); 182 + 183 + Z_NO_COMPRESSION = 0; 184 + Z_BEST_SPEED = 1; 185 + Z_BEST_COMPRESSION = 9; 186 + Z_DEFAULT_COMPRESSION = (-1); 187 + 188 + Z_FILTERED = 1; 189 + Z_HUFFMAN_ONLY = 2; 190 + Z_RLE = 3; 191 + Z_DEFAULT_STRATEGY = 0; 192 + 193 + Z_BINARY = 0; 194 + Z_ASCII = 1; 195 + Z_UNKNOWN = 2; 196 + 197 + Z_DEFLATED = 8; 198 + 199 + 200 +{$L adler32.obj} 201 +{$L compress.obj} 202 +{$L crc32.obj} 203 +{$L deflate.obj} 204 +{$L infback.obj} 205 +{$L inffast.obj} 206 +{$L inflate.obj} 207 +{$L inftrees.obj} 208 +{$L trees.obj} 209 +{$L uncompr.obj} 210 +{$L zutil.obj} 211 + 212 +procedure adler32; external; 213 +procedure compressBound; external; 214 +procedure crc32; external; 215 +procedure deflateInit2_; external; 216 +procedure deflateParams; external; 217 + 218 +function _malloc(Size: Integer): Pointer; cdecl; 219 +begin 220 + Result := AllocMem(Size); 221 +end; 222 + 223 +procedure _free(Block: Pointer); cdecl; 224 +begin 225 + FreeMem(Block); 226 +end; 227 + 228 +procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; 229 +begin 230 + FillChar(P^, count, B); 231 +end; 232 + 233 +procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; 234 +begin 235 + Move(source^, dest^, count); 236 +end; 237 + 238 + 239 + 240 +// deflate compresses data 241 +function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar; 242 + recsize: Integer): Integer; external; 243 +function deflate(var strm: TZStreamRec; flush: Integer): Integer; external; 244 +function deflateEnd(var strm: TZStreamRec): Integer; external; 245 + 246 +// inflate decompresses data 247 +function inflateInit_(var strm: TZStreamRec; version: PChar; 248 + recsize: Integer): Integer; external; 249 +function inflate(var strm: TZStreamRec; flush: Integer): Integer; external; 250 +function inflateEnd(var strm: TZStreamRec): Integer; external; 251 +function inflateReset(var strm: TZStreamRec): Integer; external; 252 + 253 + 254 +function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl; 255 +begin 256 +// GetMem(Result, Items*Size); 257 + Result := AllocMem(Items * Size); 258 +end; 259 + 260 +procedure zlibFreeMem(AppData, Block: Pointer); cdecl; 261 +begin 262 + FreeMem(Block); 263 +end; 264 + 265 +{function zlibCheck(code: Integer): Integer; 266 +begin 267 + Result := code; 268 + if code < 0 then 269 + raise EZlibError.Create('error'); //!! 270 +end;} 271 + 272 +function CCheck(code: Integer): Integer; 273 +begin 274 + Result := code; 275 + if code < 0 then 276 + raise ECompressionError.Create('error'); //!! 277 +end; 278 + 279 +function DCheck(code: Integer): Integer; 280 +begin 281 + Result := code; 282 + if code < 0 then 283 + raise EDecompressionError.Create('error'); //!! 284 +end; 285 + 286 +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; 287 + out OutBuf: Pointer; out OutBytes: Integer); 288 +var 289 + strm: TZStreamRec; 290 + P: Pointer; 291 +begin 292 + FillChar(strm, sizeof(strm), 0); 293 + strm.zalloc := zlibAllocMem; 294 + strm.zfree := zlibFreeMem; 295 + OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255; 296 + GetMem(OutBuf, OutBytes); 297 + try 298 + strm.next_in := InBuf; 299 + strm.avail_in := InBytes; 300 + strm.next_out := OutBuf; 301 + strm.avail_out := OutBytes; 302 + CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm))); 303 + try 304 + while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do 305 + begin 306 + P := OutBuf; 307 + Inc(OutBytes, 256); 308 + ReallocMem(OutBuf, OutBytes); 309 + strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 310 + strm.avail_out := 256; 311 + end; 312 + finally 313 + CCheck(deflateEnd(strm)); 314 + end; 315 + ReallocMem(OutBuf, strm.total_out); 316 + OutBytes := strm.total_out; 317 + except 318 + FreeMem(OutBuf); 319 + raise 320 + end; 321 +end; 322 + 323 + 324 +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; 325 + OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); 326 +var 327 + strm: TZStreamRec; 328 + P: Pointer; 329 + BufInc: Integer; 330 +begin 331 + FillChar(strm, sizeof(strm), 0); 332 + strm.zalloc := zlibAllocMem; 333 + strm.zfree := zlibFreeMem; 334 + BufInc := (InBytes + 255) and not 255; 335 + if OutEstimate = 0 then 336 + OutBytes := BufInc 337 + else 338 + OutBytes := OutEstimate; 339 + GetMem(OutBuf, OutBytes); 340 + try 341 + strm.next_in := InBuf; 342 + strm.avail_in := InBytes; 343 + strm.next_out := OutBuf; 344 + strm.avail_out := OutBytes; 345 + DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); 346 + try 347 + while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do 348 + begin 349 + P := OutBuf; 350 + Inc(OutBytes, BufInc); 351 + ReallocMem(OutBuf, OutBytes); 352 + strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 353 + strm.avail_out := BufInc; 354 + end; 355 + finally 356 + DCheck(inflateEnd(strm)); 357 + end; 358 + ReallocMem(OutBuf, strm.total_out); 359 + OutBytes := strm.total_out; 360 + except 361 + FreeMem(OutBuf); 362 + raise 363 + end; 364 +end; 365 + 366 +procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; 367 + const OutBuf: Pointer; BufSize: Integer); 368 +var 369 + strm: TZStreamRec; 370 +begin 371 + FillChar(strm, sizeof(strm), 0); 372 + strm.zalloc := zlibAllocMem; 373 + strm.zfree := zlibFreeMem; 374 + strm.next_in := InBuf; 375 + strm.avail_in := InBytes; 376 + strm.next_out := OutBuf; 377 + strm.avail_out := BufSize; 378 + DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); 379 + try 380 + if DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END then 381 + raise EZlibError.CreateRes(@sTargetBufferTooSmall); 382 + finally 383 + DCheck(inflateEnd(strm)); 384 + end; 385 +end; 386 + 387 +// TCustomZlibStream 388 + 389 +constructor TCustomZLibStream.Create(Strm: TStream); 390 +begin 391 + inherited Create; 392 + FStrm := Strm; 393 + FStrmPos := Strm.Position; 394 + FZRec.zalloc := zlibAllocMem; 395 + FZRec.zfree := zlibFreeMem; 396 +end; 397 + 398 +procedure TCustomZLibStream.Progress(Sender: TObject); 399 +begin 400 + if Assigned(FOnProgress) then FOnProgress(Sender); 401 +end; 402 + 403 + 404 +// TCompressionStream 405 + 406 +constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel; 407 + Dest: TStream); 408 +const 409 + Levels: array [TCompressionLevel] of ShortInt = 410 + (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION); 411 +begin 412 + inherited Create(Dest); 413 + FZRec.next_out := FBuffer; 414 + FZRec.avail_out := sizeof(FBuffer); 415 + CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec))); 416 +end; 417 + 418 +destructor TCompressionStream.Destroy; 419 +begin 420 + FZRec.next_in := nil; 421 + FZRec.avail_in := 0; 422 + try 423 + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; 424 + while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END) 425 + and (FZRec.avail_out = 0) do 426 + begin 427 + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); 428 + FZRec.next_out := FBuffer; 429 + FZRec.avail_out := sizeof(FBuffer); 430 + end; 431 + if FZRec.avail_out < sizeof(FBuffer) then 432 + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out); 433 + finally 434 + deflateEnd(FZRec); 435 + end; 436 + inherited Destroy; 437 +end; 438 + 439 +function TCompressionStream.Read(var Buffer; Count: Longint): Longint; 440 +begin 441 + raise ECompressionError.CreateRes(@sInvalidStreamOp); 442 +end; 443 + 444 +function TCompressionStream.Write(const Buffer; Count: Longint): Longint; 445 +begin 446 + FZRec.next_in := @Buffer; 447 + FZRec.avail_in := Count; 448 + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; 449 + while (FZRec.avail_in > 0) do 450 + begin 451 + CCheck(deflate(FZRec, 0)); 452 + if FZRec.avail_out = 0 then 453 + begin 454 + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); 455 + FZRec.next_out := FBuffer; 456 + FZRec.avail_out := sizeof(FBuffer); 457 + FStrmPos := FStrm.Position; 458 + Progress(Self); 459 + end; 460 + end; 461 + Result := Count; 462 +end; 463 + 464 +function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint; 465 +begin 466 + if (Offset = 0) and (Origin = soFromCurrent) then 467 + Result := FZRec.total_in 468 + else 469 + raise ECompressionError.CreateRes(@sInvalidStreamOp); 470 +end; 471 + 472 +function TCompressionStream.GetCompressionRate: Single; 473 +begin 474 + if FZRec.total_in = 0 then 475 + Result := 0 476 + else 477 + Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0; 478 +end; 479 + 480 + 481 +// TDecompressionStream 482 + 483 +constructor TDecompressionStream.Create(Source: TStream); 484 +begin 485 + inherited Create(Source); 486 + FZRec.next_in := FBuffer; 487 + FZRec.avail_in := 0; 488 + DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec))); 489 +end; 490 + 491 +destructor TDecompressionStream.Destroy; 492 +begin 493 + FStrm.Seek(-FZRec.avail_in, 1); 494 + inflateEnd(FZRec); 495 + inherited Destroy; 496 +end; 497 + 498 +function TDecompressionStream.Read(var Buffer; Count: Longint): Longint; 499 +begin 500 + FZRec.next_out := @Buffer; 501 + FZRec.avail_out := Count; 502 + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; 503 + while (FZRec.avail_out > 0) do 504 + begin 505 + if FZRec.avail_in = 0 then 506 + begin 507 + FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer)); 508 + if FZRec.avail_in = 0 then 509 + begin 510 + Result := Count - FZRec.avail_out; 511 + Exit; 512 + end; 513 + FZRec.next_in := FBuffer; 514 + FStrmPos := FStrm.Position; 515 + Progress(Self); 516 + end; 517 + CCheck(inflate(FZRec, 0)); 518 + end; 519 + Result := Count; 520 +end; 521 + 522 +function TDecompressionStream.Write(const Buffer; Count: Longint): Longint; 523 +begin 524 + raise EDecompressionError.CreateRes(@sInvalidStreamOp); 525 +end; 526 + 527 +function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint; 528 +var 529 + I: Integer; 530 + Buf: array [0..4095] of Char; 531 +begin 532 + if (Offset = 0) and (Origin = soFromBeginning) then 533 + begin 534 + DCheck(inflateReset(FZRec)); 535 + FZRec.next_in := FBuffer; 536 + FZRec.avail_in := 0; 537 + FStrm.Position := 0; 538 + FStrmPos := 0; 539 + end 540 + else if ( (Offset >= 0) and (Origin = soFromCurrent)) or 541 + ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then 542 + begin 543 + if Origin = soFromBeginning then Dec(Offset, FZRec.total_out); 544 + if Offset > 0 then 545 + begin 546 + for I := 1 to Offset div sizeof(Buf) do 547 + ReadBuffer(Buf, sizeof(Buf)); 548 + ReadBuffer(Buf, Offset mod sizeof(Buf)); 549 + end; 550 + end 551 + else 552 + raise EDecompressionError.CreateRes(@sInvalidStreamOp); 553 + Result := FZRec.total_out; 554 +end; 555 + 556 + 557 +end.
Added compat/zlib/contrib/delphi/ZLibConst.pas.
1 +unit ZLibConst; 2 + 3 +interface 4 + 5 +resourcestring 6 + sTargetBufferTooSmall = 'ZLib error: target buffer may be too small'; 7 + sInvalidStreamOp = 'Invalid stream operation'; 8 + 9 +implementation 10 + 11 +end.
Added compat/zlib/contrib/delphi/readme.txt.
1 + 2 +Overview 3 +======== 4 + 5 +This directory contains an update to the ZLib interface unit, 6 +distributed by Borland as a Delphi supplemental component. 7 + 8 +The original ZLib unit is Copyright (c) 1997,99 Borland Corp., 9 +and is based on zlib version 1.0.4. There are a series of bugs 10 +and security problems associated with that old zlib version, and 11 +we recommend the users to update their ZLib unit. 12 + 13 + 14 +Summary of modifications 15 +======================== 16 + 17 +- Improved makefile, adapted to zlib version 1.2.1. 18 + 19 +- Some field types from TZStreamRec are changed from Integer to 20 + Longint, for consistency with the zlib.h header, and for 64-bit 21 + readiness. 22 + 23 +- The zlib_version constant is updated. 24 + 25 +- The new Z_RLE strategy has its corresponding symbolic constant. 26 + 27 +- The allocation and deallocation functions and function types 28 + (TAlloc, TFree, zlibAllocMem and zlibFreeMem) are now cdecl, 29 + and _malloc and _free are added as C RTL stubs. As a result, 30 + the original C sources of zlib can be compiled out of the box, 31 + and linked to the ZLib unit. 32 + 33 + 34 +Suggestions for improvements 35 +============================ 36 + 37 +Currently, the ZLib unit provides only a limited wrapper around 38 +the zlib library, and much of the original zlib functionality is 39 +missing. Handling compressed file formats like ZIP/GZIP or PNG 40 +cannot be implemented without having this functionality. 41 +Applications that handle these formats are either using their own, 42 +duplicated code, or not using the ZLib unit at all. 43 + 44 +Here are a few suggestions: 45 + 46 +- Checksum class wrappers around adler32() and crc32(), similar 47 + to the Java classes that implement the java.util.zip.Checksum 48 + interface. 49 + 50 +- The ability to read and write raw deflate streams, without the 51 + zlib stream header and trailer. Raw deflate streams are used 52 + in the ZIP file format. 53 + 54 +- The ability to read and write gzip streams, used in the GZIP 55 + file format, and normally produced by the gzip program. 56 + 57 +- The ability to select a different compression strategy, useful 58 + to PNG and MNG image compression, and to multimedia compression 59 + in general. Besides the compression level 60 + 61 + TCompressionLevel = (clNone, clFastest, clDefault, clMax); 62 + 63 + which, in fact, could have used the 'z' prefix and avoided 64 + TColor-like symbols 65 + 66 + TCompressionLevel = (zcNone, zcFastest, zcDefault, zcMax); 67 + 68 + there could be a compression strategy 69 + 70 + TCompressionStrategy = (zsDefault, zsFiltered, zsHuffmanOnly, zsRle); 71 + 72 +- ZIP and GZIP stream handling via TStreams. 73 + 74 + 75 +-- 76 +Cosmin Truta <cosmint@cs.ubbcluj.ro>
Added compat/zlib/contrib/delphi/zlibd32.mak.
1 +# Makefile for zlib 2 +# For use with Delphi and C++ Builder under Win32 3 +# Updated for zlib 1.2.x by Cosmin Truta 4 + 5 +# ------------ Borland C++ ------------ 6 + 7 +# This project uses the Delphi (fastcall/register) calling convention: 8 +LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl 9 + 10 +CC = bcc32 11 +LD = bcc32 12 +AR = tlib 13 +# do not use "-pr" in CFLAGS 14 +CFLAGS = -a -d -k- -O2 $(LOC) 15 +LDFLAGS = 16 + 17 + 18 +# variables 19 +ZLIB_LIB = zlib.lib 20 + 21 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 22 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 23 +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj 24 +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 25 + 26 + 27 +# targets 28 +all: $(ZLIB_LIB) example.exe minigzip.exe 29 + 30 +.c.obj: 31 + $(CC) -c $(CFLAGS) $*.c 32 + 33 +adler32.obj: adler32.c zlib.h zconf.h 34 + 35 +compress.obj: compress.c zlib.h zconf.h 36 + 37 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 38 + 39 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 40 + 41 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 42 + 43 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 44 + 45 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 46 + 47 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 48 + 49 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 50 + inffast.h inffixed.h 51 + 52 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 53 + inffast.h 54 + 55 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 56 + inffast.h inffixed.h 57 + 58 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 59 + 60 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 61 + 62 +uncompr.obj: uncompr.c zlib.h zconf.h 63 + 64 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 65 + 66 +example.obj: test/example.c zlib.h zconf.h 67 + 68 +minigzip.obj: test/minigzip.c zlib.h zconf.h 69 + 70 + 71 +# For the sake of the old Borland make, 72 +# the command line is cut to fit in the MS-DOS 128 byte limit: 73 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) 74 + -del $(ZLIB_LIB) 75 + $(AR) $(ZLIB_LIB) $(OBJP1) 76 + $(AR) $(ZLIB_LIB) $(OBJP2) 77 + 78 + 79 +# testing 80 +test: example.exe minigzip.exe 81 + example 82 + echo hello world | minigzip | minigzip -d 83 + 84 +example.exe: example.obj $(ZLIB_LIB) 85 + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) 86 + 87 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 88 + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) 89 + 90 + 91 +# cleanup 92 +clean: 93 + -del *.obj 94 + -del *.exe 95 + -del *.lib 96 + -del *.tds 97 + -del zlib.bak 98 + -del foo.gz 99 +
Added compat/zlib/contrib/dotzlib/DotZLib.build.
1 +<?xml version="1.0" encoding="utf-8" ?> 2 +<project name="DotZLib" default="build" basedir="./DotZLib"> 3 + <description>A .Net wrapper library around ZLib1.dll</description> 4 + 5 + <property name="nunit.location" value="c:/program files/NUnit V2.1/bin" /> 6 + <property name="build.root" value="bin" /> 7 + 8 + <property name="debug" value="true" /> 9 + <property name="nunit" value="true" /> 10 + 11 + <property name="build.folder" value="${build.root}/debug/" if="${debug}" /> 12 + <property name="build.folder" value="${build.root}/release/" unless="${debug}" /> 13 + 14 + <target name="clean" description="Remove all generated files"> 15 + <delete dir="${build.root}" failonerror="false" /> 16 + </target> 17 + 18 + <target name="build" description="compiles the source code"> 19 + 20 + <mkdir dir="${build.folder}" /> 21 + <csc target="library" output="${build.folder}DotZLib.dll" debug="${debug}"> 22 + <references basedir="${nunit.location}"> 23 + <includes if="${nunit}" name="nunit.framework.dll" /> 24 + </references> 25 + <sources> 26 + <includes name="*.cs" /> 27 + <excludes name="UnitTests.cs" unless="${nunit}" /> 28 + </sources> 29 + <arg value="/d:nunit" if="${nunit}" /> 30 + </csc> 31 + </target> 32 + 33 +</project>
Added compat/zlib/contrib/dotzlib/DotZLib.chm.
cannot compute difference between binary files
Added compat/zlib/contrib/dotzlib/DotZLib.sln.
1 +Microsoft Visual Studio Solution File, Format Version 8.00 2 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotZLib", "DotZLib\DotZLib.csproj", "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" 3 + ProjectSection(ProjectDependencies) = postProject 4 + EndProjectSection 5 +EndProject 6 +Global 7 + GlobalSection(SolutionConfiguration) = preSolution 8 + Debug = Debug 9 + Release = Release 10 + EndGlobalSection 11 + GlobalSection(ProjectConfiguration) = postSolution 12 + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.ActiveCfg = Debug|.NET 13 + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.Build.0 = Debug|.NET 14 + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.ActiveCfg = Release|.NET 15 + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.Build.0 = Release|.NET 16 + EndGlobalSection 17 + GlobalSection(ExtensibilityGlobals) = postSolution 18 + EndGlobalSection 19 + GlobalSection(ExtensibilityAddIns) = postSolution 20 + EndGlobalSection 21 +EndGlobal
Added compat/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs.
1 +using System.Reflection; 2 +using System.Runtime.CompilerServices; 3 + 4 +// 5 +// General Information about an assembly is controlled through the following 6 +// set of attributes. Change these attribute values to modify the information 7 +// associated with an assembly. 8 +// 9 +[assembly: AssemblyTitle("DotZLib")] 10 +[assembly: AssemblyDescription(".Net bindings for ZLib compression dll 1.2.x")] 11 +[assembly: AssemblyConfiguration("")] 12 +[assembly: AssemblyCompany("Henrik Ravn")] 13 +[assembly: AssemblyProduct("")] 14 +[assembly: AssemblyCopyright("(c) 2004 by Henrik Ravn")] 15 +[assembly: AssemblyTrademark("")] 16 +[assembly: AssemblyCulture("")] 17 + 18 +// 19 +// Version information for an assembly consists of the following four values: 20 +// 21 +// Major Version 22 +// Minor Version 23 +// Build Number 24 +// Revision 25 +// 26 +// You can specify all the values or you can default the Revision and Build Numbers 27 +// by using the '*' as shown below: 28 + 29 +[assembly: AssemblyVersion("1.0.*")] 30 + 31 +// 32 +// In order to sign your assembly you must specify a key to use. Refer to the 33 +// Microsoft .NET Framework documentation for more information on assembly signing. 34 +// 35 +// Use the attributes below to control which key is used for signing. 36 +// 37 +// Notes: 38 +// (*) If no key is specified, the assembly is not signed. 39 +// (*) KeyName refers to a key that has been installed in the Crypto Service 40 +// Provider (CSP) on your machine. KeyFile refers to a file which contains 41 +// a key. 42 +// (*) If the KeyFile and the KeyName values are both specified, the 43 +// following processing occurs: 44 +// (1) If the KeyName can be found in the CSP, that key is used. 45 +// (2) If the KeyName does not exist and the KeyFile does exist, the key 46 +// in the KeyFile is installed into the CSP and used. 47 +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 +// When specifying the KeyFile, the location of the KeyFile should be 49 +// relative to the project output directory which is 50 +// %Project Directory%\obj\<configuration>. For example, if your KeyFile is 51 +// located in the project directory, you would specify the AssemblyKeyFile 52 +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 +// documentation for more information on this. 55 +// 56 +[assembly: AssemblyDelaySign(false)] 57 +[assembly: AssemblyKeyFile("")] 58 +[assembly: AssemblyKeyName("")]
Added compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Runtime.InteropServices; 10 +using System.Text; 11 + 12 + 13 +namespace DotZLib 14 +{ 15 + #region ChecksumGeneratorBase 16 + /// <summary> 17 + /// Implements the common functionality needed for all <see cref="ChecksumGenerator"/>s 18 + /// </summary> 19 + /// <example></example> 20 + public abstract class ChecksumGeneratorBase : ChecksumGenerator 21 + { 22 + /// <summary> 23 + /// The value of the current checksum 24 + /// </summary> 25 + protected uint _current; 26 + 27 + /// <summary> 28 + /// Initializes a new instance of the checksum generator base - the current checksum is 29 + /// set to zero 30 + /// </summary> 31 + public ChecksumGeneratorBase() 32 + { 33 + _current = 0; 34 + } 35 + 36 + /// <summary> 37 + /// Initializes a new instance of the checksum generator basewith a specified value 38 + /// </summary> 39 + /// <param name="initialValue">The value to set the current checksum to</param> 40 + public ChecksumGeneratorBase(uint initialValue) 41 + { 42 + _current = initialValue; 43 + } 44 + 45 + /// <summary> 46 + /// Resets the current checksum to zero 47 + /// </summary> 48 + public void Reset() { _current = 0; } 49 + 50 + /// <summary> 51 + /// Gets the current checksum value 52 + /// </summary> 53 + public uint Value { get { return _current; } } 54 + 55 + /// <summary> 56 + /// Updates the current checksum with part of an array of bytes 57 + /// </summary> 58 + /// <param name="data">The data to update the checksum with</param> 59 + /// <param name="offset">Where in <c>data</c> to start updating</param> 60 + /// <param name="count">The number of bytes from <c>data</c> to use</param> 61 + /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception> 62 + /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception> 63 + /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception> 64 + /// <remarks>All the other <c>Update</c> methods are implmeneted in terms of this one. 65 + /// This is therefore the only method a derived class has to implement</remarks> 66 + public abstract void Update(byte[] data, int offset, int count); 67 + 68 + /// <summary> 69 + /// Updates the current checksum with an array of bytes. 70 + /// </summary> 71 + /// <param name="data">The data to update the checksum with</param> 72 + public void Update(byte[] data) 73 + { 74 + Update(data, 0, data.Length); 75 + } 76 + 77 + /// <summary> 78 + /// Updates the current checksum with the data from a string 79 + /// </summary> 80 + /// <param name="data">The string to update the checksum with</param> 81 + /// <remarks>The characters in the string are converted by the UTF-8 encoding</remarks> 82 + public void Update(string data) 83 + { 84 + Update(Encoding.UTF8.GetBytes(data)); 85 + } 86 + 87 + /// <summary> 88 + /// Updates the current checksum with the data from a string, using a specific encoding 89 + /// </summary> 90 + /// <param name="data">The string to update the checksum with</param> 91 + /// <param name="encoding">The encoding to use</param> 92 + public void Update(string data, Encoding encoding) 93 + { 94 + Update(encoding.GetBytes(data)); 95 + } 96 + 97 + } 98 + #endregion 99 + 100 + #region CRC32 101 + /// <summary> 102 + /// Implements a CRC32 checksum generator 103 + /// </summary> 104 + public sealed class CRC32Checksum : ChecksumGeneratorBase 105 + { 106 + #region DLL imports 107 + 108 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 109 + private static extern uint crc32(uint crc, int data, uint length); 110 + 111 + #endregion 112 + 113 + /// <summary> 114 + /// Initializes a new instance of the CRC32 checksum generator 115 + /// </summary> 116 + public CRC32Checksum() : base() {} 117 + 118 + /// <summary> 119 + /// Initializes a new instance of the CRC32 checksum generator with a specified value 120 + /// </summary> 121 + /// <param name="initialValue">The value to set the current checksum to</param> 122 + public CRC32Checksum(uint initialValue) : base(initialValue) {} 123 + 124 + /// <summary> 125 + /// Updates the current checksum with part of an array of bytes 126 + /// </summary> 127 + /// <param name="data">The data to update the checksum with</param> 128 + /// <param name="offset">Where in <c>data</c> to start updating</param> 129 + /// <param name="count">The number of bytes from <c>data</c> to use</param> 130 + /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception> 131 + /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception> 132 + /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception> 133 + public override void Update(byte[] data, int offset, int count) 134 + { 135 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 136 + if ((offset+count) > data.Length) throw new ArgumentException(); 137 + GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); 138 + try 139 + { 140 + _current = crc32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); 141 + } 142 + finally 143 + { 144 + hData.Free(); 145 + } 146 + } 147 + 148 + } 149 + #endregion 150 + 151 + #region Adler 152 + /// <summary> 153 + /// Implements a checksum generator that computes the Adler checksum on data 154 + /// </summary> 155 + public sealed class AdlerChecksum : ChecksumGeneratorBase 156 + { 157 + #region DLL imports 158 + 159 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 160 + private static extern uint adler32(uint adler, int data, uint length); 161 + 162 + #endregion 163 + 164 + /// <summary> 165 + /// Initializes a new instance of the Adler checksum generator 166 + /// </summary> 167 + public AdlerChecksum() : base() {} 168 + 169 + /// <summary> 170 + /// Initializes a new instance of the Adler checksum generator with a specified value 171 + /// </summary> 172 + /// <param name="initialValue">The value to set the current checksum to</param> 173 + public AdlerChecksum(uint initialValue) : base(initialValue) {} 174 + 175 + /// <summary> 176 + /// Updates the current checksum with part of an array of bytes 177 + /// </summary> 178 + /// <param name="data">The data to update the checksum with</param> 179 + /// <param name="offset">Where in <c>data</c> to start updating</param> 180 + /// <param name="count">The number of bytes from <c>data</c> to use</param> 181 + /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception> 182 + /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception> 183 + /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception> 184 + public override void Update(byte[] data, int offset, int count) 185 + { 186 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 187 + if ((offset+count) > data.Length) throw new ArgumentException(); 188 + GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); 189 + try 190 + { 191 + _current = adler32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); 192 + } 193 + finally 194 + { 195 + hData.Free(); 196 + } 197 + } 198 + 199 + } 200 + #endregion 201 + 202 +}
Added compat/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Diagnostics; 10 + 11 +namespace DotZLib 12 +{ 13 + 14 + /// <summary> 15 + /// This class implements a circular buffer 16 + /// </summary> 17 + internal class CircularBuffer 18 + { 19 + #region Private data 20 + private int _capacity; 21 + private int _head; 22 + private int _tail; 23 + private int _size; 24 + private byte[] _buffer; 25 + #endregion 26 + 27 + public CircularBuffer(int capacity) 28 + { 29 + Debug.Assert( capacity > 0 ); 30 + _buffer = new byte[capacity]; 31 + _capacity = capacity; 32 + _head = 0; 33 + _tail = 0; 34 + _size = 0; 35 + } 36 + 37 + public int Size { get { return _size; } } 38 + 39 + public int Put(byte[] source, int offset, int count) 40 + { 41 + Debug.Assert( count > 0 ); 42 + int trueCount = Math.Min(count, _capacity - Size); 43 + for (int i = 0; i < trueCount; ++i) 44 + _buffer[(_tail+i) % _capacity] = source[offset+i]; 45 + _tail += trueCount; 46 + _tail %= _capacity; 47 + _size += trueCount; 48 + return trueCount; 49 + } 50 + 51 + public bool Put(byte b) 52 + { 53 + if (Size == _capacity) // no room 54 + return false; 55 + _buffer[_tail++] = b; 56 + _tail %= _capacity; 57 + ++_size; 58 + return true; 59 + } 60 + 61 + public int Get(byte[] destination, int offset, int count) 62 + { 63 + int trueCount = Math.Min(count,Size); 64 + for (int i = 0; i < trueCount; ++i) 65 + destination[offset + i] = _buffer[(_head+i) % _capacity]; 66 + _head += trueCount; 67 + _head %= _capacity; 68 + _size -= trueCount; 69 + return trueCount; 70 + } 71 + 72 + public int Get() 73 + { 74 + if (Size == 0) 75 + return -1; 76 + 77 + int result = (int)_buffer[_head++ % _capacity]; 78 + --_size; 79 + return result; 80 + } 81 + 82 + } 83 +}
Added compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Runtime.InteropServices; 10 + 11 +namespace DotZLib 12 +{ 13 + /// <summary> 14 + /// Implements the common functionality needed for all <see cref="Codec"/>s 15 + /// </summary> 16 + public abstract class CodecBase : Codec, IDisposable 17 + { 18 + 19 + #region Data members 20 + 21 + /// <summary> 22 + /// Instance of the internal zlib buffer structure that is 23 + /// passed to all functions in the zlib dll 24 + /// </summary> 25 + internal ZStream _ztream = new ZStream(); 26 + 27 + /// <summary> 28 + /// True if the object instance has been disposed, false otherwise 29 + /// </summary> 30 + protected bool _isDisposed = false; 31 + 32 + /// <summary> 33 + /// The size of the internal buffers 34 + /// </summary> 35 + protected const int kBufferSize = 16384; 36 + 37 + private byte[] _outBuffer = new byte[kBufferSize]; 38 + private byte[] _inBuffer = new byte[kBufferSize]; 39 + 40 + private GCHandle _hInput; 41 + private GCHandle _hOutput; 42 + 43 + private uint _checksum = 0; 44 + 45 + #endregion 46 + 47 + /// <summary> 48 + /// Initializes a new instance of the <c>CodeBase</c> class. 49 + /// </summary> 50 + public CodecBase() 51 + { 52 + try 53 + { 54 + _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned); 55 + _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned); 56 + } 57 + catch (Exception) 58 + { 59 + CleanUp(false); 60 + throw; 61 + } 62 + } 63 + 64 + 65 + #region Codec Members 66 + 67 + /// <summary> 68 + /// Occurs when more processed data are available. 69 + /// </summary> 70 + public event DataAvailableHandler DataAvailable; 71 + 72 + /// <summary> 73 + /// Fires the <see cref="DataAvailable"/> event 74 + /// </summary> 75 + protected void OnDataAvailable() 76 + { 77 + if (_ztream.total_out > 0) 78 + { 79 + if (DataAvailable != null) 80 + DataAvailable( _outBuffer, 0, (int)_ztream.total_out); 81 + resetOutput(); 82 + } 83 + } 84 + 85 + /// <summary> 86 + /// Adds more data to the codec to be processed. 87 + /// </summary> 88 + /// <param name="data">Byte array containing the data to be added to the codec</param> 89 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 90 + public void Add(byte[] data) 91 + { 92 + Add(data,0,data.Length); 93 + } 94 + 95 + /// <summary> 96 + /// Adds more data to the codec to be processed. 97 + /// </summary> 98 + /// <param name="data">Byte array containing the data to be added to the codec</param> 99 + /// <param name="offset">The index of the first byte to add from <c>data</c></param> 100 + /// <param name="count">The number of bytes to add</param> 101 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 102 + /// <remarks>This must be implemented by a derived class</remarks> 103 + public abstract void Add(byte[] data, int offset, int count); 104 + 105 + /// <summary> 106 + /// Finishes up any pending data that needs to be processed and handled. 107 + /// </summary> 108 + /// <remarks>This must be implemented by a derived class</remarks> 109 + public abstract void Finish(); 110 + 111 + /// <summary> 112 + /// Gets the checksum of the data that has been added so far 113 + /// </summary> 114 + public uint Checksum { get { return _checksum; } } 115 + 116 + #endregion 117 + 118 + #region Destructor & IDisposable stuff 119 + 120 + /// <summary> 121 + /// Destroys this instance 122 + /// </summary> 123 + ~CodecBase() 124 + { 125 + CleanUp(false); 126 + } 127 + 128 + /// <summary> 129 + /// Releases any unmanaged resources and calls the <see cref="CleanUp()"/> method of the derived class 130 + /// </summary> 131 + public void Dispose() 132 + { 133 + CleanUp(true); 134 + } 135 + 136 + /// <summary> 137 + /// Performs any codec specific cleanup 138 + /// </summary> 139 + /// <remarks>This must be implemented by a derived class</remarks> 140 + protected abstract void CleanUp(); 141 + 142 + // performs the release of the handles and calls the dereived CleanUp() 143 + private void CleanUp(bool isDisposing) 144 + { 145 + if (!_isDisposed) 146 + { 147 + CleanUp(); 148 + if (_hInput.IsAllocated) 149 + _hInput.Free(); 150 + if (_hOutput.IsAllocated) 151 + _hOutput.Free(); 152 + 153 + _isDisposed = true; 154 + } 155 + } 156 + 157 + 158 + #endregion 159 + 160 + #region Helper methods 161 + 162 + /// <summary> 163 + /// Copies a number of bytes to the internal codec buffer - ready for proccesing 164 + /// </summary> 165 + /// <param name="data">The byte array that contains the data to copy</param> 166 + /// <param name="startIndex">The index of the first byte to copy</param> 167 + /// <param name="count">The number of bytes to copy from <c>data</c></param> 168 + protected void copyInput(byte[] data, int startIndex, int count) 169 + { 170 + Array.Copy(data, startIndex, _inBuffer,0, count); 171 + _ztream.next_in = _hInput.AddrOfPinnedObject(); 172 + _ztream.total_in = 0; 173 + _ztream.avail_in = (uint)count; 174 + 175 + } 176 + 177 + /// <summary> 178 + /// Resets the internal output buffers to a known state - ready for processing 179 + /// </summary> 180 + protected void resetOutput() 181 + { 182 + _ztream.total_out = 0; 183 + _ztream.avail_out = kBufferSize; 184 + _ztream.next_out = _hOutput.AddrOfPinnedObject(); 185 + } 186 + 187 + /// <summary> 188 + /// Updates the running checksum property 189 + /// </summary> 190 + /// <param name="newSum">The new checksum value</param> 191 + protected void setChecksum(uint newSum) 192 + { 193 + _checksum = newSum; 194 + } 195 + #endregion 196 + 197 + } 198 +}
Added compat/zlib/contrib/dotzlib/DotZLib/Deflater.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Diagnostics; 10 +using System.Runtime.InteropServices; 11 + 12 +namespace DotZLib 13 +{ 14 + 15 + /// <summary> 16 + /// Implements a data compressor, using the deflate algorithm in the ZLib dll 17 + /// </summary> 18 + public sealed class Deflater : CodecBase 19 + { 20 + #region Dll imports 21 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] 22 + private static extern int deflateInit_(ref ZStream sz, int level, string vs, int size); 23 + 24 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 25 + private static extern int deflate(ref ZStream sz, int flush); 26 + 27 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 28 + private static extern int deflateReset(ref ZStream sz); 29 + 30 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 31 + private static extern int deflateEnd(ref ZStream sz); 32 + #endregion 33 + 34 + /// <summary> 35 + /// Constructs an new instance of the <c>Deflater</c> 36 + /// </summary> 37 + /// <param name="level">The compression level to use for this <c>Deflater</c></param> 38 + public Deflater(CompressLevel level) : base() 39 + { 40 + int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); 41 + if (retval != 0) 42 + throw new ZLibException(retval, "Could not initialize deflater"); 43 + 44 + resetOutput(); 45 + } 46 + 47 + /// <summary> 48 + /// Adds more data to the codec to be processed. 49 + /// </summary> 50 + /// <param name="data">Byte array containing the data to be added to the codec</param> 51 + /// <param name="offset">The index of the first byte to add from <c>data</c></param> 52 + /// <param name="count">The number of bytes to add</param> 53 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 54 + public override void Add(byte[] data, int offset, int count) 55 + { 56 + if (data == null) throw new ArgumentNullException(); 57 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 58 + if ((offset+count) > data.Length) throw new ArgumentException(); 59 + 60 + int total = count; 61 + int inputIndex = offset; 62 + int err = 0; 63 + 64 + while (err >= 0 && inputIndex < total) 65 + { 66 + copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); 67 + while (err >= 0 && _ztream.avail_in > 0) 68 + { 69 + err = deflate(ref _ztream, (int)FlushTypes.None); 70 + if (err == 0) 71 + while (_ztream.avail_out == 0) 72 + { 73 + OnDataAvailable(); 74 + err = deflate(ref _ztream, (int)FlushTypes.None); 75 + } 76 + inputIndex += (int)_ztream.total_in; 77 + } 78 + } 79 + setChecksum( _ztream.adler ); 80 + } 81 + 82 + 83 + /// <summary> 84 + /// Finishes up any pending data that needs to be processed and handled. 85 + /// </summary> 86 + public override void Finish() 87 + { 88 + int err; 89 + do 90 + { 91 + err = deflate(ref _ztream, (int)FlushTypes.Finish); 92 + OnDataAvailable(); 93 + } 94 + while (err == 0); 95 + setChecksum( _ztream.adler ); 96 + deflateReset(ref _ztream); 97 + resetOutput(); 98 + } 99 + 100 + /// <summary> 101 + /// Closes the internal zlib deflate stream 102 + /// </summary> 103 + protected override void CleanUp() { deflateEnd(ref _ztream); } 104 + 105 + } 106 +}
Added compat/zlib/contrib/dotzlib/DotZLib/DotZLib.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.IO; 10 +using System.Runtime.InteropServices; 11 +using System.Text; 12 + 13 + 14 +namespace DotZLib 15 +{ 16 + 17 + #region Internal types 18 + 19 + /// <summary> 20 + /// Defines constants for the various flush types used with zlib 21 + /// </summary> 22 + internal enum FlushTypes 23 + { 24 + None, Partial, Sync, Full, Finish, Block 25 + } 26 + 27 + #region ZStream structure 28 + // internal mapping of the zlib zstream structure for marshalling 29 + [StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Ansi)] 30 + internal struct ZStream 31 + { 32 + public IntPtr next_in; 33 + public uint avail_in; 34 + public uint total_in; 35 + 36 + public IntPtr next_out; 37 + public uint avail_out; 38 + public uint total_out; 39 + 40 + [MarshalAs(UnmanagedType.LPStr)] 41 + string msg; 42 + uint state; 43 + 44 + uint zalloc; 45 + uint zfree; 46 + uint opaque; 47 + 48 + int data_type; 49 + public uint adler; 50 + uint reserved; 51 + } 52 + 53 + #endregion 54 + 55 + #endregion 56 + 57 + #region Public enums 58 + /// <summary> 59 + /// Defines constants for the available compression levels in zlib 60 + /// </summary> 61 + public enum CompressLevel : int 62 + { 63 + /// <summary> 64 + /// The default compression level with a reasonable compromise between compression and speed 65 + /// </summary> 66 + Default = -1, 67 + /// <summary> 68 + /// No compression at all. The data are passed straight through. 69 + /// </summary> 70 + None = 0, 71 + /// <summary> 72 + /// The maximum compression rate available. 73 + /// </summary> 74 + Best = 9, 75 + /// <summary> 76 + /// The fastest available compression level. 77 + /// </summary> 78 + Fastest = 1 79 + } 80 + #endregion 81 + 82 + #region Exception classes 83 + /// <summary> 84 + /// The exception that is thrown when an error occurs on the zlib dll 85 + /// </summary> 86 + public class ZLibException : ApplicationException 87 + { 88 + /// <summary> 89 + /// Initializes a new instance of the <see cref="ZLibException"/> class with a specified 90 + /// error message and error code 91 + /// </summary> 92 + /// <param name="errorCode">The zlib error code that caused the exception</param> 93 + /// <param name="msg">A message that (hopefully) describes the error</param> 94 + public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg)) 95 + { 96 + } 97 + 98 + /// <summary> 99 + /// Initializes a new instance of the <see cref="ZLibException"/> class with a specified 100 + /// error code 101 + /// </summary> 102 + /// <param name="errorCode">The zlib error code that caused the exception</param> 103 + public ZLibException(int errorCode) : base(String.Format("ZLib error {0}", errorCode)) 104 + { 105 + } 106 + } 107 + #endregion 108 + 109 + #region Interfaces 110 + 111 + /// <summary> 112 + /// Declares methods and properties that enables a running checksum to be calculated 113 + /// </summary> 114 + public interface ChecksumGenerator 115 + { 116 + /// <summary> 117 + /// Gets the current value of the checksum 118 + /// </summary> 119 + uint Value { get; } 120 + 121 + /// <summary> 122 + /// Clears the current checksum to 0 123 + /// </summary> 124 + void Reset(); 125 + 126 + /// <summary> 127 + /// Updates the current checksum with an array of bytes 128 + /// </summary> 129 + /// <param name="data">The data to update the checksum with</param> 130 + void Update(byte[] data); 131 + 132 + /// <summary> 133 + /// Updates the current checksum with part of an array of bytes 134 + /// </summary> 135 + /// <param name="data">The data to update the checksum with</param> 136 + /// <param name="offset">Where in <c>data</c> to start updating</param> 137 + /// <param name="count">The number of bytes from <c>data</c> to use</param> 138 + /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception> 139 + /// <exception cref="ArgumentNullException"><c>data</c> is a null reference</exception> 140 + /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception> 141 + void Update(byte[] data, int offset, int count); 142 + 143 + /// <summary> 144 + /// Updates the current checksum with the data from a string 145 + /// </summary> 146 + /// <param name="data">The string to update the checksum with</param> 147 + /// <remarks>The characters in the string are converted by the UTF-8 encoding</remarks> 148 + void Update(string data); 149 + 150 + /// <summary> 151 + /// Updates the current checksum with the data from a string, using a specific encoding 152 + /// </summary> 153 + /// <param name="data">The string to update the checksum with</param> 154 + /// <param name="encoding">The encoding to use</param> 155 + void Update(string data, Encoding encoding); 156 + } 157 + 158 + 159 + /// <summary> 160 + /// Represents the method that will be called from a codec when new data 161 + /// are available. 162 + /// </summary> 163 + /// <paramref name="data">The byte array containing the processed data</paramref> 164 + /// <paramref name="startIndex">The index of the first processed byte in <c>data</c></paramref> 165 + /// <paramref name="count">The number of processed bytes available</paramref> 166 + /// <remarks>On return from this method, the data may be overwritten, so grab it while you can. 167 + /// You cannot assume that startIndex will be zero. 168 + /// </remarks> 169 + public delegate void DataAvailableHandler(byte[] data, int startIndex, int count); 170 + 171 + /// <summary> 172 + /// Declares methods and events for implementing compressors/decompressors 173 + /// </summary> 174 + public interface Codec 175 + { 176 + /// <summary> 177 + /// Occurs when more processed data are available. 178 + /// </summary> 179 + event DataAvailableHandler DataAvailable; 180 + 181 + /// <summary> 182 + /// Adds more data to the codec to be processed. 183 + /// </summary> 184 + /// <param name="data">Byte array containing the data to be added to the codec</param> 185 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 186 + void Add(byte[] data); 187 + 188 + /// <summary> 189 + /// Adds more data to the codec to be processed. 190 + /// </summary> 191 + /// <param name="data">Byte array containing the data to be added to the codec</param> 192 + /// <param name="offset">The index of the first byte to add from <c>data</c></param> 193 + /// <param name="count">The number of bytes to add</param> 194 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 195 + void Add(byte[] data, int offset, int count); 196 + 197 + /// <summary> 198 + /// Finishes up any pending data that needs to be processed and handled. 199 + /// </summary> 200 + void Finish(); 201 + 202 + /// <summary> 203 + /// Gets the checksum of the data that has been added so far 204 + /// </summary> 205 + uint Checksum { get; } 206 + 207 + 208 + } 209 + 210 + #endregion 211 + 212 + #region Classes 213 + /// <summary> 214 + /// Encapsulates general information about the ZLib library 215 + /// </summary> 216 + public class Info 217 + { 218 + #region DLL imports 219 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 220 + private static extern uint zlibCompileFlags(); 221 + 222 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 223 + private static extern string zlibVersion(); 224 + #endregion 225 + 226 + #region Private stuff 227 + private uint _flags; 228 + 229 + // helper function that unpacks a bitsize mask 230 + private static int bitSize(uint bits) 231 + { 232 + switch (bits) 233 + { 234 + case 0: return 16; 235 + case 1: return 32; 236 + case 2: return 64; 237 + } 238 + return -1; 239 + } 240 + #endregion 241 + 242 + /// <summary> 243 + /// Constructs an instance of the <c>Info</c> class. 244 + /// </summary> 245 + public Info() 246 + { 247 + _flags = zlibCompileFlags(); 248 + } 249 + 250 + /// <summary> 251 + /// True if the library is compiled with debug info 252 + /// </summary> 253 + public bool HasDebugInfo { get { return 0 != (_flags & 0x100); } } 254 + 255 + /// <summary> 256 + /// True if the library is compiled with assembly optimizations 257 + /// </summary> 258 + public bool UsesAssemblyCode { get { return 0 != (_flags & 0x200); } } 259 + 260 + /// <summary> 261 + /// Gets the size of the unsigned int that was compiled into Zlib 262 + /// </summary> 263 + public int SizeOfUInt { get { return bitSize(_flags & 3); } } 264 + 265 + /// <summary> 266 + /// Gets the size of the unsigned long that was compiled into Zlib 267 + /// </summary> 268 + public int SizeOfULong { get { return bitSize((_flags >> 2) & 3); } } 269 + 270 + /// <summary> 271 + /// Gets the size of the pointers that were compiled into Zlib 272 + /// </summary> 273 + public int SizeOfPointer { get { return bitSize((_flags >> 4) & 3); } } 274 + 275 + /// <summary> 276 + /// Gets the size of the z_off_t type that was compiled into Zlib 277 + /// </summary> 278 + public int SizeOfOffset { get { return bitSize((_flags >> 6) & 3); } } 279 + 280 + /// <summary> 281 + /// Gets the version of ZLib as a string, e.g. "1.2.1" 282 + /// </summary> 283 + public static string Version { get { return zlibVersion(); } } 284 + } 285 + 286 + #endregion 287 + 288 +}
Added compat/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj.
1 +<VisualStudioProject> 2 + <CSHARP 3 + ProjectType = "Local" 4 + ProductVersion = "7.10.3077" 5 + SchemaVersion = "2.0" 6 + ProjectGuid = "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" 7 + > 8 + <Build> 9 + <Settings 10 + ApplicationIcon = "" 11 + AssemblyKeyContainerName = "" 12 + AssemblyName = "DotZLib" 13 + AssemblyOriginatorKeyFile = "" 14 + DefaultClientScript = "JScript" 15 + DefaultHTMLPageLayout = "Grid" 16 + DefaultTargetSchema = "IE50" 17 + DelaySign = "false" 18 + OutputType = "Library" 19 + PreBuildEvent = "" 20 + PostBuildEvent = "" 21 + RootNamespace = "DotZLib" 22 + RunPostBuildEvent = "OnBuildSuccess" 23 + StartupObject = "" 24 + > 25 + <Config 26 + Name = "Debug" 27 + AllowUnsafeBlocks = "false" 28 + BaseAddress = "285212672" 29 + CheckForOverflowUnderflow = "false" 30 + ConfigurationOverrideFile = "" 31 + DefineConstants = "DEBUG;TRACE" 32 + DocumentationFile = "docs\DotZLib.xml" 33 + DebugSymbols = "true" 34 + FileAlignment = "4096" 35 + IncrementalBuild = "false" 36 + NoStdLib = "false" 37 + NoWarn = "1591" 38 + Optimize = "false" 39 + OutputPath = "bin\Debug\" 40 + RegisterForComInterop = "false" 41 + RemoveIntegerChecks = "false" 42 + TreatWarningsAsErrors = "false" 43 + WarningLevel = "4" 44 + /> 45 + <Config 46 + Name = "Release" 47 + AllowUnsafeBlocks = "false" 48 + BaseAddress = "285212672" 49 + CheckForOverflowUnderflow = "false" 50 + ConfigurationOverrideFile = "" 51 + DefineConstants = "TRACE" 52 + DocumentationFile = "docs\DotZLib.xml" 53 + DebugSymbols = "false" 54 + FileAlignment = "4096" 55 + IncrementalBuild = "false" 56 + NoStdLib = "false" 57 + NoWarn = "" 58 + Optimize = "true" 59 + OutputPath = "bin\Release\" 60 + RegisterForComInterop = "false" 61 + RemoveIntegerChecks = "false" 62 + TreatWarningsAsErrors = "false" 63 + WarningLevel = "4" 64 + /> 65 + </Settings> 66 + <References> 67 + <Reference 68 + Name = "System" 69 + AssemblyName = "System" 70 + HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" 71 + /> 72 + <Reference 73 + Name = "System.Data" 74 + AssemblyName = "System.Data" 75 + HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" 76 + /> 77 + <Reference 78 + Name = "System.XML" 79 + AssemblyName = "System.Xml" 80 + HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" 81 + /> 82 + <Reference 83 + Name = "nunit.framework" 84 + AssemblyName = "nunit.framework" 85 + HintPath = "E:\apps\NUnit V2.1\\bin\nunit.framework.dll" 86 + AssemblyFolderKey = "hklm\dn\nunit.framework" 87 + /> 88 + </References> 89 + </Build> 90 + <Files> 91 + <Include> 92 + <File 93 + RelPath = "AssemblyInfo.cs" 94 + SubType = "Code" 95 + BuildAction = "Compile" 96 + /> 97 + <File 98 + RelPath = "ChecksumImpl.cs" 99 + SubType = "Code" 100 + BuildAction = "Compile" 101 + /> 102 + <File 103 + RelPath = "CircularBuffer.cs" 104 + SubType = "Code" 105 + BuildAction = "Compile" 106 + /> 107 + <File 108 + RelPath = "CodecBase.cs" 109 + SubType = "Code" 110 + BuildAction = "Compile" 111 + /> 112 + <File 113 + RelPath = "Deflater.cs" 114 + SubType = "Code" 115 + BuildAction = "Compile" 116 + /> 117 + <File 118 + RelPath = "DotZLib.cs" 119 + SubType = "Code" 120 + BuildAction = "Compile" 121 + /> 122 + <File 123 + RelPath = "GZipStream.cs" 124 + SubType = "Code" 125 + BuildAction = "Compile" 126 + /> 127 + <File 128 + RelPath = "Inflater.cs" 129 + SubType = "Code" 130 + BuildAction = "Compile" 131 + /> 132 + <File 133 + RelPath = "UnitTests.cs" 134 + SubType = "Code" 135 + BuildAction = "Compile" 136 + /> 137 + </Include> 138 + </Files> 139 + </CSHARP> 140 +</VisualStudioProject> 141 +
Added compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.IO; 10 +using System.Runtime.InteropServices; 11 + 12 +namespace DotZLib 13 +{ 14 + /// <summary> 15 + /// Implements a compressed <see cref="Stream"/>, in GZip (.gz) format. 16 + /// </summary> 17 + public class GZipStream : Stream, IDisposable 18 + { 19 + #region Dll Imports 20 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] 21 + private static extern IntPtr gzopen(string name, string mode); 22 + 23 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 24 + private static extern int gzclose(IntPtr gzFile); 25 + 26 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 27 + private static extern int gzwrite(IntPtr gzFile, int data, int length); 28 + 29 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 30 + private static extern int gzread(IntPtr gzFile, int data, int length); 31 + 32 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 33 + private static extern int gzgetc(IntPtr gzFile); 34 + 35 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 36 + private static extern int gzputc(IntPtr gzFile, int c); 37 + 38 + #endregion 39 + 40 + #region Private data 41 + private IntPtr _gzFile; 42 + private bool _isDisposed = false; 43 + private bool _isWriting; 44 + #endregion 45 + 46 + #region Constructors 47 + /// <summary> 48 + /// Creates a new file as a writeable GZipStream 49 + /// </summary> 50 + /// <param name="fileName">The name of the compressed file to create</param> 51 + /// <param name="level">The compression level to use when adding data</param> 52 + /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> 53 + public GZipStream(string fileName, CompressLevel level) 54 + { 55 + _isWriting = true; 56 + _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level)); 57 + if (_gzFile == IntPtr.Zero) 58 + throw new ZLibException(-1, "Could not open " + fileName); 59 + } 60 + 61 + /// <summary> 62 + /// Opens an existing file as a readable GZipStream 63 + /// </summary> 64 + /// <param name="fileName">The name of the file to open</param> 65 + /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> 66 + public GZipStream(string fileName) 67 + { 68 + _isWriting = false; 69 + _gzFile = gzopen(fileName, "rb"); 70 + if (_gzFile == IntPtr.Zero) 71 + throw new ZLibException(-1, "Could not open " + fileName); 72 + 73 + } 74 + #endregion 75 + 76 + #region Access properties 77 + /// <summary> 78 + /// Returns true of this stream can be read from, false otherwise 79 + /// </summary> 80 + public override bool CanRead 81 + { 82 + get 83 + { 84 + return !_isWriting; 85 + } 86 + } 87 + 88 + 89 + /// <summary> 90 + /// Returns false. 91 + /// </summary> 92 + public override bool CanSeek 93 + { 94 + get 95 + { 96 + return false; 97 + } 98 + } 99 + 100 + /// <summary> 101 + /// Returns true if this tsream is writeable, false otherwise 102 + /// </summary> 103 + public override bool CanWrite 104 + { 105 + get 106 + { 107 + return _isWriting; 108 + } 109 + } 110 + #endregion 111 + 112 + #region Destructor & IDispose stuff 113 + 114 + /// <summary> 115 + /// Destroys this instance 116 + /// </summary> 117 + ~GZipStream() 118 + { 119 + cleanUp(false); 120 + } 121 + 122 + /// <summary> 123 + /// Closes the external file handle 124 + /// </summary> 125 + public void Dispose() 126 + { 127 + cleanUp(true); 128 + } 129 + 130 + // Does the actual closing of the file handle. 131 + private void cleanUp(bool isDisposing) 132 + { 133 + if (!_isDisposed) 134 + { 135 + gzclose(_gzFile); 136 + _isDisposed = true; 137 + } 138 + } 139 + #endregion 140 + 141 + #region Basic reading and writing 142 + /// <summary> 143 + /// Attempts to read a number of bytes from the stream. 144 + /// </summary> 145 + /// <param name="buffer">The destination data buffer</param> 146 + /// <param name="offset">The index of the first destination byte in <c>buffer</c></param> 147 + /// <param name="count">The number of bytes requested</param> 148 + /// <returns>The number of bytes read</returns> 149 + /// <exception cref="ArgumentNullException">If <c>buffer</c> is null</exception> 150 + /// <exception cref="ArgumentOutOfRangeException">If <c>count</c> or <c>offset</c> are negative</exception> 151 + /// <exception cref="ArgumentException">If <c>offset</c> + <c>count</c> is > buffer.Length</exception> 152 + /// <exception cref="NotSupportedException">If this stream is not readable.</exception> 153 + /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception> 154 + public override int Read(byte[] buffer, int offset, int count) 155 + { 156 + if (!CanRead) throw new NotSupportedException(); 157 + if (buffer == null) throw new ArgumentNullException(); 158 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 159 + if ((offset+count) > buffer.Length) throw new ArgumentException(); 160 + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); 161 + 162 + GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); 163 + int result; 164 + try 165 + { 166 + result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); 167 + if (result < 0) 168 + throw new IOException(); 169 + } 170 + finally 171 + { 172 + h.Free(); 173 + } 174 + return result; 175 + } 176 + 177 + /// <summary> 178 + /// Attempts to read a single byte from the stream. 179 + /// </summary> 180 + /// <returns>The byte that was read, or -1 in case of error or End-Of-File</returns> 181 + public override int ReadByte() 182 + { 183 + if (!CanRead) throw new NotSupportedException(); 184 + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); 185 + return gzgetc(_gzFile); 186 + } 187 + 188 + /// <summary> 189 + /// Writes a number of bytes to the stream 190 + /// </summary> 191 + /// <param name="buffer"></param> 192 + /// <param name="offset"></param> 193 + /// <param name="count"></param> 194 + /// <exception cref="ArgumentNullException">If <c>buffer</c> is null</exception> 195 + /// <exception cref="ArgumentOutOfRangeException">If <c>count</c> or <c>offset</c> are negative</exception> 196 + /// <exception cref="ArgumentException">If <c>offset</c> + <c>count</c> is > buffer.Length</exception> 197 + /// <exception cref="NotSupportedException">If this stream is not writeable.</exception> 198 + /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception> 199 + public override void Write(byte[] buffer, int offset, int count) 200 + { 201 + if (!CanWrite) throw new NotSupportedException(); 202 + if (buffer == null) throw new ArgumentNullException(); 203 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 204 + if ((offset+count) > buffer.Length) throw new ArgumentException(); 205 + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); 206 + 207 + GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); 208 + try 209 + { 210 + int result = gzwrite(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); 211 + if (result < 0) 212 + throw new IOException(); 213 + } 214 + finally 215 + { 216 + h.Free(); 217 + } 218 + } 219 + 220 + /// <summary> 221 + /// Writes a single byte to the stream 222 + /// </summary> 223 + /// <param name="value">The byte to add to the stream.</param> 224 + /// <exception cref="NotSupportedException">If this stream is not writeable.</exception> 225 + /// <exception cref="ObjectDisposedException">If this stream has been disposed.</exception> 226 + public override void WriteByte(byte value) 227 + { 228 + if (!CanWrite) throw new NotSupportedException(); 229 + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); 230 + 231 + int result = gzputc(_gzFile, (int)value); 232 + if (result < 0) 233 + throw new IOException(); 234 + } 235 + #endregion 236 + 237 + #region Position & length stuff 238 + /// <summary> 239 + /// Not supported. 240 + /// </summary> 241 + /// <param name="value"></param> 242 + /// <exception cref="NotSupportedException">Always thrown</exception> 243 + public override void SetLength(long value) 244 + { 245 + throw new NotSupportedException(); 246 + } 247 + 248 + /// <summary> 249 + /// Not suppported. 250 + /// </summary> 251 + /// <param name="offset"></param> 252 + /// <param name="origin"></param> 253 + /// <returns></returns> 254 + /// <exception cref="NotSupportedException">Always thrown</exception> 255 + public override long Seek(long offset, SeekOrigin origin) 256 + { 257 + throw new NotSupportedException(); 258 + } 259 + 260 + /// <summary> 261 + /// Flushes the <c>GZipStream</c>. 262 + /// </summary> 263 + /// <remarks>In this implementation, this method does nothing. This is because excessive 264 + /// flushing may degrade the achievable compression rates.</remarks> 265 + public override void Flush() 266 + { 267 + // left empty on purpose 268 + } 269 + 270 + /// <summary> 271 + /// Gets/sets the current position in the <c>GZipStream</c>. Not suppported. 272 + /// </summary> 273 + /// <remarks>In this implementation this property is not supported</remarks> 274 + /// <exception cref="NotSupportedException">Always thrown</exception> 275 + public override long Position 276 + { 277 + get 278 + { 279 + throw new NotSupportedException(); 280 + } 281 + set 282 + { 283 + throw new NotSupportedException(); 284 + } 285 + } 286 + 287 + /// <summary> 288 + /// Gets the size of the stream. Not suppported. 289 + /// </summary> 290 + /// <remarks>In this implementation this property is not supported</remarks> 291 + /// <exception cref="NotSupportedException">Always thrown</exception> 292 + public override long Length 293 + { 294 + get 295 + { 296 + throw new NotSupportedException(); 297 + } 298 + } 299 + #endregion 300 + } 301 +}
Added compat/zlib/contrib/dotzlib/DotZLib/Inflater.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Diagnostics; 10 +using System.Runtime.InteropServices; 11 + 12 +namespace DotZLib 13 +{ 14 + 15 + /// <summary> 16 + /// Implements a data decompressor, using the inflate algorithm in the ZLib dll 17 + /// </summary> 18 + public class Inflater : CodecBase 19 + { 20 + #region Dll imports 21 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] 22 + private static extern int inflateInit_(ref ZStream sz, string vs, int size); 23 + 24 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 25 + private static extern int inflate(ref ZStream sz, int flush); 26 + 27 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 28 + private static extern int inflateReset(ref ZStream sz); 29 + 30 + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] 31 + private static extern int inflateEnd(ref ZStream sz); 32 + #endregion 33 + 34 + /// <summary> 35 + /// Constructs an new instance of the <c>Inflater</c> 36 + /// </summary> 37 + public Inflater() : base() 38 + { 39 + int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream)); 40 + if (retval != 0) 41 + throw new ZLibException(retval, "Could not initialize inflater"); 42 + 43 + resetOutput(); 44 + } 45 + 46 + 47 + /// <summary> 48 + /// Adds more data to the codec to be processed. 49 + /// </summary> 50 + /// <param name="data">Byte array containing the data to be added to the codec</param> 51 + /// <param name="offset">The index of the first byte to add from <c>data</c></param> 52 + /// <param name="count">The number of bytes to add</param> 53 + /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> 54 + public override void Add(byte[] data, int offset, int count) 55 + { 56 + if (data == null) throw new ArgumentNullException(); 57 + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); 58 + if ((offset+count) > data.Length) throw new ArgumentException(); 59 + 60 + int total = count; 61 + int inputIndex = offset; 62 + int err = 0; 63 + 64 + while (err >= 0 && inputIndex < total) 65 + { 66 + copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); 67 + err = inflate(ref _ztream, (int)FlushTypes.None); 68 + if (err == 0) 69 + while (_ztream.avail_out == 0) 70 + { 71 + OnDataAvailable(); 72 + err = inflate(ref _ztream, (int)FlushTypes.None); 73 + } 74 + 75 + inputIndex += (int)_ztream.total_in; 76 + } 77 + setChecksum( _ztream.adler ); 78 + } 79 + 80 + 81 + /// <summary> 82 + /// Finishes up any pending data that needs to be processed and handled. 83 + /// </summary> 84 + public override void Finish() 85 + { 86 + int err; 87 + do 88 + { 89 + err = inflate(ref _ztream, (int)FlushTypes.Finish); 90 + OnDataAvailable(); 91 + } 92 + while (err == 0); 93 + setChecksum( _ztream.adler ); 94 + inflateReset(ref _ztream); 95 + resetOutput(); 96 + } 97 + 98 + /// <summary> 99 + /// Closes the internal zlib inflate stream 100 + /// </summary> 101 + protected override void CleanUp() { inflateEnd(ref _ztream); } 102 + 103 + 104 + } 105 +}
Added compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs.
1 +// 2 +// � Copyright Henrik Ravn 2004 3 +// 4 +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. 5 +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 +// 7 + 8 +using System; 9 +using System.Collections; 10 +using System.IO; 11 + 12 +// uncomment the define below to include unit tests 13 +//#define nunit 14 +#if nunit 15 +using NUnit.Framework; 16 + 17 +// Unit tests for the DotZLib class library 18 +// ---------------------------------------- 19 +// 20 +// Use this with NUnit 2 from http://www.nunit.org 21 +// 22 + 23 +namespace DotZLibTests 24 +{ 25 + using DotZLib; 26 + 27 + // helper methods 28 + internal class Utils 29 + { 30 + public static bool byteArrEqual( byte[] lhs, byte[] rhs ) 31 + { 32 + if (lhs.Length != rhs.Length) 33 + return false; 34 + for (int i = lhs.Length-1; i >= 0; --i) 35 + if (lhs[i] != rhs[i]) 36 + return false; 37 + return true; 38 + } 39 + 40 + } 41 + 42 + 43 + [TestFixture] 44 + public class CircBufferTests 45 + { 46 + #region Circular buffer tests 47 + [Test] 48 + public void SinglePutGet() 49 + { 50 + CircularBuffer buf = new CircularBuffer(10); 51 + Assert.AreEqual( 0, buf.Size ); 52 + Assert.AreEqual( -1, buf.Get() ); 53 + 54 + Assert.IsTrue(buf.Put( 1 )); 55 + Assert.AreEqual( 1, buf.Size ); 56 + Assert.AreEqual( 1, buf.Get() ); 57 + Assert.AreEqual( 0, buf.Size ); 58 + Assert.AreEqual( -1, buf.Get() ); 59 + } 60 + 61 + [Test] 62 + public void BlockPutGet() 63 + { 64 + CircularBuffer buf = new CircularBuffer(10); 65 + byte[] arr = {1,2,3,4,5,6,7,8,9,10}; 66 + Assert.AreEqual( 10, buf.Put(arr,0,10) ); 67 + Assert.AreEqual( 10, buf.Size ); 68 + Assert.IsFalse( buf.Put(11) ); 69 + Assert.AreEqual( 1, buf.Get() ); 70 + Assert.IsTrue( buf.Put(11) ); 71 + 72 + byte[] arr2 = (byte[])arr.Clone(); 73 + Assert.AreEqual( 9, buf.Get(arr2,1,9) ); 74 + Assert.IsTrue( Utils.byteArrEqual(arr,arr2) ); 75 + } 76 + 77 + #endregion 78 + } 79 + 80 + [TestFixture] 81 + public class ChecksumTests 82 + { 83 + #region CRC32 Tests 84 + [Test] 85 + public void CRC32_Null() 86 + { 87 + CRC32Checksum crc32 = new CRC32Checksum(); 88 + Assert.AreEqual( 0, crc32.Value ); 89 + 90 + crc32 = new CRC32Checksum(1); 91 + Assert.AreEqual( 1, crc32.Value ); 92 + 93 + crc32 = new CRC32Checksum(556); 94 + Assert.AreEqual( 556, crc32.Value ); 95 + } 96 + 97 + [Test] 98 + public void CRC32_Data() 99 + { 100 + CRC32Checksum crc32 = new CRC32Checksum(); 101 + byte[] data = { 1,2,3,4,5,6,7 }; 102 + crc32.Update(data); 103 + Assert.AreEqual( 0x70e46888, crc32.Value ); 104 + 105 + crc32 = new CRC32Checksum(); 106 + crc32.Update("penguin"); 107 + Assert.AreEqual( 0x0e5c1a120, crc32.Value ); 108 + 109 + crc32 = new CRC32Checksum(1); 110 + crc32.Update("penguin"); 111 + Assert.AreEqual(0x43b6aa94, crc32.Value); 112 + 113 + } 114 + #endregion 115 + 116 + #region Adler tests 117 + 118 + [Test] 119 + public void Adler_Null() 120 + { 121 + AdlerChecksum adler = new AdlerChecksum(); 122 + Assert.AreEqual(0, adler.Value); 123 + 124 + adler = new AdlerChecksum(1); 125 + Assert.AreEqual( 1, adler.Value ); 126 + 127 + adler = new AdlerChecksum(556); 128 + Assert.AreEqual( 556, adler.Value ); 129 + } 130 + 131 + [Test] 132 + public void Adler_Data() 133 + { 134 + AdlerChecksum adler = new AdlerChecksum(1); 135 + byte[] data = { 1,2,3,4,5,6,7 }; 136 + adler.Update(data); 137 + Assert.AreEqual( 0x5b001d, adler.Value ); 138 + 139 + adler = new AdlerChecksum(); 140 + adler.Update("penguin"); 141 + Assert.AreEqual(0x0bcf02f6, adler.Value ); 142 + 143 + adler = new AdlerChecksum(1); 144 + adler.Update("penguin"); 145 + Assert.AreEqual(0x0bd602f7, adler.Value); 146 + 147 + } 148 + #endregion 149 + } 150 + 151 + [TestFixture] 152 + public class InfoTests 153 + { 154 + #region Info tests 155 + [Test] 156 + public void Info_Version() 157 + { 158 + Info info = new Info(); 159 + Assert.AreEqual("1.2.7", Info.Version); 160 + Assert.AreEqual(32, info.SizeOfUInt); 161 + Assert.AreEqual(32, info.SizeOfULong); 162 + Assert.AreEqual(32, info.SizeOfPointer); 163 + Assert.AreEqual(32, info.SizeOfOffset); 164 + } 165 + #endregion 166 + } 167 + 168 + [TestFixture] 169 + public class DeflateInflateTests 170 + { 171 + #region Deflate tests 172 + [Test] 173 + public void Deflate_Init() 174 + { 175 + using (Deflater def = new Deflater(CompressLevel.Default)) 176 + { 177 + } 178 + } 179 + 180 + private ArrayList compressedData = new ArrayList(); 181 + private uint adler1; 182 + 183 + private ArrayList uncompressedData = new ArrayList(); 184 + private uint adler2; 185 + 186 + public void CDataAvail(byte[] data, int startIndex, int count) 187 + { 188 + for (int i = 0; i < count; ++i) 189 + compressedData.Add(data[i+startIndex]); 190 + } 191 + 192 + [Test] 193 + public void Deflate_Compress() 194 + { 195 + compressedData.Clear(); 196 + 197 + byte[] testData = new byte[35000]; 198 + for (int i = 0; i < testData.Length; ++i) 199 + testData[i] = 5; 200 + 201 + using (Deflater def = new Deflater((CompressLevel)5)) 202 + { 203 + def.DataAvailable += new DataAvailableHandler(CDataAvail); 204 + def.Add(testData); 205 + def.Finish(); 206 + adler1 = def.Checksum; 207 + } 208 + } 209 + #endregion 210 + 211 + #region Inflate tests 212 + [Test] 213 + public void Inflate_Init() 214 + { 215 + using (Inflater inf = new Inflater()) 216 + { 217 + } 218 + } 219 + 220 + private void DDataAvail(byte[] data, int startIndex, int count) 221 + { 222 + for (int i = 0; i < count; ++i) 223 + uncompressedData.Add(data[i+startIndex]); 224 + } 225 + 226 + [Test] 227 + public void Inflate_Expand() 228 + { 229 + uncompressedData.Clear(); 230 + 231 + using (Inflater inf = new Inflater()) 232 + { 233 + inf.DataAvailable += new DataAvailableHandler(DDataAvail); 234 + inf.Add((byte[])compressedData.ToArray(typeof(byte))); 235 + inf.Finish(); 236 + adler2 = inf.Checksum; 237 + } 238 + Assert.AreEqual( adler1, adler2 ); 239 + } 240 + #endregion 241 + } 242 + 243 + [TestFixture] 244 + public class GZipStreamTests 245 + { 246 + #region GZipStream test 247 + [Test] 248 + public void GZipStream_WriteRead() 249 + { 250 + using (GZipStream gzOut = new GZipStream("gzstream.gz", CompressLevel.Best)) 251 + { 252 + BinaryWriter writer = new BinaryWriter(gzOut); 253 + writer.Write("hi there"); 254 + writer.Write(Math.PI); 255 + writer.Write(42); 256 + } 257 + 258 + using (GZipStream gzIn = new GZipStream("gzstream.gz")) 259 + { 260 + BinaryReader reader = new BinaryReader(gzIn); 261 + string s = reader.ReadString(); 262 + Assert.AreEqual("hi there",s); 263 + double d = reader.ReadDouble(); 264 + Assert.AreEqual(Math.PI, d); 265 + int i = reader.ReadInt32(); 266 + Assert.AreEqual(42,i); 267 + } 268 + 269 + } 270 + #endregion 271 + } 272 +} 273 + 274 +#endif
Added compat/zlib/contrib/dotzlib/LICENSE_1_0.txt.
1 +Boost Software License - Version 1.0 - August 17th, 2003 2 + 3 +Permission is hereby granted, free of charge, to any person or organization 4 +obtaining a copy of the software and accompanying documentation covered by 5 +this license (the "Software") to use, reproduce, display, distribute, 6 +execute, and transmit the Software, and to prepare derivative works of the 7 +Software, and to permit third-parties to whom the Software is furnished to 8 +do so, all subject to the following: 9 + 10 +The copyright notices in the Software and this entire statement, including 11 +the above license grant, this restriction and the following disclaimer, 12 +must be included in all copies of the Software, in whole or in part, and 13 +all derivative works of the Software, unless such copies or derivative 14 +works are solely in the form of machine-executable object code generated by 15 +a source language processor. 16 + 17 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 +DEALINGS IN THE SOFTWARE.
Added compat/zlib/contrib/dotzlib/readme.txt.
1 +This directory contains a .Net wrapper class library for the ZLib1.dll 2 + 3 +The wrapper includes support for inflating/deflating memory buffers, 4 +.Net streaming wrappers for the gz streams part of zlib, and wrappers 5 +for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. 6 + 7 +Directory structure: 8 +-------------------- 9 + 10 +LICENSE_1_0.txt - License file. 11 +readme.txt - This file. 12 +DotZLib.chm - Class library documentation 13 +DotZLib.build - NAnt build file 14 +DotZLib.sln - Microsoft Visual Studio 2003 solution file 15 + 16 +DotZLib\*.cs - Source files for the class library 17 + 18 +Unit tests: 19 +----------- 20 +The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. 21 +To include unit tests in the build, define nunit before building. 22 + 23 + 24 +Build instructions: 25 +------------------- 26 + 27 +1. Using Visual Studio.Net 2003: 28 + Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) 29 + will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on 30 + you are building the release or debug version of the library. Check 31 + DotZLib/UnitTests.cs for instructions on how to include unit tests in the 32 + build. 33 + 34 +2. Using NAnt: 35 + Open a command prompt with access to the build environment and run nant 36 + in the same directory as the DotZLib.build file. 37 + You can define 2 properties on the nant command-line to control the build: 38 + debug={true|false} to toggle between release/debug builds (default=true). 39 + nunit={true|false} to include or esclude unit tests (default=true). 40 + Also the target clean will remove binaries. 41 + Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release 42 + or ./DotZLib/bin/debug, depending on whether you are building the release 43 + or debug version of the library. 44 + 45 + Examples: 46 + nant -D:debug=false -D:nunit=false 47 + will build a release mode version of the library without unit tests. 48 + nant 49 + will build a debug version of the library with unit tests 50 + nant clean 51 + will remove all previously built files. 52 + 53 + 54 +--------------------------------- 55 +Copyright (c) Henrik Ravn 2004 56 + 57 +Use, modification and distribution are subject to the Boost Software License, Version 1.0. 58 +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Added compat/zlib/contrib/gcc_gvmat64/gvmat64.S.
1 +/* 2 +;uInt longest_match_x64( 3 +; deflate_state *s, 4 +; IPos cur_match); // current match 5 + 6 +; gvmat64.S -- Asm portion of the optimized longest_match for 32 bits x86_64 7 +; (AMD64 on Athlon 64, Opteron, Phenom 8 +; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) 9 +; this file is translation from gvmat64.asm to GCC 4.x (for Linux, Mac XCode) 10 +; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. 11 +; 12 +; File written by Gilles Vollant, by converting to assembly the longest_match 13 +; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. 14 +; and by taking inspiration on asm686 with masm, optimised assembly code 15 +; from Brian Raiter, written 1998 16 +; 17 +; This software is provided 'as-is', without any express or implied 18 +; warranty. In no event will the authors be held liable for any damages 19 +; arising from the use of this software. 20 +; 21 +; Permission is granted to anyone to use this software for any purpose, 22 +; including commercial applications, and to alter it and redistribute it 23 +; freely, subject to the following restrictions: 24 +; 25 +; 1. The origin of this software must not be misrepresented; you must not 26 +; claim that you wrote the original software. If you use this software 27 +; in a product, an acknowledgment in the product documentation would be 28 +; appreciated but is not required. 29 +; 2. Altered source versions must be plainly marked as such, and must not be 30 +; misrepresented as being the original software 31 +; 3. This notice may not be removed or altered from any source distribution. 32 +; 33 +; http://www.zlib.net 34 +; http://www.winimage.com/zLibDll 35 +; http://www.muppetlabs.com/~breadbox/software/assembly.html 36 +; 37 +; to compile this file for zLib, I use option: 38 +; gcc -c -arch x86_64 gvmat64.S 39 + 40 + 41 +;uInt longest_match(s, cur_match) 42 +; deflate_state *s; 43 +; IPos cur_match; // current match / 44 +; 45 +; with XCode for Mac, I had strange error with some jump on intel syntax 46 +; this is why BEFORE_JMP and AFTER_JMP are used 47 + */ 48 + 49 + 50 +#define BEFORE_JMP .att_syntax 51 +#define AFTER_JMP .intel_syntax noprefix 52 + 53 +#ifndef NO_UNDERLINE 54 +# define match_init _match_init 55 +# define longest_match _longest_match 56 +#endif 57 + 58 +.intel_syntax noprefix 59 + 60 +.globl match_init, longest_match 61 +.text 62 +longest_match: 63 + 64 + 65 + 66 +#define LocalVarsSize 96 67 +/* 68 +; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 69 +; free register : r14,r15 70 +; register can be saved : rsp 71 +*/ 72 + 73 +#define chainlenwmask (rsp + 8 - LocalVarsSize) 74 +#define nicematch (rsp + 16 - LocalVarsSize) 75 + 76 +#define save_rdi (rsp + 24 - LocalVarsSize) 77 +#define save_rsi (rsp + 32 - LocalVarsSize) 78 +#define save_rbx (rsp + 40 - LocalVarsSize) 79 +#define save_rbp (rsp + 48 - LocalVarsSize) 80 +#define save_r12 (rsp + 56 - LocalVarsSize) 81 +#define save_r13 (rsp + 64 - LocalVarsSize) 82 +#define save_r14 (rsp + 72 - LocalVarsSize) 83 +#define save_r15 (rsp + 80 - LocalVarsSize) 84 + 85 + 86 +/* 87 +; all the +4 offsets are due to the addition of pending_buf_size (in zlib 88 +; in the deflate_state structure since the asm code was first written 89 +; (if you compile with zlib 1.0.4 or older, remove the +4). 90 +; Note : these value are good with a 8 bytes boundary pack structure 91 +*/ 92 + 93 +#define MAX_MATCH 258 94 +#define MIN_MATCH 3 95 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 96 + 97 +/* 98 +;;; Offsets for fields in the deflate_state structure. These numbers 99 +;;; are calculated from the definition of deflate_state, with the 100 +;;; assumption that the compiler will dword-align the fields. (Thus, 101 +;;; changing the definition of deflate_state could easily cause this 102 +;;; program to crash horribly, without so much as a warning at 103 +;;; compile time. Sigh.) 104 + 105 +; all the +zlib1222add offsets are due to the addition of fields 106 +; in zlib in the deflate_state structure since the asm code was first written 107 +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). 108 +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). 109 +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). 110 +*/ 111 + 112 + 113 + 114 +/* you can check the structure offset by running 115 + 116 +#include <stdlib.h> 117 +#include <stdio.h> 118 +#include "deflate.h" 119 + 120 +void print_depl() 121 +{ 122 +deflate_state ds; 123 +deflate_state *s=&ds; 124 +printf("size pointer=%u\n",(int)sizeof(void*)); 125 + 126 +printf("#define dsWSize %u\n",(int)(((char*)&(s->w_size))-((char*)s))); 127 +printf("#define dsWMask %u\n",(int)(((char*)&(s->w_mask))-((char*)s))); 128 +printf("#define dsWindow %u\n",(int)(((char*)&(s->window))-((char*)s))); 129 +printf("#define dsPrev %u\n",(int)(((char*)&(s->prev))-((char*)s))); 130 +printf("#define dsMatchLen %u\n",(int)(((char*)&(s->match_length))-((char*)s))); 131 +printf("#define dsPrevMatch %u\n",(int)(((char*)&(s->prev_match))-((char*)s))); 132 +printf("#define dsStrStart %u\n",(int)(((char*)&(s->strstart))-((char*)s))); 133 +printf("#define dsMatchStart %u\n",(int)(((char*)&(s->match_start))-((char*)s))); 134 +printf("#define dsLookahead %u\n",(int)(((char*)&(s->lookahead))-((char*)s))); 135 +printf("#define dsPrevLen %u\n",(int)(((char*)&(s->prev_length))-((char*)s))); 136 +printf("#define dsMaxChainLen %u\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); 137 +printf("#define dsGoodMatch %u\n",(int)(((char*)&(s->good_match))-((char*)s))); 138 +printf("#define dsNiceMatch %u\n",(int)(((char*)&(s->nice_match))-((char*)s))); 139 +} 140 +*/ 141 + 142 +#define dsWSize 68 143 +#define dsWMask 76 144 +#define dsWindow 80 145 +#define dsPrev 96 146 +#define dsMatchLen 144 147 +#define dsPrevMatch 148 148 +#define dsStrStart 156 149 +#define dsMatchStart 160 150 +#define dsLookahead 164 151 +#define dsPrevLen 168 152 +#define dsMaxChainLen 172 153 +#define dsGoodMatch 188 154 +#define dsNiceMatch 192 155 + 156 +#define window_size [ rcx + dsWSize] 157 +#define WMask [ rcx + dsWMask] 158 +#define window_ad [ rcx + dsWindow] 159 +#define prev_ad [ rcx + dsPrev] 160 +#define strstart [ rcx + dsStrStart] 161 +#define match_start [ rcx + dsMatchStart] 162 +#define Lookahead [ rcx + dsLookahead] //; 0ffffffffh on infozip 163 +#define prev_length [ rcx + dsPrevLen] 164 +#define max_chain_length [ rcx + dsMaxChainLen] 165 +#define good_match [ rcx + dsGoodMatch] 166 +#define nice_match [ rcx + dsNiceMatch] 167 + 168 +/* 169 +; windows: 170 +; parameter 1 in rcx(deflate state s), param 2 in rdx (cur match) 171 + 172 +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and 173 +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp 174 +; 175 +; All registers must be preserved across the call, except for 176 +; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. 177 + 178 +; 179 +; gcc on macosx-linux: 180 +; see http://www.x86-64.org/documentation/abi-0.99.pdf 181 +; param 1 in rdi, param 2 in rsi 182 +; rbx, rsp, rbp, r12 to r15 must be preserved 183 + 184 +;;; Save registers that the compiler may be using, and adjust esp to 185 +;;; make room for our stack frame. 186 + 187 + 188 +;;; Retrieve the function arguments. r8d will hold cur_match 189 +;;; throughout the entire function. edx will hold the pointer to the 190 +;;; deflate_state structure during the function's setup (before 191 +;;; entering the main loop. 192 + 193 +; ms: parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) 194 +; mac: param 1 in rdi, param 2 rsi 195 +; this clear high 32 bits of r8, which can be garbage in both r8 and rdx 196 +*/ 197 + mov [save_rbx],rbx 198 + mov [save_rbp],rbp 199 + 200 + 201 + mov rcx,rdi 202 + 203 + mov r8d,esi 204 + 205 + 206 + mov [save_r12],r12 207 + mov [save_r13],r13 208 + mov [save_r14],r14 209 + mov [save_r15],r15 210 + 211 + 212 +//;;; uInt wmask = s->w_mask; 213 +//;;; unsigned chain_length = s->max_chain_length; 214 +//;;; if (s->prev_length >= s->good_match) { 215 +//;;; chain_length >>= 2; 216 +//;;; } 217 + 218 + 219 + mov edi, prev_length 220 + mov esi, good_match 221 + mov eax, WMask 222 + mov ebx, max_chain_length 223 + cmp edi, esi 224 + jl LastMatchGood 225 + shr ebx, 2 226 +LastMatchGood: 227 + 228 +//;;; chainlen is decremented once beforehand so that the function can 229 +//;;; use the sign flag instead of the zero flag for the exit test. 230 +//;;; It is then shifted into the high word, to make room for the wmask 231 +//;;; value, which it will always accompany. 232 + 233 + dec ebx 234 + shl ebx, 16 235 + or ebx, eax 236 + 237 +//;;; on zlib only 238 +//;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; 239 + 240 + 241 + 242 + mov eax, nice_match 243 + mov [chainlenwmask], ebx 244 + mov r10d, Lookahead 245 + cmp r10d, eax 246 + cmovnl r10d, eax 247 + mov [nicematch],r10d 248 + 249 + 250 + 251 +//;;; register Bytef *scan = s->window + s->strstart; 252 + mov r10, window_ad 253 + mov ebp, strstart 254 + lea r13, [r10 + rbp] 255 + 256 +//;;; Determine how many bytes the scan ptr is off from being 257 +//;;; dword-aligned. 258 + 259 + mov r9,r13 260 + neg r13 261 + and r13,3 262 + 263 +//;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 264 +//;;; s->strstart - (IPos)MAX_DIST(s) : NIL; 265 + 266 + 267 + mov eax, window_size 268 + sub eax, MIN_LOOKAHEAD 269 + 270 + 271 + xor edi,edi 272 + sub ebp, eax 273 + 274 + mov r11d, prev_length 275 + 276 + cmovng ebp,edi 277 + 278 +//;;; int best_len = s->prev_length; 279 + 280 + 281 +//;;; Store the sum of s->window + best_len in esi locally, and in esi. 282 + 283 + lea rsi,[r10+r11] 284 + 285 +//;;; register ush scan_start = *(ushf*)scan; 286 +//;;; register ush scan_end = *(ushf*)(scan+best_len-1); 287 +//;;; Posf *prev = s->prev; 288 + 289 + movzx r12d,word ptr [r9] 290 + movzx ebx, word ptr [r9 + r11 - 1] 291 + 292 + mov rdi, prev_ad 293 + 294 +//;;; Jump into the main loop. 295 + 296 + mov edx, [chainlenwmask] 297 + 298 + cmp bx,word ptr [rsi + r8 - 1] 299 + jz LookupLoopIsZero 300 + 301 + 302 + 303 +LookupLoop1: 304 + and r8d, edx 305 + 306 + movzx r8d, word ptr [rdi + r8*2] 307 + cmp r8d, ebp 308 + jbe LeaveNow 309 + 310 + 311 + 312 + sub edx, 0x00010000 313 + BEFORE_JMP 314 + js LeaveNow 315 + AFTER_JMP 316 + 317 +LoopEntry1: 318 + cmp bx,word ptr [rsi + r8 - 1] 319 + BEFORE_JMP 320 + jz LookupLoopIsZero 321 + AFTER_JMP 322 + 323 +LookupLoop2: 324 + and r8d, edx 325 + 326 + movzx r8d, word ptr [rdi + r8*2] 327 + cmp r8d, ebp 328 + BEFORE_JMP 329 + jbe LeaveNow 330 + AFTER_JMP 331 + sub edx, 0x00010000 332 + BEFORE_JMP 333 + js LeaveNow 334 + AFTER_JMP 335 + 336 +LoopEntry2: 337 + cmp bx,word ptr [rsi + r8 - 1] 338 + BEFORE_JMP 339 + jz LookupLoopIsZero 340 + AFTER_JMP 341 + 342 +LookupLoop4: 343 + and r8d, edx 344 + 345 + movzx r8d, word ptr [rdi + r8*2] 346 + cmp r8d, ebp 347 + BEFORE_JMP 348 + jbe LeaveNow 349 + AFTER_JMP 350 + sub edx, 0x00010000 351 + BEFORE_JMP 352 + js LeaveNow 353 + AFTER_JMP 354 + 355 +LoopEntry4: 356 + 357 + cmp bx,word ptr [rsi + r8 - 1] 358 + BEFORE_JMP 359 + jnz LookupLoop1 360 + jmp LookupLoopIsZero 361 + AFTER_JMP 362 +/* 363 +;;; do { 364 +;;; match = s->window + cur_match; 365 +;;; if (*(ushf*)(match+best_len-1) != scan_end || 366 +;;; *(ushf*)match != scan_start) continue; 367 +;;; [...] 368 +;;; } while ((cur_match = prev[cur_match & wmask]) > limit 369 +;;; && --chain_length != 0); 370 +;;; 371 +;;; Here is the inner loop of the function. The function will spend the 372 +;;; majority of its time in this loop, and majority of that time will 373 +;;; be spent in the first ten instructions. 374 +;;; 375 +;;; Within this loop: 376 +;;; ebx = scanend 377 +;;; r8d = curmatch 378 +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) 379 +;;; esi = windowbestlen - i.e., (window + bestlen) 380 +;;; edi = prev 381 +;;; ebp = limit 382 +*/ 383 +.balign 16 384 +LookupLoop: 385 + and r8d, edx 386 + 387 + movzx r8d, word ptr [rdi + r8*2] 388 + cmp r8d, ebp 389 + BEFORE_JMP 390 + jbe LeaveNow 391 + AFTER_JMP 392 + sub edx, 0x00010000 393 + BEFORE_JMP 394 + js LeaveNow 395 + AFTER_JMP 396 + 397 +LoopEntry: 398 + 399 + cmp bx,word ptr [rsi + r8 - 1] 400 + BEFORE_JMP 401 + jnz LookupLoop1 402 + AFTER_JMP 403 +LookupLoopIsZero: 404 + cmp r12w, word ptr [r10 + r8] 405 + BEFORE_JMP 406 + jnz LookupLoop1 407 + AFTER_JMP 408 + 409 + 410 +//;;; Store the current value of chainlen. 411 + mov [chainlenwmask], edx 412 +/* 413 +;;; Point edi to the string under scrutiny, and esi to the string we 414 +;;; are hoping to match it up with. In actuality, esi and edi are 415 +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is 416 +;;; initialized to -(MAX_MATCH_8 - scanalign). 417 +*/ 418 + lea rsi,[r8+r10] 419 + mov rdx, 0xfffffffffffffef8 //; -(MAX_MATCH_8) 420 + lea rsi, [rsi + r13 + 0x0108] //;MAX_MATCH_8] 421 + lea rdi, [r9 + r13 + 0x0108] //;MAX_MATCH_8] 422 + 423 + prefetcht1 [rsi+rdx] 424 + prefetcht1 [rdi+rdx] 425 + 426 +/* 427 +;;; Test the strings for equality, 8 bytes at a time. At the end, 428 +;;; adjust rdx so that it is offset to the exact byte that mismatched. 429 +;;; 430 +;;; We already know at this point that the first three bytes of the 431 +;;; strings match each other, and they can be safely passed over before 432 +;;; starting the compare loop. So what this code does is skip over 0-3 433 +;;; bytes, as much as necessary in order to dword-align the edi 434 +;;; pointer. (rsi will still be misaligned three times out of four.) 435 +;;; 436 +;;; It should be confessed that this loop usually does not represent 437 +;;; much of the total running time. Replacing it with a more 438 +;;; straightforward "rep cmpsb" would not drastically degrade 439 +;;; performance. 440 +*/ 441 + 442 +LoopCmps: 443 + mov rax, [rsi + rdx] 444 + xor rax, [rdi + rdx] 445 + jnz LeaveLoopCmps 446 + 447 + mov rax, [rsi + rdx + 8] 448 + xor rax, [rdi + rdx + 8] 449 + jnz LeaveLoopCmps8 450 + 451 + 452 + mov rax, [rsi + rdx + 8+8] 453 + xor rax, [rdi + rdx + 8+8] 454 + jnz LeaveLoopCmps16 455 + 456 + add rdx,8+8+8 457 + 458 + BEFORE_JMP 459 + jnz LoopCmps 460 + jmp LenMaximum 461 + AFTER_JMP 462 + 463 +LeaveLoopCmps16: add rdx,8 464 +LeaveLoopCmps8: add rdx,8 465 +LeaveLoopCmps: 466 + 467 + test eax, 0x0000FFFF 468 + jnz LenLower 469 + 470 + test eax,0xffffffff 471 + 472 + jnz LenLower32 473 + 474 + add rdx,4 475 + shr rax,32 476 + or ax,ax 477 + BEFORE_JMP 478 + jnz LenLower 479 + AFTER_JMP 480 + 481 +LenLower32: 482 + shr eax,16 483 + add rdx,2 484 + 485 +LenLower: 486 + sub al, 1 487 + adc rdx, 0 488 +//;;; Calculate the length of the match. If it is longer than MAX_MATCH, 489 +//;;; then automatically accept it as the best possible match and leave. 490 + 491 + lea rax, [rdi + rdx] 492 + sub rax, r9 493 + cmp eax, MAX_MATCH 494 + BEFORE_JMP 495 + jge LenMaximum 496 + AFTER_JMP 497 +/* 498 +;;; If the length of the match is not longer than the best match we 499 +;;; have so far, then forget it and return to the lookup loop. 500 +;/////////////////////////////////// 501 +*/ 502 + cmp eax, r11d 503 + jg LongerMatch 504 + 505 + lea rsi,[r10+r11] 506 + 507 + mov rdi, prev_ad 508 + mov edx, [chainlenwmask] 509 + BEFORE_JMP 510 + jmp LookupLoop 511 + AFTER_JMP 512 +/* 513 +;;; s->match_start = cur_match; 514 +;;; best_len = len; 515 +;;; if (len >= nice_match) break; 516 +;;; scan_end = *(ushf*)(scan+best_len-1); 517 +*/ 518 +LongerMatch: 519 + mov r11d, eax 520 + mov match_start, r8d 521 + cmp eax, [nicematch] 522 + BEFORE_JMP 523 + jge LeaveNow 524 + AFTER_JMP 525 + 526 + lea rsi,[r10+rax] 527 + 528 + movzx ebx, word ptr [r9 + rax - 1] 529 + mov rdi, prev_ad 530 + mov edx, [chainlenwmask] 531 + BEFORE_JMP 532 + jmp LookupLoop 533 + AFTER_JMP 534 + 535 +//;;; Accept the current string, with the maximum possible length. 536 + 537 +LenMaximum: 538 + mov r11d,MAX_MATCH 539 + mov match_start, r8d 540 + 541 +//;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 542 +//;;; return s->lookahead; 543 + 544 +LeaveNow: 545 + mov eax, Lookahead 546 + cmp r11d, eax 547 + cmovng eax, r11d 548 + 549 + 550 + 551 +//;;; Restore the stack and return from whence we came. 552 + 553 + 554 +// mov rsi,[save_rsi] 555 +// mov rdi,[save_rdi] 556 + mov rbx,[save_rbx] 557 + mov rbp,[save_rbp] 558 + mov r12,[save_r12] 559 + mov r13,[save_r13] 560 + mov r14,[save_r14] 561 + mov r15,[save_r15] 562 + 563 + 564 + ret 0 565 +//; please don't remove this string ! 566 +//; Your can freely use gvmat64 in any free or commercial app 567 +//; but it is far better don't remove the string in the binary! 568 + // db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 569 + 570 + 571 +match_init: 572 + ret 0 573 + 574 +
Added compat/zlib/contrib/infback9/README.
1 +See infback9.h for what this is and how to use it.
Added compat/zlib/contrib/infback9/infback9.c.
1 +/* infback9.c -- inflate deflate64 data using a call-back interface 2 + * Copyright (C) 1995-2008 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "zutil.h" 7 +#include "infback9.h" 8 +#include "inftree9.h" 9 +#include "inflate9.h" 10 + 11 +#define WSIZE 65536UL 12 + 13 +/* 14 + strm provides memory allocation functions in zalloc and zfree, or 15 + Z_NULL to use the library memory allocation functions. 16 + 17 + window is a user-supplied window and output buffer that is 64K bytes. 18 + */ 19 +int ZEXPORT inflateBack9Init_(strm, window, version, stream_size) 20 +z_stream FAR *strm; 21 +unsigned char FAR *window; 22 +const char *version; 23 +int stream_size; 24 +{ 25 + struct inflate_state FAR *state; 26 + 27 + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 28 + stream_size != (int)(sizeof(z_stream))) 29 + return Z_VERSION_ERROR; 30 + if (strm == Z_NULL || window == Z_NULL) 31 + return Z_STREAM_ERROR; 32 + strm->msg = Z_NULL; /* in case we return an error */ 33 + if (strm->zalloc == (alloc_func)0) { 34 + strm->zalloc = zcalloc; 35 + strm->opaque = (voidpf)0; 36 + } 37 + if (strm->zfree == (free_func)0) strm->zfree = zcfree; 38 + state = (struct inflate_state FAR *)ZALLOC(strm, 1, 39 + sizeof(struct inflate_state)); 40 + if (state == Z_NULL) return Z_MEM_ERROR; 41 + Tracev((stderr, "inflate: allocated\n")); 42 + strm->state = (voidpf)state; 43 + state->window = window; 44 + return Z_OK; 45 +} 46 + 47 +/* 48 + Build and output length and distance decoding tables for fixed code 49 + decoding. 50 + */ 51 +#ifdef MAKEFIXED 52 +#include <stdio.h> 53 + 54 +void makefixed9(void) 55 +{ 56 + unsigned sym, bits, low, size; 57 + code *next, *lenfix, *distfix; 58 + struct inflate_state state; 59 + code fixed[544]; 60 + 61 + /* literal/length table */ 62 + sym = 0; 63 + while (sym < 144) state.lens[sym++] = 8; 64 + while (sym < 256) state.lens[sym++] = 9; 65 + while (sym < 280) state.lens[sym++] = 7; 66 + while (sym < 288) state.lens[sym++] = 8; 67 + next = fixed; 68 + lenfix = next; 69 + bits = 9; 70 + inflate_table9(LENS, state.lens, 288, &(next), &(bits), state.work); 71 + 72 + /* distance table */ 73 + sym = 0; 74 + while (sym < 32) state.lens[sym++] = 5; 75 + distfix = next; 76 + bits = 5; 77 + inflate_table9(DISTS, state.lens, 32, &(next), &(bits), state.work); 78 + 79 + /* write tables */ 80 + puts(" /* inffix9.h -- table for decoding deflate64 fixed codes"); 81 + puts(" * Generated automatically by makefixed9()."); 82 + puts(" */"); 83 + puts(""); 84 + puts(" /* WARNING: this file should *not* be used by applications."); 85 + puts(" It is part of the implementation of this library and is"); 86 + puts(" subject to change. Applications should only use zlib.h."); 87 + puts(" */"); 88 + puts(""); 89 + size = 1U << 9; 90 + printf(" static const code lenfix[%u] = {", size); 91 + low = 0; 92 + for (;;) { 93 + if ((low % 6) == 0) printf("\n "); 94 + printf("{%u,%u,%d}", lenfix[low].op, lenfix[low].bits, 95 + lenfix[low].val); 96 + if (++low == size) break; 97 + putchar(','); 98 + } 99 + puts("\n };"); 100 + size = 1U << 5; 101 + printf("\n static const code distfix[%u] = {", size); 102 + low = 0; 103 + for (;;) { 104 + if ((low % 5) == 0) printf("\n "); 105 + printf("{%u,%u,%d}", distfix[low].op, distfix[low].bits, 106 + distfix[low].val); 107 + if (++low == size) break; 108 + putchar(','); 109 + } 110 + puts("\n };"); 111 +} 112 +#endif /* MAKEFIXED */ 113 + 114 +/* Macros for inflateBack(): */ 115 + 116 +/* Clear the input bit accumulator */ 117 +#define INITBITS() \ 118 + do { \ 119 + hold = 0; \ 120 + bits = 0; \ 121 + } while (0) 122 + 123 +/* Assure that some input is available. If input is requested, but denied, 124 + then return a Z_BUF_ERROR from inflateBack(). */ 125 +#define PULL() \ 126 + do { \ 127 + if (have == 0) { \ 128 + have = in(in_desc, &next); \ 129 + if (have == 0) { \ 130 + next = Z_NULL; \ 131 + ret = Z_BUF_ERROR; \ 132 + goto inf_leave; \ 133 + } \ 134 + } \ 135 + } while (0) 136 + 137 +/* Get a byte of input into the bit accumulator, or return from inflateBack() 138 + with an error if there is no input available. */ 139 +#define PULLBYTE() \ 140 + do { \ 141 + PULL(); \ 142 + have--; \ 143 + hold += (unsigned long)(*next++) << bits; \ 144 + bits += 8; \ 145 + } while (0) 146 + 147 +/* Assure that there are at least n bits in the bit accumulator. If there is 148 + not enough available input to do that, then return from inflateBack() with 149 + an error. */ 150 +#define NEEDBITS(n) \ 151 + do { \ 152 + while (bits < (unsigned)(n)) \ 153 + PULLBYTE(); \ 154 + } while (0) 155 + 156 +/* Return the low n bits of the bit accumulator (n <= 16) */ 157 +#define BITS(n) \ 158 + ((unsigned)hold & ((1U << (n)) - 1)) 159 + 160 +/* Remove n bits from the bit accumulator */ 161 +#define DROPBITS(n) \ 162 + do { \ 163 + hold >>= (n); \ 164 + bits -= (unsigned)(n); \ 165 + } while (0) 166 + 167 +/* Remove zero to seven bits as needed to go to a byte boundary */ 168 +#define BYTEBITS() \ 169 + do { \ 170 + hold >>= bits & 7; \ 171 + bits -= bits & 7; \ 172 + } while (0) 173 + 174 +/* Assure that some output space is available, by writing out the window 175 + if it's full. If the write fails, return from inflateBack() with a 176 + Z_BUF_ERROR. */ 177 +#define ROOM() \ 178 + do { \ 179 + if (left == 0) { \ 180 + put = window; \ 181 + left = WSIZE; \ 182 + wrap = 1; \ 183 + if (out(out_desc, put, (unsigned)left)) { \ 184 + ret = Z_BUF_ERROR; \ 185 + goto inf_leave; \ 186 + } \ 187 + } \ 188 + } while (0) 189 + 190 +/* 191 + strm provides the memory allocation functions and window buffer on input, 192 + and provides information on the unused input on return. For Z_DATA_ERROR 193 + returns, strm will also provide an error message. 194 + 195 + in() and out() are the call-back input and output functions. When 196 + inflateBack() needs more input, it calls in(). When inflateBack() has 197 + filled the window with output, or when it completes with data in the 198 + window, it calls out() to write out the data. The application must not 199 + change the provided input until in() is called again or inflateBack() 200 + returns. The application must not change the window/output buffer until 201 + inflateBack() returns. 202 + 203 + in() and out() are called with a descriptor parameter provided in the 204 + inflateBack() call. This parameter can be a structure that provides the 205 + information required to do the read or write, as well as accumulated 206 + information on the input and output such as totals and check values. 207 + 208 + in() should return zero on failure. out() should return non-zero on 209 + failure. If either in() or out() fails, than inflateBack() returns a 210 + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it 211 + was in() or out() that caused in the error. Otherwise, inflateBack() 212 + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format 213 + error, or Z_MEM_ERROR if it could not allocate memory for the state. 214 + inflateBack() can also return Z_STREAM_ERROR if the input parameters 215 + are not correct, i.e. strm is Z_NULL or the state was not initialized. 216 + */ 217 +int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc) 218 +z_stream FAR *strm; 219 +in_func in; 220 +void FAR *in_desc; 221 +out_func out; 222 +void FAR *out_desc; 223 +{ 224 + struct inflate_state FAR *state; 225 + unsigned char FAR *next; /* next input */ 226 + unsigned char FAR *put; /* next output */ 227 + unsigned have; /* available input */ 228 + unsigned long left; /* available output */ 229 + inflate_mode mode; /* current inflate mode */ 230 + int lastblock; /* true if processing last block */ 231 + int wrap; /* true if the window has wrapped */ 232 + unsigned long write; /* window write index */ 233 + unsigned char FAR *window; /* allocated sliding window, if needed */ 234 + unsigned long hold; /* bit buffer */ 235 + unsigned bits; /* bits in bit buffer */ 236 + unsigned extra; /* extra bits needed */ 237 + unsigned long length; /* literal or length of data to copy */ 238 + unsigned long offset; /* distance back to copy string from */ 239 + unsigned long copy; /* number of stored or match bytes to copy */ 240 + unsigned char FAR *from; /* where to copy match bytes from */ 241 + code const FAR *lencode; /* starting table for length/literal codes */ 242 + code const FAR *distcode; /* starting table for distance codes */ 243 + unsigned lenbits; /* index bits for lencode */ 244 + unsigned distbits; /* index bits for distcode */ 245 + code here; /* current decoding table entry */ 246 + code last; /* parent table entry */ 247 + unsigned len; /* length to copy for repeats, bits to drop */ 248 + int ret; /* return code */ 249 + static const unsigned short order[19] = /* permutation of code lengths */ 250 + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 251 +#include "inffix9.h" 252 + 253 + /* Check that the strm exists and that the state was initialized */ 254 + if (strm == Z_NULL || strm->state == Z_NULL) 255 + return Z_STREAM_ERROR; 256 + state = (struct inflate_state FAR *)strm->state; 257 + 258 + /* Reset the state */ 259 + strm->msg = Z_NULL; 260 + mode = TYPE; 261 + lastblock = 0; 262 + write = 0; 263 + wrap = 0; 264 + window = state->window; 265 + next = strm->next_in; 266 + have = next != Z_NULL ? strm->avail_in : 0; 267 + hold = 0; 268 + bits = 0; 269 + put = window; 270 + left = WSIZE; 271 + lencode = Z_NULL; 272 + distcode = Z_NULL; 273 + 274 + /* Inflate until end of block marked as last */ 275 + for (;;) 276 + switch (mode) { 277 + case TYPE: 278 + /* determine and dispatch block type */ 279 + if (lastblock) { 280 + BYTEBITS(); 281 + mode = DONE; 282 + break; 283 + } 284 + NEEDBITS(3); 285 + lastblock = BITS(1); 286 + DROPBITS(1); 287 + switch (BITS(2)) { 288 + case 0: /* stored block */ 289 + Tracev((stderr, "inflate: stored block%s\n", 290 + lastblock ? " (last)" : "")); 291 + mode = STORED; 292 + break; 293 + case 1: /* fixed block */ 294 + lencode = lenfix; 295 + lenbits = 9; 296 + distcode = distfix; 297 + distbits = 5; 298 + Tracev((stderr, "inflate: fixed codes block%s\n", 299 + lastblock ? " (last)" : "")); 300 + mode = LEN; /* decode codes */ 301 + break; 302 + case 2: /* dynamic block */ 303 + Tracev((stderr, "inflate: dynamic codes block%s\n", 304 + lastblock ? " (last)" : "")); 305 + mode = TABLE; 306 + break; 307 + case 3: 308 + strm->msg = (char *)"invalid block type"; 309 + mode = BAD; 310 + } 311 + DROPBITS(2); 312 + break; 313 + 314 + case STORED: 315 + /* get and verify stored block length */ 316 + BYTEBITS(); /* go to byte boundary */ 317 + NEEDBITS(32); 318 + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 319 + strm->msg = (char *)"invalid stored block lengths"; 320 + mode = BAD; 321 + break; 322 + } 323 + length = (unsigned)hold & 0xffff; 324 + Tracev((stderr, "inflate: stored length %lu\n", 325 + length)); 326 + INITBITS(); 327 + 328 + /* copy stored block from input to output */ 329 + while (length != 0) { 330 + copy = length; 331 + PULL(); 332 + ROOM(); 333 + if (copy > have) copy = have; 334 + if (copy > left) copy = left; 335 + zmemcpy(put, next, copy); 336 + have -= copy; 337 + next += copy; 338 + left -= copy; 339 + put += copy; 340 + length -= copy; 341 + } 342 + Tracev((stderr, "inflate: stored end\n")); 343 + mode = TYPE; 344 + break; 345 + 346 + case TABLE: 347 + /* get dynamic table entries descriptor */ 348 + NEEDBITS(14); 349 + state->nlen = BITS(5) + 257; 350 + DROPBITS(5); 351 + state->ndist = BITS(5) + 1; 352 + DROPBITS(5); 353 + state->ncode = BITS(4) + 4; 354 + DROPBITS(4); 355 + if (state->nlen > 286) { 356 + strm->msg = (char *)"too many length symbols"; 357 + mode = BAD; 358 + break; 359 + } 360 + Tracev((stderr, "inflate: table sizes ok\n")); 361 + 362 + /* get code length code lengths (not a typo) */ 363 + state->have = 0; 364 + while (state->have < state->ncode) { 365 + NEEDBITS(3); 366 + state->lens[order[state->have++]] = (unsigned short)BITS(3); 367 + DROPBITS(3); 368 + } 369 + while (state->have < 19) 370 + state->lens[order[state->have++]] = 0; 371 + state->next = state->codes; 372 + lencode = (code const FAR *)(state->next); 373 + lenbits = 7; 374 + ret = inflate_table9(CODES, state->lens, 19, &(state->next), 375 + &(lenbits), state->work); 376 + if (ret) { 377 + strm->msg = (char *)"invalid code lengths set"; 378 + mode = BAD; 379 + break; 380 + } 381 + Tracev((stderr, "inflate: code lengths ok\n")); 382 + 383 + /* get length and distance code code lengths */ 384 + state->have = 0; 385 + while (state->have < state->nlen + state->ndist) { 386 + for (;;) { 387 + here = lencode[BITS(lenbits)]; 388 + if ((unsigned)(here.bits) <= bits) break; 389 + PULLBYTE(); 390 + } 391 + if (here.val < 16) { 392 + NEEDBITS(here.bits); 393 + DROPBITS(here.bits); 394 + state->lens[state->have++] = here.val; 395 + } 396 + else { 397 + if (here.val == 16) { 398 + NEEDBITS(here.bits + 2); 399 + DROPBITS(here.bits); 400 + if (state->have == 0) { 401 + strm->msg = (char *)"invalid bit length repeat"; 402 + mode = BAD; 403 + break; 404 + } 405 + len = (unsigned)(state->lens[state->have - 1]); 406 + copy = 3 + BITS(2); 407 + DROPBITS(2); 408 + } 409 + else if (here.val == 17) { 410 + NEEDBITS(here.bits + 3); 411 + DROPBITS(here.bits); 412 + len = 0; 413 + copy = 3 + BITS(3); 414 + DROPBITS(3); 415 + } 416 + else { 417 + NEEDBITS(here.bits + 7); 418 + DROPBITS(here.bits); 419 + len = 0; 420 + copy = 11 + BITS(7); 421 + DROPBITS(7); 422 + } 423 + if (state->have + copy > state->nlen + state->ndist) { 424 + strm->msg = (char *)"invalid bit length repeat"; 425 + mode = BAD; 426 + break; 427 + } 428 + while (copy--) 429 + state->lens[state->have++] = (unsigned short)len; 430 + } 431 + } 432 + 433 + /* handle error breaks in while */ 434 + if (mode == BAD) break; 435 + 436 + /* check for end-of-block code (better have one) */ 437 + if (state->lens[256] == 0) { 438 + strm->msg = (char *)"invalid code -- missing end-of-block"; 439 + mode = BAD; 440 + break; 441 + } 442 + 443 + /* build code tables -- note: do not change the lenbits or distbits 444 + values here (9 and 6) without reading the comments in inftree9.h 445 + concerning the ENOUGH constants, which depend on those values */ 446 + state->next = state->codes; 447 + lencode = (code const FAR *)(state->next); 448 + lenbits = 9; 449 + ret = inflate_table9(LENS, state->lens, state->nlen, 450 + &(state->next), &(lenbits), state->work); 451 + if (ret) { 452 + strm->msg = (char *)"invalid literal/lengths set"; 453 + mode = BAD; 454 + break; 455 + } 456 + distcode = (code const FAR *)(state->next); 457 + distbits = 6; 458 + ret = inflate_table9(DISTS, state->lens + state->nlen, 459 + state->ndist, &(state->next), &(distbits), 460 + state->work); 461 + if (ret) { 462 + strm->msg = (char *)"invalid distances set"; 463 + mode = BAD; 464 + break; 465 + } 466 + Tracev((stderr, "inflate: codes ok\n")); 467 + mode = LEN; 468 + 469 + case LEN: 470 + /* get a literal, length, or end-of-block code */ 471 + for (;;) { 472 + here = lencode[BITS(lenbits)]; 473 + if ((unsigned)(here.bits) <= bits) break; 474 + PULLBYTE(); 475 + } 476 + if (here.op && (here.op & 0xf0) == 0) { 477 + last = here; 478 + for (;;) { 479 + here = lencode[last.val + 480 + (BITS(last.bits + last.op) >> last.bits)]; 481 + if ((unsigned)(last.bits + here.bits) <= bits) break; 482 + PULLBYTE(); 483 + } 484 + DROPBITS(last.bits); 485 + } 486 + DROPBITS(here.bits); 487 + length = (unsigned)here.val; 488 + 489 + /* process literal */ 490 + if (here.op == 0) { 491 + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 492 + "inflate: literal '%c'\n" : 493 + "inflate: literal 0x%02x\n", here.val)); 494 + ROOM(); 495 + *put++ = (unsigned char)(length); 496 + left--; 497 + mode = LEN; 498 + break; 499 + } 500 + 501 + /* process end of block */ 502 + if (here.op & 32) { 503 + Tracevv((stderr, "inflate: end of block\n")); 504 + mode = TYPE; 505 + break; 506 + } 507 + 508 + /* invalid code */ 509 + if (here.op & 64) { 510 + strm->msg = (char *)"invalid literal/length code"; 511 + mode = BAD; 512 + break; 513 + } 514 + 515 + /* length code -- get extra bits, if any */ 516 + extra = (unsigned)(here.op) & 31; 517 + if (extra != 0) { 518 + NEEDBITS(extra); 519 + length += BITS(extra); 520 + DROPBITS(extra); 521 + } 522 + Tracevv((stderr, "inflate: length %lu\n", length)); 523 + 524 + /* get distance code */ 525 + for (;;) { 526 + here = distcode[BITS(distbits)]; 527 + if ((unsigned)(here.bits) <= bits) break; 528 + PULLBYTE(); 529 + } 530 + if ((here.op & 0xf0) == 0) { 531 + last = here; 532 + for (;;) { 533 + here = distcode[last.val + 534 + (BITS(last.bits + last.op) >> last.bits)]; 535 + if ((unsigned)(last.bits + here.bits) <= bits) break; 536 + PULLBYTE(); 537 + } 538 + DROPBITS(last.bits); 539 + } 540 + DROPBITS(here.bits); 541 + if (here.op & 64) { 542 + strm->msg = (char *)"invalid distance code"; 543 + mode = BAD; 544 + break; 545 + } 546 + offset = (unsigned)here.val; 547 + 548 + /* get distance extra bits, if any */ 549 + extra = (unsigned)(here.op) & 15; 550 + if (extra != 0) { 551 + NEEDBITS(extra); 552 + offset += BITS(extra); 553 + DROPBITS(extra); 554 + } 555 + if (offset > WSIZE - (wrap ? 0: left)) { 556 + strm->msg = (char *)"invalid distance too far back"; 557 + mode = BAD; 558 + break; 559 + } 560 + Tracevv((stderr, "inflate: distance %lu\n", offset)); 561 + 562 + /* copy match from window to output */ 563 + do { 564 + ROOM(); 565 + copy = WSIZE - offset; 566 + if (copy < left) { 567 + from = put + copy; 568 + copy = left - copy; 569 + } 570 + else { 571 + from = put - offset; 572 + copy = left; 573 + } 574 + if (copy > length) copy = length; 575 + length -= copy; 576 + left -= copy; 577 + do { 578 + *put++ = *from++; 579 + } while (--copy); 580 + } while (length != 0); 581 + break; 582 + 583 + case DONE: 584 + /* inflate stream terminated properly -- write leftover output */ 585 + ret = Z_STREAM_END; 586 + if (left < WSIZE) { 587 + if (out(out_desc, window, (unsigned)(WSIZE - left))) 588 + ret = Z_BUF_ERROR; 589 + } 590 + goto inf_leave; 591 + 592 + case BAD: 593 + ret = Z_DATA_ERROR; 594 + goto inf_leave; 595 + 596 + default: /* can't happen, but makes compilers happy */ 597 + ret = Z_STREAM_ERROR; 598 + goto inf_leave; 599 + } 600 + 601 + /* Return unused input */ 602 + inf_leave: 603 + strm->next_in = next; 604 + strm->avail_in = have; 605 + return ret; 606 +} 607 + 608 +int ZEXPORT inflateBack9End(strm) 609 +z_stream FAR *strm; 610 +{ 611 + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 612 + return Z_STREAM_ERROR; 613 + ZFREE(strm, strm->state); 614 + strm->state = Z_NULL; 615 + Tracev((stderr, "inflate: end\n")); 616 + return Z_OK; 617 +}
Added compat/zlib/contrib/infback9/infback9.h.
1 +/* infback9.h -- header for using inflateBack9 functions 2 + * Copyright (C) 2003 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* 7 + * This header file and associated patches provide a decoder for PKWare's 8 + * undocumented deflate64 compression method (method 9). Use with infback9.c, 9 + * inftree9.h, inftree9.c, and inffix9.h. These patches are not supported. 10 + * This should be compiled with zlib, since it uses zutil.h and zutil.o. 11 + * This code has not yet been tested on 16-bit architectures. See the 12 + * comments in zlib.h for inflateBack() usage. These functions are used 13 + * identically, except that there is no windowBits parameter, and a 64K 14 + * window must be provided. Also if int's are 16 bits, then a zero for 15 + * the third parameter of the "out" function actually means 65536UL. 16 + * zlib.h must be included before this header file. 17 + */ 18 + 19 +#ifdef __cplusplus 20 +extern "C" { 21 +#endif 22 + 23 +ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm, 24 + in_func in, void FAR *in_desc, 25 + out_func out, void FAR *out_desc)); 26 +ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm)); 27 +ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm, 28 + unsigned char FAR *window, 29 + const char *version, 30 + int stream_size)); 31 +#define inflateBack9Init(strm, window) \ 32 + inflateBack9Init_((strm), (window), \ 33 + ZLIB_VERSION, sizeof(z_stream)) 34 + 35 +#ifdef __cplusplus 36 +} 37 +#endif
Added compat/zlib/contrib/infback9/inffix9.h.
1 + /* inffix9.h -- table for decoding deflate64 fixed codes 2 + * Generated automatically by makefixed9(). 3 + */ 4 + 5 + /* WARNING: this file should *not* be used by applications. 6 + It is part of the implementation of this library and is 7 + subject to change. Applications should only use zlib.h. 8 + */ 9 + 10 + static const code lenfix[512] = { 11 + {96,7,0},{0,8,80},{0,8,16},{132,8,115},{130,7,31},{0,8,112}, 12 + {0,8,48},{0,9,192},{128,7,10},{0,8,96},{0,8,32},{0,9,160}, 13 + {0,8,0},{0,8,128},{0,8,64},{0,9,224},{128,7,6},{0,8,88}, 14 + {0,8,24},{0,9,144},{131,7,59},{0,8,120},{0,8,56},{0,9,208}, 15 + {129,7,17},{0,8,104},{0,8,40},{0,9,176},{0,8,8},{0,8,136}, 16 + {0,8,72},{0,9,240},{128,7,4},{0,8,84},{0,8,20},{133,8,227}, 17 + {131,7,43},{0,8,116},{0,8,52},{0,9,200},{129,7,13},{0,8,100}, 18 + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232}, 19 + {128,7,8},{0,8,92},{0,8,28},{0,9,152},{132,7,83},{0,8,124}, 20 + {0,8,60},{0,9,216},{130,7,23},{0,8,108},{0,8,44},{0,9,184}, 21 + {0,8,12},{0,8,140},{0,8,76},{0,9,248},{128,7,3},{0,8,82}, 22 + {0,8,18},{133,8,163},{131,7,35},{0,8,114},{0,8,50},{0,9,196}, 23 + {129,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},{0,8,130}, 24 + {0,8,66},{0,9,228},{128,7,7},{0,8,90},{0,8,26},{0,9,148}, 25 + {132,7,67},{0,8,122},{0,8,58},{0,9,212},{130,7,19},{0,8,106}, 26 + {0,8,42},{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244}, 27 + {128,7,5},{0,8,86},{0,8,22},{65,8,0},{131,7,51},{0,8,118}, 28 + {0,8,54},{0,9,204},{129,7,15},{0,8,102},{0,8,38},{0,9,172}, 29 + {0,8,6},{0,8,134},{0,8,70},{0,9,236},{128,7,9},{0,8,94}, 30 + {0,8,30},{0,9,156},{132,7,99},{0,8,126},{0,8,62},{0,9,220}, 31 + {130,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 32 + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{133,8,131}, 33 + {130,7,31},{0,8,113},{0,8,49},{0,9,194},{128,7,10},{0,8,97}, 34 + {0,8,33},{0,9,162},{0,8,1},{0,8,129},{0,8,65},{0,9,226}, 35 + {128,7,6},{0,8,89},{0,8,25},{0,9,146},{131,7,59},{0,8,121}, 36 + {0,8,57},{0,9,210},{129,7,17},{0,8,105},{0,8,41},{0,9,178}, 37 + {0,8,9},{0,8,137},{0,8,73},{0,9,242},{128,7,4},{0,8,85}, 38 + {0,8,21},{144,8,3},{131,7,43},{0,8,117},{0,8,53},{0,9,202}, 39 + {129,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133}, 40 + {0,8,69},{0,9,234},{128,7,8},{0,8,93},{0,8,29},{0,9,154}, 41 + {132,7,83},{0,8,125},{0,8,61},{0,9,218},{130,7,23},{0,8,109}, 42 + {0,8,45},{0,9,186},{0,8,13},{0,8,141},{0,8,77},{0,9,250}, 43 + {128,7,3},{0,8,83},{0,8,19},{133,8,195},{131,7,35},{0,8,115}, 44 + {0,8,51},{0,9,198},{129,7,11},{0,8,99},{0,8,35},{0,9,166}, 45 + {0,8,3},{0,8,131},{0,8,67},{0,9,230},{128,7,7},{0,8,91}, 46 + {0,8,27},{0,9,150},{132,7,67},{0,8,123},{0,8,59},{0,9,214}, 47 + {130,7,19},{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139}, 48 + {0,8,75},{0,9,246},{128,7,5},{0,8,87},{0,8,23},{77,8,0}, 49 + {131,7,51},{0,8,119},{0,8,55},{0,9,206},{129,7,15},{0,8,103}, 50 + {0,8,39},{0,9,174},{0,8,7},{0,8,135},{0,8,71},{0,9,238}, 51 + {128,7,9},{0,8,95},{0,8,31},{0,9,158},{132,7,99},{0,8,127}, 52 + {0,8,63},{0,9,222},{130,7,27},{0,8,111},{0,8,47},{0,9,190}, 53 + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80}, 54 + {0,8,16},{132,8,115},{130,7,31},{0,8,112},{0,8,48},{0,9,193}, 55 + {128,7,10},{0,8,96},{0,8,32},{0,9,161},{0,8,0},{0,8,128}, 56 + {0,8,64},{0,9,225},{128,7,6},{0,8,88},{0,8,24},{0,9,145}, 57 + {131,7,59},{0,8,120},{0,8,56},{0,9,209},{129,7,17},{0,8,104}, 58 + {0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},{0,9,241}, 59 + {128,7,4},{0,8,84},{0,8,20},{133,8,227},{131,7,43},{0,8,116}, 60 + {0,8,52},{0,9,201},{129,7,13},{0,8,100},{0,8,36},{0,9,169}, 61 + {0,8,4},{0,8,132},{0,8,68},{0,9,233},{128,7,8},{0,8,92}, 62 + {0,8,28},{0,9,153},{132,7,83},{0,8,124},{0,8,60},{0,9,217}, 63 + {130,7,23},{0,8,108},{0,8,44},{0,9,185},{0,8,12},{0,8,140}, 64 + {0,8,76},{0,9,249},{128,7,3},{0,8,82},{0,8,18},{133,8,163}, 65 + {131,7,35},{0,8,114},{0,8,50},{0,9,197},{129,7,11},{0,8,98}, 66 + {0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 67 + {128,7,7},{0,8,90},{0,8,26},{0,9,149},{132,7,67},{0,8,122}, 68 + {0,8,58},{0,9,213},{130,7,19},{0,8,106},{0,8,42},{0,9,181}, 69 + {0,8,10},{0,8,138},{0,8,74},{0,9,245},{128,7,5},{0,8,86}, 70 + {0,8,22},{65,8,0},{131,7,51},{0,8,118},{0,8,54},{0,9,205}, 71 + {129,7,15},{0,8,102},{0,8,38},{0,9,173},{0,8,6},{0,8,134}, 72 + {0,8,70},{0,9,237},{128,7,9},{0,8,94},{0,8,30},{0,9,157}, 73 + {132,7,99},{0,8,126},{0,8,62},{0,9,221},{130,7,27},{0,8,110}, 74 + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253}, 75 + {96,7,0},{0,8,81},{0,8,17},{133,8,131},{130,7,31},{0,8,113}, 76 + {0,8,49},{0,9,195},{128,7,10},{0,8,97},{0,8,33},{0,9,163}, 77 + {0,8,1},{0,8,129},{0,8,65},{0,9,227},{128,7,6},{0,8,89}, 78 + {0,8,25},{0,9,147},{131,7,59},{0,8,121},{0,8,57},{0,9,211}, 79 + {129,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},{0,8,137}, 80 + {0,8,73},{0,9,243},{128,7,4},{0,8,85},{0,8,21},{144,8,3}, 81 + {131,7,43},{0,8,117},{0,8,53},{0,9,203},{129,7,13},{0,8,101}, 82 + {0,8,37},{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235}, 83 + {128,7,8},{0,8,93},{0,8,29},{0,9,155},{132,7,83},{0,8,125}, 84 + {0,8,61},{0,9,219},{130,7,23},{0,8,109},{0,8,45},{0,9,187}, 85 + {0,8,13},{0,8,141},{0,8,77},{0,9,251},{128,7,3},{0,8,83}, 86 + {0,8,19},{133,8,195},{131,7,35},{0,8,115},{0,8,51},{0,9,199}, 87 + {129,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 88 + {0,8,67},{0,9,231},{128,7,7},{0,8,91},{0,8,27},{0,9,151}, 89 + {132,7,67},{0,8,123},{0,8,59},{0,9,215},{130,7,19},{0,8,107}, 90 + {0,8,43},{0,9,183},{0,8,11},{0,8,139},{0,8,75},{0,9,247}, 91 + {128,7,5},{0,8,87},{0,8,23},{77,8,0},{131,7,51},{0,8,119}, 92 + {0,8,55},{0,9,207},{129,7,15},{0,8,103},{0,8,39},{0,9,175}, 93 + {0,8,7},{0,8,135},{0,8,71},{0,9,239},{128,7,9},{0,8,95}, 94 + {0,8,31},{0,9,159},{132,7,99},{0,8,127},{0,8,63},{0,9,223}, 95 + {130,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143}, 96 + {0,8,79},{0,9,255} 97 + }; 98 + 99 + static const code distfix[32] = { 100 + {128,5,1},{135,5,257},{131,5,17},{139,5,4097},{129,5,5}, 101 + {137,5,1025},{133,5,65},{141,5,16385},{128,5,3},{136,5,513}, 102 + {132,5,33},{140,5,8193},{130,5,9},{138,5,2049},{134,5,129}, 103 + {142,5,32769},{128,5,2},{135,5,385},{131,5,25},{139,5,6145}, 104 + {129,5,7},{137,5,1537},{133,5,97},{141,5,24577},{128,5,4}, 105 + {136,5,769},{132,5,49},{140,5,12289},{130,5,13},{138,5,3073}, 106 + {134,5,193},{142,5,49153} 107 + };
Added compat/zlib/contrib/infback9/inflate9.h.
1 +/* inflate9.h -- internal inflate state definition 2 + * Copyright (C) 1995-2003 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* Possible inflate modes between inflate() calls */ 12 +typedef enum { 13 + TYPE, /* i: waiting for type bits, including last-flag bit */ 14 + STORED, /* i: waiting for stored size (length and complement) */ 15 + TABLE, /* i: waiting for dynamic block table lengths */ 16 + LEN, /* i: waiting for length/lit code */ 17 + DONE, /* finished check, done -- remain here until reset */ 18 + BAD /* got a data error -- remain here until reset */ 19 +} inflate_mode; 20 + 21 +/* 22 + State transitions between above modes - 23 + 24 + (most modes can go to the BAD mode -- not shown for clarity) 25 + 26 + Read deflate blocks: 27 + TYPE -> STORED or TABLE or LEN or DONE 28 + STORED -> TYPE 29 + TABLE -> LENLENS -> CODELENS -> LEN 30 + Read deflate codes: 31 + LEN -> LEN or TYPE 32 + */ 33 + 34 +/* state maintained between inflate() calls. Approximately 7K bytes. */ 35 +struct inflate_state { 36 + /* sliding window */ 37 + unsigned char FAR *window; /* allocated sliding window, if needed */ 38 + /* dynamic table building */ 39 + unsigned ncode; /* number of code length code lengths */ 40 + unsigned nlen; /* number of length code lengths */ 41 + unsigned ndist; /* number of distance code lengths */ 42 + unsigned have; /* number of code lengths in lens[] */ 43 + code FAR *next; /* next available space in codes[] */ 44 + unsigned short lens[320]; /* temporary storage for code lengths */ 45 + unsigned short work[288]; /* work area for code table building */ 46 + code codes[ENOUGH]; /* space for code tables */ 47 +};
Added compat/zlib/contrib/infback9/inftree9.c.
1 +/* inftree9.c -- generate Huffman trees for efficient decoding 2 + * Copyright (C) 1995-2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "zutil.h" 7 +#include "inftree9.h" 8 + 9 +#define MAXBITS 15 10 + 11 +const char inflate9_copyright[] = 12 + " inflate9 1.2.7 Copyright 1995-2012 Mark Adler "; 13 +/* 14 + If you use the zlib library in a product, an acknowledgment is welcome 15 + in the documentation of your product. If for some reason you cannot 16 + include such an acknowledgment, I would appreciate that you keep this 17 + copyright string in the executable of your product. 18 + */ 19 + 20 +/* 21 + Build a set of tables to decode the provided canonical Huffman code. 22 + The code lengths are lens[0..codes-1]. The result starts at *table, 23 + whose indices are 0..2^bits-1. work is a writable array of at least 24 + lens shorts, which is used as a work area. type is the type of code 25 + to be generated, CODES, LENS, or DISTS. On return, zero is success, 26 + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 27 + on return points to the next available entry's address. bits is the 28 + requested root table index bits, and on return it is the actual root 29 + table index bits. It will differ if the request is greater than the 30 + longest code or if it is less than the shortest code. 31 + */ 32 +int inflate_table9(type, lens, codes, table, bits, work) 33 +codetype type; 34 +unsigned short FAR *lens; 35 +unsigned codes; 36 +code FAR * FAR *table; 37 +unsigned FAR *bits; 38 +unsigned short FAR *work; 39 +{ 40 + unsigned len; /* a code's length in bits */ 41 + unsigned sym; /* index of code symbols */ 42 + unsigned min, max; /* minimum and maximum code lengths */ 43 + unsigned root; /* number of index bits for root table */ 44 + unsigned curr; /* number of index bits for current table */ 45 + unsigned drop; /* code bits to drop for sub-table */ 46 + int left; /* number of prefix codes available */ 47 + unsigned used; /* code entries in table used */ 48 + unsigned huff; /* Huffman code */ 49 + unsigned incr; /* for incrementing code, index */ 50 + unsigned fill; /* index for replicating entries */ 51 + unsigned low; /* low bits for current root entry */ 52 + unsigned mask; /* mask for low root bits */ 53 + code this; /* table entry for duplication */ 54 + code FAR *next; /* next available space in table */ 55 + const unsigned short FAR *base; /* base value table to use */ 56 + const unsigned short FAR *extra; /* extra bits table to use */ 57 + int end; /* use base and extra for symbol > end */ 58 + unsigned short count[MAXBITS+1]; /* number of codes of each length */ 59 + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 60 + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 61 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 62 + 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 63 + 131, 163, 195, 227, 3, 0, 0}; 64 + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 65 + 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 66 + 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, 67 + 133, 133, 133, 133, 144, 78, 68}; 68 + static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ 69 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 70 + 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 71 + 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153}; 72 + static const unsigned short dext[32] = { /* Distance codes 0..31 extra */ 73 + 128, 128, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132, 74 + 133, 133, 134, 134, 135, 135, 136, 136, 137, 137, 138, 138, 75 + 139, 139, 140, 140, 141, 141, 142, 142}; 76 + 77 + /* 78 + Process a set of code lengths to create a canonical Huffman code. The 79 + code lengths are lens[0..codes-1]. Each length corresponds to the 80 + symbols 0..codes-1. The Huffman code is generated by first sorting the 81 + symbols by length from short to long, and retaining the symbol order 82 + for codes with equal lengths. Then the code starts with all zero bits 83 + for the first code of the shortest length, and the codes are integer 84 + increments for the same length, and zeros are appended as the length 85 + increases. For the deflate format, these bits are stored backwards 86 + from their more natural integer increment ordering, and so when the 87 + decoding tables are built in the large loop below, the integer codes 88 + are incremented backwards. 89 + 90 + This routine assumes, but does not check, that all of the entries in 91 + lens[] are in the range 0..MAXBITS. The caller must assure this. 92 + 1..MAXBITS is interpreted as that code length. zero means that that 93 + symbol does not occur in this code. 94 + 95 + The codes are sorted by computing a count of codes for each length, 96 + creating from that a table of starting indices for each length in the 97 + sorted table, and then entering the symbols in order in the sorted 98 + table. The sorted table is work[], with that space being provided by 99 + the caller. 100 + 101 + The length counts are used for other purposes as well, i.e. finding 102 + the minimum and maximum length codes, determining if there are any 103 + codes at all, checking for a valid set of lengths, and looking ahead 104 + at length counts to determine sub-table sizes when building the 105 + decoding tables. 106 + */ 107 + 108 + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 109 + for (len = 0; len <= MAXBITS; len++) 110 + count[len] = 0; 111 + for (sym = 0; sym < codes; sym++) 112 + count[lens[sym]]++; 113 + 114 + /* bound code lengths, force root to be within code lengths */ 115 + root = *bits; 116 + for (max = MAXBITS; max >= 1; max--) 117 + if (count[max] != 0) break; 118 + if (root > max) root = max; 119 + if (max == 0) return -1; /* no codes! */ 120 + for (min = 1; min <= MAXBITS; min++) 121 + if (count[min] != 0) break; 122 + if (root < min) root = min; 123 + 124 + /* check for an over-subscribed or incomplete set of lengths */ 125 + left = 1; 126 + for (len = 1; len <= MAXBITS; len++) { 127 + left <<= 1; 128 + left -= count[len]; 129 + if (left < 0) return -1; /* over-subscribed */ 130 + } 131 + if (left > 0 && (type == CODES || max != 1)) 132 + return -1; /* incomplete set */ 133 + 134 + /* generate offsets into symbol table for each length for sorting */ 135 + offs[1] = 0; 136 + for (len = 1; len < MAXBITS; len++) 137 + offs[len + 1] = offs[len] + count[len]; 138 + 139 + /* sort symbols by length, by symbol order within each length */ 140 + for (sym = 0; sym < codes; sym++) 141 + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 142 + 143 + /* 144 + Create and fill in decoding tables. In this loop, the table being 145 + filled is at next and has curr index bits. The code being used is huff 146 + with length len. That code is converted to an index by dropping drop 147 + bits off of the bottom. For codes where len is less than drop + curr, 148 + those top drop + curr - len bits are incremented through all values to 149 + fill the table with replicated entries. 150 + 151 + root is the number of index bits for the root table. When len exceeds 152 + root, sub-tables are created pointed to by the root entry with an index 153 + of the low root bits of huff. This is saved in low to check for when a 154 + new sub-table should be started. drop is zero when the root table is 155 + being filled, and drop is root when sub-tables are being filled. 156 + 157 + When a new sub-table is needed, it is necessary to look ahead in the 158 + code lengths to determine what size sub-table is needed. The length 159 + counts are used for this, and so count[] is decremented as codes are 160 + entered in the tables. 161 + 162 + used keeps track of how many table entries have been allocated from the 163 + provided *table space. It is checked for LENS and DIST tables against 164 + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in 165 + the initial root table size constants. See the comments in inftree9.h 166 + for more information. 167 + 168 + sym increments through all symbols, and the loop terminates when 169 + all codes of length max, i.e. all codes, have been processed. This 170 + routine permits incomplete codes, so another loop after this one fills 171 + in the rest of the decoding tables with invalid code markers. 172 + */ 173 + 174 + /* set up for code type */ 175 + switch (type) { 176 + case CODES: 177 + base = extra = work; /* dummy value--not used */ 178 + end = 19; 179 + break; 180 + case LENS: 181 + base = lbase; 182 + base -= 257; 183 + extra = lext; 184 + extra -= 257; 185 + end = 256; 186 + break; 187 + default: /* DISTS */ 188 + base = dbase; 189 + extra = dext; 190 + end = -1; 191 + } 192 + 193 + /* initialize state for loop */ 194 + huff = 0; /* starting code */ 195 + sym = 0; /* starting code symbol */ 196 + len = min; /* starting code length */ 197 + next = *table; /* current table to fill in */ 198 + curr = root; /* current table index bits */ 199 + drop = 0; /* current bits to drop from code for index */ 200 + low = (unsigned)(-1); /* trigger new sub-table when len > root */ 201 + used = 1U << root; /* use root table entries */ 202 + mask = used - 1; /* mask for comparing low */ 203 + 204 + /* check available table space */ 205 + if ((type == LENS && used >= ENOUGH_LENS) || 206 + (type == DISTS && used >= ENOUGH_DISTS)) 207 + return 1; 208 + 209 + /* process all codes and make table entries */ 210 + for (;;) { 211 + /* create table entry */ 212 + this.bits = (unsigned char)(len - drop); 213 + if ((int)(work[sym]) < end) { 214 + this.op = (unsigned char)0; 215 + this.val = work[sym]; 216 + } 217 + else if ((int)(work[sym]) > end) { 218 + this.op = (unsigned char)(extra[work[sym]]); 219 + this.val = base[work[sym]]; 220 + } 221 + else { 222 + this.op = (unsigned char)(32 + 64); /* end of block */ 223 + this.val = 0; 224 + } 225 + 226 + /* replicate for those indices with low len bits equal to huff */ 227 + incr = 1U << (len - drop); 228 + fill = 1U << curr; 229 + do { 230 + fill -= incr; 231 + next[(huff >> drop) + fill] = this; 232 + } while (fill != 0); 233 + 234 + /* backwards increment the len-bit code huff */ 235 + incr = 1U << (len - 1); 236 + while (huff & incr) 237 + incr >>= 1; 238 + if (incr != 0) { 239 + huff &= incr - 1; 240 + huff += incr; 241 + } 242 + else 243 + huff = 0; 244 + 245 + /* go to next symbol, update count, len */ 246 + sym++; 247 + if (--(count[len]) == 0) { 248 + if (len == max) break; 249 + len = lens[work[sym]]; 250 + } 251 + 252 + /* create new sub-table if needed */ 253 + if (len > root && (huff & mask) != low) { 254 + /* if first time, transition to sub-tables */ 255 + if (drop == 0) 256 + drop = root; 257 + 258 + /* increment past last table */ 259 + next += 1U << curr; 260 + 261 + /* determine length of next table */ 262 + curr = len - drop; 263 + left = (int)(1 << curr); 264 + while (curr + drop < max) { 265 + left -= count[curr + drop]; 266 + if (left <= 0) break; 267 + curr++; 268 + left <<= 1; 269 + } 270 + 271 + /* check for enough space */ 272 + used += 1U << curr; 273 + if ((type == LENS && used >= ENOUGH_LENS) || 274 + (type == DISTS && used >= ENOUGH_DISTS)) 275 + return 1; 276 + 277 + /* point entry in root table to sub-table */ 278 + low = huff & mask; 279 + (*table)[low].op = (unsigned char)curr; 280 + (*table)[low].bits = (unsigned char)root; 281 + (*table)[low].val = (unsigned short)(next - *table); 282 + } 283 + } 284 + 285 + /* 286 + Fill in rest of table for incomplete codes. This loop is similar to the 287 + loop above in incrementing huff for table indices. It is assumed that 288 + len is equal to curr + drop, so there is no loop needed to increment 289 + through high index bits. When the current sub-table is filled, the loop 290 + drops back to the root table to fill in any remaining entries there. 291 + */ 292 + this.op = (unsigned char)64; /* invalid code marker */ 293 + this.bits = (unsigned char)(len - drop); 294 + this.val = (unsigned short)0; 295 + while (huff != 0) { 296 + /* when done with sub-table, drop back to root table */ 297 + if (drop != 0 && (huff & mask) != low) { 298 + drop = 0; 299 + len = root; 300 + next = *table; 301 + curr = root; 302 + this.bits = (unsigned char)len; 303 + } 304 + 305 + /* put invalid code marker in table */ 306 + next[huff >> drop] = this; 307 + 308 + /* backwards increment the len-bit code huff */ 309 + incr = 1U << (len - 1); 310 + while (huff & incr) 311 + incr >>= 1; 312 + if (incr != 0) { 313 + huff &= incr - 1; 314 + huff += incr; 315 + } 316 + else 317 + huff = 0; 318 + } 319 + 320 + /* set return parameters */ 321 + *table += used; 322 + *bits = root; 323 + return 0; 324 +}
Added compat/zlib/contrib/infback9/inftree9.h.
1 +/* inftree9.h -- header to use inftree9.c 2 + * Copyright (C) 1995-2008 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* Structure for decoding tables. Each entry provides either the 12 + information needed to do the operation requested by the code that 13 + indexed that table entry, or it provides a pointer to another 14 + table that indexes more bits of the code. op indicates whether 15 + the entry is a pointer to another table, a literal, a length or 16 + distance, an end-of-block, or an invalid code. For a table 17 + pointer, the low four bits of op is the number of index bits of 18 + that table. For a length or distance, the low four bits of op 19 + is the number of extra bits to get after the code. bits is 20 + the number of bits in this code or part of the code to drop off 21 + of the bit buffer. val is the actual byte to output in the case 22 + of a literal, the base length or distance, or the offset from 23 + the current table to the next table. Each entry is four bytes. */ 24 +typedef struct { 25 + unsigned char op; /* operation, extra bits, table bits */ 26 + unsigned char bits; /* bits in this part of the code */ 27 + unsigned short val; /* offset in table or code value */ 28 +} code; 29 + 30 +/* op values as set by inflate_table(): 31 + 00000000 - literal 32 + 0000tttt - table link, tttt != 0 is the number of table index bits 33 + 100eeeee - length or distance, eeee is the number of extra bits 34 + 01100000 - end of block 35 + 01000000 - invalid code 36 + */ 37 + 38 +/* Maximum size of the dynamic table. The maximum number of code structures is 39 + 1446, which is the sum of 852 for literal/length codes and 594 for distance 40 + codes. These values were found by exhaustive searches using the program 41 + examples/enough.c found in the zlib distribtution. The arguments to that 42 + program are the number of symbols, the initial root table size, and the 43 + maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 + returns returns 852, and "enough 32 6 15" for distance codes returns 594. 45 + The initial root table size (9 or 6) is found in the fifth argument of the 46 + inflate_table() calls in infback9.c. If the root table size is changed, 47 + then these maximum sizes would be need to be recalculated and updated. */ 48 +#define ENOUGH_LENS 852 49 +#define ENOUGH_DISTS 594 50 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 51 + 52 +/* Type of code to build for inflate_table9() */ 53 +typedef enum { 54 + CODES, 55 + LENS, 56 + DISTS 57 +} codetype; 58 + 59 +extern int inflate_table9 OF((codetype type, unsigned short FAR *lens, 60 + unsigned codes, code FAR * FAR *table, 61 + unsigned FAR *bits, unsigned short FAR *work));
Added compat/zlib/contrib/inflate86/inffas86.c.
1 +/* inffas86.c is a hand tuned assembler version of 2 + * 3 + * inffast.c -- fast decoding 4 + * Copyright (C) 1995-2003 Mark Adler 5 + * For conditions of distribution and use, see copyright notice in zlib.h 6 + * 7 + * Copyright (C) 2003 Chris Anderson <christop@charm.net> 8 + * Please use the copyright conditions above. 9 + * 10 + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also 11 + * slightly quicker on x86 systems because, instead of using rep movsb to copy 12 + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single 13 + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates 14 + * from http://fedora.linux.duke.edu/fc1_x86_64 15 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with 16 + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, 17 + * when decompressing mozilla-source-1.3.tar.gz. 18 + * 19 + * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from 20 + * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at 21 + * the moment. I have successfully compiled and tested this code with gcc2.96, 22 + * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S 23 + * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX 24 + * enabled. I will attempt to merge the MMX code into this version. Newer 25 + * versions of this and inffast.S can be found at 26 + * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ 27 + */ 28 + 29 +#include "zutil.h" 30 +#include "inftrees.h" 31 +#include "inflate.h" 32 +#include "inffast.h" 33 + 34 +/* Mark Adler's comments from inffast.c: */ 35 + 36 +/* 37 + Decode literal, length, and distance codes and write out the resulting 38 + literal and match bytes until either not enough input or output is 39 + available, an end-of-block is encountered, or a data error is encountered. 40 + When large enough input and output buffers are supplied to inflate(), for 41 + example, a 16K input buffer and a 64K output buffer, more than 95% of the 42 + inflate execution time is spent in this routine. 43 + 44 + Entry assumptions: 45 + 46 + state->mode == LEN 47 + strm->avail_in >= 6 48 + strm->avail_out >= 258 49 + start >= strm->avail_out 50 + state->bits < 8 51 + 52 + On return, state->mode is one of: 53 + 54 + LEN -- ran out of enough output space or enough available input 55 + TYPE -- reached end of block code, inflate() to interpret next block 56 + BAD -- error in block data 57 + 58 + Notes: 59 + 60 + - The maximum input bits used by a length/distance pair is 15 bits for the 61 + length code, 5 bits for the length extra, 15 bits for the distance code, 62 + and 13 bits for the distance extra. This totals 48 bits, or six bytes. 63 + Therefore if strm->avail_in >= 6, then there is enough input to avoid 64 + checking for available input while decoding. 65 + 66 + - The maximum bytes that a single length/distance pair can output is 258 67 + bytes, which is the maximum length that can be coded. inflate_fast() 68 + requires strm->avail_out >= 258 for each loop to avoid checking for 69 + output space. 70 + */ 71 +void inflate_fast(strm, start) 72 +z_streamp strm; 73 +unsigned start; /* inflate()'s starting value for strm->avail_out */ 74 +{ 75 + struct inflate_state FAR *state; 76 + struct inffast_ar { 77 +/* 64 32 x86 x86_64 */ 78 +/* ar offset register */ 79 +/* 0 0 */ void *esp; /* esp save */ 80 +/* 8 4 */ void *ebp; /* ebp save */ 81 +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ 82 +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ 83 +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ 84 +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ 85 +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ 86 +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ 87 +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ 88 +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ 89 +/* 80 40 */ unsigned long hold; /* edx rdx local strm->hold */ 90 +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ 91 +/* 92 48 */ unsigned wsize; /* window size */ 92 +/* 96 52 */ unsigned write; /* window write index */ 93 +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ 94 +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ 95 +/*108 64 */ unsigned len; /* r14 match length */ 96 +/*112 68 */ unsigned dist; /* r15 match distance */ 97 +/*116 72 */ unsigned status; /* set when state chng*/ 98 + } ar; 99 + 100 +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) 101 +#define PAD_AVAIL_IN 6 102 +#define PAD_AVAIL_OUT 258 103 +#else 104 +#define PAD_AVAIL_IN 5 105 +#define PAD_AVAIL_OUT 257 106 +#endif 107 + 108 + /* copy state to local variables */ 109 + state = (struct inflate_state FAR *)strm->state; 110 + ar.in = strm->next_in; 111 + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); 112 + ar.out = strm->next_out; 113 + ar.beg = ar.out - (start - strm->avail_out); 114 + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); 115 + ar.wsize = state->wsize; 116 + ar.write = state->wnext; 117 + ar.window = state->window; 118 + ar.hold = state->hold; 119 + ar.bits = state->bits; 120 + ar.lcode = state->lencode; 121 + ar.dcode = state->distcode; 122 + ar.lmask = (1U << state->lenbits) - 1; 123 + ar.dmask = (1U << state->distbits) - 1; 124 + 125 + /* decode literals and length/distances until end-of-block or not enough 126 + input data or output space */ 127 + 128 + /* align in on 1/2 hold size boundary */ 129 + while (((unsigned long)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { 130 + ar.hold += (unsigned long)*ar.in++ << ar.bits; 131 + ar.bits += 8; 132 + } 133 + 134 +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) 135 + __asm__ __volatile__ ( 136 +" leaq %0, %%rax\n" 137 +" movq %%rbp, 8(%%rax)\n" /* save regs rbp and rsp */ 138 +" movq %%rsp, (%%rax)\n" 139 +" movq %%rax, %%rsp\n" /* make rsp point to &ar */ 140 +" movq 16(%%rsp), %%rsi\n" /* rsi = in */ 141 +" movq 32(%%rsp), %%rdi\n" /* rdi = out */ 142 +" movq 24(%%rsp), %%r9\n" /* r9 = last */ 143 +" movq 48(%%rsp), %%r10\n" /* r10 = end */ 144 +" movq 64(%%rsp), %%rbp\n" /* rbp = lcode */ 145 +" movq 72(%%rsp), %%r11\n" /* r11 = dcode */ 146 +" movq 80(%%rsp), %%rdx\n" /* rdx = hold */ 147 +" movl 88(%%rsp), %%ebx\n" /* ebx = bits */ 148 +" movl 100(%%rsp), %%r12d\n" /* r12d = lmask */ 149 +" movl 104(%%rsp), %%r13d\n" /* r13d = dmask */ 150 + /* r14d = len */ 151 + /* r15d = dist */ 152 +" cld\n" 153 +" cmpq %%rdi, %%r10\n" 154 +" je .L_one_time\n" /* if only one decode left */ 155 +" cmpq %%rsi, %%r9\n" 156 +" je .L_one_time\n" 157 +" jmp .L_do_loop\n" 158 + 159 +".L_one_time:\n" 160 +" movq %%r12, %%r8\n" /* r8 = lmask */ 161 +" cmpb $32, %%bl\n" 162 +" ja .L_get_length_code_one_time\n" 163 + 164 +" lodsl\n" /* eax = *(uint *)in++ */ 165 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 166 +" addb $32, %%bl\n" /* bits += 32 */ 167 +" shlq %%cl, %%rax\n" 168 +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ 169 +" jmp .L_get_length_code_one_time\n" 170 + 171 +".align 32,0x90\n" 172 +".L_while_test:\n" 173 +" cmpq %%rdi, %%r10\n" 174 +" jbe .L_break_loop\n" 175 +" cmpq %%rsi, %%r9\n" 176 +" jbe .L_break_loop\n" 177 + 178 +".L_do_loop:\n" 179 +" movq %%r12, %%r8\n" /* r8 = lmask */ 180 +" cmpb $32, %%bl\n" 181 +" ja .L_get_length_code\n" /* if (32 < bits) */ 182 + 183 +" lodsl\n" /* eax = *(uint *)in++ */ 184 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 185 +" addb $32, %%bl\n" /* bits += 32 */ 186 +" shlq %%cl, %%rax\n" 187 +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ 188 + 189 +".L_get_length_code:\n" 190 +" andq %%rdx, %%r8\n" /* r8 &= hold */ 191 +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ 192 + 193 +" movb %%ah, %%cl\n" /* cl = this.bits */ 194 +" subb %%ah, %%bl\n" /* bits -= this.bits */ 195 +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ 196 + 197 +" testb %%al, %%al\n" 198 +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ 199 + 200 +" movq %%r12, %%r8\n" /* r8 = lmask */ 201 +" shrl $16, %%eax\n" /* output this.val char */ 202 +" stosb\n" 203 + 204 +".L_get_length_code_one_time:\n" 205 +" andq %%rdx, %%r8\n" /* r8 &= hold */ 206 +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ 207 + 208 +".L_dolen:\n" 209 +" movb %%ah, %%cl\n" /* cl = this.bits */ 210 +" subb %%ah, %%bl\n" /* bits -= this.bits */ 211 +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ 212 + 213 +" testb %%al, %%al\n" 214 +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ 215 + 216 +" shrl $16, %%eax\n" /* output this.val char */ 217 +" stosb\n" 218 +" jmp .L_while_test\n" 219 + 220 +".align 32,0x90\n" 221 +".L_test_for_length_base:\n" 222 +" movl %%eax, %%r14d\n" /* len = this */ 223 +" shrl $16, %%r14d\n" /* len = this.val */ 224 +" movb %%al, %%cl\n" 225 + 226 +" testb $16, %%al\n" 227 +" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ 228 +" andb $15, %%cl\n" /* op &= 15 */ 229 +" jz .L_decode_distance\n" /* if (!op) */ 230 + 231 +".L_add_bits_to_len:\n" 232 +" subb %%cl, %%bl\n" 233 +" xorl %%eax, %%eax\n" 234 +" incl %%eax\n" 235 +" shll %%cl, %%eax\n" 236 +" decl %%eax\n" 237 +" andl %%edx, %%eax\n" /* eax &= hold */ 238 +" shrq %%cl, %%rdx\n" 239 +" addl %%eax, %%r14d\n" /* len += hold & mask[op] */ 240 + 241 +".L_decode_distance:\n" 242 +" movq %%r13, %%r8\n" /* r8 = dmask */ 243 +" cmpb $32, %%bl\n" 244 +" ja .L_get_distance_code\n" /* if (32 < bits) */ 245 + 246 +" lodsl\n" /* eax = *(uint *)in++ */ 247 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 248 +" addb $32, %%bl\n" /* bits += 32 */ 249 +" shlq %%cl, %%rax\n" 250 +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ 251 + 252 +".L_get_distance_code:\n" 253 +" andq %%rdx, %%r8\n" /* r8 &= hold */ 254 +" movl (%%r11,%%r8,4), %%eax\n" /* eax = dcode[hold & dmask] */ 255 + 256 +".L_dodist:\n" 257 +" movl %%eax, %%r15d\n" /* dist = this */ 258 +" shrl $16, %%r15d\n" /* dist = this.val */ 259 +" movb %%ah, %%cl\n" 260 +" subb %%ah, %%bl\n" /* bits -= this.bits */ 261 +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ 262 +" movb %%al, %%cl\n" /* cl = this.op */ 263 + 264 +" testb $16, %%al\n" /* if ((op & 16) == 0) */ 265 +" jz .L_test_for_second_level_dist\n" 266 +" andb $15, %%cl\n" /* op &= 15 */ 267 +" jz .L_check_dist_one\n" 268 + 269 +".L_add_bits_to_dist:\n" 270 +" subb %%cl, %%bl\n" 271 +" xorl %%eax, %%eax\n" 272 +" incl %%eax\n" 273 +" shll %%cl, %%eax\n" 274 +" decl %%eax\n" /* (1 << op) - 1 */ 275 +" andl %%edx, %%eax\n" /* eax &= hold */ 276 +" shrq %%cl, %%rdx\n" 277 +" addl %%eax, %%r15d\n" /* dist += hold & ((1 << op) - 1) */ 278 + 279 +".L_check_window:\n" 280 +" movq %%rsi, %%r8\n" /* save in so from can use it's reg */ 281 +" movq %%rdi, %%rax\n" 282 +" subq 40(%%rsp), %%rax\n" /* nbytes = out - beg */ 283 + 284 +" cmpl %%r15d, %%eax\n" 285 +" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ 286 + 287 +" movl %%r14d, %%ecx\n" /* ecx = len */ 288 +" movq %%rdi, %%rsi\n" 289 +" subq %%r15, %%rsi\n" /* from = out - dist */ 290 + 291 +" sarl %%ecx\n" 292 +" jnc .L_copy_two\n" /* if len % 2 == 0 */ 293 + 294 +" rep movsw\n" 295 +" movb (%%rsi), %%al\n" 296 +" movb %%al, (%%rdi)\n" 297 +" incq %%rdi\n" 298 + 299 +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ 300 +" jmp .L_while_test\n" 301 + 302 +".L_copy_two:\n" 303 +" rep movsw\n" 304 +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ 305 +" jmp .L_while_test\n" 306 + 307 +".align 32,0x90\n" 308 +".L_check_dist_one:\n" 309 +" cmpl $1, %%r15d\n" /* if dist 1, is a memset */ 310 +" jne .L_check_window\n" 311 +" cmpq %%rdi, 40(%%rsp)\n" /* if out == beg, outside window */ 312 +" je .L_check_window\n" 313 + 314 +" movl %%r14d, %%ecx\n" /* ecx = len */ 315 +" movb -1(%%rdi), %%al\n" 316 +" movb %%al, %%ah\n" 317 + 318 +" sarl %%ecx\n" 319 +" jnc .L_set_two\n" 320 +" movb %%al, (%%rdi)\n" 321 +" incq %%rdi\n" 322 + 323 +".L_set_two:\n" 324 +" rep stosw\n" 325 +" jmp .L_while_test\n" 326 + 327 +".align 32,0x90\n" 328 +".L_test_for_second_level_length:\n" 329 +" testb $64, %%al\n" 330 +" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ 331 + 332 +" xorl %%eax, %%eax\n" 333 +" incl %%eax\n" 334 +" shll %%cl, %%eax\n" 335 +" decl %%eax\n" 336 +" andl %%edx, %%eax\n" /* eax &= hold */ 337 +" addl %%r14d, %%eax\n" /* eax += len */ 338 +" movl (%%rbp,%%rax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ 339 +" jmp .L_dolen\n" 340 + 341 +".align 32,0x90\n" 342 +".L_test_for_second_level_dist:\n" 343 +" testb $64, %%al\n" 344 +" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ 345 + 346 +" xorl %%eax, %%eax\n" 347 +" incl %%eax\n" 348 +" shll %%cl, %%eax\n" 349 +" decl %%eax\n" 350 +" andl %%edx, %%eax\n" /* eax &= hold */ 351 +" addl %%r15d, %%eax\n" /* eax += dist */ 352 +" movl (%%r11,%%rax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ 353 +" jmp .L_dodist\n" 354 + 355 +".align 32,0x90\n" 356 +".L_clip_window:\n" 357 +" movl %%eax, %%ecx\n" /* ecx = nbytes */ 358 +" movl 92(%%rsp), %%eax\n" /* eax = wsize, prepare for dist cmp */ 359 +" negl %%ecx\n" /* nbytes = -nbytes */ 360 + 361 +" cmpl %%r15d, %%eax\n" 362 +" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ 363 + 364 +" addl %%r15d, %%ecx\n" /* nbytes = dist - nbytes */ 365 +" cmpl $0, 96(%%rsp)\n" 366 +" jne .L_wrap_around_window\n" /* if (write != 0) */ 367 + 368 +" movq 56(%%rsp), %%rsi\n" /* from = window */ 369 +" subl %%ecx, %%eax\n" /* eax -= nbytes */ 370 +" addq %%rax, %%rsi\n" /* from += wsize - nbytes */ 371 + 372 +" movl %%r14d, %%eax\n" /* eax = len */ 373 +" cmpl %%ecx, %%r14d\n" 374 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 375 + 376 +" subl %%ecx, %%eax\n" /* eax -= nbytes */ 377 +" rep movsb\n" 378 +" movq %%rdi, %%rsi\n" 379 +" subq %%r15, %%rsi\n" /* from = &out[ -dist ] */ 380 +" jmp .L_do_copy\n" 381 + 382 +".align 32,0x90\n" 383 +".L_wrap_around_window:\n" 384 +" movl 96(%%rsp), %%eax\n" /* eax = write */ 385 +" cmpl %%eax, %%ecx\n" 386 +" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ 387 + 388 +" movl 92(%%rsp), %%esi\n" /* from = wsize */ 389 +" addq 56(%%rsp), %%rsi\n" /* from += window */ 390 +" addq %%rax, %%rsi\n" /* from += write */ 391 +" subq %%rcx, %%rsi\n" /* from -= nbytes */ 392 +" subl %%eax, %%ecx\n" /* nbytes -= write */ 393 + 394 +" movl %%r14d, %%eax\n" /* eax = len */ 395 +" cmpl %%ecx, %%eax\n" 396 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 397 + 398 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 399 +" rep movsb\n" 400 +" movq 56(%%rsp), %%rsi\n" /* from = window */ 401 +" movl 96(%%rsp), %%ecx\n" /* nbytes = write */ 402 +" cmpl %%ecx, %%eax\n" 403 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 404 + 405 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 406 +" rep movsb\n" 407 +" movq %%rdi, %%rsi\n" 408 +" subq %%r15, %%rsi\n" /* from = out - dist */ 409 +" jmp .L_do_copy\n" 410 + 411 +".align 32,0x90\n" 412 +".L_contiguous_in_window:\n" 413 +" movq 56(%%rsp), %%rsi\n" /* rsi = window */ 414 +" addq %%rax, %%rsi\n" 415 +" subq %%rcx, %%rsi\n" /* from += write - nbytes */ 416 + 417 +" movl %%r14d, %%eax\n" /* eax = len */ 418 +" cmpl %%ecx, %%eax\n" 419 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 420 + 421 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 422 +" rep movsb\n" 423 +" movq %%rdi, %%rsi\n" 424 +" subq %%r15, %%rsi\n" /* from = out - dist */ 425 +" jmp .L_do_copy\n" /* if (nbytes >= len) */ 426 + 427 +".align 32,0x90\n" 428 +".L_do_copy:\n" 429 +" movl %%eax, %%ecx\n" /* ecx = len */ 430 +" rep movsb\n" 431 + 432 +" movq %%r8, %%rsi\n" /* move in back to %esi, toss from */ 433 +" jmp .L_while_test\n" 434 + 435 +".L_test_for_end_of_block:\n" 436 +" testb $32, %%al\n" 437 +" jz .L_invalid_literal_length_code\n" 438 +" movl $1, 116(%%rsp)\n" 439 +" jmp .L_break_loop_with_status\n" 440 + 441 +".L_invalid_literal_length_code:\n" 442 +" movl $2, 116(%%rsp)\n" 443 +" jmp .L_break_loop_with_status\n" 444 + 445 +".L_invalid_distance_code:\n" 446 +" movl $3, 116(%%rsp)\n" 447 +" jmp .L_break_loop_with_status\n" 448 + 449 +".L_invalid_distance_too_far:\n" 450 +" movl $4, 116(%%rsp)\n" 451 +" jmp .L_break_loop_with_status\n" 452 + 453 +".L_break_loop:\n" 454 +" movl $0, 116(%%rsp)\n" 455 + 456 +".L_break_loop_with_status:\n" 457 +/* put in, out, bits, and hold back into ar and pop esp */ 458 +" movq %%rsi, 16(%%rsp)\n" /* in */ 459 +" movq %%rdi, 32(%%rsp)\n" /* out */ 460 +" movl %%ebx, 88(%%rsp)\n" /* bits */ 461 +" movq %%rdx, 80(%%rsp)\n" /* hold */ 462 +" movq (%%rsp), %%rax\n" /* restore rbp and rsp */ 463 +" movq 8(%%rsp), %%rbp\n" 464 +" movq %%rax, %%rsp\n" 465 + : 466 + : "m" (ar) 467 + : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", 468 + "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" 469 + ); 470 +#elif ( defined( __GNUC__ ) || defined( __ICC ) ) && defined( __i386 ) 471 + __asm__ __volatile__ ( 472 +" leal %0, %%eax\n" 473 +" movl %%esp, (%%eax)\n" /* save esp, ebp */ 474 +" movl %%ebp, 4(%%eax)\n" 475 +" movl %%eax, %%esp\n" 476 +" movl 8(%%esp), %%esi\n" /* esi = in */ 477 +" movl 16(%%esp), %%edi\n" /* edi = out */ 478 +" movl 40(%%esp), %%edx\n" /* edx = hold */ 479 +" movl 44(%%esp), %%ebx\n" /* ebx = bits */ 480 +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ 481 + 482 +" cld\n" 483 +" jmp .L_do_loop\n" 484 + 485 +".align 32,0x90\n" 486 +".L_while_test:\n" 487 +" cmpl %%edi, 24(%%esp)\n" /* out < end */ 488 +" jbe .L_break_loop\n" 489 +" cmpl %%esi, 12(%%esp)\n" /* in < last */ 490 +" jbe .L_break_loop\n" 491 + 492 +".L_do_loop:\n" 493 +" cmpb $15, %%bl\n" 494 +" ja .L_get_length_code\n" /* if (15 < bits) */ 495 + 496 +" xorl %%eax, %%eax\n" 497 +" lodsw\n" /* al = *(ushort *)in++ */ 498 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 499 +" addb $16, %%bl\n" /* bits += 16 */ 500 +" shll %%cl, %%eax\n" 501 +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ 502 + 503 +".L_get_length_code:\n" 504 +" movl 56(%%esp), %%eax\n" /* eax = lmask */ 505 +" andl %%edx, %%eax\n" /* eax &= hold */ 506 +" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */ 507 + 508 +".L_dolen:\n" 509 +" movb %%ah, %%cl\n" /* cl = this.bits */ 510 +" subb %%ah, %%bl\n" /* bits -= this.bits */ 511 +" shrl %%cl, %%edx\n" /* hold >>= this.bits */ 512 + 513 +" testb %%al, %%al\n" 514 +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ 515 + 516 +" shrl $16, %%eax\n" /* output this.val char */ 517 +" stosb\n" 518 +" jmp .L_while_test\n" 519 + 520 +".align 32,0x90\n" 521 +".L_test_for_length_base:\n" 522 +" movl %%eax, %%ecx\n" /* len = this */ 523 +" shrl $16, %%ecx\n" /* len = this.val */ 524 +" movl %%ecx, 64(%%esp)\n" /* save len */ 525 +" movb %%al, %%cl\n" 526 + 527 +" testb $16, %%al\n" 528 +" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ 529 +" andb $15, %%cl\n" /* op &= 15 */ 530 +" jz .L_decode_distance\n" /* if (!op) */ 531 +" cmpb %%cl, %%bl\n" 532 +" jae .L_add_bits_to_len\n" /* if (op <= bits) */ 533 + 534 +" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ 535 +" xorl %%eax, %%eax\n" 536 +" lodsw\n" /* al = *(ushort *)in++ */ 537 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 538 +" addb $16, %%bl\n" /* bits += 16 */ 539 +" shll %%cl, %%eax\n" 540 +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ 541 +" movb %%ch, %%cl\n" /* move op back to ecx */ 542 + 543 +".L_add_bits_to_len:\n" 544 +" subb %%cl, %%bl\n" 545 +" xorl %%eax, %%eax\n" 546 +" incl %%eax\n" 547 +" shll %%cl, %%eax\n" 548 +" decl %%eax\n" 549 +" andl %%edx, %%eax\n" /* eax &= hold */ 550 +" shrl %%cl, %%edx\n" 551 +" addl %%eax, 64(%%esp)\n" /* len += hold & mask[op] */ 552 + 553 +".L_decode_distance:\n" 554 +" cmpb $15, %%bl\n" 555 +" ja .L_get_distance_code\n" /* if (15 < bits) */ 556 + 557 +" xorl %%eax, %%eax\n" 558 +" lodsw\n" /* al = *(ushort *)in++ */ 559 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 560 +" addb $16, %%bl\n" /* bits += 16 */ 561 +" shll %%cl, %%eax\n" 562 +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ 563 + 564 +".L_get_distance_code:\n" 565 +" movl 60(%%esp), %%eax\n" /* eax = dmask */ 566 +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ 567 +" andl %%edx, %%eax\n" /* eax &= hold */ 568 +" movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */ 569 + 570 +".L_dodist:\n" 571 +" movl %%eax, %%ebp\n" /* dist = this */ 572 +" shrl $16, %%ebp\n" /* dist = this.val */ 573 +" movb %%ah, %%cl\n" 574 +" subb %%ah, %%bl\n" /* bits -= this.bits */ 575 +" shrl %%cl, %%edx\n" /* hold >>= this.bits */ 576 +" movb %%al, %%cl\n" /* cl = this.op */ 577 + 578 +" testb $16, %%al\n" /* if ((op & 16) == 0) */ 579 +" jz .L_test_for_second_level_dist\n" 580 +" andb $15, %%cl\n" /* op &= 15 */ 581 +" jz .L_check_dist_one\n" 582 +" cmpb %%cl, %%bl\n" 583 +" jae .L_add_bits_to_dist\n" /* if (op <= bits) 97.6% */ 584 + 585 +" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ 586 +" xorl %%eax, %%eax\n" 587 +" lodsw\n" /* al = *(ushort *)in++ */ 588 +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ 589 +" addb $16, %%bl\n" /* bits += 16 */ 590 +" shll %%cl, %%eax\n" 591 +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ 592 +" movb %%ch, %%cl\n" /* move op back to ecx */ 593 + 594 +".L_add_bits_to_dist:\n" 595 +" subb %%cl, %%bl\n" 596 +" xorl %%eax, %%eax\n" 597 +" incl %%eax\n" 598 +" shll %%cl, %%eax\n" 599 +" decl %%eax\n" /* (1 << op) - 1 */ 600 +" andl %%edx, %%eax\n" /* eax &= hold */ 601 +" shrl %%cl, %%edx\n" 602 +" addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */ 603 + 604 +".L_check_window:\n" 605 +" movl %%esi, 8(%%esp)\n" /* save in so from can use it's reg */ 606 +" movl %%edi, %%eax\n" 607 +" subl 20(%%esp), %%eax\n" /* nbytes = out - beg */ 608 + 609 +" cmpl %%ebp, %%eax\n" 610 +" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ 611 + 612 +" movl 64(%%esp), %%ecx\n" /* ecx = len */ 613 +" movl %%edi, %%esi\n" 614 +" subl %%ebp, %%esi\n" /* from = out - dist */ 615 + 616 +" sarl %%ecx\n" 617 +" jnc .L_copy_two\n" /* if len % 2 == 0 */ 618 + 619 +" rep movsw\n" 620 +" movb (%%esi), %%al\n" 621 +" movb %%al, (%%edi)\n" 622 +" incl %%edi\n" 623 + 624 +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ 625 +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ 626 +" jmp .L_while_test\n" 627 + 628 +".L_copy_two:\n" 629 +" rep movsw\n" 630 +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ 631 +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ 632 +" jmp .L_while_test\n" 633 + 634 +".align 32,0x90\n" 635 +".L_check_dist_one:\n" 636 +" cmpl $1, %%ebp\n" /* if dist 1, is a memset */ 637 +" jne .L_check_window\n" 638 +" cmpl %%edi, 20(%%esp)\n" 639 +" je .L_check_window\n" /* out == beg, if outside window */ 640 + 641 +" movl 64(%%esp), %%ecx\n" /* ecx = len */ 642 +" movb -1(%%edi), %%al\n" 643 +" movb %%al, %%ah\n" 644 + 645 +" sarl %%ecx\n" 646 +" jnc .L_set_two\n" 647 +" movb %%al, (%%edi)\n" 648 +" incl %%edi\n" 649 + 650 +".L_set_two:\n" 651 +" rep stosw\n" 652 +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ 653 +" jmp .L_while_test\n" 654 + 655 +".align 32,0x90\n" 656 +".L_test_for_second_level_length:\n" 657 +" testb $64, %%al\n" 658 +" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ 659 + 660 +" xorl %%eax, %%eax\n" 661 +" incl %%eax\n" 662 +" shll %%cl, %%eax\n" 663 +" decl %%eax\n" 664 +" andl %%edx, %%eax\n" /* eax &= hold */ 665 +" addl 64(%%esp), %%eax\n" /* eax += len */ 666 +" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ 667 +" jmp .L_dolen\n" 668 + 669 +".align 32,0x90\n" 670 +".L_test_for_second_level_dist:\n" 671 +" testb $64, %%al\n" 672 +" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ 673 + 674 +" xorl %%eax, %%eax\n" 675 +" incl %%eax\n" 676 +" shll %%cl, %%eax\n" 677 +" decl %%eax\n" 678 +" andl %%edx, %%eax\n" /* eax &= hold */ 679 +" addl %%ebp, %%eax\n" /* eax += dist */ 680 +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ 681 +" movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ 682 +" jmp .L_dodist\n" 683 + 684 +".align 32,0x90\n" 685 +".L_clip_window:\n" 686 +" movl %%eax, %%ecx\n" 687 +" movl 48(%%esp), %%eax\n" /* eax = wsize */ 688 +" negl %%ecx\n" /* nbytes = -nbytes */ 689 +" movl 28(%%esp), %%esi\n" /* from = window */ 690 + 691 +" cmpl %%ebp, %%eax\n" 692 +" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ 693 + 694 +" addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */ 695 +" cmpl $0, 52(%%esp)\n" 696 +" jne .L_wrap_around_window\n" /* if (write != 0) */ 697 + 698 +" subl %%ecx, %%eax\n" 699 +" addl %%eax, %%esi\n" /* from += wsize - nbytes */ 700 + 701 +" movl 64(%%esp), %%eax\n" /* eax = len */ 702 +" cmpl %%ecx, %%eax\n" 703 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 704 + 705 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 706 +" rep movsb\n" 707 +" movl %%edi, %%esi\n" 708 +" subl %%ebp, %%esi\n" /* from = out - dist */ 709 +" jmp .L_do_copy\n" 710 + 711 +".align 32,0x90\n" 712 +".L_wrap_around_window:\n" 713 +" movl 52(%%esp), %%eax\n" /* eax = write */ 714 +" cmpl %%eax, %%ecx\n" 715 +" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ 716 + 717 +" addl 48(%%esp), %%esi\n" /* from += wsize */ 718 +" addl %%eax, %%esi\n" /* from += write */ 719 +" subl %%ecx, %%esi\n" /* from -= nbytes */ 720 +" subl %%eax, %%ecx\n" /* nbytes -= write */ 721 + 722 +" movl 64(%%esp), %%eax\n" /* eax = len */ 723 +" cmpl %%ecx, %%eax\n" 724 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 725 + 726 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 727 +" rep movsb\n" 728 +" movl 28(%%esp), %%esi\n" /* from = window */ 729 +" movl 52(%%esp), %%ecx\n" /* nbytes = write */ 730 +" cmpl %%ecx, %%eax\n" 731 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 732 + 733 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 734 +" rep movsb\n" 735 +" movl %%edi, %%esi\n" 736 +" subl %%ebp, %%esi\n" /* from = out - dist */ 737 +" jmp .L_do_copy\n" 738 + 739 +".align 32,0x90\n" 740 +".L_contiguous_in_window:\n" 741 +" addl %%eax, %%esi\n" 742 +" subl %%ecx, %%esi\n" /* from += write - nbytes */ 743 + 744 +" movl 64(%%esp), %%eax\n" /* eax = len */ 745 +" cmpl %%ecx, %%eax\n" 746 +" jbe .L_do_copy\n" /* if (nbytes >= len) */ 747 + 748 +" subl %%ecx, %%eax\n" /* len -= nbytes */ 749 +" rep movsb\n" 750 +" movl %%edi, %%esi\n" 751 +" subl %%ebp, %%esi\n" /* from = out - dist */ 752 +" jmp .L_do_copy\n" /* if (nbytes >= len) */ 753 + 754 +".align 32,0x90\n" 755 +".L_do_copy:\n" 756 +" movl %%eax, %%ecx\n" 757 +" rep movsb\n" 758 + 759 +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ 760 +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ 761 +" jmp .L_while_test\n" 762 + 763 +".L_test_for_end_of_block:\n" 764 +" testb $32, %%al\n" 765 +" jz .L_invalid_literal_length_code\n" 766 +" movl $1, 72(%%esp)\n" 767 +" jmp .L_break_loop_with_status\n" 768 + 769 +".L_invalid_literal_length_code:\n" 770 +" movl $2, 72(%%esp)\n" 771 +" jmp .L_break_loop_with_status\n" 772 + 773 +".L_invalid_distance_code:\n" 774 +" movl $3, 72(%%esp)\n" 775 +" jmp .L_break_loop_with_status\n" 776 + 777 +".L_invalid_distance_too_far:\n" 778 +" movl 8(%%esp), %%esi\n" 779 +" movl $4, 72(%%esp)\n" 780 +" jmp .L_break_loop_with_status\n" 781 + 782 +".L_break_loop:\n" 783 +" movl $0, 72(%%esp)\n" 784 + 785 +".L_break_loop_with_status:\n" 786 +/* put in, out, bits, and hold back into ar and pop esp */ 787 +" movl %%esi, 8(%%esp)\n" /* save in */ 788 +" movl %%edi, 16(%%esp)\n" /* save out */ 789 +" movl %%ebx, 44(%%esp)\n" /* save bits */ 790 +" movl %%edx, 40(%%esp)\n" /* save hold */ 791 +" movl 4(%%esp), %%ebp\n" /* restore esp, ebp */ 792 +" movl (%%esp), %%esp\n" 793 + : 794 + : "m" (ar) 795 + : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi" 796 + ); 797 +#elif defined( _MSC_VER ) && ! defined( _M_AMD64 ) 798 + __asm { 799 + lea eax, ar 800 + mov [eax], esp /* save esp, ebp */ 801 + mov [eax+4], ebp 802 + mov esp, eax 803 + mov esi, [esp+8] /* esi = in */ 804 + mov edi, [esp+16] /* edi = out */ 805 + mov edx, [esp+40] /* edx = hold */ 806 + mov ebx, [esp+44] /* ebx = bits */ 807 + mov ebp, [esp+32] /* ebp = lcode */ 808 + 809 + cld 810 + jmp L_do_loop 811 + 812 +ALIGN 4 813 +L_while_test: 814 + cmp [esp+24], edi 815 + jbe L_break_loop 816 + cmp [esp+12], esi 817 + jbe L_break_loop 818 + 819 +L_do_loop: 820 + cmp bl, 15 821 + ja L_get_length_code /* if (15 < bits) */ 822 + 823 + xor eax, eax 824 + lodsw /* al = *(ushort *)in++ */ 825 + mov cl, bl /* cl = bits, needs it for shifting */ 826 + add bl, 16 /* bits += 16 */ 827 + shl eax, cl 828 + or edx, eax /* hold |= *((ushort *)in)++ << bits */ 829 + 830 +L_get_length_code: 831 + mov eax, [esp+56] /* eax = lmask */ 832 + and eax, edx /* eax &= hold */ 833 + mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */ 834 + 835 +L_dolen: 836 + mov cl, ah /* cl = this.bits */ 837 + sub bl, ah /* bits -= this.bits */ 838 + shr edx, cl /* hold >>= this.bits */ 839 + 840 + test al, al 841 + jnz L_test_for_length_base /* if (op != 0) 45.7% */ 842 + 843 + shr eax, 16 /* output this.val char */ 844 + stosb 845 + jmp L_while_test 846 + 847 +ALIGN 4 848 +L_test_for_length_base: 849 + mov ecx, eax /* len = this */ 850 + shr ecx, 16 /* len = this.val */ 851 + mov [esp+64], ecx /* save len */ 852 + mov cl, al 853 + 854 + test al, 16 855 + jz L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ 856 + and cl, 15 /* op &= 15 */ 857 + jz L_decode_distance /* if (!op) */ 858 + cmp bl, cl 859 + jae L_add_bits_to_len /* if (op <= bits) */ 860 + 861 + mov ch, cl /* stash op in ch, freeing cl */ 862 + xor eax, eax 863 + lodsw /* al = *(ushort *)in++ */ 864 + mov cl, bl /* cl = bits, needs it for shifting */ 865 + add bl, 16 /* bits += 16 */ 866 + shl eax, cl 867 + or edx, eax /* hold |= *((ushort *)in)++ << bits */ 868 + mov cl, ch /* move op back to ecx */ 869 + 870 +L_add_bits_to_len: 871 + sub bl, cl 872 + xor eax, eax 873 + inc eax 874 + shl eax, cl 875 + dec eax 876 + and eax, edx /* eax &= hold */ 877 + shr edx, cl 878 + add [esp+64], eax /* len += hold & mask[op] */ 879 + 880 +L_decode_distance: 881 + cmp bl, 15 882 + ja L_get_distance_code /* if (15 < bits) */ 883 + 884 + xor eax, eax 885 + lodsw /* al = *(ushort *)in++ */ 886 + mov cl, bl /* cl = bits, needs it for shifting */ 887 + add bl, 16 /* bits += 16 */ 888 + shl eax, cl 889 + or edx, eax /* hold |= *((ushort *)in)++ << bits */ 890 + 891 +L_get_distance_code: 892 + mov eax, [esp+60] /* eax = dmask */ 893 + mov ecx, [esp+36] /* ecx = dcode */ 894 + and eax, edx /* eax &= hold */ 895 + mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */ 896 + 897 +L_dodist: 898 + mov ebp, eax /* dist = this */ 899 + shr ebp, 16 /* dist = this.val */ 900 + mov cl, ah 901 + sub bl, ah /* bits -= this.bits */ 902 + shr edx, cl /* hold >>= this.bits */ 903 + mov cl, al /* cl = this.op */ 904 + 905 + test al, 16 /* if ((op & 16) == 0) */ 906 + jz L_test_for_second_level_dist 907 + and cl, 15 /* op &= 15 */ 908 + jz L_check_dist_one 909 + cmp bl, cl 910 + jae L_add_bits_to_dist /* if (op <= bits) 97.6% */ 911 + 912 + mov ch, cl /* stash op in ch, freeing cl */ 913 + xor eax, eax 914 + lodsw /* al = *(ushort *)in++ */ 915 + mov cl, bl /* cl = bits, needs it for shifting */ 916 + add bl, 16 /* bits += 16 */ 917 + shl eax, cl 918 + or edx, eax /* hold |= *((ushort *)in)++ << bits */ 919 + mov cl, ch /* move op back to ecx */ 920 + 921 +L_add_bits_to_dist: 922 + sub bl, cl 923 + xor eax, eax 924 + inc eax 925 + shl eax, cl 926 + dec eax /* (1 << op) - 1 */ 927 + and eax, edx /* eax &= hold */ 928 + shr edx, cl 929 + add ebp, eax /* dist += hold & ((1 << op) - 1) */ 930 + 931 +L_check_window: 932 + mov [esp+8], esi /* save in so from can use it's reg */ 933 + mov eax, edi 934 + sub eax, [esp+20] /* nbytes = out - beg */ 935 + 936 + cmp eax, ebp 937 + jb L_clip_window /* if (dist > nbytes) 4.2% */ 938 + 939 + mov ecx, [esp+64] /* ecx = len */ 940 + mov esi, edi 941 + sub esi, ebp /* from = out - dist */ 942 + 943 + sar ecx, 1 944 + jnc L_copy_two 945 + 946 + rep movsw 947 + mov al, [esi] 948 + mov [edi], al 949 + inc edi 950 + 951 + mov esi, [esp+8] /* move in back to %esi, toss from */ 952 + mov ebp, [esp+32] /* ebp = lcode */ 953 + jmp L_while_test 954 + 955 +L_copy_two: 956 + rep movsw 957 + mov esi, [esp+8] /* move in back to %esi, toss from */ 958 + mov ebp, [esp+32] /* ebp = lcode */ 959 + jmp L_while_test 960 + 961 +ALIGN 4 962 +L_check_dist_one: 963 + cmp ebp, 1 /* if dist 1, is a memset */ 964 + jne L_check_window 965 + cmp [esp+20], edi 966 + je L_check_window /* out == beg, if outside window */ 967 + 968 + mov ecx, [esp+64] /* ecx = len */ 969 + mov al, [edi-1] 970 + mov ah, al 971 + 972 + sar ecx, 1 973 + jnc L_set_two 974 + mov [edi], al /* memset out with from[-1] */ 975 + inc edi 976 + 977 +L_set_two: 978 + rep stosw 979 + mov ebp, [esp+32] /* ebp = lcode */ 980 + jmp L_while_test 981 + 982 +ALIGN 4 983 +L_test_for_second_level_length: 984 + test al, 64 985 + jnz L_test_for_end_of_block /* if ((op & 64) != 0) */ 986 + 987 + xor eax, eax 988 + inc eax 989 + shl eax, cl 990 + dec eax 991 + and eax, edx /* eax &= hold */ 992 + add eax, [esp+64] /* eax += len */ 993 + mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/ 994 + jmp L_dolen 995 + 996 +ALIGN 4 997 +L_test_for_second_level_dist: 998 + test al, 64 999 + jnz L_invalid_distance_code /* if ((op & 64) != 0) */ 1000 + 1001 + xor eax, eax 1002 + inc eax 1003 + shl eax, cl 1004 + dec eax 1005 + and eax, edx /* eax &= hold */ 1006 + add eax, ebp /* eax += dist */ 1007 + mov ecx, [esp+36] /* ecx = dcode */ 1008 + mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/ 1009 + jmp L_dodist 1010 + 1011 +ALIGN 4 1012 +L_clip_window: 1013 + mov ecx, eax 1014 + mov eax, [esp+48] /* eax = wsize */ 1015 + neg ecx /* nbytes = -nbytes */ 1016 + mov esi, [esp+28] /* from = window */ 1017 + 1018 + cmp eax, ebp 1019 + jb L_invalid_distance_too_far /* if (dist > wsize) */ 1020 + 1021 + add ecx, ebp /* nbytes = dist - nbytes */ 1022 + cmp dword ptr [esp+52], 0 1023 + jne L_wrap_around_window /* if (write != 0) */ 1024 + 1025 + sub eax, ecx 1026 + add esi, eax /* from += wsize - nbytes */ 1027 + 1028 + mov eax, [esp+64] /* eax = len */ 1029 + cmp eax, ecx 1030 + jbe L_do_copy /* if (nbytes >= len) */ 1031 + 1032 + sub eax, ecx /* len -= nbytes */ 1033 + rep movsb 1034 + mov esi, edi 1035 + sub esi, ebp /* from = out - dist */ 1036 + jmp L_do_copy 1037 + 1038 +ALIGN 4 1039 +L_wrap_around_window: 1040 + mov eax, [esp+52] /* eax = write */ 1041 + cmp ecx, eax 1042 + jbe L_contiguous_in_window /* if (write >= nbytes) */ 1043 + 1044 + add esi, [esp+48] /* from += wsize */ 1045 + add esi, eax /* from += write */ 1046 + sub esi, ecx /* from -= nbytes */ 1047 + sub ecx, eax /* nbytes -= write */ 1048 + 1049 + mov eax, [esp+64] /* eax = len */ 1050 + cmp eax, ecx 1051 + jbe L_do_copy /* if (nbytes >= len) */ 1052 + 1053 + sub eax, ecx /* len -= nbytes */ 1054 + rep movsb 1055 + mov esi, [esp+28] /* from = window */ 1056 + mov ecx, [esp+52] /* nbytes = write */ 1057 + cmp eax, ecx 1058 + jbe L_do_copy /* if (nbytes >= len) */ 1059 + 1060 + sub eax, ecx /* len -= nbytes */ 1061 + rep movsb 1062 + mov esi, edi 1063 + sub esi, ebp /* from = out - dist */ 1064 + jmp L_do_copy 1065 + 1066 +ALIGN 4 1067 +L_contiguous_in_window: 1068 + add esi, eax 1069 + sub esi, ecx /* from += write - nbytes */ 1070 + 1071 + mov eax, [esp+64] /* eax = len */ 1072 + cmp eax, ecx 1073 + jbe L_do_copy /* if (nbytes >= len) */ 1074 + 1075 + sub eax, ecx /* len -= nbytes */ 1076 + rep movsb 1077 + mov esi, edi 1078 + sub esi, ebp /* from = out - dist */ 1079 + jmp L_do_copy 1080 + 1081 +ALIGN 4 1082 +L_do_copy: 1083 + mov ecx, eax 1084 + rep movsb 1085 + 1086 + mov esi, [esp+8] /* move in back to %esi, toss from */ 1087 + mov ebp, [esp+32] /* ebp = lcode */ 1088 + jmp L_while_test 1089 + 1090 +L_test_for_end_of_block: 1091 + test al, 32 1092 + jz L_invalid_literal_length_code 1093 + mov dword ptr [esp+72], 1 1094 + jmp L_break_loop_with_status 1095 + 1096 +L_invalid_literal_length_code: 1097 + mov dword ptr [esp+72], 2 1098 + jmp L_break_loop_with_status 1099 + 1100 +L_invalid_distance_code: 1101 + mov dword ptr [esp+72], 3 1102 + jmp L_break_loop_with_status 1103 + 1104 +L_invalid_distance_too_far: 1105 + mov esi, [esp+4] 1106 + mov dword ptr [esp+72], 4 1107 + jmp L_break_loop_with_status 1108 + 1109 +L_break_loop: 1110 + mov dword ptr [esp+72], 0 1111 + 1112 +L_break_loop_with_status: 1113 +/* put in, out, bits, and hold back into ar and pop esp */ 1114 + mov [esp+8], esi /* save in */ 1115 + mov [esp+16], edi /* save out */ 1116 + mov [esp+44], ebx /* save bits */ 1117 + mov [esp+40], edx /* save hold */ 1118 + mov ebp, [esp+4] /* restore esp, ebp */ 1119 + mov esp, [esp] 1120 + } 1121 +#else 1122 +#error "x86 architecture not defined" 1123 +#endif 1124 + 1125 + if (ar.status > 1) { 1126 + if (ar.status == 2) 1127 + strm->msg = "invalid literal/length code"; 1128 + else if (ar.status == 3) 1129 + strm->msg = "invalid distance code"; 1130 + else 1131 + strm->msg = "invalid distance too far back"; 1132 + state->mode = BAD; 1133 + } 1134 + else if ( ar.status == 1 ) { 1135 + state->mode = TYPE; 1136 + } 1137 + 1138 + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 1139 + ar.len = ar.bits >> 3; 1140 + ar.in -= ar.len; 1141 + ar.bits -= ar.len << 3; 1142 + ar.hold &= (1U << ar.bits) - 1; 1143 + 1144 + /* update state and return */ 1145 + strm->next_in = ar.in; 1146 + strm->next_out = ar.out; 1147 + strm->avail_in = (unsigned)(ar.in < ar.last ? 1148 + PAD_AVAIL_IN + (ar.last - ar.in) : 1149 + PAD_AVAIL_IN - (ar.in - ar.last)); 1150 + strm->avail_out = (unsigned)(ar.out < ar.end ? 1151 + PAD_AVAIL_OUT + (ar.end - ar.out) : 1152 + PAD_AVAIL_OUT - (ar.out - ar.end)); 1153 + state->hold = ar.hold; 1154 + state->bits = ar.bits; 1155 + return; 1156 +} 1157 +
Added compat/zlib/contrib/inflate86/inffast.S.
1 +/* 2 + * inffast.S is a hand tuned assembler version of: 3 + * 4 + * inffast.c -- fast decoding 5 + * Copyright (C) 1995-2003 Mark Adler 6 + * For conditions of distribution and use, see copyright notice in zlib.h 7 + * 8 + * Copyright (C) 2003 Chris Anderson <christop@charm.net> 9 + * Please use the copyright conditions above. 10 + * 11 + * This version (Jan-23-2003) of inflate_fast was coded and tested under 12 + * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that 13 + * machine, I found that gzip style archives decompressed about 20% faster than 14 + * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will 15 + * depend on how large of a buffer is used for z_stream.next_in & next_out 16 + * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in 17 + * stream processing I/O and crc32/addler32. In my case, this routine used 18 + * 70% of the cpu time and crc32 used 20%. 19 + * 20 + * I am confident that this version will work in the general case, but I have 21 + * not tested a wide variety of datasets or a wide variety of platforms. 22 + * 23 + * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating. 24 + * It should be a runtime flag instead of compile time flag... 25 + * 26 + * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction. 27 + * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code 28 + * is compiled. Without either option, runtime detection is enabled. Runtime 29 + * detection should work on all modern cpus and the recomended algorithm (flip 30 + * ID bit on eflags and then use the cpuid instruction) is used in many 31 + * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12 32 + * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o 33 + * inffast.obj generates a COFF object which can then be linked with MSVC++ 34 + * compiled code. Tested under FreeBSD 4.7 with gcc-2.95. 35 + * 36 + * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and 37 + * slower than compiler generated code). Adjusted cpuid check to use the MMX 38 + * code only for Pentiums < P4 until I have more data on the P4. Speed 39 + * improvment is only about 15% on the Athlon when compared with code generated 40 + * with MSVC++. Not sure yet, but I think the P4 will also be slower using the 41 + * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and 42 + * have less latency than MMX ops. Added code to buffer the last 11 bytes of 43 + * the input stream since the MMX code grabs bits in chunks of 32, which 44 + * differs from the inffast.c algorithm. I don't think there would have been 45 + * read overruns where a page boundary was crossed (a segfault), but there 46 + * could have been overruns when next_in ends on unaligned memory (unintialized 47 + * memory read). 48 + * 49 + * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C 50 + * version of the non-MMX code so that it doesn't depend on zstrm and zstate 51 + * structure offsets which are hard coded in this file. This was last tested 52 + * with zlib-1.2.0 which is currently in beta testing, newer versions of this 53 + * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and 54 + * http://www.charm.net/~christop/zlib/ 55 + */ 56 + 57 + 58 +/* 59 + * if you have underscore linking problems (_inflate_fast undefined), try 60 + * using -DGAS_COFF 61 + */ 62 +#if ! defined( GAS_COFF ) && ! defined( GAS_ELF ) 63 + 64 +#if defined( WIN32 ) || defined( __CYGWIN__ ) 65 +#define GAS_COFF /* windows object format */ 66 +#else 67 +#define GAS_ELF 68 +#endif 69 + 70 +#endif /* ! GAS_COFF && ! GAS_ELF */ 71 + 72 + 73 +#if defined( GAS_COFF ) 74 + 75 +/* coff externals have underscores */ 76 +#define inflate_fast _inflate_fast 77 +#define inflate_fast_use_mmx _inflate_fast_use_mmx 78 + 79 +#endif /* GAS_COFF */ 80 + 81 + 82 +.file "inffast.S" 83 + 84 +.globl inflate_fast 85 + 86 +.text 87 +.align 4,0 88 +.L_invalid_literal_length_code_msg: 89 +.string "invalid literal/length code" 90 + 91 +.align 4,0 92 +.L_invalid_distance_code_msg: 93 +.string "invalid distance code" 94 + 95 +.align 4,0 96 +.L_invalid_distance_too_far_msg: 97 +.string "invalid distance too far back" 98 + 99 +#if ! defined( NO_MMX ) 100 +.align 4,0 101 +.L_mask: /* mask[N] = ( 1 << N ) - 1 */ 102 +.long 0 103 +.long 1 104 +.long 3 105 +.long 7 106 +.long 15 107 +.long 31 108 +.long 63 109 +.long 127 110 +.long 255 111 +.long 511 112 +.long 1023 113 +.long 2047 114 +.long 4095 115 +.long 8191 116 +.long 16383 117 +.long 32767 118 +.long 65535 119 +.long 131071 120 +.long 262143 121 +.long 524287 122 +.long 1048575 123 +.long 2097151 124 +.long 4194303 125 +.long 8388607 126 +.long 16777215 127 +.long 33554431 128 +.long 67108863 129 +.long 134217727 130 +.long 268435455 131 +.long 536870911 132 +.long 1073741823 133 +.long 2147483647 134 +.long 4294967295 135 +#endif /* NO_MMX */ 136 + 137 +.text 138 + 139 +/* 140 + * struct z_stream offsets, in zlib.h 141 + */ 142 +#define next_in_strm 0 /* strm->next_in */ 143 +#define avail_in_strm 4 /* strm->avail_in */ 144 +#define next_out_strm 12 /* strm->next_out */ 145 +#define avail_out_strm 16 /* strm->avail_out */ 146 +#define msg_strm 24 /* strm->msg */ 147 +#define state_strm 28 /* strm->state */ 148 + 149 +/* 150 + * struct inflate_state offsets, in inflate.h 151 + */ 152 +#define mode_state 0 /* state->mode */ 153 +#define wsize_state 32 /* state->wsize */ 154 +#define write_state 40 /* state->write */ 155 +#define window_state 44 /* state->window */ 156 +#define hold_state 48 /* state->hold */ 157 +#define bits_state 52 /* state->bits */ 158 +#define lencode_state 68 /* state->lencode */ 159 +#define distcode_state 72 /* state->distcode */ 160 +#define lenbits_state 76 /* state->lenbits */ 161 +#define distbits_state 80 /* state->distbits */ 162 + 163 +/* 164 + * inflate_fast's activation record 165 + */ 166 +#define local_var_size 64 /* how much local space for vars */ 167 +#define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */ 168 +#define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */ 169 + 170 +/* 171 + * offsets for local vars on stack 172 + */ 173 +#define out 60 /* unsigned char* */ 174 +#define window 56 /* unsigned char* */ 175 +#define wsize 52 /* unsigned int */ 176 +#define write 48 /* unsigned int */ 177 +#define in 44 /* unsigned char* */ 178 +#define beg 40 /* unsigned char* */ 179 +#define buf 28 /* char[ 12 ] */ 180 +#define len 24 /* unsigned int */ 181 +#define last 20 /* unsigned char* */ 182 +#define end 16 /* unsigned char* */ 183 +#define dcode 12 /* code* */ 184 +#define lcode 8 /* code* */ 185 +#define dmask 4 /* unsigned int */ 186 +#define lmask 0 /* unsigned int */ 187 + 188 +/* 189 + * typedef enum inflate_mode consts, in inflate.h 190 + */ 191 +#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */ 192 +#define INFLATE_MODE_BAD 26 193 + 194 + 195 +#if ! defined( USE_MMX ) && ! defined( NO_MMX ) 196 + 197 +#define RUN_TIME_MMX 198 + 199 +#define CHECK_MMX 1 200 +#define DO_USE_MMX 2 201 +#define DONT_USE_MMX 3 202 + 203 +.globl inflate_fast_use_mmx 204 + 205 +.data 206 + 207 +.align 4,0 208 +inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */ 209 +.long CHECK_MMX 210 + 211 +#if defined( GAS_ELF ) 212 +/* elf info */ 213 +.type inflate_fast_use_mmx,@object 214 +.size inflate_fast_use_mmx,4 215 +#endif 216 + 217 +#endif /* RUN_TIME_MMX */ 218 + 219 +#if defined( GAS_COFF ) 220 +/* coff info: scl 2 = extern, type 32 = function */ 221 +.def inflate_fast; .scl 2; .type 32; .endef 222 +#endif 223 + 224 +.text 225 + 226 +.align 32,0x90 227 +inflate_fast: 228 + pushl %edi 229 + pushl %esi 230 + pushl %ebp 231 + pushl %ebx 232 + pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */ 233 + subl $local_var_size, %esp 234 + cld 235 + 236 +#define strm_r %esi 237 +#define state_r %edi 238 + 239 + movl strm_sp(%esp), strm_r 240 + movl state_strm(strm_r), state_r 241 + 242 + /* in = strm->next_in; 243 + * out = strm->next_out; 244 + * last = in + strm->avail_in - 11; 245 + * beg = out - (start - strm->avail_out); 246 + * end = out + (strm->avail_out - 257); 247 + */ 248 + movl avail_in_strm(strm_r), %edx 249 + movl next_in_strm(strm_r), %eax 250 + 251 + addl %eax, %edx /* avail_in += next_in */ 252 + subl $11, %edx /* avail_in -= 11 */ 253 + 254 + movl %eax, in(%esp) 255 + movl %edx, last(%esp) 256 + 257 + movl start_sp(%esp), %ebp 258 + movl avail_out_strm(strm_r), %ecx 259 + movl next_out_strm(strm_r), %ebx 260 + 261 + subl %ecx, %ebp /* start -= avail_out */ 262 + negl %ebp /* start = -start */ 263 + addl %ebx, %ebp /* start += next_out */ 264 + 265 + subl $257, %ecx /* avail_out -= 257 */ 266 + addl %ebx, %ecx /* avail_out += out */ 267 + 268 + movl %ebx, out(%esp) 269 + movl %ebp, beg(%esp) 270 + movl %ecx, end(%esp) 271 + 272 + /* wsize = state->wsize; 273 + * write = state->write; 274 + * window = state->window; 275 + * hold = state->hold; 276 + * bits = state->bits; 277 + * lcode = state->lencode; 278 + * dcode = state->distcode; 279 + * lmask = ( 1 << state->lenbits ) - 1; 280 + * dmask = ( 1 << state->distbits ) - 1; 281 + */ 282 + 283 + movl lencode_state(state_r), %eax 284 + movl distcode_state(state_r), %ecx 285 + 286 + movl %eax, lcode(%esp) 287 + movl %ecx, dcode(%esp) 288 + 289 + movl $1, %eax 290 + movl lenbits_state(state_r), %ecx 291 + shll %cl, %eax 292 + decl %eax 293 + movl %eax, lmask(%esp) 294 + 295 + movl $1, %eax 296 + movl distbits_state(state_r), %ecx 297 + shll %cl, %eax 298 + decl %eax 299 + movl %eax, dmask(%esp) 300 + 301 + movl wsize_state(state_r), %eax 302 + movl write_state(state_r), %ecx 303 + movl window_state(state_r), %edx 304 + 305 + movl %eax, wsize(%esp) 306 + movl %ecx, write(%esp) 307 + movl %edx, window(%esp) 308 + 309 + movl hold_state(state_r), %ebp 310 + movl bits_state(state_r), %ebx 311 + 312 +#undef strm_r 313 +#undef state_r 314 + 315 +#define in_r %esi 316 +#define from_r %esi 317 +#define out_r %edi 318 + 319 + movl in(%esp), in_r 320 + movl last(%esp), %ecx 321 + cmpl in_r, %ecx 322 + ja .L_align_long /* if in < last */ 323 + 324 + addl $11, %ecx /* ecx = &in[ avail_in ] */ 325 + subl in_r, %ecx /* ecx = avail_in */ 326 + movl $12, %eax 327 + subl %ecx, %eax /* eax = 12 - avail_in */ 328 + leal buf(%esp), %edi 329 + rep movsb /* memcpy( buf, in, avail_in ) */ 330 + movl %eax, %ecx 331 + xorl %eax, %eax 332 + rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */ 333 + leal buf(%esp), in_r /* in = buf */ 334 + movl in_r, last(%esp) /* last = in, do just one iteration */ 335 + jmp .L_is_aligned 336 + 337 + /* align in_r on long boundary */ 338 +.L_align_long: 339 + testl $3, in_r 340 + jz .L_is_aligned 341 + xorl %eax, %eax 342 + movb (in_r), %al 343 + incl in_r 344 + movl %ebx, %ecx 345 + addl $8, %ebx 346 + shll %cl, %eax 347 + orl %eax, %ebp 348 + jmp .L_align_long 349 + 350 +.L_is_aligned: 351 + movl out(%esp), out_r 352 + 353 +#if defined( NO_MMX ) 354 + jmp .L_do_loop 355 +#endif 356 + 357 +#if defined( USE_MMX ) 358 + jmp .L_init_mmx 359 +#endif 360 + 361 +/*** Runtime MMX check ***/ 362 + 363 +#if defined( RUN_TIME_MMX ) 364 +.L_check_mmx: 365 + cmpl $DO_USE_MMX, inflate_fast_use_mmx 366 + je .L_init_mmx 367 + ja .L_do_loop /* > 2 */ 368 + 369 + pushl %eax 370 + pushl %ebx 371 + pushl %ecx 372 + pushl %edx 373 + pushf 374 + movl (%esp), %eax /* copy eflags to eax */ 375 + xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21) 376 + * to see if cpu supports cpuid... 377 + * ID bit method not supported by NexGen but 378 + * bios may load a cpuid instruction and 379 + * cpuid may be disabled on Cyrix 5-6x86 */ 380 + popf 381 + pushf 382 + popl %edx /* copy new eflags to edx */ 383 + xorl %eax, %edx /* test if ID bit is flipped */ 384 + jz .L_dont_use_mmx /* not flipped if zero */ 385 + xorl %eax, %eax 386 + cpuid 387 + cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */ 388 + jne .L_dont_use_mmx 389 + cmpl $0x6c65746e, %ecx 390 + jne .L_dont_use_mmx 391 + cmpl $0x49656e69, %edx 392 + jne .L_dont_use_mmx 393 + movl $1, %eax 394 + cpuid /* get cpu features */ 395 + shrl $8, %eax 396 + andl $15, %eax 397 + cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */ 398 + jne .L_dont_use_mmx 399 + testl $0x800000, %edx /* test if MMX feature is set (bit 23) */ 400 + jnz .L_use_mmx 401 + jmp .L_dont_use_mmx 402 +.L_use_mmx: 403 + movl $DO_USE_MMX, inflate_fast_use_mmx 404 + jmp .L_check_mmx_pop 405 +.L_dont_use_mmx: 406 + movl $DONT_USE_MMX, inflate_fast_use_mmx 407 +.L_check_mmx_pop: 408 + popl %edx 409 + popl %ecx 410 + popl %ebx 411 + popl %eax 412 + jmp .L_check_mmx 413 +#endif 414 + 415 + 416 +/*** Non-MMX code ***/ 417 + 418 +#if defined ( NO_MMX ) || defined( RUN_TIME_MMX ) 419 + 420 +#define hold_r %ebp 421 +#define bits_r %bl 422 +#define bitslong_r %ebx 423 + 424 +.align 32,0x90 425 +.L_while_test: 426 + /* while (in < last && out < end) 427 + */ 428 + cmpl out_r, end(%esp) 429 + jbe .L_break_loop /* if (out >= end) */ 430 + 431 + cmpl in_r, last(%esp) 432 + jbe .L_break_loop 433 + 434 +.L_do_loop: 435 + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out 436 + * 437 + * do { 438 + * if (bits < 15) { 439 + * hold |= *((unsigned short *)in)++ << bits; 440 + * bits += 16 441 + * } 442 + * this = lcode[hold & lmask] 443 + */ 444 + cmpb $15, bits_r 445 + ja .L_get_length_code /* if (15 < bits) */ 446 + 447 + xorl %eax, %eax 448 + lodsw /* al = *(ushort *)in++ */ 449 + movb bits_r, %cl /* cl = bits, needs it for shifting */ 450 + addb $16, bits_r /* bits += 16 */ 451 + shll %cl, %eax 452 + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 453 + 454 +.L_get_length_code: 455 + movl lmask(%esp), %edx /* edx = lmask */ 456 + movl lcode(%esp), %ecx /* ecx = lcode */ 457 + andl hold_r, %edx /* edx &= hold */ 458 + movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */ 459 + 460 +.L_dolen: 461 + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out 462 + * 463 + * dolen: 464 + * bits -= this.bits; 465 + * hold >>= this.bits 466 + */ 467 + movb %ah, %cl /* cl = this.bits */ 468 + subb %ah, bits_r /* bits -= this.bits */ 469 + shrl %cl, hold_r /* hold >>= this.bits */ 470 + 471 + /* check if op is a literal 472 + * if (op == 0) { 473 + * PUP(out) = this.val; 474 + * } 475 + */ 476 + testb %al, %al 477 + jnz .L_test_for_length_base /* if (op != 0) 45.7% */ 478 + 479 + shrl $16, %eax /* output this.val char */ 480 + stosb 481 + jmp .L_while_test 482 + 483 +.L_test_for_length_base: 484 + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len 485 + * 486 + * else if (op & 16) { 487 + * len = this.val 488 + * op &= 15 489 + * if (op) { 490 + * if (op > bits) { 491 + * hold |= *((unsigned short *)in)++ << bits; 492 + * bits += 16 493 + * } 494 + * len += hold & mask[op]; 495 + * bits -= op; 496 + * hold >>= op; 497 + * } 498 + */ 499 +#define len_r %edx 500 + movl %eax, len_r /* len = this */ 501 + shrl $16, len_r /* len = this.val */ 502 + movb %al, %cl 503 + 504 + testb $16, %al 505 + jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ 506 + andb $15, %cl /* op &= 15 */ 507 + jz .L_save_len /* if (!op) */ 508 + cmpb %cl, bits_r 509 + jae .L_add_bits_to_len /* if (op <= bits) */ 510 + 511 + movb %cl, %ch /* stash op in ch, freeing cl */ 512 + xorl %eax, %eax 513 + lodsw /* al = *(ushort *)in++ */ 514 + movb bits_r, %cl /* cl = bits, needs it for shifting */ 515 + addb $16, bits_r /* bits += 16 */ 516 + shll %cl, %eax 517 + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 518 + movb %ch, %cl /* move op back to ecx */ 519 + 520 +.L_add_bits_to_len: 521 + movl $1, %eax 522 + shll %cl, %eax 523 + decl %eax 524 + subb %cl, bits_r 525 + andl hold_r, %eax /* eax &= hold */ 526 + shrl %cl, hold_r 527 + addl %eax, len_r /* len += hold & mask[op] */ 528 + 529 +.L_save_len: 530 + movl len_r, len(%esp) /* save len */ 531 +#undef len_r 532 + 533 +.L_decode_distance: 534 + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist 535 + * 536 + * if (bits < 15) { 537 + * hold |= *((unsigned short *)in)++ << bits; 538 + * bits += 16 539 + * } 540 + * this = dcode[hold & dmask]; 541 + * dodist: 542 + * bits -= this.bits; 543 + * hold >>= this.bits; 544 + * op = this.op; 545 + */ 546 + 547 + cmpb $15, bits_r 548 + ja .L_get_distance_code /* if (15 < bits) */ 549 + 550 + xorl %eax, %eax 551 + lodsw /* al = *(ushort *)in++ */ 552 + movb bits_r, %cl /* cl = bits, needs it for shifting */ 553 + addb $16, bits_r /* bits += 16 */ 554 + shll %cl, %eax 555 + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 556 + 557 +.L_get_distance_code: 558 + movl dmask(%esp), %edx /* edx = dmask */ 559 + movl dcode(%esp), %ecx /* ecx = dcode */ 560 + andl hold_r, %edx /* edx &= hold */ 561 + movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */ 562 + 563 +#define dist_r %edx 564 +.L_dodist: 565 + movl %eax, dist_r /* dist = this */ 566 + shrl $16, dist_r /* dist = this.val */ 567 + movb %ah, %cl 568 + subb %ah, bits_r /* bits -= this.bits */ 569 + shrl %cl, hold_r /* hold >>= this.bits */ 570 + 571 + /* if (op & 16) { 572 + * dist = this.val 573 + * op &= 15 574 + * if (op > bits) { 575 + * hold |= *((unsigned short *)in)++ << bits; 576 + * bits += 16 577 + * } 578 + * dist += hold & mask[op]; 579 + * bits -= op; 580 + * hold >>= op; 581 + */ 582 + movb %al, %cl /* cl = this.op */ 583 + 584 + testb $16, %al /* if ((op & 16) == 0) */ 585 + jz .L_test_for_second_level_dist 586 + andb $15, %cl /* op &= 15 */ 587 + jz .L_check_dist_one 588 + cmpb %cl, bits_r 589 + jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */ 590 + 591 + movb %cl, %ch /* stash op in ch, freeing cl */ 592 + xorl %eax, %eax 593 + lodsw /* al = *(ushort *)in++ */ 594 + movb bits_r, %cl /* cl = bits, needs it for shifting */ 595 + addb $16, bits_r /* bits += 16 */ 596 + shll %cl, %eax 597 + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 598 + movb %ch, %cl /* move op back to ecx */ 599 + 600 +.L_add_bits_to_dist: 601 + movl $1, %eax 602 + shll %cl, %eax 603 + decl %eax /* (1 << op) - 1 */ 604 + subb %cl, bits_r 605 + andl hold_r, %eax /* eax &= hold */ 606 + shrl %cl, hold_r 607 + addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */ 608 + jmp .L_check_window 609 + 610 +.L_check_window: 611 + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 612 + * %ecx = nbytes 613 + * 614 + * nbytes = out - beg; 615 + * if (dist <= nbytes) { 616 + * from = out - dist; 617 + * do { 618 + * PUP(out) = PUP(from); 619 + * } while (--len > 0) { 620 + * } 621 + */ 622 + 623 + movl in_r, in(%esp) /* save in so from can use it's reg */ 624 + movl out_r, %eax 625 + subl beg(%esp), %eax /* nbytes = out - beg */ 626 + 627 + cmpl dist_r, %eax 628 + jb .L_clip_window /* if (dist > nbytes) 4.2% */ 629 + 630 + movl len(%esp), %ecx 631 + movl out_r, from_r 632 + subl dist_r, from_r /* from = out - dist */ 633 + 634 + subl $3, %ecx 635 + movb (from_r), %al 636 + movb %al, (out_r) 637 + movb 1(from_r), %al 638 + movb 2(from_r), %dl 639 + addl $3, from_r 640 + movb %al, 1(out_r) 641 + movb %dl, 2(out_r) 642 + addl $3, out_r 643 + rep movsb 644 + 645 + movl in(%esp), in_r /* move in back to %esi, toss from */ 646 + jmp .L_while_test 647 + 648 +.align 16,0x90 649 +.L_check_dist_one: 650 + cmpl $1, dist_r 651 + jne .L_check_window 652 + cmpl out_r, beg(%esp) 653 + je .L_check_window 654 + 655 + decl out_r 656 + movl len(%esp), %ecx 657 + movb (out_r), %al 658 + subl $3, %ecx 659 + 660 + movb %al, 1(out_r) 661 + movb %al, 2(out_r) 662 + movb %al, 3(out_r) 663 + addl $4, out_r 664 + rep stosb 665 + 666 + jmp .L_while_test 667 + 668 +.align 16,0x90 669 +.L_test_for_second_level_length: 670 + /* else if ((op & 64) == 0) { 671 + * this = lcode[this.val + (hold & mask[op])]; 672 + * } 673 + */ 674 + testb $64, %al 675 + jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ 676 + 677 + movl $1, %eax 678 + shll %cl, %eax 679 + decl %eax 680 + andl hold_r, %eax /* eax &= hold */ 681 + addl %edx, %eax /* eax += this.val */ 682 + movl lcode(%esp), %edx /* edx = lcode */ 683 + movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */ 684 + jmp .L_dolen 685 + 686 +.align 16,0x90 687 +.L_test_for_second_level_dist: 688 + /* else if ((op & 64) == 0) { 689 + * this = dcode[this.val + (hold & mask[op])]; 690 + * } 691 + */ 692 + testb $64, %al 693 + jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ 694 + 695 + movl $1, %eax 696 + shll %cl, %eax 697 + decl %eax 698 + andl hold_r, %eax /* eax &= hold */ 699 + addl %edx, %eax /* eax += this.val */ 700 + movl dcode(%esp), %edx /* edx = dcode */ 701 + movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */ 702 + jmp .L_dodist 703 + 704 +.align 16,0x90 705 +.L_clip_window: 706 + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 707 + * %ecx = nbytes 708 + * 709 + * else { 710 + * if (dist > wsize) { 711 + * invalid distance 712 + * } 713 + * from = window; 714 + * nbytes = dist - nbytes; 715 + * if (write == 0) { 716 + * from += wsize - nbytes; 717 + */ 718 +#define nbytes_r %ecx 719 + movl %eax, nbytes_r 720 + movl wsize(%esp), %eax /* prepare for dist compare */ 721 + negl nbytes_r /* nbytes = -nbytes */ 722 + movl window(%esp), from_r /* from = window */ 723 + 724 + cmpl dist_r, %eax 725 + jb .L_invalid_distance_too_far /* if (dist > wsize) */ 726 + 727 + addl dist_r, nbytes_r /* nbytes = dist - nbytes */ 728 + cmpl $0, write(%esp) 729 + jne .L_wrap_around_window /* if (write != 0) */ 730 + 731 + subl nbytes_r, %eax 732 + addl %eax, from_r /* from += wsize - nbytes */ 733 + 734 + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 735 + * %ecx = nbytes, %eax = len 736 + * 737 + * if (nbytes < len) { 738 + * len -= nbytes; 739 + * do { 740 + * PUP(out) = PUP(from); 741 + * } while (--nbytes); 742 + * from = out - dist; 743 + * } 744 + * } 745 + */ 746 +#define len_r %eax 747 + movl len(%esp), len_r 748 + cmpl nbytes_r, len_r 749 + jbe .L_do_copy1 /* if (nbytes >= len) */ 750 + 751 + subl nbytes_r, len_r /* len -= nbytes */ 752 + rep movsb 753 + movl out_r, from_r 754 + subl dist_r, from_r /* from = out - dist */ 755 + jmp .L_do_copy1 756 + 757 + cmpl nbytes_r, len_r 758 + jbe .L_do_copy1 /* if (nbytes >= len) */ 759 + 760 + subl nbytes_r, len_r /* len -= nbytes */ 761 + rep movsb 762 + movl out_r, from_r 763 + subl dist_r, from_r /* from = out - dist */ 764 + jmp .L_do_copy1 765 + 766 +.L_wrap_around_window: 767 + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 768 + * %ecx = nbytes, %eax = write, %eax = len 769 + * 770 + * else if (write < nbytes) { 771 + * from += wsize + write - nbytes; 772 + * nbytes -= write; 773 + * if (nbytes < len) { 774 + * len -= nbytes; 775 + * do { 776 + * PUP(out) = PUP(from); 777 + * } while (--nbytes); 778 + * from = window; 779 + * nbytes = write; 780 + * if (nbytes < len) { 781 + * len -= nbytes; 782 + * do { 783 + * PUP(out) = PUP(from); 784 + * } while(--nbytes); 785 + * from = out - dist; 786 + * } 787 + * } 788 + * } 789 + */ 790 +#define write_r %eax 791 + movl write(%esp), write_r 792 + cmpl write_r, nbytes_r 793 + jbe .L_contiguous_in_window /* if (write >= nbytes) */ 794 + 795 + addl wsize(%esp), from_r 796 + addl write_r, from_r 797 + subl nbytes_r, from_r /* from += wsize + write - nbytes */ 798 + subl write_r, nbytes_r /* nbytes -= write */ 799 +#undef write_r 800 + 801 + movl len(%esp), len_r 802 + cmpl nbytes_r, len_r 803 + jbe .L_do_copy1 /* if (nbytes >= len) */ 804 + 805 + subl nbytes_r, len_r /* len -= nbytes */ 806 + rep movsb 807 + movl window(%esp), from_r /* from = window */ 808 + movl write(%esp), nbytes_r /* nbytes = write */ 809 + cmpl nbytes_r, len_r 810 + jbe .L_do_copy1 /* if (nbytes >= len) */ 811 + 812 + subl nbytes_r, len_r /* len -= nbytes */ 813 + rep movsb 814 + movl out_r, from_r 815 + subl dist_r, from_r /* from = out - dist */ 816 + jmp .L_do_copy1 817 + 818 +.L_contiguous_in_window: 819 + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 820 + * %ecx = nbytes, %eax = write, %eax = len 821 + * 822 + * else { 823 + * from += write - nbytes; 824 + * if (nbytes < len) { 825 + * len -= nbytes; 826 + * do { 827 + * PUP(out) = PUP(from); 828 + * } while (--nbytes); 829 + * from = out - dist; 830 + * } 831 + * } 832 + */ 833 +#define write_r %eax 834 + addl write_r, from_r 835 + subl nbytes_r, from_r /* from += write - nbytes */ 836 +#undef write_r 837 + 838 + movl len(%esp), len_r 839 + cmpl nbytes_r, len_r 840 + jbe .L_do_copy1 /* if (nbytes >= len) */ 841 + 842 + subl nbytes_r, len_r /* len -= nbytes */ 843 + rep movsb 844 + movl out_r, from_r 845 + subl dist_r, from_r /* from = out - dist */ 846 + 847 +.L_do_copy1: 848 + /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out 849 + * %eax = len 850 + * 851 + * while (len > 0) { 852 + * PUP(out) = PUP(from); 853 + * len--; 854 + * } 855 + * } 856 + * } while (in < last && out < end); 857 + */ 858 +#undef nbytes_r 859 +#define in_r %esi 860 + movl len_r, %ecx 861 + rep movsb 862 + 863 + movl in(%esp), in_r /* move in back to %esi, toss from */ 864 + jmp .L_while_test 865 + 866 +#undef len_r 867 +#undef dist_r 868 + 869 +#endif /* NO_MMX || RUN_TIME_MMX */ 870 + 871 + 872 +/*** MMX code ***/ 873 + 874 +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) 875 + 876 +.align 32,0x90 877 +.L_init_mmx: 878 + emms 879 + 880 +#undef bits_r 881 +#undef bitslong_r 882 +#define bitslong_r %ebp 883 +#define hold_mm %mm0 884 + movd %ebp, hold_mm 885 + movl %ebx, bitslong_r 886 + 887 +#define used_mm %mm1 888 +#define dmask2_mm %mm2 889 +#define lmask2_mm %mm3 890 +#define lmask_mm %mm4 891 +#define dmask_mm %mm5 892 +#define tmp_mm %mm6 893 + 894 + movd lmask(%esp), lmask_mm 895 + movq lmask_mm, lmask2_mm 896 + movd dmask(%esp), dmask_mm 897 + movq dmask_mm, dmask2_mm 898 + pxor used_mm, used_mm 899 + movl lcode(%esp), %ebx /* ebx = lcode */ 900 + jmp .L_do_loop_mmx 901 + 902 +.align 32,0x90 903 +.L_while_test_mmx: 904 + /* while (in < last && out < end) 905 + */ 906 + cmpl out_r, end(%esp) 907 + jbe .L_break_loop /* if (out >= end) */ 908 + 909 + cmpl in_r, last(%esp) 910 + jbe .L_break_loop 911 + 912 +.L_do_loop_mmx: 913 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 914 + 915 + cmpl $32, bitslong_r 916 + ja .L_get_length_code_mmx /* if (32 < bits) */ 917 + 918 + movd bitslong_r, tmp_mm 919 + movd (in_r), %mm7 920 + addl $4, in_r 921 + psllq tmp_mm, %mm7 922 + addl $32, bitslong_r 923 + por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ 924 + 925 +.L_get_length_code_mmx: 926 + pand hold_mm, lmask_mm 927 + movd lmask_mm, %eax 928 + movq lmask2_mm, lmask_mm 929 + movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */ 930 + 931 +.L_dolen_mmx: 932 + movzbl %ah, %ecx /* ecx = this.bits */ 933 + movd %ecx, used_mm 934 + subl %ecx, bitslong_r /* bits -= this.bits */ 935 + 936 + testb %al, %al 937 + jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */ 938 + 939 + shrl $16, %eax /* output this.val char */ 940 + stosb 941 + jmp .L_while_test_mmx 942 + 943 +.L_test_for_length_base_mmx: 944 +#define len_r %edx 945 + movl %eax, len_r /* len = this */ 946 + shrl $16, len_r /* len = this.val */ 947 + 948 + testb $16, %al 949 + jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */ 950 + andl $15, %eax /* op &= 15 */ 951 + jz .L_decode_distance_mmx /* if (!op) */ 952 + 953 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 954 + movd %eax, used_mm 955 + movd hold_mm, %ecx 956 + subl %eax, bitslong_r 957 + andl .L_mask(,%eax,4), %ecx 958 + addl %ecx, len_r /* len += hold & mask[op] */ 959 + 960 +.L_decode_distance_mmx: 961 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 962 + 963 + cmpl $32, bitslong_r 964 + ja .L_get_dist_code_mmx /* if (32 < bits) */ 965 + 966 + movd bitslong_r, tmp_mm 967 + movd (in_r), %mm7 968 + addl $4, in_r 969 + psllq tmp_mm, %mm7 970 + addl $32, bitslong_r 971 + por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ 972 + 973 +.L_get_dist_code_mmx: 974 + movl dcode(%esp), %ebx /* ebx = dcode */ 975 + pand hold_mm, dmask_mm 976 + movd dmask_mm, %eax 977 + movq dmask2_mm, dmask_mm 978 + movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */ 979 + 980 +.L_dodist_mmx: 981 +#define dist_r %ebx 982 + movzbl %ah, %ecx /* ecx = this.bits */ 983 + movl %eax, dist_r 984 + shrl $16, dist_r /* dist = this.val */ 985 + subl %ecx, bitslong_r /* bits -= this.bits */ 986 + movd %ecx, used_mm 987 + 988 + testb $16, %al /* if ((op & 16) == 0) */ 989 + jz .L_test_for_second_level_dist_mmx 990 + andl $15, %eax /* op &= 15 */ 991 + jz .L_check_dist_one_mmx 992 + 993 +.L_add_bits_to_dist_mmx: 994 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 995 + movd %eax, used_mm /* save bit length of current op */ 996 + movd hold_mm, %ecx /* get the next bits on input stream */ 997 + subl %eax, bitslong_r /* bits -= op bits */ 998 + andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */ 999 + addl %ecx, dist_r /* dist += hold & mask[op] */ 1000 + 1001 +.L_check_window_mmx: 1002 + movl in_r, in(%esp) /* save in so from can use it's reg */ 1003 + movl out_r, %eax 1004 + subl beg(%esp), %eax /* nbytes = out - beg */ 1005 + 1006 + cmpl dist_r, %eax 1007 + jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */ 1008 + 1009 + movl len_r, %ecx 1010 + movl out_r, from_r 1011 + subl dist_r, from_r /* from = out - dist */ 1012 + 1013 + subl $3, %ecx 1014 + movb (from_r), %al 1015 + movb %al, (out_r) 1016 + movb 1(from_r), %al 1017 + movb 2(from_r), %dl 1018 + addl $3, from_r 1019 + movb %al, 1(out_r) 1020 + movb %dl, 2(out_r) 1021 + addl $3, out_r 1022 + rep movsb 1023 + 1024 + movl in(%esp), in_r /* move in back to %esi, toss from */ 1025 + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 1026 + jmp .L_while_test_mmx 1027 + 1028 +.align 16,0x90 1029 +.L_check_dist_one_mmx: 1030 + cmpl $1, dist_r 1031 + jne .L_check_window_mmx 1032 + cmpl out_r, beg(%esp) 1033 + je .L_check_window_mmx 1034 + 1035 + decl out_r 1036 + movl len_r, %ecx 1037 + movb (out_r), %al 1038 + subl $3, %ecx 1039 + 1040 + movb %al, 1(out_r) 1041 + movb %al, 2(out_r) 1042 + movb %al, 3(out_r) 1043 + addl $4, out_r 1044 + rep stosb 1045 + 1046 + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 1047 + jmp .L_while_test_mmx 1048 + 1049 +.align 16,0x90 1050 +.L_test_for_second_level_length_mmx: 1051 + testb $64, %al 1052 + jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ 1053 + 1054 + andl $15, %eax 1055 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 1056 + movd hold_mm, %ecx 1057 + andl .L_mask(,%eax,4), %ecx 1058 + addl len_r, %ecx 1059 + movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */ 1060 + jmp .L_dolen_mmx 1061 + 1062 +.align 16,0x90 1063 +.L_test_for_second_level_dist_mmx: 1064 + testb $64, %al 1065 + jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ 1066 + 1067 + andl $15, %eax 1068 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 1069 + movd hold_mm, %ecx 1070 + andl .L_mask(,%eax,4), %ecx 1071 + movl dcode(%esp), %eax /* ecx = dcode */ 1072 + addl dist_r, %ecx 1073 + movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */ 1074 + jmp .L_dodist_mmx 1075 + 1076 +.align 16,0x90 1077 +.L_clip_window_mmx: 1078 +#define nbytes_r %ecx 1079 + movl %eax, nbytes_r 1080 + movl wsize(%esp), %eax /* prepare for dist compare */ 1081 + negl nbytes_r /* nbytes = -nbytes */ 1082 + movl window(%esp), from_r /* from = window */ 1083 + 1084 + cmpl dist_r, %eax 1085 + jb .L_invalid_distance_too_far /* if (dist > wsize) */ 1086 + 1087 + addl dist_r, nbytes_r /* nbytes = dist - nbytes */ 1088 + cmpl $0, write(%esp) 1089 + jne .L_wrap_around_window_mmx /* if (write != 0) */ 1090 + 1091 + subl nbytes_r, %eax 1092 + addl %eax, from_r /* from += wsize - nbytes */ 1093 + 1094 + cmpl nbytes_r, len_r 1095 + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ 1096 + 1097 + subl nbytes_r, len_r /* len -= nbytes */ 1098 + rep movsb 1099 + movl out_r, from_r 1100 + subl dist_r, from_r /* from = out - dist */ 1101 + jmp .L_do_copy1_mmx 1102 + 1103 + cmpl nbytes_r, len_r 1104 + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ 1105 + 1106 + subl nbytes_r, len_r /* len -= nbytes */ 1107 + rep movsb 1108 + movl out_r, from_r 1109 + subl dist_r, from_r /* from = out - dist */ 1110 + jmp .L_do_copy1_mmx 1111 + 1112 +.L_wrap_around_window_mmx: 1113 +#define write_r %eax 1114 + movl write(%esp), write_r 1115 + cmpl write_r, nbytes_r 1116 + jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */ 1117 + 1118 + addl wsize(%esp), from_r 1119 + addl write_r, from_r 1120 + subl nbytes_r, from_r /* from += wsize + write - nbytes */ 1121 + subl write_r, nbytes_r /* nbytes -= write */ 1122 +#undef write_r 1123 + 1124 + cmpl nbytes_r, len_r 1125 + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ 1126 + 1127 + subl nbytes_r, len_r /* len -= nbytes */ 1128 + rep movsb 1129 + movl window(%esp), from_r /* from = window */ 1130 + movl write(%esp), nbytes_r /* nbytes = write */ 1131 + cmpl nbytes_r, len_r 1132 + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ 1133 + 1134 + subl nbytes_r, len_r /* len -= nbytes */ 1135 + rep movsb 1136 + movl out_r, from_r 1137 + subl dist_r, from_r /* from = out - dist */ 1138 + jmp .L_do_copy1_mmx 1139 + 1140 +.L_contiguous_in_window_mmx: 1141 +#define write_r %eax 1142 + addl write_r, from_r 1143 + subl nbytes_r, from_r /* from += write - nbytes */ 1144 +#undef write_r 1145 + 1146 + cmpl nbytes_r, len_r 1147 + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ 1148 + 1149 + subl nbytes_r, len_r /* len -= nbytes */ 1150 + rep movsb 1151 + movl out_r, from_r 1152 + subl dist_r, from_r /* from = out - dist */ 1153 + 1154 +.L_do_copy1_mmx: 1155 +#undef nbytes_r 1156 +#define in_r %esi 1157 + movl len_r, %ecx 1158 + rep movsb 1159 + 1160 + movl in(%esp), in_r /* move in back to %esi, toss from */ 1161 + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 1162 + jmp .L_while_test_mmx 1163 + 1164 +#undef hold_r 1165 +#undef bitslong_r 1166 + 1167 +#endif /* USE_MMX || RUN_TIME_MMX */ 1168 + 1169 + 1170 +/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/ 1171 + 1172 +.L_invalid_distance_code: 1173 + /* else { 1174 + * strm->msg = "invalid distance code"; 1175 + * state->mode = BAD; 1176 + * } 1177 + */ 1178 + movl $.L_invalid_distance_code_msg, %ecx 1179 + movl $INFLATE_MODE_BAD, %edx 1180 + jmp .L_update_stream_state 1181 + 1182 +.L_test_for_end_of_block: 1183 + /* else if (op & 32) { 1184 + * state->mode = TYPE; 1185 + * break; 1186 + * } 1187 + */ 1188 + testb $32, %al 1189 + jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */ 1190 + 1191 + movl $0, %ecx 1192 + movl $INFLATE_MODE_TYPE, %edx 1193 + jmp .L_update_stream_state 1194 + 1195 +.L_invalid_literal_length_code: 1196 + /* else { 1197 + * strm->msg = "invalid literal/length code"; 1198 + * state->mode = BAD; 1199 + * } 1200 + */ 1201 + movl $.L_invalid_literal_length_code_msg, %ecx 1202 + movl $INFLATE_MODE_BAD, %edx 1203 + jmp .L_update_stream_state 1204 + 1205 +.L_invalid_distance_too_far: 1206 + /* strm->msg = "invalid distance too far back"; 1207 + * state->mode = BAD; 1208 + */ 1209 + movl in(%esp), in_r /* from_r has in's reg, put in back */ 1210 + movl $.L_invalid_distance_too_far_msg, %ecx 1211 + movl $INFLATE_MODE_BAD, %edx 1212 + jmp .L_update_stream_state 1213 + 1214 +.L_update_stream_state: 1215 + /* set strm->msg = %ecx, strm->state->mode = %edx */ 1216 + movl strm_sp(%esp), %eax 1217 + testl %ecx, %ecx /* if (msg != NULL) */ 1218 + jz .L_skip_msg 1219 + movl %ecx, msg_strm(%eax) /* strm->msg = msg */ 1220 +.L_skip_msg: 1221 + movl state_strm(%eax), %eax /* state = strm->state */ 1222 + movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */ 1223 + jmp .L_break_loop 1224 + 1225 +.align 32,0x90 1226 +.L_break_loop: 1227 + 1228 +/* 1229 + * Regs: 1230 + * 1231 + * bits = %ebp when mmx, and in %ebx when non-mmx 1232 + * hold = %hold_mm when mmx, and in %ebp when non-mmx 1233 + * in = %esi 1234 + * out = %edi 1235 + */ 1236 + 1237 +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) 1238 + 1239 +#if defined( RUN_TIME_MMX ) 1240 + 1241 + cmpl $DO_USE_MMX, inflate_fast_use_mmx 1242 + jne .L_update_next_in 1243 + 1244 +#endif /* RUN_TIME_MMX */ 1245 + 1246 + movl %ebp, %ebx 1247 + 1248 +.L_update_next_in: 1249 + 1250 +#endif 1251 + 1252 +#define strm_r %eax 1253 +#define state_r %edx 1254 + 1255 + /* len = bits >> 3; 1256 + * in -= len; 1257 + * bits -= len << 3; 1258 + * hold &= (1U << bits) - 1; 1259 + * state->hold = hold; 1260 + * state->bits = bits; 1261 + * strm->next_in = in; 1262 + * strm->next_out = out; 1263 + */ 1264 + movl strm_sp(%esp), strm_r 1265 + movl %ebx, %ecx 1266 + movl state_strm(strm_r), state_r 1267 + shrl $3, %ecx 1268 + subl %ecx, in_r 1269 + shll $3, %ecx 1270 + subl %ecx, %ebx 1271 + movl out_r, next_out_strm(strm_r) 1272 + movl %ebx, bits_state(state_r) 1273 + movl %ebx, %ecx 1274 + 1275 + leal buf(%esp), %ebx 1276 + cmpl %ebx, last(%esp) 1277 + jne .L_buf_not_used /* if buf != last */ 1278 + 1279 + subl %ebx, in_r /* in -= buf */ 1280 + movl next_in_strm(strm_r), %ebx 1281 + movl %ebx, last(%esp) /* last = strm->next_in */ 1282 + addl %ebx, in_r /* in += strm->next_in */ 1283 + movl avail_in_strm(strm_r), %ebx 1284 + subl $11, %ebx 1285 + addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */ 1286 + 1287 +.L_buf_not_used: 1288 + movl in_r, next_in_strm(strm_r) 1289 + 1290 + movl $1, %ebx 1291 + shll %cl, %ebx 1292 + decl %ebx 1293 + 1294 +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) 1295 + 1296 +#if defined( RUN_TIME_MMX ) 1297 + 1298 + cmpl $DO_USE_MMX, inflate_fast_use_mmx 1299 + jne .L_update_hold 1300 + 1301 +#endif /* RUN_TIME_MMX */ 1302 + 1303 + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 1304 + movd hold_mm, %ebp 1305 + 1306 + emms 1307 + 1308 +.L_update_hold: 1309 + 1310 +#endif /* USE_MMX || RUN_TIME_MMX */ 1311 + 1312 + andl %ebx, %ebp 1313 + movl %ebp, hold_state(state_r) 1314 + 1315 +#define last_r %ebx 1316 + 1317 + /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */ 1318 + movl last(%esp), last_r 1319 + cmpl in_r, last_r 1320 + jbe .L_last_is_smaller /* if (in >= last) */ 1321 + 1322 + subl in_r, last_r /* last -= in */ 1323 + addl $11, last_r /* last += 11 */ 1324 + movl last_r, avail_in_strm(strm_r) 1325 + jmp .L_fixup_out 1326 +.L_last_is_smaller: 1327 + subl last_r, in_r /* in -= last */ 1328 + negl in_r /* in = -in */ 1329 + addl $11, in_r /* in += 11 */ 1330 + movl in_r, avail_in_strm(strm_r) 1331 + 1332 +#undef last_r 1333 +#define end_r %ebx 1334 + 1335 +.L_fixup_out: 1336 + /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/ 1337 + movl end(%esp), end_r 1338 + cmpl out_r, end_r 1339 + jbe .L_end_is_smaller /* if (out >= end) */ 1340 + 1341 + subl out_r, end_r /* end -= out */ 1342 + addl $257, end_r /* end += 257 */ 1343 + movl end_r, avail_out_strm(strm_r) 1344 + jmp .L_done 1345 +.L_end_is_smaller: 1346 + subl end_r, out_r /* out -= end */ 1347 + negl out_r /* out = -out */ 1348 + addl $257, out_r /* out += 257 */ 1349 + movl out_r, avail_out_strm(strm_r) 1350 + 1351 +#undef end_r 1352 +#undef strm_r 1353 +#undef state_r 1354 + 1355 +.L_done: 1356 + addl $local_var_size, %esp 1357 + popf 1358 + popl %ebx 1359 + popl %ebp 1360 + popl %esi 1361 + popl %edi 1362 + ret 1363 + 1364 +#if defined( GAS_ELF ) 1365 +/* elf info */ 1366 +.type inflate_fast,@function 1367 +.size inflate_fast,.-inflate_fast 1368 +#endif
Added compat/zlib/contrib/iostream/test.cpp.
1 + 2 +#include "zfstream.h" 3 + 4 +int main() { 5 + 6 + // Construct a stream object with this filebuffer. Anything sent 7 + // to this stream will go to standard out. 8 + gzofstream os( 1, ios::out ); 9 + 10 + // This text is getting compressed and sent to stdout. 11 + // To prove this, run 'test | zcat'. 12 + os << "Hello, Mommy" << endl; 13 + 14 + os << setcompressionlevel( Z_NO_COMPRESSION ); 15 + os << "hello, hello, hi, ho!" << endl; 16 + 17 + setcompressionlevel( os, Z_DEFAULT_COMPRESSION ) 18 + << "I'm compressing again" << endl; 19 + 20 + os.close(); 21 + 22 + return 0; 23 + 24 +}
Added compat/zlib/contrib/iostream/zfstream.cpp.
1 + 2 +#include "zfstream.h" 3 + 4 +gzfilebuf::gzfilebuf() : 5 + file(NULL), 6 + mode(0), 7 + own_file_descriptor(0) 8 +{ } 9 + 10 +gzfilebuf::~gzfilebuf() { 11 + 12 + sync(); 13 + if ( own_file_descriptor ) 14 + close(); 15 + 16 +} 17 + 18 +gzfilebuf *gzfilebuf::open( const char *name, 19 + int io_mode ) { 20 + 21 + if ( is_open() ) 22 + return NULL; 23 + 24 + char char_mode[10]; 25 + char *p = char_mode; 26 + 27 + if ( io_mode & ios::in ) { 28 + mode = ios::in; 29 + *p++ = 'r'; 30 + } else if ( io_mode & ios::app ) { 31 + mode = ios::app; 32 + *p++ = 'a'; 33 + } else { 34 + mode = ios::out; 35 + *p++ = 'w'; 36 + } 37 + 38 + if ( io_mode & ios::binary ) { 39 + mode |= ios::binary; 40 + *p++ = 'b'; 41 + } 42 + 43 + // Hard code the compression level 44 + if ( io_mode & (ios::out|ios::app )) { 45 + *p++ = '9'; 46 + } 47 + 48 + // Put the end-of-string indicator 49 + *p = '\0'; 50 + 51 + if ( (file = gzopen(name, char_mode)) == NULL ) 52 + return NULL; 53 + 54 + own_file_descriptor = 1; 55 + 56 + return this; 57 + 58 +} 59 + 60 +gzfilebuf *gzfilebuf::attach( int file_descriptor, 61 + int io_mode ) { 62 + 63 + if ( is_open() ) 64 + return NULL; 65 + 66 + char char_mode[10]; 67 + char *p = char_mode; 68 + 69 + if ( io_mode & ios::in ) { 70 + mode = ios::in; 71 + *p++ = 'r'; 72 + } else if ( io_mode & ios::app ) { 73 + mode = ios::app; 74 + *p++ = 'a'; 75 + } else { 76 + mode = ios::out; 77 + *p++ = 'w'; 78 + } 79 + 80 + if ( io_mode & ios::binary ) { 81 + mode |= ios::binary; 82 + *p++ = 'b'; 83 + } 84 + 85 + // Hard code the compression level 86 + if ( io_mode & (ios::out|ios::app )) { 87 + *p++ = '9'; 88 + } 89 + 90 + // Put the end-of-string indicator 91 + *p = '\0'; 92 + 93 + if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) 94 + return NULL; 95 + 96 + own_file_descriptor = 0; 97 + 98 + return this; 99 + 100 +} 101 + 102 +gzfilebuf *gzfilebuf::close() { 103 + 104 + if ( is_open() ) { 105 + 106 + sync(); 107 + gzclose( file ); 108 + file = NULL; 109 + 110 + } 111 + 112 + return this; 113 + 114 +} 115 + 116 +int gzfilebuf::setcompressionlevel( int comp_level ) { 117 + 118 + return gzsetparams(file, comp_level, -2); 119 + 120 +} 121 + 122 +int gzfilebuf::setcompressionstrategy( int comp_strategy ) { 123 + 124 + return gzsetparams(file, -2, comp_strategy); 125 + 126 +} 127 + 128 + 129 +streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) { 130 + 131 + return streampos(EOF); 132 + 133 +} 134 + 135 +int gzfilebuf::underflow() { 136 + 137 + // If the file hasn't been opened for reading, error. 138 + if ( !is_open() || !(mode & ios::in) ) 139 + return EOF; 140 + 141 + // if a buffer doesn't exists, allocate one. 142 + if ( !base() ) { 143 + 144 + if ( (allocate()) == EOF ) 145 + return EOF; 146 + setp(0,0); 147 + 148 + } else { 149 + 150 + if ( in_avail() ) 151 + return (unsigned char) *gptr(); 152 + 153 + if ( out_waiting() ) { 154 + if ( flushbuf() == EOF ) 155 + return EOF; 156 + } 157 + 158 + } 159 + 160 + // Attempt to fill the buffer. 161 + 162 + int result = fillbuf(); 163 + if ( result == EOF ) { 164 + // disable get area 165 + setg(0,0,0); 166 + return EOF; 167 + } 168 + 169 + return (unsigned char) *gptr(); 170 + 171 +} 172 + 173 +int gzfilebuf::overflow( int c ) { 174 + 175 + if ( !is_open() || !(mode & ios::out) ) 176 + return EOF; 177 + 178 + if ( !base() ) { 179 + if ( allocate() == EOF ) 180 + return EOF; 181 + setg(0,0,0); 182 + } else { 183 + if (in_avail()) { 184 + return EOF; 185 + } 186 + if (out_waiting()) { 187 + if (flushbuf() == EOF) 188 + return EOF; 189 + } 190 + } 191 + 192 + int bl = blen(); 193 + setp( base(), base() + bl); 194 + 195 + if ( c != EOF ) { 196 + 197 + *pptr() = c; 198 + pbump(1); 199 + 200 + } 201 + 202 + return 0; 203 + 204 +} 205 + 206 +int gzfilebuf::sync() { 207 + 208 + if ( !is_open() ) 209 + return EOF; 210 + 211 + if ( out_waiting() ) 212 + return flushbuf(); 213 + 214 + return 0; 215 + 216 +} 217 + 218 +int gzfilebuf::flushbuf() { 219 + 220 + int n; 221 + char *q; 222 + 223 + q = pbase(); 224 + n = pptr() - q; 225 + 226 + if ( gzwrite( file, q, n) < n ) 227 + return EOF; 228 + 229 + setp(0,0); 230 + 231 + return 0; 232 + 233 +} 234 + 235 +int gzfilebuf::fillbuf() { 236 + 237 + int required; 238 + char *p; 239 + 240 + p = base(); 241 + 242 + required = blen(); 243 + 244 + int t = gzread( file, p, required ); 245 + 246 + if ( t <= 0) return EOF; 247 + 248 + setg( base(), base(), base()+t); 249 + 250 + return t; 251 + 252 +} 253 + 254 +gzfilestream_common::gzfilestream_common() : 255 + ios( gzfilestream_common::rdbuf() ) 256 +{ } 257 + 258 +gzfilestream_common::~gzfilestream_common() 259 +{ } 260 + 261 +void gzfilestream_common::attach( int fd, int io_mode ) { 262 + 263 + if ( !buffer.attach( fd, io_mode) ) 264 + clear( ios::failbit | ios::badbit ); 265 + else 266 + clear(); 267 + 268 +} 269 + 270 +void gzfilestream_common::open( const char *name, int io_mode ) { 271 + 272 + if ( !buffer.open( name, io_mode ) ) 273 + clear( ios::failbit | ios::badbit ); 274 + else 275 + clear(); 276 + 277 +} 278 + 279 +void gzfilestream_common::close() { 280 + 281 + if ( !buffer.close() ) 282 + clear( ios::failbit | ios::badbit ); 283 + 284 +} 285 + 286 +gzfilebuf *gzfilestream_common::rdbuf() 287 +{ 288 + return &buffer; 289 +} 290 + 291 +gzifstream::gzifstream() : 292 + ios( gzfilestream_common::rdbuf() ) 293 +{ 294 + clear( ios::badbit ); 295 +} 296 + 297 +gzifstream::gzifstream( const char *name, int io_mode ) : 298 + ios( gzfilestream_common::rdbuf() ) 299 +{ 300 + gzfilestream_common::open( name, io_mode ); 301 +} 302 + 303 +gzifstream::gzifstream( int fd, int io_mode ) : 304 + ios( gzfilestream_common::rdbuf() ) 305 +{ 306 + gzfilestream_common::attach( fd, io_mode ); 307 +} 308 + 309 +gzifstream::~gzifstream() { } 310 + 311 +gzofstream::gzofstream() : 312 + ios( gzfilestream_common::rdbuf() ) 313 +{ 314 + clear( ios::badbit ); 315 +} 316 + 317 +gzofstream::gzofstream( const char *name, int io_mode ) : 318 + ios( gzfilestream_common::rdbuf() ) 319 +{ 320 + gzfilestream_common::open( name, io_mode ); 321 +} 322 + 323 +gzofstream::gzofstream( int fd, int io_mode ) : 324 + ios( gzfilestream_common::rdbuf() ) 325 +{ 326 + gzfilestream_common::attach( fd, io_mode ); 327 +} 328 + 329 +gzofstream::~gzofstream() { }
Added compat/zlib/contrib/iostream/zfstream.h.
1 + 2 +#ifndef zfstream_h 3 +#define zfstream_h 4 + 5 +#include <fstream.h> 6 +#include "zlib.h" 7 + 8 +class gzfilebuf : public streambuf { 9 + 10 +public: 11 + 12 + gzfilebuf( ); 13 + virtual ~gzfilebuf(); 14 + 15 + gzfilebuf *open( const char *name, int io_mode ); 16 + gzfilebuf *attach( int file_descriptor, int io_mode ); 17 + gzfilebuf *close(); 18 + 19 + int setcompressionlevel( int comp_level ); 20 + int setcompressionstrategy( int comp_strategy ); 21 + 22 + inline int is_open() const { return (file !=NULL); } 23 + 24 + virtual streampos seekoff( streamoff, ios::seek_dir, int ); 25 + 26 + virtual int sync(); 27 + 28 +protected: 29 + 30 + virtual int underflow(); 31 + virtual int overflow( int = EOF ); 32 + 33 +private: 34 + 35 + gzFile file; 36 + short mode; 37 + short own_file_descriptor; 38 + 39 + int flushbuf(); 40 + int fillbuf(); 41 + 42 +}; 43 + 44 +class gzfilestream_common : virtual public ios { 45 + 46 + friend class gzifstream; 47 + friend class gzofstream; 48 + friend gzofstream &setcompressionlevel( gzofstream &, int ); 49 + friend gzofstream &setcompressionstrategy( gzofstream &, int ); 50 + 51 +public: 52 + virtual ~gzfilestream_common(); 53 + 54 + void attach( int fd, int io_mode ); 55 + void open( const char *name, int io_mode ); 56 + void close(); 57 + 58 +protected: 59 + gzfilestream_common(); 60 + 61 +private: 62 + gzfilebuf *rdbuf(); 63 + 64 + gzfilebuf buffer; 65 + 66 +}; 67 + 68 +class gzifstream : public gzfilestream_common, public istream { 69 + 70 +public: 71 + 72 + gzifstream(); 73 + gzifstream( const char *name, int io_mode = ios::in ); 74 + gzifstream( int fd, int io_mode = ios::in ); 75 + 76 + virtual ~gzifstream(); 77 + 78 +}; 79 + 80 +class gzofstream : public gzfilestream_common, public ostream { 81 + 82 +public: 83 + 84 + gzofstream(); 85 + gzofstream( const char *name, int io_mode = ios::out ); 86 + gzofstream( int fd, int io_mode = ios::out ); 87 + 88 + virtual ~gzofstream(); 89 + 90 +}; 91 + 92 +template<class T> class gzomanip { 93 + friend gzofstream &operator<<(gzofstream &, const gzomanip<T> &); 94 +public: 95 + gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } 96 +private: 97 + gzofstream &(*func)(gzofstream &, T); 98 + T val; 99 +}; 100 + 101 +template<class T> gzofstream &operator<<(gzofstream &s, const gzomanip<T> &m) 102 +{ 103 + return (*m.func)(s, m.val); 104 +} 105 + 106 +inline gzofstream &setcompressionlevel( gzofstream &s, int l ) 107 +{ 108 + (s.rdbuf())->setcompressionlevel(l); 109 + return s; 110 +} 111 + 112 +inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) 113 +{ 114 + (s.rdbuf())->setcompressionstrategy(l); 115 + return s; 116 +} 117 + 118 +inline gzomanip<int> setcompressionlevel(int l) 119 +{ 120 + return gzomanip<int>(&setcompressionlevel,l); 121 +} 122 + 123 +inline gzomanip<int> setcompressionstrategy(int l) 124 +{ 125 + return gzomanip<int>(&setcompressionstrategy,l); 126 +} 127 + 128 +#endif
Added compat/zlib/contrib/iostream2/zstream.h.
1 +/* 2 + * 3 + * Copyright (c) 1997 4 + * Christian Michelsen Research AS 5 + * Advanced Computing 6 + * Fantoftvegen 38, 5036 BERGEN, Norway 7 + * http://www.cmr.no 8 + * 9 + * Permission to use, copy, modify, distribute and sell this software 10 + * and its documentation for any purpose is hereby granted without fee, 11 + * provided that the above copyright notice appear in all copies and 12 + * that both that copyright notice and this permission notice appear 13 + * in supporting documentation. Christian Michelsen Research AS makes no 14 + * representations about the suitability of this software for any 15 + * purpose. It is provided "as is" without express or implied warranty. 16 + * 17 + */ 18 + 19 +#ifndef ZSTREAM__H 20 +#define ZSTREAM__H 21 + 22 +/* 23 + * zstream.h - C++ interface to the 'zlib' general purpose compression library 24 + * $Id: zstream.h 1.1 1997-06-25 12:00:56+02 tyge Exp tyge $ 25 + */ 26 + 27 +#include <strstream.h> 28 +#include <string.h> 29 +#include <stdio.h> 30 +#include "zlib.h" 31 + 32 +#if defined(_WIN32) 33 +# include <fcntl.h> 34 +# include <io.h> 35 +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 36 +#else 37 +# define SET_BINARY_MODE(file) 38 +#endif 39 + 40 +class zstringlen { 41 +public: 42 + zstringlen(class izstream&); 43 + zstringlen(class ozstream&, const char*); 44 + size_t value() const { return val.word; } 45 +private: 46 + struct Val { unsigned char byte; size_t word; } val; 47 +}; 48 + 49 +// ----------------------------- izstream ----------------------------- 50 + 51 +class izstream 52 +{ 53 + public: 54 + izstream() : m_fp(0) {} 55 + izstream(FILE* fp) : m_fp(0) { open(fp); } 56 + izstream(const char* name) : m_fp(0) { open(name); } 57 + ~izstream() { close(); } 58 + 59 + /* Opens a gzip (.gz) file for reading. 60 + * open() can be used to read a file which is not in gzip format; 61 + * in this case read() will directly read from the file without 62 + * decompression. errno can be checked to distinguish two error 63 + * cases (if errno is zero, the zlib error is Z_MEM_ERROR). 64 + */ 65 + void open(const char* name) { 66 + if (m_fp) close(); 67 + m_fp = ::gzopen(name, "rb"); 68 + } 69 + 70 + void open(FILE* fp) { 71 + SET_BINARY_MODE(fp); 72 + if (m_fp) close(); 73 + m_fp = ::gzdopen(fileno(fp), "rb"); 74 + } 75 + 76 + /* Flushes all pending input if necessary, closes the compressed file 77 + * and deallocates all the (de)compression state. The return value is 78 + * the zlib error number (see function error() below). 79 + */ 80 + int close() { 81 + int r = ::gzclose(m_fp); 82 + m_fp = 0; return r; 83 + } 84 + 85 + /* Binary read the given number of bytes from the compressed file. 86 + */ 87 + int read(void* buf, size_t len) { 88 + return ::gzread(m_fp, buf, len); 89 + } 90 + 91 + /* Returns the error message for the last error which occurred on the 92 + * given compressed file. errnum is set to zlib error number. If an 93 + * error occurred in the file system and not in the compression library, 94 + * errnum is set to Z_ERRNO and the application may consult errno 95 + * to get the exact error code. 96 + */ 97 + const char* error(int* errnum) { 98 + return ::gzerror(m_fp, errnum); 99 + } 100 + 101 + gzFile fp() { return m_fp; } 102 + 103 + private: 104 + gzFile m_fp; 105 +}; 106 + 107 +/* 108 + * Binary read the given (array of) object(s) from the compressed file. 109 + * If the input file was not in gzip format, read() copies the objects number 110 + * of bytes into the buffer. 111 + * returns the number of uncompressed bytes actually read 112 + * (0 for end of file, -1 for error). 113 + */ 114 +template <class T, class Items> 115 +inline int read(izstream& zs, T* x, Items items) { 116 + return ::gzread(zs.fp(), x, items*sizeof(T)); 117 +} 118 + 119 +/* 120 + * Binary input with the '>' operator. 121 + */ 122 +template <class T> 123 +inline izstream& operator>(izstream& zs, T& x) { 124 + ::gzread(zs.fp(), &x, sizeof(T)); 125 + return zs; 126 +} 127 + 128 + 129 +inline zstringlen::zstringlen(izstream& zs) { 130 + zs > val.byte; 131 + if (val.byte == 255) zs > val.word; 132 + else val.word = val.byte; 133 +} 134 + 135 +/* 136 + * Read length of string + the string with the '>' operator. 137 + */ 138 +inline izstream& operator>(izstream& zs, char* x) { 139 + zstringlen len(zs); 140 + ::gzread(zs.fp(), x, len.value()); 141 + x[len.value()] = '\0'; 142 + return zs; 143 +} 144 + 145 +inline char* read_string(izstream& zs) { 146 + zstringlen len(zs); 147 + char* x = new char[len.value()+1]; 148 + ::gzread(zs.fp(), x, len.value()); 149 + x[len.value()] = '\0'; 150 + return x; 151 +} 152 + 153 +// ----------------------------- ozstream ----------------------------- 154 + 155 +class ozstream 156 +{ 157 + public: 158 + ozstream() : m_fp(0), m_os(0) { 159 + } 160 + ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION) 161 + : m_fp(0), m_os(0) { 162 + open(fp, level); 163 + } 164 + ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION) 165 + : m_fp(0), m_os(0) { 166 + open(name, level); 167 + } 168 + ~ozstream() { 169 + close(); 170 + } 171 + 172 + /* Opens a gzip (.gz) file for writing. 173 + * The compression level parameter should be in 0..9 174 + * errno can be checked to distinguish two error cases 175 + * (if errno is zero, the zlib error is Z_MEM_ERROR). 176 + */ 177 + void open(const char* name, int level = Z_DEFAULT_COMPRESSION) { 178 + char mode[4] = "wb\0"; 179 + if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; 180 + if (m_fp) close(); 181 + m_fp = ::gzopen(name, mode); 182 + } 183 + 184 + /* open from a FILE pointer. 185 + */ 186 + void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) { 187 + SET_BINARY_MODE(fp); 188 + char mode[4] = "wb\0"; 189 + if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; 190 + if (m_fp) close(); 191 + m_fp = ::gzdopen(fileno(fp), mode); 192 + } 193 + 194 + /* Flushes all pending output if necessary, closes the compressed file 195 + * and deallocates all the (de)compression state. The return value is 196 + * the zlib error number (see function error() below). 197 + */ 198 + int close() { 199 + if (m_os) { 200 + ::gzwrite(m_fp, m_os->str(), m_os->pcount()); 201 + delete[] m_os->str(); delete m_os; m_os = 0; 202 + } 203 + int r = ::gzclose(m_fp); m_fp = 0; return r; 204 + } 205 + 206 + /* Binary write the given number of bytes into the compressed file. 207 + */ 208 + int write(const void* buf, size_t len) { 209 + return ::gzwrite(m_fp, (voidp) buf, len); 210 + } 211 + 212 + /* Flushes all pending output into the compressed file. The parameter 213 + * _flush is as in the deflate() function. The return value is the zlib 214 + * error number (see function gzerror below). flush() returns Z_OK if 215 + * the flush_ parameter is Z_FINISH and all output could be flushed. 216 + * flush() should be called only when strictly necessary because it can 217 + * degrade compression. 218 + */ 219 + int flush(int _flush) { 220 + os_flush(); 221 + return ::gzflush(m_fp, _flush); 222 + } 223 + 224 + /* Returns the error message for the last error which occurred on the 225 + * given compressed file. errnum is set to zlib error number. If an 226 + * error occurred in the file system and not in the compression library, 227 + * errnum is set to Z_ERRNO and the application may consult errno 228 + * to get the exact error code. 229 + */ 230 + const char* error(int* errnum) { 231 + return ::gzerror(m_fp, errnum); 232 + } 233 + 234 + gzFile fp() { return m_fp; } 235 + 236 + ostream& os() { 237 + if (m_os == 0) m_os = new ostrstream; 238 + return *m_os; 239 + } 240 + 241 + void os_flush() { 242 + if (m_os && m_os->pcount()>0) { 243 + ostrstream* oss = new ostrstream; 244 + oss->fill(m_os->fill()); 245 + oss->flags(m_os->flags()); 246 + oss->precision(m_os->precision()); 247 + oss->width(m_os->width()); 248 + ::gzwrite(m_fp, m_os->str(), m_os->pcount()); 249 + delete[] m_os->str(); delete m_os; m_os = oss; 250 + } 251 + } 252 + 253 + private: 254 + gzFile m_fp; 255 + ostrstream* m_os; 256 +}; 257 + 258 +/* 259 + * Binary write the given (array of) object(s) into the compressed file. 260 + * returns the number of uncompressed bytes actually written 261 + * (0 in case of error). 262 + */ 263 +template <class T, class Items> 264 +inline int write(ozstream& zs, const T* x, Items items) { 265 + return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T)); 266 +} 267 + 268 +/* 269 + * Binary output with the '<' operator. 270 + */ 271 +template <class T> 272 +inline ozstream& operator<(ozstream& zs, const T& x) { 273 + ::gzwrite(zs.fp(), (voidp) &x, sizeof(T)); 274 + return zs; 275 +} 276 + 277 +inline zstringlen::zstringlen(ozstream& zs, const char* x) { 278 + val.byte = 255; val.word = ::strlen(x); 279 + if (val.word < 255) zs < (val.byte = val.word); 280 + else zs < val; 281 +} 282 + 283 +/* 284 + * Write length of string + the string with the '<' operator. 285 + */ 286 +inline ozstream& operator<(ozstream& zs, const char* x) { 287 + zstringlen len(zs, x); 288 + ::gzwrite(zs.fp(), (voidp) x, len.value()); 289 + return zs; 290 +} 291 + 292 +#ifdef _MSC_VER 293 +inline ozstream& operator<(ozstream& zs, char* const& x) { 294 + return zs < (const char*) x; 295 +} 296 +#endif 297 + 298 +/* 299 + * Ascii write with the << operator; 300 + */ 301 +template <class T> 302 +inline ostream& operator<<(ozstream& zs, const T& x) { 303 + zs.os_flush(); 304 + return zs.os() << x; 305 +} 306 + 307 +#endif
Added compat/zlib/contrib/iostream2/zstream_test.cpp.
1 +#include "zstream.h" 2 +#include <math.h> 3 +#include <stdlib.h> 4 +#include <iomanip.h> 5 + 6 +void main() { 7 + char h[256] = "Hello"; 8 + char* g = "Goodbye"; 9 + ozstream out("temp.gz"); 10 + out < "This works well" < h < g; 11 + out.close(); 12 + 13 + izstream in("temp.gz"); // read it back 14 + char *x = read_string(in), *y = new char[256], z[256]; 15 + in > y > z; 16 + in.close(); 17 + cout << x << endl << y << endl << z << endl; 18 + 19 + out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results 20 + out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl; 21 + out << z << endl << y << endl << x << endl; 22 + out << 1.1234567890123456789 << endl; 23 + 24 + delete[] x; delete[] y; 25 +}
Added compat/zlib/contrib/iostream3/README.
1 +These classes provide a C++ stream interface to the zlib library. It allows you 2 +to do things like: 3 + 4 + gzofstream outf("blah.gz"); 5 + outf << "These go into the gzip file " << 123 << endl; 6 + 7 +It does this by deriving a specialized stream buffer for gzipped files, which is 8 +the way Stroustrup would have done it. :-> 9 + 10 +The gzifstream and gzofstream classes were originally written by Kevin Ruland 11 +and made available in the zlib contrib/iostream directory. The older version still 12 +compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of 13 +this version. 14 + 15 +The new classes are as standard-compliant as possible, closely following the 16 +approach of the standard library's fstream classes. It compiles under gcc versions 17 +3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard 18 +library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs 19 +from the previous one in the following respects: 20 +- added showmanyc 21 +- added setbuf, with support for unbuffered output via setbuf(0,0) 22 +- a few bug fixes of stream behavior 23 +- gzipped output file opened with default compression level instead of maximum level 24 +- setcompressionlevel()/strategy() members replaced by single setcompression() 25 + 26 +The code is provided "as is", with the permission to use, copy, modify, distribute 27 +and sell it for any purpose without fee. 28 + 29 +Ludwig Schwardt 30 +<schwardt@sun.ac.za> 31 + 32 +DSP Lab 33 +Electrical & Electronic Engineering Department 34 +University of Stellenbosch 35 +South Africa
Added compat/zlib/contrib/iostream3/TODO.
1 +Possible upgrades to gzfilebuf: 2 + 3 +- The ability to do putback (e.g. putbackfail) 4 + 5 +- The ability to seek (zlib supports this, but could be slow/tricky) 6 + 7 +- Simultaneous read/write access (does it make sense?) 8 + 9 +- Support for ios_base::ate open mode 10 + 11 +- Locale support? 12 + 13 +- Check public interface to see which calls give problems 14 + (due to dependence on library internals) 15 + 16 +- Override operator<<(ostream&, gzfilebuf*) to allow direct copying 17 + of stream buffer to stream ( i.e. os << is.rdbuf(); )
Added compat/zlib/contrib/iostream3/test.cc.
1 +/* 2 + * Test program for gzifstream and gzofstream 3 + * 4 + * by Ludwig Schwardt <schwardt@sun.ac.za> 5 + * original version by Kevin Ruland <kevin@rodin.wustl.edu> 6 + */ 7 + 8 +#include "zfstream.h" 9 +#include <iostream> // for cout 10 + 11 +int main() { 12 + 13 + gzofstream outf; 14 + gzifstream inf; 15 + char buf[80]; 16 + 17 + outf.open("test1.txt.gz"); 18 + outf << "The quick brown fox sidestepped the lazy canine\n" 19 + << 1.3 << "\nPlan " << 9 << std::endl; 20 + outf.close(); 21 + std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" 22 + << "The quick brown fox sidestepped the lazy canine\n" 23 + << 1.3 << "\nPlan " << 9 << std::endl; 24 + 25 + std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; 26 + inf.open("test1.txt.gz"); 27 + while (inf.getline(buf,80,'\n')) { 28 + std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 29 + } 30 + inf.close(); 31 + 32 + outf.rdbuf()->pubsetbuf(0,0); 33 + outf.open("test2.txt.gz"); 34 + outf << setcompression(Z_NO_COMPRESSION) 35 + << "The quick brown fox sidestepped the lazy canine\n" 36 + << 1.3 << "\nPlan " << 9 << std::endl; 37 + outf.close(); 38 + std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; 39 + 40 + std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; 41 + inf.rdbuf()->pubsetbuf(0,0); 42 + inf.open("test2.txt.gz"); 43 + while (inf.getline(buf,80,'\n')) { 44 + std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 45 + } 46 + inf.close(); 47 + 48 + return 0; 49 + 50 +}
Added compat/zlib/contrib/iostream3/zfstream.cc.
1 +/* 2 + * A C++ I/O streams interface to the zlib gz* functions 3 + * 4 + * by Ludwig Schwardt <schwardt@sun.ac.za> 5 + * original version by Kevin Ruland <kevin@rodin.wustl.edu> 6 + * 7 + * This version is standard-compliant and compatible with gcc 3.x. 8 + */ 9 + 10 +#include "zfstream.h" 11 +#include <cstring> // for strcpy, strcat, strlen (mode strings) 12 +#include <cstdio> // for BUFSIZ 13 + 14 +// Internal buffer sizes (default and "unbuffered" versions) 15 +#define BIGBUFSIZE BUFSIZ 16 +#define SMALLBUFSIZE 1 17 + 18 +/*****************************************************************************/ 19 + 20 +// Default constructor 21 +gzfilebuf::gzfilebuf() 22 +: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false), 23 + buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true) 24 +{ 25 + // No buffers to start with 26 + this->disable_buffer(); 27 +} 28 + 29 +// Destructor 30 +gzfilebuf::~gzfilebuf() 31 +{ 32 + // Sync output buffer and close only if responsible for file 33 + // (i.e. attached streams should be left open at this stage) 34 + this->sync(); 35 + if (own_fd) 36 + this->close(); 37 + // Make sure internal buffer is deallocated 38 + this->disable_buffer(); 39 +} 40 + 41 +// Set compression level and strategy 42 +int 43 +gzfilebuf::setcompression(int comp_level, 44 + int comp_strategy) 45 +{ 46 + return gzsetparams(file, comp_level, comp_strategy); 47 +} 48 + 49 +// Open gzipped file 50 +gzfilebuf* 51 +gzfilebuf::open(const char *name, 52 + std::ios_base::openmode mode) 53 +{ 54 + // Fail if file already open 55 + if (this->is_open()) 56 + return NULL; 57 + // Don't support simultaneous read/write access (yet) 58 + if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) 59 + return NULL; 60 + 61 + // Build mode string for gzopen and check it [27.8.1.3.2] 62 + char char_mode[6] = "\0\0\0\0\0"; 63 + if (!this->open_mode(mode, char_mode)) 64 + return NULL; 65 + 66 + // Attempt to open file 67 + if ((file = gzopen(name, char_mode)) == NULL) 68 + return NULL; 69 + 70 + // On success, allocate internal buffer and set flags 71 + this->enable_buffer(); 72 + io_mode = mode; 73 + own_fd = true; 74 + return this; 75 +} 76 + 77 +// Attach to gzipped file 78 +gzfilebuf* 79 +gzfilebuf::attach(int fd, 80 + std::ios_base::openmode mode) 81 +{ 82 + // Fail if file already open 83 + if (this->is_open()) 84 + return NULL; 85 + // Don't support simultaneous read/write access (yet) 86 + if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) 87 + return NULL; 88 + 89 + // Build mode string for gzdopen and check it [27.8.1.3.2] 90 + char char_mode[6] = "\0\0\0\0\0"; 91 + if (!this->open_mode(mode, char_mode)) 92 + return NULL; 93 + 94 + // Attempt to attach to file 95 + if ((file = gzdopen(fd, char_mode)) == NULL) 96 + return NULL; 97 + 98 + // On success, allocate internal buffer and set flags 99 + this->enable_buffer(); 100 + io_mode = mode; 101 + own_fd = false; 102 + return this; 103 +} 104 + 105 +// Close gzipped file 106 +gzfilebuf* 107 +gzfilebuf::close() 108 +{ 109 + // Fail immediately if no file is open 110 + if (!this->is_open()) 111 + return NULL; 112 + // Assume success 113 + gzfilebuf* retval = this; 114 + // Attempt to sync and close gzipped file 115 + if (this->sync() == -1) 116 + retval = NULL; 117 + if (gzclose(file) < 0) 118 + retval = NULL; 119 + // File is now gone anyway (postcondition [27.8.1.3.8]) 120 + file = NULL; 121 + own_fd = false; 122 + // Destroy internal buffer if it exists 123 + this->disable_buffer(); 124 + return retval; 125 +} 126 + 127 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 128 + 129 +// Convert int open mode to mode string 130 +bool 131 +gzfilebuf::open_mode(std::ios_base::openmode mode, 132 + char* c_mode) const 133 +{ 134 + bool testb = mode & std::ios_base::binary; 135 + bool testi = mode & std::ios_base::in; 136 + bool testo = mode & std::ios_base::out; 137 + bool testt = mode & std::ios_base::trunc; 138 + bool testa = mode & std::ios_base::app; 139 + 140 + // Check for valid flag combinations - see [27.8.1.3.2] (Table 92) 141 + // Original zfstream hardcoded the compression level to maximum here... 142 + // Double the time for less than 1% size improvement seems 143 + // excessive though - keeping it at the default level 144 + // To change back, just append "9" to the next three mode strings 145 + if (!testi && testo && !testt && !testa) 146 + strcpy(c_mode, "w"); 147 + if (!testi && testo && !testt && testa) 148 + strcpy(c_mode, "a"); 149 + if (!testi && testo && testt && !testa) 150 + strcpy(c_mode, "w"); 151 + if (testi && !testo && !testt && !testa) 152 + strcpy(c_mode, "r"); 153 + // No read/write mode yet 154 +// if (testi && testo && !testt && !testa) 155 +// strcpy(c_mode, "r+"); 156 +// if (testi && testo && testt && !testa) 157 +// strcpy(c_mode, "w+"); 158 + 159 + // Mode string should be empty for invalid combination of flags 160 + if (strlen(c_mode) == 0) 161 + return false; 162 + if (testb) 163 + strcat(c_mode, "b"); 164 + return true; 165 +} 166 + 167 +// Determine number of characters in internal get buffer 168 +std::streamsize 169 +gzfilebuf::showmanyc() 170 +{ 171 + // Calls to underflow will fail if file not opened for reading 172 + if (!this->is_open() || !(io_mode & std::ios_base::in)) 173 + return -1; 174 + // Make sure get area is in use 175 + if (this->gptr() && (this->gptr() < this->egptr())) 176 + return std::streamsize(this->egptr() - this->gptr()); 177 + else 178 + return 0; 179 +} 180 + 181 +// Fill get area from gzipped file 182 +gzfilebuf::int_type 183 +gzfilebuf::underflow() 184 +{ 185 + // If something is left in the get area by chance, return it 186 + // (this shouldn't normally happen, as underflow is only supposed 187 + // to be called when gptr >= egptr, but it serves as error check) 188 + if (this->gptr() && (this->gptr() < this->egptr())) 189 + return traits_type::to_int_type(*(this->gptr())); 190 + 191 + // If the file hasn't been opened for reading, produce error 192 + if (!this->is_open() || !(io_mode & std::ios_base::in)) 193 + return traits_type::eof(); 194 + 195 + // Attempt to fill internal buffer from gzipped file 196 + // (buffer must be guaranteed to exist...) 197 + int bytes_read = gzread(file, buffer, buffer_size); 198 + // Indicates error or EOF 199 + if (bytes_read <= 0) 200 + { 201 + // Reset get area 202 + this->setg(buffer, buffer, buffer); 203 + return traits_type::eof(); 204 + } 205 + // Make all bytes read from file available as get area 206 + this->setg(buffer, buffer, buffer + bytes_read); 207 + 208 + // Return next character in get area 209 + return traits_type::to_int_type(*(this->gptr())); 210 +} 211 + 212 +// Write put area to gzipped file 213 +gzfilebuf::int_type 214 +gzfilebuf::overflow(int_type c) 215 +{ 216 + // Determine whether put area is in use 217 + if (this->pbase()) 218 + { 219 + // Double-check pointer range 220 + if (this->pptr() > this->epptr() || this->pptr() < this->pbase()) 221 + return traits_type::eof(); 222 + // Add extra character to buffer if not EOF 223 + if (!traits_type::eq_int_type(c, traits_type::eof())) 224 + { 225 + *(this->pptr()) = traits_type::to_char_type(c); 226 + this->pbump(1); 227 + } 228 + // Number of characters to write to file 229 + int bytes_to_write = this->pptr() - this->pbase(); 230 + // Overflow doesn't fail if nothing is to be written 231 + if (bytes_to_write > 0) 232 + { 233 + // If the file hasn't been opened for writing, produce error 234 + if (!this->is_open() || !(io_mode & std::ios_base::out)) 235 + return traits_type::eof(); 236 + // If gzipped file won't accept all bytes written to it, fail 237 + if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write) 238 + return traits_type::eof(); 239 + // Reset next pointer to point to pbase on success 240 + this->pbump(-bytes_to_write); 241 + } 242 + } 243 + // Write extra character to file if not EOF 244 + else if (!traits_type::eq_int_type(c, traits_type::eof())) 245 + { 246 + // If the file hasn't been opened for writing, produce error 247 + if (!this->is_open() || !(io_mode & std::ios_base::out)) 248 + return traits_type::eof(); 249 + // Impromptu char buffer (allows "unbuffered" output) 250 + char_type last_char = traits_type::to_char_type(c); 251 + // If gzipped file won't accept this character, fail 252 + if (gzwrite(file, &last_char, 1) != 1) 253 + return traits_type::eof(); 254 + } 255 + 256 + // If you got here, you have succeeded (even if c was EOF) 257 + // The return value should therefore be non-EOF 258 + if (traits_type::eq_int_type(c, traits_type::eof())) 259 + return traits_type::not_eof(c); 260 + else 261 + return c; 262 +} 263 + 264 +// Assign new buffer 265 +std::streambuf* 266 +gzfilebuf::setbuf(char_type* p, 267 + std::streamsize n) 268 +{ 269 + // First make sure stuff is sync'ed, for safety 270 + if (this->sync() == -1) 271 + return NULL; 272 + // If buffering is turned off on purpose via setbuf(0,0), still allocate one... 273 + // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at 274 + // least a buffer of size 1 (very inefficient though, therefore make it bigger?) 275 + // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems) 276 + if (!p || !n) 277 + { 278 + // Replace existing buffer (if any) with small internal buffer 279 + this->disable_buffer(); 280 + buffer = NULL; 281 + buffer_size = 0; 282 + own_buffer = true; 283 + this->enable_buffer(); 284 + } 285 + else 286 + { 287 + // Replace existing buffer (if any) with external buffer 288 + this->disable_buffer(); 289 + buffer = p; 290 + buffer_size = n; 291 + own_buffer = false; 292 + this->enable_buffer(); 293 + } 294 + return this; 295 +} 296 + 297 +// Write put area to gzipped file (i.e. ensures that put area is empty) 298 +int 299 +gzfilebuf::sync() 300 +{ 301 + return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0; 302 +} 303 + 304 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 305 + 306 +// Allocate internal buffer 307 +void 308 +gzfilebuf::enable_buffer() 309 +{ 310 + // If internal buffer required, allocate one 311 + if (own_buffer && !buffer) 312 + { 313 + // Check for buffered vs. "unbuffered" 314 + if (buffer_size > 0) 315 + { 316 + // Allocate internal buffer 317 + buffer = new char_type[buffer_size]; 318 + // Get area starts empty and will be expanded by underflow as need arises 319 + this->setg(buffer, buffer, buffer); 320 + // Setup entire internal buffer as put area. 321 + // The one-past-end pointer actually points to the last element of the buffer, 322 + // so that overflow(c) can safely add the extra character c to the sequence. 323 + // These pointers remain in place for the duration of the buffer 324 + this->setp(buffer, buffer + buffer_size - 1); 325 + } 326 + else 327 + { 328 + // Even in "unbuffered" case, (small?) get buffer is still required 329 + buffer_size = SMALLBUFSIZE; 330 + buffer = new char_type[buffer_size]; 331 + this->setg(buffer, buffer, buffer); 332 + // "Unbuffered" means no put buffer 333 + this->setp(0, 0); 334 + } 335 + } 336 + else 337 + { 338 + // If buffer already allocated, reset buffer pointers just to make sure no 339 + // stale chars are lying around 340 + this->setg(buffer, buffer, buffer); 341 + this->setp(buffer, buffer + buffer_size - 1); 342 + } 343 +} 344 + 345 +// Destroy internal buffer 346 +void 347 +gzfilebuf::disable_buffer() 348 +{ 349 + // If internal buffer exists, deallocate it 350 + if (own_buffer && buffer) 351 + { 352 + // Preserve unbuffered status by zeroing size 353 + if (!this->pbase()) 354 + buffer_size = 0; 355 + delete[] buffer; 356 + buffer = NULL; 357 + this->setg(0, 0, 0); 358 + this->setp(0, 0); 359 + } 360 + else 361 + { 362 + // Reset buffer pointers to initial state if external buffer exists 363 + this->setg(buffer, buffer, buffer); 364 + if (buffer) 365 + this->setp(buffer, buffer + buffer_size - 1); 366 + else 367 + this->setp(0, 0); 368 + } 369 +} 370 + 371 +/*****************************************************************************/ 372 + 373 +// Default constructor initializes stream buffer 374 +gzifstream::gzifstream() 375 +: std::istream(NULL), sb() 376 +{ this->init(&sb); } 377 + 378 +// Initialize stream buffer and open file 379 +gzifstream::gzifstream(const char* name, 380 + std::ios_base::openmode mode) 381 +: std::istream(NULL), sb() 382 +{ 383 + this->init(&sb); 384 + this->open(name, mode); 385 +} 386 + 387 +// Initialize stream buffer and attach to file 388 +gzifstream::gzifstream(int fd, 389 + std::ios_base::openmode mode) 390 +: std::istream(NULL), sb() 391 +{ 392 + this->init(&sb); 393 + this->attach(fd, mode); 394 +} 395 + 396 +// Open file and go into fail() state if unsuccessful 397 +void 398 +gzifstream::open(const char* name, 399 + std::ios_base::openmode mode) 400 +{ 401 + if (!sb.open(name, mode | std::ios_base::in)) 402 + this->setstate(std::ios_base::failbit); 403 + else 404 + this->clear(); 405 +} 406 + 407 +// Attach to file and go into fail() state if unsuccessful 408 +void 409 +gzifstream::attach(int fd, 410 + std::ios_base::openmode mode) 411 +{ 412 + if (!sb.attach(fd, mode | std::ios_base::in)) 413 + this->setstate(std::ios_base::failbit); 414 + else 415 + this->clear(); 416 +} 417 + 418 +// Close file 419 +void 420 +gzifstream::close() 421 +{ 422 + if (!sb.close()) 423 + this->setstate(std::ios_base::failbit); 424 +} 425 + 426 +/*****************************************************************************/ 427 + 428 +// Default constructor initializes stream buffer 429 +gzofstream::gzofstream() 430 +: std::ostream(NULL), sb() 431 +{ this->init(&sb); } 432 + 433 +// Initialize stream buffer and open file 434 +gzofstream::gzofstream(const char* name, 435 + std::ios_base::openmode mode) 436 +: std::ostream(NULL), sb() 437 +{ 438 + this->init(&sb); 439 + this->open(name, mode); 440 +} 441 + 442 +// Initialize stream buffer and attach to file 443 +gzofstream::gzofstream(int fd, 444 + std::ios_base::openmode mode) 445 +: std::ostream(NULL), sb() 446 +{ 447 + this->init(&sb); 448 + this->attach(fd, mode); 449 +} 450 + 451 +// Open file and go into fail() state if unsuccessful 452 +void 453 +gzofstream::open(const char* name, 454 + std::ios_base::openmode mode) 455 +{ 456 + if (!sb.open(name, mode | std::ios_base::out)) 457 + this->setstate(std::ios_base::failbit); 458 + else 459 + this->clear(); 460 +} 461 + 462 +// Attach to file and go into fail() state if unsuccessful 463 +void 464 +gzofstream::attach(int fd, 465 + std::ios_base::openmode mode) 466 +{ 467 + if (!sb.attach(fd, mode | std::ios_base::out)) 468 + this->setstate(std::ios_base::failbit); 469 + else 470 + this->clear(); 471 +} 472 + 473 +// Close file 474 +void 475 +gzofstream::close() 476 +{ 477 + if (!sb.close()) 478 + this->setstate(std::ios_base::failbit); 479 +}
Added compat/zlib/contrib/iostream3/zfstream.h.
1 +/* 2 + * A C++ I/O streams interface to the zlib gz* functions 3 + * 4 + * by Ludwig Schwardt <schwardt@sun.ac.za> 5 + * original version by Kevin Ruland <kevin@rodin.wustl.edu> 6 + * 7 + * This version is standard-compliant and compatible with gcc 3.x. 8 + */ 9 + 10 +#ifndef ZFSTREAM_H 11 +#define ZFSTREAM_H 12 + 13 +#include <istream> // not iostream, since we don't need cin/cout 14 +#include <ostream> 15 +#include "zlib.h" 16 + 17 +/*****************************************************************************/ 18 + 19 +/** 20 + * @brief Gzipped file stream buffer class. 21 + * 22 + * This class implements basic_filebuf for gzipped files. It doesn't yet support 23 + * seeking (allowed by zlib but slow/limited), putback and read/write access 24 + * (tricky). Otherwise, it attempts to be a drop-in replacement for the standard 25 + * file streambuf. 26 +*/ 27 +class gzfilebuf : public std::streambuf 28 +{ 29 +public: 30 + // Default constructor. 31 + gzfilebuf(); 32 + 33 + // Destructor. 34 + virtual 35 + ~gzfilebuf(); 36 + 37 + /** 38 + * @brief Set compression level and strategy on the fly. 39 + * @param comp_level Compression level (see zlib.h for allowed values) 40 + * @param comp_strategy Compression strategy (see zlib.h for allowed values) 41 + * @return Z_OK on success, Z_STREAM_ERROR otherwise. 42 + * 43 + * Unfortunately, these parameters cannot be modified separately, as the 44 + * previous zfstream version assumed. Since the strategy is seldom changed, 45 + * it can default and setcompression(level) then becomes like the old 46 + * setcompressionlevel(level). 47 + */ 48 + int 49 + setcompression(int comp_level, 50 + int comp_strategy = Z_DEFAULT_STRATEGY); 51 + 52 + /** 53 + * @brief Check if file is open. 54 + * @return True if file is open. 55 + */ 56 + bool 57 + is_open() const { return (file != NULL); } 58 + 59 + /** 60 + * @brief Open gzipped file. 61 + * @param name File name. 62 + * @param mode Open mode flags. 63 + * @return @c this on success, NULL on failure. 64 + */ 65 + gzfilebuf* 66 + open(const char* name, 67 + std::ios_base::openmode mode); 68 + 69 + /** 70 + * @brief Attach to already open gzipped file. 71 + * @param fd File descriptor. 72 + * @param mode Open mode flags. 73 + * @return @c this on success, NULL on failure. 74 + */ 75 + gzfilebuf* 76 + attach(int fd, 77 + std::ios_base::openmode mode); 78 + 79 + /** 80 + * @brief Close gzipped file. 81 + * @return @c this on success, NULL on failure. 82 + */ 83 + gzfilebuf* 84 + close(); 85 + 86 +protected: 87 + /** 88 + * @brief Convert ios open mode int to mode string used by zlib. 89 + * @return True if valid mode flag combination. 90 + */ 91 + bool 92 + open_mode(std::ios_base::openmode mode, 93 + char* c_mode) const; 94 + 95 + /** 96 + * @brief Number of characters available in stream buffer. 97 + * @return Number of characters. 98 + * 99 + * This indicates number of characters in get area of stream buffer. 100 + * These characters can be read without accessing the gzipped file. 101 + */ 102 + virtual std::streamsize 103 + showmanyc(); 104 + 105 + /** 106 + * @brief Fill get area from gzipped file. 107 + * @return First character in get area on success, EOF on error. 108 + * 109 + * This actually reads characters from gzipped file to stream 110 + * buffer. Always buffered. 111 + */ 112 + virtual int_type 113 + underflow(); 114 + 115 + /** 116 + * @brief Write put area to gzipped file. 117 + * @param c Extra character to add to buffer contents. 118 + * @return Non-EOF on success, EOF on error. 119 + * 120 + * This actually writes characters in stream buffer to 121 + * gzipped file. With unbuffered output this is done one 122 + * character at a time. 123 + */ 124 + virtual int_type 125 + overflow(int_type c = traits_type::eof()); 126 + 127 + /** 128 + * @brief Installs external stream buffer. 129 + * @param p Pointer to char buffer. 130 + * @param n Size of external buffer. 131 + * @return @c this on success, NULL on failure. 132 + * 133 + * Call setbuf(0,0) to enable unbuffered output. 134 + */ 135 + virtual std::streambuf* 136 + setbuf(char_type* p, 137 + std::streamsize n); 138 + 139 + /** 140 + * @brief Flush stream buffer to file. 141 + * @return 0 on success, -1 on error. 142 + * 143 + * This calls underflow(EOF) to do the job. 144 + */ 145 + virtual int 146 + sync(); 147 + 148 +// 149 +// Some future enhancements 150 +// 151 +// virtual int_type uflow(); 152 +// virtual int_type pbackfail(int_type c = traits_type::eof()); 153 +// virtual pos_type 154 +// seekoff(off_type off, 155 +// std::ios_base::seekdir way, 156 +// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); 157 +// virtual pos_type 158 +// seekpos(pos_type sp, 159 +// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); 160 + 161 +private: 162 + /** 163 + * @brief Allocate internal buffer. 164 + * 165 + * This function is safe to call multiple times. It will ensure 166 + * that a proper internal buffer exists if it is required. If the 167 + * buffer already exists or is external, the buffer pointers will be 168 + * reset to their original state. 169 + */ 170 + void 171 + enable_buffer(); 172 + 173 + /** 174 + * @brief Destroy internal buffer. 175 + * 176 + * This function is safe to call multiple times. It will ensure 177 + * that the internal buffer is deallocated if it exists. In any 178 + * case, it will also reset the buffer pointers. 179 + */ 180 + void 181 + disable_buffer(); 182 + 183 + /** 184 + * Underlying file pointer. 185 + */ 186 + gzFile file; 187 + 188 + /** 189 + * Mode in which file was opened. 190 + */ 191 + std::ios_base::openmode io_mode; 192 + 193 + /** 194 + * @brief True if this object owns file descriptor. 195 + * 196 + * This makes the class responsible for closing the file 197 + * upon destruction. 198 + */ 199 + bool own_fd; 200 + 201 + /** 202 + * @brief Stream buffer. 203 + * 204 + * For simplicity this remains allocated on the free store for the 205 + * entire life span of the gzfilebuf object, unless replaced by setbuf. 206 + */ 207 + char_type* buffer; 208 + 209 + /** 210 + * @brief Stream buffer size. 211 + * 212 + * Defaults to system default buffer size (typically 8192 bytes). 213 + * Modified by setbuf. 214 + */ 215 + std::streamsize buffer_size; 216 + 217 + /** 218 + * @brief True if this object owns stream buffer. 219 + * 220 + * This makes the class responsible for deleting the buffer 221 + * upon destruction. 222 + */ 223 + bool own_buffer; 224 +}; 225 + 226 +/*****************************************************************************/ 227 + 228 +/** 229 + * @brief Gzipped file input stream class. 230 + * 231 + * This class implements ifstream for gzipped files. Seeking and putback 232 + * is not supported yet. 233 +*/ 234 +class gzifstream : public std::istream 235 +{ 236 +public: 237 + // Default constructor 238 + gzifstream(); 239 + 240 + /** 241 + * @brief Construct stream on gzipped file to be opened. 242 + * @param name File name. 243 + * @param mode Open mode flags (forced to contain ios::in). 244 + */ 245 + explicit 246 + gzifstream(const char* name, 247 + std::ios_base::openmode mode = std::ios_base::in); 248 + 249 + /** 250 + * @brief Construct stream on already open gzipped file. 251 + * @param fd File descriptor. 252 + * @param mode Open mode flags (forced to contain ios::in). 253 + */ 254 + explicit 255 + gzifstream(int fd, 256 + std::ios_base::openmode mode = std::ios_base::in); 257 + 258 + /** 259 + * Obtain underlying stream buffer. 260 + */ 261 + gzfilebuf* 262 + rdbuf() const 263 + { return const_cast<gzfilebuf*>(&sb); } 264 + 265 + /** 266 + * @brief Check if file is open. 267 + * @return True if file is open. 268 + */ 269 + bool 270 + is_open() { return sb.is_open(); } 271 + 272 + /** 273 + * @brief Open gzipped file. 274 + * @param name File name. 275 + * @param mode Open mode flags (forced to contain ios::in). 276 + * 277 + * Stream will be in state good() if file opens successfully; 278 + * otherwise in state fail(). This differs from the behavior of 279 + * ifstream, which never sets the state to good() and therefore 280 + * won't allow you to reuse the stream for a second file unless 281 + * you manually clear() the state. The choice is a matter of 282 + * convenience. 283 + */ 284 + void 285 + open(const char* name, 286 + std::ios_base::openmode mode = std::ios_base::in); 287 + 288 + /** 289 + * @brief Attach to already open gzipped file. 290 + * @param fd File descriptor. 291 + * @param mode Open mode flags (forced to contain ios::in). 292 + * 293 + * Stream will be in state good() if attach succeeded; otherwise 294 + * in state fail(). 295 + */ 296 + void 297 + attach(int fd, 298 + std::ios_base::openmode mode = std::ios_base::in); 299 + 300 + /** 301 + * @brief Close gzipped file. 302 + * 303 + * Stream will be in state fail() if close failed. 304 + */ 305 + void 306 + close(); 307 + 308 +private: 309 + /** 310 + * Underlying stream buffer. 311 + */ 312 + gzfilebuf sb; 313 +}; 314 + 315 +/*****************************************************************************/ 316 + 317 +/** 318 + * @brief Gzipped file output stream class. 319 + * 320 + * This class implements ofstream for gzipped files. Seeking and putback 321 + * is not supported yet. 322 +*/ 323 +class gzofstream : public std::ostream 324 +{ 325 +public: 326 + // Default constructor 327 + gzofstream(); 328 + 329 + /** 330 + * @brief Construct stream on gzipped file to be opened. 331 + * @param name File name. 332 + * @param mode Open mode flags (forced to contain ios::out). 333 + */ 334 + explicit 335 + gzofstream(const char* name, 336 + std::ios_base::openmode mode = std::ios_base::out); 337 + 338 + /** 339 + * @brief Construct stream on already open gzipped file. 340 + * @param fd File descriptor. 341 + * @param mode Open mode flags (forced to contain ios::out). 342 + */ 343 + explicit 344 + gzofstream(int fd, 345 + std::ios_base::openmode mode = std::ios_base::out); 346 + 347 + /** 348 + * Obtain underlying stream buffer. 349 + */ 350 + gzfilebuf* 351 + rdbuf() const 352 + { return const_cast<gzfilebuf*>(&sb); } 353 + 354 + /** 355 + * @brief Check if file is open. 356 + * @return True if file is open. 357 + */ 358 + bool 359 + is_open() { return sb.is_open(); } 360 + 361 + /** 362 + * @brief Open gzipped file. 363 + * @param name File name. 364 + * @param mode Open mode flags (forced to contain ios::out). 365 + * 366 + * Stream will be in state good() if file opens successfully; 367 + * otherwise in state fail(). This differs from the behavior of 368 + * ofstream, which never sets the state to good() and therefore 369 + * won't allow you to reuse the stream for a second file unless 370 + * you manually clear() the state. The choice is a matter of 371 + * convenience. 372 + */ 373 + void 374 + open(const char* name, 375 + std::ios_base::openmode mode = std::ios_base::out); 376 + 377 + /** 378 + * @brief Attach to already open gzipped file. 379 + * @param fd File descriptor. 380 + * @param mode Open mode flags (forced to contain ios::out). 381 + * 382 + * Stream will be in state good() if attach succeeded; otherwise 383 + * in state fail(). 384 + */ 385 + void 386 + attach(int fd, 387 + std::ios_base::openmode mode = std::ios_base::out); 388 + 389 + /** 390 + * @brief Close gzipped file. 391 + * 392 + * Stream will be in state fail() if close failed. 393 + */ 394 + void 395 + close(); 396 + 397 +private: 398 + /** 399 + * Underlying stream buffer. 400 + */ 401 + gzfilebuf sb; 402 +}; 403 + 404 +/*****************************************************************************/ 405 + 406 +/** 407 + * @brief Gzipped file output stream manipulator class. 408 + * 409 + * This class defines a two-argument manipulator for gzofstream. It is used 410 + * as base for the setcompression(int,int) manipulator. 411 +*/ 412 +template<typename T1, typename T2> 413 + class gzomanip2 414 + { 415 + public: 416 + // Allows insertor to peek at internals 417 + template <typename Ta, typename Tb> 418 + friend gzofstream& 419 + operator<<(gzofstream&, 420 + const gzomanip2<Ta,Tb>&); 421 + 422 + // Constructor 423 + gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2), 424 + T1 v1, 425 + T2 v2); 426 + private: 427 + // Underlying manipulator function 428 + gzofstream& 429 + (*func)(gzofstream&, T1, T2); 430 + 431 + // Arguments for manipulator function 432 + T1 val1; 433 + T2 val2; 434 + }; 435 + 436 +/*****************************************************************************/ 437 + 438 +// Manipulator function thunks through to stream buffer 439 +inline gzofstream& 440 +setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY) 441 +{ 442 + (gzs.rdbuf())->setcompression(l, s); 443 + return gzs; 444 +} 445 + 446 +// Manipulator constructor stores arguments 447 +template<typename T1, typename T2> 448 + inline 449 + gzomanip2<T1,T2>::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2), 450 + T1 v1, 451 + T2 v2) 452 + : func(f), val1(v1), val2(v2) 453 + { } 454 + 455 +// Insertor applies underlying manipulator function to stream 456 +template<typename T1, typename T2> 457 + inline gzofstream& 458 + operator<<(gzofstream& s, const gzomanip2<T1,T2>& m) 459 + { return (*m.func)(s, m.val1, m.val2); } 460 + 461 +// Insert this onto stream to simplify setting of compression level 462 +inline gzomanip2<int,int> 463 +setcompression(int l, int s = Z_DEFAULT_STRATEGY) 464 +{ return gzomanip2<int,int>(&setcompression, l, s); } 465 + 466 +#endif // ZFSTREAM_H
Added compat/zlib/contrib/masmx64/bld_ml64.bat.
1 +ml64.exe /Flinffasx64 /c /Zi inffasx64.asm 2 +ml64.exe /Flgvmat64 /c /Zi gvmat64.asm
Added compat/zlib/contrib/masmx64/gvmat64.asm.
1 +;uInt longest_match_x64( 2 +; deflate_state *s, 3 +; IPos cur_match); /* current match */ 4 + 5 +; gvmat64.asm -- Asm portion of the optimized longest_match for 32 bits x86_64 6 +; (AMD64 on Athlon 64, Opteron, Phenom 7 +; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) 8 +; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. 9 +; 10 +; File written by Gilles Vollant, by converting to assembly the longest_match 11 +; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. 12 +; 13 +; and by taking inspiration on asm686 with masm, optimised assembly code 14 +; from Brian Raiter, written 1998 15 +; 16 +; This software is provided 'as-is', without any express or implied 17 +; warranty. In no event will the authors be held liable for any damages 18 +; arising from the use of this software. 19 +; 20 +; Permission is granted to anyone to use this software for any purpose, 21 +; including commercial applications, and to alter it and redistribute it 22 +; freely, subject to the following restrictions: 23 +; 24 +; 1. The origin of this software must not be misrepresented; you must not 25 +; claim that you wrote the original software. If you use this software 26 +; in a product, an acknowledgment in the product documentation would be 27 +; appreciated but is not required. 28 +; 2. Altered source versions must be plainly marked as such, and must not be 29 +; misrepresented as being the original software 30 +; 3. This notice may not be removed or altered from any source distribution. 31 +; 32 +; 33 +; 34 +; http://www.zlib.net 35 +; http://www.winimage.com/zLibDll 36 +; http://www.muppetlabs.com/~breadbox/software/assembly.html 37 +; 38 +; to compile this file for infozip Zip, I use option: 39 +; ml64.exe /Flgvmat64 /c /Zi /DINFOZIP gvmat64.asm 40 +; 41 +; to compile this file for zLib, I use option: 42 +; ml64.exe /Flgvmat64 /c /Zi gvmat64.asm 43 +; Be carrefull to adapt zlib1222add below to your version of zLib 44 +; (if you use a version of zLib before 1.0.4 or after 1.2.2.2, change 45 +; value of zlib1222add later) 46 +; 47 +; This file compile with Microsoft Macro Assembler (x64) for AMD64 48 +; 49 +; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK 50 +; 51 +; (you can get Windows WDK with ml64 for AMD64 from 52 +; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) 53 +; 54 + 55 + 56 +;uInt longest_match(s, cur_match) 57 +; deflate_state *s; 58 +; IPos cur_match; /* current match */ 59 +.code 60 +longest_match PROC 61 + 62 + 63 +;LocalVarsSize equ 88 64 + LocalVarsSize equ 72 65 + 66 +; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 67 +; free register : r14,r15 68 +; register can be saved : rsp 69 + 70 + chainlenwmask equ rsp + 8 - LocalVarsSize ; high word: current chain len 71 + ; low word: s->wmask 72 +;window equ rsp + xx - LocalVarsSize ; local copy of s->window ; stored in r10 73 +;windowbestlen equ rsp + xx - LocalVarsSize ; s->window + bestlen , use r10+r11 74 +;scanstart equ rsp + xx - LocalVarsSize ; first two bytes of string ; stored in r12w 75 +;scanend equ rsp + xx - LocalVarsSize ; last two bytes of string use ebx 76 +;scanalign equ rsp + xx - LocalVarsSize ; dword-misalignment of string r13 77 +;bestlen equ rsp + xx - LocalVarsSize ; size of best match so far -> r11d 78 +;scan equ rsp + xx - LocalVarsSize ; ptr to string wanting match -> r9 79 +IFDEF INFOZIP 80 +ELSE 81 + nicematch equ (rsp + 16 - LocalVarsSize) ; a good enough match size 82 +ENDIF 83 + 84 +save_rdi equ rsp + 24 - LocalVarsSize 85 +save_rsi equ rsp + 32 - LocalVarsSize 86 +save_rbx equ rsp + 40 - LocalVarsSize 87 +save_rbp equ rsp + 48 - LocalVarsSize 88 +save_r12 equ rsp + 56 - LocalVarsSize 89 +save_r13 equ rsp + 64 - LocalVarsSize 90 +;save_r14 equ rsp + 72 - LocalVarsSize 91 +;save_r15 equ rsp + 80 - LocalVarsSize 92 + 93 + 94 +; summary of register usage 95 +; scanend ebx 96 +; scanendw bx 97 +; chainlenwmask edx 98 +; curmatch rsi 99 +; curmatchd esi 100 +; windowbestlen r8 101 +; scanalign r9 102 +; scanalignd r9d 103 +; window r10 104 +; bestlen r11 105 +; bestlend r11d 106 +; scanstart r12d 107 +; scanstartw r12w 108 +; scan r13 109 +; nicematch r14d 110 +; limit r15 111 +; limitd r15d 112 +; prev rcx 113 + 114 +; all the +4 offsets are due to the addition of pending_buf_size (in zlib 115 +; in the deflate_state structure since the asm code was first written 116 +; (if you compile with zlib 1.0.4 or older, remove the +4). 117 +; Note : these value are good with a 8 bytes boundary pack structure 118 + 119 + 120 + MAX_MATCH equ 258 121 + MIN_MATCH equ 3 122 + MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) 123 + 124 + 125 +;;; Offsets for fields in the deflate_state structure. These numbers 126 +;;; are calculated from the definition of deflate_state, with the 127 +;;; assumption that the compiler will dword-align the fields. (Thus, 128 +;;; changing the definition of deflate_state could easily cause this 129 +;;; program to crash horribly, without so much as a warning at 130 +;;; compile time. Sigh.) 131 + 132 +; all the +zlib1222add offsets are due to the addition of fields 133 +; in zlib in the deflate_state structure since the asm code was first written 134 +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). 135 +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). 136 +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). 137 + 138 + 139 +IFDEF INFOZIP 140 + 141 +_DATA SEGMENT 142 +COMM window_size:DWORD 143 +; WMask ; 7fff 144 +COMM window:BYTE:010040H 145 +COMM prev:WORD:08000H 146 +; MatchLen : unused 147 +; PrevMatch : unused 148 +COMM strstart:DWORD 149 +COMM match_start:DWORD 150 +; Lookahead : ignore 151 +COMM prev_length:DWORD ; PrevLen 152 +COMM max_chain_length:DWORD 153 +COMM good_match:DWORD 154 +COMM nice_match:DWORD 155 +prev_ad equ OFFSET prev 156 +window_ad equ OFFSET window 157 +nicematch equ nice_match 158 +_DATA ENDS 159 +WMask equ 07fffh 160 + 161 +ELSE 162 + 163 + IFNDEF zlib1222add 164 + zlib1222add equ 8 165 + ENDIF 166 +dsWSize equ 56+zlib1222add+(zlib1222add/2) 167 +dsWMask equ 64+zlib1222add+(zlib1222add/2) 168 +dsWindow equ 72+zlib1222add 169 +dsPrev equ 88+zlib1222add 170 +dsMatchLen equ 128+zlib1222add 171 +dsPrevMatch equ 132+zlib1222add 172 +dsStrStart equ 140+zlib1222add 173 +dsMatchStart equ 144+zlib1222add 174 +dsLookahead equ 148+zlib1222add 175 +dsPrevLen equ 152+zlib1222add 176 +dsMaxChainLen equ 156+zlib1222add 177 +dsGoodMatch equ 172+zlib1222add 178 +dsNiceMatch equ 176+zlib1222add 179 + 180 +window_size equ [ rcx + dsWSize] 181 +WMask equ [ rcx + dsWMask] 182 +window_ad equ [ rcx + dsWindow] 183 +prev_ad equ [ rcx + dsPrev] 184 +strstart equ [ rcx + dsStrStart] 185 +match_start equ [ rcx + dsMatchStart] 186 +Lookahead equ [ rcx + dsLookahead] ; 0ffffffffh on infozip 187 +prev_length equ [ rcx + dsPrevLen] 188 +max_chain_length equ [ rcx + dsMaxChainLen] 189 +good_match equ [ rcx + dsGoodMatch] 190 +nice_match equ [ rcx + dsNiceMatch] 191 +ENDIF 192 + 193 +; parameter 1 in r8(deflate state s), param 2 in rdx (cur match) 194 + 195 +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and 196 +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp 197 +; 198 +; All registers must be preserved across the call, except for 199 +; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. 200 + 201 + 202 + 203 +;;; Save registers that the compiler may be using, and adjust esp to 204 +;;; make room for our stack frame. 205 + 206 + 207 +;;; Retrieve the function arguments. r8d will hold cur_match 208 +;;; throughout the entire function. edx will hold the pointer to the 209 +;;; deflate_state structure during the function's setup (before 210 +;;; entering the main loop. 211 + 212 +; parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) 213 + 214 +; this clear high 32 bits of r8, which can be garbage in both r8 and rdx 215 + 216 + mov [save_rdi],rdi 217 + mov [save_rsi],rsi 218 + mov [save_rbx],rbx 219 + mov [save_rbp],rbp 220 +IFDEF INFOZIP 221 + mov r8d,ecx 222 +ELSE 223 + mov r8d,edx 224 +ENDIF 225 + mov [save_r12],r12 226 + mov [save_r13],r13 227 +; mov [save_r14],r14 228 +; mov [save_r15],r15 229 + 230 + 231 +;;; uInt wmask = s->w_mask; 232 +;;; unsigned chain_length = s->max_chain_length; 233 +;;; if (s->prev_length >= s->good_match) { 234 +;;; chain_length >>= 2; 235 +;;; } 236 + 237 + mov edi, prev_length 238 + mov esi, good_match 239 + mov eax, WMask 240 + mov ebx, max_chain_length 241 + cmp edi, esi 242 + jl LastMatchGood 243 + shr ebx, 2 244 +LastMatchGood: 245 + 246 +;;; chainlen is decremented once beforehand so that the function can 247 +;;; use the sign flag instead of the zero flag for the exit test. 248 +;;; It is then shifted into the high word, to make room for the wmask 249 +;;; value, which it will always accompany. 250 + 251 + dec ebx 252 + shl ebx, 16 253 + or ebx, eax 254 + 255 +;;; on zlib only 256 +;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; 257 + 258 +IFDEF INFOZIP 259 + mov [chainlenwmask], ebx 260 +; on infozip nice_match = [nice_match] 261 +ELSE 262 + mov eax, nice_match 263 + mov [chainlenwmask], ebx 264 + mov r10d, Lookahead 265 + cmp r10d, eax 266 + cmovnl r10d, eax 267 + mov [nicematch],r10d 268 +ENDIF 269 + 270 +;;; register Bytef *scan = s->window + s->strstart; 271 + mov r10, window_ad 272 + mov ebp, strstart 273 + lea r13, [r10 + rbp] 274 + 275 +;;; Determine how many bytes the scan ptr is off from being 276 +;;; dword-aligned. 277 + 278 + mov r9,r13 279 + neg r13 280 + and r13,3 281 + 282 +;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 283 +;;; s->strstart - (IPos)MAX_DIST(s) : NIL; 284 +IFDEF INFOZIP 285 + mov eax,07efah ; MAX_DIST = (WSIZE-MIN_LOOKAHEAD) (0x8000-(3+8+1)) 286 +ELSE 287 + mov eax, window_size 288 + sub eax, MIN_LOOKAHEAD 289 +ENDIF 290 + xor edi,edi 291 + sub ebp, eax 292 + 293 + mov r11d, prev_length 294 + 295 + cmovng ebp,edi 296 + 297 +;;; int best_len = s->prev_length; 298 + 299 + 300 +;;; Store the sum of s->window + best_len in esi locally, and in esi. 301 + 302 + lea rsi,[r10+r11] 303 + 304 +;;; register ush scan_start = *(ushf*)scan; 305 +;;; register ush scan_end = *(ushf*)(scan+best_len-1); 306 +;;; Posf *prev = s->prev; 307 + 308 + movzx r12d,word ptr [r9] 309 + movzx ebx, word ptr [r9 + r11 - 1] 310 + 311 + mov rdi, prev_ad 312 + 313 +;;; Jump into the main loop. 314 + 315 + mov edx, [chainlenwmask] 316 + 317 + cmp bx,word ptr [rsi + r8 - 1] 318 + jz LookupLoopIsZero 319 + 320 +LookupLoop1: 321 + and r8d, edx 322 + 323 + movzx r8d, word ptr [rdi + r8*2] 324 + cmp r8d, ebp 325 + jbe LeaveNow 326 + sub edx, 00010000h 327 + js LeaveNow 328 + 329 +LoopEntry1: 330 + cmp bx,word ptr [rsi + r8 - 1] 331 + jz LookupLoopIsZero 332 + 333 +LookupLoop2: 334 + and r8d, edx 335 + 336 + movzx r8d, word ptr [rdi + r8*2] 337 + cmp r8d, ebp 338 + jbe LeaveNow 339 + sub edx, 00010000h 340 + js LeaveNow 341 + 342 +LoopEntry2: 343 + cmp bx,word ptr [rsi + r8 - 1] 344 + jz LookupLoopIsZero 345 + 346 +LookupLoop4: 347 + and r8d, edx 348 + 349 + movzx r8d, word ptr [rdi + r8*2] 350 + cmp r8d, ebp 351 + jbe LeaveNow 352 + sub edx, 00010000h 353 + js LeaveNow 354 + 355 +LoopEntry4: 356 + 357 + cmp bx,word ptr [rsi + r8 - 1] 358 + jnz LookupLoop1 359 + jmp LookupLoopIsZero 360 + 361 + 362 +;;; do { 363 +;;; match = s->window + cur_match; 364 +;;; if (*(ushf*)(match+best_len-1) != scan_end || 365 +;;; *(ushf*)match != scan_start) continue; 366 +;;; [...] 367 +;;; } while ((cur_match = prev[cur_match & wmask]) > limit 368 +;;; && --chain_length != 0); 369 +;;; 370 +;;; Here is the inner loop of the function. The function will spend the 371 +;;; majority of its time in this loop, and majority of that time will 372 +;;; be spent in the first ten instructions. 373 +;;; 374 +;;; Within this loop: 375 +;;; ebx = scanend 376 +;;; r8d = curmatch 377 +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) 378 +;;; esi = windowbestlen - i.e., (window + bestlen) 379 +;;; edi = prev 380 +;;; ebp = limit 381 + 382 +LookupLoop: 383 + and r8d, edx 384 + 385 + movzx r8d, word ptr [rdi + r8*2] 386 + cmp r8d, ebp 387 + jbe LeaveNow 388 + sub edx, 00010000h 389 + js LeaveNow 390 + 391 +LoopEntry: 392 + 393 + cmp bx,word ptr [rsi + r8 - 1] 394 + jnz LookupLoop1 395 +LookupLoopIsZero: 396 + cmp r12w, word ptr [r10 + r8] 397 + jnz LookupLoop1 398 + 399 + 400 +;;; Store the current value of chainlen. 401 + mov [chainlenwmask], edx 402 + 403 +;;; Point edi to the string under scrutiny, and esi to the string we 404 +;;; are hoping to match it up with. In actuality, esi and edi are 405 +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is 406 +;;; initialized to -(MAX_MATCH_8 - scanalign). 407 + 408 + lea rsi,[r8+r10] 409 + mov rdx, 0fffffffffffffef8h; -(MAX_MATCH_8) 410 + lea rsi, [rsi + r13 + 0108h] ;MAX_MATCH_8] 411 + lea rdi, [r9 + r13 + 0108h] ;MAX_MATCH_8] 412 + 413 + prefetcht1 [rsi+rdx] 414 + prefetcht1 [rdi+rdx] 415 + 416 + 417 +;;; Test the strings for equality, 8 bytes at a time. At the end, 418 +;;; adjust rdx so that it is offset to the exact byte that mismatched. 419 +;;; 420 +;;; We already know at this point that the first three bytes of the 421 +;;; strings match each other, and they can be safely passed over before 422 +;;; starting the compare loop. So what this code does is skip over 0-3 423 +;;; bytes, as much as necessary in order to dword-align the edi 424 +;;; pointer. (rsi will still be misaligned three times out of four.) 425 +;;; 426 +;;; It should be confessed that this loop usually does not represent 427 +;;; much of the total running time. Replacing it with a more 428 +;;; straightforward "rep cmpsb" would not drastically degrade 429 +;;; performance. 430 + 431 + 432 +LoopCmps: 433 + mov rax, [rsi + rdx] 434 + xor rax, [rdi + rdx] 435 + jnz LeaveLoopCmps 436 + 437 + mov rax, [rsi + rdx + 8] 438 + xor rax, [rdi + rdx + 8] 439 + jnz LeaveLoopCmps8 440 + 441 + 442 + mov rax, [rsi + rdx + 8+8] 443 + xor rax, [rdi + rdx + 8+8] 444 + jnz LeaveLoopCmps16 445 + 446 + add rdx,8+8+8 447 + 448 + jnz short LoopCmps 449 + jmp short LenMaximum 450 +LeaveLoopCmps16: add rdx,8 451 +LeaveLoopCmps8: add rdx,8 452 +LeaveLoopCmps: 453 + 454 + test eax, 0000FFFFh 455 + jnz LenLower 456 + 457 + test eax,0ffffffffh 458 + 459 + jnz LenLower32 460 + 461 + add rdx,4 462 + shr rax,32 463 + or ax,ax 464 + jnz LenLower 465 + 466 +LenLower32: 467 + shr eax,16 468 + add rdx,2 469 +LenLower: sub al, 1 470 + adc rdx, 0 471 +;;; Calculate the length of the match. If it is longer than MAX_MATCH, 472 +;;; then automatically accept it as the best possible match and leave. 473 + 474 + lea rax, [rdi + rdx] 475 + sub rax, r9 476 + cmp eax, MAX_MATCH 477 + jge LenMaximum 478 + 479 +;;; If the length of the match is not longer than the best match we 480 +;;; have so far, then forget it and return to the lookup loop. 481 +;/////////////////////////////////// 482 + 483 + cmp eax, r11d 484 + jg LongerMatch 485 + 486 + lea rsi,[r10+r11] 487 + 488 + mov rdi, prev_ad 489 + mov edx, [chainlenwmask] 490 + jmp LookupLoop 491 + 492 +;;; s->match_start = cur_match; 493 +;;; best_len = len; 494 +;;; if (len >= nice_match) break; 495 +;;; scan_end = *(ushf*)(scan+best_len-1); 496 + 497 +LongerMatch: 498 + mov r11d, eax 499 + mov match_start, r8d 500 + cmp eax, [nicematch] 501 + jge LeaveNow 502 + 503 + lea rsi,[r10+rax] 504 + 505 + movzx ebx, word ptr [r9 + rax - 1] 506 + mov rdi, prev_ad 507 + mov edx, [chainlenwmask] 508 + jmp LookupLoop 509 + 510 +;;; Accept the current string, with the maximum possible length. 511 + 512 +LenMaximum: 513 + mov r11d,MAX_MATCH 514 + mov match_start, r8d 515 + 516 +;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 517 +;;; return s->lookahead; 518 + 519 +LeaveNow: 520 +IFDEF INFOZIP 521 + mov eax,r11d 522 +ELSE 523 + mov eax, Lookahead 524 + cmp r11d, eax 525 + cmovng eax, r11d 526 +ENDIF 527 + 528 +;;; Restore the stack and return from whence we came. 529 + 530 + 531 + mov rsi,[save_rsi] 532 + mov rdi,[save_rdi] 533 + mov rbx,[save_rbx] 534 + mov rbp,[save_rbp] 535 + mov r12,[save_r12] 536 + mov r13,[save_r13] 537 +; mov r14,[save_r14] 538 +; mov r15,[save_r15] 539 + 540 + 541 + ret 0 542 +; please don't remove this string ! 543 +; Your can freely use gvmat64 in any free or commercial app 544 +; but it is far better don't remove the string in the binary! 545 + db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 546 +longest_match ENDP 547 + 548 +match_init PROC 549 + ret 0 550 +match_init ENDP 551 + 552 + 553 +END
Added compat/zlib/contrib/masmx64/inffas8664.c.
1 +/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding 2 + * version for AMD64 on Windows using Microsoft C compiler 3 + * 4 + * Copyright (C) 1995-2003 Mark Adler 5 + * For conditions of distribution and use, see copyright notice in zlib.h 6 + * 7 + * Copyright (C) 2003 Chris Anderson <christop@charm.net> 8 + * Please use the copyright conditions above. 9 + * 10 + * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant 11 + * 12 + * inffas8664.c call function inffas8664fnc in inffasx64.asm 13 + * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c 14 + * 15 + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also 16 + * slightly quicker on x86 systems because, instead of using rep movsb to copy 17 + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single 18 + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates 19 + * from http://fedora.linux.duke.edu/fc1_x86_64 20 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with 21 + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, 22 + * when decompressing mozilla-source-1.3.tar.gz. 23 + * 24 + * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from 25 + * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at 26 + * the moment. I have successfully compiled and tested this code with gcc2.96, 27 + * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S 28 + * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX 29 + * enabled. I will attempt to merge the MMX code into this version. Newer 30 + * versions of this and inffast.S can be found at 31 + * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ 32 + * 33 + */ 34 + 35 +#include <stdio.h> 36 +#include "zutil.h" 37 +#include "inftrees.h" 38 +#include "inflate.h" 39 +#include "inffast.h" 40 + 41 +/* Mark Adler's comments from inffast.c: */ 42 + 43 +/* 44 + Decode literal, length, and distance codes and write out the resulting 45 + literal and match bytes until either not enough input or output is 46 + available, an end-of-block is encountered, or a data error is encountered. 47 + When large enough input and output buffers are supplied to inflate(), for 48 + example, a 16K input buffer and a 64K output buffer, more than 95% of the 49 + inflate execution time is spent in this routine. 50 + 51 + Entry assumptions: 52 + 53 + state->mode == LEN 54 + strm->avail_in >= 6 55 + strm->avail_out >= 258 56 + start >= strm->avail_out 57 + state->bits < 8 58 + 59 + On return, state->mode is one of: 60 + 61 + LEN -- ran out of enough output space or enough available input 62 + TYPE -- reached end of block code, inflate() to interpret next block 63 + BAD -- error in block data 64 + 65 + Notes: 66 + 67 + - The maximum input bits used by a length/distance pair is 15 bits for the 68 + length code, 5 bits for the length extra, 15 bits for the distance code, 69 + and 13 bits for the distance extra. This totals 48 bits, or six bytes. 70 + Therefore if strm->avail_in >= 6, then there is enough input to avoid 71 + checking for available input while decoding. 72 + 73 + - The maximum bytes that a single length/distance pair can output is 258 74 + bytes, which is the maximum length that can be coded. inflate_fast() 75 + requires strm->avail_out >= 258 for each loop to avoid checking for 76 + output space. 77 + */ 78 + 79 + 80 + 81 + typedef struct inffast_ar { 82 +/* 64 32 x86 x86_64 */ 83 +/* ar offset register */ 84 +/* 0 0 */ void *esp; /* esp save */ 85 +/* 8 4 */ void *ebp; /* ebp save */ 86 +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ 87 +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ 88 +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ 89 +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ 90 +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ 91 +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ 92 +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ 93 +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ 94 +/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */ 95 +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ 96 +/* 92 48 */ unsigned wsize; /* window size */ 97 +/* 96 52 */ unsigned write; /* window write index */ 98 +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ 99 +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ 100 +/*108 64 */ unsigned len; /* r14 match length */ 101 +/*112 68 */ unsigned dist; /* r15 match distance */ 102 +/*116 72 */ unsigned status; /* set when state chng*/ 103 + } type_ar; 104 +#ifdef ASMINF 105 + 106 +void inflate_fast(strm, start) 107 +z_streamp strm; 108 +unsigned start; /* inflate()'s starting value for strm->avail_out */ 109 +{ 110 + struct inflate_state FAR *state; 111 + type_ar ar; 112 + void inffas8664fnc(struct inffast_ar * par); 113 + 114 + 115 + 116 +#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64)) 117 +#define PAD_AVAIL_IN 6 118 +#define PAD_AVAIL_OUT 258 119 +#else 120 +#define PAD_AVAIL_IN 5 121 +#define PAD_AVAIL_OUT 257 122 +#endif 123 + 124 + /* copy state to local variables */ 125 + state = (struct inflate_state FAR *)strm->state; 126 + 127 + ar.in = strm->next_in; 128 + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); 129 + ar.out = strm->next_out; 130 + ar.beg = ar.out - (start - strm->avail_out); 131 + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); 132 + ar.wsize = state->wsize; 133 + ar.write = state->wnext; 134 + ar.window = state->window; 135 + ar.hold = state->hold; 136 + ar.bits = state->bits; 137 + ar.lcode = state->lencode; 138 + ar.dcode = state->distcode; 139 + ar.lmask = (1U << state->lenbits) - 1; 140 + ar.dmask = (1U << state->distbits) - 1; 141 + 142 + /* decode literals and length/distances until end-of-block or not enough 143 + input data or output space */ 144 + 145 + /* align in on 1/2 hold size boundary */ 146 + while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { 147 + ar.hold += (unsigned long)*ar.in++ << ar.bits; 148 + ar.bits += 8; 149 + } 150 + 151 + inffas8664fnc(&ar); 152 + 153 + if (ar.status > 1) { 154 + if (ar.status == 2) 155 + strm->msg = "invalid literal/length code"; 156 + else if (ar.status == 3) 157 + strm->msg = "invalid distance code"; 158 + else 159 + strm->msg = "invalid distance too far back"; 160 + state->mode = BAD; 161 + } 162 + else if ( ar.status == 1 ) { 163 + state->mode = TYPE; 164 + } 165 + 166 + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 167 + ar.len = ar.bits >> 3; 168 + ar.in -= ar.len; 169 + ar.bits -= ar.len << 3; 170 + ar.hold &= (1U << ar.bits) - 1; 171 + 172 + /* update state and return */ 173 + strm->next_in = ar.in; 174 + strm->next_out = ar.out; 175 + strm->avail_in = (unsigned)(ar.in < ar.last ? 176 + PAD_AVAIL_IN + (ar.last - ar.in) : 177 + PAD_AVAIL_IN - (ar.in - ar.last)); 178 + strm->avail_out = (unsigned)(ar.out < ar.end ? 179 + PAD_AVAIL_OUT + (ar.end - ar.out) : 180 + PAD_AVAIL_OUT - (ar.out - ar.end)); 181 + state->hold = (unsigned long)ar.hold; 182 + state->bits = ar.bits; 183 + return; 184 +} 185 + 186 +#endif
Added compat/zlib/contrib/masmx64/inffasx64.asm.
1 +; inffasx64.asm is a hand tuned assembler version of inffast.c - fast decoding 2 +; version for AMD64 on Windows using Microsoft C compiler 3 +; 4 +; inffasx64.asm is automatically convert from AMD64 portion of inffas86.c 5 +; inffasx64.asm is called by inffas8664.c, which contain more info. 6 + 7 + 8 +; to compile this file, I use option 9 +; ml64.exe /Flinffasx64 /c /Zi inffasx64.asm 10 +; with Microsoft Macro Assembler (x64) for AMD64 11 +; 12 + 13 +; This file compile with Microsoft Macro Assembler (x64) for AMD64 14 +; 15 +; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK 16 +; 17 +; (you can get Windows WDK with ml64 for AMD64 from 18 +; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) 19 +; 20 + 21 + 22 +.code 23 +inffas8664fnc PROC 24 + 25 +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and 26 +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp 27 +; 28 +; All registers must be preserved across the call, except for 29 +; rax, rcx, rdx, r8, r-9, r10, and r11, which are scratch. 30 + 31 + 32 + mov [rsp-8],rsi 33 + mov [rsp-16],rdi 34 + mov [rsp-24],r12 35 + mov [rsp-32],r13 36 + mov [rsp-40],r14 37 + mov [rsp-48],r15 38 + mov [rsp-56],rbx 39 + 40 + mov rax,rcx 41 + 42 + mov [rax+8], rbp ; /* save regs rbp and rsp */ 43 + mov [rax], rsp 44 + 45 + mov rsp, rax ; /* make rsp point to &ar */ 46 + 47 + mov rsi, [rsp+16] ; /* rsi = in */ 48 + mov rdi, [rsp+32] ; /* rdi = out */ 49 + mov r9, [rsp+24] ; /* r9 = last */ 50 + mov r10, [rsp+48] ; /* r10 = end */ 51 + mov rbp, [rsp+64] ; /* rbp = lcode */ 52 + mov r11, [rsp+72] ; /* r11 = dcode */ 53 + mov rdx, [rsp+80] ; /* rdx = hold */ 54 + mov ebx, [rsp+88] ; /* ebx = bits */ 55 + mov r12d, [rsp+100] ; /* r12d = lmask */ 56 + mov r13d, [rsp+104] ; /* r13d = dmask */ 57 + ; /* r14d = len */ 58 + ; /* r15d = dist */ 59 + 60 + 61 + cld 62 + cmp r10, rdi 63 + je L_one_time ; /* if only one decode left */ 64 + cmp r9, rsi 65 + 66 + jne L_do_loop 67 + 68 + 69 +L_one_time: 70 + mov r8, r12 ; /* r8 = lmask */ 71 + cmp bl, 32 72 + ja L_get_length_code_one_time 73 + 74 + lodsd ; /* eax = *(uint *)in++ */ 75 + mov cl, bl ; /* cl = bits, needs it for shifting */ 76 + add bl, 32 ; /* bits += 32 */ 77 + shl rax, cl 78 + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ 79 + jmp L_get_length_code_one_time 80 + 81 +ALIGN 4 82 +L_while_test: 83 + cmp r10, rdi 84 + jbe L_break_loop 85 + cmp r9, rsi 86 + jbe L_break_loop 87 + 88 +L_do_loop: 89 + mov r8, r12 ; /* r8 = lmask */ 90 + cmp bl, 32 91 + ja L_get_length_code ; /* if (32 < bits) */ 92 + 93 + lodsd ; /* eax = *(uint *)in++ */ 94 + mov cl, bl ; /* cl = bits, needs it for shifting */ 95 + add bl, 32 ; /* bits += 32 */ 96 + shl rax, cl 97 + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ 98 + 99 +L_get_length_code: 100 + and r8, rdx ; /* r8 &= hold */ 101 + mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ 102 + 103 + mov cl, ah ; /* cl = this.bits */ 104 + sub bl, ah ; /* bits -= this.bits */ 105 + shr rdx, cl ; /* hold >>= this.bits */ 106 + 107 + test al, al 108 + jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ 109 + 110 + mov r8, r12 ; /* r8 = lmask */ 111 + shr eax, 16 ; /* output this.val char */ 112 + stosb 113 + 114 +L_get_length_code_one_time: 115 + and r8, rdx ; /* r8 &= hold */ 116 + mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ 117 + 118 +L_dolen: 119 + mov cl, ah ; /* cl = this.bits */ 120 + sub bl, ah ; /* bits -= this.bits */ 121 + shr rdx, cl ; /* hold >>= this.bits */ 122 + 123 + test al, al 124 + jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ 125 + 126 + shr eax, 16 ; /* output this.val char */ 127 + stosb 128 + jmp L_while_test 129 + 130 +ALIGN 4 131 +L_test_for_length_base: 132 + mov r14d, eax ; /* len = this */ 133 + shr r14d, 16 ; /* len = this.val */ 134 + mov cl, al 135 + 136 + test al, 16 137 + jz L_test_for_second_level_length ; /* if ((op & 16) == 0) 8% */ 138 + and cl, 15 ; /* op &= 15 */ 139 + jz L_decode_distance ; /* if (!op) */ 140 + 141 +L_add_bits_to_len: 142 + sub bl, cl 143 + xor eax, eax 144 + inc eax 145 + shl eax, cl 146 + dec eax 147 + and eax, edx ; /* eax &= hold */ 148 + shr rdx, cl 149 + add r14d, eax ; /* len += hold & mask[op] */ 150 + 151 +L_decode_distance: 152 + mov r8, r13 ; /* r8 = dmask */ 153 + cmp bl, 32 154 + ja L_get_distance_code ; /* if (32 < bits) */ 155 + 156 + lodsd ; /* eax = *(uint *)in++ */ 157 + mov cl, bl ; /* cl = bits, needs it for shifting */ 158 + add bl, 32 ; /* bits += 32 */ 159 + shl rax, cl 160 + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ 161 + 162 +L_get_distance_code: 163 + and r8, rdx ; /* r8 &= hold */ 164 + mov eax, [r11+r8*4] ; /* eax = dcode[hold & dmask] */ 165 + 166 +L_dodist: 167 + mov r15d, eax ; /* dist = this */ 168 + shr r15d, 16 ; /* dist = this.val */ 169 + mov cl, ah 170 + sub bl, ah ; /* bits -= this.bits */ 171 + shr rdx, cl ; /* hold >>= this.bits */ 172 + mov cl, al ; /* cl = this.op */ 173 + 174 + test al, 16 ; /* if ((op & 16) == 0) */ 175 + jz L_test_for_second_level_dist 176 + and cl, 15 ; /* op &= 15 */ 177 + jz L_check_dist_one 178 + 179 +L_add_bits_to_dist: 180 + sub bl, cl 181 + xor eax, eax 182 + inc eax 183 + shl eax, cl 184 + dec eax ; /* (1 << op) - 1 */ 185 + and eax, edx ; /* eax &= hold */ 186 + shr rdx, cl 187 + add r15d, eax ; /* dist += hold & ((1 << op) - 1) */ 188 + 189 +L_check_window: 190 + mov r8, rsi ; /* save in so from can use it's reg */ 191 + mov rax, rdi 192 + sub rax, [rsp+40] ; /* nbytes = out - beg */ 193 + 194 + cmp eax, r15d 195 + jb L_clip_window ; /* if (dist > nbytes) 4.2% */ 196 + 197 + mov ecx, r14d ; /* ecx = len */ 198 + mov rsi, rdi 199 + sub rsi, r15 ; /* from = out - dist */ 200 + 201 + sar ecx, 1 202 + jnc L_copy_two ; /* if len % 2 == 0 */ 203 + 204 + rep movsw 205 + mov al, [rsi] 206 + mov [rdi], al 207 + inc rdi 208 + 209 + mov rsi, r8 ; /* move in back to %rsi, toss from */ 210 + jmp L_while_test 211 + 212 +L_copy_two: 213 + rep movsw 214 + mov rsi, r8 ; /* move in back to %rsi, toss from */ 215 + jmp L_while_test 216 + 217 +ALIGN 4 218 +L_check_dist_one: 219 + cmp r15d, 1 ; /* if dist 1, is a memset */ 220 + jne L_check_window 221 + cmp [rsp+40], rdi ; /* if out == beg, outside window */ 222 + je L_check_window 223 + 224 + mov ecx, r14d ; /* ecx = len */ 225 + mov al, [rdi-1] 226 + mov ah, al 227 + 228 + sar ecx, 1 229 + jnc L_set_two 230 + mov [rdi], al 231 + inc rdi 232 + 233 +L_set_two: 234 + rep stosw 235 + jmp L_while_test 236 + 237 +ALIGN 4 238 +L_test_for_second_level_length: 239 + test al, 64 240 + jnz L_test_for_end_of_block ; /* if ((op & 64) != 0) */ 241 + 242 + xor eax, eax 243 + inc eax 244 + shl eax, cl 245 + dec eax 246 + and eax, edx ; /* eax &= hold */ 247 + add eax, r14d ; /* eax += len */ 248 + mov eax, [rbp+rax*4] ; /* eax = lcode[val+(hold&mask[op])]*/ 249 + jmp L_dolen 250 + 251 +ALIGN 4 252 +L_test_for_second_level_dist: 253 + test al, 64 254 + jnz L_invalid_distance_code ; /* if ((op & 64) != 0) */ 255 + 256 + xor eax, eax 257 + inc eax 258 + shl eax, cl 259 + dec eax 260 + and eax, edx ; /* eax &= hold */ 261 + add eax, r15d ; /* eax += dist */ 262 + mov eax, [r11+rax*4] ; /* eax = dcode[val+(hold&mask[op])]*/ 263 + jmp L_dodist 264 + 265 +ALIGN 4 266 +L_clip_window: 267 + mov ecx, eax ; /* ecx = nbytes */ 268 + mov eax, [rsp+92] ; /* eax = wsize, prepare for dist cmp */ 269 + neg ecx ; /* nbytes = -nbytes */ 270 + 271 + cmp eax, r15d 272 + jb L_invalid_distance_too_far ; /* if (dist > wsize) */ 273 + 274 + add ecx, r15d ; /* nbytes = dist - nbytes */ 275 + cmp dword ptr [rsp+96], 0 276 + jne L_wrap_around_window ; /* if (write != 0) */ 277 + 278 + mov rsi, [rsp+56] ; /* from = window */ 279 + sub eax, ecx ; /* eax -= nbytes */ 280 + add rsi, rax ; /* from += wsize - nbytes */ 281 + 282 + mov eax, r14d ; /* eax = len */ 283 + cmp r14d, ecx 284 + jbe L_do_copy ; /* if (nbytes >= len) */ 285 + 286 + sub eax, ecx ; /* eax -= nbytes */ 287 + rep movsb 288 + mov rsi, rdi 289 + sub rsi, r15 ; /* from = &out[ -dist ] */ 290 + jmp L_do_copy 291 + 292 +ALIGN 4 293 +L_wrap_around_window: 294 + mov eax, [rsp+96] ; /* eax = write */ 295 + cmp ecx, eax 296 + jbe L_contiguous_in_window ; /* if (write >= nbytes) */ 297 + 298 + mov esi, [rsp+92] ; /* from = wsize */ 299 + add rsi, [rsp+56] ; /* from += window */ 300 + add rsi, rax ; /* from += write */ 301 + sub rsi, rcx ; /* from -= nbytes */ 302 + sub ecx, eax ; /* nbytes -= write */ 303 + 304 + mov eax, r14d ; /* eax = len */ 305 + cmp eax, ecx 306 + jbe L_do_copy ; /* if (nbytes >= len) */ 307 + 308 + sub eax, ecx ; /* len -= nbytes */ 309 + rep movsb 310 + mov rsi, [rsp+56] ; /* from = window */ 311 + mov ecx, [rsp+96] ; /* nbytes = write */ 312 + cmp eax, ecx 313 + jbe L_do_copy ; /* if (nbytes >= len) */ 314 + 315 + sub eax, ecx ; /* len -= nbytes */ 316 + rep movsb 317 + mov rsi, rdi 318 + sub rsi, r15 ; /* from = out - dist */ 319 + jmp L_do_copy 320 + 321 +ALIGN 4 322 +L_contiguous_in_window: 323 + mov rsi, [rsp+56] ; /* rsi = window */ 324 + add rsi, rax 325 + sub rsi, rcx ; /* from += write - nbytes */ 326 + 327 + mov eax, r14d ; /* eax = len */ 328 + cmp eax, ecx 329 + jbe L_do_copy ; /* if (nbytes >= len) */ 330 + 331 + sub eax, ecx ; /* len -= nbytes */ 332 + rep movsb 333 + mov rsi, rdi 334 + sub rsi, r15 ; /* from = out - dist */ 335 + jmp L_do_copy ; /* if (nbytes >= len) */ 336 + 337 +ALIGN 4 338 +L_do_copy: 339 + mov ecx, eax ; /* ecx = len */ 340 + rep movsb 341 + 342 + mov rsi, r8 ; /* move in back to %esi, toss from */ 343 + jmp L_while_test 344 + 345 +L_test_for_end_of_block: 346 + test al, 32 347 + jz L_invalid_literal_length_code 348 + mov dword ptr [rsp+116], 1 349 + jmp L_break_loop_with_status 350 + 351 +L_invalid_literal_length_code: 352 + mov dword ptr [rsp+116], 2 353 + jmp L_break_loop_with_status 354 + 355 +L_invalid_distance_code: 356 + mov dword ptr [rsp+116], 3 357 + jmp L_break_loop_with_status 358 + 359 +L_invalid_distance_too_far: 360 + mov dword ptr [rsp+116], 4 361 + jmp L_break_loop_with_status 362 + 363 +L_break_loop: 364 + mov dword ptr [rsp+116], 0 365 + 366 +L_break_loop_with_status: 367 +; /* put in, out, bits, and hold back into ar and pop esp */ 368 + mov [rsp+16], rsi ; /* in */ 369 + mov [rsp+32], rdi ; /* out */ 370 + mov [rsp+88], ebx ; /* bits */ 371 + mov [rsp+80], rdx ; /* hold */ 372 + 373 + mov rax, [rsp] ; /* restore rbp and rsp */ 374 + mov rbp, [rsp+8] 375 + mov rsp, rax 376 + 377 + 378 + 379 + mov rsi,[rsp-8] 380 + mov rdi,[rsp-16] 381 + mov r12,[rsp-24] 382 + mov r13,[rsp-32] 383 + mov r14,[rsp-40] 384 + mov r15,[rsp-48] 385 + mov rbx,[rsp-56] 386 + 387 + ret 0 388 +; : 389 +; : "m" (ar) 390 +; : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", 391 +; "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" 392 +; ); 393 + 394 +inffas8664fnc ENDP 395 +;_TEXT ENDS 396 +END
Added compat/zlib/contrib/masmx64/readme.txt.
1 +Summary 2 +------- 3 +This directory contains ASM implementations of the functions 4 +longest_match() and inflate_fast(), for 64 bits x86 (both AMD64 and Intel EM64t), 5 +for use with Microsoft Macro Assembler (x64) for AMD64 and Microsoft C++ 64 bits. 6 + 7 +gvmat64.asm is written by Gilles Vollant (2005), by using Brian Raiter 686/32 bits 8 + assembly optimized version from Jean-loup Gailly original longest_match function 9 + 10 +inffasx64.asm and inffas8664.c were written by Chris Anderson, by optimizing 11 + original function from Mark Adler 12 + 13 +Use instructions 14 +---------------- 15 +Assemble the .asm files using MASM and put the object files into the zlib source 16 +directory. You can also get object files here: 17 + 18 + http://www.winimage.com/zLibDll/zlib124_masm_obj.zip 19 + 20 +define ASMV and ASMINF in your project. Include inffas8664.c in your source tree, 21 +and inffasx64.obj and gvmat64.obj as object to link. 22 + 23 + 24 +Build instructions 25 +------------------ 26 +run bld_64.bat with Microsoft Macro Assembler (x64) for AMD64 (ml64.exe) 27 + 28 +ml64.exe is given with Visual Studio 2005, Windows 2003 server DDK 29 + 30 +You can get Windows 2003 server DDK with ml64 and cl for AMD64 from 31 + http://www.microsoft.com/whdc/devtools/ddk/default.mspx for low price)
Added compat/zlib/contrib/masmx86/bld_ml32.bat.
1 +ml /coff /Zi /c /Flmatch686.lst match686.asm 2 +ml /coff /Zi /c /Flinffas32.lst inffas32.asm
Added compat/zlib/contrib/masmx86/inffas32.asm.
1 +;/* inffas32.asm is a hand tuned assembler version of inffast.c -- fast decoding 2 +; * 3 +; * inffas32.asm is derivated from inffas86.c, with translation of assembly code 4 +; * 5 +; * Copyright (C) 1995-2003 Mark Adler 6 +; * For conditions of distribution and use, see copyright notice in zlib.h 7 +; * 8 +; * Copyright (C) 2003 Chris Anderson <christop@charm.net> 9 +; * Please use the copyright conditions above. 10 +; * 11 +; * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from 12 +; * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at 13 +; * the moment. I have successfully compiled and tested this code with gcc2.96, 14 +; * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S 15 +; * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX 16 +; * enabled. I will attempt to merge the MMX code into this version. Newer 17 +; * versions of this and inffast.S can be found at 18 +; * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ 19 +; * 20 +; * 2005 : modification by Gilles Vollant 21 +; */ 22 +; For Visual C++ 4.x and higher and ML 6.x and higher 23 +; ml.exe is in directory \MASM611C of Win95 DDK 24 +; ml.exe is also distributed in http://www.masm32.com/masmdl.htm 25 +; and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/ 26 +; 27 +; 28 +; compile with command line option 29 +; ml /coff /Zi /c /Flinffas32.lst inffas32.asm 30 + 31 +; if you define NO_GZIP (see inflate.h), compile with 32 +; ml /coff /Zi /c /Flinffas32.lst /DNO_GUNZIP inffas32.asm 33 + 34 + 35 +; zlib122sup is 0 fort zlib 1.2.2.1 and lower 36 +; zlib122sup is 8 fort zlib 1.2.2.2 and more (with addition of dmax and head 37 +; in inflate_state in inflate.h) 38 +zlib1222sup equ 8 39 + 40 + 41 +IFDEF GUNZIP 42 + INFLATE_MODE_TYPE equ 11 43 + INFLATE_MODE_BAD equ 26 44 +ELSE 45 + IFNDEF NO_GUNZIP 46 + INFLATE_MODE_TYPE equ 11 47 + INFLATE_MODE_BAD equ 26 48 + ELSE 49 + INFLATE_MODE_TYPE equ 3 50 + INFLATE_MODE_BAD equ 17 51 + ENDIF 52 +ENDIF 53 + 54 + 55 +; 75 "inffast.S" 56 +;FILE "inffast.S" 57 + 58 +;;;GLOBAL _inflate_fast 59 + 60 +;;;SECTION .text 61 + 62 + 63 + 64 + .586p 65 + .mmx 66 + 67 + name inflate_fast_x86 68 + .MODEL FLAT 69 + 70 +_DATA segment 71 +inflate_fast_use_mmx: 72 + dd 1 73 + 74 + 75 +_TEXT segment 76 + 77 + 78 + 79 +ALIGN 4 80 + db 'Fast decoding Code from Chris Anderson' 81 + db 0 82 + 83 +ALIGN 4 84 +invalid_literal_length_code_msg: 85 + db 'invalid literal/length code' 86 + db 0 87 + 88 +ALIGN 4 89 +invalid_distance_code_msg: 90 + db 'invalid distance code' 91 + db 0 92 + 93 +ALIGN 4 94 +invalid_distance_too_far_msg: 95 + db 'invalid distance too far back' 96 + db 0 97 + 98 + 99 +ALIGN 4 100 +inflate_fast_mask: 101 +dd 0 102 +dd 1 103 +dd 3 104 +dd 7 105 +dd 15 106 +dd 31 107 +dd 63 108 +dd 127 109 +dd 255 110 +dd 511 111 +dd 1023 112 +dd 2047 113 +dd 4095 114 +dd 8191 115 +dd 16383 116 +dd 32767 117 +dd 65535 118 +dd 131071 119 +dd 262143 120 +dd 524287 121 +dd 1048575 122 +dd 2097151 123 +dd 4194303 124 +dd 8388607 125 +dd 16777215 126 +dd 33554431 127 +dd 67108863 128 +dd 134217727 129 +dd 268435455 130 +dd 536870911 131 +dd 1073741823 132 +dd 2147483647 133 +dd 4294967295 134 + 135 + 136 +mode_state equ 0 ;/* state->mode */ 137 +wsize_state equ (32+zlib1222sup) ;/* state->wsize */ 138 +write_state equ (36+4+zlib1222sup) ;/* state->write */ 139 +window_state equ (40+4+zlib1222sup) ;/* state->window */ 140 +hold_state equ (44+4+zlib1222sup) ;/* state->hold */ 141 +bits_state equ (48+4+zlib1222sup) ;/* state->bits */ 142 +lencode_state equ (64+4+zlib1222sup) ;/* state->lencode */ 143 +distcode_state equ (68+4+zlib1222sup) ;/* state->distcode */ 144 +lenbits_state equ (72+4+zlib1222sup) ;/* state->lenbits */ 145 +distbits_state equ (76+4+zlib1222sup) ;/* state->distbits */ 146 + 147 + 148 +;;SECTION .text 149 +; 205 "inffast.S" 150 +;GLOBAL inflate_fast_use_mmx 151 + 152 +;SECTION .data 153 + 154 + 155 +; GLOBAL inflate_fast_use_mmx:object 156 +;.size inflate_fast_use_mmx, 4 157 +; 226 "inffast.S" 158 +;SECTION .text 159 + 160 +ALIGN 4 161 +_inflate_fast proc near 162 +.FPO (16, 4, 0, 0, 1, 0) 163 + push edi 164 + push esi 165 + push ebp 166 + push ebx 167 + pushfd 168 + sub esp,64 169 + cld 170 + 171 + 172 + 173 + 174 + mov esi, [esp+88] 175 + mov edi, [esi+28] 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + mov edx, [esi+4] 184 + mov eax, [esi+0] 185 + 186 + add edx,eax 187 + sub edx,11 188 + 189 + mov [esp+44],eax 190 + mov [esp+20],edx 191 + 192 + mov ebp, [esp+92] 193 + mov ecx, [esi+16] 194 + mov ebx, [esi+12] 195 + 196 + sub ebp,ecx 197 + neg ebp 198 + add ebp,ebx 199 + 200 + sub ecx,257 201 + add ecx,ebx 202 + 203 + mov [esp+60],ebx 204 + mov [esp+40],ebp 205 + mov [esp+16],ecx 206 +; 285 "inffast.S" 207 + mov eax, [edi+lencode_state] 208 + mov ecx, [edi+distcode_state] 209 + 210 + mov [esp+8],eax 211 + mov [esp+12],ecx 212 + 213 + mov eax,1 214 + mov ecx, [edi+lenbits_state] 215 + shl eax,cl 216 + dec eax 217 + mov [esp+0],eax 218 + 219 + mov eax,1 220 + mov ecx, [edi+distbits_state] 221 + shl eax,cl 222 + dec eax 223 + mov [esp+4],eax 224 + 225 + mov eax, [edi+wsize_state] 226 + mov ecx, [edi+write_state] 227 + mov edx, [edi+window_state] 228 + 229 + mov [esp+52],eax 230 + mov [esp+48],ecx 231 + mov [esp+56],edx 232 + 233 + mov ebp, [edi+hold_state] 234 + mov ebx, [edi+bits_state] 235 +; 321 "inffast.S" 236 + mov esi, [esp+44] 237 + mov ecx, [esp+20] 238 + cmp ecx,esi 239 + ja L_align_long 240 + 241 + add ecx,11 242 + sub ecx,esi 243 + mov eax,12 244 + sub eax,ecx 245 + lea edi, [esp+28] 246 + rep movsb 247 + mov ecx,eax 248 + xor eax,eax 249 + rep stosb 250 + lea esi, [esp+28] 251 + mov [esp+20],esi 252 + jmp L_is_aligned 253 + 254 + 255 +L_align_long: 256 + test esi,3 257 + jz L_is_aligned 258 + xor eax,eax 259 + mov al, [esi] 260 + inc esi 261 + mov ecx,ebx 262 + add ebx,8 263 + shl eax,cl 264 + or ebp,eax 265 + jmp L_align_long 266 + 267 +L_is_aligned: 268 + mov edi, [esp+60] 269 +; 366 "inffast.S" 270 +L_check_mmx: 271 + cmp dword ptr [inflate_fast_use_mmx],2 272 + je L_init_mmx 273 + ja L_do_loop 274 + 275 + push eax 276 + push ebx 277 + push ecx 278 + push edx 279 + pushfd 280 + mov eax, [esp] 281 + xor dword ptr [esp],0200000h 282 + 283 + 284 + 285 + 286 + popfd 287 + pushfd 288 + pop edx 289 + xor edx,eax 290 + jz L_dont_use_mmx 291 + xor eax,eax 292 + cpuid 293 + cmp ebx,0756e6547h 294 + jne L_dont_use_mmx 295 + cmp ecx,06c65746eh 296 + jne L_dont_use_mmx 297 + cmp edx,049656e69h 298 + jne L_dont_use_mmx 299 + mov eax,1 300 + cpuid 301 + shr eax,8 302 + and eax,15 303 + cmp eax,6 304 + jne L_dont_use_mmx 305 + test edx,0800000h 306 + jnz L_use_mmx 307 + jmp L_dont_use_mmx 308 +L_use_mmx: 309 + mov dword ptr [inflate_fast_use_mmx],2 310 + jmp L_check_mmx_pop 311 +L_dont_use_mmx: 312 + mov dword ptr [inflate_fast_use_mmx],3 313 +L_check_mmx_pop: 314 + pop edx 315 + pop ecx 316 + pop ebx 317 + pop eax 318 + jmp L_check_mmx 319 +; 426 "inffast.S" 320 +ALIGN 4 321 +L_do_loop: 322 +; 437 "inffast.S" 323 + cmp bl,15 324 + ja L_get_length_code 325 + 326 + xor eax,eax 327 + lodsw 328 + mov cl,bl 329 + add bl,16 330 + shl eax,cl 331 + or ebp,eax 332 + 333 +L_get_length_code: 334 + mov edx, [esp+0] 335 + mov ecx, [esp+8] 336 + and edx,ebp 337 + mov eax, [ecx+edx*4] 338 + 339 +L_dolen: 340 + 341 + 342 + 343 + 344 + 345 + 346 + mov cl,ah 347 + sub bl,ah 348 + shr ebp,cl 349 + 350 + 351 + 352 + 353 + 354 + 355 + test al,al 356 + jnz L_test_for_length_base 357 + 358 + shr eax,16 359 + stosb 360 + 361 +L_while_test: 362 + 363 + 364 + cmp [esp+16],edi 365 + jbe L_break_loop 366 + 367 + cmp [esp+20],esi 368 + ja L_do_loop 369 + jmp L_break_loop 370 + 371 +L_test_for_length_base: 372 +; 502 "inffast.S" 373 + mov edx,eax 374 + shr edx,16 375 + mov cl,al 376 + 377 + test al,16 378 + jz L_test_for_second_level_length 379 + and cl,15 380 + jz L_save_len 381 + cmp bl,cl 382 + jae L_add_bits_to_len 383 + 384 + mov ch,cl 385 + xor eax,eax 386 + lodsw 387 + mov cl,bl 388 + add bl,16 389 + shl eax,cl 390 + or ebp,eax 391 + mov cl,ch 392 + 393 +L_add_bits_to_len: 394 + mov eax,1 395 + shl eax,cl 396 + dec eax 397 + sub bl,cl 398 + and eax,ebp 399 + shr ebp,cl 400 + add edx,eax 401 + 402 +L_save_len: 403 + mov [esp+24],edx 404 + 405 + 406 +L_decode_distance: 407 +; 549 "inffast.S" 408 + cmp bl,15 409 + ja L_get_distance_code 410 + 411 + xor eax,eax 412 + lodsw 413 + mov cl,bl 414 + add bl,16 415 + shl eax,cl 416 + or ebp,eax 417 + 418 +L_get_distance_code: 419 + mov edx, [esp+4] 420 + mov ecx, [esp+12] 421 + and edx,ebp 422 + mov eax, [ecx+edx*4] 423 + 424 + 425 +L_dodist: 426 + mov edx,eax 427 + shr edx,16 428 + mov cl,ah 429 + sub bl,ah 430 + shr ebp,cl 431 +; 584 "inffast.S" 432 + mov cl,al 433 + 434 + test al,16 435 + jz L_test_for_second_level_dist 436 + and cl,15 437 + jz L_check_dist_one 438 + cmp bl,cl 439 + jae L_add_bits_to_dist 440 + 441 + mov ch,cl 442 + xor eax,eax 443 + lodsw 444 + mov cl,bl 445 + add bl,16 446 + shl eax,cl 447 + or ebp,eax 448 + mov cl,ch 449 + 450 +L_add_bits_to_dist: 451 + mov eax,1 452 + shl eax,cl 453 + dec eax 454 + sub bl,cl 455 + and eax,ebp 456 + shr ebp,cl 457 + add edx,eax 458 + jmp L_check_window 459 + 460 +L_check_window: 461 +; 625 "inffast.S" 462 + mov [esp+44],esi 463 + mov eax,edi 464 + sub eax, [esp+40] 465 + 466 + cmp eax,edx 467 + jb L_clip_window 468 + 469 + mov ecx, [esp+24] 470 + mov esi,edi 471 + sub esi,edx 472 + 473 + sub ecx,3 474 + mov al, [esi] 475 + mov [edi],al 476 + mov al, [esi+1] 477 + mov dl, [esi+2] 478 + add esi,3 479 + mov [edi+1],al 480 + mov [edi+2],dl 481 + add edi,3 482 + rep movsb 483 + 484 + mov esi, [esp+44] 485 + jmp L_while_test 486 + 487 +ALIGN 4 488 +L_check_dist_one: 489 + cmp edx,1 490 + jne L_check_window 491 + cmp [esp+40],edi 492 + je L_check_window 493 + 494 + dec edi 495 + mov ecx, [esp+24] 496 + mov al, [edi] 497 + sub ecx,3 498 + 499 + mov [edi+1],al 500 + mov [edi+2],al 501 + mov [edi+3],al 502 + add edi,4 503 + rep stosb 504 + 505 + jmp L_while_test 506 + 507 +ALIGN 4 508 +L_test_for_second_level_length: 509 + 510 + 511 + 512 + 513 + test al,64 514 + jnz L_test_for_end_of_block 515 + 516 + mov eax,1 517 + shl eax,cl 518 + dec eax 519 + and eax,ebp 520 + add eax,edx 521 + mov edx, [esp+8] 522 + mov eax, [edx+eax*4] 523 + jmp L_dolen 524 + 525 +ALIGN 4 526 +L_test_for_second_level_dist: 527 + 528 + 529 + 530 + 531 + test al,64 532 + jnz L_invalid_distance_code 533 + 534 + mov eax,1 535 + shl eax,cl 536 + dec eax 537 + and eax,ebp 538 + add eax,edx 539 + mov edx, [esp+12] 540 + mov eax, [edx+eax*4] 541 + jmp L_dodist 542 + 543 +ALIGN 4 544 +L_clip_window: 545 +; 721 "inffast.S" 546 + mov ecx,eax 547 + mov eax, [esp+52] 548 + neg ecx 549 + mov esi, [esp+56] 550 + 551 + cmp eax,edx 552 + jb L_invalid_distance_too_far 553 + 554 + add ecx,edx 555 + cmp dword ptr [esp+48],0 556 + jne L_wrap_around_window 557 + 558 + sub eax,ecx 559 + add esi,eax 560 +; 749 "inffast.S" 561 + mov eax, [esp+24] 562 + cmp eax,ecx 563 + jbe L_do_copy1 564 + 565 + sub eax,ecx 566 + rep movsb 567 + mov esi,edi 568 + sub esi,edx 569 + jmp L_do_copy1 570 + 571 + cmp eax,ecx 572 + jbe L_do_copy1 573 + 574 + sub eax,ecx 575 + rep movsb 576 + mov esi,edi 577 + sub esi,edx 578 + jmp L_do_copy1 579 + 580 +L_wrap_around_window: 581 +; 793 "inffast.S" 582 + mov eax, [esp+48] 583 + cmp ecx,eax 584 + jbe L_contiguous_in_window 585 + 586 + add esi, [esp+52] 587 + add esi,eax 588 + sub esi,ecx 589 + sub ecx,eax 590 + 591 + 592 + mov eax, [esp+24] 593 + cmp eax,ecx 594 + jbe L_do_copy1 595 + 596 + sub eax,ecx 597 + rep movsb 598 + mov esi, [esp+56] 599 + mov ecx, [esp+48] 600 + cmp eax,ecx 601 + jbe L_do_copy1 602 + 603 + sub eax,ecx 604 + rep movsb 605 + mov esi,edi 606 + sub esi,edx 607 + jmp L_do_copy1 608 + 609 +L_contiguous_in_window: 610 +; 836 "inffast.S" 611 + add esi,eax 612 + sub esi,ecx 613 + 614 + 615 + mov eax, [esp+24] 616 + cmp eax,ecx 617 + jbe L_do_copy1 618 + 619 + sub eax,ecx 620 + rep movsb 621 + mov esi,edi 622 + sub esi,edx 623 + 624 +L_do_copy1: 625 +; 862 "inffast.S" 626 + mov ecx,eax 627 + rep movsb 628 + 629 + mov esi, [esp+44] 630 + jmp L_while_test 631 +; 878 "inffast.S" 632 +ALIGN 4 633 +L_init_mmx: 634 + emms 635 + 636 + 637 + 638 + 639 + 640 + movd mm0,ebp 641 + mov ebp,ebx 642 +; 896 "inffast.S" 643 + movd mm4,dword ptr [esp+0] 644 + movq mm3,mm4 645 + movd mm5,dword ptr [esp+4] 646 + movq mm2,mm5 647 + pxor mm1,mm1 648 + mov ebx, [esp+8] 649 + jmp L_do_loop_mmx 650 + 651 +ALIGN 4 652 +L_do_loop_mmx: 653 + psrlq mm0,mm1 654 + 655 + cmp ebp,32 656 + ja L_get_length_code_mmx 657 + 658 + movd mm6,ebp 659 + movd mm7,dword ptr [esi] 660 + add esi,4 661 + psllq mm7,mm6 662 + add ebp,32 663 + por mm0,mm7 664 + 665 +L_get_length_code_mmx: 666 + pand mm4,mm0 667 + movd eax,mm4 668 + movq mm4,mm3 669 + mov eax, [ebx+eax*4] 670 + 671 +L_dolen_mmx: 672 + movzx ecx,ah 673 + movd mm1,ecx 674 + sub ebp,ecx 675 + 676 + test al,al 677 + jnz L_test_for_length_base_mmx 678 + 679 + shr eax,16 680 + stosb 681 + 682 +L_while_test_mmx: 683 + 684 + 685 + cmp [esp+16],edi 686 + jbe L_break_loop 687 + 688 + cmp [esp+20],esi 689 + ja L_do_loop_mmx 690 + jmp L_break_loop 691 + 692 +L_test_for_length_base_mmx: 693 + 694 + mov edx,eax 695 + shr edx,16 696 + 697 + test al,16 698 + jz L_test_for_second_level_length_mmx 699 + and eax,15 700 + jz L_decode_distance_mmx 701 + 702 + psrlq mm0,mm1 703 + movd mm1,eax 704 + movd ecx,mm0 705 + sub ebp,eax 706 + and ecx, [inflate_fast_mask+eax*4] 707 + add edx,ecx 708 + 709 +L_decode_distance_mmx: 710 + psrlq mm0,mm1 711 + 712 + cmp ebp,32 713 + ja L_get_dist_code_mmx 714 + 715 + movd mm6,ebp 716 + movd mm7,dword ptr [esi] 717 + add esi,4 718 + psllq mm7,mm6 719 + add ebp,32 720 + por mm0,mm7 721 + 722 +L_get_dist_code_mmx: 723 + mov ebx, [esp+12] 724 + pand mm5,mm0 725 + movd eax,mm5 726 + movq mm5,mm2 727 + mov eax, [ebx+eax*4] 728 + 729 +L_dodist_mmx: 730 + 731 + movzx ecx,ah 732 + mov ebx,eax 733 + shr ebx,16 734 + sub ebp,ecx 735 + movd mm1,ecx 736 + 737 + test al,16 738 + jz L_test_for_second_level_dist_mmx 739 + and eax,15 740 + jz L_check_dist_one_mmx 741 + 742 +L_add_bits_to_dist_mmx: 743 + psrlq mm0,mm1 744 + movd mm1,eax 745 + movd ecx,mm0 746 + sub ebp,eax 747 + and ecx, [inflate_fast_mask+eax*4] 748 + add ebx,ecx 749 + 750 +L_check_window_mmx: 751 + mov [esp+44],esi 752 + mov eax,edi 753 + sub eax, [esp+40] 754 + 755 + cmp eax,ebx 756 + jb L_clip_window_mmx 757 + 758 + mov ecx,edx 759 + mov esi,edi 760 + sub esi,ebx 761 + 762 + sub ecx,3 763 + mov al, [esi] 764 + mov [edi],al 765 + mov al, [esi+1] 766 + mov dl, [esi+2] 767 + add esi,3 768 + mov [edi+1],al 769 + mov [edi+2],dl 770 + add edi,3 771 + rep movsb 772 + 773 + mov esi, [esp+44] 774 + mov ebx, [esp+8] 775 + jmp L_while_test_mmx 776 + 777 +ALIGN 4 778 +L_check_dist_one_mmx: 779 + cmp ebx,1 780 + jne L_check_window_mmx 781 + cmp [esp+40],edi 782 + je L_check_window_mmx 783 + 784 + dec edi 785 + mov ecx,edx 786 + mov al, [edi] 787 + sub ecx,3 788 + 789 + mov [edi+1],al 790 + mov [edi+2],al 791 + mov [edi+3],al 792 + add edi,4 793 + rep stosb 794 + 795 + mov ebx, [esp+8] 796 + jmp L_while_test_mmx 797 + 798 +ALIGN 4 799 +L_test_for_second_level_length_mmx: 800 + test al,64 801 + jnz L_test_for_end_of_block 802 + 803 + and eax,15 804 + psrlq mm0,mm1 805 + movd ecx,mm0 806 + and ecx, [inflate_fast_mask+eax*4] 807 + add ecx,edx 808 + mov eax, [ebx+ecx*4] 809 + jmp L_dolen_mmx 810 + 811 +ALIGN 4 812 +L_test_for_second_level_dist_mmx: 813 + test al,64 814 + jnz L_invalid_distance_code 815 + 816 + and eax,15 817 + psrlq mm0,mm1 818 + movd ecx,mm0 819 + and ecx, [inflate_fast_mask+eax*4] 820 + mov eax, [esp+12] 821 + add ecx,ebx 822 + mov eax, [eax+ecx*4] 823 + jmp L_dodist_mmx 824 + 825 +ALIGN 4 826 +L_clip_window_mmx: 827 + 828 + mov ecx,eax 829 + mov eax, [esp+52] 830 + neg ecx 831 + mov esi, [esp+56] 832 + 833 + cmp eax,ebx 834 + jb L_invalid_distance_too_far 835 + 836 + add ecx,ebx 837 + cmp dword ptr [esp+48],0 838 + jne L_wrap_around_window_mmx 839 + 840 + sub eax,ecx 841 + add esi,eax 842 + 843 + cmp edx,ecx 844 + jbe L_do_copy1_mmx 845 + 846 + sub edx,ecx 847 + rep movsb 848 + mov esi,edi 849 + sub esi,ebx 850 + jmp L_do_copy1_mmx 851 + 852 + cmp edx,ecx 853 + jbe L_do_copy1_mmx 854 + 855 + sub edx,ecx 856 + rep movsb 857 + mov esi,edi 858 + sub esi,ebx 859 + jmp L_do_copy1_mmx 860 + 861 +L_wrap_around_window_mmx: 862 + 863 + mov eax, [esp+48] 864 + cmp ecx,eax 865 + jbe L_contiguous_in_window_mmx 866 + 867 + add esi, [esp+52] 868 + add esi,eax 869 + sub esi,ecx 870 + sub ecx,eax 871 + 872 + 873 + cmp edx,ecx 874 + jbe L_do_copy1_mmx 875 + 876 + sub edx,ecx 877 + rep movsb 878 + mov esi, [esp+56] 879 + mov ecx, [esp+48] 880 + cmp edx,ecx 881 + jbe L_do_copy1_mmx 882 + 883 + sub edx,ecx 884 + rep movsb 885 + mov esi,edi 886 + sub esi,ebx 887 + jmp L_do_copy1_mmx 888 + 889 +L_contiguous_in_window_mmx: 890 + 891 + add esi,eax 892 + sub esi,ecx 893 + 894 + 895 + cmp edx,ecx 896 + jbe L_do_copy1_mmx 897 + 898 + sub edx,ecx 899 + rep movsb 900 + mov esi,edi 901 + sub esi,ebx 902 + 903 +L_do_copy1_mmx: 904 + 905 + 906 + mov ecx,edx 907 + rep movsb 908 + 909 + mov esi, [esp+44] 910 + mov ebx, [esp+8] 911 + jmp L_while_test_mmx 912 +; 1174 "inffast.S" 913 +L_invalid_distance_code: 914 + 915 + 916 + 917 + 918 + 919 + mov ecx, invalid_distance_code_msg 920 + mov edx,INFLATE_MODE_BAD 921 + jmp L_update_stream_state 922 + 923 +L_test_for_end_of_block: 924 + 925 + 926 + 927 + 928 + 929 + test al,32 930 + jz L_invalid_literal_length_code 931 + 932 + mov ecx,0 933 + mov edx,INFLATE_MODE_TYPE 934 + jmp L_update_stream_state 935 + 936 +L_invalid_literal_length_code: 937 + 938 + 939 + 940 + 941 + 942 + mov ecx, invalid_literal_length_code_msg 943 + mov edx,INFLATE_MODE_BAD 944 + jmp L_update_stream_state 945 + 946 +L_invalid_distance_too_far: 947 + 948 + 949 + 950 + mov esi, [esp+44] 951 + mov ecx, invalid_distance_too_far_msg 952 + mov edx,INFLATE_MODE_BAD 953 + jmp L_update_stream_state 954 + 955 +L_update_stream_state: 956 + 957 + mov eax, [esp+88] 958 + test ecx,ecx 959 + jz L_skip_msg 960 + mov [eax+24],ecx 961 +L_skip_msg: 962 + mov eax, [eax+28] 963 + mov [eax+mode_state],edx 964 + jmp L_break_loop 965 + 966 +ALIGN 4 967 +L_break_loop: 968 +; 1243 "inffast.S" 969 + cmp dword ptr [inflate_fast_use_mmx],2 970 + jne L_update_next_in 971 + 972 + 973 + 974 + mov ebx,ebp 975 + 976 +L_update_next_in: 977 +; 1266 "inffast.S" 978 + mov eax, [esp+88] 979 + mov ecx,ebx 980 + mov edx, [eax+28] 981 + shr ecx,3 982 + sub esi,ecx 983 + shl ecx,3 984 + sub ebx,ecx 985 + mov [eax+12],edi 986 + mov [edx+bits_state],ebx 987 + mov ecx,ebx 988 + 989 + lea ebx, [esp+28] 990 + cmp [esp+20],ebx 991 + jne L_buf_not_used 992 + 993 + sub esi,ebx 994 + mov ebx, [eax+0] 995 + mov [esp+20],ebx 996 + add esi,ebx 997 + mov ebx, [eax+4] 998 + sub ebx,11 999 + add [esp+20],ebx 1000 + 1001 +L_buf_not_used: 1002 + mov [eax+0],esi 1003 + 1004 + mov ebx,1 1005 + shl ebx,cl 1006 + dec ebx 1007 + 1008 + 1009 + 1010 + 1011 + 1012 + cmp dword ptr [inflate_fast_use_mmx],2 1013 + jne L_update_hold 1014 + 1015 + 1016 + 1017 + psrlq mm0,mm1 1018 + movd ebp,mm0 1019 + 1020 + emms 1021 + 1022 +L_update_hold: 1023 + 1024 + 1025 + 1026 + and ebp,ebx 1027 + mov [edx+hold_state],ebp 1028 + 1029 + 1030 + 1031 + 1032 + mov ebx, [esp+20] 1033 + cmp ebx,esi 1034 + jbe L_last_is_smaller 1035 + 1036 + sub ebx,esi 1037 + add ebx,11 1038 + mov [eax+4],ebx 1039 + jmp L_fixup_out 1040 +L_last_is_smaller: 1041 + sub esi,ebx 1042 + neg esi 1043 + add esi,11 1044 + mov [eax+4],esi 1045 + 1046 + 1047 + 1048 + 1049 +L_fixup_out: 1050 + 1051 + mov ebx, [esp+16] 1052 + cmp ebx,edi 1053 + jbe L_end_is_smaller 1054 + 1055 + sub ebx,edi 1056 + add ebx,257 1057 + mov [eax+16],ebx 1058 + jmp L_done 1059 +L_end_is_smaller: 1060 + sub edi,ebx 1061 + neg edi 1062 + add edi,257 1063 + mov [eax+16],edi 1064 + 1065 + 1066 + 1067 + 1068 + 1069 +L_done: 1070 + add esp,64 1071 + popfd 1072 + pop ebx 1073 + pop ebp 1074 + pop esi 1075 + pop edi 1076 + ret 1077 +_inflate_fast endp 1078 + 1079 +_TEXT ends 1080 +end
Added compat/zlib/contrib/masmx86/match686.asm.
1 +; match686.asm -- Asm portion of the optimized longest_match for 32 bits x86 2 +; Copyright (C) 1995-1996 Jean-loup Gailly, Brian Raiter and Gilles Vollant. 3 +; File written by Gilles Vollant, by converting match686.S from Brian Raiter 4 +; for MASM. This is as assembly version of longest_match 5 +; from Jean-loup Gailly in deflate.c 6 +; 7 +; http://www.zlib.net 8 +; http://www.winimage.com/zLibDll 9 +; http://www.muppetlabs.com/~breadbox/software/assembly.html 10 +; 11 +; For Visual C++ 4.x and higher and ML 6.x and higher 12 +; ml.exe is distributed in 13 +; http://www.microsoft.com/downloads/details.aspx?FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 14 +; 15 +; this file contain two implementation of longest_match 16 +; 17 +; this longest_match was written by Brian raiter (1998), optimized for Pentium Pro 18 +; (and the faster known version of match_init on modern Core 2 Duo and AMD Phenom) 19 +; 20 +; for using an assembly version of longest_match, you need define ASMV in project 21 +; 22 +; compile the asm file running 23 +; ml /coff /Zi /c /Flmatch686.lst match686.asm 24 +; and do not include match686.obj in your project 25 +; 26 +; note: contrib of zLib 1.2.3 and earlier contained both a deprecated version for 27 +; Pentium (prior Pentium Pro) and this version for Pentium Pro and modern processor 28 +; with autoselect (with cpu detection code) 29 +; if you want support the old pentium optimization, you can still use these version 30 +; 31 +; this file is not optimized for old pentium, but it compatible with all x86 32 bits 32 +; processor (starting 80386) 33 +; 34 +; 35 +; see below : zlib1222add must be adjuster if you use a zlib version < 1.2.2.2 36 + 37 +;uInt longest_match(s, cur_match) 38 +; deflate_state *s; 39 +; IPos cur_match; /* current match */ 40 + 41 + NbStack equ 76 42 + cur_match equ dword ptr[esp+NbStack-0] 43 + str_s equ dword ptr[esp+NbStack-4] 44 +; 5 dword on top (ret,ebp,esi,edi,ebx) 45 + adrret equ dword ptr[esp+NbStack-8] 46 + pushebp equ dword ptr[esp+NbStack-12] 47 + pushedi equ dword ptr[esp+NbStack-16] 48 + pushesi equ dword ptr[esp+NbStack-20] 49 + pushebx equ dword ptr[esp+NbStack-24] 50 + 51 + chain_length equ dword ptr [esp+NbStack-28] 52 + limit equ dword ptr [esp+NbStack-32] 53 + best_len equ dword ptr [esp+NbStack-36] 54 + window equ dword ptr [esp+NbStack-40] 55 + prev equ dword ptr [esp+NbStack-44] 56 + scan_start equ word ptr [esp+NbStack-48] 57 + wmask equ dword ptr [esp+NbStack-52] 58 + match_start_ptr equ dword ptr [esp+NbStack-56] 59 + nice_match equ dword ptr [esp+NbStack-60] 60 + scan equ dword ptr [esp+NbStack-64] 61 + 62 + windowlen equ dword ptr [esp+NbStack-68] 63 + match_start equ dword ptr [esp+NbStack-72] 64 + strend equ dword ptr [esp+NbStack-76] 65 + NbStackAdd equ (NbStack-24) 66 + 67 + .386p 68 + 69 + name gvmatch 70 + .MODEL FLAT 71 + 72 + 73 + 74 +; all the +zlib1222add offsets are due to the addition of fields 75 +; in zlib in the deflate_state structure since the asm code was first written 76 +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). 77 +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). 78 +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). 79 + 80 + zlib1222add equ 8 81 + 82 +; Note : these value are good with a 8 bytes boundary pack structure 83 + dep_chain_length equ 74h+zlib1222add 84 + dep_window equ 30h+zlib1222add 85 + dep_strstart equ 64h+zlib1222add 86 + dep_prev_length equ 70h+zlib1222add 87 + dep_nice_match equ 88h+zlib1222add 88 + dep_w_size equ 24h+zlib1222add 89 + dep_prev equ 38h+zlib1222add 90 + dep_w_mask equ 2ch+zlib1222add 91 + dep_good_match equ 84h+zlib1222add 92 + dep_match_start equ 68h+zlib1222add 93 + dep_lookahead equ 6ch+zlib1222add 94 + 95 + 96 +_TEXT segment 97 + 98 +IFDEF NOUNDERLINE 99 + public longest_match 100 + public match_init 101 +ELSE 102 + public _longest_match 103 + public _match_init 104 +ENDIF 105 + 106 + MAX_MATCH equ 258 107 + MIN_MATCH equ 3 108 + MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) 109 + 110 + 111 + 112 +MAX_MATCH equ 258 113 +MIN_MATCH equ 3 114 +MIN_LOOKAHEAD equ (MAX_MATCH + MIN_MATCH + 1) 115 +MAX_MATCH_8_ equ ((MAX_MATCH + 7) AND 0FFF0h) 116 + 117 + 118 +;;; stack frame offsets 119 + 120 +chainlenwmask equ esp + 0 ; high word: current chain len 121 + ; low word: s->wmask 122 +window equ esp + 4 ; local copy of s->window 123 +windowbestlen equ esp + 8 ; s->window + bestlen 124 +scanstart equ esp + 16 ; first two bytes of string 125 +scanend equ esp + 12 ; last two bytes of string 126 +scanalign equ esp + 20 ; dword-misalignment of string 127 +nicematch equ esp + 24 ; a good enough match size 128 +bestlen equ esp + 28 ; size of best match so far 129 +scan equ esp + 32 ; ptr to string wanting match 130 + 131 +LocalVarsSize equ 36 132 +; saved ebx byte esp + 36 133 +; saved edi byte esp + 40 134 +; saved esi byte esp + 44 135 +; saved ebp byte esp + 48 136 +; return address byte esp + 52 137 +deflatestate equ esp + 56 ; the function arguments 138 +curmatch equ esp + 60 139 + 140 +;;; Offsets for fields in the deflate_state structure. These numbers 141 +;;; are calculated from the definition of deflate_state, with the 142 +;;; assumption that the compiler will dword-align the fields. (Thus, 143 +;;; changing the definition of deflate_state could easily cause this 144 +;;; program to crash horribly, without so much as a warning at 145 +;;; compile time. Sigh.) 146 + 147 +dsWSize equ 36+zlib1222add 148 +dsWMask equ 44+zlib1222add 149 +dsWindow equ 48+zlib1222add 150 +dsPrev equ 56+zlib1222add 151 +dsMatchLen equ 88+zlib1222add 152 +dsPrevMatch equ 92+zlib1222add 153 +dsStrStart equ 100+zlib1222add 154 +dsMatchStart equ 104+zlib1222add 155 +dsLookahead equ 108+zlib1222add 156 +dsPrevLen equ 112+zlib1222add 157 +dsMaxChainLen equ 116+zlib1222add 158 +dsGoodMatch equ 132+zlib1222add 159 +dsNiceMatch equ 136+zlib1222add 160 + 161 + 162 +;;; match686.asm -- Pentium-Pro-optimized version of longest_match() 163 +;;; Written for zlib 1.1.2 164 +;;; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com> 165 +;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html 166 +;;; 167 +;; 168 +;; This software is provided 'as-is', without any express or implied 169 +;; warranty. In no event will the authors be held liable for any damages 170 +;; arising from the use of this software. 171 +;; 172 +;; Permission is granted to anyone to use this software for any purpose, 173 +;; including commercial applications, and to alter it and redistribute it 174 +;; freely, subject to the following restrictions: 175 +;; 176 +;; 1. The origin of this software must not be misrepresented; you must not 177 +;; claim that you wrote the original software. If you use this software 178 +;; in a product, an acknowledgment in the product documentation would be 179 +;; appreciated but is not required. 180 +;; 2. Altered source versions must be plainly marked as such, and must not be 181 +;; misrepresented as being the original software 182 +;; 3. This notice may not be removed or altered from any source distribution. 183 +;; 184 + 185 +;GLOBAL _longest_match, _match_init 186 + 187 + 188 +;SECTION .text 189 + 190 +;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch) 191 + 192 +;_longest_match: 193 + IFDEF NOUNDERLINE 194 + longest_match proc near 195 + ELSE 196 + _longest_match proc near 197 + ENDIF 198 +.FPO (9, 4, 0, 0, 1, 0) 199 + 200 +;;; Save registers that the compiler may be using, and adjust esp to 201 +;;; make room for our stack frame. 202 + 203 + push ebp 204 + push edi 205 + push esi 206 + push ebx 207 + sub esp, LocalVarsSize 208 + 209 +;;; Retrieve the function arguments. ecx will hold cur_match 210 +;;; throughout the entire function. edx will hold the pointer to the 211 +;;; deflate_state structure during the function's setup (before 212 +;;; entering the main loop. 213 + 214 + mov edx, [deflatestate] 215 + mov ecx, [curmatch] 216 + 217 +;;; uInt wmask = s->w_mask; 218 +;;; unsigned chain_length = s->max_chain_length; 219 +;;; if (s->prev_length >= s->good_match) { 220 +;;; chain_length >>= 2; 221 +;;; } 222 + 223 + mov eax, [edx + dsPrevLen] 224 + mov ebx, [edx + dsGoodMatch] 225 + cmp eax, ebx 226 + mov eax, [edx + dsWMask] 227 + mov ebx, [edx + dsMaxChainLen] 228 + jl LastMatchGood 229 + shr ebx, 2 230 +LastMatchGood: 231 + 232 +;;; chainlen is decremented once beforehand so that the function can 233 +;;; use the sign flag instead of the zero flag for the exit test. 234 +;;; It is then shifted into the high word, to make room for the wmask 235 +;;; value, which it will always accompany. 236 + 237 + dec ebx 238 + shl ebx, 16 239 + or ebx, eax 240 + mov [chainlenwmask], ebx 241 + 242 +;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; 243 + 244 + mov eax, [edx + dsNiceMatch] 245 + mov ebx, [edx + dsLookahead] 246 + cmp ebx, eax 247 + jl LookaheadLess 248 + mov ebx, eax 249 +LookaheadLess: mov [nicematch], ebx 250 + 251 +;;; register Bytef *scan = s->window + s->strstart; 252 + 253 + mov esi, [edx + dsWindow] 254 + mov [window], esi 255 + mov ebp, [edx + dsStrStart] 256 + lea edi, [esi + ebp] 257 + mov [scan], edi 258 + 259 +;;; Determine how many bytes the scan ptr is off from being 260 +;;; dword-aligned. 261 + 262 + mov eax, edi 263 + neg eax 264 + and eax, 3 265 + mov [scanalign], eax 266 + 267 +;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 268 +;;; s->strstart - (IPos)MAX_DIST(s) : NIL; 269 + 270 + mov eax, [edx + dsWSize] 271 + sub eax, MIN_LOOKAHEAD 272 + sub ebp, eax 273 + jg LimitPositive 274 + xor ebp, ebp 275 +LimitPositive: 276 + 277 +;;; int best_len = s->prev_length; 278 + 279 + mov eax, [edx + dsPrevLen] 280 + mov [bestlen], eax 281 + 282 +;;; Store the sum of s->window + best_len in esi locally, and in esi. 283 + 284 + add esi, eax 285 + mov [windowbestlen], esi 286 + 287 +;;; register ush scan_start = *(ushf*)scan; 288 +;;; register ush scan_end = *(ushf*)(scan+best_len-1); 289 +;;; Posf *prev = s->prev; 290 + 291 + movzx ebx, word ptr [edi] 292 + mov [scanstart], ebx 293 + movzx ebx, word ptr [edi + eax - 1] 294 + mov [scanend], ebx 295 + mov edi, [edx + dsPrev] 296 + 297 +;;; Jump into the main loop. 298 + 299 + mov edx, [chainlenwmask] 300 + jmp short LoopEntry 301 + 302 +align 4 303 + 304 +;;; do { 305 +;;; match = s->window + cur_match; 306 +;;; if (*(ushf*)(match+best_len-1) != scan_end || 307 +;;; *(ushf*)match != scan_start) continue; 308 +;;; [...] 309 +;;; } while ((cur_match = prev[cur_match & wmask]) > limit 310 +;;; && --chain_length != 0); 311 +;;; 312 +;;; Here is the inner loop of the function. The function will spend the 313 +;;; majority of its time in this loop, and majority of that time will 314 +;;; be spent in the first ten instructions. 315 +;;; 316 +;;; Within this loop: 317 +;;; ebx = scanend 318 +;;; ecx = curmatch 319 +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) 320 +;;; esi = windowbestlen - i.e., (window + bestlen) 321 +;;; edi = prev 322 +;;; ebp = limit 323 + 324 +LookupLoop: 325 + and ecx, edx 326 + movzx ecx, word ptr [edi + ecx*2] 327 + cmp ecx, ebp 328 + jbe LeaveNow 329 + sub edx, 00010000h 330 + js LeaveNow 331 +LoopEntry: movzx eax, word ptr [esi + ecx - 1] 332 + cmp eax, ebx 333 + jnz LookupLoop 334 + mov eax, [window] 335 + movzx eax, word ptr [eax + ecx] 336 + cmp eax, [scanstart] 337 + jnz LookupLoop 338 + 339 +;;; Store the current value of chainlen. 340 + 341 + mov [chainlenwmask], edx 342 + 343 +;;; Point edi to the string under scrutiny, and esi to the string we 344 +;;; are hoping to match it up with. In actuality, esi and edi are 345 +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is 346 +;;; initialized to -(MAX_MATCH_8 - scanalign). 347 + 348 + mov esi, [window] 349 + mov edi, [scan] 350 + add esi, ecx 351 + mov eax, [scanalign] 352 + mov edx, 0fffffef8h; -(MAX_MATCH_8) 353 + lea edi, [edi + eax + 0108h] ;MAX_MATCH_8] 354 + lea esi, [esi + eax + 0108h] ;MAX_MATCH_8] 355 + 356 +;;; Test the strings for equality, 8 bytes at a time. At the end, 357 +;;; adjust edx so that it is offset to the exact byte that mismatched. 358 +;;; 359 +;;; We already know at this point that the first three bytes of the 360 +;;; strings match each other, and they can be safely passed over before 361 +;;; starting the compare loop. So what this code does is skip over 0-3 362 +;;; bytes, as much as necessary in order to dword-align the edi 363 +;;; pointer. (esi will still be misaligned three times out of four.) 364 +;;; 365 +;;; It should be confessed that this loop usually does not represent 366 +;;; much of the total running time. Replacing it with a more 367 +;;; straightforward "rep cmpsb" would not drastically degrade 368 +;;; performance. 369 + 370 +LoopCmps: 371 + mov eax, [esi + edx] 372 + xor eax, [edi + edx] 373 + jnz LeaveLoopCmps 374 + mov eax, [esi + edx + 4] 375 + xor eax, [edi + edx + 4] 376 + jnz LeaveLoopCmps4 377 + add edx, 8 378 + jnz LoopCmps 379 + jmp short LenMaximum 380 +LeaveLoopCmps4: add edx, 4 381 +LeaveLoopCmps: test eax, 0000FFFFh 382 + jnz LenLower 383 + add edx, 2 384 + shr eax, 16 385 +LenLower: sub al, 1 386 + adc edx, 0 387 + 388 +;;; Calculate the length of the match. If it is longer than MAX_MATCH, 389 +;;; then automatically accept it as the best possible match and leave. 390 + 391 + lea eax, [edi + edx] 392 + mov edi, [scan] 393 + sub eax, edi 394 + cmp eax, MAX_MATCH 395 + jge LenMaximum 396 + 397 +;;; If the length of the match is not longer than the best match we 398 +;;; have so far, then forget it and return to the lookup loop. 399 + 400 + mov edx, [deflatestate] 401 + mov ebx, [bestlen] 402 + cmp eax, ebx 403 + jg LongerMatch 404 + mov esi, [windowbestlen] 405 + mov edi, [edx + dsPrev] 406 + mov ebx, [scanend] 407 + mov edx, [chainlenwmask] 408 + jmp LookupLoop 409 + 410 +;;; s->match_start = cur_match; 411 +;;; best_len = len; 412 +;;; if (len >= nice_match) break; 413 +;;; scan_end = *(ushf*)(scan+best_len-1); 414 + 415 +LongerMatch: mov ebx, [nicematch] 416 + mov [bestlen], eax 417 + mov [edx + dsMatchStart], ecx 418 + cmp eax, ebx 419 + jge LeaveNow 420 + mov esi, [window] 421 + add esi, eax 422 + mov [windowbestlen], esi 423 + movzx ebx, word ptr [edi + eax - 1] 424 + mov edi, [edx + dsPrev] 425 + mov [scanend], ebx 426 + mov edx, [chainlenwmask] 427 + jmp LookupLoop 428 + 429 +;;; Accept the current string, with the maximum possible length. 430 + 431 +LenMaximum: mov edx, [deflatestate] 432 + mov dword ptr [bestlen], MAX_MATCH 433 + mov [edx + dsMatchStart], ecx 434 + 435 +;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 436 +;;; return s->lookahead; 437 + 438 +LeaveNow: 439 + mov edx, [deflatestate] 440 + mov ebx, [bestlen] 441 + mov eax, [edx + dsLookahead] 442 + cmp ebx, eax 443 + jg LookaheadRet 444 + mov eax, ebx 445 +LookaheadRet: 446 + 447 +;;; Restore the stack and return from whence we came. 448 + 449 + add esp, LocalVarsSize 450 + pop ebx 451 + pop esi 452 + pop edi 453 + pop ebp 454 + 455 + ret 456 +; please don't remove this string ! 457 +; Your can freely use match686 in any free or commercial app if you don't remove the string in the binary! 458 + db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998",0dh,0ah 459 + 460 + 461 + IFDEF NOUNDERLINE 462 + longest_match endp 463 + ELSE 464 + _longest_match endp 465 + ENDIF 466 + 467 + IFDEF NOUNDERLINE 468 + match_init proc near 469 + ret 470 + match_init endp 471 + ELSE 472 + _match_init proc near 473 + ret 474 + _match_init endp 475 + ENDIF 476 + 477 + 478 +_TEXT ends 479 +end
Added compat/zlib/contrib/masmx86/readme.txt.
1 + 2 +Summary 3 +------- 4 +This directory contains ASM implementations of the functions 5 +longest_match() and inflate_fast(). 6 + 7 + 8 +Use instructions 9 +---------------- 10 +Assemble using MASM, and copy the object files into the zlib source 11 +directory, then run the appropriate makefile, as suggested below. You can 12 +donwload MASM from here: 13 + 14 + http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 15 + 16 +You can also get objects files here: 17 + 18 + http://www.winimage.com/zLibDll/zlib124_masm_obj.zip 19 + 20 +Build instructions 21 +------------------ 22 +* With Microsoft C and MASM: 23 +nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" 24 + 25 +* With Borland C and TASM: 26 +make -f win32/Makefile.bor LOCAL_ZLIB="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" OBJPA="+match686c.obj+match686.obj+inffas32.obj" 27 +
Added compat/zlib/contrib/minizip/Makefile.
1 +CC=cc 2 +CFLAGS=-O -I../.. 3 + 4 +UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a 5 +ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a 6 + 7 +.c.o: 8 + $(CC) -c $(CFLAGS) $*.c 9 + 10 +all: miniunz minizip 11 + 12 +miniunz: $(UNZ_OBJS) 13 + $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) 14 + 15 +minizip: $(ZIP_OBJS) 16 + $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) 17 + 18 +test: miniunz minizip 19 + ./minizip test readme.txt 20 + ./miniunz -l test.zip 21 + mv readme.txt readme.old 22 + ./miniunz test.zip 23 + 24 +clean: 25 + /bin/rm -f *.o *~ minizip miniunz
Added compat/zlib/contrib/minizip/Makefile.am.
1 +lib_LTLIBRARIES = libminizip.la 2 + 3 +if COND_DEMOS 4 +bin_PROGRAMS = miniunzip minizip 5 +endif 6 + 7 +zlib_top_srcdir = $(top_srcdir)/../.. 8 +zlib_top_builddir = $(top_builddir)/../.. 9 + 10 +AM_CPPFLAGS = -I$(zlib_top_srcdir) 11 +AM_LDFLAGS = -L$(zlib_top_builddir) 12 + 13 +if WIN32 14 +iowin32_src = iowin32.c 15 +iowin32_h = iowin32.h 16 +endif 17 + 18 +libminizip_la_SOURCES = \ 19 + ioapi.c \ 20 + mztools.c \ 21 + unzip.c \ 22 + zip.c \ 23 + ${iowin32_src} 24 + 25 +libminizip_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:0:0 -lz 26 + 27 +minizip_includedir = $(includedir)/minizip 28 +minizip_include_HEADERS = \ 29 + crypt.h \ 30 + ioapi.h \ 31 + mztools.h \ 32 + unzip.h \ 33 + zip.h \ 34 + ${iowin32_h} 35 + 36 +pkgconfigdir = $(libdir)/pkgconfig 37 +pkgconfig_DATA = minizip.pc 38 + 39 +EXTRA_PROGRAMS = miniunzip minizip 40 + 41 +miniunzip_SOURCES = miniunz.c 42 +miniunzip_LDADD = libminizip.la 43 + 44 +minizip_SOURCES = minizip.c 45 +minizip_LDADD = libminizip.la -lz
Added compat/zlib/contrib/minizip/MiniZip64_Changes.txt.
1 + 2 +MiniZip 1.1 was derrived from MiniZip at version 1.01f 3 + 4 +Change in 1.0 (Okt 2009) 5 + - **TODO - Add history** 6 +
Added compat/zlib/contrib/minizip/MiniZip64_info.txt.
1 +MiniZip - Copyright (c) 1998-2010 - by Gilles Vollant - version 1.1 64 bits from Mathias Svensson 2 + 3 +Introduction 4 +--------------------- 5 +MiniZip 1.1 is built from MiniZip 1.0 by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 +When adding ZIP64 support into minizip it would result into risk of breaking compatibility with minizip 1.0. 8 +All possible work was done for compatibility. 9 + 10 + 11 +Background 12 +--------------------- 13 +When adding ZIP64 support Mathias Svensson found that Even Rouault have added ZIP64 14 +support for unzip.c into minizip for a open source project called gdal ( http://www.gdal.org/ ) 15 + 16 +That was used as a starting point. And after that ZIP64 support was added to zip.c 17 +some refactoring and code cleanup was also done. 18 + 19 + 20 +Changed from MiniZip 1.0 to MiniZip 1.1 21 +--------------------------------------- 22 +* Added ZIP64 support for unzip ( by Even Rouault ) 23 +* Added ZIP64 support for zip ( by Mathias Svensson ) 24 +* Reverted some changed that Even Rouault did. 25 +* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users. 26 +* Added unzip patch for BZIP Compression method (patch create by Daniel Borca) 27 +* Added BZIP Compress method for zip 28 +* Did some refactoring and code cleanup 29 + 30 + 31 +Credits 32 + 33 + Gilles Vollant - Original MiniZip author 34 + Even Rouault - ZIP64 unzip Support 35 + Daniel Borca - BZip Compression method support in unzip 36 + Mathias Svensson - ZIP64 zip support 37 + Mathias Svensson - BZip Compression method support in zip 38 + 39 + Resources 40 + 41 + ZipLayout http://result42.com/projects/ZipFileLayout 42 + Command line tool for Windows that shows the layout and information of the headers in a zip archive. 43 + Used when debugging and validating the creation of zip files using MiniZip64 44 + 45 + 46 + ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT 47 + Zip File specification 48 + 49 + 50 +Notes. 51 + * 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. 52 + 53 +License 54 +---------------------------------------------------------- 55 + Condition of use and distribution are the same than zlib : 56 + 57 + This software is provided 'as-is', without any express or implied 58 + warranty. In no event will the authors be held liable for any damages 59 + arising from the use of this software. 60 + 61 + Permission is granted to anyone to use this software for any purpose, 62 + including commercial applications, and to alter it and redistribute it 63 + freely, subject to the following restrictions: 64 + 65 + 1. The origin of this software must not be misrepresented; you must not 66 + claim that you wrote the original software. If you use this software 67 + in a product, an acknowledgment in the product documentation would be 68 + appreciated but is not required. 69 + 2. Altered source versions must be plainly marked as such, and must not be 70 + misrepresented as being the original software. 71 + 3. This notice may not be removed or altered from any source distribution. 72 + 73 +---------------------------------------------------------- 74 +
Added compat/zlib/contrib/minizip/configure.ac.
1 +# -*- Autoconf -*- 2 +# Process this file with autoconf to produce a configure script. 3 + 4 +AC_INIT([minizip], [1.2.7], [bugzilla.redhat.com]) 5 +AC_CONFIG_SRCDIR([minizip.c]) 6 +AM_INIT_AUTOMAKE([foreign]) 7 +LT_INIT 8 + 9 +AC_MSG_CHECKING([whether to build example programs]) 10 +AC_ARG_ENABLE([demos], AC_HELP_STRING([--enable-demos], [build example programs])) 11 +AM_CONDITIONAL([COND_DEMOS], [test "$enable_demos" = yes]) 12 +if test "$enable_demos" = yes 13 +then 14 + AC_MSG_RESULT([yes]) 15 +else 16 + AC_MSG_RESULT([no]) 17 +fi 18 + 19 +case "${host}" in 20 + *-mingw* | mingw*) 21 + WIN32="yes" 22 + ;; 23 + *) 24 + ;; 25 +esac 26 +AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"]) 27 + 28 + 29 +AC_SUBST([HAVE_UNISTD_H], [0]) 30 +AC_CHECK_HEADER([unistd.h], [HAVE_UNISTD_H=1], []) 31 +AC_CONFIG_FILES([Makefile minizip.pc]) 32 +AC_OUTPUT
Added compat/zlib/contrib/minizip/crypt.h.
1 +/* crypt.h -- base code for crypt/uncrypt ZIPfile 2 + 3 + 4 + Version 1.01e, February 12th, 2005 5 + 6 + Copyright (C) 1998-2005 Gilles Vollant 7 + 8 + This code is a modified version of crypting code in Infozip distribution 9 + 10 + The encryption/decryption parts of this source code (as opposed to the 11 + non-echoing password parts) were originally written in Europe. The 12 + whole source package can be freely distributed, including from the USA. 13 + (Prior to January 2000, re-export from the US was a violation of US law.) 14 + 15 + This encryption code is a direct transcription of the algorithm from 16 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 + file (appnote.txt) is distributed with the PKZIP program (even in the 18 + version without encryption capabilities). 19 + 20 + If you don't need crypting in your application, just define symbols 21 + NOCRYPT and NOUNCRYPT. 22 + 23 + This code support the "Traditional PKWARE Encryption". 24 + 25 + The new AES encryption added on Zip format by Winzip (see the page 26 + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 + Encryption is not supported. 28 +*/ 29 + 30 +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 + 32 +/*********************************************************************** 33 + * Return the next byte in the pseudo-random sequence 34 + */ 35 +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 36 +{ 37 + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 + * unpredictable manner on 16-bit systems; not a problem 39 + * with any known compiler so far, though */ 40 + 41 + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 +} 44 + 45 +/*********************************************************************** 46 + * Update the encryption keys with the next byte of plain text 47 + */ 48 +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 49 +{ 50 + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 + { 54 + register int keyshift = (int)((*(pkeys+1)) >> 24); 55 + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 + } 57 + return c; 58 +} 59 + 60 + 61 +/*********************************************************************** 62 + * Initialize the encryption keys and the random header according to 63 + * the given password. 64 + */ 65 +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 66 +{ 67 + *(pkeys+0) = 305419896L; 68 + *(pkeys+1) = 591751049L; 69 + *(pkeys+2) = 878082192L; 70 + while (*passwd != '\0') { 71 + update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 + passwd++; 73 + } 74 +} 75 + 76 +#define zdecode(pkeys,pcrc_32_tab,c) \ 77 + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 + 79 +#define zencode(pkeys,pcrc_32_tab,c,t) \ 80 + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 + 82 +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 + 84 +#define RAND_HEAD_LEN 12 85 + /* "last resort" source for second part of crypt seed pattern */ 86 +# ifndef ZCR_SEED2 87 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 +# endif 89 + 90 +static int crypthead(const char* passwd, /* password string */ 91 + unsigned char* buf, /* where to write header */ 92 + int bufSize, 93 + unsigned long* pkeys, 94 + const unsigned long* pcrc_32_tab, 95 + unsigned long crcForCrypting) 96 +{ 97 + int n; /* index in random header */ 98 + int t; /* temporary */ 99 + int c; /* random byte */ 100 + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 101 + static unsigned calls = 0; /* ensure different random header each time */ 102 + 103 + if (bufSize<RAND_HEAD_LEN) 104 + return 0; 105 + 106 + /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the 107 + * output of rand() to get less predictability, since rand() is 108 + * often poorly implemented. 109 + */ 110 + if (++calls == 1) 111 + { 112 + srand((unsigned)(time(NULL) ^ ZCR_SEED2)); 113 + } 114 + init_keys(passwd, pkeys, pcrc_32_tab); 115 + for (n = 0; n < RAND_HEAD_LEN-2; n++) 116 + { 117 + c = (rand() >> 7) & 0xff; 118 + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 119 + } 120 + /* Encrypt random header (last two bytes is high word of crc) */ 121 + init_keys(passwd, pkeys, pcrc_32_tab); 122 + for (n = 0; n < RAND_HEAD_LEN-2; n++) 123 + { 124 + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 125 + } 126 + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 127 + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 128 + return n; 129 +} 130 + 131 +#endif
Added compat/zlib/contrib/minizip/ioapi.c.
1 +/* ioapi.h -- IO base function header for compress/uncompress .zip 2 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 + 4 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 + 6 + Modifications for Zip64 support 7 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 + 9 + For more info read MiniZip_info.txt 10 + 11 +*/ 12 + 13 +#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) 14 + #define _CRT_SECURE_NO_WARNINGS 15 +#endif 16 + 17 +#if defined(__APPLE__) || defined(IOAPI_NO_64) 18 +// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions 19 +#define FOPEN_FUNC(filename, mode) fopen(filename, mode) 20 +#define FTELLO_FUNC(stream) ftello(stream) 21 +#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 22 +#else 23 +#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 24 +#define FTELLO_FUNC(stream) ftello64(stream) 25 +#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 26 +#endif 27 + 28 + 29 +#include "ioapi.h" 30 + 31 +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) 32 +{ 33 + if (pfilefunc->zfile_func64.zopen64_file != NULL) 34 + return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); 35 + else 36 + { 37 + return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); 38 + } 39 +} 40 + 41 +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) 42 +{ 43 + if (pfilefunc->zfile_func64.zseek64_file != NULL) 44 + return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); 45 + else 46 + { 47 + uLong offsetTruncated = (uLong)offset; 48 + if (offsetTruncated != offset) 49 + return -1; 50 + else 51 + return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); 52 + } 53 +} 54 + 55 +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) 56 +{ 57 + if (pfilefunc->zfile_func64.zseek64_file != NULL) 58 + return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); 59 + else 60 + { 61 + uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); 62 + if ((tell_uLong) == MAXU32) 63 + return (ZPOS64_T)-1; 64 + else 65 + return tell_uLong; 66 + } 67 +} 68 + 69 +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) 70 +{ 71 + p_filefunc64_32->zfile_func64.zopen64_file = NULL; 72 + p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; 73 + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 74 + p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; 75 + p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; 76 + p_filefunc64_32->zfile_func64.ztell64_file = NULL; 77 + p_filefunc64_32->zfile_func64.zseek64_file = NULL; 78 + p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; 79 + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 80 + p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; 81 + p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; 82 + p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; 83 +} 84 + 85 + 86 + 87 +static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); 88 +static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 89 +static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); 90 +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); 91 +static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 92 +static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); 93 +static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); 94 + 95 +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) 96 +{ 97 + FILE* file = NULL; 98 + const char* mode_fopen = NULL; 99 + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 100 + mode_fopen = "rb"; 101 + else 102 + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 103 + mode_fopen = "r+b"; 104 + else 105 + if (mode & ZLIB_FILEFUNC_MODE_CREATE) 106 + mode_fopen = "wb"; 107 + 108 + if ((filename!=NULL) && (mode_fopen != NULL)) 109 + file = fopen(filename, mode_fopen); 110 + return file; 111 +} 112 + 113 +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) 114 +{ 115 + FILE* file = NULL; 116 + const char* mode_fopen = NULL; 117 + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 118 + mode_fopen = "rb"; 119 + else 120 + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 121 + mode_fopen = "r+b"; 122 + else 123 + if (mode & ZLIB_FILEFUNC_MODE_CREATE) 124 + mode_fopen = "wb"; 125 + 126 + if ((filename!=NULL) && (mode_fopen != NULL)) 127 + file = FOPEN_FUNC((const char*)filename, mode_fopen); 128 + return file; 129 +} 130 + 131 + 132 +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) 133 +{ 134 + uLong ret; 135 + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 136 + return ret; 137 +} 138 + 139 +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) 140 +{ 141 + uLong ret; 142 + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 143 + return ret; 144 +} 145 + 146 +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) 147 +{ 148 + long ret; 149 + ret = ftell((FILE *)stream); 150 + return ret; 151 +} 152 + 153 + 154 +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) 155 +{ 156 + ZPOS64_T ret; 157 + ret = FTELLO_FUNC((FILE *)stream); 158 + return ret; 159 +} 160 + 161 +static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) 162 +{ 163 + int fseek_origin=0; 164 + long ret; 165 + switch (origin) 166 + { 167 + case ZLIB_FILEFUNC_SEEK_CUR : 168 + fseek_origin = SEEK_CUR; 169 + break; 170 + case ZLIB_FILEFUNC_SEEK_END : 171 + fseek_origin = SEEK_END; 172 + break; 173 + case ZLIB_FILEFUNC_SEEK_SET : 174 + fseek_origin = SEEK_SET; 175 + break; 176 + default: return -1; 177 + } 178 + ret = 0; 179 + if (fseek((FILE *)stream, offset, fseek_origin) != 0) 180 + ret = -1; 181 + return ret; 182 +} 183 + 184 +static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) 185 +{ 186 + int fseek_origin=0; 187 + long ret; 188 + switch (origin) 189 + { 190 + case ZLIB_FILEFUNC_SEEK_CUR : 191 + fseek_origin = SEEK_CUR; 192 + break; 193 + case ZLIB_FILEFUNC_SEEK_END : 194 + fseek_origin = SEEK_END; 195 + break; 196 + case ZLIB_FILEFUNC_SEEK_SET : 197 + fseek_origin = SEEK_SET; 198 + break; 199 + default: return -1; 200 + } 201 + ret = 0; 202 + 203 + if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) 204 + ret = -1; 205 + 206 + return ret; 207 +} 208 + 209 + 210 +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) 211 +{ 212 + int ret; 213 + ret = fclose((FILE *)stream); 214 + return ret; 215 +} 216 + 217 +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) 218 +{ 219 + int ret; 220 + ret = ferror((FILE *)stream); 221 + return ret; 222 +} 223 + 224 +void fill_fopen_filefunc (pzlib_filefunc_def) 225 + zlib_filefunc_def* pzlib_filefunc_def; 226 +{ 227 + pzlib_filefunc_def->zopen_file = fopen_file_func; 228 + pzlib_filefunc_def->zread_file = fread_file_func; 229 + pzlib_filefunc_def->zwrite_file = fwrite_file_func; 230 + pzlib_filefunc_def->ztell_file = ftell_file_func; 231 + pzlib_filefunc_def->zseek_file = fseek_file_func; 232 + pzlib_filefunc_def->zclose_file = fclose_file_func; 233 + pzlib_filefunc_def->zerror_file = ferror_file_func; 234 + pzlib_filefunc_def->opaque = NULL; 235 +} 236 + 237 +void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) 238 +{ 239 + pzlib_filefunc_def->zopen64_file = fopen64_file_func; 240 + pzlib_filefunc_def->zread_file = fread_file_func; 241 + pzlib_filefunc_def->zwrite_file = fwrite_file_func; 242 + pzlib_filefunc_def->ztell64_file = ftell64_file_func; 243 + pzlib_filefunc_def->zseek64_file = fseek64_file_func; 244 + pzlib_filefunc_def->zclose_file = fclose_file_func; 245 + pzlib_filefunc_def->zerror_file = ferror_file_func; 246 + pzlib_filefunc_def->opaque = NULL; 247 +}
Added compat/zlib/contrib/minizip/ioapi.h.
1 +/* ioapi.h -- IO base function header for compress/uncompress .zip 2 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 + 4 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 + 6 + Modifications for Zip64 support 7 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 + 9 + For more info read MiniZip_info.txt 10 + 11 + Changes 12 + 13 + 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) 14 + Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. 15 + More if/def section may be needed to support other platforms 16 + Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. 17 + (but you should use iowin32.c for windows instead) 18 + 19 +*/ 20 + 21 +#ifndef _ZLIBIOAPI64_H 22 +#define _ZLIBIOAPI64_H 23 + 24 +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 25 + 26 + // Linux needs this to support file operation on files larger then 4+GB 27 + // But might need better if/def to select just the platforms that needs them. 28 + 29 + #ifndef __USE_FILE_OFFSET64 30 + #define __USE_FILE_OFFSET64 31 + #endif 32 + #ifndef __USE_LARGEFILE64 33 + #define __USE_LARGEFILE64 34 + #endif 35 + #ifndef _LARGEFILE64_SOURCE 36 + #define _LARGEFILE64_SOURCE 37 + #endif 38 + #ifndef _FILE_OFFSET_BIT 39 + #define _FILE_OFFSET_BIT 64 40 + #endif 41 + 42 +#endif 43 + 44 +#include <stdio.h> 45 +#include <stdlib.h> 46 +#include "zlib.h" 47 + 48 +#if defined(USE_FILE32API) 49 +#define fopen64 fopen 50 +#define ftello64 ftell 51 +#define fseeko64 fseek 52 +#else 53 +#ifdef __FreeBSD__ 54 +#define fopen64 fopen 55 +#define ftello64 ftello 56 +#define fseeko64 fseeko 57 +#endif 58 +#ifdef _MSC_VER 59 + #define fopen64 fopen 60 + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 61 + #define ftello64 _ftelli64 62 + #define fseeko64 _fseeki64 63 + #else // old MSC 64 + #define ftello64 ftell 65 + #define fseeko64 fseek 66 + #endif 67 +#endif 68 +#endif 69 + 70 +/* 71 +#ifndef ZPOS64_T 72 + #ifdef _WIN32 73 + #define ZPOS64_T fpos_t 74 + #else 75 + #include <stdint.h> 76 + #define ZPOS64_T uint64_t 77 + #endif 78 +#endif 79 +*/ 80 + 81 +#ifdef HAVE_MINIZIP64_CONF_H 82 +#include "mz64conf.h" 83 +#endif 84 + 85 +/* a type choosen by DEFINE */ 86 +#ifdef HAVE_64BIT_INT_CUSTOM 87 +typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 88 +#else 89 +#ifdef HAS_STDINT_H 90 +#include "stdint.h" 91 +typedef uint64_t ZPOS64_T; 92 +#else 93 + 94 +/* Maximum unsigned 32-bit value used as placeholder for zip64 */ 95 +#define MAXU32 0xffffffff 96 + 97 +#if defined(_MSC_VER) || defined(__BORLANDC__) 98 +typedef unsigned __int64 ZPOS64_T; 99 +#else 100 +typedef unsigned long long int ZPOS64_T; 101 +#endif 102 +#endif 103 +#endif 104 + 105 + 106 + 107 +#ifdef __cplusplus 108 +extern "C" { 109 +#endif 110 + 111 + 112 +#define ZLIB_FILEFUNC_SEEK_CUR (1) 113 +#define ZLIB_FILEFUNC_SEEK_END (2) 114 +#define ZLIB_FILEFUNC_SEEK_SET (0) 115 + 116 +#define ZLIB_FILEFUNC_MODE_READ (1) 117 +#define ZLIB_FILEFUNC_MODE_WRITE (2) 118 +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 119 + 120 +#define ZLIB_FILEFUNC_MODE_EXISTING (4) 121 +#define ZLIB_FILEFUNC_MODE_CREATE (8) 122 + 123 + 124 +#ifndef ZCALLBACK 125 + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 126 + #define ZCALLBACK CALLBACK 127 + #else 128 + #define ZCALLBACK 129 + #endif 130 +#endif 131 + 132 + 133 + 134 + 135 +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 136 +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 137 +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 138 +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 139 +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 140 + 141 +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 142 +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 143 + 144 + 145 +/* here is the "old" 32 bits structure structure */ 146 +typedef struct zlib_filefunc_def_s 147 +{ 148 + open_file_func zopen_file; 149 + read_file_func zread_file; 150 + write_file_func zwrite_file; 151 + tell_file_func ztell_file; 152 + seek_file_func zseek_file; 153 + close_file_func zclose_file; 154 + testerror_file_func zerror_file; 155 + voidpf opaque; 156 +} zlib_filefunc_def; 157 + 158 +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 159 +typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 160 +typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 161 + 162 +typedef struct zlib_filefunc64_def_s 163 +{ 164 + open64_file_func zopen64_file; 165 + read_file_func zread_file; 166 + write_file_func zwrite_file; 167 + tell64_file_func ztell64_file; 168 + seek64_file_func zseek64_file; 169 + close_file_func zclose_file; 170 + testerror_file_func zerror_file; 171 + voidpf opaque; 172 +} zlib_filefunc64_def; 173 + 174 +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 175 +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 176 + 177 +/* now internal definition, only for zip.c and unzip.h */ 178 +typedef struct zlib_filefunc64_32_def_s 179 +{ 180 + zlib_filefunc64_def zfile_func64; 181 + open_file_func zopen32_file; 182 + tell_file_func ztell32_file; 183 + seek_file_func zseek32_file; 184 +} zlib_filefunc64_32_def; 185 + 186 + 187 +#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 188 +#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 189 +//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) 190 +//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) 191 +#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 192 +#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 193 + 194 +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 195 +long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 196 +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 197 + 198 +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); 199 + 200 +#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 201 +#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 202 +#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 203 + 204 +#ifdef __cplusplus 205 +} 206 +#endif 207 + 208 +#endif
Added compat/zlib/contrib/minizip/iowin32.c.
1 +/* iowin32.c -- IO base function header for compress/uncompress .zip 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications for Zip64 support 8 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 9 + 10 + For more info read MiniZip_info.txt 11 + 12 +*/ 13 + 14 +#include <stdlib.h> 15 + 16 +#include "zlib.h" 17 +#include "ioapi.h" 18 +#include "iowin32.h" 19 + 20 +#ifndef INVALID_HANDLE_VALUE 21 +#define INVALID_HANDLE_VALUE (0xFFFFFFFF) 22 +#endif 23 + 24 +#ifndef INVALID_SET_FILE_POINTER 25 +#define INVALID_SET_FILE_POINTER ((DWORD)-1) 26 +#endif 27 + 28 +voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); 29 +uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 30 +uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 31 +ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); 32 +long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 33 +int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); 34 +int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); 35 + 36 +typedef struct 37 +{ 38 + HANDLE hf; 39 + int error; 40 +} WIN32FILE_IOWIN; 41 + 42 + 43 +static void win32_translate_open_mode(int mode, 44 + DWORD* lpdwDesiredAccess, 45 + DWORD* lpdwCreationDisposition, 46 + DWORD* lpdwShareMode, 47 + DWORD* lpdwFlagsAndAttributes) 48 +{ 49 + *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; 50 + 51 + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 52 + { 53 + *lpdwDesiredAccess = GENERIC_READ; 54 + *lpdwCreationDisposition = OPEN_EXISTING; 55 + *lpdwShareMode = FILE_SHARE_READ; 56 + } 57 + else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 58 + { 59 + *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 60 + *lpdwCreationDisposition = OPEN_EXISTING; 61 + } 62 + else if (mode & ZLIB_FILEFUNC_MODE_CREATE) 63 + { 64 + *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 65 + *lpdwCreationDisposition = CREATE_ALWAYS; 66 + } 67 +} 68 + 69 +static voidpf win32_build_iowin(HANDLE hFile) 70 +{ 71 + voidpf ret=NULL; 72 + 73 + if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) 74 + { 75 + WIN32FILE_IOWIN w32fiow; 76 + w32fiow.hf = hFile; 77 + w32fiow.error = 0; 78 + ret = malloc(sizeof(WIN32FILE_IOWIN)); 79 + 80 + if (ret==NULL) 81 + CloseHandle(hFile); 82 + else 83 + *((WIN32FILE_IOWIN*)ret) = w32fiow; 84 + } 85 + return ret; 86 +} 87 + 88 +voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) 89 +{ 90 + const char* mode_fopen = NULL; 91 + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 92 + HANDLE hFile = NULL; 93 + 94 + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); 95 + 96 + if ((filename!=NULL) && (dwDesiredAccess != 0)) 97 + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); 98 + 99 + return win32_build_iowin(hFile); 100 +} 101 + 102 + 103 +voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) 104 +{ 105 + const char* mode_fopen = NULL; 106 + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 107 + HANDLE hFile = NULL; 108 + 109 + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); 110 + 111 + if ((filename!=NULL) && (dwDesiredAccess != 0)) 112 + hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); 113 + 114 + return win32_build_iowin(hFile); 115 +} 116 + 117 + 118 +voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) 119 +{ 120 + const char* mode_fopen = NULL; 121 + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 122 + HANDLE hFile = NULL; 123 + 124 + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); 125 + 126 + if ((filename!=NULL) && (dwDesiredAccess != 0)) 127 + hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); 128 + 129 + return win32_build_iowin(hFile); 130 +} 131 + 132 + 133 +voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) 134 +{ 135 + const char* mode_fopen = NULL; 136 + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 137 + HANDLE hFile = NULL; 138 + 139 + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); 140 + 141 + if ((filename!=NULL) && (dwDesiredAccess != 0)) 142 + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); 143 + 144 + return win32_build_iowin(hFile); 145 +} 146 + 147 + 148 +uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size) 149 +{ 150 + uLong ret=0; 151 + HANDLE hFile = NULL; 152 + if (stream!=NULL) 153 + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 154 + 155 + if (hFile != NULL) 156 + { 157 + if (!ReadFile(hFile, buf, size, &ret, NULL)) 158 + { 159 + DWORD dwErr = GetLastError(); 160 + if (dwErr == ERROR_HANDLE_EOF) 161 + dwErr = 0; 162 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 163 + } 164 + } 165 + 166 + return ret; 167 +} 168 + 169 + 170 +uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) 171 +{ 172 + uLong ret=0; 173 + HANDLE hFile = NULL; 174 + if (stream!=NULL) 175 + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 176 + 177 + if (hFile != NULL) 178 + { 179 + if (!WriteFile(hFile, buf, size, &ret, NULL)) 180 + { 181 + DWORD dwErr = GetLastError(); 182 + if (dwErr == ERROR_HANDLE_EOF) 183 + dwErr = 0; 184 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 185 + } 186 + } 187 + 188 + return ret; 189 +} 190 + 191 +long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) 192 +{ 193 + long ret=-1; 194 + HANDLE hFile = NULL; 195 + if (stream!=NULL) 196 + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 197 + if (hFile != NULL) 198 + { 199 + DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); 200 + if (dwSet == INVALID_SET_FILE_POINTER) 201 + { 202 + DWORD dwErr = GetLastError(); 203 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 204 + ret = -1; 205 + } 206 + else 207 + ret=(long)dwSet; 208 + } 209 + return ret; 210 +} 211 + 212 +ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) 213 +{ 214 + ZPOS64_T ret= (ZPOS64_T)-1; 215 + HANDLE hFile = NULL; 216 + if (stream!=NULL) 217 + hFile = ((WIN32FILE_IOWIN*)stream)->hf; 218 + 219 + if (hFile) 220 + { 221 + LARGE_INTEGER li; 222 + li.QuadPart = 0; 223 + li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT); 224 + if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) 225 + { 226 + DWORD dwErr = GetLastError(); 227 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 228 + ret = (ZPOS64_T)-1; 229 + } 230 + else 231 + ret=li.QuadPart; 232 + } 233 + return ret; 234 +} 235 + 236 + 237 +long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) 238 +{ 239 + DWORD dwMoveMethod=0xFFFFFFFF; 240 + HANDLE hFile = NULL; 241 + 242 + long ret=-1; 243 + if (stream!=NULL) 244 + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 245 + switch (origin) 246 + { 247 + case ZLIB_FILEFUNC_SEEK_CUR : 248 + dwMoveMethod = FILE_CURRENT; 249 + break; 250 + case ZLIB_FILEFUNC_SEEK_END : 251 + dwMoveMethod = FILE_END; 252 + break; 253 + case ZLIB_FILEFUNC_SEEK_SET : 254 + dwMoveMethod = FILE_BEGIN; 255 + break; 256 + default: return -1; 257 + } 258 + 259 + if (hFile != NULL) 260 + { 261 + DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); 262 + if (dwSet == INVALID_SET_FILE_POINTER) 263 + { 264 + DWORD dwErr = GetLastError(); 265 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 266 + ret = -1; 267 + } 268 + else 269 + ret=0; 270 + } 271 + return ret; 272 +} 273 + 274 +long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) 275 +{ 276 + DWORD dwMoveMethod=0xFFFFFFFF; 277 + HANDLE hFile = NULL; 278 + long ret=-1; 279 + 280 + if (stream!=NULL) 281 + hFile = ((WIN32FILE_IOWIN*)stream)->hf; 282 + 283 + switch (origin) 284 + { 285 + case ZLIB_FILEFUNC_SEEK_CUR : 286 + dwMoveMethod = FILE_CURRENT; 287 + break; 288 + case ZLIB_FILEFUNC_SEEK_END : 289 + dwMoveMethod = FILE_END; 290 + break; 291 + case ZLIB_FILEFUNC_SEEK_SET : 292 + dwMoveMethod = FILE_BEGIN; 293 + break; 294 + default: return -1; 295 + } 296 + 297 + if (hFile) 298 + { 299 + LARGE_INTEGER* li = (LARGE_INTEGER*)&offset; 300 + DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod); 301 + if (dwSet == INVALID_SET_FILE_POINTER) 302 + { 303 + DWORD dwErr = GetLastError(); 304 + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 305 + ret = -1; 306 + } 307 + else 308 + ret=0; 309 + } 310 + return ret; 311 +} 312 + 313 +int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream) 314 +{ 315 + int ret=-1; 316 + 317 + if (stream!=NULL) 318 + { 319 + HANDLE hFile; 320 + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 321 + if (hFile != NULL) 322 + { 323 + CloseHandle(hFile); 324 + ret=0; 325 + } 326 + free(stream); 327 + } 328 + return ret; 329 +} 330 + 331 +int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) 332 +{ 333 + int ret=-1; 334 + if (stream!=NULL) 335 + { 336 + ret = ((WIN32FILE_IOWIN*)stream) -> error; 337 + } 338 + return ret; 339 +} 340 + 341 +void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) 342 +{ 343 + pzlib_filefunc_def->zopen_file = win32_open_file_func; 344 + pzlib_filefunc_def->zread_file = win32_read_file_func; 345 + pzlib_filefunc_def->zwrite_file = win32_write_file_func; 346 + pzlib_filefunc_def->ztell_file = win32_tell_file_func; 347 + pzlib_filefunc_def->zseek_file = win32_seek_file_func; 348 + pzlib_filefunc_def->zclose_file = win32_close_file_func; 349 + pzlib_filefunc_def->zerror_file = win32_error_file_func; 350 + pzlib_filefunc_def->opaque = NULL; 351 +} 352 + 353 +void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) 354 +{ 355 + pzlib_filefunc_def->zopen64_file = win32_open64_file_func; 356 + pzlib_filefunc_def->zread_file = win32_read_file_func; 357 + pzlib_filefunc_def->zwrite_file = win32_write_file_func; 358 + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; 359 + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; 360 + pzlib_filefunc_def->zclose_file = win32_close_file_func; 361 + pzlib_filefunc_def->zerror_file = win32_error_file_func; 362 + pzlib_filefunc_def->opaque = NULL; 363 +} 364 + 365 + 366 +void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) 367 +{ 368 + pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; 369 + pzlib_filefunc_def->zread_file = win32_read_file_func; 370 + pzlib_filefunc_def->zwrite_file = win32_write_file_func; 371 + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; 372 + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; 373 + pzlib_filefunc_def->zclose_file = win32_close_file_func; 374 + pzlib_filefunc_def->zerror_file = win32_error_file_func; 375 + pzlib_filefunc_def->opaque = NULL; 376 +} 377 + 378 + 379 +void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) 380 +{ 381 + pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; 382 + pzlib_filefunc_def->zread_file = win32_read_file_func; 383 + pzlib_filefunc_def->zwrite_file = win32_write_file_func; 384 + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; 385 + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; 386 + pzlib_filefunc_def->zclose_file = win32_close_file_func; 387 + pzlib_filefunc_def->zerror_file = win32_error_file_func; 388 + pzlib_filefunc_def->opaque = NULL; 389 +}
Added compat/zlib/contrib/minizip/iowin32.h.
1 +/* iowin32.h -- IO base function header for compress/uncompress .zip 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications for Zip64 support 8 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 9 + 10 + For more info read MiniZip_info.txt 11 + 12 +*/ 13 + 14 +#include <windows.h> 15 + 16 + 17 +#ifdef __cplusplus 18 +extern "C" { 19 +#endif 20 + 21 +void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 22 +void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def)); 23 +void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def)); 24 +void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def)); 25 + 26 +#ifdef __cplusplus 27 +} 28 +#endif
Added compat/zlib/contrib/minizip/make_vms.com.
1 +$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig 2 +$ open/write zdef vmsdefs.h 3 +$ copy sys$input: zdef 4 +$ deck 5 +#define unix 6 +#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from 7 +#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator 8 +#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord 9 +#define Write_EndOfCentralDirectoryRecord Write_EoDRecord 10 +$ eod 11 +$ close zdef 12 +$ copy vmsdefs.h,ioapi.h_orig ioapi.h 13 +$ cc/include=[--]/prefix=all ioapi.c 14 +$ cc/include=[--]/prefix=all miniunz.c 15 +$ cc/include=[--]/prefix=all unzip.c 16 +$ cc/include=[--]/prefix=all minizip.c 17 +$ cc/include=[--]/prefix=all zip.c 18 +$ link miniunz,unzip,ioapi,[--]libz.olb/lib 19 +$ link minizip,zip,ioapi,[--]libz.olb/lib 20 +$ mcr []minizip test minizip_info.txt 21 +$ mcr []miniunz -l test.zip 22 +$ rename minizip_info.txt; minizip_info.txt_old 23 +$ mcr []miniunz test.zip 24 +$ delete test.zip;* 25 +$exit
Added compat/zlib/contrib/minizip/miniunz.c.
1 +/* 2 + miniunz.c 3 + Version 1.1, February 14h, 2010 4 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 5 + 6 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 7 + 8 + Modifications of Unzip for Zip64 9 + Copyright (C) 2007-2008 Even Rouault 10 + 11 + Modifications for Zip64 support on both zip and unzip 12 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 13 +*/ 14 + 15 +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 16 + #ifndef __USE_FILE_OFFSET64 17 + #define __USE_FILE_OFFSET64 18 + #endif 19 + #ifndef __USE_LARGEFILE64 20 + #define __USE_LARGEFILE64 21 + #endif 22 + #ifndef _LARGEFILE64_SOURCE 23 + #define _LARGEFILE64_SOURCE 24 + #endif 25 + #ifndef _FILE_OFFSET_BIT 26 + #define _FILE_OFFSET_BIT 64 27 + #endif 28 +#endif 29 + 30 +#ifdef __APPLE__ 31 +// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions 32 +#define FOPEN_FUNC(filename, mode) fopen(filename, mode) 33 +#define FTELLO_FUNC(stream) ftello(stream) 34 +#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 35 +#else 36 +#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 37 +#define FTELLO_FUNC(stream) ftello64(stream) 38 +#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 39 +#endif 40 + 41 + 42 +#include <stdio.h> 43 +#include <stdlib.h> 44 +#include <string.h> 45 +#include <time.h> 46 +#include <errno.h> 47 +#include <fcntl.h> 48 + 49 +#ifdef _WIN32 50 +# include <direct.h> 51 +# include <io.h> 52 +#else 53 +# include <unistd.h> 54 +# include <utime.h> 55 +#endif 56 + 57 + 58 +#include "unzip.h" 59 + 60 +#define CASESENSITIVITY (0) 61 +#define WRITEBUFFERSIZE (8192) 62 +#define MAXFILENAME (256) 63 + 64 +#ifdef _WIN32 65 +#define USEWIN32IOAPI 66 +#include "iowin32.h" 67 +#endif 68 +/* 69 + mini unzip, demo of unzip package 70 + 71 + usage : 72 + Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] 73 + 74 + list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT 75 + if it exists 76 +*/ 77 + 78 + 79 +/* change_file_date : change the date/time of a file 80 + filename : the filename of the file where date/time must be modified 81 + dosdate : the new date at the MSDos format (4 bytes) 82 + tmu_date : the SAME new date at the tm_unz format */ 83 +void change_file_date(filename,dosdate,tmu_date) 84 + const char *filename; 85 + uLong dosdate; 86 + tm_unz tmu_date; 87 +{ 88 +#ifdef _WIN32 89 + HANDLE hFile; 90 + FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; 91 + 92 + hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, 93 + 0,NULL,OPEN_EXISTING,0,NULL); 94 + GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); 95 + DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); 96 + LocalFileTimeToFileTime(&ftLocal,&ftm); 97 + SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); 98 + CloseHandle(hFile); 99 +#else 100 +#ifdef unix || __APPLE__ 101 + struct utimbuf ut; 102 + struct tm newdate; 103 + newdate.tm_sec = tmu_date.tm_sec; 104 + newdate.tm_min=tmu_date.tm_min; 105 + newdate.tm_hour=tmu_date.tm_hour; 106 + newdate.tm_mday=tmu_date.tm_mday; 107 + newdate.tm_mon=tmu_date.tm_mon; 108 + if (tmu_date.tm_year > 1900) 109 + newdate.tm_year=tmu_date.tm_year - 1900; 110 + else 111 + newdate.tm_year=tmu_date.tm_year ; 112 + newdate.tm_isdst=-1; 113 + 114 + ut.actime=ut.modtime=mktime(&newdate); 115 + utime(filename,&ut); 116 +#endif 117 +#endif 118 +} 119 + 120 + 121 +/* mymkdir and change_file_date are not 100 % portable 122 + As I don't know well Unix, I wait feedback for the unix portion */ 123 + 124 +int mymkdir(dirname) 125 + const char* dirname; 126 +{ 127 + int ret=0; 128 +#ifdef _WIN32 129 + ret = _mkdir(dirname); 130 +#elif unix 131 + ret = mkdir (dirname,0775); 132 +#elif __APPLE__ 133 + ret = mkdir (dirname,0775); 134 +#endif 135 + return ret; 136 +} 137 + 138 +int makedir (newdir) 139 + char *newdir; 140 +{ 141 + char *buffer ; 142 + char *p; 143 + int len = (int)strlen(newdir); 144 + 145 + if (len <= 0) 146 + return 0; 147 + 148 + buffer = (char*)malloc(len+1); 149 + if (buffer==NULL) 150 + { 151 + printf("Error allocating memory\n"); 152 + return UNZ_INTERNALERROR; 153 + } 154 + strcpy(buffer,newdir); 155 + 156 + if (buffer[len-1] == '/') { 157 + buffer[len-1] = '\0'; 158 + } 159 + if (mymkdir(buffer) == 0) 160 + { 161 + free(buffer); 162 + return 1; 163 + } 164 + 165 + p = buffer+1; 166 + while (1) 167 + { 168 + char hold; 169 + 170 + while(*p && *p != '\\' && *p != '/') 171 + p++; 172 + hold = *p; 173 + *p = 0; 174 + if ((mymkdir(buffer) == -1) && (errno == ENOENT)) 175 + { 176 + printf("couldn't create directory %s\n",buffer); 177 + free(buffer); 178 + return 0; 179 + } 180 + if (hold == 0) 181 + break; 182 + *p++ = hold; 183 + } 184 + free(buffer); 185 + return 1; 186 +} 187 + 188 +void do_banner() 189 +{ 190 + printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); 191 + printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); 192 +} 193 + 194 +void do_help() 195 +{ 196 + printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ 197 + " -e Extract without pathname (junk paths)\n" \ 198 + " -x Extract with pathname\n" \ 199 + " -v list files\n" \ 200 + " -l list files\n" \ 201 + " -d directory to extract into\n" \ 202 + " -o overwrite files without prompting\n" \ 203 + " -p extract crypted file using password\n\n"); 204 +} 205 + 206 +void Display64BitsSize(ZPOS64_T n, int size_char) 207 +{ 208 + /* to avoid compatibility problem , we do here the conversion */ 209 + char number[21]; 210 + int offset=19; 211 + int pos_string = 19; 212 + number[20]=0; 213 + for (;;) { 214 + number[offset]=(char)((n%10)+'0'); 215 + if (number[offset] != '0') 216 + pos_string=offset; 217 + n/=10; 218 + if (offset==0) 219 + break; 220 + offset--; 221 + } 222 + { 223 + int size_display_string = 19-pos_string; 224 + while (size_char > size_display_string) 225 + { 226 + size_char--; 227 + printf(" "); 228 + } 229 + } 230 + 231 + printf("%s",&number[pos_string]); 232 +} 233 + 234 +int do_list(uf) 235 + unzFile uf; 236 +{ 237 + uLong i; 238 + unz_global_info64 gi; 239 + int err; 240 + 241 + err = unzGetGlobalInfo64(uf,&gi); 242 + if (err!=UNZ_OK) 243 + printf("error %d with zipfile in unzGetGlobalInfo \n",err); 244 + printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); 245 + printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); 246 + for (i=0;i<gi.number_entry;i++) 247 + { 248 + char filename_inzip[256]; 249 + unz_file_info64 file_info; 250 + uLong ratio=0; 251 + const char *string_method; 252 + char charCrypt=' '; 253 + err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 254 + if (err!=UNZ_OK) 255 + { 256 + printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 257 + break; 258 + } 259 + if (file_info.uncompressed_size>0) 260 + ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); 261 + 262 + /* display a '*' if the file is crypted */ 263 + if ((file_info.flag & 1) != 0) 264 + charCrypt='*'; 265 + 266 + if (file_info.compression_method==0) 267 + string_method="Stored"; 268 + else 269 + if (file_info.compression_method==Z_DEFLATED) 270 + { 271 + uInt iLevel=(uInt)((file_info.flag & 0x6)/2); 272 + if (iLevel==0) 273 + string_method="Defl:N"; 274 + else if (iLevel==1) 275 + string_method="Defl:X"; 276 + else if ((iLevel==2) || (iLevel==3)) 277 + string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ 278 + } 279 + else 280 + if (file_info.compression_method==Z_BZIP2ED) 281 + { 282 + string_method="BZip2 "; 283 + } 284 + else 285 + string_method="Unkn. "; 286 + 287 + Display64BitsSize(file_info.uncompressed_size,7); 288 + printf(" %6s%c",string_method,charCrypt); 289 + Display64BitsSize(file_info.compressed_size,7); 290 + printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", 291 + ratio, 292 + (uLong)file_info.tmu_date.tm_mon + 1, 293 + (uLong)file_info.tmu_date.tm_mday, 294 + (uLong)file_info.tmu_date.tm_year % 100, 295 + (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, 296 + (uLong)file_info.crc,filename_inzip); 297 + if ((i+1)<gi.number_entry) 298 + { 299 + err = unzGoToNextFile(uf); 300 + if (err!=UNZ_OK) 301 + { 302 + printf("error %d with zipfile in unzGoToNextFile\n",err); 303 + break; 304 + } 305 + } 306 + } 307 + 308 + return 0; 309 +} 310 + 311 + 312 +int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) 313 + unzFile uf; 314 + const int* popt_extract_without_path; 315 + int* popt_overwrite; 316 + const char* password; 317 +{ 318 + char filename_inzip[256]; 319 + char* filename_withoutpath; 320 + char* p; 321 + int err=UNZ_OK; 322 + FILE *fout=NULL; 323 + void* buf; 324 + uInt size_buf; 325 + 326 + unz_file_info64 file_info; 327 + uLong ratio=0; 328 + err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 329 + 330 + if (err!=UNZ_OK) 331 + { 332 + printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 333 + return err; 334 + } 335 + 336 + size_buf = WRITEBUFFERSIZE; 337 + buf = (void*)malloc(size_buf); 338 + if (buf==NULL) 339 + { 340 + printf("Error allocating memory\n"); 341 + return UNZ_INTERNALERROR; 342 + } 343 + 344 + p = filename_withoutpath = filename_inzip; 345 + while ((*p) != '\0') 346 + { 347 + if (((*p)=='/') || ((*p)=='\\')) 348 + filename_withoutpath = p+1; 349 + p++; 350 + } 351 + 352 + if ((*filename_withoutpath)=='\0') 353 + { 354 + if ((*popt_extract_without_path)==0) 355 + { 356 + printf("creating directory: %s\n",filename_inzip); 357 + mymkdir(filename_inzip); 358 + } 359 + } 360 + else 361 + { 362 + const char* write_filename; 363 + int skip=0; 364 + 365 + if ((*popt_extract_without_path)==0) 366 + write_filename = filename_inzip; 367 + else 368 + write_filename = filename_withoutpath; 369 + 370 + err = unzOpenCurrentFilePassword(uf,password); 371 + if (err!=UNZ_OK) 372 + { 373 + printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); 374 + } 375 + 376 + if (((*popt_overwrite)==0) && (err==UNZ_OK)) 377 + { 378 + char rep=0; 379 + FILE* ftestexist; 380 + ftestexist = FOPEN_FUNC(write_filename,"rb"); 381 + if (ftestexist!=NULL) 382 + { 383 + fclose(ftestexist); 384 + do 385 + { 386 + char answer[128]; 387 + int ret; 388 + 389 + printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); 390 + ret = scanf("%1s",answer); 391 + if (ret != 1) 392 + { 393 + exit(EXIT_FAILURE); 394 + } 395 + rep = answer[0] ; 396 + if ((rep>='a') && (rep<='z')) 397 + rep -= 0x20; 398 + } 399 + while ((rep!='Y') && (rep!='N') && (rep!='A')); 400 + } 401 + 402 + if (rep == 'N') 403 + skip = 1; 404 + 405 + if (rep == 'A') 406 + *popt_overwrite=1; 407 + } 408 + 409 + if ((skip==0) && (err==UNZ_OK)) 410 + { 411 + fout=FOPEN_FUNC(write_filename,"wb"); 412 + /* some zipfile don't contain directory alone before file */ 413 + if ((fout==NULL) && ((*popt_extract_without_path)==0) && 414 + (filename_withoutpath!=(char*)filename_inzip)) 415 + { 416 + char c=*(filename_withoutpath-1); 417 + *(filename_withoutpath-1)='\0'; 418 + makedir(write_filename); 419 + *(filename_withoutpath-1)=c; 420 + fout=FOPEN_FUNC(write_filename,"wb"); 421 + } 422 + 423 + if (fout==NULL) 424 + { 425 + printf("error opening %s\n",write_filename); 426 + } 427 + } 428 + 429 + if (fout!=NULL) 430 + { 431 + printf(" extracting: %s\n",write_filename); 432 + 433 + do 434 + { 435 + err = unzReadCurrentFile(uf,buf,size_buf); 436 + if (err<0) 437 + { 438 + printf("error %d with zipfile in unzReadCurrentFile\n",err); 439 + break; 440 + } 441 + if (err>0) 442 + if (fwrite(buf,err,1,fout)!=1) 443 + { 444 + printf("error in writing extracted file\n"); 445 + err=UNZ_ERRNO; 446 + break; 447 + } 448 + } 449 + while (err>0); 450 + if (fout) 451 + fclose(fout); 452 + 453 + if (err==0) 454 + change_file_date(write_filename,file_info.dosDate, 455 + file_info.tmu_date); 456 + } 457 + 458 + if (err==UNZ_OK) 459 + { 460 + err = unzCloseCurrentFile (uf); 461 + if (err!=UNZ_OK) 462 + { 463 + printf("error %d with zipfile in unzCloseCurrentFile\n",err); 464 + } 465 + } 466 + else 467 + unzCloseCurrentFile(uf); /* don't lose the error */ 468 + } 469 + 470 + free(buf); 471 + return err; 472 +} 473 + 474 + 475 +int do_extract(uf,opt_extract_without_path,opt_overwrite,password) 476 + unzFile uf; 477 + int opt_extract_without_path; 478 + int opt_overwrite; 479 + const char* password; 480 +{ 481 + uLong i; 482 + unz_global_info64 gi; 483 + int err; 484 + FILE* fout=NULL; 485 + 486 + err = unzGetGlobalInfo64(uf,&gi); 487 + if (err!=UNZ_OK) 488 + printf("error %d with zipfile in unzGetGlobalInfo \n",err); 489 + 490 + for (i=0;i<gi.number_entry;i++) 491 + { 492 + if (do_extract_currentfile(uf,&opt_extract_without_path, 493 + &opt_overwrite, 494 + password) != UNZ_OK) 495 + break; 496 + 497 + if ((i+1)<gi.number_entry) 498 + { 499 + err = unzGoToNextFile(uf); 500 + if (err!=UNZ_OK) 501 + { 502 + printf("error %d with zipfile in unzGoToNextFile\n",err); 503 + break; 504 + } 505 + } 506 + } 507 + 508 + return 0; 509 +} 510 + 511 +int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password) 512 + unzFile uf; 513 + const char* filename; 514 + int opt_extract_without_path; 515 + int opt_overwrite; 516 + const char* password; 517 +{ 518 + int err = UNZ_OK; 519 + if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) 520 + { 521 + printf("file %s not found in the zipfile\n",filename); 522 + return 2; 523 + } 524 + 525 + if (do_extract_currentfile(uf,&opt_extract_without_path, 526 + &opt_overwrite, 527 + password) == UNZ_OK) 528 + return 0; 529 + else 530 + return 1; 531 +} 532 + 533 + 534 +int main(argc,argv) 535 + int argc; 536 + char *argv[]; 537 +{ 538 + const char *zipfilename=NULL; 539 + const char *filename_to_extract=NULL; 540 + const char *password=NULL; 541 + char filename_try[MAXFILENAME+16] = ""; 542 + int i; 543 + int ret_value=0; 544 + int opt_do_list=0; 545 + int opt_do_extract=1; 546 + int opt_do_extract_withoutpath=0; 547 + int opt_overwrite=0; 548 + int opt_extractdir=0; 549 + const char *dirname=NULL; 550 + unzFile uf=NULL; 551 + 552 + do_banner(); 553 + if (argc==1) 554 + { 555 + do_help(); 556 + return 0; 557 + } 558 + else 559 + { 560 + for (i=1;i<argc;i++) 561 + { 562 + if ((*argv[i])=='-') 563 + { 564 + const char *p=argv[i]+1; 565 + 566 + while ((*p)!='\0') 567 + { 568 + char c=*(p++);; 569 + if ((c=='l') || (c=='L')) 570 + opt_do_list = 1; 571 + if ((c=='v') || (c=='V')) 572 + opt_do_list = 1; 573 + if ((c=='x') || (c=='X')) 574 + opt_do_extract = 1; 575 + if ((c=='e') || (c=='E')) 576 + opt_do_extract = opt_do_extract_withoutpath = 1; 577 + if ((c=='o') || (c=='O')) 578 + opt_overwrite=1; 579 + if ((c=='d') || (c=='D')) 580 + { 581 + opt_extractdir=1; 582 + dirname=argv[i+1]; 583 + } 584 + 585 + if (((c=='p') || (c=='P')) && (i+1<argc)) 586 + { 587 + password=argv[i+1]; 588 + i++; 589 + } 590 + } 591 + } 592 + else 593 + { 594 + if (zipfilename == NULL) 595 + zipfilename = argv[i]; 596 + else if ((filename_to_extract==NULL) && (!opt_extractdir)) 597 + filename_to_extract = argv[i] ; 598 + } 599 + } 600 + } 601 + 602 + if (zipfilename!=NULL) 603 + { 604 + 605 +# ifdef USEWIN32IOAPI 606 + zlib_filefunc64_def ffunc; 607 +# endif 608 + 609 + strncpy(filename_try, zipfilename,MAXFILENAME-1); 610 + /* strncpy doesnt append the trailing NULL, of the string is too long. */ 611 + filename_try[ MAXFILENAME ] = '\0'; 612 + 613 +# ifdef USEWIN32IOAPI 614 + fill_win32_filefunc64A(&ffunc); 615 + uf = unzOpen2_64(zipfilename,&ffunc); 616 +# else 617 + uf = unzOpen64(zipfilename); 618 +# endif 619 + if (uf==NULL) 620 + { 621 + strcat(filename_try,".zip"); 622 +# ifdef USEWIN32IOAPI 623 + uf = unzOpen2_64(filename_try,&ffunc); 624 +# else 625 + uf = unzOpen64(filename_try); 626 +# endif 627 + } 628 + } 629 + 630 + if (uf==NULL) 631 + { 632 + printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); 633 + return 1; 634 + } 635 + printf("%s opened\n",filename_try); 636 + 637 + if (opt_do_list==1) 638 + ret_value = do_list(uf); 639 + else if (opt_do_extract==1) 640 + { 641 +#ifdef _WIN32 642 + if (opt_extractdir && _chdir(dirname)) 643 +#else 644 + if (opt_extractdir && chdir(dirname)) 645 +#endif 646 + { 647 + printf("Error changing into %s, aborting\n", dirname); 648 + exit(-1); 649 + } 650 + 651 + if (filename_to_extract == NULL) 652 + ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password); 653 + else 654 + ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password); 655 + } 656 + 657 + unzClose(uf); 658 + 659 + return ret_value; 660 +}
Added compat/zlib/contrib/minizip/minizip.c.
1 +/* 2 + minizip.c 3 + Version 1.1, February 14h, 2010 4 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 5 + 6 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 7 + 8 + Modifications of Unzip for Zip64 9 + Copyright (C) 2007-2008 Even Rouault 10 + 11 + Modifications for Zip64 support on both zip and unzip 12 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 13 +*/ 14 + 15 + 16 +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 17 + #ifndef __USE_FILE_OFFSET64 18 + #define __USE_FILE_OFFSET64 19 + #endif 20 + #ifndef __USE_LARGEFILE64 21 + #define __USE_LARGEFILE64 22 + #endif 23 + #ifndef _LARGEFILE64_SOURCE 24 + #define _LARGEFILE64_SOURCE 25 + #endif 26 + #ifndef _FILE_OFFSET_BIT 27 + #define _FILE_OFFSET_BIT 64 28 + #endif 29 +#endif 30 + 31 +#ifdef __APPLE__ 32 +// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions 33 +#define FOPEN_FUNC(filename, mode) fopen(filename, mode) 34 +#define FTELLO_FUNC(stream) ftello(stream) 35 +#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 36 +#else 37 +#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 38 +#define FTELLO_FUNC(stream) ftello64(stream) 39 +#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 40 +#endif 41 + 42 + 43 + 44 +#include <stdio.h> 45 +#include <stdlib.h> 46 +#include <string.h> 47 +#include <time.h> 48 +#include <errno.h> 49 +#include <fcntl.h> 50 + 51 +#ifdef _WIN32 52 +# include <direct.h> 53 +# include <io.h> 54 +#else 55 +# include <unistd.h> 56 +# include <utime.h> 57 +# include <sys/types.h> 58 +# include <sys/stat.h> 59 +#endif 60 + 61 +#include "zip.h" 62 + 63 +#ifdef _WIN32 64 + #define USEWIN32IOAPI 65 + #include "iowin32.h" 66 +#endif 67 + 68 + 69 + 70 +#define WRITEBUFFERSIZE (16384) 71 +#define MAXFILENAME (256) 72 + 73 +#ifdef _WIN32 74 +uLong filetime(f, tmzip, dt) 75 + char *f; /* name of file to get info on */ 76 + tm_zip *tmzip; /* return value: access, modific. and creation times */ 77 + uLong *dt; /* dostime */ 78 +{ 79 + int ret = 0; 80 + { 81 + FILETIME ftLocal; 82 + HANDLE hFind; 83 + WIN32_FIND_DATAA ff32; 84 + 85 + hFind = FindFirstFileA(f,&ff32); 86 + if (hFind != INVALID_HANDLE_VALUE) 87 + { 88 + FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); 89 + FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); 90 + FindClose(hFind); 91 + ret = 1; 92 + } 93 + } 94 + return ret; 95 +} 96 +#else 97 +#ifdef unix || __APPLE__ 98 +uLong filetime(f, tmzip, dt) 99 + char *f; /* name of file to get info on */ 100 + tm_zip *tmzip; /* return value: access, modific. and creation times */ 101 + uLong *dt; /* dostime */ 102 +{ 103 + int ret=0; 104 + struct stat s; /* results of stat() */ 105 + struct tm* filedate; 106 + time_t tm_t=0; 107 + 108 + if (strcmp(f,"-")!=0) 109 + { 110 + char name[MAXFILENAME+1]; 111 + int len = strlen(f); 112 + if (len > MAXFILENAME) 113 + len = MAXFILENAME; 114 + 115 + strncpy(name, f,MAXFILENAME-1); 116 + /* strncpy doesnt append the trailing NULL, of the string is too long. */ 117 + name[ MAXFILENAME ] = '\0'; 118 + 119 + if (name[len - 1] == '/') 120 + name[len - 1] = '\0'; 121 + /* not all systems allow stat'ing a file with / appended */ 122 + if (stat(name,&s)==0) 123 + { 124 + tm_t = s.st_mtime; 125 + ret = 1; 126 + } 127 + } 128 + filedate = localtime(&tm_t); 129 + 130 + tmzip->tm_sec = filedate->tm_sec; 131 + tmzip->tm_min = filedate->tm_min; 132 + tmzip->tm_hour = filedate->tm_hour; 133 + tmzip->tm_mday = filedate->tm_mday; 134 + tmzip->tm_mon = filedate->tm_mon ; 135 + tmzip->tm_year = filedate->tm_year; 136 + 137 + return ret; 138 +} 139 +#else 140 +uLong filetime(f, tmzip, dt) 141 + char *f; /* name of file to get info on */ 142 + tm_zip *tmzip; /* return value: access, modific. and creation times */ 143 + uLong *dt; /* dostime */ 144 +{ 145 + return 0; 146 +} 147 +#endif 148 +#endif 149 + 150 + 151 + 152 + 153 +int check_exist_file(filename) 154 + const char* filename; 155 +{ 156 + FILE* ftestexist; 157 + int ret = 1; 158 + ftestexist = FOPEN_FUNC(filename,"rb"); 159 + if (ftestexist==NULL) 160 + ret = 0; 161 + else 162 + fclose(ftestexist); 163 + return ret; 164 +} 165 + 166 +void do_banner() 167 +{ 168 + printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); 169 + printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); 170 +} 171 + 172 +void do_help() 173 +{ 174 + printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ 175 + " -o Overwrite existing file.zip\n" \ 176 + " -a Append to existing file.zip\n" \ 177 + " -0 Store only\n" \ 178 + " -1 Compress faster\n" \ 179 + " -9 Compress better\n\n" \ 180 + " -j exclude path. store only the file name.\n\n"); 181 +} 182 + 183 +/* calculate the CRC32 of a file, 184 + because to encrypt a file, we need known the CRC32 of the file before */ 185 +int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) 186 +{ 187 + unsigned long calculate_crc=0; 188 + int err=ZIP_OK; 189 + FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); 190 + 191 + unsigned long size_read = 0; 192 + unsigned long total_read = 0; 193 + if (fin==NULL) 194 + { 195 + err = ZIP_ERRNO; 196 + } 197 + 198 + if (err == ZIP_OK) 199 + do 200 + { 201 + err = ZIP_OK; 202 + size_read = (int)fread(buf,1,size_buf,fin); 203 + if (size_read < size_buf) 204 + if (feof(fin)==0) 205 + { 206 + printf("error in reading %s\n",filenameinzip); 207 + err = ZIP_ERRNO; 208 + } 209 + 210 + if (size_read>0) 211 + calculate_crc = crc32(calculate_crc,buf,size_read); 212 + total_read += size_read; 213 + 214 + } while ((err == ZIP_OK) && (size_read>0)); 215 + 216 + if (fin) 217 + fclose(fin); 218 + 219 + *result_crc=calculate_crc; 220 + printf("file %s crc %lx\n", filenameinzip, calculate_crc); 221 + return err; 222 +} 223 + 224 +int isLargeFile(const char* filename) 225 +{ 226 + int largeFile = 0; 227 + ZPOS64_T pos = 0; 228 + FILE* pFile = FOPEN_FUNC(filename, "rb"); 229 + 230 + if(pFile != NULL) 231 + { 232 + int n = FSEEKO_FUNC(pFile, 0, SEEK_END); 233 + pos = FTELLO_FUNC(pFile); 234 + 235 + printf("File : %s is %lld bytes\n", filename, pos); 236 + 237 + if(pos >= 0xffffffff) 238 + largeFile = 1; 239 + 240 + fclose(pFile); 241 + } 242 + 243 + return largeFile; 244 +} 245 + 246 +int main(argc,argv) 247 + int argc; 248 + char *argv[]; 249 +{ 250 + int i; 251 + int opt_overwrite=0; 252 + int opt_compress_level=Z_DEFAULT_COMPRESSION; 253 + int opt_exclude_path=0; 254 + int zipfilenamearg = 0; 255 + char filename_try[MAXFILENAME+16]; 256 + int zipok; 257 + int err=0; 258 + int size_buf=0; 259 + void* buf=NULL; 260 + const char* password=NULL; 261 + 262 + 263 + do_banner(); 264 + if (argc==1) 265 + { 266 + do_help(); 267 + return 0; 268 + } 269 + else 270 + { 271 + for (i=1;i<argc;i++) 272 + { 273 + if ((*argv[i])=='-') 274 + { 275 + const char *p=argv[i]+1; 276 + 277 + while ((*p)!='\0') 278 + { 279 + char c=*(p++);; 280 + if ((c=='o') || (c=='O')) 281 + opt_overwrite = 1; 282 + if ((c=='a') || (c=='A')) 283 + opt_overwrite = 2; 284 + if ((c>='0') && (c<='9')) 285 + opt_compress_level = c-'0'; 286 + if ((c=='j') || (c=='J')) 287 + opt_exclude_path = 1; 288 + 289 + if (((c=='p') || (c=='P')) && (i+1<argc)) 290 + { 291 + password=argv[i+1]; 292 + i++; 293 + } 294 + } 295 + } 296 + else 297 + { 298 + if (zipfilenamearg == 0) 299 + { 300 + zipfilenamearg = i ; 301 + } 302 + } 303 + } 304 + } 305 + 306 + size_buf = WRITEBUFFERSIZE; 307 + buf = (void*)malloc(size_buf); 308 + if (buf==NULL) 309 + { 310 + printf("Error allocating memory\n"); 311 + return ZIP_INTERNALERROR; 312 + } 313 + 314 + if (zipfilenamearg==0) 315 + { 316 + zipok=0; 317 + } 318 + else 319 + { 320 + int i,len; 321 + int dot_found=0; 322 + 323 + zipok = 1 ; 324 + strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); 325 + /* strncpy doesnt append the trailing NULL, of the string is too long. */ 326 + filename_try[ MAXFILENAME ] = '\0'; 327 + 328 + len=(int)strlen(filename_try); 329 + for (i=0;i<len;i++) 330 + if (filename_try[i]=='.') 331 + dot_found=1; 332 + 333 + if (dot_found==0) 334 + strcat(filename_try,".zip"); 335 + 336 + if (opt_overwrite==2) 337 + { 338 + /* if the file don't exist, we not append file */ 339 + if (check_exist_file(filename_try)==0) 340 + opt_overwrite=1; 341 + } 342 + else 343 + if (opt_overwrite==0) 344 + if (check_exist_file(filename_try)!=0) 345 + { 346 + char rep=0; 347 + do 348 + { 349 + char answer[128]; 350 + int ret; 351 + printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); 352 + ret = scanf("%1s",answer); 353 + if (ret != 1) 354 + { 355 + exit(EXIT_FAILURE); 356 + } 357 + rep = answer[0] ; 358 + if ((rep>='a') && (rep<='z')) 359 + rep -= 0x20; 360 + } 361 + while ((rep!='Y') && (rep!='N') && (rep!='A')); 362 + if (rep=='N') 363 + zipok = 0; 364 + if (rep=='A') 365 + opt_overwrite = 2; 366 + } 367 + } 368 + 369 + if (zipok==1) 370 + { 371 + zipFile zf; 372 + int errclose; 373 +# ifdef USEWIN32IOAPI 374 + zlib_filefunc64_def ffunc; 375 + fill_win32_filefunc64A(&ffunc); 376 + zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); 377 +# else 378 + zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); 379 +# endif 380 + 381 + if (zf == NULL) 382 + { 383 + printf("error opening %s\n",filename_try); 384 + err= ZIP_ERRNO; 385 + } 386 + else 387 + printf("creating %s\n",filename_try); 388 + 389 + for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) 390 + { 391 + if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) && 392 + ((argv[i][1]=='o') || (argv[i][1]=='O') || 393 + (argv[i][1]=='a') || (argv[i][1]=='A') || 394 + (argv[i][1]=='p') || (argv[i][1]=='P') || 395 + ((argv[i][1]>='0') || (argv[i][1]<='9'))) && 396 + (strlen(argv[i]) == 2))) 397 + { 398 + FILE * fin; 399 + int size_read; 400 + const char* filenameinzip = argv[i]; 401 + const char *savefilenameinzip; 402 + zip_fileinfo zi; 403 + unsigned long crcFile=0; 404 + int zip64 = 0; 405 + 406 + zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = 407 + zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; 408 + zi.dosDate = 0; 409 + zi.internal_fa = 0; 410 + zi.external_fa = 0; 411 + filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); 412 + 413 +/* 414 + err = zipOpenNewFileInZip(zf,filenameinzip,&zi, 415 + NULL,0,NULL,0,NULL / * comment * /, 416 + (opt_compress_level != 0) ? Z_DEFLATED : 0, 417 + opt_compress_level); 418 +*/ 419 + if ((password != NULL) && (err==ZIP_OK)) 420 + err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); 421 + 422 + zip64 = isLargeFile(filenameinzip); 423 + 424 + /* The path name saved, should not include a leading slash. */ 425 + /*if it did, windows/xp and dynazip couldn't read the zip file. */ 426 + savefilenameinzip = filenameinzip; 427 + while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) 428 + { 429 + savefilenameinzip++; 430 + } 431 + 432 + /*should the zip file contain any path at all?*/ 433 + if( opt_exclude_path ) 434 + { 435 + const char *tmpptr; 436 + const char *lastslash = 0; 437 + for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) 438 + { 439 + if( *tmpptr == '\\' || *tmpptr == '/') 440 + { 441 + lastslash = tmpptr; 442 + } 443 + } 444 + if( lastslash != NULL ) 445 + { 446 + savefilenameinzip = lastslash+1; // base filename follows last slash. 447 + } 448 + } 449 + 450 + /**/ 451 + err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, 452 + NULL,0,NULL,0,NULL /* comment*/, 453 + (opt_compress_level != 0) ? Z_DEFLATED : 0, 454 + opt_compress_level,0, 455 + /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ 456 + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 457 + password,crcFile, zip64); 458 + 459 + if (err != ZIP_OK) 460 + printf("error in opening %s in zipfile\n",filenameinzip); 461 + else 462 + { 463 + fin = FOPEN_FUNC(filenameinzip,"rb"); 464 + if (fin==NULL) 465 + { 466 + err=ZIP_ERRNO; 467 + printf("error in opening %s for reading\n",filenameinzip); 468 + } 469 + } 470 + 471 + if (err == ZIP_OK) 472 + do 473 + { 474 + err = ZIP_OK; 475 + size_read = (int)fread(buf,1,size_buf,fin); 476 + if (size_read < size_buf) 477 + if (feof(fin)==0) 478 + { 479 + printf("error in reading %s\n",filenameinzip); 480 + err = ZIP_ERRNO; 481 + } 482 + 483 + if (size_read>0) 484 + { 485 + err = zipWriteInFileInZip (zf,buf,size_read); 486 + if (err<0) 487 + { 488 + printf("error in writing %s in the zipfile\n", 489 + filenameinzip); 490 + } 491 + 492 + } 493 + } while ((err == ZIP_OK) && (size_read>0)); 494 + 495 + if (fin) 496 + fclose(fin); 497 + 498 + if (err<0) 499 + err=ZIP_ERRNO; 500 + else 501 + { 502 + err = zipCloseFileInZip(zf); 503 + if (err!=ZIP_OK) 504 + printf("error in closing %s in the zipfile\n", 505 + filenameinzip); 506 + } 507 + } 508 + } 509 + errclose = zipClose(zf,NULL); 510 + if (errclose != ZIP_OK) 511 + printf("error in closing %s\n",filename_try); 512 + } 513 + else 514 + { 515 + do_help(); 516 + } 517 + 518 + free(buf); 519 + return 0; 520 +}
Added compat/zlib/contrib/minizip/minizip.pc.in.
1 +prefix=@prefix@ 2 +exec_prefix=@exec_prefix@ 3 +libdir=@libdir@ 4 +includedir=@includedir@/minizip 5 + 6 +Name: minizip 7 +Description: Minizip zip file manipulation library 8 +Requires: 9 +Version: @PACKAGE_VERSION@ 10 +Libs: -L${libdir} -lminizip 11 +Libs.private: -lz 12 +Cflags: -I${includedir}
Added compat/zlib/contrib/minizip/mztools.c.
1 +/* 2 + Additional tools for Minizip 3 + Code: Xavier Roche '2004 4 + License: Same as ZLIB (www.gzip.org) 5 +*/ 6 + 7 +/* Code */ 8 +#include <stdio.h> 9 +#include <stdlib.h> 10 +#include <string.h> 11 +#include "zlib.h" 12 +#include "unzip.h" 13 + 14 +#define READ_8(adr) ((unsigned char)*(adr)) 15 +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 16 +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 17 + 18 +#define WRITE_8(buff, n) do { \ 19 + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 20 +} while(0) 21 +#define WRITE_16(buff, n) do { \ 22 + WRITE_8((unsigned char*)(buff), n); \ 23 + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 24 +} while(0) 25 +#define WRITE_32(buff, n) do { \ 26 + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 27 + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 28 +} while(0) 29 + 30 +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 31 +const char* file; 32 +const char* fileOut; 33 +const char* fileOutTmp; 34 +uLong* nRecovered; 35 +uLong* bytesRecovered; 36 +{ 37 + int err = Z_OK; 38 + FILE* fpZip = fopen(file, "rb"); 39 + FILE* fpOut = fopen(fileOut, "wb"); 40 + FILE* fpOutCD = fopen(fileOutTmp, "wb"); 41 + if (fpZip != NULL && fpOut != NULL) { 42 + int entries = 0; 43 + uLong totalBytes = 0; 44 + char header[30]; 45 + char filename[1024]; 46 + char extra[1024]; 47 + int offset = 0; 48 + int offsetCD = 0; 49 + while ( fread(header, 1, 30, fpZip) == 30 ) { 50 + int currentOffset = offset; 51 + 52 + /* File entry */ 53 + if (READ_32(header) == 0x04034b50) { 54 + unsigned int version = READ_16(header + 4); 55 + unsigned int gpflag = READ_16(header + 6); 56 + unsigned int method = READ_16(header + 8); 57 + unsigned int filetime = READ_16(header + 10); 58 + unsigned int filedate = READ_16(header + 12); 59 + unsigned int crc = READ_32(header + 14); /* crc */ 60 + unsigned int cpsize = READ_32(header + 18); /* compressed size */ 61 + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 62 + unsigned int fnsize = READ_16(header + 26); /* file name length */ 63 + unsigned int extsize = READ_16(header + 28); /* extra field length */ 64 + filename[0] = extra[0] = '\0'; 65 + 66 + /* Header */ 67 + if (fwrite(header, 1, 30, fpOut) == 30) { 68 + offset += 30; 69 + } else { 70 + err = Z_ERRNO; 71 + break; 72 + } 73 + 74 + /* Filename */ 75 + if (fnsize > 0) { 76 + if (fnsize < sizeof(filename)) { 77 + if (fread(filename, 1, fnsize, fpZip) == fnsize) { 78 + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 79 + offset += fnsize; 80 + } else { 81 + err = Z_ERRNO; 82 + break; 83 + } 84 + } else { 85 + err = Z_ERRNO; 86 + break; 87 + } 88 + } else { 89 + err = Z_ERRNO; 90 + break; 91 + } 92 + } else { 93 + err = Z_STREAM_ERROR; 94 + break; 95 + } 96 + 97 + /* Extra field */ 98 + if (extsize > 0) { 99 + if (extsize < sizeof(extra)) { 100 + if (fread(extra, 1, extsize, fpZip) == extsize) { 101 + if (fwrite(extra, 1, extsize, fpOut) == extsize) { 102 + offset += extsize; 103 + } else { 104 + err = Z_ERRNO; 105 + break; 106 + } 107 + } else { 108 + err = Z_ERRNO; 109 + break; 110 + } 111 + } else { 112 + err = Z_ERRNO; 113 + break; 114 + } 115 + } 116 + 117 + /* Data */ 118 + { 119 + int dataSize = cpsize; 120 + if (dataSize == 0) { 121 + dataSize = uncpsize; 122 + } 123 + if (dataSize > 0) { 124 + char* data = malloc(dataSize); 125 + if (data != NULL) { 126 + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 127 + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 128 + offset += dataSize; 129 + totalBytes += dataSize; 130 + } else { 131 + err = Z_ERRNO; 132 + } 133 + } else { 134 + err = Z_ERRNO; 135 + } 136 + free(data); 137 + if (err != Z_OK) { 138 + break; 139 + } 140 + } else { 141 + err = Z_MEM_ERROR; 142 + break; 143 + } 144 + } 145 + } 146 + 147 + /* Central directory entry */ 148 + { 149 + char header[46]; 150 + char* comment = ""; 151 + int comsize = (int) strlen(comment); 152 + WRITE_32(header, 0x02014b50); 153 + WRITE_16(header + 4, version); 154 + WRITE_16(header + 6, version); 155 + WRITE_16(header + 8, gpflag); 156 + WRITE_16(header + 10, method); 157 + WRITE_16(header + 12, filetime); 158 + WRITE_16(header + 14, filedate); 159 + WRITE_32(header + 16, crc); 160 + WRITE_32(header + 20, cpsize); 161 + WRITE_32(header + 24, uncpsize); 162 + WRITE_16(header + 28, fnsize); 163 + WRITE_16(header + 30, extsize); 164 + WRITE_16(header + 32, comsize); 165 + WRITE_16(header + 34, 0); /* disk # */ 166 + WRITE_16(header + 36, 0); /* int attrb */ 167 + WRITE_32(header + 38, 0); /* ext attrb */ 168 + WRITE_32(header + 42, currentOffset); 169 + /* Header */ 170 + if (fwrite(header, 1, 46, fpOutCD) == 46) { 171 + offsetCD += 46; 172 + 173 + /* Filename */ 174 + if (fnsize > 0) { 175 + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 176 + offsetCD += fnsize; 177 + } else { 178 + err = Z_ERRNO; 179 + break; 180 + } 181 + } else { 182 + err = Z_STREAM_ERROR; 183 + break; 184 + } 185 + 186 + /* Extra field */ 187 + if (extsize > 0) { 188 + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 189 + offsetCD += extsize; 190 + } else { 191 + err = Z_ERRNO; 192 + break; 193 + } 194 + } 195 + 196 + /* Comment field */ 197 + if (comsize > 0) { 198 + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 199 + offsetCD += comsize; 200 + } else { 201 + err = Z_ERRNO; 202 + break; 203 + } 204 + } 205 + 206 + 207 + } else { 208 + err = Z_ERRNO; 209 + break; 210 + } 211 + } 212 + 213 + /* Success */ 214 + entries++; 215 + 216 + } else { 217 + break; 218 + } 219 + } 220 + 221 + /* Final central directory */ 222 + { 223 + int entriesZip = entries; 224 + char header[22]; 225 + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 226 + int comsize = (int) strlen(comment); 227 + if (entriesZip > 0xffff) { 228 + entriesZip = 0xffff; 229 + } 230 + WRITE_32(header, 0x06054b50); 231 + WRITE_16(header + 4, 0); /* disk # */ 232 + WRITE_16(header + 6, 0); /* disk # */ 233 + WRITE_16(header + 8, entriesZip); /* hack */ 234 + WRITE_16(header + 10, entriesZip); /* hack */ 235 + WRITE_32(header + 12, offsetCD); /* size of CD */ 236 + WRITE_32(header + 16, offset); /* offset to CD */ 237 + WRITE_16(header + 20, comsize); /* comment */ 238 + 239 + /* Header */ 240 + if (fwrite(header, 1, 22, fpOutCD) == 22) { 241 + 242 + /* Comment field */ 243 + if (comsize > 0) { 244 + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 245 + err = Z_ERRNO; 246 + } 247 + } 248 + 249 + } else { 250 + err = Z_ERRNO; 251 + } 252 + } 253 + 254 + /* Final merge (file + central directory) */ 255 + fclose(fpOutCD); 256 + if (err == Z_OK) { 257 + fpOutCD = fopen(fileOutTmp, "rb"); 258 + if (fpOutCD != NULL) { 259 + int nRead; 260 + char buffer[8192]; 261 + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 262 + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 263 + err = Z_ERRNO; 264 + break; 265 + } 266 + } 267 + fclose(fpOutCD); 268 + } 269 + } 270 + 271 + /* Close */ 272 + fclose(fpZip); 273 + fclose(fpOut); 274 + 275 + /* Wipe temporary file */ 276 + (void)remove(fileOutTmp); 277 + 278 + /* Number of recovered entries */ 279 + if (err == Z_OK) { 280 + if (nRecovered != NULL) { 281 + *nRecovered = entries; 282 + } 283 + if (bytesRecovered != NULL) { 284 + *bytesRecovered = totalBytes; 285 + } 286 + } 287 + } else { 288 + err = Z_STREAM_ERROR; 289 + } 290 + return err; 291 +}
Added compat/zlib/contrib/minizip/mztools.h.
1 +/* 2 + Additional tools for Minizip 3 + Code: Xavier Roche '2004 4 + License: Same as ZLIB (www.gzip.org) 5 +*/ 6 + 7 +#ifndef _zip_tools_H 8 +#define _zip_tools_H 9 + 10 +#ifdef __cplusplus 11 +extern "C" { 12 +#endif 13 + 14 +#ifndef _ZLIB_H 15 +#include "zlib.h" 16 +#endif 17 + 18 +#include "unzip.h" 19 + 20 +/* Repair a ZIP file (missing central directory) 21 + file: file to recover 22 + fileOut: output file after recovery 23 + fileOutTmp: temporary file name used for recovery 24 +*/ 25 +extern int ZEXPORT unzRepair(const char* file, 26 + const char* fileOut, 27 + const char* fileOutTmp, 28 + uLong* nRecovered, 29 + uLong* bytesRecovered); 30 + 31 + 32 +#ifdef __cplusplus 33 +} 34 +#endif 35 + 36 + 37 +#endif
Added compat/zlib/contrib/minizip/unzip.c.
1 +/* unzip.c -- IO for uncompress .zip files using zlib 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications of Unzip for Zip64 8 + Copyright (C) 2007-2008 Even Rouault 9 + 10 + Modifications for Zip64 support on both zip and unzip 11 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 12 + 13 + For more info read MiniZip_info.txt 14 + 15 + 16 + ------------------------------------------------------------------------------------ 17 + Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of 18 + compatibility with older software. The following is from the original crypt.c. 19 + Code woven in by Terry Thorsen 1/2003. 20 + 21 + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 22 + 23 + See the accompanying file LICENSE, version 2000-Apr-09 or later 24 + (the contents of which are also included in zip.h) for terms of use. 25 + If, for some reason, all these files are missing, the Info-ZIP license 26 + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 27 + 28 + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] 29 + 30 + The encryption/decryption parts of this source code (as opposed to the 31 + non-echoing password parts) were originally written in Europe. The 32 + whole source package can be freely distributed, including from the USA. 33 + (Prior to January 2000, re-export from the US was a violation of US law.) 34 + 35 + This encryption code is a direct transcription of the algorithm from 36 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This 37 + file (appnote.txt) is distributed with the PKZIP program (even in the 38 + version without encryption capabilities). 39 + 40 + ------------------------------------------------------------------------------------ 41 + 42 + Changes in unzip.c 43 + 44 + 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos 45 + 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* 46 + 2007-2008 - Even Rouault - Remove old C style function prototypes 47 + 2007-2008 - Even Rouault - Add unzip support for ZIP64 48 + 49 + Copyright (C) 2007-2008 Even Rouault 50 + 51 + 52 + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). 53 + Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G 54 + should only read the compressed/uncompressed size from the Zip64 format if 55 + the size from normal header was 0xFFFFFFFF 56 + Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant 57 + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) 58 + Patch created by Daniel Borca 59 + 60 + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer 61 + 62 + Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson 63 + 64 +*/ 65 + 66 + 67 +#include <stdio.h> 68 +#include <stdlib.h> 69 +#include <string.h> 70 + 71 +#ifndef NOUNCRYPT 72 + #define NOUNCRYPT 73 +#endif 74 + 75 +#include "zlib.h" 76 +#include "unzip.h" 77 + 78 +#ifdef STDC 79 +# include <stddef.h> 80 +# include <string.h> 81 +# include <stdlib.h> 82 +#endif 83 +#ifdef NO_ERRNO_H 84 + extern int errno; 85 +#else 86 +# include <errno.h> 87 +#endif 88 + 89 + 90 +#ifndef local 91 +# define local static 92 +#endif 93 +/* compile with -Dlocal if your debugger can't find static symbols */ 94 + 95 + 96 +#ifndef CASESENSITIVITYDEFAULT_NO 97 +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) 98 +# define CASESENSITIVITYDEFAULT_NO 99 +# endif 100 +#endif 101 + 102 + 103 +#ifndef UNZ_BUFSIZE 104 +#define UNZ_BUFSIZE (16384) 105 +#endif 106 + 107 +#ifndef UNZ_MAXFILENAMEINZIP 108 +#define UNZ_MAXFILENAMEINZIP (256) 109 +#endif 110 + 111 +#ifndef ALLOC 112 +# define ALLOC(size) (malloc(size)) 113 +#endif 114 +#ifndef TRYFREE 115 +# define TRYFREE(p) {if (p) free(p);} 116 +#endif 117 + 118 +#define SIZECENTRALDIRITEM (0x2e) 119 +#define SIZEZIPLOCALHEADER (0x1e) 120 + 121 + 122 +const char unz_copyright[] = 123 + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 124 + 125 +/* unz_file_info_interntal contain internal info about a file in zipfile*/ 126 +typedef struct unz_file_info64_internal_s 127 +{ 128 + ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ 129 +} unz_file_info64_internal; 130 + 131 + 132 +/* file_in_zip_read_info_s contain internal information about a file in zipfile, 133 + when reading and decompress it */ 134 +typedef struct 135 +{ 136 + char *read_buffer; /* internal buffer for compressed data */ 137 + z_stream stream; /* zLib stream structure for inflate */ 138 + 139 +#ifdef HAVE_BZIP2 140 + bz_stream bstream; /* bzLib stream structure for bziped */ 141 +#endif 142 + 143 + ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 144 + uLong stream_initialised; /* flag set if stream structure is initialised*/ 145 + 146 + ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ 147 + uInt size_local_extrafield;/* size of the local extra field */ 148 + ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ 149 + ZPOS64_T total_out_64; 150 + 151 + uLong crc32; /* crc32 of all data uncompressed */ 152 + uLong crc32_wait; /* crc32 we must obtain after decompress all */ 153 + ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ 154 + ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 155 + zlib_filefunc64_32_def z_filefunc; 156 + voidpf filestream; /* io structore of the zipfile */ 157 + uLong compression_method; /* compression method (0==store) */ 158 + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 159 + int raw; 160 +} file_in_zip64_read_info_s; 161 + 162 + 163 +/* unz64_s contain internal information about the zipfile 164 +*/ 165 +typedef struct 166 +{ 167 + zlib_filefunc64_32_def z_filefunc; 168 + int is64bitOpenFunction; 169 + voidpf filestream; /* io structore of the zipfile */ 170 + unz_global_info64 gi; /* public global information */ 171 + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 172 + ZPOS64_T num_file; /* number of the current file in the zipfile*/ 173 + ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ 174 + ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ 175 + ZPOS64_T central_pos; /* position of the beginning of the central dir*/ 176 + 177 + ZPOS64_T size_central_dir; /* size of the central directory */ 178 + ZPOS64_T offset_central_dir; /* offset of start of central directory with 179 + respect to the starting disk number */ 180 + 181 + unz_file_info64 cur_file_info; /* public info about the current file in zip*/ 182 + unz_file_info64_internal cur_file_info_internal; /* private info about it*/ 183 + file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current 184 + file if we are decompressing it */ 185 + int encrypted; 186 + 187 + int isZip64; 188 + 189 +# ifndef NOUNCRYPT 190 + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 191 + const unsigned long* pcrc_32_tab; 192 +# endif 193 +} unz64_s; 194 + 195 + 196 +#ifndef NOUNCRYPT 197 +#include "crypt.h" 198 +#endif 199 + 200 +/* =========================================================================== 201 + Read a byte from a gz_stream; update next_in and avail_in. Return EOF 202 + for end of file. 203 + IN assertion: the stream s has been sucessfully opened for reading. 204 +*/ 205 + 206 + 207 +local int unz64local_getByte OF(( 208 + const zlib_filefunc64_32_def* pzlib_filefunc_def, 209 + voidpf filestream, 210 + int *pi)); 211 + 212 +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) 213 +{ 214 + unsigned char c; 215 + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); 216 + if (err==1) 217 + { 218 + *pi = (int)c; 219 + return UNZ_OK; 220 + } 221 + else 222 + { 223 + if (ZERROR64(*pzlib_filefunc_def,filestream)) 224 + return UNZ_ERRNO; 225 + else 226 + return UNZ_EOF; 227 + } 228 +} 229 + 230 + 231 +/* =========================================================================== 232 + Reads a long in LSB order from the given gz_stream. Sets 233 +*/ 234 +local int unz64local_getShort OF(( 235 + const zlib_filefunc64_32_def* pzlib_filefunc_def, 236 + voidpf filestream, 237 + uLong *pX)); 238 + 239 +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, 240 + voidpf filestream, 241 + uLong *pX) 242 +{ 243 + uLong x ; 244 + int i = 0; 245 + int err; 246 + 247 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 248 + x = (uLong)i; 249 + 250 + if (err==UNZ_OK) 251 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 252 + x |= ((uLong)i)<<8; 253 + 254 + if (err==UNZ_OK) 255 + *pX = x; 256 + else 257 + *pX = 0; 258 + return err; 259 +} 260 + 261 +local int unz64local_getLong OF(( 262 + const zlib_filefunc64_32_def* pzlib_filefunc_def, 263 + voidpf filestream, 264 + uLong *pX)); 265 + 266 +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, 267 + voidpf filestream, 268 + uLong *pX) 269 +{ 270 + uLong x ; 271 + int i = 0; 272 + int err; 273 + 274 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 275 + x = (uLong)i; 276 + 277 + if (err==UNZ_OK) 278 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 279 + x |= ((uLong)i)<<8; 280 + 281 + if (err==UNZ_OK) 282 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 283 + x |= ((uLong)i)<<16; 284 + 285 + if (err==UNZ_OK) 286 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 287 + x += ((uLong)i)<<24; 288 + 289 + if (err==UNZ_OK) 290 + *pX = x; 291 + else 292 + *pX = 0; 293 + return err; 294 +} 295 + 296 +local int unz64local_getLong64 OF(( 297 + const zlib_filefunc64_32_def* pzlib_filefunc_def, 298 + voidpf filestream, 299 + ZPOS64_T *pX)); 300 + 301 + 302 +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, 303 + voidpf filestream, 304 + ZPOS64_T *pX) 305 +{ 306 + ZPOS64_T x ; 307 + int i = 0; 308 + int err; 309 + 310 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 311 + x = (ZPOS64_T)i; 312 + 313 + if (err==UNZ_OK) 314 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 315 + x |= ((ZPOS64_T)i)<<8; 316 + 317 + if (err==UNZ_OK) 318 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 319 + x |= ((ZPOS64_T)i)<<16; 320 + 321 + if (err==UNZ_OK) 322 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 323 + x |= ((ZPOS64_T)i)<<24; 324 + 325 + if (err==UNZ_OK) 326 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 327 + x |= ((ZPOS64_T)i)<<32; 328 + 329 + if (err==UNZ_OK) 330 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 331 + x |= ((ZPOS64_T)i)<<40; 332 + 333 + if (err==UNZ_OK) 334 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 335 + x |= ((ZPOS64_T)i)<<48; 336 + 337 + if (err==UNZ_OK) 338 + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); 339 + x |= ((ZPOS64_T)i)<<56; 340 + 341 + if (err==UNZ_OK) 342 + *pX = x; 343 + else 344 + *pX = 0; 345 + return err; 346 +} 347 + 348 +/* My own strcmpi / strcasecmp */ 349 +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) 350 +{ 351 + for (;;) 352 + { 353 + char c1=*(fileName1++); 354 + char c2=*(fileName2++); 355 + if ((c1>='a') && (c1<='z')) 356 + c1 -= 0x20; 357 + if ((c2>='a') && (c2<='z')) 358 + c2 -= 0x20; 359 + if (c1=='\0') 360 + return ((c2=='\0') ? 0 : -1); 361 + if (c2=='\0') 362 + return 1; 363 + if (c1<c2) 364 + return -1; 365 + if (c1>c2) 366 + return 1; 367 + } 368 +} 369 + 370 + 371 +#ifdef CASESENSITIVITYDEFAULT_NO 372 +#define CASESENSITIVITYDEFAULTVALUE 2 373 +#else 374 +#define CASESENSITIVITYDEFAULTVALUE 1 375 +#endif 376 + 377 +#ifndef STRCMPCASENOSENTIVEFUNCTION 378 +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal 379 +#endif 380 + 381 +/* 382 + Compare two filename (fileName1,fileName2). 383 + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 384 + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 385 + or strcasecmp) 386 + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 387 + (like 1 on Unix, 2 on Windows) 388 + 389 +*/ 390 +extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, 391 + const char* fileName2, 392 + int iCaseSensitivity) 393 + 394 +{ 395 + if (iCaseSensitivity==0) 396 + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 397 + 398 + if (iCaseSensitivity==1) 399 + return strcmp(fileName1,fileName2); 400 + 401 + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); 402 +} 403 + 404 +#ifndef BUFREADCOMMENT 405 +#define BUFREADCOMMENT (0x400) 406 +#endif 407 + 408 +/* 409 + Locate the Central directory of a zipfile (at the end, just before 410 + the global comment) 411 +*/ 412 +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); 413 +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) 414 +{ 415 + unsigned char* buf; 416 + ZPOS64_T uSizeFile; 417 + ZPOS64_T uBackRead; 418 + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 419 + ZPOS64_T uPosFound=0; 420 + 421 + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 422 + return 0; 423 + 424 + 425 + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 426 + 427 + if (uMaxBack>uSizeFile) 428 + uMaxBack = uSizeFile; 429 + 430 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 431 + if (buf==NULL) 432 + return 0; 433 + 434 + uBackRead = 4; 435 + while (uBackRead<uMaxBack) 436 + { 437 + uLong uReadSize; 438 + ZPOS64_T uReadPos ; 439 + int i; 440 + if (uBackRead+BUFREADCOMMENT>uMaxBack) 441 + uBackRead = uMaxBack; 442 + else 443 + uBackRead+=BUFREADCOMMENT; 444 + uReadPos = uSizeFile-uBackRead ; 445 + 446 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 447 + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 448 + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 449 + break; 450 + 451 + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 452 + break; 453 + 454 + for (i=(int)uReadSize-3; (i--)>0;) 455 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 456 + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 457 + { 458 + uPosFound = uReadPos+i; 459 + break; 460 + } 461 + 462 + if (uPosFound!=0) 463 + break; 464 + } 465 + TRYFREE(buf); 466 + return uPosFound; 467 +} 468 + 469 + 470 +/* 471 + Locate the Central directory 64 of a zipfile (at the end, just before 472 + the global comment) 473 +*/ 474 +local ZPOS64_T unz64local_SearchCentralDir64 OF(( 475 + const zlib_filefunc64_32_def* pzlib_filefunc_def, 476 + voidpf filestream)); 477 + 478 +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, 479 + voidpf filestream) 480 +{ 481 + unsigned char* buf; 482 + ZPOS64_T uSizeFile; 483 + ZPOS64_T uBackRead; 484 + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 485 + ZPOS64_T uPosFound=0; 486 + uLong uL; 487 + ZPOS64_T relativeOffset; 488 + 489 + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 490 + return 0; 491 + 492 + 493 + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 494 + 495 + if (uMaxBack>uSizeFile) 496 + uMaxBack = uSizeFile; 497 + 498 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 499 + if (buf==NULL) 500 + return 0; 501 + 502 + uBackRead = 4; 503 + while (uBackRead<uMaxBack) 504 + { 505 + uLong uReadSize; 506 + ZPOS64_T uReadPos; 507 + int i; 508 + if (uBackRead+BUFREADCOMMENT>uMaxBack) 509 + uBackRead = uMaxBack; 510 + else 511 + uBackRead+=BUFREADCOMMENT; 512 + uReadPos = uSizeFile-uBackRead ; 513 + 514 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 515 + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 516 + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 517 + break; 518 + 519 + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 520 + break; 521 + 522 + for (i=(int)uReadSize-3; (i--)>0;) 523 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 524 + ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) 525 + { 526 + uPosFound = uReadPos+i; 527 + break; 528 + } 529 + 530 + if (uPosFound!=0) 531 + break; 532 + } 533 + TRYFREE(buf); 534 + if (uPosFound == 0) 535 + return 0; 536 + 537 + /* Zip64 end of central directory locator */ 538 + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) 539 + return 0; 540 + 541 + /* the signature, already checked */ 542 + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 543 + return 0; 544 + 545 + /* number of the disk with the start of the zip64 end of central directory */ 546 + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 547 + return 0; 548 + if (uL != 0) 549 + return 0; 550 + 551 + /* relative offset of the zip64 end of central directory record */ 552 + if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) 553 + return 0; 554 + 555 + /* total number of disks */ 556 + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 557 + return 0; 558 + if (uL != 1) 559 + return 0; 560 + 561 + /* Goto end of central directory record */ 562 + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) 563 + return 0; 564 + 565 + /* the signature */ 566 + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) 567 + return 0; 568 + 569 + if (uL != 0x06064b50) 570 + return 0; 571 + 572 + return relativeOffset; 573 +} 574 + 575 +/* 576 + Open a Zip file. path contain the full pathname (by example, 577 + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer 578 + "zlib/zlib114.zip". 579 + If the zipfile cannot be opened (file doesn't exist or in not valid), the 580 + return value is NULL. 581 + Else, the return value is a unzFile Handle, usable with other function 582 + of this unzip package. 583 +*/ 584 +local unzFile unzOpenInternal (const void *path, 585 + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, 586 + int is64bitOpenFunction) 587 +{ 588 + unz64_s us; 589 + unz64_s *s; 590 + ZPOS64_T central_pos; 591 + uLong uL; 592 + 593 + uLong number_disk; /* number of the current dist, used for 594 + spaning ZIP, unsupported, always 0*/ 595 + uLong number_disk_with_CD; /* number the the disk with central dir, used 596 + for spaning ZIP, unsupported, always 0*/ 597 + ZPOS64_T number_entry_CD; /* total number of entries in 598 + the central dir 599 + (same than number_entry on nospan) */ 600 + 601 + int err=UNZ_OK; 602 + 603 + if (unz_copyright[0]!=' ') 604 + return NULL; 605 + 606 + us.z_filefunc.zseek32_file = NULL; 607 + us.z_filefunc.ztell32_file = NULL; 608 + if (pzlib_filefunc64_32_def==NULL) 609 + fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); 610 + else 611 + us.z_filefunc = *pzlib_filefunc64_32_def; 612 + us.is64bitOpenFunction = is64bitOpenFunction; 613 + 614 + 615 + 616 + us.filestream = ZOPEN64(us.z_filefunc, 617 + path, 618 + ZLIB_FILEFUNC_MODE_READ | 619 + ZLIB_FILEFUNC_MODE_EXISTING); 620 + if (us.filestream==NULL) 621 + return NULL; 622 + 623 + central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); 624 + if (central_pos) 625 + { 626 + uLong uS; 627 + ZPOS64_T uL64; 628 + 629 + us.isZip64 = 1; 630 + 631 + if (ZSEEK64(us.z_filefunc, us.filestream, 632 + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 633 + err=UNZ_ERRNO; 634 + 635 + /* the signature, already checked */ 636 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 637 + err=UNZ_ERRNO; 638 + 639 + /* size of zip64 end of central directory record */ 640 + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) 641 + err=UNZ_ERRNO; 642 + 643 + /* version made by */ 644 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) 645 + err=UNZ_ERRNO; 646 + 647 + /* version needed to extract */ 648 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) 649 + err=UNZ_ERRNO; 650 + 651 + /* number of this disk */ 652 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 653 + err=UNZ_ERRNO; 654 + 655 + /* number of the disk with the start of the central directory */ 656 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 657 + err=UNZ_ERRNO; 658 + 659 + /* total number of entries in the central directory on this disk */ 660 + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 661 + err=UNZ_ERRNO; 662 + 663 + /* total number of entries in the central directory */ 664 + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 665 + err=UNZ_ERRNO; 666 + 667 + if ((number_entry_CD!=us.gi.number_entry) || 668 + (number_disk_with_CD!=0) || 669 + (number_disk!=0)) 670 + err=UNZ_BADZIPFILE; 671 + 672 + /* size of the central directory */ 673 + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) 674 + err=UNZ_ERRNO; 675 + 676 + /* offset of start of central directory with respect to the 677 + starting disk number */ 678 + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 679 + err=UNZ_ERRNO; 680 + 681 + us.gi.size_comment = 0; 682 + } 683 + else 684 + { 685 + central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); 686 + if (central_pos==0) 687 + err=UNZ_ERRNO; 688 + 689 + us.isZip64 = 0; 690 + 691 + if (ZSEEK64(us.z_filefunc, us.filestream, 692 + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 693 + err=UNZ_ERRNO; 694 + 695 + /* the signature, already checked */ 696 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 697 + err=UNZ_ERRNO; 698 + 699 + /* number of this disk */ 700 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 701 + err=UNZ_ERRNO; 702 + 703 + /* number of the disk with the start of the central directory */ 704 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 705 + err=UNZ_ERRNO; 706 + 707 + /* total number of entries in the central dir on this disk */ 708 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 709 + err=UNZ_ERRNO; 710 + us.gi.number_entry = uL; 711 + 712 + /* total number of entries in the central dir */ 713 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 714 + err=UNZ_ERRNO; 715 + number_entry_CD = uL; 716 + 717 + if ((number_entry_CD!=us.gi.number_entry) || 718 + (number_disk_with_CD!=0) || 719 + (number_disk!=0)) 720 + err=UNZ_BADZIPFILE; 721 + 722 + /* size of the central directory */ 723 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 724 + err=UNZ_ERRNO; 725 + us.size_central_dir = uL; 726 + 727 + /* offset of start of central directory with respect to the 728 + starting disk number */ 729 + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 730 + err=UNZ_ERRNO; 731 + us.offset_central_dir = uL; 732 + 733 + /* zipfile comment length */ 734 + if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 735 + err=UNZ_ERRNO; 736 + } 737 + 738 + if ((central_pos<us.offset_central_dir+us.size_central_dir) && 739 + (err==UNZ_OK)) 740 + err=UNZ_BADZIPFILE; 741 + 742 + if (err!=UNZ_OK) 743 + { 744 + ZCLOSE64(us.z_filefunc, us.filestream); 745 + return NULL; 746 + } 747 + 748 + us.byte_before_the_zipfile = central_pos - 749 + (us.offset_central_dir+us.size_central_dir); 750 + us.central_pos = central_pos; 751 + us.pfile_in_zip_read = NULL; 752 + us.encrypted = 0; 753 + 754 + 755 + s=(unz64_s*)ALLOC(sizeof(unz64_s)); 756 + if( s != NULL) 757 + { 758 + *s=us; 759 + unzGoToFirstFile((unzFile)s); 760 + } 761 + return (unzFile)s; 762 +} 763 + 764 + 765 +extern unzFile ZEXPORT unzOpen2 (const char *path, 766 + zlib_filefunc_def* pzlib_filefunc32_def) 767 +{ 768 + if (pzlib_filefunc32_def != NULL) 769 + { 770 + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; 771 + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); 772 + return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0); 773 + } 774 + else 775 + return unzOpenInternal(path, NULL, 0); 776 +} 777 + 778 +extern unzFile ZEXPORT unzOpen2_64 (const void *path, 779 + zlib_filefunc64_def* pzlib_filefunc_def) 780 +{ 781 + if (pzlib_filefunc_def != NULL) 782 + { 783 + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; 784 + zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; 785 + zlib_filefunc64_32_def_fill.ztell32_file = NULL; 786 + zlib_filefunc64_32_def_fill.zseek32_file = NULL; 787 + return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1); 788 + } 789 + else 790 + return unzOpenInternal(path, NULL, 1); 791 +} 792 + 793 +extern unzFile ZEXPORT unzOpen (const char *path) 794 +{ 795 + return unzOpenInternal(path, NULL, 0); 796 +} 797 + 798 +extern unzFile ZEXPORT unzOpen64 (const void *path) 799 +{ 800 + return unzOpenInternal(path, NULL, 1); 801 +} 802 + 803 +/* 804 + Close a ZipFile opened with unzipOpen. 805 + If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 806 + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 807 + return UNZ_OK if there is no problem. */ 808 +extern int ZEXPORT unzClose (unzFile file) 809 +{ 810 + unz64_s* s; 811 + if (file==NULL) 812 + return UNZ_PARAMERROR; 813 + s=(unz64_s*)file; 814 + 815 + if (s->pfile_in_zip_read!=NULL) 816 + unzCloseCurrentFile(file); 817 + 818 + ZCLOSE64(s->z_filefunc, s->filestream); 819 + TRYFREE(s); 820 + return UNZ_OK; 821 +} 822 + 823 + 824 +/* 825 + Write info about the ZipFile in the *pglobal_info structure. 826 + No preparation of the structure is needed 827 + return UNZ_OK if there is no problem. */ 828 +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) 829 +{ 830 + unz64_s* s; 831 + if (file==NULL) 832 + return UNZ_PARAMERROR; 833 + s=(unz64_s*)file; 834 + *pglobal_info=s->gi; 835 + return UNZ_OK; 836 +} 837 + 838 +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) 839 +{ 840 + unz64_s* s; 841 + if (file==NULL) 842 + return UNZ_PARAMERROR; 843 + s=(unz64_s*)file; 844 + /* to do : check if number_entry is not truncated */ 845 + pglobal_info32->number_entry = (uLong)s->gi.number_entry; 846 + pglobal_info32->size_comment = s->gi.size_comment; 847 + return UNZ_OK; 848 +} 849 +/* 850 + Translate date/time from Dos format to tm_unz (readable more easilty) 851 +*/ 852 +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) 853 +{ 854 + ZPOS64_T uDate; 855 + uDate = (ZPOS64_T)(ulDosDate>>16); 856 + ptm->tm_mday = (uInt)(uDate&0x1f) ; 857 + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 858 + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 859 + 860 + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); 861 + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; 862 + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; 863 +} 864 + 865 +/* 866 + Get Info about the current file in the zipfile, with internal only info 867 +*/ 868 +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, 869 + unz_file_info64 *pfile_info, 870 + unz_file_info64_internal 871 + *pfile_info_internal, 872 + char *szFileName, 873 + uLong fileNameBufferSize, 874 + void *extraField, 875 + uLong extraFieldBufferSize, 876 + char *szComment, 877 + uLong commentBufferSize)); 878 + 879 +local int unz64local_GetCurrentFileInfoInternal (unzFile file, 880 + unz_file_info64 *pfile_info, 881 + unz_file_info64_internal 882 + *pfile_info_internal, 883 + char *szFileName, 884 + uLong fileNameBufferSize, 885 + void *extraField, 886 + uLong extraFieldBufferSize, 887 + char *szComment, 888 + uLong commentBufferSize) 889 +{ 890 + unz64_s* s; 891 + unz_file_info64 file_info; 892 + unz_file_info64_internal file_info_internal; 893 + int err=UNZ_OK; 894 + uLong uMagic; 895 + long lSeek=0; 896 + uLong uL; 897 + 898 + if (file==NULL) 899 + return UNZ_PARAMERROR; 900 + s=(unz64_s*)file; 901 + if (ZSEEK64(s->z_filefunc, s->filestream, 902 + s->pos_in_central_dir+s->byte_before_the_zipfile, 903 + ZLIB_FILEFUNC_SEEK_SET)!=0) 904 + err=UNZ_ERRNO; 905 + 906 + 907 + /* we check the magic */ 908 + if (err==UNZ_OK) 909 + { 910 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 911 + err=UNZ_ERRNO; 912 + else if (uMagic!=0x02014b50) 913 + err=UNZ_BADZIPFILE; 914 + } 915 + 916 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 917 + err=UNZ_ERRNO; 918 + 919 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 920 + err=UNZ_ERRNO; 921 + 922 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 923 + err=UNZ_ERRNO; 924 + 925 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 926 + err=UNZ_ERRNO; 927 + 928 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 929 + err=UNZ_ERRNO; 930 + 931 + unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 932 + 933 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 934 + err=UNZ_ERRNO; 935 + 936 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 937 + err=UNZ_ERRNO; 938 + file_info.compressed_size = uL; 939 + 940 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 941 + err=UNZ_ERRNO; 942 + file_info.uncompressed_size = uL; 943 + 944 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 945 + err=UNZ_ERRNO; 946 + 947 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 948 + err=UNZ_ERRNO; 949 + 950 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 951 + err=UNZ_ERRNO; 952 + 953 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 954 + err=UNZ_ERRNO; 955 + 956 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 957 + err=UNZ_ERRNO; 958 + 959 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 960 + err=UNZ_ERRNO; 961 + 962 + // relative offset of local header 963 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 964 + err=UNZ_ERRNO; 965 + file_info_internal.offset_curfile = uL; 966 + 967 + lSeek+=file_info.size_filename; 968 + if ((err==UNZ_OK) && (szFileName!=NULL)) 969 + { 970 + uLong uSizeRead ; 971 + if (file_info.size_filename<fileNameBufferSize) 972 + { 973 + *(szFileName+file_info.size_filename)='\0'; 974 + uSizeRead = file_info.size_filename; 975 + } 976 + else 977 + uSizeRead = fileNameBufferSize; 978 + 979 + if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 980 + if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 981 + err=UNZ_ERRNO; 982 + lSeek -= uSizeRead; 983 + } 984 + 985 + // Read extrafield 986 + if ((err==UNZ_OK) && (extraField!=NULL)) 987 + { 988 + ZPOS64_T uSizeRead ; 989 + if (file_info.size_file_extra<extraFieldBufferSize) 990 + uSizeRead = file_info.size_file_extra; 991 + else 992 + uSizeRead = extraFieldBufferSize; 993 + 994 + if (lSeek!=0) 995 + { 996 + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 997 + lSeek=0; 998 + else 999 + err=UNZ_ERRNO; 1000 + } 1001 + 1002 + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 1003 + if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) 1004 + err=UNZ_ERRNO; 1005 + 1006 + lSeek += file_info.size_file_extra - (uLong)uSizeRead; 1007 + } 1008 + else 1009 + lSeek += file_info.size_file_extra; 1010 + 1011 + 1012 + if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) 1013 + { 1014 + uLong acc = 0; 1015 + 1016 + // since lSeek now points to after the extra field we need to move back 1017 + lSeek -= file_info.size_file_extra; 1018 + 1019 + if (lSeek!=0) 1020 + { 1021 + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1022 + lSeek=0; 1023 + else 1024 + err=UNZ_ERRNO; 1025 + } 1026 + 1027 + while(acc < file_info.size_file_extra) 1028 + { 1029 + uLong headerId; 1030 + uLong dataSize; 1031 + 1032 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) 1033 + err=UNZ_ERRNO; 1034 + 1035 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) 1036 + err=UNZ_ERRNO; 1037 + 1038 + /* ZIP64 extra fields */ 1039 + if (headerId == 0x0001) 1040 + { 1041 + uLong uL; 1042 + 1043 + if(file_info.uncompressed_size == MAXU32) 1044 + { 1045 + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 1046 + err=UNZ_ERRNO; 1047 + } 1048 + 1049 + if(file_info.compressed_size == MAXU32) 1050 + { 1051 + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 1052 + err=UNZ_ERRNO; 1053 + } 1054 + 1055 + if(file_info_internal.offset_curfile == MAXU32) 1056 + { 1057 + /* Relative Header offset */ 1058 + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 1059 + err=UNZ_ERRNO; 1060 + } 1061 + 1062 + if(file_info.disk_num_start == MAXU32) 1063 + { 1064 + /* Disk Start Number */ 1065 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) 1066 + err=UNZ_ERRNO; 1067 + } 1068 + 1069 + } 1070 + else 1071 + { 1072 + if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) 1073 + err=UNZ_ERRNO; 1074 + } 1075 + 1076 + acc += 2 + 2 + dataSize; 1077 + } 1078 + } 1079 + 1080 + if ((err==UNZ_OK) && (szComment!=NULL)) 1081 + { 1082 + uLong uSizeRead ; 1083 + if (file_info.size_file_comment<commentBufferSize) 1084 + { 1085 + *(szComment+file_info.size_file_comment)='\0'; 1086 + uSizeRead = file_info.size_file_comment; 1087 + } 1088 + else 1089 + uSizeRead = commentBufferSize; 1090 + 1091 + if (lSeek!=0) 1092 + { 1093 + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1094 + lSeek=0; 1095 + else 1096 + err=UNZ_ERRNO; 1097 + } 1098 + 1099 + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 1100 + if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 1101 + err=UNZ_ERRNO; 1102 + lSeek+=file_info.size_file_comment - uSizeRead; 1103 + } 1104 + else 1105 + lSeek+=file_info.size_file_comment; 1106 + 1107 + 1108 + if ((err==UNZ_OK) && (pfile_info!=NULL)) 1109 + *pfile_info=file_info; 1110 + 1111 + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) 1112 + *pfile_info_internal=file_info_internal; 1113 + 1114 + return err; 1115 +} 1116 + 1117 + 1118 + 1119 +/* 1120 + Write info about the ZipFile in the *pglobal_info structure. 1121 + No preparation of the structure is needed 1122 + return UNZ_OK if there is no problem. 1123 +*/ 1124 +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, 1125 + unz_file_info64 * pfile_info, 1126 + char * szFileName, uLong fileNameBufferSize, 1127 + void *extraField, uLong extraFieldBufferSize, 1128 + char* szComment, uLong commentBufferSize) 1129 +{ 1130 + return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, 1131 + szFileName,fileNameBufferSize, 1132 + extraField,extraFieldBufferSize, 1133 + szComment,commentBufferSize); 1134 +} 1135 + 1136 +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, 1137 + unz_file_info * pfile_info, 1138 + char * szFileName, uLong fileNameBufferSize, 1139 + void *extraField, uLong extraFieldBufferSize, 1140 + char* szComment, uLong commentBufferSize) 1141 +{ 1142 + int err; 1143 + unz_file_info64 file_info64; 1144 + err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, 1145 + szFileName,fileNameBufferSize, 1146 + extraField,extraFieldBufferSize, 1147 + szComment,commentBufferSize); 1148 + if ((err==UNZ_OK) && (pfile_info != NULL)) 1149 + { 1150 + pfile_info->version = file_info64.version; 1151 + pfile_info->version_needed = file_info64.version_needed; 1152 + pfile_info->flag = file_info64.flag; 1153 + pfile_info->compression_method = file_info64.compression_method; 1154 + pfile_info->dosDate = file_info64.dosDate; 1155 + pfile_info->crc = file_info64.crc; 1156 + 1157 + pfile_info->size_filename = file_info64.size_filename; 1158 + pfile_info->size_file_extra = file_info64.size_file_extra; 1159 + pfile_info->size_file_comment = file_info64.size_file_comment; 1160 + 1161 + pfile_info->disk_num_start = file_info64.disk_num_start; 1162 + pfile_info->internal_fa = file_info64.internal_fa; 1163 + pfile_info->external_fa = file_info64.external_fa; 1164 + 1165 + pfile_info->tmu_date = file_info64.tmu_date, 1166 + 1167 + 1168 + pfile_info->compressed_size = (uLong)file_info64.compressed_size; 1169 + pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; 1170 + 1171 + } 1172 + return err; 1173 +} 1174 +/* 1175 + Set the current file of the zipfile to the first file. 1176 + return UNZ_OK if there is no problem 1177 +*/ 1178 +extern int ZEXPORT unzGoToFirstFile (unzFile file) 1179 +{ 1180 + int err=UNZ_OK; 1181 + unz64_s* s; 1182 + if (file==NULL) 1183 + return UNZ_PARAMERROR; 1184 + s=(unz64_s*)file; 1185 + s->pos_in_central_dir=s->offset_central_dir; 1186 + s->num_file=0; 1187 + err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1188 + &s->cur_file_info_internal, 1189 + NULL,0,NULL,0,NULL,0); 1190 + s->current_file_ok = (err == UNZ_OK); 1191 + return err; 1192 +} 1193 + 1194 +/* 1195 + Set the current file of the zipfile to the next file. 1196 + return UNZ_OK if there is no problem 1197 + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1198 +*/ 1199 +extern int ZEXPORT unzGoToNextFile (unzFile file) 1200 +{ 1201 + unz64_s* s; 1202 + int err; 1203 + 1204 + if (file==NULL) 1205 + return UNZ_PARAMERROR; 1206 + s=(unz64_s*)file; 1207 + if (!s->current_file_ok) 1208 + return UNZ_END_OF_LIST_OF_FILE; 1209 + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ 1210 + if (s->num_file+1==s->gi.number_entry) 1211 + return UNZ_END_OF_LIST_OF_FILE; 1212 + 1213 + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 1214 + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 1215 + s->num_file++; 1216 + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1217 + &s->cur_file_info_internal, 1218 + NULL,0,NULL,0,NULL,0); 1219 + s->current_file_ok = (err == UNZ_OK); 1220 + return err; 1221 +} 1222 + 1223 + 1224 +/* 1225 + Try locate the file szFileName in the zipfile. 1226 + For the iCaseSensitivity signification, see unzipStringFileNameCompare 1227 + 1228 + return value : 1229 + UNZ_OK if the file is found. It becomes the current file. 1230 + UNZ_END_OF_LIST_OF_FILE if the file is not found 1231 +*/ 1232 +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) 1233 +{ 1234 + unz64_s* s; 1235 + int err; 1236 + 1237 + /* We remember the 'current' position in the file so that we can jump 1238 + * back there if we fail. 1239 + */ 1240 + unz_file_info64 cur_file_infoSaved; 1241 + unz_file_info64_internal cur_file_info_internalSaved; 1242 + ZPOS64_T num_fileSaved; 1243 + ZPOS64_T pos_in_central_dirSaved; 1244 + 1245 + 1246 + if (file==NULL) 1247 + return UNZ_PARAMERROR; 1248 + 1249 + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 1250 + return UNZ_PARAMERROR; 1251 + 1252 + s=(unz64_s*)file; 1253 + if (!s->current_file_ok) 1254 + return UNZ_END_OF_LIST_OF_FILE; 1255 + 1256 + /* Save the current state */ 1257 + num_fileSaved = s->num_file; 1258 + pos_in_central_dirSaved = s->pos_in_central_dir; 1259 + cur_file_infoSaved = s->cur_file_info; 1260 + cur_file_info_internalSaved = s->cur_file_info_internal; 1261 + 1262 + err = unzGoToFirstFile(file); 1263 + 1264 + while (err == UNZ_OK) 1265 + { 1266 + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 1267 + err = unzGetCurrentFileInfo64(file,NULL, 1268 + szCurrentFileName,sizeof(szCurrentFileName)-1, 1269 + NULL,0,NULL,0); 1270 + if (err == UNZ_OK) 1271 + { 1272 + if (unzStringFileNameCompare(szCurrentFileName, 1273 + szFileName,iCaseSensitivity)==0) 1274 + return UNZ_OK; 1275 + err = unzGoToNextFile(file); 1276 + } 1277 + } 1278 + 1279 + /* We failed, so restore the state of the 'current file' to where we 1280 + * were. 1281 + */ 1282 + s->num_file = num_fileSaved ; 1283 + s->pos_in_central_dir = pos_in_central_dirSaved ; 1284 + s->cur_file_info = cur_file_infoSaved; 1285 + s->cur_file_info_internal = cur_file_info_internalSaved; 1286 + return err; 1287 +} 1288 + 1289 + 1290 +/* 1291 +/////////////////////////////////////////// 1292 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) 1293 +// I need random access 1294 +// 1295 +// Further optimization could be realized by adding an ability 1296 +// to cache the directory in memory. The goal being a single 1297 +// comprehensive file read to put the file I need in a memory. 1298 +*/ 1299 + 1300 +/* 1301 +typedef struct unz_file_pos_s 1302 +{ 1303 + ZPOS64_T pos_in_zip_directory; // offset in file 1304 + ZPOS64_T num_of_file; // # of file 1305 +} unz_file_pos; 1306 +*/ 1307 + 1308 +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) 1309 +{ 1310 + unz64_s* s; 1311 + 1312 + if (file==NULL || file_pos==NULL) 1313 + return UNZ_PARAMERROR; 1314 + s=(unz64_s*)file; 1315 + if (!s->current_file_ok) 1316 + return UNZ_END_OF_LIST_OF_FILE; 1317 + 1318 + file_pos->pos_in_zip_directory = s->pos_in_central_dir; 1319 + file_pos->num_of_file = s->num_file; 1320 + 1321 + return UNZ_OK; 1322 +} 1323 + 1324 +extern int ZEXPORT unzGetFilePos( 1325 + unzFile file, 1326 + unz_file_pos* file_pos) 1327 +{ 1328 + unz64_file_pos file_pos64; 1329 + int err = unzGetFilePos64(file,&file_pos64); 1330 + if (err==UNZ_OK) 1331 + { 1332 + file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; 1333 + file_pos->num_of_file = (uLong)file_pos64.num_of_file; 1334 + } 1335 + return err; 1336 +} 1337 + 1338 +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) 1339 +{ 1340 + unz64_s* s; 1341 + int err; 1342 + 1343 + if (file==NULL || file_pos==NULL) 1344 + return UNZ_PARAMERROR; 1345 + s=(unz64_s*)file; 1346 + 1347 + /* jump to the right spot */ 1348 + s->pos_in_central_dir = file_pos->pos_in_zip_directory; 1349 + s->num_file = file_pos->num_of_file; 1350 + 1351 + /* set the current file */ 1352 + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1353 + &s->cur_file_info_internal, 1354 + NULL,0,NULL,0,NULL,0); 1355 + /* return results */ 1356 + s->current_file_ok = (err == UNZ_OK); 1357 + return err; 1358 +} 1359 + 1360 +extern int ZEXPORT unzGoToFilePos( 1361 + unzFile file, 1362 + unz_file_pos* file_pos) 1363 +{ 1364 + unz64_file_pos file_pos64; 1365 + if (file_pos == NULL) 1366 + return UNZ_PARAMERROR; 1367 + 1368 + file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; 1369 + file_pos64.num_of_file = file_pos->num_of_file; 1370 + return unzGoToFilePos64(file,&file_pos64); 1371 +} 1372 + 1373 +/* 1374 +// Unzip Helper Functions - should be here? 1375 +/////////////////////////////////////////// 1376 +*/ 1377 + 1378 +/* 1379 + Read the local header of the current zipfile 1380 + Check the coherency of the local header and info in the end of central 1381 + directory about this file 1382 + store in *piSizeVar the size of extra info in local header 1383 + (filename and size of extra field data) 1384 +*/ 1385 +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, 1386 + ZPOS64_T * poffset_local_extrafield, 1387 + uInt * psize_local_extrafield) 1388 +{ 1389 + uLong uMagic,uData,uFlags; 1390 + uLong size_filename; 1391 + uLong size_extra_field; 1392 + int err=UNZ_OK; 1393 + 1394 + *piSizeVar = 0; 1395 + *poffset_local_extrafield = 0; 1396 + *psize_local_extrafield = 0; 1397 + 1398 + if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 1399 + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 1400 + return UNZ_ERRNO; 1401 + 1402 + 1403 + if (err==UNZ_OK) 1404 + { 1405 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 1406 + err=UNZ_ERRNO; 1407 + else if (uMagic!=0x04034b50) 1408 + err=UNZ_BADZIPFILE; 1409 + } 1410 + 1411 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1412 + err=UNZ_ERRNO; 1413 +/* 1414 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 1415 + err=UNZ_BADZIPFILE; 1416 +*/ 1417 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 1418 + err=UNZ_ERRNO; 1419 + 1420 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1421 + err=UNZ_ERRNO; 1422 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 1423 + err=UNZ_BADZIPFILE; 1424 + 1425 + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 1426 +/* #ifdef HAVE_BZIP2 */ 1427 + (s->cur_file_info.compression_method!=Z_BZIP2ED) && 1428 +/* #endif */ 1429 + (s->cur_file_info.compression_method!=Z_DEFLATED)) 1430 + err=UNZ_BADZIPFILE; 1431 + 1432 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 1433 + err=UNZ_ERRNO; 1434 + 1435 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 1436 + err=UNZ_ERRNO; 1437 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) 1438 + err=UNZ_BADZIPFILE; 1439 + 1440 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 1441 + err=UNZ_ERRNO; 1442 + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) 1443 + err=UNZ_BADZIPFILE; 1444 + 1445 + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1446 + err=UNZ_ERRNO; 1447 + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) 1448 + err=UNZ_BADZIPFILE; 1449 + 1450 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) 1451 + err=UNZ_ERRNO; 1452 + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1453 + err=UNZ_BADZIPFILE; 1454 + 1455 + *piSizeVar += (uInt)size_filename; 1456 + 1457 + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1458 + err=UNZ_ERRNO; 1459 + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1460 + SIZEZIPLOCALHEADER + size_filename; 1461 + *psize_local_extrafield = (uInt)size_extra_field; 1462 + 1463 + *piSizeVar += (uInt)size_extra_field; 1464 + 1465 + return err; 1466 +} 1467 + 1468 +/* 1469 + Open for reading data the current file in the zipfile. 1470 + If there is no error and the file is opened, the return value is UNZ_OK. 1471 +*/ 1472 +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, 1473 + int* level, int raw, const char* password) 1474 +{ 1475 + int err=UNZ_OK; 1476 + uInt iSizeVar; 1477 + unz64_s* s; 1478 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1479 + ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ 1480 + uInt size_local_extrafield; /* size of the local extra field */ 1481 +# ifndef NOUNCRYPT 1482 + char source[12]; 1483 +# else 1484 + if (password != NULL) 1485 + return UNZ_PARAMERROR; 1486 +# endif 1487 + 1488 + if (file==NULL) 1489 + return UNZ_PARAMERROR; 1490 + s=(unz64_s*)file; 1491 + if (!s->current_file_ok) 1492 + return UNZ_PARAMERROR; 1493 + 1494 + if (s->pfile_in_zip_read != NULL) 1495 + unzCloseCurrentFile(file); 1496 + 1497 + if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) 1498 + return UNZ_BADZIPFILE; 1499 + 1500 + pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); 1501 + if (pfile_in_zip_read_info==NULL) 1502 + return UNZ_INTERNALERROR; 1503 + 1504 + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); 1505 + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; 1506 + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; 1507 + pfile_in_zip_read_info->pos_local_extrafield=0; 1508 + pfile_in_zip_read_info->raw=raw; 1509 + 1510 + if (pfile_in_zip_read_info->read_buffer==NULL) 1511 + { 1512 + TRYFREE(pfile_in_zip_read_info); 1513 + return UNZ_INTERNALERROR; 1514 + } 1515 + 1516 + pfile_in_zip_read_info->stream_initialised=0; 1517 + 1518 + if (method!=NULL) 1519 + *method = (int)s->cur_file_info.compression_method; 1520 + 1521 + if (level!=NULL) 1522 + { 1523 + *level = 6; 1524 + switch (s->cur_file_info.flag & 0x06) 1525 + { 1526 + case 6 : *level = 1; break; 1527 + case 4 : *level = 2; break; 1528 + case 2 : *level = 9; break; 1529 + } 1530 + } 1531 + 1532 + if ((s->cur_file_info.compression_method!=0) && 1533 +/* #ifdef HAVE_BZIP2 */ 1534 + (s->cur_file_info.compression_method!=Z_BZIP2ED) && 1535 +/* #endif */ 1536 + (s->cur_file_info.compression_method!=Z_DEFLATED)) 1537 + 1538 + err=UNZ_BADZIPFILE; 1539 + 1540 + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1541 + pfile_in_zip_read_info->crc32=0; 1542 + pfile_in_zip_read_info->total_out_64=0; 1543 + pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; 1544 + pfile_in_zip_read_info->filestream=s->filestream; 1545 + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1546 + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1547 + 1548 + pfile_in_zip_read_info->stream.total_out = 0; 1549 + 1550 + if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) 1551 + { 1552 +#ifdef HAVE_BZIP2 1553 + pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; 1554 + pfile_in_zip_read_info->bstream.bzfree = (free_func)0; 1555 + pfile_in_zip_read_info->bstream.opaque = (voidpf)0; 1556 + pfile_in_zip_read_info->bstream.state = (voidpf)0; 1557 + 1558 + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1559 + pfile_in_zip_read_info->stream.zfree = (free_func)0; 1560 + pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1561 + pfile_in_zip_read_info->stream.next_in = (voidpf)0; 1562 + pfile_in_zip_read_info->stream.avail_in = 0; 1563 + 1564 + err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); 1565 + if (err == Z_OK) 1566 + pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; 1567 + else 1568 + { 1569 + TRYFREE(pfile_in_zip_read_info); 1570 + return err; 1571 + } 1572 +#else 1573 + pfile_in_zip_read_info->raw=1; 1574 +#endif 1575 + } 1576 + else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) 1577 + { 1578 + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1579 + pfile_in_zip_read_info->stream.zfree = (free_func)0; 1580 + pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1581 + pfile_in_zip_read_info->stream.next_in = 0; 1582 + pfile_in_zip_read_info->stream.avail_in = 0; 1583 + 1584 + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1585 + if (err == Z_OK) 1586 + pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; 1587 + else 1588 + { 1589 + TRYFREE(pfile_in_zip_read_info); 1590 + return err; 1591 + } 1592 + /* windowBits is passed < 0 to tell that there is no zlib header. 1593 + * Note that in this case inflate *requires* an extra "dummy" byte 1594 + * after the compressed stream in order to complete decompression and 1595 + * return Z_STREAM_END. 1596 + * In unzip, i don't wait absolutely Z_STREAM_END because I known the 1597 + * size of both compressed and uncompressed data 1598 + */ 1599 + } 1600 + pfile_in_zip_read_info->rest_read_compressed = 1601 + s->cur_file_info.compressed_size ; 1602 + pfile_in_zip_read_info->rest_read_uncompressed = 1603 + s->cur_file_info.uncompressed_size ; 1604 + 1605 + 1606 + pfile_in_zip_read_info->pos_in_zipfile = 1607 + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 1608 + iSizeVar; 1609 + 1610 + pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1611 + 1612 + s->pfile_in_zip_read = pfile_in_zip_read_info; 1613 + s->encrypted = 0; 1614 + 1615 +# ifndef NOUNCRYPT 1616 + if (password != NULL) 1617 + { 1618 + int i; 1619 + s->pcrc_32_tab = get_crc_table(); 1620 + init_keys(password,s->keys,s->pcrc_32_tab); 1621 + if (ZSEEK64(s->z_filefunc, s->filestream, 1622 + s->pfile_in_zip_read->pos_in_zipfile + 1623 + s->pfile_in_zip_read->byte_before_the_zipfile, 1624 + SEEK_SET)!=0) 1625 + return UNZ_INTERNALERROR; 1626 + if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) 1627 + return UNZ_INTERNALERROR; 1628 + 1629 + for (i = 0; i<12; i++) 1630 + zdecode(s->keys,s->pcrc_32_tab,source[i]); 1631 + 1632 + s->pfile_in_zip_read->pos_in_zipfile+=12; 1633 + s->encrypted=1; 1634 + } 1635 +# endif 1636 + 1637 + 1638 + return UNZ_OK; 1639 +} 1640 + 1641 +extern int ZEXPORT unzOpenCurrentFile (unzFile file) 1642 +{ 1643 + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1644 +} 1645 + 1646 +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) 1647 +{ 1648 + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1649 +} 1650 + 1651 +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) 1652 +{ 1653 + return unzOpenCurrentFile3(file, method, level, raw, NULL); 1654 +} 1655 + 1656 +/** Addition for GDAL : START */ 1657 + 1658 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) 1659 +{ 1660 + unz64_s* s; 1661 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1662 + s=(unz64_s*)file; 1663 + if (file==NULL) 1664 + return 0; //UNZ_PARAMERROR; 1665 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1666 + if (pfile_in_zip_read_info==NULL) 1667 + return 0; //UNZ_PARAMERROR; 1668 + return pfile_in_zip_read_info->pos_in_zipfile + 1669 + pfile_in_zip_read_info->byte_before_the_zipfile; 1670 +} 1671 + 1672 +/** Addition for GDAL : END */ 1673 + 1674 +/* 1675 + Read bytes from the current file. 1676 + buf contain buffer where data must be copied 1677 + len the size of buf. 1678 + 1679 + return the number of byte copied if somes bytes are copied 1680 + return 0 if the end of file was reached 1681 + return <0 with error code if there is an error 1682 + (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1683 +*/ 1684 +extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) 1685 +{ 1686 + int err=UNZ_OK; 1687 + uInt iRead = 0; 1688 + unz64_s* s; 1689 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1690 + if (file==NULL) 1691 + return UNZ_PARAMERROR; 1692 + s=(unz64_s*)file; 1693 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1694 + 1695 + if (pfile_in_zip_read_info==NULL) 1696 + return UNZ_PARAMERROR; 1697 + 1698 + 1699 + if (pfile_in_zip_read_info->read_buffer == NULL) 1700 + return UNZ_END_OF_LIST_OF_FILE; 1701 + if (len==0) 1702 + return 0; 1703 + 1704 + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; 1705 + 1706 + pfile_in_zip_read_info->stream.avail_out = (uInt)len; 1707 + 1708 + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && 1709 + (!(pfile_in_zip_read_info->raw))) 1710 + pfile_in_zip_read_info->stream.avail_out = 1711 + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; 1712 + 1713 + if ((len>pfile_in_zip_read_info->rest_read_compressed+ 1714 + pfile_in_zip_read_info->stream.avail_in) && 1715 + (pfile_in_zip_read_info->raw)) 1716 + pfile_in_zip_read_info->stream.avail_out = 1717 + (uInt)pfile_in_zip_read_info->rest_read_compressed+ 1718 + pfile_in_zip_read_info->stream.avail_in; 1719 + 1720 + while (pfile_in_zip_read_info->stream.avail_out>0) 1721 + { 1722 + if ((pfile_in_zip_read_info->stream.avail_in==0) && 1723 + (pfile_in_zip_read_info->rest_read_compressed>0)) 1724 + { 1725 + uInt uReadThis = UNZ_BUFSIZE; 1726 + if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) 1727 + uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1728 + if (uReadThis == 0) 1729 + return UNZ_EOF; 1730 + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, 1731 + pfile_in_zip_read_info->filestream, 1732 + pfile_in_zip_read_info->pos_in_zipfile + 1733 + pfile_in_zip_read_info->byte_before_the_zipfile, 1734 + ZLIB_FILEFUNC_SEEK_SET)!=0) 1735 + return UNZ_ERRNO; 1736 + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, 1737 + pfile_in_zip_read_info->filestream, 1738 + pfile_in_zip_read_info->read_buffer, 1739 + uReadThis)!=uReadThis) 1740 + return UNZ_ERRNO; 1741 + 1742 + 1743 +# ifndef NOUNCRYPT 1744 + if(s->encrypted) 1745 + { 1746 + uInt i; 1747 + for(i=0;i<uReadThis;i++) 1748 + pfile_in_zip_read_info->read_buffer[i] = 1749 + zdecode(s->keys,s->pcrc_32_tab, 1750 + pfile_in_zip_read_info->read_buffer[i]); 1751 + } 1752 +# endif 1753 + 1754 + 1755 + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; 1756 + 1757 + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; 1758 + 1759 + pfile_in_zip_read_info->stream.next_in = 1760 + (Bytef*)pfile_in_zip_read_info->read_buffer; 1761 + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; 1762 + } 1763 + 1764 + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) 1765 + { 1766 + uInt uDoCopy,i ; 1767 + 1768 + if ((pfile_in_zip_read_info->stream.avail_in == 0) && 1769 + (pfile_in_zip_read_info->rest_read_compressed == 0)) 1770 + return (iRead==0) ? UNZ_EOF : iRead; 1771 + 1772 + if (pfile_in_zip_read_info->stream.avail_out < 1773 + pfile_in_zip_read_info->stream.avail_in) 1774 + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; 1775 + else 1776 + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; 1777 + 1778 + for (i=0;i<uDoCopy;i++) 1779 + *(pfile_in_zip_read_info->stream.next_out+i) = 1780 + *(pfile_in_zip_read_info->stream.next_in+i); 1781 + 1782 + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; 1783 + 1784 + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1785 + pfile_in_zip_read_info->stream.next_out, 1786 + uDoCopy); 1787 + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; 1788 + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; 1789 + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; 1790 + pfile_in_zip_read_info->stream.next_out += uDoCopy; 1791 + pfile_in_zip_read_info->stream.next_in += uDoCopy; 1792 + pfile_in_zip_read_info->stream.total_out += uDoCopy; 1793 + iRead += uDoCopy; 1794 + } 1795 + else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) 1796 + { 1797 +#ifdef HAVE_BZIP2 1798 + uLong uTotalOutBefore,uTotalOutAfter; 1799 + const Bytef *bufBefore; 1800 + uLong uOutThis; 1801 + 1802 + pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; 1803 + pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; 1804 + pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; 1805 + pfile_in_zip_read_info->bstream.total_in_hi32 = 0; 1806 + pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; 1807 + pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; 1808 + pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; 1809 + pfile_in_zip_read_info->bstream.total_out_hi32 = 0; 1810 + 1811 + uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; 1812 + bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; 1813 + 1814 + err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); 1815 + 1816 + uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; 1817 + uOutThis = uTotalOutAfter-uTotalOutBefore; 1818 + 1819 + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; 1820 + 1821 + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); 1822 + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; 1823 + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1824 + 1825 + pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; 1826 + pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; 1827 + pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; 1828 + pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; 1829 + pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; 1830 + pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; 1831 + 1832 + if (err==BZ_STREAM_END) 1833 + return (iRead==0) ? UNZ_EOF : iRead; 1834 + if (err!=BZ_OK) 1835 + break; 1836 +#endif 1837 + } // end Z_BZIP2ED 1838 + else 1839 + { 1840 + ZPOS64_T uTotalOutBefore,uTotalOutAfter; 1841 + const Bytef *bufBefore; 1842 + ZPOS64_T uOutThis; 1843 + int flush=Z_SYNC_FLUSH; 1844 + 1845 + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1846 + bufBefore = pfile_in_zip_read_info->stream.next_out; 1847 + 1848 + /* 1849 + if ((pfile_in_zip_read_info->rest_read_uncompressed == 1850 + pfile_in_zip_read_info->stream.avail_out) && 1851 + (pfile_in_zip_read_info->rest_read_compressed == 0)) 1852 + flush = Z_FINISH; 1853 + */ 1854 + err=inflate(&pfile_in_zip_read_info->stream,flush); 1855 + 1856 + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) 1857 + err = Z_DATA_ERROR; 1858 + 1859 + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1860 + uOutThis = uTotalOutAfter-uTotalOutBefore; 1861 + 1862 + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; 1863 + 1864 + pfile_in_zip_read_info->crc32 = 1865 + crc32(pfile_in_zip_read_info->crc32,bufBefore, 1866 + (uInt)(uOutThis)); 1867 + 1868 + pfile_in_zip_read_info->rest_read_uncompressed -= 1869 + uOutThis; 1870 + 1871 + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1872 + 1873 + if (err==Z_STREAM_END) 1874 + return (iRead==0) ? UNZ_EOF : iRead; 1875 + if (err!=Z_OK) 1876 + break; 1877 + } 1878 + } 1879 + 1880 + if (err==Z_OK) 1881 + return iRead; 1882 + return err; 1883 +} 1884 + 1885 + 1886 +/* 1887 + Give the current position in uncompressed data 1888 +*/ 1889 +extern z_off_t ZEXPORT unztell (unzFile file) 1890 +{ 1891 + unz64_s* s; 1892 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1893 + if (file==NULL) 1894 + return UNZ_PARAMERROR; 1895 + s=(unz64_s*)file; 1896 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1897 + 1898 + if (pfile_in_zip_read_info==NULL) 1899 + return UNZ_PARAMERROR; 1900 + 1901 + return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1902 +} 1903 + 1904 +extern ZPOS64_T ZEXPORT unztell64 (unzFile file) 1905 +{ 1906 + 1907 + unz64_s* s; 1908 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1909 + if (file==NULL) 1910 + return (ZPOS64_T)-1; 1911 + s=(unz64_s*)file; 1912 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1913 + 1914 + if (pfile_in_zip_read_info==NULL) 1915 + return (ZPOS64_T)-1; 1916 + 1917 + return pfile_in_zip_read_info->total_out_64; 1918 +} 1919 + 1920 + 1921 +/* 1922 + return 1 if the end of file was reached, 0 elsewhere 1923 +*/ 1924 +extern int ZEXPORT unzeof (unzFile file) 1925 +{ 1926 + unz64_s* s; 1927 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1928 + if (file==NULL) 1929 + return UNZ_PARAMERROR; 1930 + s=(unz64_s*)file; 1931 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1932 + 1933 + if (pfile_in_zip_read_info==NULL) 1934 + return UNZ_PARAMERROR; 1935 + 1936 + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) 1937 + return 1; 1938 + else 1939 + return 0; 1940 +} 1941 + 1942 + 1943 + 1944 +/* 1945 +Read extra field from the current file (opened by unzOpenCurrentFile) 1946 +This is the local-header version of the extra field (sometimes, there is 1947 +more info in the local-header version than in the central-header) 1948 + 1949 + if buf==NULL, it return the size of the local extra field that can be read 1950 + 1951 + if buf!=NULL, len is the size of the buffer, the extra header is copied in 1952 + buf. 1953 + the return value is the number of bytes copied in buf, or (if <0) 1954 + the error code 1955 +*/ 1956 +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) 1957 +{ 1958 + unz64_s* s; 1959 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 1960 + uInt read_now; 1961 + ZPOS64_T size_to_read; 1962 + 1963 + if (file==NULL) 1964 + return UNZ_PARAMERROR; 1965 + s=(unz64_s*)file; 1966 + pfile_in_zip_read_info=s->pfile_in_zip_read; 1967 + 1968 + if (pfile_in_zip_read_info==NULL) 1969 + return UNZ_PARAMERROR; 1970 + 1971 + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - 1972 + pfile_in_zip_read_info->pos_local_extrafield); 1973 + 1974 + if (buf==NULL) 1975 + return (int)size_to_read; 1976 + 1977 + if (len>size_to_read) 1978 + read_now = (uInt)size_to_read; 1979 + else 1980 + read_now = (uInt)len ; 1981 + 1982 + if (read_now==0) 1983 + return 0; 1984 + 1985 + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, 1986 + pfile_in_zip_read_info->filestream, 1987 + pfile_in_zip_read_info->offset_local_extrafield + 1988 + pfile_in_zip_read_info->pos_local_extrafield, 1989 + ZLIB_FILEFUNC_SEEK_SET)!=0) 1990 + return UNZ_ERRNO; 1991 + 1992 + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, 1993 + pfile_in_zip_read_info->filestream, 1994 + buf,read_now)!=read_now) 1995 + return UNZ_ERRNO; 1996 + 1997 + return (int)read_now; 1998 +} 1999 + 2000 +/* 2001 + Close the file in zip opened with unzipOpenCurrentFile 2002 + Return UNZ_CRCERROR if all the file was read but the CRC is not good 2003 +*/ 2004 +extern int ZEXPORT unzCloseCurrentFile (unzFile file) 2005 +{ 2006 + int err=UNZ_OK; 2007 + 2008 + unz64_s* s; 2009 + file_in_zip64_read_info_s* pfile_in_zip_read_info; 2010 + if (file==NULL) 2011 + return UNZ_PARAMERROR; 2012 + s=(unz64_s*)file; 2013 + pfile_in_zip_read_info=s->pfile_in_zip_read; 2014 + 2015 + if (pfile_in_zip_read_info==NULL) 2016 + return UNZ_PARAMERROR; 2017 + 2018 + 2019 + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && 2020 + (!pfile_in_zip_read_info->raw)) 2021 + { 2022 + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) 2023 + err=UNZ_CRCERROR; 2024 + } 2025 + 2026 + 2027 + TRYFREE(pfile_in_zip_read_info->read_buffer); 2028 + pfile_in_zip_read_info->read_buffer = NULL; 2029 + if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) 2030 + inflateEnd(&pfile_in_zip_read_info->stream); 2031 +#ifdef HAVE_BZIP2 2032 + else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) 2033 + BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); 2034 +#endif 2035 + 2036 + 2037 + pfile_in_zip_read_info->stream_initialised = 0; 2038 + TRYFREE(pfile_in_zip_read_info); 2039 + 2040 + s->pfile_in_zip_read=NULL; 2041 + 2042 + return err; 2043 +} 2044 + 2045 + 2046 +/* 2047 + Get the global comment string of the ZipFile, in the szComment buffer. 2048 + uSizeBuf is the size of the szComment buffer. 2049 + return the number of byte copied or an error code <0 2050 +*/ 2051 +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) 2052 +{ 2053 + unz64_s* s; 2054 + uLong uReadThis ; 2055 + if (file==NULL) 2056 + return (int)UNZ_PARAMERROR; 2057 + s=(unz64_s*)file; 2058 + 2059 + uReadThis = uSizeBuf; 2060 + if (uReadThis>s->gi.size_comment) 2061 + uReadThis = s->gi.size_comment; 2062 + 2063 + if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 2064 + return UNZ_ERRNO; 2065 + 2066 + if (uReadThis>0) 2067 + { 2068 + *szComment='\0'; 2069 + if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 2070 + return UNZ_ERRNO; 2071 + } 2072 + 2073 + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) 2074 + *(szComment+s->gi.size_comment)='\0'; 2075 + return (int)uReadThis; 2076 +} 2077 + 2078 +/* Additions by RX '2004 */ 2079 +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) 2080 +{ 2081 + unz64_s* s; 2082 + 2083 + if (file==NULL) 2084 + return 0; //UNZ_PARAMERROR; 2085 + s=(unz64_s*)file; 2086 + if (!s->current_file_ok) 2087 + return 0; 2088 + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) 2089 + if (s->num_file==s->gi.number_entry) 2090 + return 0; 2091 + return s->pos_in_central_dir; 2092 +} 2093 + 2094 +extern uLong ZEXPORT unzGetOffset (unzFile file) 2095 +{ 2096 + ZPOS64_T offset64; 2097 + 2098 + if (file==NULL) 2099 + return 0; //UNZ_PARAMERROR; 2100 + offset64 = unzGetOffset64(file); 2101 + return (uLong)offset64; 2102 +} 2103 + 2104 +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) 2105 +{ 2106 + unz64_s* s; 2107 + int err; 2108 + 2109 + if (file==NULL) 2110 + return UNZ_PARAMERROR; 2111 + s=(unz64_s*)file; 2112 + 2113 + s->pos_in_central_dir = pos; 2114 + s->num_file = s->gi.number_entry; /* hack */ 2115 + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, 2116 + &s->cur_file_info_internal, 2117 + NULL,0,NULL,0,NULL,0); 2118 + s->current_file_ok = (err == UNZ_OK); 2119 + return err; 2120 +} 2121 + 2122 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) 2123 +{ 2124 + return unzSetOffset64(file,pos); 2125 +}
Added compat/zlib/contrib/minizip/unzip.h.
1 +/* unzip.h -- IO for uncompress .zip files using zlib 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications of Unzip for Zip64 8 + Copyright (C) 2007-2008 Even Rouault 9 + 10 + Modifications for Zip64 support on both zip and unzip 11 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 12 + 13 + For more info read MiniZip_info.txt 14 + 15 + --------------------------------------------------------------------------------- 16 + 17 + Condition of use and distribution are the same than zlib : 18 + 19 + This software is provided 'as-is', without any express or implied 20 + warranty. In no event will the authors be held liable for any damages 21 + arising from the use of this software. 22 + 23 + Permission is granted to anyone to use this software for any purpose, 24 + including commercial applications, and to alter it and redistribute it 25 + freely, subject to the following restrictions: 26 + 27 + 1. The origin of this software must not be misrepresented; you must not 28 + claim that you wrote the original software. If you use this software 29 + in a product, an acknowledgment in the product documentation would be 30 + appreciated but is not required. 31 + 2. Altered source versions must be plainly marked as such, and must not be 32 + misrepresented as being the original software. 33 + 3. This notice may not be removed or altered from any source distribution. 34 + 35 + --------------------------------------------------------------------------------- 36 + 37 + Changes 38 + 39 + See header of unzip64.c 40 + 41 +*/ 42 + 43 +#ifndef _unz64_H 44 +#define _unz64_H 45 + 46 +#ifdef __cplusplus 47 +extern "C" { 48 +#endif 49 + 50 +#ifndef _ZLIB_H 51 +#include "zlib.h" 52 +#endif 53 + 54 +#ifndef _ZLIBIOAPI_H 55 +#include "ioapi.h" 56 +#endif 57 + 58 +#ifdef HAVE_BZIP2 59 +#include "bzlib.h" 60 +#endif 61 + 62 +#define Z_BZIP2ED 12 63 + 64 +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 65 +/* like the STRICT of WIN32, we define a pointer that cannot be converted 66 + from (void*) without cast */ 67 +typedef struct TagunzFile__ { int unused; } unzFile__; 68 +typedef unzFile__ *unzFile; 69 +#else 70 +typedef voidp unzFile; 71 +#endif 72 + 73 + 74 +#define UNZ_OK (0) 75 +#define UNZ_END_OF_LIST_OF_FILE (-100) 76 +#define UNZ_ERRNO (Z_ERRNO) 77 +#define UNZ_EOF (0) 78 +#define UNZ_PARAMERROR (-102) 79 +#define UNZ_BADZIPFILE (-103) 80 +#define UNZ_INTERNALERROR (-104) 81 +#define UNZ_CRCERROR (-105) 82 + 83 +/* tm_unz contain date/time info */ 84 +typedef struct tm_unz_s 85 +{ 86 + uInt tm_sec; /* seconds after the minute - [0,59] */ 87 + uInt tm_min; /* minutes after the hour - [0,59] */ 88 + uInt tm_hour; /* hours since midnight - [0,23] */ 89 + uInt tm_mday; /* day of the month - [1,31] */ 90 + uInt tm_mon; /* months since January - [0,11] */ 91 + uInt tm_year; /* years - [1980..2044] */ 92 +} tm_unz; 93 + 94 +/* unz_global_info structure contain global data about the ZIPfile 95 + These data comes from the end of central dir */ 96 +typedef struct unz_global_info64_s 97 +{ 98 + ZPOS64_T number_entry; /* total number of entries in 99 + the central dir on this disk */ 100 + uLong size_comment; /* size of the global comment of the zipfile */ 101 +} unz_global_info64; 102 + 103 +typedef struct unz_global_info_s 104 +{ 105 + uLong number_entry; /* total number of entries in 106 + the central dir on this disk */ 107 + uLong size_comment; /* size of the global comment of the zipfile */ 108 +} unz_global_info; 109 + 110 +/* unz_file_info contain information about a file in the zipfile */ 111 +typedef struct unz_file_info64_s 112 +{ 113 + uLong version; /* version made by 2 bytes */ 114 + uLong version_needed; /* version needed to extract 2 bytes */ 115 + uLong flag; /* general purpose bit flag 2 bytes */ 116 + uLong compression_method; /* compression method 2 bytes */ 117 + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 118 + uLong crc; /* crc-32 4 bytes */ 119 + ZPOS64_T compressed_size; /* compressed size 8 bytes */ 120 + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 121 + uLong size_filename; /* filename length 2 bytes */ 122 + uLong size_file_extra; /* extra field length 2 bytes */ 123 + uLong size_file_comment; /* file comment length 2 bytes */ 124 + 125 + uLong disk_num_start; /* disk number start 2 bytes */ 126 + uLong internal_fa; /* internal file attributes 2 bytes */ 127 + uLong external_fa; /* external file attributes 4 bytes */ 128 + 129 + tm_unz tmu_date; 130 +} unz_file_info64; 131 + 132 +typedef struct unz_file_info_s 133 +{ 134 + uLong version; /* version made by 2 bytes */ 135 + uLong version_needed; /* version needed to extract 2 bytes */ 136 + uLong flag; /* general purpose bit flag 2 bytes */ 137 + uLong compression_method; /* compression method 2 bytes */ 138 + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 139 + uLong crc; /* crc-32 4 bytes */ 140 + uLong compressed_size; /* compressed size 4 bytes */ 141 + uLong uncompressed_size; /* uncompressed size 4 bytes */ 142 + uLong size_filename; /* filename length 2 bytes */ 143 + uLong size_file_extra; /* extra field length 2 bytes */ 144 + uLong size_file_comment; /* file comment length 2 bytes */ 145 + 146 + uLong disk_num_start; /* disk number start 2 bytes */ 147 + uLong internal_fa; /* internal file attributes 2 bytes */ 148 + uLong external_fa; /* external file attributes 4 bytes */ 149 + 150 + tm_unz tmu_date; 151 +} unz_file_info; 152 + 153 +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 154 + const char* fileName2, 155 + int iCaseSensitivity)); 156 +/* 157 + Compare two filename (fileName1,fileName2). 158 + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 159 + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 160 + or strcasecmp) 161 + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 162 + (like 1 on Unix, 2 on Windows) 163 +*/ 164 + 165 + 166 +extern unzFile ZEXPORT unzOpen OF((const char *path)); 167 +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); 168 +/* 169 + Open a Zip file. path contain the full pathname (by example, 170 + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 171 + "zlib/zlib113.zip". 172 + If the zipfile cannot be opened (file don't exist or in not valid), the 173 + return value is NULL. 174 + Else, the return value is a unzFile Handle, usable with other function 175 + of this unzip package. 176 + the "64" function take a const void* pointer, because the path is just the 177 + value passed to the open64_file_func callback. 178 + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 179 + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* 180 + does not describe the reality 181 +*/ 182 + 183 + 184 +extern unzFile ZEXPORT unzOpen2 OF((const char *path, 185 + zlib_filefunc_def* pzlib_filefunc_def)); 186 +/* 187 + Open a Zip file, like unzOpen, but provide a set of file low level API 188 + for read/write the zip file (see ioapi.h) 189 +*/ 190 + 191 +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, 192 + zlib_filefunc64_def* pzlib_filefunc_def)); 193 +/* 194 + Open a Zip file, like unz64Open, but provide a set of file low level API 195 + for read/write the zip file (see ioapi.h) 196 +*/ 197 + 198 +extern int ZEXPORT unzClose OF((unzFile file)); 199 +/* 200 + Close a ZipFile opened with unzipOpen. 201 + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 202 + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 203 + return UNZ_OK if there is no problem. */ 204 + 205 +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 206 + unz_global_info *pglobal_info)); 207 + 208 +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, 209 + unz_global_info64 *pglobal_info)); 210 +/* 211 + Write info about the ZipFile in the *pglobal_info structure. 212 + No preparation of the structure is needed 213 + return UNZ_OK if there is no problem. */ 214 + 215 + 216 +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 217 + char *szComment, 218 + uLong uSizeBuf)); 219 +/* 220 + Get the global comment string of the ZipFile, in the szComment buffer. 221 + uSizeBuf is the size of the szComment buffer. 222 + return the number of byte copied or an error code <0 223 +*/ 224 + 225 + 226 +/***************************************************************************/ 227 +/* Unzip package allow you browse the directory of the zipfile */ 228 + 229 +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 230 +/* 231 + Set the current file of the zipfile to the first file. 232 + return UNZ_OK if there is no problem 233 +*/ 234 + 235 +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 236 +/* 237 + Set the current file of the zipfile to the next file. 238 + return UNZ_OK if there is no problem 239 + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 240 +*/ 241 + 242 +extern int ZEXPORT unzLocateFile OF((unzFile file, 243 + const char *szFileName, 244 + int iCaseSensitivity)); 245 +/* 246 + Try locate the file szFileName in the zipfile. 247 + For the iCaseSensitivity signification, see unzStringFileNameCompare 248 + 249 + return value : 250 + UNZ_OK if the file is found. It becomes the current file. 251 + UNZ_END_OF_LIST_OF_FILE if the file is not found 252 +*/ 253 + 254 + 255 +/* ****************************************** */ 256 +/* Ryan supplied functions */ 257 +/* unz_file_info contain information about a file in the zipfile */ 258 +typedef struct unz_file_pos_s 259 +{ 260 + uLong pos_in_zip_directory; /* offset in zip file directory */ 261 + uLong num_of_file; /* # of file */ 262 +} unz_file_pos; 263 + 264 +extern int ZEXPORT unzGetFilePos( 265 + unzFile file, 266 + unz_file_pos* file_pos); 267 + 268 +extern int ZEXPORT unzGoToFilePos( 269 + unzFile file, 270 + unz_file_pos* file_pos); 271 + 272 +typedef struct unz64_file_pos_s 273 +{ 274 + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 275 + ZPOS64_T num_of_file; /* # of file */ 276 +} unz64_file_pos; 277 + 278 +extern int ZEXPORT unzGetFilePos64( 279 + unzFile file, 280 + unz64_file_pos* file_pos); 281 + 282 +extern int ZEXPORT unzGoToFilePos64( 283 + unzFile file, 284 + const unz64_file_pos* file_pos); 285 + 286 +/* ****************************************** */ 287 + 288 +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, 289 + unz_file_info64 *pfile_info, 290 + char *szFileName, 291 + uLong fileNameBufferSize, 292 + void *extraField, 293 + uLong extraFieldBufferSize, 294 + char *szComment, 295 + uLong commentBufferSize)); 296 + 297 +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 298 + unz_file_info *pfile_info, 299 + char *szFileName, 300 + uLong fileNameBufferSize, 301 + void *extraField, 302 + uLong extraFieldBufferSize, 303 + char *szComment, 304 + uLong commentBufferSize)); 305 +/* 306 + Get Info about the current file 307 + if pfile_info!=NULL, the *pfile_info structure will contain somes info about 308 + the current file 309 + if szFileName!=NULL, the filemane string will be copied in szFileName 310 + (fileNameBufferSize is the size of the buffer) 311 + if extraField!=NULL, the extra field information will be copied in extraField 312 + (extraFieldBufferSize is the size of the buffer). 313 + This is the Central-header version of the extra field 314 + if szComment!=NULL, the comment string of the file will be copied in szComment 315 + (commentBufferSize is the size of the buffer) 316 +*/ 317 + 318 + 319 +/** Addition for GDAL : START */ 320 + 321 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 322 + 323 +/** Addition for GDAL : END */ 324 + 325 + 326 +/***************************************************************************/ 327 +/* for reading the content of the current zipfile, you can open it, read data 328 + from it, and close it (you can close it before reading all the file) 329 + */ 330 + 331 +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 332 +/* 333 + Open for reading data the current file in the zipfile. 334 + If there is no error, the return value is UNZ_OK. 335 +*/ 336 + 337 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 338 + const char* password)); 339 +/* 340 + Open for reading data the current file in the zipfile. 341 + password is a crypting password 342 + If there is no error, the return value is UNZ_OK. 343 +*/ 344 + 345 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 346 + int* method, 347 + int* level, 348 + int raw)); 349 +/* 350 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 351 + if raw==1 352 + *method will receive method of compression, *level will receive level of 353 + compression 354 + note : you can set level parameter as NULL (if you did not want known level, 355 + but you CANNOT set method parameter as NULL 356 +*/ 357 + 358 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 359 + int* method, 360 + int* level, 361 + int raw, 362 + const char* password)); 363 +/* 364 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 365 + if raw==1 366 + *method will receive method of compression, *level will receive level of 367 + compression 368 + note : you can set level parameter as NULL (if you did not want known level, 369 + but you CANNOT set method parameter as NULL 370 +*/ 371 + 372 + 373 +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 374 +/* 375 + Close the file in zip opened with unzOpenCurrentFile 376 + Return UNZ_CRCERROR if all the file was read but the CRC is not good 377 +*/ 378 + 379 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 380 + voidp buf, 381 + unsigned len)); 382 +/* 383 + Read bytes from the current file (opened by unzOpenCurrentFile) 384 + buf contain buffer where data must be copied 385 + len the size of buf. 386 + 387 + return the number of byte copied if somes bytes are copied 388 + return 0 if the end of file was reached 389 + return <0 with error code if there is an error 390 + (UNZ_ERRNO for IO error, or zLib error for uncompress error) 391 +*/ 392 + 393 +extern z_off_t ZEXPORT unztell OF((unzFile file)); 394 + 395 +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 396 +/* 397 + Give the current position in uncompressed data 398 +*/ 399 + 400 +extern int ZEXPORT unzeof OF((unzFile file)); 401 +/* 402 + return 1 if the end of file was reached, 0 elsewhere 403 +*/ 404 + 405 +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 406 + voidp buf, 407 + unsigned len)); 408 +/* 409 + Read extra field from the current file (opened by unzOpenCurrentFile) 410 + This is the local-header version of the extra field (sometimes, there is 411 + more info in the local-header version than in the central-header) 412 + 413 + if buf==NULL, it return the size of the local extra field 414 + 415 + if buf!=NULL, len is the size of the buffer, the extra header is copied in 416 + buf. 417 + the return value is the number of bytes copied in buf, or (if <0) 418 + the error code 419 +*/ 420 + 421 +/***************************************************************************/ 422 + 423 +/* Get the current file offset */ 424 +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); 425 +extern uLong ZEXPORT unzGetOffset (unzFile file); 426 + 427 +/* Set the current file offset */ 428 +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); 429 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 430 + 431 + 432 + 433 +#ifdef __cplusplus 434 +} 435 +#endif 436 + 437 +#endif /* _unz64_H */
Added compat/zlib/contrib/minizip/zip.c.
1 +/* zip.c -- IO on .zip files using zlib 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications for Zip64 support 8 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 9 + 10 + For more info read MiniZip_info.txt 11 + 12 + Changes 13 + Oct-2009 - Mathias Svensson - Remove old C style function prototypes 14 + Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives 15 + Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. 16 + Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data 17 + It is used when recreting zip archive with RAW when deleting items from a zip. 18 + ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed. 19 + Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) 20 + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer 21 + 22 +*/ 23 + 24 + 25 +#include <stdio.h> 26 +#include <stdlib.h> 27 +#include <string.h> 28 +#include <time.h> 29 +#include "zlib.h" 30 +#include "zip.h" 31 + 32 +#ifdef STDC 33 +# include <stddef.h> 34 +# include <string.h> 35 +# include <stdlib.h> 36 +#endif 37 +#ifdef NO_ERRNO_H 38 + extern int errno; 39 +#else 40 +# include <errno.h> 41 +#endif 42 + 43 + 44 +#ifndef local 45 +# define local static 46 +#endif 47 +/* compile with -Dlocal if your debugger can't find static symbols */ 48 + 49 +#ifndef VERSIONMADEBY 50 +# define VERSIONMADEBY (0x0) /* platform depedent */ 51 +#endif 52 + 53 +#ifndef Z_BUFSIZE 54 +#define Z_BUFSIZE (64*1024) //(16384) 55 +#endif 56 + 57 +#ifndef Z_MAXFILENAMEINZIP 58 +#define Z_MAXFILENAMEINZIP (256) 59 +#endif 60 + 61 +#ifndef ALLOC 62 +# define ALLOC(size) (malloc(size)) 63 +#endif 64 +#ifndef TRYFREE 65 +# define TRYFREE(p) {if (p) free(p);} 66 +#endif 67 + 68 +/* 69 +#define SIZECENTRALDIRITEM (0x2e) 70 +#define SIZEZIPLOCALHEADER (0x1e) 71 +*/ 72 + 73 +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 74 + 75 + 76 +// NOT sure that this work on ALL platform 77 +#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) 78 + 79 +#ifndef SEEK_CUR 80 +#define SEEK_CUR 1 81 +#endif 82 + 83 +#ifndef SEEK_END 84 +#define SEEK_END 2 85 +#endif 86 + 87 +#ifndef SEEK_SET 88 +#define SEEK_SET 0 89 +#endif 90 + 91 +#ifndef DEF_MEM_LEVEL 92 +#if MAX_MEM_LEVEL >= 8 93 +# define DEF_MEM_LEVEL 8 94 +#else 95 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL 96 +#endif 97 +#endif 98 +const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 99 + 100 + 101 +#define SIZEDATA_INDATABLOCK (4096-(4*4)) 102 + 103 +#define LOCALHEADERMAGIC (0x04034b50) 104 +#define CENTRALHEADERMAGIC (0x02014b50) 105 +#define ENDHEADERMAGIC (0x06054b50) 106 +#define ZIP64ENDHEADERMAGIC (0x6064b50) 107 +#define ZIP64ENDLOCHEADERMAGIC (0x7064b50) 108 + 109 +#define FLAG_LOCALHEADER_OFFSET (0x06) 110 +#define CRC_LOCALHEADER_OFFSET (0x0e) 111 + 112 +#define SIZECENTRALHEADER (0x2e) /* 46 */ 113 + 114 +typedef struct linkedlist_datablock_internal_s 115 +{ 116 + struct linkedlist_datablock_internal_s* next_datablock; 117 + uLong avail_in_this_block; 118 + uLong filled_in_this_block; 119 + uLong unused; /* for future use and alignement */ 120 + unsigned char data[SIZEDATA_INDATABLOCK]; 121 +} linkedlist_datablock_internal; 122 + 123 +typedef struct linkedlist_data_s 124 +{ 125 + linkedlist_datablock_internal* first_block; 126 + linkedlist_datablock_internal* last_block; 127 +} linkedlist_data; 128 + 129 + 130 +typedef struct 131 +{ 132 + z_stream stream; /* zLib stream structure for inflate */ 133 +#ifdef HAVE_BZIP2 134 + bz_stream bstream; /* bzLib stream structure for bziped */ 135 +#endif 136 + 137 + int stream_initialised; /* 1 is stream is initialised */ 138 + uInt pos_in_buffered_data; /* last written byte in buffered_data */ 139 + 140 + ZPOS64_T pos_local_header; /* offset of the local header of the file 141 + currenty writing */ 142 + char* central_header; /* central header data for the current file */ 143 + uLong size_centralExtra; 144 + uLong size_centralheader; /* size of the central header for cur file */ 145 + uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ 146 + uLong flag; /* flag of the file currently writing */ 147 + 148 + int method; /* compression method of file currenty wr.*/ 149 + int raw; /* 1 for directly writing raw data */ 150 + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ 151 + uLong dosDate; 152 + uLong crc32; 153 + int encrypt; 154 + int zip64; /* Add ZIP64 extened information in the extra field */ 155 + ZPOS64_T pos_zip64extrainfo; 156 + ZPOS64_T totalCompressedData; 157 + ZPOS64_T totalUncompressedData; 158 +#ifndef NOCRYPT 159 + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 160 + const unsigned long* pcrc_32_tab; 161 + int crypt_header_size; 162 +#endif 163 +} curfile64_info; 164 + 165 +typedef struct 166 +{ 167 + zlib_filefunc64_32_def z_filefunc; 168 + voidpf filestream; /* io structore of the zipfile */ 169 + linkedlist_data central_dir;/* datablock with central dir in construction*/ 170 + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ 171 + curfile64_info ci; /* info on the file curretly writing */ 172 + 173 + ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ 174 + ZPOS64_T add_position_when_writting_offset; 175 + ZPOS64_T number_entry; 176 + 177 +#ifndef NO_ADDFILEINEXISTINGZIP 178 + char *globalcomment; 179 +#endif 180 + 181 +} zip64_internal; 182 + 183 + 184 +#ifndef NOCRYPT 185 +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED 186 +#include "crypt.h" 187 +#endif 188 + 189 +local linkedlist_datablock_internal* allocate_new_datablock() 190 +{ 191 + linkedlist_datablock_internal* ldi; 192 + ldi = (linkedlist_datablock_internal*) 193 + ALLOC(sizeof(linkedlist_datablock_internal)); 194 + if (ldi!=NULL) 195 + { 196 + ldi->next_datablock = NULL ; 197 + ldi->filled_in_this_block = 0 ; 198 + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; 199 + } 200 + return ldi; 201 +} 202 + 203 +local void free_datablock(linkedlist_datablock_internal* ldi) 204 +{ 205 + while (ldi!=NULL) 206 + { 207 + linkedlist_datablock_internal* ldinext = ldi->next_datablock; 208 + TRYFREE(ldi); 209 + ldi = ldinext; 210 + } 211 +} 212 + 213 +local void init_linkedlist(linkedlist_data* ll) 214 +{ 215 + ll->first_block = ll->last_block = NULL; 216 +} 217 + 218 +local void free_linkedlist(linkedlist_data* ll) 219 +{ 220 + free_datablock(ll->first_block); 221 + ll->first_block = ll->last_block = NULL; 222 +} 223 + 224 + 225 +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) 226 +{ 227 + linkedlist_datablock_internal* ldi; 228 + const unsigned char* from_copy; 229 + 230 + if (ll==NULL) 231 + return ZIP_INTERNALERROR; 232 + 233 + if (ll->last_block == NULL) 234 + { 235 + ll->first_block = ll->last_block = allocate_new_datablock(); 236 + if (ll->first_block == NULL) 237 + return ZIP_INTERNALERROR; 238 + } 239 + 240 + ldi = ll->last_block; 241 + from_copy = (unsigned char*)buf; 242 + 243 + while (len>0) 244 + { 245 + uInt copy_this; 246 + uInt i; 247 + unsigned char* to_copy; 248 + 249 + if (ldi->avail_in_this_block==0) 250 + { 251 + ldi->next_datablock = allocate_new_datablock(); 252 + if (ldi->next_datablock == NULL) 253 + return ZIP_INTERNALERROR; 254 + ldi = ldi->next_datablock ; 255 + ll->last_block = ldi; 256 + } 257 + 258 + if (ldi->avail_in_this_block < len) 259 + copy_this = (uInt)ldi->avail_in_this_block; 260 + else 261 + copy_this = (uInt)len; 262 + 263 + to_copy = &(ldi->data[ldi->filled_in_this_block]); 264 + 265 + for (i=0;i<copy_this;i++) 266 + *(to_copy+i)=*(from_copy+i); 267 + 268 + ldi->filled_in_this_block += copy_this; 269 + ldi->avail_in_this_block -= copy_this; 270 + from_copy += copy_this ; 271 + len -= copy_this; 272 + } 273 + return ZIP_OK; 274 +} 275 + 276 + 277 + 278 +/****************************************************************************/ 279 + 280 +#ifndef NO_ADDFILEINEXISTINGZIP 281 +/* =========================================================================== 282 + Inputs a long in LSB order to the given file 283 + nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) 284 +*/ 285 + 286 +local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); 287 +local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) 288 +{ 289 + unsigned char buf[8]; 290 + int n; 291 + for (n = 0; n < nbByte; n++) 292 + { 293 + buf[n] = (unsigned char)(x & 0xff); 294 + x >>= 8; 295 + } 296 + if (x != 0) 297 + { /* data overflow - hack for ZIP64 (X Roche) */ 298 + for (n = 0; n < nbByte; n++) 299 + { 300 + buf[n] = 0xff; 301 + } 302 + } 303 + 304 + if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) 305 + return ZIP_ERRNO; 306 + else 307 + return ZIP_OK; 308 +} 309 + 310 +local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); 311 +local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) 312 +{ 313 + unsigned char* buf=(unsigned char*)dest; 314 + int n; 315 + for (n = 0; n < nbByte; n++) { 316 + buf[n] = (unsigned char)(x & 0xff); 317 + x >>= 8; 318 + } 319 + 320 + if (x != 0) 321 + { /* data overflow - hack for ZIP64 */ 322 + for (n = 0; n < nbByte; n++) 323 + { 324 + buf[n] = 0xff; 325 + } 326 + } 327 +} 328 + 329 +/****************************************************************************/ 330 + 331 + 332 +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) 333 +{ 334 + uLong year = (uLong)ptm->tm_year; 335 + if (year>=1980) 336 + year-=1980; 337 + else if (year>=80) 338 + year-=80; 339 + return 340 + (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | 341 + ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); 342 +} 343 + 344 + 345 +/****************************************************************************/ 346 + 347 +local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); 348 + 349 +local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) 350 +{ 351 + unsigned char c; 352 + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); 353 + if (err==1) 354 + { 355 + *pi = (int)c; 356 + return ZIP_OK; 357 + } 358 + else 359 + { 360 + if (ZERROR64(*pzlib_filefunc_def,filestream)) 361 + return ZIP_ERRNO; 362 + else 363 + return ZIP_EOF; 364 + } 365 +} 366 + 367 + 368 +/* =========================================================================== 369 + Reads a long in LSB order from the given gz_stream. Sets 370 +*/ 371 +local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); 372 + 373 +local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) 374 +{ 375 + uLong x ; 376 + int i = 0; 377 + int err; 378 + 379 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 380 + x = (uLong)i; 381 + 382 + if (err==ZIP_OK) 383 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 384 + x += ((uLong)i)<<8; 385 + 386 + if (err==ZIP_OK) 387 + *pX = x; 388 + else 389 + *pX = 0; 390 + return err; 391 +} 392 + 393 +local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); 394 + 395 +local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) 396 +{ 397 + uLong x ; 398 + int i = 0; 399 + int err; 400 + 401 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 402 + x = (uLong)i; 403 + 404 + if (err==ZIP_OK) 405 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 406 + x += ((uLong)i)<<8; 407 + 408 + if (err==ZIP_OK) 409 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 410 + x += ((uLong)i)<<16; 411 + 412 + if (err==ZIP_OK) 413 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 414 + x += ((uLong)i)<<24; 415 + 416 + if (err==ZIP_OK) 417 + *pX = x; 418 + else 419 + *pX = 0; 420 + return err; 421 +} 422 + 423 +local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); 424 + 425 + 426 +local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) 427 +{ 428 + ZPOS64_T x; 429 + int i = 0; 430 + int err; 431 + 432 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 433 + x = (ZPOS64_T)i; 434 + 435 + if (err==ZIP_OK) 436 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 437 + x += ((ZPOS64_T)i)<<8; 438 + 439 + if (err==ZIP_OK) 440 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 441 + x += ((ZPOS64_T)i)<<16; 442 + 443 + if (err==ZIP_OK) 444 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 445 + x += ((ZPOS64_T)i)<<24; 446 + 447 + if (err==ZIP_OK) 448 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 449 + x += ((ZPOS64_T)i)<<32; 450 + 451 + if (err==ZIP_OK) 452 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 453 + x += ((ZPOS64_T)i)<<40; 454 + 455 + if (err==ZIP_OK) 456 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 457 + x += ((ZPOS64_T)i)<<48; 458 + 459 + if (err==ZIP_OK) 460 + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); 461 + x += ((ZPOS64_T)i)<<56; 462 + 463 + if (err==ZIP_OK) 464 + *pX = x; 465 + else 466 + *pX = 0; 467 + 468 + return err; 469 +} 470 + 471 +#ifndef BUFREADCOMMENT 472 +#define BUFREADCOMMENT (0x400) 473 +#endif 474 +/* 475 + Locate the Central directory of a zipfile (at the end, just before 476 + the global comment) 477 +*/ 478 +local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); 479 + 480 +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) 481 +{ 482 + unsigned char* buf; 483 + ZPOS64_T uSizeFile; 484 + ZPOS64_T uBackRead; 485 + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 486 + ZPOS64_T uPosFound=0; 487 + 488 + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 489 + return 0; 490 + 491 + 492 + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 493 + 494 + if (uMaxBack>uSizeFile) 495 + uMaxBack = uSizeFile; 496 + 497 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 498 + if (buf==NULL) 499 + return 0; 500 + 501 + uBackRead = 4; 502 + while (uBackRead<uMaxBack) 503 + { 504 + uLong uReadSize; 505 + ZPOS64_T uReadPos ; 506 + int i; 507 + if (uBackRead+BUFREADCOMMENT>uMaxBack) 508 + uBackRead = uMaxBack; 509 + else 510 + uBackRead+=BUFREADCOMMENT; 511 + uReadPos = uSizeFile-uBackRead ; 512 + 513 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 514 + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 515 + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 516 + break; 517 + 518 + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 519 + break; 520 + 521 + for (i=(int)uReadSize-3; (i--)>0;) 522 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 523 + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 524 + { 525 + uPosFound = uReadPos+i; 526 + break; 527 + } 528 + 529 + if (uPosFound!=0) 530 + break; 531 + } 532 + TRYFREE(buf); 533 + return uPosFound; 534 +} 535 + 536 +/* 537 +Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before 538 +the global comment) 539 +*/ 540 +local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); 541 + 542 +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) 543 +{ 544 + unsigned char* buf; 545 + ZPOS64_T uSizeFile; 546 + ZPOS64_T uBackRead; 547 + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ 548 + ZPOS64_T uPosFound=0; 549 + uLong uL; 550 + ZPOS64_T relativeOffset; 551 + 552 + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 553 + return 0; 554 + 555 + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); 556 + 557 + if (uMaxBack>uSizeFile) 558 + uMaxBack = uSizeFile; 559 + 560 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 561 + if (buf==NULL) 562 + return 0; 563 + 564 + uBackRead = 4; 565 + while (uBackRead<uMaxBack) 566 + { 567 + uLong uReadSize; 568 + ZPOS64_T uReadPos; 569 + int i; 570 + if (uBackRead+BUFREADCOMMENT>uMaxBack) 571 + uBackRead = uMaxBack; 572 + else 573 + uBackRead+=BUFREADCOMMENT; 574 + uReadPos = uSizeFile-uBackRead ; 575 + 576 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 577 + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); 578 + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 579 + break; 580 + 581 + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 582 + break; 583 + 584 + for (i=(int)uReadSize-3; (i--)>0;) 585 + { 586 + // Signature "0x07064b50" Zip64 end of central directory locater 587 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) 588 + { 589 + uPosFound = uReadPos+i; 590 + break; 591 + } 592 + } 593 + 594 + if (uPosFound!=0) 595 + break; 596 + } 597 + 598 + TRYFREE(buf); 599 + if (uPosFound == 0) 600 + return 0; 601 + 602 + /* Zip64 end of central directory locator */ 603 + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) 604 + return 0; 605 + 606 + /* the signature, already checked */ 607 + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) 608 + return 0; 609 + 610 + /* number of the disk with the start of the zip64 end of central directory */ 611 + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) 612 + return 0; 613 + if (uL != 0) 614 + return 0; 615 + 616 + /* relative offset of the zip64 end of central directory record */ 617 + if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) 618 + return 0; 619 + 620 + /* total number of disks */ 621 + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) 622 + return 0; 623 + if (uL != 1) 624 + return 0; 625 + 626 + /* Goto Zip64 end of central directory record */ 627 + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) 628 + return 0; 629 + 630 + /* the signature */ 631 + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) 632 + return 0; 633 + 634 + if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' 635 + return 0; 636 + 637 + return relativeOffset; 638 +} 639 + 640 +int LoadCentralDirectoryRecord(zip64_internal* pziinit) 641 +{ 642 + int err=ZIP_OK; 643 + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 644 + 645 + ZPOS64_T size_central_dir; /* size of the central directory */ 646 + ZPOS64_T offset_central_dir; /* offset of start of central directory */ 647 + ZPOS64_T central_pos; 648 + uLong uL; 649 + 650 + uLong number_disk; /* number of the current dist, used for 651 + spaning ZIP, unsupported, always 0*/ 652 + uLong number_disk_with_CD; /* number the the disk with central dir, used 653 + for spaning ZIP, unsupported, always 0*/ 654 + ZPOS64_T number_entry; 655 + ZPOS64_T number_entry_CD; /* total number of entries in 656 + the central dir 657 + (same than number_entry on nospan) */ 658 + uLong VersionMadeBy; 659 + uLong VersionNeeded; 660 + uLong size_comment; 661 + 662 + int hasZIP64Record = 0; 663 + 664 + // check first if we find a ZIP64 record 665 + central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); 666 + if(central_pos > 0) 667 + { 668 + hasZIP64Record = 1; 669 + } 670 + else if(central_pos == 0) 671 + { 672 + central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); 673 + } 674 + 675 +/* disable to allow appending to empty ZIP archive 676 + if (central_pos==0) 677 + err=ZIP_ERRNO; 678 +*/ 679 + 680 + if(hasZIP64Record) 681 + { 682 + ZPOS64_T sizeEndOfCentralDirectory; 683 + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) 684 + err=ZIP_ERRNO; 685 + 686 + /* the signature, already checked */ 687 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) 688 + err=ZIP_ERRNO; 689 + 690 + /* size of zip64 end of central directory record */ 691 + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) 692 + err=ZIP_ERRNO; 693 + 694 + /* version made by */ 695 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) 696 + err=ZIP_ERRNO; 697 + 698 + /* version needed to extract */ 699 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) 700 + err=ZIP_ERRNO; 701 + 702 + /* number of this disk */ 703 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) 704 + err=ZIP_ERRNO; 705 + 706 + /* number of the disk with the start of the central directory */ 707 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) 708 + err=ZIP_ERRNO; 709 + 710 + /* total number of entries in the central directory on this disk */ 711 + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) 712 + err=ZIP_ERRNO; 713 + 714 + /* total number of entries in the central directory */ 715 + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) 716 + err=ZIP_ERRNO; 717 + 718 + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) 719 + err=ZIP_BADZIPFILE; 720 + 721 + /* size of the central directory */ 722 + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) 723 + err=ZIP_ERRNO; 724 + 725 + /* offset of start of central directory with respect to the 726 + starting disk number */ 727 + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) 728 + err=ZIP_ERRNO; 729 + 730 + // TODO.. 731 + // read the comment from the standard central header. 732 + size_comment = 0; 733 + } 734 + else 735 + { 736 + // Read End of central Directory info 737 + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 738 + err=ZIP_ERRNO; 739 + 740 + /* the signature, already checked */ 741 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) 742 + err=ZIP_ERRNO; 743 + 744 + /* number of this disk */ 745 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) 746 + err=ZIP_ERRNO; 747 + 748 + /* number of the disk with the start of the central directory */ 749 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) 750 + err=ZIP_ERRNO; 751 + 752 + /* total number of entries in the central dir on this disk */ 753 + number_entry = 0; 754 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) 755 + err=ZIP_ERRNO; 756 + else 757 + number_entry = uL; 758 + 759 + /* total number of entries in the central dir */ 760 + number_entry_CD = 0; 761 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) 762 + err=ZIP_ERRNO; 763 + else 764 + number_entry_CD = uL; 765 + 766 + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) 767 + err=ZIP_BADZIPFILE; 768 + 769 + /* size of the central directory */ 770 + size_central_dir = 0; 771 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) 772 + err=ZIP_ERRNO; 773 + else 774 + size_central_dir = uL; 775 + 776 + /* offset of start of central directory with respect to the starting disk number */ 777 + offset_central_dir = 0; 778 + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) 779 + err=ZIP_ERRNO; 780 + else 781 + offset_central_dir = uL; 782 + 783 + 784 + /* zipfile global comment length */ 785 + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) 786 + err=ZIP_ERRNO; 787 + } 788 + 789 + if ((central_pos<offset_central_dir+size_central_dir) && 790 + (err==ZIP_OK)) 791 + err=ZIP_BADZIPFILE; 792 + 793 + if (err!=ZIP_OK) 794 + { 795 + ZCLOSE64(pziinit->z_filefunc, pziinit->filestream); 796 + return ZIP_ERRNO; 797 + } 798 + 799 + if (size_comment>0) 800 + { 801 + pziinit->globalcomment = (char*)ALLOC(size_comment+1); 802 + if (pziinit->globalcomment) 803 + { 804 + size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); 805 + pziinit->globalcomment[size_comment]=0; 806 + } 807 + } 808 + 809 + byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); 810 + pziinit->add_position_when_writting_offset = byte_before_the_zipfile; 811 + 812 + { 813 + ZPOS64_T size_central_dir_to_read = size_central_dir; 814 + size_t buf_size = SIZEDATA_INDATABLOCK; 815 + void* buf_read = (void*)ALLOC(buf_size); 816 + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) 817 + err=ZIP_ERRNO; 818 + 819 + while ((size_central_dir_to_read>0) && (err==ZIP_OK)) 820 + { 821 + ZPOS64_T read_this = SIZEDATA_INDATABLOCK; 822 + if (read_this > size_central_dir_to_read) 823 + read_this = size_central_dir_to_read; 824 + 825 + if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) 826 + err=ZIP_ERRNO; 827 + 828 + if (err==ZIP_OK) 829 + err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); 830 + 831 + size_central_dir_to_read-=read_this; 832 + } 833 + TRYFREE(buf_read); 834 + } 835 + pziinit->begin_pos = byte_before_the_zipfile; 836 + pziinit->number_entry = number_entry_CD; 837 + 838 + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) 839 + err=ZIP_ERRNO; 840 + 841 + return err; 842 +} 843 + 844 + 845 +#endif /* !NO_ADDFILEINEXISTINGZIP*/ 846 + 847 + 848 +/************************************************************/ 849 +extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) 850 +{ 851 + zip64_internal ziinit; 852 + zip64_internal* zi; 853 + int err=ZIP_OK; 854 + 855 + ziinit.z_filefunc.zseek32_file = NULL; 856 + ziinit.z_filefunc.ztell32_file = NULL; 857 + if (pzlib_filefunc64_32_def==NULL) 858 + fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); 859 + else 860 + ziinit.z_filefunc = *pzlib_filefunc64_32_def; 861 + 862 + ziinit.filestream = ZOPEN64(ziinit.z_filefunc, 863 + pathname, 864 + (append == APPEND_STATUS_CREATE) ? 865 + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : 866 + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); 867 + 868 + if (ziinit.filestream == NULL) 869 + return NULL; 870 + 871 + if (append == APPEND_STATUS_CREATEAFTER) 872 + ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); 873 + 874 + ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); 875 + ziinit.in_opened_file_inzip = 0; 876 + ziinit.ci.stream_initialised = 0; 877 + ziinit.number_entry = 0; 878 + ziinit.add_position_when_writting_offset = 0; 879 + init_linkedlist(&(ziinit.central_dir)); 880 + 881 + 882 + 883 + zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); 884 + if (zi==NULL) 885 + { 886 + ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); 887 + return NULL; 888 + } 889 + 890 + /* now we add file in a zipfile */ 891 +# ifndef NO_ADDFILEINEXISTINGZIP 892 + ziinit.globalcomment = NULL; 893 + if (append == APPEND_STATUS_ADDINZIP) 894 + { 895 + // Read and Cache Central Directory Records 896 + err = LoadCentralDirectoryRecord(&ziinit); 897 + } 898 + 899 + if (globalcomment) 900 + { 901 + *globalcomment = ziinit.globalcomment; 902 + } 903 +# endif /* !NO_ADDFILEINEXISTINGZIP*/ 904 + 905 + if (err != ZIP_OK) 906 + { 907 +# ifndef NO_ADDFILEINEXISTINGZIP 908 + TRYFREE(ziinit.globalcomment); 909 +# endif /* !NO_ADDFILEINEXISTINGZIP*/ 910 + TRYFREE(zi); 911 + return NULL; 912 + } 913 + else 914 + { 915 + *zi = ziinit; 916 + return (zipFile)zi; 917 + } 918 +} 919 + 920 +extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) 921 +{ 922 + if (pzlib_filefunc32_def != NULL) 923 + { 924 + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; 925 + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); 926 + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); 927 + } 928 + else 929 + return zipOpen3(pathname, append, globalcomment, NULL); 930 +} 931 + 932 +extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) 933 +{ 934 + if (pzlib_filefunc_def != NULL) 935 + { 936 + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; 937 + zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; 938 + zlib_filefunc64_32_def_fill.ztell32_file = NULL; 939 + zlib_filefunc64_32_def_fill.zseek32_file = NULL; 940 + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); 941 + } 942 + else 943 + return zipOpen3(pathname, append, globalcomment, NULL); 944 +} 945 + 946 + 947 + 948 +extern zipFile ZEXPORT zipOpen (const char* pathname, int append) 949 +{ 950 + return zipOpen3((const void*)pathname,append,NULL,NULL); 951 +} 952 + 953 +extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) 954 +{ 955 + return zipOpen3(pathname,append,NULL,NULL); 956 +} 957 + 958 +int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) 959 +{ 960 + /* write the local header */ 961 + int err; 962 + uInt size_filename = (uInt)strlen(filename); 963 + uInt size_extrafield = size_extrafield_local; 964 + 965 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); 966 + 967 + if (err==ZIP_OK) 968 + { 969 + if(zi->ci.zip64) 970 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ 971 + else 972 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ 973 + } 974 + 975 + if (err==ZIP_OK) 976 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); 977 + 978 + if (err==ZIP_OK) 979 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); 980 + 981 + if (err==ZIP_OK) 982 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); 983 + 984 + // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later 985 + if (err==ZIP_OK) 986 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ 987 + if (err==ZIP_OK) 988 + { 989 + if(zi->ci.zip64) 990 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */ 991 + else 992 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ 993 + } 994 + if (err==ZIP_OK) 995 + { 996 + if(zi->ci.zip64) 997 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ 998 + else 999 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ 1000 + } 1001 + 1002 + if (err==ZIP_OK) 1003 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); 1004 + 1005 + if(zi->ci.zip64) 1006 + { 1007 + size_extrafield += 20; 1008 + } 1009 + 1010 + if (err==ZIP_OK) 1011 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); 1012 + 1013 + if ((err==ZIP_OK) && (size_filename > 0)) 1014 + { 1015 + if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) 1016 + err = ZIP_ERRNO; 1017 + } 1018 + 1019 + if ((err==ZIP_OK) && (size_extrafield_local > 0)) 1020 + { 1021 + if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) 1022 + err = ZIP_ERRNO; 1023 + } 1024 + 1025 + 1026 + if ((err==ZIP_OK) && (zi->ci.zip64)) 1027 + { 1028 + // write the Zip64 extended info 1029 + short HeaderID = 1; 1030 + short DataSize = 16; 1031 + ZPOS64_T CompressedSize = 0; 1032 + ZPOS64_T UncompressedSize = 0; 1033 + 1034 + // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) 1035 + zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); 1036 + 1037 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); 1038 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); 1039 + 1040 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); 1041 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); 1042 + } 1043 + 1044 + return err; 1045 +} 1046 + 1047 +/* 1048 + NOTE. 1049 + When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped 1050 + before calling this function it can be done with zipRemoveExtraInfoBlock 1051 + 1052 + It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize 1053 + unnecessary allocations. 1054 + */ 1055 +extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, 1056 + const void* extrafield_local, uInt size_extrafield_local, 1057 + const void* extrafield_global, uInt size_extrafield_global, 1058 + const char* comment, int method, int level, int raw, 1059 + int windowBits,int memLevel, int strategy, 1060 + const char* password, uLong crcForCrypting, 1061 + uLong versionMadeBy, uLong flagBase, int zip64) 1062 +{ 1063 + zip64_internal* zi; 1064 + uInt size_filename; 1065 + uInt size_comment; 1066 + uInt i; 1067 + int err = ZIP_OK; 1068 + 1069 +# ifdef NOCRYPT 1070 + (crcForCrypting); 1071 + if (password != NULL) 1072 + return ZIP_PARAMERROR; 1073 +# endif 1074 + 1075 + if (file == NULL) 1076 + return ZIP_PARAMERROR; 1077 + 1078 +#ifdef HAVE_BZIP2 1079 + if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) 1080 + return ZIP_PARAMERROR; 1081 +#else 1082 + if ((method!=0) && (method!=Z_DEFLATED)) 1083 + return ZIP_PARAMERROR; 1084 +#endif 1085 + 1086 + zi = (zip64_internal*)file; 1087 + 1088 + if (zi->in_opened_file_inzip == 1) 1089 + { 1090 + err = zipCloseFileInZip (file); 1091 + if (err != ZIP_OK) 1092 + return err; 1093 + } 1094 + 1095 + if (filename==NULL) 1096 + filename="-"; 1097 + 1098 + if (comment==NULL) 1099 + size_comment = 0; 1100 + else 1101 + size_comment = (uInt)strlen(comment); 1102 + 1103 + size_filename = (uInt)strlen(filename); 1104 + 1105 + if (zipfi == NULL) 1106 + zi->ci.dosDate = 0; 1107 + else 1108 + { 1109 + if (zipfi->dosDate != 0) 1110 + zi->ci.dosDate = zipfi->dosDate; 1111 + else 1112 + zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); 1113 + } 1114 + 1115 + zi->ci.flag = flagBase; 1116 + if ((level==8) || (level==9)) 1117 + zi->ci.flag |= 2; 1118 + if (level==2) 1119 + zi->ci.flag |= 4; 1120 + if (level==1) 1121 + zi->ci.flag |= 6; 1122 + if (password != NULL) 1123 + zi->ci.flag |= 1; 1124 + 1125 + zi->ci.crc32 = 0; 1126 + zi->ci.method = method; 1127 + zi->ci.encrypt = 0; 1128 + zi->ci.stream_initialised = 0; 1129 + zi->ci.pos_in_buffered_data = 0; 1130 + zi->ci.raw = raw; 1131 + zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); 1132 + 1133 + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; 1134 + zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data 1135 + 1136 + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); 1137 + 1138 + zi->ci.size_centralExtra = size_extrafield_global; 1139 + zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); 1140 + /* version info */ 1141 + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2); 1142 + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); 1143 + zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); 1144 + zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); 1145 + zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); 1146 + zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ 1147 + zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ 1148 + zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ 1149 + zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); 1150 + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); 1151 + zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); 1152 + zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ 1153 + 1154 + if (zipfi==NULL) 1155 + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); 1156 + else 1157 + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); 1158 + 1159 + if (zipfi==NULL) 1160 + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); 1161 + else 1162 + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); 1163 + 1164 + if(zi->ci.pos_local_header >= 0xffffffff) 1165 + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); 1166 + else 1167 + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); 1168 + 1169 + for (i=0;i<size_filename;i++) 1170 + *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 1171 + 1172 + for (i=0;i<size_extrafield_global;i++) 1173 + *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) = 1174 + *(((const char*)extrafield_global)+i); 1175 + 1176 + for (i=0;i<size_comment;i++) 1177 + *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+ 1178 + size_extrafield_global+i) = *(comment+i); 1179 + if (zi->ci.central_header == NULL) 1180 + return ZIP_INTERNALERROR; 1181 + 1182 + zi->ci.zip64 = zip64; 1183 + zi->ci.totalCompressedData = 0; 1184 + zi->ci.totalUncompressedData = 0; 1185 + zi->ci.pos_zip64extrainfo = 0; 1186 + 1187 + err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); 1188 + 1189 +#ifdef HAVE_BZIP2 1190 + zi->ci.bstream.avail_in = (uInt)0; 1191 + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; 1192 + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; 1193 + zi->ci.bstream.total_in_hi32 = 0; 1194 + zi->ci.bstream.total_in_lo32 = 0; 1195 + zi->ci.bstream.total_out_hi32 = 0; 1196 + zi->ci.bstream.total_out_lo32 = 0; 1197 +#endif 1198 + 1199 + zi->ci.stream.avail_in = (uInt)0; 1200 + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1201 + zi->ci.stream.next_out = zi->ci.buffered_data; 1202 + zi->ci.stream.total_in = 0; 1203 + zi->ci.stream.total_out = 0; 1204 + zi->ci.stream.data_type = Z_BINARY; 1205 + 1206 +#ifdef HAVE_BZIP2 1207 + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) 1208 +#else 1209 + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1210 +#endif 1211 + { 1212 + if(zi->ci.method == Z_DEFLATED) 1213 + { 1214 + zi->ci.stream.zalloc = (alloc_func)0; 1215 + zi->ci.stream.zfree = (free_func)0; 1216 + zi->ci.stream.opaque = (voidpf)0; 1217 + 1218 + if (windowBits>0) 1219 + windowBits = -windowBits; 1220 + 1221 + err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); 1222 + 1223 + if (err==Z_OK) 1224 + zi->ci.stream_initialised = Z_DEFLATED; 1225 + } 1226 + else if(zi->ci.method == Z_BZIP2ED) 1227 + { 1228 +#ifdef HAVE_BZIP2 1229 + // Init BZip stuff here 1230 + zi->ci.bstream.bzalloc = 0; 1231 + zi->ci.bstream.bzfree = 0; 1232 + zi->ci.bstream.opaque = (voidpf)0; 1233 + 1234 + err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); 1235 + if(err == BZ_OK) 1236 + zi->ci.stream_initialised = Z_BZIP2ED; 1237 +#endif 1238 + } 1239 + 1240 + } 1241 + 1242 +# ifndef NOCRYPT 1243 + zi->ci.crypt_header_size = 0; 1244 + if ((err==Z_OK) && (password != NULL)) 1245 + { 1246 + unsigned char bufHead[RAND_HEAD_LEN]; 1247 + unsigned int sizeHead; 1248 + zi->ci.encrypt = 1; 1249 + zi->ci.pcrc_32_tab = get_crc_table(); 1250 + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ 1251 + 1252 + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); 1253 + zi->ci.crypt_header_size = sizeHead; 1254 + 1255 + if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) 1256 + err = ZIP_ERRNO; 1257 + } 1258 +# endif 1259 + 1260 + if (err==Z_OK) 1261 + zi->in_opened_file_inzip = 1; 1262 + return err; 1263 +} 1264 + 1265 +extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, 1266 + const void* extrafield_local, uInt size_extrafield_local, 1267 + const void* extrafield_global, uInt size_extrafield_global, 1268 + const char* comment, int method, int level, int raw, 1269 + int windowBits,int memLevel, int strategy, 1270 + const char* password, uLong crcForCrypting, 1271 + uLong versionMadeBy, uLong flagBase) 1272 +{ 1273 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1274 + extrafield_local, size_extrafield_local, 1275 + extrafield_global, size_extrafield_global, 1276 + comment, method, level, raw, 1277 + windowBits, memLevel, strategy, 1278 + password, crcForCrypting, versionMadeBy, flagBase, 0); 1279 +} 1280 + 1281 +extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, 1282 + const void* extrafield_local, uInt size_extrafield_local, 1283 + const void* extrafield_global, uInt size_extrafield_global, 1284 + const char* comment, int method, int level, int raw, 1285 + int windowBits,int memLevel, int strategy, 1286 + const char* password, uLong crcForCrypting) 1287 +{ 1288 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1289 + extrafield_local, size_extrafield_local, 1290 + extrafield_global, size_extrafield_global, 1291 + comment, method, level, raw, 1292 + windowBits, memLevel, strategy, 1293 + password, crcForCrypting, VERSIONMADEBY, 0, 0); 1294 +} 1295 + 1296 +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, 1297 + const void* extrafield_local, uInt size_extrafield_local, 1298 + const void* extrafield_global, uInt size_extrafield_global, 1299 + const char* comment, int method, int level, int raw, 1300 + int windowBits,int memLevel, int strategy, 1301 + const char* password, uLong crcForCrypting, int zip64) 1302 +{ 1303 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1304 + extrafield_local, size_extrafield_local, 1305 + extrafield_global, size_extrafield_global, 1306 + comment, method, level, raw, 1307 + windowBits, memLevel, strategy, 1308 + password, crcForCrypting, VERSIONMADEBY, 0, zip64); 1309 +} 1310 + 1311 +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, 1312 + const void* extrafield_local, uInt size_extrafield_local, 1313 + const void* extrafield_global, uInt size_extrafield_global, 1314 + const char* comment, int method, int level, int raw) 1315 +{ 1316 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1317 + extrafield_local, size_extrafield_local, 1318 + extrafield_global, size_extrafield_global, 1319 + comment, method, level, raw, 1320 + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1321 + NULL, 0, VERSIONMADEBY, 0, 0); 1322 +} 1323 + 1324 +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, 1325 + const void* extrafield_local, uInt size_extrafield_local, 1326 + const void* extrafield_global, uInt size_extrafield_global, 1327 + const char* comment, int method, int level, int raw, int zip64) 1328 +{ 1329 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1330 + extrafield_local, size_extrafield_local, 1331 + extrafield_global, size_extrafield_global, 1332 + comment, method, level, raw, 1333 + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1334 + NULL, 0, VERSIONMADEBY, 0, zip64); 1335 +} 1336 + 1337 +extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, 1338 + const void* extrafield_local, uInt size_extrafield_local, 1339 + const void*extrafield_global, uInt size_extrafield_global, 1340 + const char* comment, int method, int level, int zip64) 1341 +{ 1342 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1343 + extrafield_local, size_extrafield_local, 1344 + extrafield_global, size_extrafield_global, 1345 + comment, method, level, 0, 1346 + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1347 + NULL, 0, VERSIONMADEBY, 0, zip64); 1348 +} 1349 + 1350 +extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, 1351 + const void* extrafield_local, uInt size_extrafield_local, 1352 + const void*extrafield_global, uInt size_extrafield_global, 1353 + const char* comment, int method, int level) 1354 +{ 1355 + return zipOpenNewFileInZip4_64 (file, filename, zipfi, 1356 + extrafield_local, size_extrafield_local, 1357 + extrafield_global, size_extrafield_global, 1358 + comment, method, level, 0, 1359 + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1360 + NULL, 0, VERSIONMADEBY, 0, 0); 1361 +} 1362 + 1363 +local int zip64FlushWriteBuffer(zip64_internal* zi) 1364 +{ 1365 + int err=ZIP_OK; 1366 + 1367 + if (zi->ci.encrypt != 0) 1368 + { 1369 +#ifndef NOCRYPT 1370 + uInt i; 1371 + int t; 1372 + for (i=0;i<zi->ci.pos_in_buffered_data;i++) 1373 + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); 1374 +#endif 1375 + } 1376 + 1377 + if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) 1378 + err = ZIP_ERRNO; 1379 + 1380 + zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; 1381 + 1382 +#ifdef HAVE_BZIP2 1383 + if(zi->ci.method == Z_BZIP2ED) 1384 + { 1385 + zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; 1386 + zi->ci.bstream.total_in_lo32 = 0; 1387 + zi->ci.bstream.total_in_hi32 = 0; 1388 + } 1389 + else 1390 +#endif 1391 + { 1392 + zi->ci.totalUncompressedData += zi->ci.stream.total_in; 1393 + zi->ci.stream.total_in = 0; 1394 + } 1395 + 1396 + 1397 + zi->ci.pos_in_buffered_data = 0; 1398 + 1399 + return err; 1400 +} 1401 + 1402 +extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) 1403 +{ 1404 + zip64_internal* zi; 1405 + int err=ZIP_OK; 1406 + 1407 + if (file == NULL) 1408 + return ZIP_PARAMERROR; 1409 + zi = (zip64_internal*)file; 1410 + 1411 + if (zi->in_opened_file_inzip == 0) 1412 + return ZIP_PARAMERROR; 1413 + 1414 + zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); 1415 + 1416 +#ifdef HAVE_BZIP2 1417 + if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw)) 1418 + { 1419 + zi->ci.bstream.next_in = (void*)buf; 1420 + zi->ci.bstream.avail_in = len; 1421 + err = BZ_RUN_OK; 1422 + 1423 + while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0)) 1424 + { 1425 + if (zi->ci.bstream.avail_out == 0) 1426 + { 1427 + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) 1428 + err = ZIP_ERRNO; 1429 + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; 1430 + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; 1431 + } 1432 + 1433 + 1434 + if(err != BZ_RUN_OK) 1435 + break; 1436 + 1437 + if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) 1438 + { 1439 + uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; 1440 +// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; 1441 + err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); 1442 + 1443 + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; 1444 + } 1445 + } 1446 + 1447 + if(err == BZ_RUN_OK) 1448 + err = ZIP_OK; 1449 + } 1450 + else 1451 +#endif 1452 + { 1453 + zi->ci.stream.next_in = (Bytef*)buf; 1454 + zi->ci.stream.avail_in = len; 1455 + 1456 + while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) 1457 + { 1458 + if (zi->ci.stream.avail_out == 0) 1459 + { 1460 + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) 1461 + err = ZIP_ERRNO; 1462 + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1463 + zi->ci.stream.next_out = zi->ci.buffered_data; 1464 + } 1465 + 1466 + 1467 + if(err != ZIP_OK) 1468 + break; 1469 + 1470 + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1471 + { 1472 + uLong uTotalOutBefore = zi->ci.stream.total_out; 1473 + err=deflate(&zi->ci.stream, Z_NO_FLUSH); 1474 + if(uTotalOutBefore > zi->ci.stream.total_out) 1475 + { 1476 + int bBreak = 0; 1477 + bBreak++; 1478 + } 1479 + 1480 + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1481 + } 1482 + else 1483 + { 1484 + uInt copy_this,i; 1485 + if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) 1486 + copy_this = zi->ci.stream.avail_in; 1487 + else 1488 + copy_this = zi->ci.stream.avail_out; 1489 + 1490 + for (i = 0; i < copy_this; i++) 1491 + *(((char*)zi->ci.stream.next_out)+i) = 1492 + *(((const char*)zi->ci.stream.next_in)+i); 1493 + { 1494 + zi->ci.stream.avail_in -= copy_this; 1495 + zi->ci.stream.avail_out-= copy_this; 1496 + zi->ci.stream.next_in+= copy_this; 1497 + zi->ci.stream.next_out+= copy_this; 1498 + zi->ci.stream.total_in+= copy_this; 1499 + zi->ci.stream.total_out+= copy_this; 1500 + zi->ci.pos_in_buffered_data += copy_this; 1501 + } 1502 + } 1503 + }// while(...) 1504 + } 1505 + 1506 + return err; 1507 +} 1508 + 1509 +extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) 1510 +{ 1511 + return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); 1512 +} 1513 + 1514 +extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) 1515 +{ 1516 + zip64_internal* zi; 1517 + ZPOS64_T compressed_size; 1518 + uLong invalidValue = 0xffffffff; 1519 + short datasize = 0; 1520 + int err=ZIP_OK; 1521 + 1522 + if (file == NULL) 1523 + return ZIP_PARAMERROR; 1524 + zi = (zip64_internal*)file; 1525 + 1526 + if (zi->in_opened_file_inzip == 0) 1527 + return ZIP_PARAMERROR; 1528 + zi->ci.stream.avail_in = 0; 1529 + 1530 + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1531 + { 1532 + while (err==ZIP_OK) 1533 + { 1534 + uLong uTotalOutBefore; 1535 + if (zi->ci.stream.avail_out == 0) 1536 + { 1537 + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) 1538 + err = ZIP_ERRNO; 1539 + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1540 + zi->ci.stream.next_out = zi->ci.buffered_data; 1541 + } 1542 + uTotalOutBefore = zi->ci.stream.total_out; 1543 + err=deflate(&zi->ci.stream, Z_FINISH); 1544 + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1545 + } 1546 + } 1547 + else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) 1548 + { 1549 +#ifdef HAVE_BZIP2 1550 + err = BZ_FINISH_OK; 1551 + while (err==BZ_FINISH_OK) 1552 + { 1553 + uLong uTotalOutBefore; 1554 + if (zi->ci.bstream.avail_out == 0) 1555 + { 1556 + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) 1557 + err = ZIP_ERRNO; 1558 + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; 1559 + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; 1560 + } 1561 + uTotalOutBefore = zi->ci.bstream.total_out_lo32; 1562 + err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); 1563 + if(err == BZ_STREAM_END) 1564 + err = Z_STREAM_END; 1565 + 1566 + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); 1567 + } 1568 + 1569 + if(err == BZ_FINISH_OK) 1570 + err = ZIP_OK; 1571 +#endif 1572 + } 1573 + 1574 + if (err==Z_STREAM_END) 1575 + err=ZIP_OK; /* this is normal */ 1576 + 1577 + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) 1578 + { 1579 + if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) 1580 + err = ZIP_ERRNO; 1581 + } 1582 + 1583 + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1584 + { 1585 + int tmp_err = deflateEnd(&zi->ci.stream); 1586 + if (err == ZIP_OK) 1587 + err = tmp_err; 1588 + zi->ci.stream_initialised = 0; 1589 + } 1590 +#ifdef HAVE_BZIP2 1591 + else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) 1592 + { 1593 + int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); 1594 + if (err==ZIP_OK) 1595 + err = tmperr; 1596 + zi->ci.stream_initialised = 0; 1597 + } 1598 +#endif 1599 + 1600 + if (!zi->ci.raw) 1601 + { 1602 + crc32 = (uLong)zi->ci.crc32; 1603 + uncompressed_size = zi->ci.totalUncompressedData; 1604 + } 1605 + compressed_size = zi->ci.totalCompressedData; 1606 + 1607 +# ifndef NOCRYPT 1608 + compressed_size += zi->ci.crypt_header_size; 1609 +# endif 1610 + 1611 + // update Current Item crc and sizes, 1612 + if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) 1613 + { 1614 + /*version Made by*/ 1615 + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); 1616 + /*version needed*/ 1617 + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); 1618 + 1619 + } 1620 + 1621 + zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ 1622 + 1623 + 1624 + if(compressed_size >= 0xffffffff) 1625 + zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/ 1626 + else 1627 + zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ 1628 + 1629 + /// set internal file attributes field 1630 + if (zi->ci.stream.data_type == Z_ASCII) 1631 + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); 1632 + 1633 + if(uncompressed_size >= 0xffffffff) 1634 + zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/ 1635 + else 1636 + zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ 1637 + 1638 + // Add ZIP64 extra info field for uncompressed size 1639 + if(uncompressed_size >= 0xffffffff) 1640 + datasize += 8; 1641 + 1642 + // Add ZIP64 extra info field for compressed size 1643 + if(compressed_size >= 0xffffffff) 1644 + datasize += 8; 1645 + 1646 + // Add ZIP64 extra info field for relative offset to local file header of current file 1647 + if(zi->ci.pos_local_header >= 0xffffffff) 1648 + datasize += 8; 1649 + 1650 + if(datasize > 0) 1651 + { 1652 + char* p = NULL; 1653 + 1654 + if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) 1655 + { 1656 + // we can not write more data to the buffer that we have room for. 1657 + return ZIP_BADZIPFILE; 1658 + } 1659 + 1660 + p = zi->ci.central_header + zi->ci.size_centralheader; 1661 + 1662 + // Add Extra Information Header for 'ZIP64 information' 1663 + zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID 1664 + p += 2; 1665 + zip64local_putValue_inmemory(p, datasize, 2); // DataSize 1666 + p += 2; 1667 + 1668 + if(uncompressed_size >= 0xffffffff) 1669 + { 1670 + zip64local_putValue_inmemory(p, uncompressed_size, 8); 1671 + p += 8; 1672 + } 1673 + 1674 + if(compressed_size >= 0xffffffff) 1675 + { 1676 + zip64local_putValue_inmemory(p, compressed_size, 8); 1677 + p += 8; 1678 + } 1679 + 1680 + if(zi->ci.pos_local_header >= 0xffffffff) 1681 + { 1682 + zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); 1683 + p += 8; 1684 + } 1685 + 1686 + // Update how much extra free space we got in the memory buffer 1687 + // and increase the centralheader size so the new ZIP64 fields are included 1688 + // ( 4 below is the size of HeaderID and DataSize field ) 1689 + zi->ci.size_centralExtraFree -= datasize + 4; 1690 + zi->ci.size_centralheader += datasize + 4; 1691 + 1692 + // Update the extra info size field 1693 + zi->ci.size_centralExtra += datasize + 4; 1694 + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); 1695 + } 1696 + 1697 + if (err==ZIP_OK) 1698 + err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); 1699 + 1700 + free(zi->ci.central_header); 1701 + 1702 + if (err==ZIP_OK) 1703 + { 1704 + // Update the LocalFileHeader with the new values. 1705 + 1706 + ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); 1707 + 1708 + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) 1709 + err = ZIP_ERRNO; 1710 + 1711 + if (err==ZIP_OK) 1712 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ 1713 + 1714 + if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff ) 1715 + { 1716 + if(zi->ci.pos_zip64extrainfo > 0) 1717 + { 1718 + // Update the size in the ZIP64 extended field. 1719 + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) 1720 + err = ZIP_ERRNO; 1721 + 1722 + if (err==ZIP_OK) /* compressed size, unknown */ 1723 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); 1724 + 1725 + if (err==ZIP_OK) /* uncompressed size, unknown */ 1726 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); 1727 + } 1728 + else 1729 + err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal 1730 + } 1731 + else 1732 + { 1733 + if (err==ZIP_OK) /* compressed size, unknown */ 1734 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); 1735 + 1736 + if (err==ZIP_OK) /* uncompressed size, unknown */ 1737 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); 1738 + } 1739 + 1740 + if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) 1741 + err = ZIP_ERRNO; 1742 + } 1743 + 1744 + zi->number_entry ++; 1745 + zi->in_opened_file_inzip = 0; 1746 + 1747 + return err; 1748 +} 1749 + 1750 +extern int ZEXPORT zipCloseFileInZip (zipFile file) 1751 +{ 1752 + return zipCloseFileInZipRaw (file,0,0); 1753 +} 1754 + 1755 +int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) 1756 +{ 1757 + int err = ZIP_OK; 1758 + ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; 1759 + 1760 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); 1761 + 1762 + /*num disks*/ 1763 + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1764 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); 1765 + 1766 + /*relative offset*/ 1767 + if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ 1768 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); 1769 + 1770 + /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ 1771 + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1772 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); 1773 + 1774 + return err; 1775 +} 1776 + 1777 +int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) 1778 +{ 1779 + int err = ZIP_OK; 1780 + 1781 + uLong Zip64DataSize = 44; 1782 + 1783 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); 1784 + 1785 + if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ 1786 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? 1787 + 1788 + if (err==ZIP_OK) /* version made by */ 1789 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); 1790 + 1791 + if (err==ZIP_OK) /* version needed */ 1792 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); 1793 + 1794 + if (err==ZIP_OK) /* number of this disk */ 1795 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); 1796 + 1797 + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1798 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); 1799 + 1800 + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ 1801 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); 1802 + 1803 + if (err==ZIP_OK) /* total number of entries in the central dir */ 1804 + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); 1805 + 1806 + if (err==ZIP_OK) /* size of the central directory */ 1807 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); 1808 + 1809 + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ 1810 + { 1811 + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; 1812 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); 1813 + } 1814 + return err; 1815 +} 1816 +int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) 1817 +{ 1818 + int err = ZIP_OK; 1819 + 1820 + /*signature*/ 1821 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); 1822 + 1823 + if (err==ZIP_OK) /* number of this disk */ 1824 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1825 + 1826 + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1827 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1828 + 1829 + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ 1830 + { 1831 + { 1832 + if(zi->number_entry >= 0xFFFF) 1833 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record 1834 + else 1835 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 1836 + } 1837 + } 1838 + 1839 + if (err==ZIP_OK) /* total number of entries in the central dir */ 1840 + { 1841 + if(zi->number_entry >= 0xFFFF) 1842 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record 1843 + else 1844 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 1845 + } 1846 + 1847 + if (err==ZIP_OK) /* size of the central directory */ 1848 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); 1849 + 1850 + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ 1851 + { 1852 + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; 1853 + if(pos >= 0xffffffff) 1854 + { 1855 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); 1856 + } 1857 + else 1858 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); 1859 + } 1860 + 1861 + return err; 1862 +} 1863 + 1864 +int Write_GlobalComment(zip64_internal* zi, const char* global_comment) 1865 +{ 1866 + int err = ZIP_OK; 1867 + uInt size_global_comment = 0; 1868 + 1869 + if(global_comment != NULL) 1870 + size_global_comment = (uInt)strlen(global_comment); 1871 + 1872 + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); 1873 + 1874 + if (err == ZIP_OK && size_global_comment > 0) 1875 + { 1876 + if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment) 1877 + err = ZIP_ERRNO; 1878 + } 1879 + return err; 1880 +} 1881 + 1882 +extern int ZEXPORT zipClose (zipFile file, const char* global_comment) 1883 +{ 1884 + zip64_internal* zi; 1885 + int err = 0; 1886 + uLong size_centraldir = 0; 1887 + ZPOS64_T centraldir_pos_inzip; 1888 + ZPOS64_T pos; 1889 + 1890 + if (file == NULL) 1891 + return ZIP_PARAMERROR; 1892 + 1893 + zi = (zip64_internal*)file; 1894 + 1895 + if (zi->in_opened_file_inzip == 1) 1896 + { 1897 + err = zipCloseFileInZip (file); 1898 + } 1899 + 1900 +#ifndef NO_ADDFILEINEXISTINGZIP 1901 + if (global_comment==NULL) 1902 + global_comment = zi->globalcomment; 1903 +#endif 1904 + 1905 + centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); 1906 + 1907 + if (err==ZIP_OK) 1908 + { 1909 + linkedlist_datablock_internal* ldi = zi->central_dir.first_block; 1910 + while (ldi!=NULL) 1911 + { 1912 + if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) 1913 + { 1914 + if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) 1915 + err = ZIP_ERRNO; 1916 + } 1917 + 1918 + size_centraldir += ldi->filled_in_this_block; 1919 + ldi = ldi->next_datablock; 1920 + } 1921 + } 1922 + free_linkedlist(&(zi->central_dir)); 1923 + 1924 + pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; 1925 + if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) 1926 + { 1927 + ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); 1928 + Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); 1929 + 1930 + Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); 1931 + } 1932 + 1933 + if (err==ZIP_OK) 1934 + err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); 1935 + 1936 + if(err == ZIP_OK) 1937 + err = Write_GlobalComment(zi, global_comment); 1938 + 1939 + if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) 1940 + if (err == ZIP_OK) 1941 + err = ZIP_ERRNO; 1942 + 1943 +#ifndef NO_ADDFILEINEXISTINGZIP 1944 + TRYFREE(zi->globalcomment); 1945 +#endif 1946 + TRYFREE(zi); 1947 + 1948 + return err; 1949 +} 1950 + 1951 +extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) 1952 +{ 1953 + char* p = pData; 1954 + int size = 0; 1955 + char* pNewHeader; 1956 + char* pTmp; 1957 + short header; 1958 + short dataSize; 1959 + 1960 + int retVal = ZIP_OK; 1961 + 1962 + if(pData == NULL || *dataLen < 4) 1963 + return ZIP_PARAMERROR; 1964 + 1965 + pNewHeader = (char*)ALLOC(*dataLen); 1966 + pTmp = pNewHeader; 1967 + 1968 + while(p < (pData + *dataLen)) 1969 + { 1970 + header = *(short*)p; 1971 + dataSize = *(((short*)p)+1); 1972 + 1973 + if( header == sHeader ) // Header found. 1974 + { 1975 + p += dataSize + 4; // skip it. do not copy to temp buffer 1976 + } 1977 + else 1978 + { 1979 + // Extra Info block should not be removed, So copy it to the temp buffer. 1980 + memcpy(pTmp, p, dataSize + 4); 1981 + p += dataSize + 4; 1982 + size += dataSize + 4; 1983 + } 1984 + 1985 + } 1986 + 1987 + if(size < *dataLen) 1988 + { 1989 + // clean old extra info block. 1990 + memset(pData,0, *dataLen); 1991 + 1992 + // copy the new extra info block over the old 1993 + if(size > 0) 1994 + memcpy(pData, pNewHeader, size); 1995 + 1996 + // set the new extra info size 1997 + *dataLen = size; 1998 + 1999 + retVal = ZIP_OK; 2000 + } 2001 + else 2002 + retVal = ZIP_ERRNO; 2003 + 2004 + TRYFREE(pNewHeader); 2005 + 2006 + return retVal; 2007 +}
Added compat/zlib/contrib/minizip/zip.h.
1 +/* zip.h -- IO on .zip files using zlib 2 + Version 1.1, February 14h, 2010 3 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 + 5 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 + 7 + Modifications for Zip64 support 8 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 9 + 10 + For more info read MiniZip_info.txt 11 + 12 + --------------------------------------------------------------------------- 13 + 14 + Condition of use and distribution are the same than zlib : 15 + 16 + This software is provided 'as-is', without any express or implied 17 + warranty. In no event will the authors be held liable for any damages 18 + arising from the use of this software. 19 + 20 + Permission is granted to anyone to use this software for any purpose, 21 + including commercial applications, and to alter it and redistribute it 22 + freely, subject to the following restrictions: 23 + 24 + 1. The origin of this software must not be misrepresented; you must not 25 + claim that you wrote the original software. If you use this software 26 + in a product, an acknowledgment in the product documentation would be 27 + appreciated but is not required. 28 + 2. Altered source versions must be plainly marked as such, and must not be 29 + misrepresented as being the original software. 30 + 3. This notice may not be removed or altered from any source distribution. 31 + 32 + --------------------------------------------------------------------------- 33 + 34 + Changes 35 + 36 + See header of zip.h 37 + 38 +*/ 39 + 40 +#ifndef _zip12_H 41 +#define _zip12_H 42 + 43 +#ifdef __cplusplus 44 +extern "C" { 45 +#endif 46 + 47 +//#define HAVE_BZIP2 48 + 49 +#ifndef _ZLIB_H 50 +#include "zlib.h" 51 +#endif 52 + 53 +#ifndef _ZLIBIOAPI_H 54 +#include "ioapi.h" 55 +#endif 56 + 57 +#ifdef HAVE_BZIP2 58 +#include "bzlib.h" 59 +#endif 60 + 61 +#define Z_BZIP2ED 12 62 + 63 +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 64 +/* like the STRICT of WIN32, we define a pointer that cannot be converted 65 + from (void*) without cast */ 66 +typedef struct TagzipFile__ { int unused; } zipFile__; 67 +typedef zipFile__ *zipFile; 68 +#else 69 +typedef voidp zipFile; 70 +#endif 71 + 72 +#define ZIP_OK (0) 73 +#define ZIP_EOF (0) 74 +#define ZIP_ERRNO (Z_ERRNO) 75 +#define ZIP_PARAMERROR (-102) 76 +#define ZIP_BADZIPFILE (-103) 77 +#define ZIP_INTERNALERROR (-104) 78 + 79 +#ifndef DEF_MEM_LEVEL 80 +# if MAX_MEM_LEVEL >= 8 81 +# define DEF_MEM_LEVEL 8 82 +# else 83 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL 84 +# endif 85 +#endif 86 +/* default memLevel */ 87 + 88 +/* tm_zip contain date/time info */ 89 +typedef struct tm_zip_s 90 +{ 91 + uInt tm_sec; /* seconds after the minute - [0,59] */ 92 + uInt tm_min; /* minutes after the hour - [0,59] */ 93 + uInt tm_hour; /* hours since midnight - [0,23] */ 94 + uInt tm_mday; /* day of the month - [1,31] */ 95 + uInt tm_mon; /* months since January - [0,11] */ 96 + uInt tm_year; /* years - [1980..2044] */ 97 +} tm_zip; 98 + 99 +typedef struct 100 +{ 101 + tm_zip tmz_date; /* date in understandable format */ 102 + uLong dosDate; /* if dos_date == 0, tmu_date is used */ 103 +/* uLong flag; */ /* general purpose bit flag 2 bytes */ 104 + 105 + uLong internal_fa; /* internal file attributes 2 bytes */ 106 + uLong external_fa; /* external file attributes 4 bytes */ 107 +} zip_fileinfo; 108 + 109 +typedef const char* zipcharpc; 110 + 111 + 112 +#define APPEND_STATUS_CREATE (0) 113 +#define APPEND_STATUS_CREATEAFTER (1) 114 +#define APPEND_STATUS_ADDINZIP (2) 115 + 116 +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 117 +extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); 118 +/* 119 + Create a zipfile. 120 + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 121 + an Unix computer "zlib/zlib113.zip". 122 + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip 123 + will be created at the end of the file. 124 + (useful if the file contain a self extractor code) 125 + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will 126 + add files in existing zip (be sure you don't add file that doesn't exist) 127 + If the zipfile cannot be opened, the return value is NULL. 128 + Else, the return value is a zipFile Handle, usable with other function 129 + of this zip package. 130 +*/ 131 + 132 +/* Note : there is no delete function into a zipfile. 133 + If you want delete file into a zipfile, you must open a zipfile, and create another 134 + Of couse, you can use RAW reading and writing to copy the file you did not want delte 135 +*/ 136 + 137 +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, 138 + int append, 139 + zipcharpc* globalcomment, 140 + zlib_filefunc_def* pzlib_filefunc_def)); 141 + 142 +extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, 143 + int append, 144 + zipcharpc* globalcomment, 145 + zlib_filefunc64_def* pzlib_filefunc_def)); 146 + 147 +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 148 + const char* filename, 149 + const zip_fileinfo* zipfi, 150 + const void* extrafield_local, 151 + uInt size_extrafield_local, 152 + const void* extrafield_global, 153 + uInt size_extrafield_global, 154 + const char* comment, 155 + int method, 156 + int level)); 157 + 158 +extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, 159 + const char* filename, 160 + const zip_fileinfo* zipfi, 161 + const void* extrafield_local, 162 + uInt size_extrafield_local, 163 + const void* extrafield_global, 164 + uInt size_extrafield_global, 165 + const char* comment, 166 + int method, 167 + int level, 168 + int zip64)); 169 + 170 +/* 171 + Open a file in the ZIP for writing. 172 + filename : the filename in zip (if NULL, '-' without quote will be used 173 + *zipfi contain supplemental information 174 + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local 175 + contains the extrafield data the the local header 176 + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global 177 + contains the extrafield data the the local header 178 + if comment != NULL, comment contain the comment string 179 + method contain the compression method (0 for store, Z_DEFLATED for deflate) 180 + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 181 + zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 182 + this MUST be '1' if the uncompressed size is >= 0xffffffff. 183 + 184 +*/ 185 + 186 + 187 +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, 188 + const char* filename, 189 + const zip_fileinfo* zipfi, 190 + const void* extrafield_local, 191 + uInt size_extrafield_local, 192 + const void* extrafield_global, 193 + uInt size_extrafield_global, 194 + const char* comment, 195 + int method, 196 + int level, 197 + int raw)); 198 + 199 + 200 +extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, 201 + const char* filename, 202 + const zip_fileinfo* zipfi, 203 + const void* extrafield_local, 204 + uInt size_extrafield_local, 205 + const void* extrafield_global, 206 + uInt size_extrafield_global, 207 + const char* comment, 208 + int method, 209 + int level, 210 + int raw, 211 + int zip64)); 212 +/* 213 + Same than zipOpenNewFileInZip, except if raw=1, we write raw file 214 + */ 215 + 216 +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, 217 + const char* filename, 218 + const zip_fileinfo* zipfi, 219 + const void* extrafield_local, 220 + uInt size_extrafield_local, 221 + const void* extrafield_global, 222 + uInt size_extrafield_global, 223 + const char* comment, 224 + int method, 225 + int level, 226 + int raw, 227 + int windowBits, 228 + int memLevel, 229 + int strategy, 230 + const char* password, 231 + uLong crcForCrypting)); 232 + 233 +extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, 234 + const char* filename, 235 + const zip_fileinfo* zipfi, 236 + const void* extrafield_local, 237 + uInt size_extrafield_local, 238 + const void* extrafield_global, 239 + uInt size_extrafield_global, 240 + const char* comment, 241 + int method, 242 + int level, 243 + int raw, 244 + int windowBits, 245 + int memLevel, 246 + int strategy, 247 + const char* password, 248 + uLong crcForCrypting, 249 + int zip64 250 + )); 251 + 252 +/* 253 + Same than zipOpenNewFileInZip2, except 254 + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 255 + password : crypting password (NULL for no crypting) 256 + crcForCrypting : crc of file to compress (needed for crypting) 257 + */ 258 + 259 +extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, 260 + const char* filename, 261 + const zip_fileinfo* zipfi, 262 + const void* extrafield_local, 263 + uInt size_extrafield_local, 264 + const void* extrafield_global, 265 + uInt size_extrafield_global, 266 + const char* comment, 267 + int method, 268 + int level, 269 + int raw, 270 + int windowBits, 271 + int memLevel, 272 + int strategy, 273 + const char* password, 274 + uLong crcForCrypting, 275 + uLong versionMadeBy, 276 + uLong flagBase 277 + )); 278 + 279 + 280 +extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, 281 + const char* filename, 282 + const zip_fileinfo* zipfi, 283 + const void* extrafield_local, 284 + uInt size_extrafield_local, 285 + const void* extrafield_global, 286 + uInt size_extrafield_global, 287 + const char* comment, 288 + int method, 289 + int level, 290 + int raw, 291 + int windowBits, 292 + int memLevel, 293 + int strategy, 294 + const char* password, 295 + uLong crcForCrypting, 296 + uLong versionMadeBy, 297 + uLong flagBase, 298 + int zip64 299 + )); 300 +/* 301 + Same than zipOpenNewFileInZip4, except 302 + versionMadeBy : value for Version made by field 303 + flag : value for flag field (compression level info will be added) 304 + */ 305 + 306 + 307 +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, 308 + const void* buf, 309 + unsigned len)); 310 +/* 311 + Write data in the zipfile 312 +*/ 313 + 314 +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 315 +/* 316 + Close the current file in the zipfile 317 +*/ 318 + 319 +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 320 + uLong uncompressed_size, 321 + uLong crc32)); 322 + 323 +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, 324 + ZPOS64_T uncompressed_size, 325 + uLong crc32)); 326 + 327 +/* 328 + Close the current file in the zipfile, for file opened with 329 + parameter raw=1 in zipOpenNewFileInZip2 330 + uncompressed_size and crc32 are value for the uncompressed size 331 +*/ 332 + 333 +extern int ZEXPORT zipClose OF((zipFile file, 334 + const char* global_comment)); 335 +/* 336 + Close the zipfile 337 +*/ 338 + 339 + 340 +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); 341 +/* 342 + zipRemoveExtraInfoBlock - Added by Mathias Svensson 343 + 344 + Remove extra information block from a extra information data for the local file header or central directory header 345 + 346 + It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. 347 + 348 + 0x0001 is the signature header for the ZIP64 extra information blocks 349 + 350 + usage. 351 + Remove ZIP64 Extra information from a central director extra field data 352 + zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); 353 + 354 + Remove ZIP64 Extra information from a Local File Header extra field data 355 + zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); 356 +*/ 357 + 358 +#ifdef __cplusplus 359 +} 360 +#endif 361 + 362 +#endif /* _zip64_H */
Added compat/zlib/contrib/pascal/example.pas.
1 +(* example.c -- usage example of the zlib compression library 2 + * Copyright (C) 1995-2003 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + * 5 + * Pascal translation 6 + * Copyright (C) 1998 by Jacques Nomssi Nzali. 7 + * For conditions of distribution and use, see copyright notice in readme.txt 8 + * 9 + * Adaptation to the zlibpas interface 10 + * Copyright (C) 2003 by Cosmin Truta. 11 + * For conditions of distribution and use, see copyright notice in readme.txt 12 + *) 13 + 14 +program example; 15 + 16 +{$DEFINE TEST_COMPRESS} 17 +{DO NOT $DEFINE TEST_GZIO} 18 +{$DEFINE TEST_DEFLATE} 19 +{$DEFINE TEST_INFLATE} 20 +{$DEFINE TEST_FLUSH} 21 +{$DEFINE TEST_SYNC} 22 +{$DEFINE TEST_DICT} 23 + 24 +uses SysUtils, zlibpas; 25 + 26 +const TESTFILE = 'foo.gz'; 27 + 28 +(* "hello world" would be more standard, but the repeated "hello" 29 + * stresses the compression code better, sorry... 30 + *) 31 +const hello: PChar = 'hello, hello!'; 32 + 33 +const dictionary: PChar = 'hello'; 34 + 35 +var dictId: LongInt; (* Adler32 value of the dictionary *) 36 + 37 +procedure CHECK_ERR(err: Integer; msg: String); 38 +begin 39 + if err <> Z_OK then 40 + begin 41 + WriteLn(msg, ' error: ', err); 42 + Halt(1); 43 + end; 44 +end; 45 + 46 +procedure EXIT_ERR(const msg: String); 47 +begin 48 + WriteLn('Error: ', msg); 49 + Halt(1); 50 +end; 51 + 52 +(* =========================================================================== 53 + * Test compress and uncompress 54 + *) 55 +{$IFDEF TEST_COMPRESS} 56 +procedure test_compress(compr: Pointer; comprLen: LongInt; 57 + uncompr: Pointer; uncomprLen: LongInt); 58 +var err: Integer; 59 + len: LongInt; 60 +begin 61 + len := StrLen(hello)+1; 62 + 63 + err := compress(compr, comprLen, hello, len); 64 + CHECK_ERR(err, 'compress'); 65 + 66 + StrCopy(PChar(uncompr), 'garbage'); 67 + 68 + err := uncompress(uncompr, uncomprLen, compr, comprLen); 69 + CHECK_ERR(err, 'uncompress'); 70 + 71 + if StrComp(PChar(uncompr), hello) <> 0 then 72 + EXIT_ERR('bad uncompress') 73 + else 74 + WriteLn('uncompress(): ', PChar(uncompr)); 75 +end; 76 +{$ENDIF} 77 + 78 +(* =========================================================================== 79 + * Test read/write of .gz files 80 + *) 81 +{$IFDEF TEST_GZIO} 82 +procedure test_gzio(const fname: PChar; (* compressed file name *) 83 + uncompr: Pointer; 84 + uncomprLen: LongInt); 85 +var err: Integer; 86 + len: Integer; 87 + zfile: gzFile; 88 + pos: LongInt; 89 +begin 90 + len := StrLen(hello)+1; 91 + 92 + zfile := gzopen(fname, 'wb'); 93 + if zfile = NIL then 94 + begin 95 + WriteLn('gzopen error'); 96 + Halt(1); 97 + end; 98 + gzputc(zfile, 'h'); 99 + if gzputs(zfile, 'ello') <> 4 then 100 + begin 101 + WriteLn('gzputs err: ', gzerror(zfile, err)); 102 + Halt(1); 103 + end; 104 + {$IFDEF GZ_FORMAT_STRING} 105 + if gzprintf(zfile, ', %s!', 'hello') <> 8 then 106 + begin 107 + WriteLn('gzprintf err: ', gzerror(zfile, err)); 108 + Halt(1); 109 + end; 110 + {$ELSE} 111 + if gzputs(zfile, ', hello!') <> 8 then 112 + begin 113 + WriteLn('gzputs err: ', gzerror(zfile, err)); 114 + Halt(1); 115 + end; 116 + {$ENDIF} 117 + gzseek(zfile, 1, SEEK_CUR); (* add one zero byte *) 118 + gzclose(zfile); 119 + 120 + zfile := gzopen(fname, 'rb'); 121 + if zfile = NIL then 122 + begin 123 + WriteLn('gzopen error'); 124 + Halt(1); 125 + end; 126 + 127 + StrCopy(PChar(uncompr), 'garbage'); 128 + 129 + if gzread(zfile, uncompr, uncomprLen) <> len then 130 + begin 131 + WriteLn('gzread err: ', gzerror(zfile, err)); 132 + Halt(1); 133 + end; 134 + if StrComp(PChar(uncompr), hello) <> 0 then 135 + begin 136 + WriteLn('bad gzread: ', PChar(uncompr)); 137 + Halt(1); 138 + end 139 + else 140 + WriteLn('gzread(): ', PChar(uncompr)); 141 + 142 + pos := gzseek(zfile, -8, SEEK_CUR); 143 + if (pos <> 6) or (gztell(zfile) <> pos) then 144 + begin 145 + WriteLn('gzseek error, pos=', pos, ', gztell=', gztell(zfile)); 146 + Halt(1); 147 + end; 148 + 149 + if gzgetc(zfile) <> ' ' then 150 + begin 151 + WriteLn('gzgetc error'); 152 + Halt(1); 153 + end; 154 + 155 + if gzungetc(' ', zfile) <> ' ' then 156 + begin 157 + WriteLn('gzungetc error'); 158 + Halt(1); 159 + end; 160 + 161 + gzgets(zfile, PChar(uncompr), uncomprLen); 162 + uncomprLen := StrLen(PChar(uncompr)); 163 + if uncomprLen <> 7 then (* " hello!" *) 164 + begin 165 + WriteLn('gzgets err after gzseek: ', gzerror(zfile, err)); 166 + Halt(1); 167 + end; 168 + if StrComp(PChar(uncompr), hello + 6) <> 0 then 169 + begin 170 + WriteLn('bad gzgets after gzseek'); 171 + Halt(1); 172 + end 173 + else 174 + WriteLn('gzgets() after gzseek: ', PChar(uncompr)); 175 + 176 + gzclose(zfile); 177 +end; 178 +{$ENDIF} 179 + 180 +(* =========================================================================== 181 + * Test deflate with small buffers 182 + *) 183 +{$IFDEF TEST_DEFLATE} 184 +procedure test_deflate(compr: Pointer; comprLen: LongInt); 185 +var c_stream: z_stream; (* compression stream *) 186 + err: Integer; 187 + len: LongInt; 188 +begin 189 + len := StrLen(hello)+1; 190 + 191 + c_stream.zalloc := NIL; 192 + c_stream.zfree := NIL; 193 + c_stream.opaque := NIL; 194 + 195 + err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); 196 + CHECK_ERR(err, 'deflateInit'); 197 + 198 + c_stream.next_in := hello; 199 + c_stream.next_out := compr; 200 + 201 + while (c_stream.total_in <> len) and 202 + (c_stream.total_out < comprLen) do 203 + begin 204 + c_stream.avail_out := 1; { force small buffers } 205 + c_stream.avail_in := 1; 206 + err := deflate(c_stream, Z_NO_FLUSH); 207 + CHECK_ERR(err, 'deflate'); 208 + end; 209 + 210 + (* Finish the stream, still forcing small buffers: *) 211 + while TRUE do 212 + begin 213 + c_stream.avail_out := 1; 214 + err := deflate(c_stream, Z_FINISH); 215 + if err = Z_STREAM_END then 216 + break; 217 + CHECK_ERR(err, 'deflate'); 218 + end; 219 + 220 + err := deflateEnd(c_stream); 221 + CHECK_ERR(err, 'deflateEnd'); 222 +end; 223 +{$ENDIF} 224 + 225 +(* =========================================================================== 226 + * Test inflate with small buffers 227 + *) 228 +{$IFDEF TEST_INFLATE} 229 +procedure test_inflate(compr: Pointer; comprLen : LongInt; 230 + uncompr: Pointer; uncomprLen : LongInt); 231 +var err: Integer; 232 + d_stream: z_stream; (* decompression stream *) 233 +begin 234 + StrCopy(PChar(uncompr), 'garbage'); 235 + 236 + d_stream.zalloc := NIL; 237 + d_stream.zfree := NIL; 238 + d_stream.opaque := NIL; 239 + 240 + d_stream.next_in := compr; 241 + d_stream.avail_in := 0; 242 + d_stream.next_out := uncompr; 243 + 244 + err := inflateInit(d_stream); 245 + CHECK_ERR(err, 'inflateInit'); 246 + 247 + while (d_stream.total_out < uncomprLen) and 248 + (d_stream.total_in < comprLen) do 249 + begin 250 + d_stream.avail_out := 1; (* force small buffers *) 251 + d_stream.avail_in := 1; 252 + err := inflate(d_stream, Z_NO_FLUSH); 253 + if err = Z_STREAM_END then 254 + break; 255 + CHECK_ERR(err, 'inflate'); 256 + end; 257 + 258 + err := inflateEnd(d_stream); 259 + CHECK_ERR(err, 'inflateEnd'); 260 + 261 + if StrComp(PChar(uncompr), hello) <> 0 then 262 + EXIT_ERR('bad inflate') 263 + else 264 + WriteLn('inflate(): ', PChar(uncompr)); 265 +end; 266 +{$ENDIF} 267 + 268 +(* =========================================================================== 269 + * Test deflate with large buffers and dynamic change of compression level 270 + *) 271 +{$IFDEF TEST_DEFLATE} 272 +procedure test_large_deflate(compr: Pointer; comprLen: LongInt; 273 + uncompr: Pointer; uncomprLen: LongInt); 274 +var c_stream: z_stream; (* compression stream *) 275 + err: Integer; 276 +begin 277 + c_stream.zalloc := NIL; 278 + c_stream.zfree := NIL; 279 + c_stream.opaque := NIL; 280 + 281 + err := deflateInit(c_stream, Z_BEST_SPEED); 282 + CHECK_ERR(err, 'deflateInit'); 283 + 284 + c_stream.next_out := compr; 285 + c_stream.avail_out := Integer(comprLen); 286 + 287 + (* At this point, uncompr is still mostly zeroes, so it should compress 288 + * very well: 289 + *) 290 + c_stream.next_in := uncompr; 291 + c_stream.avail_in := Integer(uncomprLen); 292 + err := deflate(c_stream, Z_NO_FLUSH); 293 + CHECK_ERR(err, 'deflate'); 294 + if c_stream.avail_in <> 0 then 295 + EXIT_ERR('deflate not greedy'); 296 + 297 + (* Feed in already compressed data and switch to no compression: *) 298 + deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); 299 + c_stream.next_in := compr; 300 + c_stream.avail_in := Integer(comprLen div 2); 301 + err := deflate(c_stream, Z_NO_FLUSH); 302 + CHECK_ERR(err, 'deflate'); 303 + 304 + (* Switch back to compressing mode: *) 305 + deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED); 306 + c_stream.next_in := uncompr; 307 + c_stream.avail_in := Integer(uncomprLen); 308 + err := deflate(c_stream, Z_NO_FLUSH); 309 + CHECK_ERR(err, 'deflate'); 310 + 311 + err := deflate(c_stream, Z_FINISH); 312 + if err <> Z_STREAM_END then 313 + EXIT_ERR('deflate should report Z_STREAM_END'); 314 + 315 + err := deflateEnd(c_stream); 316 + CHECK_ERR(err, 'deflateEnd'); 317 +end; 318 +{$ENDIF} 319 + 320 +(* =========================================================================== 321 + * Test inflate with large buffers 322 + *) 323 +{$IFDEF TEST_INFLATE} 324 +procedure test_large_inflate(compr: Pointer; comprLen: LongInt; 325 + uncompr: Pointer; uncomprLen: LongInt); 326 +var err: Integer; 327 + d_stream: z_stream; (* decompression stream *) 328 +begin 329 + StrCopy(PChar(uncompr), 'garbage'); 330 + 331 + d_stream.zalloc := NIL; 332 + d_stream.zfree := NIL; 333 + d_stream.opaque := NIL; 334 + 335 + d_stream.next_in := compr; 336 + d_stream.avail_in := Integer(comprLen); 337 + 338 + err := inflateInit(d_stream); 339 + CHECK_ERR(err, 'inflateInit'); 340 + 341 + while TRUE do 342 + begin 343 + d_stream.next_out := uncompr; (* discard the output *) 344 + d_stream.avail_out := Integer(uncomprLen); 345 + err := inflate(d_stream, Z_NO_FLUSH); 346 + if err = Z_STREAM_END then 347 + break; 348 + CHECK_ERR(err, 'large inflate'); 349 + end; 350 + 351 + err := inflateEnd(d_stream); 352 + CHECK_ERR(err, 'inflateEnd'); 353 + 354 + if d_stream.total_out <> 2 * uncomprLen + comprLen div 2 then 355 + begin 356 + WriteLn('bad large inflate: ', d_stream.total_out); 357 + Halt(1); 358 + end 359 + else 360 + WriteLn('large_inflate(): OK'); 361 +end; 362 +{$ENDIF} 363 + 364 +(* =========================================================================== 365 + * Test deflate with full flush 366 + *) 367 +{$IFDEF TEST_FLUSH} 368 +procedure test_flush(compr: Pointer; var comprLen : LongInt); 369 +var c_stream: z_stream; (* compression stream *) 370 + err: Integer; 371 + len: Integer; 372 +begin 373 + len := StrLen(hello)+1; 374 + 375 + c_stream.zalloc := NIL; 376 + c_stream.zfree := NIL; 377 + c_stream.opaque := NIL; 378 + 379 + err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); 380 + CHECK_ERR(err, 'deflateInit'); 381 + 382 + c_stream.next_in := hello; 383 + c_stream.next_out := compr; 384 + c_stream.avail_in := 3; 385 + c_stream.avail_out := Integer(comprLen); 386 + err := deflate(c_stream, Z_FULL_FLUSH); 387 + CHECK_ERR(err, 'deflate'); 388 + 389 + Inc(PByteArray(compr)^[3]); (* force an error in first compressed block *) 390 + c_stream.avail_in := len - 3; 391 + 392 + err := deflate(c_stream, Z_FINISH); 393 + if err <> Z_STREAM_END then 394 + CHECK_ERR(err, 'deflate'); 395 + 396 + err := deflateEnd(c_stream); 397 + CHECK_ERR(err, 'deflateEnd'); 398 + 399 + comprLen := c_stream.total_out; 400 +end; 401 +{$ENDIF} 402 + 403 +(* =========================================================================== 404 + * Test inflateSync() 405 + *) 406 +{$IFDEF TEST_SYNC} 407 +procedure test_sync(compr: Pointer; comprLen: LongInt; 408 + uncompr: Pointer; uncomprLen : LongInt); 409 +var err: Integer; 410 + d_stream: z_stream; (* decompression stream *) 411 +begin 412 + StrCopy(PChar(uncompr), 'garbage'); 413 + 414 + d_stream.zalloc := NIL; 415 + d_stream.zfree := NIL; 416 + d_stream.opaque := NIL; 417 + 418 + d_stream.next_in := compr; 419 + d_stream.avail_in := 2; (* just read the zlib header *) 420 + 421 + err := inflateInit(d_stream); 422 + CHECK_ERR(err, 'inflateInit'); 423 + 424 + d_stream.next_out := uncompr; 425 + d_stream.avail_out := Integer(uncomprLen); 426 + 427 + inflate(d_stream, Z_NO_FLUSH); 428 + CHECK_ERR(err, 'inflate'); 429 + 430 + d_stream.avail_in := Integer(comprLen-2); (* read all compressed data *) 431 + err := inflateSync(d_stream); (* but skip the damaged part *) 432 + CHECK_ERR(err, 'inflateSync'); 433 + 434 + err := inflate(d_stream, Z_FINISH); 435 + if err <> Z_DATA_ERROR then 436 + EXIT_ERR('inflate should report DATA_ERROR'); 437 + (* Because of incorrect adler32 *) 438 + 439 + err := inflateEnd(d_stream); 440 + CHECK_ERR(err, 'inflateEnd'); 441 + 442 + WriteLn('after inflateSync(): hel', PChar(uncompr)); 443 +end; 444 +{$ENDIF} 445 + 446 +(* =========================================================================== 447 + * Test deflate with preset dictionary 448 + *) 449 +{$IFDEF TEST_DICT} 450 +procedure test_dict_deflate(compr: Pointer; comprLen: LongInt); 451 +var c_stream: z_stream; (* compression stream *) 452 + err: Integer; 453 +begin 454 + c_stream.zalloc := NIL; 455 + c_stream.zfree := NIL; 456 + c_stream.opaque := NIL; 457 + 458 + err := deflateInit(c_stream, Z_BEST_COMPRESSION); 459 + CHECK_ERR(err, 'deflateInit'); 460 + 461 + err := deflateSetDictionary(c_stream, dictionary, StrLen(dictionary)); 462 + CHECK_ERR(err, 'deflateSetDictionary'); 463 + 464 + dictId := c_stream.adler; 465 + c_stream.next_out := compr; 466 + c_stream.avail_out := Integer(comprLen); 467 + 468 + c_stream.next_in := hello; 469 + c_stream.avail_in := StrLen(hello)+1; 470 + 471 + err := deflate(c_stream, Z_FINISH); 472 + if err <> Z_STREAM_END then 473 + EXIT_ERR('deflate should report Z_STREAM_END'); 474 + 475 + err := deflateEnd(c_stream); 476 + CHECK_ERR(err, 'deflateEnd'); 477 +end; 478 +{$ENDIF} 479 + 480 +(* =========================================================================== 481 + * Test inflate with a preset dictionary 482 + *) 483 +{$IFDEF TEST_DICT} 484 +procedure test_dict_inflate(compr: Pointer; comprLen: LongInt; 485 + uncompr: Pointer; uncomprLen: LongInt); 486 +var err: Integer; 487 + d_stream: z_stream; (* decompression stream *) 488 +begin 489 + StrCopy(PChar(uncompr), 'garbage'); 490 + 491 + d_stream.zalloc := NIL; 492 + d_stream.zfree := NIL; 493 + d_stream.opaque := NIL; 494 + 495 + d_stream.next_in := compr; 496 + d_stream.avail_in := Integer(comprLen); 497 + 498 + err := inflateInit(d_stream); 499 + CHECK_ERR(err, 'inflateInit'); 500 + 501 + d_stream.next_out := uncompr; 502 + d_stream.avail_out := Integer(uncomprLen); 503 + 504 + while TRUE do 505 + begin 506 + err := inflate(d_stream, Z_NO_FLUSH); 507 + if err = Z_STREAM_END then 508 + break; 509 + if err = Z_NEED_DICT then 510 + begin 511 + if d_stream.adler <> dictId then 512 + EXIT_ERR('unexpected dictionary'); 513 + err := inflateSetDictionary(d_stream, dictionary, StrLen(dictionary)); 514 + end; 515 + CHECK_ERR(err, 'inflate with dict'); 516 + end; 517 + 518 + err := inflateEnd(d_stream); 519 + CHECK_ERR(err, 'inflateEnd'); 520 + 521 + if StrComp(PChar(uncompr), hello) <> 0 then 522 + EXIT_ERR('bad inflate with dict') 523 + else 524 + WriteLn('inflate with dictionary: ', PChar(uncompr)); 525 +end; 526 +{$ENDIF} 527 + 528 +var compr, uncompr: Pointer; 529 + comprLen, uncomprLen: LongInt; 530 + 531 +begin 532 + if zlibVersion^ <> ZLIB_VERSION[1] then 533 + EXIT_ERR('Incompatible zlib version'); 534 + 535 + WriteLn('zlib version: ', zlibVersion); 536 + WriteLn('zlib compile flags: ', Format('0x%x', [zlibCompileFlags])); 537 + 538 + comprLen := 10000 * SizeOf(Integer); (* don't overflow on MSDOS *) 539 + uncomprLen := comprLen; 540 + GetMem(compr, comprLen); 541 + GetMem(uncompr, uncomprLen); 542 + if (compr = NIL) or (uncompr = NIL) then 543 + EXIT_ERR('Out of memory'); 544 + (* compr and uncompr are cleared to avoid reading uninitialized 545 + * data and to ensure that uncompr compresses well. 546 + *) 547 + FillChar(compr^, comprLen, 0); 548 + FillChar(uncompr^, uncomprLen, 0); 549 + 550 + {$IFDEF TEST_COMPRESS} 551 + WriteLn('** Testing compress'); 552 + test_compress(compr, comprLen, uncompr, uncomprLen); 553 + {$ENDIF} 554 + 555 + {$IFDEF TEST_GZIO} 556 + WriteLn('** Testing gzio'); 557 + if ParamCount >= 1 then 558 + test_gzio(ParamStr(1), uncompr, uncomprLen) 559 + else 560 + test_gzio(TESTFILE, uncompr, uncomprLen); 561 + {$ENDIF} 562 + 563 + {$IFDEF TEST_DEFLATE} 564 + WriteLn('** Testing deflate with small buffers'); 565 + test_deflate(compr, comprLen); 566 + {$ENDIF} 567 + {$IFDEF TEST_INFLATE} 568 + WriteLn('** Testing inflate with small buffers'); 569 + test_inflate(compr, comprLen, uncompr, uncomprLen); 570 + {$ENDIF} 571 + 572 + {$IFDEF TEST_DEFLATE} 573 + WriteLn('** Testing deflate with large buffers'); 574 + test_large_deflate(compr, comprLen, uncompr, uncomprLen); 575 + {$ENDIF} 576 + {$IFDEF TEST_INFLATE} 577 + WriteLn('** Testing inflate with large buffers'); 578 + test_large_inflate(compr, comprLen, uncompr, uncomprLen); 579 + {$ENDIF} 580 + 581 + {$IFDEF TEST_FLUSH} 582 + WriteLn('** Testing deflate with full flush'); 583 + test_flush(compr, comprLen); 584 + {$ENDIF} 585 + {$IFDEF TEST_SYNC} 586 + WriteLn('** Testing inflateSync'); 587 + test_sync(compr, comprLen, uncompr, uncomprLen); 588 + {$ENDIF} 589 + comprLen := uncomprLen; 590 + 591 + {$IFDEF TEST_DICT} 592 + WriteLn('** Testing deflate and inflate with preset dictionary'); 593 + test_dict_deflate(compr, comprLen); 594 + test_dict_inflate(compr, comprLen, uncompr, uncomprLen); 595 + {$ENDIF} 596 + 597 + FreeMem(compr, comprLen); 598 + FreeMem(uncompr, uncomprLen); 599 +end.
Added compat/zlib/contrib/pascal/readme.txt.
1 + 2 +This directory contains a Pascal (Delphi, Kylix) interface to the 3 +zlib data compression library. 4 + 5 + 6 +Directory listing 7 +================= 8 + 9 +zlibd32.mak makefile for Borland C++ 10 +example.pas usage example of zlib 11 +zlibpas.pas the Pascal interface to zlib 12 +readme.txt this file 13 + 14 + 15 +Compatibility notes 16 +=================== 17 + 18 +- Although the name "zlib" would have been more normal for the 19 + zlibpas unit, this name is already taken by Borland's ZLib unit. 20 + This is somehow unfortunate, because that unit is not a genuine 21 + interface to the full-fledged zlib functionality, but a suite of 22 + class wrappers around zlib streams. Other essential features, 23 + such as checksums, are missing. 24 + It would have been more appropriate for that unit to have a name 25 + like "ZStreams", or something similar. 26 + 27 +- The C and zlib-supplied types int, uInt, long, uLong, etc. are 28 + translated directly into Pascal types of similar sizes (Integer, 29 + LongInt, etc.), to avoid namespace pollution. In particular, 30 + there is no conversion of unsigned int into a Pascal unsigned 31 + integer. The Word type is non-portable and has the same size 32 + (16 bits) both in a 16-bit and in a 32-bit environment, unlike 33 + Integer. Even if there is a 32-bit Cardinal type, there is no 34 + real need for unsigned int in zlib under a 32-bit environment. 35 + 36 +- Except for the callbacks, the zlib function interfaces are 37 + assuming the calling convention normally used in Pascal 38 + (__pascal for DOS and Windows16, __fastcall for Windows32). 39 + Since the cdecl keyword is used, the old Turbo Pascal does 40 + not work with this interface. 41 + 42 +- The gz* function interfaces are not translated, to avoid 43 + interfacing problems with the C runtime library. Besides, 44 + gzprintf(gzFile file, const char *format, ...) 45 + cannot be translated into Pascal. 46 + 47 + 48 +Legal issues 49 +============ 50 + 51 +The zlibpas interface is: 52 + Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler. 53 + Copyright (C) 1998 by Bob Dellaca. 54 + Copyright (C) 2003 by Cosmin Truta. 55 + 56 +The example program is: 57 + Copyright (C) 1995-2003 by Jean-loup Gailly. 58 + Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali. 59 + Copyright (C) 2003 by Cosmin Truta. 60 + 61 + This software is provided 'as-is', without any express or implied 62 + warranty. In no event will the author be held liable for any damages 63 + arising from the use of this software. 64 + 65 + Permission is granted to anyone to use this software for any purpose, 66 + including commercial applications, and to alter it and redistribute it 67 + freely, subject to the following restrictions: 68 + 69 + 1. The origin of this software must not be misrepresented; you must not 70 + claim that you wrote the original software. If you use this software 71 + in a product, an acknowledgment in the product documentation would be 72 + appreciated but is not required. 73 + 2. Altered source versions must be plainly marked as such, and must not be 74 + misrepresented as being the original software. 75 + 3. This notice may not be removed or altered from any source distribution. 76 +
Added compat/zlib/contrib/pascal/zlibd32.mak.
1 +# Makefile for zlib 2 +# For use with Delphi and C++ Builder under Win32 3 +# Updated for zlib 1.2.x by Cosmin Truta 4 + 5 +# ------------ Borland C++ ------------ 6 + 7 +# This project uses the Delphi (fastcall/register) calling convention: 8 +LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl 9 + 10 +CC = bcc32 11 +LD = bcc32 12 +AR = tlib 13 +# do not use "-pr" in CFLAGS 14 +CFLAGS = -a -d -k- -O2 $(LOC) 15 +LDFLAGS = 16 + 17 + 18 +# variables 19 +ZLIB_LIB = zlib.lib 20 + 21 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 22 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 23 +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj 24 +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 25 + 26 + 27 +# targets 28 +all: $(ZLIB_LIB) example.exe minigzip.exe 29 + 30 +.c.obj: 31 + $(CC) -c $(CFLAGS) $*.c 32 + 33 +adler32.obj: adler32.c zlib.h zconf.h 34 + 35 +compress.obj: compress.c zlib.h zconf.h 36 + 37 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 38 + 39 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 40 + 41 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 42 + 43 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 44 + 45 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 46 + 47 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 48 + 49 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 50 + inffast.h inffixed.h 51 + 52 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 53 + inffast.h 54 + 55 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 56 + inffast.h inffixed.h 57 + 58 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 59 + 60 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 61 + 62 +uncompr.obj: uncompr.c zlib.h zconf.h 63 + 64 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 65 + 66 +example.obj: test/example.c zlib.h zconf.h 67 + 68 +minigzip.obj: test/minigzip.c zlib.h zconf.h 69 + 70 + 71 +# For the sake of the old Borland make, 72 +# the command line is cut to fit in the MS-DOS 128 byte limit: 73 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) 74 + -del $(ZLIB_LIB) 75 + $(AR) $(ZLIB_LIB) $(OBJP1) 76 + $(AR) $(ZLIB_LIB) $(OBJP2) 77 + 78 + 79 +# testing 80 +test: example.exe minigzip.exe 81 + example 82 + echo hello world | minigzip | minigzip -d 83 + 84 +example.exe: example.obj $(ZLIB_LIB) 85 + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) 86 + 87 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 88 + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) 89 + 90 + 91 +# cleanup 92 +clean: 93 + -del *.obj 94 + -del *.exe 95 + -del *.lib 96 + -del *.tds 97 + -del zlib.bak 98 + -del foo.gz 99 +
Added compat/zlib/contrib/pascal/zlibpas.pas.
1 +(* zlibpas -- Pascal interface to the zlib data compression library 2 + * 3 + * Copyright (C) 2003 Cosmin Truta. 4 + * Derived from original sources by Bob Dellaca. 5 + * For conditions of distribution and use, see copyright notice in readme.txt 6 + *) 7 + 8 +unit zlibpas; 9 + 10 +interface 11 + 12 +const 13 + ZLIB_VERSION = '1.2.7'; 14 + ZLIB_VERNUM = $1270; 15 + 16 +type 17 + alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; 18 + cdecl; 19 + free_func = procedure(opaque, address: Pointer); 20 + cdecl; 21 + 22 + in_func = function(opaque: Pointer; var buf: PByte): Integer; 23 + cdecl; 24 + out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer; 25 + cdecl; 26 + 27 + z_streamp = ^z_stream; 28 + z_stream = packed record 29 + next_in: PChar; (* next input byte *) 30 + avail_in: Integer; (* number of bytes available at next_in *) 31 + total_in: LongInt; (* total nb of input bytes read so far *) 32 + 33 + next_out: PChar; (* next output byte should be put there *) 34 + avail_out: Integer; (* remaining free space at next_out *) 35 + total_out: LongInt; (* total nb of bytes output so far *) 36 + 37 + msg: PChar; (* last error message, NULL if no error *) 38 + state: Pointer; (* not visible by applications *) 39 + 40 + zalloc: alloc_func; (* used to allocate the internal state *) 41 + zfree: free_func; (* used to free the internal state *) 42 + opaque: Pointer; (* private data object passed to zalloc and zfree *) 43 + 44 + data_type: Integer; (* best guess about the data type: ascii or binary *) 45 + adler: LongInt; (* adler32 value of the uncompressed data *) 46 + reserved: LongInt; (* reserved for future use *) 47 + end; 48 + 49 + gz_headerp = ^gz_header; 50 + gz_header = packed record 51 + text: Integer; (* true if compressed data believed to be text *) 52 + time: LongInt; (* modification time *) 53 + xflags: Integer; (* extra flags (not used when writing a gzip file) *) 54 + os: Integer; (* operating system *) 55 + extra: PChar; (* pointer to extra field or Z_NULL if none *) 56 + extra_len: Integer; (* extra field length (valid if extra != Z_NULL) *) 57 + extra_max: Integer; (* space at extra (only when reading header) *) 58 + name: PChar; (* pointer to zero-terminated file name or Z_NULL *) 59 + name_max: Integer; (* space at name (only when reading header) *) 60 + comment: PChar; (* pointer to zero-terminated comment or Z_NULL *) 61 + comm_max: Integer; (* space at comment (only when reading header) *) 62 + hcrc: Integer; (* true if there was or will be a header crc *) 63 + done: Integer; (* true when done reading gzip header *) 64 + end; 65 + 66 +(* constants *) 67 +const 68 + Z_NO_FLUSH = 0; 69 + Z_PARTIAL_FLUSH = 1; 70 + Z_SYNC_FLUSH = 2; 71 + Z_FULL_FLUSH = 3; 72 + Z_FINISH = 4; 73 + Z_BLOCK = 5; 74 + Z_TREES = 6; 75 + 76 + Z_OK = 0; 77 + Z_STREAM_END = 1; 78 + Z_NEED_DICT = 2; 79 + Z_ERRNO = -1; 80 + Z_STREAM_ERROR = -2; 81 + Z_DATA_ERROR = -3; 82 + Z_MEM_ERROR = -4; 83 + Z_BUF_ERROR = -5; 84 + Z_VERSION_ERROR = -6; 85 + 86 + Z_NO_COMPRESSION = 0; 87 + Z_BEST_SPEED = 1; 88 + Z_BEST_COMPRESSION = 9; 89 + Z_DEFAULT_COMPRESSION = -1; 90 + 91 + Z_FILTERED = 1; 92 + Z_HUFFMAN_ONLY = 2; 93 + Z_RLE = 3; 94 + Z_FIXED = 4; 95 + Z_DEFAULT_STRATEGY = 0; 96 + 97 + Z_BINARY = 0; 98 + Z_TEXT = 1; 99 + Z_ASCII = 1; 100 + Z_UNKNOWN = 2; 101 + 102 + Z_DEFLATED = 8; 103 + 104 +(* basic functions *) 105 +function zlibVersion: PChar; 106 +function deflateInit(var strm: z_stream; level: Integer): Integer; 107 +function deflate(var strm: z_stream; flush: Integer): Integer; 108 +function deflateEnd(var strm: z_stream): Integer; 109 +function inflateInit(var strm: z_stream): Integer; 110 +function inflate(var strm: z_stream; flush: Integer): Integer; 111 +function inflateEnd(var strm: z_stream): Integer; 112 + 113 +(* advanced functions *) 114 +function deflateInit2(var strm: z_stream; level, method, windowBits, 115 + memLevel, strategy: Integer): Integer; 116 +function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; 117 + dictLength: Integer): Integer; 118 +function deflateCopy(var dest, source: z_stream): Integer; 119 +function deflateReset(var strm: z_stream): Integer; 120 +function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; 121 +function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer; 122 +function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; 123 +function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer; 124 +function deflatePrime(var strm: z_stream; bits, value: Integer): Integer; 125 +function deflateSetHeader(var strm: z_stream; head: gz_header): Integer; 126 +function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; 127 +function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; 128 + dictLength: Integer): Integer; 129 +function inflateSync(var strm: z_stream): Integer; 130 +function inflateCopy(var dest, source: z_stream): Integer; 131 +function inflateReset(var strm: z_stream): Integer; 132 +function inflateReset2(var strm: z_stream; windowBits: Integer): Integer; 133 +function inflatePrime(var strm: z_stream; bits, value: Integer): Integer; 134 +function inflateMark(var strm: z_stream): LongInt; 135 +function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer; 136 +function inflateBackInit(var strm: z_stream; 137 + windowBits: Integer; window: PChar): Integer; 138 +function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; 139 + out_fn: out_func; out_desc: Pointer): Integer; 140 +function inflateBackEnd(var strm: z_stream): Integer; 141 +function zlibCompileFlags: LongInt; 142 + 143 +(* utility functions *) 144 +function compress(dest: PChar; var destLen: LongInt; 145 + const source: PChar; sourceLen: LongInt): Integer; 146 +function compress2(dest: PChar; var destLen: LongInt; 147 + const source: PChar; sourceLen: LongInt; 148 + level: Integer): Integer; 149 +function compressBound(sourceLen: LongInt): LongInt; 150 +function uncompress(dest: PChar; var destLen: LongInt; 151 + const source: PChar; sourceLen: LongInt): Integer; 152 + 153 +(* checksum functions *) 154 +function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; 155 +function adler32_combine(adler1, adler2, len2: LongInt): LongInt; 156 +function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; 157 +function crc32_combine(crc1, crc2, len2: LongInt): LongInt; 158 + 159 +(* various hacks, don't look :) *) 160 +function deflateInit_(var strm: z_stream; level: Integer; 161 + const version: PChar; stream_size: Integer): Integer; 162 +function inflateInit_(var strm: z_stream; const version: PChar; 163 + stream_size: Integer): Integer; 164 +function deflateInit2_(var strm: z_stream; 165 + level, method, windowBits, memLevel, strategy: Integer; 166 + const version: PChar; stream_size: Integer): Integer; 167 +function inflateInit2_(var strm: z_stream; windowBits: Integer; 168 + const version: PChar; stream_size: Integer): Integer; 169 +function inflateBackInit_(var strm: z_stream; 170 + windowBits: Integer; window: PChar; 171 + const version: PChar; stream_size: Integer): Integer; 172 + 173 + 174 +implementation 175 + 176 +{$L adler32.obj} 177 +{$L compress.obj} 178 +{$L crc32.obj} 179 +{$L deflate.obj} 180 +{$L infback.obj} 181 +{$L inffast.obj} 182 +{$L inflate.obj} 183 +{$L inftrees.obj} 184 +{$L trees.obj} 185 +{$L uncompr.obj} 186 +{$L zutil.obj} 187 + 188 +function adler32; external; 189 +function adler32_combine; external; 190 +function compress; external; 191 +function compress2; external; 192 +function compressBound; external; 193 +function crc32; external; 194 +function crc32_combine; external; 195 +function deflate; external; 196 +function deflateBound; external; 197 +function deflateCopy; external; 198 +function deflateEnd; external; 199 +function deflateInit_; external; 200 +function deflateInit2_; external; 201 +function deflateParams; external; 202 +function deflatePending; external; 203 +function deflatePrime; external; 204 +function deflateReset; external; 205 +function deflateSetDictionary; external; 206 +function deflateSetHeader; external; 207 +function deflateTune; external; 208 +function inflate; external; 209 +function inflateBack; external; 210 +function inflateBackEnd; external; 211 +function inflateBackInit_; external; 212 +function inflateCopy; external; 213 +function inflateEnd; external; 214 +function inflateGetHeader; external; 215 +function inflateInit_; external; 216 +function inflateInit2_; external; 217 +function inflateMark; external; 218 +function inflatePrime; external; 219 +function inflateReset; external; 220 +function inflateReset2; external; 221 +function inflateSetDictionary; external; 222 +function inflateSync; external; 223 +function uncompress; external; 224 +function zlibCompileFlags; external; 225 +function zlibVersion; external; 226 + 227 +function deflateInit(var strm: z_stream; level: Integer): Integer; 228 +begin 229 + Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); 230 +end; 231 + 232 +function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, 233 + strategy: Integer): Integer; 234 +begin 235 + Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, 236 + ZLIB_VERSION, sizeof(z_stream)); 237 +end; 238 + 239 +function inflateInit(var strm: z_stream): Integer; 240 +begin 241 + Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); 242 +end; 243 + 244 +function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; 245 +begin 246 + Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); 247 +end; 248 + 249 +function inflateBackInit(var strm: z_stream; 250 + windowBits: Integer; window: PChar): Integer; 251 +begin 252 + Result := inflateBackInit_(strm, windowBits, window, 253 + ZLIB_VERSION, sizeof(z_stream)); 254 +end; 255 + 256 +function _malloc(Size: Integer): Pointer; cdecl; 257 +begin 258 + GetMem(Result, Size); 259 +end; 260 + 261 +procedure _free(Block: Pointer); cdecl; 262 +begin 263 + FreeMem(Block); 264 +end; 265 + 266 +procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; 267 +begin 268 + FillChar(P^, count, B); 269 +end; 270 + 271 +procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; 272 +begin 273 + Move(source^, dest^, count); 274 +end; 275 + 276 +end.
Added compat/zlib/contrib/puff/Makefile.
1 +CFLAGS=-O 2 + 3 +puff: puff.o pufftest.o 4 + 5 +puff.o: puff.h 6 + 7 +pufftest.o: puff.h 8 + 9 +test: puff 10 + puff zeros.raw 11 + 12 +puft: puff.c puff.h pufftest.o 13 + cc -fprofile-arcs -ftest-coverage -o puft puff.c pufftest.o 14 + 15 +# puff full coverage test (should say 100%) 16 +cov: puft 17 + @rm -f *.gcov *.gcda 18 + @puft -w zeros.raw 2>&1 | cat > /dev/null 19 + @echo '04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 20 + @echo '00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 21 + @echo '00 00 00 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 254 22 + @echo '00 01 00 fe ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 23 + @echo '01 01 00 fe ff 0a' | xxd -r -p | puft -f 2>&1 | cat > /dev/null 24 + @echo '02 7e ff ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 25 + @echo '02' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 26 + @echo '04 80 49 92 24 49 92 24 0f b4 ff ff c3 04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 27 + @echo '04 80 49 92 24 49 92 24 71 ff ff 93 11 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 249 28 + @echo '04 c0 81 08 00 00 00 00 20 7f eb 0b 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 29 + @echo '0b 00 00' | xxd -r -p | puft -f 2>&1 | cat > /dev/null 30 + @echo '1a 07' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 31 + @echo '0c c0 81 00 00 00 00 00 90 ff 6b 04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 245 32 + @puft -f zeros.raw 2>&1 | cat > /dev/null 33 + @echo 'fc 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 253 34 + @echo '04 00 fe ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 252 35 + @echo '04 00 24 49' | xxd -r -p | puft 2> /dev/null || test $$? -eq 251 36 + @echo '04 80 49 92 24 49 92 24 0f b4 ff ff c3 84' | xxd -r -p | puft 2> /dev/null || test $$? -eq 248 37 + @echo '04 00 24 e9 ff ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 250 38 + @echo '04 00 24 e9 ff 6d' | xxd -r -p | puft 2> /dev/null || test $$? -eq 247 39 + @gcov -n puff.c 40 + 41 +clean: 42 + rm -f puff puft *.o *.gc*
Added compat/zlib/contrib/puff/README.
1 +Puff -- A Simple Inflate 2 +3 Mar 2003 3 +Mark Adler 4 +madler@alumni.caltech.edu 5 + 6 +What this is -- 7 + 8 +puff.c provides the routine puff() to decompress the deflate data format. It 9 +does so more slowly than zlib, but the code is about one-fifth the size of the 10 +inflate code in zlib, and written to be very easy to read. 11 + 12 +Why I wrote this -- 13 + 14 +puff.c was written to document the deflate format unambiguously, by virtue of 15 +being working C code. It is meant to supplement RFC 1951, which formally 16 +describes the deflate format. I have received many questions on details of the 17 +deflate format, and I hope that reading this code will answer those questions. 18 +puff.c is heavily commented with details of the deflate format, especially 19 +those little nooks and cranies of the format that might not be obvious from a 20 +specification. 21 + 22 +puff.c may also be useful in applications where code size or memory usage is a 23 +very limited resource, and speed is not as important. 24 + 25 +How to use it -- 26 + 27 +Well, most likely you should just be reading puff.c and using zlib for actual 28 +applications, but if you must ... 29 + 30 +Include puff.h in your code, which provides this prototype: 31 + 32 +int puff(unsigned char *dest, /* pointer to destination pointer */ 33 + unsigned long *destlen, /* amount of output space */ 34 + unsigned char *source, /* pointer to source data pointer */ 35 + unsigned long *sourcelen); /* amount of input available */ 36 + 37 +Then you can call puff() to decompress a deflate stream that is in memory in 38 +its entirety at source, to a sufficiently sized block of memory for the 39 +decompressed data at dest. puff() is the only external symbol in puff.c The 40 +only C library functions that puff.c needs are setjmp() and longjmp(), which 41 +are used to simplify error checking in the code to improve readabilty. puff.c 42 +does no memory allocation, and uses less than 2K bytes off of the stack. 43 + 44 +If destlen is not enough space for the uncompressed data, then inflate will 45 +return an error without writing more than destlen bytes. Note that this means 46 +that in order to decompress the deflate data successfully, you need to know 47 +the size of the uncompressed data ahead of time. 48 + 49 +If needed, puff() can determine the size of the uncompressed data with no 50 +output space. This is done by passing dest equal to (unsigned char *)0. Then 51 +the initial value of *destlen is ignored and *destlen is set to the length of 52 +the uncompressed data. So if the size of the uncompressed data is not known, 53 +then two passes of puff() can be used--first to determine the size, and second 54 +to do the actual inflation after allocating the appropriate memory. Not 55 +pretty, but it works. (This is one of the reasons you should be using zlib.) 56 + 57 +The deflate format is self-terminating. If the deflate stream does not end 58 +in *sourcelen bytes, puff() will return an error without reading at or past 59 +endsource. 60 + 61 +On return, *sourcelen is updated to the amount of input data consumed, and 62 +*destlen is updated to the size of the uncompressed data. See the comments 63 +in puff.c for the possible return codes for puff().
Added compat/zlib/contrib/puff/puff.c.
1 +/* 2 + * puff.c 3 + * Copyright (C) 2002-2010 Mark Adler 4 + * For conditions of distribution and use, see copyright notice in puff.h 5 + * version 2.2, 25 Apr 2010 6 + * 7 + * puff.c is a simple inflate written to be an unambiguous way to specify the 8 + * deflate format. It is not written for speed but rather simplicity. As a 9 + * side benefit, this code might actually be useful when small code is more 10 + * important than speed, such as bootstrap applications. For typical deflate 11 + * data, zlib's inflate() is about four times as fast as puff(). zlib's 12 + * inflate compiles to around 20K on my machine, whereas puff.c compiles to 13 + * around 4K on my machine (a PowerPC using GNU cc). If the faster decode() 14 + * function here is used, then puff() is only twice as slow as zlib's 15 + * inflate(). 16 + * 17 + * All dynamically allocated memory comes from the stack. The stack required 18 + * is less than 2K bytes. This code is compatible with 16-bit int's and 19 + * assumes that long's are at least 32 bits. puff.c uses the short data type, 20 + * assumed to be 16 bits, for arrays in order to to conserve memory. The code 21 + * works whether integers are stored big endian or little endian. 22 + * 23 + * In the comments below are "Format notes" that describe the inflate process 24 + * and document some of the less obvious aspects of the format. This source 25 + * code is meant to supplement RFC 1951, which formally describes the deflate 26 + * format: 27 + * 28 + * http://www.zlib.org/rfc-deflate.html 29 + */ 30 + 31 +/* 32 + * Change history: 33 + * 34 + * 1.0 10 Feb 2002 - First version 35 + * 1.1 17 Feb 2002 - Clarifications of some comments and notes 36 + * - Update puff() dest and source pointers on negative 37 + * errors to facilitate debugging deflators 38 + * - Remove longest from struct huffman -- not needed 39 + * - Simplify offs[] index in construct() 40 + * - Add input size and checking, using longjmp() to 41 + * maintain easy readability 42 + * - Use short data type for large arrays 43 + * - Use pointers instead of long to specify source and 44 + * destination sizes to avoid arbitrary 4 GB limits 45 + * 1.2 17 Mar 2002 - Add faster version of decode(), doubles speed (!), 46 + * but leave simple version for readabilty 47 + * - Make sure invalid distances detected if pointers 48 + * are 16 bits 49 + * - Fix fixed codes table error 50 + * - Provide a scanning mode for determining size of 51 + * uncompressed data 52 + * 1.3 20 Mar 2002 - Go back to lengths for puff() parameters [Gailly] 53 + * - Add a puff.h file for the interface 54 + * - Add braces in puff() for else do [Gailly] 55 + * - Use indexes instead of pointers for readability 56 + * 1.4 31 Mar 2002 - Simplify construct() code set check 57 + * - Fix some comments 58 + * - Add FIXLCODES #define 59 + * 1.5 6 Apr 2002 - Minor comment fixes 60 + * 1.6 7 Aug 2002 - Minor format changes 61 + * 1.7 3 Mar 2003 - Added test code for distribution 62 + * - Added zlib-like license 63 + * 1.8 9 Jan 2004 - Added some comments on no distance codes case 64 + * 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland] 65 + * - Catch missing end-of-block symbol error 66 + * 2.0 25 Jul 2008 - Add #define to permit distance too far back 67 + * - Add option in TEST code for puff to write the data 68 + * - Add option in TEST code to skip input bytes 69 + * - Allow TEST code to read from piped stdin 70 + * 2.1 4 Apr 2010 - Avoid variable initialization for happier compilers 71 + * - Avoid unsigned comparisons for even happier compilers 72 + * 2.2 25 Apr 2010 - Fix bug in variable initializations [Oberhumer] 73 + * - Add const where appropriate [Oberhumer] 74 + * - Split if's and ?'s for coverage testing 75 + * - Break out test code to separate file 76 + * - Move NIL to puff.h 77 + * - Allow incomplete code only if single code length is 1 78 + * - Add full code coverage test to Makefile 79 + */ 80 + 81 +#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ 82 +#include "puff.h" /* prototype for puff() */ 83 + 84 +#define local static /* for local function definitions */ 85 + 86 +/* 87 + * Maximums for allocations and loops. It is not useful to change these -- 88 + * they are fixed by the deflate format. 89 + */ 90 +#define MAXBITS 15 /* maximum bits in a code */ 91 +#define MAXLCODES 286 /* maximum number of literal/length codes */ 92 +#define MAXDCODES 30 /* maximum number of distance codes */ 93 +#define MAXCODES (MAXLCODES+MAXDCODES) /* maximum codes lengths to read */ 94 +#define FIXLCODES 288 /* number of fixed literal/length codes */ 95 + 96 +/* input and output state */ 97 +struct state { 98 + /* output state */ 99 + unsigned char *out; /* output buffer */ 100 + unsigned long outlen; /* available space at out */ 101 + unsigned long outcnt; /* bytes written to out so far */ 102 + 103 + /* input state */ 104 + const unsigned char *in; /* input buffer */ 105 + unsigned long inlen; /* available input at in */ 106 + unsigned long incnt; /* bytes read so far */ 107 + int bitbuf; /* bit buffer */ 108 + int bitcnt; /* number of bits in bit buffer */ 109 + 110 + /* input limit error return state for bits() and decode() */ 111 + jmp_buf env; 112 +}; 113 + 114 +/* 115 + * Return need bits from the input stream. This always leaves less than 116 + * eight bits in the buffer. bits() works properly for need == 0. 117 + * 118 + * Format notes: 119 + * 120 + * - Bits are stored in bytes from the least significant bit to the most 121 + * significant bit. Therefore bits are dropped from the bottom of the bit 122 + * buffer, using shift right, and new bytes are appended to the top of the 123 + * bit buffer, using shift left. 124 + */ 125 +local int bits(struct state *s, int need) 126 +{ 127 + long val; /* bit accumulator (can use up to 20 bits) */ 128 + 129 + /* load at least need bits into val */ 130 + val = s->bitbuf; 131 + while (s->bitcnt < need) { 132 + if (s->incnt == s->inlen) 133 + longjmp(s->env, 1); /* out of input */ 134 + val |= (long)(s->in[s->incnt++]) << s->bitcnt; /* load eight bits */ 135 + s->bitcnt += 8; 136 + } 137 + 138 + /* drop need bits and update buffer, always zero to seven bits left */ 139 + s->bitbuf = (int)(val >> need); 140 + s->bitcnt -= need; 141 + 142 + /* return need bits, zeroing the bits above that */ 143 + return (int)(val & ((1L << need) - 1)); 144 +} 145 + 146 +/* 147 + * Process a stored block. 148 + * 149 + * Format notes: 150 + * 151 + * - After the two-bit stored block type (00), the stored block length and 152 + * stored bytes are byte-aligned for fast copying. Therefore any leftover 153 + * bits in the byte that has the last bit of the type, as many as seven, are 154 + * discarded. The value of the discarded bits are not defined and should not 155 + * be checked against any expectation. 156 + * 157 + * - The second inverted copy of the stored block length does not have to be 158 + * checked, but it's probably a good idea to do so anyway. 159 + * 160 + * - A stored block can have zero length. This is sometimes used to byte-align 161 + * subsets of the compressed data for random access or partial recovery. 162 + */ 163 +local int stored(struct state *s) 164 +{ 165 + unsigned len; /* length of stored block */ 166 + 167 + /* discard leftover bits from current byte (assumes s->bitcnt < 8) */ 168 + s->bitbuf = 0; 169 + s->bitcnt = 0; 170 + 171 + /* get length and check against its one's complement */ 172 + if (s->incnt + 4 > s->inlen) 173 + return 2; /* not enough input */ 174 + len = s->in[s->incnt++]; 175 + len |= s->in[s->incnt++] << 8; 176 + if (s->in[s->incnt++] != (~len & 0xff) || 177 + s->in[s->incnt++] != ((~len >> 8) & 0xff)) 178 + return -2; /* didn't match complement! */ 179 + 180 + /* copy len bytes from in to out */ 181 + if (s->incnt + len > s->inlen) 182 + return 2; /* not enough input */ 183 + if (s->out != NIL) { 184 + if (s->outcnt + len > s->outlen) 185 + return 1; /* not enough output space */ 186 + while (len--) 187 + s->out[s->outcnt++] = s->in[s->incnt++]; 188 + } 189 + else { /* just scanning */ 190 + s->outcnt += len; 191 + s->incnt += len; 192 + } 193 + 194 + /* done with a valid stored block */ 195 + return 0; 196 +} 197 + 198 +/* 199 + * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of 200 + * each length, which for a canonical code are stepped through in order. 201 + * symbol[] are the symbol values in canonical order, where the number of 202 + * entries is the sum of the counts in count[]. The decoding process can be 203 + * seen in the function decode() below. 204 + */ 205 +struct huffman { 206 + short *count; /* number of symbols of each length */ 207 + short *symbol; /* canonically ordered symbols */ 208 +}; 209 + 210 +/* 211 + * Decode a code from the stream s using huffman table h. Return the symbol or 212 + * a negative value if there is an error. If all of the lengths are zero, i.e. 213 + * an empty code, or if the code is incomplete and an invalid code is received, 214 + * then -10 is returned after reading MAXBITS bits. 215 + * 216 + * Format notes: 217 + * 218 + * - The codes as stored in the compressed data are bit-reversed relative to 219 + * a simple integer ordering of codes of the same lengths. Hence below the 220 + * bits are pulled from the compressed data one at a time and used to 221 + * build the code value reversed from what is in the stream in order to 222 + * permit simple integer comparisons for decoding. A table-based decoding 223 + * scheme (as used in zlib) does not need to do this reversal. 224 + * 225 + * - The first code for the shortest length is all zeros. Subsequent codes of 226 + * the same length are simply integer increments of the previous code. When 227 + * moving up a length, a zero bit is appended to the code. For a complete 228 + * code, the last code of the longest length will be all ones. 229 + * 230 + * - Incomplete codes are handled by this decoder, since they are permitted 231 + * in the deflate format. See the format notes for fixed() and dynamic(). 232 + */ 233 +#ifdef SLOW 234 +local int decode(struct state *s, const struct huffman *h) 235 +{ 236 + int len; /* current number of bits in code */ 237 + int code; /* len bits being decoded */ 238 + int first; /* first code of length len */ 239 + int count; /* number of codes of length len */ 240 + int index; /* index of first code of length len in symbol table */ 241 + 242 + code = first = index = 0; 243 + for (len = 1; len <= MAXBITS; len++) { 244 + code |= bits(s, 1); /* get next bit */ 245 + count = h->count[len]; 246 + if (code - count < first) /* if length len, return symbol */ 247 + return h->symbol[index + (code - first)]; 248 + index += count; /* else update for next length */ 249 + first += count; 250 + first <<= 1; 251 + code <<= 1; 252 + } 253 + return -10; /* ran out of codes */ 254 +} 255 + 256 +/* 257 + * A faster version of decode() for real applications of this code. It's not 258 + * as readable, but it makes puff() twice as fast. And it only makes the code 259 + * a few percent larger. 260 + */ 261 +#else /* !SLOW */ 262 +local int decode(struct state *s, const struct huffman *h) 263 +{ 264 + int len; /* current number of bits in code */ 265 + int code; /* len bits being decoded */ 266 + int first; /* first code of length len */ 267 + int count; /* number of codes of length len */ 268 + int index; /* index of first code of length len in symbol table */ 269 + int bitbuf; /* bits from stream */ 270 + int left; /* bits left in next or left to process */ 271 + short *next; /* next number of codes */ 272 + 273 + bitbuf = s->bitbuf; 274 + left = s->bitcnt; 275 + code = first = index = 0; 276 + len = 1; 277 + next = h->count + 1; 278 + while (1) { 279 + while (left--) { 280 + code |= bitbuf & 1; 281 + bitbuf >>= 1; 282 + count = *next++; 283 + if (code - count < first) { /* if length len, return symbol */ 284 + s->bitbuf = bitbuf; 285 + s->bitcnt = (s->bitcnt - len) & 7; 286 + return h->symbol[index + (code - first)]; 287 + } 288 + index += count; /* else update for next length */ 289 + first += count; 290 + first <<= 1; 291 + code <<= 1; 292 + len++; 293 + } 294 + left = (MAXBITS+1) - len; 295 + if (left == 0) 296 + break; 297 + if (s->incnt == s->inlen) 298 + longjmp(s->env, 1); /* out of input */ 299 + bitbuf = s->in[s->incnt++]; 300 + if (left > 8) 301 + left = 8; 302 + } 303 + return -10; /* ran out of codes */ 304 +} 305 +#endif /* SLOW */ 306 + 307 +/* 308 + * Given the list of code lengths length[0..n-1] representing a canonical 309 + * Huffman code for n symbols, construct the tables required to decode those 310 + * codes. Those tables are the number of codes of each length, and the symbols 311 + * sorted by length, retaining their original order within each length. The 312 + * return value is zero for a complete code set, negative for an over- 313 + * subscribed code set, and positive for an incomplete code set. The tables 314 + * can be used if the return value is zero or positive, but they cannot be used 315 + * if the return value is negative. If the return value is zero, it is not 316 + * possible for decode() using that table to return an error--any stream of 317 + * enough bits will resolve to a symbol. If the return value is positive, then 318 + * it is possible for decode() using that table to return an error for received 319 + * codes past the end of the incomplete lengths. 320 + * 321 + * Not used by decode(), but used for error checking, h->count[0] is the number 322 + * of the n symbols not in the code. So n - h->count[0] is the number of 323 + * codes. This is useful for checking for incomplete codes that have more than 324 + * one symbol, which is an error in a dynamic block. 325 + * 326 + * Assumption: for all i in 0..n-1, 0 <= length[i] <= MAXBITS 327 + * This is assured by the construction of the length arrays in dynamic() and 328 + * fixed() and is not verified by construct(). 329 + * 330 + * Format notes: 331 + * 332 + * - Permitted and expected examples of incomplete codes are one of the fixed 333 + * codes and any code with a single symbol which in deflate is coded as one 334 + * bit instead of zero bits. See the format notes for fixed() and dynamic(). 335 + * 336 + * - Within a given code length, the symbols are kept in ascending order for 337 + * the code bits definition. 338 + */ 339 +local int construct(struct huffman *h, const short *length, int n) 340 +{ 341 + int symbol; /* current symbol when stepping through length[] */ 342 + int len; /* current length when stepping through h->count[] */ 343 + int left; /* number of possible codes left of current length */ 344 + short offs[MAXBITS+1]; /* offsets in symbol table for each length */ 345 + 346 + /* count number of codes of each length */ 347 + for (len = 0; len <= MAXBITS; len++) 348 + h->count[len] = 0; 349 + for (symbol = 0; symbol < n; symbol++) 350 + (h->count[length[symbol]])++; /* assumes lengths are within bounds */ 351 + if (h->count[0] == n) /* no codes! */ 352 + return 0; /* complete, but decode() will fail */ 353 + 354 + /* check for an over-subscribed or incomplete set of lengths */ 355 + left = 1; /* one possible code of zero length */ 356 + for (len = 1; len <= MAXBITS; len++) { 357 + left <<= 1; /* one more bit, double codes left */ 358 + left -= h->count[len]; /* deduct count from possible codes */ 359 + if (left < 0) 360 + return left; /* over-subscribed--return negative */ 361 + } /* left > 0 means incomplete */ 362 + 363 + /* generate offsets into symbol table for each length for sorting */ 364 + offs[1] = 0; 365 + for (len = 1; len < MAXBITS; len++) 366 + offs[len + 1] = offs[len] + h->count[len]; 367 + 368 + /* 369 + * put symbols in table sorted by length, by symbol order within each 370 + * length 371 + */ 372 + for (symbol = 0; symbol < n; symbol++) 373 + if (length[symbol] != 0) 374 + h->symbol[offs[length[symbol]]++] = symbol; 375 + 376 + /* return zero for complete set, positive for incomplete set */ 377 + return left; 378 +} 379 + 380 +/* 381 + * Decode literal/length and distance codes until an end-of-block code. 382 + * 383 + * Format notes: 384 + * 385 + * - Compressed data that is after the block type if fixed or after the code 386 + * description if dynamic is a combination of literals and length/distance 387 + * pairs terminated by and end-of-block code. Literals are simply Huffman 388 + * coded bytes. A length/distance pair is a coded length followed by a 389 + * coded distance to represent a string that occurs earlier in the 390 + * uncompressed data that occurs again at the current location. 391 + * 392 + * - Literals, lengths, and the end-of-block code are combined into a single 393 + * code of up to 286 symbols. They are 256 literals (0..255), 29 length 394 + * symbols (257..285), and the end-of-block symbol (256). 395 + * 396 + * - There are 256 possible lengths (3..258), and so 29 symbols are not enough 397 + * to represent all of those. Lengths 3..10 and 258 are in fact represented 398 + * by just a length symbol. Lengths 11..257 are represented as a symbol and 399 + * some number of extra bits that are added as an integer to the base length 400 + * of the length symbol. The number of extra bits is determined by the base 401 + * length symbol. These are in the static arrays below, lens[] for the base 402 + * lengths and lext[] for the corresponding number of extra bits. 403 + * 404 + * - The reason that 258 gets its own symbol is that the longest length is used 405 + * often in highly redundant files. Note that 258 can also be coded as the 406 + * base value 227 plus the maximum extra value of 31. While a good deflate 407 + * should never do this, it is not an error, and should be decoded properly. 408 + * 409 + * - If a length is decoded, including its extra bits if any, then it is 410 + * followed a distance code. There are up to 30 distance symbols. Again 411 + * there are many more possible distances (1..32768), so extra bits are added 412 + * to a base value represented by the symbol. The distances 1..4 get their 413 + * own symbol, but the rest require extra bits. The base distances and 414 + * corresponding number of extra bits are below in the static arrays dist[] 415 + * and dext[]. 416 + * 417 + * - Literal bytes are simply written to the output. A length/distance pair is 418 + * an instruction to copy previously uncompressed bytes to the output. The 419 + * copy is from distance bytes back in the output stream, copying for length 420 + * bytes. 421 + * 422 + * - Distances pointing before the beginning of the output data are not 423 + * permitted. 424 + * 425 + * - Overlapped copies, where the length is greater than the distance, are 426 + * allowed and common. For example, a distance of one and a length of 258 427 + * simply copies the last byte 258 times. A distance of four and a length of 428 + * twelve copies the last four bytes three times. A simple forward copy 429 + * ignoring whether the length is greater than the distance or not implements 430 + * this correctly. You should not use memcpy() since its behavior is not 431 + * defined for overlapped arrays. You should not use memmove() or bcopy() 432 + * since though their behavior -is- defined for overlapping arrays, it is 433 + * defined to do the wrong thing in this case. 434 + */ 435 +local int codes(struct state *s, 436 + const struct huffman *lencode, 437 + const struct huffman *distcode) 438 +{ 439 + int symbol; /* decoded symbol */ 440 + int len; /* length for copy */ 441 + unsigned dist; /* distance for copy */ 442 + static const short lens[29] = { /* Size base for length codes 257..285 */ 443 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 444 + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; 445 + static const short lext[29] = { /* Extra bits for length codes 257..285 */ 446 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 447 + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; 448 + static const short dists[30] = { /* Offset base for distance codes 0..29 */ 449 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 450 + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 451 + 8193, 12289, 16385, 24577}; 452 + static const short dext[30] = { /* Extra bits for distance codes 0..29 */ 453 + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 454 + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 455 + 12, 12, 13, 13}; 456 + 457 + /* decode literals and length/distance pairs */ 458 + do { 459 + symbol = decode(s, lencode); 460 + if (symbol < 0) 461 + return symbol; /* invalid symbol */ 462 + if (symbol < 256) { /* literal: symbol is the byte */ 463 + /* write out the literal */ 464 + if (s->out != NIL) { 465 + if (s->outcnt == s->outlen) 466 + return 1; 467 + s->out[s->outcnt] = symbol; 468 + } 469 + s->outcnt++; 470 + } 471 + else if (symbol > 256) { /* length */ 472 + /* get and compute length */ 473 + symbol -= 257; 474 + if (symbol >= 29) 475 + return -10; /* invalid fixed code */ 476 + len = lens[symbol] + bits(s, lext[symbol]); 477 + 478 + /* get and check distance */ 479 + symbol = decode(s, distcode); 480 + if (symbol < 0) 481 + return symbol; /* invalid symbol */ 482 + dist = dists[symbol] + bits(s, dext[symbol]); 483 +#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 484 + if (dist > s->outcnt) 485 + return -11; /* distance too far back */ 486 +#endif 487 + 488 + /* copy length bytes from distance bytes back */ 489 + if (s->out != NIL) { 490 + if (s->outcnt + len > s->outlen) 491 + return 1; 492 + while (len--) { 493 + s->out[s->outcnt] = 494 +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 495 + dist > s->outcnt ? 496 + 0 : 497 +#endif 498 + s->out[s->outcnt - dist]; 499 + s->outcnt++; 500 + } 501 + } 502 + else 503 + s->outcnt += len; 504 + } 505 + } while (symbol != 256); /* end of block symbol */ 506 + 507 + /* done with a valid fixed or dynamic block */ 508 + return 0; 509 +} 510 + 511 +/* 512 + * Process a fixed codes block. 513 + * 514 + * Format notes: 515 + * 516 + * - This block type can be useful for compressing small amounts of data for 517 + * which the size of the code descriptions in a dynamic block exceeds the 518 + * benefit of custom codes for that block. For fixed codes, no bits are 519 + * spent on code descriptions. Instead the code lengths for literal/length 520 + * codes and distance codes are fixed. The specific lengths for each symbol 521 + * can be seen in the "for" loops below. 522 + * 523 + * - The literal/length code is complete, but has two symbols that are invalid 524 + * and should result in an error if received. This cannot be implemented 525 + * simply as an incomplete code since those two symbols are in the "middle" 526 + * of the code. They are eight bits long and the longest literal/length\ 527 + * code is nine bits. Therefore the code must be constructed with those 528 + * symbols, and the invalid symbols must be detected after decoding. 529 + * 530 + * - The fixed distance codes also have two invalid symbols that should result 531 + * in an error if received. Since all of the distance codes are the same 532 + * length, this can be implemented as an incomplete code. Then the invalid 533 + * codes are detected while decoding. 534 + */ 535 +local int fixed(struct state *s) 536 +{ 537 + static int virgin = 1; 538 + static short lencnt[MAXBITS+1], lensym[FIXLCODES]; 539 + static short distcnt[MAXBITS+1], distsym[MAXDCODES]; 540 + static struct huffman lencode, distcode; 541 + 542 + /* build fixed huffman tables if first call (may not be thread safe) */ 543 + if (virgin) { 544 + int symbol; 545 + short lengths[FIXLCODES]; 546 + 547 + /* construct lencode and distcode */ 548 + lencode.count = lencnt; 549 + lencode.symbol = lensym; 550 + distcode.count = distcnt; 551 + distcode.symbol = distsym; 552 + 553 + /* literal/length table */ 554 + for (symbol = 0; symbol < 144; symbol++) 555 + lengths[symbol] = 8; 556 + for (; symbol < 256; symbol++) 557 + lengths[symbol] = 9; 558 + for (; symbol < 280; symbol++) 559 + lengths[symbol] = 7; 560 + for (; symbol < FIXLCODES; symbol++) 561 + lengths[symbol] = 8; 562 + construct(&lencode, lengths, FIXLCODES); 563 + 564 + /* distance table */ 565 + for (symbol = 0; symbol < MAXDCODES; symbol++) 566 + lengths[symbol] = 5; 567 + construct(&distcode, lengths, MAXDCODES); 568 + 569 + /* do this just once */ 570 + virgin = 0; 571 + } 572 + 573 + /* decode data until end-of-block code */ 574 + return codes(s, &lencode, &distcode); 575 +} 576 + 577 +/* 578 + * Process a dynamic codes block. 579 + * 580 + * Format notes: 581 + * 582 + * - A dynamic block starts with a description of the literal/length and 583 + * distance codes for that block. New dynamic blocks allow the compressor to 584 + * rapidly adapt to changing data with new codes optimized for that data. 585 + * 586 + * - The codes used by the deflate format are "canonical", which means that 587 + * the actual bits of the codes are generated in an unambiguous way simply 588 + * from the number of bits in each code. Therefore the code descriptions 589 + * are simply a list of code lengths for each symbol. 590 + * 591 + * - The code lengths are stored in order for the symbols, so lengths are 592 + * provided for each of the literal/length symbols, and for each of the 593 + * distance symbols. 594 + * 595 + * - If a symbol is not used in the block, this is represented by a zero as 596 + * as the code length. This does not mean a zero-length code, but rather 597 + * that no code should be created for this symbol. There is no way in the 598 + * deflate format to represent a zero-length code. 599 + * 600 + * - The maximum number of bits in a code is 15, so the possible lengths for 601 + * any code are 1..15. 602 + * 603 + * - The fact that a length of zero is not permitted for a code has an 604 + * interesting consequence. Normally if only one symbol is used for a given 605 + * code, then in fact that code could be represented with zero bits. However 606 + * in deflate, that code has to be at least one bit. So for example, if 607 + * only a single distance base symbol appears in a block, then it will be 608 + * represented by a single code of length one, in particular one 0 bit. This 609 + * is an incomplete code, since if a 1 bit is received, it has no meaning, 610 + * and should result in an error. So incomplete distance codes of one symbol 611 + * should be permitted, and the receipt of invalid codes should be handled. 612 + * 613 + * - It is also possible to have a single literal/length code, but that code 614 + * must be the end-of-block code, since every dynamic block has one. This 615 + * is not the most efficient way to create an empty block (an empty fixed 616 + * block is fewer bits), but it is allowed by the format. So incomplete 617 + * literal/length codes of one symbol should also be permitted. 618 + * 619 + * - If there are only literal codes and no lengths, then there are no distance 620 + * codes. This is represented by one distance code with zero bits. 621 + * 622 + * - The list of up to 286 length/literal lengths and up to 30 distance lengths 623 + * are themselves compressed using Huffman codes and run-length encoding. In 624 + * the list of code lengths, a 0 symbol means no code, a 1..15 symbol means 625 + * that length, and the symbols 16, 17, and 18 are run-length instructions. 626 + * Each of 16, 17, and 18 are follwed by extra bits to define the length of 627 + * the run. 16 copies the last length 3 to 6 times. 17 represents 3 to 10 628 + * zero lengths, and 18 represents 11 to 138 zero lengths. Unused symbols 629 + * are common, hence the special coding for zero lengths. 630 + * 631 + * - The symbols for 0..18 are Huffman coded, and so that code must be 632 + * described first. This is simply a sequence of up to 19 three-bit values 633 + * representing no code (0) or the code length for that symbol (1..7). 634 + * 635 + * - A dynamic block starts with three fixed-size counts from which is computed 636 + * the number of literal/length code lengths, the number of distance code 637 + * lengths, and the number of code length code lengths (ok, you come up with 638 + * a better name!) in the code descriptions. For the literal/length and 639 + * distance codes, lengths after those provided are considered zero, i.e. no 640 + * code. The code length code lengths are received in a permuted order (see 641 + * the order[] array below) to make a short code length code length list more 642 + * likely. As it turns out, very short and very long codes are less likely 643 + * to be seen in a dynamic code description, hence what may appear initially 644 + * to be a peculiar ordering. 645 + * 646 + * - Given the number of literal/length code lengths (nlen) and distance code 647 + * lengths (ndist), then they are treated as one long list of nlen + ndist 648 + * code lengths. Therefore run-length coding can and often does cross the 649 + * boundary between the two sets of lengths. 650 + * 651 + * - So to summarize, the code description at the start of a dynamic block is 652 + * three counts for the number of code lengths for the literal/length codes, 653 + * the distance codes, and the code length codes. This is followed by the 654 + * code length code lengths, three bits each. This is used to construct the 655 + * code length code which is used to read the remainder of the lengths. Then 656 + * the literal/length code lengths and distance lengths are read as a single 657 + * set of lengths using the code length codes. Codes are constructed from 658 + * the resulting two sets of lengths, and then finally you can start 659 + * decoding actual compressed data in the block. 660 + * 661 + * - For reference, a "typical" size for the code description in a dynamic 662 + * block is around 80 bytes. 663 + */ 664 +local int dynamic(struct state *s) 665 +{ 666 + int nlen, ndist, ncode; /* number of lengths in descriptor */ 667 + int index; /* index of lengths[] */ 668 + int err; /* construct() return value */ 669 + short lengths[MAXCODES]; /* descriptor code lengths */ 670 + short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */ 671 + short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */ 672 + struct huffman lencode, distcode; /* length and distance codes */ 673 + static const short order[19] = /* permutation of code length codes */ 674 + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 675 + 676 + /* construct lencode and distcode */ 677 + lencode.count = lencnt; 678 + lencode.symbol = lensym; 679 + distcode.count = distcnt; 680 + distcode.symbol = distsym; 681 + 682 + /* get number of lengths in each table, check lengths */ 683 + nlen = bits(s, 5) + 257; 684 + ndist = bits(s, 5) + 1; 685 + ncode = bits(s, 4) + 4; 686 + if (nlen > MAXLCODES || ndist > MAXDCODES) 687 + return -3; /* bad counts */ 688 + 689 + /* read code length code lengths (really), missing lengths are zero */ 690 + for (index = 0; index < ncode; index++) 691 + lengths[order[index]] = bits(s, 3); 692 + for (; index < 19; index++) 693 + lengths[order[index]] = 0; 694 + 695 + /* build huffman table for code lengths codes (use lencode temporarily) */ 696 + err = construct(&lencode, lengths, 19); 697 + if (err != 0) /* require complete code set here */ 698 + return -4; 699 + 700 + /* read length/literal and distance code length tables */ 701 + index = 0; 702 + while (index < nlen + ndist) { 703 + int symbol; /* decoded value */ 704 + int len; /* last length to repeat */ 705 + 706 + symbol = decode(s, &lencode); 707 + if (symbol < 16) /* length in 0..15 */ 708 + lengths[index++] = symbol; 709 + else { /* repeat instruction */ 710 + len = 0; /* assume repeating zeros */ 711 + if (symbol == 16) { /* repeat last length 3..6 times */ 712 + if (index == 0) 713 + return -5; /* no last length! */ 714 + len = lengths[index - 1]; /* last length */ 715 + symbol = 3 + bits(s, 2); 716 + } 717 + else if (symbol == 17) /* repeat zero 3..10 times */ 718 + symbol = 3 + bits(s, 3); 719 + else /* == 18, repeat zero 11..138 times */ 720 + symbol = 11 + bits(s, 7); 721 + if (index + symbol > nlen + ndist) 722 + return -6; /* too many lengths! */ 723 + while (symbol--) /* repeat last or zero symbol times */ 724 + lengths[index++] = len; 725 + } 726 + } 727 + 728 + /* check for end-of-block code -- there better be one! */ 729 + if (lengths[256] == 0) 730 + return -9; 731 + 732 + /* build huffman table for literal/length codes */ 733 + err = construct(&lencode, lengths, nlen); 734 + if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) 735 + return -7; /* incomplete code ok only for single length 1 code */ 736 + 737 + /* build huffman table for distance codes */ 738 + err = construct(&distcode, lengths + nlen, ndist); 739 + if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) 740 + return -8; /* incomplete code ok only for single length 1 code */ 741 + 742 + /* decode data until end-of-block code */ 743 + return codes(s, &lencode, &distcode); 744 +} 745 + 746 +/* 747 + * Inflate source to dest. On return, destlen and sourcelen are updated to the 748 + * size of the uncompressed data and the size of the deflate data respectively. 749 + * On success, the return value of puff() is zero. If there is an error in the 750 + * source data, i.e. it is not in the deflate format, then a negative value is 751 + * returned. If there is not enough input available or there is not enough 752 + * output space, then a positive error is returned. In that case, destlen and 753 + * sourcelen are not updated to facilitate retrying from the beginning with the 754 + * provision of more input data or more output space. In the case of invalid 755 + * inflate data (a negative error), the dest and source pointers are updated to 756 + * facilitate the debugging of deflators. 757 + * 758 + * puff() also has a mode to determine the size of the uncompressed output with 759 + * no output written. For this dest must be (unsigned char *)0. In this case, 760 + * the input value of *destlen is ignored, and on return *destlen is set to the 761 + * size of the uncompressed output. 762 + * 763 + * The return codes are: 764 + * 765 + * 2: available inflate data did not terminate 766 + * 1: output space exhausted before completing inflate 767 + * 0: successful inflate 768 + * -1: invalid block type (type == 3) 769 + * -2: stored block length did not match one's complement 770 + * -3: dynamic block code description: too many length or distance codes 771 + * -4: dynamic block code description: code lengths codes incomplete 772 + * -5: dynamic block code description: repeat lengths with no first length 773 + * -6: dynamic block code description: repeat more than specified lengths 774 + * -7: dynamic block code description: invalid literal/length code lengths 775 + * -8: dynamic block code description: invalid distance code lengths 776 + * -9: dynamic block code description: missing end-of-block code 777 + * -10: invalid literal/length or distance code in fixed or dynamic block 778 + * -11: distance is too far back in fixed or dynamic block 779 + * 780 + * Format notes: 781 + * 782 + * - Three bits are read for each block to determine the kind of block and 783 + * whether or not it is the last block. Then the block is decoded and the 784 + * process repeated if it was not the last block. 785 + * 786 + * - The leftover bits in the last byte of the deflate data after the last 787 + * block (if it was a fixed or dynamic block) are undefined and have no 788 + * expected values to check. 789 + */ 790 +int puff(unsigned char *dest, /* pointer to destination pointer */ 791 + unsigned long *destlen, /* amount of output space */ 792 + const unsigned char *source, /* pointer to source data pointer */ 793 + unsigned long *sourcelen) /* amount of input available */ 794 +{ 795 + struct state s; /* input/output state */ 796 + int last, type; /* block information */ 797 + int err; /* return value */ 798 + 799 + /* initialize output state */ 800 + s.out = dest; 801 + s.outlen = *destlen; /* ignored if dest is NIL */ 802 + s.outcnt = 0; 803 + 804 + /* initialize input state */ 805 + s.in = source; 806 + s.inlen = *sourcelen; 807 + s.incnt = 0; 808 + s.bitbuf = 0; 809 + s.bitcnt = 0; 810 + 811 + /* return if bits() or decode() tries to read past available input */ 812 + if (setjmp(s.env) != 0) /* if came back here via longjmp() */ 813 + err = 2; /* then skip do-loop, return error */ 814 + else { 815 + /* process blocks until last block or error */ 816 + do { 817 + last = bits(&s, 1); /* one if last block */ 818 + type = bits(&s, 2); /* block type 0..3 */ 819 + err = type == 0 ? 820 + stored(&s) : 821 + (type == 1 ? 822 + fixed(&s) : 823 + (type == 2 ? 824 + dynamic(&s) : 825 + -1)); /* type == 3, invalid */ 826 + if (err != 0) 827 + break; /* return with error */ 828 + } while (!last); 829 + } 830 + 831 + /* update the lengths and return */ 832 + if (err <= 0) { 833 + *destlen = s.outcnt; 834 + *sourcelen = s.incnt; 835 + } 836 + return err; 837 +}
Added compat/zlib/contrib/puff/puff.h.
1 +/* puff.h 2 + Copyright (C) 2002-2010 Mark Adler, all rights reserved 3 + version 2.2, 25 Apr 2010 4 + 5 + This software is provided 'as-is', without any express or implied 6 + warranty. In no event will the author be held liable for any damages 7 + arising from the use of this software. 8 + 9 + Permission is granted to anyone to use this software for any purpose, 10 + including commercial applications, and to alter it and redistribute it 11 + freely, subject to the following restrictions: 12 + 13 + 1. The origin of this software must not be misrepresented; you must not 14 + claim that you wrote the original software. If you use this software 15 + in a product, an acknowledgment in the product documentation would be 16 + appreciated but is not required. 17 + 2. Altered source versions must be plainly marked as such, and must not be 18 + misrepresented as being the original software. 19 + 3. This notice may not be removed or altered from any source distribution. 20 + 21 + Mark Adler madler@alumni.caltech.edu 22 + */ 23 + 24 + 25 +/* 26 + * See puff.c for purpose and usage. 27 + */ 28 +#ifndef NIL 29 +# define NIL ((unsigned char *)0) /* for no output option */ 30 +#endif 31 + 32 +int puff(unsigned char *dest, /* pointer to destination pointer */ 33 + unsigned long *destlen, /* amount of output space */ 34 + const unsigned char *source, /* pointer to source data pointer */ 35 + unsigned long *sourcelen); /* amount of input available */
Added compat/zlib/contrib/puff/pufftest.c.
1 +/* 2 + * pufftest.c 3 + * Copyright (C) 2002-2010 Mark Adler 4 + * For conditions of distribution and use, see copyright notice in puff.h 5 + * version 2.2, 25 Apr 2010 6 + */ 7 + 8 +/* Example of how to use puff(). 9 + 10 + Usage: puff [-w] [-f] [-nnn] file 11 + ... | puff [-w] [-f] [-nnn] 12 + 13 + where file is the input file with deflate data, nnn is the number of bytes 14 + of input to skip before inflating (e.g. to skip a zlib or gzip header), and 15 + -w is used to write the decompressed data to stdout. -f is for coverage 16 + testing, and causes pufftest to fail with not enough output space (-f does 17 + a write like -w, so -w is not required). */ 18 + 19 +#include <stdio.h> 20 +#include <stdlib.h> 21 +#include "puff.h" 22 + 23 +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 24 +# include <fcntl.h> 25 +# include <io.h> 26 +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 27 +#else 28 +# define SET_BINARY_MODE(file) 29 +#endif 30 + 31 +#define local static 32 + 33 +/* Return size times approximately the cube root of 2, keeping the result as 1, 34 + 3, or 5 times a power of 2 -- the result is always > size, until the result 35 + is the maximum value of an unsigned long, where it remains. This is useful 36 + to keep reallocations less than ~33% over the actual data. */ 37 +local size_t bythirds(size_t size) 38 +{ 39 + int n; 40 + size_t m; 41 + 42 + m = size; 43 + for (n = 0; m; n++) 44 + m >>= 1; 45 + if (n < 3) 46 + return size + 1; 47 + n -= 3; 48 + m = size >> n; 49 + m += m == 6 ? 2 : 1; 50 + m <<= n; 51 + return m > size ? m : (size_t)(-1); 52 +} 53 + 54 +/* Read the input file *name, or stdin if name is NULL, into allocated memory. 55 + Reallocate to larger buffers until the entire file is read in. Return a 56 + pointer to the allocated data, or NULL if there was a memory allocation 57 + failure. *len is the number of bytes of data read from the input file (even 58 + if load() returns NULL). If the input file was empty or could not be opened 59 + or read, *len is zero. */ 60 +local void *load(const char *name, size_t *len) 61 +{ 62 + size_t size; 63 + void *buf, *swap; 64 + FILE *in; 65 + 66 + *len = 0; 67 + buf = malloc(size = 4096); 68 + if (buf == NULL) 69 + return NULL; 70 + in = name == NULL ? stdin : fopen(name, "rb"); 71 + if (in != NULL) { 72 + for (;;) { 73 + *len += fread((char *)buf + *len, 1, size - *len, in); 74 + if (*len < size) break; 75 + size = bythirds(size); 76 + if (size == *len || (swap = realloc(buf, size)) == NULL) { 77 + free(buf); 78 + buf = NULL; 79 + break; 80 + } 81 + buf = swap; 82 + } 83 + fclose(in); 84 + } 85 + return buf; 86 +} 87 + 88 +int main(int argc, char **argv) 89 +{ 90 + int ret, put = 0, fail = 0; 91 + unsigned skip = 0; 92 + char *arg, *name = NULL; 93 + unsigned char *source = NULL, *dest; 94 + size_t len = 0; 95 + unsigned long sourcelen, destlen; 96 + 97 + /* process arguments */ 98 + while (arg = *++argv, --argc) 99 + if (arg[0] == '-') { 100 + if (arg[1] == 'w' && arg[2] == 0) 101 + put = 1; 102 + else if (arg[1] == 'f' && arg[2] == 0) 103 + fail = 1, put = 1; 104 + else if (arg[1] >= '0' && arg[1] <= '9') 105 + skip = (unsigned)atoi(arg + 1); 106 + else { 107 + fprintf(stderr, "invalid option %s\n", arg); 108 + return 3; 109 + } 110 + } 111 + else if (name != NULL) { 112 + fprintf(stderr, "only one file name allowed\n"); 113 + return 3; 114 + } 115 + else 116 + name = arg; 117 + source = load(name, &len); 118 + if (source == NULL) { 119 + fprintf(stderr, "memory allocation failure\n"); 120 + return 4; 121 + } 122 + if (len == 0) { 123 + fprintf(stderr, "could not read %s, or it was empty\n", 124 + name == NULL ? "<stdin>" : name); 125 + free(source); 126 + return 3; 127 + } 128 + if (skip >= len) { 129 + fprintf(stderr, "skip request of %d leaves no input\n", skip); 130 + free(source); 131 + return 3; 132 + } 133 + 134 + /* test inflate data with offset skip */ 135 + len -= skip; 136 + sourcelen = (unsigned long)len; 137 + ret = puff(NIL, &destlen, source + skip, &sourcelen); 138 + if (ret) 139 + fprintf(stderr, "puff() failed with return code %d\n", ret); 140 + else { 141 + fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen); 142 + if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n", 143 + len - sourcelen); 144 + } 145 + 146 + /* if requested, inflate again and write decompressd data to stdout */ 147 + if (put && ret == 0) { 148 + if (fail) 149 + destlen >>= 1; 150 + dest = malloc(destlen); 151 + if (dest == NULL) { 152 + fprintf(stderr, "memory allocation failure\n"); 153 + free(source); 154 + return 4; 155 + } 156 + puff(dest, &destlen, source + skip, &sourcelen); 157 + SET_BINARY_MODE(stdout); 158 + fwrite(dest, 1, destlen, stdout); 159 + free(dest); 160 + } 161 + 162 + /* clean up */ 163 + free(source); 164 + return ret; 165 +}
Added compat/zlib/contrib/puff/zeros.raw.
cannot compute difference between binary files
Added compat/zlib/contrib/testzlib/testzlib.c.
1 +#include <stdio.h> 2 +#include <stdlib.h> 3 +#include <windows.h> 4 + 5 +#include "zlib.h" 6 + 7 + 8 +void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B) 9 +{ 10 + R->HighPart = A.HighPart - B.HighPart; 11 + if (A.LowPart >= B.LowPart) 12 + R->LowPart = A.LowPart - B.LowPart; 13 + else 14 + { 15 + R->LowPart = A.LowPart - B.LowPart; 16 + R->HighPart --; 17 + } 18 +} 19 + 20 +#ifdef _M_X64 21 +// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc 22 +unsigned __int64 __rdtsc(void); 23 +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) 24 +{ 25 + // printf("rdtsc = %I64x\n",__rdtsc()); 26 + pbeginTime64->QuadPart=__rdtsc(); 27 +} 28 + 29 +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) 30 +{ 31 + LARGE_INTEGER LIres; 32 + unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart)); 33 + LIres.QuadPart=res; 34 + // printf("rdtsc = %I64x\n",__rdtsc()); 35 + return LIres; 36 +} 37 +#else 38 +#ifdef _M_IX86 39 +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) 40 +{ 41 + DWORD dwEdx,dwEax; 42 + _asm 43 + { 44 + rdtsc 45 + mov dwEax,eax 46 + mov dwEdx,edx 47 + } 48 + pbeginTime64->LowPart=dwEax; 49 + pbeginTime64->HighPart=dwEdx; 50 +} 51 + 52 +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) 53 +{ 54 + myGetRDTSC32(pbeginTime64); 55 +} 56 + 57 +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) 58 +{ 59 + LARGE_INTEGER LIres,endTime64; 60 + myGetRDTSC32(&endTime64); 61 + 62 + LIres.LowPart=LIres.HighPart=0; 63 + MyDoMinus64(&LIres,endTime64,beginTime64); 64 + return LIres; 65 +} 66 +#else 67 +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) 68 +{ 69 +} 70 + 71 +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) 72 +{ 73 +} 74 + 75 +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) 76 +{ 77 + LARGE_INTEGER lr; 78 + lr.QuadPart=0; 79 + return lr; 80 +} 81 +#endif 82 +#endif 83 + 84 +void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf) 85 +{ 86 + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64))) 87 + { 88 + pbeginTime64->LowPart = GetTickCount(); 89 + pbeginTime64->HighPart = 0; 90 + } 91 +} 92 + 93 +DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) 94 +{ 95 + LARGE_INTEGER endTime64,ticksPerSecond,ticks; 96 + DWORDLONG ticksShifted,tickSecShifted; 97 + DWORD dwLog=16+0; 98 + DWORD dwRet; 99 + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64))) 100 + dwRet = (GetTickCount() - beginTime64.LowPart)*1; 101 + else 102 + { 103 + MyDoMinus64(&ticks,endTime64,beginTime64); 104 + QueryPerformanceFrequency(&ticksPerSecond); 105 + 106 + 107 + { 108 + ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog); 109 + tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog); 110 + 111 + } 112 + 113 + dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted)); 114 + dwRet *=1; 115 + } 116 + return dwRet; 117 +} 118 + 119 +int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) 120 +{ 121 + FILE* stream; 122 + void* ptr; 123 + int retVal=1; 124 + stream=fopen(filename, "rb"); 125 + if (stream==NULL) 126 + return 0; 127 + 128 + fseek(stream,0,SEEK_END); 129 + 130 + *plFileSize=ftell(stream); 131 + fseek(stream,0,SEEK_SET); 132 + ptr=malloc((*plFileSize)+1); 133 + if (ptr==NULL) 134 + retVal=0; 135 + else 136 + { 137 + if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) 138 + retVal=0; 139 + } 140 + fclose(stream); 141 + *pFilePtr=ptr; 142 + return retVal; 143 +} 144 + 145 +int main(int argc, char *argv[]) 146 +{ 147 + int BlockSizeCompress=0x8000; 148 + int BlockSizeUncompress=0x8000; 149 + int cprLevel=Z_DEFAULT_COMPRESSION ; 150 + long lFileSize; 151 + unsigned char* FilePtr; 152 + long lBufferSizeCpr; 153 + long lBufferSizeUncpr; 154 + long lCompressedSize=0; 155 + unsigned char* CprPtr; 156 + unsigned char* UncprPtr; 157 + long lSizeCpr,lSizeUncpr; 158 + DWORD dwGetTick,dwMsecQP; 159 + LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc; 160 + 161 + if (argc<=1) 162 + { 163 + printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); 164 + return 0; 165 + } 166 + 167 + if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) 168 + { 169 + printf("error reading %s\n",argv[1]); 170 + return 1; 171 + } 172 + else printf("file %s read, %u bytes\n",argv[1],lFileSize); 173 + 174 + if (argc>=3) 175 + BlockSizeCompress=atol(argv[2]); 176 + 177 + if (argc>=4) 178 + BlockSizeUncompress=atol(argv[3]); 179 + 180 + if (argc>=5) 181 + cprLevel=(int)atol(argv[4]); 182 + 183 + lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; 184 + lBufferSizeUncpr = lBufferSizeCpr; 185 + 186 + CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); 187 + 188 + BeginCountPerfCounter(&li_qp,TRUE); 189 + dwGetTick=GetTickCount(); 190 + BeginCountRdtsc(&li_rdtsc); 191 + { 192 + z_stream zcpr; 193 + int ret=Z_OK; 194 + long lOrigToDo = lFileSize; 195 + long lOrigDone = 0; 196 + int step=0; 197 + memset(&zcpr,0,sizeof(z_stream)); 198 + deflateInit(&zcpr,cprLevel); 199 + 200 + zcpr.next_in = FilePtr; 201 + zcpr.next_out = CprPtr; 202 + 203 + 204 + do 205 + { 206 + long all_read_before = zcpr.total_in; 207 + zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); 208 + zcpr.avail_out = BlockSizeCompress; 209 + ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); 210 + lOrigDone += (zcpr.total_in-all_read_before); 211 + lOrigToDo -= (zcpr.total_in-all_read_before); 212 + step++; 213 + } while (ret==Z_OK); 214 + 215 + lSizeCpr=zcpr.total_out; 216 + deflateEnd(&zcpr); 217 + dwGetTick=GetTickCount()-dwGetTick; 218 + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); 219 + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); 220 + printf("total compress size = %u, in %u step\n",lSizeCpr,step); 221 + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); 222 + printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); 223 + printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); 224 + } 225 + 226 + CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr); 227 + UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); 228 + 229 + BeginCountPerfCounter(&li_qp,TRUE); 230 + dwGetTick=GetTickCount(); 231 + BeginCountRdtsc(&li_rdtsc); 232 + { 233 + z_stream zcpr; 234 + int ret=Z_OK; 235 + long lOrigToDo = lSizeCpr; 236 + long lOrigDone = 0; 237 + int step=0; 238 + memset(&zcpr,0,sizeof(z_stream)); 239 + inflateInit(&zcpr); 240 + 241 + zcpr.next_in = CprPtr; 242 + zcpr.next_out = UncprPtr; 243 + 244 + 245 + do 246 + { 247 + long all_read_before = zcpr.total_in; 248 + zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); 249 + zcpr.avail_out = BlockSizeUncompress; 250 + ret=inflate(&zcpr,Z_SYNC_FLUSH); 251 + lOrigDone += (zcpr.total_in-all_read_before); 252 + lOrigToDo -= (zcpr.total_in-all_read_before); 253 + step++; 254 + } while (ret==Z_OK); 255 + 256 + lSizeUncpr=zcpr.total_out; 257 + inflateEnd(&zcpr); 258 + dwGetTick=GetTickCount()-dwGetTick; 259 + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); 260 + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); 261 + printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); 262 + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); 263 + printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); 264 + printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); 265 + } 266 + 267 + if (lSizeUncpr==lFileSize) 268 + { 269 + if (memcmp(FilePtr,UncprPtr,lFileSize)==0) 270 + printf("compare ok\n"); 271 + 272 + } 273 + 274 + return 0; 275 +}
Added compat/zlib/contrib/testzlib/testzlib.txt.
1 +To build testzLib with Visual Studio 2005: 2 + 3 +copy to a directory file from : 4 +- root of zLib tree 5 +- contrib/testzlib 6 +- contrib/masmx86 7 +- contrib/masmx64 8 +- contrib/vstudio/vc7 9 + 10 +and open testzlib8.sln
Added compat/zlib/contrib/untgz/Makefile.
1 +CC=cc 2 +CFLAGS=-g 3 + 4 +untgz: untgz.o ../../libz.a 5 + $(CC) $(CFLAGS) -o untgz untgz.o -L../.. -lz 6 + 7 +untgz.o: untgz.c ../../zlib.h 8 + $(CC) $(CFLAGS) -c -I../.. untgz.c 9 + 10 +../../libz.a: 11 + cd ../..; ./configure; make 12 + 13 +clean: 14 + rm -f untgz untgz.o *~
Added compat/zlib/contrib/untgz/Makefile.msc.
1 +CC=cl 2 +CFLAGS=-MD 3 + 4 +untgz.exe: untgz.obj ..\..\zlib.lib 5 + $(CC) $(CFLAGS) untgz.obj ..\..\zlib.lib 6 + 7 +untgz.obj: untgz.c ..\..\zlib.h 8 + $(CC) $(CFLAGS) -c -I..\.. untgz.c 9 + 10 +..\..\zlib.lib: 11 + cd ..\.. 12 + $(MAKE) -f win32\makefile.msc 13 + cd contrib\untgz 14 + 15 +clean: 16 + -del untgz.obj 17 + -del untgz.exe
Added compat/zlib/contrib/untgz/untgz.c.
1 +/* 2 + * untgz.c -- Display contents and extract files from a gzip'd TAR file 3 + * 4 + * written by Pedro A. Aranda Gutierrez <paag@tid.es> 5 + * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org> 6 + * various fixes by Cosmin Truta <cosmint@cs.ubbcluj.ro> 7 + */ 8 + 9 +#include <stdio.h> 10 +#include <stdlib.h> 11 +#include <string.h> 12 +#include <time.h> 13 +#include <errno.h> 14 + 15 +#include "zlib.h" 16 + 17 +#ifdef unix 18 +# include <unistd.h> 19 +#else 20 +# include <direct.h> 21 +# include <io.h> 22 +#endif 23 + 24 +#ifdef WIN32 25 +#include <windows.h> 26 +# ifndef F_OK 27 +# define F_OK 0 28 +# endif 29 +# define mkdir(dirname,mode) _mkdir(dirname) 30 +# ifdef _MSC_VER 31 +# define access(path,mode) _access(path,mode) 32 +# define chmod(path,mode) _chmod(path,mode) 33 +# define strdup(str) _strdup(str) 34 +# endif 35 +#else 36 +# include <utime.h> 37 +#endif 38 + 39 + 40 +/* values used in typeflag field */ 41 + 42 +#define REGTYPE '0' /* regular file */ 43 +#define AREGTYPE '\0' /* regular file */ 44 +#define LNKTYPE '1' /* link */ 45 +#define SYMTYPE '2' /* reserved */ 46 +#define CHRTYPE '3' /* character special */ 47 +#define BLKTYPE '4' /* block special */ 48 +#define DIRTYPE '5' /* directory */ 49 +#define FIFOTYPE '6' /* FIFO special */ 50 +#define CONTTYPE '7' /* reserved */ 51 + 52 +/* GNU tar extensions */ 53 + 54 +#define GNUTYPE_DUMPDIR 'D' /* file names from dumped directory */ 55 +#define GNUTYPE_LONGLINK 'K' /* long link name */ 56 +#define GNUTYPE_LONGNAME 'L' /* long file name */ 57 +#define GNUTYPE_MULTIVOL 'M' /* continuation of file from another volume */ 58 +#define GNUTYPE_NAMES 'N' /* file name that does not fit into main hdr */ 59 +#define GNUTYPE_SPARSE 'S' /* sparse file */ 60 +#define GNUTYPE_VOLHDR 'V' /* tape/volume header */ 61 + 62 + 63 +/* tar header */ 64 + 65 +#define BLOCKSIZE 512 66 +#define SHORTNAMESIZE 100 67 + 68 +struct tar_header 69 +{ /* byte offset */ 70 + char name[100]; /* 0 */ 71 + char mode[8]; /* 100 */ 72 + char uid[8]; /* 108 */ 73 + char gid[8]; /* 116 */ 74 + char size[12]; /* 124 */ 75 + char mtime[12]; /* 136 */ 76 + char chksum[8]; /* 148 */ 77 + char typeflag; /* 156 */ 78 + char linkname[100]; /* 157 */ 79 + char magic[6]; /* 257 */ 80 + char version[2]; /* 263 */ 81 + char uname[32]; /* 265 */ 82 + char gname[32]; /* 297 */ 83 + char devmajor[8]; /* 329 */ 84 + char devminor[8]; /* 337 */ 85 + char prefix[155]; /* 345 */ 86 + /* 500 */ 87 +}; 88 + 89 +union tar_buffer 90 +{ 91 + char buffer[BLOCKSIZE]; 92 + struct tar_header header; 93 +}; 94 + 95 +struct attr_item 96 +{ 97 + struct attr_item *next; 98 + char *fname; 99 + int mode; 100 + time_t time; 101 +}; 102 + 103 +enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; 104 + 105 +char *TGZfname OF((const char *)); 106 +void TGZnotfound OF((const char *)); 107 + 108 +int getoct OF((char *, int)); 109 +char *strtime OF((time_t *)); 110 +int setfiletime OF((char *, time_t)); 111 +void push_attr OF((struct attr_item **, char *, int, time_t)); 112 +void restore_attr OF((struct attr_item **)); 113 + 114 +int ExprMatch OF((char *, char *)); 115 + 116 +int makedir OF((char *)); 117 +int matchname OF((int, int, char **, char *)); 118 + 119 +void error OF((const char *)); 120 +int tar OF((gzFile, int, int, int, char **)); 121 + 122 +void help OF((int)); 123 +int main OF((int, char **)); 124 + 125 +char *prog; 126 + 127 +const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL }; 128 + 129 +/* return the file name of the TGZ archive */ 130 +/* or NULL if it does not exist */ 131 + 132 +char *TGZfname (const char *arcname) 133 +{ 134 + static char buffer[1024]; 135 + int origlen,i; 136 + 137 + strcpy(buffer,arcname); 138 + origlen = strlen(buffer); 139 + 140 + for (i=0; TGZsuffix[i]; i++) 141 + { 142 + strcpy(buffer+origlen,TGZsuffix[i]); 143 + if (access(buffer,F_OK) == 0) 144 + return buffer; 145 + } 146 + return NULL; 147 +} 148 + 149 + 150 +/* error message for the filename */ 151 + 152 +void TGZnotfound (const char *arcname) 153 +{ 154 + int i; 155 + 156 + fprintf(stderr,"%s: Couldn't find ",prog); 157 + for (i=0;TGZsuffix[i];i++) 158 + fprintf(stderr,(TGZsuffix[i+1]) ? "%s%s, " : "or %s%s\n", 159 + arcname, 160 + TGZsuffix[i]); 161 + exit(1); 162 +} 163 + 164 + 165 +/* convert octal digits to int */ 166 +/* on error return -1 */ 167 + 168 +int getoct (char *p,int width) 169 +{ 170 + int result = 0; 171 + char c; 172 + 173 + while (width--) 174 + { 175 + c = *p++; 176 + if (c == 0) 177 + break; 178 + if (c == ' ') 179 + continue; 180 + if (c < '0' || c > '7') 181 + return -1; 182 + result = result * 8 + (c - '0'); 183 + } 184 + return result; 185 +} 186 + 187 + 188 +/* convert time_t to string */ 189 +/* use the "YYYY/MM/DD hh:mm:ss" format */ 190 + 191 +char *strtime (time_t *t) 192 +{ 193 + struct tm *local; 194 + static char result[32]; 195 + 196 + local = localtime(t); 197 + sprintf(result,"%4d/%02d/%02d %02d:%02d:%02d", 198 + local->tm_year+1900, local->tm_mon+1, local->tm_mday, 199 + local->tm_hour, local->tm_min, local->tm_sec); 200 + return result; 201 +} 202 + 203 + 204 +/* set file time */ 205 + 206 +int setfiletime (char *fname,time_t ftime) 207 +{ 208 +#ifdef WIN32 209 + static int isWinNT = -1; 210 + SYSTEMTIME st; 211 + FILETIME locft, modft; 212 + struct tm *loctm; 213 + HANDLE hFile; 214 + int result; 215 + 216 + loctm = localtime(&ftime); 217 + if (loctm == NULL) 218 + return -1; 219 + 220 + st.wYear = (WORD)loctm->tm_year + 1900; 221 + st.wMonth = (WORD)loctm->tm_mon + 1; 222 + st.wDayOfWeek = (WORD)loctm->tm_wday; 223 + st.wDay = (WORD)loctm->tm_mday; 224 + st.wHour = (WORD)loctm->tm_hour; 225 + st.wMinute = (WORD)loctm->tm_min; 226 + st.wSecond = (WORD)loctm->tm_sec; 227 + st.wMilliseconds = 0; 228 + if (!SystemTimeToFileTime(&st, &locft) || 229 + !LocalFileTimeToFileTime(&locft, &modft)) 230 + return -1; 231 + 232 + if (isWinNT < 0) 233 + isWinNT = (GetVersion() < 0x80000000) ? 1 : 0; 234 + hFile = CreateFile(fname, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 235 + (isWinNT ? FILE_FLAG_BACKUP_SEMANTICS : 0), 236 + NULL); 237 + if (hFile == INVALID_HANDLE_VALUE) 238 + return -1; 239 + result = SetFileTime(hFile, NULL, NULL, &modft) ? 0 : -1; 240 + CloseHandle(hFile); 241 + return result; 242 +#else 243 + struct utimbuf settime; 244 + 245 + settime.actime = settime.modtime = ftime; 246 + return utime(fname,&settime); 247 +#endif 248 +} 249 + 250 + 251 +/* push file attributes */ 252 + 253 +void push_attr(struct attr_item **list,char *fname,int mode,time_t time) 254 +{ 255 + struct attr_item *item; 256 + 257 + item = (struct attr_item *)malloc(sizeof(struct attr_item)); 258 + if (item == NULL) 259 + error("Out of memory"); 260 + item->fname = strdup(fname); 261 + item->mode = mode; 262 + item->time = time; 263 + item->next = *list; 264 + *list = item; 265 +} 266 + 267 + 268 +/* restore file attributes */ 269 + 270 +void restore_attr(struct attr_item **list) 271 +{ 272 + struct attr_item *item, *prev; 273 + 274 + for (item = *list; item != NULL; ) 275 + { 276 + setfiletime(item->fname,item->time); 277 + chmod(item->fname,item->mode); 278 + prev = item; 279 + item = item->next; 280 + free(prev); 281 + } 282 + *list = NULL; 283 +} 284 + 285 + 286 +/* match regular expression */ 287 + 288 +#define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) 289 + 290 +int ExprMatch (char *string,char *expr) 291 +{ 292 + while (1) 293 + { 294 + if (ISSPECIAL(*expr)) 295 + { 296 + if (*expr == '/') 297 + { 298 + if (*string != '\\' && *string != '/') 299 + return 0; 300 + string ++; expr++; 301 + } 302 + else if (*expr == '*') 303 + { 304 + if (*expr ++ == 0) 305 + return 1; 306 + while (*++string != *expr) 307 + if (*string == 0) 308 + return 0; 309 + } 310 + } 311 + else 312 + { 313 + if (*string != *expr) 314 + return 0; 315 + if (*expr++ == 0) 316 + return 1; 317 + string++; 318 + } 319 + } 320 +} 321 + 322 + 323 +/* recursive mkdir */ 324 +/* abort on ENOENT; ignore other errors like "directory already exists" */ 325 +/* return 1 if OK */ 326 +/* 0 on error */ 327 + 328 +int makedir (char *newdir) 329 +{ 330 + char *buffer = strdup(newdir); 331 + char *p; 332 + int len = strlen(buffer); 333 + 334 + if (len <= 0) { 335 + free(buffer); 336 + return 0; 337 + } 338 + if (buffer[len-1] == '/') { 339 + buffer[len-1] = '\0'; 340 + } 341 + if (mkdir(buffer, 0755) == 0) 342 + { 343 + free(buffer); 344 + return 1; 345 + } 346 + 347 + p = buffer+1; 348 + while (1) 349 + { 350 + char hold; 351 + 352 + while(*p && *p != '\\' && *p != '/') 353 + p++; 354 + hold = *p; 355 + *p = 0; 356 + if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT)) 357 + { 358 + fprintf(stderr,"%s: Couldn't create directory %s\n",prog,buffer); 359 + free(buffer); 360 + return 0; 361 + } 362 + if (hold == 0) 363 + break; 364 + *p++ = hold; 365 + } 366 + free(buffer); 367 + return 1; 368 +} 369 + 370 + 371 +int matchname (int arg,int argc,char **argv,char *fname) 372 +{ 373 + if (arg == argc) /* no arguments given (untgz tgzarchive) */ 374 + return 1; 375 + 376 + while (arg < argc) 377 + if (ExprMatch(fname,argv[arg++])) 378 + return 1; 379 + 380 + return 0; /* ignore this for the moment being */ 381 +} 382 + 383 + 384 +/* tar file list or extract */ 385 + 386 +int tar (gzFile in,int action,int arg,int argc,char **argv) 387 +{ 388 + union tar_buffer buffer; 389 + int len; 390 + int err; 391 + int getheader = 1; 392 + int remaining = 0; 393 + FILE *outfile = NULL; 394 + char fname[BLOCKSIZE]; 395 + int tarmode; 396 + time_t tartime; 397 + struct attr_item *attributes = NULL; 398 + 399 + if (action == TGZ_LIST) 400 + printf(" date time size file\n" 401 + " ---------- -------- --------- -------------------------------------\n"); 402 + while (1) 403 + { 404 + len = gzread(in, &buffer, BLOCKSIZE); 405 + if (len < 0) 406 + error(gzerror(in, &err)); 407 + /* 408 + * Always expect complete blocks to process 409 + * the tar information. 410 + */ 411 + if (len != BLOCKSIZE) 412 + { 413 + action = TGZ_INVALID; /* force error exit */ 414 + remaining = 0; /* force I/O cleanup */ 415 + } 416 + 417 + /* 418 + * If we have to get a tar header 419 + */ 420 + if (getheader >= 1) 421 + { 422 + /* 423 + * if we met the end of the tar 424 + * or the end-of-tar block, 425 + * we are done 426 + */ 427 + if (len == 0 || buffer.header.name[0] == 0) 428 + break; 429 + 430 + tarmode = getoct(buffer.header.mode,8); 431 + tartime = (time_t)getoct(buffer.header.mtime,12); 432 + if (tarmode == -1 || tartime == (time_t)-1) 433 + { 434 + buffer.header.name[0] = 0; 435 + action = TGZ_INVALID; 436 + } 437 + 438 + if (getheader == 1) 439 + { 440 + strncpy(fname,buffer.header.name,SHORTNAMESIZE); 441 + if (fname[SHORTNAMESIZE-1] != 0) 442 + fname[SHORTNAMESIZE] = 0; 443 + } 444 + else 445 + { 446 + /* 447 + * The file name is longer than SHORTNAMESIZE 448 + */ 449 + if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0) 450 + error("bad long name"); 451 + getheader = 1; 452 + } 453 + 454 + /* 455 + * Act according to the type flag 456 + */ 457 + switch (buffer.header.typeflag) 458 + { 459 + case DIRTYPE: 460 + if (action == TGZ_LIST) 461 + printf(" %s <dir> %s\n",strtime(&tartime),fname); 462 + if (action == TGZ_EXTRACT) 463 + { 464 + makedir(fname); 465 + push_attr(&attributes,fname,tarmode,tartime); 466 + } 467 + break; 468 + case REGTYPE: 469 + case AREGTYPE: 470 + remaining = getoct(buffer.header.size,12); 471 + if (remaining == -1) 472 + { 473 + action = TGZ_INVALID; 474 + break; 475 + } 476 + if (action == TGZ_LIST) 477 + printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); 478 + else if (action == TGZ_EXTRACT) 479 + { 480 + if (matchname(arg,argc,argv,fname)) 481 + { 482 + outfile = fopen(fname,"wb"); 483 + if (outfile == NULL) { 484 + /* try creating directory */ 485 + char *p = strrchr(fname, '/'); 486 + if (p != NULL) { 487 + *p = '\0'; 488 + makedir(fname); 489 + *p = '/'; 490 + outfile = fopen(fname,"wb"); 491 + } 492 + } 493 + if (outfile != NULL) 494 + printf("Extracting %s\n",fname); 495 + else 496 + fprintf(stderr, "%s: Couldn't create %s",prog,fname); 497 + } 498 + else 499 + outfile = NULL; 500 + } 501 + getheader = 0; 502 + break; 503 + case GNUTYPE_LONGLINK: 504 + case GNUTYPE_LONGNAME: 505 + remaining = getoct(buffer.header.size,12); 506 + if (remaining < 0 || remaining >= BLOCKSIZE) 507 + { 508 + action = TGZ_INVALID; 509 + break; 510 + } 511 + len = gzread(in, fname, BLOCKSIZE); 512 + if (len < 0) 513 + error(gzerror(in, &err)); 514 + if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining) 515 + { 516 + action = TGZ_INVALID; 517 + break; 518 + } 519 + getheader = 2; 520 + break; 521 + default: 522 + if (action == TGZ_LIST) 523 + printf(" %s <---> %s\n",strtime(&tartime),fname); 524 + break; 525 + } 526 + } 527 + else 528 + { 529 + unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; 530 + 531 + if (outfile != NULL) 532 + { 533 + if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) 534 + { 535 + fprintf(stderr, 536 + "%s: Error writing %s -- skipping\n",prog,fname); 537 + fclose(outfile); 538 + outfile = NULL; 539 + remove(fname); 540 + } 541 + } 542 + remaining -= bytes; 543 + } 544 + 545 + if (remaining == 0) 546 + { 547 + getheader = 1; 548 + if (outfile != NULL) 549 + { 550 + fclose(outfile); 551 + outfile = NULL; 552 + if (action != TGZ_INVALID) 553 + push_attr(&attributes,fname,tarmode,tartime); 554 + } 555 + } 556 + 557 + /* 558 + * Abandon if errors are found 559 + */ 560 + if (action == TGZ_INVALID) 561 + { 562 + error("broken archive"); 563 + break; 564 + } 565 + } 566 + 567 + /* 568 + * Restore file modes and time stamps 569 + */ 570 + restore_attr(&attributes); 571 + 572 + if (gzclose(in) != Z_OK) 573 + error("failed gzclose"); 574 + 575 + return 0; 576 +} 577 + 578 + 579 +/* ============================================================ */ 580 + 581 +void help(int exitval) 582 +{ 583 + printf("untgz version 0.2.1\n" 584 + " using zlib version %s\n\n", 585 + zlibVersion()); 586 + printf("Usage: untgz file.tgz extract all files\n" 587 + " untgz file.tgz fname ... extract selected files\n" 588 + " untgz -l file.tgz list archive contents\n" 589 + " untgz -h display this help\n"); 590 + exit(exitval); 591 +} 592 + 593 +void error(const char *msg) 594 +{ 595 + fprintf(stderr, "%s: %s\n", prog, msg); 596 + exit(1); 597 +} 598 + 599 + 600 +/* ============================================================ */ 601 + 602 +#if defined(WIN32) && defined(__GNUC__) 603 +int _CRT_glob = 0; /* disable argument globbing in MinGW */ 604 +#endif 605 + 606 +int main(int argc,char **argv) 607 +{ 608 + int action = TGZ_EXTRACT; 609 + int arg = 1; 610 + char *TGZfile; 611 + gzFile *f; 612 + 613 + prog = strrchr(argv[0],'\\'); 614 + if (prog == NULL) 615 + { 616 + prog = strrchr(argv[0],'/'); 617 + if (prog == NULL) 618 + { 619 + prog = strrchr(argv[0],':'); 620 + if (prog == NULL) 621 + prog = argv[0]; 622 + else 623 + prog++; 624 + } 625 + else 626 + prog++; 627 + } 628 + else 629 + prog++; 630 + 631 + if (argc == 1) 632 + help(0); 633 + 634 + if (strcmp(argv[arg],"-l") == 0) 635 + { 636 + action = TGZ_LIST; 637 + if (argc == ++arg) 638 + help(0); 639 + } 640 + else if (strcmp(argv[arg],"-h") == 0) 641 + { 642 + help(0); 643 + } 644 + 645 + if ((TGZfile = TGZfname(argv[arg])) == NULL) 646 + TGZnotfound(argv[arg]); 647 + 648 + ++arg; 649 + if ((action == TGZ_LIST) && (arg != argc)) 650 + help(1); 651 + 652 +/* 653 + * Process the TGZ file 654 + */ 655 + switch(action) 656 + { 657 + case TGZ_LIST: 658 + case TGZ_EXTRACT: 659 + f = gzopen(TGZfile,"rb"); 660 + if (f == NULL) 661 + { 662 + fprintf(stderr,"%s: Couldn't gzopen %s\n",prog,TGZfile); 663 + return 1; 664 + } 665 + exit(tar(f, action, arg, argc, argv)); 666 + break; 667 + 668 + default: 669 + error("Unknown option"); 670 + exit(1); 671 + } 672 + 673 + return 0; 674 +}
Added compat/zlib/contrib/vstudio/readme.txt.
1 +Building instructions for the DLL versions of Zlib 1.2.7 2 +======================================================== 3 + 4 +This directory contains projects that build zlib and minizip using 5 +Microsoft Visual C++ 9.0/10.0. 6 + 7 +You don't need to build these projects yourself. You can download the 8 +binaries from: 9 + http://www.winimage.com/zLibDll 10 + 11 +More information can be found at this site. 12 + 13 + 14 + 15 + 16 + 17 +Build instructions for Visual Studio 2008 (32 bits or 64 bits) 18 +-------------------------------------------------------------- 19 +- Uncompress current zlib, including all contrib/* files 20 +- Compile assembly code (with Visual Studio Command Prompt) by running: 21 + bld_ml64.bat (in contrib\masmx64) 22 + bld_ml32.bat (in contrib\masmx86) 23 +- Open contrib\vstudio\vc9\zlibvc.sln with Microsoft Visual C++ 2008 24 +- Or run: vcbuild /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32" 25 + 26 +Build instructions for Visual Studio 2010 (32 bits or 64 bits) 27 +-------------------------------------------------------------- 28 +- Uncompress current zlib, including all contrib/* files 29 +- Open contrib\vstudio\vc10\zlibvc.sln with Microsoft Visual C++ 2010 30 + 31 + 32 +Important 33 +--------- 34 +- To use zlibwapi.dll in your application, you must define the 35 + macro ZLIB_WINAPI when compiling your application's source files. 36 + 37 + 38 +Additional notes 39 +---------------- 40 +- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built 41 + by Gilles Vollant from the zlib 1.1.x sources, and distributed at 42 + http://www.winimage.com/zLibDll 43 + It uses the WINAPI calling convention for the exported functions, and 44 + includes the minizip functionality. If your application needs that 45 + particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll. 46 + 47 +- The new DLL was renamed because there exist several incompatible 48 + versions of zlib.dll on the Internet. 49 + 50 +- There is also an official DLL build of zlib, named zlib1.dll. This one 51 + is exporting the functions using the CDECL convention. See the file 52 + win32\DLL_FAQ.txt found in this zlib distribution. 53 + 54 +- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol 55 + has a slightly different effect. To avoid compatibility problems, do 56 + not define it here. 57 + 58 + 59 +Gilles Vollant 60 +info@winimage.com
Added compat/zlib/contrib/vstudio/vc10/miniunz.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="Release|Itanium"> 17 + <Configuration>Release</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="Release|Win32"> 21 + <Configuration>Release</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="Release|x64"> 25 + <Configuration>Release</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + </ItemGroup> 29 + <PropertyGroup Label="Globals"> 30 + <ProjectGuid>{C52F9E7B-498A-42BE-8DB4-85A15694382A}</ProjectGuid> 31 + <Keyword>Win32Proj</Keyword> 32 + </PropertyGroup> 33 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 34 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 35 + <ConfigurationType>Application</ConfigurationType> 36 + <CharacterSet>MultiByte</CharacterSet> 37 + </PropertyGroup> 38 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 39 + <ConfigurationType>Application</ConfigurationType> 40 + <CharacterSet>MultiByte</CharacterSet> 41 + </PropertyGroup> 42 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 43 + <ConfigurationType>Application</ConfigurationType> 44 + <CharacterSet>MultiByte</CharacterSet> 45 + </PropertyGroup> 46 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 47 + <ConfigurationType>Application</ConfigurationType> 48 + <CharacterSet>MultiByte</CharacterSet> 49 + </PropertyGroup> 50 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 51 + <ConfigurationType>Application</ConfigurationType> 52 + <CharacterSet>MultiByte</CharacterSet> 53 + </PropertyGroup> 54 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 55 + <ConfigurationType>Application</ConfigurationType> 56 + <CharacterSet>MultiByte</CharacterSet> 57 + </PropertyGroup> 58 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 59 + <ImportGroup Label="ExtensionSettings"> 60 + </ImportGroup> 61 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 62 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 63 + </ImportGroup> 64 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 65 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 66 + </ImportGroup> 67 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 68 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 69 + </ImportGroup> 70 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 71 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 72 + </ImportGroup> 73 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 74 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 75 + </ImportGroup> 76 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 77 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 78 + </ImportGroup> 79 + <PropertyGroup Label="UserMacros" /> 80 + <PropertyGroup> 81 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 82 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\MiniUnzip$(Configuration)\</OutDir> 83 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\MiniUnzip$(Configuration)\Tmp\</IntDir> 84 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> 85 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</GenerateManifest> 86 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\MiniUnzip$(Configuration)\</OutDir> 87 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\MiniUnzip$(Configuration)\Tmp\</IntDir> 88 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> 89 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</GenerateManifest> 90 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\MiniUnzip$(Configuration)\</OutDir> 91 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\MiniUnzip$(Configuration)\Tmp\</IntDir> 92 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental> 93 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</GenerateManifest> 94 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\MiniUnzip$(Configuration)\</OutDir> 95 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\MiniUnzip$(Configuration)\Tmp\</IntDir> 96 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</LinkIncremental> 97 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">false</GenerateManifest> 98 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\MiniUnzip$(Configuration)\</OutDir> 99 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\MiniUnzip$(Configuration)\Tmp\</IntDir> 100 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> 101 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</GenerateManifest> 102 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\MiniUnzip$(Configuration)\</OutDir> 103 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\MiniUnzip$(Configuration)\Tmp\</IntDir> 104 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</LinkIncremental> 105 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</GenerateManifest> 106 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 107 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 108 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 109 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 110 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 111 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 112 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 113 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 114 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 115 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 116 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 117 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 118 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 119 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 120 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 121 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 122 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 123 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 124 + </PropertyGroup> 125 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 126 + <ClCompile> 127 + <Optimization>Disabled</Optimization> 128 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 129 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 130 + <MinimalRebuild>true</MinimalRebuild> 131 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 132 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 133 + <BufferSecurityCheck>false</BufferSecurityCheck> 134 + <PrecompiledHeader> 135 + </PrecompiledHeader> 136 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 137 + <WarningLevel>Level3</WarningLevel> 138 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 139 + </ClCompile> 140 + <Link> 141 + <AdditionalDependencies>x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 142 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 143 + <GenerateDebugInformation>true</GenerateDebugInformation> 144 + <ProgramDatabaseFile>$(OutDir)miniunz.pdb</ProgramDatabaseFile> 145 + <SubSystem>Console</SubSystem> 146 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 147 + <DataExecutionPrevention> 148 + </DataExecutionPrevention> 149 + <TargetMachine>MachineX86</TargetMachine> 150 + </Link> 151 + </ItemDefinitionGroup> 152 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 153 + <ClCompile> 154 + <Optimization>MaxSpeed</Optimization> 155 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 156 + <OmitFramePointers>true</OmitFramePointers> 157 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 158 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 159 + <StringPooling>true</StringPooling> 160 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 161 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 162 + <BufferSecurityCheck>false</BufferSecurityCheck> 163 + <FunctionLevelLinking>true</FunctionLevelLinking> 164 + <PrecompiledHeader> 165 + </PrecompiledHeader> 166 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 167 + <WarningLevel>Level3</WarningLevel> 168 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 169 + </ClCompile> 170 + <Link> 171 + <AdditionalDependencies>x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 172 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 173 + <GenerateDebugInformation>true</GenerateDebugInformation> 174 + <SubSystem>Console</SubSystem> 175 + <OptimizeReferences>true</OptimizeReferences> 176 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 177 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 178 + <DataExecutionPrevention> 179 + </DataExecutionPrevention> 180 + <TargetMachine>MachineX86</TargetMachine> 181 + </Link> 182 + </ItemDefinitionGroup> 183 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 184 + <Midl> 185 + <TargetEnvironment>X64</TargetEnvironment> 186 + </Midl> 187 + <ClCompile> 188 + <Optimization>Disabled</Optimization> 189 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 190 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 191 + <MinimalRebuild>true</MinimalRebuild> 192 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 193 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 194 + <BufferSecurityCheck>false</BufferSecurityCheck> 195 + <PrecompiledHeader> 196 + </PrecompiledHeader> 197 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 198 + <WarningLevel>Level3</WarningLevel> 199 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 200 + </ClCompile> 201 + <Link> 202 + <AdditionalDependencies>x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 203 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 204 + <GenerateDebugInformation>true</GenerateDebugInformation> 205 + <ProgramDatabaseFile>$(OutDir)miniunz.pdb</ProgramDatabaseFile> 206 + <SubSystem>Console</SubSystem> 207 + <TargetMachine>MachineX64</TargetMachine> 208 + </Link> 209 + </ItemDefinitionGroup> 210 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 211 + <Midl> 212 + <TargetEnvironment>Itanium</TargetEnvironment> 213 + </Midl> 214 + <ClCompile> 215 + <Optimization>Disabled</Optimization> 216 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 217 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 218 + <MinimalRebuild>true</MinimalRebuild> 219 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 220 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 221 + <BufferSecurityCheck>false</BufferSecurityCheck> 222 + <PrecompiledHeader> 223 + </PrecompiledHeader> 224 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 225 + <WarningLevel>Level3</WarningLevel> 226 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 227 + </ClCompile> 228 + <Link> 229 + <AdditionalDependencies>ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 230 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 231 + <GenerateDebugInformation>true</GenerateDebugInformation> 232 + <ProgramDatabaseFile>$(OutDir)miniunz.pdb</ProgramDatabaseFile> 233 + <SubSystem>Console</SubSystem> 234 + <TargetMachine>MachineIA64</TargetMachine> 235 + </Link> 236 + </ItemDefinitionGroup> 237 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 238 + <Midl> 239 + <TargetEnvironment>X64</TargetEnvironment> 240 + </Midl> 241 + <ClCompile> 242 + <Optimization>MaxSpeed</Optimization> 243 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 244 + <OmitFramePointers>true</OmitFramePointers> 245 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 246 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 247 + <StringPooling>true</StringPooling> 248 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 249 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 250 + <BufferSecurityCheck>false</BufferSecurityCheck> 251 + <FunctionLevelLinking>true</FunctionLevelLinking> 252 + <PrecompiledHeader> 253 + </PrecompiledHeader> 254 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 255 + <WarningLevel>Level3</WarningLevel> 256 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 257 + </ClCompile> 258 + <Link> 259 + <AdditionalDependencies>x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 260 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 261 + <GenerateDebugInformation>true</GenerateDebugInformation> 262 + <SubSystem>Console</SubSystem> 263 + <OptimizeReferences>true</OptimizeReferences> 264 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 265 + <TargetMachine>MachineX64</TargetMachine> 266 + </Link> 267 + </ItemDefinitionGroup> 268 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 269 + <Midl> 270 + <TargetEnvironment>Itanium</TargetEnvironment> 271 + </Midl> 272 + <ClCompile> 273 + <Optimization>MaxSpeed</Optimization> 274 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 275 + <OmitFramePointers>true</OmitFramePointers> 276 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 277 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 278 + <StringPooling>true</StringPooling> 279 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 280 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 281 + <BufferSecurityCheck>false</BufferSecurityCheck> 282 + <FunctionLevelLinking>true</FunctionLevelLinking> 283 + <PrecompiledHeader> 284 + </PrecompiledHeader> 285 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 286 + <WarningLevel>Level3</WarningLevel> 287 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 288 + </ClCompile> 289 + <Link> 290 + <AdditionalDependencies>ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 291 + <OutputFile>$(OutDir)miniunz.exe</OutputFile> 292 + <GenerateDebugInformation>true</GenerateDebugInformation> 293 + <SubSystem>Console</SubSystem> 294 + <OptimizeReferences>true</OptimizeReferences> 295 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 296 + <TargetMachine>MachineIA64</TargetMachine> 297 + </Link> 298 + </ItemDefinitionGroup> 299 + <ItemGroup> 300 + <ClCompile Include="..\..\minizip\miniunz.c" /> 301 + </ItemGroup> 302 + <ItemGroup> 303 + <ProjectReference Include="zlibvc.vcxproj"> 304 + <Project>{8fd826f8-3739-44e6-8cc8-997122e53b8d}</Project> 305 + </ProjectReference> 306 + </ItemGroup> 307 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 308 + <ImportGroup Label="ExtensionTargets"> 309 + </ImportGroup> 310 +</Project>
Added compat/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{048af943-022b-4db6-beeb-a54c34774ee2}</UniqueIdentifier> 6 + <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions> 7 + </Filter> 8 + <Filter Include="Header Files"> 9 + <UniqueIdentifier>{c1d600d2-888f-4aea-b73e-8b0dd9befa0c}</UniqueIdentifier> 10 + <Extensions>h;hpp;hxx;hm;inl;inc</Extensions> 11 + </Filter> 12 + <Filter Include="Resource Files"> 13 + <UniqueIdentifier>{0844199a-966b-4f19-81db-1e0125e141b9}</UniqueIdentifier> 14 + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions> 15 + </Filter> 16 + </ItemGroup> 17 + <ItemGroup> 18 + <ClCompile Include="..\..\minizip\miniunz.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + </ItemGroup> 22 +</Project>
Added compat/zlib/contrib/vstudio/vc10/miniunz.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc10/minizip.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="Release|Itanium"> 17 + <Configuration>Release</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="Release|Win32"> 21 + <Configuration>Release</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="Release|x64"> 25 + <Configuration>Release</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + </ItemGroup> 29 + <PropertyGroup Label="Globals"> 30 + <ProjectGuid>{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}</ProjectGuid> 31 + <Keyword>Win32Proj</Keyword> 32 + </PropertyGroup> 33 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 34 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 35 + <ConfigurationType>Application</ConfigurationType> 36 + <CharacterSet>MultiByte</CharacterSet> 37 + </PropertyGroup> 38 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 39 + <ConfigurationType>Application</ConfigurationType> 40 + <CharacterSet>MultiByte</CharacterSet> 41 + </PropertyGroup> 42 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 43 + <ConfigurationType>Application</ConfigurationType> 44 + <CharacterSet>MultiByte</CharacterSet> 45 + </PropertyGroup> 46 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 47 + <ConfigurationType>Application</ConfigurationType> 48 + <CharacterSet>MultiByte</CharacterSet> 49 + </PropertyGroup> 50 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 51 + <ConfigurationType>Application</ConfigurationType> 52 + <CharacterSet>MultiByte</CharacterSet> 53 + </PropertyGroup> 54 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 55 + <ConfigurationType>Application</ConfigurationType> 56 + <CharacterSet>MultiByte</CharacterSet> 57 + </PropertyGroup> 58 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 59 + <ImportGroup Label="ExtensionSettings"> 60 + </ImportGroup> 61 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 62 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 63 + </ImportGroup> 64 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 65 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 66 + </ImportGroup> 67 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 68 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 69 + </ImportGroup> 70 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 71 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 72 + </ImportGroup> 73 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 74 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 75 + </ImportGroup> 76 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 77 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 78 + </ImportGroup> 79 + <PropertyGroup Label="UserMacros" /> 80 + <PropertyGroup> 81 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 82 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\MiniZip$(Configuration)\</OutDir> 83 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\MiniZip$(Configuration)\Tmp\</IntDir> 84 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> 85 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</GenerateManifest> 86 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\MiniZip$(Configuration)\</OutDir> 87 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\MiniZip$(Configuration)\Tmp\</IntDir> 88 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> 89 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\$(Configuration)\</OutDir> 90 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\$(Configuration)\</IntDir> 91 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental> 92 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</GenerateManifest> 93 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\$(Configuration)\</OutDir> 94 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\$(Configuration)\</IntDir> 95 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</LinkIncremental> 96 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">false</GenerateManifest> 97 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\$(Configuration)\</OutDir> 98 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\$(Configuration)\</IntDir> 99 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> 100 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\$(Configuration)\</OutDir> 101 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\$(Configuration)\</IntDir> 102 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</LinkIncremental> 103 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 104 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 105 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 106 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 107 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 108 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 109 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 110 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 111 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 112 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 113 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 114 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 115 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 116 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 117 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 118 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 119 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 120 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 121 + </PropertyGroup> 122 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 123 + <ClCompile> 124 + <Optimization>Disabled</Optimization> 125 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 126 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 127 + <MinimalRebuild>true</MinimalRebuild> 128 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 129 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 130 + <BufferSecurityCheck>false</BufferSecurityCheck> 131 + <PrecompiledHeader> 132 + </PrecompiledHeader> 133 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 134 + <WarningLevel>Level3</WarningLevel> 135 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 136 + </ClCompile> 137 + <Link> 138 + <AdditionalDependencies>x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 139 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 140 + <GenerateDebugInformation>true</GenerateDebugInformation> 141 + <ProgramDatabaseFile>$(OutDir)minizip.pdb</ProgramDatabaseFile> 142 + <SubSystem>Console</SubSystem> 143 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 144 + <DataExecutionPrevention> 145 + </DataExecutionPrevention> 146 + <TargetMachine>MachineX86</TargetMachine> 147 + </Link> 148 + </ItemDefinitionGroup> 149 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 150 + <ClCompile> 151 + <Optimization>MaxSpeed</Optimization> 152 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 153 + <OmitFramePointers>true</OmitFramePointers> 154 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 155 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 156 + <StringPooling>true</StringPooling> 157 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 158 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 159 + <BufferSecurityCheck>false</BufferSecurityCheck> 160 + <FunctionLevelLinking>true</FunctionLevelLinking> 161 + <PrecompiledHeader> 162 + </PrecompiledHeader> 163 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 164 + <WarningLevel>Level3</WarningLevel> 165 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 166 + </ClCompile> 167 + <Link> 168 + <AdditionalDependencies>x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 169 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 170 + <GenerateDebugInformation>true</GenerateDebugInformation> 171 + <SubSystem>Console</SubSystem> 172 + <OptimizeReferences>true</OptimizeReferences> 173 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 174 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 175 + <DataExecutionPrevention> 176 + </DataExecutionPrevention> 177 + <TargetMachine>MachineX86</TargetMachine> 178 + </Link> 179 + </ItemDefinitionGroup> 180 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 181 + <Midl> 182 + <TargetEnvironment>X64</TargetEnvironment> 183 + </Midl> 184 + <ClCompile> 185 + <Optimization>Disabled</Optimization> 186 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 187 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 188 + <MinimalRebuild>true</MinimalRebuild> 189 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 190 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 191 + <BufferSecurityCheck>false</BufferSecurityCheck> 192 + <PrecompiledHeader> 193 + </PrecompiledHeader> 194 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 195 + <WarningLevel>Level3</WarningLevel> 196 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 197 + </ClCompile> 198 + <Link> 199 + <AdditionalDependencies>x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 200 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 201 + <GenerateDebugInformation>true</GenerateDebugInformation> 202 + <ProgramDatabaseFile>$(OutDir)minizip.pdb</ProgramDatabaseFile> 203 + <SubSystem>Console</SubSystem> 204 + <TargetMachine>MachineX64</TargetMachine> 205 + </Link> 206 + </ItemDefinitionGroup> 207 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 208 + <Midl> 209 + <TargetEnvironment>Itanium</TargetEnvironment> 210 + </Midl> 211 + <ClCompile> 212 + <Optimization>Disabled</Optimization> 213 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 214 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 215 + <MinimalRebuild>true</MinimalRebuild> 216 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 217 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 218 + <BufferSecurityCheck>false</BufferSecurityCheck> 219 + <PrecompiledHeader> 220 + </PrecompiledHeader> 221 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 222 + <WarningLevel>Level3</WarningLevel> 223 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 224 + </ClCompile> 225 + <Link> 226 + <AdditionalDependencies>ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 227 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 228 + <GenerateDebugInformation>true</GenerateDebugInformation> 229 + <ProgramDatabaseFile>$(OutDir)minizip.pdb</ProgramDatabaseFile> 230 + <SubSystem>Console</SubSystem> 231 + <TargetMachine>MachineIA64</TargetMachine> 232 + </Link> 233 + </ItemDefinitionGroup> 234 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 235 + <Midl> 236 + <TargetEnvironment>X64</TargetEnvironment> 237 + </Midl> 238 + <ClCompile> 239 + <Optimization>MaxSpeed</Optimization> 240 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 241 + <OmitFramePointers>true</OmitFramePointers> 242 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 243 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 244 + <StringPooling>true</StringPooling> 245 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 246 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 247 + <BufferSecurityCheck>false</BufferSecurityCheck> 248 + <FunctionLevelLinking>true</FunctionLevelLinking> 249 + <PrecompiledHeader> 250 + </PrecompiledHeader> 251 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 252 + <WarningLevel>Level3</WarningLevel> 253 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 254 + </ClCompile> 255 + <Link> 256 + <AdditionalDependencies>x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 257 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 258 + <GenerateDebugInformation>true</GenerateDebugInformation> 259 + <SubSystem>Console</SubSystem> 260 + <OptimizeReferences>true</OptimizeReferences> 261 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 262 + <TargetMachine>MachineX64</TargetMachine> 263 + </Link> 264 + </ItemDefinitionGroup> 265 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 266 + <Midl> 267 + <TargetEnvironment>Itanium</TargetEnvironment> 268 + </Midl> 269 + <ClCompile> 270 + <Optimization>MaxSpeed</Optimization> 271 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 272 + <OmitFramePointers>true</OmitFramePointers> 273 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 274 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 275 + <StringPooling>true</StringPooling> 276 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 277 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 278 + <BufferSecurityCheck>false</BufferSecurityCheck> 279 + <FunctionLevelLinking>true</FunctionLevelLinking> 280 + <PrecompiledHeader> 281 + </PrecompiledHeader> 282 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 283 + <WarningLevel>Level3</WarningLevel> 284 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 285 + </ClCompile> 286 + <Link> 287 + <AdditionalDependencies>ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 288 + <OutputFile>$(OutDir)minizip.exe</OutputFile> 289 + <GenerateDebugInformation>true</GenerateDebugInformation> 290 + <SubSystem>Console</SubSystem> 291 + <OptimizeReferences>true</OptimizeReferences> 292 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 293 + <TargetMachine>MachineIA64</TargetMachine> 294 + </Link> 295 + </ItemDefinitionGroup> 296 + <ItemGroup> 297 + <ClCompile Include="..\..\minizip\minizip.c" /> 298 + </ItemGroup> 299 + <ItemGroup> 300 + <ProjectReference Include="zlibvc.vcxproj"> 301 + <Project>{8fd826f8-3739-44e6-8cc8-997122e53b8d}</Project> 302 + </ProjectReference> 303 + </ItemGroup> 304 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 305 + <ImportGroup Label="ExtensionTargets"> 306 + </ImportGroup> 307 +</Project>
Added compat/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{c0419b40-bf50-40da-b153-ff74215b79de}</UniqueIdentifier> 6 + <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions> 7 + </Filter> 8 + <Filter Include="Header Files"> 9 + <UniqueIdentifier>{bb87b070-735b-478e-92ce-7383abb2f36c}</UniqueIdentifier> 10 + <Extensions>h;hpp;hxx;hm;inl;inc</Extensions> 11 + </Filter> 12 + <Filter Include="Resource Files"> 13 + <UniqueIdentifier>{f46ab6a6-548f-43cb-ae96-681abb5bd5db}</UniqueIdentifier> 14 + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions> 15 + </Filter> 16 + </ItemGroup> 17 + <ItemGroup> 18 + <ClCompile Include="..\..\minizip\minizip.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + </ItemGroup> 22 +</Project>
Added compat/zlib/contrib/vstudio/vc10/minizip.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlib.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="ReleaseWithoutAsm|Itanium"> 17 + <Configuration>ReleaseWithoutAsm</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="ReleaseWithoutAsm|Win32"> 21 + <Configuration>ReleaseWithoutAsm</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="ReleaseWithoutAsm|x64"> 25 + <Configuration>ReleaseWithoutAsm</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + <ProjectConfiguration Include="Release|Itanium"> 29 + <Configuration>Release</Configuration> 30 + <Platform>Itanium</Platform> 31 + </ProjectConfiguration> 32 + <ProjectConfiguration Include="Release|Win32"> 33 + <Configuration>Release</Configuration> 34 + <Platform>Win32</Platform> 35 + </ProjectConfiguration> 36 + <ProjectConfiguration Include="Release|x64"> 37 + <Configuration>Release</Configuration> 38 + <Platform>x64</Platform> 39 + </ProjectConfiguration> 40 + </ItemGroup> 41 + <PropertyGroup Label="Globals"> 42 + <ProjectGuid>{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}</ProjectGuid> 43 + <RootNamespace>testzlib</RootNamespace> 44 + <Keyword>Win32Proj</Keyword> 45 + </PropertyGroup> 46 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 47 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 48 + <ConfigurationType>Application</ConfigurationType> 49 + <CharacterSet>MultiByte</CharacterSet> 50 + <WholeProgramOptimization>true</WholeProgramOptimization> 51 + </PropertyGroup> 52 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="Configuration"> 53 + <ConfigurationType>Application</ConfigurationType> 54 + <CharacterSet>MultiByte</CharacterSet> 55 + <WholeProgramOptimization>true</WholeProgramOptimization> 56 + </PropertyGroup> 57 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 58 + <ConfigurationType>Application</ConfigurationType> 59 + <CharacterSet>MultiByte</CharacterSet> 60 + </PropertyGroup> 61 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 62 + <ConfigurationType>Application</ConfigurationType> 63 + <CharacterSet>MultiByte</CharacterSet> 64 + <WholeProgramOptimization>true</WholeProgramOptimization> 65 + </PropertyGroup> 66 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="Configuration"> 67 + <ConfigurationType>Application</ConfigurationType> 68 + <CharacterSet>MultiByte</CharacterSet> 69 + <WholeProgramOptimization>true</WholeProgramOptimization> 70 + </PropertyGroup> 71 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 72 + <ConfigurationType>Application</ConfigurationType> 73 + <CharacterSet>MultiByte</CharacterSet> 74 + </PropertyGroup> 75 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 76 + <ConfigurationType>Application</ConfigurationType> 77 + <WholeProgramOptimization>true</WholeProgramOptimization> 78 + </PropertyGroup> 79 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="Configuration"> 80 + <ConfigurationType>Application</ConfigurationType> 81 + <WholeProgramOptimization>true</WholeProgramOptimization> 82 + </PropertyGroup> 83 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 84 + <ConfigurationType>Application</ConfigurationType> 85 + </PropertyGroup> 86 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 87 + <ImportGroup Label="ExtensionSettings"> 88 + </ImportGroup> 89 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 90 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 91 + </ImportGroup> 92 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="PropertySheets"> 93 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 94 + </ImportGroup> 95 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 96 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 97 + </ImportGroup> 98 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 99 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 100 + </ImportGroup> 101 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="PropertySheets"> 102 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 103 + </ImportGroup> 104 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 105 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 106 + </ImportGroup> 107 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 108 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 109 + </ImportGroup> 110 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="PropertySheets"> 111 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 112 + </ImportGroup> 113 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 114 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 115 + </ImportGroup> 116 + <PropertyGroup Label="UserMacros" /> 117 + <PropertyGroup> 118 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 119 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\TestZlib$(Configuration)\</OutDir> 120 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\TestZlib$(Configuration)\Tmp\</IntDir> 121 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> 122 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</GenerateManifest> 123 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\TestZlib$(Configuration)\</OutDir> 124 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\TestZlib$(Configuration)\Tmp\</IntDir> 125 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">false</LinkIncremental> 126 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">false</GenerateManifest> 127 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\TestZlib$(Configuration)\</OutDir> 128 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\TestZlib$(Configuration)\Tmp\</IntDir> 129 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> 130 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</GenerateManifest> 131 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\TestZlib$(Configuration)\</OutDir> 132 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\TestZlib$(Configuration)\Tmp\</IntDir> 133 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</GenerateManifest> 134 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\TestZlib$(Configuration)\</OutDir> 135 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\TestZlib$(Configuration)\Tmp\</IntDir> 136 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</LinkIncremental> 137 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">false</GenerateManifest> 138 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\TestZlib$(Configuration)\</OutDir> 139 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\TestZlib$(Configuration)\Tmp\</IntDir> 140 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">false</GenerateManifest> 141 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\TestZlib$(Configuration)\</OutDir> 142 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\TestZlib$(Configuration)\Tmp\</IntDir> 143 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">false</LinkIncremental> 144 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">false</GenerateManifest> 145 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\TestZlib$(Configuration)\</OutDir> 146 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\TestZlib$(Configuration)\Tmp\</IntDir> 147 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</GenerateManifest> 148 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\TestZlib$(Configuration)\</OutDir> 149 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\TestZlib$(Configuration)\Tmp\</IntDir> 150 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</LinkIncremental> 151 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</GenerateManifest> 152 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 153 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 154 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 155 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 156 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 157 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 158 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 159 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 160 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 161 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 162 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 163 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 164 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 165 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 166 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 167 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 168 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 169 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 170 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 171 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 172 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 173 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 174 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 175 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 176 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 177 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 178 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 179 + </PropertyGroup> 180 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 181 + <ClCompile> 182 + <Optimization>Disabled</Optimization> 183 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 184 + <PreprocessorDefinitions>ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 185 + <MinimalRebuild>true</MinimalRebuild> 186 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 187 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 188 + <BufferSecurityCheck>false</BufferSecurityCheck> 189 + <PrecompiledHeader> 190 + </PrecompiledHeader> 191 + <AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput> 192 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 193 + <WarningLevel>Level3</WarningLevel> 194 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 195 + </ClCompile> 196 + <Link> 197 + <AdditionalDependencies>..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies)</AdditionalDependencies> 198 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 199 + <GenerateDebugInformation>true</GenerateDebugInformation> 200 + <ProgramDatabaseFile>$(OutDir)testzlib.pdb</ProgramDatabaseFile> 201 + <SubSystem>Console</SubSystem> 202 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 203 + <DataExecutionPrevention> 204 + </DataExecutionPrevention> 205 + <TargetMachine>MachineX86</TargetMachine> 206 + </Link> 207 + </ItemDefinitionGroup> 208 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'"> 209 + <ClCompile> 210 + <Optimization>MaxSpeed</Optimization> 211 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 212 + <OmitFramePointers>true</OmitFramePointers> 213 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 214 + <PreprocessorDefinitions>WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 215 + <StringPooling>true</StringPooling> 216 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 217 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 218 + <BufferSecurityCheck>false</BufferSecurityCheck> 219 + <FunctionLevelLinking>true</FunctionLevelLinking> 220 + <PrecompiledHeader> 221 + </PrecompiledHeader> 222 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 223 + <WarningLevel>Level3</WarningLevel> 224 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 225 + </ClCompile> 226 + <Link> 227 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 228 + <GenerateDebugInformation>true</GenerateDebugInformation> 229 + <SubSystem>Console</SubSystem> 230 + <OptimizeReferences>true</OptimizeReferences> 231 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 232 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 233 + <DataExecutionPrevention> 234 + </DataExecutionPrevention> 235 + <TargetMachine>MachineX86</TargetMachine> 236 + </Link> 237 + </ItemDefinitionGroup> 238 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 239 + <ClCompile> 240 + <Optimization>MaxSpeed</Optimization> 241 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 242 + <OmitFramePointers>true</OmitFramePointers> 243 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 244 + <PreprocessorDefinitions>ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 245 + <StringPooling>true</StringPooling> 246 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 247 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 248 + <BufferSecurityCheck>false</BufferSecurityCheck> 249 + <FunctionLevelLinking>true</FunctionLevelLinking> 250 + <PrecompiledHeader> 251 + </PrecompiledHeader> 252 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 253 + <WarningLevel>Level3</WarningLevel> 254 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 255 + </ClCompile> 256 + <Link> 257 + <AdditionalDependencies>..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies)</AdditionalDependencies> 258 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 259 + <GenerateDebugInformation>true</GenerateDebugInformation> 260 + <SubSystem>Console</SubSystem> 261 + <OptimizeReferences>true</OptimizeReferences> 262 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 263 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 264 + <DataExecutionPrevention> 265 + </DataExecutionPrevention> 266 + <TargetMachine>MachineX86</TargetMachine> 267 + </Link> 268 + </ItemDefinitionGroup> 269 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 270 + <ClCompile> 271 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 272 + <PreprocessorDefinitions>ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 273 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 274 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 275 + <BufferSecurityCheck>false</BufferSecurityCheck> 276 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 277 + </ClCompile> 278 + <Link> 279 + <AdditionalDependencies>..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies)</AdditionalDependencies> 280 + </Link> 281 + </ItemDefinitionGroup> 282 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 283 + <Midl> 284 + <TargetEnvironment>Itanium</TargetEnvironment> 285 + </Midl> 286 + <ClCompile> 287 + <Optimization>Disabled</Optimization> 288 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 289 + <PreprocessorDefinitions>ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 290 + <MinimalRebuild>true</MinimalRebuild> 291 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 292 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 293 + <BufferSecurityCheck>false</BufferSecurityCheck> 294 + <PrecompiledHeader> 295 + </PrecompiledHeader> 296 + <AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput> 297 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 298 + <WarningLevel>Level3</WarningLevel> 299 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 300 + </ClCompile> 301 + <Link> 302 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 303 + <GenerateDebugInformation>true</GenerateDebugInformation> 304 + <ProgramDatabaseFile>$(OutDir)testzlib.pdb</ProgramDatabaseFile> 305 + <SubSystem>Console</SubSystem> 306 + <TargetMachine>MachineIA64</TargetMachine> 307 + </Link> 308 + </ItemDefinitionGroup> 309 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'"> 310 + <ClCompile> 311 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 312 + <PreprocessorDefinitions>WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 313 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 314 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 315 + <BufferSecurityCheck>false</BufferSecurityCheck> 316 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 317 + </ClCompile> 318 + <Link> 319 + <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> 320 + </Link> 321 + </ItemDefinitionGroup> 322 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'"> 323 + <Midl> 324 + <TargetEnvironment>Itanium</TargetEnvironment> 325 + </Midl> 326 + <ClCompile> 327 + <Optimization>MaxSpeed</Optimization> 328 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 329 + <OmitFramePointers>true</OmitFramePointers> 330 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 331 + <PreprocessorDefinitions>ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 332 + <StringPooling>true</StringPooling> 333 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 334 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 335 + <BufferSecurityCheck>false</BufferSecurityCheck> 336 + <FunctionLevelLinking>true</FunctionLevelLinking> 337 + <PrecompiledHeader> 338 + </PrecompiledHeader> 339 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 340 + <WarningLevel>Level3</WarningLevel> 341 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 342 + </ClCompile> 343 + <Link> 344 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 345 + <GenerateDebugInformation>true</GenerateDebugInformation> 346 + <SubSystem>Console</SubSystem> 347 + <OptimizeReferences>true</OptimizeReferences> 348 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 349 + <TargetMachine>MachineIA64</TargetMachine> 350 + </Link> 351 + </ItemDefinitionGroup> 352 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 353 + <ClCompile> 354 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 355 + <PreprocessorDefinitions>ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 356 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 357 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 358 + <BufferSecurityCheck>false</BufferSecurityCheck> 359 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 360 + </ClCompile> 361 + <Link> 362 + <AdditionalDependencies>..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies)</AdditionalDependencies> 363 + </Link> 364 + </ItemDefinitionGroup> 365 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 366 + <Midl> 367 + <TargetEnvironment>Itanium</TargetEnvironment> 368 + </Midl> 369 + <ClCompile> 370 + <Optimization>MaxSpeed</Optimization> 371 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 372 + <OmitFramePointers>true</OmitFramePointers> 373 + <AdditionalIncludeDirectories>..\..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 374 + <PreprocessorDefinitions>ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 375 + <StringPooling>true</StringPooling> 376 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 377 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 378 + <BufferSecurityCheck>false</BufferSecurityCheck> 379 + <FunctionLevelLinking>true</FunctionLevelLinking> 380 + <PrecompiledHeader> 381 + </PrecompiledHeader> 382 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 383 + <WarningLevel>Level3</WarningLevel> 384 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 385 + </ClCompile> 386 + <Link> 387 + <OutputFile>$(OutDir)testzlib.exe</OutputFile> 388 + <GenerateDebugInformation>true</GenerateDebugInformation> 389 + <SubSystem>Console</SubSystem> 390 + <OptimizeReferences>true</OptimizeReferences> 391 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 392 + <TargetMachine>MachineIA64</TargetMachine> 393 + </Link> 394 + </ItemDefinitionGroup> 395 + <ItemGroup> 396 + <ClCompile Include="..\..\..\adler32.c" /> 397 + <ClCompile Include="..\..\..\compress.c" /> 398 + <ClCompile Include="..\..\..\crc32.c" /> 399 + <ClCompile Include="..\..\..\deflate.c" /> 400 + <ClCompile Include="..\..\..\infback.c" /> 401 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 402 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</ExcludedFromBuild> 403 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> 404 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">true</ExcludedFromBuild> 405 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">true</ExcludedFromBuild> 406 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">true</ExcludedFromBuild> 407 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> 408 + </ClCompile> 409 + <ClCompile Include="..\..\..\inffast.c" /> 410 + <ClCompile Include="..\..\..\inflate.c" /> 411 + <ClCompile Include="..\..\..\inftrees.c" /> 412 + <ClCompile Include="..\..\testzlib\testzlib.c" /> 413 + <ClCompile Include="..\..\..\trees.c" /> 414 + <ClCompile Include="..\..\..\uncompr.c" /> 415 + <ClCompile Include="..\..\..\zutil.c" /> 416 + </ItemGroup> 417 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 418 + <ImportGroup Label="ExtensionTargets"> 419 + </ImportGroup> 420 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{c1f6a2e3-5da5-4955-8653-310d3efe05a9}</UniqueIdentifier> 6 + <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions> 7 + </Filter> 8 + <Filter Include="Header Files"> 9 + <UniqueIdentifier>{c2aaffdc-2c95-4d6f-8466-4bec5890af2c}</UniqueIdentifier> 10 + <Extensions>h;hpp;hxx;hm;inl;inc</Extensions> 11 + </Filter> 12 + <Filter Include="Resource Files"> 13 + <UniqueIdentifier>{c274fe07-05f2-461c-964b-f6341e4e7eb5}</UniqueIdentifier> 14 + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions> 15 + </Filter> 16 + </ItemGroup> 17 + <ItemGroup> 18 + <ClCompile Include="..\..\..\adler32.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + <ClCompile Include="..\..\..\compress.c"> 22 + <Filter>Source Files</Filter> 23 + </ClCompile> 24 + <ClCompile Include="..\..\..\crc32.c"> 25 + <Filter>Source Files</Filter> 26 + </ClCompile> 27 + <ClCompile Include="..\..\..\deflate.c"> 28 + <Filter>Source Files</Filter> 29 + </ClCompile> 30 + <ClCompile Include="..\..\..\infback.c"> 31 + <Filter>Source Files</Filter> 32 + </ClCompile> 33 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 34 + <Filter>Source Files</Filter> 35 + </ClCompile> 36 + <ClCompile Include="..\..\..\inffast.c"> 37 + <Filter>Source Files</Filter> 38 + </ClCompile> 39 + <ClCompile Include="..\..\..\inflate.c"> 40 + <Filter>Source Files</Filter> 41 + </ClCompile> 42 + <ClCompile Include="..\..\..\inftrees.c"> 43 + <Filter>Source Files</Filter> 44 + </ClCompile> 45 + <ClCompile Include="..\..\testzlib\testzlib.c"> 46 + <Filter>Source Files</Filter> 47 + </ClCompile> 48 + <ClCompile Include="..\..\..\trees.c"> 49 + <Filter>Source Files</Filter> 50 + </ClCompile> 51 + <ClCompile Include="..\..\..\uncompr.c"> 52 + <Filter>Source Files</Filter> 53 + </ClCompile> 54 + <ClCompile Include="..\..\..\zutil.c"> 55 + <Filter>Source Files</Filter> 56 + </ClCompile> 57 + </ItemGroup> 58 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlib.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="Release|Itanium"> 17 + <Configuration>Release</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="Release|Win32"> 21 + <Configuration>Release</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="Release|x64"> 25 + <Configuration>Release</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + </ItemGroup> 29 + <PropertyGroup Label="Globals"> 30 + <ProjectGuid>{C52F9E7B-498A-42BE-8DB4-85A15694366A}</ProjectGuid> 31 + <Keyword>Win32Proj</Keyword> 32 + </PropertyGroup> 33 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 34 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 35 + <ConfigurationType>Application</ConfigurationType> 36 + <CharacterSet>MultiByte</CharacterSet> 37 + </PropertyGroup> 38 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 39 + <ConfigurationType>Application</ConfigurationType> 40 + <CharacterSet>MultiByte</CharacterSet> 41 + </PropertyGroup> 42 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 43 + <ConfigurationType>Application</ConfigurationType> 44 + <CharacterSet>MultiByte</CharacterSet> 45 + </PropertyGroup> 46 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 47 + <ConfigurationType>Application</ConfigurationType> 48 + <CharacterSet>MultiByte</CharacterSet> 49 + </PropertyGroup> 50 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 51 + <ConfigurationType>Application</ConfigurationType> 52 + <CharacterSet>MultiByte</CharacterSet> 53 + </PropertyGroup> 54 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 55 + <ConfigurationType>Application</ConfigurationType> 56 + <CharacterSet>MultiByte</CharacterSet> 57 + </PropertyGroup> 58 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 59 + <ImportGroup Label="ExtensionSettings"> 60 + </ImportGroup> 61 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 62 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 63 + </ImportGroup> 64 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 65 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 66 + </ImportGroup> 67 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 68 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 69 + </ImportGroup> 70 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 71 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 72 + </ImportGroup> 73 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 74 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 75 + </ImportGroup> 76 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 77 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 78 + </ImportGroup> 79 + <PropertyGroup Label="UserMacros" /> 80 + <PropertyGroup> 81 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 82 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\TestZlibDll$(Configuration)\</OutDir> 83 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\TestZlibDll$(Configuration)\Tmp\</IntDir> 84 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> 85 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</GenerateManifest> 86 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\TestZlibDll$(Configuration)\</OutDir> 87 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\TestZlibDll$(Configuration)\Tmp\</IntDir> 88 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> 89 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</GenerateManifest> 90 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\TestZlibDll$(Configuration)\</OutDir> 91 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\TestZlibDll$(Configuration)\Tmp\</IntDir> 92 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental> 93 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</GenerateManifest> 94 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\TestZlibDll$(Configuration)\</OutDir> 95 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\TestZlibDll$(Configuration)\Tmp\</IntDir> 96 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</LinkIncremental> 97 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">false</GenerateManifest> 98 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\TestZlibDll$(Configuration)\</OutDir> 99 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\TestZlibDll$(Configuration)\Tmp\</IntDir> 100 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> 101 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</GenerateManifest> 102 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\TestZlibDll$(Configuration)\</OutDir> 103 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\TestZlibDll$(Configuration)\Tmp\</IntDir> 104 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</LinkIncremental> 105 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</GenerateManifest> 106 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 107 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 108 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 109 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 110 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 111 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 112 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 113 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 114 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 115 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 116 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 117 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 118 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 119 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 120 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 121 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 122 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 123 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 124 + </PropertyGroup> 125 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 126 + <ClCompile> 127 + <Optimization>Disabled</Optimization> 128 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 129 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 130 + <MinimalRebuild>true</MinimalRebuild> 131 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 132 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 133 + <BufferSecurityCheck>false</BufferSecurityCheck> 134 + <PrecompiledHeader> 135 + </PrecompiledHeader> 136 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 137 + <WarningLevel>Level3</WarningLevel> 138 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 139 + </ClCompile> 140 + <Link> 141 + <AdditionalDependencies>x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 142 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 143 + <GenerateDebugInformation>true</GenerateDebugInformation> 144 + <ProgramDatabaseFile>$(OutDir)testzlib.pdb</ProgramDatabaseFile> 145 + <SubSystem>Console</SubSystem> 146 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 147 + <DataExecutionPrevention> 148 + </DataExecutionPrevention> 149 + <TargetMachine>MachineX86</TargetMachine> 150 + </Link> 151 + </ItemDefinitionGroup> 152 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 153 + <ClCompile> 154 + <Optimization>MaxSpeed</Optimization> 155 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 156 + <OmitFramePointers>true</OmitFramePointers> 157 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 158 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> 159 + <StringPooling>true</StringPooling> 160 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 161 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 162 + <BufferSecurityCheck>false</BufferSecurityCheck> 163 + <FunctionLevelLinking>true</FunctionLevelLinking> 164 + <PrecompiledHeader> 165 + </PrecompiledHeader> 166 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 167 + <WarningLevel>Level3</WarningLevel> 168 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 169 + </ClCompile> 170 + <Link> 171 + <AdditionalDependencies>x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 172 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 173 + <GenerateDebugInformation>true</GenerateDebugInformation> 174 + <SubSystem>Console</SubSystem> 175 + <OptimizeReferences>true</OptimizeReferences> 176 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 177 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 178 + <DataExecutionPrevention> 179 + </DataExecutionPrevention> 180 + <TargetMachine>MachineX86</TargetMachine> 181 + </Link> 182 + </ItemDefinitionGroup> 183 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 184 + <Midl> 185 + <TargetEnvironment>X64</TargetEnvironment> 186 + </Midl> 187 + <ClCompile> 188 + <Optimization>Disabled</Optimization> 189 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 190 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 191 + <MinimalRebuild>true</MinimalRebuild> 192 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 193 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 194 + <BufferSecurityCheck>false</BufferSecurityCheck> 195 + <PrecompiledHeader> 196 + </PrecompiledHeader> 197 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 198 + <WarningLevel>Level3</WarningLevel> 199 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 200 + </ClCompile> 201 + <Link> 202 + <AdditionalDependencies>x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 203 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 204 + <GenerateDebugInformation>true</GenerateDebugInformation> 205 + <ProgramDatabaseFile>$(OutDir)testzlib.pdb</ProgramDatabaseFile> 206 + <SubSystem>Console</SubSystem> 207 + <TargetMachine>MachineX64</TargetMachine> 208 + </Link> 209 + </ItemDefinitionGroup> 210 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 211 + <Midl> 212 + <TargetEnvironment>Itanium</TargetEnvironment> 213 + </Midl> 214 + <ClCompile> 215 + <Optimization>Disabled</Optimization> 216 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 217 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 218 + <MinimalRebuild>true</MinimalRebuild> 219 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 220 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 221 + <BufferSecurityCheck>false</BufferSecurityCheck> 222 + <PrecompiledHeader> 223 + </PrecompiledHeader> 224 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 225 + <WarningLevel>Level3</WarningLevel> 226 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 227 + </ClCompile> 228 + <Link> 229 + <AdditionalDependencies>ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 230 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 231 + <GenerateDebugInformation>true</GenerateDebugInformation> 232 + <ProgramDatabaseFile>$(OutDir)testzlib.pdb</ProgramDatabaseFile> 233 + <SubSystem>Console</SubSystem> 234 + <TargetMachine>MachineIA64</TargetMachine> 235 + </Link> 236 + </ItemDefinitionGroup> 237 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 238 + <Midl> 239 + <TargetEnvironment>X64</TargetEnvironment> 240 + </Midl> 241 + <ClCompile> 242 + <Optimization>MaxSpeed</Optimization> 243 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 244 + <OmitFramePointers>true</OmitFramePointers> 245 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 246 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 247 + <StringPooling>true</StringPooling> 248 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 249 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 250 + <BufferSecurityCheck>false</BufferSecurityCheck> 251 + <FunctionLevelLinking>true</FunctionLevelLinking> 252 + <PrecompiledHeader> 253 + </PrecompiledHeader> 254 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 255 + <WarningLevel>Level3</WarningLevel> 256 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 257 + </ClCompile> 258 + <Link> 259 + <AdditionalDependencies>x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 260 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 261 + <GenerateDebugInformation>true</GenerateDebugInformation> 262 + <SubSystem>Console</SubSystem> 263 + <OptimizeReferences>true</OptimizeReferences> 264 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 265 + <TargetMachine>MachineX64</TargetMachine> 266 + </Link> 267 + </ItemDefinitionGroup> 268 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 269 + <Midl> 270 + <TargetEnvironment>Itanium</TargetEnvironment> 271 + </Midl> 272 + <ClCompile> 273 + <Optimization>MaxSpeed</Optimization> 274 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 275 + <OmitFramePointers>true</OmitFramePointers> 276 + <AdditionalIncludeDirectories>..\..\..;..\..\minizip;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 277 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 278 + <StringPooling>true</StringPooling> 279 + <BasicRuntimeChecks>Default</BasicRuntimeChecks> 280 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 281 + <BufferSecurityCheck>false</BufferSecurityCheck> 282 + <FunctionLevelLinking>true</FunctionLevelLinking> 283 + <PrecompiledHeader> 284 + </PrecompiledHeader> 285 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 286 + <WarningLevel>Level3</WarningLevel> 287 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 288 + </ClCompile> 289 + <Link> 290 + <AdditionalDependencies>ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> 291 + <OutputFile>$(OutDir)testzlibdll.exe</OutputFile> 292 + <GenerateDebugInformation>true</GenerateDebugInformation> 293 + <SubSystem>Console</SubSystem> 294 + <OptimizeReferences>true</OptimizeReferences> 295 + <EnableCOMDATFolding>true</EnableCOMDATFolding> 296 + <TargetMachine>MachineIA64</TargetMachine> 297 + </Link> 298 + </ItemDefinitionGroup> 299 + <ItemGroup> 300 + <ClCompile Include="..\..\testzlib\testzlib.c" /> 301 + </ItemGroup> 302 + <ItemGroup> 303 + <ProjectReference Include="zlibvc.vcxproj"> 304 + <Project>{8fd826f8-3739-44e6-8cc8-997122e53b8d}</Project> 305 + </ProjectReference> 306 + </ItemGroup> 307 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 308 + <ImportGroup Label="ExtensionTargets"> 309 + </ImportGroup> 310 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{fa61a89f-93fc-4c89-b29e-36224b7592f4}</UniqueIdentifier> 6 + <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions> 7 + </Filter> 8 + <Filter Include="Header Files"> 9 + <UniqueIdentifier>{d4b85da0-2ba2-4934-b57f-e2584e3848ee}</UniqueIdentifier> 10 + <Extensions>h;hpp;hxx;hm;inl;inc</Extensions> 11 + </Filter> 12 + <Filter Include="Resource Files"> 13 + <UniqueIdentifier>{e573e075-00bd-4a7d-bd67-a8cc9bfc5aca}</UniqueIdentifier> 14 + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions> 15 + </Filter> 16 + </ItemGroup> 17 + <ItemGroup> 18 + <ClCompile Include="..\..\testzlib\testzlib.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + </ItemGroup> 22 +</Project>
Added compat/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlib.rc.
1 +#include <windows.h> 2 + 3 +#define IDR_VERSION1 1 4 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 5 + FILEVERSION 1.2.7,0 6 + PRODUCTVERSION 1.2.7,0 7 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 + FILEFLAGS 0 9 + FILEOS VOS_DOS_WINDOWS32 10 + FILETYPE VFT_DLL 11 + FILESUBTYPE 0 // not used 12 +BEGIN 13 + BLOCK "StringFileInfo" 14 + BEGIN 15 + BLOCK "040904E4" 16 + //language ID = U.S. English, char set = Windows, Multilingual 17 + 18 + BEGIN 19 + VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" 20 + VALUE "FileVersion", "1.2.7\0" 21 + VALUE "InternalName", "zlib\0" 22 + VALUE "OriginalFilename", "zlib.dll\0" 23 + VALUE "ProductName", "ZLib.DLL\0" 24 + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" 25 + VALUE "LegalCopyright", "(C) 1995-2012 Jean-loup Gailly & Mark Adler\0" 26 + END 27 + END 28 + BLOCK "VarFileInfo" 29 + BEGIN 30 + VALUE "Translation", 0x0409, 1252 31 + END 32 +END
Added compat/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="ReleaseWithoutAsm|Itanium"> 17 + <Configuration>ReleaseWithoutAsm</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="ReleaseWithoutAsm|Win32"> 21 + <Configuration>ReleaseWithoutAsm</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="ReleaseWithoutAsm|x64"> 25 + <Configuration>ReleaseWithoutAsm</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + <ProjectConfiguration Include="Release|Itanium"> 29 + <Configuration>Release</Configuration> 30 + <Platform>Itanium</Platform> 31 + </ProjectConfiguration> 32 + <ProjectConfiguration Include="Release|Win32"> 33 + <Configuration>Release</Configuration> 34 + <Platform>Win32</Platform> 35 + </ProjectConfiguration> 36 + <ProjectConfiguration Include="Release|x64"> 37 + <Configuration>Release</Configuration> 38 + <Platform>x64</Platform> 39 + </ProjectConfiguration> 40 + </ItemGroup> 41 + <PropertyGroup Label="Globals"> 42 + <ProjectGuid>{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}</ProjectGuid> 43 + </PropertyGroup> 44 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 45 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="Configuration"> 46 + <ConfigurationType>StaticLibrary</ConfigurationType> 47 + <UseOfMfc>false</UseOfMfc> 48 + </PropertyGroup> 49 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 50 + <ConfigurationType>StaticLibrary</ConfigurationType> 51 + <UseOfMfc>false</UseOfMfc> 52 + </PropertyGroup> 53 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 54 + <ConfigurationType>StaticLibrary</ConfigurationType> 55 + <UseOfMfc>false</UseOfMfc> 56 + </PropertyGroup> 57 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="Configuration"> 58 + <ConfigurationType>StaticLibrary</ConfigurationType> 59 + <UseOfMfc>false</UseOfMfc> 60 + </PropertyGroup> 61 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 62 + <ConfigurationType>StaticLibrary</ConfigurationType> 63 + <UseOfMfc>false</UseOfMfc> 64 + </PropertyGroup> 65 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 66 + <ConfigurationType>StaticLibrary</ConfigurationType> 67 + <UseOfMfc>false</UseOfMfc> 68 + </PropertyGroup> 69 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="Configuration"> 70 + <ConfigurationType>StaticLibrary</ConfigurationType> 71 + <UseOfMfc>false</UseOfMfc> 72 + </PropertyGroup> 73 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 74 + <ConfigurationType>StaticLibrary</ConfigurationType> 75 + <UseOfMfc>false</UseOfMfc> 76 + </PropertyGroup> 77 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 78 + <ConfigurationType>StaticLibrary</ConfigurationType> 79 + <UseOfMfc>false</UseOfMfc> 80 + </PropertyGroup> 81 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 82 + <ImportGroup Label="ExtensionSettings"> 83 + </ImportGroup> 84 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="PropertySheets"> 85 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 86 + </ImportGroup> 87 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 88 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 89 + </ImportGroup> 90 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 91 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 92 + </ImportGroup> 93 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="PropertySheets"> 94 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 95 + </ImportGroup> 96 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 97 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 98 + </ImportGroup> 99 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 100 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 101 + </ImportGroup> 102 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="PropertySheets"> 103 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 104 + </ImportGroup> 105 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 106 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 107 + </ImportGroup> 108 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 109 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 110 + </ImportGroup> 111 + <PropertyGroup Label="UserMacros" /> 112 + <PropertyGroup> 113 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 114 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\ZlibStat$(Configuration)\</OutDir> 115 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\ZlibStat$(Configuration)\Tmp\</IntDir> 116 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\ZlibStat$(Configuration)\</OutDir> 117 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\ZlibStat$(Configuration)\Tmp\</IntDir> 118 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\ZlibStat$(Configuration)\</OutDir> 119 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\ZlibStat$(Configuration)\Tmp\</IntDir> 120 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\ZlibStat$(Configuration)\</OutDir> 121 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\ZlibStat$(Configuration)\Tmp\</IntDir> 122 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\ZlibStat$(Configuration)\</OutDir> 123 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\ZlibStat$(Configuration)\Tmp\</IntDir> 124 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\ZlibStat$(Configuration)\</OutDir> 125 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\ZlibStat$(Configuration)\Tmp\</IntDir> 126 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\ZlibStat$(Configuration)\</OutDir> 127 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\ZlibStat$(Configuration)\Tmp\</IntDir> 128 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\ZlibStat$(Configuration)\</OutDir> 129 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\ZlibStat$(Configuration)\Tmp\</IntDir> 130 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\ZlibStat$(Configuration)\</OutDir> 131 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\ZlibStat$(Configuration)\Tmp\</IntDir> 132 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 133 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 134 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 135 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 136 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 137 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 138 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 139 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 140 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 141 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 142 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 143 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 144 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 145 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 146 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 147 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 148 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 149 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 150 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 151 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 152 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 153 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 154 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 155 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 156 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 157 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 158 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 159 + </PropertyGroup> 160 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 161 + <ClCompile> 162 + <Optimization>Disabled</Optimization> 163 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 164 + <PreprocessorDefinitions>WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 165 + <ExceptionHandling> 166 + </ExceptionHandling> 167 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 168 + <BufferSecurityCheck>false</BufferSecurityCheck> 169 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 170 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 171 + <ObjectFileName>$(IntDir)</ObjectFileName> 172 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 173 + <WarningLevel>Level3</WarningLevel> 174 + <SuppressStartupBanner>true</SuppressStartupBanner> 175 + <DebugInformationFormat>OldStyle</DebugInformationFormat> 176 + </ClCompile> 177 + <ResourceCompile> 178 + <Culture>0x040c</Culture> 179 + </ResourceCompile> 180 + <Lib> 181 + <AdditionalOptions>/MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 182 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 183 + <SuppressStartupBanner>true</SuppressStartupBanner> 184 + </Lib> 185 + </ItemDefinitionGroup> 186 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 187 + <ClCompile> 188 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 189 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 190 + <PreprocessorDefinitions>WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;%(PreprocessorDefinitions)</PreprocessorDefinitions> 191 + <StringPooling>true</StringPooling> 192 + <ExceptionHandling> 193 + </ExceptionHandling> 194 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 195 + <BufferSecurityCheck>false</BufferSecurityCheck> 196 + <FunctionLevelLinking>true</FunctionLevelLinking> 197 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 198 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 199 + <ObjectFileName>$(IntDir)</ObjectFileName> 200 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 201 + <WarningLevel>Level3</WarningLevel> 202 + <SuppressStartupBanner>true</SuppressStartupBanner> 203 + </ClCompile> 204 + <ResourceCompile> 205 + <Culture>0x040c</Culture> 206 + </ResourceCompile> 207 + <Lib> 208 + <AdditionalOptions>/MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 209 + <AdditionalDependencies>..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies)</AdditionalDependencies> 210 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 211 + <SuppressStartupBanner>true</SuppressStartupBanner> 212 + </Lib> 213 + </ItemDefinitionGroup> 214 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'"> 215 + <ClCompile> 216 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 217 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 218 + <PreprocessorDefinitions>WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> 219 + <StringPooling>true</StringPooling> 220 + <ExceptionHandling> 221 + </ExceptionHandling> 222 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 223 + <BufferSecurityCheck>false</BufferSecurityCheck> 224 + <FunctionLevelLinking>true</FunctionLevelLinking> 225 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 226 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 227 + <ObjectFileName>$(IntDir)</ObjectFileName> 228 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 229 + <WarningLevel>Level3</WarningLevel> 230 + <SuppressStartupBanner>true</SuppressStartupBanner> 231 + </ClCompile> 232 + <ResourceCompile> 233 + <Culture>0x040c</Culture> 234 + </ResourceCompile> 235 + <Lib> 236 + <AdditionalOptions>/MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 237 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 238 + <SuppressStartupBanner>true</SuppressStartupBanner> 239 + </Lib> 240 + </ItemDefinitionGroup> 241 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 242 + <Midl> 243 + <TargetEnvironment>X64</TargetEnvironment> 244 + </Midl> 245 + <ClCompile> 246 + <Optimization>Disabled</Optimization> 247 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 248 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 249 + <ExceptionHandling> 250 + </ExceptionHandling> 251 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 252 + <BufferSecurityCheck>false</BufferSecurityCheck> 253 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 254 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 255 + <ObjectFileName>$(IntDir)</ObjectFileName> 256 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 257 + <WarningLevel>Level3</WarningLevel> 258 + <SuppressStartupBanner>true</SuppressStartupBanner> 259 + <DebugInformationFormat>OldStyle</DebugInformationFormat> 260 + </ClCompile> 261 + <ResourceCompile> 262 + <Culture>0x040c</Culture> 263 + </ResourceCompile> 264 + <Lib> 265 + <AdditionalOptions>/MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 266 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 267 + <SuppressStartupBanner>true</SuppressStartupBanner> 268 + </Lib> 269 + </ItemDefinitionGroup> 270 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 271 + <Midl> 272 + <TargetEnvironment>Itanium</TargetEnvironment> 273 + </Midl> 274 + <ClCompile> 275 + <Optimization>Disabled</Optimization> 276 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 277 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 278 + <ExceptionHandling> 279 + </ExceptionHandling> 280 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 281 + <BufferSecurityCheck>false</BufferSecurityCheck> 282 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 283 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 284 + <ObjectFileName>$(IntDir)</ObjectFileName> 285 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 286 + <WarningLevel>Level3</WarningLevel> 287 + <SuppressStartupBanner>true</SuppressStartupBanner> 288 + <DebugInformationFormat>OldStyle</DebugInformationFormat> 289 + </ClCompile> 290 + <ResourceCompile> 291 + <Culture>0x040c</Culture> 292 + </ResourceCompile> 293 + <Lib> 294 + <AdditionalOptions>/MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 295 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 296 + <SuppressStartupBanner>true</SuppressStartupBanner> 297 + </Lib> 298 + </ItemDefinitionGroup> 299 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 300 + <Midl> 301 + <TargetEnvironment>X64</TargetEnvironment> 302 + </Midl> 303 + <ClCompile> 304 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 305 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 306 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 307 + <StringPooling>true</StringPooling> 308 + <ExceptionHandling> 309 + </ExceptionHandling> 310 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 311 + <BufferSecurityCheck>false</BufferSecurityCheck> 312 + <FunctionLevelLinking>true</FunctionLevelLinking> 313 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 314 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 315 + <ObjectFileName>$(IntDir)</ObjectFileName> 316 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 317 + <WarningLevel>Level3</WarningLevel> 318 + <SuppressStartupBanner>true</SuppressStartupBanner> 319 + </ClCompile> 320 + <ResourceCompile> 321 + <Culture>0x040c</Culture> 322 + </ResourceCompile> 323 + <Lib> 324 + <AdditionalOptions>/MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 325 + <AdditionalDependencies>..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies)</AdditionalDependencies> 326 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 327 + <SuppressStartupBanner>true</SuppressStartupBanner> 328 + </Lib> 329 + </ItemDefinitionGroup> 330 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 331 + <Midl> 332 + <TargetEnvironment>Itanium</TargetEnvironment> 333 + </Midl> 334 + <ClCompile> 335 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 336 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 337 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 338 + <StringPooling>true</StringPooling> 339 + <ExceptionHandling> 340 + </ExceptionHandling> 341 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 342 + <BufferSecurityCheck>false</BufferSecurityCheck> 343 + <FunctionLevelLinking>true</FunctionLevelLinking> 344 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 345 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 346 + <ObjectFileName>$(IntDir)</ObjectFileName> 347 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 348 + <WarningLevel>Level3</WarningLevel> 349 + <SuppressStartupBanner>true</SuppressStartupBanner> 350 + </ClCompile> 351 + <ResourceCompile> 352 + <Culture>0x040c</Culture> 353 + </ResourceCompile> 354 + <Lib> 355 + <AdditionalOptions>/MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 356 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 357 + <SuppressStartupBanner>true</SuppressStartupBanner> 358 + </Lib> 359 + </ItemDefinitionGroup> 360 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'"> 361 + <Midl> 362 + <TargetEnvironment>X64</TargetEnvironment> 363 + </Midl> 364 + <ClCompile> 365 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 366 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 367 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 368 + <StringPooling>true</StringPooling> 369 + <ExceptionHandling> 370 + </ExceptionHandling> 371 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 372 + <BufferSecurityCheck>false</BufferSecurityCheck> 373 + <FunctionLevelLinking>true</FunctionLevelLinking> 374 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 375 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 376 + <ObjectFileName>$(IntDir)</ObjectFileName> 377 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 378 + <WarningLevel>Level3</WarningLevel> 379 + <SuppressStartupBanner>true</SuppressStartupBanner> 380 + </ClCompile> 381 + <ResourceCompile> 382 + <Culture>0x040c</Culture> 383 + </ResourceCompile> 384 + <Lib> 385 + <AdditionalOptions>/MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 386 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 387 + <SuppressStartupBanner>true</SuppressStartupBanner> 388 + </Lib> 389 + </ItemDefinitionGroup> 390 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'"> 391 + <Midl> 392 + <TargetEnvironment>Itanium</TargetEnvironment> 393 + </Midl> 394 + <ClCompile> 395 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 396 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 397 + <PreprocessorDefinitions>ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 398 + <StringPooling>true</StringPooling> 399 + <ExceptionHandling> 400 + </ExceptionHandling> 401 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 402 + <BufferSecurityCheck>false</BufferSecurityCheck> 403 + <FunctionLevelLinking>true</FunctionLevelLinking> 404 + <PrecompiledHeaderOutputFile>$(IntDir)zlibstat.pch</PrecompiledHeaderOutputFile> 405 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 406 + <ObjectFileName>$(IntDir)</ObjectFileName> 407 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 408 + <WarningLevel>Level3</WarningLevel> 409 + <SuppressStartupBanner>true</SuppressStartupBanner> 410 + </ClCompile> 411 + <ResourceCompile> 412 + <Culture>0x040c</Culture> 413 + </ResourceCompile> 414 + <Lib> 415 + <AdditionalOptions>/MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions)</AdditionalOptions> 416 + <OutputFile>$(OutDir)zlibstat.lib</OutputFile> 417 + <SuppressStartupBanner>true</SuppressStartupBanner> 418 + </Lib> 419 + </ItemDefinitionGroup> 420 + <ItemGroup> 421 + <ClCompile Include="..\..\..\adler32.c" /> 422 + <ClCompile Include="..\..\..\compress.c" /> 423 + <ClCompile Include="..\..\..\crc32.c" /> 424 + <ClCompile Include="..\..\..\deflate.c" /> 425 + <ClCompile Include="..\..\..\gzclose.c" /> 426 + <ClCompile Include="..\..\..\gzlib.c" /> 427 + <ClCompile Include="..\..\..\gzread.c" /> 428 + <ClCompile Include="..\..\..\gzwrite.c" /> 429 + <ClCompile Include="..\..\..\infback.c" /> 430 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 431 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</ExcludedFromBuild> 432 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> 433 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">true</ExcludedFromBuild> 434 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">true</ExcludedFromBuild> 435 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">true</ExcludedFromBuild> 436 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> 437 + </ClCompile> 438 + <ClCompile Include="..\..\..\inffast.c" /> 439 + <ClCompile Include="..\..\..\inflate.c" /> 440 + <ClCompile Include="..\..\..\inftrees.c" /> 441 + <ClCompile Include="..\..\minizip\ioapi.c" /> 442 + <ClCompile Include="..\..\..\trees.c" /> 443 + <ClCompile Include="..\..\..\uncompr.c" /> 444 + <ClCompile Include="..\..\minizip\unzip.c" /> 445 + <ClCompile Include="..\..\minizip\zip.c" /> 446 + <ClCompile Include="..\..\..\zutil.c" /> 447 + </ItemGroup> 448 + <ItemGroup> 449 + <ResourceCompile Include="zlib.rc" /> 450 + </ItemGroup> 451 + <ItemGroup> 452 + <None Include="zlibvc.def" /> 453 + </ItemGroup> 454 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 455 + <ImportGroup Label="ExtensionTargets"> 456 + </ImportGroup> 457 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{174213f6-7f66-4ae8-a3a8-a1e0a1e6ffdd}</UniqueIdentifier> 6 + </Filter> 7 + </ItemGroup> 8 + <ItemGroup> 9 + <ClCompile Include="..\..\..\adler32.c"> 10 + <Filter>Source Files</Filter> 11 + </ClCompile> 12 + <ClCompile Include="..\..\..\compress.c"> 13 + <Filter>Source Files</Filter> 14 + </ClCompile> 15 + <ClCompile Include="..\..\..\crc32.c"> 16 + <Filter>Source Files</Filter> 17 + </ClCompile> 18 + <ClCompile Include="..\..\..\deflate.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + <ClCompile Include="..\..\..\gzclose.c"> 22 + <Filter>Source Files</Filter> 23 + </ClCompile> 24 + <ClCompile Include="..\..\..\gzlib.c"> 25 + <Filter>Source Files</Filter> 26 + </ClCompile> 27 + <ClCompile Include="..\..\..\gzread.c"> 28 + <Filter>Source Files</Filter> 29 + </ClCompile> 30 + <ClCompile Include="..\..\..\gzwrite.c"> 31 + <Filter>Source Files</Filter> 32 + </ClCompile> 33 + <ClCompile Include="..\..\..\infback.c"> 34 + <Filter>Source Files</Filter> 35 + </ClCompile> 36 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 37 + <Filter>Source Files</Filter> 38 + </ClCompile> 39 + <ClCompile Include="..\..\..\inffast.c"> 40 + <Filter>Source Files</Filter> 41 + </ClCompile> 42 + <ClCompile Include="..\..\..\inflate.c"> 43 + <Filter>Source Files</Filter> 44 + </ClCompile> 45 + <ClCompile Include="..\..\..\inftrees.c"> 46 + <Filter>Source Files</Filter> 47 + </ClCompile> 48 + <ClCompile Include="..\..\minizip\ioapi.c"> 49 + <Filter>Source Files</Filter> 50 + </ClCompile> 51 + <ClCompile Include="..\..\..\trees.c"> 52 + <Filter>Source Files</Filter> 53 + </ClCompile> 54 + <ClCompile Include="..\..\..\uncompr.c"> 55 + <Filter>Source Files</Filter> 56 + </ClCompile> 57 + <ClCompile Include="..\..\minizip\unzip.c"> 58 + <Filter>Source Files</Filter> 59 + </ClCompile> 60 + <ClCompile Include="..\..\minizip\zip.c"> 61 + <Filter>Source Files</Filter> 62 + </ClCompile> 63 + <ClCompile Include="..\..\..\zutil.c"> 64 + <Filter>Source Files</Filter> 65 + </ClCompile> 66 + </ItemGroup> 67 + <ItemGroup> 68 + <ResourceCompile Include="zlib.rc"> 69 + <Filter>Source Files</Filter> 70 + </ResourceCompile> 71 + </ItemGroup> 72 + <ItemGroup> 73 + <None Include="zlibvc.def"> 74 + <Filter>Source Files</Filter> 75 + </None> 76 + </ItemGroup> 77 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlibvc.def.
1 +LIBRARY 2 +; zlib data compression and ZIP file I/O library 3 + 4 +VERSION 1.2.7 5 + 6 +EXPORTS 7 + adler32 @1 8 + compress @2 9 + crc32 @3 10 + deflate @4 11 + deflateCopy @5 12 + deflateEnd @6 13 + deflateInit2_ @7 14 + deflateInit_ @8 15 + deflateParams @9 16 + deflateReset @10 17 + deflateSetDictionary @11 18 + gzclose @12 19 + gzdopen @13 20 + gzerror @14 21 + gzflush @15 22 + gzopen @16 23 + gzread @17 24 + gzwrite @18 25 + inflate @19 26 + inflateEnd @20 27 + inflateInit2_ @21 28 + inflateInit_ @22 29 + inflateReset @23 30 + inflateSetDictionary @24 31 + inflateSync @25 32 + uncompress @26 33 + zlibVersion @27 34 + gzprintf @28 35 + gzputc @29 36 + gzgetc @30 37 + gzseek @31 38 + gzrewind @32 39 + gztell @33 40 + gzeof @34 41 + gzsetparams @35 42 + zError @36 43 + inflateSyncPoint @37 44 + get_crc_table @38 45 + compress2 @39 46 + gzputs @40 47 + gzgets @41 48 + inflateCopy @42 49 + inflateBackInit_ @43 50 + inflateBack @44 51 + inflateBackEnd @45 52 + compressBound @46 53 + deflateBound @47 54 + gzclearerr @48 55 + gzungetc @49 56 + zlibCompileFlags @50 57 + deflatePrime @51 58 + deflatePending @52 59 + 60 + unzOpen @61 61 + unzClose @62 62 + unzGetGlobalInfo @63 63 + unzGetCurrentFileInfo @64 64 + unzGoToFirstFile @65 65 + unzGoToNextFile @66 66 + unzOpenCurrentFile @67 67 + unzReadCurrentFile @68 68 + unzOpenCurrentFile3 @69 69 + unztell @70 70 + unzeof @71 71 + unzCloseCurrentFile @72 72 + unzGetGlobalComment @73 73 + unzStringFileNameCompare @74 74 + unzLocateFile @75 75 + unzGetLocalExtrafield @76 76 + unzOpen2 @77 77 + unzOpenCurrentFile2 @78 78 + unzOpenCurrentFilePassword @79 79 + 80 + zipOpen @80 81 + zipOpenNewFileInZip @81 82 + zipWriteInFileInZip @82 83 + zipCloseFileInZip @83 84 + zipClose @84 85 + zipOpenNewFileInZip2 @86 86 + zipCloseFileInZipRaw @87 87 + zipOpen2 @88 88 + zipOpenNewFileInZip3 @89 89 + 90 + unzGetFilePos @100 91 + unzGoToFilePos @101 92 + 93 + fill_win32_filefunc @110 94 + 95 +; zlibwapi v1.2.4 added: 96 + fill_win32_filefunc64 @111 97 + fill_win32_filefunc64A @112 98 + fill_win32_filefunc64W @113 99 + 100 + unzOpen64 @120 101 + unzOpen2_64 @121 102 + unzGetGlobalInfo64 @122 103 + unzGetCurrentFileInfo64 @124 104 + unzGetCurrentFileZStreamPos64 @125 105 + unztell64 @126 106 + unzGetFilePos64 @127 107 + unzGoToFilePos64 @128 108 + 109 + zipOpen64 @130 110 + zipOpen2_64 @131 111 + zipOpenNewFileInZip64 @132 112 + zipOpenNewFileInZip2_64 @133 113 + zipOpenNewFileInZip3_64 @134 114 + zipOpenNewFileInZip4_64 @135 115 + zipCloseFileInZipRaw64 @136 116 + 117 +; zlib1 v1.2.4 added: 118 + adler32_combine @140 119 + crc32_combine @142 120 + deflateSetHeader @144 121 + deflateTune @145 122 + gzbuffer @146 123 + gzclose_r @147 124 + gzclose_w @148 125 + gzdirect @149 126 + gzoffset @150 127 + inflateGetHeader @156 128 + inflateMark @157 129 + inflatePrime @158 130 + inflateReset2 @159 131 + inflateUndermine @160 132 + 133 +; zlib1 v1.2.6 added: 134 + gzgetc_ @161 135 + inflateResetKeep @163 136 + deflateResetKeep @164 137 + 138 +; zlib1 v1.2.7 added: 139 + gzopen_w @165
Added compat/zlib/contrib/vstudio/vc10/zlibvc.sln.
1 + 2 +Microsoft Visual Studio Solution File, Format Version 11.00 3 +# Visual Studio 2010 4 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcxproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" 5 +EndProject 6 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" 7 +EndProject 8 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcxproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" 9 +EndProject 10 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlibdll", "testzlibdll.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" 11 +EndProject 12 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcxproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" 13 +EndProject 14 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" 15 +EndProject 16 +Global 17 + GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 + Debug|Itanium = Debug|Itanium 19 + Debug|Win32 = Debug|Win32 20 + Debug|x64 = Debug|x64 21 + Release|Itanium = Release|Itanium 22 + Release|Win32 = Release|Win32 23 + Release|x64 = Release|x64 24 + ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium 25 + ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 26 + ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 27 + EndGlobalSection 28 + GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium 30 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium 31 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 33 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 34 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 35 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium 36 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium 37 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 38 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 39 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 40 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 41 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 42 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 43 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 44 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 45 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 46 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 47 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium 48 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium 49 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 50 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 51 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 52 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 53 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium 54 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium 55 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 56 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 57 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 58 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 59 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 60 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 61 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 62 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 63 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 65 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium 66 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium 67 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 68 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 69 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 70 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 71 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium 72 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium 73 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 74 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 75 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 76 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 77 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 78 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 79 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 80 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 81 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 82 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 83 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium 84 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium 85 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 86 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 87 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 88 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 89 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium 90 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium 91 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 92 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 93 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 94 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 95 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 96 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 97 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 98 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 99 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium 100 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium 101 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 102 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 103 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 104 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 105 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium 106 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium 107 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 108 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 109 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 110 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 111 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 112 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 113 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 114 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 115 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium 116 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium 117 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 118 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 119 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 120 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 121 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium 122 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium 123 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 124 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 125 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 126 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 127 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 128 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 129 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 130 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 131 + EndGlobalSection 132 + GlobalSection(SolutionProperties) = preSolution 133 + HideSolutionNode = FALSE 134 + EndGlobalSection 135 +EndGlobal
Added compat/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup Label="ProjectConfigurations"> 4 + <ProjectConfiguration Include="Debug|Itanium"> 5 + <Configuration>Debug</Configuration> 6 + <Platform>Itanium</Platform> 7 + </ProjectConfiguration> 8 + <ProjectConfiguration Include="Debug|Win32"> 9 + <Configuration>Debug</Configuration> 10 + <Platform>Win32</Platform> 11 + </ProjectConfiguration> 12 + <ProjectConfiguration Include="Debug|x64"> 13 + <Configuration>Debug</Configuration> 14 + <Platform>x64</Platform> 15 + </ProjectConfiguration> 16 + <ProjectConfiguration Include="ReleaseWithoutAsm|Itanium"> 17 + <Configuration>ReleaseWithoutAsm</Configuration> 18 + <Platform>Itanium</Platform> 19 + </ProjectConfiguration> 20 + <ProjectConfiguration Include="ReleaseWithoutAsm|Win32"> 21 + <Configuration>ReleaseWithoutAsm</Configuration> 22 + <Platform>Win32</Platform> 23 + </ProjectConfiguration> 24 + <ProjectConfiguration Include="ReleaseWithoutAsm|x64"> 25 + <Configuration>ReleaseWithoutAsm</Configuration> 26 + <Platform>x64</Platform> 27 + </ProjectConfiguration> 28 + <ProjectConfiguration Include="Release|Itanium"> 29 + <Configuration>Release</Configuration> 30 + <Platform>Itanium</Platform> 31 + </ProjectConfiguration> 32 + <ProjectConfiguration Include="Release|Win32"> 33 + <Configuration>Release</Configuration> 34 + <Platform>Win32</Platform> 35 + </ProjectConfiguration> 36 + <ProjectConfiguration Include="Release|x64"> 37 + <Configuration>Release</Configuration> 38 + <Platform>x64</Platform> 39 + </ProjectConfiguration> 40 + </ItemGroup> 41 + <PropertyGroup Label="Globals"> 42 + <ProjectGuid>{8FD826F8-3739-44E6-8CC8-997122E53B8D}</ProjectGuid> 43 + </PropertyGroup> 44 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 45 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 46 + <ConfigurationType>DynamicLibrary</ConfigurationType> 47 + <UseOfMfc>false</UseOfMfc> 48 + <WholeProgramOptimization>true</WholeProgramOptimization> 49 + </PropertyGroup> 50 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="Configuration"> 51 + <ConfigurationType>DynamicLibrary</ConfigurationType> 52 + <UseOfMfc>false</UseOfMfc> 53 + <WholeProgramOptimization>true</WholeProgramOptimization> 54 + </PropertyGroup> 55 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 56 + <ConfigurationType>DynamicLibrary</ConfigurationType> 57 + <UseOfMfc>false</UseOfMfc> 58 + </PropertyGroup> 59 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="Configuration"> 60 + <ConfigurationType>DynamicLibrary</ConfigurationType> 61 + <UseOfMfc>false</UseOfMfc> 62 + <WholeProgramOptimization>true</WholeProgramOptimization> 63 + </PropertyGroup> 64 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="Configuration"> 65 + <ConfigurationType>DynamicLibrary</ConfigurationType> 66 + <UseOfMfc>false</UseOfMfc> 67 + <WholeProgramOptimization>true</WholeProgramOptimization> 68 + </PropertyGroup> 69 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="Configuration"> 70 + <ConfigurationType>DynamicLibrary</ConfigurationType> 71 + <UseOfMfc>false</UseOfMfc> 72 + </PropertyGroup> 73 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 74 + <ConfigurationType>DynamicLibrary</ConfigurationType> 75 + <UseOfMfc>false</UseOfMfc> 76 + <WholeProgramOptimization>true</WholeProgramOptimization> 77 + </PropertyGroup> 78 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="Configuration"> 79 + <ConfigurationType>DynamicLibrary</ConfigurationType> 80 + <UseOfMfc>false</UseOfMfc> 81 + <WholeProgramOptimization>true</WholeProgramOptimization> 82 + </PropertyGroup> 83 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 84 + <ConfigurationType>DynamicLibrary</ConfigurationType> 85 + <UseOfMfc>false</UseOfMfc> 86 + </PropertyGroup> 87 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 88 + <ImportGroup Label="ExtensionSettings"> 89 + </ImportGroup> 90 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 91 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 92 + </ImportGroup> 93 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" Label="PropertySheets"> 94 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 95 + </ImportGroup> 96 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 97 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 98 + </ImportGroup> 99 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" Label="PropertySheets"> 100 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 101 + </ImportGroup> 102 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" Label="PropertySheets"> 103 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 104 + </ImportGroup> 105 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" Label="PropertySheets"> 106 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 107 + </ImportGroup> 108 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 109 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 110 + </ImportGroup> 111 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" Label="PropertySheets"> 112 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 113 + </ImportGroup> 114 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 115 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 116 + </ImportGroup> 117 + <PropertyGroup Label="UserMacros" /> 118 + <PropertyGroup> 119 + <_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion> 120 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\ZlibDll$(Configuration)\</OutDir> 121 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">x86\ZlibDll$(Configuration)\Tmp\</IntDir> 122 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> 123 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</GenerateManifest> 124 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\ZlibDll$(Configuration)\</OutDir> 125 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">x86\ZlibDll$(Configuration)\Tmp\</IntDir> 126 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">false</LinkIncremental> 127 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">false</GenerateManifest> 128 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\ZlibDll$(Configuration)\</OutDir> 129 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">x86\ZlibDll$(Configuration)\Tmp\</IntDir> 130 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> 131 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</GenerateManifest> 132 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\ZlibDll$(Configuration)\</OutDir> 133 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">x64\ZlibDll$(Configuration)\Tmp\</IntDir> 134 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental> 135 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</GenerateManifest> 136 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\ZlibDll$(Configuration)\</OutDir> 137 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">ia64\ZlibDll$(Configuration)\Tmp\</IntDir> 138 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</LinkIncremental> 139 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">false</GenerateManifest> 140 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\ZlibDll$(Configuration)\</OutDir> 141 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">x64\ZlibDll$(Configuration)\Tmp\</IntDir> 142 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">false</LinkIncremental> 143 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">false</GenerateManifest> 144 + <OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\ZlibDll$(Configuration)\</OutDir> 145 + <IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">ia64\ZlibDll$(Configuration)\Tmp\</IntDir> 146 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">false</LinkIncremental> 147 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">false</GenerateManifest> 148 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\ZlibDll$(Configuration)\</OutDir> 149 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">x64\ZlibDll$(Configuration)\Tmp\</IntDir> 150 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> 151 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</GenerateManifest> 152 + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\ZlibDll$(Configuration)\</OutDir> 153 + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ia64\ZlibDll$(Configuration)\Tmp\</IntDir> 154 + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</LinkIncremental> 155 + <GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">false</GenerateManifest> 156 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 157 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 158 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'" /> 159 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 160 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 161 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> 162 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 163 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 164 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" /> 165 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 166 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 167 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'" /> 168 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 169 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 170 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'" /> 171 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 172 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 173 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'" /> 174 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">AllRules.ruleset</CodeAnalysisRuleSet> 175 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 176 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'" /> 177 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> 178 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 179 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" /> 180 + <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> 181 + <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 182 + <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> 183 + <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">zlibwapi</TargetName> 184 + <TargetName Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">zlibwapi</TargetName> 185 + <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">zlibwapi</TargetName> 186 + <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">zlibwapi</TargetName> 187 + <TargetName Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'">zlibwapi</TargetName> 188 + <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">zlibwapi</TargetName> 189 + </PropertyGroup> 190 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 191 + <Midl> 192 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 193 + <MkTypLibCompatible>true</MkTypLibCompatible> 194 + <SuppressStartupBanner>true</SuppressStartupBanner> 195 + <TargetEnvironment>Win32</TargetEnvironment> 196 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 197 + </Midl> 198 + <ClCompile> 199 + <Optimization>Disabled</Optimization> 200 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 201 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions)</PreprocessorDefinitions> 202 + <ExceptionHandling> 203 + </ExceptionHandling> 204 + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> 205 + <BufferSecurityCheck>false</BufferSecurityCheck> 206 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 207 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 208 + <ObjectFileName>$(IntDir)</ObjectFileName> 209 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 210 + <BrowseInformation> 211 + </BrowseInformation> 212 + <WarningLevel>Level3</WarningLevel> 213 + <SuppressStartupBanner>true</SuppressStartupBanner> 214 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 215 + </ClCompile> 216 + <ResourceCompile> 217 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 218 + <Culture>0x040c</Culture> 219 + </ResourceCompile> 220 + <Link> 221 + <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions> 222 + <AdditionalDependencies>..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies)</AdditionalDependencies> 223 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 224 + <SuppressStartupBanner>true</SuppressStartupBanner> 225 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 226 + <GenerateDebugInformation>true</GenerateDebugInformation> 227 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 228 + <GenerateMapFile>true</GenerateMapFile> 229 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 230 + <SubSystem>Windows</SubSystem> 231 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 232 + <DataExecutionPrevention> 233 + </DataExecutionPrevention> 234 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 235 + </Link> 236 + <PreBuildEvent> 237 + <Command>cd ..\..\masmx86 238 +bld_ml32.bat</Command> 239 + </PreBuildEvent> 240 + </ItemDefinitionGroup> 241 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'"> 242 + <Midl> 243 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 244 + <MkTypLibCompatible>true</MkTypLibCompatible> 245 + <SuppressStartupBanner>true</SuppressStartupBanner> 246 + <TargetEnvironment>Win32</TargetEnvironment> 247 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 248 + </Midl> 249 + <ClCompile> 250 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 251 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 252 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions)</PreprocessorDefinitions> 253 + <StringPooling>true</StringPooling> 254 + <ExceptionHandling> 255 + </ExceptionHandling> 256 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 257 + <BufferSecurityCheck>false</BufferSecurityCheck> 258 + <FunctionLevelLinking>true</FunctionLevelLinking> 259 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 260 + <AssemblerOutput>All</AssemblerOutput> 261 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 262 + <ObjectFileName>$(IntDir)</ObjectFileName> 263 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 264 + <BrowseInformation> 265 + </BrowseInformation> 266 + <WarningLevel>Level3</WarningLevel> 267 + <SuppressStartupBanner>true</SuppressStartupBanner> 268 + </ClCompile> 269 + <ResourceCompile> 270 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 271 + <Culture>0x040c</Culture> 272 + </ResourceCompile> 273 + <Link> 274 + <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions> 275 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 276 + <SuppressStartupBanner>true</SuppressStartupBanner> 277 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 278 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 279 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 280 + <GenerateMapFile>true</GenerateMapFile> 281 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 282 + <SubSystem>Windows</SubSystem> 283 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 284 + <DataExecutionPrevention> 285 + </DataExecutionPrevention> 286 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 287 + </Link> 288 + </ItemDefinitionGroup> 289 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 290 + <Midl> 291 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 292 + <MkTypLibCompatible>true</MkTypLibCompatible> 293 + <SuppressStartupBanner>true</SuppressStartupBanner> 294 + <TargetEnvironment>Win32</TargetEnvironment> 295 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 296 + </Midl> 297 + <ClCompile> 298 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 299 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 300 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions)</PreprocessorDefinitions> 301 + <StringPooling>true</StringPooling> 302 + <ExceptionHandling> 303 + </ExceptionHandling> 304 + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> 305 + <BufferSecurityCheck>false</BufferSecurityCheck> 306 + <FunctionLevelLinking>true</FunctionLevelLinking> 307 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 308 + <AssemblerOutput>All</AssemblerOutput> 309 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 310 + <ObjectFileName>$(IntDir)</ObjectFileName> 311 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 312 + <BrowseInformation> 313 + </BrowseInformation> 314 + <WarningLevel>Level3</WarningLevel> 315 + <SuppressStartupBanner>true</SuppressStartupBanner> 316 + </ClCompile> 317 + <ResourceCompile> 318 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 319 + <Culture>0x040c</Culture> 320 + </ResourceCompile> 321 + <Link> 322 + <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions> 323 + <AdditionalDependencies>..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies)</AdditionalDependencies> 324 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 325 + <SuppressStartupBanner>true</SuppressStartupBanner> 326 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 327 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 328 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 329 + <GenerateMapFile>true</GenerateMapFile> 330 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 331 + <SubSystem>Windows</SubSystem> 332 + <RandomizedBaseAddress>false</RandomizedBaseAddress> 333 + <DataExecutionPrevention> 334 + </DataExecutionPrevention> 335 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 336 + </Link> 337 + <PreBuildEvent> 338 + <Command>cd ..\..\masmx86 339 +bld_ml32.bat</Command> 340 + </PreBuildEvent> 341 + </ItemDefinitionGroup> 342 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 343 + <Midl> 344 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 345 + <MkTypLibCompatible>true</MkTypLibCompatible> 346 + <SuppressStartupBanner>true</SuppressStartupBanner> 347 + <TargetEnvironment>X64</TargetEnvironment> 348 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 349 + </Midl> 350 + <ClCompile> 351 + <Optimization>Disabled</Optimization> 352 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 353 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 354 + <ExceptionHandling> 355 + </ExceptionHandling> 356 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 357 + <BufferSecurityCheck>false</BufferSecurityCheck> 358 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 359 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 360 + <ObjectFileName>$(IntDir)</ObjectFileName> 361 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 362 + <BrowseInformation> 363 + </BrowseInformation> 364 + <WarningLevel>Level3</WarningLevel> 365 + <SuppressStartupBanner>true</SuppressStartupBanner> 366 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 367 + </ClCompile> 368 + <ResourceCompile> 369 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 370 + <Culture>0x040c</Culture> 371 + </ResourceCompile> 372 + <Link> 373 + <AdditionalDependencies>..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies)</AdditionalDependencies> 374 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 375 + <SuppressStartupBanner>true</SuppressStartupBanner> 376 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 377 + <GenerateDebugInformation>true</GenerateDebugInformation> 378 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 379 + <GenerateMapFile>true</GenerateMapFile> 380 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 381 + <SubSystem>Windows</SubSystem> 382 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 383 + <TargetMachine>MachineX64</TargetMachine> 384 + </Link> 385 + <PreBuildEvent> 386 + <Command>cd ..\..\contrib\masmx64 387 +bld_ml64.bat</Command> 388 + </PreBuildEvent> 389 + </ItemDefinitionGroup> 390 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'"> 391 + <Midl> 392 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 393 + <MkTypLibCompatible>true</MkTypLibCompatible> 394 + <SuppressStartupBanner>true</SuppressStartupBanner> 395 + <TargetEnvironment>Itanium</TargetEnvironment> 396 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 397 + </Midl> 398 + <ClCompile> 399 + <Optimization>Disabled</Optimization> 400 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 401 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 402 + <ExceptionHandling> 403 + </ExceptionHandling> 404 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 405 + <BufferSecurityCheck>false</BufferSecurityCheck> 406 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 407 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 408 + <ObjectFileName>$(IntDir)</ObjectFileName> 409 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 410 + <BrowseInformation> 411 + </BrowseInformation> 412 + <WarningLevel>Level3</WarningLevel> 413 + <SuppressStartupBanner>true</SuppressStartupBanner> 414 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 415 + </ClCompile> 416 + <ResourceCompile> 417 + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 418 + <Culture>0x040c</Culture> 419 + </ResourceCompile> 420 + <Link> 421 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 422 + <SuppressStartupBanner>true</SuppressStartupBanner> 423 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 424 + <GenerateDebugInformation>true</GenerateDebugInformation> 425 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 426 + <GenerateMapFile>true</GenerateMapFile> 427 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 428 + <SubSystem>Windows</SubSystem> 429 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 430 + <TargetMachine>MachineIA64</TargetMachine> 431 + </Link> 432 + </ItemDefinitionGroup> 433 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|x64'"> 434 + <Midl> 435 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 436 + <MkTypLibCompatible>true</MkTypLibCompatible> 437 + <SuppressStartupBanner>true</SuppressStartupBanner> 438 + <TargetEnvironment>X64</TargetEnvironment> 439 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 440 + </Midl> 441 + <ClCompile> 442 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 443 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 444 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 445 + <StringPooling>true</StringPooling> 446 + <ExceptionHandling> 447 + </ExceptionHandling> 448 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 449 + <BufferSecurityCheck>false</BufferSecurityCheck> 450 + <FunctionLevelLinking>true</FunctionLevelLinking> 451 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 452 + <AssemblerOutput>All</AssemblerOutput> 453 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 454 + <ObjectFileName>$(IntDir)</ObjectFileName> 455 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 456 + <BrowseInformation> 457 + </BrowseInformation> 458 + <WarningLevel>Level3</WarningLevel> 459 + <SuppressStartupBanner>true</SuppressStartupBanner> 460 + </ClCompile> 461 + <ResourceCompile> 462 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 463 + <Culture>0x040c</Culture> 464 + </ResourceCompile> 465 + <Link> 466 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 467 + <SuppressStartupBanner>true</SuppressStartupBanner> 468 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 469 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 470 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 471 + <GenerateMapFile>true</GenerateMapFile> 472 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 473 + <SubSystem>Windows</SubSystem> 474 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 475 + <TargetMachine>MachineX64</TargetMachine> 476 + </Link> 477 + </ItemDefinitionGroup> 478 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'"> 479 + <Midl> 480 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 481 + <MkTypLibCompatible>true</MkTypLibCompatible> 482 + <SuppressStartupBanner>true</SuppressStartupBanner> 483 + <TargetEnvironment>Itanium</TargetEnvironment> 484 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 485 + </Midl> 486 + <ClCompile> 487 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 488 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 489 + <PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 490 + <StringPooling>true</StringPooling> 491 + <ExceptionHandling> 492 + </ExceptionHandling> 493 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 494 + <BufferSecurityCheck>false</BufferSecurityCheck> 495 + <FunctionLevelLinking>true</FunctionLevelLinking> 496 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 497 + <AssemblerOutput>All</AssemblerOutput> 498 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 499 + <ObjectFileName>$(IntDir)</ObjectFileName> 500 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 501 + <BrowseInformation> 502 + </BrowseInformation> 503 + <WarningLevel>Level3</WarningLevel> 504 + <SuppressStartupBanner>true</SuppressStartupBanner> 505 + </ClCompile> 506 + <ResourceCompile> 507 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 508 + <Culture>0x040c</Culture> 509 + </ResourceCompile> 510 + <Link> 511 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 512 + <SuppressStartupBanner>true</SuppressStartupBanner> 513 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 514 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 515 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 516 + <GenerateMapFile>true</GenerateMapFile> 517 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 518 + <SubSystem>Windows</SubSystem> 519 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 520 + <TargetMachine>MachineIA64</TargetMachine> 521 + </Link> 522 + </ItemDefinitionGroup> 523 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 524 + <Midl> 525 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 526 + <MkTypLibCompatible>true</MkTypLibCompatible> 527 + <SuppressStartupBanner>true</SuppressStartupBanner> 528 + <TargetEnvironment>X64</TargetEnvironment> 529 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 530 + </Midl> 531 + <ClCompile> 532 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 533 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 534 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 535 + <StringPooling>true</StringPooling> 536 + <ExceptionHandling> 537 + </ExceptionHandling> 538 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 539 + <BufferSecurityCheck>false</BufferSecurityCheck> 540 + <FunctionLevelLinking>true</FunctionLevelLinking> 541 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 542 + <AssemblerOutput>All</AssemblerOutput> 543 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 544 + <ObjectFileName>$(IntDir)</ObjectFileName> 545 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 546 + <BrowseInformation> 547 + </BrowseInformation> 548 + <WarningLevel>Level3</WarningLevel> 549 + <SuppressStartupBanner>true</SuppressStartupBanner> 550 + </ClCompile> 551 + <ResourceCompile> 552 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 553 + <Culture>0x040c</Culture> 554 + </ResourceCompile> 555 + <Link> 556 + <AdditionalDependencies>..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies)</AdditionalDependencies> 557 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 558 + <SuppressStartupBanner>true</SuppressStartupBanner> 559 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 560 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 561 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 562 + <GenerateMapFile>true</GenerateMapFile> 563 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 564 + <SubSystem>Windows</SubSystem> 565 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 566 + <TargetMachine>MachineX64</TargetMachine> 567 + </Link> 568 + <PreBuildEvent> 569 + <Command>cd ..\..\masmx64 570 +bld_ml64.bat</Command> 571 + </PreBuildEvent> 572 + </ItemDefinitionGroup> 573 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'"> 574 + <Midl> 575 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 576 + <MkTypLibCompatible>true</MkTypLibCompatible> 577 + <SuppressStartupBanner>true</SuppressStartupBanner> 578 + <TargetEnvironment>Itanium</TargetEnvironment> 579 + <TypeLibraryName>$(OutDir)zlibvc.tlb</TypeLibraryName> 580 + </Midl> 581 + <ClCompile> 582 + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> 583 + <AdditionalIncludeDirectories>..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 584 + <PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions> 585 + <StringPooling>true</StringPooling> 586 + <ExceptionHandling> 587 + </ExceptionHandling> 588 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 589 + <BufferSecurityCheck>false</BufferSecurityCheck> 590 + <FunctionLevelLinking>true</FunctionLevelLinking> 591 + <PrecompiledHeaderOutputFile>$(IntDir)zlibvc.pch</PrecompiledHeaderOutputFile> 592 + <AssemblerOutput>All</AssemblerOutput> 593 + <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation> 594 + <ObjectFileName>$(IntDir)</ObjectFileName> 595 + <ProgramDataBaseFileName>$(OutDir)</ProgramDataBaseFileName> 596 + <BrowseInformation> 597 + </BrowseInformation> 598 + <WarningLevel>Level3</WarningLevel> 599 + <SuppressStartupBanner>true</SuppressStartupBanner> 600 + </ClCompile> 601 + <ResourceCompile> 602 + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> 603 + <Culture>0x040c</Culture> 604 + </ResourceCompile> 605 + <Link> 606 + <OutputFile>$(OutDir)zlibwapi.dll</OutputFile> 607 + <SuppressStartupBanner>true</SuppressStartupBanner> 608 + <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> 609 + <ModuleDefinitionFile>.\zlibvc.def</ModuleDefinitionFile> 610 + <ProgramDatabaseFile>$(OutDir)zlibwapi.pdb</ProgramDatabaseFile> 611 + <GenerateMapFile>true</GenerateMapFile> 612 + <MapFileName>$(OutDir)zlibwapi.map</MapFileName> 613 + <SubSystem>Windows</SubSystem> 614 + <ImportLibrary>$(OutDir)zlibwapi.lib</ImportLibrary> 615 + <TargetMachine>MachineIA64</TargetMachine> 616 + </Link> 617 + </ItemDefinitionGroup> 618 + <ItemGroup> 619 + <ClCompile Include="..\..\..\adler32.c" /> 620 + <ClCompile Include="..\..\..\compress.c" /> 621 + <ClCompile Include="..\..\..\crc32.c" /> 622 + <ClCompile Include="..\..\..\deflate.c" /> 623 + <ClCompile Include="..\..\..\gzclose.c" /> 624 + <ClCompile Include="..\..\..\gzlib.c" /> 625 + <ClCompile Include="..\..\..\gzread.c" /> 626 + <ClCompile Include="..\..\..\gzwrite.c" /> 627 + <ClCompile Include="..\..\..\infback.c" /> 628 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 629 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Itanium'">true</ExcludedFromBuild> 630 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> 631 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Itanium'">true</ExcludedFromBuild> 632 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseWithoutAsm|Win32'">true</ExcludedFromBuild> 633 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">true</ExcludedFromBuild> 634 + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> 635 + </ClCompile> 636 + <ClCompile Include="..\..\..\inffast.c" /> 637 + <ClCompile Include="..\..\..\inflate.c" /> 638 + <ClCompile Include="..\..\..\inftrees.c" /> 639 + <ClCompile Include="..\..\minizip\ioapi.c" /> 640 + <ClCompile Include="..\..\minizip\iowin32.c" /> 641 + <ClCompile Include="..\..\..\trees.c" /> 642 + <ClCompile Include="..\..\..\uncompr.c" /> 643 + <ClCompile Include="..\..\minizip\unzip.c"> 644 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 645 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 646 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 647 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 648 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 649 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 650 + </ClCompile> 651 + <ClCompile Include="..\..\minizip\zip.c"> 652 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 653 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Itanium'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 654 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 655 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 656 + <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 657 + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ZLIB_INTERNAL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 658 + </ClCompile> 659 + <ClCompile Include="..\..\..\zutil.c" /> 660 + </ItemGroup> 661 + <ItemGroup> 662 + <ResourceCompile Include="zlib.rc" /> 663 + </ItemGroup> 664 + <ItemGroup> 665 + <None Include="zlibvc.def" /> 666 + </ItemGroup> 667 + <ItemGroup> 668 + <ClInclude Include="..\..\..\deflate.h" /> 669 + <ClInclude Include="..\..\..\infblock.h" /> 670 + <ClInclude Include="..\..\..\infcodes.h" /> 671 + <ClInclude Include="..\..\..\inffast.h" /> 672 + <ClInclude Include="..\..\..\inftrees.h" /> 673 + <ClInclude Include="..\..\..\infutil.h" /> 674 + <ClInclude Include="..\..\..\zconf.h" /> 675 + <ClInclude Include="..\..\..\zlib.h" /> 676 + <ClInclude Include="..\..\..\zutil.h" /> 677 + </ItemGroup> 678 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 679 + <ImportGroup Label="ExtensionTargets"> 680 + </ImportGroup> 681 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 + <ItemGroup> 4 + <Filter Include="Source Files"> 5 + <UniqueIdentifier>{07934a85-8b61-443d-a0ee-b2eedb74f3cd}</UniqueIdentifier> 6 + <Extensions>cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90</Extensions> 7 + </Filter> 8 + <Filter Include="Header Files"> 9 + <UniqueIdentifier>{1d99675b-433d-4a21-9e50-ed4ab8b19762}</UniqueIdentifier> 10 + <Extensions>h;hpp;hxx;hm;inl;fi;fd</Extensions> 11 + </Filter> 12 + <Filter Include="Resource Files"> 13 + <UniqueIdentifier>{431c0958-fa71-44d0-9084-2d19d100c0cc}</UniqueIdentifier> 14 + <Extensions>ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe</Extensions> 15 + </Filter> 16 + </ItemGroup> 17 + <ItemGroup> 18 + <ClCompile Include="..\..\..\adler32.c"> 19 + <Filter>Source Files</Filter> 20 + </ClCompile> 21 + <ClCompile Include="..\..\..\compress.c"> 22 + <Filter>Source Files</Filter> 23 + </ClCompile> 24 + <ClCompile Include="..\..\..\crc32.c"> 25 + <Filter>Source Files</Filter> 26 + </ClCompile> 27 + <ClCompile Include="..\..\..\deflate.c"> 28 + <Filter>Source Files</Filter> 29 + </ClCompile> 30 + <ClCompile Include="..\..\..\gzclose.c"> 31 + <Filter>Source Files</Filter> 32 + </ClCompile> 33 + <ClCompile Include="..\..\..\gzlib.c"> 34 + <Filter>Source Files</Filter> 35 + </ClCompile> 36 + <ClCompile Include="..\..\..\gzread.c"> 37 + <Filter>Source Files</Filter> 38 + </ClCompile> 39 + <ClCompile Include="..\..\..\gzwrite.c"> 40 + <Filter>Source Files</Filter> 41 + </ClCompile> 42 + <ClCompile Include="..\..\..\infback.c"> 43 + <Filter>Source Files</Filter> 44 + </ClCompile> 45 + <ClCompile Include="..\..\masmx64\inffas8664.c"> 46 + <Filter>Source Files</Filter> 47 + </ClCompile> 48 + <ClCompile Include="..\..\..\inffast.c"> 49 + <Filter>Source Files</Filter> 50 + </ClCompile> 51 + <ClCompile Include="..\..\..\inflate.c"> 52 + <Filter>Source Files</Filter> 53 + </ClCompile> 54 + <ClCompile Include="..\..\..\inftrees.c"> 55 + <Filter>Source Files</Filter> 56 + </ClCompile> 57 + <ClCompile Include="..\..\minizip\ioapi.c"> 58 + <Filter>Source Files</Filter> 59 + </ClCompile> 60 + <ClCompile Include="..\..\minizip\iowin32.c"> 61 + <Filter>Source Files</Filter> 62 + </ClCompile> 63 + <ClCompile Include="..\..\..\trees.c"> 64 + <Filter>Source Files</Filter> 65 + </ClCompile> 66 + <ClCompile Include="..\..\..\uncompr.c"> 67 + <Filter>Source Files</Filter> 68 + </ClCompile> 69 + <ClCompile Include="..\..\minizip\unzip.c"> 70 + <Filter>Source Files</Filter> 71 + </ClCompile> 72 + <ClCompile Include="..\..\minizip\zip.c"> 73 + <Filter>Source Files</Filter> 74 + </ClCompile> 75 + <ClCompile Include="..\..\..\zutil.c"> 76 + <Filter>Source Files</Filter> 77 + </ClCompile> 78 + </ItemGroup> 79 + <ItemGroup> 80 + <ResourceCompile Include="zlib.rc"> 81 + <Filter>Source Files</Filter> 82 + </ResourceCompile> 83 + </ItemGroup> 84 + <ItemGroup> 85 + <None Include="zlibvc.def"> 86 + <Filter>Source Files</Filter> 87 + </None> 88 + </ItemGroup> 89 + <ItemGroup> 90 + <ClInclude Include="..\..\..\deflate.h"> 91 + <Filter>Header Files</Filter> 92 + </ClInclude> 93 + <ClInclude Include="..\..\..\infblock.h"> 94 + <Filter>Header Files</Filter> 95 + </ClInclude> 96 + <ClInclude Include="..\..\..\infcodes.h"> 97 + <Filter>Header Files</Filter> 98 + </ClInclude> 99 + <ClInclude Include="..\..\..\inffast.h"> 100 + <Filter>Header Files</Filter> 101 + </ClInclude> 102 + <ClInclude Include="..\..\..\inftrees.h"> 103 + <Filter>Header Files</Filter> 104 + </ClInclude> 105 + <ClInclude Include="..\..\..\infutil.h"> 106 + <Filter>Header Files</Filter> 107 + </ClInclude> 108 + <ClInclude Include="..\..\..\zconf.h"> 109 + <Filter>Header Files</Filter> 110 + </ClInclude> 111 + <ClInclude Include="..\..\..\zlib.h"> 112 + <Filter>Header Files</Filter> 113 + </ClInclude> 114 + <ClInclude Include="..\..\..\zutil.h"> 115 + <Filter>Header Files</Filter> 116 + </ClInclude> 117 + </ItemGroup> 118 +</Project>
Added compat/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.user.
1 +<?xml version="1.0" encoding="utf-8"?> 2 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 +</Project>
Added compat/zlib/contrib/vstudio/vc9/miniunz.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9.00" 5 + Name="miniunz" 6 + ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694382A}" 7 + Keyword="Win32Proj" 8 + TargetFrameworkVersion="131072" 9 + > 10 + <Platforms> 11 + <Platform 12 + Name="Win32" 13 + /> 14 + <Platform 15 + Name="x64" 16 + /> 17 + <Platform 18 + Name="Itanium" 19 + /> 20 + </Platforms> 21 + <ToolFiles> 22 + </ToolFiles> 23 + <Configurations> 24 + <Configuration 25 + Name="Debug|Win32" 26 + OutputDirectory="x86\MiniUnzip$(ConfigurationName)" 27 + IntermediateDirectory="x86\MiniUnzip$(ConfigurationName)\Tmp" 28 + ConfigurationType="1" 29 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 30 + CharacterSet="2" 31 + > 32 + <Tool 33 + Name="VCPreBuildEventTool" 34 + /> 35 + <Tool 36 + Name="VCCustomBuildTool" 37 + /> 38 + <Tool 39 + Name="VCXMLDataGeneratorTool" 40 + /> 41 + <Tool 42 + Name="VCWebServiceProxyGeneratorTool" 43 + /> 44 + <Tool 45 + Name="VCMIDLTool" 46 + /> 47 + <Tool 48 + Name="VCCLCompilerTool" 49 + Optimization="0" 50 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 51 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE" 52 + MinimalRebuild="true" 53 + BasicRuntimeChecks="0" 54 + RuntimeLibrary="1" 55 + BufferSecurityCheck="false" 56 + UsePrecompiledHeader="0" 57 + AssemblerListingLocation="$(IntDir)\" 58 + WarningLevel="3" 59 + Detect64BitPortabilityProblems="true" 60 + DebugInformationFormat="4" 61 + /> 62 + <Tool 63 + Name="VCManagedResourceCompilerTool" 64 + /> 65 + <Tool 66 + Name="VCResourceCompilerTool" 67 + /> 68 + <Tool 69 + Name="VCPreLinkEventTool" 70 + /> 71 + <Tool 72 + Name="VCLinkerTool" 73 + AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib" 74 + OutputFile="$(OutDir)/miniunz.exe" 75 + LinkIncremental="2" 76 + GenerateManifest="false" 77 + GenerateDebugInformation="true" 78 + ProgramDatabaseFile="$(OutDir)/miniunz.pdb" 79 + SubSystem="1" 80 + RandomizedBaseAddress="1" 81 + DataExecutionPrevention="0" 82 + TargetMachine="1" 83 + /> 84 + <Tool 85 + Name="VCALinkTool" 86 + /> 87 + <Tool 88 + Name="VCManifestTool" 89 + /> 90 + <Tool 91 + Name="VCXDCMakeTool" 92 + /> 93 + <Tool 94 + Name="VCBscMakeTool" 95 + /> 96 + <Tool 97 + Name="VCFxCopTool" 98 + /> 99 + <Tool 100 + Name="VCAppVerifierTool" 101 + /> 102 + <Tool 103 + Name="VCPostBuildEventTool" 104 + /> 105 + </Configuration> 106 + <Configuration 107 + Name="Release|Win32" 108 + OutputDirectory="x86\MiniUnzip$(ConfigurationName)" 109 + IntermediateDirectory="x86\MiniUnzip$(ConfigurationName)\Tmp" 110 + ConfigurationType="1" 111 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 112 + CharacterSet="2" 113 + > 114 + <Tool 115 + Name="VCPreBuildEventTool" 116 + /> 117 + <Tool 118 + Name="VCCustomBuildTool" 119 + /> 120 + <Tool 121 + Name="VCXMLDataGeneratorTool" 122 + /> 123 + <Tool 124 + Name="VCWebServiceProxyGeneratorTool" 125 + /> 126 + <Tool 127 + Name="VCMIDLTool" 128 + /> 129 + <Tool 130 + Name="VCCLCompilerTool" 131 + Optimization="2" 132 + InlineFunctionExpansion="1" 133 + OmitFramePointers="true" 134 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 135 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE" 136 + StringPooling="true" 137 + BasicRuntimeChecks="0" 138 + RuntimeLibrary="0" 139 + BufferSecurityCheck="false" 140 + EnableFunctionLevelLinking="true" 141 + UsePrecompiledHeader="0" 142 + AssemblerListingLocation="$(IntDir)\" 143 + WarningLevel="3" 144 + Detect64BitPortabilityProblems="true" 145 + DebugInformationFormat="3" 146 + /> 147 + <Tool 148 + Name="VCManagedResourceCompilerTool" 149 + /> 150 + <Tool 151 + Name="VCResourceCompilerTool" 152 + /> 153 + <Tool 154 + Name="VCPreLinkEventTool" 155 + /> 156 + <Tool 157 + Name="VCLinkerTool" 158 + AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib" 159 + OutputFile="$(OutDir)/miniunz.exe" 160 + LinkIncremental="1" 161 + GenerateManifest="false" 162 + GenerateDebugInformation="true" 163 + SubSystem="1" 164 + OptimizeReferences="2" 165 + EnableCOMDATFolding="2" 166 + OptimizeForWindows98="1" 167 + RandomizedBaseAddress="1" 168 + DataExecutionPrevention="0" 169 + TargetMachine="1" 170 + /> 171 + <Tool 172 + Name="VCALinkTool" 173 + /> 174 + <Tool 175 + Name="VCManifestTool" 176 + /> 177 + <Tool 178 + Name="VCXDCMakeTool" 179 + /> 180 + <Tool 181 + Name="VCBscMakeTool" 182 + /> 183 + <Tool 184 + Name="VCFxCopTool" 185 + /> 186 + <Tool 187 + Name="VCAppVerifierTool" 188 + /> 189 + <Tool 190 + Name="VCPostBuildEventTool" 191 + /> 192 + </Configuration> 193 + <Configuration 194 + Name="Debug|x64" 195 + OutputDirectory="x64\MiniUnzip$(ConfigurationName)" 196 + IntermediateDirectory="x64\MiniUnzip$(ConfigurationName)\Tmp" 197 + ConfigurationType="1" 198 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 199 + CharacterSet="2" 200 + > 201 + <Tool 202 + Name="VCPreBuildEventTool" 203 + /> 204 + <Tool 205 + Name="VCCustomBuildTool" 206 + /> 207 + <Tool 208 + Name="VCXMLDataGeneratorTool" 209 + /> 210 + <Tool 211 + Name="VCWebServiceProxyGeneratorTool" 212 + /> 213 + <Tool 214 + Name="VCMIDLTool" 215 + TargetEnvironment="3" 216 + /> 217 + <Tool 218 + Name="VCCLCompilerTool" 219 + Optimization="0" 220 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 221 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 222 + MinimalRebuild="true" 223 + BasicRuntimeChecks="0" 224 + RuntimeLibrary="3" 225 + BufferSecurityCheck="false" 226 + UsePrecompiledHeader="0" 227 + AssemblerListingLocation="$(IntDir)\" 228 + WarningLevel="3" 229 + Detect64BitPortabilityProblems="true" 230 + DebugInformationFormat="3" 231 + /> 232 + <Tool 233 + Name="VCManagedResourceCompilerTool" 234 + /> 235 + <Tool 236 + Name="VCResourceCompilerTool" 237 + /> 238 + <Tool 239 + Name="VCPreLinkEventTool" 240 + /> 241 + <Tool 242 + Name="VCLinkerTool" 243 + AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib" 244 + OutputFile="$(OutDir)/miniunz.exe" 245 + LinkIncremental="2" 246 + GenerateManifest="false" 247 + GenerateDebugInformation="true" 248 + ProgramDatabaseFile="$(OutDir)/miniunz.pdb" 249 + SubSystem="1" 250 + TargetMachine="17" 251 + /> 252 + <Tool 253 + Name="VCALinkTool" 254 + /> 255 + <Tool 256 + Name="VCManifestTool" 257 + /> 258 + <Tool 259 + Name="VCXDCMakeTool" 260 + /> 261 + <Tool 262 + Name="VCBscMakeTool" 263 + /> 264 + <Tool 265 + Name="VCFxCopTool" 266 + /> 267 + <Tool 268 + Name="VCAppVerifierTool" 269 + /> 270 + <Tool 271 + Name="VCWebDeploymentTool" 272 + /> 273 + <Tool 274 + Name="VCPostBuildEventTool" 275 + /> 276 + </Configuration> 277 + <Configuration 278 + Name="Debug|Itanium" 279 + OutputDirectory="ia64\MiniUnzip$(ConfigurationName)" 280 + IntermediateDirectory="ia64\MiniUnzip$(ConfigurationName)\Tmp" 281 + ConfigurationType="1" 282 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 283 + CharacterSet="2" 284 + > 285 + <Tool 286 + Name="VCPreBuildEventTool" 287 + /> 288 + <Tool 289 + Name="VCCustomBuildTool" 290 + /> 291 + <Tool 292 + Name="VCXMLDataGeneratorTool" 293 + /> 294 + <Tool 295 + Name="VCWebServiceProxyGeneratorTool" 296 + /> 297 + <Tool 298 + Name="VCMIDLTool" 299 + TargetEnvironment="2" 300 + /> 301 + <Tool 302 + Name="VCCLCompilerTool" 303 + Optimization="0" 304 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 305 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 306 + MinimalRebuild="true" 307 + BasicRuntimeChecks="0" 308 + RuntimeLibrary="3" 309 + BufferSecurityCheck="false" 310 + UsePrecompiledHeader="0" 311 + AssemblerListingLocation="$(IntDir)\" 312 + WarningLevel="3" 313 + Detect64BitPortabilityProblems="true" 314 + DebugInformationFormat="3" 315 + /> 316 + <Tool 317 + Name="VCManagedResourceCompilerTool" 318 + /> 319 + <Tool 320 + Name="VCResourceCompilerTool" 321 + /> 322 + <Tool 323 + Name="VCPreLinkEventTool" 324 + /> 325 + <Tool 326 + Name="VCLinkerTool" 327 + AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib" 328 + OutputFile="$(OutDir)/miniunz.exe" 329 + LinkIncremental="2" 330 + GenerateManifest="false" 331 + GenerateDebugInformation="true" 332 + ProgramDatabaseFile="$(OutDir)/miniunz.pdb" 333 + SubSystem="1" 334 + TargetMachine="5" 335 + /> 336 + <Tool 337 + Name="VCALinkTool" 338 + /> 339 + <Tool 340 + Name="VCManifestTool" 341 + /> 342 + <Tool 343 + Name="VCXDCMakeTool" 344 + /> 345 + <Tool 346 + Name="VCBscMakeTool" 347 + /> 348 + <Tool 349 + Name="VCFxCopTool" 350 + /> 351 + <Tool 352 + Name="VCAppVerifierTool" 353 + /> 354 + <Tool 355 + Name="VCWebDeploymentTool" 356 + /> 357 + <Tool 358 + Name="VCPostBuildEventTool" 359 + /> 360 + </Configuration> 361 + <Configuration 362 + Name="Release|x64" 363 + OutputDirectory="x64\MiniUnzip$(ConfigurationName)" 364 + IntermediateDirectory="x64\MiniUnzip$(ConfigurationName)\Tmp" 365 + ConfigurationType="1" 366 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 367 + CharacterSet="2" 368 + > 369 + <Tool 370 + Name="VCPreBuildEventTool" 371 + /> 372 + <Tool 373 + Name="VCCustomBuildTool" 374 + /> 375 + <Tool 376 + Name="VCXMLDataGeneratorTool" 377 + /> 378 + <Tool 379 + Name="VCWebServiceProxyGeneratorTool" 380 + /> 381 + <Tool 382 + Name="VCMIDLTool" 383 + TargetEnvironment="3" 384 + /> 385 + <Tool 386 + Name="VCCLCompilerTool" 387 + Optimization="2" 388 + InlineFunctionExpansion="1" 389 + OmitFramePointers="true" 390 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 391 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 392 + StringPooling="true" 393 + BasicRuntimeChecks="0" 394 + RuntimeLibrary="2" 395 + BufferSecurityCheck="false" 396 + EnableFunctionLevelLinking="true" 397 + UsePrecompiledHeader="0" 398 + AssemblerListingLocation="$(IntDir)\" 399 + WarningLevel="3" 400 + Detect64BitPortabilityProblems="true" 401 + DebugInformationFormat="3" 402 + /> 403 + <Tool 404 + Name="VCManagedResourceCompilerTool" 405 + /> 406 + <Tool 407 + Name="VCResourceCompilerTool" 408 + /> 409 + <Tool 410 + Name="VCPreLinkEventTool" 411 + /> 412 + <Tool 413 + Name="VCLinkerTool" 414 + AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib" 415 + OutputFile="$(OutDir)/miniunz.exe" 416 + LinkIncremental="1" 417 + GenerateManifest="false" 418 + GenerateDebugInformation="true" 419 + SubSystem="1" 420 + OptimizeReferences="2" 421 + EnableCOMDATFolding="2" 422 + OptimizeForWindows98="1" 423 + TargetMachine="17" 424 + /> 425 + <Tool 426 + Name="VCALinkTool" 427 + /> 428 + <Tool 429 + Name="VCManifestTool" 430 + /> 431 + <Tool 432 + Name="VCXDCMakeTool" 433 + /> 434 + <Tool 435 + Name="VCBscMakeTool" 436 + /> 437 + <Tool 438 + Name="VCFxCopTool" 439 + /> 440 + <Tool 441 + Name="VCAppVerifierTool" 442 + /> 443 + <Tool 444 + Name="VCWebDeploymentTool" 445 + /> 446 + <Tool 447 + Name="VCPostBuildEventTool" 448 + /> 449 + </Configuration> 450 + <Configuration 451 + Name="Release|Itanium" 452 + OutputDirectory="ia64\MiniUnzip$(ConfigurationName)" 453 + IntermediateDirectory="ia64\MiniUnzip$(ConfigurationName)\Tmp" 454 + ConfigurationType="1" 455 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 456 + CharacterSet="2" 457 + > 458 + <Tool 459 + Name="VCPreBuildEventTool" 460 + /> 461 + <Tool 462 + Name="VCCustomBuildTool" 463 + /> 464 + <Tool 465 + Name="VCXMLDataGeneratorTool" 466 + /> 467 + <Tool 468 + Name="VCWebServiceProxyGeneratorTool" 469 + /> 470 + <Tool 471 + Name="VCMIDLTool" 472 + TargetEnvironment="2" 473 + /> 474 + <Tool 475 + Name="VCCLCompilerTool" 476 + Optimization="2" 477 + InlineFunctionExpansion="1" 478 + OmitFramePointers="true" 479 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 480 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 481 + StringPooling="true" 482 + BasicRuntimeChecks="0" 483 + RuntimeLibrary="2" 484 + BufferSecurityCheck="false" 485 + EnableFunctionLevelLinking="true" 486 + UsePrecompiledHeader="0" 487 + AssemblerListingLocation="$(IntDir)\" 488 + WarningLevel="3" 489 + Detect64BitPortabilityProblems="true" 490 + DebugInformationFormat="3" 491 + /> 492 + <Tool 493 + Name="VCManagedResourceCompilerTool" 494 + /> 495 + <Tool 496 + Name="VCResourceCompilerTool" 497 + /> 498 + <Tool 499 + Name="VCPreLinkEventTool" 500 + /> 501 + <Tool 502 + Name="VCLinkerTool" 503 + AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib" 504 + OutputFile="$(OutDir)/miniunz.exe" 505 + LinkIncremental="1" 506 + GenerateManifest="false" 507 + GenerateDebugInformation="true" 508 + SubSystem="1" 509 + OptimizeReferences="2" 510 + EnableCOMDATFolding="2" 511 + OptimizeForWindows98="1" 512 + TargetMachine="5" 513 + /> 514 + <Tool 515 + Name="VCALinkTool" 516 + /> 517 + <Tool 518 + Name="VCManifestTool" 519 + /> 520 + <Tool 521 + Name="VCXDCMakeTool" 522 + /> 523 + <Tool 524 + Name="VCBscMakeTool" 525 + /> 526 + <Tool 527 + Name="VCFxCopTool" 528 + /> 529 + <Tool 530 + Name="VCAppVerifierTool" 531 + /> 532 + <Tool 533 + Name="VCWebDeploymentTool" 534 + /> 535 + <Tool 536 + Name="VCPostBuildEventTool" 537 + /> 538 + </Configuration> 539 + </Configurations> 540 + <References> 541 + </References> 542 + <Files> 543 + <Filter 544 + Name="Source Files" 545 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" 546 + > 547 + <File 548 + RelativePath="..\..\minizip\miniunz.c" 549 + > 550 + </File> 551 + </Filter> 552 + <Filter 553 + Name="Header Files" 554 + Filter="h;hpp;hxx;hm;inl;inc" 555 + > 556 + </Filter> 557 + <Filter 558 + Name="Resource Files" 559 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 560 + > 561 + </Filter> 562 + </Files> 563 + <Globals> 564 + </Globals> 565 +</VisualStudioProject>
Added compat/zlib/contrib/vstudio/vc9/minizip.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9.00" 5 + Name="minizip" 6 + ProjectGUID="{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" 7 + Keyword="Win32Proj" 8 + TargetFrameworkVersion="131072" 9 + > 10 + <Platforms> 11 + <Platform 12 + Name="Win32" 13 + /> 14 + <Platform 15 + Name="x64" 16 + /> 17 + <Platform 18 + Name="Itanium" 19 + /> 20 + </Platforms> 21 + <ToolFiles> 22 + </ToolFiles> 23 + <Configurations> 24 + <Configuration 25 + Name="Debug|Win32" 26 + OutputDirectory="x86\MiniZip$(ConfigurationName)" 27 + IntermediateDirectory="x86\MiniZip$(ConfigurationName)\Tmp" 28 + ConfigurationType="1" 29 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 30 + CharacterSet="2" 31 + > 32 + <Tool 33 + Name="VCPreBuildEventTool" 34 + /> 35 + <Tool 36 + Name="VCCustomBuildTool" 37 + /> 38 + <Tool 39 + Name="VCXMLDataGeneratorTool" 40 + /> 41 + <Tool 42 + Name="VCWebServiceProxyGeneratorTool" 43 + /> 44 + <Tool 45 + Name="VCMIDLTool" 46 + /> 47 + <Tool 48 + Name="VCCLCompilerTool" 49 + Optimization="0" 50 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 51 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE" 52 + MinimalRebuild="true" 53 + BasicRuntimeChecks="0" 54 + RuntimeLibrary="1" 55 + BufferSecurityCheck="false" 56 + UsePrecompiledHeader="0" 57 + AssemblerListingLocation="$(IntDir)\" 58 + WarningLevel="3" 59 + Detect64BitPortabilityProblems="true" 60 + DebugInformationFormat="4" 61 + /> 62 + <Tool 63 + Name="VCManagedResourceCompilerTool" 64 + /> 65 + <Tool 66 + Name="VCResourceCompilerTool" 67 + /> 68 + <Tool 69 + Name="VCPreLinkEventTool" 70 + /> 71 + <Tool 72 + Name="VCLinkerTool" 73 + AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib" 74 + OutputFile="$(OutDir)/minizip.exe" 75 + LinkIncremental="2" 76 + GenerateManifest="false" 77 + GenerateDebugInformation="true" 78 + ProgramDatabaseFile="$(OutDir)/minizip.pdb" 79 + SubSystem="1" 80 + RandomizedBaseAddress="1" 81 + DataExecutionPrevention="0" 82 + TargetMachine="1" 83 + /> 84 + <Tool 85 + Name="VCALinkTool" 86 + /> 87 + <Tool 88 + Name="VCManifestTool" 89 + /> 90 + <Tool 91 + Name="VCXDCMakeTool" 92 + /> 93 + <Tool 94 + Name="VCBscMakeTool" 95 + /> 96 + <Tool 97 + Name="VCFxCopTool" 98 + /> 99 + <Tool 100 + Name="VCAppVerifierTool" 101 + /> 102 + <Tool 103 + Name="VCPostBuildEventTool" 104 + /> 105 + </Configuration> 106 + <Configuration 107 + Name="Release|Win32" 108 + OutputDirectory="x86\MiniZip$(ConfigurationName)" 109 + IntermediateDirectory="x86\MiniZip$(ConfigurationName)\Tmp" 110 + ConfigurationType="1" 111 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 112 + CharacterSet="2" 113 + > 114 + <Tool 115 + Name="VCPreBuildEventTool" 116 + /> 117 + <Tool 118 + Name="VCCustomBuildTool" 119 + /> 120 + <Tool 121 + Name="VCXMLDataGeneratorTool" 122 + /> 123 + <Tool 124 + Name="VCWebServiceProxyGeneratorTool" 125 + /> 126 + <Tool 127 + Name="VCMIDLTool" 128 + /> 129 + <Tool 130 + Name="VCCLCompilerTool" 131 + Optimization="2" 132 + InlineFunctionExpansion="1" 133 + OmitFramePointers="true" 134 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 135 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE" 136 + StringPooling="true" 137 + BasicRuntimeChecks="0" 138 + RuntimeLibrary="0" 139 + BufferSecurityCheck="false" 140 + EnableFunctionLevelLinking="true" 141 + UsePrecompiledHeader="0" 142 + AssemblerListingLocation="$(IntDir)\" 143 + WarningLevel="3" 144 + Detect64BitPortabilityProblems="true" 145 + DebugInformationFormat="3" 146 + /> 147 + <Tool 148 + Name="VCManagedResourceCompilerTool" 149 + /> 150 + <Tool 151 + Name="VCResourceCompilerTool" 152 + /> 153 + <Tool 154 + Name="VCPreLinkEventTool" 155 + /> 156 + <Tool 157 + Name="VCLinkerTool" 158 + AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib" 159 + OutputFile="$(OutDir)/minizip.exe" 160 + LinkIncremental="1" 161 + GenerateDebugInformation="true" 162 + SubSystem="1" 163 + OptimizeReferences="2" 164 + EnableCOMDATFolding="2" 165 + OptimizeForWindows98="1" 166 + RandomizedBaseAddress="1" 167 + DataExecutionPrevention="0" 168 + TargetMachine="1" 169 + /> 170 + <Tool 171 + Name="VCALinkTool" 172 + /> 173 + <Tool 174 + Name="VCManifestTool" 175 + /> 176 + <Tool 177 + Name="VCXDCMakeTool" 178 + /> 179 + <Tool 180 + Name="VCBscMakeTool" 181 + /> 182 + <Tool 183 + Name="VCFxCopTool" 184 + /> 185 + <Tool 186 + Name="VCAppVerifierTool" 187 + /> 188 + <Tool 189 + Name="VCPostBuildEventTool" 190 + /> 191 + </Configuration> 192 + <Configuration 193 + Name="Debug|x64" 194 + OutputDirectory="x64\$(ConfigurationName)" 195 + IntermediateDirectory="x64\$(ConfigurationName)" 196 + ConfigurationType="1" 197 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 198 + CharacterSet="2" 199 + > 200 + <Tool 201 + Name="VCPreBuildEventTool" 202 + /> 203 + <Tool 204 + Name="VCCustomBuildTool" 205 + /> 206 + <Tool 207 + Name="VCXMLDataGeneratorTool" 208 + /> 209 + <Tool 210 + Name="VCWebServiceProxyGeneratorTool" 211 + /> 212 + <Tool 213 + Name="VCMIDLTool" 214 + TargetEnvironment="3" 215 + /> 216 + <Tool 217 + Name="VCCLCompilerTool" 218 + Optimization="0" 219 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 220 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 221 + MinimalRebuild="true" 222 + BasicRuntimeChecks="0" 223 + RuntimeLibrary="3" 224 + BufferSecurityCheck="false" 225 + UsePrecompiledHeader="0" 226 + AssemblerListingLocation="$(IntDir)\" 227 + WarningLevel="3" 228 + Detect64BitPortabilityProblems="true" 229 + DebugInformationFormat="3" 230 + /> 231 + <Tool 232 + Name="VCManagedResourceCompilerTool" 233 + /> 234 + <Tool 235 + Name="VCResourceCompilerTool" 236 + /> 237 + <Tool 238 + Name="VCPreLinkEventTool" 239 + /> 240 + <Tool 241 + Name="VCLinkerTool" 242 + AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib" 243 + OutputFile="$(OutDir)/minizip.exe" 244 + LinkIncremental="2" 245 + GenerateManifest="false" 246 + GenerateDebugInformation="true" 247 + ProgramDatabaseFile="$(OutDir)/minizip.pdb" 248 + SubSystem="1" 249 + TargetMachine="17" 250 + /> 251 + <Tool 252 + Name="VCALinkTool" 253 + /> 254 + <Tool 255 + Name="VCManifestTool" 256 + /> 257 + <Tool 258 + Name="VCXDCMakeTool" 259 + /> 260 + <Tool 261 + Name="VCBscMakeTool" 262 + /> 263 + <Tool 264 + Name="VCFxCopTool" 265 + /> 266 + <Tool 267 + Name="VCAppVerifierTool" 268 + /> 269 + <Tool 270 + Name="VCWebDeploymentTool" 271 + /> 272 + <Tool 273 + Name="VCPostBuildEventTool" 274 + /> 275 + </Configuration> 276 + <Configuration 277 + Name="Debug|Itanium" 278 + OutputDirectory="ia64\$(ConfigurationName)" 279 + IntermediateDirectory="ia64\$(ConfigurationName)" 280 + ConfigurationType="1" 281 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 282 + CharacterSet="2" 283 + > 284 + <Tool 285 + Name="VCPreBuildEventTool" 286 + /> 287 + <Tool 288 + Name="VCCustomBuildTool" 289 + /> 290 + <Tool 291 + Name="VCXMLDataGeneratorTool" 292 + /> 293 + <Tool 294 + Name="VCWebServiceProxyGeneratorTool" 295 + /> 296 + <Tool 297 + Name="VCMIDLTool" 298 + TargetEnvironment="2" 299 + /> 300 + <Tool 301 + Name="VCCLCompilerTool" 302 + Optimization="0" 303 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 304 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 305 + MinimalRebuild="true" 306 + BasicRuntimeChecks="0" 307 + RuntimeLibrary="3" 308 + BufferSecurityCheck="false" 309 + UsePrecompiledHeader="0" 310 + AssemblerListingLocation="$(IntDir)\" 311 + WarningLevel="3" 312 + Detect64BitPortabilityProblems="true" 313 + DebugInformationFormat="3" 314 + /> 315 + <Tool 316 + Name="VCManagedResourceCompilerTool" 317 + /> 318 + <Tool 319 + Name="VCResourceCompilerTool" 320 + /> 321 + <Tool 322 + Name="VCPreLinkEventTool" 323 + /> 324 + <Tool 325 + Name="VCLinkerTool" 326 + AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib" 327 + OutputFile="$(OutDir)/minizip.exe" 328 + LinkIncremental="2" 329 + GenerateManifest="false" 330 + GenerateDebugInformation="true" 331 + ProgramDatabaseFile="$(OutDir)/minizip.pdb" 332 + SubSystem="1" 333 + TargetMachine="5" 334 + /> 335 + <Tool 336 + Name="VCALinkTool" 337 + /> 338 + <Tool 339 + Name="VCManifestTool" 340 + /> 341 + <Tool 342 + Name="VCXDCMakeTool" 343 + /> 344 + <Tool 345 + Name="VCBscMakeTool" 346 + /> 347 + <Tool 348 + Name="VCFxCopTool" 349 + /> 350 + <Tool 351 + Name="VCAppVerifierTool" 352 + /> 353 + <Tool 354 + Name="VCWebDeploymentTool" 355 + /> 356 + <Tool 357 + Name="VCPostBuildEventTool" 358 + /> 359 + </Configuration> 360 + <Configuration 361 + Name="Release|x64" 362 + OutputDirectory="x64\$(ConfigurationName)" 363 + IntermediateDirectory="x64\$(ConfigurationName)" 364 + ConfigurationType="1" 365 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 366 + CharacterSet="2" 367 + > 368 + <Tool 369 + Name="VCPreBuildEventTool" 370 + /> 371 + <Tool 372 + Name="VCCustomBuildTool" 373 + /> 374 + <Tool 375 + Name="VCXMLDataGeneratorTool" 376 + /> 377 + <Tool 378 + Name="VCWebServiceProxyGeneratorTool" 379 + /> 380 + <Tool 381 + Name="VCMIDLTool" 382 + TargetEnvironment="3" 383 + /> 384 + <Tool 385 + Name="VCCLCompilerTool" 386 + Optimization="2" 387 + InlineFunctionExpansion="1" 388 + OmitFramePointers="true" 389 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 390 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 391 + StringPooling="true" 392 + BasicRuntimeChecks="0" 393 + RuntimeLibrary="2" 394 + BufferSecurityCheck="false" 395 + EnableFunctionLevelLinking="true" 396 + UsePrecompiledHeader="0" 397 + AssemblerListingLocation="$(IntDir)\" 398 + WarningLevel="3" 399 + Detect64BitPortabilityProblems="true" 400 + DebugInformationFormat="3" 401 + /> 402 + <Tool 403 + Name="VCManagedResourceCompilerTool" 404 + /> 405 + <Tool 406 + Name="VCResourceCompilerTool" 407 + /> 408 + <Tool 409 + Name="VCPreLinkEventTool" 410 + /> 411 + <Tool 412 + Name="VCLinkerTool" 413 + AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib" 414 + OutputFile="$(OutDir)/minizip.exe" 415 + LinkIncremental="1" 416 + GenerateDebugInformation="true" 417 + SubSystem="1" 418 + OptimizeReferences="2" 419 + EnableCOMDATFolding="2" 420 + OptimizeForWindows98="1" 421 + TargetMachine="17" 422 + /> 423 + <Tool 424 + Name="VCALinkTool" 425 + /> 426 + <Tool 427 + Name="VCManifestTool" 428 + /> 429 + <Tool 430 + Name="VCXDCMakeTool" 431 + /> 432 + <Tool 433 + Name="VCBscMakeTool" 434 + /> 435 + <Tool 436 + Name="VCFxCopTool" 437 + /> 438 + <Tool 439 + Name="VCAppVerifierTool" 440 + /> 441 + <Tool 442 + Name="VCWebDeploymentTool" 443 + /> 444 + <Tool 445 + Name="VCPostBuildEventTool" 446 + /> 447 + </Configuration> 448 + <Configuration 449 + Name="Release|Itanium" 450 + OutputDirectory="ia64\$(ConfigurationName)" 451 + IntermediateDirectory="ia64\$(ConfigurationName)" 452 + ConfigurationType="1" 453 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 454 + CharacterSet="2" 455 + > 456 + <Tool 457 + Name="VCPreBuildEventTool" 458 + /> 459 + <Tool 460 + Name="VCCustomBuildTool" 461 + /> 462 + <Tool 463 + Name="VCXMLDataGeneratorTool" 464 + /> 465 + <Tool 466 + Name="VCWebServiceProxyGeneratorTool" 467 + /> 468 + <Tool 469 + Name="VCMIDLTool" 470 + TargetEnvironment="2" 471 + /> 472 + <Tool 473 + Name="VCCLCompilerTool" 474 + Optimization="2" 475 + InlineFunctionExpansion="1" 476 + OmitFramePointers="true" 477 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 478 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 479 + StringPooling="true" 480 + BasicRuntimeChecks="0" 481 + RuntimeLibrary="2" 482 + BufferSecurityCheck="false" 483 + EnableFunctionLevelLinking="true" 484 + UsePrecompiledHeader="0" 485 + AssemblerListingLocation="$(IntDir)\" 486 + WarningLevel="3" 487 + Detect64BitPortabilityProblems="true" 488 + DebugInformationFormat="3" 489 + /> 490 + <Tool 491 + Name="VCManagedResourceCompilerTool" 492 + /> 493 + <Tool 494 + Name="VCResourceCompilerTool" 495 + /> 496 + <Tool 497 + Name="VCPreLinkEventTool" 498 + /> 499 + <Tool 500 + Name="VCLinkerTool" 501 + AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib" 502 + OutputFile="$(OutDir)/minizip.exe" 503 + LinkIncremental="1" 504 + GenerateDebugInformation="true" 505 + SubSystem="1" 506 + OptimizeReferences="2" 507 + EnableCOMDATFolding="2" 508 + OptimizeForWindows98="1" 509 + TargetMachine="5" 510 + /> 511 + <Tool 512 + Name="VCALinkTool" 513 + /> 514 + <Tool 515 + Name="VCManifestTool" 516 + /> 517 + <Tool 518 + Name="VCXDCMakeTool" 519 + /> 520 + <Tool 521 + Name="VCBscMakeTool" 522 + /> 523 + <Tool 524 + Name="VCFxCopTool" 525 + /> 526 + <Tool 527 + Name="VCAppVerifierTool" 528 + /> 529 + <Tool 530 + Name="VCWebDeploymentTool" 531 + /> 532 + <Tool 533 + Name="VCPostBuildEventTool" 534 + /> 535 + </Configuration> 536 + </Configurations> 537 + <References> 538 + </References> 539 + <Files> 540 + <Filter 541 + Name="Source Files" 542 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" 543 + > 544 + <File 545 + RelativePath="..\..\minizip\minizip.c" 546 + > 547 + </File> 548 + </Filter> 549 + <Filter 550 + Name="Header Files" 551 + Filter="h;hpp;hxx;hm;inl;inc" 552 + > 553 + </Filter> 554 + <Filter 555 + Name="Resource Files" 556 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 557 + > 558 + </Filter> 559 + </Files> 560 + <Globals> 561 + </Globals> 562 +</VisualStudioProject>
Added compat/zlib/contrib/vstudio/vc9/testzlib.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9,00" 5 + Name="testzlib" 6 + ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" 7 + RootNamespace="testzlib" 8 + Keyword="Win32Proj" 9 + TargetFrameworkVersion="131072" 10 + > 11 + <Platforms> 12 + <Platform 13 + Name="Win32" 14 + /> 15 + <Platform 16 + Name="x64" 17 + /> 18 + <Platform 19 + Name="Itanium" 20 + /> 21 + </Platforms> 22 + <ToolFiles> 23 + </ToolFiles> 24 + <Configurations> 25 + <Configuration 26 + Name="Debug|Win32" 27 + OutputDirectory="x86\TestZlib$(ConfigurationName)" 28 + IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp" 29 + ConfigurationType="1" 30 + CharacterSet="2" 31 + > 32 + <Tool 33 + Name="VCPreBuildEventTool" 34 + /> 35 + <Tool 36 + Name="VCCustomBuildTool" 37 + /> 38 + <Tool 39 + Name="VCXMLDataGeneratorTool" 40 + /> 41 + <Tool 42 + Name="VCWebServiceProxyGeneratorTool" 43 + /> 44 + <Tool 45 + Name="VCMIDLTool" 46 + /> 47 + <Tool 48 + Name="VCCLCompilerTool" 49 + Optimization="0" 50 + AdditionalIncludeDirectories="..\..\.." 51 + PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 52 + MinimalRebuild="true" 53 + BasicRuntimeChecks="0" 54 + RuntimeLibrary="1" 55 + BufferSecurityCheck="false" 56 + UsePrecompiledHeader="0" 57 + AssemblerOutput="4" 58 + AssemblerListingLocation="$(IntDir)\" 59 + WarningLevel="3" 60 + Detect64BitPortabilityProblems="true" 61 + DebugInformationFormat="4" 62 + /> 63 + <Tool 64 + Name="VCManagedResourceCompilerTool" 65 + /> 66 + <Tool 67 + Name="VCResourceCompilerTool" 68 + /> 69 + <Tool 70 + Name="VCPreLinkEventTool" 71 + /> 72 + <Tool 73 + Name="VCLinkerTool" 74 + AdditionalDependencies="..\..\masmx86\match686.obj ..\..\masmx86\inffas32.obj" 75 + OutputFile="$(OutDir)/testzlib.exe" 76 + LinkIncremental="2" 77 + GenerateManifest="false" 78 + GenerateDebugInformation="true" 79 + ProgramDatabaseFile="$(OutDir)/testzlib.pdb" 80 + SubSystem="1" 81 + RandomizedBaseAddress="1" 82 + DataExecutionPrevention="0" 83 + TargetMachine="1" 84 + /> 85 + <Tool 86 + Name="VCALinkTool" 87 + /> 88 + <Tool 89 + Name="VCManifestTool" 90 + /> 91 + <Tool 92 + Name="VCXDCMakeTool" 93 + /> 94 + <Tool 95 + Name="VCBscMakeTool" 96 + /> 97 + <Tool 98 + Name="VCFxCopTool" 99 + /> 100 + <Tool 101 + Name="VCAppVerifierTool" 102 + /> 103 + <Tool 104 + Name="VCPostBuildEventTool" 105 + /> 106 + </Configuration> 107 + <Configuration 108 + Name="Debug|x64" 109 + OutputDirectory="x64\TestZlib$(ConfigurationName)" 110 + IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp" 111 + ConfigurationType="1" 112 + > 113 + <Tool 114 + Name="VCPreBuildEventTool" 115 + /> 116 + <Tool 117 + Name="VCCustomBuildTool" 118 + /> 119 + <Tool 120 + Name="VCXMLDataGeneratorTool" 121 + /> 122 + <Tool 123 + Name="VCWebServiceProxyGeneratorTool" 124 + /> 125 + <Tool 126 + Name="VCMIDLTool" 127 + /> 128 + <Tool 129 + Name="VCCLCompilerTool" 130 + AdditionalIncludeDirectories="..\..\.." 131 + PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 132 + BasicRuntimeChecks="0" 133 + RuntimeLibrary="3" 134 + BufferSecurityCheck="false" 135 + AssemblerListingLocation="$(IntDir)\" 136 + /> 137 + <Tool 138 + Name="VCManagedResourceCompilerTool" 139 + /> 140 + <Tool 141 + Name="VCResourceCompilerTool" 142 + /> 143 + <Tool 144 + Name="VCPreLinkEventTool" 145 + /> 146 + <Tool 147 + Name="VCLinkerTool" 148 + AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj" 149 + GenerateManifest="false" 150 + /> 151 + <Tool 152 + Name="VCALinkTool" 153 + /> 154 + <Tool 155 + Name="VCManifestTool" 156 + /> 157 + <Tool 158 + Name="VCXDCMakeTool" 159 + /> 160 + <Tool 161 + Name="VCBscMakeTool" 162 + /> 163 + <Tool 164 + Name="VCFxCopTool" 165 + /> 166 + <Tool 167 + Name="VCAppVerifierTool" 168 + /> 169 + <Tool 170 + Name="VCPostBuildEventTool" 171 + /> 172 + </Configuration> 173 + <Configuration 174 + Name="Debug|Itanium" 175 + OutputDirectory="ia64\TestZlib$(ConfigurationName)" 176 + IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp" 177 + ConfigurationType="1" 178 + CharacterSet="2" 179 + > 180 + <Tool 181 + Name="VCPreBuildEventTool" 182 + /> 183 + <Tool 184 + Name="VCCustomBuildTool" 185 + /> 186 + <Tool 187 + Name="VCXMLDataGeneratorTool" 188 + /> 189 + <Tool 190 + Name="VCWebServiceProxyGeneratorTool" 191 + /> 192 + <Tool 193 + Name="VCMIDLTool" 194 + TargetEnvironment="2" 195 + /> 196 + <Tool 197 + Name="VCCLCompilerTool" 198 + Optimization="0" 199 + AdditionalIncludeDirectories="..\..\.." 200 + PreprocessorDefinitions="ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 201 + MinimalRebuild="true" 202 + BasicRuntimeChecks="0" 203 + RuntimeLibrary="3" 204 + BufferSecurityCheck="false" 205 + UsePrecompiledHeader="0" 206 + AssemblerOutput="4" 207 + AssemblerListingLocation="$(IntDir)\" 208 + WarningLevel="3" 209 + Detect64BitPortabilityProblems="true" 210 + DebugInformationFormat="3" 211 + /> 212 + <Tool 213 + Name="VCManagedResourceCompilerTool" 214 + /> 215 + <Tool 216 + Name="VCResourceCompilerTool" 217 + /> 218 + <Tool 219 + Name="VCPreLinkEventTool" 220 + /> 221 + <Tool 222 + Name="VCLinkerTool" 223 + OutputFile="$(OutDir)/testzlib.exe" 224 + LinkIncremental="2" 225 + GenerateManifest="false" 226 + GenerateDebugInformation="true" 227 + ProgramDatabaseFile="$(OutDir)/testzlib.pdb" 228 + SubSystem="1" 229 + TargetMachine="5" 230 + /> 231 + <Tool 232 + Name="VCALinkTool" 233 + /> 234 + <Tool 235 + Name="VCManifestTool" 236 + /> 237 + <Tool 238 + Name="VCXDCMakeTool" 239 + /> 240 + <Tool 241 + Name="VCBscMakeTool" 242 + /> 243 + <Tool 244 + Name="VCFxCopTool" 245 + /> 246 + <Tool 247 + Name="VCAppVerifierTool" 248 + /> 249 + <Tool 250 + Name="VCPostBuildEventTool" 251 + /> 252 + </Configuration> 253 + <Configuration 254 + Name="ReleaseWithoutAsm|Win32" 255 + OutputDirectory="x86\TestZlib$(ConfigurationName)" 256 + IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp" 257 + ConfigurationType="1" 258 + CharacterSet="2" 259 + WholeProgramOptimization="1" 260 + > 261 + <Tool 262 + Name="VCPreBuildEventTool" 263 + /> 264 + <Tool 265 + Name="VCCustomBuildTool" 266 + /> 267 + <Tool 268 + Name="VCXMLDataGeneratorTool" 269 + /> 270 + <Tool 271 + Name="VCWebServiceProxyGeneratorTool" 272 + /> 273 + <Tool 274 + Name="VCMIDLTool" 275 + /> 276 + <Tool 277 + Name="VCCLCompilerTool" 278 + Optimization="2" 279 + InlineFunctionExpansion="1" 280 + OmitFramePointers="true" 281 + AdditionalIncludeDirectories="..\..\.." 282 + PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 283 + StringPooling="true" 284 + BasicRuntimeChecks="0" 285 + RuntimeLibrary="0" 286 + BufferSecurityCheck="false" 287 + EnableFunctionLevelLinking="true" 288 + UsePrecompiledHeader="0" 289 + AssemblerListingLocation="$(IntDir)\" 290 + WarningLevel="3" 291 + Detect64BitPortabilityProblems="true" 292 + DebugInformationFormat="3" 293 + /> 294 + <Tool 295 + Name="VCManagedResourceCompilerTool" 296 + /> 297 + <Tool 298 + Name="VCResourceCompilerTool" 299 + /> 300 + <Tool 301 + Name="VCPreLinkEventTool" 302 + /> 303 + <Tool 304 + Name="VCLinkerTool" 305 + OutputFile="$(OutDir)/testzlib.exe" 306 + LinkIncremental="1" 307 + GenerateManifest="false" 308 + GenerateDebugInformation="true" 309 + SubSystem="1" 310 + OptimizeReferences="2" 311 + EnableCOMDATFolding="2" 312 + OptimizeForWindows98="1" 313 + RandomizedBaseAddress="1" 314 + DataExecutionPrevention="0" 315 + TargetMachine="1" 316 + /> 317 + <Tool 318 + Name="VCALinkTool" 319 + /> 320 + <Tool 321 + Name="VCManifestTool" 322 + /> 323 + <Tool 324 + Name="VCXDCMakeTool" 325 + /> 326 + <Tool 327 + Name="VCBscMakeTool" 328 + /> 329 + <Tool 330 + Name="VCFxCopTool" 331 + /> 332 + <Tool 333 + Name="VCAppVerifierTool" 334 + /> 335 + <Tool 336 + Name="VCPostBuildEventTool" 337 + /> 338 + </Configuration> 339 + <Configuration 340 + Name="ReleaseWithoutAsm|x64" 341 + OutputDirectory="x64\TestZlib$(ConfigurationName)" 342 + IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp" 343 + ConfigurationType="1" 344 + WholeProgramOptimization="1" 345 + > 346 + <Tool 347 + Name="VCPreBuildEventTool" 348 + /> 349 + <Tool 350 + Name="VCCustomBuildTool" 351 + /> 352 + <Tool 353 + Name="VCXMLDataGeneratorTool" 354 + /> 355 + <Tool 356 + Name="VCWebServiceProxyGeneratorTool" 357 + /> 358 + <Tool 359 + Name="VCMIDLTool" 360 + /> 361 + <Tool 362 + Name="VCCLCompilerTool" 363 + AdditionalIncludeDirectories="..\..\.." 364 + PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 365 + BasicRuntimeChecks="0" 366 + RuntimeLibrary="2" 367 + BufferSecurityCheck="false" 368 + AssemblerListingLocation="$(IntDir)\" 369 + /> 370 + <Tool 371 + Name="VCManagedResourceCompilerTool" 372 + /> 373 + <Tool 374 + Name="VCResourceCompilerTool" 375 + /> 376 + <Tool 377 + Name="VCPreLinkEventTool" 378 + /> 379 + <Tool 380 + Name="VCLinkerTool" 381 + AdditionalDependencies="" 382 + GenerateManifest="false" 383 + /> 384 + <Tool 385 + Name="VCALinkTool" 386 + /> 387 + <Tool 388 + Name="VCManifestTool" 389 + /> 390 + <Tool 391 + Name="VCXDCMakeTool" 392 + /> 393 + <Tool 394 + Name="VCBscMakeTool" 395 + /> 396 + <Tool 397 + Name="VCFxCopTool" 398 + /> 399 + <Tool 400 + Name="VCAppVerifierTool" 401 + /> 402 + <Tool 403 + Name="VCPostBuildEventTool" 404 + /> 405 + </Configuration> 406 + <Configuration 407 + Name="ReleaseWithoutAsm|Itanium" 408 + OutputDirectory="ia64\TestZlib$(ConfigurationName)" 409 + IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp" 410 + ConfigurationType="1" 411 + CharacterSet="2" 412 + WholeProgramOptimization="1" 413 + > 414 + <Tool 415 + Name="VCPreBuildEventTool" 416 + /> 417 + <Tool 418 + Name="VCCustomBuildTool" 419 + /> 420 + <Tool 421 + Name="VCXMLDataGeneratorTool" 422 + /> 423 + <Tool 424 + Name="VCWebServiceProxyGeneratorTool" 425 + /> 426 + <Tool 427 + Name="VCMIDLTool" 428 + TargetEnvironment="2" 429 + /> 430 + <Tool 431 + Name="VCCLCompilerTool" 432 + Optimization="2" 433 + InlineFunctionExpansion="1" 434 + OmitFramePointers="true" 435 + AdditionalIncludeDirectories="..\..\.." 436 + PreprocessorDefinitions="ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 437 + StringPooling="true" 438 + BasicRuntimeChecks="0" 439 + RuntimeLibrary="2" 440 + BufferSecurityCheck="false" 441 + EnableFunctionLevelLinking="true" 442 + UsePrecompiledHeader="0" 443 + AssemblerListingLocation="$(IntDir)\" 444 + WarningLevel="3" 445 + Detect64BitPortabilityProblems="true" 446 + DebugInformationFormat="3" 447 + /> 448 + <Tool 449 + Name="VCManagedResourceCompilerTool" 450 + /> 451 + <Tool 452 + Name="VCResourceCompilerTool" 453 + /> 454 + <Tool 455 + Name="VCPreLinkEventTool" 456 + /> 457 + <Tool 458 + Name="VCLinkerTool" 459 + OutputFile="$(OutDir)/testzlib.exe" 460 + LinkIncremental="1" 461 + GenerateManifest="false" 462 + GenerateDebugInformation="true" 463 + SubSystem="1" 464 + OptimizeReferences="2" 465 + EnableCOMDATFolding="2" 466 + OptimizeForWindows98="1" 467 + TargetMachine="5" 468 + /> 469 + <Tool 470 + Name="VCALinkTool" 471 + /> 472 + <Tool 473 + Name="VCManifestTool" 474 + /> 475 + <Tool 476 + Name="VCXDCMakeTool" 477 + /> 478 + <Tool 479 + Name="VCBscMakeTool" 480 + /> 481 + <Tool 482 + Name="VCFxCopTool" 483 + /> 484 + <Tool 485 + Name="VCAppVerifierTool" 486 + /> 487 + <Tool 488 + Name="VCPostBuildEventTool" 489 + /> 490 + </Configuration> 491 + <Configuration 492 + Name="Release|Win32" 493 + OutputDirectory="x86\TestZlib$(ConfigurationName)" 494 + IntermediateDirectory="x86\TestZlib$(ConfigurationName)\Tmp" 495 + ConfigurationType="1" 496 + CharacterSet="2" 497 + WholeProgramOptimization="1" 498 + > 499 + <Tool 500 + Name="VCPreBuildEventTool" 501 + /> 502 + <Tool 503 + Name="VCCustomBuildTool" 504 + /> 505 + <Tool 506 + Name="VCXMLDataGeneratorTool" 507 + /> 508 + <Tool 509 + Name="VCWebServiceProxyGeneratorTool" 510 + /> 511 + <Tool 512 + Name="VCMIDLTool" 513 + /> 514 + <Tool 515 + Name="VCCLCompilerTool" 516 + Optimization="2" 517 + InlineFunctionExpansion="1" 518 + OmitFramePointers="true" 519 + AdditionalIncludeDirectories="..\..\.." 520 + PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 521 + StringPooling="true" 522 + BasicRuntimeChecks="0" 523 + RuntimeLibrary="0" 524 + BufferSecurityCheck="false" 525 + EnableFunctionLevelLinking="true" 526 + UsePrecompiledHeader="0" 527 + AssemblerListingLocation="$(IntDir)\" 528 + WarningLevel="3" 529 + Detect64BitPortabilityProblems="true" 530 + DebugInformationFormat="3" 531 + /> 532 + <Tool 533 + Name="VCManagedResourceCompilerTool" 534 + /> 535 + <Tool 536 + Name="VCResourceCompilerTool" 537 + /> 538 + <Tool 539 + Name="VCPreLinkEventTool" 540 + /> 541 + <Tool 542 + Name="VCLinkerTool" 543 + AdditionalDependencies="..\..\masmx86\match686.obj ..\..\masmx86\inffas32.obj" 544 + OutputFile="$(OutDir)/testzlib.exe" 545 + LinkIncremental="1" 546 + GenerateManifest="false" 547 + GenerateDebugInformation="true" 548 + SubSystem="1" 549 + OptimizeReferences="2" 550 + EnableCOMDATFolding="2" 551 + OptimizeForWindows98="1" 552 + RandomizedBaseAddress="1" 553 + DataExecutionPrevention="0" 554 + TargetMachine="1" 555 + /> 556 + <Tool 557 + Name="VCALinkTool" 558 + /> 559 + <Tool 560 + Name="VCManifestTool" 561 + /> 562 + <Tool 563 + Name="VCXDCMakeTool" 564 + /> 565 + <Tool 566 + Name="VCBscMakeTool" 567 + /> 568 + <Tool 569 + Name="VCFxCopTool" 570 + /> 571 + <Tool 572 + Name="VCAppVerifierTool" 573 + /> 574 + <Tool 575 + Name="VCPostBuildEventTool" 576 + /> 577 + </Configuration> 578 + <Configuration 579 + Name="Release|x64" 580 + OutputDirectory="x64\TestZlib$(ConfigurationName)" 581 + IntermediateDirectory="x64\TestZlib$(ConfigurationName)\Tmp" 582 + ConfigurationType="1" 583 + WholeProgramOptimization="1" 584 + > 585 + <Tool 586 + Name="VCPreBuildEventTool" 587 + /> 588 + <Tool 589 + Name="VCCustomBuildTool" 590 + /> 591 + <Tool 592 + Name="VCXMLDataGeneratorTool" 593 + /> 594 + <Tool 595 + Name="VCWebServiceProxyGeneratorTool" 596 + /> 597 + <Tool 598 + Name="VCMIDLTool" 599 + /> 600 + <Tool 601 + Name="VCCLCompilerTool" 602 + AdditionalIncludeDirectories="..\..\.." 603 + PreprocessorDefinitions="ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 604 + BasicRuntimeChecks="0" 605 + RuntimeLibrary="0" 606 + BufferSecurityCheck="false" 607 + AssemblerListingLocation="$(IntDir)\" 608 + /> 609 + <Tool 610 + Name="VCManagedResourceCompilerTool" 611 + /> 612 + <Tool 613 + Name="VCResourceCompilerTool" 614 + /> 615 + <Tool 616 + Name="VCPreLinkEventTool" 617 + /> 618 + <Tool 619 + Name="VCLinkerTool" 620 + AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj" 621 + GenerateManifest="false" 622 + /> 623 + <Tool 624 + Name="VCALinkTool" 625 + /> 626 + <Tool 627 + Name="VCManifestTool" 628 + /> 629 + <Tool 630 + Name="VCXDCMakeTool" 631 + /> 632 + <Tool 633 + Name="VCBscMakeTool" 634 + /> 635 + <Tool 636 + Name="VCFxCopTool" 637 + /> 638 + <Tool 639 + Name="VCAppVerifierTool" 640 + /> 641 + <Tool 642 + Name="VCPostBuildEventTool" 643 + /> 644 + </Configuration> 645 + <Configuration 646 + Name="Release|Itanium" 647 + OutputDirectory="ia64\TestZlib$(ConfigurationName)" 648 + IntermediateDirectory="ia64\TestZlib$(ConfigurationName)\Tmp" 649 + ConfigurationType="1" 650 + CharacterSet="2" 651 + WholeProgramOptimization="1" 652 + > 653 + <Tool 654 + Name="VCPreBuildEventTool" 655 + /> 656 + <Tool 657 + Name="VCCustomBuildTool" 658 + /> 659 + <Tool 660 + Name="VCXMLDataGeneratorTool" 661 + /> 662 + <Tool 663 + Name="VCWebServiceProxyGeneratorTool" 664 + /> 665 + <Tool 666 + Name="VCMIDLTool" 667 + TargetEnvironment="2" 668 + /> 669 + <Tool 670 + Name="VCCLCompilerTool" 671 + Optimization="2" 672 + InlineFunctionExpansion="1" 673 + OmitFramePointers="true" 674 + AdditionalIncludeDirectories="..\..\.." 675 + PreprocessorDefinitions="ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 676 + StringPooling="true" 677 + BasicRuntimeChecks="0" 678 + RuntimeLibrary="2" 679 + BufferSecurityCheck="false" 680 + EnableFunctionLevelLinking="true" 681 + UsePrecompiledHeader="0" 682 + AssemblerListingLocation="$(IntDir)\" 683 + WarningLevel="3" 684 + Detect64BitPortabilityProblems="true" 685 + DebugInformationFormat="3" 686 + /> 687 + <Tool 688 + Name="VCManagedResourceCompilerTool" 689 + /> 690 + <Tool 691 + Name="VCResourceCompilerTool" 692 + /> 693 + <Tool 694 + Name="VCPreLinkEventTool" 695 + /> 696 + <Tool 697 + Name="VCLinkerTool" 698 + OutputFile="$(OutDir)/testzlib.exe" 699 + LinkIncremental="1" 700 + GenerateManifest="false" 701 + GenerateDebugInformation="true" 702 + SubSystem="1" 703 + OptimizeReferences="2" 704 + EnableCOMDATFolding="2" 705 + OptimizeForWindows98="1" 706 + TargetMachine="5" 707 + /> 708 + <Tool 709 + Name="VCALinkTool" 710 + /> 711 + <Tool 712 + Name="VCManifestTool" 713 + /> 714 + <Tool 715 + Name="VCXDCMakeTool" 716 + /> 717 + <Tool 718 + Name="VCBscMakeTool" 719 + /> 720 + <Tool 721 + Name="VCFxCopTool" 722 + /> 723 + <Tool 724 + Name="VCAppVerifierTool" 725 + /> 726 + <Tool 727 + Name="VCPostBuildEventTool" 728 + /> 729 + </Configuration> 730 + </Configurations> 731 + <References> 732 + </References> 733 + <Files> 734 + <Filter 735 + Name="Source Files" 736 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" 737 + > 738 + <File 739 + RelativePath="..\..\..\adler32.c" 740 + > 741 + </File> 742 + <File 743 + RelativePath="..\..\..\compress.c" 744 + > 745 + </File> 746 + <File 747 + RelativePath="..\..\..\crc32.c" 748 + > 749 + </File> 750 + <File 751 + RelativePath="..\..\..\deflate.c" 752 + > 753 + </File> 754 + <File 755 + RelativePath="..\..\..\infback.c" 756 + > 757 + </File> 758 + <File 759 + RelativePath="..\..\masmx64\inffas8664.c" 760 + > 761 + <FileConfiguration 762 + Name="Debug|Win32" 763 + ExcludedFromBuild="true" 764 + > 765 + <Tool 766 + Name="VCCLCompilerTool" 767 + /> 768 + </FileConfiguration> 769 + <FileConfiguration 770 + Name="Debug|Itanium" 771 + ExcludedFromBuild="true" 772 + > 773 + <Tool 774 + Name="VCCLCompilerTool" 775 + /> 776 + </FileConfiguration> 777 + <FileConfiguration 778 + Name="ReleaseWithoutAsm|Win32" 779 + ExcludedFromBuild="true" 780 + > 781 + <Tool 782 + Name="VCCLCompilerTool" 783 + /> 784 + </FileConfiguration> 785 + <FileConfiguration 786 + Name="ReleaseWithoutAsm|Itanium" 787 + ExcludedFromBuild="true" 788 + > 789 + <Tool 790 + Name="VCCLCompilerTool" 791 + /> 792 + </FileConfiguration> 793 + <FileConfiguration 794 + Name="Release|Win32" 795 + ExcludedFromBuild="true" 796 + > 797 + <Tool 798 + Name="VCCLCompilerTool" 799 + /> 800 + </FileConfiguration> 801 + <FileConfiguration 802 + Name="Release|Itanium" 803 + ExcludedFromBuild="true" 804 + > 805 + <Tool 806 + Name="VCCLCompilerTool" 807 + /> 808 + </FileConfiguration> 809 + </File> 810 + <File 811 + RelativePath="..\..\..\inffast.c" 812 + > 813 + </File> 814 + <File 815 + RelativePath="..\..\..\inflate.c" 816 + > 817 + </File> 818 + <File 819 + RelativePath="..\..\..\inftrees.c" 820 + > 821 + </File> 822 + <File 823 + RelativePath="..\..\testzlib\testzlib.c" 824 + > 825 + </File> 826 + <File 827 + RelativePath="..\..\..\trees.c" 828 + > 829 + </File> 830 + <File 831 + RelativePath="..\..\..\uncompr.c" 832 + > 833 + </File> 834 + <File 835 + RelativePath="..\..\..\zutil.c" 836 + > 837 + </File> 838 + </Filter> 839 + <Filter 840 + Name="Header Files" 841 + Filter="h;hpp;hxx;hm;inl;inc" 842 + > 843 + </Filter> 844 + <Filter 845 + Name="Resource Files" 846 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 847 + > 848 + </Filter> 849 + </Files> 850 + <Globals> 851 + </Globals> 852 +</VisualStudioProject>
Added compat/zlib/contrib/vstudio/vc9/testzlibdll.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9.00" 5 + Name="TestZlibDll" 6 + ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694366A}" 7 + Keyword="Win32Proj" 8 + TargetFrameworkVersion="131072" 9 + > 10 + <Platforms> 11 + <Platform 12 + Name="Win32" 13 + /> 14 + <Platform 15 + Name="x64" 16 + /> 17 + <Platform 18 + Name="Itanium" 19 + /> 20 + </Platforms> 21 + <ToolFiles> 22 + </ToolFiles> 23 + <Configurations> 24 + <Configuration 25 + Name="Debug|Win32" 26 + OutputDirectory="x86\TestZlibDll$(ConfigurationName)" 27 + IntermediateDirectory="x86\TestZlibDll$(ConfigurationName)\Tmp" 28 + ConfigurationType="1" 29 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 30 + CharacterSet="2" 31 + > 32 + <Tool 33 + Name="VCPreBuildEventTool" 34 + /> 35 + <Tool 36 + Name="VCCustomBuildTool" 37 + /> 38 + <Tool 39 + Name="VCXMLDataGeneratorTool" 40 + /> 41 + <Tool 42 + Name="VCWebServiceProxyGeneratorTool" 43 + /> 44 + <Tool 45 + Name="VCMIDLTool" 46 + /> 47 + <Tool 48 + Name="VCCLCompilerTool" 49 + Optimization="0" 50 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 51 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE" 52 + MinimalRebuild="true" 53 + BasicRuntimeChecks="0" 54 + RuntimeLibrary="1" 55 + BufferSecurityCheck="false" 56 + UsePrecompiledHeader="0" 57 + AssemblerListingLocation="$(IntDir)\" 58 + WarningLevel="3" 59 + Detect64BitPortabilityProblems="true" 60 + DebugInformationFormat="4" 61 + /> 62 + <Tool 63 + Name="VCManagedResourceCompilerTool" 64 + /> 65 + <Tool 66 + Name="VCResourceCompilerTool" 67 + /> 68 + <Tool 69 + Name="VCPreLinkEventTool" 70 + /> 71 + <Tool 72 + Name="VCLinkerTool" 73 + AdditionalDependencies="x86\ZlibDllDebug\zlibwapi.lib" 74 + OutputFile="$(OutDir)/testzlib.exe" 75 + LinkIncremental="2" 76 + GenerateManifest="false" 77 + GenerateDebugInformation="true" 78 + ProgramDatabaseFile="$(OutDir)/testzlib.pdb" 79 + SubSystem="1" 80 + RandomizedBaseAddress="1" 81 + DataExecutionPrevention="0" 82 + TargetMachine="1" 83 + /> 84 + <Tool 85 + Name="VCALinkTool" 86 + /> 87 + <Tool 88 + Name="VCManifestTool" 89 + /> 90 + <Tool 91 + Name="VCXDCMakeTool" 92 + /> 93 + <Tool 94 + Name="VCBscMakeTool" 95 + /> 96 + <Tool 97 + Name="VCFxCopTool" 98 + /> 99 + <Tool 100 + Name="VCAppVerifierTool" 101 + /> 102 + <Tool 103 + Name="VCPostBuildEventTool" 104 + /> 105 + </Configuration> 106 + <Configuration 107 + Name="Release|Win32" 108 + OutputDirectory="x86\TestZlibDll$(ConfigurationName)" 109 + IntermediateDirectory="x86\TestZlibDll$(ConfigurationName)\Tmp" 110 + ConfigurationType="1" 111 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 112 + CharacterSet="2" 113 + > 114 + <Tool 115 + Name="VCPreBuildEventTool" 116 + /> 117 + <Tool 118 + Name="VCCustomBuildTool" 119 + /> 120 + <Tool 121 + Name="VCXMLDataGeneratorTool" 122 + /> 123 + <Tool 124 + Name="VCWebServiceProxyGeneratorTool" 125 + /> 126 + <Tool 127 + Name="VCMIDLTool" 128 + /> 129 + <Tool 130 + Name="VCCLCompilerTool" 131 + Optimization="2" 132 + InlineFunctionExpansion="1" 133 + OmitFramePointers="true" 134 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 135 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE" 136 + StringPooling="true" 137 + BasicRuntimeChecks="0" 138 + RuntimeLibrary="0" 139 + BufferSecurityCheck="false" 140 + EnableFunctionLevelLinking="true" 141 + UsePrecompiledHeader="0" 142 + AssemblerListingLocation="$(IntDir)\" 143 + WarningLevel="3" 144 + Detect64BitPortabilityProblems="true" 145 + DebugInformationFormat="3" 146 + /> 147 + <Tool 148 + Name="VCManagedResourceCompilerTool" 149 + /> 150 + <Tool 151 + Name="VCResourceCompilerTool" 152 + /> 153 + <Tool 154 + Name="VCPreLinkEventTool" 155 + /> 156 + <Tool 157 + Name="VCLinkerTool" 158 + AdditionalDependencies="x86\ZlibDllRelease\zlibwapi.lib" 159 + OutputFile="$(OutDir)/testzlib.exe" 160 + LinkIncremental="1" 161 + GenerateManifest="false" 162 + GenerateDebugInformation="true" 163 + SubSystem="1" 164 + OptimizeReferences="2" 165 + EnableCOMDATFolding="2" 166 + OptimizeForWindows98="1" 167 + RandomizedBaseAddress="1" 168 + DataExecutionPrevention="0" 169 + TargetMachine="1" 170 + /> 171 + <Tool 172 + Name="VCALinkTool" 173 + /> 174 + <Tool 175 + Name="VCManifestTool" 176 + /> 177 + <Tool 178 + Name="VCXDCMakeTool" 179 + /> 180 + <Tool 181 + Name="VCBscMakeTool" 182 + /> 183 + <Tool 184 + Name="VCFxCopTool" 185 + /> 186 + <Tool 187 + Name="VCAppVerifierTool" 188 + /> 189 + <Tool 190 + Name="VCPostBuildEventTool" 191 + /> 192 + </Configuration> 193 + <Configuration 194 + Name="Debug|x64" 195 + OutputDirectory="x64\TestZlibDll$(ConfigurationName)" 196 + IntermediateDirectory="x64\TestZlibDll$(ConfigurationName)\Tmp" 197 + ConfigurationType="1" 198 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 199 + CharacterSet="2" 200 + > 201 + <Tool 202 + Name="VCPreBuildEventTool" 203 + /> 204 + <Tool 205 + Name="VCCustomBuildTool" 206 + /> 207 + <Tool 208 + Name="VCXMLDataGeneratorTool" 209 + /> 210 + <Tool 211 + Name="VCWebServiceProxyGeneratorTool" 212 + /> 213 + <Tool 214 + Name="VCMIDLTool" 215 + TargetEnvironment="3" 216 + /> 217 + <Tool 218 + Name="VCCLCompilerTool" 219 + Optimization="0" 220 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 221 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 222 + MinimalRebuild="true" 223 + BasicRuntimeChecks="0" 224 + RuntimeLibrary="3" 225 + BufferSecurityCheck="false" 226 + UsePrecompiledHeader="0" 227 + AssemblerListingLocation="$(IntDir)\" 228 + WarningLevel="3" 229 + Detect64BitPortabilityProblems="true" 230 + DebugInformationFormat="3" 231 + /> 232 + <Tool 233 + Name="VCManagedResourceCompilerTool" 234 + /> 235 + <Tool 236 + Name="VCResourceCompilerTool" 237 + /> 238 + <Tool 239 + Name="VCPreLinkEventTool" 240 + /> 241 + <Tool 242 + Name="VCLinkerTool" 243 + AdditionalDependencies="x64\ZlibDllDebug\zlibwapi.lib" 244 + OutputFile="$(OutDir)/testzlib.exe" 245 + LinkIncremental="2" 246 + GenerateManifest="false" 247 + GenerateDebugInformation="true" 248 + ProgramDatabaseFile="$(OutDir)/testzlib.pdb" 249 + SubSystem="1" 250 + TargetMachine="17" 251 + /> 252 + <Tool 253 + Name="VCALinkTool" 254 + /> 255 + <Tool 256 + Name="VCManifestTool" 257 + /> 258 + <Tool 259 + Name="VCXDCMakeTool" 260 + /> 261 + <Tool 262 + Name="VCBscMakeTool" 263 + /> 264 + <Tool 265 + Name="VCFxCopTool" 266 + /> 267 + <Tool 268 + Name="VCAppVerifierTool" 269 + /> 270 + <Tool 271 + Name="VCWebDeploymentTool" 272 + /> 273 + <Tool 274 + Name="VCPostBuildEventTool" 275 + /> 276 + </Configuration> 277 + <Configuration 278 + Name="Debug|Itanium" 279 + OutputDirectory="ia64\TestZlibDll$(ConfigurationName)" 280 + IntermediateDirectory="ia64\TestZlibDll$(ConfigurationName)\Tmp" 281 + ConfigurationType="1" 282 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 283 + CharacterSet="2" 284 + > 285 + <Tool 286 + Name="VCPreBuildEventTool" 287 + /> 288 + <Tool 289 + Name="VCCustomBuildTool" 290 + /> 291 + <Tool 292 + Name="VCXMLDataGeneratorTool" 293 + /> 294 + <Tool 295 + Name="VCWebServiceProxyGeneratorTool" 296 + /> 297 + <Tool 298 + Name="VCMIDLTool" 299 + TargetEnvironment="2" 300 + /> 301 + <Tool 302 + Name="VCCLCompilerTool" 303 + Optimization="0" 304 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 305 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64" 306 + MinimalRebuild="true" 307 + BasicRuntimeChecks="0" 308 + RuntimeLibrary="3" 309 + BufferSecurityCheck="false" 310 + UsePrecompiledHeader="0" 311 + AssemblerListingLocation="$(IntDir)\" 312 + WarningLevel="3" 313 + Detect64BitPortabilityProblems="true" 314 + DebugInformationFormat="3" 315 + /> 316 + <Tool 317 + Name="VCManagedResourceCompilerTool" 318 + /> 319 + <Tool 320 + Name="VCResourceCompilerTool" 321 + /> 322 + <Tool 323 + Name="VCPreLinkEventTool" 324 + /> 325 + <Tool 326 + Name="VCLinkerTool" 327 + AdditionalDependencies="ia64\ZlibDllDebug\zlibwapi.lib" 328 + OutputFile="$(OutDir)/testzlib.exe" 329 + LinkIncremental="2" 330 + GenerateManifest="false" 331 + GenerateDebugInformation="true" 332 + ProgramDatabaseFile="$(OutDir)/testzlib.pdb" 333 + SubSystem="1" 334 + TargetMachine="5" 335 + /> 336 + <Tool 337 + Name="VCALinkTool" 338 + /> 339 + <Tool 340 + Name="VCManifestTool" 341 + /> 342 + <Tool 343 + Name="VCXDCMakeTool" 344 + /> 345 + <Tool 346 + Name="VCBscMakeTool" 347 + /> 348 + <Tool 349 + Name="VCFxCopTool" 350 + /> 351 + <Tool 352 + Name="VCAppVerifierTool" 353 + /> 354 + <Tool 355 + Name="VCWebDeploymentTool" 356 + /> 357 + <Tool 358 + Name="VCPostBuildEventTool" 359 + /> 360 + </Configuration> 361 + <Configuration 362 + Name="Release|x64" 363 + OutputDirectory="x64\TestZlibDll$(ConfigurationName)" 364 + IntermediateDirectory="x64\TestZlibDll$(ConfigurationName)\Tmp" 365 + ConfigurationType="1" 366 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 367 + CharacterSet="2" 368 + > 369 + <Tool 370 + Name="VCPreBuildEventTool" 371 + /> 372 + <Tool 373 + Name="VCCustomBuildTool" 374 + /> 375 + <Tool 376 + Name="VCXMLDataGeneratorTool" 377 + /> 378 + <Tool 379 + Name="VCWebServiceProxyGeneratorTool" 380 + /> 381 + <Tool 382 + Name="VCMIDLTool" 383 + TargetEnvironment="3" 384 + /> 385 + <Tool 386 + Name="VCCLCompilerTool" 387 + Optimization="2" 388 + InlineFunctionExpansion="1" 389 + OmitFramePointers="true" 390 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 391 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 392 + StringPooling="true" 393 + BasicRuntimeChecks="0" 394 + RuntimeLibrary="2" 395 + BufferSecurityCheck="false" 396 + EnableFunctionLevelLinking="true" 397 + UsePrecompiledHeader="0" 398 + AssemblerListingLocation="$(IntDir)\" 399 + WarningLevel="3" 400 + Detect64BitPortabilityProblems="true" 401 + DebugInformationFormat="3" 402 + /> 403 + <Tool 404 + Name="VCManagedResourceCompilerTool" 405 + /> 406 + <Tool 407 + Name="VCResourceCompilerTool" 408 + /> 409 + <Tool 410 + Name="VCPreLinkEventTool" 411 + /> 412 + <Tool 413 + Name="VCLinkerTool" 414 + AdditionalDependencies="x64\ZlibDllRelease\zlibwapi.lib" 415 + OutputFile="$(OutDir)/testzlib.exe" 416 + LinkIncremental="1" 417 + GenerateManifest="false" 418 + GenerateDebugInformation="true" 419 + SubSystem="1" 420 + OptimizeReferences="2" 421 + EnableCOMDATFolding="2" 422 + OptimizeForWindows98="1" 423 + TargetMachine="17" 424 + /> 425 + <Tool 426 + Name="VCALinkTool" 427 + /> 428 + <Tool 429 + Name="VCManifestTool" 430 + /> 431 + <Tool 432 + Name="VCXDCMakeTool" 433 + /> 434 + <Tool 435 + Name="VCBscMakeTool" 436 + /> 437 + <Tool 438 + Name="VCFxCopTool" 439 + /> 440 + <Tool 441 + Name="VCAppVerifierTool" 442 + /> 443 + <Tool 444 + Name="VCWebDeploymentTool" 445 + /> 446 + <Tool 447 + Name="VCPostBuildEventTool" 448 + /> 449 + </Configuration> 450 + <Configuration 451 + Name="Release|Itanium" 452 + OutputDirectory="ia64\TestZlibDll$(ConfigurationName)" 453 + IntermediateDirectory="ia64\TestZlibDll$(ConfigurationName)\Tmp" 454 + ConfigurationType="1" 455 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 456 + CharacterSet="2" 457 + > 458 + <Tool 459 + Name="VCPreBuildEventTool" 460 + /> 461 + <Tool 462 + Name="VCCustomBuildTool" 463 + /> 464 + <Tool 465 + Name="VCXMLDataGeneratorTool" 466 + /> 467 + <Tool 468 + Name="VCWebServiceProxyGeneratorTool" 469 + /> 470 + <Tool 471 + Name="VCMIDLTool" 472 + TargetEnvironment="2" 473 + /> 474 + <Tool 475 + Name="VCCLCompilerTool" 476 + Optimization="2" 477 + InlineFunctionExpansion="1" 478 + OmitFramePointers="true" 479 + AdditionalIncludeDirectories="..\..\..;..\..\minizip" 480 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64" 481 + StringPooling="true" 482 + BasicRuntimeChecks="0" 483 + RuntimeLibrary="2" 484 + BufferSecurityCheck="false" 485 + EnableFunctionLevelLinking="true" 486 + UsePrecompiledHeader="0" 487 + AssemblerListingLocation="$(IntDir)\" 488 + WarningLevel="3" 489 + Detect64BitPortabilityProblems="true" 490 + DebugInformationFormat="3" 491 + /> 492 + <Tool 493 + Name="VCManagedResourceCompilerTool" 494 + /> 495 + <Tool 496 + Name="VCResourceCompilerTool" 497 + /> 498 + <Tool 499 + Name="VCPreLinkEventTool" 500 + /> 501 + <Tool 502 + Name="VCLinkerTool" 503 + AdditionalDependencies="ia64\ZlibDllRelease\zlibwapi.lib" 504 + OutputFile="$(OutDir)/testzlib.exe" 505 + LinkIncremental="1" 506 + GenerateManifest="false" 507 + GenerateDebugInformation="true" 508 + SubSystem="1" 509 + OptimizeReferences="2" 510 + EnableCOMDATFolding="2" 511 + OptimizeForWindows98="1" 512 + TargetMachine="5" 513 + /> 514 + <Tool 515 + Name="VCALinkTool" 516 + /> 517 + <Tool 518 + Name="VCManifestTool" 519 + /> 520 + <Tool 521 + Name="VCXDCMakeTool" 522 + /> 523 + <Tool 524 + Name="VCBscMakeTool" 525 + /> 526 + <Tool 527 + Name="VCFxCopTool" 528 + /> 529 + <Tool 530 + Name="VCAppVerifierTool" 531 + /> 532 + <Tool 533 + Name="VCWebDeploymentTool" 534 + /> 535 + <Tool 536 + Name="VCPostBuildEventTool" 537 + /> 538 + </Configuration> 539 + </Configurations> 540 + <References> 541 + </References> 542 + <Files> 543 + <Filter 544 + Name="Source Files" 545 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" 546 + > 547 + <File 548 + RelativePath="..\..\testzlib\testzlib.c" 549 + > 550 + </File> 551 + </Filter> 552 + <Filter 553 + Name="Header Files" 554 + Filter="h;hpp;hxx;hm;inl;inc" 555 + > 556 + </Filter> 557 + <Filter 558 + Name="Resource Files" 559 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 560 + > 561 + </Filter> 562 + </Files> 563 + <Globals> 564 + </Globals> 565 +</VisualStudioProject>
Added compat/zlib/contrib/vstudio/vc9/zlib.rc.
1 +#include <windows.h> 2 + 3 +#define IDR_VERSION1 1 4 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 5 + FILEVERSION 1.2.7,0 6 + PRODUCTVERSION 1.2.7,0 7 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 + FILEFLAGS 0 9 + FILEOS VOS_DOS_WINDOWS32 10 + FILETYPE VFT_DLL 11 + FILESUBTYPE 0 // not used 12 +BEGIN 13 + BLOCK "StringFileInfo" 14 + BEGIN 15 + BLOCK "040904E4" 16 + //language ID = U.S. English, char set = Windows, Multilingual 17 + 18 + BEGIN 19 + VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" 20 + VALUE "FileVersion", "1.2.7\0" 21 + VALUE "InternalName", "zlib\0" 22 + VALUE "OriginalFilename", "zlib.dll\0" 23 + VALUE "ProductName", "ZLib.DLL\0" 24 + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" 25 + VALUE "LegalCopyright", "(C) 1995-2012 Jean-loup Gailly & Mark Adler\0" 26 + END 27 + END 28 + BLOCK "VarFileInfo" 29 + BEGIN 30 + VALUE "Translation", 0x0409, 1252 31 + END 32 +END
Added compat/zlib/contrib/vstudio/vc9/zlibstat.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9,00" 5 + Name="zlibstat" 6 + ProjectGUID="{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" 7 + TargetFrameworkVersion="131072" 8 + > 9 + <Platforms> 10 + <Platform 11 + Name="Win32" 12 + /> 13 + <Platform 14 + Name="x64" 15 + /> 16 + <Platform 17 + Name="Itanium" 18 + /> 19 + </Platforms> 20 + <ToolFiles> 21 + </ToolFiles> 22 + <Configurations> 23 + <Configuration 24 + Name="Debug|Win32" 25 + OutputDirectory="x86\ZlibStat$(ConfigurationName)" 26 + IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp" 27 + ConfigurationType="4" 28 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 29 + UseOfMFC="0" 30 + ATLMinimizesCRunTimeLibraryUsage="false" 31 + > 32 + <Tool 33 + Name="VCPreBuildEventTool" 34 + /> 35 + <Tool 36 + Name="VCCustomBuildTool" 37 + /> 38 + <Tool 39 + Name="VCXMLDataGeneratorTool" 40 + /> 41 + <Tool 42 + Name="VCWebServiceProxyGeneratorTool" 43 + /> 44 + <Tool 45 + Name="VCMIDLTool" 46 + /> 47 + <Tool 48 + Name="VCCLCompilerTool" 49 + Optimization="0" 50 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 51 + PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 52 + ExceptionHandling="0" 53 + RuntimeLibrary="1" 54 + BufferSecurityCheck="false" 55 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 56 + AssemblerListingLocation="$(IntDir)\" 57 + ObjectFile="$(IntDir)\" 58 + ProgramDataBaseFileName="$(OutDir)\" 59 + WarningLevel="3" 60 + SuppressStartupBanner="true" 61 + Detect64BitPortabilityProblems="true" 62 + DebugInformationFormat="1" 63 + /> 64 + <Tool 65 + Name="VCManagedResourceCompilerTool" 66 + /> 67 + <Tool 68 + Name="VCResourceCompilerTool" 69 + Culture="1036" 70 + /> 71 + <Tool 72 + Name="VCPreLinkEventTool" 73 + /> 74 + <Tool 75 + Name="VCLibrarianTool" 76 + AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB" 77 + OutputFile="$(OutDir)\zlibstat.lib" 78 + SuppressStartupBanner="true" 79 + /> 80 + <Tool 81 + Name="VCALinkTool" 82 + /> 83 + <Tool 84 + Name="VCXDCMakeTool" 85 + /> 86 + <Tool 87 + Name="VCBscMakeTool" 88 + /> 89 + <Tool 90 + Name="VCFxCopTool" 91 + /> 92 + <Tool 93 + Name="VCPostBuildEventTool" 94 + /> 95 + </Configuration> 96 + <Configuration 97 + Name="Debug|x64" 98 + OutputDirectory="x64\ZlibStat$(ConfigurationName)" 99 + IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp" 100 + ConfigurationType="4" 101 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 102 + UseOfMFC="0" 103 + ATLMinimizesCRunTimeLibraryUsage="false" 104 + > 105 + <Tool 106 + Name="VCPreBuildEventTool" 107 + /> 108 + <Tool 109 + Name="VCCustomBuildTool" 110 + /> 111 + <Tool 112 + Name="VCXMLDataGeneratorTool" 113 + /> 114 + <Tool 115 + Name="VCWebServiceProxyGeneratorTool" 116 + /> 117 + <Tool 118 + Name="VCMIDLTool" 119 + TargetEnvironment="3" 120 + /> 121 + <Tool 122 + Name="VCCLCompilerTool" 123 + Optimization="0" 124 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 125 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 126 + ExceptionHandling="0" 127 + RuntimeLibrary="3" 128 + BufferSecurityCheck="false" 129 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 130 + AssemblerListingLocation="$(IntDir)\" 131 + ObjectFile="$(IntDir)\" 132 + ProgramDataBaseFileName="$(OutDir)\" 133 + WarningLevel="3" 134 + SuppressStartupBanner="true" 135 + Detect64BitPortabilityProblems="true" 136 + DebugInformationFormat="1" 137 + /> 138 + <Tool 139 + Name="VCManagedResourceCompilerTool" 140 + /> 141 + <Tool 142 + Name="VCResourceCompilerTool" 143 + Culture="1036" 144 + /> 145 + <Tool 146 + Name="VCPreLinkEventTool" 147 + /> 148 + <Tool 149 + Name="VCLibrarianTool" 150 + AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB" 151 + OutputFile="$(OutDir)\zlibstat.lib" 152 + SuppressStartupBanner="true" 153 + /> 154 + <Tool 155 + Name="VCALinkTool" 156 + /> 157 + <Tool 158 + Name="VCXDCMakeTool" 159 + /> 160 + <Tool 161 + Name="VCBscMakeTool" 162 + /> 163 + <Tool 164 + Name="VCFxCopTool" 165 + /> 166 + <Tool 167 + Name="VCPostBuildEventTool" 168 + /> 169 + </Configuration> 170 + <Configuration 171 + Name="Debug|Itanium" 172 + OutputDirectory="ia64\ZlibStat$(ConfigurationName)" 173 + IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp" 174 + ConfigurationType="4" 175 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 176 + UseOfMFC="0" 177 + ATLMinimizesCRunTimeLibraryUsage="false" 178 + > 179 + <Tool 180 + Name="VCPreBuildEventTool" 181 + /> 182 + <Tool 183 + Name="VCCustomBuildTool" 184 + /> 185 + <Tool 186 + Name="VCXMLDataGeneratorTool" 187 + /> 188 + <Tool 189 + Name="VCWebServiceProxyGeneratorTool" 190 + /> 191 + <Tool 192 + Name="VCMIDLTool" 193 + TargetEnvironment="2" 194 + /> 195 + <Tool 196 + Name="VCCLCompilerTool" 197 + Optimization="0" 198 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 199 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 200 + ExceptionHandling="0" 201 + RuntimeLibrary="3" 202 + BufferSecurityCheck="false" 203 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 204 + AssemblerListingLocation="$(IntDir)\" 205 + ObjectFile="$(IntDir)\" 206 + ProgramDataBaseFileName="$(OutDir)\" 207 + WarningLevel="3" 208 + SuppressStartupBanner="true" 209 + Detect64BitPortabilityProblems="true" 210 + DebugInformationFormat="1" 211 + /> 212 + <Tool 213 + Name="VCManagedResourceCompilerTool" 214 + /> 215 + <Tool 216 + Name="VCResourceCompilerTool" 217 + Culture="1036" 218 + /> 219 + <Tool 220 + Name="VCPreLinkEventTool" 221 + /> 222 + <Tool 223 + Name="VCLibrarianTool" 224 + AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB" 225 + OutputFile="$(OutDir)\zlibstat.lib" 226 + SuppressStartupBanner="true" 227 + /> 228 + <Tool 229 + Name="VCALinkTool" 230 + /> 231 + <Tool 232 + Name="VCXDCMakeTool" 233 + /> 234 + <Tool 235 + Name="VCBscMakeTool" 236 + /> 237 + <Tool 238 + Name="VCFxCopTool" 239 + /> 240 + <Tool 241 + Name="VCPostBuildEventTool" 242 + /> 243 + </Configuration> 244 + <Configuration 245 + Name="Release|Win32" 246 + OutputDirectory="x86\ZlibStat$(ConfigurationName)" 247 + IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp" 248 + ConfigurationType="4" 249 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 250 + UseOfMFC="0" 251 + ATLMinimizesCRunTimeLibraryUsage="false" 252 + > 253 + <Tool 254 + Name="VCPreBuildEventTool" 255 + /> 256 + <Tool 257 + Name="VCCustomBuildTool" 258 + /> 259 + <Tool 260 + Name="VCXMLDataGeneratorTool" 261 + /> 262 + <Tool 263 + Name="VCWebServiceProxyGeneratorTool" 264 + /> 265 + <Tool 266 + Name="VCMIDLTool" 267 + /> 268 + <Tool 269 + Name="VCCLCompilerTool" 270 + InlineFunctionExpansion="1" 271 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 272 + PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF" 273 + StringPooling="true" 274 + ExceptionHandling="0" 275 + RuntimeLibrary="0" 276 + BufferSecurityCheck="false" 277 + EnableFunctionLevelLinking="true" 278 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 279 + AssemblerListingLocation="$(IntDir)\" 280 + ObjectFile="$(IntDir)\" 281 + ProgramDataBaseFileName="$(OutDir)\" 282 + WarningLevel="3" 283 + SuppressStartupBanner="true" 284 + /> 285 + <Tool 286 + Name="VCManagedResourceCompilerTool" 287 + /> 288 + <Tool 289 + Name="VCResourceCompilerTool" 290 + Culture="1036" 291 + /> 292 + <Tool 293 + Name="VCPreLinkEventTool" 294 + /> 295 + <Tool 296 + Name="VCLibrarianTool" 297 + AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB" 298 + AdditionalDependencies="..\..\masmx86\match686.obj ..\..\masmx86\inffas32.obj " 299 + OutputFile="$(OutDir)\zlibstat.lib" 300 + SuppressStartupBanner="true" 301 + /> 302 + <Tool 303 + Name="VCALinkTool" 304 + /> 305 + <Tool 306 + Name="VCXDCMakeTool" 307 + /> 308 + <Tool 309 + Name="VCBscMakeTool" 310 + /> 311 + <Tool 312 + Name="VCFxCopTool" 313 + /> 314 + <Tool 315 + Name="VCPostBuildEventTool" 316 + /> 317 + </Configuration> 318 + <Configuration 319 + Name="Release|x64" 320 + OutputDirectory="x64\ZlibStat$(ConfigurationName)" 321 + IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp" 322 + ConfigurationType="4" 323 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 324 + UseOfMFC="0" 325 + ATLMinimizesCRunTimeLibraryUsage="false" 326 + > 327 + <Tool 328 + Name="VCPreBuildEventTool" 329 + /> 330 + <Tool 331 + Name="VCCustomBuildTool" 332 + /> 333 + <Tool 334 + Name="VCXMLDataGeneratorTool" 335 + /> 336 + <Tool 337 + Name="VCWebServiceProxyGeneratorTool" 338 + /> 339 + <Tool 340 + Name="VCMIDLTool" 341 + TargetEnvironment="3" 342 + /> 343 + <Tool 344 + Name="VCCLCompilerTool" 345 + InlineFunctionExpansion="1" 346 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 347 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;WIN64" 348 + StringPooling="true" 349 + ExceptionHandling="0" 350 + RuntimeLibrary="2" 351 + BufferSecurityCheck="false" 352 + EnableFunctionLevelLinking="true" 353 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 354 + AssemblerListingLocation="$(IntDir)\" 355 + ObjectFile="$(IntDir)\" 356 + ProgramDataBaseFileName="$(OutDir)\" 357 + WarningLevel="3" 358 + SuppressStartupBanner="true" 359 + /> 360 + <Tool 361 + Name="VCManagedResourceCompilerTool" 362 + /> 363 + <Tool 364 + Name="VCResourceCompilerTool" 365 + Culture="1036" 366 + /> 367 + <Tool 368 + Name="VCPreLinkEventTool" 369 + /> 370 + <Tool 371 + Name="VCLibrarianTool" 372 + AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB" 373 + AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj " 374 + OutputFile="$(OutDir)\zlibstat.lib" 375 + SuppressStartupBanner="true" 376 + /> 377 + <Tool 378 + Name="VCALinkTool" 379 + /> 380 + <Tool 381 + Name="VCXDCMakeTool" 382 + /> 383 + <Tool 384 + Name="VCBscMakeTool" 385 + /> 386 + <Tool 387 + Name="VCFxCopTool" 388 + /> 389 + <Tool 390 + Name="VCPostBuildEventTool" 391 + /> 392 + </Configuration> 393 + <Configuration 394 + Name="Release|Itanium" 395 + OutputDirectory="ia64\ZlibStat$(ConfigurationName)" 396 + IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp" 397 + ConfigurationType="4" 398 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 399 + UseOfMFC="0" 400 + ATLMinimizesCRunTimeLibraryUsage="false" 401 + > 402 + <Tool 403 + Name="VCPreBuildEventTool" 404 + /> 405 + <Tool 406 + Name="VCCustomBuildTool" 407 + /> 408 + <Tool 409 + Name="VCXMLDataGeneratorTool" 410 + /> 411 + <Tool 412 + Name="VCWebServiceProxyGeneratorTool" 413 + /> 414 + <Tool 415 + Name="VCMIDLTool" 416 + TargetEnvironment="2" 417 + /> 418 + <Tool 419 + Name="VCCLCompilerTool" 420 + InlineFunctionExpansion="1" 421 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 422 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 423 + StringPooling="true" 424 + ExceptionHandling="0" 425 + RuntimeLibrary="2" 426 + BufferSecurityCheck="false" 427 + EnableFunctionLevelLinking="true" 428 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 429 + AssemblerListingLocation="$(IntDir)\" 430 + ObjectFile="$(IntDir)\" 431 + ProgramDataBaseFileName="$(OutDir)\" 432 + WarningLevel="3" 433 + SuppressStartupBanner="true" 434 + /> 435 + <Tool 436 + Name="VCManagedResourceCompilerTool" 437 + /> 438 + <Tool 439 + Name="VCResourceCompilerTool" 440 + Culture="1036" 441 + /> 442 + <Tool 443 + Name="VCPreLinkEventTool" 444 + /> 445 + <Tool 446 + Name="VCLibrarianTool" 447 + AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB" 448 + OutputFile="$(OutDir)\zlibstat.lib" 449 + SuppressStartupBanner="true" 450 + /> 451 + <Tool 452 + Name="VCALinkTool" 453 + /> 454 + <Tool 455 + Name="VCXDCMakeTool" 456 + /> 457 + <Tool 458 + Name="VCBscMakeTool" 459 + /> 460 + <Tool 461 + Name="VCFxCopTool" 462 + /> 463 + <Tool 464 + Name="VCPostBuildEventTool" 465 + /> 466 + </Configuration> 467 + <Configuration 468 + Name="ReleaseWithoutAsm|Win32" 469 + OutputDirectory="x86\ZlibStat$(ConfigurationName)" 470 + IntermediateDirectory="x86\ZlibStat$(ConfigurationName)\Tmp" 471 + ConfigurationType="4" 472 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 473 + UseOfMFC="0" 474 + ATLMinimizesCRunTimeLibraryUsage="false" 475 + > 476 + <Tool 477 + Name="VCPreBuildEventTool" 478 + /> 479 + <Tool 480 + Name="VCCustomBuildTool" 481 + /> 482 + <Tool 483 + Name="VCXMLDataGeneratorTool" 484 + /> 485 + <Tool 486 + Name="VCWebServiceProxyGeneratorTool" 487 + /> 488 + <Tool 489 + Name="VCMIDLTool" 490 + /> 491 + <Tool 492 + Name="VCCLCompilerTool" 493 + InlineFunctionExpansion="1" 494 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 495 + PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS" 496 + StringPooling="true" 497 + ExceptionHandling="0" 498 + RuntimeLibrary="0" 499 + BufferSecurityCheck="false" 500 + EnableFunctionLevelLinking="true" 501 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 502 + AssemblerListingLocation="$(IntDir)\" 503 + ObjectFile="$(IntDir)\" 504 + ProgramDataBaseFileName="$(OutDir)\" 505 + WarningLevel="3" 506 + SuppressStartupBanner="true" 507 + /> 508 + <Tool 509 + Name="VCManagedResourceCompilerTool" 510 + /> 511 + <Tool 512 + Name="VCResourceCompilerTool" 513 + Culture="1036" 514 + /> 515 + <Tool 516 + Name="VCPreLinkEventTool" 517 + /> 518 + <Tool 519 + Name="VCLibrarianTool" 520 + AdditionalOptions="/MACHINE:X86 /NODEFAULTLIB" 521 + OutputFile="$(OutDir)\zlibstat.lib" 522 + SuppressStartupBanner="true" 523 + /> 524 + <Tool 525 + Name="VCALinkTool" 526 + /> 527 + <Tool 528 + Name="VCXDCMakeTool" 529 + /> 530 + <Tool 531 + Name="VCBscMakeTool" 532 + /> 533 + <Tool 534 + Name="VCFxCopTool" 535 + /> 536 + <Tool 537 + Name="VCPostBuildEventTool" 538 + /> 539 + </Configuration> 540 + <Configuration 541 + Name="ReleaseWithoutAsm|x64" 542 + OutputDirectory="x64\ZlibStat$(ConfigurationName)" 543 + IntermediateDirectory="x64\ZlibStat$(ConfigurationName)\Tmp" 544 + ConfigurationType="4" 545 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 546 + UseOfMFC="0" 547 + ATLMinimizesCRunTimeLibraryUsage="false" 548 + > 549 + <Tool 550 + Name="VCPreBuildEventTool" 551 + /> 552 + <Tool 553 + Name="VCCustomBuildTool" 554 + /> 555 + <Tool 556 + Name="VCXMLDataGeneratorTool" 557 + /> 558 + <Tool 559 + Name="VCWebServiceProxyGeneratorTool" 560 + /> 561 + <Tool 562 + Name="VCMIDLTool" 563 + TargetEnvironment="3" 564 + /> 565 + <Tool 566 + Name="VCCLCompilerTool" 567 + InlineFunctionExpansion="1" 568 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 569 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 570 + StringPooling="true" 571 + ExceptionHandling="0" 572 + RuntimeLibrary="2" 573 + BufferSecurityCheck="false" 574 + EnableFunctionLevelLinking="true" 575 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 576 + AssemblerListingLocation="$(IntDir)\" 577 + ObjectFile="$(IntDir)\" 578 + ProgramDataBaseFileName="$(OutDir)\" 579 + WarningLevel="3" 580 + SuppressStartupBanner="true" 581 + /> 582 + <Tool 583 + Name="VCManagedResourceCompilerTool" 584 + /> 585 + <Tool 586 + Name="VCResourceCompilerTool" 587 + Culture="1036" 588 + /> 589 + <Tool 590 + Name="VCPreLinkEventTool" 591 + /> 592 + <Tool 593 + Name="VCLibrarianTool" 594 + AdditionalOptions="/MACHINE:AMD64 /NODEFAULTLIB" 595 + OutputFile="$(OutDir)\zlibstat.lib" 596 + SuppressStartupBanner="true" 597 + /> 598 + <Tool 599 + Name="VCALinkTool" 600 + /> 601 + <Tool 602 + Name="VCXDCMakeTool" 603 + /> 604 + <Tool 605 + Name="VCBscMakeTool" 606 + /> 607 + <Tool 608 + Name="VCFxCopTool" 609 + /> 610 + <Tool 611 + Name="VCPostBuildEventTool" 612 + /> 613 + </Configuration> 614 + <Configuration 615 + Name="ReleaseWithoutAsm|Itanium" 616 + OutputDirectory="ia64\ZlibStat$(ConfigurationName)" 617 + IntermediateDirectory="ia64\ZlibStat$(ConfigurationName)\Tmp" 618 + ConfigurationType="4" 619 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 620 + UseOfMFC="0" 621 + ATLMinimizesCRunTimeLibraryUsage="false" 622 + > 623 + <Tool 624 + Name="VCPreBuildEventTool" 625 + /> 626 + <Tool 627 + Name="VCCustomBuildTool" 628 + /> 629 + <Tool 630 + Name="VCXMLDataGeneratorTool" 631 + /> 632 + <Tool 633 + Name="VCWebServiceProxyGeneratorTool" 634 + /> 635 + <Tool 636 + Name="VCMIDLTool" 637 + TargetEnvironment="2" 638 + /> 639 + <Tool 640 + Name="VCCLCompilerTool" 641 + InlineFunctionExpansion="1" 642 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 643 + PreprocessorDefinitions="ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64" 644 + StringPooling="true" 645 + ExceptionHandling="0" 646 + RuntimeLibrary="2" 647 + BufferSecurityCheck="false" 648 + EnableFunctionLevelLinking="true" 649 + PrecompiledHeaderFile="$(IntDir)/zlibstat.pch" 650 + AssemblerListingLocation="$(IntDir)\" 651 + ObjectFile="$(IntDir)\" 652 + ProgramDataBaseFileName="$(OutDir)\" 653 + WarningLevel="3" 654 + SuppressStartupBanner="true" 655 + /> 656 + <Tool 657 + Name="VCManagedResourceCompilerTool" 658 + /> 659 + <Tool 660 + Name="VCResourceCompilerTool" 661 + Culture="1036" 662 + /> 663 + <Tool 664 + Name="VCPreLinkEventTool" 665 + /> 666 + <Tool 667 + Name="VCLibrarianTool" 668 + AdditionalOptions="/MACHINE:IA64 /NODEFAULTLIB" 669 + OutputFile="$(OutDir)\zlibstat.lib" 670 + SuppressStartupBanner="true" 671 + /> 672 + <Tool 673 + Name="VCALinkTool" 674 + /> 675 + <Tool 676 + Name="VCXDCMakeTool" 677 + /> 678 + <Tool 679 + Name="VCBscMakeTool" 680 + /> 681 + <Tool 682 + Name="VCFxCopTool" 683 + /> 684 + <Tool 685 + Name="VCPostBuildEventTool" 686 + /> 687 + </Configuration> 688 + </Configurations> 689 + <References> 690 + </References> 691 + <Files> 692 + <Filter 693 + Name="Source Files" 694 + > 695 + <File 696 + RelativePath="..\..\..\adler32.c" 697 + > 698 + </File> 699 + <File 700 + RelativePath="..\..\..\compress.c" 701 + > 702 + </File> 703 + <File 704 + RelativePath="..\..\..\crc32.c" 705 + > 706 + </File> 707 + <File 708 + RelativePath="..\..\..\deflate.c" 709 + > 710 + </File> 711 + <File 712 + RelativePath="..\..\..\gzclose.c" 713 + > 714 + </File> 715 + <File 716 + RelativePath="..\..\..\gzguts.h" 717 + > 718 + </File> 719 + <File 720 + RelativePath="..\..\..\gzlib.c" 721 + > 722 + </File> 723 + <File 724 + RelativePath="..\..\..\gzread.c" 725 + > 726 + </File> 727 + <File 728 + RelativePath="..\..\..\gzwrite.c" 729 + > 730 + </File> 731 + <File 732 + RelativePath="..\..\..\infback.c" 733 + > 734 + </File> 735 + <File 736 + RelativePath="..\..\masmx64\inffas8664.c" 737 + > 738 + <FileConfiguration 739 + Name="Debug|Win32" 740 + ExcludedFromBuild="true" 741 + > 742 + <Tool 743 + Name="VCCLCompilerTool" 744 + /> 745 + </FileConfiguration> 746 + <FileConfiguration 747 + Name="Debug|Itanium" 748 + ExcludedFromBuild="true" 749 + > 750 + <Tool 751 + Name="VCCLCompilerTool" 752 + /> 753 + </FileConfiguration> 754 + <FileConfiguration 755 + Name="Release|Win32" 756 + ExcludedFromBuild="true" 757 + > 758 + <Tool 759 + Name="VCCLCompilerTool" 760 + /> 761 + </FileConfiguration> 762 + <FileConfiguration 763 + Name="Release|Itanium" 764 + ExcludedFromBuild="true" 765 + > 766 + <Tool 767 + Name="VCCLCompilerTool" 768 + /> 769 + </FileConfiguration> 770 + <FileConfiguration 771 + Name="ReleaseWithoutAsm|Win32" 772 + ExcludedFromBuild="true" 773 + > 774 + <Tool 775 + Name="VCCLCompilerTool" 776 + /> 777 + </FileConfiguration> 778 + <FileConfiguration 779 + Name="ReleaseWithoutAsm|Itanium" 780 + ExcludedFromBuild="true" 781 + > 782 + <Tool 783 + Name="VCCLCompilerTool" 784 + /> 785 + </FileConfiguration> 786 + </File> 787 + <File 788 + RelativePath="..\..\..\inffast.c" 789 + > 790 + </File> 791 + <File 792 + RelativePath="..\..\..\inflate.c" 793 + > 794 + </File> 795 + <File 796 + RelativePath="..\..\..\inftrees.c" 797 + > 798 + </File> 799 + <File 800 + RelativePath="..\..\minizip\ioapi.c" 801 + > 802 + </File> 803 + <File 804 + RelativePath="..\..\..\trees.c" 805 + > 806 + </File> 807 + <File 808 + RelativePath="..\..\..\uncompr.c" 809 + > 810 + </File> 811 + <File 812 + RelativePath="..\..\minizip\unzip.c" 813 + > 814 + </File> 815 + <File 816 + RelativePath="..\..\minizip\zip.c" 817 + > 818 + </File> 819 + <File 820 + RelativePath=".\zlib.rc" 821 + > 822 + </File> 823 + <File 824 + RelativePath=".\zlibvc.def" 825 + > 826 + </File> 827 + <File 828 + RelativePath="..\..\..\zutil.c" 829 + > 830 + </File> 831 + </Filter> 832 + </Files> 833 + <Globals> 834 + </Globals> 835 +</VisualStudioProject>
Added compat/zlib/contrib/vstudio/vc9/zlibvc.def.
1 +LIBRARY 2 +; zlib data compression and ZIP file I/O library 3 + 4 +VERSION 1.2.7 5 + 6 +EXPORTS 7 + adler32 @1 8 + compress @2 9 + crc32 @3 10 + deflate @4 11 + deflateCopy @5 12 + deflateEnd @6 13 + deflateInit2_ @7 14 + deflateInit_ @8 15 + deflateParams @9 16 + deflateReset @10 17 + deflateSetDictionary @11 18 + gzclose @12 19 + gzdopen @13 20 + gzerror @14 21 + gzflush @15 22 + gzopen @16 23 + gzread @17 24 + gzwrite @18 25 + inflate @19 26 + inflateEnd @20 27 + inflateInit2_ @21 28 + inflateInit_ @22 29 + inflateReset @23 30 + inflateSetDictionary @24 31 + inflateSync @25 32 + uncompress @26 33 + zlibVersion @27 34 + gzprintf @28 35 + gzputc @29 36 + gzgetc @30 37 + gzseek @31 38 + gzrewind @32 39 + gztell @33 40 + gzeof @34 41 + gzsetparams @35 42 + zError @36 43 + inflateSyncPoint @37 44 + get_crc_table @38 45 + compress2 @39 46 + gzputs @40 47 + gzgets @41 48 + inflateCopy @42 49 + inflateBackInit_ @43 50 + inflateBack @44 51 + inflateBackEnd @45 52 + compressBound @46 53 + deflateBound @47 54 + gzclearerr @48 55 + gzungetc @49 56 + zlibCompileFlags @50 57 + deflatePrime @51 58 + deflatePending @52 59 + 60 + unzOpen @61 61 + unzClose @62 62 + unzGetGlobalInfo @63 63 + unzGetCurrentFileInfo @64 64 + unzGoToFirstFile @65 65 + unzGoToNextFile @66 66 + unzOpenCurrentFile @67 67 + unzReadCurrentFile @68 68 + unzOpenCurrentFile3 @69 69 + unztell @70 70 + unzeof @71 71 + unzCloseCurrentFile @72 72 + unzGetGlobalComment @73 73 + unzStringFileNameCompare @74 74 + unzLocateFile @75 75 + unzGetLocalExtrafield @76 76 + unzOpen2 @77 77 + unzOpenCurrentFile2 @78 78 + unzOpenCurrentFilePassword @79 79 + 80 + zipOpen @80 81 + zipOpenNewFileInZip @81 82 + zipWriteInFileInZip @82 83 + zipCloseFileInZip @83 84 + zipClose @84 85 + zipOpenNewFileInZip2 @86 86 + zipCloseFileInZipRaw @87 87 + zipOpen2 @88 88 + zipOpenNewFileInZip3 @89 89 + 90 + unzGetFilePos @100 91 + unzGoToFilePos @101 92 + 93 + fill_win32_filefunc @110 94 + 95 +; zlibwapi v1.2.4 added: 96 + fill_win32_filefunc64 @111 97 + fill_win32_filefunc64A @112 98 + fill_win32_filefunc64W @113 99 + 100 + unzOpen64 @120 101 + unzOpen2_64 @121 102 + unzGetGlobalInfo64 @122 103 + unzGetCurrentFileInfo64 @124 104 + unzGetCurrentFileZStreamPos64 @125 105 + unztell64 @126 106 + unzGetFilePos64 @127 107 + unzGoToFilePos64 @128 108 + 109 + zipOpen64 @130 110 + zipOpen2_64 @131 111 + zipOpenNewFileInZip64 @132 112 + zipOpenNewFileInZip2_64 @133 113 + zipOpenNewFileInZip3_64 @134 114 + zipOpenNewFileInZip4_64 @135 115 + zipCloseFileInZipRaw64 @136 116 + 117 +; zlib1 v1.2.4 added: 118 + adler32_combine @140 119 + crc32_combine @142 120 + deflateSetHeader @144 121 + deflateTune @145 122 + gzbuffer @146 123 + gzclose_r @147 124 + gzclose_w @148 125 + gzdirect @149 126 + gzoffset @150 127 + inflateGetHeader @156 128 + inflateMark @157 129 + inflatePrime @158 130 + inflateReset2 @159 131 + inflateUndermine @160 132 + 133 +; zlib1 v1.2.6 added: 134 + gzgetc_ @161 135 + inflateResetKeep @163 136 + deflateResetKeep @164 137 + 138 +; zlib1 v1.2.7 added: 139 + gzopen_w @165
Added compat/zlib/contrib/vstudio/vc9/zlibvc.sln.
1 + 2 +Microsoft Visual Studio Solution File, Format Version 10.00 3 +# Visual Studio 2008 4 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" 5 +EndProject 6 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" 7 +EndProject 8 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" 9 +EndProject 10 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestZlibDll", "testzlibdll.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" 11 + ProjectSection(ProjectDependencies) = postProject 12 + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} 13 + EndProjectSection 14 +EndProject 15 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" 16 + ProjectSection(ProjectDependencies) = postProject 17 + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} 18 + EndProjectSection 19 +EndProject 20 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" 21 + ProjectSection(ProjectDependencies) = postProject 22 + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} 23 + EndProjectSection 24 +EndProject 25 +Global 26 + GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 + Debug|Itanium = Debug|Itanium 28 + Debug|Win32 = Debug|Win32 29 + Debug|x64 = Debug|x64 30 + Release|Itanium = Release|Itanium 31 + Release|Win32 = Release|Win32 32 + Release|x64 = Release|x64 33 + ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium 34 + ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 35 + ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 36 + EndGlobalSection 37 + GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium 39 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium 40 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 41 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 42 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 43 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 44 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium 45 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium 46 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 47 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 48 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 49 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 50 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 51 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 52 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 53 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 54 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 55 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 56 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium 57 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium 58 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 59 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 60 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 61 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 62 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium 63 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium 64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 65 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 66 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 67 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 68 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 69 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 70 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 71 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 72 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 73 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 74 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium 75 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium 76 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 77 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 78 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 79 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 80 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium 81 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium 82 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 83 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 84 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 85 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 86 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium 87 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium 88 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 89 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 90 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 91 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 92 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium 93 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium 94 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 95 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 96 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 97 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 98 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium 99 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium 100 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 101 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 102 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 103 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 104 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 105 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 106 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 107 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 108 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium 109 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium 110 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 111 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 112 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 113 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 114 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium 115 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium 116 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 117 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 118 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 119 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 120 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 121 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 122 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 123 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 124 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium 125 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium 126 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 127 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 128 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 129 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 130 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium 131 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium 132 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 133 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 134 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 135 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 136 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium 137 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium 138 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 139 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 140 + EndGlobalSection 141 + GlobalSection(SolutionProperties) = preSolution 142 + HideSolutionNode = FALSE 143 + EndGlobalSection 144 +EndGlobal
Added compat/zlib/contrib/vstudio/vc9/zlibvc.vcproj.
1 +<?xml version="1.0" encoding="Windows-1252"?> 2 +<VisualStudioProject 3 + ProjectType="Visual C++" 4 + Version="9,00" 5 + Name="zlibvc" 6 + ProjectGUID="{8FD826F8-3739-44E6-8CC8-997122E53B8D}" 7 + RootNamespace="zlibvc" 8 + TargetFrameworkVersion="131072" 9 + > 10 + <Platforms> 11 + <Platform 12 + Name="Win32" 13 + /> 14 + <Platform 15 + Name="x64" 16 + /> 17 + <Platform 18 + Name="Itanium" 19 + /> 20 + </Platforms> 21 + <ToolFiles> 22 + </ToolFiles> 23 + <Configurations> 24 + <Configuration 25 + Name="Debug|Win32" 26 + OutputDirectory="x86\ZlibDll$(ConfigurationName)" 27 + IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp" 28 + ConfigurationType="2" 29 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 30 + UseOfMFC="0" 31 + ATLMinimizesCRunTimeLibraryUsage="false" 32 + > 33 + <Tool 34 + Name="VCPreBuildEventTool" 35 + /> 36 + <Tool 37 + Name="VCCustomBuildTool" 38 + /> 39 + <Tool 40 + Name="VCXMLDataGeneratorTool" 41 + /> 42 + <Tool 43 + Name="VCWebServiceProxyGeneratorTool" 44 + /> 45 + <Tool 46 + Name="VCMIDLTool" 47 + PreprocessorDefinitions="_DEBUG" 48 + MkTypLibCompatible="true" 49 + SuppressStartupBanner="true" 50 + TargetEnvironment="1" 51 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 52 + /> 53 + <Tool 54 + Name="VCCLCompilerTool" 55 + Optimization="0" 56 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 57 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF" 58 + ExceptionHandling="0" 59 + RuntimeLibrary="1" 60 + BufferSecurityCheck="false" 61 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 62 + AssemblerListingLocation="$(IntDir)\" 63 + ObjectFile="$(IntDir)\" 64 + ProgramDataBaseFileName="$(OutDir)\" 65 + BrowseInformation="0" 66 + WarningLevel="3" 67 + SuppressStartupBanner="true" 68 + DebugInformationFormat="4" 69 + /> 70 + <Tool 71 + Name="VCManagedResourceCompilerTool" 72 + /> 73 + <Tool 74 + Name="VCResourceCompilerTool" 75 + PreprocessorDefinitions="_DEBUG" 76 + Culture="1036" 77 + /> 78 + <Tool 79 + Name="VCPreLinkEventTool" 80 + /> 81 + <Tool 82 + Name="VCLinkerTool" 83 + AdditionalOptions="/MACHINE:I386" 84 + AdditionalDependencies="..\..\masmx86\match686.obj ..\..\masmx86\inffas32.obj" 85 + OutputFile="$(OutDir)\zlibwapi.dll" 86 + LinkIncremental="2" 87 + SuppressStartupBanner="true" 88 + GenerateManifest="false" 89 + ModuleDefinitionFile=".\zlibvc.def" 90 + GenerateDebugInformation="true" 91 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 92 + GenerateMapFile="true" 93 + MapFileName="$(OutDir)/zlibwapi.map" 94 + SubSystem="2" 95 + RandomizedBaseAddress="1" 96 + DataExecutionPrevention="0" 97 + ImportLibrary="$(OutDir)/zlibwapi.lib" 98 + /> 99 + <Tool 100 + Name="VCALinkTool" 101 + /> 102 + <Tool 103 + Name="VCManifestTool" 104 + /> 105 + <Tool 106 + Name="VCXDCMakeTool" 107 + /> 108 + <Tool 109 + Name="VCBscMakeTool" 110 + /> 111 + <Tool 112 + Name="VCFxCopTool" 113 + /> 114 + <Tool 115 + Name="VCAppVerifierTool" 116 + /> 117 + <Tool 118 + Name="VCPostBuildEventTool" 119 + /> 120 + </Configuration> 121 + <Configuration 122 + Name="Debug|x64" 123 + OutputDirectory="x64\ZlibDll$(ConfigurationName)" 124 + IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp" 125 + ConfigurationType="2" 126 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 127 + UseOfMFC="0" 128 + ATLMinimizesCRunTimeLibraryUsage="false" 129 + > 130 + <Tool 131 + Name="VCPreBuildEventTool" 132 + /> 133 + <Tool 134 + Name="VCCustomBuildTool" 135 + /> 136 + <Tool 137 + Name="VCXMLDataGeneratorTool" 138 + /> 139 + <Tool 140 + Name="VCWebServiceProxyGeneratorTool" 141 + /> 142 + <Tool 143 + Name="VCMIDLTool" 144 + PreprocessorDefinitions="_DEBUG" 145 + MkTypLibCompatible="true" 146 + SuppressStartupBanner="true" 147 + TargetEnvironment="3" 148 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 149 + /> 150 + <Tool 151 + Name="VCCLCompilerTool" 152 + Optimization="0" 153 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 154 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64" 155 + ExceptionHandling="0" 156 + RuntimeLibrary="3" 157 + BufferSecurityCheck="false" 158 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 159 + AssemblerListingLocation="$(IntDir)\" 160 + ObjectFile="$(IntDir)\" 161 + ProgramDataBaseFileName="$(OutDir)\" 162 + BrowseInformation="0" 163 + WarningLevel="3" 164 + SuppressStartupBanner="true" 165 + DebugInformationFormat="3" 166 + /> 167 + <Tool 168 + Name="VCManagedResourceCompilerTool" 169 + /> 170 + <Tool 171 + Name="VCResourceCompilerTool" 172 + PreprocessorDefinitions="_DEBUG" 173 + Culture="1036" 174 + /> 175 + <Tool 176 + Name="VCPreLinkEventTool" 177 + /> 178 + <Tool 179 + Name="VCLinkerTool" 180 + AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj " 181 + OutputFile="$(OutDir)\zlibwapi.dll" 182 + LinkIncremental="2" 183 + SuppressStartupBanner="true" 184 + GenerateManifest="false" 185 + ModuleDefinitionFile=".\zlibvc.def" 186 + GenerateDebugInformation="true" 187 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 188 + GenerateMapFile="true" 189 + MapFileName="$(OutDir)/zlibwapi.map" 190 + SubSystem="2" 191 + ImportLibrary="$(OutDir)/zlibwapi.lib" 192 + TargetMachine="17" 193 + /> 194 + <Tool 195 + Name="VCALinkTool" 196 + /> 197 + <Tool 198 + Name="VCManifestTool" 199 + /> 200 + <Tool 201 + Name="VCXDCMakeTool" 202 + /> 203 + <Tool 204 + Name="VCBscMakeTool" 205 + /> 206 + <Tool 207 + Name="VCFxCopTool" 208 + /> 209 + <Tool 210 + Name="VCAppVerifierTool" 211 + /> 212 + <Tool 213 + Name="VCPostBuildEventTool" 214 + /> 215 + </Configuration> 216 + <Configuration 217 + Name="Debug|Itanium" 218 + OutputDirectory="ia64\ZlibDll$(ConfigurationName)" 219 + IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp" 220 + ConfigurationType="2" 221 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 222 + UseOfMFC="0" 223 + ATLMinimizesCRunTimeLibraryUsage="false" 224 + > 225 + <Tool 226 + Name="VCPreBuildEventTool" 227 + /> 228 + <Tool 229 + Name="VCCustomBuildTool" 230 + /> 231 + <Tool 232 + Name="VCXMLDataGeneratorTool" 233 + /> 234 + <Tool 235 + Name="VCWebServiceProxyGeneratorTool" 236 + /> 237 + <Tool 238 + Name="VCMIDLTool" 239 + PreprocessorDefinitions="_DEBUG" 240 + MkTypLibCompatible="true" 241 + SuppressStartupBanner="true" 242 + TargetEnvironment="2" 243 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 244 + /> 245 + <Tool 246 + Name="VCCLCompilerTool" 247 + Optimization="0" 248 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 249 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64" 250 + ExceptionHandling="0" 251 + RuntimeLibrary="3" 252 + BufferSecurityCheck="false" 253 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 254 + AssemblerListingLocation="$(IntDir)\" 255 + ObjectFile="$(IntDir)\" 256 + ProgramDataBaseFileName="$(OutDir)\" 257 + BrowseInformation="0" 258 + WarningLevel="3" 259 + SuppressStartupBanner="true" 260 + DebugInformationFormat="3" 261 + /> 262 + <Tool 263 + Name="VCManagedResourceCompilerTool" 264 + /> 265 + <Tool 266 + Name="VCResourceCompilerTool" 267 + PreprocessorDefinitions="_DEBUG" 268 + Culture="1036" 269 + /> 270 + <Tool 271 + Name="VCPreLinkEventTool" 272 + /> 273 + <Tool 274 + Name="VCLinkerTool" 275 + OutputFile="$(OutDir)\zlibwapi.dll" 276 + LinkIncremental="2" 277 + SuppressStartupBanner="true" 278 + GenerateManifest="false" 279 + ModuleDefinitionFile=".\zlibvc.def" 280 + GenerateDebugInformation="true" 281 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 282 + GenerateMapFile="true" 283 + MapFileName="$(OutDir)/zlibwapi.map" 284 + SubSystem="2" 285 + ImportLibrary="$(OutDir)/zlibwapi.lib" 286 + TargetMachine="5" 287 + /> 288 + <Tool 289 + Name="VCALinkTool" 290 + /> 291 + <Tool 292 + Name="VCManifestTool" 293 + /> 294 + <Tool 295 + Name="VCXDCMakeTool" 296 + /> 297 + <Tool 298 + Name="VCBscMakeTool" 299 + /> 300 + <Tool 301 + Name="VCFxCopTool" 302 + /> 303 + <Tool 304 + Name="VCAppVerifierTool" 305 + /> 306 + <Tool 307 + Name="VCPostBuildEventTool" 308 + /> 309 + </Configuration> 310 + <Configuration 311 + Name="ReleaseWithoutAsm|Win32" 312 + OutputDirectory="x86\ZlibDll$(ConfigurationName)" 313 + IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp" 314 + ConfigurationType="2" 315 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 316 + UseOfMFC="0" 317 + ATLMinimizesCRunTimeLibraryUsage="false" 318 + WholeProgramOptimization="1" 319 + > 320 + <Tool 321 + Name="VCPreBuildEventTool" 322 + /> 323 + <Tool 324 + Name="VCCustomBuildTool" 325 + /> 326 + <Tool 327 + Name="VCXMLDataGeneratorTool" 328 + /> 329 + <Tool 330 + Name="VCWebServiceProxyGeneratorTool" 331 + /> 332 + <Tool 333 + Name="VCMIDLTool" 334 + PreprocessorDefinitions="NDEBUG" 335 + MkTypLibCompatible="true" 336 + SuppressStartupBanner="true" 337 + TargetEnvironment="1" 338 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 339 + /> 340 + <Tool 341 + Name="VCCLCompilerTool" 342 + InlineFunctionExpansion="1" 343 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 344 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI" 345 + StringPooling="true" 346 + ExceptionHandling="0" 347 + RuntimeLibrary="2" 348 + BufferSecurityCheck="false" 349 + EnableFunctionLevelLinking="true" 350 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 351 + AssemblerOutput="2" 352 + AssemblerListingLocation="$(IntDir)\" 353 + ObjectFile="$(IntDir)\" 354 + ProgramDataBaseFileName="$(OutDir)\" 355 + BrowseInformation="0" 356 + WarningLevel="3" 357 + SuppressStartupBanner="true" 358 + /> 359 + <Tool 360 + Name="VCManagedResourceCompilerTool" 361 + /> 362 + <Tool 363 + Name="VCResourceCompilerTool" 364 + PreprocessorDefinitions="NDEBUG" 365 + Culture="1036" 366 + /> 367 + <Tool 368 + Name="VCPreLinkEventTool" 369 + /> 370 + <Tool 371 + Name="VCLinkerTool" 372 + AdditionalOptions="/MACHINE:I386" 373 + OutputFile="$(OutDir)\zlibwapi.dll" 374 + LinkIncremental="1" 375 + SuppressStartupBanner="true" 376 + GenerateManifest="false" 377 + IgnoreAllDefaultLibraries="false" 378 + ModuleDefinitionFile=".\zlibvc.def" 379 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 380 + GenerateMapFile="true" 381 + MapFileName="$(OutDir)/zlibwapi.map" 382 + SubSystem="2" 383 + OptimizeForWindows98="1" 384 + RandomizedBaseAddress="1" 385 + DataExecutionPrevention="0" 386 + ImportLibrary="$(OutDir)/zlibwapi.lib" 387 + /> 388 + <Tool 389 + Name="VCALinkTool" 390 + /> 391 + <Tool 392 + Name="VCManifestTool" 393 + /> 394 + <Tool 395 + Name="VCXDCMakeTool" 396 + /> 397 + <Tool 398 + Name="VCBscMakeTool" 399 + /> 400 + <Tool 401 + Name="VCFxCopTool" 402 + /> 403 + <Tool 404 + Name="VCAppVerifierTool" 405 + /> 406 + <Tool 407 + Name="VCPostBuildEventTool" 408 + /> 409 + </Configuration> 410 + <Configuration 411 + Name="ReleaseWithoutAsm|x64" 412 + OutputDirectory="x64\ZlibDll$(ConfigurationName)" 413 + IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp" 414 + ConfigurationType="2" 415 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 416 + UseOfMFC="0" 417 + ATLMinimizesCRunTimeLibraryUsage="false" 418 + WholeProgramOptimization="1" 419 + > 420 + <Tool 421 + Name="VCPreBuildEventTool" 422 + /> 423 + <Tool 424 + Name="VCCustomBuildTool" 425 + /> 426 + <Tool 427 + Name="VCXMLDataGeneratorTool" 428 + /> 429 + <Tool 430 + Name="VCWebServiceProxyGeneratorTool" 431 + /> 432 + <Tool 433 + Name="VCMIDLTool" 434 + PreprocessorDefinitions="NDEBUG" 435 + MkTypLibCompatible="true" 436 + SuppressStartupBanner="true" 437 + TargetEnvironment="3" 438 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 439 + /> 440 + <Tool 441 + Name="VCCLCompilerTool" 442 + InlineFunctionExpansion="1" 443 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 444 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64" 445 + StringPooling="true" 446 + ExceptionHandling="0" 447 + RuntimeLibrary="2" 448 + BufferSecurityCheck="false" 449 + EnableFunctionLevelLinking="true" 450 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 451 + AssemblerOutput="2" 452 + AssemblerListingLocation="$(IntDir)\" 453 + ObjectFile="$(IntDir)\" 454 + ProgramDataBaseFileName="$(OutDir)\" 455 + BrowseInformation="0" 456 + WarningLevel="3" 457 + SuppressStartupBanner="true" 458 + /> 459 + <Tool 460 + Name="VCManagedResourceCompilerTool" 461 + /> 462 + <Tool 463 + Name="VCResourceCompilerTool" 464 + PreprocessorDefinitions="NDEBUG" 465 + Culture="1036" 466 + /> 467 + <Tool 468 + Name="VCPreLinkEventTool" 469 + /> 470 + <Tool 471 + Name="VCLinkerTool" 472 + OutputFile="$(OutDir)\zlibwapi.dll" 473 + LinkIncremental="1" 474 + SuppressStartupBanner="true" 475 + GenerateManifest="false" 476 + IgnoreAllDefaultLibraries="false" 477 + ModuleDefinitionFile=".\zlibvc.def" 478 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 479 + GenerateMapFile="true" 480 + MapFileName="$(OutDir)/zlibwapi.map" 481 + SubSystem="2" 482 + OptimizeForWindows98="1" 483 + ImportLibrary="$(OutDir)/zlibwapi.lib" 484 + TargetMachine="17" 485 + /> 486 + <Tool 487 + Name="VCALinkTool" 488 + /> 489 + <Tool 490 + Name="VCManifestTool" 491 + /> 492 + <Tool 493 + Name="VCXDCMakeTool" 494 + /> 495 + <Tool 496 + Name="VCBscMakeTool" 497 + /> 498 + <Tool 499 + Name="VCFxCopTool" 500 + /> 501 + <Tool 502 + Name="VCAppVerifierTool" 503 + /> 504 + <Tool 505 + Name="VCPostBuildEventTool" 506 + /> 507 + </Configuration> 508 + <Configuration 509 + Name="ReleaseWithoutAsm|Itanium" 510 + OutputDirectory="ia64\ZlibDll$(ConfigurationName)" 511 + IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp" 512 + ConfigurationType="2" 513 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 514 + UseOfMFC="0" 515 + ATLMinimizesCRunTimeLibraryUsage="false" 516 + WholeProgramOptimization="1" 517 + > 518 + <Tool 519 + Name="VCPreBuildEventTool" 520 + /> 521 + <Tool 522 + Name="VCCustomBuildTool" 523 + /> 524 + <Tool 525 + Name="VCXMLDataGeneratorTool" 526 + /> 527 + <Tool 528 + Name="VCWebServiceProxyGeneratorTool" 529 + /> 530 + <Tool 531 + Name="VCMIDLTool" 532 + PreprocessorDefinitions="NDEBUG" 533 + MkTypLibCompatible="true" 534 + SuppressStartupBanner="true" 535 + TargetEnvironment="2" 536 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 537 + /> 538 + <Tool 539 + Name="VCCLCompilerTool" 540 + InlineFunctionExpansion="1" 541 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 542 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64" 543 + StringPooling="true" 544 + ExceptionHandling="0" 545 + RuntimeLibrary="2" 546 + BufferSecurityCheck="false" 547 + EnableFunctionLevelLinking="true" 548 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 549 + AssemblerOutput="2" 550 + AssemblerListingLocation="$(IntDir)\" 551 + ObjectFile="$(IntDir)\" 552 + ProgramDataBaseFileName="$(OutDir)\" 553 + BrowseInformation="0" 554 + WarningLevel="3" 555 + SuppressStartupBanner="true" 556 + /> 557 + <Tool 558 + Name="VCManagedResourceCompilerTool" 559 + /> 560 + <Tool 561 + Name="VCResourceCompilerTool" 562 + PreprocessorDefinitions="NDEBUG" 563 + Culture="1036" 564 + /> 565 + <Tool 566 + Name="VCPreLinkEventTool" 567 + /> 568 + <Tool 569 + Name="VCLinkerTool" 570 + OutputFile="$(OutDir)\zlibwapi.dll" 571 + LinkIncremental="1" 572 + SuppressStartupBanner="true" 573 + GenerateManifest="false" 574 + IgnoreAllDefaultLibraries="false" 575 + ModuleDefinitionFile=".\zlibvc.def" 576 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 577 + GenerateMapFile="true" 578 + MapFileName="$(OutDir)/zlibwapi.map" 579 + SubSystem="2" 580 + OptimizeForWindows98="1" 581 + ImportLibrary="$(OutDir)/zlibwapi.lib" 582 + TargetMachine="5" 583 + /> 584 + <Tool 585 + Name="VCALinkTool" 586 + /> 587 + <Tool 588 + Name="VCManifestTool" 589 + /> 590 + <Tool 591 + Name="VCXDCMakeTool" 592 + /> 593 + <Tool 594 + Name="VCBscMakeTool" 595 + /> 596 + <Tool 597 + Name="VCFxCopTool" 598 + /> 599 + <Tool 600 + Name="VCAppVerifierTool" 601 + /> 602 + <Tool 603 + Name="VCPostBuildEventTool" 604 + /> 605 + </Configuration> 606 + <Configuration 607 + Name="Release|Win32" 608 + OutputDirectory="x86\ZlibDll$(ConfigurationName)" 609 + IntermediateDirectory="x86\ZlibDll$(ConfigurationName)\Tmp" 610 + ConfigurationType="2" 611 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 612 + UseOfMFC="0" 613 + ATLMinimizesCRunTimeLibraryUsage="false" 614 + WholeProgramOptimization="1" 615 + > 616 + <Tool 617 + Name="VCPreBuildEventTool" 618 + /> 619 + <Tool 620 + Name="VCCustomBuildTool" 621 + /> 622 + <Tool 623 + Name="VCXMLDataGeneratorTool" 624 + /> 625 + <Tool 626 + Name="VCWebServiceProxyGeneratorTool" 627 + /> 628 + <Tool 629 + Name="VCMIDLTool" 630 + PreprocessorDefinitions="NDEBUG" 631 + MkTypLibCompatible="true" 632 + SuppressStartupBanner="true" 633 + TargetEnvironment="1" 634 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 635 + /> 636 + <Tool 637 + Name="VCCLCompilerTool" 638 + InlineFunctionExpansion="1" 639 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 640 + PreprocessorDefinitions="WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF" 641 + StringPooling="true" 642 + ExceptionHandling="0" 643 + RuntimeLibrary="0" 644 + BufferSecurityCheck="false" 645 + EnableFunctionLevelLinking="true" 646 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 647 + AssemblerOutput="2" 648 + AssemblerListingLocation="$(IntDir)\" 649 + ObjectFile="$(IntDir)\" 650 + ProgramDataBaseFileName="$(OutDir)\" 651 + BrowseInformation="0" 652 + WarningLevel="3" 653 + SuppressStartupBanner="true" 654 + /> 655 + <Tool 656 + Name="VCManagedResourceCompilerTool" 657 + /> 658 + <Tool 659 + Name="VCResourceCompilerTool" 660 + PreprocessorDefinitions="NDEBUG" 661 + Culture="1036" 662 + /> 663 + <Tool 664 + Name="VCPreLinkEventTool" 665 + /> 666 + <Tool 667 + Name="VCLinkerTool" 668 + AdditionalOptions="/MACHINE:I386" 669 + AdditionalDependencies="..\..\masmx86\match686.obj ..\..\masmx86\inffas32.obj " 670 + OutputFile="$(OutDir)\zlibwapi.dll" 671 + LinkIncremental="1" 672 + SuppressStartupBanner="true" 673 + GenerateManifest="false" 674 + IgnoreAllDefaultLibraries="false" 675 + ModuleDefinitionFile=".\zlibvc.def" 676 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 677 + GenerateMapFile="true" 678 + MapFileName="$(OutDir)/zlibwapi.map" 679 + SubSystem="2" 680 + OptimizeForWindows98="1" 681 + RandomizedBaseAddress="1" 682 + DataExecutionPrevention="0" 683 + ImportLibrary="$(OutDir)/zlibwapi.lib" 684 + /> 685 + <Tool 686 + Name="VCALinkTool" 687 + /> 688 + <Tool 689 + Name="VCManifestTool" 690 + /> 691 + <Tool 692 + Name="VCXDCMakeTool" 693 + /> 694 + <Tool 695 + Name="VCBscMakeTool" 696 + /> 697 + <Tool 698 + Name="VCFxCopTool" 699 + /> 700 + <Tool 701 + Name="VCAppVerifierTool" 702 + /> 703 + <Tool 704 + Name="VCPostBuildEventTool" 705 + /> 706 + </Configuration> 707 + <Configuration 708 + Name="Release|x64" 709 + OutputDirectory="x64\ZlibDll$(ConfigurationName)" 710 + IntermediateDirectory="x64\ZlibDll$(ConfigurationName)\Tmp" 711 + ConfigurationType="2" 712 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 713 + UseOfMFC="0" 714 + ATLMinimizesCRunTimeLibraryUsage="false" 715 + WholeProgramOptimization="1" 716 + > 717 + <Tool 718 + Name="VCPreBuildEventTool" 719 + /> 720 + <Tool 721 + Name="VCCustomBuildTool" 722 + /> 723 + <Tool 724 + Name="VCXMLDataGeneratorTool" 725 + /> 726 + <Tool 727 + Name="VCWebServiceProxyGeneratorTool" 728 + /> 729 + <Tool 730 + Name="VCMIDLTool" 731 + PreprocessorDefinitions="NDEBUG" 732 + MkTypLibCompatible="true" 733 + SuppressStartupBanner="true" 734 + TargetEnvironment="3" 735 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 736 + /> 737 + <Tool 738 + Name="VCCLCompilerTool" 739 + InlineFunctionExpansion="1" 740 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 741 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64" 742 + StringPooling="true" 743 + ExceptionHandling="0" 744 + RuntimeLibrary="2" 745 + BufferSecurityCheck="false" 746 + EnableFunctionLevelLinking="true" 747 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 748 + AssemblerOutput="2" 749 + AssemblerListingLocation="$(IntDir)\" 750 + ObjectFile="$(IntDir)\" 751 + ProgramDataBaseFileName="$(OutDir)\" 752 + BrowseInformation="0" 753 + WarningLevel="3" 754 + SuppressStartupBanner="true" 755 + /> 756 + <Tool 757 + Name="VCManagedResourceCompilerTool" 758 + /> 759 + <Tool 760 + Name="VCResourceCompilerTool" 761 + PreprocessorDefinitions="NDEBUG" 762 + Culture="1036" 763 + /> 764 + <Tool 765 + Name="VCPreLinkEventTool" 766 + /> 767 + <Tool 768 + Name="VCLinkerTool" 769 + AdditionalDependencies="..\..\masmx64\gvmat64.obj ..\..\masmx64\inffasx64.obj " 770 + OutputFile="$(OutDir)\zlibwapi.dll" 771 + LinkIncremental="1" 772 + SuppressStartupBanner="true" 773 + GenerateManifest="false" 774 + IgnoreAllDefaultLibraries="false" 775 + ModuleDefinitionFile=".\zlibvc.def" 776 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 777 + GenerateMapFile="true" 778 + MapFileName="$(OutDir)/zlibwapi.map" 779 + SubSystem="2" 780 + OptimizeForWindows98="1" 781 + ImportLibrary="$(OutDir)/zlibwapi.lib" 782 + TargetMachine="17" 783 + /> 784 + <Tool 785 + Name="VCALinkTool" 786 + /> 787 + <Tool 788 + Name="VCManifestTool" 789 + /> 790 + <Tool 791 + Name="VCXDCMakeTool" 792 + /> 793 + <Tool 794 + Name="VCBscMakeTool" 795 + /> 796 + <Tool 797 + Name="VCFxCopTool" 798 + /> 799 + <Tool 800 + Name="VCAppVerifierTool" 801 + /> 802 + <Tool 803 + Name="VCPostBuildEventTool" 804 + /> 805 + </Configuration> 806 + <Configuration 807 + Name="Release|Itanium" 808 + OutputDirectory="ia64\ZlibDll$(ConfigurationName)" 809 + IntermediateDirectory="ia64\ZlibDll$(ConfigurationName)\Tmp" 810 + ConfigurationType="2" 811 + InheritedPropertySheets="UpgradeFromVC70.vsprops" 812 + UseOfMFC="0" 813 + ATLMinimizesCRunTimeLibraryUsage="false" 814 + WholeProgramOptimization="1" 815 + > 816 + <Tool 817 + Name="VCPreBuildEventTool" 818 + /> 819 + <Tool 820 + Name="VCCustomBuildTool" 821 + /> 822 + <Tool 823 + Name="VCXMLDataGeneratorTool" 824 + /> 825 + <Tool 826 + Name="VCWebServiceProxyGeneratorTool" 827 + /> 828 + <Tool 829 + Name="VCMIDLTool" 830 + PreprocessorDefinitions="NDEBUG" 831 + MkTypLibCompatible="true" 832 + SuppressStartupBanner="true" 833 + TargetEnvironment="2" 834 + TypeLibraryName="$(OutDir)/zlibvc.tlb" 835 + /> 836 + <Tool 837 + Name="VCCLCompilerTool" 838 + InlineFunctionExpansion="1" 839 + AdditionalIncludeDirectories="..\..\..;..\..\masmx86" 840 + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64" 841 + StringPooling="true" 842 + ExceptionHandling="0" 843 + RuntimeLibrary="2" 844 + BufferSecurityCheck="false" 845 + EnableFunctionLevelLinking="true" 846 + PrecompiledHeaderFile="$(IntDir)/zlibvc.pch" 847 + AssemblerOutput="2" 848 + AssemblerListingLocation="$(IntDir)\" 849 + ObjectFile="$(IntDir)\" 850 + ProgramDataBaseFileName="$(OutDir)\" 851 + BrowseInformation="0" 852 + WarningLevel="3" 853 + SuppressStartupBanner="true" 854 + /> 855 + <Tool 856 + Name="VCManagedResourceCompilerTool" 857 + /> 858 + <Tool 859 + Name="VCResourceCompilerTool" 860 + PreprocessorDefinitions="NDEBUG" 861 + Culture="1036" 862 + /> 863 + <Tool 864 + Name="VCPreLinkEventTool" 865 + /> 866 + <Tool 867 + Name="VCLinkerTool" 868 + OutputFile="$(OutDir)\zlibwapi.dll" 869 + LinkIncremental="1" 870 + SuppressStartupBanner="true" 871 + GenerateManifest="false" 872 + IgnoreAllDefaultLibraries="false" 873 + ModuleDefinitionFile=".\zlibvc.def" 874 + ProgramDatabaseFile="$(OutDir)/zlibwapi.pdb" 875 + GenerateMapFile="true" 876 + MapFileName="$(OutDir)/zlibwapi.map" 877 + SubSystem="2" 878 + OptimizeForWindows98="1" 879 + ImportLibrary="$(OutDir)/zlibwapi.lib" 880 + TargetMachine="5" 881 + /> 882 + <Tool 883 + Name="VCALinkTool" 884 + /> 885 + <Tool 886 + Name="VCManifestTool" 887 + /> 888 + <Tool 889 + Name="VCXDCMakeTool" 890 + /> 891 + <Tool 892 + Name="VCBscMakeTool" 893 + /> 894 + <Tool 895 + Name="VCFxCopTool" 896 + /> 897 + <Tool 898 + Name="VCAppVerifierTool" 899 + /> 900 + <Tool 901 + Name="VCPostBuildEventTool" 902 + /> 903 + </Configuration> 904 + </Configurations> 905 + <References> 906 + </References> 907 + <Files> 908 + <Filter 909 + Name="Source Files" 910 + Filter="cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90" 911 + > 912 + <File 913 + RelativePath="..\..\..\adler32.c" 914 + > 915 + </File> 916 + <File 917 + RelativePath="..\..\..\compress.c" 918 + > 919 + </File> 920 + <File 921 + RelativePath="..\..\..\crc32.c" 922 + > 923 + </File> 924 + <File 925 + RelativePath="..\..\..\deflate.c" 926 + > 927 + </File> 928 + <File 929 + RelativePath="..\..\..\gzclose.c" 930 + > 931 + </File> 932 + <File 933 + RelativePath="..\..\..\gzguts.h" 934 + > 935 + </File> 936 + <File 937 + RelativePath="..\..\..\gzlib.c" 938 + > 939 + </File> 940 + <File 941 + RelativePath="..\..\..\gzread.c" 942 + > 943 + </File> 944 + <File 945 + RelativePath="..\..\..\gzwrite.c" 946 + > 947 + </File> 948 + <File 949 + RelativePath="..\..\..\infback.c" 950 + > 951 + </File> 952 + <File 953 + RelativePath="..\..\masmx64\inffas8664.c" 954 + > 955 + <FileConfiguration 956 + Name="Debug|Win32" 957 + ExcludedFromBuild="true" 958 + > 959 + <Tool 960 + Name="VCCLCompilerTool" 961 + /> 962 + </FileConfiguration> 963 + <FileConfiguration 964 + Name="Debug|Itanium" 965 + ExcludedFromBuild="true" 966 + > 967 + <Tool 968 + Name="VCCLCompilerTool" 969 + /> 970 + </FileConfiguration> 971 + <FileConfiguration 972 + Name="ReleaseWithoutAsm|Win32" 973 + ExcludedFromBuild="true" 974 + > 975 + <Tool 976 + Name="VCCLCompilerTool" 977 + /> 978 + </FileConfiguration> 979 + <FileConfiguration 980 + Name="ReleaseWithoutAsm|Itanium" 981 + ExcludedFromBuild="true" 982 + > 983 + <Tool 984 + Name="VCCLCompilerTool" 985 + /> 986 + </FileConfiguration> 987 + <FileConfiguration 988 + Name="Release|Win32" 989 + ExcludedFromBuild="true" 990 + > 991 + <Tool 992 + Name="VCCLCompilerTool" 993 + /> 994 + </FileConfiguration> 995 + <FileConfiguration 996 + Name="Release|Itanium" 997 + ExcludedFromBuild="true" 998 + > 999 + <Tool 1000 + Name="VCCLCompilerTool" 1001 + /> 1002 + </FileConfiguration> 1003 + </File> 1004 + <File 1005 + RelativePath="..\..\..\inffast.c" 1006 + > 1007 + </File> 1008 + <File 1009 + RelativePath="..\..\..\inflate.c" 1010 + > 1011 + </File> 1012 + <File 1013 + RelativePath="..\..\..\inftrees.c" 1014 + > 1015 + </File> 1016 + <File 1017 + RelativePath="..\..\minizip\ioapi.c" 1018 + > 1019 + </File> 1020 + <File 1021 + RelativePath="..\..\minizip\iowin32.c" 1022 + > 1023 + </File> 1024 + <File 1025 + RelativePath="..\..\..\trees.c" 1026 + > 1027 + </File> 1028 + <File 1029 + RelativePath="..\..\..\uncompr.c" 1030 + > 1031 + </File> 1032 + <File 1033 + RelativePath="..\..\minizip\unzip.c" 1034 + > 1035 + <FileConfiguration 1036 + Name="Release|Win32" 1037 + > 1038 + <Tool 1039 + Name="VCCLCompilerTool" 1040 + AdditionalIncludeDirectories="" 1041 + PreprocessorDefinitions="ZLIB_INTERNAL" 1042 + /> 1043 + </FileConfiguration> 1044 + <FileConfiguration 1045 + Name="Release|x64" 1046 + > 1047 + <Tool 1048 + Name="VCCLCompilerTool" 1049 + AdditionalIncludeDirectories="" 1050 + PreprocessorDefinitions="ZLIB_INTERNAL" 1051 + /> 1052 + </FileConfiguration> 1053 + <FileConfiguration 1054 + Name="Release|Itanium" 1055 + > 1056 + <Tool 1057 + Name="VCCLCompilerTool" 1058 + AdditionalIncludeDirectories="" 1059 + PreprocessorDefinitions="ZLIB_INTERNAL" 1060 + /> 1061 + </FileConfiguration> 1062 + </File> 1063 + <File 1064 + RelativePath="..\..\minizip\zip.c" 1065 + > 1066 + <FileConfiguration 1067 + Name="Release|Win32" 1068 + > 1069 + <Tool 1070 + Name="VCCLCompilerTool" 1071 + AdditionalIncludeDirectories="" 1072 + PreprocessorDefinitions="ZLIB_INTERNAL" 1073 + /> 1074 + </FileConfiguration> 1075 + <FileConfiguration 1076 + Name="Release|x64" 1077 + > 1078 + <Tool 1079 + Name="VCCLCompilerTool" 1080 + AdditionalIncludeDirectories="" 1081 + PreprocessorDefinitions="ZLIB_INTERNAL" 1082 + /> 1083 + </FileConfiguration> 1084 + <FileConfiguration 1085 + Name="Release|Itanium" 1086 + > 1087 + <Tool 1088 + Name="VCCLCompilerTool" 1089 + AdditionalIncludeDirectories="" 1090 + PreprocessorDefinitions="ZLIB_INTERNAL" 1091 + /> 1092 + </FileConfiguration> 1093 + </File> 1094 + <File 1095 + RelativePath=".\zlib.rc" 1096 + > 1097 + </File> 1098 + <File 1099 + RelativePath=".\zlibvc.def" 1100 + > 1101 + </File> 1102 + <File 1103 + RelativePath="..\..\..\zutil.c" 1104 + > 1105 + </File> 1106 + </Filter> 1107 + <Filter 1108 + Name="Header Files" 1109 + Filter="h;hpp;hxx;hm;inl;fi;fd" 1110 + > 1111 + <File 1112 + RelativePath="..\..\..\deflate.h" 1113 + > 1114 + </File> 1115 + <File 1116 + RelativePath="..\..\..\infblock.h" 1117 + > 1118 + </File> 1119 + <File 1120 + RelativePath="..\..\..\infcodes.h" 1121 + > 1122 + </File> 1123 + <File 1124 + RelativePath="..\..\..\inffast.h" 1125 + > 1126 + </File> 1127 + <File 1128 + RelativePath="..\..\..\inftrees.h" 1129 + > 1130 + </File> 1131 + <File 1132 + RelativePath="..\..\..\infutil.h" 1133 + > 1134 + </File> 1135 + <File 1136 + RelativePath="..\..\..\zconf.h" 1137 + > 1138 + </File> 1139 + <File 1140 + RelativePath="..\..\..\zlib.h" 1141 + > 1142 + </File> 1143 + <File 1144 + RelativePath="..\..\..\zutil.h" 1145 + > 1146 + </File> 1147 + </Filter> 1148 + <Filter 1149 + Name="Resource Files" 1150 + Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" 1151 + > 1152 + </Filter> 1153 + </Files> 1154 + <Globals> 1155 + </Globals> 1156 +</VisualStudioProject>
Added compat/zlib/crc32.c.
1 +/* crc32.c -- compute the CRC-32 of a data stream 2 + * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + * 5 + * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster 6 + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 7 + * tables for updating the shift register in one step with three exclusive-ors 8 + * instead of four steps with four exclusive-ors. This results in about a 9 + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 10 + */ 11 + 12 +/* @(#) $Id$ */ 13 + 14 +/* 15 + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 16 + protection on the static variables used to control the first-use generation 17 + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 18 + first call get_crc_table() to initialize the tables before allowing more than 19 + one thread to use crc32(). 20 + 21 + DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. 22 + */ 23 + 24 +#ifdef MAKECRCH 25 +# include <stdio.h> 26 +# ifndef DYNAMIC_CRC_TABLE 27 +# define DYNAMIC_CRC_TABLE 28 +# endif /* !DYNAMIC_CRC_TABLE */ 29 +#endif /* MAKECRCH */ 30 + 31 +#include "zutil.h" /* for STDC and FAR definitions */ 32 + 33 +#define local static 34 + 35 +/* Definitions for doing the crc four data bytes at a time. */ 36 +#if !defined(NOBYFOUR) && defined(Z_U4) 37 +# define BYFOUR 38 +#endif 39 +#ifdef BYFOUR 40 + local unsigned long crc32_little OF((unsigned long, 41 + const unsigned char FAR *, unsigned)); 42 + local unsigned long crc32_big OF((unsigned long, 43 + const unsigned char FAR *, unsigned)); 44 +# define TBLS 8 45 +#else 46 +# define TBLS 1 47 +#endif /* BYFOUR */ 48 + 49 +/* Local functions for crc concatenation */ 50 +local unsigned long gf2_matrix_times OF((unsigned long *mat, 51 + unsigned long vec)); 52 +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 53 +local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); 54 + 55 + 56 +#ifdef DYNAMIC_CRC_TABLE 57 + 58 +local volatile int crc_table_empty = 1; 59 +local z_crc_t FAR crc_table[TBLS][256]; 60 +local void make_crc_table OF((void)); 61 +#ifdef MAKECRCH 62 + local void write_table OF((FILE *, const z_crc_t FAR *)); 63 +#endif /* MAKECRCH */ 64 +/* 65 + Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 66 + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 67 + 68 + Polynomials over GF(2) are represented in binary, one bit per coefficient, 69 + with the lowest powers in the most significant bit. Then adding polynomials 70 + is just exclusive-or, and multiplying a polynomial by x is a right shift by 71 + one. If we call the above polynomial p, and represent a byte as the 72 + polynomial q, also with the lowest power in the most significant bit (so the 73 + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 74 + where a mod b means the remainder after dividing a by b. 75 + 76 + This calculation is done using the shift-register method of multiplying and 77 + taking the remainder. The register is initialized to zero, and for each 78 + incoming bit, x^32 is added mod p to the register if the bit is a one (where 79 + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 80 + x (which is shifting right by one and adding x^32 mod p if the bit shifted 81 + out is a one). We start with the highest power (least significant bit) of 82 + q and repeat for all eight bits of q. 83 + 84 + The first table is simply the CRC of all possible eight bit values. This is 85 + all the information needed to generate CRCs on data a byte at a time for all 86 + combinations of CRC register values and incoming bytes. The remaining tables 87 + allow for word-at-a-time CRC calculation for both big-endian and little- 88 + endian machines, where a word is four bytes. 89 +*/ 90 +local void make_crc_table() 91 +{ 92 + z_crc_t c; 93 + int n, k; 94 + z_crc_t poly; /* polynomial exclusive-or pattern */ 95 + /* terms of polynomial defining this crc (except x^32): */ 96 + static volatile int first = 1; /* flag to limit concurrent making */ 97 + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 98 + 99 + /* See if another task is already doing this (not thread-safe, but better 100 + than nothing -- significantly reduces duration of vulnerability in 101 + case the advice about DYNAMIC_CRC_TABLE is ignored) */ 102 + if (first) { 103 + first = 0; 104 + 105 + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 106 + poly = 0; 107 + for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) 108 + poly |= (z_crc_t)1 << (31 - p[n]); 109 + 110 + /* generate a crc for every 8-bit value */ 111 + for (n = 0; n < 256; n++) { 112 + c = (z_crc_t)n; 113 + for (k = 0; k < 8; k++) 114 + c = c & 1 ? poly ^ (c >> 1) : c >> 1; 115 + crc_table[0][n] = c; 116 + } 117 + 118 +#ifdef BYFOUR 119 + /* generate crc for each value followed by one, two, and three zeros, 120 + and then the byte reversal of those as well as the first table */ 121 + for (n = 0; n < 256; n++) { 122 + c = crc_table[0][n]; 123 + crc_table[4][n] = ZSWAP32(c); 124 + for (k = 1; k < 4; k++) { 125 + c = crc_table[0][c & 0xff] ^ (c >> 8); 126 + crc_table[k][n] = c; 127 + crc_table[k + 4][n] = ZSWAP32(c); 128 + } 129 + } 130 +#endif /* BYFOUR */ 131 + 132 + crc_table_empty = 0; 133 + } 134 + else { /* not first */ 135 + /* wait for the other guy to finish (not efficient, but rare) */ 136 + while (crc_table_empty) 137 + ; 138 + } 139 + 140 +#ifdef MAKECRCH 141 + /* write out CRC tables to crc32.h */ 142 + { 143 + FILE *out; 144 + 145 + out = fopen("crc32.h", "w"); 146 + if (out == NULL) return; 147 + fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 148 + fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 149 + fprintf(out, "local const z_crc_t FAR "); 150 + fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 151 + write_table(out, crc_table[0]); 152 +# ifdef BYFOUR 153 + fprintf(out, "#ifdef BYFOUR\n"); 154 + for (k = 1; k < 8; k++) { 155 + fprintf(out, " },\n {\n"); 156 + write_table(out, crc_table[k]); 157 + } 158 + fprintf(out, "#endif\n"); 159 +# endif /* BYFOUR */ 160 + fprintf(out, " }\n};\n"); 161 + fclose(out); 162 + } 163 +#endif /* MAKECRCH */ 164 +} 165 + 166 +#ifdef MAKECRCH 167 +local void write_table(out, table) 168 + FILE *out; 169 + const z_crc_t FAR *table; 170 +{ 171 + int n; 172 + 173 + for (n = 0; n < 256; n++) 174 + fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", 175 + (unsigned long)(table[n]), 176 + n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 177 +} 178 +#endif /* MAKECRCH */ 179 + 180 +#else /* !DYNAMIC_CRC_TABLE */ 181 +/* ======================================================================== 182 + * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 183 + */ 184 +#include "crc32.h" 185 +#endif /* DYNAMIC_CRC_TABLE */ 186 + 187 +/* ========================================================================= 188 + * This function can be used by asm versions of crc32() 189 + */ 190 +const z_crc_t FAR * ZEXPORT get_crc_table() 191 +{ 192 +#ifdef DYNAMIC_CRC_TABLE 193 + if (crc_table_empty) 194 + make_crc_table(); 195 +#endif /* DYNAMIC_CRC_TABLE */ 196 + return (const z_crc_t FAR *)crc_table; 197 +} 198 + 199 +/* ========================================================================= */ 200 +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 201 +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 202 + 203 +/* ========================================================================= */ 204 +unsigned long ZEXPORT crc32(crc, buf, len) 205 + unsigned long crc; 206 + const unsigned char FAR *buf; 207 + uInt len; 208 +{ 209 + if (buf == Z_NULL) return 0UL; 210 + 211 +#ifdef DYNAMIC_CRC_TABLE 212 + if (crc_table_empty) 213 + make_crc_table(); 214 +#endif /* DYNAMIC_CRC_TABLE */ 215 + 216 +#ifdef BYFOUR 217 + if (sizeof(void *) == sizeof(ptrdiff_t)) { 218 + z_crc_t endian; 219 + 220 + endian = 1; 221 + if (*((unsigned char *)(&endian))) 222 + return crc32_little(crc, buf, len); 223 + else 224 + return crc32_big(crc, buf, len); 225 + } 226 +#endif /* BYFOUR */ 227 + crc = crc ^ 0xffffffffUL; 228 + while (len >= 8) { 229 + DO8; 230 + len -= 8; 231 + } 232 + if (len) do { 233 + DO1; 234 + } while (--len); 235 + return crc ^ 0xffffffffUL; 236 +} 237 + 238 +#ifdef BYFOUR 239 + 240 +/* ========================================================================= */ 241 +#define DOLIT4 c ^= *buf4++; \ 242 + c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 243 + crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 244 +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 245 + 246 +/* ========================================================================= */ 247 +local unsigned long crc32_little(crc, buf, len) 248 + unsigned long crc; 249 + const unsigned char FAR *buf; 250 + unsigned len; 251 +{ 252 + register z_crc_t c; 253 + register const z_crc_t FAR *buf4; 254 + 255 + c = (z_crc_t)crc; 256 + c = ~c; 257 + while (len && ((ptrdiff_t)buf & 3)) { 258 + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 259 + len--; 260 + } 261 + 262 + buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 263 + while (len >= 32) { 264 + DOLIT32; 265 + len -= 32; 266 + } 267 + while (len >= 4) { 268 + DOLIT4; 269 + len -= 4; 270 + } 271 + buf = (const unsigned char FAR *)buf4; 272 + 273 + if (len) do { 274 + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 275 + } while (--len); 276 + c = ~c; 277 + return (unsigned long)c; 278 +} 279 + 280 +/* ========================================================================= */ 281 +#define DOBIG4 c ^= *++buf4; \ 282 + c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 283 + crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 284 +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 285 + 286 +/* ========================================================================= */ 287 +local unsigned long crc32_big(crc, buf, len) 288 + unsigned long crc; 289 + const unsigned char FAR *buf; 290 + unsigned len; 291 +{ 292 + register z_crc_t c; 293 + register const z_crc_t FAR *buf4; 294 + 295 + c = ZSWAP32((z_crc_t)crc); 296 + c = ~c; 297 + while (len && ((ptrdiff_t)buf & 3)) { 298 + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 299 + len--; 300 + } 301 + 302 + buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 303 + buf4--; 304 + while (len >= 32) { 305 + DOBIG32; 306 + len -= 32; 307 + } 308 + while (len >= 4) { 309 + DOBIG4; 310 + len -= 4; 311 + } 312 + buf4++; 313 + buf = (const unsigned char FAR *)buf4; 314 + 315 + if (len) do { 316 + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 317 + } while (--len); 318 + c = ~c; 319 + return (unsigned long)(ZSWAP32(c)); 320 +} 321 + 322 +#endif /* BYFOUR */ 323 + 324 +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 325 + 326 +/* ========================================================================= */ 327 +local unsigned long gf2_matrix_times(mat, vec) 328 + unsigned long *mat; 329 + unsigned long vec; 330 +{ 331 + unsigned long sum; 332 + 333 + sum = 0; 334 + while (vec) { 335 + if (vec & 1) 336 + sum ^= *mat; 337 + vec >>= 1; 338 + mat++; 339 + } 340 + return sum; 341 +} 342 + 343 +/* ========================================================================= */ 344 +local void gf2_matrix_square(square, mat) 345 + unsigned long *square; 346 + unsigned long *mat; 347 +{ 348 + int n; 349 + 350 + for (n = 0; n < GF2_DIM; n++) 351 + square[n] = gf2_matrix_times(mat, mat[n]); 352 +} 353 + 354 +/* ========================================================================= */ 355 +local uLong crc32_combine_(crc1, crc2, len2) 356 + uLong crc1; 357 + uLong crc2; 358 + z_off64_t len2; 359 +{ 360 + int n; 361 + unsigned long row; 362 + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ 363 + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ 364 + 365 + /* degenerate case (also disallow negative lengths) */ 366 + if (len2 <= 0) 367 + return crc1; 368 + 369 + /* put operator for one zero bit in odd */ 370 + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ 371 + row = 1; 372 + for (n = 1; n < GF2_DIM; n++) { 373 + odd[n] = row; 374 + row <<= 1; 375 + } 376 + 377 + /* put operator for two zero bits in even */ 378 + gf2_matrix_square(even, odd); 379 + 380 + /* put operator for four zero bits in odd */ 381 + gf2_matrix_square(odd, even); 382 + 383 + /* apply len2 zeros to crc1 (first square will put the operator for one 384 + zero byte, eight zero bits, in even) */ 385 + do { 386 + /* apply zeros operator for this bit of len2 */ 387 + gf2_matrix_square(even, odd); 388 + if (len2 & 1) 389 + crc1 = gf2_matrix_times(even, crc1); 390 + len2 >>= 1; 391 + 392 + /* if no more bits set, then done */ 393 + if (len2 == 0) 394 + break; 395 + 396 + /* another iteration of the loop with odd and even swapped */ 397 + gf2_matrix_square(odd, even); 398 + if (len2 & 1) 399 + crc1 = gf2_matrix_times(odd, crc1); 400 + len2 >>= 1; 401 + 402 + /* if no more bits set, then done */ 403 + } while (len2 != 0); 404 + 405 + /* return combined crc */ 406 + crc1 ^= crc2; 407 + return crc1; 408 +} 409 + 410 +/* ========================================================================= */ 411 +uLong ZEXPORT crc32_combine(crc1, crc2, len2) 412 + uLong crc1; 413 + uLong crc2; 414 + z_off_t len2; 415 +{ 416 + return crc32_combine_(crc1, crc2, len2); 417 +} 418 + 419 +uLong ZEXPORT crc32_combine64(crc1, crc2, len2) 420 + uLong crc1; 421 + uLong crc2; 422 + z_off64_t len2; 423 +{ 424 + return crc32_combine_(crc1, crc2, len2); 425 +}
Added compat/zlib/crc32.h.
1 +/* crc32.h -- tables for rapid CRC calculation 2 + * Generated automatically by crc32.c 3 + */ 4 + 5 +local const z_crc_t FAR crc_table[TBLS][256] = 6 +{ 7 + { 8 + 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, 9 + 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, 10 + 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, 11 + 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, 12 + 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, 13 + 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, 14 + 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, 15 + 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, 16 + 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, 17 + 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, 18 + 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, 19 + 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, 20 + 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, 21 + 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, 22 + 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, 23 + 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, 24 + 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, 25 + 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, 26 + 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, 27 + 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, 28 + 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, 29 + 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, 30 + 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, 31 + 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, 32 + 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, 33 + 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, 34 + 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, 35 + 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, 36 + 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, 37 + 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, 38 + 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, 39 + 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, 40 + 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, 41 + 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, 42 + 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, 43 + 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, 44 + 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, 45 + 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, 46 + 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, 47 + 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, 48 + 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, 49 + 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, 50 + 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, 51 + 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, 52 + 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, 53 + 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, 54 + 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, 55 + 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, 56 + 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, 57 + 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 58 + 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 59 + 0x2d02ef8dUL 60 +#ifdef BYFOUR 61 + }, 62 + { 63 + 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, 64 + 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, 65 + 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, 66 + 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, 67 + 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, 68 + 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, 69 + 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, 70 + 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, 71 + 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, 72 + 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, 73 + 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, 74 + 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, 75 + 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, 76 + 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, 77 + 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, 78 + 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, 79 + 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, 80 + 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, 81 + 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, 82 + 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, 83 + 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, 84 + 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, 85 + 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, 86 + 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, 87 + 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, 88 + 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, 89 + 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, 90 + 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, 91 + 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, 92 + 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, 93 + 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, 94 + 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, 95 + 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, 96 + 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, 97 + 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, 98 + 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, 99 + 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, 100 + 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, 101 + 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, 102 + 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, 103 + 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, 104 + 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, 105 + 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, 106 + 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, 107 + 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, 108 + 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, 109 + 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, 110 + 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, 111 + 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, 112 + 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, 113 + 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, 114 + 0x9324fd72UL 115 + }, 116 + { 117 + 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, 118 + 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, 119 + 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, 120 + 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, 121 + 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, 122 + 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, 123 + 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, 124 + 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, 125 + 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, 126 + 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, 127 + 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, 128 + 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, 129 + 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, 130 + 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, 131 + 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, 132 + 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, 133 + 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, 134 + 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, 135 + 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, 136 + 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, 137 + 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, 138 + 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, 139 + 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, 140 + 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, 141 + 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, 142 + 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, 143 + 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, 144 + 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, 145 + 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, 146 + 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, 147 + 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, 148 + 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, 149 + 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, 150 + 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, 151 + 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, 152 + 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, 153 + 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, 154 + 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, 155 + 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, 156 + 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, 157 + 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, 158 + 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, 159 + 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, 160 + 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, 161 + 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, 162 + 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, 163 + 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, 164 + 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, 165 + 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, 166 + 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, 167 + 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, 168 + 0xbe9834edUL 169 + }, 170 + { 171 + 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, 172 + 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, 173 + 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, 174 + 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, 175 + 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, 176 + 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, 177 + 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, 178 + 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, 179 + 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, 180 + 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, 181 + 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, 182 + 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, 183 + 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, 184 + 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, 185 + 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, 186 + 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, 187 + 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, 188 + 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, 189 + 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, 190 + 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, 191 + 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, 192 + 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, 193 + 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, 194 + 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, 195 + 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, 196 + 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, 197 + 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, 198 + 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, 199 + 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, 200 + 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, 201 + 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, 202 + 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, 203 + 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, 204 + 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, 205 + 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, 206 + 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, 207 + 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, 208 + 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, 209 + 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, 210 + 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, 211 + 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, 212 + 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, 213 + 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, 214 + 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, 215 + 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, 216 + 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, 217 + 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, 218 + 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, 219 + 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, 220 + 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, 221 + 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, 222 + 0xde0506f1UL 223 + }, 224 + { 225 + 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, 226 + 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, 227 + 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, 228 + 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, 229 + 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, 230 + 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, 231 + 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, 232 + 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, 233 + 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, 234 + 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, 235 + 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, 236 + 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, 237 + 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, 238 + 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, 239 + 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, 240 + 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, 241 + 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, 242 + 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, 243 + 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, 244 + 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, 245 + 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, 246 + 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, 247 + 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, 248 + 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, 249 + 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, 250 + 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, 251 + 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, 252 + 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, 253 + 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, 254 + 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, 255 + 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, 256 + 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, 257 + 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, 258 + 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, 259 + 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, 260 + 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, 261 + 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, 262 + 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, 263 + 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, 264 + 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, 265 + 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, 266 + 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, 267 + 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, 268 + 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, 269 + 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, 270 + 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, 271 + 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, 272 + 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, 273 + 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, 274 + 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, 275 + 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, 276 + 0x8def022dUL 277 + }, 278 + { 279 + 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, 280 + 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, 281 + 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, 282 + 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, 283 + 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, 284 + 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, 285 + 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, 286 + 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, 287 + 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, 288 + 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, 289 + 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, 290 + 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, 291 + 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, 292 + 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, 293 + 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, 294 + 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, 295 + 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, 296 + 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, 297 + 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, 298 + 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, 299 + 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, 300 + 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, 301 + 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, 302 + 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, 303 + 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, 304 + 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, 305 + 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, 306 + 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, 307 + 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, 308 + 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, 309 + 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, 310 + 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, 311 + 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, 312 + 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, 313 + 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, 314 + 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, 315 + 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, 316 + 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, 317 + 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, 318 + 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, 319 + 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, 320 + 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, 321 + 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, 322 + 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, 323 + 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, 324 + 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, 325 + 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, 326 + 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, 327 + 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, 328 + 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, 329 + 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, 330 + 0x72fd2493UL 331 + }, 332 + { 333 + 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, 334 + 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, 335 + 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, 336 + 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, 337 + 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, 338 + 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, 339 + 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, 340 + 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, 341 + 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, 342 + 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, 343 + 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, 344 + 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, 345 + 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, 346 + 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, 347 + 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, 348 + 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, 349 + 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, 350 + 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, 351 + 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, 352 + 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, 353 + 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, 354 + 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, 355 + 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, 356 + 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, 357 + 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, 358 + 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, 359 + 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, 360 + 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, 361 + 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, 362 + 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, 363 + 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, 364 + 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, 365 + 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, 366 + 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, 367 + 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, 368 + 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, 369 + 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, 370 + 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, 371 + 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, 372 + 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, 373 + 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, 374 + 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, 375 + 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, 376 + 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, 377 + 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, 378 + 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, 379 + 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, 380 + 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, 381 + 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, 382 + 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, 383 + 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, 384 + 0xed3498beUL 385 + }, 386 + { 387 + 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, 388 + 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, 389 + 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, 390 + 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, 391 + 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, 392 + 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, 393 + 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, 394 + 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, 395 + 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, 396 + 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, 397 + 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, 398 + 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, 399 + 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, 400 + 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, 401 + 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, 402 + 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, 403 + 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, 404 + 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, 405 + 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, 406 + 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, 407 + 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, 408 + 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, 409 + 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, 410 + 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, 411 + 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, 412 + 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, 413 + 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, 414 + 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, 415 + 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, 416 + 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, 417 + 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, 418 + 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, 419 + 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, 420 + 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, 421 + 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, 422 + 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, 423 + 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, 424 + 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, 425 + 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, 426 + 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, 427 + 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, 428 + 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, 429 + 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, 430 + 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, 431 + 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, 432 + 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, 433 + 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, 434 + 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, 435 + 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, 436 + 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, 437 + 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, 438 + 0xf10605deUL 439 +#endif 440 + } 441 +};
Added compat/zlib/deflate.c.
1 +/* deflate.c -- compress data using the deflation algorithm 2 + * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* 7 + * ALGORITHM 8 + * 9 + * The "deflation" process depends on being able to identify portions 10 + * of the input text which are identical to earlier input (within a 11 + * sliding window trailing behind the input currently being processed). 12 + * 13 + * The most straightforward technique turns out to be the fastest for 14 + * most input files: try all possible matches and select the longest. 15 + * The key feature of this algorithm is that insertions into the string 16 + * dictionary are very simple and thus fast, and deletions are avoided 17 + * completely. Insertions are performed at each input character, whereas 18 + * string matches are performed only when the previous match ends. So it 19 + * is preferable to spend more time in matches to allow very fast string 20 + * insertions and avoid deletions. The matching algorithm for small 21 + * strings is inspired from that of Rabin & Karp. A brute force approach 22 + * is used to find longer strings when a small match has been found. 23 + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze 24 + * (by Leonid Broukhis). 25 + * A previous version of this file used a more sophisticated algorithm 26 + * (by Fiala and Greene) which is guaranteed to run in linear amortized 27 + * time, but has a larger average cost, uses more memory and is patented. 28 + * However the F&G algorithm may be faster for some highly redundant 29 + * files if the parameter max_chain_length (described below) is too large. 30 + * 31 + * ACKNOWLEDGEMENTS 32 + * 33 + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and 34 + * I found it in 'freeze' written by Leonid Broukhis. 35 + * Thanks to many people for bug reports and testing. 36 + * 37 + * REFERENCES 38 + * 39 + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". 40 + * Available in http://tools.ietf.org/html/rfc1951 41 + * 42 + * A description of the Rabin and Karp algorithm is given in the book 43 + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 44 + * 45 + * Fiala,E.R., and Greene,D.H. 46 + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 47 + * 48 + */ 49 + 50 +/* @(#) $Id$ */ 51 + 52 +#include "deflate.h" 53 + 54 +const char deflate_copyright[] = 55 + " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; 56 +/* 57 + If you use the zlib library in a product, an acknowledgment is welcome 58 + in the documentation of your product. If for some reason you cannot 59 + include such an acknowledgment, I would appreciate that you keep this 60 + copyright string in the executable of your product. 61 + */ 62 + 63 +/* =========================================================================== 64 + * Function prototypes. 65 + */ 66 +typedef enum { 67 + need_more, /* block not completed, need more input or more output */ 68 + block_done, /* block flush performed */ 69 + finish_started, /* finish started, need only more output at next deflate */ 70 + finish_done /* finish done, accept no more input or output */ 71 +} block_state; 72 + 73 +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); 74 +/* Compression function. Returns the block state after the call. */ 75 + 76 +local void fill_window OF((deflate_state *s)); 77 +local block_state deflate_stored OF((deflate_state *s, int flush)); 78 +local block_state deflate_fast OF((deflate_state *s, int flush)); 79 +#ifndef FASTEST 80 +local block_state deflate_slow OF((deflate_state *s, int flush)); 81 +#endif 82 +local block_state deflate_rle OF((deflate_state *s, int flush)); 83 +local block_state deflate_huff OF((deflate_state *s, int flush)); 84 +local void lm_init OF((deflate_state *s)); 85 +local void putShortMSB OF((deflate_state *s, uInt b)); 86 +local void flush_pending OF((z_streamp strm)); 87 +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); 88 +#ifdef ASMV 89 + void match_init OF((void)); /* asm code initialization */ 90 + uInt longest_match OF((deflate_state *s, IPos cur_match)); 91 +#else 92 +local uInt longest_match OF((deflate_state *s, IPos cur_match)); 93 +#endif 94 + 95 +#ifdef DEBUG 96 +local void check_match OF((deflate_state *s, IPos start, IPos match, 97 + int length)); 98 +#endif 99 + 100 +/* =========================================================================== 101 + * Local data 102 + */ 103 + 104 +#define NIL 0 105 +/* Tail of hash chains */ 106 + 107 +#ifndef TOO_FAR 108 +# define TOO_FAR 4096 109 +#endif 110 +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ 111 + 112 +/* Values for max_lazy_match, good_match and max_chain_length, depending on 113 + * the desired pack level (0..9). The values given below have been tuned to 114 + * exclude worst case performance for pathological files. Better values may be 115 + * found for specific files. 116 + */ 117 +typedef struct config_s { 118 + ush good_length; /* reduce lazy search above this match length */ 119 + ush max_lazy; /* do not perform lazy search above this match length */ 120 + ush nice_length; /* quit search above this match length */ 121 + ush max_chain; 122 + compress_func func; 123 +} config; 124 + 125 +#ifdef FASTEST 126 +local const config configuration_table[2] = { 127 +/* good lazy nice chain */ 128 +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 129 +/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ 130 +#else 131 +local const config configuration_table[10] = { 132 +/* good lazy nice chain */ 133 +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 134 +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ 135 +/* 2 */ {4, 5, 16, 8, deflate_fast}, 136 +/* 3 */ {4, 6, 32, 32, deflate_fast}, 137 + 138 +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ 139 +/* 5 */ {8, 16, 32, 32, deflate_slow}, 140 +/* 6 */ {8, 16, 128, 128, deflate_slow}, 141 +/* 7 */ {8, 32, 128, 256, deflate_slow}, 142 +/* 8 */ {32, 128, 258, 1024, deflate_slow}, 143 +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ 144 +#endif 145 + 146 +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 147 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different 148 + * meaning. 149 + */ 150 + 151 +#define EQUAL 0 152 +/* result of memcmp for equal strings */ 153 + 154 +#ifndef NO_DUMMY_DECL 155 +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ 156 +#endif 157 + 158 +/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ 159 +#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) 160 + 161 +/* =========================================================================== 162 + * Update a hash value with the given input byte 163 + * IN assertion: all calls to to UPDATE_HASH are made with consecutive 164 + * input characters, so that a running hash key can be computed from the 165 + * previous key instead of complete recalculation each time. 166 + */ 167 +#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 168 + 169 + 170 +/* =========================================================================== 171 + * Insert string str in the dictionary and set match_head to the previous head 172 + * of the hash chain (the most recent string with same hash key). Return 173 + * the previous length of the hash chain. 174 + * If this file is compiled with -DFASTEST, the compression level is forced 175 + * to 1, and no hash chains are maintained. 176 + * IN assertion: all calls to to INSERT_STRING are made with consecutive 177 + * input characters and the first MIN_MATCH bytes of str are valid 178 + * (except for the last MIN_MATCH-1 bytes of the input file). 179 + */ 180 +#ifdef FASTEST 181 +#define INSERT_STRING(s, str, match_head) \ 182 + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ 183 + match_head = s->head[s->ins_h], \ 184 + s->head[s->ins_h] = (Pos)(str)) 185 +#else 186 +#define INSERT_STRING(s, str, match_head) \ 187 + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ 188 + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ 189 + s->head[s->ins_h] = (Pos)(str)) 190 +#endif 191 + 192 +/* =========================================================================== 193 + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 194 + * prev[] will be initialized on the fly. 195 + */ 196 +#define CLEAR_HASH(s) \ 197 + s->head[s->hash_size-1] = NIL; \ 198 + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); 199 + 200 +/* ========================================================================= */ 201 +int ZEXPORT deflateInit_(strm, level, version, stream_size) 202 + z_streamp strm; 203 + int level; 204 + const char *version; 205 + int stream_size; 206 +{ 207 + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 208 + Z_DEFAULT_STRATEGY, version, stream_size); 209 + /* To do: ignore strm->next_in if we use it as window */ 210 +} 211 + 212 +/* ========================================================================= */ 213 +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, 214 + version, stream_size) 215 + z_streamp strm; 216 + int level; 217 + int method; 218 + int windowBits; 219 + int memLevel; 220 + int strategy; 221 + const char *version; 222 + int stream_size; 223 +{ 224 + deflate_state *s; 225 + int wrap = 1; 226 + static const char my_version[] = ZLIB_VERSION; 227 + 228 + ushf *overlay; 229 + /* We overlay pending_buf and d_buf+l_buf. This works since the average 230 + * output size for (length,distance) codes is <= 24 bits. 231 + */ 232 + 233 + if (version == Z_NULL || version[0] != my_version[0] || 234 + stream_size != sizeof(z_stream)) { 235 + return Z_VERSION_ERROR; 236 + } 237 + if (strm == Z_NULL) return Z_STREAM_ERROR; 238 + 239 + strm->msg = Z_NULL; 240 + if (strm->zalloc == (alloc_func)0) { 241 +#ifdef Z_SOLO 242 + return Z_STREAM_ERROR; 243 +#else 244 + strm->zalloc = zcalloc; 245 + strm->opaque = (voidpf)0; 246 +#endif 247 + } 248 + if (strm->zfree == (free_func)0) 249 +#ifdef Z_SOLO 250 + return Z_STREAM_ERROR; 251 +#else 252 + strm->zfree = zcfree; 253 +#endif 254 + 255 +#ifdef FASTEST 256 + if (level != 0) level = 1; 257 +#else 258 + if (level == Z_DEFAULT_COMPRESSION) level = 6; 259 +#endif 260 + 261 + if (windowBits < 0) { /* suppress zlib wrapper */ 262 + wrap = 0; 263 + windowBits = -windowBits; 264 + } 265 +#ifdef GZIP 266 + else if (windowBits > 15) { 267 + wrap = 2; /* write gzip wrapper instead */ 268 + windowBits -= 16; 269 + } 270 +#endif 271 + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 272 + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || 273 + strategy < 0 || strategy > Z_FIXED) { 274 + return Z_STREAM_ERROR; 275 + } 276 + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ 277 + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); 278 + if (s == Z_NULL) return Z_MEM_ERROR; 279 + strm->state = (struct internal_state FAR *)s; 280 + s->strm = strm; 281 + 282 + s->wrap = wrap; 283 + s->gzhead = Z_NULL; 284 + s->w_bits = windowBits; 285 + s->w_size = 1 << s->w_bits; 286 + s->w_mask = s->w_size - 1; 287 + 288 + s->hash_bits = memLevel + 7; 289 + s->hash_size = 1 << s->hash_bits; 290 + s->hash_mask = s->hash_size - 1; 291 + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); 292 + 293 + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 294 + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 295 + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 296 + 297 + s->high_water = 0; /* nothing written to s->window yet */ 298 + 299 + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 300 + 301 + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); 302 + s->pending_buf = (uchf *) overlay; 303 + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); 304 + 305 + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 306 + s->pending_buf == Z_NULL) { 307 + s->status = FINISH_STATE; 308 + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 309 + deflateEnd (strm); 310 + return Z_MEM_ERROR; 311 + } 312 + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); 313 + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; 314 + 315 + s->level = level; 316 + s->strategy = strategy; 317 + s->method = (Byte)method; 318 + 319 + return deflateReset(strm); 320 +} 321 + 322 +/* ========================================================================= */ 323 +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) 324 + z_streamp strm; 325 + const Bytef *dictionary; 326 + uInt dictLength; 327 +{ 328 + deflate_state *s; 329 + uInt str, n; 330 + int wrap; 331 + unsigned avail; 332 + unsigned char *next; 333 + 334 + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) 335 + return Z_STREAM_ERROR; 336 + s = strm->state; 337 + wrap = s->wrap; 338 + if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) 339 + return Z_STREAM_ERROR; 340 + 341 + /* when using zlib wrappers, compute Adler-32 for provided dictionary */ 342 + if (wrap == 1) 343 + strm->adler = adler32(strm->adler, dictionary, dictLength); 344 + s->wrap = 0; /* avoid computing Adler-32 in read_buf */ 345 + 346 + /* if dictionary would fill window, just replace the history */ 347 + if (dictLength >= s->w_size) { 348 + if (wrap == 0) { /* already empty otherwise */ 349 + CLEAR_HASH(s); 350 + s->strstart = 0; 351 + s->block_start = 0L; 352 + s->insert = 0; 353 + } 354 + dictionary += dictLength - s->w_size; /* use the tail */ 355 + dictLength = s->w_size; 356 + } 357 + 358 + /* insert dictionary into window and hash */ 359 + avail = strm->avail_in; 360 + next = strm->next_in; 361 + strm->avail_in = dictLength; 362 + strm->next_in = (Bytef *)dictionary; 363 + fill_window(s); 364 + while (s->lookahead >= MIN_MATCH) { 365 + str = s->strstart; 366 + n = s->lookahead - (MIN_MATCH-1); 367 + do { 368 + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); 369 +#ifndef FASTEST 370 + s->prev[str & s->w_mask] = s->head[s->ins_h]; 371 +#endif 372 + s->head[s->ins_h] = (Pos)str; 373 + str++; 374 + } while (--n); 375 + s->strstart = str; 376 + s->lookahead = MIN_MATCH-1; 377 + fill_window(s); 378 + } 379 + s->strstart += s->lookahead; 380 + s->block_start = (long)s->strstart; 381 + s->insert = s->lookahead; 382 + s->lookahead = 0; 383 + s->match_length = s->prev_length = MIN_MATCH-1; 384 + s->match_available = 0; 385 + strm->next_in = next; 386 + strm->avail_in = avail; 387 + s->wrap = wrap; 388 + return Z_OK; 389 +} 390 + 391 +/* ========================================================================= */ 392 +int ZEXPORT deflateResetKeep (strm) 393 + z_streamp strm; 394 +{ 395 + deflate_state *s; 396 + 397 + if (strm == Z_NULL || strm->state == Z_NULL || 398 + strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { 399 + return Z_STREAM_ERROR; 400 + } 401 + 402 + strm->total_in = strm->total_out = 0; 403 + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ 404 + strm->data_type = Z_UNKNOWN; 405 + 406 + s = (deflate_state *)strm->state; 407 + s->pending = 0; 408 + s->pending_out = s->pending_buf; 409 + 410 + if (s->wrap < 0) { 411 + s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ 412 + } 413 + s->status = s->wrap ? INIT_STATE : BUSY_STATE; 414 + strm->adler = 415 +#ifdef GZIP 416 + s->wrap == 2 ? crc32(0L, Z_NULL, 0) : 417 +#endif 418 + adler32(0L, Z_NULL, 0); 419 + s->last_flush = Z_NO_FLUSH; 420 + 421 + _tr_init(s); 422 + 423 + return Z_OK; 424 +} 425 + 426 +/* ========================================================================= */ 427 +int ZEXPORT deflateReset (strm) 428 + z_streamp strm; 429 +{ 430 + int ret; 431 + 432 + ret = deflateResetKeep(strm); 433 + if (ret == Z_OK) 434 + lm_init(strm->state); 435 + return ret; 436 +} 437 + 438 +/* ========================================================================= */ 439 +int ZEXPORT deflateSetHeader (strm, head) 440 + z_streamp strm; 441 + gz_headerp head; 442 +{ 443 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 444 + if (strm->state->wrap != 2) return Z_STREAM_ERROR; 445 + strm->state->gzhead = head; 446 + return Z_OK; 447 +} 448 + 449 +/* ========================================================================= */ 450 +int ZEXPORT deflatePending (strm, pending, bits) 451 + unsigned *pending; 452 + int *bits; 453 + z_streamp strm; 454 +{ 455 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 456 + if (pending != Z_NULL) 457 + *pending = strm->state->pending; 458 + if (bits != Z_NULL) 459 + *bits = strm->state->bi_valid; 460 + return Z_OK; 461 +} 462 + 463 +/* ========================================================================= */ 464 +int ZEXPORT deflatePrime (strm, bits, value) 465 + z_streamp strm; 466 + int bits; 467 + int value; 468 +{ 469 + deflate_state *s; 470 + int put; 471 + 472 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 473 + s = strm->state; 474 + if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) 475 + return Z_BUF_ERROR; 476 + do { 477 + put = Buf_size - s->bi_valid; 478 + if (put > bits) 479 + put = bits; 480 + s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); 481 + s->bi_valid += put; 482 + _tr_flush_bits(s); 483 + value >>= put; 484 + bits -= put; 485 + } while (bits); 486 + return Z_OK; 487 +} 488 + 489 +/* ========================================================================= */ 490 +int ZEXPORT deflateParams(strm, level, strategy) 491 + z_streamp strm; 492 + int level; 493 + int strategy; 494 +{ 495 + deflate_state *s; 496 + compress_func func; 497 + int err = Z_OK; 498 + 499 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 500 + s = strm->state; 501 + 502 +#ifdef FASTEST 503 + if (level != 0) level = 1; 504 +#else 505 + if (level == Z_DEFAULT_COMPRESSION) level = 6; 506 +#endif 507 + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { 508 + return Z_STREAM_ERROR; 509 + } 510 + func = configuration_table[s->level].func; 511 + 512 + if ((strategy != s->strategy || func != configuration_table[level].func) && 513 + strm->total_in != 0) { 514 + /* Flush the last buffer: */ 515 + err = deflate(strm, Z_BLOCK); 516 + } 517 + if (s->level != level) { 518 + s->level = level; 519 + s->max_lazy_match = configuration_table[level].max_lazy; 520 + s->good_match = configuration_table[level].good_length; 521 + s->nice_match = configuration_table[level].nice_length; 522 + s->max_chain_length = configuration_table[level].max_chain; 523 + } 524 + s->strategy = strategy; 525 + return err; 526 +} 527 + 528 +/* ========================================================================= */ 529 +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) 530 + z_streamp strm; 531 + int good_length; 532 + int max_lazy; 533 + int nice_length; 534 + int max_chain; 535 +{ 536 + deflate_state *s; 537 + 538 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 539 + s = strm->state; 540 + s->good_match = good_length; 541 + s->max_lazy_match = max_lazy; 542 + s->nice_match = nice_length; 543 + s->max_chain_length = max_chain; 544 + return Z_OK; 545 +} 546 + 547 +/* ========================================================================= 548 + * For the default windowBits of 15 and memLevel of 8, this function returns 549 + * a close to exact, as well as small, upper bound on the compressed size. 550 + * They are coded as constants here for a reason--if the #define's are 551 + * changed, then this function needs to be changed as well. The return 552 + * value for 15 and 8 only works for those exact settings. 553 + * 554 + * For any setting other than those defaults for windowBits and memLevel, 555 + * the value returned is a conservative worst case for the maximum expansion 556 + * resulting from using fixed blocks instead of stored blocks, which deflate 557 + * can emit on compressed data for some combinations of the parameters. 558 + * 559 + * This function could be more sophisticated to provide closer upper bounds for 560 + * every combination of windowBits and memLevel. But even the conservative 561 + * upper bound of about 14% expansion does not seem onerous for output buffer 562 + * allocation. 563 + */ 564 +uLong ZEXPORT deflateBound(strm, sourceLen) 565 + z_streamp strm; 566 + uLong sourceLen; 567 +{ 568 + deflate_state *s; 569 + uLong complen, wraplen; 570 + Bytef *str; 571 + 572 + /* conservative upper bound for compressed data */ 573 + complen = sourceLen + 574 + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; 575 + 576 + /* if can't get parameters, return conservative bound plus zlib wrapper */ 577 + if (strm == Z_NULL || strm->state == Z_NULL) 578 + return complen + 6; 579 + 580 + /* compute wrapper length */ 581 + s = strm->state; 582 + switch (s->wrap) { 583 + case 0: /* raw deflate */ 584 + wraplen = 0; 585 + break; 586 + case 1: /* zlib wrapper */ 587 + wraplen = 6 + (s->strstart ? 4 : 0); 588 + break; 589 + case 2: /* gzip wrapper */ 590 + wraplen = 18; 591 + if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ 592 + if (s->gzhead->extra != Z_NULL) 593 + wraplen += 2 + s->gzhead->extra_len; 594 + str = s->gzhead->name; 595 + if (str != Z_NULL) 596 + do { 597 + wraplen++; 598 + } while (*str++); 599 + str = s->gzhead->comment; 600 + if (str != Z_NULL) 601 + do { 602 + wraplen++; 603 + } while (*str++); 604 + if (s->gzhead->hcrc) 605 + wraplen += 2; 606 + } 607 + break; 608 + default: /* for compiler happiness */ 609 + wraplen = 6; 610 + } 611 + 612 + /* if not default parameters, return conservative bound */ 613 + if (s->w_bits != 15 || s->hash_bits != 8 + 7) 614 + return complen + wraplen; 615 + 616 + /* default settings: return tight bound for that case */ 617 + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 618 + (sourceLen >> 25) + 13 - 6 + wraplen; 619 +} 620 + 621 +/* ========================================================================= 622 + * Put a short in the pending buffer. The 16-bit value is put in MSB order. 623 + * IN assertion: the stream state is correct and there is enough room in 624 + * pending_buf. 625 + */ 626 +local void putShortMSB (s, b) 627 + deflate_state *s; 628 + uInt b; 629 +{ 630 + put_byte(s, (Byte)(b >> 8)); 631 + put_byte(s, (Byte)(b & 0xff)); 632 +} 633 + 634 +/* ========================================================================= 635 + * Flush as much pending output as possible. All deflate() output goes 636 + * through this function so some applications may wish to modify it 637 + * to avoid allocating a large strm->next_out buffer and copying into it. 638 + * (See also read_buf()). 639 + */ 640 +local void flush_pending(strm) 641 + z_streamp strm; 642 +{ 643 + unsigned len; 644 + deflate_state *s = strm->state; 645 + 646 + _tr_flush_bits(s); 647 + len = s->pending; 648 + if (len > strm->avail_out) len = strm->avail_out; 649 + if (len == 0) return; 650 + 651 + zmemcpy(strm->next_out, s->pending_out, len); 652 + strm->next_out += len; 653 + s->pending_out += len; 654 + strm->total_out += len; 655 + strm->avail_out -= len; 656 + s->pending -= len; 657 + if (s->pending == 0) { 658 + s->pending_out = s->pending_buf; 659 + } 660 +} 661 + 662 +/* ========================================================================= */ 663 +int ZEXPORT deflate (strm, flush) 664 + z_streamp strm; 665 + int flush; 666 +{ 667 + int old_flush; /* value of flush param for previous deflate call */ 668 + deflate_state *s; 669 + 670 + if (strm == Z_NULL || strm->state == Z_NULL || 671 + flush > Z_BLOCK || flush < 0) { 672 + return Z_STREAM_ERROR; 673 + } 674 + s = strm->state; 675 + 676 + if (strm->next_out == Z_NULL || 677 + (strm->next_in == Z_NULL && strm->avail_in != 0) || 678 + (s->status == FINISH_STATE && flush != Z_FINISH)) { 679 + ERR_RETURN(strm, Z_STREAM_ERROR); 680 + } 681 + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); 682 + 683 + s->strm = strm; /* just in case */ 684 + old_flush = s->last_flush; 685 + s->last_flush = flush; 686 + 687 + /* Write the header */ 688 + if (s->status == INIT_STATE) { 689 +#ifdef GZIP 690 + if (s->wrap == 2) { 691 + strm->adler = crc32(0L, Z_NULL, 0); 692 + put_byte(s, 31); 693 + put_byte(s, 139); 694 + put_byte(s, 8); 695 + if (s->gzhead == Z_NULL) { 696 + put_byte(s, 0); 697 + put_byte(s, 0); 698 + put_byte(s, 0); 699 + put_byte(s, 0); 700 + put_byte(s, 0); 701 + put_byte(s, s->level == 9 ? 2 : 702 + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 703 + 4 : 0)); 704 + put_byte(s, OS_CODE); 705 + s->status = BUSY_STATE; 706 + } 707 + else { 708 + put_byte(s, (s->gzhead->text ? 1 : 0) + 709 + (s->gzhead->hcrc ? 2 : 0) + 710 + (s->gzhead->extra == Z_NULL ? 0 : 4) + 711 + (s->gzhead->name == Z_NULL ? 0 : 8) + 712 + (s->gzhead->comment == Z_NULL ? 0 : 16) 713 + ); 714 + put_byte(s, (Byte)(s->gzhead->time & 0xff)); 715 + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); 716 + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); 717 + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); 718 + put_byte(s, s->level == 9 ? 2 : 719 + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 720 + 4 : 0)); 721 + put_byte(s, s->gzhead->os & 0xff); 722 + if (s->gzhead->extra != Z_NULL) { 723 + put_byte(s, s->gzhead->extra_len & 0xff); 724 + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); 725 + } 726 + if (s->gzhead->hcrc) 727 + strm->adler = crc32(strm->adler, s->pending_buf, 728 + s->pending); 729 + s->gzindex = 0; 730 + s->status = EXTRA_STATE; 731 + } 732 + } 733 + else 734 +#endif 735 + { 736 + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; 737 + uInt level_flags; 738 + 739 + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) 740 + level_flags = 0; 741 + else if (s->level < 6) 742 + level_flags = 1; 743 + else if (s->level == 6) 744 + level_flags = 2; 745 + else 746 + level_flags = 3; 747 + header |= (level_flags << 6); 748 + if (s->strstart != 0) header |= PRESET_DICT; 749 + header += 31 - (header % 31); 750 + 751 + s->status = BUSY_STATE; 752 + putShortMSB(s, header); 753 + 754 + /* Save the adler32 of the preset dictionary: */ 755 + if (s->strstart != 0) { 756 + putShortMSB(s, (uInt)(strm->adler >> 16)); 757 + putShortMSB(s, (uInt)(strm->adler & 0xffff)); 758 + } 759 + strm->adler = adler32(0L, Z_NULL, 0); 760 + } 761 + } 762 +#ifdef GZIP 763 + if (s->status == EXTRA_STATE) { 764 + if (s->gzhead->extra != Z_NULL) { 765 + uInt beg = s->pending; /* start of bytes to update crc */ 766 + 767 + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { 768 + if (s->pending == s->pending_buf_size) { 769 + if (s->gzhead->hcrc && s->pending > beg) 770 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 771 + s->pending - beg); 772 + flush_pending(strm); 773 + beg = s->pending; 774 + if (s->pending == s->pending_buf_size) 775 + break; 776 + } 777 + put_byte(s, s->gzhead->extra[s->gzindex]); 778 + s->gzindex++; 779 + } 780 + if (s->gzhead->hcrc && s->pending > beg) 781 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 782 + s->pending - beg); 783 + if (s->gzindex == s->gzhead->extra_len) { 784 + s->gzindex = 0; 785 + s->status = NAME_STATE; 786 + } 787 + } 788 + else 789 + s->status = NAME_STATE; 790 + } 791 + if (s->status == NAME_STATE) { 792 + if (s->gzhead->name != Z_NULL) { 793 + uInt beg = s->pending; /* start of bytes to update crc */ 794 + int val; 795 + 796 + do { 797 + if (s->pending == s->pending_buf_size) { 798 + if (s->gzhead->hcrc && s->pending > beg) 799 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 800 + s->pending - beg); 801 + flush_pending(strm); 802 + beg = s->pending; 803 + if (s->pending == s->pending_buf_size) { 804 + val = 1; 805 + break; 806 + } 807 + } 808 + val = s->gzhead->name[s->gzindex++]; 809 + put_byte(s, val); 810 + } while (val != 0); 811 + if (s->gzhead->hcrc && s->pending > beg) 812 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 813 + s->pending - beg); 814 + if (val == 0) { 815 + s->gzindex = 0; 816 + s->status = COMMENT_STATE; 817 + } 818 + } 819 + else 820 + s->status = COMMENT_STATE; 821 + } 822 + if (s->status == COMMENT_STATE) { 823 + if (s->gzhead->comment != Z_NULL) { 824 + uInt beg = s->pending; /* start of bytes to update crc */ 825 + int val; 826 + 827 + do { 828 + if (s->pending == s->pending_buf_size) { 829 + if (s->gzhead->hcrc && s->pending > beg) 830 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 831 + s->pending - beg); 832 + flush_pending(strm); 833 + beg = s->pending; 834 + if (s->pending == s->pending_buf_size) { 835 + val = 1; 836 + break; 837 + } 838 + } 839 + val = s->gzhead->comment[s->gzindex++]; 840 + put_byte(s, val); 841 + } while (val != 0); 842 + if (s->gzhead->hcrc && s->pending > beg) 843 + strm->adler = crc32(strm->adler, s->pending_buf + beg, 844 + s->pending - beg); 845 + if (val == 0) 846 + s->status = HCRC_STATE; 847 + } 848 + else 849 + s->status = HCRC_STATE; 850 + } 851 + if (s->status == HCRC_STATE) { 852 + if (s->gzhead->hcrc) { 853 + if (s->pending + 2 > s->pending_buf_size) 854 + flush_pending(strm); 855 + if (s->pending + 2 <= s->pending_buf_size) { 856 + put_byte(s, (Byte)(strm->adler & 0xff)); 857 + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); 858 + strm->adler = crc32(0L, Z_NULL, 0); 859 + s->status = BUSY_STATE; 860 + } 861 + } 862 + else 863 + s->status = BUSY_STATE; 864 + } 865 +#endif 866 + 867 + /* Flush as much pending output as possible */ 868 + if (s->pending != 0) { 869 + flush_pending(strm); 870 + if (strm->avail_out == 0) { 871 + /* Since avail_out is 0, deflate will be called again with 872 + * more output space, but possibly with both pending and 873 + * avail_in equal to zero. There won't be anything to do, 874 + * but this is not an error situation so make sure we 875 + * return OK instead of BUF_ERROR at next call of deflate: 876 + */ 877 + s->last_flush = -1; 878 + return Z_OK; 879 + } 880 + 881 + /* Make sure there is something to do and avoid duplicate consecutive 882 + * flushes. For repeated and useless calls with Z_FINISH, we keep 883 + * returning Z_STREAM_END instead of Z_BUF_ERROR. 884 + */ 885 + } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && 886 + flush != Z_FINISH) { 887 + ERR_RETURN(strm, Z_BUF_ERROR); 888 + } 889 + 890 + /* User must not provide more input after the first FINISH: */ 891 + if (s->status == FINISH_STATE && strm->avail_in != 0) { 892 + ERR_RETURN(strm, Z_BUF_ERROR); 893 + } 894 + 895 + /* Start a new block or continue the current one. 896 + */ 897 + if (strm->avail_in != 0 || s->lookahead != 0 || 898 + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { 899 + block_state bstate; 900 + 901 + bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : 902 + (s->strategy == Z_RLE ? deflate_rle(s, flush) : 903 + (*(configuration_table[s->level].func))(s, flush)); 904 + 905 + if (bstate == finish_started || bstate == finish_done) { 906 + s->status = FINISH_STATE; 907 + } 908 + if (bstate == need_more || bstate == finish_started) { 909 + if (strm->avail_out == 0) { 910 + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ 911 + } 912 + return Z_OK; 913 + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call 914 + * of deflate should use the same flush parameter to make sure 915 + * that the flush is complete. So we don't have to output an 916 + * empty block here, this will be done at next call. This also 917 + * ensures that for a very small output buffer, we emit at most 918 + * one empty block. 919 + */ 920 + } 921 + if (bstate == block_done) { 922 + if (flush == Z_PARTIAL_FLUSH) { 923 + _tr_align(s); 924 + } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ 925 + _tr_stored_block(s, (char*)0, 0L, 0); 926 + /* For a full flush, this empty block will be recognized 927 + * as a special marker by inflate_sync(). 928 + */ 929 + if (flush == Z_FULL_FLUSH) { 930 + CLEAR_HASH(s); /* forget history */ 931 + if (s->lookahead == 0) { 932 + s->strstart = 0; 933 + s->block_start = 0L; 934 + s->insert = 0; 935 + } 936 + } 937 + } 938 + flush_pending(strm); 939 + if (strm->avail_out == 0) { 940 + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ 941 + return Z_OK; 942 + } 943 + } 944 + } 945 + Assert(strm->avail_out > 0, "bug2"); 946 + 947 + if (flush != Z_FINISH) return Z_OK; 948 + if (s->wrap <= 0) return Z_STREAM_END; 949 + 950 + /* Write the trailer */ 951 +#ifdef GZIP 952 + if (s->wrap == 2) { 953 + put_byte(s, (Byte)(strm->adler & 0xff)); 954 + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); 955 + put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); 956 + put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); 957 + put_byte(s, (Byte)(strm->total_in & 0xff)); 958 + put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); 959 + put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); 960 + put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); 961 + } 962 + else 963 +#endif 964 + { 965 + putShortMSB(s, (uInt)(strm->adler >> 16)); 966 + putShortMSB(s, (uInt)(strm->adler & 0xffff)); 967 + } 968 + flush_pending(strm); 969 + /* If avail_out is zero, the application will call deflate again 970 + * to flush the rest. 971 + */ 972 + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ 973 + return s->pending != 0 ? Z_OK : Z_STREAM_END; 974 +} 975 + 976 +/* ========================================================================= */ 977 +int ZEXPORT deflateEnd (strm) 978 + z_streamp strm; 979 +{ 980 + int status; 981 + 982 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 983 + 984 + status = strm->state->status; 985 + if (status != INIT_STATE && 986 + status != EXTRA_STATE && 987 + status != NAME_STATE && 988 + status != COMMENT_STATE && 989 + status != HCRC_STATE && 990 + status != BUSY_STATE && 991 + status != FINISH_STATE) { 992 + return Z_STREAM_ERROR; 993 + } 994 + 995 + /* Deallocate in reverse order of allocations: */ 996 + TRY_FREE(strm, strm->state->pending_buf); 997 + TRY_FREE(strm, strm->state->head); 998 + TRY_FREE(strm, strm->state->prev); 999 + TRY_FREE(strm, strm->state->window); 1000 + 1001 + ZFREE(strm, strm->state); 1002 + strm->state = Z_NULL; 1003 + 1004 + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; 1005 +} 1006 + 1007 +/* ========================================================================= 1008 + * Copy the source state to the destination state. 1009 + * To simplify the source, this is not supported for 16-bit MSDOS (which 1010 + * doesn't have enough memory anyway to duplicate compression states). 1011 + */ 1012 +int ZEXPORT deflateCopy (dest, source) 1013 + z_streamp dest; 1014 + z_streamp source; 1015 +{ 1016 +#ifdef MAXSEG_64K 1017 + return Z_STREAM_ERROR; 1018 +#else 1019 + deflate_state *ds; 1020 + deflate_state *ss; 1021 + ushf *overlay; 1022 + 1023 + 1024 + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { 1025 + return Z_STREAM_ERROR; 1026 + } 1027 + 1028 + ss = source->state; 1029 + 1030 + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); 1031 + 1032 + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); 1033 + if (ds == Z_NULL) return Z_MEM_ERROR; 1034 + dest->state = (struct internal_state FAR *) ds; 1035 + zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); 1036 + ds->strm = dest; 1037 + 1038 + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); 1039 + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); 1040 + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); 1041 + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); 1042 + ds->pending_buf = (uchf *) overlay; 1043 + 1044 + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || 1045 + ds->pending_buf == Z_NULL) { 1046 + deflateEnd (dest); 1047 + return Z_MEM_ERROR; 1048 + } 1049 + /* following zmemcpy do not work for 16-bit MSDOS */ 1050 + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); 1051 + zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); 1052 + zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); 1053 + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); 1054 + 1055 + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); 1056 + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); 1057 + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; 1058 + 1059 + ds->l_desc.dyn_tree = ds->dyn_ltree; 1060 + ds->d_desc.dyn_tree = ds->dyn_dtree; 1061 + ds->bl_desc.dyn_tree = ds->bl_tree; 1062 + 1063 + return Z_OK; 1064 +#endif /* MAXSEG_64K */ 1065 +} 1066 + 1067 +/* =========================================================================== 1068 + * Read a new buffer from the current input stream, update the adler32 1069 + * and total number of bytes read. All deflate() input goes through 1070 + * this function so some applications may wish to modify it to avoid 1071 + * allocating a large strm->next_in buffer and copying from it. 1072 + * (See also flush_pending()). 1073 + */ 1074 +local int read_buf(strm, buf, size) 1075 + z_streamp strm; 1076 + Bytef *buf; 1077 + unsigned size; 1078 +{ 1079 + unsigned len = strm->avail_in; 1080 + 1081 + if (len > size) len = size; 1082 + if (len == 0) return 0; 1083 + 1084 + strm->avail_in -= len; 1085 + 1086 + zmemcpy(buf, strm->next_in, len); 1087 + if (strm->state->wrap == 1) { 1088 + strm->adler = adler32(strm->adler, buf, len); 1089 + } 1090 +#ifdef GZIP 1091 + else if (strm->state->wrap == 2) { 1092 + strm->adler = crc32(strm->adler, buf, len); 1093 + } 1094 +#endif 1095 + strm->next_in += len; 1096 + strm->total_in += len; 1097 + 1098 + return (int)len; 1099 +} 1100 + 1101 +/* =========================================================================== 1102 + * Initialize the "longest match" routines for a new zlib stream 1103 + */ 1104 +local void lm_init (s) 1105 + deflate_state *s; 1106 +{ 1107 + s->window_size = (ulg)2L*s->w_size; 1108 + 1109 + CLEAR_HASH(s); 1110 + 1111 + /* Set the default configuration parameters: 1112 + */ 1113 + s->max_lazy_match = configuration_table[s->level].max_lazy; 1114 + s->good_match = configuration_table[s->level].good_length; 1115 + s->nice_match = configuration_table[s->level].nice_length; 1116 + s->max_chain_length = configuration_table[s->level].max_chain; 1117 + 1118 + s->strstart = 0; 1119 + s->block_start = 0L; 1120 + s->lookahead = 0; 1121 + s->insert = 0; 1122 + s->match_length = s->prev_length = MIN_MATCH-1; 1123 + s->match_available = 0; 1124 + s->ins_h = 0; 1125 +#ifndef FASTEST 1126 +#ifdef ASMV 1127 + match_init(); /* initialize the asm code */ 1128 +#endif 1129 +#endif 1130 +} 1131 + 1132 +#ifndef FASTEST 1133 +/* =========================================================================== 1134 + * Set match_start to the longest match starting at the given string and 1135 + * return its length. Matches shorter or equal to prev_length are discarded, 1136 + * in which case the result is equal to prev_length and match_start is 1137 + * garbage. 1138 + * IN assertions: cur_match is the head of the hash chain for the current 1139 + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 1140 + * OUT assertion: the match length is not greater than s->lookahead. 1141 + */ 1142 +#ifndef ASMV 1143 +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 1144 + * match.S. The code will be functionally equivalent. 1145 + */ 1146 +local uInt longest_match(s, cur_match) 1147 + deflate_state *s; 1148 + IPos cur_match; /* current match */ 1149 +{ 1150 + unsigned chain_length = s->max_chain_length;/* max hash chain length */ 1151 + register Bytef *scan = s->window + s->strstart; /* current string */ 1152 + register Bytef *match; /* matched string */ 1153 + register int len; /* length of current match */ 1154 + int best_len = s->prev_length; /* best match length so far */ 1155 + int nice_match = s->nice_match; /* stop if match long enough */ 1156 + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 1157 + s->strstart - (IPos)MAX_DIST(s) : NIL; 1158 + /* Stop when cur_match becomes <= limit. To simplify the code, 1159 + * we prevent matches with the string of window index 0. 1160 + */ 1161 + Posf *prev = s->prev; 1162 + uInt wmask = s->w_mask; 1163 + 1164 +#ifdef UNALIGNED_OK 1165 + /* Compare two bytes at a time. Note: this is not always beneficial. 1166 + * Try with and without -DUNALIGNED_OK to check. 1167 + */ 1168 + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; 1169 + register ush scan_start = *(ushf*)scan; 1170 + register ush scan_end = *(ushf*)(scan+best_len-1); 1171 +#else 1172 + register Bytef *strend = s->window + s->strstart + MAX_MATCH; 1173 + register Byte scan_end1 = scan[best_len-1]; 1174 + register Byte scan_end = scan[best_len]; 1175 +#endif 1176 + 1177 + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 1178 + * It is easy to get rid of this optimization if necessary. 1179 + */ 1180 + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 1181 + 1182 + /* Do not waste too much time if we already have a good match: */ 1183 + if (s->prev_length >= s->good_match) { 1184 + chain_length >>= 2; 1185 + } 1186 + /* Do not look for matches beyond the end of the input. This is necessary 1187 + * to make deflate deterministic. 1188 + */ 1189 + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; 1190 + 1191 + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 1192 + 1193 + do { 1194 + Assert(cur_match < s->strstart, "no future"); 1195 + match = s->window + cur_match; 1196 + 1197 + /* Skip to next match if the match length cannot increase 1198 + * or if the match length is less than 2. Note that the checks below 1199 + * for insufficient lookahead only occur occasionally for performance 1200 + * reasons. Therefore uninitialized memory will be accessed, and 1201 + * conditional jumps will be made that depend on those values. 1202 + * However the length of the match is limited to the lookahead, so 1203 + * the output of deflate is not affected by the uninitialized values. 1204 + */ 1205 +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) 1206 + /* This code assumes sizeof(unsigned short) == 2. Do not use 1207 + * UNALIGNED_OK if your compiler uses a different size. 1208 + */ 1209 + if (*(ushf*)(match+best_len-1) != scan_end || 1210 + *(ushf*)match != scan_start) continue; 1211 + 1212 + /* It is not necessary to compare scan[2] and match[2] since they are 1213 + * always equal when the other bytes match, given that the hash keys 1214 + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at 1215 + * strstart+3, +5, ... up to strstart+257. We check for insufficient 1216 + * lookahead only every 4th comparison; the 128th check will be made 1217 + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is 1218 + * necessary to put more guard bytes at the end of the window, or 1219 + * to check more often for insufficient lookahead. 1220 + */ 1221 + Assert(scan[2] == match[2], "scan[2]?"); 1222 + scan++, match++; 1223 + do { 1224 + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1225 + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1226 + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1227 + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1228 + scan < strend); 1229 + /* The funny "do {}" generates better code on most compilers */ 1230 + 1231 + /* Here, scan <= window+strstart+257 */ 1232 + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1233 + if (*scan == *match) scan++; 1234 + 1235 + len = (MAX_MATCH - 1) - (int)(strend-scan); 1236 + scan = strend - (MAX_MATCH-1); 1237 + 1238 +#else /* UNALIGNED_OK */ 1239 + 1240 + if (match[best_len] != scan_end || 1241 + match[best_len-1] != scan_end1 || 1242 + *match != *scan || 1243 + *++match != scan[1]) continue; 1244 + 1245 + /* The check at best_len-1 can be removed because it will be made 1246 + * again later. (This heuristic is not always a win.) 1247 + * It is not necessary to compare scan[2] and match[2] since they 1248 + * are always equal when the other bytes match, given that 1249 + * the hash keys are equal and that HASH_BITS >= 8. 1250 + */ 1251 + scan += 2, match++; 1252 + Assert(*scan == *match, "match[2]?"); 1253 + 1254 + /* We check for insufficient lookahead only every 8th comparison; 1255 + * the 256th check will be made at strstart+258. 1256 + */ 1257 + do { 1258 + } while (*++scan == *++match && *++scan == *++match && 1259 + *++scan == *++match && *++scan == *++match && 1260 + *++scan == *++match && *++scan == *++match && 1261 + *++scan == *++match && *++scan == *++match && 1262 + scan < strend); 1263 + 1264 + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1265 + 1266 + len = MAX_MATCH - (int)(strend - scan); 1267 + scan = strend - MAX_MATCH; 1268 + 1269 +#endif /* UNALIGNED_OK */ 1270 + 1271 + if (len > best_len) { 1272 + s->match_start = cur_match; 1273 + best_len = len; 1274 + if (len >= nice_match) break; 1275 +#ifdef UNALIGNED_OK 1276 + scan_end = *(ushf*)(scan+best_len-1); 1277 +#else 1278 + scan_end1 = scan[best_len-1]; 1279 + scan_end = scan[best_len]; 1280 +#endif 1281 + } 1282 + } while ((cur_match = prev[cur_match & wmask]) > limit 1283 + && --chain_length != 0); 1284 + 1285 + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 1286 + return s->lookahead; 1287 +} 1288 +#endif /* ASMV */ 1289 + 1290 +#else /* FASTEST */ 1291 + 1292 +/* --------------------------------------------------------------------------- 1293 + * Optimized version for FASTEST only 1294 + */ 1295 +local uInt longest_match(s, cur_match) 1296 + deflate_state *s; 1297 + IPos cur_match; /* current match */ 1298 +{ 1299 + register Bytef *scan = s->window + s->strstart; /* current string */ 1300 + register Bytef *match; /* matched string */ 1301 + register int len; /* length of current match */ 1302 + register Bytef *strend = s->window + s->strstart + MAX_MATCH; 1303 + 1304 + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 1305 + * It is easy to get rid of this optimization if necessary. 1306 + */ 1307 + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 1308 + 1309 + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 1310 + 1311 + Assert(cur_match < s->strstart, "no future"); 1312 + 1313 + match = s->window + cur_match; 1314 + 1315 + /* Return failure if the match length is less than 2: 1316 + */ 1317 + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; 1318 + 1319 + /* The check at best_len-1 can be removed because it will be made 1320 + * again later. (This heuristic is not always a win.) 1321 + * It is not necessary to compare scan[2] and match[2] since they 1322 + * are always equal when the other bytes match, given that 1323 + * the hash keys are equal and that HASH_BITS >= 8. 1324 + */ 1325 + scan += 2, match += 2; 1326 + Assert(*scan == *match, "match[2]?"); 1327 + 1328 + /* We check for insufficient lookahead only every 8th comparison; 1329 + * the 256th check will be made at strstart+258. 1330 + */ 1331 + do { 1332 + } while (*++scan == *++match && *++scan == *++match && 1333 + *++scan == *++match && *++scan == *++match && 1334 + *++scan == *++match && *++scan == *++match && 1335 + *++scan == *++match && *++scan == *++match && 1336 + scan < strend); 1337 + 1338 + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1339 + 1340 + len = MAX_MATCH - (int)(strend - scan); 1341 + 1342 + if (len < MIN_MATCH) return MIN_MATCH - 1; 1343 + 1344 + s->match_start = cur_match; 1345 + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; 1346 +} 1347 + 1348 +#endif /* FASTEST */ 1349 + 1350 +#ifdef DEBUG 1351 +/* =========================================================================== 1352 + * Check that the match at match_start is indeed a match. 1353 + */ 1354 +local void check_match(s, start, match, length) 1355 + deflate_state *s; 1356 + IPos start, match; 1357 + int length; 1358 +{ 1359 + /* check that the match is indeed a match */ 1360 + if (zmemcmp(s->window + match, 1361 + s->window + start, length) != EQUAL) { 1362 + fprintf(stderr, " start %u, match %u, length %d\n", 1363 + start, match, length); 1364 + do { 1365 + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); 1366 + } while (--length != 0); 1367 + z_error("invalid match"); 1368 + } 1369 + if (z_verbose > 1) { 1370 + fprintf(stderr,"\\[%d,%d]", start-match, length); 1371 + do { putc(s->window[start++], stderr); } while (--length != 0); 1372 + } 1373 +} 1374 +#else 1375 +# define check_match(s, start, match, length) 1376 +#endif /* DEBUG */ 1377 + 1378 +/* =========================================================================== 1379 + * Fill the window when the lookahead becomes insufficient. 1380 + * Updates strstart and lookahead. 1381 + * 1382 + * IN assertion: lookahead < MIN_LOOKAHEAD 1383 + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD 1384 + * At least one byte has been read, or avail_in == 0; reads are 1385 + * performed for at least two bytes (required for the zip translate_eol 1386 + * option -- not supported here). 1387 + */ 1388 +local void fill_window(s) 1389 + deflate_state *s; 1390 +{ 1391 + register unsigned n, m; 1392 + register Posf *p; 1393 + unsigned more; /* Amount of free space at the end of the window. */ 1394 + uInt wsize = s->w_size; 1395 + 1396 + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); 1397 + 1398 + do { 1399 + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); 1400 + 1401 + /* Deal with !@#$% 64K limit: */ 1402 + if (sizeof(int) <= 2) { 1403 + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { 1404 + more = wsize; 1405 + 1406 + } else if (more == (unsigned)(-1)) { 1407 + /* Very unlikely, but possible on 16 bit machine if 1408 + * strstart == 0 && lookahead == 1 (input done a byte at time) 1409 + */ 1410 + more--; 1411 + } 1412 + } 1413 + 1414 + /* If the window is almost full and there is insufficient lookahead, 1415 + * move the upper half to the lower one to make room in the upper half. 1416 + */ 1417 + if (s->strstart >= wsize+MAX_DIST(s)) { 1418 + 1419 + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); 1420 + s->match_start -= wsize; 1421 + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ 1422 + s->block_start -= (long) wsize; 1423 + 1424 + /* Slide the hash table (could be avoided with 32 bit values 1425 + at the expense of memory usage). We slide even when level == 0 1426 + to keep the hash table consistent if we switch back to level > 0 1427 + later. (Using level 0 permanently is not an optimal usage of 1428 + zlib, so we don't care about this pathological case.) 1429 + */ 1430 + n = s->hash_size; 1431 + p = &s->head[n]; 1432 + do { 1433 + m = *--p; 1434 + *p = (Pos)(m >= wsize ? m-wsize : NIL); 1435 + } while (--n); 1436 + 1437 + n = wsize; 1438 +#ifndef FASTEST 1439 + p = &s->prev[n]; 1440 + do { 1441 + m = *--p; 1442 + *p = (Pos)(m >= wsize ? m-wsize : NIL); 1443 + /* If n is not on any hash chain, prev[n] is garbage but 1444 + * its value will never be used. 1445 + */ 1446 + } while (--n); 1447 +#endif 1448 + more += wsize; 1449 + } 1450 + if (s->strm->avail_in == 0) break; 1451 + 1452 + /* If there was no sliding: 1453 + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && 1454 + * more == window_size - lookahead - strstart 1455 + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) 1456 + * => more >= window_size - 2*WSIZE + 2 1457 + * In the BIG_MEM or MMAP case (not yet supported), 1458 + * window_size == input_size + MIN_LOOKAHEAD && 1459 + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. 1460 + * Otherwise, window_size == 2*WSIZE so more >= 2. 1461 + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. 1462 + */ 1463 + Assert(more >= 2, "more < 2"); 1464 + 1465 + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); 1466 + s->lookahead += n; 1467 + 1468 + /* Initialize the hash value now that we have some input: */ 1469 + if (s->lookahead + s->insert >= MIN_MATCH) { 1470 + uInt str = s->strstart - s->insert; 1471 + s->ins_h = s->window[str]; 1472 + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); 1473 +#if MIN_MATCH != 3 1474 + Call UPDATE_HASH() MIN_MATCH-3 more times 1475 +#endif 1476 + while (s->insert) { 1477 + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); 1478 +#ifndef FASTEST 1479 + s->prev[str & s->w_mask] = s->head[s->ins_h]; 1480 +#endif 1481 + s->head[s->ins_h] = (Pos)str; 1482 + str++; 1483 + s->insert--; 1484 + if (s->lookahead + s->insert < MIN_MATCH) 1485 + break; 1486 + } 1487 + } 1488 + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, 1489 + * but this is not important since only literal bytes will be emitted. 1490 + */ 1491 + 1492 + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); 1493 + 1494 + /* If the WIN_INIT bytes after the end of the current data have never been 1495 + * written, then zero those bytes in order to avoid memory check reports of 1496 + * the use of uninitialized (or uninitialised as Julian writes) bytes by 1497 + * the longest match routines. Update the high water mark for the next 1498 + * time through here. WIN_INIT is set to MAX_MATCH since the longest match 1499 + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. 1500 + */ 1501 + if (s->high_water < s->window_size) { 1502 + ulg curr = s->strstart + (ulg)(s->lookahead); 1503 + ulg init; 1504 + 1505 + if (s->high_water < curr) { 1506 + /* Previous high water mark below current data -- zero WIN_INIT 1507 + * bytes or up to end of window, whichever is less. 1508 + */ 1509 + init = s->window_size - curr; 1510 + if (init > WIN_INIT) 1511 + init = WIN_INIT; 1512 + zmemzero(s->window + curr, (unsigned)init); 1513 + s->high_water = curr + init; 1514 + } 1515 + else if (s->high_water < (ulg)curr + WIN_INIT) { 1516 + /* High water mark at or above current data, but below current data 1517 + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up 1518 + * to end of window, whichever is less. 1519 + */ 1520 + init = (ulg)curr + WIN_INIT - s->high_water; 1521 + if (init > s->window_size - s->high_water) 1522 + init = s->window_size - s->high_water; 1523 + zmemzero(s->window + s->high_water, (unsigned)init); 1524 + s->high_water += init; 1525 + } 1526 + } 1527 + 1528 + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, 1529 + "not enough room for search"); 1530 +} 1531 + 1532 +/* =========================================================================== 1533 + * Flush the current block, with given end-of-file flag. 1534 + * IN assertion: strstart is set to the end of the current match. 1535 + */ 1536 +#define FLUSH_BLOCK_ONLY(s, last) { \ 1537 + _tr_flush_block(s, (s->block_start >= 0L ? \ 1538 + (charf *)&s->window[(unsigned)s->block_start] : \ 1539 + (charf *)Z_NULL), \ 1540 + (ulg)((long)s->strstart - s->block_start), \ 1541 + (last)); \ 1542 + s->block_start = s->strstart; \ 1543 + flush_pending(s->strm); \ 1544 + Tracev((stderr,"[FLUSH]")); \ 1545 +} 1546 + 1547 +/* Same but force premature exit if necessary. */ 1548 +#define FLUSH_BLOCK(s, last) { \ 1549 + FLUSH_BLOCK_ONLY(s, last); \ 1550 + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ 1551 +} 1552 + 1553 +/* =========================================================================== 1554 + * Copy without compression as much as possible from the input stream, return 1555 + * the current block state. 1556 + * This function does not insert new strings in the dictionary since 1557 + * uncompressible data is probably not useful. This function is used 1558 + * only for the level=0 compression option. 1559 + * NOTE: this function should be optimized to avoid extra copying from 1560 + * window to pending_buf. 1561 + */ 1562 +local block_state deflate_stored(s, flush) 1563 + deflate_state *s; 1564 + int flush; 1565 +{ 1566 + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 1567 + * to pending_buf_size, and each stored block has a 5 byte header: 1568 + */ 1569 + ulg max_block_size = 0xffff; 1570 + ulg max_start; 1571 + 1572 + if (max_block_size > s->pending_buf_size - 5) { 1573 + max_block_size = s->pending_buf_size - 5; 1574 + } 1575 + 1576 + /* Copy as much as possible from input to output: */ 1577 + for (;;) { 1578 + /* Fill the window as much as possible: */ 1579 + if (s->lookahead <= 1) { 1580 + 1581 + Assert(s->strstart < s->w_size+MAX_DIST(s) || 1582 + s->block_start >= (long)s->w_size, "slide too late"); 1583 + 1584 + fill_window(s); 1585 + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; 1586 + 1587 + if (s->lookahead == 0) break; /* flush the current block */ 1588 + } 1589 + Assert(s->block_start >= 0L, "block gone"); 1590 + 1591 + s->strstart += s->lookahead; 1592 + s->lookahead = 0; 1593 + 1594 + /* Emit a stored block if pending_buf will be full: */ 1595 + max_start = s->block_start + max_block_size; 1596 + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { 1597 + /* strstart == 0 is possible when wraparound on 16-bit machine */ 1598 + s->lookahead = (uInt)(s->strstart - max_start); 1599 + s->strstart = (uInt)max_start; 1600 + FLUSH_BLOCK(s, 0); 1601 + } 1602 + /* Flush if we may have to slide, otherwise block_start may become 1603 + * negative and the data will be gone: 1604 + */ 1605 + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { 1606 + FLUSH_BLOCK(s, 0); 1607 + } 1608 + } 1609 + s->insert = 0; 1610 + if (flush == Z_FINISH) { 1611 + FLUSH_BLOCK(s, 1); 1612 + return finish_done; 1613 + } 1614 + if ((long)s->strstart > s->block_start) 1615 + FLUSH_BLOCK(s, 0); 1616 + return block_done; 1617 +} 1618 + 1619 +/* =========================================================================== 1620 + * Compress as much as possible from the input stream, return the current 1621 + * block state. 1622 + * This function does not perform lazy evaluation of matches and inserts 1623 + * new strings in the dictionary only for unmatched strings or for short 1624 + * matches. It is used only for the fast compression options. 1625 + */ 1626 +local block_state deflate_fast(s, flush) 1627 + deflate_state *s; 1628 + int flush; 1629 +{ 1630 + IPos hash_head; /* head of the hash chain */ 1631 + int bflush; /* set if current block must be flushed */ 1632 + 1633 + for (;;) { 1634 + /* Make sure that we always have enough lookahead, except 1635 + * at the end of the input file. We need MAX_MATCH bytes 1636 + * for the next match, plus MIN_MATCH bytes to insert the 1637 + * string following the next match. 1638 + */ 1639 + if (s->lookahead < MIN_LOOKAHEAD) { 1640 + fill_window(s); 1641 + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1642 + return need_more; 1643 + } 1644 + if (s->lookahead == 0) break; /* flush the current block */ 1645 + } 1646 + 1647 + /* Insert the string window[strstart .. strstart+2] in the 1648 + * dictionary, and set hash_head to the head of the hash chain: 1649 + */ 1650 + hash_head = NIL; 1651 + if (s->lookahead >= MIN_MATCH) { 1652 + INSERT_STRING(s, s->strstart, hash_head); 1653 + } 1654 + 1655 + /* Find the longest match, discarding those <= prev_length. 1656 + * At this point we have always match_length < MIN_MATCH 1657 + */ 1658 + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { 1659 + /* To simplify the code, we prevent matches with the string 1660 + * of window index 0 (in particular we have to avoid a match 1661 + * of the string with itself at the start of the input file). 1662 + */ 1663 + s->match_length = longest_match (s, hash_head); 1664 + /* longest_match() sets match_start */ 1665 + } 1666 + if (s->match_length >= MIN_MATCH) { 1667 + check_match(s, s->strstart, s->match_start, s->match_length); 1668 + 1669 + _tr_tally_dist(s, s->strstart - s->match_start, 1670 + s->match_length - MIN_MATCH, bflush); 1671 + 1672 + s->lookahead -= s->match_length; 1673 + 1674 + /* Insert new strings in the hash table only if the match length 1675 + * is not too large. This saves time but degrades compression. 1676 + */ 1677 +#ifndef FASTEST 1678 + if (s->match_length <= s->max_insert_length && 1679 + s->lookahead >= MIN_MATCH) { 1680 + s->match_length--; /* string at strstart already in table */ 1681 + do { 1682 + s->strstart++; 1683 + INSERT_STRING(s, s->strstart, hash_head); 1684 + /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1685 + * always MIN_MATCH bytes ahead. 1686 + */ 1687 + } while (--s->match_length != 0); 1688 + s->strstart++; 1689 + } else 1690 +#endif 1691 + { 1692 + s->strstart += s->match_length; 1693 + s->match_length = 0; 1694 + s->ins_h = s->window[s->strstart]; 1695 + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 1696 +#if MIN_MATCH != 3 1697 + Call UPDATE_HASH() MIN_MATCH-3 more times 1698 +#endif 1699 + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not 1700 + * matter since it will be recomputed at next deflate call. 1701 + */ 1702 + } 1703 + } else { 1704 + /* No match, output a literal byte */ 1705 + Tracevv((stderr,"%c", s->window[s->strstart])); 1706 + _tr_tally_lit (s, s->window[s->strstart], bflush); 1707 + s->lookahead--; 1708 + s->strstart++; 1709 + } 1710 + if (bflush) FLUSH_BLOCK(s, 0); 1711 + } 1712 + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; 1713 + if (flush == Z_FINISH) { 1714 + FLUSH_BLOCK(s, 1); 1715 + return finish_done; 1716 + } 1717 + if (s->last_lit) 1718 + FLUSH_BLOCK(s, 0); 1719 + return block_done; 1720 +} 1721 + 1722 +#ifndef FASTEST 1723 +/* =========================================================================== 1724 + * Same as above, but achieves better compression. We use a lazy 1725 + * evaluation for matches: a match is finally adopted only if there is 1726 + * no better match at the next window position. 1727 + */ 1728 +local block_state deflate_slow(s, flush) 1729 + deflate_state *s; 1730 + int flush; 1731 +{ 1732 + IPos hash_head; /* head of hash chain */ 1733 + int bflush; /* set if current block must be flushed */ 1734 + 1735 + /* Process the input block. */ 1736 + for (;;) { 1737 + /* Make sure that we always have enough lookahead, except 1738 + * at the end of the input file. We need MAX_MATCH bytes 1739 + * for the next match, plus MIN_MATCH bytes to insert the 1740 + * string following the next match. 1741 + */ 1742 + if (s->lookahead < MIN_LOOKAHEAD) { 1743 + fill_window(s); 1744 + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1745 + return need_more; 1746 + } 1747 + if (s->lookahead == 0) break; /* flush the current block */ 1748 + } 1749 + 1750 + /* Insert the string window[strstart .. strstart+2] in the 1751 + * dictionary, and set hash_head to the head of the hash chain: 1752 + */ 1753 + hash_head = NIL; 1754 + if (s->lookahead >= MIN_MATCH) { 1755 + INSERT_STRING(s, s->strstart, hash_head); 1756 + } 1757 + 1758 + /* Find the longest match, discarding those <= prev_length. 1759 + */ 1760 + s->prev_length = s->match_length, s->prev_match = s->match_start; 1761 + s->match_length = MIN_MATCH-1; 1762 + 1763 + if (hash_head != NIL && s->prev_length < s->max_lazy_match && 1764 + s->strstart - hash_head <= MAX_DIST(s)) { 1765 + /* To simplify the code, we prevent matches with the string 1766 + * of window index 0 (in particular we have to avoid a match 1767 + * of the string with itself at the start of the input file). 1768 + */ 1769 + s->match_length = longest_match (s, hash_head); 1770 + /* longest_match() sets match_start */ 1771 + 1772 + if (s->match_length <= 5 && (s->strategy == Z_FILTERED 1773 +#if TOO_FAR <= 32767 1774 + || (s->match_length == MIN_MATCH && 1775 + s->strstart - s->match_start > TOO_FAR) 1776 +#endif 1777 + )) { 1778 + 1779 + /* If prev_match is also MIN_MATCH, match_start is garbage 1780 + * but we will ignore the current match anyway. 1781 + */ 1782 + s->match_length = MIN_MATCH-1; 1783 + } 1784 + } 1785 + /* If there was a match at the previous step and the current 1786 + * match is not better, output the previous match: 1787 + */ 1788 + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 1789 + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 1790 + /* Do not insert strings in hash table beyond this. */ 1791 + 1792 + check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1793 + 1794 + _tr_tally_dist(s, s->strstart -1 - s->prev_match, 1795 + s->prev_length - MIN_MATCH, bflush); 1796 + 1797 + /* Insert in hash table all strings up to the end of the match. 1798 + * strstart-1 and strstart are already inserted. If there is not 1799 + * enough lookahead, the last two strings are not inserted in 1800 + * the hash table. 1801 + */ 1802 + s->lookahead -= s->prev_length-1; 1803 + s->prev_length -= 2; 1804 + do { 1805 + if (++s->strstart <= max_insert) { 1806 + INSERT_STRING(s, s->strstart, hash_head); 1807 + } 1808 + } while (--s->prev_length != 0); 1809 + s->match_available = 0; 1810 + s->match_length = MIN_MATCH-1; 1811 + s->strstart++; 1812 + 1813 + if (bflush) FLUSH_BLOCK(s, 0); 1814 + 1815 + } else if (s->match_available) { 1816 + /* If there was no match at the previous position, output a 1817 + * single literal. If there was a match but the current match 1818 + * is longer, truncate the previous match to a single literal. 1819 + */ 1820 + Tracevv((stderr,"%c", s->window[s->strstart-1])); 1821 + _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1822 + if (bflush) { 1823 + FLUSH_BLOCK_ONLY(s, 0); 1824 + } 1825 + s->strstart++; 1826 + s->lookahead--; 1827 + if (s->strm->avail_out == 0) return need_more; 1828 + } else { 1829 + /* There is no previous match to compare with, wait for 1830 + * the next step to decide. 1831 + */ 1832 + s->match_available = 1; 1833 + s->strstart++; 1834 + s->lookahead--; 1835 + } 1836 + } 1837 + Assert (flush != Z_NO_FLUSH, "no flush?"); 1838 + if (s->match_available) { 1839 + Tracevv((stderr,"%c", s->window[s->strstart-1])); 1840 + _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1841 + s->match_available = 0; 1842 + } 1843 + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; 1844 + if (flush == Z_FINISH) { 1845 + FLUSH_BLOCK(s, 1); 1846 + return finish_done; 1847 + } 1848 + if (s->last_lit) 1849 + FLUSH_BLOCK(s, 0); 1850 + return block_done; 1851 +} 1852 +#endif /* FASTEST */ 1853 + 1854 +/* =========================================================================== 1855 + * For Z_RLE, simply look for runs of bytes, generate matches only of distance 1856 + * one. Do not maintain a hash table. (It will be regenerated if this run of 1857 + * deflate switches away from Z_RLE.) 1858 + */ 1859 +local block_state deflate_rle(s, flush) 1860 + deflate_state *s; 1861 + int flush; 1862 +{ 1863 + int bflush; /* set if current block must be flushed */ 1864 + uInt prev; /* byte at distance one to match */ 1865 + Bytef *scan, *strend; /* scan goes up to strend for length of run */ 1866 + 1867 + for (;;) { 1868 + /* Make sure that we always have enough lookahead, except 1869 + * at the end of the input file. We need MAX_MATCH bytes 1870 + * for the longest run, plus one for the unrolled loop. 1871 + */ 1872 + if (s->lookahead <= MAX_MATCH) { 1873 + fill_window(s); 1874 + if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { 1875 + return need_more; 1876 + } 1877 + if (s->lookahead == 0) break; /* flush the current block */ 1878 + } 1879 + 1880 + /* See how many times the previous byte repeats */ 1881 + s->match_length = 0; 1882 + if (s->lookahead >= MIN_MATCH && s->strstart > 0) { 1883 + scan = s->window + s->strstart - 1; 1884 + prev = *scan; 1885 + if (prev == *++scan && prev == *++scan && prev == *++scan) { 1886 + strend = s->window + s->strstart + MAX_MATCH; 1887 + do { 1888 + } while (prev == *++scan && prev == *++scan && 1889 + prev == *++scan && prev == *++scan && 1890 + prev == *++scan && prev == *++scan && 1891 + prev == *++scan && prev == *++scan && 1892 + scan < strend); 1893 + s->match_length = MAX_MATCH - (int)(strend - scan); 1894 + if (s->match_length > s->lookahead) 1895 + s->match_length = s->lookahead; 1896 + } 1897 + Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); 1898 + } 1899 + 1900 + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ 1901 + if (s->match_length >= MIN_MATCH) { 1902 + check_match(s, s->strstart, s->strstart - 1, s->match_length); 1903 + 1904 + _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); 1905 + 1906 + s->lookahead -= s->match_length; 1907 + s->strstart += s->match_length; 1908 + s->match_length = 0; 1909 + } else { 1910 + /* No match, output a literal byte */ 1911 + Tracevv((stderr,"%c", s->window[s->strstart])); 1912 + _tr_tally_lit (s, s->window[s->strstart], bflush); 1913 + s->lookahead--; 1914 + s->strstart++; 1915 + } 1916 + if (bflush) FLUSH_BLOCK(s, 0); 1917 + } 1918 + s->insert = 0; 1919 + if (flush == Z_FINISH) { 1920 + FLUSH_BLOCK(s, 1); 1921 + return finish_done; 1922 + } 1923 + if (s->last_lit) 1924 + FLUSH_BLOCK(s, 0); 1925 + return block_done; 1926 +} 1927 + 1928 +/* =========================================================================== 1929 + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. 1930 + * (It will be regenerated if this run of deflate switches away from Huffman.) 1931 + */ 1932 +local block_state deflate_huff(s, flush) 1933 + deflate_state *s; 1934 + int flush; 1935 +{ 1936 + int bflush; /* set if current block must be flushed */ 1937 + 1938 + for (;;) { 1939 + /* Make sure that we have a literal to write. */ 1940 + if (s->lookahead == 0) { 1941 + fill_window(s); 1942 + if (s->lookahead == 0) { 1943 + if (flush == Z_NO_FLUSH) 1944 + return need_more; 1945 + break; /* flush the current block */ 1946 + } 1947 + } 1948 + 1949 + /* Output a literal byte */ 1950 + s->match_length = 0; 1951 + Tracevv((stderr,"%c", s->window[s->strstart])); 1952 + _tr_tally_lit (s, s->window[s->strstart], bflush); 1953 + s->lookahead--; 1954 + s->strstart++; 1955 + if (bflush) FLUSH_BLOCK(s, 0); 1956 + } 1957 + s->insert = 0; 1958 + if (flush == Z_FINISH) { 1959 + FLUSH_BLOCK(s, 1); 1960 + return finish_done; 1961 + } 1962 + if (s->last_lit) 1963 + FLUSH_BLOCK(s, 0); 1964 + return block_done; 1965 +}
Added compat/zlib/deflate.h.
1 +/* deflate.h -- internal compression state 2 + * Copyright (C) 1995-2012 Jean-loup Gailly 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* @(#) $Id$ */ 12 + 13 +#ifndef DEFLATE_H 14 +#define DEFLATE_H 15 + 16 +#include "zutil.h" 17 + 18 +/* define NO_GZIP when compiling if you want to disable gzip header and 19 + trailer creation by deflate(). NO_GZIP would be used to avoid linking in 20 + the crc code when it is not needed. For shared libraries, gzip encoding 21 + should be left enabled. */ 22 +#ifndef NO_GZIP 23 +# define GZIP 24 +#endif 25 + 26 +/* =========================================================================== 27 + * Internal compression state. 28 + */ 29 + 30 +#define LENGTH_CODES 29 31 +/* number of length codes, not counting the special END_BLOCK code */ 32 + 33 +#define LITERALS 256 34 +/* number of literal bytes 0..255 */ 35 + 36 +#define L_CODES (LITERALS+1+LENGTH_CODES) 37 +/* number of Literal or Length codes, including the END_BLOCK code */ 38 + 39 +#define D_CODES 30 40 +/* number of distance codes */ 41 + 42 +#define BL_CODES 19 43 +/* number of codes used to transfer the bit lengths */ 44 + 45 +#define HEAP_SIZE (2*L_CODES+1) 46 +/* maximum heap size */ 47 + 48 +#define MAX_BITS 15 49 +/* All codes must not exceed MAX_BITS bits */ 50 + 51 +#define Buf_size 16 52 +/* size of bit buffer in bi_buf */ 53 + 54 +#define INIT_STATE 42 55 +#define EXTRA_STATE 69 56 +#define NAME_STATE 73 57 +#define COMMENT_STATE 91 58 +#define HCRC_STATE 103 59 +#define BUSY_STATE 113 60 +#define FINISH_STATE 666 61 +/* Stream status */ 62 + 63 + 64 +/* Data structure describing a single value and its code string. */ 65 +typedef struct ct_data_s { 66 + union { 67 + ush freq; /* frequency count */ 68 + ush code; /* bit string */ 69 + } fc; 70 + union { 71 + ush dad; /* father node in Huffman tree */ 72 + ush len; /* length of bit string */ 73 + } dl; 74 +} FAR ct_data; 75 + 76 +#define Freq fc.freq 77 +#define Code fc.code 78 +#define Dad dl.dad 79 +#define Len dl.len 80 + 81 +typedef struct static_tree_desc_s static_tree_desc; 82 + 83 +typedef struct tree_desc_s { 84 + ct_data *dyn_tree; /* the dynamic tree */ 85 + int max_code; /* largest code with non zero frequency */ 86 + static_tree_desc *stat_desc; /* the corresponding static tree */ 87 +} FAR tree_desc; 88 + 89 +typedef ush Pos; 90 +typedef Pos FAR Posf; 91 +typedef unsigned IPos; 92 + 93 +/* A Pos is an index in the character window. We use short instead of int to 94 + * save space in the various tables. IPos is used only for parameter passing. 95 + */ 96 + 97 +typedef struct internal_state { 98 + z_streamp strm; /* pointer back to this zlib stream */ 99 + int status; /* as the name implies */ 100 + Bytef *pending_buf; /* output still pending */ 101 + ulg pending_buf_size; /* size of pending_buf */ 102 + Bytef *pending_out; /* next pending byte to output to the stream */ 103 + uInt pending; /* nb of bytes in the pending buffer */ 104 + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 105 + gz_headerp gzhead; /* gzip header information to write */ 106 + uInt gzindex; /* where in extra, name, or comment */ 107 + Byte method; /* STORED (for zip only) or DEFLATED */ 108 + int last_flush; /* value of flush param for previous deflate call */ 109 + 110 + /* used by deflate.c: */ 111 + 112 + uInt w_size; /* LZ77 window size (32K by default) */ 113 + uInt w_bits; /* log2(w_size) (8..16) */ 114 + uInt w_mask; /* w_size - 1 */ 115 + 116 + Bytef *window; 117 + /* Sliding window. Input bytes are read into the second half of the window, 118 + * and move to the first half later to keep a dictionary of at least wSize 119 + * bytes. With this organization, matches are limited to a distance of 120 + * wSize-MAX_MATCH bytes, but this ensures that IO is always 121 + * performed with a length multiple of the block size. Also, it limits 122 + * the window size to 64K, which is quite useful on MSDOS. 123 + * To do: use the user input buffer as sliding window. 124 + */ 125 + 126 + ulg window_size; 127 + /* Actual size of window: 2*wSize, except when the user input buffer 128 + * is directly used as sliding window. 129 + */ 130 + 131 + Posf *prev; 132 + /* Link to older string with same hash index. To limit the size of this 133 + * array to 64K, this link is maintained only for the last 32K strings. 134 + * An index in this array is thus a window index modulo 32K. 135 + */ 136 + 137 + Posf *head; /* Heads of the hash chains or NIL. */ 138 + 139 + uInt ins_h; /* hash index of string to be inserted */ 140 + uInt hash_size; /* number of elements in hash table */ 141 + uInt hash_bits; /* log2(hash_size) */ 142 + uInt hash_mask; /* hash_size-1 */ 143 + 144 + uInt hash_shift; 145 + /* Number of bits by which ins_h must be shifted at each input 146 + * step. It must be such that after MIN_MATCH steps, the oldest 147 + * byte no longer takes part in the hash key, that is: 148 + * hash_shift * MIN_MATCH >= hash_bits 149 + */ 150 + 151 + long block_start; 152 + /* Window position at the beginning of the current output block. Gets 153 + * negative when the window is moved backwards. 154 + */ 155 + 156 + uInt match_length; /* length of best match */ 157 + IPos prev_match; /* previous match */ 158 + int match_available; /* set if previous match exists */ 159 + uInt strstart; /* start of string to insert */ 160 + uInt match_start; /* start of matching string */ 161 + uInt lookahead; /* number of valid bytes ahead in window */ 162 + 163 + uInt prev_length; 164 + /* Length of the best match at previous step. Matches not greater than this 165 + * are discarded. This is used in the lazy match evaluation. 166 + */ 167 + 168 + uInt max_chain_length; 169 + /* To speed up deflation, hash chains are never searched beyond this 170 + * length. A higher limit improves compression ratio but degrades the 171 + * speed. 172 + */ 173 + 174 + uInt max_lazy_match; 175 + /* Attempt to find a better match only when the current match is strictly 176 + * smaller than this value. This mechanism is used only for compression 177 + * levels >= 4. 178 + */ 179 +# define max_insert_length max_lazy_match 180 + /* Insert new strings in the hash table only if the match length is not 181 + * greater than this length. This saves time but degrades compression. 182 + * max_insert_length is used only for compression levels <= 3. 183 + */ 184 + 185 + int level; /* compression level (1..9) */ 186 + int strategy; /* favor or force Huffman coding*/ 187 + 188 + uInt good_match; 189 + /* Use a faster search when the previous match is longer than this */ 190 + 191 + int nice_match; /* Stop searching when current match exceeds this */ 192 + 193 + /* used by trees.c: */ 194 + /* Didn't use ct_data typedef below to suppress compiler warning */ 195 + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 196 + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 197 + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 198 + 199 + struct tree_desc_s l_desc; /* desc. for literal tree */ 200 + struct tree_desc_s d_desc; /* desc. for distance tree */ 201 + struct tree_desc_s bl_desc; /* desc. for bit length tree */ 202 + 203 + ush bl_count[MAX_BITS+1]; 204 + /* number of codes at each bit length for an optimal tree */ 205 + 206 + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 207 + int heap_len; /* number of elements in the heap */ 208 + int heap_max; /* element of largest frequency */ 209 + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 210 + * The same heap array is used to build all trees. 211 + */ 212 + 213 + uch depth[2*L_CODES+1]; 214 + /* Depth of each subtree used as tie breaker for trees of equal frequency 215 + */ 216 + 217 + uchf *l_buf; /* buffer for literals or lengths */ 218 + 219 + uInt lit_bufsize; 220 + /* Size of match buffer for literals/lengths. There are 4 reasons for 221 + * limiting lit_bufsize to 64K: 222 + * - frequencies can be kept in 16 bit counters 223 + * - if compression is not successful for the first block, all input 224 + * data is still in the window so we can still emit a stored block even 225 + * when input comes from standard input. (This can also be done for 226 + * all blocks if lit_bufsize is not greater than 32K.) 227 + * - if compression is not successful for a file smaller than 64K, we can 228 + * even emit a stored file instead of a stored block (saving 5 bytes). 229 + * This is applicable only for zip (not gzip or zlib). 230 + * - creating new Huffman trees less frequently may not provide fast 231 + * adaptation to changes in the input data statistics. (Take for 232 + * example a binary file with poorly compressible code followed by 233 + * a highly compressible string table.) Smaller buffer sizes give 234 + * fast adaptation but have of course the overhead of transmitting 235 + * trees more frequently. 236 + * - I can't count above 4 237 + */ 238 + 239 + uInt last_lit; /* running index in l_buf */ 240 + 241 + ushf *d_buf; 242 + /* Buffer for distances. To simplify the code, d_buf and l_buf have 243 + * the same number of elements. To use different lengths, an extra flag 244 + * array would be necessary. 245 + */ 246 + 247 + ulg opt_len; /* bit length of current block with optimal trees */ 248 + ulg static_len; /* bit length of current block with static trees */ 249 + uInt matches; /* number of string matches in current block */ 250 + uInt insert; /* bytes at end of window left to insert */ 251 + 252 +#ifdef DEBUG 253 + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 254 + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ 255 +#endif 256 + 257 + ush bi_buf; 258 + /* Output buffer. bits are inserted starting at the bottom (least 259 + * significant bits). 260 + */ 261 + int bi_valid; 262 + /* Number of valid bits in bi_buf. All bits above the last valid bit 263 + * are always zero. 264 + */ 265 + 266 + ulg high_water; 267 + /* High water mark offset in window for initialized bytes -- bytes above 268 + * this are set to zero in order to avoid memory check warnings when 269 + * longest match routines access bytes past the input. This is then 270 + * updated to the new high water mark. 271 + */ 272 + 273 +} FAR deflate_state; 274 + 275 +/* Output a byte on the stream. 276 + * IN assertion: there is enough room in pending_buf. 277 + */ 278 +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} 279 + 280 + 281 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 282 +/* Minimum amount of lookahead, except at the end of the input file. 283 + * See deflate.c for comments about the MIN_MATCH+1. 284 + */ 285 + 286 +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) 287 +/* In order to simplify the code, particularly on 16 bit machines, match 288 + * distances are limited to MAX_DIST instead of WSIZE. 289 + */ 290 + 291 +#define WIN_INIT MAX_MATCH 292 +/* Number of bytes after end of data in window to initialize in order to avoid 293 + memory checker errors from longest match routines */ 294 + 295 + /* in trees.c */ 296 +void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); 297 +int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 298 +void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, 299 + ulg stored_len, int last)); 300 +void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); 301 +void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); 302 +void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, 303 + ulg stored_len, int last)); 304 + 305 +#define d_code(dist) \ 306 + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 307 +/* Mapping from a distance to a distance code. dist is the distance - 1 and 308 + * must not have side effects. _dist_code[256] and _dist_code[257] are never 309 + * used. 310 + */ 311 + 312 +#ifndef DEBUG 313 +/* Inline versions of _tr_tally for speed: */ 314 + 315 +#if defined(GEN_TREES_H) || !defined(STDC) 316 + extern uch ZLIB_INTERNAL _length_code[]; 317 + extern uch ZLIB_INTERNAL _dist_code[]; 318 +#else 319 + extern const uch ZLIB_INTERNAL _length_code[]; 320 + extern const uch ZLIB_INTERNAL _dist_code[]; 321 +#endif 322 + 323 +# define _tr_tally_lit(s, c, flush) \ 324 + { uch cc = (c); \ 325 + s->d_buf[s->last_lit] = 0; \ 326 + s->l_buf[s->last_lit++] = cc; \ 327 + s->dyn_ltree[cc].Freq++; \ 328 + flush = (s->last_lit == s->lit_bufsize-1); \ 329 + } 330 +# define _tr_tally_dist(s, distance, length, flush) \ 331 + { uch len = (length); \ 332 + ush dist = (distance); \ 333 + s->d_buf[s->last_lit] = dist; \ 334 + s->l_buf[s->last_lit++] = len; \ 335 + dist--; \ 336 + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 337 + s->dyn_dtree[d_code(dist)].Freq++; \ 338 + flush = (s->last_lit == s->lit_bufsize-1); \ 339 + } 340 +#else 341 +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 342 +# define _tr_tally_dist(s, distance, length, flush) \ 343 + flush = _tr_tally(s, distance, length) 344 +#endif 345 + 346 +#endif /* DEFLATE_H */
Added compat/zlib/doc/algorithm.txt.
1 +1. Compression algorithm (deflate) 2 + 3 +The deflation algorithm used by gzip (also zip and zlib) is a variation of 4 +LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in 5 +the input data. The second occurrence of a string is replaced by a 6 +pointer to the previous string, in the form of a pair (distance, 7 +length). Distances are limited to 32K bytes, and lengths are limited 8 +to 258 bytes. When a string does not occur anywhere in the previous 9 +32K bytes, it is emitted as a sequence of literal bytes. (In this 10 +description, `string' must be taken as an arbitrary sequence of bytes, 11 +and is not restricted to printable characters.) 12 + 13 +Literals or match lengths are compressed with one Huffman tree, and 14 +match distances are compressed with another tree. The trees are stored 15 +in a compact form at the start of each block. The blocks can have any 16 +size (except that the compressed data for one block must fit in 17 +available memory). A block is terminated when deflate() determines that 18 +it would be useful to start another block with fresh trees. (This is 19 +somewhat similar to the behavior of LZW-based _compress_.) 20 + 21 +Duplicated strings are found using a hash table. All input strings of 22 +length 3 are inserted in the hash table. A hash index is computed for 23 +the next 3 bytes. If the hash chain for this index is not empty, all 24 +strings in the chain are compared with the current input string, and 25 +the longest match is selected. 26 + 27 +The hash chains are searched starting with the most recent strings, to 28 +favor small distances and thus take advantage of the Huffman encoding. 29 +The hash chains are singly linked. There are no deletions from the 30 +hash chains, the algorithm simply discards matches that are too old. 31 + 32 +To avoid a worst-case situation, very long hash chains are arbitrarily 33 +truncated at a certain length, determined by a runtime option (level 34 +parameter of deflateInit). So deflate() does not always find the longest 35 +possible match but generally finds a match which is long enough. 36 + 37 +deflate() also defers the selection of matches with a lazy evaluation 38 +mechanism. After a match of length N has been found, deflate() searches for 39 +a longer match at the next input byte. If a longer match is found, the 40 +previous match is truncated to a length of one (thus producing a single 41 +literal byte) and the process of lazy evaluation begins again. Otherwise, 42 +the original match is kept, and the next match search is attempted only N 43 +steps later. 44 + 45 +The lazy match evaluation is also subject to a runtime parameter. If 46 +the current match is long enough, deflate() reduces the search for a longer 47 +match, thus speeding up the whole process. If compression ratio is more 48 +important than speed, deflate() attempts a complete second search even if 49 +the first match is already long enough. 50 + 51 +The lazy match evaluation is not performed for the fastest compression 52 +modes (level parameter 1 to 3). For these fast modes, new strings 53 +are inserted in the hash table only when no match was found, or 54 +when the match is not too long. This degrades the compression ratio 55 +but saves time since there are both fewer insertions and fewer searches. 56 + 57 + 58 +2. Decompression algorithm (inflate) 59 + 60 +2.1 Introduction 61 + 62 +The key question is how to represent a Huffman code (or any prefix code) so 63 +that you can decode fast. The most important characteristic is that shorter 64 +codes are much more common than longer codes, so pay attention to decoding the 65 +short codes fast, and let the long codes take longer to decode. 66 + 67 +inflate() sets up a first level table that covers some number of bits of 68 +input less than the length of longest code. It gets that many bits from the 69 +stream, and looks it up in the table. The table will tell if the next 70 +code is that many bits or less and how many, and if it is, it will tell 71 +the value, else it will point to the next level table for which inflate() 72 +grabs more bits and tries to decode a longer code. 73 + 74 +How many bits to make the first lookup is a tradeoff between the time it 75 +takes to decode and the time it takes to build the table. If building the 76 +table took no time (and if you had infinite memory), then there would only 77 +be a first level table to cover all the way to the longest code. However, 78 +building the table ends up taking a lot longer for more bits since short 79 +codes are replicated many times in such a table. What inflate() does is 80 +simply to make the number of bits in the first table a variable, and then 81 +to set that variable for the maximum speed. 82 + 83 +For inflate, which has 286 possible codes for the literal/length tree, the size 84 +of the first table is nine bits. Also the distance trees have 30 possible 85 +values, and the size of the first table is six bits. Note that for each of 86 +those cases, the table ended up one bit longer than the ``average'' code 87 +length, i.e. the code length of an approximately flat code which would be a 88 +little more than eight bits for 286 symbols and a little less than five bits 89 +for 30 symbols. 90 + 91 + 92 +2.2 More details on the inflate table lookup 93 + 94 +Ok, you want to know what this cleverly obfuscated inflate tree actually 95 +looks like. You are correct that it's not a Huffman tree. It is simply a 96 +lookup table for the first, let's say, nine bits of a Huffman symbol. The 97 +symbol could be as short as one bit or as long as 15 bits. If a particular 98 +symbol is shorter than nine bits, then that symbol's translation is duplicated 99 +in all those entries that start with that symbol's bits. For example, if the 100 +symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a 101 +symbol is nine bits long, it appears in the table once. 102 + 103 +If the symbol is longer than nine bits, then that entry in the table points 104 +to another similar table for the remaining bits. Again, there are duplicated 105 +entries as needed. The idea is that most of the time the symbol will be short 106 +and there will only be one table look up. (That's whole idea behind data 107 +compression in the first place.) For the less frequent long symbols, there 108 +will be two lookups. If you had a compression method with really long 109 +symbols, you could have as many levels of lookups as is efficient. For 110 +inflate, two is enough. 111 + 112 +So a table entry either points to another table (in which case nine bits in 113 +the above example are gobbled), or it contains the translation for the symbol 114 +and the number of bits to gobble. Then you start again with the next 115 +ungobbled bit. 116 + 117 +You may wonder: why not just have one lookup table for how ever many bits the 118 +longest symbol is? The reason is that if you do that, you end up spending 119 +more time filling in duplicate symbol entries than you do actually decoding. 120 +At least for deflate's output that generates new trees every several 10's of 121 +kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code 122 +would take too long if you're only decoding several thousand symbols. At the 123 +other extreme, you could make a new table for every bit in the code. In fact, 124 +that's essentially a Huffman tree. But then you spend too much time 125 +traversing the tree while decoding, even for short symbols. 126 + 127 +So the number of bits for the first lookup table is a trade of the time to 128 +fill out the table vs. the time spent looking at the second level and above of 129 +the table. 130 + 131 +Here is an example, scaled down: 132 + 133 +The code being decoded, with 10 symbols, from 1 to 6 bits long: 134 + 135 +A: 0 136 +B: 10 137 +C: 1100 138 +D: 11010 139 +E: 11011 140 +F: 11100 141 +G: 11101 142 +H: 11110 143 +I: 111110 144 +J: 111111 145 + 146 +Let's make the first table three bits long (eight entries): 147 + 148 +000: A,1 149 +001: A,1 150 +010: A,1 151 +011: A,1 152 +100: B,2 153 +101: B,2 154 +110: -> table X (gobble 3 bits) 155 +111: -> table Y (gobble 3 bits) 156 + 157 +Each entry is what the bits decode as and how many bits that is, i.e. how 158 +many bits to gobble. Or the entry points to another table, with the number of 159 +bits to gobble implicit in the size of the table. 160 + 161 +Table X is two bits long since the longest code starting with 110 is five bits 162 +long: 163 + 164 +00: C,1 165 +01: C,1 166 +10: D,2 167 +11: E,2 168 + 169 +Table Y is three bits long since the longest code starting with 111 is six 170 +bits long: 171 + 172 +000: F,2 173 +001: F,2 174 +010: G,2 175 +011: G,2 176 +100: H,2 177 +101: H,2 178 +110: I,3 179 +111: J,3 180 + 181 +So what we have here are three tables with a total of 20 entries that had to 182 +be constructed. That's compared to 64 entries for a single table. Or 183 +compared to 16 entries for a Huffman tree (six two entry tables and one four 184 +entry table). Assuming that the code ideally represents the probability of 185 +the symbols, it takes on the average 1.25 lookups per symbol. That's compared 186 +to one lookup for the single table, or 1.66 lookups per symbol for the 187 +Huffman tree. 188 + 189 +There, I think that gives you a picture of what's going on. For inflate, the 190 +meaning of a particular symbol is often more than just a letter. It can be a 191 +byte (a "literal"), or it can be either a length or a distance which 192 +indicates a base value and a number of bits to fetch after the code that is 193 +added to the base value. Or it might be the special end-of-block code. The 194 +data structures created in inftrees.c try to encode all that information 195 +compactly in the tables. 196 + 197 + 198 +Jean-loup Gailly Mark Adler 199 +jloup@gzip.org madler@alumni.caltech.edu 200 + 201 + 202 +References: 203 + 204 +[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data 205 +Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3, 206 +pp. 337-343. 207 + 208 +``DEFLATE Compressed Data Format Specification'' available in 209 +http://tools.ietf.org/html/rfc1951
Added compat/zlib/doc/rfc1950.txt.
1 + 2 + 3 + 4 + 5 + 6 + 7 +Network Working Group P. Deutsch 8 +Request for Comments: 1950 Aladdin Enterprises 9 +Category: Informational J-L. Gailly 10 + Info-ZIP 11 + May 1996 12 + 13 + 14 + ZLIB Compressed Data Format Specification version 3.3 15 + 16 +Status of This Memo 17 + 18 + This memo provides information for the Internet community. This memo 19 + does not specify an Internet standard of any kind. Distribution of 20 + this memo is unlimited. 21 + 22 +IESG Note: 23 + 24 + The IESG takes no position on the validity of any Intellectual 25 + Property Rights statements contained in this document. 26 + 27 +Notices 28 + 29 + Copyright (c) 1996 L. Peter Deutsch and Jean-Loup Gailly 30 + 31 + Permission is granted to copy and distribute this document for any 32 + purpose and without charge, including translations into other 33 + languages and incorporation into compilations, provided that the 34 + copyright notice and this notice are preserved, and that any 35 + substantive changes or deletions from the original are clearly 36 + marked. 37 + 38 + A pointer to the latest version of this and related documentation in 39 + HTML format can be found at the URL 40 + <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>. 41 + 42 +Abstract 43 + 44 + This specification defines a lossless compressed data format. The 45 + data can be produced or consumed, even for an arbitrarily long 46 + sequentially presented input data stream, using only an a priori 47 + bounded amount of intermediate storage. The format presently uses 48 + the DEFLATE compression method but can be easily extended to use 49 + other compression methods. It can be implemented readily in a manner 50 + not covered by patents. This specification also defines the ADLER-32 51 + checksum (an extension and improvement of the Fletcher checksum), 52 + used for detection of data corruption, and provides an algorithm for 53 + computing it. 54 + 55 + 56 + 57 + 58 +Deutsch & Gailly Informational [Page 1] 59 + 60 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 61 + 62 + 63 +Table of Contents 64 + 65 + 1. Introduction ................................................... 2 66 + 1.1. Purpose ................................................... 2 67 + 1.2. Intended audience ......................................... 3 68 + 1.3. Scope ..................................................... 3 69 + 1.4. Compliance ................................................ 3 70 + 1.5. Definitions of terms and conventions used ................ 3 71 + 1.6. Changes from previous versions ............................ 3 72 + 2. Detailed specification ......................................... 3 73 + 2.1. Overall conventions ....................................... 3 74 + 2.2. Data format ............................................... 4 75 + 2.3. Compliance ................................................ 7 76 + 3. References ..................................................... 7 77 + 4. Source code .................................................... 8 78 + 5. Security Considerations ........................................ 8 79 + 6. Acknowledgements ............................................... 8 80 + 7. Authors' Addresses ............................................. 8 81 + 8. Appendix: Rationale ............................................ 9 82 + 9. Appendix: Sample code ..........................................10 83 + 84 +1. Introduction 85 + 86 + 1.1. Purpose 87 + 88 + The purpose of this specification is to define a lossless 89 + compressed data format that: 90 + 91 + * Is independent of CPU type, operating system, file system, 92 + and character set, and hence can be used for interchange; 93 + 94 + * Can be produced or consumed, even for an arbitrarily long 95 + sequentially presented input data stream, using only an a 96 + priori bounded amount of intermediate storage, and hence can 97 + be used in data communications or similar structures such as 98 + Unix filters; 99 + 100 + * Can use a number of different compression methods; 101 + 102 + * Can be implemented readily in a manner not covered by 103 + patents, and hence can be practiced freely. 104 + 105 + The data format defined by this specification does not attempt to 106 + allow random access to compressed data. 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 +Deutsch & Gailly Informational [Page 2] 115 + 116 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 117 + 118 + 119 + 1.2. Intended audience 120 + 121 + This specification is intended for use by implementors of software 122 + to compress data into zlib format and/or decompress data from zlib 123 + format. 124 + 125 + The text of the specification assumes a basic background in 126 + programming at the level of bits and other primitive data 127 + representations. 128 + 129 + 1.3. Scope 130 + 131 + The specification specifies a compressed data format that can be 132 + used for in-memory compression of a sequence of arbitrary bytes. 133 + 134 + 1.4. Compliance 135 + 136 + Unless otherwise indicated below, a compliant decompressor must be 137 + able to accept and decompress any data set that conforms to all 138 + the specifications presented here; a compliant compressor must 139 + produce data sets that conform to all the specifications presented 140 + here. 141 + 142 + 1.5. Definitions of terms and conventions used 143 + 144 + byte: 8 bits stored or transmitted as a unit (same as an octet). 145 + (For this specification, a byte is exactly 8 bits, even on 146 + machines which store a character on a number of bits different 147 + from 8.) See below, for the numbering of bits within a byte. 148 + 149 + 1.6. Changes from previous versions 150 + 151 + Version 3.1 was the first public release of this specification. 152 + In version 3.2, some terminology was changed and the Adler-32 153 + sample code was rewritten for clarity. In version 3.3, the 154 + support for a preset dictionary was introduced, and the 155 + specification was converted to RFC style. 156 + 157 +2. Detailed specification 158 + 159 + 2.1. Overall conventions 160 + 161 + In the diagrams below, a box like this: 162 + 163 + +---+ 164 + | | <-- the vertical bars might be missing 165 + +---+ 166 + 167 + 168 + 169 + 170 +Deutsch & Gailly Informational [Page 3] 171 + 172 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 173 + 174 + 175 + represents one byte; a box like this: 176 + 177 + +==============+ 178 + | | 179 + +==============+ 180 + 181 + represents a variable number of bytes. 182 + 183 + Bytes stored within a computer do not have a "bit order", since 184 + they are always treated as a unit. However, a byte considered as 185 + an integer between 0 and 255 does have a most- and least- 186 + significant bit, and since we write numbers with the most- 187 + significant digit on the left, we also write bytes with the most- 188 + significant bit on the left. In the diagrams below, we number the 189 + bits of a byte so that bit 0 is the least-significant bit, i.e., 190 + the bits are numbered: 191 + 192 + +--------+ 193 + |76543210| 194 + +--------+ 195 + 196 + Within a computer, a number may occupy multiple bytes. All 197 + multi-byte numbers in the format described here are stored with 198 + the MOST-significant byte first (at the lower memory address). 199 + For example, the decimal number 520 is stored as: 200 + 201 + 0 1 202 + +--------+--------+ 203 + |00000010|00001000| 204 + +--------+--------+ 205 + ^ ^ 206 + | | 207 + | + less significant byte = 8 208 + + more significant byte = 2 x 256 209 + 210 + 2.2. Data format 211 + 212 + A zlib stream has the following structure: 213 + 214 + 0 1 215 + +---+---+ 216 + |CMF|FLG| (more-->) 217 + +---+---+ 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 +Deutsch & Gailly Informational [Page 4] 227 + 228 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 229 + 230 + 231 + (if FLG.FDICT set) 232 + 233 + 0 1 2 3 234 + +---+---+---+---+ 235 + | DICTID | (more-->) 236 + +---+---+---+---+ 237 + 238 + +=====================+---+---+---+---+ 239 + |...compressed data...| ADLER32 | 240 + +=====================+---+---+---+---+ 241 + 242 + Any data which may appear after ADLER32 are not part of the zlib 243 + stream. 244 + 245 + CMF (Compression Method and flags) 246 + This byte is divided into a 4-bit compression method and a 4- 247 + bit information field depending on the compression method. 248 + 249 + bits 0 to 3 CM Compression method 250 + bits 4 to 7 CINFO Compression info 251 + 252 + CM (Compression method) 253 + This identifies the compression method used in the file. CM = 8 254 + denotes the "deflate" compression method with a window size up 255 + to 32K. This is the method used by gzip and PNG (see 256 + references [1] and [2] in Chapter 3, below, for the reference 257 + documents). CM = 15 is reserved. It might be used in a future 258 + version of this specification to indicate the presence of an 259 + extra field before the compressed data. 260 + 261 + CINFO (Compression info) 262 + For CM = 8, CINFO is the base-2 logarithm of the LZ77 window 263 + size, minus eight (CINFO=7 indicates a 32K window size). Values 264 + of CINFO above 7 are not allowed in this version of the 265 + specification. CINFO is not defined in this specification for 266 + CM not equal to 8. 267 + 268 + FLG (FLaGs) 269 + This flag byte is divided as follows: 270 + 271 + bits 0 to 4 FCHECK (check bits for CMF and FLG) 272 + bit 5 FDICT (preset dictionary) 273 + bits 6 to 7 FLEVEL (compression level) 274 + 275 + The FCHECK value must be such that CMF and FLG, when viewed as 276 + a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), 277 + is a multiple of 31. 278 + 279 + 280 + 281 + 282 +Deutsch & Gailly Informational [Page 5] 283 + 284 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 285 + 286 + 287 + FDICT (Preset dictionary) 288 + If FDICT is set, a DICT dictionary identifier is present 289 + immediately after the FLG byte. The dictionary is a sequence of 290 + bytes which are initially fed to the compressor without 291 + producing any compressed output. DICT is the Adler-32 checksum 292 + of this sequence of bytes (see the definition of ADLER32 293 + below). The decompressor can use this identifier to determine 294 + which dictionary has been used by the compressor. 295 + 296 + FLEVEL (Compression level) 297 + These flags are available for use by specific compression 298 + methods. The "deflate" method (CM = 8) sets these flags as 299 + follows: 300 + 301 + 0 - compressor used fastest algorithm 302 + 1 - compressor used fast algorithm 303 + 2 - compressor used default algorithm 304 + 3 - compressor used maximum compression, slowest algorithm 305 + 306 + The information in FLEVEL is not needed for decompression; it 307 + is there to indicate if recompression might be worthwhile. 308 + 309 + compressed data 310 + For compression method 8, the compressed data is stored in the 311 + deflate compressed data format as described in the document 312 + "DEFLATE Compressed Data Format Specification" by L. Peter 313 + Deutsch. (See reference [3] in Chapter 3, below) 314 + 315 + Other compressed data formats are not specified in this version 316 + of the zlib specification. 317 + 318 + ADLER32 (Adler-32 checksum) 319 + This contains a checksum value of the uncompressed data 320 + (excluding any dictionary data) computed according to Adler-32 321 + algorithm. This algorithm is a 32-bit extension and improvement 322 + of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 323 + standard. See references [4] and [5] in Chapter 3, below) 324 + 325 + Adler-32 is composed of two sums accumulated per byte: s1 is 326 + the sum of all bytes, s2 is the sum of all s1 values. Both sums 327 + are done modulo 65521. s1 is initialized to 1, s2 to zero. The 328 + Adler-32 checksum is stored as s2*65536 + s1 in most- 329 + significant-byte first (network) order. 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 +Deutsch & Gailly Informational [Page 6] 339 + 340 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 341 + 342 + 343 + 2.3. Compliance 344 + 345 + A compliant compressor must produce streams with correct CMF, FLG 346 + and ADLER32, but need not support preset dictionaries. When the 347 + zlib data format is used as part of another standard data format, 348 + the compressor may use only preset dictionaries that are specified 349 + by this other data format. If this other format does not use the 350 + preset dictionary feature, the compressor must not set the FDICT 351 + flag. 352 + 353 + A compliant decompressor must check CMF, FLG, and ADLER32, and 354 + provide an error indication if any of these have incorrect values. 355 + A compliant decompressor must give an error indication if CM is 356 + not one of the values defined in this specification (only the 357 + value 8 is permitted in this version), since another value could 358 + indicate the presence of new features that would cause subsequent 359 + data to be interpreted incorrectly. A compliant decompressor must 360 + give an error indication if FDICT is set and DICTID is not the 361 + identifier of a known preset dictionary. A decompressor may 362 + ignore FLEVEL and still be compliant. When the zlib data format 363 + is being used as a part of another standard format, a compliant 364 + decompressor must support all the preset dictionaries specified by 365 + the other format. When the other format does not use the preset 366 + dictionary feature, a compliant decompressor must reject any 367 + stream in which the FDICT flag is set. 368 + 369 +3. References 370 + 371 + [1] Deutsch, L.P.,"GZIP Compressed Data Format Specification", 372 + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ 373 + 374 + [2] Thomas Boutell, "PNG (Portable Network Graphics) specification", 375 + available in ftp://ftp.uu.net/graphics/png/documents/ 376 + 377 + [3] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", 378 + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ 379 + 380 + [4] Fletcher, J. G., "An Arithmetic Checksum for Serial 381 + Transmissions," IEEE Transactions on Communications, Vol. COM-30, 382 + No. 1, January 1982, pp. 247-252. 383 + 384 + [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," 385 + November, 1993, pp. 144, 145. (Available from 386 + gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073. 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 +Deutsch & Gailly Informational [Page 7] 395 + 396 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 397 + 398 + 399 +4. Source code 400 + 401 + Source code for a C language implementation of a "zlib" compliant 402 + library is available at ftp://ftp.uu.net/pub/archiving/zip/zlib/. 403 + 404 +5. Security Considerations 405 + 406 + A decoder that fails to check the ADLER32 checksum value may be 407 + subject to undetected data corruption. 408 + 409 +6. Acknowledgements 410 + 411 + Trademarks cited in this document are the property of their 412 + respective owners. 413 + 414 + Jean-Loup Gailly and Mark Adler designed the zlib format and wrote 415 + the related software described in this specification. Glenn 416 + Randers-Pehrson converted this document to RFC and HTML format. 417 + 418 +7. Authors' Addresses 419 + 420 + L. Peter Deutsch 421 + Aladdin Enterprises 422 + 203 Santa Margarita Ave. 423 + Menlo Park, CA 94025 424 + 425 + Phone: (415) 322-0103 (AM only) 426 + FAX: (415) 322-1734 427 + EMail: <ghost@aladdin.com> 428 + 429 + 430 + Jean-Loup Gailly 431 + 432 + EMail: <gzip@prep.ai.mit.edu> 433 + 434 + Questions about the technical content of this specification can be 435 + sent by email to 436 + 437 + Jean-Loup Gailly <gzip@prep.ai.mit.edu> and 438 + Mark Adler <madler@alumni.caltech.edu> 439 + 440 + Editorial comments on this specification can be sent by email to 441 + 442 + L. Peter Deutsch <ghost@aladdin.com> and 443 + Glenn Randers-Pehrson <randeg@alumni.rpi.edu> 444 + 445 + 446 + 447 + 448 + 449 + 450 +Deutsch & Gailly Informational [Page 8] 451 + 452 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 453 + 454 + 455 +8. Appendix: Rationale 456 + 457 + 8.1. Preset dictionaries 458 + 459 + A preset dictionary is specially useful to compress short input 460 + sequences. The compressor can take advantage of the dictionary 461 + context to encode the input in a more compact manner. The 462 + decompressor can be initialized with the appropriate context by 463 + virtually decompressing a compressed version of the dictionary 464 + without producing any output. However for certain compression 465 + algorithms such as the deflate algorithm this operation can be 466 + achieved without actually performing any decompression. 467 + 468 + The compressor and the decompressor must use exactly the same 469 + dictionary. The dictionary may be fixed or may be chosen among a 470 + certain number of predefined dictionaries, according to the kind 471 + of input data. The decompressor can determine which dictionary has 472 + been chosen by the compressor by checking the dictionary 473 + identifier. This document does not specify the contents of 474 + predefined dictionaries, since the optimal dictionaries are 475 + application specific. Standard data formats using this feature of 476 + the zlib specification must precisely define the allowed 477 + dictionaries. 478 + 479 + 8.2. The Adler-32 algorithm 480 + 481 + The Adler-32 algorithm is much faster than the CRC32 algorithm yet 482 + still provides an extremely low probability of undetected errors. 483 + 484 + The modulo on unsigned long accumulators can be delayed for 5552 485 + bytes, so the modulo operation time is negligible. If the bytes 486 + are a, b, c, the second sum is 3a + 2b + c + 3, and so is position 487 + and order sensitive, unlike the first sum, which is just a 488 + checksum. That 65521 is prime is important to avoid a possible 489 + large class of two-byte errors that leave the check unchanged. 490 + (The Fletcher checksum uses 255, which is not prime and which also 491 + makes the Fletcher check insensitive to single byte changes 0 <-> 492 + 255.) 493 + 494 + The sum s1 is initialized to 1 instead of zero to make the length 495 + of the sequence part of s2, so that the length does not have to be 496 + checked separately. (Any sequence of zeroes has a Fletcher 497 + checksum of zero.) 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 +Deutsch & Gailly Informational [Page 9] 507 + 508 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 509 + 510 + 511 +9. Appendix: Sample code 512 + 513 + The following C code computes the Adler-32 checksum of a data buffer. 514 + It is written for clarity, not for speed. The sample code is in the 515 + ANSI C programming language. Non C users may find it easier to read 516 + with these hints: 517 + 518 + & Bitwise AND operator. 519 + >> Bitwise right shift operator. When applied to an 520 + unsigned quantity, as here, right shift inserts zero bit(s) 521 + at the left. 522 + << Bitwise left shift operator. Left shift inserts zero 523 + bit(s) at the right. 524 + ++ "n++" increments the variable n. 525 + % modulo operator: a % b is the remainder of a divided by b. 526 + 527 + #define BASE 65521 /* largest prime smaller than 65536 */ 528 + 529 + /* 530 + Update a running Adler-32 checksum with the bytes buf[0..len-1] 531 + and return the updated checksum. The Adler-32 checksum should be 532 + initialized to 1. 533 + 534 + Usage example: 535 + 536 + unsigned long adler = 1L; 537 + 538 + while (read_buffer(buffer, length) != EOF) { 539 + adler = update_adler32(adler, buffer, length); 540 + } 541 + if (adler != original_adler) error(); 542 + */ 543 + unsigned long update_adler32(unsigned long adler, 544 + unsigned char *buf, int len) 545 + { 546 + unsigned long s1 = adler & 0xffff; 547 + unsigned long s2 = (adler >> 16) & 0xffff; 548 + int n; 549 + 550 + for (n = 0; n < len; n++) { 551 + s1 = (s1 + buf[n]) % BASE; 552 + s2 = (s2 + s1) % BASE; 553 + } 554 + return (s2 << 16) + s1; 555 + } 556 + 557 + /* Return the adler32 of the bytes buf[0..len-1] */ 558 + 559 + 560 + 561 + 562 +Deutsch & Gailly Informational [Page 10] 563 + 564 +RFC 1950 ZLIB Compressed Data Format Specification May 1996 565 + 566 + 567 + unsigned long adler32(unsigned char *buf, int len) 568 + { 569 + return update_adler32(1L, buf, len); 570 + } 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 +Deutsch & Gailly Informational [Page 11] 619 +
Added compat/zlib/doc/rfc1951.txt.
1 + 2 + 3 + 4 + 5 + 6 + 7 +Network Working Group P. Deutsch 8 +Request for Comments: 1951 Aladdin Enterprises 9 +Category: Informational May 1996 10 + 11 + 12 + DEFLATE Compressed Data Format Specification version 1.3 13 + 14 +Status of This Memo 15 + 16 + This memo provides information for the Internet community. This memo 17 + does not specify an Internet standard of any kind. Distribution of 18 + this memo is unlimited. 19 + 20 +IESG Note: 21 + 22 + The IESG takes no position on the validity of any Intellectual 23 + Property Rights statements contained in this document. 24 + 25 +Notices 26 + 27 + Copyright (c) 1996 L. Peter Deutsch 28 + 29 + Permission is granted to copy and distribute this document for any 30 + purpose and without charge, including translations into other 31 + languages and incorporation into compilations, provided that the 32 + copyright notice and this notice are preserved, and that any 33 + substantive changes or deletions from the original are clearly 34 + marked. 35 + 36 + A pointer to the latest version of this and related documentation in 37 + HTML format can be found at the URL 38 + <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>. 39 + 40 +Abstract 41 + 42 + This specification defines a lossless compressed data format that 43 + compresses data using a combination of the LZ77 algorithm and Huffman 44 + coding, with efficiency comparable to the best currently available 45 + general-purpose compression methods. The data can be produced or 46 + consumed, even for an arbitrarily long sequentially presented input 47 + data stream, using only an a priori bounded amount of intermediate 48 + storage. The format can be implemented readily in a manner not 49 + covered by patents. 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 +Deutsch Informational [Page 1] 59 + 60 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 61 + 62 + 63 +Table of Contents 64 + 65 + 1. Introduction ................................................... 2 66 + 1.1. Purpose ................................................... 2 67 + 1.2. Intended audience ......................................... 3 68 + 1.3. Scope ..................................................... 3 69 + 1.4. Compliance ................................................ 3 70 + 1.5. Definitions of terms and conventions used ................ 3 71 + 1.6. Changes from previous versions ............................ 4 72 + 2. Compressed representation overview ............................. 4 73 + 3. Detailed specification ......................................... 5 74 + 3.1. Overall conventions ....................................... 5 75 + 3.1.1. Packing into bytes .................................. 5 76 + 3.2. Compressed block format ................................... 6 77 + 3.2.1. Synopsis of prefix and Huffman coding ............... 6 78 + 3.2.2. Use of Huffman coding in the "deflate" format ....... 7 79 + 3.2.3. Details of block format ............................. 9 80 + 3.2.4. Non-compressed blocks (BTYPE=00) ................... 11 81 + 3.2.5. Compressed blocks (length and distance codes) ...... 11 82 + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) .... 12 83 + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) .. 13 84 + 3.3. Compliance ............................................... 14 85 + 4. Compression algorithm details ................................. 14 86 + 5. References .................................................... 16 87 + 6. Security Considerations ....................................... 16 88 + 7. Source code ................................................... 16 89 + 8. Acknowledgements .............................................. 16 90 + 9. Author's Address .............................................. 17 91 + 92 +1. Introduction 93 + 94 + 1.1. Purpose 95 + 96 + The purpose of this specification is to define a lossless 97 + compressed data format that: 98 + * Is independent of CPU type, operating system, file system, 99 + and character set, and hence can be used for interchange; 100 + * Can be produced or consumed, even for an arbitrarily long 101 + sequentially presented input data stream, using only an a 102 + priori bounded amount of intermediate storage, and hence 103 + can be used in data communications or similar structures 104 + such as Unix filters; 105 + * Compresses data with efficiency comparable to the best 106 + currently available general-purpose compression methods, 107 + and in particular considerably better than the "compress" 108 + program; 109 + * Can be implemented readily in a manner not covered by 110 + patents, and hence can be practiced freely; 111 + 112 + 113 + 114 +Deutsch Informational [Page 2] 115 + 116 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 117 + 118 + 119 + * Is compatible with the file format produced by the current 120 + widely used gzip utility, in that conforming decompressors 121 + will be able to read data produced by the existing gzip 122 + compressor. 123 + 124 + The data format defined by this specification does not attempt to: 125 + 126 + * Allow random access to compressed data; 127 + * Compress specialized data (e.g., raster graphics) as well 128 + as the best currently available specialized algorithms. 129 + 130 + A simple counting argument shows that no lossless compression 131 + algorithm can compress every possible input data set. For the 132 + format defined here, the worst case expansion is 5 bytes per 32K- 133 + byte block, i.e., a size increase of 0.015% for large data sets. 134 + English text usually compresses by a factor of 2.5 to 3; 135 + executable files usually compress somewhat less; graphical data 136 + such as raster images may compress much more. 137 + 138 + 1.2. Intended audience 139 + 140 + This specification is intended for use by implementors of software 141 + to compress data into "deflate" format and/or decompress data from 142 + "deflate" format. 143 + 144 + The text of the specification assumes a basic background in 145 + programming at the level of bits and other primitive data 146 + representations. Familiarity with the technique of Huffman coding 147 + is helpful but not required. 148 + 149 + 1.3. Scope 150 + 151 + The specification specifies a method for representing a sequence 152 + of bytes as a (usually shorter) sequence of bits, and a method for 153 + packing the latter bit sequence into bytes. 154 + 155 + 1.4. Compliance 156 + 157 + Unless otherwise indicated below, a compliant decompressor must be 158 + able to accept and decompress any data set that conforms to all 159 + the specifications presented here; a compliant compressor must 160 + produce data sets that conform to all the specifications presented 161 + here. 162 + 163 + 1.5. Definitions of terms and conventions used 164 + 165 + Byte: 8 bits stored or transmitted as a unit (same as an octet). 166 + For this specification, a byte is exactly 8 bits, even on machines 167 + 168 + 169 + 170 +Deutsch Informational [Page 3] 171 + 172 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 173 + 174 + 175 + which store a character on a number of bits different from eight. 176 + See below, for the numbering of bits within a byte. 177 + 178 + String: a sequence of arbitrary bytes. 179 + 180 + 1.6. Changes from previous versions 181 + 182 + There have been no technical changes to the deflate format since 183 + version 1.1 of this specification. In version 1.2, some 184 + terminology was changed. Version 1.3 is a conversion of the 185 + specification to RFC style. 186 + 187 +2. Compressed representation overview 188 + 189 + A compressed data set consists of a series of blocks, corresponding 190 + to successive blocks of input data. The block sizes are arbitrary, 191 + except that non-compressible blocks are limited to 65,535 bytes. 192 + 193 + Each block is compressed using a combination of the LZ77 algorithm 194 + and Huffman coding. The Huffman trees for each block are independent 195 + of those for previous or subsequent blocks; the LZ77 algorithm may 196 + use a reference to a duplicated string occurring in a previous block, 197 + up to 32K input bytes before. 198 + 199 + Each block consists of two parts: a pair of Huffman code trees that 200 + describe the representation of the compressed data part, and a 201 + compressed data part. (The Huffman trees themselves are compressed 202 + using Huffman encoding.) The compressed data consists of a series of 203 + elements of two types: literal bytes (of strings that have not been 204 + detected as duplicated within the previous 32K input bytes), and 205 + pointers to duplicated strings, where a pointer is represented as a 206 + pair <length, backward distance>. The representation used in the 207 + "deflate" format limits distances to 32K bytes and lengths to 258 208 + bytes, but does not limit the size of a block, except for 209 + uncompressible blocks, which are limited as noted above. 210 + 211 + Each type of value (literals, distances, and lengths) in the 212 + compressed data is represented using a Huffman code, using one code 213 + tree for literals and lengths and a separate code tree for distances. 214 + The code trees for each block appear in a compact form just before 215 + the compressed data for that block. 216 + 217 + 218 + 219 + 220 + 221 + 222 + 223 + 224 + 225 + 226 +Deutsch Informational [Page 4] 227 + 228 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 229 + 230 + 231 +3. Detailed specification 232 + 233 + 3.1. Overall conventions In the diagrams below, a box like this: 234 + 235 + +---+ 236 + | | <-- the vertical bars might be missing 237 + +---+ 238 + 239 + represents one byte; a box like this: 240 + 241 + +==============+ 242 + | | 243 + +==============+ 244 + 245 + represents a variable number of bytes. 246 + 247 + Bytes stored within a computer do not have a "bit order", since 248 + they are always treated as a unit. However, a byte considered as 249 + an integer between 0 and 255 does have a most- and least- 250 + significant bit, and since we write numbers with the most- 251 + significant digit on the left, we also write bytes with the most- 252 + significant bit on the left. In the diagrams below, we number the 253 + bits of a byte so that bit 0 is the least-significant bit, i.e., 254 + the bits are numbered: 255 + 256 + +--------+ 257 + |76543210| 258 + +--------+ 259 + 260 + Within a computer, a number may occupy multiple bytes. All 261 + multi-byte numbers in the format described here are stored with 262 + the least-significant byte first (at the lower memory address). 263 + For example, the decimal number 520 is stored as: 264 + 265 + 0 1 266 + +--------+--------+ 267 + |00001000|00000010| 268 + +--------+--------+ 269 + ^ ^ 270 + | | 271 + | + more significant byte = 2 x 256 272 + + less significant byte = 8 273 + 274 + 3.1.1. Packing into bytes 275 + 276 + This document does not address the issue of the order in which 277 + bits of a byte are transmitted on a bit-sequential medium, 278 + since the final data format described here is byte- rather than 279 + 280 + 281 + 282 +Deutsch Informational [Page 5] 283 + 284 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 285 + 286 + 287 + bit-oriented. However, we describe the compressed block format 288 + in below, as a sequence of data elements of various bit 289 + lengths, not a sequence of bytes. We must therefore specify 290 + how to pack these data elements into bytes to form the final 291 + compressed byte sequence: 292 + 293 + * Data elements are packed into bytes in order of 294 + increasing bit number within the byte, i.e., starting 295 + with the least-significant bit of the byte. 296 + * Data elements other than Huffman codes are packed 297 + starting with the least-significant bit of the data 298 + element. 299 + * Huffman codes are packed starting with the most- 300 + significant bit of the code. 301 + 302 + In other words, if one were to print out the compressed data as 303 + a sequence of bytes, starting with the first byte at the 304 + *right* margin and proceeding to the *left*, with the most- 305 + significant bit of each byte on the left as usual, one would be 306 + able to parse the result from right to left, with fixed-width 307 + elements in the correct MSB-to-LSB order and Huffman codes in 308 + bit-reversed order (i.e., with the first bit of the code in the 309 + relative LSB position). 310 + 311 + 3.2. Compressed block format 312 + 313 + 3.2.1. Synopsis of prefix and Huffman coding 314 + 315 + Prefix coding represents symbols from an a priori known 316 + alphabet by bit sequences (codes), one code for each symbol, in 317 + a manner such that different symbols may be represented by bit 318 + sequences of different lengths, but a parser can always parse 319 + an encoded string unambiguously symbol-by-symbol. 320 + 321 + We define a prefix code in terms of a binary tree in which the 322 + two edges descending from each non-leaf node are labeled 0 and 323 + 1 and in which the leaf nodes correspond one-for-one with (are 324 + labeled with) the symbols of the alphabet; then the code for a 325 + symbol is the sequence of 0's and 1's on the edges leading from 326 + the root to the leaf labeled with that symbol. For example: 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 +Deutsch Informational [Page 6] 339 + 340 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 341 + 342 + 343 + /\ Symbol Code 344 + 0 1 ------ ---- 345 + / \ A 00 346 + /\ B B 1 347 + 0 1 C 011 348 + / \ D 010 349 + A /\ 350 + 0 1 351 + / \ 352 + D C 353 + 354 + A parser can decode the next symbol from an encoded input 355 + stream by walking down the tree from the root, at each step 356 + choosing the edge corresponding to the next input bit. 357 + 358 + Given an alphabet with known symbol frequencies, the Huffman 359 + algorithm allows the construction of an optimal prefix code 360 + (one which represents strings with those symbol frequencies 361 + using the fewest bits of any possible prefix codes for that 362 + alphabet). Such a code is called a Huffman code. (See 363 + reference [1] in Chapter 5, references for additional 364 + information on Huffman codes.) 365 + 366 + Note that in the "deflate" format, the Huffman codes for the 367 + various alphabets must not exceed certain maximum code lengths. 368 + This constraint complicates the algorithm for computing code 369 + lengths from symbol frequencies. Again, see Chapter 5, 370 + references for details. 371 + 372 + 3.2.2. Use of Huffman coding in the "deflate" format 373 + 374 + The Huffman codes used for each alphabet in the "deflate" 375 + format have two additional rules: 376 + 377 + * All codes of a given bit length have lexicographically 378 + consecutive values, in the same order as the symbols 379 + they represent; 380 + 381 + * Shorter codes lexicographically precede longer codes. 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 +Deutsch Informational [Page 7] 395 + 396 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 397 + 398 + 399 + We could recode the example above to follow this rule as 400 + follows, assuming that the order of the alphabet is ABCD: 401 + 402 + Symbol Code 403 + ------ ---- 404 + A 10 405 + B 0 406 + C 110 407 + D 111 408 + 409 + I.e., 0 precedes 10 which precedes 11x, and 110 and 111 are 410 + lexicographically consecutive. 411 + 412 + Given this rule, we can define the Huffman code for an alphabet 413 + just by giving the bit lengths of the codes for each symbol of 414 + the alphabet in order; this is sufficient to determine the 415 + actual codes. In our example, the code is completely defined 416 + by the sequence of bit lengths (2, 1, 3, 3). The following 417 + algorithm generates the codes as integers, intended to be read 418 + from most- to least-significant bit. The code lengths are 419 + initially in tree[I].Len; the codes are produced in 420 + tree[I].Code. 421 + 422 + 1) Count the number of codes for each code length. Let 423 + bl_count[N] be the number of codes of length N, N >= 1. 424 + 425 + 2) Find the numerical value of the smallest code for each 426 + code length: 427 + 428 + code = 0; 429 + bl_count[0] = 0; 430 + for (bits = 1; bits <= MAX_BITS; bits++) { 431 + code = (code + bl_count[bits-1]) << 1; 432 + next_code[bits] = code; 433 + } 434 + 435 + 3) Assign numerical values to all codes, using consecutive 436 + values for all codes of the same length with the base 437 + values determined at step 2. Codes that are never used 438 + (which have a bit length of zero) must not be assigned a 439 + value. 440 + 441 + for (n = 0; n <= max_code; n++) { 442 + len = tree[n].Len; 443 + if (len != 0) { 444 + tree[n].Code = next_code[len]; 445 + next_code[len]++; 446 + } 447 + 448 + 449 + 450 +Deutsch Informational [Page 8] 451 + 452 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 453 + 454 + 455 + } 456 + 457 + Example: 458 + 459 + Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3, 460 + 3, 2, 4, 4). After step 1, we have: 461 + 462 + N bl_count[N] 463 + - ----------- 464 + 2 1 465 + 3 5 466 + 4 2 467 + 468 + Step 2 computes the following next_code values: 469 + 470 + N next_code[N] 471 + - ------------ 472 + 1 0 473 + 2 0 474 + 3 2 475 + 4 14 476 + 477 + Step 3 produces the following code values: 478 + 479 + Symbol Length Code 480 + ------ ------ ---- 481 + A 3 010 482 + B 3 011 483 + C 3 100 484 + D 3 101 485 + E 3 110 486 + F 2 00 487 + G 4 1110 488 + H 4 1111 489 + 490 + 3.2.3. Details of block format 491 + 492 + Each block of compressed data begins with 3 header bits 493 + containing the following data: 494 + 495 + first bit BFINAL 496 + next 2 bits BTYPE 497 + 498 + Note that the header bits do not necessarily begin on a byte 499 + boundary, since a block does not necessarily occupy an integral 500 + number of bytes. 501 + 502 + 503 + 504 + 505 + 506 +Deutsch Informational [Page 9] 507 + 508 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 509 + 510 + 511 + BFINAL is set if and only if this is the last block of the data 512 + set. 513 + 514 + BTYPE specifies how the data are compressed, as follows: 515 + 516 + 00 - no compression 517 + 01 - compressed with fixed Huffman codes 518 + 10 - compressed with dynamic Huffman codes 519 + 11 - reserved (error) 520 + 521 + The only difference between the two compressed cases is how the 522 + Huffman codes for the literal/length and distance alphabets are 523 + defined. 524 + 525 + In all cases, the decoding algorithm for the actual data is as 526 + follows: 527 + 528 + do 529 + read block header from input stream. 530 + if stored with no compression 531 + skip any remaining bits in current partially 532 + processed byte 533 + read LEN and NLEN (see next section) 534 + copy LEN bytes of data to output 535 + otherwise 536 + if compressed with dynamic Huffman codes 537 + read representation of code trees (see 538 + subsection below) 539 + loop (until end of block code recognized) 540 + decode literal/length value from input stream 541 + if value < 256 542 + copy value (literal byte) to output stream 543 + otherwise 544 + if value = end of block (256) 545 + break from loop 546 + otherwise (value = 257..285) 547 + decode distance from input stream 548 + 549 + move backwards distance bytes in the output 550 + stream, and copy length bytes from this 551 + position to the output stream. 552 + end loop 553 + while not last block 554 + 555 + Note that a duplicated string reference may refer to a string 556 + in a previous block; i.e., the backward distance may cross one 557 + or more block boundaries. However a distance cannot refer past 558 + the beginning of the output stream. (An application using a 559 + 560 + 561 + 562 +Deutsch Informational [Page 10] 563 + 564 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 565 + 566 + 567 + preset dictionary might discard part of the output stream; a 568 + distance can refer to that part of the output stream anyway) 569 + Note also that the referenced string may overlap the current 570 + position; for example, if the last 2 bytes decoded have values 571 + X and Y, a string reference with <length = 5, distance = 2> 572 + adds X,Y,X,Y,X to the output stream. 573 + 574 + We now specify each compression method in turn. 575 + 576 + 3.2.4. Non-compressed blocks (BTYPE=00) 577 + 578 + Any bits of input up to the next byte boundary are ignored. 579 + The rest of the block consists of the following information: 580 + 581 + 0 1 2 3 4... 582 + +---+---+---+---+================================+ 583 + | LEN | NLEN |... LEN bytes of literal data...| 584 + +---+---+---+---+================================+ 585 + 586 + LEN is the number of data bytes in the block. NLEN is the 587 + one's complement of LEN. 588 + 589 + 3.2.5. Compressed blocks (length and distance codes) 590 + 591 + As noted above, encoded data blocks in the "deflate" format 592 + consist of sequences of symbols drawn from three conceptually 593 + distinct alphabets: either literal bytes, from the alphabet of 594 + byte values (0..255), or <length, backward distance> pairs, 595 + where the length is drawn from (3..258) and the distance is 596 + drawn from (1..32,768). In fact, the literal and length 597 + alphabets are merged into a single alphabet (0..285), where 598 + values 0..255 represent literal bytes, the value 256 indicates 599 + end-of-block, and values 257..285 represent length codes 600 + (possibly in conjunction with extra bits following the symbol 601 + code) as follows: 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 +Deutsch Informational [Page 11] 619 + 620 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 621 + 622 + 623 + Extra Extra Extra 624 + Code Bits Length(s) Code Bits Lengths Code Bits Length(s) 625 + ---- ---- ------ ---- ---- ------- ---- ---- ------- 626 + 257 0 3 267 1 15,16 277 4 67-82 627 + 258 0 4 268 1 17,18 278 4 83-98 628 + 259 0 5 269 2 19-22 279 4 99-114 629 + 260 0 6 270 2 23-26 280 4 115-130 630 + 261 0 7 271 2 27-30 281 5 131-162 631 + 262 0 8 272 2 31-34 282 5 163-194 632 + 263 0 9 273 3 35-42 283 5 195-226 633 + 264 0 10 274 3 43-50 284 5 227-257 634 + 265 1 11,12 275 3 51-58 285 0 258 635 + 266 1 13,14 276 3 59-66 636 + 637 + The extra bits should be interpreted as a machine integer 638 + stored with the most-significant bit first, e.g., bits 1110 639 + represent the value 14. 640 + 641 + Extra Extra Extra 642 + Code Bits Dist Code Bits Dist Code Bits Distance 643 + ---- ---- ---- ---- ---- ------ ---- ---- -------- 644 + 0 0 1 10 4 33-48 20 9 1025-1536 645 + 1 0 2 11 4 49-64 21 9 1537-2048 646 + 2 0 3 12 5 65-96 22 10 2049-3072 647 + 3 0 4 13 5 97-128 23 10 3073-4096 648 + 4 1 5,6 14 6 129-192 24 11 4097-6144 649 + 5 1 7,8 15 6 193-256 25 11 6145-8192 650 + 6 2 9-12 16 7 257-384 26 12 8193-12288 651 + 7 2 13-16 17 7 385-512 27 12 12289-16384 652 + 8 3 17-24 18 8 513-768 28 13 16385-24576 653 + 9 3 25-32 19 8 769-1024 29 13 24577-32768 654 + 655 + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) 656 + 657 + The Huffman codes for the two alphabets are fixed, and are not 658 + represented explicitly in the data. The Huffman code lengths 659 + for the literal/length alphabet are: 660 + 661 + Lit Value Bits Codes 662 + --------- ---- ----- 663 + 0 - 143 8 00110000 through 664 + 10111111 665 + 144 - 255 9 110010000 through 666 + 111111111 667 + 256 - 279 7 0000000 through 668 + 0010111 669 + 280 - 287 8 11000000 through 670 + 11000111 671 + 672 + 673 + 674 +Deutsch Informational [Page 12] 675 + 676 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 677 + 678 + 679 + The code lengths are sufficient to generate the actual codes, 680 + as described above; we show the codes in the table for added 681 + clarity. Literal/length values 286-287 will never actually 682 + occur in the compressed data, but participate in the code 683 + construction. 684 + 685 + Distance codes 0-31 are represented by (fixed-length) 5-bit 686 + codes, with possible additional bits as shown in the table 687 + shown in Paragraph 3.2.5, above. Note that distance codes 30- 688 + 31 will never actually occur in the compressed data. 689 + 690 + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) 691 + 692 + The Huffman codes for the two alphabets appear in the block 693 + immediately after the header bits and before the actual 694 + compressed data, first the literal/length code and then the 695 + distance code. Each code is defined by a sequence of code 696 + lengths, as discussed in Paragraph 3.2.2, above. For even 697 + greater compactness, the code length sequences themselves are 698 + compressed using a Huffman code. The alphabet for code lengths 699 + is as follows: 700 + 701 + 0 - 15: Represent code lengths of 0 - 15 702 + 16: Copy the previous code length 3 - 6 times. 703 + The next 2 bits indicate repeat length 704 + (0 = 3, ... , 3 = 6) 705 + Example: Codes 8, 16 (+2 bits 11), 706 + 16 (+2 bits 10) will expand to 707 + 12 code lengths of 8 (1 + 6 + 5) 708 + 17: Repeat a code length of 0 for 3 - 10 times. 709 + (3 bits of length) 710 + 18: Repeat a code length of 0 for 11 - 138 times 711 + (7 bits of length) 712 + 713 + A code length of 0 indicates that the corresponding symbol in 714 + the literal/length or distance alphabet will not occur in the 715 + block, and should not participate in the Huffman code 716 + construction algorithm given earlier. If only one distance 717 + code is used, it is encoded using one bit, not zero bits; in 718 + this case there is a single code length of one, with one unused 719 + code. One distance code of zero bits means that there are no 720 + distance codes used at all (the data is all literals). 721 + 722 + We can now define the format of the block: 723 + 724 + 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286) 725 + 5 Bits: HDIST, # of Distance codes - 1 (1 - 32) 726 + 4 Bits: HCLEN, # of Code Length codes - 4 (4 - 19) 727 + 728 + 729 + 730 +Deutsch Informational [Page 13] 731 + 732 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 733 + 734 + 735 + (HCLEN + 4) x 3 bits: code lengths for the code length 736 + alphabet given just above, in the order: 16, 17, 18, 737 + 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 738 + 739 + These code lengths are interpreted as 3-bit integers 740 + (0-7); as above, a code length of 0 means the 741 + corresponding symbol (literal/length or distance code 742 + length) is not used. 743 + 744 + HLIT + 257 code lengths for the literal/length alphabet, 745 + encoded using the code length Huffman code 746 + 747 + HDIST + 1 code lengths for the distance alphabet, 748 + encoded using the code length Huffman code 749 + 750 + The actual compressed data of the block, 751 + encoded using the literal/length and distance Huffman 752 + codes 753 + 754 + The literal/length symbol 256 (end of data), 755 + encoded using the literal/length Huffman code 756 + 757 + The code length repeat codes can cross from HLIT + 257 to the 758 + HDIST + 1 code lengths. In other words, all code lengths form 759 + a single sequence of HLIT + HDIST + 258 values. 760 + 761 + 3.3. Compliance 762 + 763 + A compressor may limit further the ranges of values specified in 764 + the previous section and still be compliant; for example, it may 765 + limit the range of backward pointers to some value smaller than 766 + 32K. Similarly, a compressor may limit the size of blocks so that 767 + a compressible block fits in memory. 768 + 769 + A compliant decompressor must accept the full range of possible 770 + values defined in the previous section, and must accept blocks of 771 + arbitrary size. 772 + 773 +4. Compression algorithm details 774 + 775 + While it is the intent of this document to define the "deflate" 776 + compressed data format without reference to any particular 777 + compression algorithm, the format is related to the compressed 778 + formats produced by LZ77 (Lempel-Ziv 1977, see reference [2] below); 779 + since many variations of LZ77 are patented, it is strongly 780 + recommended that the implementor of a compressor follow the general 781 + algorithm presented here, which is known not to be patented per se. 782 + The material in this section is not part of the definition of the 783 + 784 + 785 + 786 +Deutsch Informational [Page 14] 787 + 788 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 789 + 790 + 791 + specification per se, and a compressor need not follow it in order to 792 + be compliant. 793 + 794 + The compressor terminates a block when it determines that starting a 795 + new block with fresh trees would be useful, or when the block size 796 + fills up the compressor's block buffer. 797 + 798 + The compressor uses a chained hash table to find duplicated strings, 799 + using a hash function that operates on 3-byte sequences. At any 800 + given point during compression, let XYZ be the next 3 input bytes to 801 + be examined (not necessarily all different, of course). First, the 802 + compressor examines the hash chain for XYZ. If the chain is empty, 803 + the compressor simply writes out X as a literal byte and advances one 804 + byte in the input. If the hash chain is not empty, indicating that 805 + the sequence XYZ (or, if we are unlucky, some other 3 bytes with the 806 + same hash function value) has occurred recently, the compressor 807 + compares all strings on the XYZ hash chain with the actual input data 808 + sequence starting at the current point, and selects the longest 809 + match. 810 + 811 + The compressor searches the hash chains starting with the most recent 812 + strings, to favor small distances and thus take advantage of the 813 + Huffman encoding. The hash chains are singly linked. There are no 814 + deletions from the hash chains; the algorithm simply discards matches 815 + that are too old. To avoid a worst-case situation, very long hash 816 + chains are arbitrarily truncated at a certain length, determined by a 817 + run-time parameter. 818 + 819 + To improve overall compression, the compressor optionally defers the 820 + selection of matches ("lazy matching"): after a match of length N has 821 + been found, the compressor searches for a longer match starting at 822 + the next input byte. If it finds a longer match, it truncates the 823 + previous match to a length of one (thus producing a single literal 824 + byte) and then emits the longer match. Otherwise, it emits the 825 + original match, and, as described above, advances N bytes before 826 + continuing. 827 + 828 + Run-time parameters also control this "lazy match" procedure. If 829 + compression ratio is most important, the compressor attempts a 830 + complete second search regardless of the length of the first match. 831 + In the normal case, if the current match is "long enough", the 832 + compressor reduces the search for a longer match, thus speeding up 833 + the process. If speed is most important, the compressor inserts new 834 + strings in the hash table only when no match was found, or when the 835 + match is not "too long". This degrades the compression ratio but 836 + saves time since there are both fewer insertions and fewer searches. 837 + 838 + 839 + 840 + 841 + 842 +Deutsch Informational [Page 15] 843 + 844 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 845 + 846 + 847 +5. References 848 + 849 + [1] Huffman, D. A., "A Method for the Construction of Minimum 850 + Redundancy Codes", Proceedings of the Institute of Radio 851 + Engineers, September 1952, Volume 40, Number 9, pp. 1098-1101. 852 + 853 + [2] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data 854 + Compression", IEEE Transactions on Information Theory, Vol. 23, 855 + No. 3, pp. 337-343. 856 + 857 + [3] Gailly, J.-L., and Adler, M., ZLIB documentation and sources, 858 + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ 859 + 860 + [4] Gailly, J.-L., and Adler, M., GZIP documentation and sources, 861 + available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/ 862 + 863 + [5] Schwartz, E. S., and Kallick, B. "Generating a canonical prefix 864 + encoding." Comm. ACM, 7,3 (Mar. 1964), pp. 166-169. 865 + 866 + [6] Hirschberg and Lelewer, "Efficient decoding of prefix codes," 867 + Comm. ACM, 33,4, April 1990, pp. 449-459. 868 + 869 +6. Security Considerations 870 + 871 + Any data compression method involves the reduction of redundancy in 872 + the data. Consequently, any corruption of the data is likely to have 873 + severe effects and be difficult to correct. Uncompressed text, on 874 + the other hand, will probably still be readable despite the presence 875 + of some corrupted bytes. 876 + 877 + It is recommended that systems using this data format provide some 878 + means of validating the integrity of the compressed data. See 879 + reference [3], for example. 880 + 881 +7. Source code 882 + 883 + Source code for a C language implementation of a "deflate" compliant 884 + compressor and decompressor is available within the zlib package at 885 + ftp://ftp.uu.net/pub/archiving/zip/zlib/. 886 + 887 +8. Acknowledgements 888 + 889 + Trademarks cited in this document are the property of their 890 + respective owners. 891 + 892 + Phil Katz designed the deflate format. Jean-Loup Gailly and Mark 893 + Adler wrote the related software described in this specification. 894 + Glenn Randers-Pehrson converted this document to RFC and HTML format. 895 + 896 + 897 + 898 +Deutsch Informational [Page 16] 899 + 900 +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 901 + 902 + 903 +9. Author's Address 904 + 905 + L. Peter Deutsch 906 + Aladdin Enterprises 907 + 203 Santa Margarita Ave. 908 + Menlo Park, CA 94025 909 + 910 + Phone: (415) 322-0103 (AM only) 911 + FAX: (415) 322-1734 912 + EMail: <ghost@aladdin.com> 913 + 914 + Questions about the technical content of this specification can be 915 + sent by email to: 916 + 917 + Jean-Loup Gailly <gzip@prep.ai.mit.edu> and 918 + Mark Adler <madler@alumni.caltech.edu> 919 + 920 + Editorial comments on this specification can be sent by email to: 921 + 922 + L. Peter Deutsch <ghost@aladdin.com> and 923 + Glenn Randers-Pehrson <randeg@alumni.rpi.edu> 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 +Deutsch Informational [Page 17] 955 +
Added compat/zlib/doc/rfc1952.txt.
1 + 2 + 3 + 4 + 5 + 6 + 7 +Network Working Group P. Deutsch 8 +Request for Comments: 1952 Aladdin Enterprises 9 +Category: Informational May 1996 10 + 11 + 12 + GZIP file format specification version 4.3 13 + 14 +Status of This Memo 15 + 16 + This memo provides information for the Internet community. This memo 17 + does not specify an Internet standard of any kind. Distribution of 18 + this memo is unlimited. 19 + 20 +IESG Note: 21 + 22 + The IESG takes no position on the validity of any Intellectual 23 + Property Rights statements contained in this document. 24 + 25 +Notices 26 + 27 + Copyright (c) 1996 L. Peter Deutsch 28 + 29 + Permission is granted to copy and distribute this document for any 30 + purpose and without charge, including translations into other 31 + languages and incorporation into compilations, provided that the 32 + copyright notice and this notice are preserved, and that any 33 + substantive changes or deletions from the original are clearly 34 + marked. 35 + 36 + A pointer to the latest version of this and related documentation in 37 + HTML format can be found at the URL 38 + <ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html>. 39 + 40 +Abstract 41 + 42 + This specification defines a lossless compressed data format that is 43 + compatible with the widely used GZIP utility. The format includes a 44 + cyclic redundancy check value for detecting data corruption. The 45 + format presently uses the DEFLATE method of compression but can be 46 + easily extended to use other compression methods. The format can be 47 + implemented readily in a manner not covered by patents. 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 +Deutsch Informational [Page 1] 59 + 60 +RFC 1952 GZIP File Format Specification May 1996 61 + 62 + 63 +Table of Contents 64 + 65 + 1. Introduction ................................................... 2 66 + 1.1. Purpose ................................................... 2 67 + 1.2. Intended audience ......................................... 3 68 + 1.3. Scope ..................................................... 3 69 + 1.4. Compliance ................................................ 3 70 + 1.5. Definitions of terms and conventions used ................. 3 71 + 1.6. Changes from previous versions ............................ 3 72 + 2. Detailed specification ......................................... 4 73 + 2.1. Overall conventions ....................................... 4 74 + 2.2. File format ............................................... 5 75 + 2.3. Member format ............................................. 5 76 + 2.3.1. Member header and trailer ........................... 6 77 + 2.3.1.1. Extra field ................................... 8 78 + 2.3.1.2. Compliance .................................... 9 79 + 3. References .................................................. 9 80 + 4. Security Considerations .................................... 10 81 + 5. Acknowledgements ........................................... 10 82 + 6. Author's Address ........................................... 10 83 + 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11 84 + 8. Appendix: Sample CRC Code .................................. 11 85 + 86 +1. Introduction 87 + 88 + 1.1. Purpose 89 + 90 + The purpose of this specification is to define a lossless 91 + compressed data format that: 92 + 93 + * Is independent of CPU type, operating system, file system, 94 + and character set, and hence can be used for interchange; 95 + * Can compress or decompress a data stream (as opposed to a 96 + randomly accessible file) to produce another data stream, 97 + using only an a priori bounded amount of intermediate 98 + storage, and hence can be used in data communications or 99 + similar structures such as Unix filters; 100 + * Compresses data with efficiency comparable to the best 101 + currently available general-purpose compression methods, 102 + and in particular considerably better than the "compress" 103 + program; 104 + * Can be implemented readily in a manner not covered by 105 + patents, and hence can be practiced freely; 106 + * Is compatible with the file format produced by the current 107 + widely used gzip utility, in that conforming decompressors 108 + will be able to read data produced by the existing gzip 109 + compressor. 110 + 111 + 112 + 113 + 114 +Deutsch Informational [Page 2] 115 + 116 +RFC 1952 GZIP File Format Specification May 1996 117 + 118 + 119 + The data format defined by this specification does not attempt to: 120 + 121 + * Provide random access to compressed data; 122 + * Compress specialized data (e.g., raster graphics) as well as 123 + the best currently available specialized algorithms. 124 + 125 + 1.2. Intended audience 126 + 127 + This specification is intended for use by implementors of software 128 + to compress data into gzip format and/or decompress data from gzip 129 + format. 130 + 131 + The text of the specification assumes a basic background in 132 + programming at the level of bits and other primitive data 133 + representations. 134 + 135 + 1.3. Scope 136 + 137 + The specification specifies a compression method and a file format 138 + (the latter assuming only that a file can store a sequence of 139 + arbitrary bytes). It does not specify any particular interface to 140 + a file system or anything about character sets or encodings 141 + (except for file names and comments, which are optional). 142 + 143 + 1.4. Compliance 144 + 145 + Unless otherwise indicated below, a compliant decompressor must be 146 + able to accept and decompress any file that conforms to all the 147 + specifications presented here; a compliant compressor must produce 148 + files that conform to all the specifications presented here. The 149 + material in the appendices is not part of the specification per se 150 + and is not relevant to compliance. 151 + 152 + 1.5. Definitions of terms and conventions used 153 + 154 + byte: 8 bits stored or transmitted as a unit (same as an octet). 155 + (For this specification, a byte is exactly 8 bits, even on 156 + machines which store a character on a number of bits different 157 + from 8.) See below for the numbering of bits within a byte. 158 + 159 + 1.6. Changes from previous versions 160 + 161 + There have been no technical changes to the gzip format since 162 + version 4.1 of this specification. In version 4.2, some 163 + terminology was changed, and the sample CRC code was rewritten for 164 + clarity and to eliminate the requirement for the caller to do pre- 165 + and post-conditioning. Version 4.3 is a conversion of the 166 + specification to RFC style. 167 + 168 + 169 + 170 +Deutsch Informational [Page 3] 171 + 172 +RFC 1952 GZIP File Format Specification May 1996 173 + 174 + 175 +2. Detailed specification 176 + 177 + 2.1. Overall conventions 178 + 179 + In the diagrams below, a box like this: 180 + 181 + +---+ 182 + | | <-- the vertical bars might be missing 183 + +---+ 184 + 185 + represents one byte; a box like this: 186 + 187 + +==============+ 188 + | | 189 + +==============+ 190 + 191 + represents a variable number of bytes. 192 + 193 + Bytes stored within a computer do not have a "bit order", since 194 + they are always treated as a unit. However, a byte considered as 195 + an integer between 0 and 255 does have a most- and least- 196 + significant bit, and since we write numbers with the most- 197 + significant digit on the left, we also write bytes with the most- 198 + significant bit on the left. In the diagrams below, we number the 199 + bits of a byte so that bit 0 is the least-significant bit, i.e., 200 + the bits are numbered: 201 + 202 + +--------+ 203 + |76543210| 204 + +--------+ 205 + 206 + This document does not address the issue of the order in which 207 + bits of a byte are transmitted on a bit-sequential medium, since 208 + the data format described here is byte- rather than bit-oriented. 209 + 210 + Within a computer, a number may occupy multiple bytes. All 211 + multi-byte numbers in the format described here are stored with 212 + the least-significant byte first (at the lower memory address). 213 + For example, the decimal number 520 is stored as: 214 + 215 + 0 1 216 + +--------+--------+ 217 + |00001000|00000010| 218 + +--------+--------+ 219 + ^ ^ 220 + | | 221 + | + more significant byte = 2 x 256 222 + + less significant byte = 8 223 + 224 + 225 + 226 +Deutsch Informational [Page 4] 227 + 228 +RFC 1952 GZIP File Format Specification May 1996 229 + 230 + 231 + 2.2. File format 232 + 233 + A gzip file consists of a series of "members" (compressed data 234 + sets). The format of each member is specified in the following 235 + section. The members simply appear one after another in the file, 236 + with no additional information before, between, or after them. 237 + 238 + 2.3. Member format 239 + 240 + Each member has the following structure: 241 + 242 + +---+---+---+---+---+---+---+---+---+---+ 243 + |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) 244 + +---+---+---+---+---+---+---+---+---+---+ 245 + 246 + (if FLG.FEXTRA set) 247 + 248 + +---+---+=================================+ 249 + | XLEN |...XLEN bytes of "extra field"...| (more-->) 250 + +---+---+=================================+ 251 + 252 + (if FLG.FNAME set) 253 + 254 + +=========================================+ 255 + |...original file name, zero-terminated...| (more-->) 256 + +=========================================+ 257 + 258 + (if FLG.FCOMMENT set) 259 + 260 + +===================================+ 261 + |...file comment, zero-terminated...| (more-->) 262 + +===================================+ 263 + 264 + (if FLG.FHCRC set) 265 + 266 + +---+---+ 267 + | CRC16 | 268 + +---+---+ 269 + 270 + +=======================+ 271 + |...compressed blocks...| (more-->) 272 + +=======================+ 273 + 274 + 0 1 2 3 4 5 6 7 275 + +---+---+---+---+---+---+---+---+ 276 + | CRC32 | ISIZE | 277 + +---+---+---+---+---+---+---+---+ 278 + 279 + 280 + 281 + 282 +Deutsch Informational [Page 5] 283 + 284 +RFC 1952 GZIP File Format Specification May 1996 285 + 286 + 287 + 2.3.1. Member header and trailer 288 + 289 + ID1 (IDentification 1) 290 + ID2 (IDentification 2) 291 + These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 292 + (0x8b, \213), to identify the file as being in gzip format. 293 + 294 + CM (Compression Method) 295 + This identifies the compression method used in the file. CM 296 + = 0-7 are reserved. CM = 8 denotes the "deflate" 297 + compression method, which is the one customarily used by 298 + gzip and which is documented elsewhere. 299 + 300 + FLG (FLaGs) 301 + This flag byte is divided into individual bits as follows: 302 + 303 + bit 0 FTEXT 304 + bit 1 FHCRC 305 + bit 2 FEXTRA 306 + bit 3 FNAME 307 + bit 4 FCOMMENT 308 + bit 5 reserved 309 + bit 6 reserved 310 + bit 7 reserved 311 + 312 + If FTEXT is set, the file is probably ASCII text. This is 313 + an optional indication, which the compressor may set by 314 + checking a small amount of the input data to see whether any 315 + non-ASCII characters are present. In case of doubt, FTEXT 316 + is cleared, indicating binary data. For systems which have 317 + different file formats for ascii text and binary data, the 318 + decompressor can use FTEXT to choose the appropriate format. 319 + We deliberately do not specify the algorithm used to set 320 + this bit, since a compressor always has the option of 321 + leaving it cleared and a decompressor always has the option 322 + of ignoring it and letting some other program handle issues 323 + of data conversion. 324 + 325 + If FHCRC is set, a CRC16 for the gzip header is present, 326 + immediately before the compressed data. The CRC16 consists 327 + of the two least significant bytes of the CRC32 for all 328 + bytes of the gzip header up to and not including the CRC16. 329 + [The FHCRC bit was never set by versions of gzip up to 330 + 1.2.4, even though it was documented with a different 331 + meaning in gzip 1.2.4.] 332 + 333 + If FEXTRA is set, optional extra fields are present, as 334 + described in a following section. 335 + 336 + 337 + 338 +Deutsch Informational [Page 6] 339 + 340 +RFC 1952 GZIP File Format Specification May 1996 341 + 342 + 343 + If FNAME is set, an original file name is present, 344 + terminated by a zero byte. The name must consist of ISO 345 + 8859-1 (LATIN-1) characters; on operating systems using 346 + EBCDIC or any other character set for file names, the name 347 + must be translated to the ISO LATIN-1 character set. This 348 + is the original name of the file being compressed, with any 349 + directory components removed, and, if the file being 350 + compressed is on a file system with case insensitive names, 351 + forced to lower case. There is no original file name if the 352 + data was compressed from a source other than a named file; 353 + for example, if the source was stdin on a Unix system, there 354 + is no file name. 355 + 356 + If FCOMMENT is set, a zero-terminated file comment is 357 + present. This comment is not interpreted; it is only 358 + intended for human consumption. The comment must consist of 359 + ISO 8859-1 (LATIN-1) characters. Line breaks should be 360 + denoted by a single line feed character (10 decimal). 361 + 362 + Reserved FLG bits must be zero. 363 + 364 + MTIME (Modification TIME) 365 + This gives the most recent modification time of the original 366 + file being compressed. The time is in Unix format, i.e., 367 + seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this 368 + may cause problems for MS-DOS and other systems that use 369 + local rather than Universal time.) If the compressed data 370 + did not come from a file, MTIME is set to the time at which 371 + compression started. MTIME = 0 means no time stamp is 372 + available. 373 + 374 + XFL (eXtra FLags) 375 + These flags are available for use by specific compression 376 + methods. The "deflate" method (CM = 8) sets these flags as 377 + follows: 378 + 379 + XFL = 2 - compressor used maximum compression, 380 + slowest algorithm 381 + XFL = 4 - compressor used fastest algorithm 382 + 383 + OS (Operating System) 384 + This identifies the type of file system on which compression 385 + took place. This may be useful in determining end-of-line 386 + convention for text files. The currently defined values are 387 + as follows: 388 + 389 + 390 + 391 + 392 + 393 + 394 +Deutsch Informational [Page 7] 395 + 396 +RFC 1952 GZIP File Format Specification May 1996 397 + 398 + 399 + 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) 400 + 1 - Amiga 401 + 2 - VMS (or OpenVMS) 402 + 3 - Unix 403 + 4 - VM/CMS 404 + 5 - Atari TOS 405 + 6 - HPFS filesystem (OS/2, NT) 406 + 7 - Macintosh 407 + 8 - Z-System 408 + 9 - CP/M 409 + 10 - TOPS-20 410 + 11 - NTFS filesystem (NT) 411 + 12 - QDOS 412 + 13 - Acorn RISCOS 413 + 255 - unknown 414 + 415 + XLEN (eXtra LENgth) 416 + If FLG.FEXTRA is set, this gives the length of the optional 417 + extra field. See below for details. 418 + 419 + CRC32 (CRC-32) 420 + This contains a Cyclic Redundancy Check value of the 421 + uncompressed data computed according to CRC-32 algorithm 422 + used in the ISO 3309 standard and in section 8.1.1.6.2 of 423 + ITU-T recommendation V.42. (See http://www.iso.ch for 424 + ordering ISO documents. See gopher://info.itu.ch for an 425 + online version of ITU-T V.42.) 426 + 427 + ISIZE (Input SIZE) 428 + This contains the size of the original (uncompressed) input 429 + data modulo 2^32. 430 + 431 + 2.3.1.1. Extra field 432 + 433 + If the FLG.FEXTRA bit is set, an "extra field" is present in 434 + the header, with total length XLEN bytes. It consists of a 435 + series of subfields, each of the form: 436 + 437 + +---+---+---+---+==================================+ 438 + |SI1|SI2| LEN |... LEN bytes of subfield data ...| 439 + +---+---+---+---+==================================+ 440 + 441 + SI1 and SI2 provide a subfield ID, typically two ASCII letters 442 + with some mnemonic value. Jean-Loup Gailly 443 + <gzip@prep.ai.mit.edu> is maintaining a registry of subfield 444 + IDs; please send him any subfield ID you wish to use. Subfield 445 + IDs with SI2 = 0 are reserved for future use. The following 446 + IDs are currently defined: 447 + 448 + 449 + 450 +Deutsch Informational [Page 8] 451 + 452 +RFC 1952 GZIP File Format Specification May 1996 453 + 454 + 455 + SI1 SI2 Data 456 + ---------- ---------- ---- 457 + 0x41 ('A') 0x70 ('P') Apollo file type information 458 + 459 + LEN gives the length of the subfield data, excluding the 4 460 + initial bytes. 461 + 462 + 2.3.1.2. Compliance 463 + 464 + A compliant compressor must produce files with correct ID1, 465 + ID2, CM, CRC32, and ISIZE, but may set all the other fields in 466 + the fixed-length part of the header to default values (255 for 467 + OS, 0 for all others). The compressor must set all reserved 468 + bits to zero. 469 + 470 + A compliant decompressor must check ID1, ID2, and CM, and 471 + provide an error indication if any of these have incorrect 472 + values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC 473 + at least so it can skip over the optional fields if they are 474 + present. It need not examine any other part of the header or 475 + trailer; in particular, a decompressor may ignore FTEXT and OS 476 + and always produce binary output, and still be compliant. A 477 + compliant decompressor must give an error indication if any 478 + reserved bit is non-zero, since such a bit could indicate the 479 + presence of a new field that would cause subsequent data to be 480 + interpreted incorrectly. 481 + 482 +3. References 483 + 484 + [1] "Information Processing - 8-bit single-byte coded graphic 485 + character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). 486 + The ISO 8859-1 (Latin-1) character set is a superset of 7-bit 487 + ASCII. Files defining this character set are available as 488 + iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/ 489 + 490 + [2] ISO 3309 491 + 492 + [3] ITU-T recommendation V.42 493 + 494 + [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", 495 + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ 496 + 497 + [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in 498 + ftp://prep.ai.mit.edu/pub/gnu/ 499 + 500 + [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table 501 + Look-Up", Communications of the ACM, 31(8), pp.1008-1013. 502 + 503 + 504 + 505 + 506 +Deutsch Informational [Page 9] 507 + 508 +RFC 1952 GZIP File Format Specification May 1996 509 + 510 + 511 + [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, 512 + pp.118-133. 513 + 514 + [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt, 515 + describing the CRC concept. 516 + 517 +4. Security Considerations 518 + 519 + Any data compression method involves the reduction of redundancy in 520 + the data. Consequently, any corruption of the data is likely to have 521 + severe effects and be difficult to correct. Uncompressed text, on 522 + the other hand, will probably still be readable despite the presence 523 + of some corrupted bytes. 524 + 525 + It is recommended that systems using this data format provide some 526 + means of validating the integrity of the compressed data, such as by 527 + setting and checking the CRC-32 check value. 528 + 529 +5. Acknowledgements 530 + 531 + Trademarks cited in this document are the property of their 532 + respective owners. 533 + 534 + Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, 535 + the related software described in this specification. Glenn 536 + Randers-Pehrson converted this document to RFC and HTML format. 537 + 538 +6. Author's Address 539 + 540 + L. Peter Deutsch 541 + Aladdin Enterprises 542 + 203 Santa Margarita Ave. 543 + Menlo Park, CA 94025 544 + 545 + Phone: (415) 322-0103 (AM only) 546 + FAX: (415) 322-1734 547 + EMail: <ghost@aladdin.com> 548 + 549 + Questions about the technical content of this specification can be 550 + sent by email to: 551 + 552 + Jean-Loup Gailly <gzip@prep.ai.mit.edu> and 553 + Mark Adler <madler@alumni.caltech.edu> 554 + 555 + Editorial comments on this specification can be sent by email to: 556 + 557 + L. Peter Deutsch <ghost@aladdin.com> and 558 + Glenn Randers-Pehrson <randeg@alumni.rpi.edu> 559 + 560 + 561 + 562 +Deutsch Informational [Page 10] 563 + 564 +RFC 1952 GZIP File Format Specification May 1996 565 + 566 + 567 +7. Appendix: Jean-Loup Gailly's gzip utility 568 + 569 + The most widely used implementation of gzip compression, and the 570 + original documentation on which this specification is based, were 571 + created by Jean-Loup Gailly <gzip@prep.ai.mit.edu>. Since this 572 + implementation is a de facto standard, we mention some more of its 573 + features here. Again, the material in this section is not part of 574 + the specification per se, and implementations need not follow it to 575 + be compliant. 576 + 577 + When compressing or decompressing a file, gzip preserves the 578 + protection, ownership, and modification time attributes on the local 579 + file system, since there is no provision for representing protection 580 + attributes in the gzip file format itself. Since the file format 581 + includes a modification time, the gzip decompressor provides a 582 + command line switch that assigns the modification time from the file, 583 + rather than the local modification time of the compressed input, to 584 + the decompressed output. 585 + 586 +8. Appendix: Sample CRC Code 587 + 588 + The following sample code represents a practical implementation of 589 + the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 590 + for a formal specification.) 591 + 592 + The sample code is in the ANSI C programming language. Non C users 593 + may find it easier to read with these hints: 594 + 595 + & Bitwise AND operator. 596 + ^ Bitwise exclusive-OR operator. 597 + >> Bitwise right shift operator. When applied to an 598 + unsigned quantity, as here, right shift inserts zero 599 + bit(s) at the left. 600 + ! Logical NOT operator. 601 + ++ "n++" increments the variable n. 602 + 0xNNN 0x introduces a hexadecimal (base 16) constant. 603 + Suffix L indicates a long value (at least 32 bits). 604 + 605 + /* Table of CRCs of all 8-bit messages. */ 606 + unsigned long crc_table[256]; 607 + 608 + /* Flag: has the table been computed? Initially false. */ 609 + int crc_table_computed = 0; 610 + 611 + /* Make the table for a fast CRC. */ 612 + void make_crc_table(void) 613 + { 614 + unsigned long c; 615 + 616 + 617 + 618 +Deutsch Informational [Page 11] 619 + 620 +RFC 1952 GZIP File Format Specification May 1996 621 + 622 + 623 + int n, k; 624 + for (n = 0; n < 256; n++) { 625 + c = (unsigned long) n; 626 + for (k = 0; k < 8; k++) { 627 + if (c & 1) { 628 + c = 0xedb88320L ^ (c >> 1); 629 + } else { 630 + c = c >> 1; 631 + } 632 + } 633 + crc_table[n] = c; 634 + } 635 + crc_table_computed = 1; 636 + } 637 + 638 + /* 639 + Update a running crc with the bytes buf[0..len-1] and return 640 + the updated crc. The crc should be initialized to zero. Pre- and 641 + post-conditioning (one's complement) is performed within this 642 + function so it shouldn't be done by the caller. Usage example: 643 + 644 + unsigned long crc = 0L; 645 + 646 + while (read_buffer(buffer, length) != EOF) { 647 + crc = update_crc(crc, buffer, length); 648 + } 649 + if (crc != original_crc) error(); 650 + */ 651 + unsigned long update_crc(unsigned long crc, 652 + unsigned char *buf, int len) 653 + { 654 + unsigned long c = crc ^ 0xffffffffL; 655 + int n; 656 + 657 + if (!crc_table_computed) 658 + make_crc_table(); 659 + for (n = 0; n < len; n++) { 660 + c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); 661 + } 662 + return c ^ 0xffffffffL; 663 + } 664 + 665 + /* Return the CRC of the bytes buf[0..len-1]. */ 666 + unsigned long crc(unsigned char *buf, int len) 667 + { 668 + return update_crc(0L, buf, len); 669 + } 670 + 671 + 672 + 673 + 674 +Deutsch Informational [Page 12] 675 +
Added compat/zlib/doc/txtvsbin.txt.
1 +A Fast Method for Identifying Plain Text Files 2 +============================================== 3 + 4 + 5 +Introduction 6 +------------ 7 + 8 +Given a file coming from an unknown source, it is sometimes desirable 9 +to find out whether the format of that file is plain text. Although 10 +this may appear like a simple task, a fully accurate detection of the 11 +file type requires heavy-duty semantic analysis on the file contents. 12 +It is, however, possible to obtain satisfactory results by employing 13 +various heuristics. 14 + 15 +Previous versions of PKZip and other zip-compatible compression tools 16 +were using a crude detection scheme: if more than 80% (4/5) of the bytes 17 +found in a certain buffer are within the range [7..127], the file is 18 +labeled as plain text, otherwise it is labeled as binary. A prominent 19 +limitation of this scheme is the restriction to Latin-based alphabets. 20 +Other alphabets, like Greek, Cyrillic or Asian, make extensive use of 21 +the bytes within the range [128..255], and texts using these alphabets 22 +are most often misidentified by this scheme; in other words, the rate 23 +of false negatives is sometimes too high, which means that the recall 24 +is low. Another weakness of this scheme is a reduced precision, due to 25 +the false positives that may occur when binary files containing large 26 +amounts of textual characters are misidentified as plain text. 27 + 28 +In this article we propose a new, simple detection scheme that features 29 +a much increased precision and a near-100% recall. This scheme is 30 +designed to work on ASCII, Unicode and other ASCII-derived alphabets, 31 +and it handles single-byte encodings (ISO-8859, MacRoman, KOI8, etc.) 32 +and variable-sized encodings (ISO-2022, UTF-8, etc.). Wider encodings 33 +(UCS-2/UTF-16 and UCS-4/UTF-32) are not handled, however. 34 + 35 + 36 +The Algorithm 37 +------------- 38 + 39 +The algorithm works by dividing the set of bytecodes [0..255] into three 40 +categories: 41 +- The white list of textual bytecodes: 42 + 9 (TAB), 10 (LF), 13 (CR), 32 (SPACE) to 255. 43 +- The gray list of tolerated bytecodes: 44 + 7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB), 27 (ESC). 45 +- The black list of undesired, non-textual bytecodes: 46 + 0 (NUL) to 6, 14 to 31. 47 + 48 +If a file contains at least one byte that belongs to the white list and 49 +no byte that belongs to the black list, then the file is categorized as 50 +plain text; otherwise, it is categorized as binary. (The boundary case, 51 +when the file is empty, automatically falls into the latter category.) 52 + 53 + 54 +Rationale 55 +--------- 56 + 57 +The idea behind this algorithm relies on two observations. 58 + 59 +The first observation is that, although the full range of 7-bit codes 60 +[0..127] is properly specified by the ASCII standard, most control 61 +characters in the range [0..31] are not used in practice. The only 62 +widely-used, almost universally-portable control codes are 9 (TAB), 63 +10 (LF) and 13 (CR). There are a few more control codes that are 64 +recognized on a reduced range of platforms and text viewers/editors: 65 +7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB) and 27 (ESC); but these 66 +codes are rarely (if ever) used alone, without being accompanied by 67 +some printable text. Even the newer, portable text formats such as 68 +XML avoid using control characters outside the list mentioned here. 69 + 70 +The second observation is that most of the binary files tend to contain 71 +control characters, especially 0 (NUL). Even though the older text 72 +detection schemes observe the presence of non-ASCII codes from the range 73 +[128..255], the precision rarely has to suffer if this upper range is 74 +labeled as textual, because the files that are genuinely binary tend to 75 +contain both control characters and codes from the upper range. On the 76 +other hand, the upper range needs to be labeled as textual, because it 77 +is used by virtually all ASCII extensions. In particular, this range is 78 +used for encoding non-Latin scripts. 79 + 80 +Since there is no counting involved, other than simply observing the 81 +presence or the absence of some byte values, the algorithm produces 82 +consistent results, regardless what alphabet encoding is being used. 83 +(If counting were involved, it could be possible to obtain different 84 +results on a text encoded, say, using ISO-8859-16 versus UTF-8.) 85 + 86 +There is an extra category of plain text files that are "polluted" with 87 +one or more black-listed codes, either by mistake or by peculiar design 88 +considerations. In such cases, a scheme that tolerates a small fraction 89 +of black-listed codes would provide an increased recall (i.e. more true 90 +positives). This, however, incurs a reduced precision overall, since 91 +false positives are more likely to appear in binary files that contain 92 +large chunks of textual data. Furthermore, "polluted" plain text should 93 +be regarded as binary by general-purpose text detection schemes, because 94 +general-purpose text processing algorithms might not be applicable. 95 +Under this premise, it is safe to say that our detection method provides 96 +a near-100% recall. 97 + 98 +Experiments have been run on many files coming from various platforms 99 +and applications. We tried plain text files, system logs, source code, 100 +formatted office documents, compiled object code, etc. The results 101 +confirm the optimistic assumptions about the capabilities of this 102 +algorithm. 103 + 104 + 105 +-- 106 +Cosmin Truta 107 +Last updated: 2006-May-28
Added compat/zlib/examples/README.examples.
1 +This directory contains examples of the use of zlib and other relevant 2 +programs and documentation. 3 + 4 +enough.c 5 + calculation and justification of ENOUGH parameter in inftrees.h 6 + - calculates the maximum table space used in inflate tree 7 + construction over all possible Huffman codes 8 + 9 +fitblk.c 10 + compress just enough input to nearly fill a requested output size 11 + - zlib isn't designed to do this, but fitblk does it anyway 12 + 13 +gun.c 14 + uncompress a gzip file 15 + - illustrates the use of inflateBack() for high speed file-to-file 16 + decompression using call-back functions 17 + - is approximately twice as fast as gzip -d 18 + - also provides Unix uncompress functionality, again twice as fast 19 + 20 +gzappend.c 21 + append to a gzip file 22 + - illustrates the use of the Z_BLOCK flush parameter for inflate() 23 + - illustrates the use of deflatePrime() to start at any bit 24 + 25 +gzjoin.c 26 + join gzip files without recalculating the crc or recompressing 27 + - illustrates the use of the Z_BLOCK flush parameter for inflate() 28 + - illustrates the use of crc32_combine() 29 + 30 +gzlog.c 31 +gzlog.h 32 + efficiently and robustly maintain a message log file in gzip format 33 + - illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(), 34 + and deflateSetDictionary() 35 + - illustrates use of a gzip header extra field 36 + 37 +zlib_how.html 38 + painfully comprehensive description of zpipe.c (see below) 39 + - describes in excruciating detail the use of deflate() and inflate() 40 + 41 +zpipe.c 42 + reads and writes zlib streams from stdin to stdout 43 + - illustrates the proper use of deflate() and inflate() 44 + - deeply commented in zlib_how.html (see above) 45 + 46 +zran.c 47 + index a zlib or gzip stream and randomly access it 48 + - illustrates the use of Z_BLOCK, inflatePrime(), and 49 + inflateSetDictionary() to provide random access
Added compat/zlib/examples/enough.c.
1 +/* enough.c -- determine the maximum size of inflate's Huffman code tables over 2 + * all possible valid and complete Huffman codes, subject to a length limit. 3 + * Copyright (C) 2007, 2008 Mark Adler 4 + * Version 1.3 17 February 2008 Mark Adler 5 + */ 6 + 7 +/* Version history: 8 + 1.0 3 Jan 2007 First version (derived from codecount.c version 1.4) 9 + 1.1 4 Jan 2007 Use faster incremental table usage computation 10 + Prune examine() search on previously visited states 11 + 1.2 5 Jan 2007 Comments clean up 12 + As inflate does, decrease root for short codes 13 + Refuse cases where inflate would increase root 14 + 1.3 17 Feb 2008 Add argument for initial root table size 15 + Fix bug for initial root table size == max - 1 16 + Use a macro to compute the history index 17 + */ 18 + 19 +/* 20 + Examine all possible Huffman codes for a given number of symbols and a 21 + maximum code length in bits to determine the maximum table size for zilb's 22 + inflate. Only complete Huffman codes are counted. 23 + 24 + Two codes are considered distinct if the vectors of the number of codes per 25 + length are not identical. So permutations of the symbol assignments result 26 + in the same code for the counting, as do permutations of the assignments of 27 + the bit values to the codes (i.e. only canonical codes are counted). 28 + 29 + We build a code from shorter to longer lengths, determining how many symbols 30 + are coded at each length. At each step, we have how many symbols remain to 31 + be coded, what the last code length used was, and how many bit patterns of 32 + that length remain unused. Then we add one to the code length and double the 33 + number of unused patterns to graduate to the next code length. We then 34 + assign all portions of the remaining symbols to that code length that 35 + preserve the properties of a correct and eventually complete code. Those 36 + properties are: we cannot use more bit patterns than are available; and when 37 + all the symbols are used, there are exactly zero possible bit patterns 38 + remaining. 39 + 40 + The inflate Huffman decoding algorithm uses two-level lookup tables for 41 + speed. There is a single first-level table to decode codes up to root bits 42 + in length (root == 9 in the current inflate implementation). The table 43 + has 1 << root entries and is indexed by the next root bits of input. Codes 44 + shorter than root bits have replicated table entries, so that the correct 45 + entry is pointed to regardless of the bits that follow the short code. If 46 + the code is longer than root bits, then the table entry points to a second- 47 + level table. The size of that table is determined by the longest code with 48 + that root-bit prefix. If that longest code has length len, then the table 49 + has size 1 << (len - root), to index the remaining bits in that set of 50 + codes. Each subsequent root-bit prefix then has its own sub-table. The 51 + total number of table entries required by the code is calculated 52 + incrementally as the number of codes at each bit length is populated. When 53 + all of the codes are shorter than root bits, then root is reduced to the 54 + longest code length, resulting in a single, smaller, one-level table. 55 + 56 + The inflate algorithm also provides for small values of root (relative to 57 + the log2 of the number of symbols), where the shortest code has more bits 58 + than root. In that case, root is increased to the length of the shortest 59 + code. This program, by design, does not handle that case, so it is verified 60 + that the number of symbols is less than 2^(root + 1). 61 + 62 + In order to speed up the examination (by about ten orders of magnitude for 63 + the default arguments), the intermediate states in the build-up of a code 64 + are remembered and previously visited branches are pruned. The memory 65 + required for this will increase rapidly with the total number of symbols and 66 + the maximum code length in bits. However this is a very small price to pay 67 + for the vast speedup. 68 + 69 + First, all of the possible Huffman codes are counted, and reachable 70 + intermediate states are noted by a non-zero count in a saved-results array. 71 + Second, the intermediate states that lead to (root + 1) bit or longer codes 72 + are used to look at all sub-codes from those junctures for their inflate 73 + memory usage. (The amount of memory used is not affected by the number of 74 + codes of root bits or less in length.) Third, the visited states in the 75 + construction of those sub-codes and the associated calculation of the table 76 + size is recalled in order to avoid recalculating from the same juncture. 77 + Beginning the code examination at (root + 1) bit codes, which is enabled by 78 + identifying the reachable nodes, accounts for about six of the orders of 79 + magnitude of improvement for the default arguments. About another four 80 + orders of magnitude come from not revisiting previous states. Out of 81 + approximately 2x10^16 possible Huffman codes, only about 2x10^6 sub-codes 82 + need to be examined to cover all of the possible table memory usage cases 83 + for the default arguments of 286 symbols limited to 15-bit codes. 84 + 85 + Note that an unsigned long long type is used for counting. It is quite easy 86 + to exceed the capacity of an eight-byte integer with a large number of 87 + symbols and a large maximum code length, so multiple-precision arithmetic 88 + would need to replace the unsigned long long arithmetic in that case. This 89 + program will abort if an overflow occurs. The big_t type identifies where 90 + the counting takes place. 91 + 92 + An unsigned long long type is also used for calculating the number of 93 + possible codes remaining at the maximum length. This limits the maximum 94 + code length to the number of bits in a long long minus the number of bits 95 + needed to represent the symbols in a flat code. The code_t type identifies 96 + where the bit pattern counting takes place. 97 + */ 98 + 99 +#include <stdio.h> 100 +#include <stdlib.h> 101 +#include <string.h> 102 +#include <assert.h> 103 + 104 +#define local static 105 + 106 +/* special data types */ 107 +typedef unsigned long long big_t; /* type for code counting */ 108 +typedef unsigned long long code_t; /* type for bit pattern counting */ 109 +struct tab { /* type for been here check */ 110 + size_t len; /* length of bit vector in char's */ 111 + char *vec; /* allocated bit vector */ 112 +}; 113 + 114 +/* The array for saving results, num[], is indexed with this triplet: 115 + 116 + syms: number of symbols remaining to code 117 + left: number of available bit patterns at length len 118 + len: number of bits in the codes currently being assigned 119 + 120 + Those indices are constrained thusly when saving results: 121 + 122 + syms: 3..totsym (totsym == total symbols to code) 123 + left: 2..syms - 1, but only the evens (so syms == 8 -> 2, 4, 6) 124 + len: 1..max - 1 (max == maximum code length in bits) 125 + 126 + syms == 2 is not saved since that immediately leads to a single code. left 127 + must be even, since it represents the number of available bit patterns at 128 + the current length, which is double the number at the previous length. 129 + left ends at syms-1 since left == syms immediately results in a single code. 130 + (left > sym is not allowed since that would result in an incomplete code.) 131 + len is less than max, since the code completes immediately when len == max. 132 + 133 + The offset into the array is calculated for the three indices with the 134 + first one (syms) being outermost, and the last one (len) being innermost. 135 + We build the array with length max-1 lists for the len index, with syms-3 136 + of those for each symbol. There are totsym-2 of those, with each one 137 + varying in length as a function of sym. See the calculation of index in 138 + count() for the index, and the calculation of size in main() for the size 139 + of the array. 140 + 141 + For the deflate example of 286 symbols limited to 15-bit codes, the array 142 + has 284,284 entries, taking up 2.17 MB for an 8-byte big_t. More than 143 + half of the space allocated for saved results is actually used -- not all 144 + possible triplets are reached in the generation of valid Huffman codes. 145 + */ 146 + 147 +/* The array for tracking visited states, done[], is itself indexed identically 148 + to the num[] array as described above for the (syms, left, len) triplet. 149 + Each element in the array is further indexed by the (mem, rem) doublet, 150 + where mem is the amount of inflate table space used so far, and rem is the 151 + remaining unused entries in the current inflate sub-table. Each indexed 152 + element is simply one bit indicating whether the state has been visited or 153 + not. Since the ranges for mem and rem are not known a priori, each bit 154 + vector is of a variable size, and grows as needed to accommodate the visited 155 + states. mem and rem are used to calculate a single index in a triangular 156 + array. Since the range of mem is expected in the default case to be about 157 + ten times larger than the range of rem, the array is skewed to reduce the 158 + memory usage, with eight times the range for mem than for rem. See the 159 + calculations for offset and bit in beenhere() for the details. 160 + 161 + For the deflate example of 286 symbols limited to 15-bit codes, the bit 162 + vectors grow to total approximately 21 MB, in addition to the 4.3 MB done[] 163 + array itself. 164 + */ 165 + 166 +/* Globals to avoid propagating constants or constant pointers recursively */ 167 +local int max; /* maximum allowed bit length for the codes */ 168 +local int root; /* size of base code table in bits */ 169 +local int large; /* largest code table so far */ 170 +local size_t size; /* number of elements in num and done */ 171 +local int *code; /* number of symbols assigned to each bit length */ 172 +local big_t *num; /* saved results array for code counting */ 173 +local struct tab *done; /* states already evaluated array */ 174 + 175 +/* Index function for num[] and done[] */ 176 +#define INDEX(i,j,k) (((size_t)((i-1)>>1)*((i-2)>>1)+(j>>1)-1)*(max-1)+k-1) 177 + 178 +/* Free allocated space. Uses globals code, num, and done. */ 179 +local void cleanup(void) 180 +{ 181 + size_t n; 182 + 183 + if (done != NULL) { 184 + for (n = 0; n < size; n++) 185 + if (done[n].len) 186 + free(done[n].vec); 187 + free(done); 188 + } 189 + if (num != NULL) 190 + free(num); 191 + if (code != NULL) 192 + free(code); 193 +} 194 + 195 +/* Return the number of possible Huffman codes using bit patterns of lengths 196 + len through max inclusive, coding syms symbols, with left bit patterns of 197 + length len unused -- return -1 if there is an overflow in the counting. 198 + Keep a record of previous results in num to prevent repeating the same 199 + calculation. Uses the globals max and num. */ 200 +local big_t count(int syms, int len, int left) 201 +{ 202 + big_t sum; /* number of possible codes from this juncture */ 203 + big_t got; /* value returned from count() */ 204 + int least; /* least number of syms to use at this juncture */ 205 + int most; /* most number of syms to use at this juncture */ 206 + int use; /* number of bit patterns to use in next call */ 207 + size_t index; /* index of this case in *num */ 208 + 209 + /* see if only one possible code */ 210 + if (syms == left) 211 + return 1; 212 + 213 + /* note and verify the expected state */ 214 + assert(syms > left && left > 0 && len < max); 215 + 216 + /* see if we've done this one already */ 217 + index = INDEX(syms, left, len); 218 + got = num[index]; 219 + if (got) 220 + return got; /* we have -- return the saved result */ 221 + 222 + /* we need to use at least this many bit patterns so that the code won't be 223 + incomplete at the next length (more bit patterns than symbols) */ 224 + least = (left << 1) - syms; 225 + if (least < 0) 226 + least = 0; 227 + 228 + /* we can use at most this many bit patterns, lest there not be enough 229 + available for the remaining symbols at the maximum length (if there were 230 + no limit to the code length, this would become: most = left - 1) */ 231 + most = (((code_t)left << (max - len)) - syms) / 232 + (((code_t)1 << (max - len)) - 1); 233 + 234 + /* count all possible codes from this juncture and add them up */ 235 + sum = 0; 236 + for (use = least; use <= most; use++) { 237 + got = count(syms - use, len + 1, (left - use) << 1); 238 + sum += got; 239 + if (got == -1 || sum < got) /* overflow */ 240 + return -1; 241 + } 242 + 243 + /* verify that all recursive calls are productive */ 244 + assert(sum != 0); 245 + 246 + /* save the result and return it */ 247 + num[index] = sum; 248 + return sum; 249 +} 250 + 251 +/* Return true if we've been here before, set to true if not. Set a bit in a 252 + bit vector to indicate visiting this state. Each (syms,len,left) state 253 + has a variable size bit vector indexed by (mem,rem). The bit vector is 254 + lengthened if needed to allow setting the (mem,rem) bit. */ 255 +local int beenhere(int syms, int len, int left, int mem, int rem) 256 +{ 257 + size_t index; /* index for this state's bit vector */ 258 + size_t offset; /* offset in this state's bit vector */ 259 + int bit; /* mask for this state's bit */ 260 + size_t length; /* length of the bit vector in bytes */ 261 + char *vector; /* new or enlarged bit vector */ 262 + 263 + /* point to vector for (syms,left,len), bit in vector for (mem,rem) */ 264 + index = INDEX(syms, left, len); 265 + mem -= 1 << root; 266 + offset = (mem >> 3) + rem; 267 + offset = ((offset * (offset + 1)) >> 1) + rem; 268 + bit = 1 << (mem & 7); 269 + 270 + /* see if we've been here */ 271 + length = done[index].len; 272 + if (offset < length && (done[index].vec[offset] & bit) != 0) 273 + return 1; /* done this! */ 274 + 275 + /* we haven't been here before -- set the bit to show we have now */ 276 + 277 + /* see if we need to lengthen the vector in order to set the bit */ 278 + if (length <= offset) { 279 + /* if we have one already, enlarge it, zero out the appended space */ 280 + if (length) { 281 + do { 282 + length <<= 1; 283 + } while (length <= offset); 284 + vector = realloc(done[index].vec, length); 285 + if (vector != NULL) 286 + memset(vector + done[index].len, 0, length - done[index].len); 287 + } 288 + 289 + /* otherwise we need to make a new vector and zero it out */ 290 + else { 291 + length = 1 << (len - root); 292 + while (length <= offset) 293 + length <<= 1; 294 + vector = calloc(length, sizeof(char)); 295 + } 296 + 297 + /* in either case, bail if we can't get the memory */ 298 + if (vector == NULL) { 299 + fputs("abort: unable to allocate enough memory\n", stderr); 300 + cleanup(); 301 + exit(1); 302 + } 303 + 304 + /* install the new vector */ 305 + done[index].len = length; 306 + done[index].vec = vector; 307 + } 308 + 309 + /* set the bit */ 310 + done[index].vec[offset] |= bit; 311 + return 0; 312 +} 313 + 314 +/* Examine all possible codes from the given node (syms, len, left). Compute 315 + the amount of memory required to build inflate's decoding tables, where the 316 + number of code structures used so far is mem, and the number remaining in 317 + the current sub-table is rem. Uses the globals max, code, root, large, and 318 + done. */ 319 +local void examine(int syms, int len, int left, int mem, int rem) 320 +{ 321 + int least; /* least number of syms to use at this juncture */ 322 + int most; /* most number of syms to use at this juncture */ 323 + int use; /* number of bit patterns to use in next call */ 324 + 325 + /* see if we have a complete code */ 326 + if (syms == left) { 327 + /* set the last code entry */ 328 + code[len] = left; 329 + 330 + /* complete computation of memory used by this code */ 331 + while (rem < left) { 332 + left -= rem; 333 + rem = 1 << (len - root); 334 + mem += rem; 335 + } 336 + assert(rem == left); 337 + 338 + /* if this is a new maximum, show the entries used and the sub-code */ 339 + if (mem > large) { 340 + large = mem; 341 + printf("max %d: ", mem); 342 + for (use = root + 1; use <= max; use++) 343 + if (code[use]) 344 + printf("%d[%d] ", code[use], use); 345 + putchar('\n'); 346 + fflush(stdout); 347 + } 348 + 349 + /* remove entries as we drop back down in the recursion */ 350 + code[len] = 0; 351 + return; 352 + } 353 + 354 + /* prune the tree if we can */ 355 + if (beenhere(syms, len, left, mem, rem)) 356 + return; 357 + 358 + /* we need to use at least this many bit patterns so that the code won't be 359 + incomplete at the next length (more bit patterns than symbols) */ 360 + least = (left << 1) - syms; 361 + if (least < 0) 362 + least = 0; 363 + 364 + /* we can use at most this many bit patterns, lest there not be enough 365 + available for the remaining symbols at the maximum length (if there were 366 + no limit to the code length, this would become: most = left - 1) */ 367 + most = (((code_t)left << (max - len)) - syms) / 368 + (((code_t)1 << (max - len)) - 1); 369 + 370 + /* occupy least table spaces, creating new sub-tables as needed */ 371 + use = least; 372 + while (rem < use) { 373 + use -= rem; 374 + rem = 1 << (len - root); 375 + mem += rem; 376 + } 377 + rem -= use; 378 + 379 + /* examine codes from here, updating table space as we go */ 380 + for (use = least; use <= most; use++) { 381 + code[len] = use; 382 + examine(syms - use, len + 1, (left - use) << 1, 383 + mem + (rem ? 1 << (len - root) : 0), rem << 1); 384 + if (rem == 0) { 385 + rem = 1 << (len - root); 386 + mem += rem; 387 + } 388 + rem--; 389 + } 390 + 391 + /* remove entries as we drop back down in the recursion */ 392 + code[len] = 0; 393 +} 394 + 395 +/* Look at all sub-codes starting with root + 1 bits. Look at only the valid 396 + intermediate code states (syms, left, len). For each completed code, 397 + calculate the amount of memory required by inflate to build the decoding 398 + tables. Find the maximum amount of memory required and show the code that 399 + requires that maximum. Uses the globals max, root, and num. */ 400 +local void enough(int syms) 401 +{ 402 + int n; /* number of remaing symbols for this node */ 403 + int left; /* number of unused bit patterns at this length */ 404 + size_t index; /* index of this case in *num */ 405 + 406 + /* clear code */ 407 + for (n = 0; n <= max; n++) 408 + code[n] = 0; 409 + 410 + /* look at all (root + 1) bit and longer codes */ 411 + large = 1 << root; /* base table */ 412 + if (root < max) /* otherwise, there's only a base table */ 413 + for (n = 3; n <= syms; n++) 414 + for (left = 2; left < n; left += 2) 415 + { 416 + /* look at all reachable (root + 1) bit nodes, and the 417 + resulting codes (complete at root + 2 or more) */ 418 + index = INDEX(n, left, root + 1); 419 + if (root + 1 < max && num[index]) /* reachable node */ 420 + examine(n, root + 1, left, 1 << root, 0); 421 + 422 + /* also look at root bit codes with completions at root + 1 423 + bits (not saved in num, since complete), just in case */ 424 + if (num[index - 1] && n <= left << 1) 425 + examine((n - left) << 1, root + 1, (n - left) << 1, 426 + 1 << root, 0); 427 + } 428 + 429 + /* done */ 430 + printf("done: maximum of %d table entries\n", large); 431 +} 432 + 433 +/* 434 + Examine and show the total number of possible Huffman codes for a given 435 + maximum number of symbols, initial root table size, and maximum code length 436 + in bits -- those are the command arguments in that order. The default 437 + values are 286, 9, and 15 respectively, for the deflate literal/length code. 438 + The possible codes are counted for each number of coded symbols from two to 439 + the maximum. The counts for each of those and the total number of codes are 440 + shown. The maximum number of inflate table entires is then calculated 441 + across all possible codes. Each new maximum number of table entries and the 442 + associated sub-code (starting at root + 1 == 10 bits) is shown. 443 + 444 + To count and examine Huffman codes that are not length-limited, provide a 445 + maximum length equal to the number of symbols minus one. 446 + 447 + For the deflate literal/length code, use "enough". For the deflate distance 448 + code, use "enough 30 6". 449 + 450 + This uses the %llu printf format to print big_t numbers, which assumes that 451 + big_t is an unsigned long long. If the big_t type is changed (for example 452 + to a multiple precision type), the method of printing will also need to be 453 + updated. 454 + */ 455 +int main(int argc, char **argv) 456 +{ 457 + int syms; /* total number of symbols to code */ 458 + int n; /* number of symbols to code for this run */ 459 + big_t got; /* return value of count() */ 460 + big_t sum; /* accumulated number of codes over n */ 461 + 462 + /* set up globals for cleanup() */ 463 + code = NULL; 464 + num = NULL; 465 + done = NULL; 466 + 467 + /* get arguments -- default to the deflate literal/length code */ 468 + syms = 286; 469 + root = 9; 470 + max = 15; 471 + if (argc > 1) { 472 + syms = atoi(argv[1]); 473 + if (argc > 2) { 474 + root = atoi(argv[2]); 475 + if (argc > 3) 476 + max = atoi(argv[3]); 477 + } 478 + } 479 + if (argc > 4 || syms < 2 || root < 1 || max < 1) { 480 + fputs("invalid arguments, need: [sym >= 2 [root >= 1 [max >= 1]]]\n", 481 + stderr); 482 + return 1; 483 + } 484 + 485 + /* if not restricting the code length, the longest is syms - 1 */ 486 + if (max > syms - 1) 487 + max = syms - 1; 488 + 489 + /* determine the number of bits in a code_t */ 490 + n = 0; 491 + while (((code_t)1 << n) != 0) 492 + n++; 493 + 494 + /* make sure that the calculation of most will not overflow */ 495 + if (max > n || syms - 2 >= (((code_t)0 - 1) >> (max - 1))) { 496 + fputs("abort: code length too long for internal types\n", stderr); 497 + return 1; 498 + } 499 + 500 + /* reject impossible code requests */ 501 + if (syms - 1 > ((code_t)1 << max) - 1) { 502 + fprintf(stderr, "%d symbols cannot be coded in %d bits\n", 503 + syms, max); 504 + return 1; 505 + } 506 + 507 + /* allocate code vector */ 508 + code = calloc(max + 1, sizeof(int)); 509 + if (code == NULL) { 510 + fputs("abort: unable to allocate enough memory\n", stderr); 511 + return 1; 512 + } 513 + 514 + /* determine size of saved results array, checking for overflows, 515 + allocate and clear the array (set all to zero with calloc()) */ 516 + if (syms == 2) /* iff max == 1 */ 517 + num = NULL; /* won't be saving any results */ 518 + else { 519 + size = syms >> 1; 520 + if (size > ((size_t)0 - 1) / (n = (syms - 1) >> 1) || 521 + (size *= n, size > ((size_t)0 - 1) / (n = max - 1)) || 522 + (size *= n, size > ((size_t)0 - 1) / sizeof(big_t)) || 523 + (num = calloc(size, sizeof(big_t))) == NULL) { 524 + fputs("abort: unable to allocate enough memory\n", stderr); 525 + cleanup(); 526 + return 1; 527 + } 528 + } 529 + 530 + /* count possible codes for all numbers of symbols, add up counts */ 531 + sum = 0; 532 + for (n = 2; n <= syms; n++) { 533 + got = count(n, 1, 2); 534 + sum += got; 535 + if (got == -1 || sum < got) { /* overflow */ 536 + fputs("abort: can't count that high!\n", stderr); 537 + cleanup(); 538 + return 1; 539 + } 540 + printf("%llu %d-codes\n", got, n); 541 + } 542 + printf("%llu total codes for 2 to %d symbols", sum, syms); 543 + if (max < syms - 1) 544 + printf(" (%d-bit length limit)\n", max); 545 + else 546 + puts(" (no length limit)"); 547 + 548 + /* allocate and clear done array for beenhere() */ 549 + if (syms == 2) 550 + done = NULL; 551 + else if (size > ((size_t)0 - 1) / sizeof(struct tab) || 552 + (done = calloc(size, sizeof(struct tab))) == NULL) { 553 + fputs("abort: unable to allocate enough memory\n", stderr); 554 + cleanup(); 555 + return 1; 556 + } 557 + 558 + /* find and show maximum inflate table usage */ 559 + if (root > max) /* reduce root to max length */ 560 + root = max; 561 + if (syms < ((code_t)1 << (root + 1))) 562 + enough(syms); 563 + else 564 + puts("cannot handle minimum code lengths > root"); 565 + 566 + /* done */ 567 + cleanup(); 568 + return 0; 569 +}
Added compat/zlib/examples/fitblk.c.
1 +/* fitblk.c: example of fitting compressed output to a specified size 2 + Not copyrighted -- provided to the public domain 3 + Version 1.1 25 November 2004 Mark Adler */ 4 + 5 +/* Version history: 6 + 1.0 24 Nov 2004 First version 7 + 1.1 25 Nov 2004 Change deflateInit2() to deflateInit() 8 + Use fixed-size, stack-allocated raw buffers 9 + Simplify code moving compression to subroutines 10 + Use assert() for internal errors 11 + Add detailed description of approach 12 + */ 13 + 14 +/* Approach to just fitting a requested compressed size: 15 + 16 + fitblk performs three compression passes on a portion of the input 17 + data in order to determine how much of that input will compress to 18 + nearly the requested output block size. The first pass generates 19 + enough deflate blocks to produce output to fill the requested 20 + output size plus a specfied excess amount (see the EXCESS define 21 + below). The last deflate block may go quite a bit past that, but 22 + is discarded. The second pass decompresses and recompresses just 23 + the compressed data that fit in the requested plus excess sized 24 + buffer. The deflate process is terminated after that amount of 25 + input, which is less than the amount consumed on the first pass. 26 + The last deflate block of the result will be of a comparable size 27 + to the final product, so that the header for that deflate block and 28 + the compression ratio for that block will be about the same as in 29 + the final product. The third compression pass decompresses the 30 + result of the second step, but only the compressed data up to the 31 + requested size minus an amount to allow the compressed stream to 32 + complete (see the MARGIN define below). That will result in a 33 + final compressed stream whose length is less than or equal to the 34 + requested size. Assuming sufficient input and a requested size 35 + greater than a few hundred bytes, the shortfall will typically be 36 + less than ten bytes. 37 + 38 + If the input is short enough that the first compression completes 39 + before filling the requested output size, then that compressed 40 + stream is return with no recompression. 41 + 42 + EXCESS is chosen to be just greater than the shortfall seen in a 43 + two pass approach similar to the above. That shortfall is due to 44 + the last deflate block compressing more efficiently with a smaller 45 + header on the second pass. EXCESS is set to be large enough so 46 + that there is enough uncompressed data for the second pass to fill 47 + out the requested size, and small enough so that the final deflate 48 + block of the second pass will be close in size to the final deflate 49 + block of the third and final pass. MARGIN is chosen to be just 50 + large enough to assure that the final compression has enough room 51 + to complete in all cases. 52 + */ 53 + 54 +#include <stdio.h> 55 +#include <stdlib.h> 56 +#include <assert.h> 57 +#include "zlib.h" 58 + 59 +#define local static 60 + 61 +/* print nastygram and leave */ 62 +local void quit(char *why) 63 +{ 64 + fprintf(stderr, "fitblk abort: %s\n", why); 65 + exit(1); 66 +} 67 + 68 +#define RAWLEN 4096 /* intermediate uncompressed buffer size */ 69 + 70 +/* compress from file to def until provided buffer is full or end of 71 + input reached; return last deflate() return value, or Z_ERRNO if 72 + there was read error on the file */ 73 +local int partcompress(FILE *in, z_streamp def) 74 +{ 75 + int ret, flush; 76 + unsigned char raw[RAWLEN]; 77 + 78 + flush = Z_NO_FLUSH; 79 + do { 80 + def->avail_in = fread(raw, 1, RAWLEN, in); 81 + if (ferror(in)) 82 + return Z_ERRNO; 83 + def->next_in = raw; 84 + if (feof(in)) 85 + flush = Z_FINISH; 86 + ret = deflate(def, flush); 87 + assert(ret != Z_STREAM_ERROR); 88 + } while (def->avail_out != 0 && flush == Z_NO_FLUSH); 89 + return ret; 90 +} 91 + 92 +/* recompress from inf's input to def's output; the input for inf and 93 + the output for def are set in those structures before calling; 94 + return last deflate() return value, or Z_MEM_ERROR if inflate() 95 + was not able to allocate enough memory when it needed to */ 96 +local int recompress(z_streamp inf, z_streamp def) 97 +{ 98 + int ret, flush; 99 + unsigned char raw[RAWLEN]; 100 + 101 + flush = Z_NO_FLUSH; 102 + do { 103 + /* decompress */ 104 + inf->avail_out = RAWLEN; 105 + inf->next_out = raw; 106 + ret = inflate(inf, Z_NO_FLUSH); 107 + assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR && 108 + ret != Z_NEED_DICT); 109 + if (ret == Z_MEM_ERROR) 110 + return ret; 111 + 112 + /* compress what was decompresed until done or no room */ 113 + def->avail_in = RAWLEN - inf->avail_out; 114 + def->next_in = raw; 115 + if (inf->avail_out != 0) 116 + flush = Z_FINISH; 117 + ret = deflate(def, flush); 118 + assert(ret != Z_STREAM_ERROR); 119 + } while (ret != Z_STREAM_END && def->avail_out != 0); 120 + return ret; 121 +} 122 + 123 +#define EXCESS 256 /* empirically determined stream overage */ 124 +#define MARGIN 8 /* amount to back off for completion */ 125 + 126 +/* compress from stdin to fixed-size block on stdout */ 127 +int main(int argc, char **argv) 128 +{ 129 + int ret; /* return code */ 130 + unsigned size; /* requested fixed output block size */ 131 + unsigned have; /* bytes written by deflate() call */ 132 + unsigned char *blk; /* intermediate and final stream */ 133 + unsigned char *tmp; /* close to desired size stream */ 134 + z_stream def, inf; /* zlib deflate and inflate states */ 135 + 136 + /* get requested output size */ 137 + if (argc != 2) 138 + quit("need one argument: size of output block"); 139 + ret = strtol(argv[1], argv + 1, 10); 140 + if (argv[1][0] != 0) 141 + quit("argument must be a number"); 142 + if (ret < 8) /* 8 is minimum zlib stream size */ 143 + quit("need positive size of 8 or greater"); 144 + size = (unsigned)ret; 145 + 146 + /* allocate memory for buffers and compression engine */ 147 + blk = malloc(size + EXCESS); 148 + def.zalloc = Z_NULL; 149 + def.zfree = Z_NULL; 150 + def.opaque = Z_NULL; 151 + ret = deflateInit(&def, Z_DEFAULT_COMPRESSION); 152 + if (ret != Z_OK || blk == NULL) 153 + quit("out of memory"); 154 + 155 + /* compress from stdin until output full, or no more input */ 156 + def.avail_out = size + EXCESS; 157 + def.next_out = blk; 158 + ret = partcompress(stdin, &def); 159 + if (ret == Z_ERRNO) 160 + quit("error reading input"); 161 + 162 + /* if it all fit, then size was undersubscribed -- done! */ 163 + if (ret == Z_STREAM_END && def.avail_out >= EXCESS) { 164 + /* write block to stdout */ 165 + have = size + EXCESS - def.avail_out; 166 + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) 167 + quit("error writing output"); 168 + 169 + /* clean up and print results to stderr */ 170 + ret = deflateEnd(&def); 171 + assert(ret != Z_STREAM_ERROR); 172 + free(blk); 173 + fprintf(stderr, 174 + "%u bytes unused out of %u requested (all input)\n", 175 + size - have, size); 176 + return 0; 177 + } 178 + 179 + /* it didn't all fit -- set up for recompression */ 180 + inf.zalloc = Z_NULL; 181 + inf.zfree = Z_NULL; 182 + inf.opaque = Z_NULL; 183 + inf.avail_in = 0; 184 + inf.next_in = Z_NULL; 185 + ret = inflateInit(&inf); 186 + tmp = malloc(size + EXCESS); 187 + if (ret != Z_OK || tmp == NULL) 188 + quit("out of memory"); 189 + ret = deflateReset(&def); 190 + assert(ret != Z_STREAM_ERROR); 191 + 192 + /* do first recompression close to the right amount */ 193 + inf.avail_in = size + EXCESS; 194 + inf.next_in = blk; 195 + def.avail_out = size + EXCESS; 196 + def.next_out = tmp; 197 + ret = recompress(&inf, &def); 198 + if (ret == Z_MEM_ERROR) 199 + quit("out of memory"); 200 + 201 + /* set up for next reocmpression */ 202 + ret = inflateReset(&inf); 203 + assert(ret != Z_STREAM_ERROR); 204 + ret = deflateReset(&def); 205 + assert(ret != Z_STREAM_ERROR); 206 + 207 + /* do second and final recompression (third compression) */ 208 + inf.avail_in = size - MARGIN; /* assure stream will complete */ 209 + inf.next_in = tmp; 210 + def.avail_out = size; 211 + def.next_out = blk; 212 + ret = recompress(&inf, &def); 213 + if (ret == Z_MEM_ERROR) 214 + quit("out of memory"); 215 + assert(ret == Z_STREAM_END); /* otherwise MARGIN too small */ 216 + 217 + /* done -- write block to stdout */ 218 + have = size - def.avail_out; 219 + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) 220 + quit("error writing output"); 221 + 222 + /* clean up and print results to stderr */ 223 + free(tmp); 224 + ret = inflateEnd(&inf); 225 + assert(ret != Z_STREAM_ERROR); 226 + ret = deflateEnd(&def); 227 + assert(ret != Z_STREAM_ERROR); 228 + free(blk); 229 + fprintf(stderr, 230 + "%u bytes unused out of %u requested (%lu input)\n", 231 + size - have, size, def.total_in); 232 + return 0; 233 +}
Added compat/zlib/examples/gun.c.
1 +/* gun.c -- simple gunzip to give an example of the use of inflateBack() 2 + * Copyright (C) 2003, 2005, 2008, 2010 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + Version 1.6 17 January 2010 Mark Adler */ 5 + 6 +/* Version history: 7 + 1.0 16 Feb 2003 First version for testing of inflateBack() 8 + 1.1 21 Feb 2005 Decompress concatenated gzip streams 9 + Remove use of "this" variable (C++ keyword) 10 + Fix return value for in() 11 + Improve allocation failure checking 12 + Add typecasting for void * structures 13 + Add -h option for command version and usage 14 + Add a bunch of comments 15 + 1.2 20 Mar 2005 Add Unix compress (LZW) decompression 16 + Copy file attributes from input file to output file 17 + 1.3 12 Jun 2005 Add casts for error messages [Oberhumer] 18 + 1.4 8 Dec 2006 LZW decompression speed improvements 19 + 1.5 9 Feb 2008 Avoid warning in latest version of gcc 20 + 1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings 21 + */ 22 + 23 +/* 24 + gun [ -t ] [ name ... ] 25 + 26 + decompresses the data in the named gzip files. If no arguments are given, 27 + gun will decompress from stdin to stdout. The names must end in .gz, -gz, 28 + .z, -z, _z, or .Z. The uncompressed data will be written to a file name 29 + with the suffix stripped. On success, the original file is deleted. On 30 + failure, the output file is deleted. For most failures, the command will 31 + continue to process the remaining names on the command line. A memory 32 + allocation failure will abort the command. If -t is specified, then the 33 + listed files or stdin will be tested as gzip files for integrity (without 34 + checking for a proper suffix), no output will be written, and no files 35 + will be deleted. 36 + 37 + Like gzip, gun allows concatenated gzip streams and will decompress them, 38 + writing all of the uncompressed data to the output. Unlike gzip, gun allows 39 + an empty file on input, and will produce no error writing an empty output 40 + file. 41 + 42 + gun will also decompress files made by Unix compress, which uses LZW 43 + compression. These files are automatically detected by virtue of their 44 + magic header bytes. Since the end of Unix compress stream is marked by the 45 + end-of-file, they cannot be concantenated. If a Unix compress stream is 46 + encountered in an input file, it is the last stream in that file. 47 + 48 + Like gunzip and uncompress, the file attributes of the orignal compressed 49 + file are maintained in the final uncompressed file, to the extent that the 50 + user permissions allow it. 51 + 52 + On my Mac OS X PowerPC G4, gun is almost twice as fast as gunzip (version 53 + 1.2.4) is on the same file, when gun is linked with zlib 1.2.2. Also the 54 + LZW decompression provided by gun is about twice as fast as the standard 55 + Unix uncompress command. 56 + */ 57 + 58 +/* external functions and related types and constants */ 59 +#include <stdio.h> /* fprintf() */ 60 +#include <stdlib.h> /* malloc(), free() */ 61 +#include <string.h> /* strerror(), strcmp(), strlen(), memcpy() */ 62 +#include <errno.h> /* errno */ 63 +#include <fcntl.h> /* open() */ 64 +#include <unistd.h> /* read(), write(), close(), chown(), unlink() */ 65 +#include <sys/types.h> 66 +#include <sys/stat.h> /* stat(), chmod() */ 67 +#include <utime.h> /* utime() */ 68 +#include "zlib.h" /* inflateBackInit(), inflateBack(), */ 69 + /* inflateBackEnd(), crc32() */ 70 + 71 +/* function declaration */ 72 +#define local static 73 + 74 +/* buffer constants */ 75 +#define SIZE 32768U /* input and output buffer sizes */ 76 +#define PIECE 16384 /* limits i/o chunks for 16-bit int case */ 77 + 78 +/* structure for infback() to pass to input function in() -- it maintains the 79 + input file and a buffer of size SIZE */ 80 +struct ind { 81 + int infile; 82 + unsigned char *inbuf; 83 +}; 84 + 85 +/* Load input buffer, assumed to be empty, and return bytes loaded and a 86 + pointer to them. read() is called until the buffer is full, or until it 87 + returns end-of-file or error. Return 0 on error. */ 88 +local unsigned in(void *in_desc, unsigned char **buf) 89 +{ 90 + int ret; 91 + unsigned len; 92 + unsigned char *next; 93 + struct ind *me = (struct ind *)in_desc; 94 + 95 + next = me->inbuf; 96 + *buf = next; 97 + len = 0; 98 + do { 99 + ret = PIECE; 100 + if ((unsigned)ret > SIZE - len) 101 + ret = (int)(SIZE - len); 102 + ret = (int)read(me->infile, next, ret); 103 + if (ret == -1) { 104 + len = 0; 105 + break; 106 + } 107 + next += ret; 108 + len += ret; 109 + } while (ret != 0 && len < SIZE); 110 + return len; 111 +} 112 + 113 +/* structure for infback() to pass to output function out() -- it maintains the 114 + output file, a running CRC-32 check on the output and the total number of 115 + bytes output, both for checking against the gzip trailer. (The length in 116 + the gzip trailer is stored modulo 2^32, so it's ok if a long is 32 bits and 117 + the output is greater than 4 GB.) */ 118 +struct outd { 119 + int outfile; 120 + int check; /* true if checking crc and total */ 121 + unsigned long crc; 122 + unsigned long total; 123 +}; 124 + 125 +/* Write output buffer and update the CRC-32 and total bytes written. write() 126 + is called until all of the output is written or an error is encountered. 127 + On success out() returns 0. For a write failure, out() returns 1. If the 128 + output file descriptor is -1, then nothing is written. 129 + */ 130 +local int out(void *out_desc, unsigned char *buf, unsigned len) 131 +{ 132 + int ret; 133 + struct outd *me = (struct outd *)out_desc; 134 + 135 + if (me->check) { 136 + me->crc = crc32(me->crc, buf, len); 137 + me->total += len; 138 + } 139 + if (me->outfile != -1) 140 + do { 141 + ret = PIECE; 142 + if ((unsigned)ret > len) 143 + ret = (int)len; 144 + ret = (int)write(me->outfile, buf, ret); 145 + if (ret == -1) 146 + return 1; 147 + buf += ret; 148 + len -= ret; 149 + } while (len != 0); 150 + return 0; 151 +} 152 + 153 +/* next input byte macro for use inside lunpipe() and gunpipe() */ 154 +#define NEXT() (have ? 0 : (have = in(indp, &next)), \ 155 + last = have ? (have--, (int)(*next++)) : -1) 156 + 157 +/* memory for gunpipe() and lunpipe() -- 158 + the first 256 entries of prefix[] and suffix[] are never used, could 159 + have offset the index, but it's faster to waste the memory */ 160 +unsigned char inbuf[SIZE]; /* input buffer */ 161 +unsigned char outbuf[SIZE]; /* output buffer */ 162 +unsigned short prefix[65536]; /* index to LZW prefix string */ 163 +unsigned char suffix[65536]; /* one-character LZW suffix */ 164 +unsigned char match[65280 + 2]; /* buffer for reversed match or gzip 165 + 32K sliding window */ 166 + 167 +/* throw out what's left in the current bits byte buffer (this is a vestigial 168 + aspect of the compressed data format derived from an implementation that 169 + made use of a special VAX machine instruction!) */ 170 +#define FLUSHCODE() \ 171 + do { \ 172 + left = 0; \ 173 + rem = 0; \ 174 + if (chunk > have) { \ 175 + chunk -= have; \ 176 + have = 0; \ 177 + if (NEXT() == -1) \ 178 + break; \ 179 + chunk--; \ 180 + if (chunk > have) { \ 181 + chunk = have = 0; \ 182 + break; \ 183 + } \ 184 + } \ 185 + have -= chunk; \ 186 + next += chunk; \ 187 + chunk = 0; \ 188 + } while (0) 189 + 190 +/* Decompress a compress (LZW) file from indp to outfile. The compress magic 191 + header (two bytes) has already been read and verified. There are have bytes 192 + of buffered input at next. strm is used for passing error information back 193 + to gunpipe(). 194 + 195 + lunpipe() will return Z_OK on success, Z_BUF_ERROR for an unexpected end of 196 + file, read error, or write error (a write error indicated by strm->next_in 197 + not equal to Z_NULL), or Z_DATA_ERROR for invalid input. 198 + */ 199 +local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, 200 + int outfile, z_stream *strm) 201 +{ 202 + int last; /* last byte read by NEXT(), or -1 if EOF */ 203 + unsigned chunk; /* bytes left in current chunk */ 204 + int left; /* bits left in rem */ 205 + unsigned rem; /* unused bits from input */ 206 + int bits; /* current bits per code */ 207 + unsigned code; /* code, table traversal index */ 208 + unsigned mask; /* mask for current bits codes */ 209 + int max; /* maximum bits per code for this stream */ 210 + unsigned flags; /* compress flags, then block compress flag */ 211 + unsigned end; /* last valid entry in prefix/suffix tables */ 212 + unsigned temp; /* current code */ 213 + unsigned prev; /* previous code */ 214 + unsigned final; /* last character written for previous code */ 215 + unsigned stack; /* next position for reversed string */ 216 + unsigned outcnt; /* bytes in output buffer */ 217 + struct outd outd; /* output structure */ 218 + unsigned char *p; 219 + 220 + /* set up output */ 221 + outd.outfile = outfile; 222 + outd.check = 0; 223 + 224 + /* process remainder of compress header -- a flags byte */ 225 + flags = NEXT(); 226 + if (last == -1) 227 + return Z_BUF_ERROR; 228 + if (flags & 0x60) { 229 + strm->msg = (char *)"unknown lzw flags set"; 230 + return Z_DATA_ERROR; 231 + } 232 + max = flags & 0x1f; 233 + if (max < 9 || max > 16) { 234 + strm->msg = (char *)"lzw bits out of range"; 235 + return Z_DATA_ERROR; 236 + } 237 + if (max == 9) /* 9 doesn't really mean 9 */ 238 + max = 10; 239 + flags &= 0x80; /* true if block compress */ 240 + 241 + /* clear table */ 242 + bits = 9; 243 + mask = 0x1ff; 244 + end = flags ? 256 : 255; 245 + 246 + /* set up: get first 9-bit code, which is the first decompressed byte, but 247 + don't create a table entry until the next code */ 248 + if (NEXT() == -1) /* no compressed data is ok */ 249 + return Z_OK; 250 + final = prev = (unsigned)last; /* low 8 bits of code */ 251 + if (NEXT() == -1) /* missing a bit */ 252 + return Z_BUF_ERROR; 253 + if (last & 1) { /* code must be < 256 */ 254 + strm->msg = (char *)"invalid lzw code"; 255 + return Z_DATA_ERROR; 256 + } 257 + rem = (unsigned)last >> 1; /* remaining 7 bits */ 258 + left = 7; 259 + chunk = bits - 2; /* 7 bytes left in this chunk */ 260 + outbuf[0] = (unsigned char)final; /* write first decompressed byte */ 261 + outcnt = 1; 262 + 263 + /* decode codes */ 264 + stack = 0; 265 + for (;;) { 266 + /* if the table will be full after this, increment the code size */ 267 + if (end >= mask && bits < max) { 268 + FLUSHCODE(); 269 + bits++; 270 + mask <<= 1; 271 + mask++; 272 + } 273 + 274 + /* get a code of length bits */ 275 + if (chunk == 0) /* decrement chunk modulo bits */ 276 + chunk = bits; 277 + code = rem; /* low bits of code */ 278 + if (NEXT() == -1) { /* EOF is end of compressed data */ 279 + /* write remaining buffered output */ 280 + if (outcnt && out(&outd, outbuf, outcnt)) { 281 + strm->next_in = outbuf; /* signal write error */ 282 + return Z_BUF_ERROR; 283 + } 284 + return Z_OK; 285 + } 286 + code += (unsigned)last << left; /* middle (or high) bits of code */ 287 + left += 8; 288 + chunk--; 289 + if (bits > left) { /* need more bits */ 290 + if (NEXT() == -1) /* can't end in middle of code */ 291 + return Z_BUF_ERROR; 292 + code += (unsigned)last << left; /* high bits of code */ 293 + left += 8; 294 + chunk--; 295 + } 296 + code &= mask; /* mask to current code length */ 297 + left -= bits; /* number of unused bits */ 298 + rem = (unsigned)last >> (8 - left); /* unused bits from last byte */ 299 + 300 + /* process clear code (256) */ 301 + if (code == 256 && flags) { 302 + FLUSHCODE(); 303 + bits = 9; /* initialize bits and mask */ 304 + mask = 0x1ff; 305 + end = 255; /* empty table */ 306 + continue; /* get next code */ 307 + } 308 + 309 + /* special code to reuse last match */ 310 + temp = code; /* save the current code */ 311 + if (code > end) { 312 + /* Be picky on the allowed code here, and make sure that the code 313 + we drop through (prev) will be a valid index so that random 314 + input does not cause an exception. The code != end + 1 check is 315 + empirically derived, and not checked in the original uncompress 316 + code. If this ever causes a problem, that check could be safely 317 + removed. Leaving this check in greatly improves gun's ability 318 + to detect random or corrupted input after a compress header. 319 + In any case, the prev > end check must be retained. */ 320 + if (code != end + 1 || prev > end) { 321 + strm->msg = (char *)"invalid lzw code"; 322 + return Z_DATA_ERROR; 323 + } 324 + match[stack++] = (unsigned char)final; 325 + code = prev; 326 + } 327 + 328 + /* walk through linked list to generate output in reverse order */ 329 + p = match + stack; 330 + while (code >= 256) { 331 + *p++ = suffix[code]; 332 + code = prefix[code]; 333 + } 334 + stack = p - match; 335 + match[stack++] = (unsigned char)code; 336 + final = code; 337 + 338 + /* link new table entry */ 339 + if (end < mask) { 340 + end++; 341 + prefix[end] = (unsigned short)prev; 342 + suffix[end] = (unsigned char)final; 343 + } 344 + 345 + /* set previous code for next iteration */ 346 + prev = temp; 347 + 348 + /* write output in forward order */ 349 + while (stack > SIZE - outcnt) { 350 + while (outcnt < SIZE) 351 + outbuf[outcnt++] = match[--stack]; 352 + if (out(&outd, outbuf, outcnt)) { 353 + strm->next_in = outbuf; /* signal write error */ 354 + return Z_BUF_ERROR; 355 + } 356 + outcnt = 0; 357 + } 358 + p = match + stack; 359 + do { 360 + outbuf[outcnt++] = *--p; 361 + } while (p > match); 362 + stack = 0; 363 + 364 + /* loop for next code with final and prev as the last match, rem and 365 + left provide the first 0..7 bits of the next code, end is the last 366 + valid table entry */ 367 + } 368 +} 369 + 370 +/* Decompress a gzip file from infile to outfile. strm is assumed to have been 371 + successfully initialized with inflateBackInit(). The input file may consist 372 + of a series of gzip streams, in which case all of them will be decompressed 373 + to the output file. If outfile is -1, then the gzip stream(s) integrity is 374 + checked and nothing is written. 375 + 376 + The return value is a zlib error code: Z_MEM_ERROR if out of memory, 377 + Z_DATA_ERROR if the header or the compressed data is invalid, or if the 378 + trailer CRC-32 check or length doesn't match, Z_BUF_ERROR if the input ends 379 + prematurely or a write error occurs, or Z_ERRNO if junk (not a another gzip 380 + stream) follows a valid gzip stream. 381 + */ 382 +local int gunpipe(z_stream *strm, int infile, int outfile) 383 +{ 384 + int ret, first, last; 385 + unsigned have, flags, len; 386 + unsigned char *next = NULL; 387 + struct ind ind, *indp; 388 + struct outd outd; 389 + 390 + /* setup input buffer */ 391 + ind.infile = infile; 392 + ind.inbuf = inbuf; 393 + indp = &ind; 394 + 395 + /* decompress concatenated gzip streams */ 396 + have = 0; /* no input data read in yet */ 397 + first = 1; /* looking for first gzip header */ 398 + strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ 399 + for (;;) { 400 + /* look for the two magic header bytes for a gzip stream */ 401 + if (NEXT() == -1) { 402 + ret = Z_OK; 403 + break; /* empty gzip stream is ok */ 404 + } 405 + if (last != 31 || (NEXT() != 139 && last != 157)) { 406 + strm->msg = (char *)"incorrect header check"; 407 + ret = first ? Z_DATA_ERROR : Z_ERRNO; 408 + break; /* not a gzip or compress header */ 409 + } 410 + first = 0; /* next non-header is junk */ 411 + 412 + /* process a compress (LZW) file -- can't be concatenated after this */ 413 + if (last == 157) { 414 + ret = lunpipe(have, next, indp, outfile, strm); 415 + break; 416 + } 417 + 418 + /* process remainder of gzip header */ 419 + ret = Z_BUF_ERROR; 420 + if (NEXT() != 8) { /* only deflate method allowed */ 421 + if (last == -1) break; 422 + strm->msg = (char *)"unknown compression method"; 423 + ret = Z_DATA_ERROR; 424 + break; 425 + } 426 + flags = NEXT(); /* header flags */ 427 + NEXT(); /* discard mod time, xflgs, os */ 428 + NEXT(); 429 + NEXT(); 430 + NEXT(); 431 + NEXT(); 432 + NEXT(); 433 + if (last == -1) break; 434 + if (flags & 0xe0) { 435 + strm->msg = (char *)"unknown header flags set"; 436 + ret = Z_DATA_ERROR; 437 + break; 438 + } 439 + if (flags & 4) { /* extra field */ 440 + len = NEXT(); 441 + len += (unsigned)(NEXT()) << 8; 442 + if (last == -1) break; 443 + while (len > have) { 444 + len -= have; 445 + have = 0; 446 + if (NEXT() == -1) break; 447 + len--; 448 + } 449 + if (last == -1) break; 450 + have -= len; 451 + next += len; 452 + } 453 + if (flags & 8) /* file name */ 454 + while (NEXT() != 0 && last != -1) 455 + ; 456 + if (flags & 16) /* comment */ 457 + while (NEXT() != 0 && last != -1) 458 + ; 459 + if (flags & 2) { /* header crc */ 460 + NEXT(); 461 + NEXT(); 462 + } 463 + if (last == -1) break; 464 + 465 + /* set up output */ 466 + outd.outfile = outfile; 467 + outd.check = 1; 468 + outd.crc = crc32(0L, Z_NULL, 0); 469 + outd.total = 0; 470 + 471 + /* decompress data to output */ 472 + strm->next_in = next; 473 + strm->avail_in = have; 474 + ret = inflateBack(strm, in, indp, out, &outd); 475 + if (ret != Z_STREAM_END) break; 476 + next = strm->next_in; 477 + have = strm->avail_in; 478 + strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ 479 + 480 + /* check trailer */ 481 + ret = Z_BUF_ERROR; 482 + if (NEXT() != (int)(outd.crc & 0xff) || 483 + NEXT() != (int)((outd.crc >> 8) & 0xff) || 484 + NEXT() != (int)((outd.crc >> 16) & 0xff) || 485 + NEXT() != (int)((outd.crc >> 24) & 0xff)) { 486 + /* crc error */ 487 + if (last != -1) { 488 + strm->msg = (char *)"incorrect data check"; 489 + ret = Z_DATA_ERROR; 490 + } 491 + break; 492 + } 493 + if (NEXT() != (int)(outd.total & 0xff) || 494 + NEXT() != (int)((outd.total >> 8) & 0xff) || 495 + NEXT() != (int)((outd.total >> 16) & 0xff) || 496 + NEXT() != (int)((outd.total >> 24) & 0xff)) { 497 + /* length error */ 498 + if (last != -1) { 499 + strm->msg = (char *)"incorrect length check"; 500 + ret = Z_DATA_ERROR; 501 + } 502 + break; 503 + } 504 + 505 + /* go back and look for another gzip stream */ 506 + } 507 + 508 + /* clean up and return */ 509 + return ret; 510 +} 511 + 512 +/* Copy file attributes, from -> to, as best we can. This is best effort, so 513 + no errors are reported. The mode bits, including suid, sgid, and the sticky 514 + bit are copied (if allowed), the owner's user id and group id are copied 515 + (again if allowed), and the access and modify times are copied. */ 516 +local void copymeta(char *from, char *to) 517 +{ 518 + struct stat was; 519 + struct utimbuf when; 520 + 521 + /* get all of from's Unix meta data, return if not a regular file */ 522 + if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG) 523 + return; 524 + 525 + /* set to's mode bits, ignore errors */ 526 + (void)chmod(to, was.st_mode & 07777); 527 + 528 + /* copy owner's user and group, ignore errors */ 529 + (void)chown(to, was.st_uid, was.st_gid); 530 + 531 + /* copy access and modify times, ignore errors */ 532 + when.actime = was.st_atime; 533 + when.modtime = was.st_mtime; 534 + (void)utime(to, &when); 535 +} 536 + 537 +/* Decompress the file inname to the file outnname, of if test is true, just 538 + decompress without writing and check the gzip trailer for integrity. If 539 + inname is NULL or an empty string, read from stdin. If outname is NULL or 540 + an empty string, write to stdout. strm is a pre-initialized inflateBack 541 + structure. When appropriate, copy the file attributes from inname to 542 + outname. 543 + 544 + gunzip() returns 1 if there is an out-of-memory error or an unexpected 545 + return code from gunpipe(). Otherwise it returns 0. 546 + */ 547 +local int gunzip(z_stream *strm, char *inname, char *outname, int test) 548 +{ 549 + int ret; 550 + int infile, outfile; 551 + 552 + /* open files */ 553 + if (inname == NULL || *inname == 0) { 554 + inname = "-"; 555 + infile = 0; /* stdin */ 556 + } 557 + else { 558 + infile = open(inname, O_RDONLY, 0); 559 + if (infile == -1) { 560 + fprintf(stderr, "gun cannot open %s\n", inname); 561 + return 0; 562 + } 563 + } 564 + if (test) 565 + outfile = -1; 566 + else if (outname == NULL || *outname == 0) { 567 + outname = "-"; 568 + outfile = 1; /* stdout */ 569 + } 570 + else { 571 + outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666); 572 + if (outfile == -1) { 573 + close(infile); 574 + fprintf(stderr, "gun cannot create %s\n", outname); 575 + return 0; 576 + } 577 + } 578 + errno = 0; 579 + 580 + /* decompress */ 581 + ret = gunpipe(strm, infile, outfile); 582 + if (outfile > 2) close(outfile); 583 + if (infile > 2) close(infile); 584 + 585 + /* interpret result */ 586 + switch (ret) { 587 + case Z_OK: 588 + case Z_ERRNO: 589 + if (infile > 2 && outfile > 2) { 590 + copymeta(inname, outname); /* copy attributes */ 591 + unlink(inname); 592 + } 593 + if (ret == Z_ERRNO) 594 + fprintf(stderr, "gun warning: trailing garbage ignored in %s\n", 595 + inname); 596 + break; 597 + case Z_DATA_ERROR: 598 + if (outfile > 2) unlink(outname); 599 + fprintf(stderr, "gun data error on %s: %s\n", inname, strm->msg); 600 + break; 601 + case Z_MEM_ERROR: 602 + if (outfile > 2) unlink(outname); 603 + fprintf(stderr, "gun out of memory error--aborting\n"); 604 + return 1; 605 + case Z_BUF_ERROR: 606 + if (outfile > 2) unlink(outname); 607 + if (strm->next_in != Z_NULL) { 608 + fprintf(stderr, "gun write error on %s: %s\n", 609 + outname, strerror(errno)); 610 + } 611 + else if (errno) { 612 + fprintf(stderr, "gun read error on %s: %s\n", 613 + inname, strerror(errno)); 614 + } 615 + else { 616 + fprintf(stderr, "gun unexpected end of file on %s\n", 617 + inname); 618 + } 619 + break; 620 + default: 621 + if (outfile > 2) unlink(outname); 622 + fprintf(stderr, "gun internal error--aborting\n"); 623 + return 1; 624 + } 625 + return 0; 626 +} 627 + 628 +/* Process the gun command line arguments. See the command syntax near the 629 + beginning of this source file. */ 630 +int main(int argc, char **argv) 631 +{ 632 + int ret, len, test; 633 + char *outname; 634 + unsigned char *window; 635 + z_stream strm; 636 + 637 + /* initialize inflateBack state for repeated use */ 638 + window = match; /* reuse LZW match buffer */ 639 + strm.zalloc = Z_NULL; 640 + strm.zfree = Z_NULL; 641 + strm.opaque = Z_NULL; 642 + ret = inflateBackInit(&strm, 15, window); 643 + if (ret != Z_OK) { 644 + fprintf(stderr, "gun out of memory error--aborting\n"); 645 + return 1; 646 + } 647 + 648 + /* decompress each file to the same name with the suffix removed */ 649 + argc--; 650 + argv++; 651 + test = 0; 652 + if (argc && strcmp(*argv, "-h") == 0) { 653 + fprintf(stderr, "gun 1.6 (17 Jan 2010)\n"); 654 + fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n"); 655 + fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); 656 + return 0; 657 + } 658 + if (argc && strcmp(*argv, "-t") == 0) { 659 + test = 1; 660 + argc--; 661 + argv++; 662 + } 663 + if (argc) 664 + do { 665 + if (test) 666 + outname = NULL; 667 + else { 668 + len = (int)strlen(*argv); 669 + if (strcmp(*argv + len - 3, ".gz") == 0 || 670 + strcmp(*argv + len - 3, "-gz") == 0) 671 + len -= 3; 672 + else if (strcmp(*argv + len - 2, ".z") == 0 || 673 + strcmp(*argv + len - 2, "-z") == 0 || 674 + strcmp(*argv + len - 2, "_z") == 0 || 675 + strcmp(*argv + len - 2, ".Z") == 0) 676 + len -= 2; 677 + else { 678 + fprintf(stderr, "gun error: no gz type on %s--skipping\n", 679 + *argv); 680 + continue; 681 + } 682 + outname = malloc(len + 1); 683 + if (outname == NULL) { 684 + fprintf(stderr, "gun out of memory error--aborting\n"); 685 + ret = 1; 686 + break; 687 + } 688 + memcpy(outname, *argv, len); 689 + outname[len] = 0; 690 + } 691 + ret = gunzip(&strm, *argv, outname, test); 692 + if (outname != NULL) free(outname); 693 + if (ret) break; 694 + } while (argv++, --argc); 695 + else 696 + ret = gunzip(&strm, NULL, NULL, test); 697 + 698 + /* clean up */ 699 + inflateBackEnd(&strm); 700 + return ret; 701 +}
Added compat/zlib/examples/gzappend.c.
1 +/* gzappend -- command to append to a gzip file 2 + 3 + Copyright (C) 2003 Mark Adler, all rights reserved 4 + version 1.1, 4 Nov 2003 5 + 6 + This software is provided 'as-is', without any express or implied 7 + warranty. In no event will the author be held liable for any damages 8 + arising from the use of this software. 9 + 10 + Permission is granted to anyone to use this software for any purpose, 11 + including commercial applications, and to alter it and redistribute it 12 + freely, subject to the following restrictions: 13 + 14 + 1. The origin of this software must not be misrepresented; you must not 15 + claim that you wrote the original software. If you use this software 16 + in a product, an acknowledgment in the product documentation would be 17 + appreciated but is not required. 18 + 2. Altered source versions must be plainly marked as such, and must not be 19 + misrepresented as being the original software. 20 + 3. This notice may not be removed or altered from any source distribution. 21 + 22 + Mark Adler madler@alumni.caltech.edu 23 + */ 24 + 25 +/* 26 + * Change history: 27 + * 28 + * 1.0 19 Oct 2003 - First version 29 + * 1.1 4 Nov 2003 - Expand and clarify some comments and notes 30 + * - Add version and copyright to help 31 + * - Send help to stdout instead of stderr 32 + * - Add some preemptive typecasts 33 + * - Add L to constants in lseek() calls 34 + * - Remove some debugging information in error messages 35 + * - Use new data_type definition for zlib 1.2.1 36 + * - Simplfy and unify file operations 37 + * - Finish off gzip file in gztack() 38 + * - Use deflatePrime() instead of adding empty blocks 39 + * - Keep gzip file clean on appended file read errors 40 + * - Use in-place rotate instead of auxiliary buffer 41 + * (Why you ask? Because it was fun to write!) 42 + */ 43 + 44 +/* 45 + gzappend takes a gzip file and appends to it, compressing files from the 46 + command line or data from stdin. The gzip file is written to directly, to 47 + avoid copying that file, in case it's large. Note that this results in the 48 + unfriendly behavior that if gzappend fails, the gzip file is corrupted. 49 + 50 + This program was written to illustrate the use of the new Z_BLOCK option of 51 + zlib 1.2.x's inflate() function. This option returns from inflate() at each 52 + block boundary to facilitate locating and modifying the last block bit at 53 + the start of the final deflate block. Also whether using Z_BLOCK or not, 54 + another required feature of zlib 1.2.x is that inflate() now provides the 55 + number of unusued bits in the last input byte used. gzappend will not work 56 + with versions of zlib earlier than 1.2.1. 57 + 58 + gzappend first decompresses the gzip file internally, discarding all but 59 + the last 32K of uncompressed data, and noting the location of the last block 60 + bit and the number of unused bits in the last byte of the compressed data. 61 + The gzip trailer containing the CRC-32 and length of the uncompressed data 62 + is verified. This trailer will be later overwritten. 63 + 64 + Then the last block bit is cleared by seeking back in the file and rewriting 65 + the byte that contains it. Seeking forward, the last byte of the compressed 66 + data is saved along with the number of unused bits to initialize deflate. 67 + 68 + A deflate process is initialized, using the last 32K of the uncompressed 69 + data from the gzip file to initialize the dictionary. If the total 70 + uncompressed data was less than 32K, then all of it is used to initialize 71 + the dictionary. The deflate output bit buffer is also initialized with the 72 + last bits from the original deflate stream. From here on, the data to 73 + append is simply compressed using deflate, and written to the gzip file. 74 + When that is complete, the new CRC-32 and uncompressed length are written 75 + as the trailer of the gzip file. 76 + */ 77 + 78 +#include <stdio.h> 79 +#include <stdlib.h> 80 +#include <string.h> 81 +#include <fcntl.h> 82 +#include <unistd.h> 83 +#include "zlib.h" 84 + 85 +#define local static 86 +#define LGCHUNK 14 87 +#define CHUNK (1U << LGCHUNK) 88 +#define DSIZE 32768U 89 + 90 +/* print an error message and terminate with extreme prejudice */ 91 +local void bye(char *msg1, char *msg2) 92 +{ 93 + fprintf(stderr, "gzappend error: %s%s\n", msg1, msg2); 94 + exit(1); 95 +} 96 + 97 +/* return the greatest common divisor of a and b using Euclid's algorithm, 98 + modified to be fast when one argument much greater than the other, and 99 + coded to avoid unnecessary swapping */ 100 +local unsigned gcd(unsigned a, unsigned b) 101 +{ 102 + unsigned c; 103 + 104 + while (a && b) 105 + if (a > b) { 106 + c = b; 107 + while (a - c >= c) 108 + c <<= 1; 109 + a -= c; 110 + } 111 + else { 112 + c = a; 113 + while (b - c >= c) 114 + c <<= 1; 115 + b -= c; 116 + } 117 + return a + b; 118 +} 119 + 120 +/* rotate list[0..len-1] left by rot positions, in place */ 121 +local void rotate(unsigned char *list, unsigned len, unsigned rot) 122 +{ 123 + unsigned char tmp; 124 + unsigned cycles; 125 + unsigned char *start, *last, *to, *from; 126 + 127 + /* normalize rot and handle degenerate cases */ 128 + if (len < 2) return; 129 + if (rot >= len) rot %= len; 130 + if (rot == 0) return; 131 + 132 + /* pointer to last entry in list */ 133 + last = list + (len - 1); 134 + 135 + /* do simple left shift by one */ 136 + if (rot == 1) { 137 + tmp = *list; 138 + memcpy(list, list + 1, len - 1); 139 + *last = tmp; 140 + return; 141 + } 142 + 143 + /* do simple right shift by one */ 144 + if (rot == len - 1) { 145 + tmp = *last; 146 + memmove(list + 1, list, len - 1); 147 + *list = tmp; 148 + return; 149 + } 150 + 151 + /* otherwise do rotate as a set of cycles in place */ 152 + cycles = gcd(len, rot); /* number of cycles */ 153 + do { 154 + start = from = list + cycles; /* start index is arbitrary */ 155 + tmp = *from; /* save entry to be overwritten */ 156 + for (;;) { 157 + to = from; /* next step in cycle */ 158 + from += rot; /* go right rot positions */ 159 + if (from > last) from -= len; /* (pointer better not wrap) */ 160 + if (from == start) break; /* all but one shifted */ 161 + *to = *from; /* shift left */ 162 + } 163 + *to = tmp; /* complete the circle */ 164 + } while (--cycles); 165 +} 166 + 167 +/* structure for gzip file read operations */ 168 +typedef struct { 169 + int fd; /* file descriptor */ 170 + int size; /* 1 << size is bytes in buf */ 171 + unsigned left; /* bytes available at next */ 172 + unsigned char *buf; /* buffer */ 173 + unsigned char *next; /* next byte in buffer */ 174 + char *name; /* file name for error messages */ 175 +} file; 176 + 177 +/* reload buffer */ 178 +local int readin(file *in) 179 +{ 180 + int len; 181 + 182 + len = read(in->fd, in->buf, 1 << in->size); 183 + if (len == -1) bye("error reading ", in->name); 184 + in->left = (unsigned)len; 185 + in->next = in->buf; 186 + return len; 187 +} 188 + 189 +/* read from file in, exit if end-of-file */ 190 +local int readmore(file *in) 191 +{ 192 + if (readin(in) == 0) bye("unexpected end of ", in->name); 193 + return 0; 194 +} 195 + 196 +#define read1(in) (in->left == 0 ? readmore(in) : 0, \ 197 + in->left--, *(in->next)++) 198 + 199 +/* skip over n bytes of in */ 200 +local void skip(file *in, unsigned n) 201 +{ 202 + unsigned bypass; 203 + 204 + if (n > in->left) { 205 + n -= in->left; 206 + bypass = n & ~((1U << in->size) - 1); 207 + if (bypass) { 208 + if (lseek(in->fd, (off_t)bypass, SEEK_CUR) == -1) 209 + bye("seeking ", in->name); 210 + n -= bypass; 211 + } 212 + readmore(in); 213 + if (n > in->left) 214 + bye("unexpected end of ", in->name); 215 + } 216 + in->left -= n; 217 + in->next += n; 218 +} 219 + 220 +/* read a four-byte unsigned integer, little-endian, from in */ 221 +unsigned long read4(file *in) 222 +{ 223 + unsigned long val; 224 + 225 + val = read1(in); 226 + val += (unsigned)read1(in) << 8; 227 + val += (unsigned long)read1(in) << 16; 228 + val += (unsigned long)read1(in) << 24; 229 + return val; 230 +} 231 + 232 +/* skip over gzip header */ 233 +local void gzheader(file *in) 234 +{ 235 + int flags; 236 + unsigned n; 237 + 238 + if (read1(in) != 31 || read1(in) != 139) bye(in->name, " not a gzip file"); 239 + if (read1(in) != 8) bye("unknown compression method in", in->name); 240 + flags = read1(in); 241 + if (flags & 0xe0) bye("unknown header flags set in", in->name); 242 + skip(in, 6); 243 + if (flags & 4) { 244 + n = read1(in); 245 + n += (unsigned)(read1(in)) << 8; 246 + skip(in, n); 247 + } 248 + if (flags & 8) while (read1(in) != 0) ; 249 + if (flags & 16) while (read1(in) != 0) ; 250 + if (flags & 2) skip(in, 2); 251 +} 252 + 253 +/* decompress gzip file "name", return strm with a deflate stream ready to 254 + continue compression of the data in the gzip file, and return a file 255 + descriptor pointing to where to write the compressed data -- the deflate 256 + stream is initialized to compress using level "level" */ 257 +local int gzscan(char *name, z_stream *strm, int level) 258 +{ 259 + int ret, lastbit, left, full; 260 + unsigned have; 261 + unsigned long crc, tot; 262 + unsigned char *window; 263 + off_t lastoff, end; 264 + file gz; 265 + 266 + /* open gzip file */ 267 + gz.name = name; 268 + gz.fd = open(name, O_RDWR, 0); 269 + if (gz.fd == -1) bye("cannot open ", name); 270 + gz.buf = malloc(CHUNK); 271 + if (gz.buf == NULL) bye("out of memory", ""); 272 + gz.size = LGCHUNK; 273 + gz.left = 0; 274 + 275 + /* skip gzip header */ 276 + gzheader(&gz); 277 + 278 + /* prepare to decompress */ 279 + window = malloc(DSIZE); 280 + if (window == NULL) bye("out of memory", ""); 281 + strm->zalloc = Z_NULL; 282 + strm->zfree = Z_NULL; 283 + strm->opaque = Z_NULL; 284 + ret = inflateInit2(strm, -15); 285 + if (ret != Z_OK) bye("out of memory", " or library mismatch"); 286 + 287 + /* decompress the deflate stream, saving append information */ 288 + lastbit = 0; 289 + lastoff = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; 290 + left = 0; 291 + strm->avail_in = gz.left; 292 + strm->next_in = gz.next; 293 + crc = crc32(0L, Z_NULL, 0); 294 + have = full = 0; 295 + do { 296 + /* if needed, get more input */ 297 + if (strm->avail_in == 0) { 298 + readmore(&gz); 299 + strm->avail_in = gz.left; 300 + strm->next_in = gz.next; 301 + } 302 + 303 + /* set up output to next available section of sliding window */ 304 + strm->avail_out = DSIZE - have; 305 + strm->next_out = window + have; 306 + 307 + /* inflate and check for errors */ 308 + ret = inflate(strm, Z_BLOCK); 309 + if (ret == Z_STREAM_ERROR) bye("internal stream error!", ""); 310 + if (ret == Z_MEM_ERROR) bye("out of memory", ""); 311 + if (ret == Z_DATA_ERROR) 312 + bye("invalid compressed data--format violated in", name); 313 + 314 + /* update crc and sliding window pointer */ 315 + crc = crc32(crc, window + have, DSIZE - have - strm->avail_out); 316 + if (strm->avail_out) 317 + have = DSIZE - strm->avail_out; 318 + else { 319 + have = 0; 320 + full = 1; 321 + } 322 + 323 + /* process end of block */ 324 + if (strm->data_type & 128) { 325 + if (strm->data_type & 64) 326 + left = strm->data_type & 0x1f; 327 + else { 328 + lastbit = strm->data_type & 0x1f; 329 + lastoff = lseek(gz.fd, 0L, SEEK_CUR) - strm->avail_in; 330 + } 331 + } 332 + } while (ret != Z_STREAM_END); 333 + inflateEnd(strm); 334 + gz.left = strm->avail_in; 335 + gz.next = strm->next_in; 336 + 337 + /* save the location of the end of the compressed data */ 338 + end = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; 339 + 340 + /* check gzip trailer and save total for deflate */ 341 + if (crc != read4(&gz)) 342 + bye("invalid compressed data--crc mismatch in ", name); 343 + tot = strm->total_out; 344 + if ((tot & 0xffffffffUL) != read4(&gz)) 345 + bye("invalid compressed data--length mismatch in", name); 346 + 347 + /* if not at end of file, warn */ 348 + if (gz.left || readin(&gz)) 349 + fprintf(stderr, 350 + "gzappend warning: junk at end of gzip file overwritten\n"); 351 + 352 + /* clear last block bit */ 353 + lseek(gz.fd, lastoff - (lastbit != 0), SEEK_SET); 354 + if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); 355 + *gz.buf = (unsigned char)(*gz.buf ^ (1 << ((8 - lastbit) & 7))); 356 + lseek(gz.fd, -1L, SEEK_CUR); 357 + if (write(gz.fd, gz.buf, 1) != 1) bye("writing after seek to ", name); 358 + 359 + /* if window wrapped, build dictionary from window by rotating */ 360 + if (full) { 361 + rotate(window, DSIZE, have); 362 + have = DSIZE; 363 + } 364 + 365 + /* set up deflate stream with window, crc, total_in, and leftover bits */ 366 + ret = deflateInit2(strm, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); 367 + if (ret != Z_OK) bye("out of memory", ""); 368 + deflateSetDictionary(strm, window, have); 369 + strm->adler = crc; 370 + strm->total_in = tot; 371 + if (left) { 372 + lseek(gz.fd, --end, SEEK_SET); 373 + if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); 374 + deflatePrime(strm, 8 - left, *gz.buf); 375 + } 376 + lseek(gz.fd, end, SEEK_SET); 377 + 378 + /* clean up and return */ 379 + free(window); 380 + free(gz.buf); 381 + return gz.fd; 382 +} 383 + 384 +/* append file "name" to gzip file gd using deflate stream strm -- if last 385 + is true, then finish off the deflate stream at the end */ 386 +local void gztack(char *name, int gd, z_stream *strm, int last) 387 +{ 388 + int fd, len, ret; 389 + unsigned left; 390 + unsigned char *in, *out; 391 + 392 + /* open file to compress and append */ 393 + fd = 0; 394 + if (name != NULL) { 395 + fd = open(name, O_RDONLY, 0); 396 + if (fd == -1) 397 + fprintf(stderr, "gzappend warning: %s not found, skipping ...\n", 398 + name); 399 + } 400 + 401 + /* allocate buffers */ 402 + in = fd == -1 ? NULL : malloc(CHUNK); 403 + out = malloc(CHUNK); 404 + if (out == NULL) bye("out of memory", ""); 405 + 406 + /* compress input file and append to gzip file */ 407 + do { 408 + /* get more input */ 409 + len = fd == -1 ? 0 : read(fd, in, CHUNK); 410 + if (len == -1) { 411 + fprintf(stderr, 412 + "gzappend warning: error reading %s, skipping rest ...\n", 413 + name); 414 + len = 0; 415 + } 416 + strm->avail_in = (unsigned)len; 417 + strm->next_in = in; 418 + if (len) strm->adler = crc32(strm->adler, in, (unsigned)len); 419 + 420 + /* compress and write all available output */ 421 + do { 422 + strm->avail_out = CHUNK; 423 + strm->next_out = out; 424 + ret = deflate(strm, last && len == 0 ? Z_FINISH : Z_NO_FLUSH); 425 + left = CHUNK - strm->avail_out; 426 + while (left) { 427 + len = write(gd, out + CHUNK - strm->avail_out - left, left); 428 + if (len == -1) bye("writing gzip file", ""); 429 + left -= (unsigned)len; 430 + } 431 + } while (strm->avail_out == 0 && ret != Z_STREAM_END); 432 + } while (len != 0); 433 + 434 + /* write trailer after last entry */ 435 + if (last) { 436 + deflateEnd(strm); 437 + out[0] = (unsigned char)(strm->adler); 438 + out[1] = (unsigned char)(strm->adler >> 8); 439 + out[2] = (unsigned char)(strm->adler >> 16); 440 + out[3] = (unsigned char)(strm->adler >> 24); 441 + out[4] = (unsigned char)(strm->total_in); 442 + out[5] = (unsigned char)(strm->total_in >> 8); 443 + out[6] = (unsigned char)(strm->total_in >> 16); 444 + out[7] = (unsigned char)(strm->total_in >> 24); 445 + len = 8; 446 + do { 447 + ret = write(gd, out + 8 - len, len); 448 + if (ret == -1) bye("writing gzip file", ""); 449 + len -= ret; 450 + } while (len); 451 + close(gd); 452 + } 453 + 454 + /* clean up and return */ 455 + free(out); 456 + if (in != NULL) free(in); 457 + if (fd > 0) close(fd); 458 +} 459 + 460 +/* process the compression level option if present, scan the gzip file, and 461 + append the specified files, or append the data from stdin if no other file 462 + names are provided on the command line -- the gzip file must be writable 463 + and seekable */ 464 +int main(int argc, char **argv) 465 +{ 466 + int gd, level; 467 + z_stream strm; 468 + 469 + /* ignore command name */ 470 + argv++; 471 + 472 + /* provide usage if no arguments */ 473 + if (*argv == NULL) { 474 + printf("gzappend 1.1 (4 Nov 2003) Copyright (C) 2003 Mark Adler\n"); 475 + printf( 476 + "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n"); 477 + return 0; 478 + } 479 + 480 + /* set compression level */ 481 + level = Z_DEFAULT_COMPRESSION; 482 + if (argv[0][0] == '-') { 483 + if (argv[0][1] < '0' || argv[0][1] > '9' || argv[0][2] != 0) 484 + bye("invalid compression level", ""); 485 + level = argv[0][1] - '0'; 486 + if (*++argv == NULL) bye("no gzip file name after options", ""); 487 + } 488 + 489 + /* prepare to append to gzip file */ 490 + gd = gzscan(*argv++, &strm, level); 491 + 492 + /* append files on command line, or from stdin if none */ 493 + if (*argv == NULL) 494 + gztack(NULL, gd, &strm, 1); 495 + else 496 + do { 497 + gztack(*argv, gd, &strm, argv[1] == NULL); 498 + } while (*++argv != NULL); 499 + return 0; 500 +}
Added compat/zlib/examples/gzjoin.c.
1 +/* gzjoin -- command to join gzip files into one gzip file 2 + 3 + Copyright (C) 2004 Mark Adler, all rights reserved 4 + version 1.0, 11 Dec 2004 5 + 6 + This software is provided 'as-is', without any express or implied 7 + warranty. In no event will the author be held liable for any damages 8 + arising from the use of this software. 9 + 10 + Permission is granted to anyone to use this software for any purpose, 11 + including commercial applications, and to alter it and redistribute it 12 + freely, subject to the following restrictions: 13 + 14 + 1. The origin of this software must not be misrepresented; you must not 15 + claim that you wrote the original software. If you use this software 16 + in a product, an acknowledgment in the product documentation would be 17 + appreciated but is not required. 18 + 2. Altered source versions must be plainly marked as such, and must not be 19 + misrepresented as being the original software. 20 + 3. This notice may not be removed or altered from any source distribution. 21 + 22 + Mark Adler madler@alumni.caltech.edu 23 + */ 24 + 25 +/* 26 + * Change history: 27 + * 28 + * 1.0 11 Dec 2004 - First version 29 + * 1.1 12 Jun 2005 - Changed ssize_t to long for portability 30 + */ 31 + 32 +/* 33 + gzjoin takes one or more gzip files on the command line and writes out a 34 + single gzip file that will uncompress to the concatenation of the 35 + uncompressed data from the individual gzip files. gzjoin does this without 36 + having to recompress any of the data and without having to calculate a new 37 + crc32 for the concatenated uncompressed data. gzjoin does however have to 38 + decompress all of the input data in order to find the bits in the compressed 39 + data that need to be modified to concatenate the streams. 40 + 41 + gzjoin does not do an integrity check on the input gzip files other than 42 + checking the gzip header and decompressing the compressed data. They are 43 + otherwise assumed to be complete and correct. 44 + 45 + Each joint between gzip files removes at least 18 bytes of previous trailer 46 + and subsequent header, and inserts an average of about three bytes to the 47 + compressed data in order to connect the streams. The output gzip file 48 + has a minimal ten-byte gzip header with no file name or modification time. 49 + 50 + This program was written to illustrate the use of the Z_BLOCK option of 51 + inflate() and the crc32_combine() function. gzjoin will not compile with 52 + versions of zlib earlier than 1.2.3. 53 + */ 54 + 55 +#include <stdio.h> /* fputs(), fprintf(), fwrite(), putc() */ 56 +#include <stdlib.h> /* exit(), malloc(), free() */ 57 +#include <fcntl.h> /* open() */ 58 +#include <unistd.h> /* close(), read(), lseek() */ 59 +#include "zlib.h" 60 + /* crc32(), crc32_combine(), inflateInit2(), inflate(), inflateEnd() */ 61 + 62 +#define local static 63 + 64 +/* exit with an error (return a value to allow use in an expression) */ 65 +local int bail(char *why1, char *why2) 66 +{ 67 + fprintf(stderr, "gzjoin error: %s%s, output incomplete\n", why1, why2); 68 + exit(1); 69 + return 0; 70 +} 71 + 72 +/* -- simple buffered file input with access to the buffer -- */ 73 + 74 +#define CHUNK 32768 /* must be a power of two and fit in unsigned */ 75 + 76 +/* bin buffered input file type */ 77 +typedef struct { 78 + char *name; /* name of file for error messages */ 79 + int fd; /* file descriptor */ 80 + unsigned left; /* bytes remaining at next */ 81 + unsigned char *next; /* next byte to read */ 82 + unsigned char *buf; /* allocated buffer of length CHUNK */ 83 +} bin; 84 + 85 +/* close a buffered file and free allocated memory */ 86 +local void bclose(bin *in) 87 +{ 88 + if (in != NULL) { 89 + if (in->fd != -1) 90 + close(in->fd); 91 + if (in->buf != NULL) 92 + free(in->buf); 93 + free(in); 94 + } 95 +} 96 + 97 +/* open a buffered file for input, return a pointer to type bin, or NULL on 98 + failure */ 99 +local bin *bopen(char *name) 100 +{ 101 + bin *in; 102 + 103 + in = malloc(sizeof(bin)); 104 + if (in == NULL) 105 + return NULL; 106 + in->buf = malloc(CHUNK); 107 + in->fd = open(name, O_RDONLY, 0); 108 + if (in->buf == NULL || in->fd == -1) { 109 + bclose(in); 110 + return NULL; 111 + } 112 + in->left = 0; 113 + in->next = in->buf; 114 + in->name = name; 115 + return in; 116 +} 117 + 118 +/* load buffer from file, return -1 on read error, 0 or 1 on success, with 119 + 1 indicating that end-of-file was reached */ 120 +local int bload(bin *in) 121 +{ 122 + long len; 123 + 124 + if (in == NULL) 125 + return -1; 126 + if (in->left != 0) 127 + return 0; 128 + in->next = in->buf; 129 + do { 130 + len = (long)read(in->fd, in->buf + in->left, CHUNK - in->left); 131 + if (len < 0) 132 + return -1; 133 + in->left += (unsigned)len; 134 + } while (len != 0 && in->left < CHUNK); 135 + return len == 0 ? 1 : 0; 136 +} 137 + 138 +/* get a byte from the file, bail if end of file */ 139 +#define bget(in) (in->left ? 0 : bload(in), \ 140 + in->left ? (in->left--, *(in->next)++) : \ 141 + bail("unexpected end of file on ", in->name)) 142 + 143 +/* get a four-byte little-endian unsigned integer from file */ 144 +local unsigned long bget4(bin *in) 145 +{ 146 + unsigned long val; 147 + 148 + val = bget(in); 149 + val += (unsigned long)(bget(in)) << 8; 150 + val += (unsigned long)(bget(in)) << 16; 151 + val += (unsigned long)(bget(in)) << 24; 152 + return val; 153 +} 154 + 155 +/* skip bytes in file */ 156 +local void bskip(bin *in, unsigned skip) 157 +{ 158 + /* check pointer */ 159 + if (in == NULL) 160 + return; 161 + 162 + /* easy case -- skip bytes in buffer */ 163 + if (skip <= in->left) { 164 + in->left -= skip; 165 + in->next += skip; 166 + return; 167 + } 168 + 169 + /* skip what's in buffer, discard buffer contents */ 170 + skip -= in->left; 171 + in->left = 0; 172 + 173 + /* seek past multiples of CHUNK bytes */ 174 + if (skip > CHUNK) { 175 + unsigned left; 176 + 177 + left = skip & (CHUNK - 1); 178 + if (left == 0) { 179 + /* exact number of chunks: seek all the way minus one byte to check 180 + for end-of-file with a read */ 181 + lseek(in->fd, skip - 1, SEEK_CUR); 182 + if (read(in->fd, in->buf, 1) != 1) 183 + bail("unexpected end of file on ", in->name); 184 + return; 185 + } 186 + 187 + /* skip the integral chunks, update skip with remainder */ 188 + lseek(in->fd, skip - left, SEEK_CUR); 189 + skip = left; 190 + } 191 + 192 + /* read more input and skip remainder */ 193 + bload(in); 194 + if (skip > in->left) 195 + bail("unexpected end of file on ", in->name); 196 + in->left -= skip; 197 + in->next += skip; 198 +} 199 + 200 +/* -- end of buffered input functions -- */ 201 + 202 +/* skip the gzip header from file in */ 203 +local void gzhead(bin *in) 204 +{ 205 + int flags; 206 + 207 + /* verify gzip magic header and compression method */ 208 + if (bget(in) != 0x1f || bget(in) != 0x8b || bget(in) != 8) 209 + bail(in->name, " is not a valid gzip file"); 210 + 211 + /* get and verify flags */ 212 + flags = bget(in); 213 + if ((flags & 0xe0) != 0) 214 + bail("unknown reserved bits set in ", in->name); 215 + 216 + /* skip modification time, extra flags, and os */ 217 + bskip(in, 6); 218 + 219 + /* skip extra field if present */ 220 + if (flags & 4) { 221 + unsigned len; 222 + 223 + len = bget(in); 224 + len += (unsigned)(bget(in)) << 8; 225 + bskip(in, len); 226 + } 227 + 228 + /* skip file name if present */ 229 + if (flags & 8) 230 + while (bget(in) != 0) 231 + ; 232 + 233 + /* skip comment if present */ 234 + if (flags & 16) 235 + while (bget(in) != 0) 236 + ; 237 + 238 + /* skip header crc if present */ 239 + if (flags & 2) 240 + bskip(in, 2); 241 +} 242 + 243 +/* write a four-byte little-endian unsigned integer to out */ 244 +local void put4(unsigned long val, FILE *out) 245 +{ 246 + putc(val & 0xff, out); 247 + putc((val >> 8) & 0xff, out); 248 + putc((val >> 16) & 0xff, out); 249 + putc((val >> 24) & 0xff, out); 250 +} 251 + 252 +/* Load up zlib stream from buffered input, bail if end of file */ 253 +local void zpull(z_streamp strm, bin *in) 254 +{ 255 + if (in->left == 0) 256 + bload(in); 257 + if (in->left == 0) 258 + bail("unexpected end of file on ", in->name); 259 + strm->avail_in = in->left; 260 + strm->next_in = in->next; 261 +} 262 + 263 +/* Write header for gzip file to out and initialize trailer. */ 264 +local void gzinit(unsigned long *crc, unsigned long *tot, FILE *out) 265 +{ 266 + fwrite("\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out); 267 + *crc = crc32(0L, Z_NULL, 0); 268 + *tot = 0; 269 +} 270 + 271 +/* Copy the compressed data from name, zeroing the last block bit of the last 272 + block if clr is true, and adding empty blocks as needed to get to a byte 273 + boundary. If clr is false, then the last block becomes the last block of 274 + the output, and the gzip trailer is written. crc and tot maintains the 275 + crc and length (modulo 2^32) of the output for the trailer. The resulting 276 + gzip file is written to out. gzinit() must be called before the first call 277 + of gzcopy() to write the gzip header and to initialize crc and tot. */ 278 +local void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot, 279 + FILE *out) 280 +{ 281 + int ret; /* return value from zlib functions */ 282 + int pos; /* where the "last block" bit is in byte */ 283 + int last; /* true if processing the last block */ 284 + bin *in; /* buffered input file */ 285 + unsigned char *start; /* start of compressed data in buffer */ 286 + unsigned char *junk; /* buffer for uncompressed data -- discarded */ 287 + z_off_t len; /* length of uncompressed data (support > 4 GB) */ 288 + z_stream strm; /* zlib inflate stream */ 289 + 290 + /* open gzip file and skip header */ 291 + in = bopen(name); 292 + if (in == NULL) 293 + bail("could not open ", name); 294 + gzhead(in); 295 + 296 + /* allocate buffer for uncompressed data and initialize raw inflate 297 + stream */ 298 + junk = malloc(CHUNK); 299 + strm.zalloc = Z_NULL; 300 + strm.zfree = Z_NULL; 301 + strm.opaque = Z_NULL; 302 + strm.avail_in = 0; 303 + strm.next_in = Z_NULL; 304 + ret = inflateInit2(&strm, -15); 305 + if (junk == NULL || ret != Z_OK) 306 + bail("out of memory", ""); 307 + 308 + /* inflate and copy compressed data, clear last-block bit if requested */ 309 + len = 0; 310 + zpull(&strm, in); 311 + start = strm.next_in; 312 + last = start[0] & 1; 313 + if (last && clr) 314 + start[0] &= ~1; 315 + strm.avail_out = 0; 316 + for (;;) { 317 + /* if input used and output done, write used input and get more */ 318 + if (strm.avail_in == 0 && strm.avail_out != 0) { 319 + fwrite(start, 1, strm.next_in - start, out); 320 + start = in->buf; 321 + in->left = 0; 322 + zpull(&strm, in); 323 + } 324 + 325 + /* decompress -- return early when end-of-block reached */ 326 + strm.avail_out = CHUNK; 327 + strm.next_out = junk; 328 + ret = inflate(&strm, Z_BLOCK); 329 + switch (ret) { 330 + case Z_MEM_ERROR: 331 + bail("out of memory", ""); 332 + case Z_DATA_ERROR: 333 + bail("invalid compressed data in ", in->name); 334 + } 335 + 336 + /* update length of uncompressed data */ 337 + len += CHUNK - strm.avail_out; 338 + 339 + /* check for block boundary (only get this when block copied out) */ 340 + if (strm.data_type & 128) { 341 + /* if that was the last block, then done */ 342 + if (last) 343 + break; 344 + 345 + /* number of unused bits in last byte */ 346 + pos = strm.data_type & 7; 347 + 348 + /* find the next last-block bit */ 349 + if (pos != 0) { 350 + /* next last-block bit is in last used byte */ 351 + pos = 0x100 >> pos; 352 + last = strm.next_in[-1] & pos; 353 + if (last && clr) 354 + strm.next_in[-1] &= ~pos; 355 + } 356 + else { 357 + /* next last-block bit is in next unused byte */ 358 + if (strm.avail_in == 0) { 359 + /* don't have that byte yet -- get it */ 360 + fwrite(start, 1, strm.next_in - start, out); 361 + start = in->buf; 362 + in->left = 0; 363 + zpull(&strm, in); 364 + } 365 + last = strm.next_in[0] & 1; 366 + if (last && clr) 367 + strm.next_in[0] &= ~1; 368 + } 369 + } 370 + } 371 + 372 + /* update buffer with unused input */ 373 + in->left = strm.avail_in; 374 + in->next = strm.next_in; 375 + 376 + /* copy used input, write empty blocks to get to byte boundary */ 377 + pos = strm.data_type & 7; 378 + fwrite(start, 1, in->next - start - 1, out); 379 + last = in->next[-1]; 380 + if (pos == 0 || !clr) 381 + /* already at byte boundary, or last file: write last byte */ 382 + putc(last, out); 383 + else { 384 + /* append empty blocks to last byte */ 385 + last &= ((0x100 >> pos) - 1); /* assure unused bits are zero */ 386 + if (pos & 1) { 387 + /* odd -- append an empty stored block */ 388 + putc(last, out); 389 + if (pos == 1) 390 + putc(0, out); /* two more bits in block header */ 391 + fwrite("\0\0\xff\xff", 1, 4, out); 392 + } 393 + else { 394 + /* even -- append 1, 2, or 3 empty fixed blocks */ 395 + switch (pos) { 396 + case 6: 397 + putc(last | 8, out); 398 + last = 0; 399 + case 4: 400 + putc(last | 0x20, out); 401 + last = 0; 402 + case 2: 403 + putc(last | 0x80, out); 404 + putc(0, out); 405 + } 406 + } 407 + } 408 + 409 + /* update crc and tot */ 410 + *crc = crc32_combine(*crc, bget4(in), len); 411 + *tot += (unsigned long)len; 412 + 413 + /* clean up */ 414 + inflateEnd(&strm); 415 + free(junk); 416 + bclose(in); 417 + 418 + /* write trailer if this is the last gzip file */ 419 + if (!clr) { 420 + put4(*crc, out); 421 + put4(*tot, out); 422 + } 423 +} 424 + 425 +/* join the gzip files on the command line, write result to stdout */ 426 +int main(int argc, char **argv) 427 +{ 428 + unsigned long crc, tot; /* running crc and total uncompressed length */ 429 + 430 + /* skip command name */ 431 + argc--; 432 + argv++; 433 + 434 + /* show usage if no arguments */ 435 + if (argc == 0) { 436 + fputs("gzjoin usage: gzjoin f1.gz [f2.gz [f3.gz ...]] > fjoin.gz\n", 437 + stderr); 438 + return 0; 439 + } 440 + 441 + /* join gzip files on command line and write to stdout */ 442 + gzinit(&crc, &tot, stdout); 443 + while (argc--) 444 + gzcopy(*argv++, argc, &crc, &tot, stdout); 445 + 446 + /* done */ 447 + return 0; 448 +}
Added compat/zlib/examples/gzlog.c.
1 +/* 2 + * gzlog.c 3 + * Copyright (C) 2004, 2008 Mark Adler, all rights reserved 4 + * For conditions of distribution and use, see copyright notice in gzlog.h 5 + * version 2.0, 25 Apr 2008 6 + */ 7 + 8 +/* 9 + gzlog provides a mechanism for frequently appending short strings to a gzip 10 + file that is efficient both in execution time and compression ratio. The 11 + strategy is to write the short strings in an uncompressed form to the end of 12 + the gzip file, only compressing when the amount of uncompressed data has 13 + reached a given threshold. 14 + 15 + gzlog also provides protection against interruptions in the process due to 16 + system crashes. The status of the operation is recorded in an extra field 17 + in the gzip file, and is only updated once the gzip file is brought to a 18 + valid state. The last data to be appended or compressed is saved in an 19 + auxiliary file, so that if the operation is interrupted, it can be completed 20 + the next time an append operation is attempted. 21 + 22 + gzlog maintains another auxiliary file with the last 32K of data from the 23 + compressed portion, which is preloaded for the compression of the subsequent 24 + data. This minimizes the impact to the compression ratio of appending. 25 + */ 26 + 27 +/* 28 + Operations Concept: 29 + 30 + Files (log name "foo"): 31 + foo.gz -- gzip file with the complete log 32 + foo.add -- last message to append or last data to compress 33 + foo.dict -- dictionary of the last 32K of data for next compression 34 + foo.temp -- temporary dictionary file for compression after this one 35 + foo.lock -- lock file for reading and writing the other files 36 + foo.repairs -- log file for log file recovery operations (not compressed) 37 + 38 + gzip file structure: 39 + - fixed-length (no file name) header with extra field (see below) 40 + - compressed data ending initially with empty stored block 41 + - uncompressed data filling out originally empty stored block and 42 + subsequent stored blocks as needed (16K max each) 43 + - gzip trailer 44 + - no junk at end (no other gzip streams) 45 + 46 + When appending data, the information in the first three items above plus the 47 + foo.add file are sufficient to recover an interrupted append operation. The 48 + extra field has the necessary information to restore the start of the last 49 + stored block and determine where to append the data in the foo.add file, as 50 + well as the crc and length of the gzip data before the append operation. 51 + 52 + The foo.add file is created before the gzip file is marked for append, and 53 + deleted after the gzip file is marked as complete. So if the append 54 + operation is interrupted, the data to add will still be there. If due to 55 + some external force, the foo.add file gets deleted between when the append 56 + operation was interrupted and when recovery is attempted, the gzip file will 57 + still be restored, but without the appended data. 58 + 59 + When compressing data, the information in the first two items above plus the 60 + foo.add file are sufficient to recover an interrupted compress operation. 61 + The extra field has the necessary information to find the end of the 62 + compressed data, and contains both the crc and length of just the compressed 63 + data and of the complete set of data including the contents of the foo.add 64 + file. 65 + 66 + Again, the foo.add file is maintained during the compress operation in case 67 + of an interruption. If in the unlikely event the foo.add file with the data 68 + to be compressed is missing due to some external force, a gzip file with 69 + just the previous compressed data will be reconstructed. In this case, all 70 + of the data that was to be compressed is lost (approximately one megabyte). 71 + This will not occur if all that happened was an interruption of the compress 72 + operation. 73 + 74 + The third state that is marked is the replacement of the old dictionary with 75 + the new dictionary after a compress operation. Once compression is 76 + complete, the gzip file is marked as being in the replace state. This 77 + completes the gzip file, so an interrupt after being so marked does not 78 + result in recompression. Then the dictionary file is replaced, and the gzip 79 + file is marked as completed. This state prevents the possibility of 80 + restarting compression with the wrong dictionary file. 81 + 82 + All three operations are wrapped by a lock/unlock procedure. In order to 83 + gain exclusive access to the log files, first a foo.lock file must be 84 + exclusively created. When all operations are complete, the lock is 85 + released by deleting the foo.lock file. If when attempting to create the 86 + lock file, it already exists and the modify time of the lock file is more 87 + than five minutes old (set by the PATIENCE define below), then the old 88 + lock file is considered stale and deleted, and the exclusive creation of 89 + the lock file is retried. To assure that there are no false assessments 90 + of the staleness of the lock file, the operations periodically touch the 91 + lock file to update the modified date. 92 + 93 + Following is the definition of the extra field with all of the information 94 + required to enable the above append and compress operations and their 95 + recovery if interrupted. Multi-byte values are stored little endian 96 + (consistent with the gzip format). File pointers are eight bytes long. 97 + The crc's and lengths for the gzip trailer are four bytes long. (Note that 98 + the length at the end of a gzip file is used for error checking only, and 99 + for large files is actually the length modulo 2^32.) The stored block 100 + length is two bytes long. The gzip extra field two-byte identification is 101 + "ap" for append. It is assumed that writing the extra field to the file is 102 + an "atomic" operation. That is, either all of the extra field is written 103 + to the file, or none of it is, if the operation is interrupted right at the 104 + point of updating the extra field. This is a reasonable assumption, since 105 + the extra field is within the first 52 bytes of the file, which is smaller 106 + than any expected block size for a mass storage device (usually 512 bytes or 107 + larger). 108 + 109 + Extra field (35 bytes): 110 + - Pointer to first stored block length -- this points to the two-byte length 111 + of the first stored block, which is followed by the two-byte, one's 112 + complement of that length. The stored block length is preceded by the 113 + three-bit header of the stored block, which is the actual start of the 114 + stored block in the deflate format. See the bit offset field below. 115 + - Pointer to the last stored block length. This is the same as above, but 116 + for the last stored block of the uncompressed data in the gzip file. 117 + Initially this is the same as the first stored block length pointer. 118 + When the stored block gets to 16K (see the MAX_STORE define), then a new 119 + stored block as added, at which point the last stored block length pointer 120 + is different from the first stored block length pointer. When they are 121 + different, the first bit of the last stored block header is eight bits, or 122 + one byte back from the block length. 123 + - Compressed data crc and length. This is the crc and length of the data 124 + that is in the compressed portion of the deflate stream. These are used 125 + only in the event that the foo.add file containing the data to compress is 126 + lost after a compress operation is interrupted. 127 + - Total data crc and length. This is the crc and length of all of the data 128 + stored in the gzip file, compressed and uncompressed. It is used to 129 + reconstruct the gzip trailer when compressing, as well as when recovering 130 + interrupted operations. 131 + - Final stored block length. This is used to quickly find where to append, 132 + and allows the restoration of the original final stored block state when 133 + an append operation is interrupted. 134 + - First stored block start as the number of bits back from the final stored 135 + block first length byte. This value is in the range of 3..10, and is 136 + stored as the low three bits of the final byte of the extra field after 137 + subtracting three (0..7). This allows the last-block bit of the stored 138 + block header to be updated when a new stored block is added, for the case 139 + when the first stored block and the last stored block are the same. (When 140 + they are different, the numbers of bits back is known to be eight.) This 141 + also allows for new compressed data to be appended to the old compressed 142 + data in the compress operation, overwriting the previous first stored 143 + block, or for the compressed data to be terminated and a valid gzip file 144 + reconstructed on the off chance that a compression operation was 145 + interrupted and the data to compress in the foo.add file was deleted. 146 + - The operation in process. This is the next two bits in the last byte (the 147 + bits under the mask 0x18). The are interpreted as 0: nothing in process, 148 + 1: append in process, 2: compress in process, 3: replace in process. 149 + - The top three bits of the last byte in the extra field are reserved and 150 + are currently set to zero. 151 + 152 + Main procedure: 153 + - Exclusively create the foo.lock file using the O_CREAT and O_EXCL modes of 154 + the system open() call. If the modify time of an existing lock file is 155 + more than PATIENCE seconds old, then the lock file is deleted and the 156 + exclusive create is retried. 157 + - Load the extra field from the foo.gz file, and see if an operation was in 158 + progress but not completed. If so, apply the recovery procedure below. 159 + - Perform the append procedure with the provided data. 160 + - If the uncompressed data in the foo.gz file is 1MB or more, apply the 161 + compress procedure. 162 + - Delete the foo.lock file. 163 + 164 + Append procedure: 165 + - Put what to append in the foo.add file so that the operation can be 166 + restarted if this procedure is interrupted. 167 + - Mark the foo.gz extra field with the append operation in progress. 168 + + Restore the original last-block bit and stored block length of the last 169 + stored block from the information in the extra field, in case a previous 170 + append operation was interrupted. 171 + - Append the provided data to the last stored block, creating new stored 172 + blocks as needed and updating the stored blocks last-block bits and 173 + lengths. 174 + - Update the crc and length with the new data, and write the gzip trailer. 175 + - Write over the extra field (with a single write operation) with the new 176 + pointers, lengths, and crc's, and mark the gzip file as not in process. 177 + Though there is still a foo.add file, it will be ignored since nothing 178 + is in process. If a foo.add file is leftover from a previously 179 + completed operation, it is truncated when writing new data to it. 180 + - Delete the foo.add file. 181 + 182 + Compress and replace procedures: 183 + - Read all of the uncompressed data in the stored blocks in foo.gz and write 184 + it to foo.add. Also write foo.temp with the last 32K of that data to 185 + provide a dictionary for the next invocation of this procedure. 186 + - Rewrite the extra field marking foo.gz with a compression in process. 187 + * If there is no data provided to compress (due to a missing foo.add file 188 + when recovering), reconstruct and truncate the foo.gz file to contain 189 + only the previous compressed data and proceed to the step after the next 190 + one. Otherwise ... 191 + - Compress the data with the dictionary in foo.dict, and write to the 192 + foo.gz file starting at the bit immediately following the last previously 193 + compressed block. If there is no foo.dict, proceed anyway with the 194 + compression at slightly reduced efficiency. (For the foo.dict file to be 195 + missing requires some external failure beyond simply the interruption of 196 + a compress operation.) During this process, the foo.lock file is 197 + periodically touched to assure that that file is not considered stale by 198 + another process before we're done. The deflation is terminated with a 199 + non-last empty static block (10 bits long), that is then located and 200 + written over by a last-bit-set empty stored block. 201 + - Append the crc and length of the data in the gzip file (previously 202 + calculated during the append operations). 203 + - Write over the extra field with the updated stored block offsets, bits 204 + back, crc's, and lengths, and mark foo.gz as in process for a replacement 205 + of the dictionary. 206 + @ Delete the foo.add file. 207 + - Replace foo.dict with foo.temp. 208 + - Write over the extra field, marking foo.gz as complete. 209 + 210 + Recovery procedure: 211 + - If not a replace recovery, read in the foo.add file, and provide that data 212 + to the appropriate recovery below. If there is no foo.add file, provide 213 + a zero data length to the recovery. In that case, the append recovery 214 + restores the foo.gz to the previous compressed + uncompressed data state. 215 + For the the compress recovery, a missing foo.add file results in foo.gz 216 + being restored to the previous compressed-only data state. 217 + - Append recovery: 218 + - Pick up append at + step above 219 + - Compress recovery: 220 + - Pick up compress at * step above 221 + - Replace recovery: 222 + - Pick up compress at @ step above 223 + - Log the repair with a date stamp in foo.repairs 224 + */ 225 + 226 +#include <sys/types.h> 227 +#include <stdio.h> /* rename, fopen, fprintf, fclose */ 228 +#include <stdlib.h> /* malloc, free */ 229 +#include <string.h> /* strlen, strrchr, strcpy, strncpy, strcmp */ 230 +#include <fcntl.h> /* open */ 231 +#include <unistd.h> /* lseek, read, write, close, unlink, sleep, */ 232 + /* ftruncate, fsync */ 233 +#include <errno.h> /* errno */ 234 +#include <time.h> /* time, ctime */ 235 +#include <sys/stat.h> /* stat */ 236 +#include <sys/time.h> /* utimes */ 237 +#include "zlib.h" /* crc32 */ 238 + 239 +#include "gzlog.h" /* header for external access */ 240 + 241 +#define local static 242 +typedef unsigned int uint; 243 +typedef unsigned long ulong; 244 + 245 +/* Macro for debugging to deterministically force recovery operations */ 246 +#ifdef DEBUG 247 + #include <setjmp.h> /* longjmp */ 248 + jmp_buf gzlog_jump; /* where to go back to */ 249 + int gzlog_bail = 0; /* which point to bail at (1..8) */ 250 + int gzlog_count = -1; /* number of times through to wait */ 251 +# define BAIL(n) do { if (n == gzlog_bail && gzlog_count-- == 0) \ 252 + longjmp(gzlog_jump, gzlog_bail); } while (0) 253 +#else 254 +# define BAIL(n) 255 +#endif 256 + 257 +/* how old the lock file can be in seconds before considering it stale */ 258 +#define PATIENCE 300 259 + 260 +/* maximum stored block size in Kbytes -- must be in 1..63 */ 261 +#define MAX_STORE 16 262 + 263 +/* number of stored Kbytes to trigger compression (must be >= 32 to allow 264 + dictionary construction, and <= 204 * MAX_STORE, in order for >> 10 to 265 + discard the stored block headers contribution of five bytes each) */ 266 +#define TRIGGER 1024 267 + 268 +/* size of a deflate dictionary (this cannot be changed) */ 269 +#define DICT 32768U 270 + 271 +/* values for the operation (2 bits) */ 272 +#define NO_OP 0 273 +#define APPEND_OP 1 274 +#define COMPRESS_OP 2 275 +#define REPLACE_OP 3 276 + 277 +/* macros to extract little-endian integers from an unsigned byte buffer */ 278 +#define PULL2(p) ((p)[0]+((uint)((p)[1])<<8)) 279 +#define PULL4(p) (PULL2(p)+((ulong)PULL2(p+2)<<16)) 280 +#define PULL8(p) (PULL4(p)+((off_t)PULL4(p+4)<<32)) 281 + 282 +/* macros to store integers into a byte buffer in little-endian order */ 283 +#define PUT2(p,a) do {(p)[0]=a;(p)[1]=(a)>>8;} while(0) 284 +#define PUT4(p,a) do {PUT2(p,a);PUT2(p+2,a>>16);} while(0) 285 +#define PUT8(p,a) do {PUT4(p,a);PUT4(p+4,a>>32);} while(0) 286 + 287 +/* internal structure for log information */ 288 +#define LOGID "\106\035\172" /* should be three non-zero characters */ 289 +struct log { 290 + char id[4]; /* contains LOGID to detect inadvertent overwrites */ 291 + int fd; /* file descriptor for .gz file, opened read/write */ 292 + char *path; /* allocated path, e.g. "/var/log/foo" or "foo" */ 293 + char *end; /* end of path, for appending suffices such as ".gz" */ 294 + off_t first; /* offset of first stored block first length byte */ 295 + int back; /* location of first block id in bits back from first */ 296 + uint stored; /* bytes currently in last stored block */ 297 + off_t last; /* offset of last stored block first length byte */ 298 + ulong ccrc; /* crc of compressed data */ 299 + ulong clen; /* length (modulo 2^32) of compressed data */ 300 + ulong tcrc; /* crc of total data */ 301 + ulong tlen; /* length (modulo 2^32) of total data */ 302 + time_t lock; /* last modify time of our lock file */ 303 +}; 304 + 305 +/* gzip header for gzlog */ 306 +local unsigned char log_gzhead[] = { 307 + 0x1f, 0x8b, /* magic gzip id */ 308 + 8, /* compression method is deflate */ 309 + 4, /* there is an extra field (no file name) */ 310 + 0, 0, 0, 0, /* no modification time provided */ 311 + 0, 0xff, /* no extra flags, no OS specified */ 312 + 39, 0, 'a', 'p', 35, 0 /* extra field with "ap" subfield */ 313 + /* 35 is EXTRA, 39 is EXTRA + 4 */ 314 +}; 315 + 316 +#define HEAD sizeof(log_gzhead) /* should be 16 */ 317 + 318 +/* initial gzip extra field content (52 == HEAD + EXTRA + 1) */ 319 +local unsigned char log_gzext[] = { 320 + 52, 0, 0, 0, 0, 0, 0, 0, /* offset of first stored block length */ 321 + 52, 0, 0, 0, 0, 0, 0, 0, /* offset of last stored block length */ 322 + 0, 0, 0, 0, 0, 0, 0, 0, /* compressed data crc and length */ 323 + 0, 0, 0, 0, 0, 0, 0, 0, /* total data crc and length */ 324 + 0, 0, /* final stored block data length */ 325 + 5 /* op is NO_OP, last bit 8 bits back */ 326 +}; 327 + 328 +#define EXTRA sizeof(log_gzext) /* should be 35 */ 329 + 330 +/* initial gzip data and trailer */ 331 +local unsigned char log_gzbody[] = { 332 + 1, 0, 0, 0xff, 0xff, /* empty stored block (last) */ 333 + 0, 0, 0, 0, /* crc */ 334 + 0, 0, 0, 0 /* uncompressed length */ 335 +}; 336 + 337 +#define BODY sizeof(log_gzbody) 338 + 339 +/* Exclusively create foo.lock in order to negotiate exclusive access to the 340 + foo.* files. If the modify time of an existing lock file is greater than 341 + PATIENCE seconds in the past, then consider the lock file to have been 342 + abandoned, delete it, and try the exclusive create again. Save the lock 343 + file modify time for verification of ownership. Return 0 on success, or -1 344 + on failure, usually due to an access restriction or invalid path. Note that 345 + if stat() or unlink() fails, it may be due to another process noticing the 346 + abandoned lock file a smidge sooner and deleting it, so those are not 347 + flagged as an error. */ 348 +local int log_lock(struct log *log) 349 +{ 350 + int fd; 351 + struct stat st; 352 + 353 + strcpy(log->end, ".lock"); 354 + while ((fd = open(log->path, O_CREAT | O_EXCL, 0644)) < 0) { 355 + if (errno != EEXIST) 356 + return -1; 357 + if (stat(log->path, &st) == 0 && time(NULL) - st.st_mtime > PATIENCE) { 358 + unlink(log->path); 359 + continue; 360 + } 361 + sleep(2); /* relinquish the CPU for two seconds while waiting */ 362 + } 363 + close(fd); 364 + if (stat(log->path, &st) == 0) 365 + log->lock = st.st_mtime; 366 + return 0; 367 +} 368 + 369 +/* Update the modify time of the lock file to now, in order to prevent another 370 + task from thinking that the lock is stale. Save the lock file modify time 371 + for verification of ownership. */ 372 +local void log_touch(struct log *log) 373 +{ 374 + struct stat st; 375 + 376 + strcpy(log->end, ".lock"); 377 + utimes(log->path, NULL); 378 + if (stat(log->path, &st) == 0) 379 + log->lock = st.st_mtime; 380 +} 381 + 382 +/* Check the log file modify time against what is expected. Return true if 383 + this is not our lock. If it is our lock, touch it to keep it. */ 384 +local int log_check(struct log *log) 385 +{ 386 + struct stat st; 387 + 388 + strcpy(log->end, ".lock"); 389 + if (stat(log->path, &st) || st.st_mtime != log->lock) 390 + return 1; 391 + log_touch(log); 392 + return 0; 393 +} 394 + 395 +/* Unlock a previously acquired lock, but only if it's ours. */ 396 +local void log_unlock(struct log *log) 397 +{ 398 + if (log_check(log)) 399 + return; 400 + strcpy(log->end, ".lock"); 401 + unlink(log->path); 402 + log->lock = 0; 403 +} 404 + 405 +/* Check the gzip header and read in the extra field, filling in the values in 406 + the log structure. Return op on success or -1 if the gzip header was not as 407 + expected. op is the current operation in progress last written to the extra 408 + field. This assumes that the gzip file has already been opened, with the 409 + file descriptor log->fd. */ 410 +local int log_head(struct log *log) 411 +{ 412 + int op; 413 + unsigned char buf[HEAD + EXTRA]; 414 + 415 + if (lseek(log->fd, 0, SEEK_SET) < 0 || 416 + read(log->fd, buf, HEAD + EXTRA) != HEAD + EXTRA || 417 + memcmp(buf, log_gzhead, HEAD)) { 418 + return -1; 419 + } 420 + log->first = PULL8(buf + HEAD); 421 + log->last = PULL8(buf + HEAD + 8); 422 + log->ccrc = PULL4(buf + HEAD + 16); 423 + log->clen = PULL4(buf + HEAD + 20); 424 + log->tcrc = PULL4(buf + HEAD + 24); 425 + log->tlen = PULL4(buf + HEAD + 28); 426 + log->stored = PULL2(buf + HEAD + 32); 427 + log->back = 3 + (buf[HEAD + 34] & 7); 428 + op = (buf[HEAD + 34] >> 3) & 3; 429 + return op; 430 +} 431 + 432 +/* Write over the extra field contents, marking the operation as op. Use fsync 433 + to assure that the device is written to, and in the requested order. This 434 + operation, and only this operation, is assumed to be atomic in order to 435 + assure that the log is recoverable in the event of an interruption at any 436 + point in the process. Return -1 if the write to foo.gz failed. */ 437 +local int log_mark(struct log *log, int op) 438 +{ 439 + int ret; 440 + unsigned char ext[EXTRA]; 441 + 442 + PUT8(ext, log->first); 443 + PUT8(ext + 8, log->last); 444 + PUT4(ext + 16, log->ccrc); 445 + PUT4(ext + 20, log->clen); 446 + PUT4(ext + 24, log->tcrc); 447 + PUT4(ext + 28, log->tlen); 448 + PUT2(ext + 32, log->stored); 449 + ext[34] = log->back - 3 + (op << 3); 450 + fsync(log->fd); 451 + ret = lseek(log->fd, HEAD, SEEK_SET) < 0 || 452 + write(log->fd, ext, EXTRA) != EXTRA ? -1 : 0; 453 + fsync(log->fd); 454 + return ret; 455 +} 456 + 457 +/* Rewrite the last block header bits and subsequent zero bits to get to a byte 458 + boundary, setting the last block bit if last is true, and then write the 459 + remainder of the stored block header (length and one's complement). Leave 460 + the file pointer after the end of the last stored block data. Return -1 if 461 + there is a read or write failure on the foo.gz file */ 462 +local int log_last(struct log *log, int last) 463 +{ 464 + int back, len, mask; 465 + unsigned char buf[6]; 466 + 467 + /* determine the locations of the bytes and bits to modify */ 468 + back = log->last == log->first ? log->back : 8; 469 + len = back > 8 ? 2 : 1; /* bytes back from log->last */ 470 + mask = 0x80 >> ((back - 1) & 7); /* mask for block last-bit */ 471 + 472 + /* get the byte to modify (one or two back) into buf[0] -- don't need to 473 + read the byte if the last-bit is eight bits back, since in that case 474 + the entire byte will be modified */ 475 + buf[0] = 0; 476 + if (back != 8 && (lseek(log->fd, log->last - len, SEEK_SET) < 0 || 477 + read(log->fd, buf, 1) != 1)) 478 + return -1; 479 + 480 + /* change the last-bit of the last stored block as requested -- note 481 + that all bits above the last-bit are set to zero, per the type bits 482 + of a stored block being 00 and per the convention that the bits to 483 + bring the stream to a byte boundary are also zeros */ 484 + buf[1] = 0; 485 + buf[2 - len] = (*buf & (mask - 1)) + (last ? mask : 0); 486 + 487 + /* write the modified stored block header and lengths, move the file 488 + pointer to after the last stored block data */ 489 + PUT2(buf + 2, log->stored); 490 + PUT2(buf + 4, log->stored ^ 0xffff); 491 + return lseek(log->fd, log->last - len, SEEK_SET) < 0 || 492 + write(log->fd, buf + 2 - len, len + 4) != len + 4 || 493 + lseek(log->fd, log->stored, SEEK_CUR) < 0 ? -1 : 0; 494 +} 495 + 496 +/* Append len bytes from data to the locked and open log file. len may be zero 497 + if recovering and no .add file was found. In that case, the previous state 498 + of the foo.gz file is restored. The data is appended uncompressed in 499 + deflate stored blocks. Return -1 if there was an error reading or writing 500 + the foo.gz file. */ 501 +local int log_append(struct log *log, unsigned char *data, size_t len) 502 +{ 503 + uint put; 504 + off_t end; 505 + unsigned char buf[8]; 506 + 507 + /* set the last block last-bit and length, in case recovering an 508 + interrupted append, then position the file pointer to append to the 509 + block */ 510 + if (log_last(log, 1)) 511 + return -1; 512 + 513 + /* append, adding stored blocks and updating the offset of the last stored 514 + block as needed, and update the total crc and length */ 515 + while (len) { 516 + /* append as much as we can to the last block */ 517 + put = (MAX_STORE << 10) - log->stored; 518 + if (put > len) 519 + put = (uint)len; 520 + if (put) { 521 + if (write(log->fd, data, put) != put) 522 + return -1; 523 + BAIL(1); 524 + log->tcrc = crc32(log->tcrc, data, put); 525 + log->tlen += put; 526 + log->stored += put; 527 + data += put; 528 + len -= put; 529 + } 530 + 531 + /* if we need to, add a new empty stored block */ 532 + if (len) { 533 + /* mark current block as not last */ 534 + if (log_last(log, 0)) 535 + return -1; 536 + 537 + /* point to new, empty stored block */ 538 + log->last += 4 + log->stored + 1; 539 + log->stored = 0; 540 + } 541 + 542 + /* mark last block as last, update its length */ 543 + if (log_last(log, 1)) 544 + return -1; 545 + BAIL(2); 546 + } 547 + 548 + /* write the new crc and length trailer, and truncate just in case (could 549 + be recovering from partial append with a missing foo.add file) */ 550 + PUT4(buf, log->tcrc); 551 + PUT4(buf + 4, log->tlen); 552 + if (write(log->fd, buf, 8) != 8 || 553 + (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) 554 + return -1; 555 + 556 + /* write the extra field, marking the log file as done, delete .add file */ 557 + if (log_mark(log, NO_OP)) 558 + return -1; 559 + strcpy(log->end, ".add"); 560 + unlink(log->path); /* ignore error, since may not exist */ 561 + return 0; 562 +} 563 + 564 +/* Replace the foo.dict file with the foo.temp file. Also delete the foo.add 565 + file, since the compress operation may have been interrupted before that was 566 + done. Returns 1 if memory could not be allocated, or -1 if reading or 567 + writing foo.gz fails, or if the rename fails for some reason other than 568 + foo.temp not existing. foo.temp not existing is a permitted error, since 569 + the replace operation may have been interrupted after the rename is done, 570 + but before foo.gz is marked as complete. */ 571 +local int log_replace(struct log *log) 572 +{ 573 + int ret; 574 + char *dest; 575 + 576 + /* delete foo.add file */ 577 + strcpy(log->end, ".add"); 578 + unlink(log->path); /* ignore error, since may not exist */ 579 + BAIL(3); 580 + 581 + /* rename foo.name to foo.dict, replacing foo.dict if it exists */ 582 + strcpy(log->end, ".dict"); 583 + dest = malloc(strlen(log->path) + 1); 584 + if (dest == NULL) 585 + return -2; 586 + strcpy(dest, log->path); 587 + strcpy(log->end, ".temp"); 588 + ret = rename(log->path, dest); 589 + free(dest); 590 + if (ret && errno != ENOENT) 591 + return -1; 592 + BAIL(4); 593 + 594 + /* mark the foo.gz file as done */ 595 + return log_mark(log, NO_OP); 596 +} 597 + 598 +/* Compress the len bytes at data and append the compressed data to the 599 + foo.gz deflate data immediately after the previous compressed data. This 600 + overwrites the previous uncompressed data, which was stored in foo.add 601 + and is the data provided in data[0..len-1]. If this operation is 602 + interrupted, it picks up at the start of this routine, with the foo.add 603 + file read in again. If there is no data to compress (len == 0), then we 604 + simply terminate the foo.gz file after the previously compressed data, 605 + appending a final empty stored block and the gzip trailer. Return -1 if 606 + reading or writing the log.gz file failed, or -2 if there was a memory 607 + allocation failure. */ 608 +local int log_compress(struct log *log, unsigned char *data, size_t len) 609 +{ 610 + int fd; 611 + uint got, max; 612 + ssize_t dict; 613 + off_t end; 614 + z_stream strm; 615 + unsigned char buf[DICT]; 616 + 617 + /* compress and append compressed data */ 618 + if (len) { 619 + /* set up for deflate, allocating memory */ 620 + strm.zalloc = Z_NULL; 621 + strm.zfree = Z_NULL; 622 + strm.opaque = Z_NULL; 623 + if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, 624 + Z_DEFAULT_STRATEGY) != Z_OK) 625 + return -2; 626 + 627 + /* read in dictionary (last 32K of data that was compressed) */ 628 + strcpy(log->end, ".dict"); 629 + fd = open(log->path, O_RDONLY, 0); 630 + if (fd >= 0) { 631 + dict = read(fd, buf, DICT); 632 + close(fd); 633 + if (dict < 0) { 634 + deflateEnd(&strm); 635 + return -1; 636 + } 637 + if (dict) 638 + deflateSetDictionary(&strm, buf, (uint)dict); 639 + } 640 + log_touch(log); 641 + 642 + /* prime deflate with last bits of previous block, position write 643 + pointer to write those bits and overwrite what follows */ 644 + if (lseek(log->fd, log->first - (log->back > 8 ? 2 : 1), 645 + SEEK_SET) < 0 || 646 + read(log->fd, buf, 1) != 1 || lseek(log->fd, -1, SEEK_CUR) < 0) { 647 + deflateEnd(&strm); 648 + return -1; 649 + } 650 + deflatePrime(&strm, (8 - log->back) & 7, *buf); 651 + 652 + /* compress, finishing with a partial non-last empty static block */ 653 + strm.next_in = data; 654 + max = (((uint)0 - 1) >> 1) + 1; /* in case int smaller than size_t */ 655 + do { 656 + strm.avail_in = len > max ? max : (uint)len; 657 + len -= strm.avail_in; 658 + do { 659 + strm.avail_out = DICT; 660 + strm.next_out = buf; 661 + deflate(&strm, len ? Z_NO_FLUSH : Z_PARTIAL_FLUSH); 662 + got = DICT - strm.avail_out; 663 + if (got && write(log->fd, buf, got) != got) { 664 + deflateEnd(&strm); 665 + return -1; 666 + } 667 + log_touch(log); 668 + } while (strm.avail_out == 0); 669 + } while (len); 670 + deflateEnd(&strm); 671 + BAIL(5); 672 + 673 + /* find start of empty static block -- scanning backwards the first one 674 + bit is the second bit of the block, if the last byte is zero, then 675 + we know the byte before that has a one in the top bit, since an 676 + empty static block is ten bits long */ 677 + if ((log->first = lseek(log->fd, -1, SEEK_CUR)) < 0 || 678 + read(log->fd, buf, 1) != 1) 679 + return -1; 680 + log->first++; 681 + if (*buf) { 682 + log->back = 1; 683 + while ((*buf & ((uint)1 << (8 - log->back++))) == 0) 684 + ; /* guaranteed to terminate, since *buf != 0 */ 685 + } 686 + else 687 + log->back = 10; 688 + 689 + /* update compressed crc and length */ 690 + log->ccrc = log->tcrc; 691 + log->clen = log->tlen; 692 + } 693 + else { 694 + /* no data to compress -- fix up existing gzip stream */ 695 + log->tcrc = log->ccrc; 696 + log->tlen = log->clen; 697 + } 698 + 699 + /* complete and truncate gzip stream */ 700 + log->last = log->first; 701 + log->stored = 0; 702 + PUT4(buf, log->tcrc); 703 + PUT4(buf + 4, log->tlen); 704 + if (log_last(log, 1) || write(log->fd, buf, 8) != 8 || 705 + (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) 706 + return -1; 707 + BAIL(6); 708 + 709 + /* mark as being in the replace operation */ 710 + if (log_mark(log, REPLACE_OP)) 711 + return -1; 712 + 713 + /* execute the replace operation and mark the file as done */ 714 + return log_replace(log); 715 +} 716 + 717 +/* log a repair record to the .repairs file */ 718 +local void log_log(struct log *log, int op, char *record) 719 +{ 720 + time_t now; 721 + FILE *rec; 722 + 723 + now = time(NULL); 724 + strcpy(log->end, ".repairs"); 725 + rec = fopen(log->path, "a"); 726 + if (rec == NULL) 727 + return; 728 + fprintf(rec, "%.24s %s recovery: %s\n", ctime(&now), op == APPEND_OP ? 729 + "append" : (op == COMPRESS_OP ? "compress" : "replace"), record); 730 + fclose(rec); 731 + return; 732 +} 733 + 734 +/* Recover the interrupted operation op. First read foo.add for recovering an 735 + append or compress operation. Return -1 if there was an error reading or 736 + writing foo.gz or reading an existing foo.add, or -2 if there was a memory 737 + allocation failure. */ 738 +local int log_recover(struct log *log, int op) 739 +{ 740 + int fd, ret = 0; 741 + unsigned char *data = NULL; 742 + size_t len = 0; 743 + struct stat st; 744 + 745 + /* log recovery */ 746 + log_log(log, op, "start"); 747 + 748 + /* load foo.add file if expected and present */ 749 + if (op == APPEND_OP || op == COMPRESS_OP) { 750 + strcpy(log->end, ".add"); 751 + if (stat(log->path, &st) == 0 && st.st_size) { 752 + len = (size_t)(st.st_size); 753 + if (len != st.st_size || (data = malloc(st.st_size)) == NULL) { 754 + log_log(log, op, "allocation failure"); 755 + return -2; 756 + } 757 + if ((fd = open(log->path, O_RDONLY, 0)) < 0) { 758 + log_log(log, op, ".add file read failure"); 759 + return -1; 760 + } 761 + ret = read(fd, data, len) != len; 762 + close(fd); 763 + if (ret) { 764 + log_log(log, op, ".add file read failure"); 765 + return -1; 766 + } 767 + log_log(log, op, "loaded .add file"); 768 + } 769 + else 770 + log_log(log, op, "missing .add file!"); 771 + } 772 + 773 + /* recover the interrupted operation */ 774 + switch (op) { 775 + case APPEND_OP: 776 + ret = log_append(log, data, len); 777 + break; 778 + case COMPRESS_OP: 779 + ret = log_compress(log, data, len); 780 + break; 781 + case REPLACE_OP: 782 + ret = log_replace(log); 783 + } 784 + 785 + /* log status */ 786 + log_log(log, op, ret ? "failure" : "complete"); 787 + 788 + /* clean up */ 789 + if (data != NULL) 790 + free(data); 791 + return ret; 792 +} 793 + 794 +/* Close the foo.gz file (if open) and release the lock. */ 795 +local void log_close(struct log *log) 796 +{ 797 + if (log->fd >= 0) 798 + close(log->fd); 799 + log->fd = -1; 800 + log_unlock(log); 801 +} 802 + 803 +/* Open foo.gz, verify the header, and load the extra field contents, after 804 + first creating the foo.lock file to gain exclusive access to the foo.* 805 + files. If foo.gz does not exist or is empty, then write the initial header, 806 + extra, and body content of an empty foo.gz log file. If there is an error 807 + creating the lock file due to access restrictions, or an error reading or 808 + writing the foo.gz file, or if the foo.gz file is not a proper log file for 809 + this object (e.g. not a gzip file or does not contain the expected extra 810 + field), then return true. If there is an error, the lock is released. 811 + Otherwise, the lock is left in place. */ 812 +local int log_open(struct log *log) 813 +{ 814 + int op; 815 + 816 + /* release open file resource if left over -- can occur if lock lost 817 + between gzlog_open() and gzlog_write() */ 818 + if (log->fd >= 0) 819 + close(log->fd); 820 + log->fd = -1; 821 + 822 + /* negotiate exclusive access */ 823 + if (log_lock(log) < 0) 824 + return -1; 825 + 826 + /* open the log file, foo.gz */ 827 + strcpy(log->end, ".gz"); 828 + log->fd = open(log->path, O_RDWR | O_CREAT, 0644); 829 + if (log->fd < 0) { 830 + log_close(log); 831 + return -1; 832 + } 833 + 834 + /* if new, initialize foo.gz with an empty log, delete old dictionary */ 835 + if (lseek(log->fd, 0, SEEK_END) == 0) { 836 + if (write(log->fd, log_gzhead, HEAD) != HEAD || 837 + write(log->fd, log_gzext, EXTRA) != EXTRA || 838 + write(log->fd, log_gzbody, BODY) != BODY) { 839 + log_close(log); 840 + return -1; 841 + } 842 + strcpy(log->end, ".dict"); 843 + unlink(log->path); 844 + } 845 + 846 + /* verify log file and load extra field information */ 847 + if ((op = log_head(log)) < 0) { 848 + log_close(log); 849 + return -1; 850 + } 851 + 852 + /* check for interrupted process and if so, recover */ 853 + if (op != NO_OP && log_recover(log, op)) { 854 + log_close(log); 855 + return -1; 856 + } 857 + 858 + /* touch the lock file to prevent another process from grabbing it */ 859 + log_touch(log); 860 + return 0; 861 +} 862 + 863 +/* See gzlog.h for the description of the external methods below */ 864 +gzlog *gzlog_open(char *path) 865 +{ 866 + size_t n; 867 + struct log *log; 868 + 869 + /* check arguments */ 870 + if (path == NULL || *path == 0) 871 + return NULL; 872 + 873 + /* allocate and initialize log structure */ 874 + log = malloc(sizeof(struct log)); 875 + if (log == NULL) 876 + return NULL; 877 + strcpy(log->id, LOGID); 878 + log->fd = -1; 879 + 880 + /* save path and end of path for name construction */ 881 + n = strlen(path); 882 + log->path = malloc(n + 9); /* allow for ".repairs" */ 883 + if (log->path == NULL) { 884 + free(log); 885 + return NULL; 886 + } 887 + strcpy(log->path, path); 888 + log->end = log->path + n; 889 + 890 + /* gain exclusive access and verify log file -- may perform a 891 + recovery operation if needed */ 892 + if (log_open(log)) { 893 + free(log->path); 894 + free(log); 895 + return NULL; 896 + } 897 + 898 + /* return pointer to log structure */ 899 + return log; 900 +} 901 + 902 +/* gzlog_compress() return values: 903 + 0: all good 904 + -1: file i/o error (usually access issue) 905 + -2: memory allocation failure 906 + -3: invalid log pointer argument */ 907 +int gzlog_compress(gzlog *logd) 908 +{ 909 + int fd, ret; 910 + uint block; 911 + size_t len, next; 912 + unsigned char *data, buf[5]; 913 + struct log *log = logd; 914 + 915 + /* check arguments */ 916 + if (log == NULL || strcmp(log->id, LOGID) || len < 0) 917 + return -3; 918 + 919 + /* see if we lost the lock -- if so get it again and reload the extra 920 + field information (it probably changed), recover last operation if 921 + necessary */ 922 + if (log_check(log) && log_open(log)) 923 + return -1; 924 + 925 + /* create space for uncompressed data */ 926 + len = ((size_t)(log->last - log->first) & ~(((size_t)1 << 10) - 1)) + 927 + log->stored; 928 + if ((data = malloc(len)) == NULL) 929 + return -2; 930 + 931 + /* do statement here is just a cheap trick for error handling */ 932 + do { 933 + /* read in the uncompressed data */ 934 + if (lseek(log->fd, log->first - 1, SEEK_SET) < 0) 935 + break; 936 + next = 0; 937 + while (next < len) { 938 + if (read(log->fd, buf, 5) != 5) 939 + break; 940 + block = PULL2(buf + 1); 941 + if (next + block > len || 942 + read(log->fd, (char *)data + next, block) != block) 943 + break; 944 + next += block; 945 + } 946 + if (lseek(log->fd, 0, SEEK_CUR) != log->last + 4 + log->stored) 947 + break; 948 + log_touch(log); 949 + 950 + /* write the uncompressed data to the .add file */ 951 + strcpy(log->end, ".add"); 952 + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); 953 + if (fd < 0) 954 + break; 955 + ret = write(fd, data, len) != len; 956 + if (ret | close(fd)) 957 + break; 958 + log_touch(log); 959 + 960 + /* write the dictionary for the next compress to the .temp file */ 961 + strcpy(log->end, ".temp"); 962 + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); 963 + if (fd < 0) 964 + break; 965 + next = DICT > len ? len : DICT; 966 + ret = write(fd, (char *)data + len - next, next) != next; 967 + if (ret | close(fd)) 968 + break; 969 + log_touch(log); 970 + 971 + /* roll back to compressed data, mark the compress in progress */ 972 + log->last = log->first; 973 + log->stored = 0; 974 + if (log_mark(log, COMPRESS_OP)) 975 + break; 976 + BAIL(7); 977 + 978 + /* compress and append the data (clears mark) */ 979 + ret = log_compress(log, data, len); 980 + free(data); 981 + return ret; 982 + } while (0); 983 + 984 + /* broke out of do above on i/o error */ 985 + free(data); 986 + return -1; 987 +} 988 + 989 +/* gzlog_write() return values: 990 + 0: all good 991 + -1: file i/o error (usually access issue) 992 + -2: memory allocation failure 993 + -3: invalid log pointer argument */ 994 +int gzlog_write(gzlog *logd, void *data, size_t len) 995 +{ 996 + int fd, ret; 997 + struct log *log = logd; 998 + 999 + /* check arguments */ 1000 + if (log == NULL || strcmp(log->id, LOGID) || len < 0) 1001 + return -3; 1002 + if (data == NULL || len == 0) 1003 + return 0; 1004 + 1005 + /* see if we lost the lock -- if so get it again and reload the extra 1006 + field information (it probably changed), recover last operation if 1007 + necessary */ 1008 + if (log_check(log) && log_open(log)) 1009 + return -1; 1010 + 1011 + /* create and write .add file */ 1012 + strcpy(log->end, ".add"); 1013 + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); 1014 + if (fd < 0) 1015 + return -1; 1016 + ret = write(fd, data, len) != len; 1017 + if (ret | close(fd)) 1018 + return -1; 1019 + log_touch(log); 1020 + 1021 + /* mark log file with append in progress */ 1022 + if (log_mark(log, APPEND_OP)) 1023 + return -1; 1024 + BAIL(8); 1025 + 1026 + /* append data (clears mark) */ 1027 + if (log_append(log, data, len)) 1028 + return -1; 1029 + 1030 + /* check to see if it's time to compress -- if not, then done */ 1031 + if (((log->last - log->first) >> 10) + (log->stored >> 10) < TRIGGER) 1032 + return 0; 1033 + 1034 + /* time to compress */ 1035 + return gzlog_compress(log); 1036 +} 1037 + 1038 +/* gzlog_close() return values: 1039 + 0: ok 1040 + -3: invalid log pointer argument */ 1041 +int gzlog_close(gzlog *logd) 1042 +{ 1043 + struct log *log = logd; 1044 + 1045 + /* check arguments */ 1046 + if (log == NULL || strcmp(log->id, LOGID)) 1047 + return -3; 1048 + 1049 + /* close the log file and release the lock */ 1050 + log_close(log); 1051 + 1052 + /* free structure and return */ 1053 + if (log->path != NULL) 1054 + free(log->path); 1055 + strcpy(log->id, "bad"); 1056 + free(log); 1057 + return 0; 1058 +}
Added compat/zlib/examples/gzlog.h.
1 +/* gzlog.h 2 + Copyright (C) 2004, 2008 Mark Adler, all rights reserved 3 + version 2.0, 25 Apr 2008 4 + 5 + This software is provided 'as-is', without any express or implied 6 + warranty. In no event will the author be held liable for any damages 7 + arising from the use of this software. 8 + 9 + Permission is granted to anyone to use this software for any purpose, 10 + including commercial applications, and to alter it and redistribute it 11 + freely, subject to the following restrictions: 12 + 13 + 1. The origin of this software must not be misrepresented; you must not 14 + claim that you wrote the original software. If you use this software 15 + in a product, an acknowledgment in the product documentation would be 16 + appreciated but is not required. 17 + 2. Altered source versions must be plainly marked as such, and must not be 18 + misrepresented as being the original software. 19 + 3. This notice may not be removed or altered from any source distribution. 20 + 21 + Mark Adler madler@alumni.caltech.edu 22 + */ 23 + 24 +/* Version History: 25 + 1.0 26 Nov 2004 First version 26 + 2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations 27 + Interface changed slightly in that now path is a prefix 28 + Compression now occurs as needed during gzlog_write() 29 + gzlog_write() now always leaves the log file as valid gzip 30 + */ 31 + 32 +/* 33 + The gzlog object allows writing short messages to a gzipped log file, 34 + opening the log file locked for small bursts, and then closing it. The log 35 + object works by appending stored (uncompressed) data to the gzip file until 36 + 1 MB has been accumulated. At that time, the stored data is compressed, and 37 + replaces the uncompressed data in the file. The log file is truncated to 38 + its new size at that time. After each write operation, the log file is a 39 + valid gzip file that can decompressed to recover what was written. 40 + 41 + The gzlog operations can be interupted at any point due to an application or 42 + system crash, and the log file will be recovered the next time the log is 43 + opened with gzlog_open(). 44 + */ 45 + 46 +#ifndef GZLOG_H 47 +#define GZLOG_H 48 + 49 +/* gzlog object type */ 50 +typedef void gzlog; 51 + 52 +/* Open a gzlog object, creating the log file if it does not exist. Return 53 + NULL on error. Note that gzlog_open() could take a while to complete if it 54 + has to wait to verify that a lock is stale (possibly for five minutes), or 55 + if there is significant contention with other instantiations of this object 56 + when locking the resource. path is the prefix of the file names created by 57 + this object. If path is "foo", then the log file will be "foo.gz", and 58 + other auxiliary files will be created and destroyed during the process: 59 + "foo.dict" for a compression dictionary, "foo.temp" for a temporary (next) 60 + dictionary, "foo.add" for data being added or compressed, "foo.lock" for the 61 + lock file, and "foo.repairs" to log recovery operations performed due to 62 + interrupted gzlog operations. A gzlog_open() followed by a gzlog_close() 63 + will recover a previously interrupted operation, if any. */ 64 +gzlog *gzlog_open(char *path); 65 + 66 +/* Write to a gzlog object. Return zero on success, -1 if there is a file i/o 67 + error on any of the gzlog files (this should not happen if gzlog_open() 68 + succeeded, unless the device has run out of space or leftover auxiliary 69 + files have permissions or ownership that prevent their use), -2 if there is 70 + a memory allocation failure, or -3 if the log argument is invalid (e.g. if 71 + it was not created by gzlog_open()). This function will write data to the 72 + file uncompressed, until 1 MB has been accumulated, at which time that data 73 + will be compressed. The log file will be a valid gzip file upon successful 74 + return. */ 75 +int gzlog_write(gzlog *log, void *data, size_t len); 76 + 77 +/* Force compression of any uncompressed data in the log. This should be used 78 + sparingly, if at all. The main application would be when a log file will 79 + not be appended to again. If this is used to compress frequently while 80 + appending, it will both significantly increase the execution time and 81 + reduce the compression ratio. The return codes are the same as for 82 + gzlog_write(). */ 83 +int gzlog_compress(gzlog *log); 84 + 85 +/* Close a gzlog object. Return zero on success, -3 if the log argument is 86 + invalid. The log object is freed, and so cannot be referenced again. */ 87 +int gzlog_close(gzlog *log); 88 + 89 +#endif
Added compat/zlib/examples/zlib_how.html.
1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 2 + "http://www.w3.org/TR/REC-html40/loose.dtd"> 3 +<html> 4 +<head> 5 +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 6 +<title>zlib Usage Example</title> 7 +<!-- Copyright (c) 2004, 2005 Mark Adler. --> 8 +</head> 9 +<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000"> 10 +<h2 align="center"> zlib Usage Example </h2> 11 +We often get questions about how the <tt>deflate()</tt> and <tt>inflate()</tt> functions should be used. 12 +Users wonder when they should provide more input, when they should use more output, 13 +what to do with a <tt>Z_BUF_ERROR</tt>, how to make sure the process terminates properly, and 14 +so on. So for those who have read <tt>zlib.h</tt> (a few times), and 15 +would like further edification, below is an annotated example in C of simple routines to compress and decompress 16 +from an input file to an output file using <tt>deflate()</tt> and <tt>inflate()</tt> respectively. The 17 +annotations are interspersed between lines of the code. So please read between the lines. 18 +We hope this helps explain some of the intricacies of <em>zlib</em>. 19 +<p> 20 +Without further adieu, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>: 21 +<pre><b> 22 +/* zpipe.c: example of proper use of zlib's inflate() and deflate() 23 + Not copyrighted -- provided to the public domain 24 + Version 1.4 11 December 2005 Mark Adler */ 25 + 26 +/* Version history: 27 + 1.0 30 Oct 2004 First version 28 + 1.1 8 Nov 2004 Add void casting for unused return values 29 + Use switch statement for inflate() return values 30 + 1.2 9 Nov 2004 Add assertions to document zlib guarantees 31 + 1.3 6 Apr 2005 Remove incorrect assertion in inf() 32 + 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions 33 + Avoid some compiler warnings for input and output buffers 34 + */ 35 +</b></pre><!-- --> 36 +We now include the header files for the required definitions. From 37 +<tt>stdio.h</tt> we use <tt>fopen()</tt>, <tt>fread()</tt>, <tt>fwrite()</tt>, 38 +<tt>feof()</tt>, <tt>ferror()</tt>, and <tt>fclose()</tt> for file i/o, and 39 +<tt>fputs()</tt> for error messages. From <tt>string.h</tt> we use 40 +<tt>strcmp()</tt> for command line argument processing. 41 +From <tt>assert.h</tt> we use the <tt>assert()</tt> macro. 42 +From <tt>zlib.h</tt> 43 +we use the basic compression functions <tt>deflateInit()</tt>, 44 +<tt>deflate()</tt>, and <tt>deflateEnd()</tt>, and the basic decompression 45 +functions <tt>inflateInit()</tt>, <tt>inflate()</tt>, and 46 +<tt>inflateEnd()</tt>. 47 +<pre><b> 48 +#include <stdio.h> 49 +#include <string.h> 50 +#include <assert.h> 51 +#include "zlib.h" 52 +</b></pre><!-- --> 53 +This is an ugly hack required to avoid corruption of the input and output data on 54 +Windows/MS-DOS systems. Without this, those systems would assume that the input and output 55 +files are text, and try to convert the end-of-line characters from one standard to 56 +another. That would corrupt binary data, and in particular would render the compressed data unusable. 57 +This sets the input and output to binary which suppresses the end-of-line conversions. 58 +<tt>SET_BINARY_MODE()</tt> will be used later on <tt>stdin</tt> and <tt>stdout</tt>, at the beginning of <tt>main()</tt>. 59 +<pre><b> 60 +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 61 +# include <fcntl.h> 62 +# include <io.h> 63 +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 64 +#else 65 +# define SET_BINARY_MODE(file) 66 +#endif 67 +</b></pre><!-- --> 68 +<tt>CHUNK</tt> is simply the buffer size for feeding data to and pulling data 69 +from the <em>zlib</em> routines. Larger buffer sizes would be more efficient, 70 +especially for <tt>inflate()</tt>. If the memory is available, buffers sizes 71 +on the order of 128K or 256K bytes should be used. 72 +<pre><b> 73 +#define CHUNK 16384 74 +</b></pre><!-- --> 75 +The <tt>def()</tt> routine compresses data from an input file to an output file. The output data 76 +will be in the <em>zlib</em> format, which is different from the <em>gzip</em> or <em>zip</em> 77 +formats. The <em>zlib</em> format has a very small header of only two bytes to identify it as 78 +a <em>zlib</em> stream and to provide decoding information, and a four-byte trailer with a fast 79 +check value to verify the integrity of the uncompressed data after decoding. 80 +<pre><b> 81 +/* Compress from file source to file dest until EOF on source. 82 + def() returns Z_OK on success, Z_MEM_ERROR if memory could not be 83 + allocated for processing, Z_STREAM_ERROR if an invalid compression 84 + level is supplied, Z_VERSION_ERROR if the version of zlib.h and the 85 + version of the library linked do not match, or Z_ERRNO if there is 86 + an error reading or writing the files. */ 87 +int def(FILE *source, FILE *dest, int level) 88 +{ 89 +</b></pre> 90 +Here are the local variables for <tt>def()</tt>. <tt>ret</tt> will be used for <em>zlib</em> 91 +return codes. <tt>flush</tt> will keep track of the current flushing state for <tt>deflate()</tt>, 92 +which is either no flushing, or flush to completion after the end of the input file is reached. 93 +<tt>have</tt> is the amount of data returned from <tt>deflate()</tt>. The <tt>strm</tt> structure 94 +is used to pass information to and from the <em>zlib</em> routines, and to maintain the 95 +<tt>deflate()</tt> state. <tt>in</tt> and <tt>out</tt> are the input and output buffers for 96 +<tt>deflate()</tt>. 97 +<pre><b> 98 + int ret, flush; 99 + unsigned have; 100 + z_stream strm; 101 + unsigned char in[CHUNK]; 102 + unsigned char out[CHUNK]; 103 +</b></pre><!-- --> 104 +The first thing we do is to initialize the <em>zlib</em> state for compression using 105 +<tt>deflateInit()</tt>. This must be done before the first use of <tt>deflate()</tt>. 106 +The <tt>zalloc</tt>, <tt>zfree</tt>, and <tt>opaque</tt> fields in the <tt>strm</tt> 107 +structure must be initialized before calling <tt>deflateInit()</tt>. Here they are 108 +set to the <em>zlib</em> constant <tt>Z_NULL</tt> to request that <em>zlib</em> use 109 +the default memory allocation routines. An application may also choose to provide 110 +custom memory allocation routines here. <tt>deflateInit()</tt> will allocate on the 111 +order of 256K bytes for the internal state. 112 +(See <a href="zlib_tech.html"><em>zlib Technical Details</em></a>.) 113 +<p> 114 +<tt>deflateInit()</tt> is called with a pointer to the structure to be initialized and 115 +the compression level, which is an integer in the range of -1 to 9. Lower compression 116 +levels result in faster execution, but less compression. Higher levels result in 117 +greater compression, but slower execution. The <em>zlib</em> constant Z_DEFAULT_COMPRESSION, 118 +equal to -1, 119 +provides a good compromise between compression and speed and is equivalent to level 6. 120 +Level 0 actually does no compression at all, and in fact expands the data slightly to produce 121 +the <em>zlib</em> format (it is not a byte-for-byte copy of the input). 122 +More advanced applications of <em>zlib</em> 123 +may use <tt>deflateInit2()</tt> here instead. Such an application may want to reduce how 124 +much memory will be used, at some price in compression. Or it may need to request a 125 +<em>gzip</em> header and trailer instead of a <em>zlib</em> header and trailer, or raw 126 +encoding with no header or trailer at all. 127 +<p> 128 +We must check the return value of <tt>deflateInit()</tt> against the <em>zlib</em> constant 129 +<tt>Z_OK</tt> to make sure that it was able to 130 +allocate memory for the internal state, and that the provided arguments were valid. 131 +<tt>deflateInit()</tt> will also check that the version of <em>zlib</em> that the <tt>zlib.h</tt> 132 +file came from matches the version of <em>zlib</em> actually linked with the program. This 133 +is especially important for environments in which <em>zlib</em> is a shared library. 134 +<p> 135 +Note that an application can initialize multiple, independent <em>zlib</em> streams, which can 136 +operate in parallel. The state information maintained in the structure allows the <em>zlib</em> 137 +routines to be reentrant. 138 +<pre><b> 139 + /* allocate deflate state */ 140 + strm.zalloc = Z_NULL; 141 + strm.zfree = Z_NULL; 142 + strm.opaque = Z_NULL; 143 + ret = deflateInit(&strm, level); 144 + if (ret != Z_OK) 145 + return ret; 146 +</b></pre><!-- --> 147 +With the pleasantries out of the way, now we can get down to business. The outer <tt>do</tt>-loop 148 +reads all of the input file and exits at the bottom of the loop once end-of-file is reached. 149 +This loop contains the only call of <tt>deflate()</tt>. So we must make sure that all of the 150 +input data has been processed and that all of the output data has been generated and consumed 151 +before we fall out of the loop at the bottom. 152 +<pre><b> 153 + /* compress until end of file */ 154 + do { 155 +</b></pre> 156 +We start off by reading data from the input file. The number of bytes read is put directly 157 +into <tt>avail_in</tt>, and a pointer to those bytes is put into <tt>next_in</tt>. We also 158 +check to see if end-of-file on the input has been reached. If we are at the end of file, then <tt>flush</tt> is set to the 159 +<em>zlib</em> constant <tt>Z_FINISH</tt>, which is later passed to <tt>deflate()</tt> to 160 +indicate that this is the last chunk of input data to compress. We need to use <tt>feof()</tt> 161 +to check for end-of-file as opposed to seeing if fewer than <tt>CHUNK</tt> bytes have been read. The 162 +reason is that if the input file length is an exact multiple of <tt>CHUNK</tt>, we will miss 163 +the fact that we got to the end-of-file, and not know to tell <tt>deflate()</tt> to finish 164 +up the compressed stream. If we are not yet at the end of the input, then the <em>zlib</em> 165 +constant <tt>Z_NO_FLUSH</tt> will be passed to <tt>deflate</tt> to indicate that we are still 166 +in the middle of the uncompressed data. 167 +<p> 168 +If there is an error in reading from the input file, the process is aborted with 169 +<tt>deflateEnd()</tt> being called to free the allocated <em>zlib</em> state before returning 170 +the error. We wouldn't want a memory leak, now would we? <tt>deflateEnd()</tt> can be called 171 +at any time after the state has been initialized. Once that's done, <tt>deflateInit()</tt> (or 172 +<tt>deflateInit2()</tt>) would have to be called to start a new compression process. There is 173 +no point here in checking the <tt>deflateEnd()</tt> return code. The deallocation can't fail. 174 +<pre><b> 175 + strm.avail_in = fread(in, 1, CHUNK, source); 176 + if (ferror(source)) { 177 + (void)deflateEnd(&strm); 178 + return Z_ERRNO; 179 + } 180 + flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; 181 + strm.next_in = in; 182 +</b></pre><!-- --> 183 +The inner <tt>do</tt>-loop passes our chunk of input data to <tt>deflate()</tt>, and then 184 +keeps calling <tt>deflate()</tt> until it is done producing output. Once there is no more 185 +new output, <tt>deflate()</tt> is guaranteed to have consumed all of the input, i.e., 186 +<tt>avail_in</tt> will be zero. 187 +<pre><b> 188 + /* run deflate() on input until output buffer not full, finish 189 + compression if all of source has been read in */ 190 + do { 191 +</b></pre> 192 +Output space is provided to <tt>deflate()</tt> by setting <tt>avail_out</tt> to the number 193 +of available output bytes and <tt>next_out</tt> to a pointer to that space. 194 +<pre><b> 195 + strm.avail_out = CHUNK; 196 + strm.next_out = out; 197 +</b></pre> 198 +Now we call the compression engine itself, <tt>deflate()</tt>. It takes as many of the 199 +<tt>avail_in</tt> bytes at <tt>next_in</tt> as it can process, and writes as many as 200 +<tt>avail_out</tt> bytes to <tt>next_out</tt>. Those counters and pointers are then 201 +updated past the input data consumed and the output data written. It is the amount of 202 +output space available that may limit how much input is consumed. 203 +Hence the inner loop to make sure that 204 +all of the input is consumed by providing more output space each time. Since <tt>avail_in</tt> 205 +and <tt>next_in</tt> are updated by <tt>deflate()</tt>, we don't have to mess with those 206 +between <tt>deflate()</tt> calls until it's all used up. 207 +<p> 208 +The parameters to <tt>deflate()</tt> are a pointer to the <tt>strm</tt> structure containing 209 +the input and output information and the internal compression engine state, and a parameter 210 +indicating whether and how to flush data to the output. Normally <tt>deflate</tt> will consume 211 +several K bytes of input data before producing any output (except for the header), in order 212 +to accumulate statistics on the data for optimum compression. It will then put out a burst of 213 +compressed data, and proceed to consume more input before the next burst. Eventually, 214 +<tt>deflate()</tt> 215 +must be told to terminate the stream, complete the compression with provided input data, and 216 +write out the trailer check value. <tt>deflate()</tt> will continue to compress normally as long 217 +as the flush parameter is <tt>Z_NO_FLUSH</tt>. Once the <tt>Z_FINISH</tt> parameter is provided, 218 +<tt>deflate()</tt> will begin to complete the compressed output stream. However depending on how 219 +much output space is provided, <tt>deflate()</tt> may have to be called several times until it 220 +has provided the complete compressed stream, even after it has consumed all of the input. The flush 221 +parameter must continue to be <tt>Z_FINISH</tt> for those subsequent calls. 222 +<p> 223 +There are other values of the flush parameter that are used in more advanced applications. You can 224 +force <tt>deflate()</tt> to produce a burst of output that encodes all of the input data provided 225 +so far, even if it wouldn't have otherwise, for example to control data latency on a link with 226 +compressed data. You can also ask that <tt>deflate()</tt> do that as well as erase any history up to 227 +that point so that what follows can be decompressed independently, for example for random access 228 +applications. Both requests will degrade compression by an amount depending on how often such 229 +requests are made. 230 +<p> 231 +<tt>deflate()</tt> has a return value that can indicate errors, yet we do not check it here. Why 232 +not? Well, it turns out that <tt>deflate()</tt> can do no wrong here. Let's go through 233 +<tt>deflate()</tt>'s return values and dispense with them one by one. The possible values are 234 +<tt>Z_OK</tt>, <tt>Z_STREAM_END</tt>, <tt>Z_STREAM_ERROR</tt>, or <tt>Z_BUF_ERROR</tt>. <tt>Z_OK</tt> 235 +is, well, ok. <tt>Z_STREAM_END</tt> is also ok and will be returned for the last call of 236 +<tt>deflate()</tt>. This is already guaranteed by calling <tt>deflate()</tt> with <tt>Z_FINISH</tt> 237 +until it has no more output. <tt>Z_STREAM_ERROR</tt> is only possible if the stream is not 238 +initialized properly, but we did initialize it properly. There is no harm in checking for 239 +<tt>Z_STREAM_ERROR</tt> here, for example to check for the possibility that some 240 +other part of the application inadvertently clobbered the memory containing the <em>zlib</em> state. 241 +<tt>Z_BUF_ERROR</tt> will be explained further below, but 242 +suffice it to say that this is simply an indication that <tt>deflate()</tt> could not consume 243 +more input or produce more output. <tt>deflate()</tt> can be called again with more output space 244 +or more available input, which it will be in this code. 245 +<pre><b> 246 + ret = deflate(&strm, flush); /* no bad return value */ 247 + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ 248 +</b></pre> 249 +Now we compute how much output <tt>deflate()</tt> provided on the last call, which is the 250 +difference between how much space was provided before the call, and how much output space 251 +is still available after the call. Then that data, if any, is written to the output file. 252 +We can then reuse the output buffer for the next call of <tt>deflate()</tt>. Again if there 253 +is a file i/o error, we call <tt>deflateEnd()</tt> before returning to avoid a memory leak. 254 +<pre><b> 255 + have = CHUNK - strm.avail_out; 256 + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { 257 + (void)deflateEnd(&strm); 258 + return Z_ERRNO; 259 + } 260 +</b></pre> 261 +The inner <tt>do</tt>-loop is repeated until the last <tt>deflate()</tt> call fails to fill the 262 +provided output buffer. Then we know that <tt>deflate()</tt> has done as much as it can with 263 +the provided input, and that all of that input has been consumed. We can then fall out of this 264 +loop and reuse the input buffer. 265 +<p> 266 +The way we tell that <tt>deflate()</tt> has no more output is by seeing that it did not fill 267 +the output buffer, leaving <tt>avail_out</tt> greater than zero. However suppose that 268 +<tt>deflate()</tt> has no more output, but just so happened to exactly fill the output buffer! 269 +<tt>avail_out</tt> is zero, and we can't tell that <tt>deflate()</tt> has done all it can. 270 +As far as we know, <tt>deflate()</tt> 271 +has more output for us. So we call it again. But now <tt>deflate()</tt> produces no output 272 +at all, and <tt>avail_out</tt> remains unchanged as <tt>CHUNK</tt>. That <tt>deflate()</tt> call 273 +wasn't able to do anything, either consume input or produce output, and so it returns 274 +<tt>Z_BUF_ERROR</tt>. (See, I told you I'd cover this later.) However this is not a problem at 275 +all. Now we finally have the desired indication that <tt>deflate()</tt> is really done, 276 +and so we drop out of the inner loop to provide more input to <tt>deflate()</tt>. 277 +<p> 278 +With <tt>flush</tt> set to <tt>Z_FINISH</tt>, this final set of <tt>deflate()</tt> calls will 279 +complete the output stream. Once that is done, subsequent calls of <tt>deflate()</tt> would return 280 +<tt>Z_STREAM_ERROR</tt> if the flush parameter is not <tt>Z_FINISH</tt>, and do no more processing 281 +until the state is reinitialized. 282 +<p> 283 +Some applications of <em>zlib</em> have two loops that call <tt>deflate()</tt> 284 +instead of the single inner loop we have here. The first loop would call 285 +without flushing and feed all of the data to <tt>deflate()</tt>. The second loop would call 286 +<tt>deflate()</tt> with no more 287 +data and the <tt>Z_FINISH</tt> parameter to complete the process. As you can see from this 288 +example, that can be avoided by simply keeping track of the current flush state. 289 +<pre><b> 290 + } while (strm.avail_out == 0); 291 + assert(strm.avail_in == 0); /* all input will be used */ 292 +</b></pre><!-- --> 293 +Now we check to see if we have already processed all of the input file. That information was 294 +saved in the <tt>flush</tt> variable, so we see if that was set to <tt>Z_FINISH</tt>. If so, 295 +then we're done and we fall out of the outer loop. We're guaranteed to get <tt>Z_STREAM_END</tt> 296 +from the last <tt>deflate()</tt> call, since we ran it until the last chunk of input was 297 +consumed and all of the output was generated. 298 +<pre><b> 299 + /* done when last data in file processed */ 300 + } while (flush != Z_FINISH); 301 + assert(ret == Z_STREAM_END); /* stream will be complete */ 302 +</b></pre><!-- --> 303 +The process is complete, but we still need to deallocate the state to avoid a memory leak 304 +(or rather more like a memory hemorrhage if you didn't do this). Then 305 +finally we can return with a happy return value. 306 +<pre><b> 307 + /* clean up and return */ 308 + (void)deflateEnd(&strm); 309 + return Z_OK; 310 +} 311 +</b></pre><!-- --> 312 +Now we do the same thing for decompression in the <tt>inf()</tt> routine. <tt>inf()</tt> 313 +decompresses what is hopefully a valid <em>zlib</em> stream from the input file and writes the 314 +uncompressed data to the output file. Much of the discussion above for <tt>def()</tt> 315 +applies to <tt>inf()</tt> as well, so the discussion here will focus on the differences between 316 +the two. 317 +<pre><b> 318 +/* Decompress from file source to file dest until stream ends or EOF. 319 + inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be 320 + allocated for processing, Z_DATA_ERROR if the deflate data is 321 + invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and 322 + the version of the library linked do not match, or Z_ERRNO if there 323 + is an error reading or writing the files. */ 324 +int inf(FILE *source, FILE *dest) 325 +{ 326 +</b></pre> 327 +The local variables have the same functionality as they do for <tt>def()</tt>. The 328 +only difference is that there is no <tt>flush</tt> variable, since <tt>inflate()</tt> 329 +can tell from the <em>zlib</em> stream itself when the stream is complete. 330 +<pre><b> 331 + int ret; 332 + unsigned have; 333 + z_stream strm; 334 + unsigned char in[CHUNK]; 335 + unsigned char out[CHUNK]; 336 +</b></pre><!-- --> 337 +The initialization of the state is the same, except that there is no compression level, 338 +of course, and two more elements of the structure are initialized. <tt>avail_in</tt> 339 +and <tt>next_in</tt> must be initialized before calling <tt>inflateInit()</tt>. This 340 +is because the application has the option to provide the start of the zlib stream in 341 +order for <tt>inflateInit()</tt> to have access to information about the compression 342 +method to aid in memory allocation. In the current implementation of <em>zlib</em> 343 +(up through versions 1.2.x), the method-dependent memory allocations are deferred to the first call of 344 +<tt>inflate()</tt> anyway. However those fields must be initialized since later versions 345 +of <em>zlib</em> that provide more compression methods may take advantage of this interface. 346 +In any case, no decompression is performed by <tt>inflateInit()</tt>, so the 347 +<tt>avail_out</tt> and <tt>next_out</tt> fields do not need to be initialized before calling. 348 +<p> 349 +Here <tt>avail_in</tt> is set to zero and <tt>next_in</tt> is set to <tt>Z_NULL</tt> to 350 +indicate that no input data is being provided. 351 +<pre><b> 352 + /* allocate inflate state */ 353 + strm.zalloc = Z_NULL; 354 + strm.zfree = Z_NULL; 355 + strm.opaque = Z_NULL; 356 + strm.avail_in = 0; 357 + strm.next_in = Z_NULL; 358 + ret = inflateInit(&strm); 359 + if (ret != Z_OK) 360 + return ret; 361 +</b></pre><!-- --> 362 +The outer <tt>do</tt>-loop decompresses input until <tt>inflate()</tt> indicates 363 +that it has reached the end of the compressed data and has produced all of the uncompressed 364 +output. This is in contrast to <tt>def()</tt> which processes all of the input file. 365 +If end-of-file is reached before the compressed data self-terminates, then the compressed 366 +data is incomplete and an error is returned. 367 +<pre><b> 368 + /* decompress until deflate stream ends or end of file */ 369 + do { 370 +</b></pre> 371 +We read input data and set the <tt>strm</tt> structure accordingly. If we've reached the 372 +end of the input file, then we leave the outer loop and report an error, since the 373 +compressed data is incomplete. Note that we may read more data than is eventually consumed 374 +by <tt>inflate()</tt>, if the input file continues past the <em>zlib</em> stream. 375 +For applications where <em>zlib</em> streams are embedded in other data, this routine would 376 +need to be modified to return the unused data, or at least indicate how much of the input 377 +data was not used, so the application would know where to pick up after the <em>zlib</em> stream. 378 +<pre><b> 379 + strm.avail_in = fread(in, 1, CHUNK, source); 380 + if (ferror(source)) { 381 + (void)inflateEnd(&strm); 382 + return Z_ERRNO; 383 + } 384 + if (strm.avail_in == 0) 385 + break; 386 + strm.next_in = in; 387 +</b></pre><!-- --> 388 +The inner <tt>do</tt>-loop has the same function it did in <tt>def()</tt>, which is to 389 +keep calling <tt>inflate()</tt> until has generated all of the output it can with the 390 +provided input. 391 +<pre><b> 392 + /* run inflate() on input until output buffer not full */ 393 + do { 394 +</b></pre> 395 +Just like in <tt>def()</tt>, the same output space is provided for each call of <tt>inflate()</tt>. 396 +<pre><b> 397 + strm.avail_out = CHUNK; 398 + strm.next_out = out; 399 +</b></pre> 400 +Now we run the decompression engine itself. There is no need to adjust the flush parameter, since 401 +the <em>zlib</em> format is self-terminating. The main difference here is that there are 402 +return values that we need to pay attention to. <tt>Z_DATA_ERROR</tt> 403 +indicates that <tt>inflate()</tt> detected an error in the <em>zlib</em> compressed data format, 404 +which means that either the data is not a <em>zlib</em> stream to begin with, or that the data was 405 +corrupted somewhere along the way since it was compressed. The other error to be processed is 406 +<tt>Z_MEM_ERROR</tt>, which can occur since memory allocation is deferred until <tt>inflate()</tt> 407 +needs it, unlike <tt>deflate()</tt>, whose memory is allocated at the start by <tt>deflateInit()</tt>. 408 +<p> 409 +Advanced applications may use 410 +<tt>deflateSetDictionary()</tt> to prime <tt>deflate()</tt> with a set of likely data to improve the 411 +first 32K or so of compression. This is noted in the <em>zlib</em> header, so <tt>inflate()</tt> 412 +requests that that dictionary be provided before it can start to decompress. Without the dictionary, 413 +correct decompression is not possible. For this routine, we have no idea what the dictionary is, 414 +so the <tt>Z_NEED_DICT</tt> indication is converted to a <tt>Z_DATA_ERROR</tt>. 415 +<p> 416 +<tt>inflate()</tt> can also return <tt>Z_STREAM_ERROR</tt>, which should not be possible here, 417 +but could be checked for as noted above for <tt>def()</tt>. <tt>Z_BUF_ERROR</tt> does not need to be 418 +checked for here, for the same reasons noted for <tt>def()</tt>. <tt>Z_STREAM_END</tt> will be 419 +checked for later. 420 +<pre><b> 421 + ret = inflate(&strm, Z_NO_FLUSH); 422 + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ 423 + switch (ret) { 424 + case Z_NEED_DICT: 425 + ret = Z_DATA_ERROR; /* and fall through */ 426 + case Z_DATA_ERROR: 427 + case Z_MEM_ERROR: 428 + (void)inflateEnd(&strm); 429 + return ret; 430 + } 431 +</b></pre> 432 +The output of <tt>inflate()</tt> is handled identically to that of <tt>deflate()</tt>. 433 +<pre><b> 434 + have = CHUNK - strm.avail_out; 435 + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { 436 + (void)inflateEnd(&strm); 437 + return Z_ERRNO; 438 + } 439 +</b></pre> 440 +The inner <tt>do</tt>-loop ends when <tt>inflate()</tt> has no more output as indicated 441 +by not filling the output buffer, just as for <tt>deflate()</tt>. In this case, we cannot 442 +assert that <tt>strm.avail_in</tt> will be zero, since the deflate stream may end before the file 443 +does. 444 +<pre><b> 445 + } while (strm.avail_out == 0); 446 +</b></pre><!-- --> 447 +The outer <tt>do</tt>-loop ends when <tt>inflate()</tt> reports that it has reached the 448 +end of the input <em>zlib</em> stream, has completed the decompression and integrity 449 +check, and has provided all of the output. This is indicated by the <tt>inflate()</tt> 450 +return value <tt>Z_STREAM_END</tt>. The inner loop is guaranteed to leave <tt>ret</tt> 451 +equal to <tt>Z_STREAM_END</tt> if the last chunk of the input file read contained the end 452 +of the <em>zlib</em> stream. So if the return value is not <tt>Z_STREAM_END</tt>, the 453 +loop continues to read more input. 454 +<pre><b> 455 + /* done when inflate() says it's done */ 456 + } while (ret != Z_STREAM_END); 457 +</b></pre><!-- --> 458 +At this point, decompression successfully completed, or we broke out of the loop due to no 459 +more data being available from the input file. If the last <tt>inflate()</tt> return value 460 +is not <tt>Z_STREAM_END</tt>, then the <em>zlib</em> stream was incomplete and a data error 461 +is returned. Otherwise, we return with a happy return value. Of course, <tt>inflateEnd()</tt> 462 +is called first to avoid a memory leak. 463 +<pre><b> 464 + /* clean up and return */ 465 + (void)inflateEnd(&strm); 466 + return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 467 +} 468 +</b></pre><!-- --> 469 +That ends the routines that directly use <em>zlib</em>. The following routines make this 470 +a command-line program by running data through the above routines from <tt>stdin</tt> to 471 +<tt>stdout</tt>, and handling any errors reported by <tt>def()</tt> or <tt>inf()</tt>. 472 +<p> 473 +<tt>zerr()</tt> is used to interpret the possible error codes from <tt>def()</tt> 474 +and <tt>inf()</tt>, as detailed in their comments above, and print out an error message. 475 +Note that these are only a subset of the possible return values from <tt>deflate()</tt> 476 +and <tt>inflate()</tt>. 477 +<pre><b> 478 +/* report a zlib or i/o error */ 479 +void zerr(int ret) 480 +{ 481 + fputs("zpipe: ", stderr); 482 + switch (ret) { 483 + case Z_ERRNO: 484 + if (ferror(stdin)) 485 + fputs("error reading stdin\n", stderr); 486 + if (ferror(stdout)) 487 + fputs("error writing stdout\n", stderr); 488 + break; 489 + case Z_STREAM_ERROR: 490 + fputs("invalid compression level\n", stderr); 491 + break; 492 + case Z_DATA_ERROR: 493 + fputs("invalid or incomplete deflate data\n", stderr); 494 + break; 495 + case Z_MEM_ERROR: 496 + fputs("out of memory\n", stderr); 497 + break; 498 + case Z_VERSION_ERROR: 499 + fputs("zlib version mismatch!\n", stderr); 500 + } 501 +} 502 +</b></pre><!-- --> 503 +Here is the <tt>main()</tt> routine used to test <tt>def()</tt> and <tt>inf()</tt>. The 504 +<tt>zpipe</tt> command is simply a compression pipe from <tt>stdin</tt> to <tt>stdout</tt>, if 505 +no arguments are given, or it is a decompression pipe if <tt>zpipe -d</tt> is used. If any other 506 +arguments are provided, no compression or decompression is performed. Instead a usage 507 +message is displayed. Examples are <tt>zpipe < foo.txt > foo.txt.z</tt> to compress, and 508 +<tt>zpipe -d < foo.txt.z > foo.txt</tt> to decompress. 509 +<pre><b> 510 +/* compress or decompress from stdin to stdout */ 511 +int main(int argc, char **argv) 512 +{ 513 + int ret; 514 + 515 + /* avoid end-of-line conversions */ 516 + SET_BINARY_MODE(stdin); 517 + SET_BINARY_MODE(stdout); 518 + 519 + /* do compression if no arguments */ 520 + if (argc == 1) { 521 + ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); 522 + if (ret != Z_OK) 523 + zerr(ret); 524 + return ret; 525 + } 526 + 527 + /* do decompression if -d specified */ 528 + else if (argc == 2 && strcmp(argv[1], "-d") == 0) { 529 + ret = inf(stdin, stdout); 530 + if (ret != Z_OK) 531 + zerr(ret); 532 + return ret; 533 + } 534 + 535 + /* otherwise, report usage */ 536 + else { 537 + fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); 538 + return 1; 539 + } 540 +} 541 +</b></pre> 542 +<hr> 543 +<i>Copyright (c) 2004, 2005 by Mark Adler<br>Last modified 11 December 2005</i> 544 +</body> 545 +</html>
Added compat/zlib/examples/zpipe.c.
1 +/* zpipe.c: example of proper use of zlib's inflate() and deflate() 2 + Not copyrighted -- provided to the public domain 3 + Version 1.4 11 December 2005 Mark Adler */ 4 + 5 +/* Version history: 6 + 1.0 30 Oct 2004 First version 7 + 1.1 8 Nov 2004 Add void casting for unused return values 8 + Use switch statement for inflate() return values 9 + 1.2 9 Nov 2004 Add assertions to document zlib guarantees 10 + 1.3 6 Apr 2005 Remove incorrect assertion in inf() 11 + 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions 12 + Avoid some compiler warnings for input and output buffers 13 + */ 14 + 15 +#include <stdio.h> 16 +#include <string.h> 17 +#include <assert.h> 18 +#include "zlib.h" 19 + 20 +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 21 +# include <fcntl.h> 22 +# include <io.h> 23 +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 24 +#else 25 +# define SET_BINARY_MODE(file) 26 +#endif 27 + 28 +#define CHUNK 16384 29 + 30 +/* Compress from file source to file dest until EOF on source. 31 + def() returns Z_OK on success, Z_MEM_ERROR if memory could not be 32 + allocated for processing, Z_STREAM_ERROR if an invalid compression 33 + level is supplied, Z_VERSION_ERROR if the version of zlib.h and the 34 + version of the library linked do not match, or Z_ERRNO if there is 35 + an error reading or writing the files. */ 36 +int def(FILE *source, FILE *dest, int level) 37 +{ 38 + int ret, flush; 39 + unsigned have; 40 + z_stream strm; 41 + unsigned char in[CHUNK]; 42 + unsigned char out[CHUNK]; 43 + 44 + /* allocate deflate state */ 45 + strm.zalloc = Z_NULL; 46 + strm.zfree = Z_NULL; 47 + strm.opaque = Z_NULL; 48 + ret = deflateInit(&strm, level); 49 + if (ret != Z_OK) 50 + return ret; 51 + 52 + /* compress until end of file */ 53 + do { 54 + strm.avail_in = fread(in, 1, CHUNK, source); 55 + if (ferror(source)) { 56 + (void)deflateEnd(&strm); 57 + return Z_ERRNO; 58 + } 59 + flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; 60 + strm.next_in = in; 61 + 62 + /* run deflate() on input until output buffer not full, finish 63 + compression if all of source has been read in */ 64 + do { 65 + strm.avail_out = CHUNK; 66 + strm.next_out = out; 67 + ret = deflate(&strm, flush); /* no bad return value */ 68 + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ 69 + have = CHUNK - strm.avail_out; 70 + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { 71 + (void)deflateEnd(&strm); 72 + return Z_ERRNO; 73 + } 74 + } while (strm.avail_out == 0); 75 + assert(strm.avail_in == 0); /* all input will be used */ 76 + 77 + /* done when last data in file processed */ 78 + } while (flush != Z_FINISH); 79 + assert(ret == Z_STREAM_END); /* stream will be complete */ 80 + 81 + /* clean up and return */ 82 + (void)deflateEnd(&strm); 83 + return Z_OK; 84 +} 85 + 86 +/* Decompress from file source to file dest until stream ends or EOF. 87 + inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be 88 + allocated for processing, Z_DATA_ERROR if the deflate data is 89 + invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and 90 + the version of the library linked do not match, or Z_ERRNO if there 91 + is an error reading or writing the files. */ 92 +int inf(FILE *source, FILE *dest) 93 +{ 94 + int ret; 95 + unsigned have; 96 + z_stream strm; 97 + unsigned char in[CHUNK]; 98 + unsigned char out[CHUNK]; 99 + 100 + /* allocate inflate state */ 101 + strm.zalloc = Z_NULL; 102 + strm.zfree = Z_NULL; 103 + strm.opaque = Z_NULL; 104 + strm.avail_in = 0; 105 + strm.next_in = Z_NULL; 106 + ret = inflateInit(&strm); 107 + if (ret != Z_OK) 108 + return ret; 109 + 110 + /* decompress until deflate stream ends or end of file */ 111 + do { 112 + strm.avail_in = fread(in, 1, CHUNK, source); 113 + if (ferror(source)) { 114 + (void)inflateEnd(&strm); 115 + return Z_ERRNO; 116 + } 117 + if (strm.avail_in == 0) 118 + break; 119 + strm.next_in = in; 120 + 121 + /* run inflate() on input until output buffer not full */ 122 + do { 123 + strm.avail_out = CHUNK; 124 + strm.next_out = out; 125 + ret = inflate(&strm, Z_NO_FLUSH); 126 + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ 127 + switch (ret) { 128 + case Z_NEED_DICT: 129 + ret = Z_DATA_ERROR; /* and fall through */ 130 + case Z_DATA_ERROR: 131 + case Z_MEM_ERROR: 132 + (void)inflateEnd(&strm); 133 + return ret; 134 + } 135 + have = CHUNK - strm.avail_out; 136 + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { 137 + (void)inflateEnd(&strm); 138 + return Z_ERRNO; 139 + } 140 + } while (strm.avail_out == 0); 141 + 142 + /* done when inflate() says it's done */ 143 + } while (ret != Z_STREAM_END); 144 + 145 + /* clean up and return */ 146 + (void)inflateEnd(&strm); 147 + return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 148 +} 149 + 150 +/* report a zlib or i/o error */ 151 +void zerr(int ret) 152 +{ 153 + fputs("zpipe: ", stderr); 154 + switch (ret) { 155 + case Z_ERRNO: 156 + if (ferror(stdin)) 157 + fputs("error reading stdin\n", stderr); 158 + if (ferror(stdout)) 159 + fputs("error writing stdout\n", stderr); 160 + break; 161 + case Z_STREAM_ERROR: 162 + fputs("invalid compression level\n", stderr); 163 + break; 164 + case Z_DATA_ERROR: 165 + fputs("invalid or incomplete deflate data\n", stderr); 166 + break; 167 + case Z_MEM_ERROR: 168 + fputs("out of memory\n", stderr); 169 + break; 170 + case Z_VERSION_ERROR: 171 + fputs("zlib version mismatch!\n", stderr); 172 + } 173 +} 174 + 175 +/* compress or decompress from stdin to stdout */ 176 +int main(int argc, char **argv) 177 +{ 178 + int ret; 179 + 180 + /* avoid end-of-line conversions */ 181 + SET_BINARY_MODE(stdin); 182 + SET_BINARY_MODE(stdout); 183 + 184 + /* do compression if no arguments */ 185 + if (argc == 1) { 186 + ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); 187 + if (ret != Z_OK) 188 + zerr(ret); 189 + return ret; 190 + } 191 + 192 + /* do decompression if -d specified */ 193 + else if (argc == 2 && strcmp(argv[1], "-d") == 0) { 194 + ret = inf(stdin, stdout); 195 + if (ret != Z_OK) 196 + zerr(ret); 197 + return ret; 198 + } 199 + 200 + /* otherwise, report usage */ 201 + else { 202 + fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); 203 + return 1; 204 + } 205 +}
Added compat/zlib/examples/zran.c.
1 +/* zran.c -- example of zlib/gzip stream indexing and random access 2 + * Copyright (C) 2005 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + Version 1.0 29 May 2005 Mark Adler */ 5 + 6 +/* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary() 7 + for random access of a compressed file. A file containing a zlib or gzip 8 + stream is provided on the command line. The compressed stream is decoded in 9 + its entirety, and an index built with access points about every SPAN bytes 10 + in the uncompressed output. The compressed file is left open, and can then 11 + be read randomly, having to decompress on the average SPAN/2 uncompressed 12 + bytes before getting to the desired block of data. 13 + 14 + An access point can be created at the start of any deflate block, by saving 15 + the starting file offset and bit of that block, and the 32K bytes of 16 + uncompressed data that precede that block. Also the uncompressed offset of 17 + that block is saved to provide a referece for locating a desired starting 18 + point in the uncompressed stream. build_index() works by decompressing the 19 + input zlib or gzip stream a block at a time, and at the end of each block 20 + deciding if enough uncompressed data has gone by to justify the creation of 21 + a new access point. If so, that point is saved in a data structure that 22 + grows as needed to accommodate the points. 23 + 24 + To use the index, an offset in the uncompressed data is provided, for which 25 + the latest accees point at or preceding that offset is located in the index. 26 + The input file is positioned to the specified location in the index, and if 27 + necessary the first few bits of the compressed data is read from the file. 28 + inflate is initialized with those bits and the 32K of uncompressed data, and 29 + the decompression then proceeds until the desired offset in the file is 30 + reached. Then the decompression continues to read the desired uncompressed 31 + data from the file. 32 + 33 + Another approach would be to generate the index on demand. In that case, 34 + requests for random access reads from the compressed data would try to use 35 + the index, but if a read far enough past the end of the index is required, 36 + then further index entries would be generated and added. 37 + 38 + There is some fair bit of overhead to starting inflation for the random 39 + access, mainly copying the 32K byte dictionary. So if small pieces of the 40 + file are being accessed, it would make sense to implement a cache to hold 41 + some lookahead and avoid many calls to extract() for small lengths. 42 + 43 + Another way to build an index would be to use inflateCopy(). That would 44 + not be constrained to have access points at block boundaries, but requires 45 + more memory per access point, and also cannot be saved to file due to the 46 + use of pointers in the state. The approach here allows for storage of the 47 + index in a file. 48 + */ 49 + 50 +#include <stdio.h> 51 +#include <stdlib.h> 52 +#include <string.h> 53 +#include "zlib.h" 54 + 55 +#define local static 56 + 57 +#define SPAN 1048576L /* desired distance between access points */ 58 +#define WINSIZE 32768U /* sliding window size */ 59 +#define CHUNK 16384 /* file input buffer size */ 60 + 61 +/* access point entry */ 62 +struct point { 63 + off_t out; /* corresponding offset in uncompressed data */ 64 + off_t in; /* offset in input file of first full byte */ 65 + int bits; /* number of bits (1-7) from byte at in - 1, or 0 */ 66 + unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */ 67 +}; 68 + 69 +/* access point list */ 70 +struct access { 71 + int have; /* number of list entries filled in */ 72 + int size; /* number of list entries allocated */ 73 + struct point *list; /* allocated list */ 74 +}; 75 + 76 +/* Deallocate an index built by build_index() */ 77 +local void free_index(struct access *index) 78 +{ 79 + if (index != NULL) { 80 + free(index->list); 81 + free(index); 82 + } 83 +} 84 + 85 +/* Add an entry to the access point list. If out of memory, deallocate the 86 + existing list and return NULL. */ 87 +local struct access *addpoint(struct access *index, int bits, 88 + off_t in, off_t out, unsigned left, unsigned char *window) 89 +{ 90 + struct point *next; 91 + 92 + /* if list is empty, create it (start with eight points) */ 93 + if (index == NULL) { 94 + index = malloc(sizeof(struct access)); 95 + if (index == NULL) return NULL; 96 + index->list = malloc(sizeof(struct point) << 3); 97 + if (index->list == NULL) { 98 + free(index); 99 + return NULL; 100 + } 101 + index->size = 8; 102 + index->have = 0; 103 + } 104 + 105 + /* if list is full, make it bigger */ 106 + else if (index->have == index->size) { 107 + index->size <<= 1; 108 + next = realloc(index->list, sizeof(struct point) * index->size); 109 + if (next == NULL) { 110 + free_index(index); 111 + return NULL; 112 + } 113 + index->list = next; 114 + } 115 + 116 + /* fill in entry and increment how many we have */ 117 + next = index->list + index->have; 118 + next->bits = bits; 119 + next->in = in; 120 + next->out = out; 121 + if (left) 122 + memcpy(next->window, window + WINSIZE - left, left); 123 + if (left < WINSIZE) 124 + memcpy(next->window + left, window, WINSIZE - left); 125 + index->have++; 126 + 127 + /* return list, possibly reallocated */ 128 + return index; 129 +} 130 + 131 +/* Make one entire pass through the compressed stream and build an index, with 132 + access points about every span bytes of uncompressed output -- span is 133 + chosen to balance the speed of random access against the memory requirements 134 + of the list, about 32K bytes per access point. Note that data after the end 135 + of the first zlib or gzip stream in the file is ignored. build_index() 136 + returns the number of access points on success (>= 1), Z_MEM_ERROR for out 137 + of memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a 138 + file read error. On success, *built points to the resulting index. */ 139 +local int build_index(FILE *in, off_t span, struct access **built) 140 +{ 141 + int ret; 142 + off_t totin, totout; /* our own total counters to avoid 4GB limit */ 143 + off_t last; /* totout value of last access point */ 144 + struct access *index; /* access points being generated */ 145 + z_stream strm; 146 + unsigned char input[CHUNK]; 147 + unsigned char window[WINSIZE]; 148 + 149 + /* initialize inflate */ 150 + strm.zalloc = Z_NULL; 151 + strm.zfree = Z_NULL; 152 + strm.opaque = Z_NULL; 153 + strm.avail_in = 0; 154 + strm.next_in = Z_NULL; 155 + ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */ 156 + if (ret != Z_OK) 157 + return ret; 158 + 159 + /* inflate the input, maintain a sliding window, and build an index -- this 160 + also validates the integrity of the compressed data using the check 161 + information at the end of the gzip or zlib stream */ 162 + totin = totout = last = 0; 163 + index = NULL; /* will be allocated by first addpoint() */ 164 + strm.avail_out = 0; 165 + do { 166 + /* get some compressed data from input file */ 167 + strm.avail_in = fread(input, 1, CHUNK, in); 168 + if (ferror(in)) { 169 + ret = Z_ERRNO; 170 + goto build_index_error; 171 + } 172 + if (strm.avail_in == 0) { 173 + ret = Z_DATA_ERROR; 174 + goto build_index_error; 175 + } 176 + strm.next_in = input; 177 + 178 + /* process all of that, or until end of stream */ 179 + do { 180 + /* reset sliding window if necessary */ 181 + if (strm.avail_out == 0) { 182 + strm.avail_out = WINSIZE; 183 + strm.next_out = window; 184 + } 185 + 186 + /* inflate until out of input, output, or at end of block -- 187 + update the total input and output counters */ 188 + totin += strm.avail_in; 189 + totout += strm.avail_out; 190 + ret = inflate(&strm, Z_BLOCK); /* return at end of block */ 191 + totin -= strm.avail_in; 192 + totout -= strm.avail_out; 193 + if (ret == Z_NEED_DICT) 194 + ret = Z_DATA_ERROR; 195 + if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) 196 + goto build_index_error; 197 + if (ret == Z_STREAM_END) 198 + break; 199 + 200 + /* if at end of block, consider adding an index entry (note that if 201 + data_type indicates an end-of-block, then all of the 202 + uncompressed data from that block has been delivered, and none 203 + of the compressed data after that block has been consumed, 204 + except for up to seven bits) -- the totout == 0 provides an 205 + entry point after the zlib or gzip header, and assures that the 206 + index always has at least one access point; we avoid creating an 207 + access point after the last block by checking bit 6 of data_type 208 + */ 209 + if ((strm.data_type & 128) && !(strm.data_type & 64) && 210 + (totout == 0 || totout - last > span)) { 211 + index = addpoint(index, strm.data_type & 7, totin, 212 + totout, strm.avail_out, window); 213 + if (index == NULL) { 214 + ret = Z_MEM_ERROR; 215 + goto build_index_error; 216 + } 217 + last = totout; 218 + } 219 + } while (strm.avail_in != 0); 220 + } while (ret != Z_STREAM_END); 221 + 222 + /* clean up and return index (release unused entries in list) */ 223 + (void)inflateEnd(&strm); 224 + index = realloc(index, sizeof(struct point) * index->have); 225 + index->size = index->have; 226 + *built = index; 227 + return index->size; 228 + 229 + /* return error */ 230 + build_index_error: 231 + (void)inflateEnd(&strm); 232 + if (index != NULL) 233 + free_index(index); 234 + return ret; 235 +} 236 + 237 +/* Use the index to read len bytes from offset into buf, return bytes read or 238 + negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past 239 + the end of the uncompressed data, then extract() will return a value less 240 + than len, indicating how much as actually read into buf. This function 241 + should not return a data error unless the file was modified since the index 242 + was generated. extract() may also return Z_ERRNO if there is an error on 243 + reading or seeking the input file. */ 244 +local int extract(FILE *in, struct access *index, off_t offset, 245 + unsigned char *buf, int len) 246 +{ 247 + int ret, skip; 248 + z_stream strm; 249 + struct point *here; 250 + unsigned char input[CHUNK]; 251 + unsigned char discard[WINSIZE]; 252 + 253 + /* proceed only if something reasonable to do */ 254 + if (len < 0) 255 + return 0; 256 + 257 + /* find where in stream to start */ 258 + here = index->list; 259 + ret = index->have; 260 + while (--ret && here[1].out <= offset) 261 + here++; 262 + 263 + /* initialize file and inflate state to start there */ 264 + strm.zalloc = Z_NULL; 265 + strm.zfree = Z_NULL; 266 + strm.opaque = Z_NULL; 267 + strm.avail_in = 0; 268 + strm.next_in = Z_NULL; 269 + ret = inflateInit2(&strm, -15); /* raw inflate */ 270 + if (ret != Z_OK) 271 + return ret; 272 + ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET); 273 + if (ret == -1) 274 + goto extract_ret; 275 + if (here->bits) { 276 + ret = getc(in); 277 + if (ret == -1) { 278 + ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR; 279 + goto extract_ret; 280 + } 281 + (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits)); 282 + } 283 + (void)inflateSetDictionary(&strm, here->window, WINSIZE); 284 + 285 + /* skip uncompressed bytes until offset reached, then satisfy request */ 286 + offset -= here->out; 287 + strm.avail_in = 0; 288 + skip = 1; /* while skipping to offset */ 289 + do { 290 + /* define where to put uncompressed data, and how much */ 291 + if (offset == 0 && skip) { /* at offset now */ 292 + strm.avail_out = len; 293 + strm.next_out = buf; 294 + skip = 0; /* only do this once */ 295 + } 296 + if (offset > WINSIZE) { /* skip WINSIZE bytes */ 297 + strm.avail_out = WINSIZE; 298 + strm.next_out = discard; 299 + offset -= WINSIZE; 300 + } 301 + else if (offset != 0) { /* last skip */ 302 + strm.avail_out = (unsigned)offset; 303 + strm.next_out = discard; 304 + offset = 0; 305 + } 306 + 307 + /* uncompress until avail_out filled, or end of stream */ 308 + do { 309 + if (strm.avail_in == 0) { 310 + strm.avail_in = fread(input, 1, CHUNK, in); 311 + if (ferror(in)) { 312 + ret = Z_ERRNO; 313 + goto extract_ret; 314 + } 315 + if (strm.avail_in == 0) { 316 + ret = Z_DATA_ERROR; 317 + goto extract_ret; 318 + } 319 + strm.next_in = input; 320 + } 321 + ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */ 322 + if (ret == Z_NEED_DICT) 323 + ret = Z_DATA_ERROR; 324 + if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) 325 + goto extract_ret; 326 + if (ret == Z_STREAM_END) 327 + break; 328 + } while (strm.avail_out != 0); 329 + 330 + /* if reach end of stream, then don't keep trying to get more */ 331 + if (ret == Z_STREAM_END) 332 + break; 333 + 334 + /* do until offset reached and requested data read, or stream ends */ 335 + } while (skip); 336 + 337 + /* compute number of uncompressed bytes read after offset */ 338 + ret = skip ? 0 : len - strm.avail_out; 339 + 340 + /* clean up and return bytes read or error */ 341 + extract_ret: 342 + (void)inflateEnd(&strm); 343 + return ret; 344 +} 345 + 346 +/* Demonstrate the use of build_index() and extract() by processing the file 347 + provided on the command line, and the extracting 16K from about 2/3rds of 348 + the way through the uncompressed output, and writing that to stdout. */ 349 +int main(int argc, char **argv) 350 +{ 351 + int len; 352 + off_t offset; 353 + FILE *in; 354 + struct access *index = NULL; 355 + unsigned char buf[CHUNK]; 356 + 357 + /* open input file */ 358 + if (argc != 2) { 359 + fprintf(stderr, "usage: zran file.gz\n"); 360 + return 1; 361 + } 362 + in = fopen(argv[1], "rb"); 363 + if (in == NULL) { 364 + fprintf(stderr, "zran: could not open %s for reading\n", argv[1]); 365 + return 1; 366 + } 367 + 368 + /* build index */ 369 + len = build_index(in, SPAN, &index); 370 + if (len < 0) { 371 + fclose(in); 372 + switch (len) { 373 + case Z_MEM_ERROR: 374 + fprintf(stderr, "zran: out of memory\n"); 375 + break; 376 + case Z_DATA_ERROR: 377 + fprintf(stderr, "zran: compressed data error in %s\n", argv[1]); 378 + break; 379 + case Z_ERRNO: 380 + fprintf(stderr, "zran: read error on %s\n", argv[1]); 381 + break; 382 + default: 383 + fprintf(stderr, "zran: error %d while building index\n", len); 384 + } 385 + return 1; 386 + } 387 + fprintf(stderr, "zran: built index with %d access points\n", len); 388 + 389 + /* use index by reading some bytes from an arbitrary offset */ 390 + offset = (index->list[index->have - 1].out << 1) / 3; 391 + len = extract(in, index, offset, buf, CHUNK); 392 + if (len < 0) 393 + fprintf(stderr, "zran: extraction failed: %s error\n", 394 + len == Z_MEM_ERROR ? "out of memory" : "input corrupted"); 395 + else { 396 + fwrite(buf, 1, len, stdout); 397 + fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset); 398 + } 399 + 400 + /* clean up and exit */ 401 + free_index(index); 402 + fclose(in); 403 + return 0; 404 +}
Added compat/zlib/gzclose.c.
1 +/* gzclose.c -- zlib gzclose() function 2 + * Copyright (C) 2004, 2010 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "gzguts.h" 7 + 8 +/* gzclose() is in a separate file so that it is linked in only if it is used. 9 + That way the other gzclose functions can be used instead to avoid linking in 10 + unneeded compression or decompression routines. */ 11 +int ZEXPORT gzclose(file) 12 + gzFile file; 13 +{ 14 +#ifndef NO_GZCOMPRESS 15 + gz_statep state; 16 + 17 + if (file == NULL) 18 + return Z_STREAM_ERROR; 19 + state = (gz_statep)file; 20 + 21 + return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 +#else 23 + return gzclose_r(file); 24 +#endif 25 +}
Added compat/zlib/gzguts.h.
1 +/* gzguts.h -- zlib internal header definitions for gz* operations 2 + * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#ifdef _LARGEFILE64_SOURCE 7 +# ifndef _LARGEFILE_SOURCE 8 +# define _LARGEFILE_SOURCE 1 9 +# endif 10 +# ifdef _FILE_OFFSET_BITS 11 +# undef _FILE_OFFSET_BITS 12 +# endif 13 +#endif 14 + 15 +#ifdef HAVE_HIDDEN 16 +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 +#else 18 +# define ZLIB_INTERNAL 19 +#endif 20 + 21 +#include <stdio.h> 22 +#include "zlib.h" 23 +#ifdef STDC 24 +# include <string.h> 25 +# include <stdlib.h> 26 +# include <limits.h> 27 +#endif 28 +#include <fcntl.h> 29 + 30 +#ifdef _WIN32 31 +# include <stddef.h> 32 +#endif 33 + 34 +#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 35 +# include <io.h> 36 +#endif 37 + 38 +#ifdef NO_DEFLATE /* for compatibility with old definition */ 39 +# define NO_GZCOMPRESS 40 +#endif 41 + 42 +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 43 +# ifndef HAVE_VSNPRINTF 44 +# define HAVE_VSNPRINTF 45 +# endif 46 +#endif 47 + 48 +#if defined(__CYGWIN__) 49 +# ifndef HAVE_VSNPRINTF 50 +# define HAVE_VSNPRINTF 51 +# endif 52 +#endif 53 + 54 +#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) 55 +# ifndef HAVE_VSNPRINTF 56 +# define HAVE_VSNPRINTF 57 +# endif 58 +#endif 59 + 60 +#ifndef HAVE_VSNPRINTF 61 +# ifdef MSDOS 62 +/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 63 + but for now we just assume it doesn't. */ 64 +# define NO_vsnprintf 65 +# endif 66 +# ifdef __TURBOC__ 67 +# define NO_vsnprintf 68 +# endif 69 +# ifdef WIN32 70 +/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 71 +# if !defined(vsnprintf) && !defined(NO_vsnprintf) 72 +# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 73 +# define vsnprintf _vsnprintf 74 +# endif 75 +# endif 76 +# endif 77 +# ifdef __SASC 78 +# define NO_vsnprintf 79 +# endif 80 +# ifdef VMS 81 +# define NO_vsnprintf 82 +# endif 83 +# ifdef __OS400__ 84 +# define NO_vsnprintf 85 +# endif 86 +# ifdef __MVS__ 87 +# define NO_vsnprintf 88 +# endif 89 +#endif 90 + 91 +#ifndef local 92 +# define local static 93 +#endif 94 +/* compile with -Dlocal if your debugger can't find static symbols */ 95 + 96 +/* gz* functions always use library allocation functions */ 97 +#ifndef STDC 98 + extern voidp malloc OF((uInt size)); 99 + extern void free OF((voidpf ptr)); 100 +#endif 101 + 102 +/* get errno and strerror definition */ 103 +#if defined UNDER_CE 104 +# include <windows.h> 105 +# define zstrerror() gz_strwinerror((DWORD)GetLastError()) 106 +#else 107 +# ifndef NO_STRERROR 108 +# include <errno.h> 109 +# define zstrerror() strerror(errno) 110 +# else 111 +# define zstrerror() "stdio error (consult errno)" 112 +# endif 113 +#endif 114 + 115 +/* provide prototypes for these when building zlib without LFS */ 116 +#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 117 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 118 + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 119 + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 120 + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 121 +#endif 122 + 123 +/* default memLevel */ 124 +#if MAX_MEM_LEVEL >= 8 125 +# define DEF_MEM_LEVEL 8 126 +#else 127 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL 128 +#endif 129 + 130 +/* default i/o buffer size -- double this for output when reading */ 131 +#define GZBUFSIZE 8192 132 + 133 +/* gzip modes, also provide a little integrity check on the passed structure */ 134 +#define GZ_NONE 0 135 +#define GZ_READ 7247 136 +#define GZ_WRITE 31153 137 +#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 138 + 139 +/* values for gz_state how */ 140 +#define LOOK 0 /* look for a gzip header */ 141 +#define COPY 1 /* copy input directly */ 142 +#define GZIP 2 /* decompress a gzip stream */ 143 + 144 +/* internal gzip file state data structure */ 145 +typedef struct { 146 + /* exposed contents for gzgetc() macro */ 147 + struct gzFile_s x; /* "x" for exposed */ 148 + /* x.have: number of bytes available at x.next */ 149 + /* x.next: next output data to deliver or write */ 150 + /* x.pos: current position in uncompressed data */ 151 + /* used for both reading and writing */ 152 + int mode; /* see gzip modes above */ 153 + int fd; /* file descriptor */ 154 + char *path; /* path or fd for error messages */ 155 + unsigned size; /* buffer size, zero if not allocated yet */ 156 + unsigned want; /* requested buffer size, default is GZBUFSIZE */ 157 + unsigned char *in; /* input buffer */ 158 + unsigned char *out; /* output buffer (double-sized when reading) */ 159 + int direct; /* 0 if processing gzip, 1 if transparent */ 160 + /* just for reading */ 161 + int how; /* 0: get header, 1: copy, 2: decompress */ 162 + z_off64_t start; /* where the gzip data started, for rewinding */ 163 + int eof; /* true if end of input file reached */ 164 + int past; /* true if read requested past end */ 165 + /* just for writing */ 166 + int level; /* compression level */ 167 + int strategy; /* compression strategy */ 168 + /* seek request */ 169 + z_off64_t skip; /* amount to skip (already rewound if backwards) */ 170 + int seek; /* true if seek request pending */ 171 + /* error information */ 172 + int err; /* error code */ 173 + char *msg; /* error message */ 174 + /* zlib inflate or deflate stream */ 175 + z_stream strm; /* stream structure in-place (not a pointer) */ 176 +} gz_state; 177 +typedef gz_state FAR *gz_statep; 178 + 179 +/* shared functions */ 180 +void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 181 +#if defined UNDER_CE 182 +char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 183 +#endif 184 + 185 +/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 186 + value -- needed when comparing unsigned to z_off64_t, which is signed 187 + (possible z_off64_t types off_t, off64_t, and long are all signed) */ 188 +#ifdef INT_MAX 189 +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 190 +#else 191 +unsigned ZLIB_INTERNAL gz_intmax OF((void)); 192 +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 193 +#endif
Added compat/zlib/gzlib.c.
1 +/* gzlib.c -- zlib functions common to reading and writing gzip files 2 + * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "gzguts.h" 7 + 8 +#if defined(_WIN32) && !defined(__BORLANDC__) 9 +# define LSEEK _lseeki64 10 +#else 11 +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 12 +# define LSEEK lseek64 13 +#else 14 +# define LSEEK lseek 15 +#endif 16 +#endif 17 + 18 +/* Local functions */ 19 +local void gz_reset OF((gz_statep)); 20 +local gzFile gz_open OF((const void *, int, const char *)); 21 + 22 +#if defined UNDER_CE 23 + 24 +/* Map the Windows error number in ERROR to a locale-dependent error message 25 + string and return a pointer to it. Typically, the values for ERROR come 26 + from GetLastError. 27 + 28 + The string pointed to shall not be modified by the application, but may be 29 + overwritten by a subsequent call to gz_strwinerror 30 + 31 + The gz_strwinerror function does not change the current setting of 32 + GetLastError. */ 33 +char ZLIB_INTERNAL *gz_strwinerror (error) 34 + DWORD error; 35 +{ 36 + static char buf[1024]; 37 + 38 + wchar_t *msgbuf; 39 + DWORD lasterr = GetLastError(); 40 + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 41 + | FORMAT_MESSAGE_ALLOCATE_BUFFER, 42 + NULL, 43 + error, 44 + 0, /* Default language */ 45 + (LPVOID)&msgbuf, 46 + 0, 47 + NULL); 48 + if (chars != 0) { 49 + /* If there is an \r\n appended, zap it. */ 50 + if (chars >= 2 51 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { 52 + chars -= 2; 53 + msgbuf[chars] = 0; 54 + } 55 + 56 + if (chars > sizeof (buf) - 1) { 57 + chars = sizeof (buf) - 1; 58 + msgbuf[chars] = 0; 59 + } 60 + 61 + wcstombs(buf, msgbuf, chars + 1); 62 + LocalFree(msgbuf); 63 + } 64 + else { 65 + sprintf(buf, "unknown win32 error (%ld)", error); 66 + } 67 + 68 + SetLastError(lasterr); 69 + return buf; 70 +} 71 + 72 +#endif /* UNDER_CE */ 73 + 74 +/* Reset gzip file state */ 75 +local void gz_reset(state) 76 + gz_statep state; 77 +{ 78 + state->x.have = 0; /* no output data available */ 79 + if (state->mode == GZ_READ) { /* for reading ... */ 80 + state->eof = 0; /* not at end of file */ 81 + state->past = 0; /* have not read past end yet */ 82 + state->how = LOOK; /* look for gzip header */ 83 + } 84 + state->seek = 0; /* no seek request pending */ 85 + gz_error(state, Z_OK, NULL); /* clear error */ 86 + state->x.pos = 0; /* no uncompressed data yet */ 87 + state->strm.avail_in = 0; /* no input data yet */ 88 +} 89 + 90 +/* Open a gzip file either by name or file descriptor. */ 91 +local gzFile gz_open(path, fd, mode) 92 + const void *path; 93 + int fd; 94 + const char *mode; 95 +{ 96 + gz_statep state; 97 + size_t len; 98 + int oflag; 99 +#ifdef O_CLOEXEC 100 + int cloexec = 0; 101 +#endif 102 +#ifdef O_EXCL 103 + int exclusive = 0; 104 +#endif 105 + 106 + /* check input */ 107 + if (path == NULL) 108 + return NULL; 109 + 110 + /* allocate gzFile structure to return */ 111 + state = malloc(sizeof(gz_state)); 112 + if (state == NULL) 113 + return NULL; 114 + state->size = 0; /* no buffers allocated yet */ 115 + state->want = GZBUFSIZE; /* requested buffer size */ 116 + state->msg = NULL; /* no error message yet */ 117 + 118 + /* interpret mode */ 119 + state->mode = GZ_NONE; 120 + state->level = Z_DEFAULT_COMPRESSION; 121 + state->strategy = Z_DEFAULT_STRATEGY; 122 + state->direct = 0; 123 + while (*mode) { 124 + if (*mode >= '0' && *mode <= '9') 125 + state->level = *mode - '0'; 126 + else 127 + switch (*mode) { 128 + case 'r': 129 + state->mode = GZ_READ; 130 + break; 131 +#ifndef NO_GZCOMPRESS 132 + case 'w': 133 + state->mode = GZ_WRITE; 134 + break; 135 + case 'a': 136 + state->mode = GZ_APPEND; 137 + break; 138 +#endif 139 + case '+': /* can't read and write at the same time */ 140 + free(state); 141 + return NULL; 142 + case 'b': /* ignore -- will request binary anyway */ 143 + break; 144 +#ifdef O_CLOEXEC 145 + case 'e': 146 + cloexec = 1; 147 + break; 148 +#endif 149 +#ifdef O_EXCL 150 + case 'x': 151 + exclusive = 1; 152 + break; 153 +#endif 154 + case 'f': 155 + state->strategy = Z_FILTERED; 156 + break; 157 + case 'h': 158 + state->strategy = Z_HUFFMAN_ONLY; 159 + break; 160 + case 'R': 161 + state->strategy = Z_RLE; 162 + break; 163 + case 'F': 164 + state->strategy = Z_FIXED; 165 + case 'T': 166 + state->direct = 1; 167 + default: /* could consider as an error, but just ignore */ 168 + ; 169 + } 170 + mode++; 171 + } 172 + 173 + /* must provide an "r", "w", or "a" */ 174 + if (state->mode == GZ_NONE) { 175 + free(state); 176 + return NULL; 177 + } 178 + 179 + /* can't force transparent read */ 180 + if (state->mode == GZ_READ) { 181 + if (state->direct) { 182 + free(state); 183 + return NULL; 184 + } 185 + state->direct = 1; /* for empty file */ 186 + } 187 + 188 + /* save the path name for error messages */ 189 +#ifdef _WIN32 190 + if (fd == -2) { 191 + len = wcstombs(NULL, path, 0); 192 + if (len == (size_t)-1) 193 + len = 0; 194 + } 195 + else 196 +#endif 197 + len = strlen(path); 198 + state->path = malloc(len + 1); 199 + if (state->path == NULL) { 200 + free(state); 201 + return NULL; 202 + } 203 +#ifdef _WIN32 204 + if (fd == -2) 205 + if (len) 206 + wcstombs(state->path, path, len + 1); 207 + else 208 + *(state->path) = 0; 209 + else 210 +#endif 211 + strcpy(state->path, path); 212 + 213 + /* compute the flags for open() */ 214 + oflag = 215 +#ifdef O_LARGEFILE 216 + O_LARGEFILE | 217 +#endif 218 +#ifdef O_BINARY 219 + O_BINARY | 220 +#endif 221 +#ifdef O_CLOEXEC 222 + (cloexec ? O_CLOEXEC : 0) | 223 +#endif 224 + (state->mode == GZ_READ ? 225 + O_RDONLY : 226 + (O_WRONLY | O_CREAT | 227 +#ifdef O_EXCL 228 + (exclusive ? O_EXCL : 0) | 229 +#endif 230 + (state->mode == GZ_WRITE ? 231 + O_TRUNC : 232 + O_APPEND))); 233 + 234 + /* open the file with the appropriate flags (or just use fd) */ 235 + state->fd = fd > -1 ? fd : ( 236 +#ifdef _WIN32 237 + fd == -2 ? _wopen(path, oflag, 0666) : 238 +#endif 239 + open(path, oflag, 0666)); 240 + if (state->fd == -1) { 241 + free(state->path); 242 + free(state); 243 + return NULL; 244 + } 245 + if (state->mode == GZ_APPEND) 246 + state->mode = GZ_WRITE; /* simplify later checks */ 247 + 248 + /* save the current position for rewinding (only if reading) */ 249 + if (state->mode == GZ_READ) { 250 + state->start = LSEEK(state->fd, 0, SEEK_CUR); 251 + if (state->start == -1) state->start = 0; 252 + } 253 + 254 + /* initialize stream */ 255 + gz_reset(state); 256 + 257 + /* return stream */ 258 + return (gzFile)state; 259 +} 260 + 261 +/* -- see zlib.h -- */ 262 +gzFile ZEXPORT gzopen(path, mode) 263 + const char *path; 264 + const char *mode; 265 +{ 266 + return gz_open(path, -1, mode); 267 +} 268 + 269 +/* -- see zlib.h -- */ 270 +gzFile ZEXPORT gzopen64(path, mode) 271 + const char *path; 272 + const char *mode; 273 +{ 274 + return gz_open(path, -1, mode); 275 +} 276 + 277 +/* -- see zlib.h -- */ 278 +gzFile ZEXPORT gzdopen(fd, mode) 279 + int fd; 280 + const char *mode; 281 +{ 282 + char *path; /* identifier for error messages */ 283 + gzFile gz; 284 + 285 + if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) 286 + return NULL; 287 + sprintf(path, "<fd:%d>", fd); /* for debugging */ 288 + gz = gz_open(path, fd, mode); 289 + free(path); 290 + return gz; 291 +} 292 + 293 +/* -- see zlib.h -- */ 294 +#ifdef _WIN32 295 +gzFile ZEXPORT gzopen_w(path, mode) 296 + const wchar_t *path; 297 + const char *mode; 298 +{ 299 + return gz_open(path, -2, mode); 300 +} 301 +#endif 302 + 303 +/* -- see zlib.h -- */ 304 +int ZEXPORT gzbuffer(file, size) 305 + gzFile file; 306 + unsigned size; 307 +{ 308 + gz_statep state; 309 + 310 + /* get internal structure and check integrity */ 311 + if (file == NULL) 312 + return -1; 313 + state = (gz_statep)file; 314 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 315 + return -1; 316 + 317 + /* make sure we haven't already allocated memory */ 318 + if (state->size != 0) 319 + return -1; 320 + 321 + /* check and set requested size */ 322 + if (size < 2) 323 + size = 2; /* need two bytes to check magic header */ 324 + state->want = size; 325 + return 0; 326 +} 327 + 328 +/* -- see zlib.h -- */ 329 +int ZEXPORT gzrewind(file) 330 + gzFile file; 331 +{ 332 + gz_statep state; 333 + 334 + /* get internal structure */ 335 + if (file == NULL) 336 + return -1; 337 + state = (gz_statep)file; 338 + 339 + /* check that we're reading and that there's no error */ 340 + if (state->mode != GZ_READ || 341 + (state->err != Z_OK && state->err != Z_BUF_ERROR)) 342 + return -1; 343 + 344 + /* back up and start over */ 345 + if (LSEEK(state->fd, state->start, SEEK_SET) == -1) 346 + return -1; 347 + gz_reset(state); 348 + return 0; 349 +} 350 + 351 +/* -- see zlib.h -- */ 352 +z_off64_t ZEXPORT gzseek64(file, offset, whence) 353 + gzFile file; 354 + z_off64_t offset; 355 + int whence; 356 +{ 357 + unsigned n; 358 + z_off64_t ret; 359 + gz_statep state; 360 + 361 + /* get internal structure and check integrity */ 362 + if (file == NULL) 363 + return -1; 364 + state = (gz_statep)file; 365 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 366 + return -1; 367 + 368 + /* check that there's no error */ 369 + if (state->err != Z_OK && state->err != Z_BUF_ERROR) 370 + return -1; 371 + 372 + /* can only seek from start or relative to current position */ 373 + if (whence != SEEK_SET && whence != SEEK_CUR) 374 + return -1; 375 + 376 + /* normalize offset to a SEEK_CUR specification */ 377 + if (whence == SEEK_SET) 378 + offset -= state->x.pos; 379 + else if (state->seek) 380 + offset += state->skip; 381 + state->seek = 0; 382 + 383 + /* if within raw area while reading, just go there */ 384 + if (state->mode == GZ_READ && state->how == COPY && 385 + state->x.pos + offset >= 0) { 386 + ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); 387 + if (ret == -1) 388 + return -1; 389 + state->x.have = 0; 390 + state->eof = 0; 391 + state->past = 0; 392 + state->seek = 0; 393 + gz_error(state, Z_OK, NULL); 394 + state->strm.avail_in = 0; 395 + state->x.pos += offset; 396 + return state->x.pos; 397 + } 398 + 399 + /* calculate skip amount, rewinding if needed for back seek when reading */ 400 + if (offset < 0) { 401 + if (state->mode != GZ_READ) /* writing -- can't go backwards */ 402 + return -1; 403 + offset += state->x.pos; 404 + if (offset < 0) /* before start of file! */ 405 + return -1; 406 + if (gzrewind(file) == -1) /* rewind, then skip to offset */ 407 + return -1; 408 + } 409 + 410 + /* if reading, skip what's in output buffer (one less gzgetc() check) */ 411 + if (state->mode == GZ_READ) { 412 + n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? 413 + (unsigned)offset : state->x.have; 414 + state->x.have -= n; 415 + state->x.next += n; 416 + state->x.pos += n; 417 + offset -= n; 418 + } 419 + 420 + /* request skip (if not zero) */ 421 + if (offset) { 422 + state->seek = 1; 423 + state->skip = offset; 424 + } 425 + return state->x.pos + offset; 426 +} 427 + 428 +/* -- see zlib.h -- */ 429 +z_off_t ZEXPORT gzseek(file, offset, whence) 430 + gzFile file; 431 + z_off_t offset; 432 + int whence; 433 +{ 434 + z_off64_t ret; 435 + 436 + ret = gzseek64(file, (z_off64_t)offset, whence); 437 + return ret == (z_off_t)ret ? (z_off_t)ret : -1; 438 +} 439 + 440 +/* -- see zlib.h -- */ 441 +z_off64_t ZEXPORT gztell64(file) 442 + gzFile file; 443 +{ 444 + gz_statep state; 445 + 446 + /* get internal structure and check integrity */ 447 + if (file == NULL) 448 + return -1; 449 + state = (gz_statep)file; 450 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 451 + return -1; 452 + 453 + /* return position */ 454 + return state->x.pos + (state->seek ? state->skip : 0); 455 +} 456 + 457 +/* -- see zlib.h -- */ 458 +z_off_t ZEXPORT gztell(file) 459 + gzFile file; 460 +{ 461 + z_off64_t ret; 462 + 463 + ret = gztell64(file); 464 + return ret == (z_off_t)ret ? (z_off_t)ret : -1; 465 +} 466 + 467 +/* -- see zlib.h -- */ 468 +z_off64_t ZEXPORT gzoffset64(file) 469 + gzFile file; 470 +{ 471 + z_off64_t offset; 472 + gz_statep state; 473 + 474 + /* get internal structure and check integrity */ 475 + if (file == NULL) 476 + return -1; 477 + state = (gz_statep)file; 478 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 479 + return -1; 480 + 481 + /* compute and return effective offset in file */ 482 + offset = LSEEK(state->fd, 0, SEEK_CUR); 483 + if (offset == -1) 484 + return -1; 485 + if (state->mode == GZ_READ) /* reading */ 486 + offset -= state->strm.avail_in; /* don't count buffered input */ 487 + return offset; 488 +} 489 + 490 +/* -- see zlib.h -- */ 491 +z_off_t ZEXPORT gzoffset(file) 492 + gzFile file; 493 +{ 494 + z_off64_t ret; 495 + 496 + ret = gzoffset64(file); 497 + return ret == (z_off_t)ret ? (z_off_t)ret : -1; 498 +} 499 + 500 +/* -- see zlib.h -- */ 501 +int ZEXPORT gzeof(file) 502 + gzFile file; 503 +{ 504 + gz_statep state; 505 + 506 + /* get internal structure and check integrity */ 507 + if (file == NULL) 508 + return 0; 509 + state = (gz_statep)file; 510 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 511 + return 0; 512 + 513 + /* return end-of-file state */ 514 + return state->mode == GZ_READ ? state->past : 0; 515 +} 516 + 517 +/* -- see zlib.h -- */ 518 +const char * ZEXPORT gzerror(file, errnum) 519 + gzFile file; 520 + int *errnum; 521 +{ 522 + gz_statep state; 523 + 524 + /* get internal structure and check integrity */ 525 + if (file == NULL) 526 + return NULL; 527 + state = (gz_statep)file; 528 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 529 + return NULL; 530 + 531 + /* return error information */ 532 + if (errnum != NULL) 533 + *errnum = state->err; 534 + return state->msg == NULL ? "" : state->msg; 535 +} 536 + 537 +/* -- see zlib.h -- */ 538 +void ZEXPORT gzclearerr(file) 539 + gzFile file; 540 +{ 541 + gz_statep state; 542 + 543 + /* get internal structure and check integrity */ 544 + if (file == NULL) 545 + return; 546 + state = (gz_statep)file; 547 + if (state->mode != GZ_READ && state->mode != GZ_WRITE) 548 + return; 549 + 550 + /* clear error and end-of-file */ 551 + if (state->mode == GZ_READ) { 552 + state->eof = 0; 553 + state->past = 0; 554 + } 555 + gz_error(state, Z_OK, NULL); 556 +} 557 + 558 +/* Create an error message in allocated memory and set state->err and 559 + state->msg accordingly. Free any previous error message already there. Do 560 + not try to free or allocate space if the error is Z_MEM_ERROR (out of 561 + memory). Simply save the error message as a static string. If there is an 562 + allocation failure constructing the error message, then convert the error to 563 + out of memory. */ 564 +void ZLIB_INTERNAL gz_error(state, err, msg) 565 + gz_statep state; 566 + int err; 567 + const char *msg; 568 +{ 569 + /* free previously allocated message and clear */ 570 + if (state->msg != NULL) { 571 + if (state->err != Z_MEM_ERROR) 572 + free(state->msg); 573 + state->msg = NULL; 574 + } 575 + 576 + /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ 577 + if (err != Z_OK && err != Z_BUF_ERROR) 578 + state->x.have = 0; 579 + 580 + /* set error code, and if no message, then done */ 581 + state->err = err; 582 + if (msg == NULL) 583 + return; 584 + 585 + /* for an out of memory error, save as static string */ 586 + if (err == Z_MEM_ERROR) { 587 + state->msg = (char *)msg; 588 + return; 589 + } 590 + 591 + /* construct error message with path */ 592 + if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { 593 + state->err = Z_MEM_ERROR; 594 + state->msg = (char *)"out of memory"; 595 + return; 596 + } 597 + strcpy(state->msg, state->path); 598 + strcat(state->msg, ": "); 599 + strcat(state->msg, msg); 600 + return; 601 +} 602 + 603 +#ifndef INT_MAX 604 +/* portably return maximum value for an int (when limits.h presumed not 605 + available) -- we need to do this to cover cases where 2's complement not 606 + used, since C standard permits 1's complement and sign-bit representations, 607 + otherwise we could just use ((unsigned)-1) >> 1 */ 608 +unsigned ZLIB_INTERNAL gz_intmax() 609 +{ 610 + unsigned p, q; 611 + 612 + p = 1; 613 + do { 614 + q = p; 615 + p <<= 1; 616 + p++; 617 + } while (p > q); 618 + return q >> 1; 619 +} 620 +#endif
Added compat/zlib/gzread.c.
1 +/* gzread.c -- zlib functions for reading gzip files 2 + * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "gzguts.h" 7 + 8 +/* Local functions */ 9 +local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); 10 +local int gz_avail OF((gz_statep)); 11 +local int gz_look OF((gz_statep)); 12 +local int gz_decomp OF((gz_statep)); 13 +local int gz_fetch OF((gz_statep)); 14 +local int gz_skip OF((gz_statep, z_off64_t)); 15 + 16 +/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from 17 + state->fd, and update state->eof, state->err, and state->msg as appropriate. 18 + This function needs to loop on read(), since read() is not guaranteed to 19 + read the number of bytes requested, depending on the type of descriptor. */ 20 +local int gz_load(state, buf, len, have) 21 + gz_statep state; 22 + unsigned char *buf; 23 + unsigned len; 24 + unsigned *have; 25 +{ 26 + int ret; 27 + 28 + *have = 0; 29 + do { 30 + ret = read(state->fd, buf + *have, len - *have); 31 + if (ret <= 0) 32 + break; 33 + *have += ret; 34 + } while (*have < len); 35 + if (ret < 0) { 36 + gz_error(state, Z_ERRNO, zstrerror()); 37 + return -1; 38 + } 39 + if (ret == 0) 40 + state->eof = 1; 41 + return 0; 42 +} 43 + 44 +/* Load up input buffer and set eof flag if last data loaded -- return -1 on 45 + error, 0 otherwise. Note that the eof flag is set when the end of the input 46 + file is reached, even though there may be unused data in the buffer. Once 47 + that data has been used, no more attempts will be made to read the file. 48 + If strm->avail_in != 0, then the current data is moved to the beginning of 49 + the input buffer, and then the remainder of the buffer is loaded with the 50 + available data from the input file. */ 51 +local int gz_avail(state) 52 + gz_statep state; 53 +{ 54 + unsigned got; 55 + z_streamp strm = &(state->strm); 56 + 57 + if (state->err != Z_OK && state->err != Z_BUF_ERROR) 58 + return -1; 59 + if (state->eof == 0) { 60 + if (strm->avail_in) { /* copy what's there to the start */ 61 + unsigned char *p = state->in, *q = strm->next_in; 62 + unsigned n = strm->avail_in; 63 + do { 64 + *p++ = *q++; 65 + } while (--n); 66 + } 67 + if (gz_load(state, state->in + strm->avail_in, 68 + state->size - strm->avail_in, &got) == -1) 69 + return -1; 70 + strm->avail_in += got; 71 + strm->next_in = state->in; 72 + } 73 + return 0; 74 +} 75 + 76 +/* Look for gzip header, set up for inflate or copy. state->x.have must be 0. 77 + If this is the first time in, allocate required memory. state->how will be 78 + left unchanged if there is no more input data available, will be set to COPY 79 + if there is no gzip header and direct copying will be performed, or it will 80 + be set to GZIP for decompression. If direct copying, then leftover input 81 + data from the input buffer will be copied to the output buffer. In that 82 + case, all further file reads will be directly to either the output buffer or 83 + a user buffer. If decompressing, the inflate state will be initialized. 84 + gz_look() will return 0 on success or -1 on failure. */ 85 +local int gz_look(state) 86 + gz_statep state; 87 +{ 88 + z_streamp strm = &(state->strm); 89 + 90 + /* allocate read buffers and inflate memory */ 91 + if (state->size == 0) { 92 + /* allocate buffers */ 93 + state->in = malloc(state->want); 94 + state->out = malloc(state->want << 1); 95 + if (state->in == NULL || state->out == NULL) { 96 + if (state->out != NULL) 97 + free(state->out); 98 + if (state->in != NULL) 99 + free(state->in); 100 + gz_error(state, Z_MEM_ERROR, "out of memory"); 101 + return -1; 102 + } 103 + state->size = state->want; 104 + 105 + /* allocate inflate memory */ 106 + state->strm.zalloc = Z_NULL; 107 + state->strm.zfree = Z_NULL; 108 + state->strm.opaque = Z_NULL; 109 + state->strm.avail_in = 0; 110 + state->strm.next_in = Z_NULL; 111 + if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ 112 + free(state->out); 113 + free(state->in); 114 + state->size = 0; 115 + gz_error(state, Z_MEM_ERROR, "out of memory"); 116 + return -1; 117 + } 118 + } 119 + 120 + /* get at least the magic bytes in the input buffer */ 121 + if (strm->avail_in < 2) { 122 + if (gz_avail(state) == -1) 123 + return -1; 124 + if (strm->avail_in == 0) 125 + return 0; 126 + } 127 + 128 + /* look for gzip magic bytes -- if there, do gzip decoding (note: there is 129 + a logical dilemma here when considering the case of a partially written 130 + gzip file, to wit, if a single 31 byte is written, then we cannot tell 131 + whether this is a single-byte file, or just a partially written gzip 132 + file -- for here we assume that if a gzip file is being written, then 133 + the header will be written in a single operation, so that reading a 134 + single byte is sufficient indication that it is not a gzip file) */ 135 + if (strm->avail_in > 1 && 136 + strm->next_in[0] == 31 && strm->next_in[1] == 139) { 137 + inflateReset(strm); 138 + state->how = GZIP; 139 + state->direct = 0; 140 + return 0; 141 + } 142 + 143 + /* no gzip header -- if we were decoding gzip before, then this is trailing 144 + garbage. Ignore the trailing garbage and finish. */ 145 + if (state->direct == 0) { 146 + strm->avail_in = 0; 147 + state->eof = 1; 148 + state->x.have = 0; 149 + return 0; 150 + } 151 + 152 + /* doing raw i/o, copy any leftover input to output -- this assumes that 153 + the output buffer is larger than the input buffer, which also assures 154 + space for gzungetc() */ 155 + state->x.next = state->out; 156 + if (strm->avail_in) { 157 + memcpy(state->x.next, strm->next_in, strm->avail_in); 158 + state->x.have = strm->avail_in; 159 + strm->avail_in = 0; 160 + } 161 + state->how = COPY; 162 + state->direct = 1; 163 + return 0; 164 +} 165 + 166 +/* Decompress from input to the provided next_out and avail_out in the state. 167 + On return, state->x.have and state->x.next point to the just decompressed 168 + data. If the gzip stream completes, state->how is reset to LOOK to look for 169 + the next gzip stream or raw data, once state->x.have is depleted. Returns 0 170 + on success, -1 on failure. */ 171 +local int gz_decomp(state) 172 + gz_statep state; 173 +{ 174 + int ret = Z_OK; 175 + unsigned had; 176 + z_streamp strm = &(state->strm); 177 + 178 + /* fill output buffer up to end of deflate stream */ 179 + had = strm->avail_out; 180 + do { 181 + /* get more input for inflate() */ 182 + if (strm->avail_in == 0 && gz_avail(state) == -1) 183 + return -1; 184 + if (strm->avail_in == 0) { 185 + gz_error(state, Z_BUF_ERROR, "unexpected end of file"); 186 + break; 187 + } 188 + 189 + /* decompress and handle errors */ 190 + ret = inflate(strm, Z_NO_FLUSH); 191 + if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { 192 + gz_error(state, Z_STREAM_ERROR, 193 + "internal error: inflate stream corrupt"); 194 + return -1; 195 + } 196 + if (ret == Z_MEM_ERROR) { 197 + gz_error(state, Z_MEM_ERROR, "out of memory"); 198 + return -1; 199 + } 200 + if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ 201 + gz_error(state, Z_DATA_ERROR, 202 + strm->msg == NULL ? "compressed data error" : strm->msg); 203 + return -1; 204 + } 205 + } while (strm->avail_out && ret != Z_STREAM_END); 206 + 207 + /* update available output */ 208 + state->x.have = had - strm->avail_out; 209 + state->x.next = strm->next_out - state->x.have; 210 + 211 + /* if the gzip stream completed successfully, look for another */ 212 + if (ret == Z_STREAM_END) 213 + state->how = LOOK; 214 + 215 + /* good decompression */ 216 + return 0; 217 +} 218 + 219 +/* Fetch data and put it in the output buffer. Assumes state->x.have is 0. 220 + Data is either copied from the input file or decompressed from the input 221 + file depending on state->how. If state->how is LOOK, then a gzip header is 222 + looked for to determine whether to copy or decompress. Returns -1 on error, 223 + otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the 224 + end of the input file has been reached and all data has been processed. */ 225 +local int gz_fetch(state) 226 + gz_statep state; 227 +{ 228 + z_streamp strm = &(state->strm); 229 + 230 + do { 231 + switch(state->how) { 232 + case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ 233 + if (gz_look(state) == -1) 234 + return -1; 235 + if (state->how == LOOK) 236 + return 0; 237 + break; 238 + case COPY: /* -> COPY */ 239 + if (gz_load(state, state->out, state->size << 1, &(state->x.have)) 240 + == -1) 241 + return -1; 242 + state->x.next = state->out; 243 + return 0; 244 + case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ 245 + strm->avail_out = state->size << 1; 246 + strm->next_out = state->out; 247 + if (gz_decomp(state) == -1) 248 + return -1; 249 + } 250 + } while (state->x.have == 0 && (!state->eof || strm->avail_in)); 251 + return 0; 252 +} 253 + 254 +/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ 255 +local int gz_skip(state, len) 256 + gz_statep state; 257 + z_off64_t len; 258 +{ 259 + unsigned n; 260 + 261 + /* skip over len bytes or reach end-of-file, whichever comes first */ 262 + while (len) 263 + /* skip over whatever is in output buffer */ 264 + if (state->x.have) { 265 + n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? 266 + (unsigned)len : state->x.have; 267 + state->x.have -= n; 268 + state->x.next += n; 269 + state->x.pos += n; 270 + len -= n; 271 + } 272 + 273 + /* output buffer empty -- return if we're at the end of the input */ 274 + else if (state->eof && state->strm.avail_in == 0) 275 + break; 276 + 277 + /* need more data to skip -- load up output buffer */ 278 + else { 279 + /* get more output, looking for header if required */ 280 + if (gz_fetch(state) == -1) 281 + return -1; 282 + } 283 + return 0; 284 +} 285 + 286 +/* -- see zlib.h -- */ 287 +int ZEXPORT gzread(file, buf, len) 288 + gzFile file; 289 + voidp buf; 290 + unsigned len; 291 +{ 292 + unsigned got, n; 293 + gz_statep state; 294 + z_streamp strm; 295 + 296 + /* get internal structure */ 297 + if (file == NULL) 298 + return -1; 299 + state = (gz_statep)file; 300 + strm = &(state->strm); 301 + 302 + /* check that we're reading and that there's no (serious) error */ 303 + if (state->mode != GZ_READ || 304 + (state->err != Z_OK && state->err != Z_BUF_ERROR)) 305 + return -1; 306 + 307 + /* since an int is returned, make sure len fits in one, otherwise return 308 + with an error (this avoids the flaw in the interface) */ 309 + if ((int)len < 0) { 310 + gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); 311 + return -1; 312 + } 313 + 314 + /* if len is zero, avoid unnecessary operations */ 315 + if (len == 0) 316 + return 0; 317 + 318 + /* process a skip request */ 319 + if (state->seek) { 320 + state->seek = 0; 321 + if (gz_skip(state, state->skip) == -1) 322 + return -1; 323 + } 324 + 325 + /* get len bytes to buf, or less than len if at the end */ 326 + got = 0; 327 + do { 328 + /* first just try copying data from the output buffer */ 329 + if (state->x.have) { 330 + n = state->x.have > len ? len : state->x.have; 331 + memcpy(buf, state->x.next, n); 332 + state->x.next += n; 333 + state->x.have -= n; 334 + } 335 + 336 + /* output buffer empty -- return if we're at the end of the input */ 337 + else if (state->eof && strm->avail_in == 0) { 338 + state->past = 1; /* tried to read past end */ 339 + break; 340 + } 341 + 342 + /* need output data -- for small len or new stream load up our output 343 + buffer */ 344 + else if (state->how == LOOK || len < (state->size << 1)) { 345 + /* get more output, looking for header if required */ 346 + if (gz_fetch(state) == -1) 347 + return -1; 348 + continue; /* no progress yet -- go back to copy above */ 349 + /* the copy above assures that we will leave with space in the 350 + output buffer, allowing at least one gzungetc() to succeed */ 351 + } 352 + 353 + /* large len -- read directly into user buffer */ 354 + else if (state->how == COPY) { /* read directly */ 355 + if (gz_load(state, buf, len, &n) == -1) 356 + return -1; 357 + } 358 + 359 + /* large len -- decompress directly into user buffer */ 360 + else { /* state->how == GZIP */ 361 + strm->avail_out = len; 362 + strm->next_out = buf; 363 + if (gz_decomp(state) == -1) 364 + return -1; 365 + n = state->x.have; 366 + state->x.have = 0; 367 + } 368 + 369 + /* update progress */ 370 + len -= n; 371 + buf = (char *)buf + n; 372 + got += n; 373 + state->x.pos += n; 374 + } while (len); 375 + 376 + /* return number of bytes read into user buffer (will fit in int) */ 377 + return (int)got; 378 +} 379 + 380 +/* -- see zlib.h -- */ 381 +#undef gzgetc 382 +int ZEXPORT gzgetc(file) 383 + gzFile file; 384 +{ 385 + int ret; 386 + unsigned char buf[1]; 387 + gz_statep state; 388 + 389 + /* get internal structure */ 390 + if (file == NULL) 391 + return -1; 392 + state = (gz_statep)file; 393 + 394 + /* check that we're reading and that there's no (serious) error */ 395 + if (state->mode != GZ_READ || 396 + (state->err != Z_OK && state->err != Z_BUF_ERROR)) 397 + return -1; 398 + 399 + /* try output buffer (no need to check for skip request) */ 400 + if (state->x.have) { 401 + state->x.have--; 402 + state->x.pos++; 403 + return *(state->x.next)++; 404 + } 405 + 406 + /* nothing there -- try gzread() */ 407 + ret = gzread(file, buf, 1); 408 + return ret < 1 ? -1 : buf[0]; 409 +} 410 + 411 +int ZEXPORT gzgetc_(file) 412 +gzFile file; 413 +{ 414 + return gzgetc(file); 415 +} 416 + 417 +/* -- see zlib.h -- */ 418 +int ZEXPORT gzungetc(c, file) 419 + int c; 420 + gzFile file; 421 +{ 422 + gz_statep state; 423 + 424 + /* get internal structure */ 425 + if (file == NULL) 426 + return -1; 427 + state = (gz_statep)file; 428 + 429 + /* check that we're reading and that there's no (serious) error */ 430 + if (state->mode != GZ_READ || 431 + (state->err != Z_OK && state->err != Z_BUF_ERROR)) 432 + return -1; 433 + 434 + /* process a skip request */ 435 + if (state->seek) { 436 + state->seek = 0; 437 + if (gz_skip(state, state->skip) == -1) 438 + return -1; 439 + } 440 + 441 + /* can't push EOF */ 442 + if (c < 0) 443 + return -1; 444 + 445 + /* if output buffer empty, put byte at end (allows more pushing) */ 446 + if (state->x.have == 0) { 447 + state->x.have = 1; 448 + state->x.next = state->out + (state->size << 1) - 1; 449 + state->x.next[0] = c; 450 + state->x.pos--; 451 + state->past = 0; 452 + return c; 453 + } 454 + 455 + /* if no room, give up (must have already done a gzungetc()) */ 456 + if (state->x.have == (state->size << 1)) { 457 + gz_error(state, Z_DATA_ERROR, "out of room to push characters"); 458 + return -1; 459 + } 460 + 461 + /* slide output data if needed and insert byte before existing data */ 462 + if (state->x.next == state->out) { 463 + unsigned char *src = state->out + state->x.have; 464 + unsigned char *dest = state->out + (state->size << 1); 465 + while (src > state->out) 466 + *--dest = *--src; 467 + state->x.next = dest; 468 + } 469 + state->x.have++; 470 + state->x.next--; 471 + state->x.next[0] = c; 472 + state->x.pos--; 473 + state->past = 0; 474 + return c; 475 +} 476 + 477 +/* -- see zlib.h -- */ 478 +char * ZEXPORT gzgets(file, buf, len) 479 + gzFile file; 480 + char *buf; 481 + int len; 482 +{ 483 + unsigned left, n; 484 + char *str; 485 + unsigned char *eol; 486 + gz_statep state; 487 + 488 + /* check parameters and get internal structure */ 489 + if (file == NULL || buf == NULL || len < 1) 490 + return NULL; 491 + state = (gz_statep)file; 492 + 493 + /* check that we're reading and that there's no (serious) error */ 494 + if (state->mode != GZ_READ || 495 + (state->err != Z_OK && state->err != Z_BUF_ERROR)) 496 + return NULL; 497 + 498 + /* process a skip request */ 499 + if (state->seek) { 500 + state->seek = 0; 501 + if (gz_skip(state, state->skip) == -1) 502 + return NULL; 503 + } 504 + 505 + /* copy output bytes up to new line or len - 1, whichever comes first -- 506 + append a terminating zero to the string (we don't check for a zero in 507 + the contents, let the user worry about that) */ 508 + str = buf; 509 + left = (unsigned)len - 1; 510 + if (left) do { 511 + /* assure that something is in the output buffer */ 512 + if (state->x.have == 0 && gz_fetch(state) == -1) 513 + return NULL; /* error */ 514 + if (state->x.have == 0) { /* end of file */ 515 + state->past = 1; /* read past end */ 516 + break; /* return what we have */ 517 + } 518 + 519 + /* look for end-of-line in current output buffer */ 520 + n = state->x.have > left ? left : state->x.have; 521 + eol = memchr(state->x.next, '\n', n); 522 + if (eol != NULL) 523 + n = (unsigned)(eol - state->x.next) + 1; 524 + 525 + /* copy through end-of-line, or remainder if not found */ 526 + memcpy(buf, state->x.next, n); 527 + state->x.have -= n; 528 + state->x.next += n; 529 + state->x.pos += n; 530 + left -= n; 531 + buf += n; 532 + } while (left && eol == NULL); 533 + 534 + /* return terminated string, or if nothing, end of file */ 535 + if (buf == str) 536 + return NULL; 537 + buf[0] = 0; 538 + return str; 539 +} 540 + 541 +/* -- see zlib.h -- */ 542 +int ZEXPORT gzdirect(file) 543 + gzFile file; 544 +{ 545 + gz_statep state; 546 + 547 + /* get internal structure */ 548 + if (file == NULL) 549 + return 0; 550 + state = (gz_statep)file; 551 + 552 + /* if the state is not known, but we can find out, then do so (this is 553 + mainly for right after a gzopen() or gzdopen()) */ 554 + if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) 555 + (void)gz_look(state); 556 + 557 + /* return 1 if transparent, 0 if processing a gzip stream */ 558 + return state->direct; 559 +} 560 + 561 +/* -- see zlib.h -- */ 562 +int ZEXPORT gzclose_r(file) 563 + gzFile file; 564 +{ 565 + int ret, err; 566 + gz_statep state; 567 + 568 + /* get internal structure */ 569 + if (file == NULL) 570 + return Z_STREAM_ERROR; 571 + state = (gz_statep)file; 572 + 573 + /* check that we're reading */ 574 + if (state->mode != GZ_READ) 575 + return Z_STREAM_ERROR; 576 + 577 + /* free memory and close file */ 578 + if (state->size) { 579 + inflateEnd(&(state->strm)); 580 + free(state->out); 581 + free(state->in); 582 + } 583 + err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; 584 + gz_error(state, Z_OK, NULL); 585 + free(state->path); 586 + ret = close(state->fd); 587 + free(state); 588 + return ret ? Z_ERRNO : err; 589 +}
Added compat/zlib/gzwrite.c.
1 +/* gzwrite.c -- zlib functions for writing gzip files 2 + * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "gzguts.h" 7 + 8 +/* Local functions */ 9 +local int gz_init OF((gz_statep)); 10 +local int gz_comp OF((gz_statep, int)); 11 +local int gz_zero OF((gz_statep, z_off64_t)); 12 + 13 +/* Initialize state for writing a gzip file. Mark initialization by setting 14 + state->size to non-zero. Return -1 on failure or 0 on success. */ 15 +local int gz_init(state) 16 + gz_statep state; 17 +{ 18 + int ret; 19 + z_streamp strm = &(state->strm); 20 + 21 + /* allocate input buffer */ 22 + state->in = malloc(state->want); 23 + if (state->in == NULL) { 24 + gz_error(state, Z_MEM_ERROR, "out of memory"); 25 + return -1; 26 + } 27 + 28 + /* only need output buffer and deflate state if compressing */ 29 + if (!state->direct) { 30 + /* allocate output buffer */ 31 + state->out = malloc(state->want); 32 + if (state->out == NULL) { 33 + free(state->in); 34 + gz_error(state, Z_MEM_ERROR, "out of memory"); 35 + return -1; 36 + } 37 + 38 + /* allocate deflate memory, set up for gzip compression */ 39 + strm->zalloc = Z_NULL; 40 + strm->zfree = Z_NULL; 41 + strm->opaque = Z_NULL; 42 + ret = deflateInit2(strm, state->level, Z_DEFLATED, 43 + MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); 44 + if (ret != Z_OK) { 45 + free(state->out); 46 + free(state->in); 47 + gz_error(state, Z_MEM_ERROR, "out of memory"); 48 + return -1; 49 + } 50 + } 51 + 52 + /* mark state as initialized */ 53 + state->size = state->want; 54 + 55 + /* initialize write buffer if compressing */ 56 + if (!state->direct) { 57 + strm->avail_out = state->size; 58 + strm->next_out = state->out; 59 + state->x.next = strm->next_out; 60 + } 61 + return 0; 62 +} 63 + 64 +/* Compress whatever is at avail_in and next_in and write to the output file. 65 + Return -1 if there is an error writing to the output file, otherwise 0. 66 + flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, 67 + then the deflate() state is reset to start a new gzip stream. If gz->direct 68 + is true, then simply write to the output file without compressing, and 69 + ignore flush. */ 70 +local int gz_comp(state, flush) 71 + gz_statep state; 72 + int flush; 73 +{ 74 + int ret, got; 75 + unsigned have; 76 + z_streamp strm = &(state->strm); 77 + 78 + /* allocate memory if this is the first time through */ 79 + if (state->size == 0 && gz_init(state) == -1) 80 + return -1; 81 + 82 + /* write directly if requested */ 83 + if (state->direct) { 84 + got = write(state->fd, strm->next_in, strm->avail_in); 85 + if (got < 0 || (unsigned)got != strm->avail_in) { 86 + gz_error(state, Z_ERRNO, zstrerror()); 87 + return -1; 88 + } 89 + strm->avail_in = 0; 90 + return 0; 91 + } 92 + 93 + /* run deflate() on provided input until it produces no more output */ 94 + ret = Z_OK; 95 + do { 96 + /* write out current buffer contents if full, or if flushing, but if 97 + doing Z_FINISH then don't write until we get to Z_STREAM_END */ 98 + if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && 99 + (flush != Z_FINISH || ret == Z_STREAM_END))) { 100 + have = (unsigned)(strm->next_out - state->x.next); 101 + if (have && ((got = write(state->fd, state->x.next, have)) < 0 || 102 + (unsigned)got != have)) { 103 + gz_error(state, Z_ERRNO, zstrerror()); 104 + return -1; 105 + } 106 + if (strm->avail_out == 0) { 107 + strm->avail_out = state->size; 108 + strm->next_out = state->out; 109 + } 110 + state->x.next = strm->next_out; 111 + } 112 + 113 + /* compress */ 114 + have = strm->avail_out; 115 + ret = deflate(strm, flush); 116 + if (ret == Z_STREAM_ERROR) { 117 + gz_error(state, Z_STREAM_ERROR, 118 + "internal error: deflate stream corrupt"); 119 + return -1; 120 + } 121 + have -= strm->avail_out; 122 + } while (have); 123 + 124 + /* if that completed a deflate stream, allow another to start */ 125 + if (flush == Z_FINISH) 126 + deflateReset(strm); 127 + 128 + /* all done, no errors */ 129 + return 0; 130 +} 131 + 132 +/* Compress len zeros to output. Return -1 on error, 0 on success. */ 133 +local int gz_zero(state, len) 134 + gz_statep state; 135 + z_off64_t len; 136 +{ 137 + int first; 138 + unsigned n; 139 + z_streamp strm = &(state->strm); 140 + 141 + /* consume whatever's left in the input buffer */ 142 + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 143 + return -1; 144 + 145 + /* compress len zeros (len guaranteed > 0) */ 146 + first = 1; 147 + while (len) { 148 + n = GT_OFF(state->size) || (z_off64_t)state->size > len ? 149 + (unsigned)len : state->size; 150 + if (first) { 151 + memset(state->in, 0, n); 152 + first = 0; 153 + } 154 + strm->avail_in = n; 155 + strm->next_in = state->in; 156 + state->x.pos += n; 157 + if (gz_comp(state, Z_NO_FLUSH) == -1) 158 + return -1; 159 + len -= n; 160 + } 161 + return 0; 162 +} 163 + 164 +/* -- see zlib.h -- */ 165 +int ZEXPORT gzwrite(file, buf, len) 166 + gzFile file; 167 + voidpc buf; 168 + unsigned len; 169 +{ 170 + unsigned put = len; 171 + unsigned n; 172 + gz_statep state; 173 + z_streamp strm; 174 + 175 + /* get internal structure */ 176 + if (file == NULL) 177 + return 0; 178 + state = (gz_statep)file; 179 + strm = &(state->strm); 180 + 181 + /* check that we're writing and that there's no error */ 182 + if (state->mode != GZ_WRITE || state->err != Z_OK) 183 + return 0; 184 + 185 + /* since an int is returned, make sure len fits in one, otherwise return 186 + with an error (this avoids the flaw in the interface) */ 187 + if ((int)len < 0) { 188 + gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); 189 + return 0; 190 + } 191 + 192 + /* if len is zero, avoid unnecessary operations */ 193 + if (len == 0) 194 + return 0; 195 + 196 + /* allocate memory if this is the first time through */ 197 + if (state->size == 0 && gz_init(state) == -1) 198 + return 0; 199 + 200 + /* check for seek request */ 201 + if (state->seek) { 202 + state->seek = 0; 203 + if (gz_zero(state, state->skip) == -1) 204 + return 0; 205 + } 206 + 207 + /* for small len, copy to input buffer, otherwise compress directly */ 208 + if (len < state->size) { 209 + /* copy to input buffer, compress when full */ 210 + do { 211 + if (strm->avail_in == 0) 212 + strm->next_in = state->in; 213 + n = state->size - strm->avail_in; 214 + if (n > len) 215 + n = len; 216 + memcpy(strm->next_in + strm->avail_in, buf, n); 217 + strm->avail_in += n; 218 + state->x.pos += n; 219 + buf = (char *)buf + n; 220 + len -= n; 221 + if (len && gz_comp(state, Z_NO_FLUSH) == -1) 222 + return 0; 223 + } while (len); 224 + } 225 + else { 226 + /* consume whatever's left in the input buffer */ 227 + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 228 + return 0; 229 + 230 + /* directly compress user buffer to file */ 231 + strm->avail_in = len; 232 + strm->next_in = (voidp)buf; 233 + state->x.pos += len; 234 + if (gz_comp(state, Z_NO_FLUSH) == -1) 235 + return 0; 236 + } 237 + 238 + /* input was all buffered or compressed (put will fit in int) */ 239 + return (int)put; 240 +} 241 + 242 +/* -- see zlib.h -- */ 243 +int ZEXPORT gzputc(file, c) 244 + gzFile file; 245 + int c; 246 +{ 247 + unsigned char buf[1]; 248 + gz_statep state; 249 + z_streamp strm; 250 + 251 + /* get internal structure */ 252 + if (file == NULL) 253 + return -1; 254 + state = (gz_statep)file; 255 + strm = &(state->strm); 256 + 257 + /* check that we're writing and that there's no error */ 258 + if (state->mode != GZ_WRITE || state->err != Z_OK) 259 + return -1; 260 + 261 + /* check for seek request */ 262 + if (state->seek) { 263 + state->seek = 0; 264 + if (gz_zero(state, state->skip) == -1) 265 + return -1; 266 + } 267 + 268 + /* try writing to input buffer for speed (state->size == 0 if buffer not 269 + initialized) */ 270 + if (strm->avail_in < state->size) { 271 + if (strm->avail_in == 0) 272 + strm->next_in = state->in; 273 + strm->next_in[strm->avail_in++] = c; 274 + state->x.pos++; 275 + return c & 0xff; 276 + } 277 + 278 + /* no room in buffer or not initialized, use gz_write() */ 279 + buf[0] = c; 280 + if (gzwrite(file, buf, 1) != 1) 281 + return -1; 282 + return c & 0xff; 283 +} 284 + 285 +/* -- see zlib.h -- */ 286 +int ZEXPORT gzputs(file, str) 287 + gzFile file; 288 + const char *str; 289 +{ 290 + int ret; 291 + unsigned len; 292 + 293 + /* write string */ 294 + len = (unsigned)strlen(str); 295 + ret = gzwrite(file, str, len); 296 + return ret == 0 && len != 0 ? -1 : ret; 297 +} 298 + 299 +#if defined(STDC) || defined(Z_HAVE_STDARG_H) 300 +#include <stdarg.h> 301 + 302 +/* -- see zlib.h -- */ 303 +int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) 304 +{ 305 + int size, len; 306 + gz_statep state; 307 + z_streamp strm; 308 + va_list va; 309 + 310 + /* get internal structure */ 311 + if (file == NULL) 312 + return -1; 313 + state = (gz_statep)file; 314 + strm = &(state->strm); 315 + 316 + /* check that we're writing and that there's no error */ 317 + if (state->mode != GZ_WRITE || state->err != Z_OK) 318 + return 0; 319 + 320 + /* make sure we have some buffer space */ 321 + if (state->size == 0 && gz_init(state) == -1) 322 + return 0; 323 + 324 + /* check for seek request */ 325 + if (state->seek) { 326 + state->seek = 0; 327 + if (gz_zero(state, state->skip) == -1) 328 + return 0; 329 + } 330 + 331 + /* consume whatever's left in the input buffer */ 332 + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 333 + return 0; 334 + 335 + /* do the printf() into the input buffer, put length in len */ 336 + size = (int)(state->size); 337 + state->in[size - 1] = 0; 338 + va_start(va, format); 339 +#ifdef NO_vsnprintf 340 +# ifdef HAS_vsprintf_void 341 + (void)vsprintf((char *)(state->in), format, va); 342 + va_end(va); 343 + for (len = 0; len < size; len++) 344 + if (state->in[len] == 0) break; 345 +# else 346 + len = vsprintf((char *)(state->in), format, va); 347 + va_end(va); 348 +# endif 349 +#else 350 +# ifdef HAS_vsnprintf_void 351 + (void)vsnprintf((char *)(state->in), size, format, va); 352 + va_end(va); 353 + len = strlen((char *)(state->in)); 354 +# else 355 + len = vsnprintf((char *)(state->in), size, format, va); 356 + va_end(va); 357 +# endif 358 +#endif 359 + 360 + /* check that printf() results fit in buffer */ 361 + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 362 + return 0; 363 + 364 + /* update buffer and position, defer compression until needed */ 365 + strm->avail_in = (unsigned)len; 366 + strm->next_in = state->in; 367 + state->x.pos += len; 368 + return len; 369 +} 370 + 371 +#else /* !STDC && !Z_HAVE_STDARG_H */ 372 + 373 +/* -- see zlib.h -- */ 374 +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 375 + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) 376 + gzFile file; 377 + const char *format; 378 + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 379 + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; 380 +{ 381 + int size, len; 382 + gz_statep state; 383 + z_streamp strm; 384 + 385 + /* get internal structure */ 386 + if (file == NULL) 387 + return -1; 388 + state = (gz_statep)file; 389 + strm = &(state->strm); 390 + 391 + /* check that can really pass pointer in ints */ 392 + if (sizeof(int) != sizeof(void *)) 393 + return 0; 394 + 395 + /* check that we're writing and that there's no error */ 396 + if (state->mode != GZ_WRITE || state->err != Z_OK) 397 + return 0; 398 + 399 + /* make sure we have some buffer space */ 400 + if (state->size == 0 && gz_init(state) == -1) 401 + return 0; 402 + 403 + /* check for seek request */ 404 + if (state->seek) { 405 + state->seek = 0; 406 + if (gz_zero(state, state->skip) == -1) 407 + return 0; 408 + } 409 + 410 + /* consume whatever's left in the input buffer */ 411 + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 412 + return 0; 413 + 414 + /* do the printf() into the input buffer, put length in len */ 415 + size = (int)(state->size); 416 + state->in[size - 1] = 0; 417 +#ifdef NO_snprintf 418 +# ifdef HAS_sprintf_void 419 + sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, 420 + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 421 + for (len = 0; len < size; len++) 422 + if (state->in[len] == 0) break; 423 +# else 424 + len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, 425 + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 426 +# endif 427 +#else 428 +# ifdef HAS_snprintf_void 429 + snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, 430 + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 431 + len = strlen((char *)(state->in)); 432 +# else 433 + len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, 434 + a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, 435 + a19, a20); 436 +# endif 437 +#endif 438 + 439 + /* check that printf() results fit in buffer */ 440 + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 441 + return 0; 442 + 443 + /* update buffer and position, defer compression until needed */ 444 + strm->avail_in = (unsigned)len; 445 + strm->next_in = state->in; 446 + state->x.pos += len; 447 + return len; 448 +} 449 + 450 +#endif 451 + 452 +/* -- see zlib.h -- */ 453 +int ZEXPORT gzflush(file, flush) 454 + gzFile file; 455 + int flush; 456 +{ 457 + gz_statep state; 458 + 459 + /* get internal structure */ 460 + if (file == NULL) 461 + return -1; 462 + state = (gz_statep)file; 463 + 464 + /* check that we're writing and that there's no error */ 465 + if (state->mode != GZ_WRITE || state->err != Z_OK) 466 + return Z_STREAM_ERROR; 467 + 468 + /* check flush parameter */ 469 + if (flush < 0 || flush > Z_FINISH) 470 + return Z_STREAM_ERROR; 471 + 472 + /* check for seek request */ 473 + if (state->seek) { 474 + state->seek = 0; 475 + if (gz_zero(state, state->skip) == -1) 476 + return -1; 477 + } 478 + 479 + /* compress remaining data with requested flush */ 480 + gz_comp(state, flush); 481 + return state->err; 482 +} 483 + 484 +/* -- see zlib.h -- */ 485 +int ZEXPORT gzsetparams(file, level, strategy) 486 + gzFile file; 487 + int level; 488 + int strategy; 489 +{ 490 + gz_statep state; 491 + z_streamp strm; 492 + 493 + /* get internal structure */ 494 + if (file == NULL) 495 + return Z_STREAM_ERROR; 496 + state = (gz_statep)file; 497 + strm = &(state->strm); 498 + 499 + /* check that we're writing and that there's no error */ 500 + if (state->mode != GZ_WRITE || state->err != Z_OK) 501 + return Z_STREAM_ERROR; 502 + 503 + /* if no change is requested, then do nothing */ 504 + if (level == state->level && strategy == state->strategy) 505 + return Z_OK; 506 + 507 + /* check for seek request */ 508 + if (state->seek) { 509 + state->seek = 0; 510 + if (gz_zero(state, state->skip) == -1) 511 + return -1; 512 + } 513 + 514 + /* change compression parameters for subsequent input */ 515 + if (state->size) { 516 + /* flush previous input with previous parameters before changing */ 517 + if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) 518 + return state->err; 519 + deflateParams(strm, level, strategy); 520 + } 521 + state->level = level; 522 + state->strategy = strategy; 523 + return Z_OK; 524 +} 525 + 526 +/* -- see zlib.h -- */ 527 +int ZEXPORT gzclose_w(file) 528 + gzFile file; 529 +{ 530 + int ret = Z_OK; 531 + gz_statep state; 532 + 533 + /* get internal structure */ 534 + if (file == NULL) 535 + return Z_STREAM_ERROR; 536 + state = (gz_statep)file; 537 + 538 + /* check that we're writing */ 539 + if (state->mode != GZ_WRITE) 540 + return Z_STREAM_ERROR; 541 + 542 + /* check for seek request */ 543 + if (state->seek) { 544 + state->seek = 0; 545 + if (gz_zero(state, state->skip) == -1) 546 + ret = state->err; 547 + } 548 + 549 + /* flush, free memory, and close file */ 550 + if (state->size) { 551 + if (gz_comp(state, Z_FINISH) == -1) 552 + ret = state->err; 553 + if (!state->direct) { 554 + (void)deflateEnd(&(state->strm)); 555 + free(state->out); 556 + } 557 + free(state->in); 558 + } 559 + gz_error(state, Z_OK, NULL); 560 + free(state->path); 561 + if (close(state->fd) == -1) 562 + ret = Z_ERRNO; 563 + free(state); 564 + return ret; 565 +}
Added compat/zlib/infback.c.
1 +/* infback.c -- inflate using a call-back interface 2 + * Copyright (C) 1995-2011 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* 7 + This code is largely copied from inflate.c. Normally either infback.o or 8 + inflate.o would be linked into an application--not both. The interface 9 + with inffast.c is retained so that optimized assembler-coded versions of 10 + inflate_fast() can be used with either inflate.c or infback.c. 11 + */ 12 + 13 +#include "zutil.h" 14 +#include "inftrees.h" 15 +#include "inflate.h" 16 +#include "inffast.h" 17 + 18 +/* function prototypes */ 19 +local void fixedtables OF((struct inflate_state FAR *state)); 20 + 21 +/* 22 + strm provides memory allocation functions in zalloc and zfree, or 23 + Z_NULL to use the library memory allocation functions. 24 + 25 + windowBits is in the range 8..15, and window is a user-supplied 26 + window and output buffer that is 2**windowBits bytes. 27 + */ 28 +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) 29 +z_streamp strm; 30 +int windowBits; 31 +unsigned char FAR *window; 32 +const char *version; 33 +int stream_size; 34 +{ 35 + struct inflate_state FAR *state; 36 + 37 + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 38 + stream_size != (int)(sizeof(z_stream))) 39 + return Z_VERSION_ERROR; 40 + if (strm == Z_NULL || window == Z_NULL || 41 + windowBits < 8 || windowBits > 15) 42 + return Z_STREAM_ERROR; 43 + strm->msg = Z_NULL; /* in case we return an error */ 44 + if (strm->zalloc == (alloc_func)0) { 45 +#ifdef Z_SOLO 46 + return Z_STREAM_ERROR; 47 +#else 48 + strm->zalloc = zcalloc; 49 + strm->opaque = (voidpf)0; 50 +#endif 51 + } 52 + if (strm->zfree == (free_func)0) 53 +#ifdef Z_SOLO 54 + return Z_STREAM_ERROR; 55 +#else 56 + strm->zfree = zcfree; 57 +#endif 58 + state = (struct inflate_state FAR *)ZALLOC(strm, 1, 59 + sizeof(struct inflate_state)); 60 + if (state == Z_NULL) return Z_MEM_ERROR; 61 + Tracev((stderr, "inflate: allocated\n")); 62 + strm->state = (struct internal_state FAR *)state; 63 + state->dmax = 32768U; 64 + state->wbits = windowBits; 65 + state->wsize = 1U << windowBits; 66 + state->window = window; 67 + state->wnext = 0; 68 + state->whave = 0; 69 + return Z_OK; 70 +} 71 + 72 +/* 73 + Return state with length and distance decoding tables and index sizes set to 74 + fixed code decoding. Normally this returns fixed tables from inffixed.h. 75 + If BUILDFIXED is defined, then instead this routine builds the tables the 76 + first time it's called, and returns those tables the first time and 77 + thereafter. This reduces the size of the code by about 2K bytes, in 78 + exchange for a little execution time. However, BUILDFIXED should not be 79 + used for threaded applications, since the rewriting of the tables and virgin 80 + may not be thread-safe. 81 + */ 82 +local void fixedtables(state) 83 +struct inflate_state FAR *state; 84 +{ 85 +#ifdef BUILDFIXED 86 + static int virgin = 1; 87 + static code *lenfix, *distfix; 88 + static code fixed[544]; 89 + 90 + /* build fixed huffman tables if first call (may not be thread safe) */ 91 + if (virgin) { 92 + unsigned sym, bits; 93 + static code *next; 94 + 95 + /* literal/length table */ 96 + sym = 0; 97 + while (sym < 144) state->lens[sym++] = 8; 98 + while (sym < 256) state->lens[sym++] = 9; 99 + while (sym < 280) state->lens[sym++] = 7; 100 + while (sym < 288) state->lens[sym++] = 8; 101 + next = fixed; 102 + lenfix = next; 103 + bits = 9; 104 + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); 105 + 106 + /* distance table */ 107 + sym = 0; 108 + while (sym < 32) state->lens[sym++] = 5; 109 + distfix = next; 110 + bits = 5; 111 + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); 112 + 113 + /* do this just once */ 114 + virgin = 0; 115 + } 116 +#else /* !BUILDFIXED */ 117 +# include "inffixed.h" 118 +#endif /* BUILDFIXED */ 119 + state->lencode = lenfix; 120 + state->lenbits = 9; 121 + state->distcode = distfix; 122 + state->distbits = 5; 123 +} 124 + 125 +/* Macros for inflateBack(): */ 126 + 127 +/* Load returned state from inflate_fast() */ 128 +#define LOAD() \ 129 + do { \ 130 + put = strm->next_out; \ 131 + left = strm->avail_out; \ 132 + next = strm->next_in; \ 133 + have = strm->avail_in; \ 134 + hold = state->hold; \ 135 + bits = state->bits; \ 136 + } while (0) 137 + 138 +/* Set state from registers for inflate_fast() */ 139 +#define RESTORE() \ 140 + do { \ 141 + strm->next_out = put; \ 142 + strm->avail_out = left; \ 143 + strm->next_in = next; \ 144 + strm->avail_in = have; \ 145 + state->hold = hold; \ 146 + state->bits = bits; \ 147 + } while (0) 148 + 149 +/* Clear the input bit accumulator */ 150 +#define INITBITS() \ 151 + do { \ 152 + hold = 0; \ 153 + bits = 0; \ 154 + } while (0) 155 + 156 +/* Assure that some input is available. If input is requested, but denied, 157 + then return a Z_BUF_ERROR from inflateBack(). */ 158 +#define PULL() \ 159 + do { \ 160 + if (have == 0) { \ 161 + have = in(in_desc, &next); \ 162 + if (have == 0) { \ 163 + next = Z_NULL; \ 164 + ret = Z_BUF_ERROR; \ 165 + goto inf_leave; \ 166 + } \ 167 + } \ 168 + } while (0) 169 + 170 +/* Get a byte of input into the bit accumulator, or return from inflateBack() 171 + with an error if there is no input available. */ 172 +#define PULLBYTE() \ 173 + do { \ 174 + PULL(); \ 175 + have--; \ 176 + hold += (unsigned long)(*next++) << bits; \ 177 + bits += 8; \ 178 + } while (0) 179 + 180 +/* Assure that there are at least n bits in the bit accumulator. If there is 181 + not enough available input to do that, then return from inflateBack() with 182 + an error. */ 183 +#define NEEDBITS(n) \ 184 + do { \ 185 + while (bits < (unsigned)(n)) \ 186 + PULLBYTE(); \ 187 + } while (0) 188 + 189 +/* Return the low n bits of the bit accumulator (n < 16) */ 190 +#define BITS(n) \ 191 + ((unsigned)hold & ((1U << (n)) - 1)) 192 + 193 +/* Remove n bits from the bit accumulator */ 194 +#define DROPBITS(n) \ 195 + do { \ 196 + hold >>= (n); \ 197 + bits -= (unsigned)(n); \ 198 + } while (0) 199 + 200 +/* Remove zero to seven bits as needed to go to a byte boundary */ 201 +#define BYTEBITS() \ 202 + do { \ 203 + hold >>= bits & 7; \ 204 + bits -= bits & 7; \ 205 + } while (0) 206 + 207 +/* Assure that some output space is available, by writing out the window 208 + if it's full. If the write fails, return from inflateBack() with a 209 + Z_BUF_ERROR. */ 210 +#define ROOM() \ 211 + do { \ 212 + if (left == 0) { \ 213 + put = state->window; \ 214 + left = state->wsize; \ 215 + state->whave = left; \ 216 + if (out(out_desc, put, left)) { \ 217 + ret = Z_BUF_ERROR; \ 218 + goto inf_leave; \ 219 + } \ 220 + } \ 221 + } while (0) 222 + 223 +/* 224 + strm provides the memory allocation functions and window buffer on input, 225 + and provides information on the unused input on return. For Z_DATA_ERROR 226 + returns, strm will also provide an error message. 227 + 228 + in() and out() are the call-back input and output functions. When 229 + inflateBack() needs more input, it calls in(). When inflateBack() has 230 + filled the window with output, or when it completes with data in the 231 + window, it calls out() to write out the data. The application must not 232 + change the provided input until in() is called again or inflateBack() 233 + returns. The application must not change the window/output buffer until 234 + inflateBack() returns. 235 + 236 + in() and out() are called with a descriptor parameter provided in the 237 + inflateBack() call. This parameter can be a structure that provides the 238 + information required to do the read or write, as well as accumulated 239 + information on the input and output such as totals and check values. 240 + 241 + in() should return zero on failure. out() should return non-zero on 242 + failure. If either in() or out() fails, than inflateBack() returns a 243 + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it 244 + was in() or out() that caused in the error. Otherwise, inflateBack() 245 + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format 246 + error, or Z_MEM_ERROR if it could not allocate memory for the state. 247 + inflateBack() can also return Z_STREAM_ERROR if the input parameters 248 + are not correct, i.e. strm is Z_NULL or the state was not initialized. 249 + */ 250 +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) 251 +z_streamp strm; 252 +in_func in; 253 +void FAR *in_desc; 254 +out_func out; 255 +void FAR *out_desc; 256 +{ 257 + struct inflate_state FAR *state; 258 + unsigned char FAR *next; /* next input */ 259 + unsigned char FAR *put; /* next output */ 260 + unsigned have, left; /* available input and output */ 261 + unsigned long hold; /* bit buffer */ 262 + unsigned bits; /* bits in bit buffer */ 263 + unsigned copy; /* number of stored or match bytes to copy */ 264 + unsigned char FAR *from; /* where to copy match bytes from */ 265 + code here; /* current decoding table entry */ 266 + code last; /* parent table entry */ 267 + unsigned len; /* length to copy for repeats, bits to drop */ 268 + int ret; /* return code */ 269 + static const unsigned short order[19] = /* permutation of code lengths */ 270 + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 271 + 272 + /* Check that the strm exists and that the state was initialized */ 273 + if (strm == Z_NULL || strm->state == Z_NULL) 274 + return Z_STREAM_ERROR; 275 + state = (struct inflate_state FAR *)strm->state; 276 + 277 + /* Reset the state */ 278 + strm->msg = Z_NULL; 279 + state->mode = TYPE; 280 + state->last = 0; 281 + state->whave = 0; 282 + next = strm->next_in; 283 + have = next != Z_NULL ? strm->avail_in : 0; 284 + hold = 0; 285 + bits = 0; 286 + put = state->window; 287 + left = state->wsize; 288 + 289 + /* Inflate until end of block marked as last */ 290 + for (;;) 291 + switch (state->mode) { 292 + case TYPE: 293 + /* determine and dispatch block type */ 294 + if (state->last) { 295 + BYTEBITS(); 296 + state->mode = DONE; 297 + break; 298 + } 299 + NEEDBITS(3); 300 + state->last = BITS(1); 301 + DROPBITS(1); 302 + switch (BITS(2)) { 303 + case 0: /* stored block */ 304 + Tracev((stderr, "inflate: stored block%s\n", 305 + state->last ? " (last)" : "")); 306 + state->mode = STORED; 307 + break; 308 + case 1: /* fixed block */ 309 + fixedtables(state); 310 + Tracev((stderr, "inflate: fixed codes block%s\n", 311 + state->last ? " (last)" : "")); 312 + state->mode = LEN; /* decode codes */ 313 + break; 314 + case 2: /* dynamic block */ 315 + Tracev((stderr, "inflate: dynamic codes block%s\n", 316 + state->last ? " (last)" : "")); 317 + state->mode = TABLE; 318 + break; 319 + case 3: 320 + strm->msg = (char *)"invalid block type"; 321 + state->mode = BAD; 322 + } 323 + DROPBITS(2); 324 + break; 325 + 326 + case STORED: 327 + /* get and verify stored block length */ 328 + BYTEBITS(); /* go to byte boundary */ 329 + NEEDBITS(32); 330 + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 331 + strm->msg = (char *)"invalid stored block lengths"; 332 + state->mode = BAD; 333 + break; 334 + } 335 + state->length = (unsigned)hold & 0xffff; 336 + Tracev((stderr, "inflate: stored length %u\n", 337 + state->length)); 338 + INITBITS(); 339 + 340 + /* copy stored block from input to output */ 341 + while (state->length != 0) { 342 + copy = state->length; 343 + PULL(); 344 + ROOM(); 345 + if (copy > have) copy = have; 346 + if (copy > left) copy = left; 347 + zmemcpy(put, next, copy); 348 + have -= copy; 349 + next += copy; 350 + left -= copy; 351 + put += copy; 352 + state->length -= copy; 353 + } 354 + Tracev((stderr, "inflate: stored end\n")); 355 + state->mode = TYPE; 356 + break; 357 + 358 + case TABLE: 359 + /* get dynamic table entries descriptor */ 360 + NEEDBITS(14); 361 + state->nlen = BITS(5) + 257; 362 + DROPBITS(5); 363 + state->ndist = BITS(5) + 1; 364 + DROPBITS(5); 365 + state->ncode = BITS(4) + 4; 366 + DROPBITS(4); 367 +#ifndef PKZIP_BUG_WORKAROUND 368 + if (state->nlen > 286 || state->ndist > 30) { 369 + strm->msg = (char *)"too many length or distance symbols"; 370 + state->mode = BAD; 371 + break; 372 + } 373 +#endif 374 + Tracev((stderr, "inflate: table sizes ok\n")); 375 + 376 + /* get code length code lengths (not a typo) */ 377 + state->have = 0; 378 + while (state->have < state->ncode) { 379 + NEEDBITS(3); 380 + state->lens[order[state->have++]] = (unsigned short)BITS(3); 381 + DROPBITS(3); 382 + } 383 + while (state->have < 19) 384 + state->lens[order[state->have++]] = 0; 385 + state->next = state->codes; 386 + state->lencode = (code const FAR *)(state->next); 387 + state->lenbits = 7; 388 + ret = inflate_table(CODES, state->lens, 19, &(state->next), 389 + &(state->lenbits), state->work); 390 + if (ret) { 391 + strm->msg = (char *)"invalid code lengths set"; 392 + state->mode = BAD; 393 + break; 394 + } 395 + Tracev((stderr, "inflate: code lengths ok\n")); 396 + 397 + /* get length and distance code code lengths */ 398 + state->have = 0; 399 + while (state->have < state->nlen + state->ndist) { 400 + for (;;) { 401 + here = state->lencode[BITS(state->lenbits)]; 402 + if ((unsigned)(here.bits) <= bits) break; 403 + PULLBYTE(); 404 + } 405 + if (here.val < 16) { 406 + DROPBITS(here.bits); 407 + state->lens[state->have++] = here.val; 408 + } 409 + else { 410 + if (here.val == 16) { 411 + NEEDBITS(here.bits + 2); 412 + DROPBITS(here.bits); 413 + if (state->have == 0) { 414 + strm->msg = (char *)"invalid bit length repeat"; 415 + state->mode = BAD; 416 + break; 417 + } 418 + len = (unsigned)(state->lens[state->have - 1]); 419 + copy = 3 + BITS(2); 420 + DROPBITS(2); 421 + } 422 + else if (here.val == 17) { 423 + NEEDBITS(here.bits + 3); 424 + DROPBITS(here.bits); 425 + len = 0; 426 + copy = 3 + BITS(3); 427 + DROPBITS(3); 428 + } 429 + else { 430 + NEEDBITS(here.bits + 7); 431 + DROPBITS(here.bits); 432 + len = 0; 433 + copy = 11 + BITS(7); 434 + DROPBITS(7); 435 + } 436 + if (state->have + copy > state->nlen + state->ndist) { 437 + strm->msg = (char *)"invalid bit length repeat"; 438 + state->mode = BAD; 439 + break; 440 + } 441 + while (copy--) 442 + state->lens[state->have++] = (unsigned short)len; 443 + } 444 + } 445 + 446 + /* handle error breaks in while */ 447 + if (state->mode == BAD) break; 448 + 449 + /* check for end-of-block code (better have one) */ 450 + if (state->lens[256] == 0) { 451 + strm->msg = (char *)"invalid code -- missing end-of-block"; 452 + state->mode = BAD; 453 + break; 454 + } 455 + 456 + /* build code tables -- note: do not change the lenbits or distbits 457 + values here (9 and 6) without reading the comments in inftrees.h 458 + concerning the ENOUGH constants, which depend on those values */ 459 + state->next = state->codes; 460 + state->lencode = (code const FAR *)(state->next); 461 + state->lenbits = 9; 462 + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 463 + &(state->lenbits), state->work); 464 + if (ret) { 465 + strm->msg = (char *)"invalid literal/lengths set"; 466 + state->mode = BAD; 467 + break; 468 + } 469 + state->distcode = (code const FAR *)(state->next); 470 + state->distbits = 6; 471 + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 472 + &(state->next), &(state->distbits), state->work); 473 + if (ret) { 474 + strm->msg = (char *)"invalid distances set"; 475 + state->mode = BAD; 476 + break; 477 + } 478 + Tracev((stderr, "inflate: codes ok\n")); 479 + state->mode = LEN; 480 + 481 + case LEN: 482 + /* use inflate_fast() if we have enough input and output */ 483 + if (have >= 6 && left >= 258) { 484 + RESTORE(); 485 + if (state->whave < state->wsize) 486 + state->whave = state->wsize - left; 487 + inflate_fast(strm, state->wsize); 488 + LOAD(); 489 + break; 490 + } 491 + 492 + /* get a literal, length, or end-of-block code */ 493 + for (;;) { 494 + here = state->lencode[BITS(state->lenbits)]; 495 + if ((unsigned)(here.bits) <= bits) break; 496 + PULLBYTE(); 497 + } 498 + if (here.op && (here.op & 0xf0) == 0) { 499 + last = here; 500 + for (;;) { 501 + here = state->lencode[last.val + 502 + (BITS(last.bits + last.op) >> last.bits)]; 503 + if ((unsigned)(last.bits + here.bits) <= bits) break; 504 + PULLBYTE(); 505 + } 506 + DROPBITS(last.bits); 507 + } 508 + DROPBITS(here.bits); 509 + state->length = (unsigned)here.val; 510 + 511 + /* process literal */ 512 + if (here.op == 0) { 513 + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 514 + "inflate: literal '%c'\n" : 515 + "inflate: literal 0x%02x\n", here.val)); 516 + ROOM(); 517 + *put++ = (unsigned char)(state->length); 518 + left--; 519 + state->mode = LEN; 520 + break; 521 + } 522 + 523 + /* process end of block */ 524 + if (here.op & 32) { 525 + Tracevv((stderr, "inflate: end of block\n")); 526 + state->mode = TYPE; 527 + break; 528 + } 529 + 530 + /* invalid code */ 531 + if (here.op & 64) { 532 + strm->msg = (char *)"invalid literal/length code"; 533 + state->mode = BAD; 534 + break; 535 + } 536 + 537 + /* length code -- get extra bits, if any */ 538 + state->extra = (unsigned)(here.op) & 15; 539 + if (state->extra != 0) { 540 + NEEDBITS(state->extra); 541 + state->length += BITS(state->extra); 542 + DROPBITS(state->extra); 543 + } 544 + Tracevv((stderr, "inflate: length %u\n", state->length)); 545 + 546 + /* get distance code */ 547 + for (;;) { 548 + here = state->distcode[BITS(state->distbits)]; 549 + if ((unsigned)(here.bits) <= bits) break; 550 + PULLBYTE(); 551 + } 552 + if ((here.op & 0xf0) == 0) { 553 + last = here; 554 + for (;;) { 555 + here = state->distcode[last.val + 556 + (BITS(last.bits + last.op) >> last.bits)]; 557 + if ((unsigned)(last.bits + here.bits) <= bits) break; 558 + PULLBYTE(); 559 + } 560 + DROPBITS(last.bits); 561 + } 562 + DROPBITS(here.bits); 563 + if (here.op & 64) { 564 + strm->msg = (char *)"invalid distance code"; 565 + state->mode = BAD; 566 + break; 567 + } 568 + state->offset = (unsigned)here.val; 569 + 570 + /* get distance extra bits, if any */ 571 + state->extra = (unsigned)(here.op) & 15; 572 + if (state->extra != 0) { 573 + NEEDBITS(state->extra); 574 + state->offset += BITS(state->extra); 575 + DROPBITS(state->extra); 576 + } 577 + if (state->offset > state->wsize - (state->whave < state->wsize ? 578 + left : 0)) { 579 + strm->msg = (char *)"invalid distance too far back"; 580 + state->mode = BAD; 581 + break; 582 + } 583 + Tracevv((stderr, "inflate: distance %u\n", state->offset)); 584 + 585 + /* copy match from window to output */ 586 + do { 587 + ROOM(); 588 + copy = state->wsize - state->offset; 589 + if (copy < left) { 590 + from = put + copy; 591 + copy = left - copy; 592 + } 593 + else { 594 + from = put - state->offset; 595 + copy = left; 596 + } 597 + if (copy > state->length) copy = state->length; 598 + state->length -= copy; 599 + left -= copy; 600 + do { 601 + *put++ = *from++; 602 + } while (--copy); 603 + } while (state->length != 0); 604 + break; 605 + 606 + case DONE: 607 + /* inflate stream terminated properly -- write leftover output */ 608 + ret = Z_STREAM_END; 609 + if (left < state->wsize) { 610 + if (out(out_desc, state->window, state->wsize - left)) 611 + ret = Z_BUF_ERROR; 612 + } 613 + goto inf_leave; 614 + 615 + case BAD: 616 + ret = Z_DATA_ERROR; 617 + goto inf_leave; 618 + 619 + default: /* can't happen, but makes compilers happy */ 620 + ret = Z_STREAM_ERROR; 621 + goto inf_leave; 622 + } 623 + 624 + /* Return unused input */ 625 + inf_leave: 626 + strm->next_in = next; 627 + strm->avail_in = have; 628 + return ret; 629 +} 630 + 631 +int ZEXPORT inflateBackEnd(strm) 632 +z_streamp strm; 633 +{ 634 + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 635 + return Z_STREAM_ERROR; 636 + ZFREE(strm, strm->state); 637 + strm->state = Z_NULL; 638 + Tracev((stderr, "inflate: end\n")); 639 + return Z_OK; 640 +}
Added compat/zlib/inffast.c.
1 +/* inffast.c -- fast decoding 2 + * Copyright (C) 1995-2008, 2010 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "zutil.h" 7 +#include "inftrees.h" 8 +#include "inflate.h" 9 +#include "inffast.h" 10 + 11 +#ifndef ASMINF 12 + 13 +/* Allow machine dependent optimization for post-increment or pre-increment. 14 + Based on testing to date, 15 + Pre-increment preferred for: 16 + - PowerPC G3 (Adler) 17 + - MIPS R5000 (Randers-Pehrson) 18 + Post-increment preferred for: 19 + - none 20 + No measurable difference: 21 + - Pentium III (Anderson) 22 + - M68060 (Nikl) 23 + */ 24 +#ifdef POSTINC 25 +# define OFF 0 26 +# define PUP(a) *(a)++ 27 +#else 28 +# define OFF 1 29 +# define PUP(a) *++(a) 30 +#endif 31 + 32 +/* 33 + Decode literal, length, and distance codes and write out the resulting 34 + literal and match bytes until either not enough input or output is 35 + available, an end-of-block is encountered, or a data error is encountered. 36 + When large enough input and output buffers are supplied to inflate(), for 37 + example, a 16K input buffer and a 64K output buffer, more than 95% of the 38 + inflate execution time is spent in this routine. 39 + 40 + Entry assumptions: 41 + 42 + state->mode == LEN 43 + strm->avail_in >= 6 44 + strm->avail_out >= 258 45 + start >= strm->avail_out 46 + state->bits < 8 47 + 48 + On return, state->mode is one of: 49 + 50 + LEN -- ran out of enough output space or enough available input 51 + TYPE -- reached end of block code, inflate() to interpret next block 52 + BAD -- error in block data 53 + 54 + Notes: 55 + 56 + - The maximum input bits used by a length/distance pair is 15 bits for the 57 + length code, 5 bits for the length extra, 15 bits for the distance code, 58 + and 13 bits for the distance extra. This totals 48 bits, or six bytes. 59 + Therefore if strm->avail_in >= 6, then there is enough input to avoid 60 + checking for available input while decoding. 61 + 62 + - The maximum bytes that a single length/distance pair can output is 258 63 + bytes, which is the maximum length that can be coded. inflate_fast() 64 + requires strm->avail_out >= 258 for each loop to avoid checking for 65 + output space. 66 + */ 67 +void ZLIB_INTERNAL inflate_fast(strm, start) 68 +z_streamp strm; 69 +unsigned start; /* inflate()'s starting value for strm->avail_out */ 70 +{ 71 + struct inflate_state FAR *state; 72 + unsigned char FAR *in; /* local strm->next_in */ 73 + unsigned char FAR *last; /* while in < last, enough input available */ 74 + unsigned char FAR *out; /* local strm->next_out */ 75 + unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 76 + unsigned char FAR *end; /* while out < end, enough space available */ 77 +#ifdef INFLATE_STRICT 78 + unsigned dmax; /* maximum distance from zlib header */ 79 +#endif 80 + unsigned wsize; /* window size or zero if not using window */ 81 + unsigned whave; /* valid bytes in the window */ 82 + unsigned wnext; /* window write index */ 83 + unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ 84 + unsigned long hold; /* local strm->hold */ 85 + unsigned bits; /* local strm->bits */ 86 + code const FAR *lcode; /* local strm->lencode */ 87 + code const FAR *dcode; /* local strm->distcode */ 88 + unsigned lmask; /* mask for first level of length codes */ 89 + unsigned dmask; /* mask for first level of distance codes */ 90 + code here; /* retrieved table entry */ 91 + unsigned op; /* code bits, operation, extra bits, or */ 92 + /* window position, window bytes to copy */ 93 + unsigned len; /* match length, unused bytes */ 94 + unsigned dist; /* match distance */ 95 + unsigned char FAR *from; /* where to copy match from */ 96 + 97 + /* copy state to local variables */ 98 + state = (struct inflate_state FAR *)strm->state; 99 + in = strm->next_in - OFF; 100 + last = in + (strm->avail_in - 5); 101 + out = strm->next_out - OFF; 102 + beg = out - (start - strm->avail_out); 103 + end = out + (strm->avail_out - 257); 104 +#ifdef INFLATE_STRICT 105 + dmax = state->dmax; 106 +#endif 107 + wsize = state->wsize; 108 + whave = state->whave; 109 + wnext = state->wnext; 110 + window = state->window; 111 + hold = state->hold; 112 + bits = state->bits; 113 + lcode = state->lencode; 114 + dcode = state->distcode; 115 + lmask = (1U << state->lenbits) - 1; 116 + dmask = (1U << state->distbits) - 1; 117 + 118 + /* decode literals and length/distances until end-of-block or not enough 119 + input data or output space */ 120 + do { 121 + if (bits < 15) { 122 + hold += (unsigned long)(PUP(in)) << bits; 123 + bits += 8; 124 + hold += (unsigned long)(PUP(in)) << bits; 125 + bits += 8; 126 + } 127 + here = lcode[hold & lmask]; 128 + dolen: 129 + op = (unsigned)(here.bits); 130 + hold >>= op; 131 + bits -= op; 132 + op = (unsigned)(here.op); 133 + if (op == 0) { /* literal */ 134 + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 135 + "inflate: literal '%c'\n" : 136 + "inflate: literal 0x%02x\n", here.val)); 137 + PUP(out) = (unsigned char)(here.val); 138 + } 139 + else if (op & 16) { /* length base */ 140 + len = (unsigned)(here.val); 141 + op &= 15; /* number of extra bits */ 142 + if (op) { 143 + if (bits < op) { 144 + hold += (unsigned long)(PUP(in)) << bits; 145 + bits += 8; 146 + } 147 + len += (unsigned)hold & ((1U << op) - 1); 148 + hold >>= op; 149 + bits -= op; 150 + } 151 + Tracevv((stderr, "inflate: length %u\n", len)); 152 + if (bits < 15) { 153 + hold += (unsigned long)(PUP(in)) << bits; 154 + bits += 8; 155 + hold += (unsigned long)(PUP(in)) << bits; 156 + bits += 8; 157 + } 158 + here = dcode[hold & dmask]; 159 + dodist: 160 + op = (unsigned)(here.bits); 161 + hold >>= op; 162 + bits -= op; 163 + op = (unsigned)(here.op); 164 + if (op & 16) { /* distance base */ 165 + dist = (unsigned)(here.val); 166 + op &= 15; /* number of extra bits */ 167 + if (bits < op) { 168 + hold += (unsigned long)(PUP(in)) << bits; 169 + bits += 8; 170 + if (bits < op) { 171 + hold += (unsigned long)(PUP(in)) << bits; 172 + bits += 8; 173 + } 174 + } 175 + dist += (unsigned)hold & ((1U << op) - 1); 176 +#ifdef INFLATE_STRICT 177 + if (dist > dmax) { 178 + strm->msg = (char *)"invalid distance too far back"; 179 + state->mode = BAD; 180 + break; 181 + } 182 +#endif 183 + hold >>= op; 184 + bits -= op; 185 + Tracevv((stderr, "inflate: distance %u\n", dist)); 186 + op = (unsigned)(out - beg); /* max distance in output */ 187 + if (dist > op) { /* see if copy from window */ 188 + op = dist - op; /* distance back in window */ 189 + if (op > whave) { 190 + if (state->sane) { 191 + strm->msg = 192 + (char *)"invalid distance too far back"; 193 + state->mode = BAD; 194 + break; 195 + } 196 +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 197 + if (len <= op - whave) { 198 + do { 199 + PUP(out) = 0; 200 + } while (--len); 201 + continue; 202 + } 203 + len -= op - whave; 204 + do { 205 + PUP(out) = 0; 206 + } while (--op > whave); 207 + if (op == 0) { 208 + from = out - dist; 209 + do { 210 + PUP(out) = PUP(from); 211 + } while (--len); 212 + continue; 213 + } 214 +#endif 215 + } 216 + from = window - OFF; 217 + if (wnext == 0) { /* very common case */ 218 + from += wsize - op; 219 + if (op < len) { /* some from window */ 220 + len -= op; 221 + do { 222 + PUP(out) = PUP(from); 223 + } while (--op); 224 + from = out - dist; /* rest from output */ 225 + } 226 + } 227 + else if (wnext < op) { /* wrap around window */ 228 + from += wsize + wnext - op; 229 + op -= wnext; 230 + if (op < len) { /* some from end of window */ 231 + len -= op; 232 + do { 233 + PUP(out) = PUP(from); 234 + } while (--op); 235 + from = window - OFF; 236 + if (wnext < len) { /* some from start of window */ 237 + op = wnext; 238 + len -= op; 239 + do { 240 + PUP(out) = PUP(from); 241 + } while (--op); 242 + from = out - dist; /* rest from output */ 243 + } 244 + } 245 + } 246 + else { /* contiguous in window */ 247 + from += wnext - op; 248 + if (op < len) { /* some from window */ 249 + len -= op; 250 + do { 251 + PUP(out) = PUP(from); 252 + } while (--op); 253 + from = out - dist; /* rest from output */ 254 + } 255 + } 256 + while (len > 2) { 257 + PUP(out) = PUP(from); 258 + PUP(out) = PUP(from); 259 + PUP(out) = PUP(from); 260 + len -= 3; 261 + } 262 + if (len) { 263 + PUP(out) = PUP(from); 264 + if (len > 1) 265 + PUP(out) = PUP(from); 266 + } 267 + } 268 + else { 269 + from = out - dist; /* copy direct from output */ 270 + do { /* minimum length is three */ 271 + PUP(out) = PUP(from); 272 + PUP(out) = PUP(from); 273 + PUP(out) = PUP(from); 274 + len -= 3; 275 + } while (len > 2); 276 + if (len) { 277 + PUP(out) = PUP(from); 278 + if (len > 1) 279 + PUP(out) = PUP(from); 280 + } 281 + } 282 + } 283 + else if ((op & 64) == 0) { /* 2nd level distance code */ 284 + here = dcode[here.val + (hold & ((1U << op) - 1))]; 285 + goto dodist; 286 + } 287 + else { 288 + strm->msg = (char *)"invalid distance code"; 289 + state->mode = BAD; 290 + break; 291 + } 292 + } 293 + else if ((op & 64) == 0) { /* 2nd level length code */ 294 + here = lcode[here.val + (hold & ((1U << op) - 1))]; 295 + goto dolen; 296 + } 297 + else if (op & 32) { /* end-of-block */ 298 + Tracevv((stderr, "inflate: end of block\n")); 299 + state->mode = TYPE; 300 + break; 301 + } 302 + else { 303 + strm->msg = (char *)"invalid literal/length code"; 304 + state->mode = BAD; 305 + break; 306 + } 307 + } while (in < last && out < end); 308 + 309 + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 310 + len = bits >> 3; 311 + in -= len; 312 + bits -= len << 3; 313 + hold &= (1U << bits) - 1; 314 + 315 + /* update state and return */ 316 + strm->next_in = in + OFF; 317 + strm->next_out = out + OFF; 318 + strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 319 + strm->avail_out = (unsigned)(out < end ? 320 + 257 + (end - out) : 257 - (out - end)); 321 + state->hold = hold; 322 + state->bits = bits; 323 + return; 324 +} 325 + 326 +/* 327 + inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): 328 + - Using bit fields for code structure 329 + - Different op definition to avoid & for extra bits (do & for table bits) 330 + - Three separate decoding do-loops for direct, window, and wnext == 0 331 + - Special case for distance > 1 copies to do overlapped load and store copy 332 + - Explicit branch predictions (based on measured branch probabilities) 333 + - Deferring match copy and interspersed it with decoding subsequent codes 334 + - Swapping literal/length else 335 + - Swapping window/direct else 336 + - Larger unrolled copy loops (three is about right) 337 + - Moving len -= 3 statement into middle of loop 338 + */ 339 + 340 +#endif /* !ASMINF */
Added compat/zlib/inffast.h.
1 +/* inffast.h -- header to use inffast.c 2 + * Copyright (C) 1995-2003, 2010 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
Added compat/zlib/inffixed.h.
1 + /* inffixed.h -- table for decoding fixed codes 2 + * Generated automatically by makefixed(). 3 + */ 4 + 5 + /* WARNING: this file should *not* be used by applications. 6 + It is part of the implementation of this library and is 7 + subject to change. Applications should only use zlib.h. 8 + */ 9 + 10 + static const code lenfix[512] = { 11 + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 + {0,9,255} 85 + }; 86 + 87 + static const code distfix[32] = { 88 + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 + {22,5,193},{64,5,0} 94 + };
Added compat/zlib/inflate.c.
1 +/* inflate.c -- zlib decompression 2 + * Copyright (C) 1995-2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* 7 + * Change history: 8 + * 9 + * 1.2.beta0 24 Nov 2002 10 + * - First version -- complete rewrite of inflate to simplify code, avoid 11 + * creation of window when not needed, minimize use of window when it is 12 + * needed, make inffast.c even faster, implement gzip decoding, and to 13 + * improve code readability and style over the previous zlib inflate code 14 + * 15 + * 1.2.beta1 25 Nov 2002 16 + * - Use pointers for available input and output checking in inffast.c 17 + * - Remove input and output counters in inffast.c 18 + * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 19 + * - Remove unnecessary second byte pull from length extra in inffast.c 20 + * - Unroll direct copy to three copies per loop in inffast.c 21 + * 22 + * 1.2.beta2 4 Dec 2002 23 + * - Change external routine names to reduce potential conflicts 24 + * - Correct filename to inffixed.h for fixed tables in inflate.c 25 + * - Make hbuf[] unsigned char to match parameter type in inflate.c 26 + * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) 27 + * to avoid negation problem on Alphas (64 bit) in inflate.c 28 + * 29 + * 1.2.beta3 22 Dec 2002 30 + * - Add comments on state->bits assertion in inffast.c 31 + * - Add comments on op field in inftrees.h 32 + * - Fix bug in reuse of allocated window after inflateReset() 33 + * - Remove bit fields--back to byte structure for speed 34 + * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths 35 + * - Change post-increments to pre-increments in inflate_fast(), PPC biased? 36 + * - Add compile time option, POSTINC, to use post-increments instead (Intel?) 37 + * - Make MATCH copy in inflate() much faster for when inflate_fast() not used 38 + * - Use local copies of stream next and avail values, as well as local bit 39 + * buffer and bit count in inflate()--for speed when inflate_fast() not used 40 + * 41 + * 1.2.beta4 1 Jan 2003 42 + * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings 43 + * - Move a comment on output buffer sizes from inffast.c to inflate.c 44 + * - Add comments in inffast.c to introduce the inflate_fast() routine 45 + * - Rearrange window copies in inflate_fast() for speed and simplification 46 + * - Unroll last copy for window match in inflate_fast() 47 + * - Use local copies of window variables in inflate_fast() for speed 48 + * - Pull out common wnext == 0 case for speed in inflate_fast() 49 + * - Make op and len in inflate_fast() unsigned for consistency 50 + * - Add FAR to lcode and dcode declarations in inflate_fast() 51 + * - Simplified bad distance check in inflate_fast() 52 + * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new 53 + * source file infback.c to provide a call-back interface to inflate for 54 + * programs like gzip and unzip -- uses window as output buffer to avoid 55 + * window copying 56 + * 57 + * 1.2.beta5 1 Jan 2003 58 + * - Improved inflateBack() interface to allow the caller to provide initial 59 + * input in strm. 60 + * - Fixed stored blocks bug in inflateBack() 61 + * 62 + * 1.2.beta6 4 Jan 2003 63 + * - Added comments in inffast.c on effectiveness of POSTINC 64 + * - Typecasting all around to reduce compiler warnings 65 + * - Changed loops from while (1) or do {} while (1) to for (;;), again to 66 + * make compilers happy 67 + * - Changed type of window in inflateBackInit() to unsigned char * 68 + * 69 + * 1.2.beta7 27 Jan 2003 70 + * - Changed many types to unsigned or unsigned short to avoid warnings 71 + * - Added inflateCopy() function 72 + * 73 + * 1.2.0 9 Mar 2003 74 + * - Changed inflateBack() interface to provide separate opaque descriptors 75 + * for the in() and out() functions 76 + * - Changed inflateBack() argument and in_func typedef to swap the length 77 + * and buffer address return values for the input function 78 + * - Check next_in and next_out for Z_NULL on entry to inflate() 79 + * 80 + * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. 81 + */ 82 + 83 +#include "zutil.h" 84 +#include "inftrees.h" 85 +#include "inflate.h" 86 +#include "inffast.h" 87 + 88 +#ifdef MAKEFIXED 89 +# ifndef BUILDFIXED 90 +# define BUILDFIXED 91 +# endif 92 +#endif 93 + 94 +/* function prototypes */ 95 +local void fixedtables OF((struct inflate_state FAR *state)); 96 +local int updatewindow OF((z_streamp strm, unsigned out)); 97 +#ifdef BUILDFIXED 98 + void makefixed OF((void)); 99 +#endif 100 +local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, 101 + unsigned len)); 102 + 103 +int ZEXPORT inflateResetKeep(strm) 104 +z_streamp strm; 105 +{ 106 + struct inflate_state FAR *state; 107 + 108 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 109 + state = (struct inflate_state FAR *)strm->state; 110 + strm->total_in = strm->total_out = state->total = 0; 111 + strm->msg = Z_NULL; 112 + if (state->wrap) /* to support ill-conceived Java test suite */ 113 + strm->adler = state->wrap & 1; 114 + state->mode = HEAD; 115 + state->last = 0; 116 + state->havedict = 0; 117 + state->dmax = 32768U; 118 + state->head = Z_NULL; 119 + state->hold = 0; 120 + state->bits = 0; 121 + state->lencode = state->distcode = state->next = state->codes; 122 + state->sane = 1; 123 + state->back = -1; 124 + Tracev((stderr, "inflate: reset\n")); 125 + return Z_OK; 126 +} 127 + 128 +int ZEXPORT inflateReset(strm) 129 +z_streamp strm; 130 +{ 131 + struct inflate_state FAR *state; 132 + 133 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 134 + state = (struct inflate_state FAR *)strm->state; 135 + state->wsize = 0; 136 + state->whave = 0; 137 + state->wnext = 0; 138 + return inflateResetKeep(strm); 139 +} 140 + 141 +int ZEXPORT inflateReset2(strm, windowBits) 142 +z_streamp strm; 143 +int windowBits; 144 +{ 145 + int wrap; 146 + struct inflate_state FAR *state; 147 + 148 + /* get the state */ 149 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 150 + state = (struct inflate_state FAR *)strm->state; 151 + 152 + /* extract wrap request from windowBits parameter */ 153 + if (windowBits < 0) { 154 + wrap = 0; 155 + windowBits = -windowBits; 156 + } 157 + else { 158 + wrap = (windowBits >> 4) + 1; 159 +#ifdef GUNZIP 160 + if (windowBits < 48) 161 + windowBits &= 15; 162 +#endif 163 + } 164 + 165 + /* set number of window bits, free window if different */ 166 + if (windowBits && (windowBits < 8 || windowBits > 15)) 167 + return Z_STREAM_ERROR; 168 + if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { 169 + ZFREE(strm, state->window); 170 + state->window = Z_NULL; 171 + } 172 + 173 + /* update state and reset the rest of it */ 174 + state->wrap = wrap; 175 + state->wbits = (unsigned)windowBits; 176 + return inflateReset(strm); 177 +} 178 + 179 +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) 180 +z_streamp strm; 181 +int windowBits; 182 +const char *version; 183 +int stream_size; 184 +{ 185 + int ret; 186 + struct inflate_state FAR *state; 187 + 188 + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 189 + stream_size != (int)(sizeof(z_stream))) 190 + return Z_VERSION_ERROR; 191 + if (strm == Z_NULL) return Z_STREAM_ERROR; 192 + strm->msg = Z_NULL; /* in case we return an error */ 193 + if (strm->zalloc == (alloc_func)0) { 194 +#ifdef Z_SOLO 195 + return Z_STREAM_ERROR; 196 +#else 197 + strm->zalloc = zcalloc; 198 + strm->opaque = (voidpf)0; 199 +#endif 200 + } 201 + if (strm->zfree == (free_func)0) 202 +#ifdef Z_SOLO 203 + return Z_STREAM_ERROR; 204 +#else 205 + strm->zfree = zcfree; 206 +#endif 207 + state = (struct inflate_state FAR *) 208 + ZALLOC(strm, 1, sizeof(struct inflate_state)); 209 + if (state == Z_NULL) return Z_MEM_ERROR; 210 + Tracev((stderr, "inflate: allocated\n")); 211 + strm->state = (struct internal_state FAR *)state; 212 + state->window = Z_NULL; 213 + ret = inflateReset2(strm, windowBits); 214 + if (ret != Z_OK) { 215 + ZFREE(strm, state); 216 + strm->state = Z_NULL; 217 + } 218 + return ret; 219 +} 220 + 221 +int ZEXPORT inflateInit_(strm, version, stream_size) 222 +z_streamp strm; 223 +const char *version; 224 +int stream_size; 225 +{ 226 + return inflateInit2_(strm, DEF_WBITS, version, stream_size); 227 +} 228 + 229 +int ZEXPORT inflatePrime(strm, bits, value) 230 +z_streamp strm; 231 +int bits; 232 +int value; 233 +{ 234 + struct inflate_state FAR *state; 235 + 236 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 237 + state = (struct inflate_state FAR *)strm->state; 238 + if (bits < 0) { 239 + state->hold = 0; 240 + state->bits = 0; 241 + return Z_OK; 242 + } 243 + if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; 244 + value &= (1L << bits) - 1; 245 + state->hold += value << state->bits; 246 + state->bits += bits; 247 + return Z_OK; 248 +} 249 + 250 +/* 251 + Return state with length and distance decoding tables and index sizes set to 252 + fixed code decoding. Normally this returns fixed tables from inffixed.h. 253 + If BUILDFIXED is defined, then instead this routine builds the tables the 254 + first time it's called, and returns those tables the first time and 255 + thereafter. This reduces the size of the code by about 2K bytes, in 256 + exchange for a little execution time. However, BUILDFIXED should not be 257 + used for threaded applications, since the rewriting of the tables and virgin 258 + may not be thread-safe. 259 + */ 260 +local void fixedtables(state) 261 +struct inflate_state FAR *state; 262 +{ 263 +#ifdef BUILDFIXED 264 + static int virgin = 1; 265 + static code *lenfix, *distfix; 266 + static code fixed[544]; 267 + 268 + /* build fixed huffman tables if first call (may not be thread safe) */ 269 + if (virgin) { 270 + unsigned sym, bits; 271 + static code *next; 272 + 273 + /* literal/length table */ 274 + sym = 0; 275 + while (sym < 144) state->lens[sym++] = 8; 276 + while (sym < 256) state->lens[sym++] = 9; 277 + while (sym < 280) state->lens[sym++] = 7; 278 + while (sym < 288) state->lens[sym++] = 8; 279 + next = fixed; 280 + lenfix = next; 281 + bits = 9; 282 + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); 283 + 284 + /* distance table */ 285 + sym = 0; 286 + while (sym < 32) state->lens[sym++] = 5; 287 + distfix = next; 288 + bits = 5; 289 + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); 290 + 291 + /* do this just once */ 292 + virgin = 0; 293 + } 294 +#else /* !BUILDFIXED */ 295 +# include "inffixed.h" 296 +#endif /* BUILDFIXED */ 297 + state->lencode = lenfix; 298 + state->lenbits = 9; 299 + state->distcode = distfix; 300 + state->distbits = 5; 301 +} 302 + 303 +#ifdef MAKEFIXED 304 +#include <stdio.h> 305 + 306 +/* 307 + Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also 308 + defines BUILDFIXED, so the tables are built on the fly. makefixed() writes 309 + those tables to stdout, which would be piped to inffixed.h. A small program 310 + can simply call makefixed to do this: 311 + 312 + void makefixed(void); 313 + 314 + int main(void) 315 + { 316 + makefixed(); 317 + return 0; 318 + } 319 + 320 + Then that can be linked with zlib built with MAKEFIXED defined and run: 321 + 322 + a.out > inffixed.h 323 + */ 324 +void makefixed() 325 +{ 326 + unsigned low, size; 327 + struct inflate_state state; 328 + 329 + fixedtables(&state); 330 + puts(" /* inffixed.h -- table for decoding fixed codes"); 331 + puts(" * Generated automatically by makefixed()."); 332 + puts(" */"); 333 + puts(""); 334 + puts(" /* WARNING: this file should *not* be used by applications."); 335 + puts(" It is part of the implementation of this library and is"); 336 + puts(" subject to change. Applications should only use zlib.h."); 337 + puts(" */"); 338 + puts(""); 339 + size = 1U << 9; 340 + printf(" static const code lenfix[%u] = {", size); 341 + low = 0; 342 + for (;;) { 343 + if ((low % 7) == 0) printf("\n "); 344 + printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, 345 + state.lencode[low].bits, state.lencode[low].val); 346 + if (++low == size) break; 347 + putchar(','); 348 + } 349 + puts("\n };"); 350 + size = 1U << 5; 351 + printf("\n static const code distfix[%u] = {", size); 352 + low = 0; 353 + for (;;) { 354 + if ((low % 6) == 0) printf("\n "); 355 + printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, 356 + state.distcode[low].val); 357 + if (++low == size) break; 358 + putchar(','); 359 + } 360 + puts("\n };"); 361 +} 362 +#endif /* MAKEFIXED */ 363 + 364 +/* 365 + Update the window with the last wsize (normally 32K) bytes written before 366 + returning. If window does not exist yet, create it. This is only called 367 + when a window is already in use, or when output has been written during this 368 + inflate call, but the end of the deflate stream has not been reached yet. 369 + It is also called to create a window for dictionary data when a dictionary 370 + is loaded. 371 + 372 + Providing output buffers larger than 32K to inflate() should provide a speed 373 + advantage, since only the last 32K of output is copied to the sliding window 374 + upon return from inflate(), and since all distances after the first 32K of 375 + output will fall in the output data, making match copies simpler and faster. 376 + The advantage may be dependent on the size of the processor's data caches. 377 + */ 378 +local int updatewindow(strm, out) 379 +z_streamp strm; 380 +unsigned out; 381 +{ 382 + struct inflate_state FAR *state; 383 + unsigned copy, dist; 384 + 385 + state = (struct inflate_state FAR *)strm->state; 386 + 387 + /* if it hasn't been done already, allocate space for the window */ 388 + if (state->window == Z_NULL) { 389 + state->window = (unsigned char FAR *) 390 + ZALLOC(strm, 1U << state->wbits, 391 + sizeof(unsigned char)); 392 + if (state->window == Z_NULL) return 1; 393 + } 394 + 395 + /* if window not in use yet, initialize */ 396 + if (state->wsize == 0) { 397 + state->wsize = 1U << state->wbits; 398 + state->wnext = 0; 399 + state->whave = 0; 400 + } 401 + 402 + /* copy state->wsize or less output bytes into the circular window */ 403 + copy = out - strm->avail_out; 404 + if (copy >= state->wsize) { 405 + zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); 406 + state->wnext = 0; 407 + state->whave = state->wsize; 408 + } 409 + else { 410 + dist = state->wsize - state->wnext; 411 + if (dist > copy) dist = copy; 412 + zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); 413 + copy -= dist; 414 + if (copy) { 415 + zmemcpy(state->window, strm->next_out - copy, copy); 416 + state->wnext = copy; 417 + state->whave = state->wsize; 418 + } 419 + else { 420 + state->wnext += dist; 421 + if (state->wnext == state->wsize) state->wnext = 0; 422 + if (state->whave < state->wsize) state->whave += dist; 423 + } 424 + } 425 + return 0; 426 +} 427 + 428 +/* Macros for inflate(): */ 429 + 430 +/* check function to use adler32() for zlib or crc32() for gzip */ 431 +#ifdef GUNZIP 432 +# define UPDATE(check, buf, len) \ 433 + (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) 434 +#else 435 +# define UPDATE(check, buf, len) adler32(check, buf, len) 436 +#endif 437 + 438 +/* check macros for header crc */ 439 +#ifdef GUNZIP 440 +# define CRC2(check, word) \ 441 + do { \ 442 + hbuf[0] = (unsigned char)(word); \ 443 + hbuf[1] = (unsigned char)((word) >> 8); \ 444 + check = crc32(check, hbuf, 2); \ 445 + } while (0) 446 + 447 +# define CRC4(check, word) \ 448 + do { \ 449 + hbuf[0] = (unsigned char)(word); \ 450 + hbuf[1] = (unsigned char)((word) >> 8); \ 451 + hbuf[2] = (unsigned char)((word) >> 16); \ 452 + hbuf[3] = (unsigned char)((word) >> 24); \ 453 + check = crc32(check, hbuf, 4); \ 454 + } while (0) 455 +#endif 456 + 457 +/* Load registers with state in inflate() for speed */ 458 +#define LOAD() \ 459 + do { \ 460 + put = strm->next_out; \ 461 + left = strm->avail_out; \ 462 + next = strm->next_in; \ 463 + have = strm->avail_in; \ 464 + hold = state->hold; \ 465 + bits = state->bits; \ 466 + } while (0) 467 + 468 +/* Restore state from registers in inflate() */ 469 +#define RESTORE() \ 470 + do { \ 471 + strm->next_out = put; \ 472 + strm->avail_out = left; \ 473 + strm->next_in = next; \ 474 + strm->avail_in = have; \ 475 + state->hold = hold; \ 476 + state->bits = bits; \ 477 + } while (0) 478 + 479 +/* Clear the input bit accumulator */ 480 +#define INITBITS() \ 481 + do { \ 482 + hold = 0; \ 483 + bits = 0; \ 484 + } while (0) 485 + 486 +/* Get a byte of input into the bit accumulator, or return from inflate() 487 + if there is no input available. */ 488 +#define PULLBYTE() \ 489 + do { \ 490 + if (have == 0) goto inf_leave; \ 491 + have--; \ 492 + hold += (unsigned long)(*next++) << bits; \ 493 + bits += 8; \ 494 + } while (0) 495 + 496 +/* Assure that there are at least n bits in the bit accumulator. If there is 497 + not enough available input to do that, then return from inflate(). */ 498 +#define NEEDBITS(n) \ 499 + do { \ 500 + while (bits < (unsigned)(n)) \ 501 + PULLBYTE(); \ 502 + } while (0) 503 + 504 +/* Return the low n bits of the bit accumulator (n < 16) */ 505 +#define BITS(n) \ 506 + ((unsigned)hold & ((1U << (n)) - 1)) 507 + 508 +/* Remove n bits from the bit accumulator */ 509 +#define DROPBITS(n) \ 510 + do { \ 511 + hold >>= (n); \ 512 + bits -= (unsigned)(n); \ 513 + } while (0) 514 + 515 +/* Remove zero to seven bits as needed to go to a byte boundary */ 516 +#define BYTEBITS() \ 517 + do { \ 518 + hold >>= bits & 7; \ 519 + bits -= bits & 7; \ 520 + } while (0) 521 + 522 +/* 523 + inflate() uses a state machine to process as much input data and generate as 524 + much output data as possible before returning. The state machine is 525 + structured roughly as follows: 526 + 527 + for (;;) switch (state) { 528 + ... 529 + case STATEn: 530 + if (not enough input data or output space to make progress) 531 + return; 532 + ... make progress ... 533 + state = STATEm; 534 + break; 535 + ... 536 + } 537 + 538 + so when inflate() is called again, the same case is attempted again, and 539 + if the appropriate resources are provided, the machine proceeds to the 540 + next state. The NEEDBITS() macro is usually the way the state evaluates 541 + whether it can proceed or should return. NEEDBITS() does the return if 542 + the requested bits are not available. The typical use of the BITS macros 543 + is: 544 + 545 + NEEDBITS(n); 546 + ... do something with BITS(n) ... 547 + DROPBITS(n); 548 + 549 + where NEEDBITS(n) either returns from inflate() if there isn't enough 550 + input left to load n bits into the accumulator, or it continues. BITS(n) 551 + gives the low n bits in the accumulator. When done, DROPBITS(n) drops 552 + the low n bits off the accumulator. INITBITS() clears the accumulator 553 + and sets the number of available bits to zero. BYTEBITS() discards just 554 + enough bits to put the accumulator on a byte boundary. After BYTEBITS() 555 + and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. 556 + 557 + NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return 558 + if there is no input available. The decoding of variable length codes uses 559 + PULLBYTE() directly in order to pull just enough bytes to decode the next 560 + code, and no more. 561 + 562 + Some states loop until they get enough input, making sure that enough 563 + state information is maintained to continue the loop where it left off 564 + if NEEDBITS() returns in the loop. For example, want, need, and keep 565 + would all have to actually be part of the saved state in case NEEDBITS() 566 + returns: 567 + 568 + case STATEw: 569 + while (want < need) { 570 + NEEDBITS(n); 571 + keep[want++] = BITS(n); 572 + DROPBITS(n); 573 + } 574 + state = STATEx; 575 + case STATEx: 576 + 577 + As shown above, if the next state is also the next case, then the break 578 + is omitted. 579 + 580 + A state may also return if there is not enough output space available to 581 + complete that state. Those states are copying stored data, writing a 582 + literal byte, and copying a matching string. 583 + 584 + When returning, a "goto inf_leave" is used to update the total counters, 585 + update the check value, and determine whether any progress has been made 586 + during that inflate() call in order to return the proper return code. 587 + Progress is defined as a change in either strm->avail_in or strm->avail_out. 588 + When there is a window, goto inf_leave will update the window with the last 589 + output written. If a goto inf_leave occurs in the middle of decompression 590 + and there is no window currently, goto inf_leave will create one and copy 591 + output to the window for the next call of inflate(). 592 + 593 + In this implementation, the flush parameter of inflate() only affects the 594 + return code (per zlib.h). inflate() always writes as much as possible to 595 + strm->next_out, given the space available and the provided input--the effect 596 + documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers 597 + the allocation of and copying into a sliding window until necessary, which 598 + provides the effect documented in zlib.h for Z_FINISH when the entire input 599 + stream available. So the only thing the flush parameter actually does is: 600 + when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it 601 + will return Z_BUF_ERROR if it has not reached the end of the stream. 602 + */ 603 + 604 +int ZEXPORT inflate(strm, flush) 605 +z_streamp strm; 606 +int flush; 607 +{ 608 + struct inflate_state FAR *state; 609 + unsigned char FAR *next; /* next input */ 610 + unsigned char FAR *put; /* next output */ 611 + unsigned have, left; /* available input and output */ 612 + unsigned long hold; /* bit buffer */ 613 + unsigned bits; /* bits in bit buffer */ 614 + unsigned in, out; /* save starting available input and output */ 615 + unsigned copy; /* number of stored or match bytes to copy */ 616 + unsigned char FAR *from; /* where to copy match bytes from */ 617 + code here; /* current decoding table entry */ 618 + code last; /* parent table entry */ 619 + unsigned len; /* length to copy for repeats, bits to drop */ 620 + int ret; /* return code */ 621 +#ifdef GUNZIP 622 + unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ 623 +#endif 624 + static const unsigned short order[19] = /* permutation of code lengths */ 625 + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 626 + 627 + if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || 628 + (strm->next_in == Z_NULL && strm->avail_in != 0)) 629 + return Z_STREAM_ERROR; 630 + 631 + state = (struct inflate_state FAR *)strm->state; 632 + if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ 633 + LOAD(); 634 + in = have; 635 + out = left; 636 + ret = Z_OK; 637 + for (;;) 638 + switch (state->mode) { 639 + case HEAD: 640 + if (state->wrap == 0) { 641 + state->mode = TYPEDO; 642 + break; 643 + } 644 + NEEDBITS(16); 645 +#ifdef GUNZIP 646 + if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ 647 + state->check = crc32(0L, Z_NULL, 0); 648 + CRC2(state->check, hold); 649 + INITBITS(); 650 + state->mode = FLAGS; 651 + break; 652 + } 653 + state->flags = 0; /* expect zlib header */ 654 + if (state->head != Z_NULL) 655 + state->head->done = -1; 656 + if (!(state->wrap & 1) || /* check if zlib header allowed */ 657 +#else 658 + if ( 659 +#endif 660 + ((BITS(8) << 8) + (hold >> 8)) % 31) { 661 + strm->msg = (char *)"incorrect header check"; 662 + state->mode = BAD; 663 + break; 664 + } 665 + if (BITS(4) != Z_DEFLATED) { 666 + strm->msg = (char *)"unknown compression method"; 667 + state->mode = BAD; 668 + break; 669 + } 670 + DROPBITS(4); 671 + len = BITS(4) + 8; 672 + if (state->wbits == 0) 673 + state->wbits = len; 674 + else if (len > state->wbits) { 675 + strm->msg = (char *)"invalid window size"; 676 + state->mode = BAD; 677 + break; 678 + } 679 + state->dmax = 1U << len; 680 + Tracev((stderr, "inflate: zlib header ok\n")); 681 + strm->adler = state->check = adler32(0L, Z_NULL, 0); 682 + state->mode = hold & 0x200 ? DICTID : TYPE; 683 + INITBITS(); 684 + break; 685 +#ifdef GUNZIP 686 + case FLAGS: 687 + NEEDBITS(16); 688 + state->flags = (int)(hold); 689 + if ((state->flags & 0xff) != Z_DEFLATED) { 690 + strm->msg = (char *)"unknown compression method"; 691 + state->mode = BAD; 692 + break; 693 + } 694 + if (state->flags & 0xe000) { 695 + strm->msg = (char *)"unknown header flags set"; 696 + state->mode = BAD; 697 + break; 698 + } 699 + if (state->head != Z_NULL) 700 + state->head->text = (int)((hold >> 8) & 1); 701 + if (state->flags & 0x0200) CRC2(state->check, hold); 702 + INITBITS(); 703 + state->mode = TIME; 704 + case TIME: 705 + NEEDBITS(32); 706 + if (state->head != Z_NULL) 707 + state->head->time = hold; 708 + if (state->flags & 0x0200) CRC4(state->check, hold); 709 + INITBITS(); 710 + state->mode = OS; 711 + case OS: 712 + NEEDBITS(16); 713 + if (state->head != Z_NULL) { 714 + state->head->xflags = (int)(hold & 0xff); 715 + state->head->os = (int)(hold >> 8); 716 + } 717 + if (state->flags & 0x0200) CRC2(state->check, hold); 718 + INITBITS(); 719 + state->mode = EXLEN; 720 + case EXLEN: 721 + if (state->flags & 0x0400) { 722 + NEEDBITS(16); 723 + state->length = (unsigned)(hold); 724 + if (state->head != Z_NULL) 725 + state->head->extra_len = (unsigned)hold; 726 + if (state->flags & 0x0200) CRC2(state->check, hold); 727 + INITBITS(); 728 + } 729 + else if (state->head != Z_NULL) 730 + state->head->extra = Z_NULL; 731 + state->mode = EXTRA; 732 + case EXTRA: 733 + if (state->flags & 0x0400) { 734 + copy = state->length; 735 + if (copy > have) copy = have; 736 + if (copy) { 737 + if (state->head != Z_NULL && 738 + state->head->extra != Z_NULL) { 739 + len = state->head->extra_len - state->length; 740 + zmemcpy(state->head->extra + len, next, 741 + len + copy > state->head->extra_max ? 742 + state->head->extra_max - len : copy); 743 + } 744 + if (state->flags & 0x0200) 745 + state->check = crc32(state->check, next, copy); 746 + have -= copy; 747 + next += copy; 748 + state->length -= copy; 749 + } 750 + if (state->length) goto inf_leave; 751 + } 752 + state->length = 0; 753 + state->mode = NAME; 754 + case NAME: 755 + if (state->flags & 0x0800) { 756 + if (have == 0) goto inf_leave; 757 + copy = 0; 758 + do { 759 + len = (unsigned)(next[copy++]); 760 + if (state->head != Z_NULL && 761 + state->head->name != Z_NULL && 762 + state->length < state->head->name_max) 763 + state->head->name[state->length++] = len; 764 + } while (len && copy < have); 765 + if (state->flags & 0x0200) 766 + state->check = crc32(state->check, next, copy); 767 + have -= copy; 768 + next += copy; 769 + if (len) goto inf_leave; 770 + } 771 + else if (state->head != Z_NULL) 772 + state->head->name = Z_NULL; 773 + state->length = 0; 774 + state->mode = COMMENT; 775 + case COMMENT: 776 + if (state->flags & 0x1000) { 777 + if (have == 0) goto inf_leave; 778 + copy = 0; 779 + do { 780 + len = (unsigned)(next[copy++]); 781 + if (state->head != Z_NULL && 782 + state->head->comment != Z_NULL && 783 + state->length < state->head->comm_max) 784 + state->head->comment[state->length++] = len; 785 + } while (len && copy < have); 786 + if (state->flags & 0x0200) 787 + state->check = crc32(state->check, next, copy); 788 + have -= copy; 789 + next += copy; 790 + if (len) goto inf_leave; 791 + } 792 + else if (state->head != Z_NULL) 793 + state->head->comment = Z_NULL; 794 + state->mode = HCRC; 795 + case HCRC: 796 + if (state->flags & 0x0200) { 797 + NEEDBITS(16); 798 + if (hold != (state->check & 0xffff)) { 799 + strm->msg = (char *)"header crc mismatch"; 800 + state->mode = BAD; 801 + break; 802 + } 803 + INITBITS(); 804 + } 805 + if (state->head != Z_NULL) { 806 + state->head->hcrc = (int)((state->flags >> 9) & 1); 807 + state->head->done = 1; 808 + } 809 + strm->adler = state->check = crc32(0L, Z_NULL, 0); 810 + state->mode = TYPE; 811 + break; 812 +#endif 813 + case DICTID: 814 + NEEDBITS(32); 815 + strm->adler = state->check = ZSWAP32(hold); 816 + INITBITS(); 817 + state->mode = DICT; 818 + case DICT: 819 + if (state->havedict == 0) { 820 + RESTORE(); 821 + return Z_NEED_DICT; 822 + } 823 + strm->adler = state->check = adler32(0L, Z_NULL, 0); 824 + state->mode = TYPE; 825 + case TYPE: 826 + if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; 827 + case TYPEDO: 828 + if (state->last) { 829 + BYTEBITS(); 830 + state->mode = CHECK; 831 + break; 832 + } 833 + NEEDBITS(3); 834 + state->last = BITS(1); 835 + DROPBITS(1); 836 + switch (BITS(2)) { 837 + case 0: /* stored block */ 838 + Tracev((stderr, "inflate: stored block%s\n", 839 + state->last ? " (last)" : "")); 840 + state->mode = STORED; 841 + break; 842 + case 1: /* fixed block */ 843 + fixedtables(state); 844 + Tracev((stderr, "inflate: fixed codes block%s\n", 845 + state->last ? " (last)" : "")); 846 + state->mode = LEN_; /* decode codes */ 847 + if (flush == Z_TREES) { 848 + DROPBITS(2); 849 + goto inf_leave; 850 + } 851 + break; 852 + case 2: /* dynamic block */ 853 + Tracev((stderr, "inflate: dynamic codes block%s\n", 854 + state->last ? " (last)" : "")); 855 + state->mode = TABLE; 856 + break; 857 + case 3: 858 + strm->msg = (char *)"invalid block type"; 859 + state->mode = BAD; 860 + } 861 + DROPBITS(2); 862 + break; 863 + case STORED: 864 + BYTEBITS(); /* go to byte boundary */ 865 + NEEDBITS(32); 866 + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 867 + strm->msg = (char *)"invalid stored block lengths"; 868 + state->mode = BAD; 869 + break; 870 + } 871 + state->length = (unsigned)hold & 0xffff; 872 + Tracev((stderr, "inflate: stored length %u\n", 873 + state->length)); 874 + INITBITS(); 875 + state->mode = COPY_; 876 + if (flush == Z_TREES) goto inf_leave; 877 + case COPY_: 878 + state->mode = COPY; 879 + case COPY: 880 + copy = state->length; 881 + if (copy) { 882 + if (copy > have) copy = have; 883 + if (copy > left) copy = left; 884 + if (copy == 0) goto inf_leave; 885 + zmemcpy(put, next, copy); 886 + have -= copy; 887 + next += copy; 888 + left -= copy; 889 + put += copy; 890 + state->length -= copy; 891 + break; 892 + } 893 + Tracev((stderr, "inflate: stored end\n")); 894 + state->mode = TYPE; 895 + break; 896 + case TABLE: 897 + NEEDBITS(14); 898 + state->nlen = BITS(5) + 257; 899 + DROPBITS(5); 900 + state->ndist = BITS(5) + 1; 901 + DROPBITS(5); 902 + state->ncode = BITS(4) + 4; 903 + DROPBITS(4); 904 +#ifndef PKZIP_BUG_WORKAROUND 905 + if (state->nlen > 286 || state->ndist > 30) { 906 + strm->msg = (char *)"too many length or distance symbols"; 907 + state->mode = BAD; 908 + break; 909 + } 910 +#endif 911 + Tracev((stderr, "inflate: table sizes ok\n")); 912 + state->have = 0; 913 + state->mode = LENLENS; 914 + case LENLENS: 915 + while (state->have < state->ncode) { 916 + NEEDBITS(3); 917 + state->lens[order[state->have++]] = (unsigned short)BITS(3); 918 + DROPBITS(3); 919 + } 920 + while (state->have < 19) 921 + state->lens[order[state->have++]] = 0; 922 + state->next = state->codes; 923 + state->lencode = (code const FAR *)(state->next); 924 + state->lenbits = 7; 925 + ret = inflate_table(CODES, state->lens, 19, &(state->next), 926 + &(state->lenbits), state->work); 927 + if (ret) { 928 + strm->msg = (char *)"invalid code lengths set"; 929 + state->mode = BAD; 930 + break; 931 + } 932 + Tracev((stderr, "inflate: code lengths ok\n")); 933 + state->have = 0; 934 + state->mode = CODELENS; 935 + case CODELENS: 936 + while (state->have < state->nlen + state->ndist) { 937 + for (;;) { 938 + here = state->lencode[BITS(state->lenbits)]; 939 + if ((unsigned)(here.bits) <= bits) break; 940 + PULLBYTE(); 941 + } 942 + if (here.val < 16) { 943 + DROPBITS(here.bits); 944 + state->lens[state->have++] = here.val; 945 + } 946 + else { 947 + if (here.val == 16) { 948 + NEEDBITS(here.bits + 2); 949 + DROPBITS(here.bits); 950 + if (state->have == 0) { 951 + strm->msg = (char *)"invalid bit length repeat"; 952 + state->mode = BAD; 953 + break; 954 + } 955 + len = state->lens[state->have - 1]; 956 + copy = 3 + BITS(2); 957 + DROPBITS(2); 958 + } 959 + else if (here.val == 17) { 960 + NEEDBITS(here.bits + 3); 961 + DROPBITS(here.bits); 962 + len = 0; 963 + copy = 3 + BITS(3); 964 + DROPBITS(3); 965 + } 966 + else { 967 + NEEDBITS(here.bits + 7); 968 + DROPBITS(here.bits); 969 + len = 0; 970 + copy = 11 + BITS(7); 971 + DROPBITS(7); 972 + } 973 + if (state->have + copy > state->nlen + state->ndist) { 974 + strm->msg = (char *)"invalid bit length repeat"; 975 + state->mode = BAD; 976 + break; 977 + } 978 + while (copy--) 979 + state->lens[state->have++] = (unsigned short)len; 980 + } 981 + } 982 + 983 + /* handle error breaks in while */ 984 + if (state->mode == BAD) break; 985 + 986 + /* check for end-of-block code (better have one) */ 987 + if (state->lens[256] == 0) { 988 + strm->msg = (char *)"invalid code -- missing end-of-block"; 989 + state->mode = BAD; 990 + break; 991 + } 992 + 993 + /* build code tables -- note: do not change the lenbits or distbits 994 + values here (9 and 6) without reading the comments in inftrees.h 995 + concerning the ENOUGH constants, which depend on those values */ 996 + state->next = state->codes; 997 + state->lencode = (code const FAR *)(state->next); 998 + state->lenbits = 9; 999 + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 1000 + &(state->lenbits), state->work); 1001 + if (ret) { 1002 + strm->msg = (char *)"invalid literal/lengths set"; 1003 + state->mode = BAD; 1004 + break; 1005 + } 1006 + state->distcode = (code const FAR *)(state->next); 1007 + state->distbits = 6; 1008 + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 1009 + &(state->next), &(state->distbits), state->work); 1010 + if (ret) { 1011 + strm->msg = (char *)"invalid distances set"; 1012 + state->mode = BAD; 1013 + break; 1014 + } 1015 + Tracev((stderr, "inflate: codes ok\n")); 1016 + state->mode = LEN_; 1017 + if (flush == Z_TREES) goto inf_leave; 1018 + case LEN_: 1019 + state->mode = LEN; 1020 + case LEN: 1021 + if (have >= 6 && left >= 258) { 1022 + RESTORE(); 1023 + inflate_fast(strm, out); 1024 + LOAD(); 1025 + if (state->mode == TYPE) 1026 + state->back = -1; 1027 + break; 1028 + } 1029 + state->back = 0; 1030 + for (;;) { 1031 + here = state->lencode[BITS(state->lenbits)]; 1032 + if ((unsigned)(here.bits) <= bits) break; 1033 + PULLBYTE(); 1034 + } 1035 + if (here.op && (here.op & 0xf0) == 0) { 1036 + last = here; 1037 + for (;;) { 1038 + here = state->lencode[last.val + 1039 + (BITS(last.bits + last.op) >> last.bits)]; 1040 + if ((unsigned)(last.bits + here.bits) <= bits) break; 1041 + PULLBYTE(); 1042 + } 1043 + DROPBITS(last.bits); 1044 + state->back += last.bits; 1045 + } 1046 + DROPBITS(here.bits); 1047 + state->back += here.bits; 1048 + state->length = (unsigned)here.val; 1049 + if ((int)(here.op) == 0) { 1050 + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 1051 + "inflate: literal '%c'\n" : 1052 + "inflate: literal 0x%02x\n", here.val)); 1053 + state->mode = LIT; 1054 + break; 1055 + } 1056 + if (here.op & 32) { 1057 + Tracevv((stderr, "inflate: end of block\n")); 1058 + state->back = -1; 1059 + state->mode = TYPE; 1060 + break; 1061 + } 1062 + if (here.op & 64) { 1063 + strm->msg = (char *)"invalid literal/length code"; 1064 + state->mode = BAD; 1065 + break; 1066 + } 1067 + state->extra = (unsigned)(here.op) & 15; 1068 + state->mode = LENEXT; 1069 + case LENEXT: 1070 + if (state->extra) { 1071 + NEEDBITS(state->extra); 1072 + state->length += BITS(state->extra); 1073 + DROPBITS(state->extra); 1074 + state->back += state->extra; 1075 + } 1076 + Tracevv((stderr, "inflate: length %u\n", state->length)); 1077 + state->was = state->length; 1078 + state->mode = DIST; 1079 + case DIST: 1080 + for (;;) { 1081 + here = state->distcode[BITS(state->distbits)]; 1082 + if ((unsigned)(here.bits) <= bits) break; 1083 + PULLBYTE(); 1084 + } 1085 + if ((here.op & 0xf0) == 0) { 1086 + last = here; 1087 + for (;;) { 1088 + here = state->distcode[last.val + 1089 + (BITS(last.bits + last.op) >> last.bits)]; 1090 + if ((unsigned)(last.bits + here.bits) <= bits) break; 1091 + PULLBYTE(); 1092 + } 1093 + DROPBITS(last.bits); 1094 + state->back += last.bits; 1095 + } 1096 + DROPBITS(here.bits); 1097 + state->back += here.bits; 1098 + if (here.op & 64) { 1099 + strm->msg = (char *)"invalid distance code"; 1100 + state->mode = BAD; 1101 + break; 1102 + } 1103 + state->offset = (unsigned)here.val; 1104 + state->extra = (unsigned)(here.op) & 15; 1105 + state->mode = DISTEXT; 1106 + case DISTEXT: 1107 + if (state->extra) { 1108 + NEEDBITS(state->extra); 1109 + state->offset += BITS(state->extra); 1110 + DROPBITS(state->extra); 1111 + state->back += state->extra; 1112 + } 1113 +#ifdef INFLATE_STRICT 1114 + if (state->offset > state->dmax) { 1115 + strm->msg = (char *)"invalid distance too far back"; 1116 + state->mode = BAD; 1117 + break; 1118 + } 1119 +#endif 1120 + Tracevv((stderr, "inflate: distance %u\n", state->offset)); 1121 + state->mode = MATCH; 1122 + case MATCH: 1123 + if (left == 0) goto inf_leave; 1124 + copy = out - left; 1125 + if (state->offset > copy) { /* copy from window */ 1126 + copy = state->offset - copy; 1127 + if (copy > state->whave) { 1128 + if (state->sane) { 1129 + strm->msg = (char *)"invalid distance too far back"; 1130 + state->mode = BAD; 1131 + break; 1132 + } 1133 +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 1134 + Trace((stderr, "inflate.c too far\n")); 1135 + copy -= state->whave; 1136 + if (copy > state->length) copy = state->length; 1137 + if (copy > left) copy = left; 1138 + left -= copy; 1139 + state->length -= copy; 1140 + do { 1141 + *put++ = 0; 1142 + } while (--copy); 1143 + if (state->length == 0) state->mode = LEN; 1144 + break; 1145 +#endif 1146 + } 1147 + if (copy > state->wnext) { 1148 + copy -= state->wnext; 1149 + from = state->window + (state->wsize - copy); 1150 + } 1151 + else 1152 + from = state->window + (state->wnext - copy); 1153 + if (copy > state->length) copy = state->length; 1154 + } 1155 + else { /* copy from output */ 1156 + from = put - state->offset; 1157 + copy = state->length; 1158 + } 1159 + if (copy > left) copy = left; 1160 + left -= copy; 1161 + state->length -= copy; 1162 + do { 1163 + *put++ = *from++; 1164 + } while (--copy); 1165 + if (state->length == 0) state->mode = LEN; 1166 + break; 1167 + case LIT: 1168 + if (left == 0) goto inf_leave; 1169 + *put++ = (unsigned char)(state->length); 1170 + left--; 1171 + state->mode = LEN; 1172 + break; 1173 + case CHECK: 1174 + if (state->wrap) { 1175 + NEEDBITS(32); 1176 + out -= left; 1177 + strm->total_out += out; 1178 + state->total += out; 1179 + if (out) 1180 + strm->adler = state->check = 1181 + UPDATE(state->check, put - out, out); 1182 + out = left; 1183 + if (( 1184 +#ifdef GUNZIP 1185 + state->flags ? hold : 1186 +#endif 1187 + ZSWAP32(hold)) != state->check) { 1188 + strm->msg = (char *)"incorrect data check"; 1189 + state->mode = BAD; 1190 + break; 1191 + } 1192 + INITBITS(); 1193 + Tracev((stderr, "inflate: check matches trailer\n")); 1194 + } 1195 +#ifdef GUNZIP 1196 + state->mode = LENGTH; 1197 + case LENGTH: 1198 + if (state->wrap && state->flags) { 1199 + NEEDBITS(32); 1200 + if (hold != (state->total & 0xffffffffUL)) { 1201 + strm->msg = (char *)"incorrect length check"; 1202 + state->mode = BAD; 1203 + break; 1204 + } 1205 + INITBITS(); 1206 + Tracev((stderr, "inflate: length matches trailer\n")); 1207 + } 1208 +#endif 1209 + state->mode = DONE; 1210 + case DONE: 1211 + ret = Z_STREAM_END; 1212 + goto inf_leave; 1213 + case BAD: 1214 + ret = Z_DATA_ERROR; 1215 + goto inf_leave; 1216 + case MEM: 1217 + return Z_MEM_ERROR; 1218 + case SYNC: 1219 + default: 1220 + return Z_STREAM_ERROR; 1221 + } 1222 + 1223 + /* 1224 + Return from inflate(), updating the total counts and the check value. 1225 + If there was no progress during the inflate() call, return a buffer 1226 + error. Call updatewindow() to create and/or update the window state. 1227 + Note: a memory error from inflate() is non-recoverable. 1228 + */ 1229 + inf_leave: 1230 + RESTORE(); 1231 + if (state->wsize || (out != strm->avail_out && state->mode < BAD && 1232 + (state->mode < CHECK || flush != Z_FINISH))) 1233 + if (updatewindow(strm, out)) { 1234 + state->mode = MEM; 1235 + return Z_MEM_ERROR; 1236 + } 1237 + in -= strm->avail_in; 1238 + out -= strm->avail_out; 1239 + strm->total_in += in; 1240 + strm->total_out += out; 1241 + state->total += out; 1242 + if (state->wrap && out) 1243 + strm->adler = state->check = 1244 + UPDATE(state->check, strm->next_out - out, out); 1245 + strm->data_type = state->bits + (state->last ? 64 : 0) + 1246 + (state->mode == TYPE ? 128 : 0) + 1247 + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); 1248 + if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) 1249 + ret = Z_BUF_ERROR; 1250 + return ret; 1251 +} 1252 + 1253 +int ZEXPORT inflateEnd(strm) 1254 +z_streamp strm; 1255 +{ 1256 + struct inflate_state FAR *state; 1257 + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 1258 + return Z_STREAM_ERROR; 1259 + state = (struct inflate_state FAR *)strm->state; 1260 + if (state->window != Z_NULL) ZFREE(strm, state->window); 1261 + ZFREE(strm, strm->state); 1262 + strm->state = Z_NULL; 1263 + Tracev((stderr, "inflate: end\n")); 1264 + return Z_OK; 1265 +} 1266 + 1267 +int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) 1268 +z_streamp strm; 1269 +const Bytef *dictionary; 1270 +uInt dictLength; 1271 +{ 1272 + struct inflate_state FAR *state; 1273 + unsigned long dictid; 1274 + unsigned char *next; 1275 + unsigned avail; 1276 + int ret; 1277 + 1278 + /* check state */ 1279 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1280 + state = (struct inflate_state FAR *)strm->state; 1281 + if (state->wrap != 0 && state->mode != DICT) 1282 + return Z_STREAM_ERROR; 1283 + 1284 + /* check for correct dictionary identifier */ 1285 + if (state->mode == DICT) { 1286 + dictid = adler32(0L, Z_NULL, 0); 1287 + dictid = adler32(dictid, dictionary, dictLength); 1288 + if (dictid != state->check) 1289 + return Z_DATA_ERROR; 1290 + } 1291 + 1292 + /* copy dictionary to window using updatewindow(), which will amend the 1293 + existing dictionary if appropriate */ 1294 + next = strm->next_out; 1295 + avail = strm->avail_out; 1296 + strm->next_out = (Bytef *)dictionary + dictLength; 1297 + strm->avail_out = 0; 1298 + ret = updatewindow(strm, dictLength); 1299 + strm->avail_out = avail; 1300 + strm->next_out = next; 1301 + if (ret) { 1302 + state->mode = MEM; 1303 + return Z_MEM_ERROR; 1304 + } 1305 + state->havedict = 1; 1306 + Tracev((stderr, "inflate: dictionary set\n")); 1307 + return Z_OK; 1308 +} 1309 + 1310 +int ZEXPORT inflateGetHeader(strm, head) 1311 +z_streamp strm; 1312 +gz_headerp head; 1313 +{ 1314 + struct inflate_state FAR *state; 1315 + 1316 + /* check state */ 1317 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1318 + state = (struct inflate_state FAR *)strm->state; 1319 + if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; 1320 + 1321 + /* save header structure */ 1322 + state->head = head; 1323 + head->done = 0; 1324 + return Z_OK; 1325 +} 1326 + 1327 +/* 1328 + Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found 1329 + or when out of input. When called, *have is the number of pattern bytes 1330 + found in order so far, in 0..3. On return *have is updated to the new 1331 + state. If on return *have equals four, then the pattern was found and the 1332 + return value is how many bytes were read including the last byte of the 1333 + pattern. If *have is less than four, then the pattern has not been found 1334 + yet and the return value is len. In the latter case, syncsearch() can be 1335 + called again with more data and the *have state. *have is initialized to 1336 + zero for the first call. 1337 + */ 1338 +local unsigned syncsearch(have, buf, len) 1339 +unsigned FAR *have; 1340 +unsigned char FAR *buf; 1341 +unsigned len; 1342 +{ 1343 + unsigned got; 1344 + unsigned next; 1345 + 1346 + got = *have; 1347 + next = 0; 1348 + while (next < len && got < 4) { 1349 + if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) 1350 + got++; 1351 + else if (buf[next]) 1352 + got = 0; 1353 + else 1354 + got = 4 - got; 1355 + next++; 1356 + } 1357 + *have = got; 1358 + return next; 1359 +} 1360 + 1361 +int ZEXPORT inflateSync(strm) 1362 +z_streamp strm; 1363 +{ 1364 + unsigned len; /* number of bytes to look at or looked at */ 1365 + unsigned long in, out; /* temporary to save total_in and total_out */ 1366 + unsigned char buf[4]; /* to restore bit buffer to byte string */ 1367 + struct inflate_state FAR *state; 1368 + 1369 + /* check parameters */ 1370 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1371 + state = (struct inflate_state FAR *)strm->state; 1372 + if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; 1373 + 1374 + /* if first time, start search in bit buffer */ 1375 + if (state->mode != SYNC) { 1376 + state->mode = SYNC; 1377 + state->hold <<= state->bits & 7; 1378 + state->bits -= state->bits & 7; 1379 + len = 0; 1380 + while (state->bits >= 8) { 1381 + buf[len++] = (unsigned char)(state->hold); 1382 + state->hold >>= 8; 1383 + state->bits -= 8; 1384 + } 1385 + state->have = 0; 1386 + syncsearch(&(state->have), buf, len); 1387 + } 1388 + 1389 + /* search available input */ 1390 + len = syncsearch(&(state->have), strm->next_in, strm->avail_in); 1391 + strm->avail_in -= len; 1392 + strm->next_in += len; 1393 + strm->total_in += len; 1394 + 1395 + /* return no joy or set up to restart inflate() on a new block */ 1396 + if (state->have != 4) return Z_DATA_ERROR; 1397 + in = strm->total_in; out = strm->total_out; 1398 + inflateReset(strm); 1399 + strm->total_in = in; strm->total_out = out; 1400 + state->mode = TYPE; 1401 + return Z_OK; 1402 +} 1403 + 1404 +/* 1405 + Returns true if inflate is currently at the end of a block generated by 1406 + Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP 1407 + implementation to provide an additional safety check. PPP uses 1408 + Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored 1409 + block. When decompressing, PPP checks that at the end of input packet, 1410 + inflate is waiting for these length bytes. 1411 + */ 1412 +int ZEXPORT inflateSyncPoint(strm) 1413 +z_streamp strm; 1414 +{ 1415 + struct inflate_state FAR *state; 1416 + 1417 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1418 + state = (struct inflate_state FAR *)strm->state; 1419 + return state->mode == STORED && state->bits == 0; 1420 +} 1421 + 1422 +int ZEXPORT inflateCopy(dest, source) 1423 +z_streamp dest; 1424 +z_streamp source; 1425 +{ 1426 + struct inflate_state FAR *state; 1427 + struct inflate_state FAR *copy; 1428 + unsigned char FAR *window; 1429 + unsigned wsize; 1430 + 1431 + /* check input */ 1432 + if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || 1433 + source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) 1434 + return Z_STREAM_ERROR; 1435 + state = (struct inflate_state FAR *)source->state; 1436 + 1437 + /* allocate space */ 1438 + copy = (struct inflate_state FAR *) 1439 + ZALLOC(source, 1, sizeof(struct inflate_state)); 1440 + if (copy == Z_NULL) return Z_MEM_ERROR; 1441 + window = Z_NULL; 1442 + if (state->window != Z_NULL) { 1443 + window = (unsigned char FAR *) 1444 + ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); 1445 + if (window == Z_NULL) { 1446 + ZFREE(source, copy); 1447 + return Z_MEM_ERROR; 1448 + } 1449 + } 1450 + 1451 + /* copy state */ 1452 + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); 1453 + zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); 1454 + if (state->lencode >= state->codes && 1455 + state->lencode <= state->codes + ENOUGH - 1) { 1456 + copy->lencode = copy->codes + (state->lencode - state->codes); 1457 + copy->distcode = copy->codes + (state->distcode - state->codes); 1458 + } 1459 + copy->next = copy->codes + (state->next - state->codes); 1460 + if (window != Z_NULL) { 1461 + wsize = 1U << state->wbits; 1462 + zmemcpy(window, state->window, wsize); 1463 + } 1464 + copy->window = window; 1465 + dest->state = (struct internal_state FAR *)copy; 1466 + return Z_OK; 1467 +} 1468 + 1469 +int ZEXPORT inflateUndermine(strm, subvert) 1470 +z_streamp strm; 1471 +int subvert; 1472 +{ 1473 + struct inflate_state FAR *state; 1474 + 1475 + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1476 + state = (struct inflate_state FAR *)strm->state; 1477 + state->sane = !subvert; 1478 +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 1479 + return Z_OK; 1480 +#else 1481 + state->sane = 1; 1482 + return Z_DATA_ERROR; 1483 +#endif 1484 +} 1485 + 1486 +long ZEXPORT inflateMark(strm) 1487 +z_streamp strm; 1488 +{ 1489 + struct inflate_state FAR *state; 1490 + 1491 + if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; 1492 + state = (struct inflate_state FAR *)strm->state; 1493 + return ((long)(state->back) << 16) + 1494 + (state->mode == COPY ? state->length : 1495 + (state->mode == MATCH ? state->was - state->length : 0)); 1496 +}
Added compat/zlib/inflate.h.
1 +/* inflate.h -- internal inflate state definition 2 + * Copyright (C) 1995-2009 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* define NO_GZIP when compiling if you want to disable gzip header and 12 + trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 + the crc code when it is not needed. For shared libraries, gzip decoding 14 + should be left enabled. */ 15 +#ifndef NO_GZIP 16 +# define GUNZIP 17 +#endif 18 + 19 +/* Possible inflate modes between inflate() calls */ 20 +typedef enum { 21 + HEAD, /* i: waiting for magic header */ 22 + FLAGS, /* i: waiting for method and flags (gzip) */ 23 + TIME, /* i: waiting for modification time (gzip) */ 24 + OS, /* i: waiting for extra flags and operating system (gzip) */ 25 + EXLEN, /* i: waiting for extra length (gzip) */ 26 + EXTRA, /* i: waiting for extra bytes (gzip) */ 27 + NAME, /* i: waiting for end of file name (gzip) */ 28 + COMMENT, /* i: waiting for end of comment (gzip) */ 29 + HCRC, /* i: waiting for header crc (gzip) */ 30 + DICTID, /* i: waiting for dictionary check value */ 31 + DICT, /* waiting for inflateSetDictionary() call */ 32 + TYPE, /* i: waiting for type bits, including last-flag bit */ 33 + TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 + STORED, /* i: waiting for stored size (length and complement) */ 35 + COPY_, /* i/o: same as COPY below, but only first time in */ 36 + COPY, /* i/o: waiting for input or output to copy stored block */ 37 + TABLE, /* i: waiting for dynamic block table lengths */ 38 + LENLENS, /* i: waiting for code length code lengths */ 39 + CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 + LEN_, /* i: same as LEN below, but only first time in */ 41 + LEN, /* i: waiting for length/lit/eob code */ 42 + LENEXT, /* i: waiting for length extra bits */ 43 + DIST, /* i: waiting for distance code */ 44 + DISTEXT, /* i: waiting for distance extra bits */ 45 + MATCH, /* o: waiting for output space to copy string */ 46 + LIT, /* o: waiting for output space to write literal */ 47 + CHECK, /* i: waiting for 32-bit check value */ 48 + LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 + DONE, /* finished check, done -- remain here until reset */ 50 + BAD, /* got a data error -- remain here until reset */ 51 + MEM, /* got an inflate() memory error -- remain here until reset */ 52 + SYNC /* looking for synchronization bytes to restart inflate() */ 53 +} inflate_mode; 54 + 55 +/* 56 + State transitions between above modes - 57 + 58 + (most modes can go to BAD or MEM on error -- not shown for clarity) 59 + 60 + Process header: 61 + HEAD -> (gzip) or (zlib) or (raw) 62 + (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 + HCRC -> TYPE 64 + (zlib) -> DICTID or TYPE 65 + DICTID -> DICT -> TYPE 66 + (raw) -> TYPEDO 67 + Read deflate blocks: 68 + TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 + STORED -> COPY_ -> COPY -> TYPE 70 + TABLE -> LENLENS -> CODELENS -> LEN_ 71 + LEN_ -> LEN 72 + Read deflate codes in fixed or dynamic block: 73 + LEN -> LENEXT or LIT or TYPE 74 + LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 + LIT -> LEN 76 + Process trailer: 77 + CHECK -> LENGTH -> DONE 78 + */ 79 + 80 +/* state maintained between inflate() calls. Approximately 10K bytes. */ 81 +struct inflate_state { 82 + inflate_mode mode; /* current inflate mode */ 83 + int last; /* true if processing last block */ 84 + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 + int havedict; /* true if dictionary provided */ 86 + int flags; /* gzip header method and flags (0 if zlib) */ 87 + unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 + unsigned long check; /* protected copy of check value */ 89 + unsigned long total; /* protected copy of output count */ 90 + gz_headerp head; /* where to save gzip header information */ 91 + /* sliding window */ 92 + unsigned wbits; /* log base 2 of requested window size */ 93 + unsigned wsize; /* window size or zero if not using window */ 94 + unsigned whave; /* valid bytes in the window */ 95 + unsigned wnext; /* window write index */ 96 + unsigned char FAR *window; /* allocated sliding window, if needed */ 97 + /* bit accumulator */ 98 + unsigned long hold; /* input bit accumulator */ 99 + unsigned bits; /* number of bits in "in" */ 100 + /* for string and stored block copying */ 101 + unsigned length; /* literal or length of data to copy */ 102 + unsigned offset; /* distance back to copy string from */ 103 + /* for table and code decoding */ 104 + unsigned extra; /* extra bits needed */ 105 + /* fixed and dynamic code tables */ 106 + code const FAR *lencode; /* starting table for length/literal codes */ 107 + code const FAR *distcode; /* starting table for distance codes */ 108 + unsigned lenbits; /* index bits for lencode */ 109 + unsigned distbits; /* index bits for distcode */ 110 + /* dynamic table building */ 111 + unsigned ncode; /* number of code length code lengths */ 112 + unsigned nlen; /* number of length code lengths */ 113 + unsigned ndist; /* number of distance code lengths */ 114 + unsigned have; /* number of code lengths in lens[] */ 115 + code FAR *next; /* next available space in codes[] */ 116 + unsigned short lens[320]; /* temporary storage for code lengths */ 117 + unsigned short work[288]; /* work area for code table building */ 118 + code codes[ENOUGH]; /* space for code tables */ 119 + int sane; /* if false, allow invalid distance too far */ 120 + int back; /* bits back of last unprocessed length/lit */ 121 + unsigned was; /* initial length of match */ 122 +};
Added compat/zlib/inftrees.c.
1 +/* inftrees.c -- generate Huffman trees for efficient decoding 2 + * Copyright (C) 1995-2012 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +#include "zutil.h" 7 +#include "inftrees.h" 8 + 9 +#define MAXBITS 15 10 + 11 +const char inflate_copyright[] = 12 + " inflate 1.2.7 Copyright 1995-2012 Mark Adler "; 13 +/* 14 + If you use the zlib library in a product, an acknowledgment is welcome 15 + in the documentation of your product. If for some reason you cannot 16 + include such an acknowledgment, I would appreciate that you keep this 17 + copyright string in the executable of your product. 18 + */ 19 + 20 +/* 21 + Build a set of tables to decode the provided canonical Huffman code. 22 + The code lengths are lens[0..codes-1]. The result starts at *table, 23 + whose indices are 0..2^bits-1. work is a writable array of at least 24 + lens shorts, which is used as a work area. type is the type of code 25 + to be generated, CODES, LENS, or DISTS. On return, zero is success, 26 + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 27 + on return points to the next available entry's address. bits is the 28 + requested root table index bits, and on return it is the actual root 29 + table index bits. It will differ if the request is greater than the 30 + longest code or if it is less than the shortest code. 31 + */ 32 +int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) 33 +codetype type; 34 +unsigned short FAR *lens; 35 +unsigned codes; 36 +code FAR * FAR *table; 37 +unsigned FAR *bits; 38 +unsigned short FAR *work; 39 +{ 40 + unsigned len; /* a code's length in bits */ 41 + unsigned sym; /* index of code symbols */ 42 + unsigned min, max; /* minimum and maximum code lengths */ 43 + unsigned root; /* number of index bits for root table */ 44 + unsigned curr; /* number of index bits for current table */ 45 + unsigned drop; /* code bits to drop for sub-table */ 46 + int left; /* number of prefix codes available */ 47 + unsigned used; /* code entries in table used */ 48 + unsigned huff; /* Huffman code */ 49 + unsigned incr; /* for incrementing code, index */ 50 + unsigned fill; /* index for replicating entries */ 51 + unsigned low; /* low bits for current root entry */ 52 + unsigned mask; /* mask for low root bits */ 53 + code here; /* table entry for duplication */ 54 + code FAR *next; /* next available space in table */ 55 + const unsigned short FAR *base; /* base value table to use */ 56 + const unsigned short FAR *extra; /* extra bits table to use */ 57 + int end; /* use base and extra for symbol > end */ 58 + unsigned short count[MAXBITS+1]; /* number of codes of each length */ 59 + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 60 + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 61 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 62 + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 63 + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 65 + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; 66 + static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 67 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 68 + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 69 + 8193, 12289, 16385, 24577, 0, 0}; 70 + static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 71 + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 72 + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 73 + 28, 28, 29, 29, 64, 64}; 74 + 75 + /* 76 + Process a set of code lengths to create a canonical Huffman code. The 77 + code lengths are lens[0..codes-1]. Each length corresponds to the 78 + symbols 0..codes-1. The Huffman code is generated by first sorting the 79 + symbols by length from short to long, and retaining the symbol order 80 + for codes with equal lengths. Then the code starts with all zero bits 81 + for the first code of the shortest length, and the codes are integer 82 + increments for the same length, and zeros are appended as the length 83 + increases. For the deflate format, these bits are stored backwards 84 + from their more natural integer increment ordering, and so when the 85 + decoding tables are built in the large loop below, the integer codes 86 + are incremented backwards. 87 + 88 + This routine assumes, but does not check, that all of the entries in 89 + lens[] are in the range 0..MAXBITS. The caller must assure this. 90 + 1..MAXBITS is interpreted as that code length. zero means that that 91 + symbol does not occur in this code. 92 + 93 + The codes are sorted by computing a count of codes for each length, 94 + creating from that a table of starting indices for each length in the 95 + sorted table, and then entering the symbols in order in the sorted 96 + table. The sorted table is work[], with that space being provided by 97 + the caller. 98 + 99 + The length counts are used for other purposes as well, i.e. finding 100 + the minimum and maximum length codes, determining if there are any 101 + codes at all, checking for a valid set of lengths, and looking ahead 102 + at length counts to determine sub-table sizes when building the 103 + decoding tables. 104 + */ 105 + 106 + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 107 + for (len = 0; len <= MAXBITS; len++) 108 + count[len] = 0; 109 + for (sym = 0; sym < codes; sym++) 110 + count[lens[sym]]++; 111 + 112 + /* bound code lengths, force root to be within code lengths */ 113 + root = *bits; 114 + for (max = MAXBITS; max >= 1; max--) 115 + if (count[max] != 0) break; 116 + if (root > max) root = max; 117 + if (max == 0) { /* no symbols to code at all */ 118 + here.op = (unsigned char)64; /* invalid code marker */ 119 + here.bits = (unsigned char)1; 120 + here.val = (unsigned short)0; 121 + *(*table)++ = here; /* make a table to force an error */ 122 + *(*table)++ = here; 123 + *bits = 1; 124 + return 0; /* no symbols, but wait for decoding to report error */ 125 + } 126 + for (min = 1; min < max; min++) 127 + if (count[min] != 0) break; 128 + if (root < min) root = min; 129 + 130 + /* check for an over-subscribed or incomplete set of lengths */ 131 + left = 1; 132 + for (len = 1; len <= MAXBITS; len++) { 133 + left <<= 1; 134 + left -= count[len]; 135 + if (left < 0) return -1; /* over-subscribed */ 136 + } 137 + if (left > 0 && (type == CODES || max != 1)) 138 + return -1; /* incomplete set */ 139 + 140 + /* generate offsets into symbol table for each length for sorting */ 141 + offs[1] = 0; 142 + for (len = 1; len < MAXBITS; len++) 143 + offs[len + 1] = offs[len] + count[len]; 144 + 145 + /* sort symbols by length, by symbol order within each length */ 146 + for (sym = 0; sym < codes; sym++) 147 + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 148 + 149 + /* 150 + Create and fill in decoding tables. In this loop, the table being 151 + filled is at next and has curr index bits. The code being used is huff 152 + with length len. That code is converted to an index by dropping drop 153 + bits off of the bottom. For codes where len is less than drop + curr, 154 + those top drop + curr - len bits are incremented through all values to 155 + fill the table with replicated entries. 156 + 157 + root is the number of index bits for the root table. When len exceeds 158 + root, sub-tables are created pointed to by the root entry with an index 159 + of the low root bits of huff. This is saved in low to check for when a 160 + new sub-table should be started. drop is zero when the root table is 161 + being filled, and drop is root when sub-tables are being filled. 162 + 163 + When a new sub-table is needed, it is necessary to look ahead in the 164 + code lengths to determine what size sub-table is needed. The length 165 + counts are used for this, and so count[] is decremented as codes are 166 + entered in the tables. 167 + 168 + used keeps track of how many table entries have been allocated from the 169 + provided *table space. It is checked for LENS and DIST tables against 170 + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in 171 + the initial root table size constants. See the comments in inftrees.h 172 + for more information. 173 + 174 + sym increments through all symbols, and the loop terminates when 175 + all codes of length max, i.e. all codes, have been processed. This 176 + routine permits incomplete codes, so another loop after this one fills 177 + in the rest of the decoding tables with invalid code markers. 178 + */ 179 + 180 + /* set up for code type */ 181 + switch (type) { 182 + case CODES: 183 + base = extra = work; /* dummy value--not used */ 184 + end = 19; 185 + break; 186 + case LENS: 187 + base = lbase; 188 + base -= 257; 189 + extra = lext; 190 + extra -= 257; 191 + end = 256; 192 + break; 193 + default: /* DISTS */ 194 + base = dbase; 195 + extra = dext; 196 + end = -1; 197 + } 198 + 199 + /* initialize state for loop */ 200 + huff = 0; /* starting code */ 201 + sym = 0; /* starting code symbol */ 202 + len = min; /* starting code length */ 203 + next = *table; /* current table to fill in */ 204 + curr = root; /* current table index bits */ 205 + drop = 0; /* current bits to drop from code for index */ 206 + low = (unsigned)(-1); /* trigger new sub-table when len > root */ 207 + used = 1U << root; /* use root table entries */ 208 + mask = used - 1; /* mask for comparing low */ 209 + 210 + /* check available table space */ 211 + if ((type == LENS && used >= ENOUGH_LENS) || 212 + (type == DISTS && used >= ENOUGH_DISTS)) 213 + return 1; 214 + 215 + /* process all codes and make table entries */ 216 + for (;;) { 217 + /* create table entry */ 218 + here.bits = (unsigned char)(len - drop); 219 + if ((int)(work[sym]) < end) { 220 + here.op = (unsigned char)0; 221 + here.val = work[sym]; 222 + } 223 + else if ((int)(work[sym]) > end) { 224 + here.op = (unsigned char)(extra[work[sym]]); 225 + here.val = base[work[sym]]; 226 + } 227 + else { 228 + here.op = (unsigned char)(32 + 64); /* end of block */ 229 + here.val = 0; 230 + } 231 + 232 + /* replicate for those indices with low len bits equal to huff */ 233 + incr = 1U << (len - drop); 234 + fill = 1U << curr; 235 + min = fill; /* save offset to next table */ 236 + do { 237 + fill -= incr; 238 + next[(huff >> drop) + fill] = here; 239 + } while (fill != 0); 240 + 241 + /* backwards increment the len-bit code huff */ 242 + incr = 1U << (len - 1); 243 + while (huff & incr) 244 + incr >>= 1; 245 + if (incr != 0) { 246 + huff &= incr - 1; 247 + huff += incr; 248 + } 249 + else 250 + huff = 0; 251 + 252 + /* go to next symbol, update count, len */ 253 + sym++; 254 + if (--(count[len]) == 0) { 255 + if (len == max) break; 256 + len = lens[work[sym]]; 257 + } 258 + 259 + /* create new sub-table if needed */ 260 + if (len > root && (huff & mask) != low) { 261 + /* if first time, transition to sub-tables */ 262 + if (drop == 0) 263 + drop = root; 264 + 265 + /* increment past last table */ 266 + next += min; /* here min is 1 << curr */ 267 + 268 + /* determine length of next table */ 269 + curr = len - drop; 270 + left = (int)(1 << curr); 271 + while (curr + drop < max) { 272 + left -= count[curr + drop]; 273 + if (left <= 0) break; 274 + curr++; 275 + left <<= 1; 276 + } 277 + 278 + /* check for enough space */ 279 + used += 1U << curr; 280 + if ((type == LENS && used >= ENOUGH_LENS) || 281 + (type == DISTS && used >= ENOUGH_DISTS)) 282 + return 1; 283 + 284 + /* point entry in root table to sub-table */ 285 + low = huff & mask; 286 + (*table)[low].op = (unsigned char)curr; 287 + (*table)[low].bits = (unsigned char)root; 288 + (*table)[low].val = (unsigned short)(next - *table); 289 + } 290 + } 291 + 292 + /* fill in remaining table entry if code is incomplete (guaranteed to have 293 + at most one remaining entry, since if the code is incomplete, the 294 + maximum code length that was allowed to get this far is one bit) */ 295 + if (huff != 0) { 296 + here.op = (unsigned char)64; /* invalid code marker */ 297 + here.bits = (unsigned char)(len - drop); 298 + here.val = (unsigned short)0; 299 + next[huff] = here; 300 + } 301 + 302 + /* set return parameters */ 303 + *table += used; 304 + *bits = root; 305 + return 0; 306 +}
Added compat/zlib/inftrees.h.
1 +/* inftrees.h -- header to use inftrees.c 2 + * Copyright (C) 1995-2005, 2010 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* Structure for decoding tables. Each entry provides either the 12 + information needed to do the operation requested by the code that 13 + indexed that table entry, or it provides a pointer to another 14 + table that indexes more bits of the code. op indicates whether 15 + the entry is a pointer to another table, a literal, a length or 16 + distance, an end-of-block, or an invalid code. For a table 17 + pointer, the low four bits of op is the number of index bits of 18 + that table. For a length or distance, the low four bits of op 19 + is the number of extra bits to get after the code. bits is 20 + the number of bits in this code or part of the code to drop off 21 + of the bit buffer. val is the actual byte to output in the case 22 + of a literal, the base length or distance, or the offset from 23 + the current table to the next table. Each entry is four bytes. */ 24 +typedef struct { 25 + unsigned char op; /* operation, extra bits, table bits */ 26 + unsigned char bits; /* bits in this part of the code */ 27 + unsigned short val; /* offset in table or code value */ 28 +} code; 29 + 30 +/* op values as set by inflate_table(): 31 + 00000000 - literal 32 + 0000tttt - table link, tttt != 0 is the number of table index bits 33 + 0001eeee - length or distance, eeee is the number of extra bits 34 + 01100000 - end of block 35 + 01000000 - invalid code 36 + */ 37 + 38 +/* Maximum size of the dynamic table. The maximum number of code structures is 39 + 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 + codes. These values were found by exhaustive searches using the program 41 + examples/enough.c found in the zlib distribtution. The arguments to that 42 + program are the number of symbols, the initial root table size, and the 43 + maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 + returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 + The initial root table size (9 or 6) is found in the fifth argument of the 46 + inflate_table() calls in inflate.c and infback.c. If the root table size is 47 + changed, then these maximum sizes would be need to be recalculated and 48 + updated. */ 49 +#define ENOUGH_LENS 852 50 +#define ENOUGH_DISTS 592 51 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 + 53 +/* Type of code to build for inflate_table() */ 54 +typedef enum { 55 + CODES, 56 + LENS, 57 + DISTS 58 +} codetype; 59 + 60 +int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 + unsigned codes, code FAR * FAR *table, 62 + unsigned FAR *bits, unsigned short FAR *work));
Added compat/zlib/make_vms.com.
1 +$! make libz under VMS written by 2 +$! Martin P.J. Zinser 3 +$! 4 +$! In case of problems with the install you might contact me at 5 +$! zinser@zinser.no-ip.info(preferred) or 6 +$! martin.zinser@eurexchange.com (work) 7 +$! 8 +$! Make procedure history for Zlib 9 +$! 10 +$!------------------------------------------------------------------------------ 11 +$! Version history 12 +$! 0.01 20060120 First version to receive a number 13 +$! 0.02 20061008 Adapt to new Makefile.in 14 +$! 0.03 20091224 Add support for large file check 15 +$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite 16 +$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in 17 +$! 0.06 20120111 Fix missing amiss_err, update zconf_h.in, fix new exmples 18 +$! subdir path, update module search in makefile.in 19 +$! 0.07 20120115 Triggered by work done by Alexey Chupahin completly redesigned 20 +$! shared image creation 21 +$! 0.08 20120219 Make it work on VAX again, pre-load missing symbols to shared 22 +$! image 23 +$! 0.09 20120305 SMS. P1 sets builder ("MMK", "MMS", " " (built-in)). 24 +$! "" -> automatic, preference: MMK, MMS, built-in. 25 +$! 26 +$ on error then goto err_exit 27 +$! 28 +$ true = 1 29 +$ false = 0 30 +$ tmpnam = "temp_" + f$getjpi("","pid") 31 +$ tt = tmpnam + ".txt" 32 +$ tc = tmpnam + ".c" 33 +$ th = tmpnam + ".h" 34 +$ define/nolog tconfig 'th' 35 +$ its_decc = false 36 +$ its_vaxc = false 37 +$ its_gnuc = false 38 +$ s_case = False 39 +$! 40 +$! Setup variables holding "config" information 41 +$! 42 +$ Make = "''p1'" 43 +$ name = "Zlib" 44 +$ version = "?.?.?" 45 +$ v_string = "ZLIB_VERSION" 46 +$ v_file = "zlib.h" 47 +$ ccopt = "/include = []" 48 +$ lopts = "" 49 +$ dnsrl = "" 50 +$ aconf_in_file = "zconf.h.in#zconf.h_in#zconf_h.in" 51 +$ conf_check_string = "" 52 +$ linkonly = false 53 +$ optfile = name + ".opt" 54 +$ mapfile = name + ".map" 55 +$ libdefs = "" 56 +$ vax = f$getsyi("HW_MODEL").lt.1024 57 +$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096 58 +$ ia64 = f$getsyi("HW_MODEL").ge.4096 59 +$! 60 +$! 2012-03-05 SMS. 61 +$! Why is this needed? And if it is needed, why not simply ".not. vax"? 62 +$! 63 +$!!! if axp .or. ia64 then set proc/parse=extended 64 +$! 65 +$ whoami = f$parse(f$environment("Procedure"),,,,"NO_CONCEAL") 66 +$ mydef = F$parse(whoami,,,"DEVICE") 67 +$ mydir = f$parse(whoami,,,"DIRECTORY") - "][" 68 +$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type") 69 +$! 70 +$! Check for MMK/MMS 71 +$! 72 +$ if (Make .eqs. "") 73 +$ then 74 +$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS" 75 +$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK" 76 +$ else 77 +$ Make = f$edit( Make, "trim") 78 +$ endif 79 +$! 80 +$ gosub find_version 81 +$! 82 +$ open/write topt tmp.opt 83 +$ open/write optf 'optfile' 84 +$! 85 +$ gosub check_opts 86 +$! 87 +$! Look for the compiler used 88 +$! 89 +$ gosub check_compiler 90 +$ close topt 91 +$ close optf 92 +$! 93 +$ if its_decc 94 +$ then 95 +$ ccopt = "/prefix=all" + ccopt 96 +$ if f$trnlnm("SYS") .eqs. "" 97 +$ then 98 +$ if axp 99 +$ then 100 +$ define sys sys$library: 101 +$ else 102 +$ ccopt = "/decc" + ccopt 103 +$ define sys decc$library_include: 104 +$ endif 105 +$ endif 106 +$! 107 +$! 2012-03-05 SMS. 108 +$! Why /NAMES = AS_IS? Why not simply ".not. vax"? And why not on VAX? 109 +$! 110 +$ if axp .or. ia64 111 +$ then 112 +$ ccopt = ccopt + "/name=as_is/opt=(inline=speed)" 113 +$ s_case = true 114 +$ endif 115 +$ endif 116 +$ if its_vaxc .or. its_gnuc 117 +$ then 118 +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: 119 +$ endif 120 +$! 121 +$! Build a fake configure input header 122 +$! 123 +$ open/write conf_hin config.hin 124 +$ write conf_hin "#undef _LARGEFILE64_SOURCE" 125 +$ close conf_hin 126 +$! 127 +$! 128 +$ i = 0 129 +$FIND_ACONF: 130 +$ fname = f$element(i,"#",aconf_in_file) 131 +$ if fname .eqs. "#" then goto AMISS_ERR 132 +$ if f$search(fname) .eqs. "" 133 +$ then 134 +$ i = i + 1 135 +$ goto find_aconf 136 +$ endif 137 +$ open/read/err=aconf_err aconf_in 'fname' 138 +$ open/write aconf zconf.h 139 +$ACONF_LOOP: 140 +$ read/end_of_file=aconf_exit aconf_in line 141 +$ work = f$edit(line, "compress,trim") 142 +$ if f$extract(0,6,work) .nes. "#undef" 143 +$ then 144 +$ if f$extract(0,12,work) .nes. "#cmakedefine" 145 +$ then 146 +$ write aconf line 147 +$ endif 148 +$ else 149 +$ cdef = f$element(1," ",work) 150 +$ gosub check_config 151 +$ endif 152 +$ goto aconf_loop 153 +$ACONF_EXIT: 154 +$ write aconf "" 155 +$ write aconf "/* VMS specifics added by make_vms.com: */" 156 +$ write aconf "#define VMS 1" 157 +$ write aconf "#include <unistd.h>" 158 +$ write aconf "#include <unixio.h>" 159 +$ write aconf "#ifdef _LARGEFILE" 160 +$ write aconf "# define off64_t __off64_t" 161 +$ write aconf "# define fopen64 fopen" 162 +$ write aconf "# define fseeko64 fseeko" 163 +$ write aconf "# define lseek64 lseek" 164 +$ write aconf "# define ftello64 ftell" 165 +$ write aconf "#endif" 166 +$ write aconf "#if !defined( __VAX) && (__CRTL_VER >= 70312000)" 167 +$ write aconf "# define HAVE_VSNPRINTF" 168 +$ write aconf "#endif" 169 +$ close aconf_in 170 +$ close aconf 171 +$ if f$search("''th'") .nes. "" then delete 'th';* 172 +$! Build the thing plain or with mms 173 +$! 174 +$ write sys$output "Compiling Zlib sources ..." 175 +$ if make.eqs."" 176 +$ then 177 +$ if (f$search( "example.obj;*") .nes. "") then delete example.obj;* 178 +$ if (f$search( "minigzip.obj;*") .nes. "") then delete minigzip.obj;* 179 +$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" - 180 + adler32.c zlib.h zconf.h 181 +$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" - 182 + compress.c zlib.h zconf.h 183 +$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - 184 + crc32.c zlib.h zconf.h 185 +$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - 186 + deflate.c deflate.h zutil.h zlib.h zconf.h 187 +$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - 188 + gzclose.c zutil.h zlib.h zconf.h 189 +$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - 190 + gzlib.c zutil.h zlib.h zconf.h 191 +$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - 192 + gzread.c zutil.h zlib.h zconf.h 193 +$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - 194 + gzwrite.c zutil.h zlib.h zconf.h 195 +$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - 196 + infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h 197 +$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - 198 + inffast.c zutil.h zlib.h zconf.h inffast.h 199 +$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" - 200 + inflate.c zutil.h zlib.h zconf.h infblock.h 201 +$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" - 202 + inftrees.c zutil.h zlib.h zconf.h inftrees.h 203 +$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" - 204 + trees.c deflate.h zutil.h zlib.h zconf.h 205 +$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" - 206 + uncompr.c zlib.h zconf.h 207 +$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" - 208 + zutil.c zutil.h zlib.h zconf.h 209 +$ write sys$output "Building Zlib ..." 210 +$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ 211 +$ write sys$output "Building example..." 212 +$ CALL MAKE example.OBJ "CC ''CCOPT' [.test]example" - 213 + [.test]example.c zlib.h zconf.h 214 +$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb 215 +$ write sys$output "Building minigzip..." 216 +$ CALL MAKE minigzip.OBJ "CC ''CCOPT' [.test]minigzip" - 217 + [.test]minigzip.c zlib.h zconf.h 218 +$ call make minigzip.exe - 219 + "LINK minigzip,libz.olb/lib" - 220 + minigzip.obj libz.olb 221 +$ else 222 +$ gosub crea_mms 223 +$ write sys$output "Make ''name' ''version' with ''Make' " 224 +$ 'make' 225 +$ endif 226 +$! 227 +$! Create shareable image 228 +$! 229 +$ gosub crea_olist 230 +$ write sys$output "Creating libzshr.exe" 231 +$ call map_2_shopt 'mapfile' 'optfile' 232 +$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,'optfile'/opt 233 +$ write sys$output "Zlib build completed" 234 +$ delete/nolog tmp.opt;* 235 +$ exit 236 +$AMISS_ERR: 237 +$ write sys$output "No source for config.hin found." 238 +$ write sys$output "Tried any of ''aconf_in_file'" 239 +$ goto err_exit 240 +$CC_ERR: 241 +$ write sys$output "C compiler required to build ''name'" 242 +$ goto err_exit 243 +$ERR_EXIT: 244 +$ set message/facil/ident/sever/text 245 +$ close/nolog optf 246 +$ close/nolog topt 247 +$ close/nolog aconf_in 248 +$ close/nolog aconf 249 +$ close/nolog out 250 +$ close/nolog min 251 +$ close/nolog mod 252 +$ close/nolog h_in 253 +$ write sys$output "Exiting..." 254 +$ exit 2 255 +$! 256 +$! 257 +$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES 258 +$ V = 'F$Verify(0) 259 +$! P1 = What we are trying to make 260 +$! P2 = Command to make it 261 +$! P3 - P8 What it depends on 262 +$ 263 +$ If F$Search(P1) .Eqs. "" Then Goto Makeit 264 +$ Time = F$CvTime(F$File(P1,"RDT")) 265 +$arg=3 266 +$Loop: 267 +$ Argument = P'arg 268 +$ If Argument .Eqs. "" Then Goto Exit 269 +$ El=0 270 +$Loop2: 271 +$ File = F$Element(El," ",Argument) 272 +$ If File .Eqs. " " Then Goto Endl 273 +$ AFile = "" 274 +$Loop3: 275 +$ OFile = AFile 276 +$ AFile = F$Search(File) 277 +$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl 278 +$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit 279 +$ Goto Loop3 280 +$NextEL: 281 +$ El = El + 1 282 +$ Goto Loop2 283 +$EndL: 284 +$ arg=arg+1 285 +$ If arg .Le. 8 Then Goto Loop 286 +$ Goto Exit 287 +$ 288 +$Makeit: 289 +$ VV=F$VERIFY(0) 290 +$ write sys$output P2 291 +$ 'P2 292 +$ VV='F$Verify(VV) 293 +$Exit: 294 +$ If V Then Set Verify 295 +$ENDSUBROUTINE 296 +$!------------------------------------------------------------------------------ 297 +$! 298 +$! Check command line options and set symbols accordingly 299 +$! 300 +$!------------------------------------------------------------------------------ 301 +$! Version history 302 +$! 0.01 20041206 First version to receive a number 303 +$! 0.02 20060126 Add new "HELP" target 304 +$ CHECK_OPTS: 305 +$ i = 1 306 +$ OPT_LOOP: 307 +$ if i .lt. 9 308 +$ then 309 +$ cparm = f$edit(p'i',"upcase") 310 +$! 311 +$! Check if parameter actually contains something 312 +$! 313 +$ if f$edit(cparm,"trim") .nes. "" 314 +$ then 315 +$ if cparm .eqs. "DEBUG" 316 +$ then 317 +$ ccopt = ccopt + "/noopt/deb" 318 +$ lopts = lopts + "/deb" 319 +$ endif 320 +$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm) 321 +$ then 322 +$ start = f$locate("=",cparm) + 1 323 +$ len = f$length(cparm) - start 324 +$ ccopt = ccopt + f$extract(start,len,cparm) 325 +$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) - 326 + then s_case = true 327 +$ endif 328 +$ if cparm .eqs. "LINK" then linkonly = true 329 +$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm) 330 +$ then 331 +$ start = f$locate("=",cparm) + 1 332 +$ len = f$length(cparm) - start 333 +$ lopts = lopts + f$extract(start,len,cparm) 334 +$ endif 335 +$ if f$locate("CC=",cparm) .lt. f$length(cparm) 336 +$ then 337 +$ start = f$locate("=",cparm) + 1 338 +$ len = f$length(cparm) - start 339 +$ cc_com = f$extract(start,len,cparm) 340 + if (cc_com .nes. "DECC") .and. - 341 + (cc_com .nes. "VAXC") .and. - 342 + (cc_com .nes. "GNUC") 343 +$ then 344 +$ write sys$output "Unsupported compiler choice ''cc_com' ignored" 345 +$ write sys$output "Use DECC, VAXC, or GNUC instead" 346 +$ else 347 +$ if cc_com .eqs. "DECC" then its_decc = true 348 +$ if cc_com .eqs. "VAXC" then its_vaxc = true 349 +$ if cc_com .eqs. "GNUC" then its_gnuc = true 350 +$ endif 351 +$ endif 352 +$ if f$locate("MAKE=",cparm) .lt. f$length(cparm) 353 +$ then 354 +$ start = f$locate("=",cparm) + 1 355 +$ len = f$length(cparm) - start 356 +$ mmks = f$extract(start,len,cparm) 357 +$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS") 358 +$ then 359 +$ make = mmks 360 +$ else 361 +$ write sys$output "Unsupported make choice ''mmks' ignored" 362 +$ write sys$output "Use MMK or MMS instead" 363 +$ endif 364 +$ endif 365 +$ if cparm .eqs. "HELP" then gosub bhelp 366 +$ endif 367 +$ i = i + 1 368 +$ goto opt_loop 369 +$ endif 370 +$ return 371 +$!------------------------------------------------------------------------------ 372 +$! 373 +$! Look for the compiler used 374 +$! 375 +$! Version history 376 +$! 0.01 20040223 First version to receive a number 377 +$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists 378 +$! 0.03 20060202 Extend handling of GNU C 379 +$! 0.04 20090402 Compaq -> hp 380 +$CHECK_COMPILER: 381 +$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) 382 +$ then 383 +$ its_decc = (f$search("SYS$SYSTEM:DECC$COMPILER.EXE") .nes. "") 384 +$ its_vaxc = .not. its_decc .and. (F$Search("SYS$System:VAXC.Exe") .nes. "") 385 +$ its_gnuc = .not. (its_decc .or. its_vaxc) .and. (f$trnlnm("gnu_cc") .nes. "") 386 +$ endif 387 +$! 388 +$! Exit if no compiler available 389 +$! 390 +$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) 391 +$ then goto CC_ERR 392 +$ else 393 +$ if its_decc 394 +$ then 395 +$ write sys$output "CC compiler check ... hp C" 396 +$ if f$trnlnm("decc$no_rooted_search_lists") .nes. "" 397 +$ then 398 +$ dnrsl = f$trnlnm("decc$no_rooted_search_lists") 399 +$ endif 400 +$ define/nolog decc$no_rooted_search_lists 1 401 +$ else 402 +$ if its_vaxc then write sys$output "CC compiler check ... VAX C" 403 +$ if its_gnuc 404 +$ then 405 +$ write sys$output "CC compiler check ... GNU C" 406 +$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib" 407 +$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib" 408 +$ cc = "gcc" 409 +$ endif 410 +$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share" 411 +$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share" 412 +$ endif 413 +$ endif 414 +$ return 415 +$!------------------------------------------------------------------------------ 416 +$! 417 +$! If MMS/MMK are available dump out the descrip.mms if required 418 +$! 419 +$CREA_MMS: 420 +$ write sys$output "Creating descrip.mms..." 421 +$ create descrip.mms 422 +$ open/append out descrip.mms 423 +$ copy sys$input: out 424 +$ deck 425 +# descrip.mms: MMS description file for building zlib on VMS 426 +# written by Martin P.J. Zinser 427 +# <zinser@zinser.no-ip.info or martin.zinser@eurexchange.com> 428 + 429 +OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\ 430 + gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\ 431 + deflate.obj, trees.obj, zutil.obj, inflate.obj, \ 432 + inftrees.obj, inffast.obj 433 + 434 +$ eod 435 +$ write out "CFLAGS=", ccopt 436 +$ write out "LOPTS=", lopts 437 +$ write out "all : example.exe minigzip.exe libz.olb" 438 +$ copy sys$input: out 439 +$ deck 440 + @ write sys$output " Example applications available" 441 + 442 +libz.olb : libz.olb($(OBJS)) 443 + @ write sys$output " libz available" 444 + 445 +example.exe : example.obj libz.olb 446 + link $(LOPTS) example,libz.olb/lib 447 + 448 +minigzip.exe : minigzip.obj libz.olb 449 + link $(LOPTS) minigzip,libz.olb/lib 450 + 451 +clean : 452 + delete *.obj;*,libz.olb;*,*.opt;*,*.exe;* 453 + 454 + 455 +# Other dependencies. 456 +adler32.obj : adler32.c zutil.h zlib.h zconf.h 457 +compress.obj : compress.c zlib.h zconf.h 458 +crc32.obj : crc32.c zutil.h zlib.h zconf.h 459 +deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h 460 +example.obj : [.test]example.c zlib.h zconf.h 461 +gzclose.obj : gzclose.c zutil.h zlib.h zconf.h 462 +gzlib.obj : gzlib.c zutil.h zlib.h zconf.h 463 +gzread.obj : gzread.c zutil.h zlib.h zconf.h 464 +gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h 465 +inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h 466 +inflate.obj : inflate.c zutil.h zlib.h zconf.h 467 +inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h 468 +minigzip.obj : [.test]minigzip.c zlib.h zconf.h 469 +trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h 470 +uncompr.obj : uncompr.c zlib.h zconf.h 471 +zutil.obj : zutil.c zutil.h zlib.h zconf.h 472 +infback.obj : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h 473 +$ eod 474 +$ close out 475 +$ return 476 +$!------------------------------------------------------------------------------ 477 +$! 478 +$! Read list of core library sources from makefile.in and create options 479 +$! needed to build shareable image 480 +$! 481 +$CREA_OLIST: 482 +$ open/read min makefile.in 483 +$ open/write mod modules.opt 484 +$ src_check_list = "OBJZ =#OBJG =" 485 +$MRLOOP: 486 +$ read/end=mrdone min rec 487 +$ i = 0 488 +$SRC_CHECK_LOOP: 489 +$ src_check = f$element(i, "#", src_check_list) 490 +$ i = i+1 491 +$ if src_check .eqs. "#" then goto mrloop 492 +$ if (f$extract(0,6,rec) .nes. src_check) then goto src_check_loop 493 +$ rec = rec - src_check 494 +$ gosub extra_filnam 495 +$ if (f$element(1,"\",rec) .eqs. "\") then goto mrloop 496 +$MRSLOOP: 497 +$ read/end=mrdone min rec 498 +$ gosub extra_filnam 499 +$ if (f$element(1,"\",rec) .nes. "\") then goto mrsloop 500 +$MRDONE: 501 +$ close min 502 +$ close mod 503 +$ return 504 +$!------------------------------------------------------------------------------ 505 +$! 506 +$! Take record extracted in crea_olist and split it into single filenames 507 +$! 508 +$EXTRA_FILNAM: 509 +$ myrec = f$edit(rec - "\", "trim,compress") 510 +$ i = 0 511 +$FELOOP: 512 +$ srcfil = f$element(i," ", myrec) 513 +$ if (srcfil .nes. " ") 514 +$ then 515 +$ write mod f$parse(srcfil,,,"NAME"), ".obj" 516 +$ i = i + 1 517 +$ goto feloop 518 +$ endif 519 +$ return 520 +$!------------------------------------------------------------------------------ 521 +$! 522 +$! Find current Zlib version number 523 +$! 524 +$FIND_VERSION: 525 +$ open/read h_in 'v_file' 526 +$hloop: 527 +$ read/end=hdone h_in rec 528 +$ rec = f$edit(rec,"TRIM") 529 +$ if (f$extract(0,1,rec) .nes. "#") then goto hloop 530 +$ rec = f$edit(rec - "#", "TRIM") 531 +$ if f$element(0," ",rec) .nes. "define" then goto hloop 532 +$ if f$element(1," ",rec) .eqs. v_string 533 +$ then 534 +$ version = 'f$element(2," ",rec)' 535 +$ goto hdone 536 +$ endif 537 +$ goto hloop 538 +$hdone: 539 +$ close h_in 540 +$ return 541 +$!------------------------------------------------------------------------------ 542 +$! 543 +$CHECK_CONFIG: 544 +$! 545 +$ in_ldef = f$locate(cdef,libdefs) 546 +$ if (in_ldef .lt. f$length(libdefs)) 547 +$ then 548 +$ write aconf "#define ''cdef' 1" 549 +$ libdefs = f$extract(0,in_ldef,libdefs) + - 550 + f$extract(in_ldef + f$length(cdef) + 1, - 551 + f$length(libdefs) - in_ldef - f$length(cdef) - 1, - 552 + libdefs) 553 +$ else 554 +$ if (f$type('cdef') .eqs. "INTEGER") 555 +$ then 556 +$ write aconf "#define ''cdef' ", 'cdef' 557 +$ else 558 +$ if (f$type('cdef') .eqs. "STRING") 559 +$ then 560 +$ write aconf "#define ''cdef' ", """", '''cdef'', """" 561 +$ else 562 +$ gosub check_cc_def 563 +$ endif 564 +$ endif 565 +$ endif 566 +$ return 567 +$!------------------------------------------------------------------------------ 568 +$! 569 +$! Check if this is a define relating to the properties of the C/C++ 570 +$! compiler 571 +$! 572 +$ CHECK_CC_DEF: 573 +$ if (cdef .eqs. "_LARGEFILE64_SOURCE") 574 +$ then 575 +$ copy sys$input: 'tc' 576 +$ deck 577 +#include "tconfig" 578 +#define _LARGEFILE 579 +#include <stdio.h> 580 + 581 +int main(){ 582 +FILE *fp; 583 + fp = fopen("temp.txt","r"); 584 + fseeko(fp,1,SEEK_SET); 585 + fclose(fp); 586 +} 587 + 588 +$ eod 589 +$ test_inv = false 590 +$ comm_h = false 591 +$ gosub cc_prop_check 592 +$ return 593 +$ endif 594 +$ write aconf "/* ", line, " */" 595 +$ return 596 +$!------------------------------------------------------------------------------ 597 +$! 598 +$! Check for properties of C/C++ compiler 599 +$! 600 +$! Version history 601 +$! 0.01 20031020 First version to receive a number 602 +$! 0.02 20031022 Added logic for defines with value 603 +$! 0.03 20040309 Make sure local config file gets not deleted 604 +$! 0.04 20041230 Also write include for configure run 605 +$! 0.05 20050103 Add processing of "comment defines" 606 +$CC_PROP_CHECK: 607 +$ cc_prop = true 608 +$ is_need = false 609 +$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true) 610 +$ if f$search(th) .eqs. "" then create 'th' 611 +$ set message/nofac/noident/nosever/notext 612 +$ on error then continue 613 +$ cc 'tmpnam' 614 +$ if .not. ($status) then cc_prop = false 615 +$ on error then continue 616 +$! The headers might lie about the capabilities of the RTL 617 +$ link 'tmpnam',tmp.opt/opt 618 +$ if .not. ($status) then cc_prop = false 619 +$ set message/fac/ident/sever/text 620 +$ on error then goto err_exit 621 +$ delete/nolog 'tmpnam'.*;*/exclude='th' 622 +$ if (cc_prop .and. .not. is_need) .or. - 623 + (.not. cc_prop .and. is_need) 624 +$ then 625 +$ write sys$output "Checking for ''cdef'... yes" 626 +$ if f$type('cdef_val'_yes) .nes. "" 627 +$ then 628 +$ if f$type('cdef_val'_yes) .eqs. "INTEGER" - 629 + then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes) 630 +$ if f$type('cdef_val'_yes) .eqs. "STRING" - 631 + then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes) 632 +$ else 633 +$ call write_config f$fao("#define !AS 1",cdef) 634 +$ endif 635 +$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. - 636 + (cdef .eqs. "_LARGEFILE64_SOURCE") then - 637 + call write_config f$string("#define _LARGEFILE 1") 638 +$ else 639 +$ write sys$output "Checking for ''cdef'... no" 640 +$ if (comm_h) 641 +$ then 642 + call write_config f$fao("/* !AS */",line) 643 +$ else 644 +$ if f$type('cdef_val'_no) .nes. "" 645 +$ then 646 +$ if f$type('cdef_val'_no) .eqs. "INTEGER" - 647 + then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no) 648 +$ if f$type('cdef_val'_no) .eqs. "STRING" - 649 + then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no) 650 +$ else 651 +$ call write_config f$fao("#undef !AS",cdef) 652 +$ endif 653 +$ endif 654 +$ endif 655 +$ return 656 +$!------------------------------------------------------------------------------ 657 +$! 658 +$! Check for properties of C/C++ compiler with multiple result values 659 +$! 660 +$! Version history 661 +$! 0.01 20040127 First version 662 +$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05 663 +$CC_MPROP_CHECK: 664 +$ cc_prop = true 665 +$ i = 1 666 +$ idel = 1 667 +$ MT_LOOP: 668 +$ if f$type(result_'i') .eqs. "STRING" 669 +$ then 670 +$ set message/nofac/noident/nosever/notext 671 +$ on error then continue 672 +$ cc 'tmpnam'_'i' 673 +$ if .not. ($status) then cc_prop = false 674 +$ on error then continue 675 +$! The headers might lie about the capabilities of the RTL 676 +$ link 'tmpnam'_'i',tmp.opt/opt 677 +$ if .not. ($status) then cc_prop = false 678 +$ set message/fac/ident/sever/text 679 +$ on error then goto err_exit 680 +$ delete/nolog 'tmpnam'_'i'.*;* 681 +$ if (cc_prop) 682 +$ then 683 +$ write sys$output "Checking for ''cdef'... ", mdef_'i' 684 +$ if f$type(mdef_'i') .eqs. "INTEGER" - 685 + then call write_config f$fao("#define !AS !UL",cdef,mdef_'i') 686 +$ if f$type('cdef_val'_yes) .eqs. "STRING" - 687 + then call write_config f$fao("#define !AS !AS",cdef,mdef_'i') 688 +$ goto msym_clean 689 +$ else 690 +$ i = i + 1 691 +$ goto mt_loop 692 +$ endif 693 +$ endif 694 +$ write sys$output "Checking for ''cdef'... no" 695 +$ call write_config f$fao("#undef !AS",cdef) 696 +$ MSYM_CLEAN: 697 +$ if (idel .le. msym_max) 698 +$ then 699 +$ delete/sym mdef_'idel' 700 +$ idel = idel + 1 701 +$ goto msym_clean 702 +$ endif 703 +$ return 704 +$!------------------------------------------------------------------------------ 705 +$! 706 +$! Write configuration to both permanent and temporary config file 707 +$! 708 +$! Version history 709 +$! 0.01 20031029 First version to receive a number 710 +$! 711 +$WRITE_CONFIG: SUBROUTINE 712 +$ write aconf 'p1' 713 +$ open/append confh 'th' 714 +$ write confh 'p1' 715 +$ close confh 716 +$ENDSUBROUTINE 717 +$!------------------------------------------------------------------------------ 718 +$! 719 +$! Analyze the project map file and create the symbol vector for a shareable 720 +$! image from it 721 +$! 722 +$! Version history 723 +$! 0.01 20120128 First version 724 +$! 0.02 20120226 Add pre-load logic 725 +$! 726 +$ MAP_2_SHOPT: Subroutine 727 +$! 728 +$ SAY := "WRITE_ SYS$OUTPUT" 729 +$! 730 +$ IF F$SEARCH("''P1'") .EQS. "" 731 +$ THEN 732 +$ SAY "MAP_2_SHOPT-E-NOSUCHFILE: Error, inputfile ''p1' not available" 733 +$ goto exit_m2s 734 +$ ENDIF 735 +$ IF "''P2'" .EQS. "" 736 +$ THEN 737 +$ SAY "MAP_2_SHOPT: Error, no output file provided" 738 +$ goto exit_m2s 739 +$ ENDIF 740 +$! 741 +$ module1 = "deflate#deflateEnd#deflateInit_#deflateParams#deflateSetDictionary" 742 +$ module2 = "gzclose#gzerror#gzgetc#gzgets#gzopen#gzprintf#gzputc#gzputs#gzread" 743 +$ module3 = "gzseek#gztell#inflate#inflateEnd#inflateInit_#inflateSetDictionary" 744 +$ module4 = "inflateSync#uncompress#zlibVersion#compress" 745 +$ open/read map 'p1 746 +$ if axp .or. ia64 747 +$ then 748 +$ open/write aopt a.opt 749 +$ open/write bopt b.opt 750 +$ write aopt " CASE_SENSITIVE=YES" 751 +$ write bopt "SYMBOL_VECTOR= (-" 752 +$ mod_sym_num = 1 753 +$ MOD_SYM_LOOP: 754 +$ if f$type(module'mod_sym_num') .nes. "" 755 +$ then 756 +$ mod_in = 0 757 +$ MOD_SYM_IN: 758 +$ shared_proc = f$element(mod_in, "#", module'mod_sym_num') 759 +$ if shared_proc .nes. "#" 760 +$ then 761 +$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",- 762 + f$edit(shared_proc,"upcase"),shared_proc) 763 +$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc) 764 +$ mod_in = mod_in + 1 765 +$ goto mod_sym_in 766 +$ endif 767 +$ mod_sym_num = mod_sym_num + 1 768 +$ goto mod_sym_loop 769 +$ endif 770 +$MAP_LOOP: 771 +$ read/end=map_end map line 772 +$ if (f$locate("{",line).lt. f$length(line)) .or. - 773 + (f$locate("global:", line) .lt. f$length(line)) 774 +$ then 775 +$ proc = true 776 +$ goto map_loop 777 +$ endif 778 +$ if f$locate("}",line).lt. f$length(line) then proc = false 779 +$ if f$locate("local:", line) .lt. f$length(line) then proc = false 780 +$ if proc 781 +$ then 782 +$ shared_proc = f$edit(line,"collapse") 783 +$ chop_semi = f$locate(";", shared_proc) 784 +$ if chop_semi .lt. f$length(shared_proc) then - 785 + shared_proc = f$extract(0, chop_semi, shared_proc) 786 +$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",- 787 + f$edit(shared_proc,"upcase"),shared_proc) 788 +$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc) 789 +$ endif 790 +$ goto map_loop 791 +$MAP_END: 792 +$ close/nolog aopt 793 +$ close/nolog bopt 794 +$ open/append libopt 'p2' 795 +$ open/read aopt a.opt 796 +$ open/read bopt b.opt 797 +$ALOOP: 798 +$ read/end=aloop_end aopt line 799 +$ write libopt line 800 +$ goto aloop 801 +$ALOOP_END: 802 +$ close/nolog aopt 803 +$ sv = "" 804 +$BLOOP: 805 +$ read/end=bloop_end bopt svn 806 +$ if (svn.nes."") 807 +$ then 808 +$ if (sv.nes."") then write libopt sv 809 +$ sv = svn 810 +$ endif 811 +$ goto bloop 812 +$BLOOP_END: 813 +$ write libopt f$extract(0,f$length(sv)-2,sv), "-" 814 +$ write libopt ")" 815 +$ close/nolog bopt 816 +$ delete/nolog/noconf a.opt;*,b.opt;* 817 +$ else 818 +$ if vax 819 +$ then 820 +$ open/append libopt 'p2' 821 +$ mod_sym_num = 1 822 +$ VMOD_SYM_LOOP: 823 +$ if f$type(module'mod_sym_num') .nes. "" 824 +$ then 825 +$ mod_in = 0 826 +$ VMOD_SYM_IN: 827 +$ shared_proc = f$element(mod_in, "#", module'mod_sym_num') 828 +$ if shared_proc .nes. "#" 829 +$ then 830 +$ write libopt f$fao("UNIVERSAL=!AS",- 831 + f$edit(shared_proc,"upcase")) 832 +$ mod_in = mod_in + 1 833 +$ goto vmod_sym_in 834 +$ endif 835 +$ mod_sym_num = mod_sym_num + 1 836 +$ goto vmod_sym_loop 837 +$ endif 838 +$VMAP_LOOP: 839 +$ read/end=vmap_end map line 840 +$ if (f$locate("{",line).lt. f$length(line)) .or. - 841 + (f$locate("global:", line) .lt. f$length(line)) 842 +$ then 843 +$ proc = true 844 +$ goto vmap_loop 845 +$ endif 846 +$ if f$locate("}",line).lt. f$length(line) then proc = false 847 +$ if f$locate("local:", line) .lt. f$length(line) then proc = false 848 +$ if proc 849 +$ then 850 +$ shared_proc = f$edit(line,"collapse") 851 +$ chop_semi = f$locate(";", shared_proc) 852 +$ if chop_semi .lt. f$length(shared_proc) then - 853 + shared_proc = f$extract(0, chop_semi, shared_proc) 854 +$ write libopt f$fao("UNIVERSAL=!AS",- 855 + f$edit(shared_proc,"upcase")) 856 +$ endif 857 +$ goto vmap_loop 858 +$VMAP_END: 859 +$ else 860 +$ write sys$output "Unknown Architecture (Not VAX, AXP, or IA64)" 861 +$ write sys$output "No options file created" 862 +$ endif 863 +$ endif 864 +$ EXIT_M2S: 865 +$ close/nolog map 866 +$ close/nolog libopt 867 +$ endsubroutine
Added compat/zlib/msdos/Makefile.bor.
1 +# Makefile for zlib 2 +# Borland C++ 3 +# Last updated: 15-Mar-2003 4 + 5 +# To use, do "make -fmakefile.bor" 6 +# To compile in small model, set below: MODEL=s 7 + 8 +# WARNING: the small model is supported but only for small values of 9 +# MAX_WBITS and MAX_MEM_LEVEL. For example: 10 +# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3 11 +# If you wish to reduce the memory requirements (default 256K for big 12 +# objects plus a few K), you can add to the LOC macro below: 13 +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 14 +# See zconf.h for details about the memory requirements. 15 + 16 +# ------------ Turbo C++, Borland C++ ------------ 17 + 18 +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) 19 +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added 20 +# to the declaration of LOC here: 21 +LOC = $(LOCAL_ZLIB) 22 + 23 +# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. 24 +CPU_TYP = 0 25 + 26 +# memory model: one of s, m, c, l (small, medium, compact, large) 27 +MODEL=l 28 + 29 +# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version 30 +CC=bcc 31 +LD=bcc 32 +AR=tlib 33 + 34 +# compiler flags 35 +# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0 36 +CFLAGS=-O2 -Z -m$(MODEL) $(LOC) 37 + 38 +LDFLAGS=-m$(MODEL) -f- 39 + 40 + 41 +# variables 42 +ZLIB_LIB = zlib_$(MODEL).lib 43 + 44 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 45 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 46 +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj 47 +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 48 + 49 + 50 +# targets 51 +all: $(ZLIB_LIB) example.exe minigzip.exe 52 + 53 +.c.obj: 54 + $(CC) -c $(CFLAGS) $*.c 55 + 56 +adler32.obj: adler32.c zlib.h zconf.h 57 + 58 +compress.obj: compress.c zlib.h zconf.h 59 + 60 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 61 + 62 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 63 + 64 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 65 + 66 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 67 + 68 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 69 + 70 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 71 + 72 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 73 + inffast.h inffixed.h 74 + 75 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 76 + inffast.h 77 + 78 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 79 + inffast.h inffixed.h 80 + 81 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 82 + 83 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 84 + 85 +uncompr.obj: uncompr.c zlib.h zconf.h 86 + 87 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 88 + 89 +example.obj: test/example.c zlib.h zconf.h 90 + 91 +minigzip.obj: test/minigzip.c zlib.h zconf.h 92 + 93 + 94 +# the command line is cut to fit in the MS-DOS 128 byte limit: 95 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) 96 + -del $(ZLIB_LIB) 97 + $(AR) $(ZLIB_LIB) $(OBJP1) 98 + $(AR) $(ZLIB_LIB) $(OBJP2) 99 + 100 +example.exe: example.obj $(ZLIB_LIB) 101 + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) 102 + 103 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 104 + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) 105 + 106 +test: example.exe minigzip.exe 107 + example 108 + echo hello world | minigzip | minigzip -d 109 + 110 +clean: 111 + -del *.obj 112 + -del *.lib 113 + -del *.exe 114 + -del zlib_*.bak 115 + -del foo.gz
Added compat/zlib/msdos/Makefile.dj2.
1 +# Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96. 2 +# Copyright (C) 1995-1998 Jean-loup Gailly. 3 +# For conditions of distribution and use, see copyright notice in zlib.h 4 + 5 +# To compile, or to compile and test, type: 6 +# 7 +# make -fmakefile.dj2; make test -fmakefile.dj2 8 +# 9 +# To install libz.a, zconf.h and zlib.h in the djgpp directories, type: 10 +# 11 +# make install -fmakefile.dj2 12 +# 13 +# after first defining LIBRARY_PATH and INCLUDE_PATH in djgpp.env as 14 +# in the sample below if the pattern of the DJGPP distribution is to 15 +# be followed. Remember that, while <sp>'es around <=> are ignored in 16 +# makefiles, they are *not* in batch files or in djgpp.env. 17 +# - - - - - 18 +# [make] 19 +# INCLUDE_PATH=%\>;INCLUDE_PATH%%\DJDIR%\include 20 +# LIBRARY_PATH=%\>;LIBRARY_PATH%%\DJDIR%\lib 21 +# BUTT=-m486 22 +# - - - - - 23 +# Alternately, these variables may be defined below, overriding the values 24 +# in djgpp.env, as 25 +# INCLUDE_PATH=c:\usr\include 26 +# LIBRARY_PATH=c:\usr\lib 27 + 28 +CC=gcc 29 + 30 +#CFLAGS=-MMD -O 31 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 32 +#CFLAGS=-MMD -g -DDEBUG 33 +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 34 + -Wstrict-prototypes -Wmissing-prototypes 35 + 36 +# If cp.exe is available, replace "copy /Y" with "cp -fp" . 37 +CP=copy /Y 38 +# If gnu install.exe is available, replace $(CP) with ginstall. 39 +INSTALL=$(CP) 40 +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: 41 +RM=del 42 +LDLIBS=-L. -lz 43 +LD=$(CC) -s -o 44 +LDSHARED=$(CC) 45 + 46 +INCL=zlib.h zconf.h 47 +LIBS=libz.a 48 + 49 +AR=ar rcs 50 + 51 +prefix=/usr/local 52 +exec_prefix = $(prefix) 53 + 54 +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ 55 + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o 56 + 57 +OBJA = 58 +# to use the asm code: make OBJA=match.o 59 + 60 +TEST_OBJS = example.o minigzip.o 61 + 62 +all: example.exe minigzip.exe 63 + 64 +check: test 65 +test: all 66 + ./example 67 + echo hello world | .\minigzip | .\minigzip -d 68 + 69 +%.o : %.c 70 + $(CC) $(CFLAGS) -c $< -o $@ 71 + 72 +libz.a: $(OBJS) $(OBJA) 73 + $(AR) $@ $(OBJS) $(OBJA) 74 + 75 +%.exe : %.o $(LIBS) 76 + $(LD) $@ $< $(LDLIBS) 77 + 78 +# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env . 79 + 80 +.PHONY : uninstall clean 81 + 82 +install: $(INCL) $(LIBS) 83 + -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH) 84 + -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH) 85 + $(INSTALL) zlib.h $(INCLUDE_PATH) 86 + $(INSTALL) zconf.h $(INCLUDE_PATH) 87 + $(INSTALL) libz.a $(LIBRARY_PATH) 88 + 89 +uninstall: 90 + $(RM) $(INCLUDE_PATH)\zlib.h 91 + $(RM) $(INCLUDE_PATH)\zconf.h 92 + $(RM) $(LIBRARY_PATH)\libz.a 93 + 94 +clean: 95 + $(RM) *.d 96 + $(RM) *.o 97 + $(RM) *.exe 98 + $(RM) libz.a 99 + $(RM) foo.gz 100 + 101 +DEPS := $(wildcard *.d) 102 +ifneq ($(DEPS),) 103 +include $(DEPS) 104 +endif
Added compat/zlib/msdos/Makefile.emx.
1 +# Makefile for zlib. Modified for emx 0.9c by Chr. Spieler, 6/17/98. 2 +# Copyright (C) 1995-1998 Jean-loup Gailly. 3 +# For conditions of distribution and use, see copyright notice in zlib.h 4 + 5 +# To compile, or to compile and test, type: 6 +# 7 +# make -fmakefile.emx; make test -fmakefile.emx 8 +# 9 + 10 +CC=gcc 11 + 12 +#CFLAGS=-MMD -O 13 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 14 +#CFLAGS=-MMD -g -DDEBUG 15 +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 16 + -Wstrict-prototypes -Wmissing-prototypes 17 + 18 +# If cp.exe is available, replace "copy /Y" with "cp -fp" . 19 +CP=copy /Y 20 +# If gnu install.exe is available, replace $(CP) with ginstall. 21 +INSTALL=$(CP) 22 +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: 23 +RM=del 24 +LDLIBS=-L. -lzlib 25 +LD=$(CC) -s -o 26 +LDSHARED=$(CC) 27 + 28 +INCL=zlib.h zconf.h 29 +LIBS=zlib.a 30 + 31 +AR=ar rcs 32 + 33 +prefix=/usr/local 34 +exec_prefix = $(prefix) 35 + 36 +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ 37 + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o 38 + 39 +TEST_OBJS = example.o minigzip.o 40 + 41 +all: example.exe minigzip.exe 42 + 43 +test: all 44 + ./example 45 + echo hello world | .\minigzip | .\minigzip -d 46 + 47 +%.o : %.c 48 + $(CC) $(CFLAGS) -c $< -o $@ 49 + 50 +zlib.a: $(OBJS) 51 + $(AR) $@ $(OBJS) 52 + 53 +%.exe : %.o $(LIBS) 54 + $(LD) $@ $< $(LDLIBS) 55 + 56 + 57 +.PHONY : clean 58 + 59 +clean: 60 + $(RM) *.d 61 + $(RM) *.o 62 + $(RM) *.exe 63 + $(RM) zlib.a 64 + $(RM) foo.gz 65 + 66 +DEPS := $(wildcard *.d) 67 +ifneq ($(DEPS),) 68 +include $(DEPS) 69 +endif
Added compat/zlib/msdos/Makefile.msc.
1 +# Makefile for zlib 2 +# Microsoft C 5.1 or later 3 +# Last updated: 19-Mar-2003 4 + 5 +# To use, do "make makefile.msc" 6 +# To compile in small model, set below: MODEL=S 7 + 8 +# If you wish to reduce the memory requirements (default 256K for big 9 +# objects plus a few K), you can add to the LOC macro below: 10 +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 11 +# See zconf.h for details about the memory requirements. 12 + 13 +# ------------- Microsoft C 5.1 and later ------------- 14 + 15 +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) 16 +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added 17 +# to the declaration of LOC here: 18 +LOC = $(LOCAL_ZLIB) 19 + 20 +# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. 21 +CPU_TYP = 0 22 + 23 +# Memory model: one of S, M, C, L (small, medium, compact, large) 24 +MODEL=L 25 + 26 +CC=cl 27 +CFLAGS=-nologo -A$(MODEL) -G$(CPU_TYP) -W3 -Oait -Gs $(LOC) 28 +#-Ox generates bad code with MSC 5.1 29 +LIB_CFLAGS=-Zl $(CFLAGS) 30 + 31 +LD=link 32 +LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode 33 +# "/farcall/packcode" are only useful for `large code' memory models 34 +# but should be a "no-op" for small code models. 35 + 36 + 37 +# variables 38 +ZLIB_LIB = zlib_$(MODEL).lib 39 + 40 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 41 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 42 + 43 + 44 +# targets 45 +all: $(ZLIB_LIB) example.exe minigzip.exe 46 + 47 +.c.obj: 48 + $(CC) -c $(LIB_CFLAGS) $*.c 49 + 50 +adler32.obj: adler32.c zlib.h zconf.h 51 + 52 +compress.obj: compress.c zlib.h zconf.h 53 + 54 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 55 + 56 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 57 + 58 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 59 + 60 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 61 + 62 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 63 + 64 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 65 + 66 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 67 + inffast.h inffixed.h 68 + 69 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 70 + inffast.h 71 + 72 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 73 + inffast.h inffixed.h 74 + 75 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 76 + 77 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 78 + 79 +uncompr.obj: uncompr.c zlib.h zconf.h 80 + 81 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 82 + 83 +example.obj: test/example.c zlib.h zconf.h 84 + $(CC) -c $(CFLAGS) $*.c 85 + 86 +minigzip.obj: test/minigzip.c zlib.h zconf.h 87 + $(CC) -c $(CFLAGS) $*.c 88 + 89 + 90 +# the command line is cut to fit in the MS-DOS 128 byte limit: 91 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) 92 + if exist $(ZLIB_LIB) del $(ZLIB_LIB) 93 + lib $(ZLIB_LIB) $(OBJ1); 94 + lib $(ZLIB_LIB) $(OBJ2); 95 + 96 +example.exe: example.obj $(ZLIB_LIB) 97 + $(LD) $(LDFLAGS) example.obj,,,$(ZLIB_LIB); 98 + 99 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 100 + $(LD) $(LDFLAGS) minigzip.obj,,,$(ZLIB_LIB); 101 + 102 +test: example.exe minigzip.exe 103 + example 104 + echo hello world | minigzip | minigzip -d 105 + 106 +clean: 107 + -del *.obj 108 + -del *.lib 109 + -del *.exe 110 + -del *.map 111 + -del zlib_*.bak 112 + -del foo.gz
Added compat/zlib/msdos/Makefile.tc.
1 +# Makefile for zlib 2 +# Turbo C 2.01, Turbo C++ 1.01 3 +# Last updated: 15-Mar-2003 4 + 5 +# To use, do "make -fmakefile.tc" 6 +# To compile in small model, set below: MODEL=s 7 + 8 +# WARNING: the small model is supported but only for small values of 9 +# MAX_WBITS and MAX_MEM_LEVEL. For example: 10 +# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 11 +# If you wish to reduce the memory requirements (default 256K for big 12 +# objects plus a few K), you can add to CFLAGS below: 13 +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 14 +# See zconf.h for details about the memory requirements. 15 + 16 +# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------ 17 +MODEL=l 18 +CC=tcc 19 +LD=tcc 20 +AR=tlib 21 +# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 22 +CFLAGS=-O2 -G -Z -m$(MODEL) 23 +LDFLAGS=-m$(MODEL) -f- 24 + 25 + 26 +# variables 27 +ZLIB_LIB = zlib_$(MODEL).lib 28 + 29 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 30 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 31 +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj 32 +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 33 + 34 + 35 +# targets 36 +all: $(ZLIB_LIB) example.exe minigzip.exe 37 + 38 +.c.obj: 39 + $(CC) -c $(CFLAGS) $*.c 40 + 41 +adler32.obj: adler32.c zlib.h zconf.h 42 + 43 +compress.obj: compress.c zlib.h zconf.h 44 + 45 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 46 + 47 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 48 + 49 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 50 + 51 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 52 + 53 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 54 + 55 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 56 + 57 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 58 + inffast.h inffixed.h 59 + 60 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 61 + inffast.h 62 + 63 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 64 + inffast.h inffixed.h 65 + 66 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 67 + 68 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 69 + 70 +uncompr.obj: uncompr.c zlib.h zconf.h 71 + 72 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 73 + 74 +example.obj: test/example.c zlib.h zconf.h 75 + 76 +minigzip.obj: test/minigzip.c zlib.h zconf.h 77 + 78 + 79 +# the command line is cut to fit in the MS-DOS 128 byte limit: 80 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) 81 + -del $(ZLIB_LIB) 82 + $(AR) $(ZLIB_LIB) $(OBJP1) 83 + $(AR) $(ZLIB_LIB) $(OBJP2) 84 + 85 +example.exe: example.obj $(ZLIB_LIB) 86 + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) 87 + 88 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 89 + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) 90 + 91 +test: example.exe minigzip.exe 92 + example 93 + echo hello world | minigzip | minigzip -d 94 + 95 +clean: 96 + -del *.obj 97 + -del *.lib 98 + -del *.exe 99 + -del zlib_*.bak 100 + -del foo.gz
Added compat/zlib/nintendods/Makefile.
1 +#--------------------------------------------------------------------------------- 2 +.SUFFIXES: 3 +#--------------------------------------------------------------------------------- 4 + 5 +ifeq ($(strip $(DEVKITARM)),) 6 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") 7 +endif 8 + 9 +include $(DEVKITARM)/ds_rules 10 + 11 +#--------------------------------------------------------------------------------- 12 +# TARGET is the name of the output 13 +# BUILD is the directory where object files & intermediate files will be placed 14 +# SOURCES is a list of directories containing source code 15 +# DATA is a list of directories containing data files 16 +# INCLUDES is a list of directories containing header files 17 +#--------------------------------------------------------------------------------- 18 +TARGET := $(shell basename $(CURDIR)) 19 +BUILD := build 20 +SOURCES := ../../ 21 +DATA := data 22 +INCLUDES := include 23 + 24 +#--------------------------------------------------------------------------------- 25 +# options for code generation 26 +#--------------------------------------------------------------------------------- 27 +ARCH := -mthumb -mthumb-interwork 28 + 29 +CFLAGS := -Wall -O2\ 30 + -march=armv5te -mtune=arm946e-s \ 31 + -fomit-frame-pointer -ffast-math \ 32 + $(ARCH) 33 + 34 +CFLAGS += $(INCLUDE) -DARM9 35 +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 36 + 37 +ASFLAGS := $(ARCH) -march=armv5te -mtune=arm946e-s 38 +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 39 + 40 +#--------------------------------------------------------------------------------- 41 +# list of directories containing libraries, this must be the top level containing 42 +# include and lib 43 +#--------------------------------------------------------------------------------- 44 +LIBDIRS := $(LIBNDS) 45 + 46 +#--------------------------------------------------------------------------------- 47 +# no real need to edit anything past this point unless you need to add additional 48 +# rules for different file extensions 49 +#--------------------------------------------------------------------------------- 50 +ifneq ($(BUILD),$(notdir $(CURDIR))) 51 +#--------------------------------------------------------------------------------- 52 + 53 +export OUTPUT := $(CURDIR)/lib/libz.a 54 + 55 +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 57 + 58 +export DEPSDIR := $(CURDIR)/$(BUILD) 59 + 60 +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 61 +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 62 +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 63 +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 64 + 65 +#--------------------------------------------------------------------------------- 66 +# use CXX for linking C++ projects, CC for standard C 67 +#--------------------------------------------------------------------------------- 68 +ifeq ($(strip $(CPPFILES)),) 69 +#--------------------------------------------------------------------------------- 70 + export LD := $(CC) 71 +#--------------------------------------------------------------------------------- 72 +else 73 +#--------------------------------------------------------------------------------- 74 + export LD := $(CXX) 75 +#--------------------------------------------------------------------------------- 76 +endif 77 +#--------------------------------------------------------------------------------- 78 + 79 +export OFILES := $(addsuffix .o,$(BINFILES)) \ 80 + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 81 + 82 +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 83 + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 84 + -I$(CURDIR)/$(BUILD) 85 + 86 +.PHONY: $(BUILD) clean all 87 + 88 +#--------------------------------------------------------------------------------- 89 +all: $(BUILD) 90 + @[ -d $@ ] || mkdir -p include 91 + @cp ../../*.h include 92 + 93 +lib: 94 + @[ -d $@ ] || mkdir -p $@ 95 + 96 +$(BUILD): lib 97 + @[ -d $@ ] || mkdir -p $@ 98 + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 99 + 100 +#--------------------------------------------------------------------------------- 101 +clean: 102 + @echo clean ... 103 + @rm -fr $(BUILD) lib 104 + 105 +#--------------------------------------------------------------------------------- 106 +else 107 + 108 +DEPENDS := $(OFILES:.o=.d) 109 + 110 +#--------------------------------------------------------------------------------- 111 +# main targets 112 +#--------------------------------------------------------------------------------- 113 +$(OUTPUT) : $(OFILES) 114 + 115 +#--------------------------------------------------------------------------------- 116 +%.bin.o : %.bin 117 +#--------------------------------------------------------------------------------- 118 + @echo $(notdir $<) 119 + @$(bin2o) 120 + 121 + 122 +-include $(DEPENDS) 123 + 124 +#--------------------------------------------------------------------------------------- 125 +endif 126 +#---------------------------------------------------------------------------------------
Added compat/zlib/nintendods/README.
1 +This Makefile requires devkitARM (http://www.devkitpro.org/category/devkitarm/) and works inside "contrib/nds". It is based on a devkitARM template. 2 + 3 +Eduardo Costa <eduardo.m.costa@gmail.com> 4 +January 3, 2009 5 +
Added compat/zlib/old/Makefile.emx.
1 +# Makefile for zlib. Modified for emx/rsxnt by Chr. Spieler, 6/16/98. 2 +# Copyright (C) 1995-1998 Jean-loup Gailly. 3 +# For conditions of distribution and use, see copyright notice in zlib.h 4 + 5 +# To compile, or to compile and test, type: 6 +# 7 +# make -fmakefile.emx; make test -fmakefile.emx 8 +# 9 + 10 +CC=gcc -Zwin32 11 + 12 +#CFLAGS=-MMD -O 13 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 14 +#CFLAGS=-MMD -g -DDEBUG 15 +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 16 + -Wstrict-prototypes -Wmissing-prototypes 17 + 18 +# If cp.exe is available, replace "copy /Y" with "cp -fp" . 19 +CP=copy /Y 20 +# If gnu install.exe is available, replace $(CP) with ginstall. 21 +INSTALL=$(CP) 22 +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: 23 +RM=del 24 +LDLIBS=-L. -lzlib 25 +LD=$(CC) -s -o 26 +LDSHARED=$(CC) 27 + 28 +INCL=zlib.h zconf.h 29 +LIBS=zlib.a 30 + 31 +AR=ar rcs 32 + 33 +prefix=/usr/local 34 +exec_prefix = $(prefix) 35 + 36 +OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ 37 + gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 38 + 39 +TEST_OBJS = example.o minigzip.o 40 + 41 +all: example.exe minigzip.exe 42 + 43 +test: all 44 + ./example 45 + echo hello world | .\minigzip | .\minigzip -d 46 + 47 +%.o : %.c 48 + $(CC) $(CFLAGS) -c $< -o $@ 49 + 50 +zlib.a: $(OBJS) 51 + $(AR) $@ $(OBJS) 52 + 53 +%.exe : %.o $(LIBS) 54 + $(LD) $@ $< $(LDLIBS) 55 + 56 + 57 +.PHONY : clean 58 + 59 +clean: 60 + $(RM) *.d 61 + $(RM) *.o 62 + $(RM) *.exe 63 + $(RM) zlib.a 64 + $(RM) foo.gz 65 + 66 +DEPS := $(wildcard *.d) 67 +ifneq ($(DEPS),) 68 +include $(DEPS) 69 +endif
Added compat/zlib/old/Makefile.riscos.
1 +# Project: zlib_1_03 2 +# Patched for zlib 1.1.2 rw@shadow.org.uk 19980430 3 +# test works out-of-the-box, installs `somewhere' on demand 4 + 5 +# Toolflags: 6 +CCflags = -c -depend !Depend -IC: -g -throwback -DRISCOS -fah 7 +C++flags = -c -depend !Depend -IC: -throwback 8 +Linkflags = -aif -c++ -o $@ 9 +ObjAsmflags = -throwback -NoCache -depend !Depend 10 +CMHGflags = 11 +LibFileflags = -c -l -o $@ 12 +Squeezeflags = -o $@ 13 + 14 +# change the line below to where _you_ want the library installed. 15 +libdest = lib:zlib 16 + 17 +# Final targets: 18 +@.lib: @.o.adler32 @.o.compress @.o.crc32 @.o.deflate @.o.gzio \ 19 + @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil @.o.trees \ 20 + @.o.uncompr @.o.zutil 21 + LibFile $(LibFileflags) @.o.adler32 @.o.compress @.o.crc32 @.o.deflate \ 22 + @.o.gzio @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil \ 23 + @.o.trees @.o.uncompr @.o.zutil 24 +test: @.minigzip @.example @.lib 25 + @copy @.lib @.libc A~C~DF~L~N~P~Q~RS~TV 26 + @echo running tests: hang on. 27 + @/@.minigzip -f -9 libc 28 + @/@.minigzip -d libc-gz 29 + @/@.minigzip -f -1 libc 30 + @/@.minigzip -d libc-gz 31 + @/@.minigzip -h -9 libc 32 + @/@.minigzip -d libc-gz 33 + @/@.minigzip -h -1 libc 34 + @/@.minigzip -d libc-gz 35 + @/@.minigzip -9 libc 36 + @/@.minigzip -d libc-gz 37 + @/@.minigzip -1 libc 38 + @/@.minigzip -d libc-gz 39 + @diff @.lib @.libc 40 + @echo that should have reported '@.lib and @.libc identical' if you have diff. 41 + @/@.example @.fred @.fred 42 + @echo that will have given lots of hello!'s. 43 + 44 +@.minigzip: @.o.minigzip @.lib C:o.Stubs 45 + Link $(Linkflags) @.o.minigzip @.lib C:o.Stubs 46 +@.example: @.o.example @.lib C:o.Stubs 47 + Link $(Linkflags) @.o.example @.lib C:o.Stubs 48 + 49 +install: @.lib 50 + cdir $(libdest) 51 + cdir $(libdest).h 52 + @copy @.h.zlib $(libdest).h.zlib A~C~DF~L~N~P~Q~RS~TV 53 + @copy @.h.zconf $(libdest).h.zconf A~C~DF~L~N~P~Q~RS~TV 54 + @copy @.lib $(libdest).lib A~C~DF~L~N~P~Q~RS~TV 55 + @echo okay, installed zlib in $(libdest) 56 + 57 +clean:; remove @.minigzip 58 + remove @.example 59 + remove @.libc 60 + -wipe @.o.* F~r~cV 61 + remove @.fred 62 + 63 +# User-editable dependencies: 64 +.c.o: 65 + cc $(ccflags) -o $@ $< 66 + 67 +# Static dependencies: 68 + 69 +# Dynamic dependencies: 70 +o.example: c.example 71 +o.example: h.zlib 72 +o.example: h.zconf 73 +o.minigzip: c.minigzip 74 +o.minigzip: h.zlib 75 +o.minigzip: h.zconf 76 +o.adler32: c.adler32 77 +o.adler32: h.zlib 78 +o.adler32: h.zconf 79 +o.compress: c.compress 80 +o.compress: h.zlib 81 +o.compress: h.zconf 82 +o.crc32: c.crc32 83 +o.crc32: h.zlib 84 +o.crc32: h.zconf 85 +o.deflate: c.deflate 86 +o.deflate: h.deflate 87 +o.deflate: h.zutil 88 +o.deflate: h.zlib 89 +o.deflate: h.zconf 90 +o.gzio: c.gzio 91 +o.gzio: h.zutil 92 +o.gzio: h.zlib 93 +o.gzio: h.zconf 94 +o.infblock: c.infblock 95 +o.infblock: h.zutil 96 +o.infblock: h.zlib 97 +o.infblock: h.zconf 98 +o.infblock: h.infblock 99 +o.infblock: h.inftrees 100 +o.infblock: h.infcodes 101 +o.infblock: h.infutil 102 +o.infcodes: c.infcodes 103 +o.infcodes: h.zutil 104 +o.infcodes: h.zlib 105 +o.infcodes: h.zconf 106 +o.infcodes: h.inftrees 107 +o.infcodes: h.infblock 108 +o.infcodes: h.infcodes 109 +o.infcodes: h.infutil 110 +o.infcodes: h.inffast 111 +o.inffast: c.inffast 112 +o.inffast: h.zutil 113 +o.inffast: h.zlib 114 +o.inffast: h.zconf 115 +o.inffast: h.inftrees 116 +o.inffast: h.infblock 117 +o.inffast: h.infcodes 118 +o.inffast: h.infutil 119 +o.inffast: h.inffast 120 +o.inflate: c.inflate 121 +o.inflate: h.zutil 122 +o.inflate: h.zlib 123 +o.inflate: h.zconf 124 +o.inflate: h.infblock 125 +o.inftrees: c.inftrees 126 +o.inftrees: h.zutil 127 +o.inftrees: h.zlib 128 +o.inftrees: h.zconf 129 +o.inftrees: h.inftrees 130 +o.inftrees: h.inffixed 131 +o.infutil: c.infutil 132 +o.infutil: h.zutil 133 +o.infutil: h.zlib 134 +o.infutil: h.zconf 135 +o.infutil: h.infblock 136 +o.infutil: h.inftrees 137 +o.infutil: h.infcodes 138 +o.infutil: h.infutil 139 +o.trees: c.trees 140 +o.trees: h.deflate 141 +o.trees: h.zutil 142 +o.trees: h.zlib 143 +o.trees: h.zconf 144 +o.trees: h.trees 145 +o.uncompr: c.uncompr 146 +o.uncompr: h.zlib 147 +o.uncompr: h.zconf 148 +o.zutil: c.zutil 149 +o.zutil: h.zutil 150 +o.zutil: h.zlib 151 +o.zutil: h.zconf
Added compat/zlib/old/README.
1 +This directory contains files that have not been updated for zlib 1.2.x 2 + 3 +(Volunteers are encouraged to help clean this up. Thanks.)
Added compat/zlib/old/descrip.mms.
1 +# descrip.mms: MMS description file for building zlib on VMS 2 +# written by Martin P.J. Zinser <m.zinser@gsi.de> 3 + 4 +cc_defs = 5 +c_deb = 6 + 7 +.ifdef __DECC__ 8 +pref = /prefix=all 9 +.endif 10 + 11 +OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\ 12 + deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\ 13 + inftrees.obj, infcodes.obj, infutil.obj, inffast.obj 14 + 15 +CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF) 16 + 17 +all : example.exe minigzip.exe 18 + @ write sys$output " Example applications available" 19 +libz.olb : libz.olb($(OBJS)) 20 + @ write sys$output " libz available" 21 + 22 +example.exe : example.obj libz.olb 23 + link example,libz.olb/lib 24 + 25 +minigzip.exe : minigzip.obj libz.olb 26 + link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib 27 + 28 +clean : 29 + delete *.obj;*,libz.olb;* 30 + 31 + 32 +# Other dependencies. 33 +adler32.obj : zutil.h zlib.h zconf.h 34 +compress.obj : zlib.h zconf.h 35 +crc32.obj : zutil.h zlib.h zconf.h 36 +deflate.obj : deflate.h zutil.h zlib.h zconf.h 37 +example.obj : zlib.h zconf.h 38 +gzio.obj : zutil.h zlib.h zconf.h 39 +infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h 40 +infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h 41 +inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h 42 +inflate.obj : zutil.h zlib.h zconf.h infblock.h 43 +inftrees.obj : zutil.h zlib.h zconf.h inftrees.h 44 +infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h 45 +minigzip.obj : zlib.h zconf.h 46 +trees.obj : deflate.h zutil.h zlib.h zconf.h 47 +uncompr.obj : zlib.h zconf.h 48 +zutil.obj : zutil.h zlib.h zconf.h
Added compat/zlib/old/os2/Makefile.os2.
1 +# Makefile for zlib under OS/2 using GCC (PGCC) 2 +# For conditions of distribution and use, see copyright notice in zlib.h 3 + 4 +# To compile and test, type: 5 +# cp Makefile.os2 .. 6 +# cd .. 7 +# make -f Makefile.os2 test 8 + 9 +# This makefile will build a static library z.lib, a shared library 10 +# z.dll and a import library zdll.lib. You can use either z.lib or 11 +# zdll.lib by specifying either -lz or -lzdll on gcc's command line 12 + 13 +CC=gcc -Zomf -s 14 + 15 +CFLAGS=-O6 -Wall 16 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 17 +#CFLAGS=-g -DDEBUG 18 +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 19 +# -Wstrict-prototypes -Wmissing-prototypes 20 + 21 +#################### BUG WARNING: ##################### 22 +## infcodes.c hits a bug in pgcc-1.0, so you have to use either 23 +## -O# where # <= 4 or one of (-fno-ommit-frame-pointer or -fno-force-mem) 24 +## This bug is reportedly fixed in pgcc >1.0, but this was not tested 25 +CFLAGS+=-fno-force-mem 26 + 27 +LDFLAGS=-s -L. -lzdll -Zcrtdll 28 +LDSHARED=$(CC) -s -Zomf -Zdll -Zcrtdll 29 + 30 +VER=1.1.0 31 +ZLIB=z.lib 32 +SHAREDLIB=z.dll 33 +SHAREDLIBIMP=zdll.lib 34 +LIBS=$(ZLIB) $(SHAREDLIB) $(SHAREDLIBIMP) 35 + 36 +AR=emxomfar cr 37 +IMPLIB=emximp 38 +RANLIB=echo 39 +TAR=tar 40 +SHELL=bash 41 + 42 +prefix=/usr/local 43 +exec_prefix = $(prefix) 44 + 45 +OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ 46 + zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o 47 + 48 +TEST_OBJS = example.o minigzip.o 49 + 50 +DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \ 51 + algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ 52 + nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \ 53 + contrib/asm386/*.asm contrib/asm386/*.c \ 54 + contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/iostream/*.cpp \ 55 + contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ 56 + contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 57 + 58 +all: example.exe minigzip.exe 59 + 60 +test: all 61 + @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ 62 + echo hello world | ./minigzip | ./minigzip -d || \ 63 + echo ' *** minigzip test FAILED ***' ; \ 64 + if ./example; then \ 65 + echo ' *** zlib test OK ***'; \ 66 + else \ 67 + echo ' *** zlib test FAILED ***'; \ 68 + fi 69 + 70 +$(ZLIB): $(OBJS) 71 + $(AR) $@ $(OBJS) 72 + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 73 + 74 +$(SHAREDLIB): $(OBJS) os2/z.def 75 + $(LDSHARED) -o $@ $^ 76 + 77 +$(SHAREDLIBIMP): os2/z.def 78 + $(IMPLIB) -o $@ $^ 79 + 80 +example.exe: example.o $(LIBS) 81 + $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) 82 + 83 +minigzip.exe: minigzip.o $(LIBS) 84 + $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) 85 + 86 +clean: 87 + rm -f *.o *~ example minigzip libz.a libz.so* foo.gz 88 + 89 +distclean: clean 90 + 91 +zip: 92 + mv Makefile Makefile~; cp -p Makefile.in Makefile 93 + rm -f test.c ztest*.c 94 + v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ 95 + zip -ul9 zlib$$v $(DISTFILES) 96 + mv Makefile~ Makefile 97 + 98 +dist: 99 + mv Makefile Makefile~; cp -p Makefile.in Makefile 100 + rm -f test.c ztest*.c 101 + d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ 102 + rm -f $$d.tar.gz; \ 103 + if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ 104 + files=""; \ 105 + for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ 106 + cd ..; \ 107 + GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ 108 + if test ! -d $$d; then rm -f $$d; fi 109 + mv Makefile~ Makefile 110 + 111 +tags: 112 + etags *.[ch] 113 + 114 +depend: 115 + makedepend -- $(CFLAGS) -- *.[ch] 116 + 117 +# DO NOT DELETE THIS LINE -- make depend depends on it. 118 + 119 +adler32.o: zlib.h zconf.h 120 +compress.o: zlib.h zconf.h 121 +crc32.o: zlib.h zconf.h 122 +deflate.o: deflate.h zutil.h zlib.h zconf.h 123 +example.o: zlib.h zconf.h 124 +gzio.o: zutil.h zlib.h zconf.h 125 +infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h 126 +infcodes.o: zutil.h zlib.h zconf.h 127 +infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h 128 +inffast.o: zutil.h zlib.h zconf.h inftrees.h 129 +inffast.o: infblock.h infcodes.h infutil.h inffast.h 130 +inflate.o: zutil.h zlib.h zconf.h infblock.h 131 +inftrees.o: zutil.h zlib.h zconf.h inftrees.h 132 +infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h 133 +minigzip.o: zlib.h zconf.h 134 +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h 135 +uncompr.o: zlib.h zconf.h 136 +zutil.o: zutil.h zlib.h zconf.h
Added compat/zlib/old/os2/zlib.def.
1 +; 2 +; Slightly modified version of ../nt/zlib.dnt :-) 3 +; 4 + 5 +LIBRARY Z 6 +DESCRIPTION "Zlib compression library for OS/2" 7 +CODE PRELOAD MOVEABLE DISCARDABLE 8 +DATA PRELOAD MOVEABLE MULTIPLE 9 + 10 +EXPORTS 11 + adler32 12 + compress 13 + crc32 14 + deflate 15 + deflateCopy 16 + deflateEnd 17 + deflateInit2_ 18 + deflateInit_ 19 + deflateParams 20 + deflateReset 21 + deflateSetDictionary 22 + gzclose 23 + gzdopen 24 + gzerror 25 + gzflush 26 + gzopen 27 + gzread 28 + gzwrite 29 + inflate 30 + inflateEnd 31 + inflateInit2_ 32 + inflateInit_ 33 + inflateReset 34 + inflateSetDictionary 35 + inflateSync 36 + uncompress 37 + zlibVersion 38 + gzprintf 39 + gzputc 40 + gzgetc 41 + gzseek 42 + gzrewind 43 + gztell 44 + gzeof 45 + gzsetparams 46 + zError 47 + inflateSyncPoint 48 + get_crc_table 49 + compress2 50 + gzputs 51 + gzgets
Added compat/zlib/old/visual-basic.txt.
1 +See below some functions declarations for Visual Basic. 2 + 3 +Frequently Asked Question: 4 + 5 +Q: Each time I use the compress function I get the -5 error (not enough 6 + room in the output buffer). 7 + 8 +A: Make sure that the length of the compressed buffer is passed by 9 + reference ("as any"), not by value ("as long"). Also check that 10 + before the call of compress this length is equal to the total size of 11 + the compressed buffer and not zero. 12 + 13 + 14 +From: "Jon Caruana" <jon-net@usa.net> 15 +Subject: Re: How to port zlib declares to vb? 16 +Date: Mon, 28 Oct 1996 18:33:03 -0600 17 + 18 +Got the answer! (I haven't had time to check this but it's what I got, and 19 +looks correct): 20 + 21 +He has the following routines working: 22 + compress 23 + uncompress 24 + gzopen 25 + gzwrite 26 + gzread 27 + gzclose 28 + 29 +Declares follow: (Quoted from Carlos Rios <c_rios@sonda.cl>, in Vb4 form) 30 + 31 +#If Win16 Then 'Use Win16 calls. 32 +Declare Function compress Lib "ZLIB.DLL" (ByVal compr As 33 + String, comprLen As Any, ByVal buf As String, ByVal buflen 34 + As Long) As Integer 35 +Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr 36 + As String, uncomprLen As Any, ByVal compr As String, ByVal 37 + lcompr As Long) As Integer 38 +Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As 39 + String, ByVal mode As String) As Long 40 +Declare Function gzread Lib "ZLIB.DLL" (ByVal file As 41 + Long, ByVal uncompr As String, ByVal uncomprLen As Integer) 42 + As Integer 43 +Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As 44 + Long, ByVal uncompr As String, ByVal uncomprLen As Integer) 45 + As Integer 46 +Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As 47 + Long) As Integer 48 +#Else 49 +Declare Function compress Lib "ZLIB32.DLL" 50 + (ByVal compr As String, comprLen As Any, ByVal buf As 51 + String, ByVal buflen As Long) As Integer 52 +Declare Function uncompress Lib "ZLIB32.DLL" 53 + (ByVal uncompr As String, uncomprLen As Any, ByVal compr As 54 + String, ByVal lcompr As Long) As Long 55 +Declare Function gzopen Lib "ZLIB32.DLL" 56 + (ByVal file As String, ByVal mode As String) As Long 57 +Declare Function gzread Lib "ZLIB32.DLL" 58 + (ByVal file As Long, ByVal uncompr As String, ByVal 59 + uncomprLen As Long) As Long 60 +Declare Function gzwrite Lib "ZLIB32.DLL" 61 + (ByVal file As Long, ByVal uncompr As String, ByVal 62 + uncomprLen As Long) As Long 63 +Declare Function gzclose Lib "ZLIB32.DLL" 64 + (ByVal file As Long) As Long 65 +#End If 66 + 67 +-Jon Caruana 68 +jon-net@usa.net 69 +Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member 70 + 71 + 72 +Here is another example from Michael <michael_borgsys@hotmail.com> that he 73 +says conforms to the VB guidelines, and that solves the problem of not 74 +knowing the uncompressed size by storing it at the end of the file: 75 + 76 +'Calling the functions: 77 +'bracket meaning: <parameter> [optional] {Range of possible values} 78 +'Call subCompressFile(<path with filename to compress> [, <path with 79 +filename to write to>, [level of compression {1..9}]]) 80 +'Call subUncompressFile(<path with filename to compress>) 81 + 82 +Option Explicit 83 +Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller' 84 +Private Const SUCCESS As Long = 0 85 +Private Const strFilExt As String = ".cpr" 86 +Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef 87 +dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long, 88 +ByVal level As Integer) As Long 89 +Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef 90 +dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long) 91 +As Long 92 + 93 +Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal 94 +strargCprFilPth As String, Optional ByVal intLvl As Integer = 9) 95 + Dim strCprPth As String 96 + Dim lngOriSiz As Long 97 + Dim lngCprSiz As Long 98 + Dim bytaryOri() As Byte 99 + Dim bytaryCpr() As Byte 100 + lngOriSiz = FileLen(strargOriFilPth) 101 + ReDim bytaryOri(lngOriSiz - 1) 102 + Open strargOriFilPth For Binary Access Read As #1 103 + Get #1, , bytaryOri() 104 + Close #1 105 + strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth) 106 +'Select file path and name 107 + strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) = 108 +strFilExt, "", strFilExt) 'Add file extension if not exists 109 + lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit 110 +more space then original file size 111 + ReDim bytaryCpr(lngCprSiz - 1) 112 + If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) = 113 +SUCCESS Then 114 + lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100 115 + ReDim Preserve bytaryCpr(lngCprSiz - 1) 116 + Open strCprPth For Binary Access Write As #1 117 + Put #1, , bytaryCpr() 118 + Put #1, , lngOriSiz 'Add the the original size value to the end 119 +(last 4 bytes) 120 + Close #1 121 + Else 122 + MsgBox "Compression error" 123 + End If 124 + Erase bytaryCpr 125 + Erase bytaryOri 126 +End Sub 127 + 128 +Public Sub subUncompressFile(ByVal strargFilPth As String) 129 + Dim bytaryCpr() As Byte 130 + Dim bytaryOri() As Byte 131 + Dim lngOriSiz As Long 132 + Dim lngCprSiz As Long 133 + Dim strOriPth As String 134 + lngCprSiz = FileLen(strargFilPth) 135 + ReDim bytaryCpr(lngCprSiz - 1) 136 + Open strargFilPth For Binary Access Read As #1 137 + Get #1, , bytaryCpr() 138 + Close #1 139 + 'Read the original file size value: 140 + lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _ 141 + + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _ 142 + + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _ 143 + + bytaryCpr(lngCprSiz - 4) 144 + ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value 145 + ReDim bytaryOri(lngOriSiz - 1) 146 + If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS 147 +Then 148 + strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt)) 149 + Open strOriPth For Binary Access Write As #1 150 + Put #1, , bytaryOri() 151 + Close #1 152 + Else 153 + MsgBox "Uncompression error" 154 + End If 155 + Erase bytaryCpr 156 + Erase bytaryOri 157 +End Sub 158 +Public Property Get lngPercentSmaller() As Long 159 + lngPercentSmaller = lngpvtPcnSml 160 +End Property
Added compat/zlib/qnx/package.qpg.
1 +<QPG:Generation> 2 + <QPG:Options> 3 + <QPG:User unattended="no" verbosity="2" listfiles="yes"/> 4 + <QPG:Defaults type="qnx_package"/> 5 + <QPG:Source></QPG:Source> 6 + <QPG:Release number="+"/> 7 + <QPG:Build></QPG:Build> 8 + <QPG:FileSorting strip="yes"/> 9 + <QPG:Package targets="combine"/> 10 + <QPG:Repository generate="yes"/> 11 + <QPG:FinalDir></QPG:FinalDir> 12 + <QPG:Cleanup></QPG:Cleanup> 13 + </QPG:Options> 14 + 15 + <QPG:Responsible> 16 + <QPG:Company></QPG:Company> 17 + <QPG:Department></QPG:Department> 18 + <QPG:Group></QPG:Group> 19 + <QPG:Team></QPG:Team> 20 + <QPG:Employee></QPG:Employee> 21 + <QPG:EmailAddress></QPG:EmailAddress> 22 + </QPG:Responsible> 23 + 24 + <QPG:Values> 25 + <QPG:Files> 26 + <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/> 27 + <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/> 28 + <QPG:Add file="../libz.so.1.2.7" install="/opt/lib/" user="root:bin" permission="644"/> 29 + <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.7"/> 30 + <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.7"/> 31 + <QPG:Add file="../libz.so.1.2.7" install="/opt/lib/" component="slib"/> 32 + </QPG:Files> 33 + 34 + <QPG:PackageFilter> 35 + <QPM:PackageManifest> 36 + <QPM:PackageDescription> 37 + <QPM:PackageType>Library</QPM:PackageType> 38 + <QPM:PackageReleaseNotes></QPM:PackageReleaseNotes> 39 + <QPM:PackageReleaseUrgency>Medium</QPM:PackageReleaseUrgency> 40 + <QPM:PackageRepository></QPM:PackageRepository> 41 + <QPM:FileVersion>2.0</QPM:FileVersion> 42 + </QPM:PackageDescription> 43 + 44 + <QPM:ProductDescription> 45 + <QPM:ProductName>zlib</QPM:ProductName> 46 + <QPM:ProductIdentifier>zlib</QPM:ProductIdentifier> 47 + <QPM:ProductEmail>alain.bonnefoy@icbt.com</QPM:ProductEmail> 48 + <QPM:VendorName>Public</QPM:VendorName> 49 + <QPM:VendorInstallName>public</QPM:VendorInstallName> 50 + <QPM:VendorURL>www.gzip.org/zlib</QPM:VendorURL> 51 + <QPM:VendorEmbedURL></QPM:VendorEmbedURL> 52 + <QPM:VendorEmail></QPM:VendorEmail> 53 + <QPM:AuthorName>Jean-Loup Gailly,Mark Adler</QPM:AuthorName> 54 + <QPM:AuthorURL>www.gzip.org/zlib</QPM:AuthorURL> 55 + <QPM:AuthorEmbedURL></QPM:AuthorEmbedURL> 56 + <QPM:AuthorEmail>zlib@gzip.org</QPM:AuthorEmail> 57 + <QPM:ProductIconSmall></QPM:ProductIconSmall> 58 + <QPM:ProductIconLarge></QPM:ProductIconLarge> 59 + <QPM:ProductDescriptionShort>A massively spiffy yet delicately unobtrusive compression library.</QPM:ProductDescriptionShort> 60 + <QPM:ProductDescriptionLong>zlib is designed to be a free, general-purpose, legally unencumbered, lossless data compression library for use on virtually any computer hardware and operating system.</QPM:ProductDescriptionLong> 61 + <QPM:ProductDescriptionURL>http://www.gzip.org/zlib</QPM:ProductDescriptionURL> 62 + <QPM:ProductDescriptionEmbedURL></QPM:ProductDescriptionEmbedURL> 63 + </QPM:ProductDescription> 64 + 65 + <QPM:ReleaseDescription> 66 + <QPM:ReleaseVersion>1.2.7</QPM:ReleaseVersion> 67 + <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency> 68 + <QPM:ReleaseStability>Stable</QPM:ReleaseStability> 69 + <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor> 70 + <QPM:ReleaseNoteMajor></QPM:ReleaseNoteMajor> 71 + <QPM:ExcludeCountries> 72 + <QPM:Country></QPM:Country> 73 + </QPM:ExcludeCountries> 74 + 75 + <QPM:ReleaseCopyright>No License</QPM:ReleaseCopyright> 76 + </QPM:ReleaseDescription> 77 + 78 + <QPM:ContentDescription> 79 + <QPM:ContentTopic xmlmultiple="true">Software Development/Libraries and Extensions/C Libraries</QPM:ContentTopic> 80 + <QPM:ContentKeyword>zlib,compression</QPM:ContentKeyword> 81 + <QPM:TargetOS>qnx6</QPM:TargetOS> 82 + <QPM:HostOS>qnx6</QPM:HostOS> 83 + <QPM:DisplayEnvironment xmlmultiple="true">None</QPM:DisplayEnvironment> 84 + <QPM:TargetAudience xmlmultiple="true">Developer</QPM:TargetAudience> 85 + </QPM:ContentDescription> 86 + </QPM:PackageManifest> 87 + </QPG:PackageFilter> 88 + 89 + <QPG:PackageFilter proc="none" target="none"> 90 + <QPM:PackageManifest> 91 + <QPM:ProductInstallationDependencies> 92 + <QPM:ProductRequirements></QPM:ProductRequirements> 93 + </QPM:ProductInstallationDependencies> 94 + 95 + <QPM:ProductInstallationProcedure> 96 + <QPM:Script xmlmultiple="true"> 97 + <QPM:ScriptName></QPM:ScriptName> 98 + <QPM:ScriptType>Install</QPM:ScriptType> 99 + <QPM:ScriptTiming>Post</QPM:ScriptTiming> 100 + <QPM:ScriptBlocking>No</QPM:ScriptBlocking> 101 + <QPM:ScriptResult>Ignore</QPM:ScriptResult> 102 + <QPM:ShortDescription></QPM:ShortDescription> 103 + <QPM:UseBinaries>No</QPM:UseBinaries> 104 + <QPM:Priority>Optional</QPM:Priority> 105 + </QPM:Script> 106 + </QPM:ProductInstallationProcedure> 107 + </QPM:PackageManifest> 108 + 109 + <QPM:Launch> 110 + </QPM:Launch> 111 + </QPG:PackageFilter> 112 + 113 + <QPG:PackageFilter type="core" component="none"> 114 + <QPM:PackageManifest> 115 + <QPM:ProductInstallationProcedure> 116 + <QPM:OrderDependency xmlmultiple="true"> 117 + <QPM:Order>InstallOver</QPM:Order> 118 + <QPM:Product>zlib</QPM:Product> 119 + </QPM:OrderDependency> 120 + </QPM:ProductInstallationProcedure> 121 + </QPM:PackageManifest> 122 + 123 + <QPM:Launch> 124 + </QPM:Launch> 125 + </QPG:PackageFilter> 126 + 127 + <QPG:PackageFilter type="core" component="dev"> 128 + <QPM:PackageManifest> 129 + <QPM:ProductInstallationProcedure> 130 + <QPM:OrderDependency xmlmultiple="true"> 131 + <QPM:Order>InstallOver</QPM:Order> 132 + <QPM:Product>zlib-dev</QPM:Product> 133 + </QPM:OrderDependency> 134 + </QPM:ProductInstallationProcedure> 135 + </QPM:PackageManifest> 136 + 137 + <QPM:Launch> 138 + </QPM:Launch> 139 + </QPG:PackageFilter> 140 + </QPG:Values> 141 +</QPG:Generation>
Added compat/zlib/test/example.c.
1 +/* example.c -- usage example of the zlib compression library 2 + * Copyright (C) 1995-2006, 2011 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#include "zlib.h" 9 +#include <stdio.h> 10 + 11 +#ifdef STDC 12 +# include <string.h> 13 +# include <stdlib.h> 14 +#endif 15 + 16 +#if defined(VMS) || defined(RISCOS) 17 +# define TESTFILE "foo-gz" 18 +#else 19 +# define TESTFILE "foo.gz" 20 +#endif 21 + 22 +#define CHECK_ERR(err, msg) { \ 23 + if (err != Z_OK) { \ 24 + fprintf(stderr, "%s error: %d\n", msg, err); \ 25 + exit(1); \ 26 + } \ 27 +} 28 + 29 +const char hello[] = "hello, hello!"; 30 +/* "hello world" would be more standard, but the repeated "hello" 31 + * stresses the compression code better, sorry... 32 + */ 33 + 34 +const char dictionary[] = "hello"; 35 +uLong dictId; /* Adler32 value of the dictionary */ 36 + 37 +void test_deflate OF((Byte *compr, uLong comprLen)); 38 +void test_inflate OF((Byte *compr, uLong comprLen, 39 + Byte *uncompr, uLong uncomprLen)); 40 +void test_large_deflate OF((Byte *compr, uLong comprLen, 41 + Byte *uncompr, uLong uncomprLen)); 42 +void test_large_inflate OF((Byte *compr, uLong comprLen, 43 + Byte *uncompr, uLong uncomprLen)); 44 +void test_flush OF((Byte *compr, uLong *comprLen)); 45 +void test_sync OF((Byte *compr, uLong comprLen, 46 + Byte *uncompr, uLong uncomprLen)); 47 +void test_dict_deflate OF((Byte *compr, uLong comprLen)); 48 +void test_dict_inflate OF((Byte *compr, uLong comprLen, 49 + Byte *uncompr, uLong uncomprLen)); 50 +int main OF((int argc, char *argv[])); 51 + 52 + 53 +#ifdef Z_SOLO 54 + 55 +void *myalloc OF((void *, unsigned, unsigned)); 56 +void myfree OF((void *, void *)); 57 + 58 +void *myalloc(q, n, m) 59 + void *q; 60 + unsigned n, m; 61 +{ 62 + q = Z_NULL; 63 + return calloc(n, m); 64 +} 65 + 66 +void myfree(void *q, void *p) 67 +{ 68 + q = Z_NULL; 69 + free(p); 70 +} 71 + 72 +static alloc_func zalloc = myalloc; 73 +static free_func zfree = myfree; 74 + 75 +#else /* !Z_SOLO */ 76 + 77 +static alloc_func zalloc = (alloc_func)0; 78 +static free_func zfree = (free_func)0; 79 + 80 +void test_compress OF((Byte *compr, uLong comprLen, 81 + Byte *uncompr, uLong uncomprLen)); 82 +void test_gzio OF((const char *fname, 83 + Byte *uncompr, uLong uncomprLen)); 84 + 85 +/* =========================================================================== 86 + * Test compress() and uncompress() 87 + */ 88 +void test_compress(compr, comprLen, uncompr, uncomprLen) 89 + Byte *compr, *uncompr; 90 + uLong comprLen, uncomprLen; 91 +{ 92 + int err; 93 + uLong len = (uLong)strlen(hello)+1; 94 + 95 + err = compress(compr, &comprLen, (const Bytef*)hello, len); 96 + CHECK_ERR(err, "compress"); 97 + 98 + strcpy((char*)uncompr, "garbage"); 99 + 100 + err = uncompress(uncompr, &uncomprLen, compr, comprLen); 101 + CHECK_ERR(err, "uncompress"); 102 + 103 + if (strcmp((char*)uncompr, hello)) { 104 + fprintf(stderr, "bad uncompress\n"); 105 + exit(1); 106 + } else { 107 + printf("uncompress(): %s\n", (char *)uncompr); 108 + } 109 +} 110 + 111 +/* =========================================================================== 112 + * Test read/write of .gz files 113 + */ 114 +void test_gzio(fname, uncompr, uncomprLen) 115 + const char *fname; /* compressed file name */ 116 + Byte *uncompr; 117 + uLong uncomprLen; 118 +{ 119 +#ifdef NO_GZCOMPRESS 120 + fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); 121 +#else 122 + int err; 123 + int len = (int)strlen(hello)+1; 124 + gzFile file; 125 + z_off_t pos; 126 + 127 + file = gzopen(fname, "wb"); 128 + if (file == NULL) { 129 + fprintf(stderr, "gzopen error\n"); 130 + exit(1); 131 + } 132 + gzputc(file, 'h'); 133 + if (gzputs(file, "ello") != 4) { 134 + fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); 135 + exit(1); 136 + } 137 + if (gzprintf(file, ", %s!", "hello") != 8) { 138 + fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); 139 + exit(1); 140 + } 141 + gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ 142 + gzclose(file); 143 + 144 + file = gzopen(fname, "rb"); 145 + if (file == NULL) { 146 + fprintf(stderr, "gzopen error\n"); 147 + exit(1); 148 + } 149 + strcpy((char*)uncompr, "garbage"); 150 + 151 + if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { 152 + fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); 153 + exit(1); 154 + } 155 + if (strcmp((char*)uncompr, hello)) { 156 + fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); 157 + exit(1); 158 + } else { 159 + printf("gzread(): %s\n", (char*)uncompr); 160 + } 161 + 162 + pos = gzseek(file, -8L, SEEK_CUR); 163 + if (pos != 6 || gztell(file) != pos) { 164 + fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", 165 + (long)pos, (long)gztell(file)); 166 + exit(1); 167 + } 168 + 169 + if (gzgetc(file) != ' ') { 170 + fprintf(stderr, "gzgetc error\n"); 171 + exit(1); 172 + } 173 + 174 + if (gzungetc(' ', file) != ' ') { 175 + fprintf(stderr, "gzungetc error\n"); 176 + exit(1); 177 + } 178 + 179 + gzgets(file, (char*)uncompr, (int)uncomprLen); 180 + if (strlen((char*)uncompr) != 7) { /* " hello!" */ 181 + fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); 182 + exit(1); 183 + } 184 + if (strcmp((char*)uncompr, hello + 6)) { 185 + fprintf(stderr, "bad gzgets after gzseek\n"); 186 + exit(1); 187 + } else { 188 + printf("gzgets() after gzseek: %s\n", (char*)uncompr); 189 + } 190 + 191 + gzclose(file); 192 +#endif 193 +} 194 + 195 +#endif /* Z_SOLO */ 196 + 197 +/* =========================================================================== 198 + * Test deflate() with small buffers 199 + */ 200 +void test_deflate(compr, comprLen) 201 + Byte *compr; 202 + uLong comprLen; 203 +{ 204 + z_stream c_stream; /* compression stream */ 205 + int err; 206 + uLong len = (uLong)strlen(hello)+1; 207 + 208 + c_stream.zalloc = zalloc; 209 + c_stream.zfree = zfree; 210 + c_stream.opaque = (voidpf)0; 211 + 212 + err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 213 + CHECK_ERR(err, "deflateInit"); 214 + 215 + c_stream.next_in = (Bytef*)hello; 216 + c_stream.next_out = compr; 217 + 218 + while (c_stream.total_in != len && c_stream.total_out < comprLen) { 219 + c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ 220 + err = deflate(&c_stream, Z_NO_FLUSH); 221 + CHECK_ERR(err, "deflate"); 222 + } 223 + /* Finish the stream, still forcing small buffers: */ 224 + for (;;) { 225 + c_stream.avail_out = 1; 226 + err = deflate(&c_stream, Z_FINISH); 227 + if (err == Z_STREAM_END) break; 228 + CHECK_ERR(err, "deflate"); 229 + } 230 + 231 + err = deflateEnd(&c_stream); 232 + CHECK_ERR(err, "deflateEnd"); 233 +} 234 + 235 +/* =========================================================================== 236 + * Test inflate() with small buffers 237 + */ 238 +void test_inflate(compr, comprLen, uncompr, uncomprLen) 239 + Byte *compr, *uncompr; 240 + uLong comprLen, uncomprLen; 241 +{ 242 + int err; 243 + z_stream d_stream; /* decompression stream */ 244 + 245 + strcpy((char*)uncompr, "garbage"); 246 + 247 + d_stream.zalloc = zalloc; 248 + d_stream.zfree = zfree; 249 + d_stream.opaque = (voidpf)0; 250 + 251 + d_stream.next_in = compr; 252 + d_stream.avail_in = 0; 253 + d_stream.next_out = uncompr; 254 + 255 + err = inflateInit(&d_stream); 256 + CHECK_ERR(err, "inflateInit"); 257 + 258 + while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { 259 + d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ 260 + err = inflate(&d_stream, Z_NO_FLUSH); 261 + if (err == Z_STREAM_END) break; 262 + CHECK_ERR(err, "inflate"); 263 + } 264 + 265 + err = inflateEnd(&d_stream); 266 + CHECK_ERR(err, "inflateEnd"); 267 + 268 + if (strcmp((char*)uncompr, hello)) { 269 + fprintf(stderr, "bad inflate\n"); 270 + exit(1); 271 + } else { 272 + printf("inflate(): %s\n", (char *)uncompr); 273 + } 274 +} 275 + 276 +/* =========================================================================== 277 + * Test deflate() with large buffers and dynamic change of compression level 278 + */ 279 +void test_large_deflate(compr, comprLen, uncompr, uncomprLen) 280 + Byte *compr, *uncompr; 281 + uLong comprLen, uncomprLen; 282 +{ 283 + z_stream c_stream; /* compression stream */ 284 + int err; 285 + 286 + c_stream.zalloc = zalloc; 287 + c_stream.zfree = zfree; 288 + c_stream.opaque = (voidpf)0; 289 + 290 + err = deflateInit(&c_stream, Z_BEST_SPEED); 291 + CHECK_ERR(err, "deflateInit"); 292 + 293 + c_stream.next_out = compr; 294 + c_stream.avail_out = (uInt)comprLen; 295 + 296 + /* At this point, uncompr is still mostly zeroes, so it should compress 297 + * very well: 298 + */ 299 + c_stream.next_in = uncompr; 300 + c_stream.avail_in = (uInt)uncomprLen; 301 + err = deflate(&c_stream, Z_NO_FLUSH); 302 + CHECK_ERR(err, "deflate"); 303 + if (c_stream.avail_in != 0) { 304 + fprintf(stderr, "deflate not greedy\n"); 305 + exit(1); 306 + } 307 + 308 + /* Feed in already compressed data and switch to no compression: */ 309 + deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); 310 + c_stream.next_in = compr; 311 + c_stream.avail_in = (uInt)comprLen/2; 312 + err = deflate(&c_stream, Z_NO_FLUSH); 313 + CHECK_ERR(err, "deflate"); 314 + 315 + /* Switch back to compressing mode: */ 316 + deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED); 317 + c_stream.next_in = uncompr; 318 + c_stream.avail_in = (uInt)uncomprLen; 319 + err = deflate(&c_stream, Z_NO_FLUSH); 320 + CHECK_ERR(err, "deflate"); 321 + 322 + err = deflate(&c_stream, Z_FINISH); 323 + if (err != Z_STREAM_END) { 324 + fprintf(stderr, "deflate should report Z_STREAM_END\n"); 325 + exit(1); 326 + } 327 + err = deflateEnd(&c_stream); 328 + CHECK_ERR(err, "deflateEnd"); 329 +} 330 + 331 +/* =========================================================================== 332 + * Test inflate() with large buffers 333 + */ 334 +void test_large_inflate(compr, comprLen, uncompr, uncomprLen) 335 + Byte *compr, *uncompr; 336 + uLong comprLen, uncomprLen; 337 +{ 338 + int err; 339 + z_stream d_stream; /* decompression stream */ 340 + 341 + strcpy((char*)uncompr, "garbage"); 342 + 343 + d_stream.zalloc = zalloc; 344 + d_stream.zfree = zfree; 345 + d_stream.opaque = (voidpf)0; 346 + 347 + d_stream.next_in = compr; 348 + d_stream.avail_in = (uInt)comprLen; 349 + 350 + err = inflateInit(&d_stream); 351 + CHECK_ERR(err, "inflateInit"); 352 + 353 + for (;;) { 354 + d_stream.next_out = uncompr; /* discard the output */ 355 + d_stream.avail_out = (uInt)uncomprLen; 356 + err = inflate(&d_stream, Z_NO_FLUSH); 357 + if (err == Z_STREAM_END) break; 358 + CHECK_ERR(err, "large inflate"); 359 + } 360 + 361 + err = inflateEnd(&d_stream); 362 + CHECK_ERR(err, "inflateEnd"); 363 + 364 + if (d_stream.total_out != 2*uncomprLen + comprLen/2) { 365 + fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); 366 + exit(1); 367 + } else { 368 + printf("large_inflate(): OK\n"); 369 + } 370 +} 371 + 372 +/* =========================================================================== 373 + * Test deflate() with full flush 374 + */ 375 +void test_flush(compr, comprLen) 376 + Byte *compr; 377 + uLong *comprLen; 378 +{ 379 + z_stream c_stream; /* compression stream */ 380 + int err; 381 + uInt len = (uInt)strlen(hello)+1; 382 + 383 + c_stream.zalloc = zalloc; 384 + c_stream.zfree = zfree; 385 + c_stream.opaque = (voidpf)0; 386 + 387 + err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 388 + CHECK_ERR(err, "deflateInit"); 389 + 390 + c_stream.next_in = (Bytef*)hello; 391 + c_stream.next_out = compr; 392 + c_stream.avail_in = 3; 393 + c_stream.avail_out = (uInt)*comprLen; 394 + err = deflate(&c_stream, Z_FULL_FLUSH); 395 + CHECK_ERR(err, "deflate"); 396 + 397 + compr[3]++; /* force an error in first compressed block */ 398 + c_stream.avail_in = len - 3; 399 + 400 + err = deflate(&c_stream, Z_FINISH); 401 + if (err != Z_STREAM_END) { 402 + CHECK_ERR(err, "deflate"); 403 + } 404 + err = deflateEnd(&c_stream); 405 + CHECK_ERR(err, "deflateEnd"); 406 + 407 + *comprLen = c_stream.total_out; 408 +} 409 + 410 +/* =========================================================================== 411 + * Test inflateSync() 412 + */ 413 +void test_sync(compr, comprLen, uncompr, uncomprLen) 414 + Byte *compr, *uncompr; 415 + uLong comprLen, uncomprLen; 416 +{ 417 + int err; 418 + z_stream d_stream; /* decompression stream */ 419 + 420 + strcpy((char*)uncompr, "garbage"); 421 + 422 + d_stream.zalloc = zalloc; 423 + d_stream.zfree = zfree; 424 + d_stream.opaque = (voidpf)0; 425 + 426 + d_stream.next_in = compr; 427 + d_stream.avail_in = 2; /* just read the zlib header */ 428 + 429 + err = inflateInit(&d_stream); 430 + CHECK_ERR(err, "inflateInit"); 431 + 432 + d_stream.next_out = uncompr; 433 + d_stream.avail_out = (uInt)uncomprLen; 434 + 435 + inflate(&d_stream, Z_NO_FLUSH); 436 + CHECK_ERR(err, "inflate"); 437 + 438 + d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ 439 + err = inflateSync(&d_stream); /* but skip the damaged part */ 440 + CHECK_ERR(err, "inflateSync"); 441 + 442 + err = inflate(&d_stream, Z_FINISH); 443 + if (err != Z_DATA_ERROR) { 444 + fprintf(stderr, "inflate should report DATA_ERROR\n"); 445 + /* Because of incorrect adler32 */ 446 + exit(1); 447 + } 448 + err = inflateEnd(&d_stream); 449 + CHECK_ERR(err, "inflateEnd"); 450 + 451 + printf("after inflateSync(): hel%s\n", (char *)uncompr); 452 +} 453 + 454 +/* =========================================================================== 455 + * Test deflate() with preset dictionary 456 + */ 457 +void test_dict_deflate(compr, comprLen) 458 + Byte *compr; 459 + uLong comprLen; 460 +{ 461 + z_stream c_stream; /* compression stream */ 462 + int err; 463 + 464 + c_stream.zalloc = zalloc; 465 + c_stream.zfree = zfree; 466 + c_stream.opaque = (voidpf)0; 467 + 468 + err = deflateInit(&c_stream, Z_BEST_COMPRESSION); 469 + CHECK_ERR(err, "deflateInit"); 470 + 471 + err = deflateSetDictionary(&c_stream, 472 + (const Bytef*)dictionary, (int)sizeof(dictionary)); 473 + CHECK_ERR(err, "deflateSetDictionary"); 474 + 475 + dictId = c_stream.adler; 476 + c_stream.next_out = compr; 477 + c_stream.avail_out = (uInt)comprLen; 478 + 479 + c_stream.next_in = (Bytef*)hello; 480 + c_stream.avail_in = (uInt)strlen(hello)+1; 481 + 482 + err = deflate(&c_stream, Z_FINISH); 483 + if (err != Z_STREAM_END) { 484 + fprintf(stderr, "deflate should report Z_STREAM_END\n"); 485 + exit(1); 486 + } 487 + err = deflateEnd(&c_stream); 488 + CHECK_ERR(err, "deflateEnd"); 489 +} 490 + 491 +/* =========================================================================== 492 + * Test inflate() with a preset dictionary 493 + */ 494 +void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) 495 + Byte *compr, *uncompr; 496 + uLong comprLen, uncomprLen; 497 +{ 498 + int err; 499 + z_stream d_stream; /* decompression stream */ 500 + 501 + strcpy((char*)uncompr, "garbage"); 502 + 503 + d_stream.zalloc = zalloc; 504 + d_stream.zfree = zfree; 505 + d_stream.opaque = (voidpf)0; 506 + 507 + d_stream.next_in = compr; 508 + d_stream.avail_in = (uInt)comprLen; 509 + 510 + err = inflateInit(&d_stream); 511 + CHECK_ERR(err, "inflateInit"); 512 + 513 + d_stream.next_out = uncompr; 514 + d_stream.avail_out = (uInt)uncomprLen; 515 + 516 + for (;;) { 517 + err = inflate(&d_stream, Z_NO_FLUSH); 518 + if (err == Z_STREAM_END) break; 519 + if (err == Z_NEED_DICT) { 520 + if (d_stream.adler != dictId) { 521 + fprintf(stderr, "unexpected dictionary"); 522 + exit(1); 523 + } 524 + err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, 525 + (int)sizeof(dictionary)); 526 + } 527 + CHECK_ERR(err, "inflate with dict"); 528 + } 529 + 530 + err = inflateEnd(&d_stream); 531 + CHECK_ERR(err, "inflateEnd"); 532 + 533 + if (strcmp((char*)uncompr, hello)) { 534 + fprintf(stderr, "bad inflate with dict\n"); 535 + exit(1); 536 + } else { 537 + printf("inflate with dictionary: %s\n", (char *)uncompr); 538 + } 539 +} 540 + 541 +/* =========================================================================== 542 + * Usage: example [output.gz [input.gz]] 543 + */ 544 + 545 +int main(argc, argv) 546 + int argc; 547 + char *argv[]; 548 +{ 549 + Byte *compr, *uncompr; 550 + uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ 551 + uLong uncomprLen = comprLen; 552 + static const char* myVersion = ZLIB_VERSION; 553 + 554 + if (zlibVersion()[0] != myVersion[0]) { 555 + fprintf(stderr, "incompatible zlib version\n"); 556 + exit(1); 557 + 558 + } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { 559 + fprintf(stderr, "warning: different zlib version\n"); 560 + } 561 + 562 + printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n", 563 + ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags()); 564 + 565 + compr = (Byte*)calloc((uInt)comprLen, 1); 566 + uncompr = (Byte*)calloc((uInt)uncomprLen, 1); 567 + /* compr and uncompr are cleared to avoid reading uninitialized 568 + * data and to ensure that uncompr compresses well. 569 + */ 570 + if (compr == Z_NULL || uncompr == Z_NULL) { 571 + printf("out of memory\n"); 572 + exit(1); 573 + } 574 + 575 +#ifdef Z_SOLO 576 + argc = strlen(argv[0]); 577 +#else 578 + test_compress(compr, comprLen, uncompr, uncomprLen); 579 + 580 + test_gzio((argc > 1 ? argv[1] : TESTFILE), 581 + uncompr, uncomprLen); 582 +#endif 583 + 584 + test_deflate(compr, comprLen); 585 + test_inflate(compr, comprLen, uncompr, uncomprLen); 586 + 587 + test_large_deflate(compr, comprLen, uncompr, uncomprLen); 588 + test_large_inflate(compr, comprLen, uncompr, uncomprLen); 589 + 590 + test_flush(compr, &comprLen); 591 + test_sync(compr, comprLen, uncompr, uncomprLen); 592 + comprLen = uncomprLen; 593 + 594 + test_dict_deflate(compr, comprLen); 595 + test_dict_inflate(compr, comprLen, uncompr, uncomprLen); 596 + 597 + free(compr); 598 + free(uncompr); 599 + 600 + return 0; 601 +}
Added compat/zlib/test/infcover.c.
1 +/* infcover.c -- test zlib's inflate routines with full code coverage 2 + * Copyright (C) 2011 Mark Adler 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* to use, do: ./configure --cover && make cover */ 7 + 8 +#include <stdio.h> 9 +#include <stdlib.h> 10 +#include <string.h> 11 +#include <assert.h> 12 +#include "zlib.h" 13 + 14 +/* get definition of internal structure so we can mess with it (see pull()), 15 + and so we can call inflate_trees() (see cover5()) */ 16 +#define ZLIB_INTERNAL 17 +#include "inftrees.h" 18 +#include "inflate.h" 19 + 20 +#define local static 21 + 22 +/* -- memory tracking routines -- */ 23 + 24 +/* 25 + These memory tracking routines are provided to zlib and track all of zlib's 26 + allocations and deallocations, check for LIFO operations, keep a current 27 + and high water mark of total bytes requested, optionally set a limit on the 28 + total memory that can be allocated, and when done check for memory leaks. 29 + 30 + They are used as follows: 31 + 32 + z_stream strm; 33 + mem_setup(&strm) initializes the memory tracking and sets the 34 + zalloc, zfree, and opaque members of strm to use 35 + memory tracking for all zlib operations on strm 36 + mem_limit(&strm, limit) sets a limit on the total bytes requested -- a 37 + request that exceeds this limit will result in an 38 + allocation failure (returns NULL) -- setting the 39 + limit to zero means no limit, which is the default 40 + after mem_setup() 41 + mem_used(&strm, "msg") prints to stderr "msg" and the total bytes used 42 + mem_high(&strm, "msg") prints to stderr "msg" and the high water mark 43 + mem_done(&strm, "msg") ends memory tracking, releases all allocations 44 + for the tracking as well as leaked zlib blocks, if 45 + any. If there was anything unusual, such as leaked 46 + blocks, non-FIFO frees, or frees of addresses not 47 + allocated, then "msg" and information about the 48 + problem is printed to stderr. If everything is 49 + normal, nothing is printed. mem_done resets the 50 + strm members to Z_NULL to use the default memory 51 + allocation routines on the next zlib initialization 52 + using strm. 53 + */ 54 + 55 +/* these items are strung together in a linked list, one for each allocation */ 56 +struct mem_item { 57 + void *ptr; /* pointer to allocated memory */ 58 + size_t size; /* requested size of allocation */ 59 + struct mem_item *next; /* pointer to next item in list, or NULL */ 60 +}; 61 + 62 +/* this structure is at the root of the linked list, and tracks statistics */ 63 +struct mem_zone { 64 + struct mem_item *first; /* pointer to first item in list, or NULL */ 65 + size_t total, highwater; /* total allocations, and largest total */ 66 + size_t limit; /* memory allocation limit, or 0 if no limit */ 67 + int notlifo, rogue; /* counts of non-LIFO frees and rogue frees */ 68 +}; 69 + 70 +/* memory allocation routine to pass to zlib */ 71 +local void *mem_alloc(void *mem, unsigned count, unsigned size) 72 +{ 73 + void *ptr; 74 + struct mem_item *item; 75 + struct mem_zone *zone = mem; 76 + size_t len = count * (size_t)size; 77 + 78 + /* induced allocation failure */ 79 + if (zone == NULL || (zone->limit && zone->total + len > zone->limit)) 80 + return NULL; 81 + 82 + /* perform allocation using the standard library, fill memory with a 83 + non-zero value to make sure that the code isn't depending on zeros */ 84 + ptr = malloc(len); 85 + if (ptr == NULL) 86 + return NULL; 87 + memset(ptr, 0xa5, len); 88 + 89 + /* create a new item for the list */ 90 + item = malloc(sizeof(struct mem_item)); 91 + if (item == NULL) { 92 + free(ptr); 93 + return NULL; 94 + } 95 + item->ptr = ptr; 96 + item->size = len; 97 + 98 + /* insert item at the beginning of the list */ 99 + item->next = zone->first; 100 + zone->first = item; 101 + 102 + /* update the statistics */ 103 + zone->total += item->size; 104 + if (zone->total > zone->highwater) 105 + zone->highwater = zone->total; 106 + 107 + /* return the allocated memory */ 108 + return ptr; 109 +} 110 + 111 +/* memory free routine to pass to zlib */ 112 +local void mem_free(void *mem, void *ptr) 113 +{ 114 + struct mem_item *item, *next; 115 + struct mem_zone *zone = mem; 116 + 117 + /* if no zone, just do a free */ 118 + if (zone == NULL) { 119 + free(ptr); 120 + return; 121 + } 122 + 123 + /* point next to the item that matches ptr, or NULL if not found -- remove 124 + the item from the linked list if found */ 125 + next = zone->first; 126 + if (next) { 127 + if (next->ptr == ptr) 128 + zone->first = next->next; /* first one is it, remove from list */ 129 + else { 130 + do { /* search the linked list */ 131 + item = next; 132 + next = item->next; 133 + } while (next != NULL && next->ptr != ptr); 134 + if (next) { /* if found, remove from linked list */ 135 + item->next = next->next; 136 + zone->notlifo++; /* not a LIFO free */ 137 + } 138 + 139 + } 140 + } 141 + 142 + /* if found, update the statistics and free the item */ 143 + if (next) { 144 + zone->total -= next->size; 145 + free(next); 146 + } 147 + 148 + /* if not found, update the rogue count */ 149 + else 150 + zone->rogue++; 151 + 152 + /* in any case, do the requested free with the standard library function */ 153 + free(ptr); 154 +} 155 + 156 +/* set up a controlled memory allocation space for monitoring, set the stream 157 + parameters to the controlled routines, with opaque pointing to the space */ 158 +local void mem_setup(z_stream *strm) 159 +{ 160 + struct mem_zone *zone; 161 + 162 + zone = malloc(sizeof(struct mem_zone)); 163 + assert(zone != NULL); 164 + zone->first = NULL; 165 + zone->total = 0; 166 + zone->highwater = 0; 167 + zone->limit = 0; 168 + zone->notlifo = 0; 169 + zone->rogue = 0; 170 + strm->opaque = zone; 171 + strm->zalloc = mem_alloc; 172 + strm->zfree = mem_free; 173 +} 174 + 175 +/* set a limit on the total memory allocation, or 0 to remove the limit */ 176 +local void mem_limit(z_stream *strm, size_t limit) 177 +{ 178 + struct mem_zone *zone = strm->opaque; 179 + 180 + zone->limit = limit; 181 +} 182 + 183 +/* show the current total requested allocations in bytes */ 184 +local void mem_used(z_stream *strm, char *prefix) 185 +{ 186 + struct mem_zone *zone = strm->opaque; 187 + 188 + fprintf(stderr, "%s: %lu allocated\n", prefix, zone->total); 189 +} 190 + 191 +/* show the high water allocation in bytes */ 192 +local void mem_high(z_stream *strm, char *prefix) 193 +{ 194 + struct mem_zone *zone = strm->opaque; 195 + 196 + fprintf(stderr, "%s: %lu high water mark\n", prefix, zone->highwater); 197 +} 198 + 199 +/* release the memory allocation zone -- if there are any surprises, notify */ 200 +local void mem_done(z_stream *strm, char *prefix) 201 +{ 202 + int count = 0; 203 + struct mem_item *item, *next; 204 + struct mem_zone *zone = strm->opaque; 205 + 206 + /* show high water mark */ 207 + mem_high(strm, prefix); 208 + 209 + /* free leftover allocations and item structures, if any */ 210 + item = zone->first; 211 + while (item != NULL) { 212 + free(item->ptr); 213 + next = item->next; 214 + free(item); 215 + item = next; 216 + count++; 217 + } 218 + 219 + /* issue alerts about anything unexpected */ 220 + if (count || zone->total) 221 + fprintf(stderr, "** %s: %lu bytes in %d blocks not freed\n", 222 + prefix, zone->total, count); 223 + if (zone->notlifo) 224 + fprintf(stderr, "** %s: %d frees not LIFO\n", prefix, zone->notlifo); 225 + if (zone->rogue) 226 + fprintf(stderr, "** %s: %d frees not recognized\n", 227 + prefix, zone->rogue); 228 + 229 + /* free the zone and delete from the stream */ 230 + free(zone); 231 + strm->opaque = Z_NULL; 232 + strm->zalloc = Z_NULL; 233 + strm->zfree = Z_NULL; 234 +} 235 + 236 +/* -- inflate test routines -- */ 237 + 238 +/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This 239 + decodes liberally, in that hex digits can be adjacent, in which case two in 240 + a row writes a byte. Or they can delimited by any non-hex character, where 241 + the delimiters are ignored except when a single hex digit is followed by a 242 + delimiter in which case that single digit writes a byte. The returned 243 + data is allocated and must eventually be freed. NULL is returned if out of 244 + memory. If the length is not needed, then len can be NULL. */ 245 +local unsigned char *h2b(const char *hex, unsigned *len) 246 +{ 247 + unsigned char *in; 248 + unsigned next, val; 249 + 250 + in = malloc((strlen(hex) + 1) >> 1); 251 + if (in == NULL) 252 + return NULL; 253 + next = 0; 254 + val = 1; 255 + do { 256 + if (*hex >= '0' && *hex <= '9') 257 + val = (val << 4) + *hex - '0'; 258 + else if (*hex >= 'A' && *hex <= 'F') 259 + val = (val << 4) + *hex - 'A' + 10; 260 + else if (*hex >= 'a' && *hex <= 'f') 261 + val = (val << 4) + *hex - 'a' + 10; 262 + else if (val != 1 && val < 32) /* one digit followed by delimiter */ 263 + val += 240; /* make it look like two digits */ 264 + if (val > 255) { /* have two digits */ 265 + in[next++] = val & 0xff; /* save the decoded byte */ 266 + val = 1; /* start over */ 267 + } 268 + } while (*hex++); /* go through the loop with the terminating null */ 269 + if (len != NULL) 270 + *len = next; 271 + in = reallocf(in, next); 272 + return in; 273 +} 274 + 275 +/* generic inflate() run, where hex is the hexadecimal input data, what is the 276 + text to include in an error message, step is how much input data to feed 277 + inflate() on each call, or zero to feed it all, win is the window bits 278 + parameter to inflateInit2(), len is the size of the output buffer, and err 279 + is the error code expected from the first inflate() call (the second 280 + inflate() call is expected to return Z_STREAM_END). If win is 47, then 281 + header information is collected with inflateGetHeader(). If a zlib stream 282 + is looking for a dictionary, then an empty dictionary is provided. 283 + inflate() is run until all of the input data is consumed. */ 284 +local void inf(char *hex, char *what, unsigned step, int win, unsigned len, 285 + int err) 286 +{ 287 + int ret; 288 + unsigned have; 289 + unsigned char *in, *out; 290 + z_stream strm, copy; 291 + gz_header head; 292 + 293 + mem_setup(&strm); 294 + strm.avail_in = 0; 295 + strm.next_in = Z_NULL; 296 + ret = inflateInit2(&strm, win); 297 + if (ret != Z_OK) { 298 + mem_done(&strm, what); 299 + return; 300 + } 301 + out = malloc(len); assert(out != NULL); 302 + if (win == 47) { 303 + head.extra = out; 304 + head.extra_max = len; 305 + head.name = out; 306 + head.name_max = len; 307 + head.comment = out; 308 + head.comm_max = len; 309 + ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK); 310 + } 311 + in = h2b(hex, &have); assert(in != NULL); 312 + if (step == 0 || step > have) 313 + step = have; 314 + strm.avail_in = step; 315 + have -= step; 316 + strm.next_in = in; 317 + do { 318 + strm.avail_out = len; 319 + strm.next_out = out; 320 + ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err); 321 + if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT) 322 + break; 323 + if (ret == Z_NEED_DICT) { 324 + ret = inflateSetDictionary(&strm, in, 1); 325 + assert(ret == Z_DATA_ERROR); 326 + mem_limit(&strm, 1); 327 + ret = inflateSetDictionary(&strm, out, 0); 328 + assert(ret == Z_MEM_ERROR); 329 + mem_limit(&strm, 0); 330 + ((struct inflate_state *)strm.state)->mode = DICT; 331 + ret = inflateSetDictionary(&strm, out, 0); 332 + assert(ret == Z_OK); 333 + ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR); 334 + } 335 + ret = inflateCopy(©, &strm); assert(ret == Z_OK); 336 + ret = inflateEnd(©); assert(ret == Z_OK); 337 + err = 9; /* don't care next time around */ 338 + have += strm.avail_in; 339 + strm.avail_in = step > have ? have : step; 340 + have -= strm.avail_in; 341 + } while (strm.avail_in); 342 + free(in); 343 + free(out); 344 + ret = inflateReset2(&strm, -8); assert(ret == Z_OK); 345 + ret = inflateEnd(&strm); assert(ret == Z_OK); 346 + mem_done(&strm, what); 347 +} 348 + 349 +/* cover all of the lines in inflate.c up to inflate() */ 350 +local void cover_support(void) 351 +{ 352 + int ret; 353 + z_stream strm; 354 + 355 + mem_setup(&strm); 356 + strm.avail_in = 0; 357 + strm.next_in = Z_NULL; 358 + ret = inflateInit(&strm); assert(ret == Z_OK); 359 + mem_used(&strm, "inflate init"); 360 + ret = inflatePrime(&strm, 5, 31); assert(ret == Z_OK); 361 + ret = inflatePrime(&strm, -1, 0); assert(ret == Z_OK); 362 + ret = inflateSetDictionary(&strm, Z_NULL, 0); 363 + assert(ret == Z_STREAM_ERROR); 364 + ret = inflateEnd(&strm); assert(ret == Z_OK); 365 + mem_done(&strm, "prime"); 366 + 367 + inf("63 0", "force window allocation", 0, -15, 1, Z_OK); 368 + inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK); 369 + inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK); 370 + inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END); 371 + inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR); 372 + 373 + mem_setup(&strm); 374 + strm.avail_in = 0; 375 + strm.next_in = Z_NULL; 376 + ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream)); 377 + assert(ret == Z_VERSION_ERROR); 378 + mem_done(&strm, "wrong version"); 379 + 380 + strm.avail_in = 0; 381 + strm.next_in = Z_NULL; 382 + ret = inflateInit(&strm); assert(ret == Z_OK); 383 + ret = inflateEnd(&strm); assert(ret == Z_OK); 384 + fputs("inflate built-in memory routines\n", stderr); 385 +} 386 + 387 +/* cover all inflate() header and trailer cases and code after inflate() */ 388 +local void cover_wrap(void) 389 +{ 390 + int ret; 391 + z_stream strm, copy; 392 + unsigned char dict[257]; 393 + 394 + ret = inflate(Z_NULL, 0); assert(ret == Z_STREAM_ERROR); 395 + ret = inflateEnd(Z_NULL); assert(ret == Z_STREAM_ERROR); 396 + ret = inflateCopy(Z_NULL, Z_NULL); assert(ret == Z_STREAM_ERROR); 397 + fputs("inflate bad parameters\n", stderr); 398 + 399 + inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR); 400 + inf("1f 8b 8 80", "bad gzip flags", 0, 31, 0, Z_DATA_ERROR); 401 + inf("77 85", "bad zlib method", 0, 15, 0, Z_DATA_ERROR); 402 + inf("8 99", "set window size from header", 0, 0, 0, Z_OK); 403 + inf("78 9c", "bad zlib window size", 0, 8, 0, Z_DATA_ERROR); 404 + inf("78 9c 63 0 0 0 1 0 1", "check adler32", 0, 15, 1, Z_STREAM_END); 405 + inf("1f 8b 8 1e 0 0 0 0 0 0 1 0 0 0 0 0 0", "bad header crc", 0, 47, 1, 406 + Z_DATA_ERROR); 407 + inf("1f 8b 8 2 0 0 0 0 0 0 1d 26 3 0 0 0 0 0 0 0 0 0", "check gzip length", 408 + 0, 47, 0, Z_STREAM_END); 409 + inf("78 90", "bad zlib header check", 0, 47, 0, Z_DATA_ERROR); 410 + inf("8 b8 0 0 0 1", "need dictionary", 0, 8, 0, Z_NEED_DICT); 411 + inf("78 9c 63 0", "compute adler32", 0, 15, 1, Z_OK); 412 + 413 + mem_setup(&strm); 414 + strm.avail_in = 0; 415 + strm.next_in = Z_NULL; 416 + ret = inflateInit2(&strm, -8); 417 + strm.avail_in = 2; 418 + strm.next_in = (void *)"\x63"; 419 + strm.avail_out = 1; 420 + strm.next_out = (void *)&ret; 421 + mem_limit(&strm, 1); 422 + ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); 423 + ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); 424 + mem_limit(&strm, 0); 425 + memset(dict, 0, 257); 426 + ret = inflateSetDictionary(&strm, dict, 257); 427 + assert(ret == Z_OK); 428 + mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256); 429 + ret = inflatePrime(&strm, 16, 0); assert(ret == Z_OK); 430 + strm.avail_in = 2; 431 + strm.next_in = (void *)"\x80"; 432 + ret = inflateSync(&strm); assert(ret == Z_DATA_ERROR); 433 + ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR); 434 + strm.avail_in = 4; 435 + strm.next_in = (void *)"\0\0\xff\xff"; 436 + ret = inflateSync(&strm); assert(ret == Z_OK); 437 + (void)inflateSyncPoint(&strm); 438 + ret = inflateCopy(©, &strm); assert(ret == Z_MEM_ERROR); 439 + mem_limit(&strm, 0); 440 + ret = inflateUndermine(&strm, 1); assert(ret == Z_DATA_ERROR); 441 + (void)inflateMark(&strm); 442 + ret = inflateEnd(&strm); assert(ret == Z_OK); 443 + mem_done(&strm, "miscellaneous, force memory errors"); 444 +} 445 + 446 +/* input and output functions for inflateBack() */ 447 +local unsigned pull(void *desc, unsigned char **buf) 448 +{ 449 + static unsigned int next = 0; 450 + static unsigned char dat[] = {0x63, 0, 2, 0}; 451 + struct inflate_state *state; 452 + 453 + if (desc == Z_NULL) { 454 + next = 0; 455 + return 0; /* no input (already provided at next_in) */ 456 + } 457 + state = (void *)((z_stream *)desc)->state; 458 + if (state != Z_NULL) 459 + state->mode = SYNC; /* force an otherwise impossible situation */ 460 + return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0; 461 +} 462 + 463 +local int push(void *desc, unsigned char *buf, unsigned len) 464 +{ 465 + buf += len; 466 + return desc != Z_NULL; /* force error if desc not null */ 467 +} 468 + 469 +/* cover inflateBack() up to common deflate data cases and after those */ 470 +local void cover_back(void) 471 +{ 472 + int ret; 473 + z_stream strm; 474 + unsigned char win[32768]; 475 + 476 + ret = inflateBackInit_(Z_NULL, 0, win, 0, 0); 477 + assert(ret == Z_VERSION_ERROR); 478 + ret = inflateBackInit(Z_NULL, 0, win); assert(ret == Z_STREAM_ERROR); 479 + ret = inflateBack(Z_NULL, Z_NULL, Z_NULL, Z_NULL, Z_NULL); 480 + assert(ret == Z_STREAM_ERROR); 481 + ret = inflateBackEnd(Z_NULL); assert(ret == Z_STREAM_ERROR); 482 + fputs("inflateBack bad parameters\n", stderr); 483 + 484 + mem_setup(&strm); 485 + ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); 486 + strm.avail_in = 2; 487 + strm.next_in = (void *)"\x03"; 488 + ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL); 489 + assert(ret == Z_STREAM_END); 490 + /* force output error */ 491 + strm.avail_in = 3; 492 + strm.next_in = (void *)"\x63\x00"; 493 + ret = inflateBack(&strm, pull, Z_NULL, push, &strm); 494 + assert(ret == Z_BUF_ERROR); 495 + /* force mode error by mucking with state */ 496 + ret = inflateBack(&strm, pull, &strm, push, Z_NULL); 497 + assert(ret == Z_STREAM_ERROR); 498 + ret = inflateBackEnd(&strm); assert(ret == Z_OK); 499 + mem_done(&strm, "inflateBack bad state"); 500 + 501 + ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); 502 + ret = inflateBackEnd(&strm); assert(ret == Z_OK); 503 + fputs("inflateBack built-in memory routines\n", stderr); 504 +} 505 + 506 +/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */ 507 +local int try(char *hex, char *id, int err) 508 +{ 509 + int ret; 510 + unsigned len, size; 511 + unsigned char *in, *out, *win; 512 + char *prefix; 513 + z_stream strm; 514 + 515 + /* convert to hex */ 516 + in = h2b(hex, &len); 517 + assert(in != NULL); 518 + 519 + /* allocate work areas */ 520 + size = len << 3; 521 + out = malloc(size); 522 + assert(out != NULL); 523 + win = malloc(32768); 524 + assert(win != NULL); 525 + prefix = malloc(strlen(id) + 6); 526 + assert(prefix != NULL); 527 + 528 + /* first with inflate */ 529 + strcpy(prefix, id); 530 + strcat(prefix, "-late"); 531 + mem_setup(&strm); 532 + strm.avail_in = 0; 533 + strm.next_in = Z_NULL; 534 + ret = inflateInit2(&strm, err < 0 ? 47 : -15); 535 + assert(ret == Z_OK); 536 + strm.avail_in = len; 537 + strm.next_in = in; 538 + do { 539 + strm.avail_out = size; 540 + strm.next_out = out; 541 + ret = inflate(&strm, Z_TREES); 542 + assert(ret != Z_STREAM_ERROR && ret != Z_MEM_ERROR); 543 + if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT) 544 + break; 545 + } while (strm.avail_in || strm.avail_out == 0); 546 + if (err) { 547 + assert(ret == Z_DATA_ERROR); 548 + assert(strcmp(id, strm.msg) == 0); 549 + } 550 + inflateEnd(&strm); 551 + mem_done(&strm, prefix); 552 + 553 + /* then with inflateBack */ 554 + if (err >= 0) { 555 + strcpy(prefix, id); 556 + strcat(prefix, "-back"); 557 + mem_setup(&strm); 558 + ret = inflateBackInit(&strm, 15, win); 559 + assert(ret == Z_OK); 560 + strm.avail_in = len; 561 + strm.next_in = in; 562 + ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL); 563 + assert(ret != Z_STREAM_ERROR); 564 + if (err) { 565 + assert(ret == Z_DATA_ERROR); 566 + assert(strcmp(id, strm.msg) == 0); 567 + } 568 + inflateBackEnd(&strm); 569 + mem_done(&strm, prefix); 570 + } 571 + 572 + /* clean up */ 573 + free(prefix); 574 + free(win); 575 + free(out); 576 + free(in); 577 + return ret; 578 +} 579 + 580 +/* cover deflate data cases in both inflate() and inflateBack() */ 581 +local void cover_inflate(void) 582 +{ 583 + try("0 0 0 0 0", "invalid stored block lengths", 1); 584 + try("3 0", "fixed", 0); 585 + try("6", "invalid block type", 1); 586 + try("1 1 0 fe ff 0", "stored", 0); 587 + try("fc 0 0", "too many length or distance symbols", 1); 588 + try("4 0 fe ff", "invalid code lengths set", 1); 589 + try("4 0 24 49 0", "invalid bit length repeat", 1); 590 + try("4 0 24 e9 ff ff", "invalid bit length repeat", 1); 591 + try("4 0 24 e9 ff 6d", "invalid code -- missing end-of-block", 1); 592 + try("4 80 49 92 24 49 92 24 71 ff ff 93 11 0", 593 + "invalid literal/lengths set", 1); 594 + try("4 80 49 92 24 49 92 24 f b4 ff ff c3 84", "invalid distances set", 1); 595 + try("4 c0 81 8 0 0 0 0 20 7f eb b 0 0", "invalid literal/length code", 1); 596 + try("2 7e ff ff", "invalid distance code", 1); 597 + try("c c0 81 0 0 0 0 0 90 ff 6b 4 0", "invalid distance too far back", 1); 598 + 599 + /* also trailer mismatch just in inflate() */ 600 + try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 1", "incorrect data check", -1); 601 + try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 1", 602 + "incorrect length check", -1); 603 + try("5 c0 21 d 0 0 0 80 b0 fe 6d 2f 91 6c", "pull 17", 0); 604 + try("5 e0 81 91 24 cb b2 2c 49 e2 f 2e 8b 9a 47 56 9f fb fe ec d2 ff 1f", 605 + "long code", 0); 606 + try("ed c0 1 1 0 0 0 40 20 ff 57 1b 42 2c 4f", "length extra", 0); 607 + try("ed cf c1 b1 2c 47 10 c4 30 fa 6f 35 1d 1 82 59 3d fb be 2e 2a fc f c", 608 + "long distance and extra", 0); 609 + try("ed c0 81 0 0 0 0 80 a0 fd a9 17 a9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " 610 + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6", "window end", 0); 611 + inf("2 8 20 80 0 3 0", "inflate_fast TYPE return", 0, -15, 258, 612 + Z_STREAM_END); 613 + inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK); 614 +} 615 + 616 +/* cover remaining lines in inftrees.c */ 617 +local void cover_trees(void) 618 +{ 619 + int ret; 620 + unsigned bits; 621 + unsigned short lens[16], work[16]; 622 + code *next, table[ENOUGH_DISTS]; 623 + 624 + /* we need to call inflate_table() directly in order to manifest not- 625 + enough errors, since zlib insures that enough is always enough */ 626 + for (bits = 0; bits < 15; bits++) 627 + lens[bits] = (unsigned short)(bits + 1); 628 + lens[15] = 15; 629 + next = table; 630 + bits = 15; 631 + ret = inflate_table(DISTS, lens, 16, &next, &bits, work); 632 + assert(ret == 1); 633 + next = table; 634 + bits = 1; 635 + ret = inflate_table(DISTS, lens, 16, &next, &bits, work); 636 + assert(ret == 1); 637 + fputs("inflate_table not enough errors\n", stderr); 638 +} 639 + 640 +/* cover remaining inffast.c decoding and window copying */ 641 +local void cover_fast(void) 642 +{ 643 + inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68" 644 + " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR); 645 + inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49" 646 + " 50 fe ff ff 3f 0 0", "fast distance extra bits", 0, -8, 258, 647 + Z_DATA_ERROR); 648 + inf("3 7e 0 0 0 0 0", "fast invalid distance code", 0, -8, 258, 649 + Z_DATA_ERROR); 650 + inf("1b 7 0 0 0 0 0", "fast invalid literal/length code", 0, -8, 258, 651 + Z_DATA_ERROR); 652 + inf("d c7 1 ae eb 38 c 4 41 a0 87 72 de df fb 1f b8 36 b1 38 5d ff ff 0", 653 + "fast 2nd level codes and too far back", 0, -8, 258, Z_DATA_ERROR); 654 + inf("63 18 5 8c 10 8 0 0 0 0", "very common case", 0, -8, 259, Z_OK); 655 + inf("63 60 60 18 c9 0 8 18 18 18 26 c0 28 0 29 0 0 0", 656 + "contiguous and wrap around window", 6, -8, 259, Z_OK); 657 + inf("63 0 3 0 0 0 0 0", "copy direct from output", 0, -8, 259, 658 + Z_STREAM_END); 659 +} 660 + 661 +int main(void) 662 +{ 663 + fprintf(stderr, "%s\n", zlibVersion()); 664 + cover_support(); 665 + cover_wrap(); 666 + cover_back(); 667 + cover_inflate(); 668 + cover_trees(); 669 + cover_fast(); 670 + return 0; 671 +}
Added compat/zlib/test/minigzip.c.
1 +/* minigzip.c -- simulate gzip using the zlib compression library 2 + * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* 7 + * minigzip is a minimal implementation of the gzip utility. This is 8 + * only an example of using zlib and isn't meant to replace the 9 + * full-featured gzip. No attempt is made to deal with file systems 10 + * limiting names to 14 or 8+3 characters, etc... Error checking is 11 + * very limited. So use minigzip only for testing; use gzip for the 12 + * real thing. On MSDOS, use only on file names without extension 13 + * or in pipe mode. 14 + */ 15 + 16 +/* @(#) $Id$ */ 17 + 18 +#include "zlib.h" 19 +#include <stdio.h> 20 + 21 +#ifdef STDC 22 +# include <string.h> 23 +# include <stdlib.h> 24 +#endif 25 + 26 +#ifdef USE_MMAP 27 +# include <sys/types.h> 28 +# include <sys/mman.h> 29 +# include <sys/stat.h> 30 +#endif 31 + 32 +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 33 +# include <fcntl.h> 34 +# include <io.h> 35 +# ifdef UNDER_CE 36 +# include <stdlib.h> 37 +# endif 38 +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 39 +#else 40 +# define SET_BINARY_MODE(file) 41 +#endif 42 + 43 +#ifdef VMS 44 +# define unlink delete 45 +# define GZ_SUFFIX "-gz" 46 +#endif 47 +#ifdef RISCOS 48 +# define unlink remove 49 +# define GZ_SUFFIX "-gz" 50 +# define fileno(file) file->__file 51 +#endif 52 +#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 53 +# include <unix.h> /* for fileno */ 54 +#endif 55 + 56 +#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) 57 +#ifndef WIN32 /* unlink already in stdio.h for WIN32 */ 58 + extern int unlink OF((const char *)); 59 +#endif 60 +#endif 61 + 62 +#if defined(UNDER_CE) 63 +# include <windows.h> 64 +# define perror(s) pwinerror(s) 65 + 66 +/* Map the Windows error number in ERROR to a locale-dependent error 67 + message string and return a pointer to it. Typically, the values 68 + for ERROR come from GetLastError. 69 + 70 + The string pointed to shall not be modified by the application, 71 + but may be overwritten by a subsequent call to strwinerror 72 + 73 + The strwinerror function does not change the current setting 74 + of GetLastError. */ 75 + 76 +static char *strwinerror (error) 77 + DWORD error; 78 +{ 79 + static char buf[1024]; 80 + 81 + wchar_t *msgbuf; 82 + DWORD lasterr = GetLastError(); 83 + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 84 + | FORMAT_MESSAGE_ALLOCATE_BUFFER, 85 + NULL, 86 + error, 87 + 0, /* Default language */ 88 + (LPVOID)&msgbuf, 89 + 0, 90 + NULL); 91 + if (chars != 0) { 92 + /* If there is an \r\n appended, zap it. */ 93 + if (chars >= 2 94 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { 95 + chars -= 2; 96 + msgbuf[chars] = 0; 97 + } 98 + 99 + if (chars > sizeof (buf) - 1) { 100 + chars = sizeof (buf) - 1; 101 + msgbuf[chars] = 0; 102 + } 103 + 104 + wcstombs(buf, msgbuf, chars + 1); 105 + LocalFree(msgbuf); 106 + } 107 + else { 108 + sprintf(buf, "unknown win32 error (%ld)", error); 109 + } 110 + 111 + SetLastError(lasterr); 112 + return buf; 113 +} 114 + 115 +static void pwinerror (s) 116 + const char *s; 117 +{ 118 + if (s && *s) 119 + fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ())); 120 + else 121 + fprintf(stderr, "%s\n", strwinerror(GetLastError ())); 122 +} 123 + 124 +#endif /* UNDER_CE */ 125 + 126 +#ifndef GZ_SUFFIX 127 +# define GZ_SUFFIX ".gz" 128 +#endif 129 +#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) 130 + 131 +#define BUFLEN 16384 132 +#define MAX_NAME_LEN 1024 133 + 134 +#ifdef MAXSEG_64K 135 +# define local static 136 + /* Needed for systems with limitation on stack size. */ 137 +#else 138 +# define local 139 +#endif 140 + 141 +#ifdef Z_SOLO 142 +/* for Z_SOLO, create simplified gz* functions using deflate and inflate */ 143 + 144 +#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE) 145 +# include <unistd.h> /* for unlink() */ 146 +#endif 147 + 148 +void *myalloc OF((void *, unsigned, unsigned)); 149 +void myfree OF((void *, void *)); 150 + 151 +void *myalloc(q, n, m) 152 + void *q; 153 + unsigned n, m; 154 +{ 155 + q = Z_NULL; 156 + return calloc(n, m); 157 +} 158 + 159 +void myfree(q, p) 160 + void *q, *p; 161 +{ 162 + q = Z_NULL; 163 + free(p); 164 +} 165 + 166 +typedef struct gzFile_s { 167 + FILE *file; 168 + int write; 169 + int err; 170 + char *msg; 171 + z_stream strm; 172 +} *gzFile; 173 + 174 +gzFile gzopen OF((const char *, const char *)); 175 +gzFile gzdopen OF((int, const char *)); 176 +gzFile gz_open OF((const char *, int, const char *)); 177 + 178 +gzFile gzopen(path, mode) 179 +const char *path; 180 +const char *mode; 181 +{ 182 + return gz_open(path, -1, mode); 183 +} 184 + 185 +gzFile gzdopen(fd, mode) 186 +int fd; 187 +const char *mode; 188 +{ 189 + return gz_open(NULL, fd, mode); 190 +} 191 + 192 +gzFile gz_open(path, fd, mode) 193 + const char *path; 194 + int fd; 195 + const char *mode; 196 +{ 197 + gzFile gz; 198 + int ret; 199 + 200 + gz = malloc(sizeof(struct gzFile_s)); 201 + if (gz == NULL) 202 + return NULL; 203 + gz->write = strchr(mode, 'w') != NULL; 204 + gz->strm.zalloc = myalloc; 205 + gz->strm.zfree = myfree; 206 + gz->strm.opaque = Z_NULL; 207 + if (gz->write) 208 + ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0); 209 + else { 210 + gz->strm.next_in = 0; 211 + gz->strm.avail_in = Z_NULL; 212 + ret = inflateInit2(&(gz->strm), 15 + 16); 213 + } 214 + if (ret != Z_OK) { 215 + free(gz); 216 + return NULL; 217 + } 218 + gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") : 219 + fopen(path, gz->write ? "wb" : "rb"); 220 + if (gz->file == NULL) { 221 + gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm)); 222 + free(gz); 223 + return NULL; 224 + } 225 + gz->err = 0; 226 + gz->msg = ""; 227 + return gz; 228 +} 229 + 230 +int gzwrite OF((gzFile, const void *, unsigned)); 231 + 232 +int gzwrite(gz, buf, len) 233 + gzFile gz; 234 + const void *buf; 235 + unsigned len; 236 +{ 237 + z_stream *strm; 238 + unsigned char out[BUFLEN]; 239 + 240 + if (gz == NULL || !gz->write) 241 + return 0; 242 + strm = &(gz->strm); 243 + strm->next_in = (void *)buf; 244 + strm->avail_in = len; 245 + do { 246 + strm->next_out = out; 247 + strm->avail_out = BUFLEN; 248 + (void)deflate(strm, Z_NO_FLUSH); 249 + fwrite(out, 1, BUFLEN - strm->avail_out, gz->file); 250 + } while (strm->avail_out == 0); 251 + return len; 252 +} 253 + 254 +int gzread OF((gzFile, void *, unsigned)); 255 + 256 +int gzread(gz, buf, len) 257 + gzFile gz; 258 + void *buf; 259 + unsigned len; 260 +{ 261 + int ret; 262 + unsigned got; 263 + unsigned char in[1]; 264 + z_stream *strm; 265 + 266 + if (gz == NULL || gz->write) 267 + return 0; 268 + if (gz->err) 269 + return 0; 270 + strm = &(gz->strm); 271 + strm->next_out = (void *)buf; 272 + strm->avail_out = len; 273 + do { 274 + got = fread(in, 1, 1, gz->file); 275 + if (got == 0) 276 + break; 277 + strm->next_in = in; 278 + strm->avail_in = 1; 279 + ret = inflate(strm, Z_NO_FLUSH); 280 + if (ret == Z_DATA_ERROR) { 281 + gz->err = Z_DATA_ERROR; 282 + gz->msg = strm->msg; 283 + return 0; 284 + } 285 + if (ret == Z_STREAM_END) 286 + inflateReset(strm); 287 + } while (strm->avail_out); 288 + return len - strm->avail_out; 289 +} 290 + 291 +int gzclose OF((gzFile)); 292 + 293 +int gzclose(gz) 294 + gzFile gz; 295 +{ 296 + z_stream *strm; 297 + unsigned char out[BUFLEN]; 298 + 299 + if (gz == NULL) 300 + return Z_STREAM_ERROR; 301 + strm = &(gz->strm); 302 + if (gz->write) { 303 + strm->next_in = Z_NULL; 304 + strm->avail_in = 0; 305 + do { 306 + strm->next_out = out; 307 + strm->avail_out = BUFLEN; 308 + (void)deflate(strm, Z_FINISH); 309 + fwrite(out, 1, BUFLEN - strm->avail_out, gz->file); 310 + } while (strm->avail_out == 0); 311 + deflateEnd(strm); 312 + } 313 + else 314 + inflateEnd(strm); 315 + fclose(gz->file); 316 + free(gz); 317 + return Z_OK; 318 +} 319 + 320 +const char *gzerror OF((gzFile, int *)); 321 + 322 +const char *gzerror(gz, err) 323 + gzFile gz; 324 + int *err; 325 +{ 326 + *err = gz->err; 327 + return gz->msg; 328 +} 329 + 330 +#endif 331 + 332 +char *prog; 333 + 334 +void error OF((const char *msg)); 335 +void gz_compress OF((FILE *in, gzFile out)); 336 +#ifdef USE_MMAP 337 +int gz_compress_mmap OF((FILE *in, gzFile out)); 338 +#endif 339 +void gz_uncompress OF((gzFile in, FILE *out)); 340 +void file_compress OF((char *file, char *mode)); 341 +void file_uncompress OF((char *file)); 342 +int main OF((int argc, char *argv[])); 343 + 344 +/* =========================================================================== 345 + * Display error message and exit 346 + */ 347 +void error(msg) 348 + const char *msg; 349 +{ 350 + fprintf(stderr, "%s: %s\n", prog, msg); 351 + exit(1); 352 +} 353 + 354 +/* =========================================================================== 355 + * Compress input to output then close both files. 356 + */ 357 + 358 +void gz_compress(in, out) 359 + FILE *in; 360 + gzFile out; 361 +{ 362 + local char buf[BUFLEN]; 363 + int len; 364 + int err; 365 + 366 +#ifdef USE_MMAP 367 + /* Try first compressing with mmap. If mmap fails (minigzip used in a 368 + * pipe), use the normal fread loop. 369 + */ 370 + if (gz_compress_mmap(in, out) == Z_OK) return; 371 +#endif 372 + for (;;) { 373 + len = (int)fread(buf, 1, sizeof(buf), in); 374 + if (ferror(in)) { 375 + perror("fread"); 376 + exit(1); 377 + } 378 + if (len == 0) break; 379 + 380 + if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); 381 + } 382 + fclose(in); 383 + if (gzclose(out) != Z_OK) error("failed gzclose"); 384 +} 385 + 386 +#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */ 387 + 388 +/* Try compressing the input file at once using mmap. Return Z_OK if 389 + * if success, Z_ERRNO otherwise. 390 + */ 391 +int gz_compress_mmap(in, out) 392 + FILE *in; 393 + gzFile out; 394 +{ 395 + int len; 396 + int err; 397 + int ifd = fileno(in); 398 + caddr_t buf; /* mmap'ed buffer for the entire input file */ 399 + off_t buf_len; /* length of the input file */ 400 + struct stat sb; 401 + 402 + /* Determine the size of the file, needed for mmap: */ 403 + if (fstat(ifd, &sb) < 0) return Z_ERRNO; 404 + buf_len = sb.st_size; 405 + if (buf_len <= 0) return Z_ERRNO; 406 + 407 + /* Now do the actual mmap: */ 408 + buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); 409 + if (buf == (caddr_t)(-1)) return Z_ERRNO; 410 + 411 + /* Compress the whole file at once: */ 412 + len = gzwrite(out, (char *)buf, (unsigned)buf_len); 413 + 414 + if (len != (int)buf_len) error(gzerror(out, &err)); 415 + 416 + munmap(buf, buf_len); 417 + fclose(in); 418 + if (gzclose(out) != Z_OK) error("failed gzclose"); 419 + return Z_OK; 420 +} 421 +#endif /* USE_MMAP */ 422 + 423 +/* =========================================================================== 424 + * Uncompress input to output then close both files. 425 + */ 426 +void gz_uncompress(in, out) 427 + gzFile in; 428 + FILE *out; 429 +{ 430 + local char buf[BUFLEN]; 431 + int len; 432 + int err; 433 + 434 + for (;;) { 435 + len = gzread(in, buf, sizeof(buf)); 436 + if (len < 0) error (gzerror(in, &err)); 437 + if (len == 0) break; 438 + 439 + if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { 440 + error("failed fwrite"); 441 + } 442 + } 443 + if (fclose(out)) error("failed fclose"); 444 + 445 + if (gzclose(in) != Z_OK) error("failed gzclose"); 446 +} 447 + 448 + 449 +/* =========================================================================== 450 + * Compress the given file: create a corresponding .gz file and remove the 451 + * original. 452 + */ 453 +void file_compress(file, mode) 454 + char *file; 455 + char *mode; 456 +{ 457 + local char outfile[MAX_NAME_LEN]; 458 + FILE *in; 459 + gzFile out; 460 + 461 + if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { 462 + fprintf(stderr, "%s: filename too long\n", prog); 463 + exit(1); 464 + } 465 + 466 + strcpy(outfile, file); 467 + strcat(outfile, GZ_SUFFIX); 468 + 469 + in = fopen(file, "rb"); 470 + if (in == NULL) { 471 + perror(file); 472 + exit(1); 473 + } 474 + out = gzopen(outfile, mode); 475 + if (out == NULL) { 476 + fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); 477 + exit(1); 478 + } 479 + gz_compress(in, out); 480 + 481 + unlink(file); 482 +} 483 + 484 + 485 +/* =========================================================================== 486 + * Uncompress the given file and remove the original. 487 + */ 488 +void file_uncompress(file) 489 + char *file; 490 +{ 491 + local char buf[MAX_NAME_LEN]; 492 + char *infile, *outfile; 493 + FILE *out; 494 + gzFile in; 495 + size_t len = strlen(file); 496 + 497 + if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { 498 + fprintf(stderr, "%s: filename too long\n", prog); 499 + exit(1); 500 + } 501 + 502 + strcpy(buf, file); 503 + 504 + if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { 505 + infile = file; 506 + outfile = buf; 507 + outfile[len-3] = '\0'; 508 + } else { 509 + outfile = file; 510 + infile = buf; 511 + strcat(infile, GZ_SUFFIX); 512 + } 513 + in = gzopen(infile, "rb"); 514 + if (in == NULL) { 515 + fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); 516 + exit(1); 517 + } 518 + out = fopen(outfile, "wb"); 519 + if (out == NULL) { 520 + perror(file); 521 + exit(1); 522 + } 523 + 524 + gz_uncompress(in, out); 525 + 526 + unlink(infile); 527 +} 528 + 529 + 530 +/* =========================================================================== 531 + * Usage: minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...] 532 + * -c : write to standard output 533 + * -d : decompress 534 + * -f : compress with Z_FILTERED 535 + * -h : compress with Z_HUFFMAN_ONLY 536 + * -r : compress with Z_RLE 537 + * -1 to -9 : compression level 538 + */ 539 + 540 +int main(argc, argv) 541 + int argc; 542 + char *argv[]; 543 +{ 544 + int copyout = 0; 545 + int uncompr = 0; 546 + gzFile file; 547 + char *bname, outmode[20]; 548 + 549 + strcpy(outmode, "wb6 "); 550 + 551 + prog = argv[0]; 552 + bname = strrchr(argv[0], '/'); 553 + if (bname) 554 + bname++; 555 + else 556 + bname = argv[0]; 557 + argc--, argv++; 558 + 559 + if (!strcmp(bname, "gunzip")) 560 + uncompr = 1; 561 + else if (!strcmp(bname, "zcat")) 562 + copyout = uncompr = 1; 563 + 564 + while (argc > 0) { 565 + if (strcmp(*argv, "-c") == 0) 566 + copyout = 1; 567 + else if (strcmp(*argv, "-d") == 0) 568 + uncompr = 1; 569 + else if (strcmp(*argv, "-f") == 0) 570 + outmode[3] = 'f'; 571 + else if (strcmp(*argv, "-h") == 0) 572 + outmode[3] = 'h'; 573 + else if (strcmp(*argv, "-r") == 0) 574 + outmode[3] = 'R'; 575 + else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && 576 + (*argv)[2] == 0) 577 + outmode[2] = (*argv)[1]; 578 + else 579 + break; 580 + argc--, argv++; 581 + } 582 + if (outmode[3] == ' ') 583 + outmode[3] = 0; 584 + if (argc == 0) { 585 + SET_BINARY_MODE(stdin); 586 + SET_BINARY_MODE(stdout); 587 + if (uncompr) { 588 + file = gzdopen(fileno(stdin), "rb"); 589 + if (file == NULL) error("can't gzdopen stdin"); 590 + gz_uncompress(file, stdout); 591 + } else { 592 + file = gzdopen(fileno(stdout), outmode); 593 + if (file == NULL) error("can't gzdopen stdout"); 594 + gz_compress(stdin, file); 595 + } 596 + } else { 597 + if (copyout) { 598 + SET_BINARY_MODE(stdout); 599 + } 600 + do { 601 + if (uncompr) { 602 + if (copyout) { 603 + file = gzopen(*argv, "rb"); 604 + if (file == NULL) 605 + fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); 606 + else 607 + gz_uncompress(file, stdout); 608 + } else { 609 + file_uncompress(*argv); 610 + } 611 + } else { 612 + if (copyout) { 613 + FILE * in = fopen(*argv, "rb"); 614 + 615 + if (in == NULL) { 616 + perror(*argv); 617 + } else { 618 + file = gzdopen(fileno(stdout), outmode); 619 + if (file == NULL) error("can't gzdopen stdout"); 620 + 621 + gz_compress(in, file); 622 + } 623 + 624 + } else { 625 + file_compress(*argv, outmode); 626 + } 627 + } 628 + } while (argv++, --argc); 629 + } 630 + return 0; 631 +}
Added compat/zlib/treebuild.xml.
1 +<?xml version="1.0" ?> 2 +<package name="zlib" version="1.2.7"> 3 + <library name="zlib" dlversion="1.2.7" dlname="z"> 4 + <property name="description"> zip compression library </property> 5 + <property name="include-target-dir" value="$(@PACKAGE/install-includedir)" /> 6 + 7 + <!-- fixme: not implemented yet --> 8 + <property name="compiler/c/inline" value="yes" /> 9 + 10 + <include-file name="zlib.h" scope="public" mode="644" /> 11 + <include-file name="zconf.h" scope="public" mode="644" /> 12 + 13 + <source name="adler32.c"> 14 + <depend name="zlib.h" /> 15 + <depend name="zconf.h" /> 16 + </source> 17 + <source name="compress.c"> 18 + <depend name="zlib.h" /> 19 + <depend name="zconf.h" /> 20 + </source> 21 + <source name="crc32.c"> 22 + <depend name="zlib.h" /> 23 + <depend name="zconf.h" /> 24 + <depend name="crc32.h" /> 25 + </source> 26 + <source name="gzclose.c"> 27 + <depend name="zlib.h" /> 28 + <depend name="zconf.h" /> 29 + <depend name="gzguts.h" /> 30 + </source> 31 + <source name="gzlib.c"> 32 + <depend name="zlib.h" /> 33 + <depend name="zconf.h" /> 34 + <depend name="gzguts.h" /> 35 + </source> 36 + <source name="gzread.c"> 37 + <depend name="zlib.h" /> 38 + <depend name="zconf.h" /> 39 + <depend name="gzguts.h" /> 40 + </source> 41 + <source name="gzwrite.c"> 42 + <depend name="zlib.h" /> 43 + <depend name="zconf.h" /> 44 + <depend name="gzguts.h" /> 45 + </source> 46 + <source name="uncompr.c"> 47 + <depend name="zlib.h" /> 48 + <depend name="zconf.h" /> 49 + </source> 50 + <source name="deflate.c"> 51 + <depend name="zlib.h" /> 52 + <depend name="zconf.h" /> 53 + <depend name="zutil.h" /> 54 + <depend name="deflate.h" /> 55 + </source> 56 + <source name="trees.c"> 57 + <depend name="zlib.h" /> 58 + <depend name="zconf.h" /> 59 + <depend name="zutil.h" /> 60 + <depend name="deflate.h" /> 61 + <depend name="trees.h" /> 62 + </source> 63 + <source name="zutil.c"> 64 + <depend name="zlib.h" /> 65 + <depend name="zconf.h" /> 66 + <depend name="zutil.h" /> 67 + </source> 68 + <source name="inflate.c"> 69 + <depend name="zlib.h" /> 70 + <depend name="zconf.h" /> 71 + <depend name="zutil.h" /> 72 + <depend name="inftrees.h" /> 73 + <depend name="inflate.h" /> 74 + <depend name="inffast.h" /> 75 + </source> 76 + <source name="infback.c"> 77 + <depend name="zlib.h" /> 78 + <depend name="zconf.h" /> 79 + <depend name="zutil.h" /> 80 + <depend name="inftrees.h" /> 81 + <depend name="inflate.h" /> 82 + <depend name="inffast.h" /> 83 + </source> 84 + <source name="inftrees.c"> 85 + <depend name="zlib.h" /> 86 + <depend name="zconf.h" /> 87 + <depend name="zutil.h" /> 88 + <depend name="inftrees.h" /> 89 + </source> 90 + <source name="inffast.c"> 91 + <depend name="zlib.h" /> 92 + <depend name="zconf.h" /> 93 + <depend name="zutil.h" /> 94 + <depend name="inftrees.h" /> 95 + <depend name="inflate.h" /> 96 + <depend name="inffast.h" /> 97 + </source> 98 + </library> 99 +</package> 100 + 101 +<!-- 102 +CFLAGS=-O 103 +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 104 +#CFLAGS=-g -DDEBUG 105 +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ 106 +# -Wstrict-prototypes -Wmissing-prototypes 107 + 108 +# OBJA = 109 +# to use the asm code: make OBJA=match.o 110 +# 111 +match.o: match.S 112 + $(CPP) match.S > _match.s 113 + $(CC) -c _match.s 114 + mv _match.o match.o 115 + rm -f _match.s 116 +-->
Added compat/zlib/trees.c.
1 +/* trees.c -- output deflated data using Huffman coding 2 + * Copyright (C) 1995-2012 Jean-loup Gailly 3 + * detect_data_type() function provided freely by Cosmin Truta, 2006 4 + * For conditions of distribution and use, see copyright notice in zlib.h 5 + */ 6 + 7 +/* 8 + * ALGORITHM 9 + * 10 + * The "deflation" process uses several Huffman trees. The more 11 + * common source values are represented by shorter bit sequences. 12 + * 13 + * Each code tree is stored in a compressed form which is itself 14 + * a Huffman encoding of the lengths of all the code strings (in 15 + * ascending order by source values). The actual code strings are 16 + * reconstructed from the lengths in the inflate process, as described 17 + * in the deflate specification. 18 + * 19 + * REFERENCES 20 + * 21 + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 22 + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc 23 + * 24 + * Storer, James A. 25 + * Data Compression: Methods and Theory, pp. 49-50. 26 + * Computer Science Press, 1988. ISBN 0-7167-8156-5. 27 + * 28 + * Sedgewick, R. 29 + * Algorithms, p290. 30 + * Addison-Wesley, 1983. ISBN 0-201-06672-6. 31 + */ 32 + 33 +/* @(#) $Id$ */ 34 + 35 +/* #define GEN_TREES_H */ 36 + 37 +#include "deflate.h" 38 + 39 +#ifdef DEBUG 40 +# include <ctype.h> 41 +#endif 42 + 43 +/* =========================================================================== 44 + * Constants 45 + */ 46 + 47 +#define MAX_BL_BITS 7 48 +/* Bit length codes must not exceed MAX_BL_BITS bits */ 49 + 50 +#define END_BLOCK 256 51 +/* end of block literal code */ 52 + 53 +#define REP_3_6 16 54 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ 55 + 56 +#define REPZ_3_10 17 57 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ 58 + 59 +#define REPZ_11_138 18 60 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ 61 + 62 +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ 63 + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; 64 + 65 +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ 66 + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; 67 + 68 +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ 69 + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; 70 + 71 +local const uch bl_order[BL_CODES] 72 + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; 73 +/* The lengths of the bit length codes are sent in order of decreasing 74 + * probability, to avoid transmitting the lengths for unused bit length codes. 75 + */ 76 + 77 +/* =========================================================================== 78 + * Local data. These are initialized only once. 79 + */ 80 + 81 +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ 82 + 83 +#if defined(GEN_TREES_H) || !defined(STDC) 84 +/* non ANSI compilers may not accept trees.h */ 85 + 86 +local ct_data static_ltree[L_CODES+2]; 87 +/* The static literal tree. Since the bit lengths are imposed, there is no 88 + * need for the L_CODES extra codes used during heap construction. However 89 + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init 90 + * below). 91 + */ 92 + 93 +local ct_data static_dtree[D_CODES]; 94 +/* The static distance tree. (Actually a trivial tree since all codes use 95 + * 5 bits.) 96 + */ 97 + 98 +uch _dist_code[DIST_CODE_LEN]; 99 +/* Distance codes. The first 256 values correspond to the distances 100 + * 3 .. 258, the last 256 values correspond to the top 8 bits of 101 + * the 15 bit distances. 102 + */ 103 + 104 +uch _length_code[MAX_MATCH-MIN_MATCH+1]; 105 +/* length code for each normalized match length (0 == MIN_MATCH) */ 106 + 107 +local int base_length[LENGTH_CODES]; 108 +/* First normalized length for each code (0 = MIN_MATCH) */ 109 + 110 +local int base_dist[D_CODES]; 111 +/* First normalized distance for each code (0 = distance of 1) */ 112 + 113 +#else 114 +# include "trees.h" 115 +#endif /* GEN_TREES_H */ 116 + 117 +struct static_tree_desc_s { 118 + const ct_data *static_tree; /* static tree or NULL */ 119 + const intf *extra_bits; /* extra bits for each code or NULL */ 120 + int extra_base; /* base index for extra_bits */ 121 + int elems; /* max number of elements in the tree */ 122 + int max_length; /* max bit length for the codes */ 123 +}; 124 + 125 +local static_tree_desc static_l_desc = 126 +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; 127 + 128 +local static_tree_desc static_d_desc = 129 +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; 130 + 131 +local static_tree_desc static_bl_desc = 132 +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; 133 + 134 +/* =========================================================================== 135 + * Local (static) routines in this file. 136 + */ 137 + 138 +local void tr_static_init OF((void)); 139 +local void init_block OF((deflate_state *s)); 140 +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); 141 +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); 142 +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); 143 +local void build_tree OF((deflate_state *s, tree_desc *desc)); 144 +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); 145 +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); 146 +local int build_bl_tree OF((deflate_state *s)); 147 +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, 148 + int blcodes)); 149 +local void compress_block OF((deflate_state *s, ct_data *ltree, 150 + ct_data *dtree)); 151 +local int detect_data_type OF((deflate_state *s)); 152 +local unsigned bi_reverse OF((unsigned value, int length)); 153 +local void bi_windup OF((deflate_state *s)); 154 +local void bi_flush OF((deflate_state *s)); 155 +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, 156 + int header)); 157 + 158 +#ifdef GEN_TREES_H 159 +local void gen_trees_header OF((void)); 160 +#endif 161 + 162 +#ifndef DEBUG 163 +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) 164 + /* Send a code of the given tree. c and tree must not have side effects */ 165 + 166 +#else /* DEBUG */ 167 +# define send_code(s, c, tree) \ 168 + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ 169 + send_bits(s, tree[c].Code, tree[c].Len); } 170 +#endif 171 + 172 +/* =========================================================================== 173 + * Output a short LSB first on the stream. 174 + * IN assertion: there is enough room in pendingBuf. 175 + */ 176 +#define put_short(s, w) { \ 177 + put_byte(s, (uch)((w) & 0xff)); \ 178 + put_byte(s, (uch)((ush)(w) >> 8)); \ 179 +} 180 + 181 +/* =========================================================================== 182 + * Send a value on a given number of bits. 183 + * IN assertion: length <= 16 and value fits in length bits. 184 + */ 185 +#ifdef DEBUG 186 +local void send_bits OF((deflate_state *s, int value, int length)); 187 + 188 +local void send_bits(s, value, length) 189 + deflate_state *s; 190 + int value; /* value to send */ 191 + int length; /* number of bits */ 192 +{ 193 + Tracevv((stderr," l %2d v %4x ", length, value)); 194 + Assert(length > 0 && length <= 15, "invalid length"); 195 + s->bits_sent += (ulg)length; 196 + 197 + /* If not enough room in bi_buf, use (valid) bits from bi_buf and 198 + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) 199 + * unused bits in value. 200 + */ 201 + if (s->bi_valid > (int)Buf_size - length) { 202 + s->bi_buf |= (ush)value << s->bi_valid; 203 + put_short(s, s->bi_buf); 204 + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); 205 + s->bi_valid += length - Buf_size; 206 + } else { 207 + s->bi_buf |= (ush)value << s->bi_valid; 208 + s->bi_valid += length; 209 + } 210 +} 211 +#else /* !DEBUG */ 212 + 213 +#define send_bits(s, value, length) \ 214 +{ int len = length;\ 215 + if (s->bi_valid > (int)Buf_size - len) {\ 216 + int val = value;\ 217 + s->bi_buf |= (ush)val << s->bi_valid;\ 218 + put_short(s, s->bi_buf);\ 219 + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ 220 + s->bi_valid += len - Buf_size;\ 221 + } else {\ 222 + s->bi_buf |= (ush)(value) << s->bi_valid;\ 223 + s->bi_valid += len;\ 224 + }\ 225 +} 226 +#endif /* DEBUG */ 227 + 228 + 229 +/* the arguments must not have side effects */ 230 + 231 +/* =========================================================================== 232 + * Initialize the various 'constant' tables. 233 + */ 234 +local void tr_static_init() 235 +{ 236 +#if defined(GEN_TREES_H) || !defined(STDC) 237 + static int static_init_done = 0; 238 + int n; /* iterates over tree elements */ 239 + int bits; /* bit counter */ 240 + int length; /* length value */ 241 + int code; /* code value */ 242 + int dist; /* distance index */ 243 + ush bl_count[MAX_BITS+1]; 244 + /* number of codes at each bit length for an optimal tree */ 245 + 246 + if (static_init_done) return; 247 + 248 + /* For some embedded targets, global variables are not initialized: */ 249 +#ifdef NO_INIT_GLOBAL_POINTERS 250 + static_l_desc.static_tree = static_ltree; 251 + static_l_desc.extra_bits = extra_lbits; 252 + static_d_desc.static_tree = static_dtree; 253 + static_d_desc.extra_bits = extra_dbits; 254 + static_bl_desc.extra_bits = extra_blbits; 255 +#endif 256 + 257 + /* Initialize the mapping length (0..255) -> length code (0..28) */ 258 + length = 0; 259 + for (code = 0; code < LENGTH_CODES-1; code++) { 260 + base_length[code] = length; 261 + for (n = 0; n < (1<<extra_lbits[code]); n++) { 262 + _length_code[length++] = (uch)code; 263 + } 264 + } 265 + Assert (length == 256, "tr_static_init: length != 256"); 266 + /* Note that the length 255 (match length 258) can be represented 267 + * in two different ways: code 284 + 5 bits or code 285, so we 268 + * overwrite length_code[255] to use the best encoding: 269 + */ 270 + _length_code[length-1] = (uch)code; 271 + 272 + /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ 273 + dist = 0; 274 + for (code = 0 ; code < 16; code++) { 275 + base_dist[code] = dist; 276 + for (n = 0; n < (1<<extra_dbits[code]); n++) { 277 + _dist_code[dist++] = (uch)code; 278 + } 279 + } 280 + Assert (dist == 256, "tr_static_init: dist != 256"); 281 + dist >>= 7; /* from now on, all distances are divided by 128 */ 282 + for ( ; code < D_CODES; code++) { 283 + base_dist[code] = dist << 7; 284 + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { 285 + _dist_code[256 + dist++] = (uch)code; 286 + } 287 + } 288 + Assert (dist == 256, "tr_static_init: 256+dist != 512"); 289 + 290 + /* Construct the codes of the static literal tree */ 291 + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; 292 + n = 0; 293 + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; 294 + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; 295 + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; 296 + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; 297 + /* Codes 286 and 287 do not exist, but we must include them in the 298 + * tree construction to get a canonical Huffman tree (longest code 299 + * all ones) 300 + */ 301 + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); 302 + 303 + /* The static distance tree is trivial: */ 304 + for (n = 0; n < D_CODES; n++) { 305 + static_dtree[n].Len = 5; 306 + static_dtree[n].Code = bi_reverse((unsigned)n, 5); 307 + } 308 + static_init_done = 1; 309 + 310 +# ifdef GEN_TREES_H 311 + gen_trees_header(); 312 +# endif 313 +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ 314 +} 315 + 316 +/* =========================================================================== 317 + * Genererate the file trees.h describing the static trees. 318 + */ 319 +#ifdef GEN_TREES_H 320 +# ifndef DEBUG 321 +# include <stdio.h> 322 +# endif 323 + 324 +# define SEPARATOR(i, last, width) \ 325 + ((i) == (last)? "\n};\n\n" : \ 326 + ((i) % (width) == (width)-1 ? ",\n" : ", ")) 327 + 328 +void gen_trees_header() 329 +{ 330 + FILE *header = fopen("trees.h", "w"); 331 + int i; 332 + 333 + Assert (header != NULL, "Can't open trees.h"); 334 + fprintf(header, 335 + "/* header created automatically with -DGEN_TREES_H */\n\n"); 336 + 337 + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); 338 + for (i = 0; i < L_CODES+2; i++) { 339 + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, 340 + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); 341 + } 342 + 343 + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); 344 + for (i = 0; i < D_CODES; i++) { 345 + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, 346 + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); 347 + } 348 + 349 + fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); 350 + for (i = 0; i < DIST_CODE_LEN; i++) { 351 + fprintf(header, "%2u%s", _dist_code[i], 352 + SEPARATOR(i, DIST_CODE_LEN-1, 20)); 353 + } 354 + 355 + fprintf(header, 356 + "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); 357 + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { 358 + fprintf(header, "%2u%s", _length_code[i], 359 + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); 360 + } 361 + 362 + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); 363 + for (i = 0; i < LENGTH_CODES; i++) { 364 + fprintf(header, "%1u%s", base_length[i], 365 + SEPARATOR(i, LENGTH_CODES-1, 20)); 366 + } 367 + 368 + fprintf(header, "local const int base_dist[D_CODES] = {\n"); 369 + for (i = 0; i < D_CODES; i++) { 370 + fprintf(header, "%5u%s", base_dist[i], 371 + SEPARATOR(i, D_CODES-1, 10)); 372 + } 373 + 374 + fclose(header); 375 +} 376 +#endif /* GEN_TREES_H */ 377 + 378 +/* =========================================================================== 379 + * Initialize the tree data structures for a new zlib stream. 380 + */ 381 +void ZLIB_INTERNAL _tr_init(s) 382 + deflate_state *s; 383 +{ 384 + tr_static_init(); 385 + 386 + s->l_desc.dyn_tree = s->dyn_ltree; 387 + s->l_desc.stat_desc = &static_l_desc; 388 + 389 + s->d_desc.dyn_tree = s->dyn_dtree; 390 + s->d_desc.stat_desc = &static_d_desc; 391 + 392 + s->bl_desc.dyn_tree = s->bl_tree; 393 + s->bl_desc.stat_desc = &static_bl_desc; 394 + 395 + s->bi_buf = 0; 396 + s->bi_valid = 0; 397 +#ifdef DEBUG 398 + s->compressed_len = 0L; 399 + s->bits_sent = 0L; 400 +#endif 401 + 402 + /* Initialize the first block of the first file: */ 403 + init_block(s); 404 +} 405 + 406 +/* =========================================================================== 407 + * Initialize a new block. 408 + */ 409 +local void init_block(s) 410 + deflate_state *s; 411 +{ 412 + int n; /* iterates over tree elements */ 413 + 414 + /* Initialize the trees. */ 415 + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; 416 + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; 417 + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; 418 + 419 + s->dyn_ltree[END_BLOCK].Freq = 1; 420 + s->opt_len = s->static_len = 0L; 421 + s->last_lit = s->matches = 0; 422 +} 423 + 424 +#define SMALLEST 1 425 +/* Index within the heap array of least frequent node in the Huffman tree */ 426 + 427 + 428 +/* =========================================================================== 429 + * Remove the smallest element from the heap and recreate the heap with 430 + * one less element. Updates heap and heap_len. 431 + */ 432 +#define pqremove(s, tree, top) \ 433 +{\ 434 + top = s->heap[SMALLEST]; \ 435 + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ 436 + pqdownheap(s, tree, SMALLEST); \ 437 +} 438 + 439 +/* =========================================================================== 440 + * Compares to subtrees, using the tree depth as tie breaker when 441 + * the subtrees have equal frequency. This minimizes the worst case length. 442 + */ 443 +#define smaller(tree, n, m, depth) \ 444 + (tree[n].Freq < tree[m].Freq || \ 445 + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) 446 + 447 +/* =========================================================================== 448 + * Restore the heap property by moving down the tree starting at node k, 449 + * exchanging a node with the smallest of its two sons if necessary, stopping 450 + * when the heap property is re-established (each father smaller than its 451 + * two sons). 452 + */ 453 +local void pqdownheap(s, tree, k) 454 + deflate_state *s; 455 + ct_data *tree; /* the tree to restore */ 456 + int k; /* node to move down */ 457 +{ 458 + int v = s->heap[k]; 459 + int j = k << 1; /* left son of k */ 460 + while (j <= s->heap_len) { 461 + /* Set j to the smallest of the two sons: */ 462 + if (j < s->heap_len && 463 + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { 464 + j++; 465 + } 466 + /* Exit if v is smaller than both sons */ 467 + if (smaller(tree, v, s->heap[j], s->depth)) break; 468 + 469 + /* Exchange v with the smallest son */ 470 + s->heap[k] = s->heap[j]; k = j; 471 + 472 + /* And continue down the tree, setting j to the left son of k */ 473 + j <<= 1; 474 + } 475 + s->heap[k] = v; 476 +} 477 + 478 +/* =========================================================================== 479 + * Compute the optimal bit lengths for a tree and update the total bit length 480 + * for the current block. 481 + * IN assertion: the fields freq and dad are set, heap[heap_max] and 482 + * above are the tree nodes sorted by increasing frequency. 483 + * OUT assertions: the field len is set to the optimal bit length, the 484 + * array bl_count contains the frequencies for each bit length. 485 + * The length opt_len is updated; static_len is also updated if stree is 486 + * not null. 487 + */ 488 +local void gen_bitlen(s, desc) 489 + deflate_state *s; 490 + tree_desc *desc; /* the tree descriptor */ 491 +{ 492 + ct_data *tree = desc->dyn_tree; 493 + int max_code = desc->max_code; 494 + const ct_data *stree = desc->stat_desc->static_tree; 495 + const intf *extra = desc->stat_desc->extra_bits; 496 + int base = desc->stat_desc->extra_base; 497 + int max_length = desc->stat_desc->max_length; 498 + int h; /* heap index */ 499 + int n, m; /* iterate over the tree elements */ 500 + int bits; /* bit length */ 501 + int xbits; /* extra bits */ 502 + ush f; /* frequency */ 503 + int overflow = 0; /* number of elements with bit length too large */ 504 + 505 + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; 506 + 507 + /* In a first pass, compute the optimal bit lengths (which may 508 + * overflow in the case of the bit length tree). 509 + */ 510 + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ 511 + 512 + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { 513 + n = s->heap[h]; 514 + bits = tree[tree[n].Dad].Len + 1; 515 + if (bits > max_length) bits = max_length, overflow++; 516 + tree[n].Len = (ush)bits; 517 + /* We overwrite tree[n].Dad which is no longer needed */ 518 + 519 + if (n > max_code) continue; /* not a leaf node */ 520 + 521 + s->bl_count[bits]++; 522 + xbits = 0; 523 + if (n >= base) xbits = extra[n-base]; 524 + f = tree[n].Freq; 525 + s->opt_len += (ulg)f * (bits + xbits); 526 + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); 527 + } 528 + if (overflow == 0) return; 529 + 530 + Trace((stderr,"\nbit length overflow\n")); 531 + /* This happens for example on obj2 and pic of the Calgary corpus */ 532 + 533 + /* Find the first bit length which could increase: */ 534 + do { 535 + bits = max_length-1; 536 + while (s->bl_count[bits] == 0) bits--; 537 + s->bl_count[bits]--; /* move one leaf down the tree */ 538 + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ 539 + s->bl_count[max_length]--; 540 + /* The brother of the overflow item also moves one step up, 541 + * but this does not affect bl_count[max_length] 542 + */ 543 + overflow -= 2; 544 + } while (overflow > 0); 545 + 546 + /* Now recompute all bit lengths, scanning in increasing frequency. 547 + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all 548 + * lengths instead of fixing only the wrong ones. This idea is taken 549 + * from 'ar' written by Haruhiko Okumura.) 550 + */ 551 + for (bits = max_length; bits != 0; bits--) { 552 + n = s->bl_count[bits]; 553 + while (n != 0) { 554 + m = s->heap[--h]; 555 + if (m > max_code) continue; 556 + if ((unsigned) tree[m].Len != (unsigned) bits) { 557 + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); 558 + s->opt_len += ((long)bits - (long)tree[m].Len) 559 + *(long)tree[m].Freq; 560 + tree[m].Len = (ush)bits; 561 + } 562 + n--; 563 + } 564 + } 565 +} 566 + 567 +/* =========================================================================== 568 + * Generate the codes for a given tree and bit counts (which need not be 569 + * optimal). 570 + * IN assertion: the array bl_count contains the bit length statistics for 571 + * the given tree and the field len is set for all tree elements. 572 + * OUT assertion: the field code is set for all tree elements of non 573 + * zero code length. 574 + */ 575 +local void gen_codes (tree, max_code, bl_count) 576 + ct_data *tree; /* the tree to decorate */ 577 + int max_code; /* largest code with non zero frequency */ 578 + ushf *bl_count; /* number of codes at each bit length */ 579 +{ 580 + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ 581 + ush code = 0; /* running code value */ 582 + int bits; /* bit index */ 583 + int n; /* code index */ 584 + 585 + /* The distribution counts are first used to generate the code values 586 + * without bit reversal. 587 + */ 588 + for (bits = 1; bits <= MAX_BITS; bits++) { 589 + next_code[bits] = code = (code + bl_count[bits-1]) << 1; 590 + } 591 + /* Check that the bit counts in bl_count are consistent. The last code 592 + * must be all ones. 593 + */ 594 + Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, 595 + "inconsistent bit counts"); 596 + Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); 597 + 598 + for (n = 0; n <= max_code; n++) { 599 + int len = tree[n].Len; 600 + if (len == 0) continue; 601 + /* Now reverse the bits */ 602 + tree[n].Code = bi_reverse(next_code[len]++, len); 603 + 604 + Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", 605 + n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); 606 + } 607 +} 608 + 609 +/* =========================================================================== 610 + * Construct one Huffman tree and assigns the code bit strings and lengths. 611 + * Update the total bit length for the current block. 612 + * IN assertion: the field freq is set for all tree elements. 613 + * OUT assertions: the fields len and code are set to the optimal bit length 614 + * and corresponding code. The length opt_len is updated; static_len is 615 + * also updated if stree is not null. The field max_code is set. 616 + */ 617 +local void build_tree(s, desc) 618 + deflate_state *s; 619 + tree_desc *desc; /* the tree descriptor */ 620 +{ 621 + ct_data *tree = desc->dyn_tree; 622 + const ct_data *stree = desc->stat_desc->static_tree; 623 + int elems = desc->stat_desc->elems; 624 + int n, m; /* iterate over heap elements */ 625 + int max_code = -1; /* largest code with non zero frequency */ 626 + int node; /* new node being created */ 627 + 628 + /* Construct the initial heap, with least frequent element in 629 + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. 630 + * heap[0] is not used. 631 + */ 632 + s->heap_len = 0, s->heap_max = HEAP_SIZE; 633 + 634 + for (n = 0; n < elems; n++) { 635 + if (tree[n].Freq != 0) { 636 + s->heap[++(s->heap_len)] = max_code = n; 637 + s->depth[n] = 0; 638 + } else { 639 + tree[n].Len = 0; 640 + } 641 + } 642 + 643 + /* The pkzip format requires that at least one distance code exists, 644 + * and that at least one bit should be sent even if there is only one 645 + * possible code. So to avoid special checks later on we force at least 646 + * two codes of non zero frequency. 647 + */ 648 + while (s->heap_len < 2) { 649 + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); 650 + tree[node].Freq = 1; 651 + s->depth[node] = 0; 652 + s->opt_len--; if (stree) s->static_len -= stree[node].Len; 653 + /* node is 0 or 1 so it does not have extra bits */ 654 + } 655 + desc->max_code = max_code; 656 + 657 + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, 658 + * establish sub-heaps of increasing lengths: 659 + */ 660 + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); 661 + 662 + /* Construct the Huffman tree by repeatedly combining the least two 663 + * frequent nodes. 664 + */ 665 + node = elems; /* next internal node of the tree */ 666 + do { 667 + pqremove(s, tree, n); /* n = node of least frequency */ 668 + m = s->heap[SMALLEST]; /* m = node of next least frequency */ 669 + 670 + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ 671 + s->heap[--(s->heap_max)] = m; 672 + 673 + /* Create a new node father of n and m */ 674 + tree[node].Freq = tree[n].Freq + tree[m].Freq; 675 + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? 676 + s->depth[n] : s->depth[m]) + 1); 677 + tree[n].Dad = tree[m].Dad = (ush)node; 678 +#ifdef DUMP_BL_TREE 679 + if (tree == s->bl_tree) { 680 + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", 681 + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); 682 + } 683 +#endif 684 + /* and insert the new node in the heap */ 685 + s->heap[SMALLEST] = node++; 686 + pqdownheap(s, tree, SMALLEST); 687 + 688 + } while (s->heap_len >= 2); 689 + 690 + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; 691 + 692 + /* At this point, the fields freq and dad are set. We can now 693 + * generate the bit lengths. 694 + */ 695 + gen_bitlen(s, (tree_desc *)desc); 696 + 697 + /* The field len is now set, we can generate the bit codes */ 698 + gen_codes ((ct_data *)tree, max_code, s->bl_count); 699 +} 700 + 701 +/* =========================================================================== 702 + * Scan a literal or distance tree to determine the frequencies of the codes 703 + * in the bit length tree. 704 + */ 705 +local void scan_tree (s, tree, max_code) 706 + deflate_state *s; 707 + ct_data *tree; /* the tree to be scanned */ 708 + int max_code; /* and its largest code of non zero frequency */ 709 +{ 710 + int n; /* iterates over all tree elements */ 711 + int prevlen = -1; /* last emitted length */ 712 + int curlen; /* length of current code */ 713 + int nextlen = tree[0].Len; /* length of next code */ 714 + int count = 0; /* repeat count of the current code */ 715 + int max_count = 7; /* max repeat count */ 716 + int min_count = 4; /* min repeat count */ 717 + 718 + if (nextlen == 0) max_count = 138, min_count = 3; 719 + tree[max_code+1].Len = (ush)0xffff; /* guard */ 720 + 721 + for (n = 0; n <= max_code; n++) { 722 + curlen = nextlen; nextlen = tree[n+1].Len; 723 + if (++count < max_count && curlen == nextlen) { 724 + continue; 725 + } else if (count < min_count) { 726 + s->bl_tree[curlen].Freq += count; 727 + } else if (curlen != 0) { 728 + if (curlen != prevlen) s->bl_tree[curlen].Freq++; 729 + s->bl_tree[REP_3_6].Freq++; 730 + } else if (count <= 10) { 731 + s->bl_tree[REPZ_3_10].Freq++; 732 + } else { 733 + s->bl_tree[REPZ_11_138].Freq++; 734 + } 735 + count = 0; prevlen = curlen; 736 + if (nextlen == 0) { 737 + max_count = 138, min_count = 3; 738 + } else if (curlen == nextlen) { 739 + max_count = 6, min_count = 3; 740 + } else { 741 + max_count = 7, min_count = 4; 742 + } 743 + } 744 +} 745 + 746 +/* =========================================================================== 747 + * Send a literal or distance tree in compressed form, using the codes in 748 + * bl_tree. 749 + */ 750 +local void send_tree (s, tree, max_code) 751 + deflate_state *s; 752 + ct_data *tree; /* the tree to be scanned */ 753 + int max_code; /* and its largest code of non zero frequency */ 754 +{ 755 + int n; /* iterates over all tree elements */ 756 + int prevlen = -1; /* last emitted length */ 757 + int curlen; /* length of current code */ 758 + int nextlen = tree[0].Len; /* length of next code */ 759 + int count = 0; /* repeat count of the current code */ 760 + int max_count = 7; /* max repeat count */ 761 + int min_count = 4; /* min repeat count */ 762 + 763 + /* tree[max_code+1].Len = -1; */ /* guard already set */ 764 + if (nextlen == 0) max_count = 138, min_count = 3; 765 + 766 + for (n = 0; n <= max_code; n++) { 767 + curlen = nextlen; nextlen = tree[n+1].Len; 768 + if (++count < max_count && curlen == nextlen) { 769 + continue; 770 + } else if (count < min_count) { 771 + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); 772 + 773 + } else if (curlen != 0) { 774 + if (curlen != prevlen) { 775 + send_code(s, curlen, s->bl_tree); count--; 776 + } 777 + Assert(count >= 3 && count <= 6, " 3_6?"); 778 + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); 779 + 780 + } else if (count <= 10) { 781 + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); 782 + 783 + } else { 784 + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); 785 + } 786 + count = 0; prevlen = curlen; 787 + if (nextlen == 0) { 788 + max_count = 138, min_count = 3; 789 + } else if (curlen == nextlen) { 790 + max_count = 6, min_count = 3; 791 + } else { 792 + max_count = 7, min_count = 4; 793 + } 794 + } 795 +} 796 + 797 +/* =========================================================================== 798 + * Construct the Huffman tree for the bit lengths and return the index in 799 + * bl_order of the last bit length code to send. 800 + */ 801 +local int build_bl_tree(s) 802 + deflate_state *s; 803 +{ 804 + int max_blindex; /* index of last bit length code of non zero freq */ 805 + 806 + /* Determine the bit length frequencies for literal and distance trees */ 807 + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); 808 + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); 809 + 810 + /* Build the bit length tree: */ 811 + build_tree(s, (tree_desc *)(&(s->bl_desc))); 812 + /* opt_len now includes the length of the tree representations, except 813 + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. 814 + */ 815 + 816 + /* Determine the number of bit length codes to send. The pkzip format 817 + * requires that at least 4 bit length codes be sent. (appnote.txt says 818 + * 3 but the actual value used is 4.) 819 + */ 820 + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { 821 + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; 822 + } 823 + /* Update opt_len to include the bit length tree and counts */ 824 + s->opt_len += 3*(max_blindex+1) + 5+5+4; 825 + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", 826 + s->opt_len, s->static_len)); 827 + 828 + return max_blindex; 829 +} 830 + 831 +/* =========================================================================== 832 + * Send the header for a block using dynamic Huffman trees: the counts, the 833 + * lengths of the bit length codes, the literal tree and the distance tree. 834 + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. 835 + */ 836 +local void send_all_trees(s, lcodes, dcodes, blcodes) 837 + deflate_state *s; 838 + int lcodes, dcodes, blcodes; /* number of codes for each tree */ 839 +{ 840 + int rank; /* index in bl_order */ 841 + 842 + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); 843 + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, 844 + "too many codes"); 845 + Tracev((stderr, "\nbl counts: ")); 846 + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ 847 + send_bits(s, dcodes-1, 5); 848 + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ 849 + for (rank = 0; rank < blcodes; rank++) { 850 + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); 851 + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); 852 + } 853 + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); 854 + 855 + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ 856 + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); 857 + 858 + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ 859 + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); 860 +} 861 + 862 +/* =========================================================================== 863 + * Send a stored block 864 + */ 865 +void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) 866 + deflate_state *s; 867 + charf *buf; /* input block */ 868 + ulg stored_len; /* length of input block */ 869 + int last; /* one if this is the last block for a file */ 870 +{ 871 + send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ 872 +#ifdef DEBUG 873 + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; 874 + s->compressed_len += (stored_len + 4) << 3; 875 +#endif 876 + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ 877 +} 878 + 879 +/* =========================================================================== 880 + * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) 881 + */ 882 +void ZLIB_INTERNAL _tr_flush_bits(s) 883 + deflate_state *s; 884 +{ 885 + bi_flush(s); 886 +} 887 + 888 +/* =========================================================================== 889 + * Send one empty static block to give enough lookahead for inflate. 890 + * This takes 10 bits, of which 7 may remain in the bit buffer. 891 + */ 892 +void ZLIB_INTERNAL _tr_align(s) 893 + deflate_state *s; 894 +{ 895 + send_bits(s, STATIC_TREES<<1, 3); 896 + send_code(s, END_BLOCK, static_ltree); 897 +#ifdef DEBUG 898 + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ 899 +#endif 900 + bi_flush(s); 901 +} 902 + 903 +/* =========================================================================== 904 + * Determine the best encoding for the current block: dynamic trees, static 905 + * trees or store, and output the encoded block to the zip file. 906 + */ 907 +void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) 908 + deflate_state *s; 909 + charf *buf; /* input block, or NULL if too old */ 910 + ulg stored_len; /* length of input block */ 911 + int last; /* one if this is the last block for a file */ 912 +{ 913 + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ 914 + int max_blindex = 0; /* index of last bit length code of non zero freq */ 915 + 916 + /* Build the Huffman trees unless a stored block is forced */ 917 + if (s->level > 0) { 918 + 919 + /* Check if the file is binary or text */ 920 + if (s->strm->data_type == Z_UNKNOWN) 921 + s->strm->data_type = detect_data_type(s); 922 + 923 + /* Construct the literal and distance trees */ 924 + build_tree(s, (tree_desc *)(&(s->l_desc))); 925 + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 926 + s->static_len)); 927 + 928 + build_tree(s, (tree_desc *)(&(s->d_desc))); 929 + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, 930 + s->static_len)); 931 + /* At this point, opt_len and static_len are the total bit lengths of 932 + * the compressed block data, excluding the tree representations. 933 + */ 934 + 935 + /* Build the bit length tree for the above two trees, and get the index 936 + * in bl_order of the last bit length code to send. 937 + */ 938 + max_blindex = build_bl_tree(s); 939 + 940 + /* Determine the best encoding. Compute the block lengths in bytes. */ 941 + opt_lenb = (s->opt_len+3+7)>>3; 942 + static_lenb = (s->static_len+3+7)>>3; 943 + 944 + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", 945 + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, 946 + s->last_lit)); 947 + 948 + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; 949 + 950 + } else { 951 + Assert(buf != (char*)0, "lost buf"); 952 + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ 953 + } 954 + 955 +#ifdef FORCE_STORED 956 + if (buf != (char*)0) { /* force stored block */ 957 +#else 958 + if (stored_len+4 <= opt_lenb && buf != (char*)0) { 959 + /* 4: two words for the lengths */ 960 +#endif 961 + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. 962 + * Otherwise we can't have processed more than WSIZE input bytes since 963 + * the last block flush, because compression would have been 964 + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to 965 + * transform a block into a stored block. 966 + */ 967 + _tr_stored_block(s, buf, stored_len, last); 968 + 969 +#ifdef FORCE_STATIC 970 + } else if (static_lenb >= 0) { /* force static trees */ 971 +#else 972 + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { 973 +#endif 974 + send_bits(s, (STATIC_TREES<<1)+last, 3); 975 + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); 976 +#ifdef DEBUG 977 + s->compressed_len += 3 + s->static_len; 978 +#endif 979 + } else { 980 + send_bits(s, (DYN_TREES<<1)+last, 3); 981 + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, 982 + max_blindex+1); 983 + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); 984 +#ifdef DEBUG 985 + s->compressed_len += 3 + s->opt_len; 986 +#endif 987 + } 988 + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); 989 + /* The above check is made mod 2^32, for files larger than 512 MB 990 + * and uLong implemented on 32 bits. 991 + */ 992 + init_block(s); 993 + 994 + if (last) { 995 + bi_windup(s); 996 +#ifdef DEBUG 997 + s->compressed_len += 7; /* align on byte boundary */ 998 +#endif 999 + } 1000 + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, 1001 + s->compressed_len-7*last)); 1002 +} 1003 + 1004 +/* =========================================================================== 1005 + * Save the match info and tally the frequency counts. Return true if 1006 + * the current block must be flushed. 1007 + */ 1008 +int ZLIB_INTERNAL _tr_tally (s, dist, lc) 1009 + deflate_state *s; 1010 + unsigned dist; /* distance of matched string */ 1011 + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ 1012 +{ 1013 + s->d_buf[s->last_lit] = (ush)dist; 1014 + s->l_buf[s->last_lit++] = (uch)lc; 1015 + if (dist == 0) { 1016 + /* lc is the unmatched char */ 1017 + s->dyn_ltree[lc].Freq++; 1018 + } else { 1019 + s->matches++; 1020 + /* Here, lc is the match length - MIN_MATCH */ 1021 + dist--; /* dist = match distance - 1 */ 1022 + Assert((ush)dist < (ush)MAX_DIST(s) && 1023 + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && 1024 + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); 1025 + 1026 + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; 1027 + s->dyn_dtree[d_code(dist)].Freq++; 1028 + } 1029 + 1030 +#ifdef TRUNCATE_BLOCK 1031 + /* Try to guess if it is profitable to stop the current block here */ 1032 + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { 1033 + /* Compute an upper bound for the compressed length */ 1034 + ulg out_length = (ulg)s->last_lit*8L; 1035 + ulg in_length = (ulg)((long)s->strstart - s->block_start); 1036 + int dcode; 1037 + for (dcode = 0; dcode < D_CODES; dcode++) { 1038 + out_length += (ulg)s->dyn_dtree[dcode].Freq * 1039 + (5L+extra_dbits[dcode]); 1040 + } 1041 + out_length >>= 3; 1042 + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", 1043 + s->last_lit, in_length, out_length, 1044 + 100L - out_length*100L/in_length)); 1045 + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; 1046 + } 1047 +#endif 1048 + return (s->last_lit == s->lit_bufsize-1); 1049 + /* We avoid equality with lit_bufsize because of wraparound at 64K 1050 + * on 16 bit machines and because stored blocks are restricted to 1051 + * 64K-1 bytes. 1052 + */ 1053 +} 1054 + 1055 +/* =========================================================================== 1056 + * Send the block data compressed using the given Huffman trees 1057 + */ 1058 +local void compress_block(s, ltree, dtree) 1059 + deflate_state *s; 1060 + ct_data *ltree; /* literal tree */ 1061 + ct_data *dtree; /* distance tree */ 1062 +{ 1063 + unsigned dist; /* distance of matched string */ 1064 + int lc; /* match length or unmatched char (if dist == 0) */ 1065 + unsigned lx = 0; /* running index in l_buf */ 1066 + unsigned code; /* the code to send */ 1067 + int extra; /* number of extra bits to send */ 1068 + 1069 + if (s->last_lit != 0) do { 1070 + dist = s->d_buf[lx]; 1071 + lc = s->l_buf[lx++]; 1072 + if (dist == 0) { 1073 + send_code(s, lc, ltree); /* send a literal byte */ 1074 + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); 1075 + } else { 1076 + /* Here, lc is the match length - MIN_MATCH */ 1077 + code = _length_code[lc]; 1078 + send_code(s, code+LITERALS+1, ltree); /* send the length code */ 1079 + extra = extra_lbits[code]; 1080 + if (extra != 0) { 1081 + lc -= base_length[code]; 1082 + send_bits(s, lc, extra); /* send the extra length bits */ 1083 + } 1084 + dist--; /* dist is now the match distance - 1 */ 1085 + code = d_code(dist); 1086 + Assert (code < D_CODES, "bad d_code"); 1087 + 1088 + send_code(s, code, dtree); /* send the distance code */ 1089 + extra = extra_dbits[code]; 1090 + if (extra != 0) { 1091 + dist -= base_dist[code]; 1092 + send_bits(s, dist, extra); /* send the extra distance bits */ 1093 + } 1094 + } /* literal or match pair ? */ 1095 + 1096 + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ 1097 + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, 1098 + "pendingBuf overflow"); 1099 + 1100 + } while (lx < s->last_lit); 1101 + 1102 + send_code(s, END_BLOCK, ltree); 1103 +} 1104 + 1105 +/* =========================================================================== 1106 + * Check if the data type is TEXT or BINARY, using the following algorithm: 1107 + * - TEXT if the two conditions below are satisfied: 1108 + * a) There are no non-portable control characters belonging to the 1109 + * "black list" (0..6, 14..25, 28..31). 1110 + * b) There is at least one printable character belonging to the 1111 + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). 1112 + * - BINARY otherwise. 1113 + * - The following partially-portable control characters form a 1114 + * "gray list" that is ignored in this detection algorithm: 1115 + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). 1116 + * IN assertion: the fields Freq of dyn_ltree are set. 1117 + */ 1118 +local int detect_data_type(s) 1119 + deflate_state *s; 1120 +{ 1121 + /* black_mask is the bit mask of black-listed bytes 1122 + * set bits 0..6, 14..25, and 28..31 1123 + * 0xf3ffc07f = binary 11110011111111111100000001111111 1124 + */ 1125 + unsigned long black_mask = 0xf3ffc07fUL; 1126 + int n; 1127 + 1128 + /* Check for non-textual ("black-listed") bytes. */ 1129 + for (n = 0; n <= 31; n++, black_mask >>= 1) 1130 + if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) 1131 + return Z_BINARY; 1132 + 1133 + /* Check for textual ("white-listed") bytes. */ 1134 + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 1135 + || s->dyn_ltree[13].Freq != 0) 1136 + return Z_TEXT; 1137 + for (n = 32; n < LITERALS; n++) 1138 + if (s->dyn_ltree[n].Freq != 0) 1139 + return Z_TEXT; 1140 + 1141 + /* There are no "black-listed" or "white-listed" bytes: 1142 + * this stream either is empty or has tolerated ("gray-listed") bytes only. 1143 + */ 1144 + return Z_BINARY; 1145 +} 1146 + 1147 +/* =========================================================================== 1148 + * Reverse the first len bits of a code, using straightforward code (a faster 1149 + * method would use a table) 1150 + * IN assertion: 1 <= len <= 15 1151 + */ 1152 +local unsigned bi_reverse(code, len) 1153 + unsigned code; /* the value to invert */ 1154 + int len; /* its bit length */ 1155 +{ 1156 + register unsigned res = 0; 1157 + do { 1158 + res |= code & 1; 1159 + code >>= 1, res <<= 1; 1160 + } while (--len > 0); 1161 + return res >> 1; 1162 +} 1163 + 1164 +/* =========================================================================== 1165 + * Flush the bit buffer, keeping at most 7 bits in it. 1166 + */ 1167 +local void bi_flush(s) 1168 + deflate_state *s; 1169 +{ 1170 + if (s->bi_valid == 16) { 1171 + put_short(s, s->bi_buf); 1172 + s->bi_buf = 0; 1173 + s->bi_valid = 0; 1174 + } else if (s->bi_valid >= 8) { 1175 + put_byte(s, (Byte)s->bi_buf); 1176 + s->bi_buf >>= 8; 1177 + s->bi_valid -= 8; 1178 + } 1179 +} 1180 + 1181 +/* =========================================================================== 1182 + * Flush the bit buffer and align the output on a byte boundary 1183 + */ 1184 +local void bi_windup(s) 1185 + deflate_state *s; 1186 +{ 1187 + if (s->bi_valid > 8) { 1188 + put_short(s, s->bi_buf); 1189 + } else if (s->bi_valid > 0) { 1190 + put_byte(s, (Byte)s->bi_buf); 1191 + } 1192 + s->bi_buf = 0; 1193 + s->bi_valid = 0; 1194 +#ifdef DEBUG 1195 + s->bits_sent = (s->bits_sent+7) & ~7; 1196 +#endif 1197 +} 1198 + 1199 +/* =========================================================================== 1200 + * Copy a stored block, storing first the length and its 1201 + * one's complement if requested. 1202 + */ 1203 +local void copy_block(s, buf, len, header) 1204 + deflate_state *s; 1205 + charf *buf; /* the input data */ 1206 + unsigned len; /* its length */ 1207 + int header; /* true if block header must be written */ 1208 +{ 1209 + bi_windup(s); /* align on byte boundary */ 1210 + 1211 + if (header) { 1212 + put_short(s, (ush)len); 1213 + put_short(s, (ush)~len); 1214 +#ifdef DEBUG 1215 + s->bits_sent += 2*16; 1216 +#endif 1217 + } 1218 +#ifdef DEBUG 1219 + s->bits_sent += (ulg)len<<3; 1220 +#endif 1221 + while (len--) { 1222 + put_byte(s, *buf++); 1223 + } 1224 +}
Added compat/zlib/trees.h.
1 +/* header created automatically with -DGEN_TREES_H */ 2 + 3 +local const ct_data static_ltree[L_CODES+2] = { 4 +{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 +{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 +{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 +{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 +{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 +{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 +{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 +{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 +{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 +{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 +{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 +{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 +{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 +{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 +{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 +{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 +{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 +{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 +{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 +{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 +{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 +{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 +{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 +{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 +{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 +{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 +{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 +{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 +{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 +{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 +{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 +{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 +{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 +{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 +{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 +{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 +{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 +{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 +{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 +{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 +{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 +{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 +{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 +{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 +{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 +{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 +{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 +{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 +{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 +{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 +{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 +{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 +{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 +{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 +{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 +{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 +{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 +{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 +}; 63 + 64 +local const ct_data static_dtree[D_CODES] = { 65 +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 +}; 72 + 73 +const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 +}; 101 + 102 +const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 +}; 117 + 118 +local const int base_length[LENGTH_CODES] = { 119 +0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 +64, 80, 96, 112, 128, 160, 192, 224, 0 121 +}; 122 + 123 +local const int base_dist[D_CODES] = { 124 + 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 + 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 + 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 +}; 128 +
Added compat/zlib/uncompr.c.
1 +/* uncompr.c -- decompress a memory buffer 2 + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#define ZLIB_INTERNAL 9 +#include "zlib.h" 10 + 11 +/* =========================================================================== 12 + Decompresses the source buffer into the destination buffer. sourceLen is 13 + the byte length of the source buffer. Upon entry, destLen is the total 14 + size of the destination buffer, which must be large enough to hold the 15 + entire uncompressed data. (The size of the uncompressed data must have 16 + been saved previously by the compressor and transmitted to the decompressor 17 + by some mechanism outside the scope of this compression library.) 18 + Upon exit, destLen is the actual size of the compressed buffer. 19 + 20 + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 + enough memory, Z_BUF_ERROR if there was not enough room in the output 22 + buffer, or Z_DATA_ERROR if the input data was corrupted. 23 +*/ 24 +int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 + Bytef *dest; 26 + uLongf *destLen; 27 + const Bytef *source; 28 + uLong sourceLen; 29 +{ 30 + z_stream stream; 31 + int err; 32 + 33 + stream.next_in = (Bytef*)source; 34 + stream.avail_in = (uInt)sourceLen; 35 + /* Check for source > 64K on 16-bit machine: */ 36 + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 + 38 + stream.next_out = dest; 39 + stream.avail_out = (uInt)*destLen; 40 + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 + 42 + stream.zalloc = (alloc_func)0; 43 + stream.zfree = (free_func)0; 44 + 45 + err = inflateInit(&stream); 46 + if (err != Z_OK) return err; 47 + 48 + err = inflate(&stream, Z_FINISH); 49 + if (err != Z_STREAM_END) { 50 + inflateEnd(&stream); 51 + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 + return Z_DATA_ERROR; 53 + return err; 54 + } 55 + *destLen = stream.total_out; 56 + 57 + err = inflateEnd(&stream); 58 + return err; 59 +}
Added compat/zlib/watcom/watcom_f.mak.
1 +# Makefile for zlib 2 +# OpenWatcom flat model 3 +# Last updated: 28-Dec-2005 4 + 5 +# To use, do "wmake -f watcom_f.mak" 6 + 7 +C_SOURCE = adler32.c compress.c crc32.c deflate.c & 8 + gzclose.c gzlib.c gzread.c gzwrite.c & 9 + infback.c inffast.c inflate.c inftrees.c & 10 + trees.c uncompr.c zutil.c 11 + 12 +OBJS = adler32.obj compress.obj crc32.obj deflate.obj & 13 + gzclose.obj gzlib.obj gzread.obj gzwrite.obj & 14 + infback.obj inffast.obj inflate.obj inftrees.obj & 15 + trees.obj uncompr.obj zutil.obj 16 + 17 +CC = wcc386 18 +LINKER = wcl386 19 +CFLAGS = -zq -mf -3r -fp3 -s -bt=dos -oilrtfm -fr=nul -wx 20 +ZLIB_LIB = zlib_f.lib 21 + 22 +.C.OBJ: 23 + $(CC) $(CFLAGS) $[@ 24 + 25 +all: $(ZLIB_LIB) example.exe minigzip.exe 26 + 27 +$(ZLIB_LIB): $(OBJS) 28 + wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj 29 + wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj 30 + wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj 31 + wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj 32 + wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj 33 + 34 +example.exe: $(ZLIB_LIB) example.obj 35 + $(LINKER) -ldos32a -fe=example.exe example.obj $(ZLIB_LIB) 36 + 37 +minigzip.exe: $(ZLIB_LIB) minigzip.obj 38 + $(LINKER) -ldos32a -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) 39 + 40 +clean: .SYMBOLIC 41 + del *.obj 42 + del $(ZLIB_LIB) 43 + @echo Cleaning done
Added compat/zlib/watcom/watcom_l.mak.
1 +# Makefile for zlib 2 +# OpenWatcom large model 3 +# Last updated: 28-Dec-2005 4 + 5 +# To use, do "wmake -f watcom_l.mak" 6 + 7 +C_SOURCE = adler32.c compress.c crc32.c deflate.c & 8 + gzclose.c gzlib.c gzread.c gzwrite.c & 9 + infback.c inffast.c inflate.c inftrees.c & 10 + trees.c uncompr.c zutil.c 11 + 12 +OBJS = adler32.obj compress.obj crc32.obj deflate.obj & 13 + gzclose.obj gzlib.obj gzread.obj gzwrite.obj & 14 + infback.obj inffast.obj inflate.obj inftrees.obj & 15 + trees.obj uncompr.obj zutil.obj 16 + 17 +CC = wcc 18 +LINKER = wcl 19 +CFLAGS = -zq -ml -s -bt=dos -oilrtfm -fr=nul -wx 20 +ZLIB_LIB = zlib_l.lib 21 + 22 +.C.OBJ: 23 + $(CC) $(CFLAGS) $[@ 24 + 25 +all: $(ZLIB_LIB) example.exe minigzip.exe 26 + 27 +$(ZLIB_LIB): $(OBJS) 28 + wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj 29 + wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj 30 + wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj 31 + wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj 32 + wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj 33 + 34 +example.exe: $(ZLIB_LIB) example.obj 35 + $(LINKER) -fe=example.exe example.obj $(ZLIB_LIB) 36 + 37 +minigzip.exe: $(ZLIB_LIB) minigzip.obj 38 + $(LINKER) -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) 39 + 40 +clean: .SYMBOLIC 41 + del *.obj 42 + del $(ZLIB_LIB) 43 + @echo Cleaning done
Added compat/zlib/win32/DLL_FAQ.txt.
1 + 2 + Frequently Asked Questions about ZLIB1.DLL 3 + 4 + 5 +This document describes the design, the rationale, and the usage 6 +of the official DLL build of zlib, named ZLIB1.DLL. If you have 7 +general questions about zlib, you should see the file "FAQ" found 8 +in the zlib distribution, or at the following location: 9 + http://www.gzip.org/zlib/zlib_faq.html 10 + 11 + 12 + 1. What is ZLIB1.DLL, and how can I get it? 13 + 14 + - ZLIB1.DLL is the official build of zlib as a DLL. 15 + (Please remark the character '1' in the name.) 16 + 17 + Pointers to a precompiled ZLIB1.DLL can be found in the zlib 18 + web site at: 19 + http://www.zlib.net/ 20 + 21 + Applications that link to ZLIB1.DLL can rely on the following 22 + specification: 23 + 24 + * The exported symbols are exclusively defined in the source 25 + files "zlib.h" and "zlib.def", found in an official zlib 26 + source distribution. 27 + * The symbols are exported by name, not by ordinal. 28 + * The exported names are undecorated. 29 + * The calling convention of functions is "C" (CDECL). 30 + * The ZLIB1.DLL binary is linked to MSVCRT.DLL. 31 + 32 + The archive in which ZLIB1.DLL is bundled contains compiled 33 + test programs that must run with a valid build of ZLIB1.DLL. 34 + It is recommended to download the prebuilt DLL from the zlib 35 + web site, instead of building it yourself, to avoid potential 36 + incompatibilities that could be introduced by your compiler 37 + and build settings. If you do build the DLL yourself, please 38 + make sure that it complies with all the above requirements, 39 + and it runs with the precompiled test programs, bundled with 40 + the original ZLIB1.DLL distribution. 41 + 42 + If, for any reason, you need to build an incompatible DLL, 43 + please use a different file name. 44 + 45 + 46 + 2. Why did you change the name of the DLL to ZLIB1.DLL? 47 + What happened to the old ZLIB.DLL? 48 + 49 + - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required 50 + compilation settings that were incompatible to those used by 51 + a static build. The DLL settings were supposed to be enabled 52 + by defining the macro ZLIB_DLL, before including "zlib.h". 53 + Incorrect handling of this macro was silently accepted at 54 + build time, resulting in two major problems: 55 + 56 + * ZLIB_DLL was missing from the old makefile. When building 57 + the DLL, not all people added it to the build options. In 58 + consequence, incompatible incarnations of ZLIB.DLL started 59 + to circulate around the net. 60 + 61 + * When switching from using the static library to using the 62 + DLL, applications had to define the ZLIB_DLL macro and 63 + to recompile all the sources that contained calls to zlib 64 + functions. Failure to do so resulted in creating binaries 65 + that were unable to run with the official ZLIB.DLL build. 66 + 67 + The only possible solution that we could foresee was to make 68 + a binary-incompatible change in the DLL interface, in order to 69 + remove the dependency on the ZLIB_DLL macro, and to release 70 + the new DLL under a different name. 71 + 72 + We chose the name ZLIB1.DLL, where '1' indicates the major 73 + zlib version number. We hope that we will not have to break 74 + the binary compatibility again, at least not as long as the 75 + zlib-1.x series will last. 76 + 77 + There is still a ZLIB_DLL macro, that can trigger a more 78 + efficient build and use of the DLL, but compatibility no 79 + longer dependents on it. 80 + 81 + 82 + 3. Can I build ZLIB.DLL from the new zlib sources, and replace 83 + an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier? 84 + 85 + - In principle, you can do it by assigning calling convention 86 + keywords to the macros ZEXPORT and ZEXPORTVA. In practice, 87 + it depends on what you mean by "an old ZLIB.DLL", because the 88 + old DLL exists in several mutually-incompatible versions. 89 + You have to find out first what kind of calling convention is 90 + being used in your particular ZLIB.DLL build, and to use the 91 + same one in the new build. If you don't know what this is all 92 + about, you might be better off if you would just leave the old 93 + DLL intact. 94 + 95 + 96 + 4. Can I compile my application using the new zlib interface, and 97 + link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or 98 + earlier? 99 + 100 + - The official answer is "no"; the real answer depends again on 101 + what kind of ZLIB.DLL you have. Even if you are lucky, this 102 + course of action is unreliable. 103 + 104 + If you rebuild your application and you intend to use a newer 105 + version of zlib (post- 1.1.4), it is strongly recommended to 106 + link it to the new ZLIB1.DLL. 107 + 108 + 109 + 5. Why are the zlib symbols exported by name, and not by ordinal? 110 + 111 + - Although exporting symbols by ordinal is a little faster, it 112 + is risky. Any single glitch in the maintenance or use of the 113 + DEF file that contains the ordinals can result in incompatible 114 + builds and frustrating crashes. Simply put, the benefits of 115 + exporting symbols by ordinal do not justify the risks. 116 + 117 + Technically, it should be possible to maintain ordinals in 118 + the DEF file, and still export the symbols by name. Ordinals 119 + exist in every DLL, and even if the dynamic linking performed 120 + at the DLL startup is searching for names, ordinals serve as 121 + hints, for a faster name lookup. However, if the DEF file 122 + contains ordinals, the Microsoft linker automatically builds 123 + an implib that will cause the executables linked to it to use 124 + those ordinals, and not the names. It is interesting to 125 + notice that the GNU linker for Win32 does not suffer from this 126 + problem. 127 + 128 + It is possible to avoid the DEF file if the exported symbols 129 + are accompanied by a "__declspec(dllexport)" attribute in the 130 + source files. You can do this in zlib by predefining the 131 + ZLIB_DLL macro. 132 + 133 + 134 + 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling 135 + convention. Why not use the STDCALL convention? 136 + STDCALL is the standard convention in Win32, and I need it in 137 + my Visual Basic project! 138 + 139 + (For readability, we use CDECL to refer to the convention 140 + triggered by the "__cdecl" keyword, STDCALL to refer to 141 + the convention triggered by "__stdcall", and FASTCALL to 142 + refer to the convention triggered by "__fastcall".) 143 + 144 + - Most of the native Windows API functions (without varargs) use 145 + indeed the WINAPI convention (which translates to STDCALL in 146 + Win32), but the standard C functions use CDECL. If a user 147 + application is intrinsically tied to the Windows API (e.g. 148 + it calls native Windows API functions such as CreateFile()), 149 + sometimes it makes sense to decorate its own functions with 150 + WINAPI. But if ANSI C or POSIX portability is a goal (e.g. 151 + it calls standard C functions such as fopen()), it is not a 152 + sound decision to request the inclusion of <windows.h>, or to 153 + use non-ANSI constructs, for the sole purpose to make the user 154 + functions STDCALL-able. 155 + 156 + The functionality offered by zlib is not in the category of 157 + "Windows functionality", but is more like "C functionality". 158 + 159 + Technically, STDCALL is not bad; in fact, it is slightly 160 + faster than CDECL, and it works with variable-argument 161 + functions, just like CDECL. It is unfortunate that, in spite 162 + of using STDCALL in the Windows API, it is not the default 163 + convention used by the C compilers that run under Windows. 164 + The roots of the problem reside deep inside the unsafety of 165 + the K&R-style function prototypes, where the argument types 166 + are not specified; but that is another story for another day. 167 + 168 + The remaining fact is that CDECL is the default convention. 169 + Even if an explicit convention is hard-coded into the function 170 + prototypes inside C headers, problems may appear. The 171 + necessity to expose the convention in users' callbacks is one 172 + of these problems. 173 + 174 + The calling convention issues are also important when using 175 + zlib in other programming languages. Some of them, like Ada 176 + (GNAT) and Fortran (GNU G77), have C bindings implemented 177 + initially on Unix, and relying on the C calling convention. 178 + On the other hand, the pre- .NET versions of Microsoft Visual 179 + Basic require STDCALL, while Borland Delphi prefers, although 180 + it does not require, FASTCALL. 181 + 182 + In fairness to all possible uses of zlib outside the C 183 + programming language, we choose the default "C" convention. 184 + Anyone interested in different bindings or conventions is 185 + encouraged to maintain specialized projects. The "contrib/" 186 + directory from the zlib distribution already holds a couple 187 + of foreign bindings, such as Ada, C++, and Delphi. 188 + 189 + 190 + 7. I need a DLL for my Visual Basic project. What can I do? 191 + 192 + - Define the ZLIB_WINAPI macro before including "zlib.h", when 193 + building both the DLL and the user application (except that 194 + you don't need to define anything when using the DLL in Visual 195 + Basic). The ZLIB_WINAPI macro will switch on the WINAPI 196 + (STDCALL) convention. The name of this DLL must be different 197 + than the official ZLIB1.DLL. 198 + 199 + Gilles Vollant has contributed a build named ZLIBWAPI.DLL, 200 + with the ZLIB_WINAPI macro turned on, and with the minizip 201 + functionality built in. For more information, please read 202 + the notes inside "contrib/vstudio/readme.txt", found in the 203 + zlib distribution. 204 + 205 + 206 + 8. I need to use zlib in my Microsoft .NET project. What can I 207 + do? 208 + 209 + - Henrik Ravn has contributed a .NET wrapper around zlib. Look 210 + into contrib/dotzlib/, inside the zlib distribution. 211 + 212 + 213 + 9. If my application uses ZLIB1.DLL, should I link it to 214 + MSVCRT.DLL? Why? 215 + 216 + - It is not required, but it is recommended to link your 217 + application to MSVCRT.DLL, if it uses ZLIB1.DLL. 218 + 219 + The executables (.EXE, .DLL, etc.) that are involved in the 220 + same process and are using the C run-time library (i.e. they 221 + are calling standard C functions), must link to the same 222 + library. There are several libraries in the Win32 system: 223 + CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc. 224 + Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that 225 + depend on it should also be linked to MSVCRT.DLL. 226 + 227 + 228 +10. Why are you saying that ZLIB1.DLL and my application should 229 + be linked to the same C run-time (CRT) library? I linked my 230 + application and my DLLs to different C libraries (e.g. my 231 + application to a static library, and my DLLs to MSVCRT.DLL), 232 + and everything works fine. 233 + 234 + - If a user library invokes only pure Win32 API (accessible via 235 + <windows.h> and the related headers), its DLL build will work 236 + in any context. But if this library invokes standard C API, 237 + things get more complicated. 238 + 239 + There is a single Win32 library in a Win32 system. Every 240 + function in this library resides in a single DLL module, that 241 + is safe to call from anywhere. On the other hand, there are 242 + multiple versions of the C library, and each of them has its 243 + own separate internal state. Standalone executables and user 244 + DLLs that call standard C functions must link to a C run-time 245 + (CRT) library, be it static or shared (DLL). Intermixing 246 + occurs when an executable (not necessarily standalone) and a 247 + DLL are linked to different CRTs, and both are running in the 248 + same process. 249 + 250 + Intermixing multiple CRTs is possible, as long as their 251 + internal states are kept intact. The Microsoft Knowledge Base 252 + articles KB94248 "HOWTO: Use the C Run-Time" and KB140584 253 + "HOWTO: Link with the Correct C Run-Time (CRT) Library" 254 + mention the potential problems raised by intermixing. 255 + 256 + If intermixing works for you, it's because your application 257 + and DLLs are avoiding the corruption of each of the CRTs' 258 + internal states, maybe by careful design, or maybe by fortune. 259 + 260 + Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such 261 + as those provided by Borland, raises similar problems. 262 + 263 + 264 +11. Why are you linking ZLIB1.DLL to MSVCRT.DLL? 265 + 266 + - MSVCRT.DLL exists on every Windows 95 with a new service pack 267 + installed, or with Microsoft Internet Explorer 4 or later, and 268 + on all other Windows 4.x or later (Windows 98, Windows NT 4, 269 + or later). It is freely distributable; if not present in the 270 + system, it can be downloaded from Microsoft or from other 271 + software provider for free. 272 + 273 + The fact that MSVCRT.DLL does not exist on a virgin Windows 95 274 + is not so problematic. Windows 95 is scarcely found nowadays, 275 + Microsoft ended its support a long time ago, and many recent 276 + applications from various vendors, including Microsoft, do not 277 + even run on it. Furthermore, no serious user should run 278 + Windows 95 without a proper update installed. 279 + 280 + 281 +12. Why are you not linking ZLIB1.DLL to 282 + <<my favorite C run-time library>> ? 283 + 284 + - We considered and abandoned the following alternatives: 285 + 286 + * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or 287 + LIBCMT.LIB) is not a good option. People are using the DLL 288 + mainly to save disk space. If you are linking your program 289 + to a static C library, you may as well consider linking zlib 290 + in statically, too. 291 + 292 + * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because 293 + CRTDLL.DLL is present on every Win32 installation. 294 + Unfortunately, it has a series of problems: it does not 295 + work properly with Microsoft's C++ libraries, it does not 296 + provide support for 64-bit file offsets, (and so on...), 297 + and Microsoft discontinued its support a long time ago. 298 + 299 + * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied 300 + with the Microsoft .NET platform, and Visual C++ 7.0/7.1, 301 + raises problems related to the status of ZLIB1.DLL as a 302 + system component. According to the Microsoft Knowledge Base 303 + article KB326922 "INFO: Redistribution of the Shared C 304 + Runtime Component in Visual C++ .NET", MSVCR70.DLL and 305 + MSVCR71.DLL are not supposed to function as system DLLs, 306 + because they may clash with MSVCRT.DLL. Instead, the 307 + application's installer is supposed to put these DLLs 308 + (if needed) in the application's private directory. 309 + If ZLIB1.DLL depends on a non-system runtime, it cannot 310 + function as a redistributable system component. 311 + 312 + * Linking ZLIB1.DLL to non-Microsoft runtimes, such as 313 + Borland's, or Cygwin's, raises problems related to the 314 + reliable presence of these runtimes on Win32 systems. 315 + It's easier to let the DLL build of zlib up to the people 316 + who distribute these runtimes, and who may proceed as 317 + explained in the answer to Question 14. 318 + 319 + 320 +13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL, 321 + how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0 322 + (Visual Studio .NET) or newer? 323 + 324 + - Due to the problems explained in the Microsoft Knowledge Base 325 + article KB326922 (see the previous answer), the C runtime that 326 + comes with the VC7 environment is no longer considered a 327 + system component. That is, it should not be assumed that this 328 + runtime exists, or may be installed in a system directory. 329 + Since ZLIB1.DLL is supposed to be a system component, it may 330 + not depend on a non-system component. 331 + 332 + In order to link ZLIB1.DLL and your application to MSVCRT.DLL 333 + in VC7, you need the library of Visual C++ 6.0 or older. If 334 + you don't have this library at hand, it's probably best not to 335 + use ZLIB1.DLL. 336 + 337 + We are hoping that, in the future, Microsoft will provide a 338 + way to build applications linked to a proper system runtime, 339 + from the Visual C++ environment. Until then, you have a 340 + couple of alternatives, such as linking zlib in statically. 341 + If your application requires dynamic linking, you may proceed 342 + as explained in the answer to Question 14. 343 + 344 + 345 +14. I need to link my own DLL build to a CRT different than 346 + MSVCRT.DLL. What can I do? 347 + 348 + - Feel free to rebuild the DLL from the zlib sources, and link 349 + it the way you want. You should, however, clearly state that 350 + your build is unofficial. You should give it a different file 351 + name, and/or install it in a private directory that can be 352 + accessed by your application only, and is not visible to the 353 + others (i.e. it's neither in the PATH, nor in the SYSTEM or 354 + SYSTEM32 directories). Otherwise, your build may clash with 355 + applications that link to the official build. 356 + 357 + For example, in Cygwin, zlib is linked to the Cygwin runtime 358 + CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL. 359 + 360 + 361 +15. May I include additional pieces of code that I find useful, 362 + link them in ZLIB1.DLL, and export them? 363 + 364 + - No. A legitimate build of ZLIB1.DLL must not include code 365 + that does not originate from the official zlib source code. 366 + But you can make your own private DLL build, under a different 367 + file name, as suggested in the previous answer. 368 + 369 + For example, zlib is a part of the VCL library, distributed 370 + with Borland Delphi and C++ Builder. The DLL build of VCL 371 + is a redistributable file, named VCLxx.DLL. 372 + 373 + 374 +16. May I remove some functionality out of ZLIB1.DLL, by enabling 375 + macros like NO_GZCOMPRESS or NO_GZIP at compile time? 376 + 377 + - No. A legitimate build of ZLIB1.DLL must provide the complete 378 + zlib functionality, as implemented in the official zlib source 379 + code. But you can make your own private DLL build, under a 380 + different file name, as suggested in the previous answer. 381 + 382 + 383 +17. I made my own ZLIB1.DLL build. Can I test it for compliance? 384 + 385 + - We prefer that you download the official DLL from the zlib 386 + web site. If you need something peculiar from this DLL, you 387 + can send your suggestion to the zlib mailing list. 388 + 389 + However, in case you do rebuild the DLL yourself, you can run 390 + it with the test programs found in the DLL distribution. 391 + Running these test programs is not a guarantee of compliance, 392 + but a failure can imply a detected problem. 393 + 394 +** 395 + 396 +This document is written and maintained by 397 +Cosmin Truta <cosmint@cs.ubbcluj.ro>
Added compat/zlib/win32/Makefile.bor.
1 +# Makefile for zlib 2 +# Borland C++ for Win32 3 +# 4 +# Usage: 5 +# make -f win32/Makefile.bor 6 +# make -f win32/Makefile.bor LOCAL_ZLIB=-DASMV OBJA=match.obj OBJPA=+match.obj 7 + 8 +# ------------ Borland C++ ------------ 9 + 10 +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) 11 +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or 12 +# added to the declaration of LOC here: 13 +LOC = $(LOCAL_ZLIB) 14 + 15 +CC = bcc32 16 +AS = bcc32 17 +LD = bcc32 18 +AR = tlib 19 +CFLAGS = -a -d -k- -O2 $(LOC) 20 +ASFLAGS = $(LOC) 21 +LDFLAGS = $(LOC) 22 + 23 + 24 +# variables 25 +ZLIB_LIB = zlib.lib 26 + 27 +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj 28 +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 29 +#OBJA = 30 +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj 31 +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj 32 +#OBJPA= 33 + 34 + 35 +# targets 36 +all: $(ZLIB_LIB) example.exe minigzip.exe 37 + 38 +.c.obj: 39 + $(CC) -c $(CFLAGS) $< 40 + 41 +.asm.obj: 42 + $(AS) -c $(ASFLAGS) $< 43 + 44 +adler32.obj: adler32.c zlib.h zconf.h 45 + 46 +compress.obj: compress.c zlib.h zconf.h 47 + 48 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 49 + 50 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 51 + 52 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 53 + 54 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 55 + 56 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 57 + 58 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 59 + 60 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 61 + inffast.h inffixed.h 62 + 63 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 64 + inffast.h 65 + 66 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 67 + inffast.h inffixed.h 68 + 69 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 70 + 71 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 72 + 73 +uncompr.obj: uncompr.c zlib.h zconf.h 74 + 75 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 76 + 77 +example.obj: test/example.c zlib.h zconf.h 78 + 79 +minigzip.obj: test/minigzip.c zlib.h zconf.h 80 + 81 + 82 +# For the sake of the old Borland make, 83 +# the command line is cut to fit in the MS-DOS 128 byte limit: 84 +$(ZLIB_LIB): $(OBJ1) $(OBJ2) $(OBJA) 85 + -del $(ZLIB_LIB) 86 + $(AR) $(ZLIB_LIB) $(OBJP1) 87 + $(AR) $(ZLIB_LIB) $(OBJP2) 88 + $(AR) $(ZLIB_LIB) $(OBJPA) 89 + 90 + 91 +# testing 92 +test: example.exe minigzip.exe 93 + example 94 + echo hello world | minigzip | minigzip -d 95 + 96 +example.exe: example.obj $(ZLIB_LIB) 97 + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) 98 + 99 +minigzip.exe: minigzip.obj $(ZLIB_LIB) 100 + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) 101 + 102 + 103 +# cleanup 104 +clean: 105 + -del $(ZLIB_LIB) 106 + -del *.obj 107 + -del *.exe 108 + -del *.tds 109 + -del zlib.bak 110 + -del foo.gz
Added compat/zlib/win32/Makefile.gcc.
1 +# Makefile for zlib, derived from Makefile.dj2. 2 +# Modified for mingw32 by C. Spieler, 6/16/98. 3 +# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003. 4 +# Last updated: Mar 2012. 5 +# Tested under Cygwin and MinGW. 6 + 7 +# Copyright (C) 1995-2003 Jean-loup Gailly. 8 +# For conditions of distribution and use, see copyright notice in zlib.h 9 + 10 +# To compile, or to compile and test, type from the top level zlib directory: 11 +# 12 +# make -fwin32/Makefile.gcc; make test testdll -fwin32/Makefile.gcc 13 +# 14 +# To use the asm code, type: 15 +# cp contrib/asm?86/match.S ./match.S 16 +# make LOC=-DASMV OBJA=match.o -fwin32/Makefile.gcc 17 +# 18 +# To install libz.a, zconf.h and zlib.h in the system directories, type: 19 +# 20 +# make install -fwin32/Makefile.gcc 21 +# 22 +# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set. 23 +# 24 +# To install the shared lib, append SHARED_MODE=1 to the make command : 25 +# 26 +# make install -fwin32/Makefile.gcc SHARED_MODE=1 27 + 28 +# Note: 29 +# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN), 30 +# the DLL name should be changed from "zlib1.dll". 31 + 32 +STATICLIB = libz.a 33 +SHAREDLIB = zlib1.dll 34 +IMPLIB = libz.dll.a 35 + 36 +# 37 +# Set to 1 if shared object needs to be installed 38 +# 39 +SHARED_MODE=0 40 + 41 +#LOC = -DASMV 42 +#LOC = -DDEBUG -g 43 + 44 +PREFIX = 45 +CC = $(PREFIX)gcc 46 +CFLAGS = $(LOC) -O3 -Wall 47 + 48 +AS = $(CC) 49 +ASFLAGS = $(LOC) -Wall 50 + 51 +LD = $(CC) 52 +LDFLAGS = $(LOC) 53 + 54 +AR = $(PREFIX)ar 55 +ARFLAGS = rcs 56 + 57 +RC = $(PREFIX)windres 58 +RCFLAGS = --define GCC_WINDRES 59 + 60 +STRIP = $(PREFIX)strip 61 + 62 +CP = cp -fp 63 +# If GNU install is available, replace $(CP) with install. 64 +INSTALL = $(CP) 65 +RM = rm -f 66 + 67 +prefix ?= /usr/local 68 +exec_prefix = $(prefix) 69 + 70 +OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ 71 + gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 72 +OBJA = 73 + 74 +all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe 75 + 76 +test: example.exe minigzip.exe 77 + ./example 78 + echo hello world | ./minigzip | ./minigzip -d 79 + 80 +testdll: example_d.exe minigzip_d.exe 81 + ./example_d 82 + echo hello world | ./minigzip_d | ./minigzip_d -d 83 + 84 +.c.o: 85 + $(CC) $(CFLAGS) -c -o $@ $< 86 + 87 +.S.o: 88 + $(AS) $(ASFLAGS) -c -o $@ $< 89 + 90 +$(STATICLIB): $(OBJS) $(OBJA) 91 + $(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA) 92 + 93 +$(IMPLIB): $(SHAREDLIB) 94 + 95 +$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o 96 + $(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \ 97 + -o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o 98 + $(STRIP) $@ 99 + 100 +example.exe: example.o $(STATICLIB) 101 + $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) 102 + $(STRIP) $@ 103 + 104 +minigzip.exe: minigzip.o $(STATICLIB) 105 + $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) 106 + $(STRIP) $@ 107 + 108 +example_d.exe: example.o $(IMPLIB) 109 + $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) 110 + $(STRIP) $@ 111 + 112 +minigzip_d.exe: minigzip.o $(IMPLIB) 113 + $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) 114 + $(STRIP) $@ 115 + 116 +example.o: test/example.c zlib.h zconf.h 117 + $(CC) $(CFLAGS) -I. -c -o $@ test/example.c 118 + 119 +minigzip.o: test/minigzip.c zlib.h zconf.h 120 + $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c 121 + 122 +zlibrc.o: win32/zlib1.rc 123 + $(RC) $(RCFLAGS) -o $@ win32/zlib1.rc 124 + 125 +.PHONY: install uninstall clean 126 + 127 +install: zlib.h zconf.h $(STATICLIB) $(IMPLIB) 128 + @if test -z "$(DESTDIR)$(INCLUDE_PATH)" -o -z "$(DESTDIR)$(LIBRARY_PATH)" -o -z "$(DESTDIR)$(BINARY_PATH)"; then \ 129 + echo INCLUDE_PATH, LIBRARY_PATH, and BINARY_PATH must be specified; \ 130 + exit 1; \ 131 + fi 132 + -@mkdir -p '$(DESTDIR)$(INCLUDE_PATH)' 133 + -@mkdir -p '$(DESTDIR)$(LIBRARY_PATH)' '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig 134 + -if [ "$(SHARED_MODE)" = "1" ]; then \ 135 + mkdir -p '$(DESTDIR)$(BINARY_PATH)'; \ 136 + $(INSTALL) $(SHAREDLIB) '$(DESTDIR)$(BINARY_PATH)'; \ 137 + $(INSTALL) $(IMPLIB) '$(DESTDIR)$(LIBRARY_PATH)'; \ 138 + fi 139 + -$(INSTALL) zlib.h '$(DESTDIR)$(INCLUDE_PATH)' 140 + -$(INSTALL) zconf.h '$(DESTDIR)$(INCLUDE_PATH)' 141 + -$(INSTALL) $(STATICLIB) '$(DESTDIR)$(LIBRARY_PATH)' 142 + sed \ 143 + -e 's|@prefix@|${prefix}|g' \ 144 + -e 's|@exec_prefix@|${exec_prefix}|g' \ 145 + -e 's|@libdir@|$(LIBRARY_PATH)|g' \ 146 + -e 's|@sharedlibdir@|$(LIBRARY_PATH)|g' \ 147 + -e 's|@includedir@|$(INCLUDE_PATH)|g' \ 148 + -e 's|@VERSION@|'`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' zlib.h`'|g' \ 149 + zlib.pc.in > '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig/zlib.pc 150 + 151 +uninstall: 152 + -if [ "$(SHARED_MODE)" = "1" ]; then \ 153 + $(RM) '$(DESTDIR)$(BINARY_PATH)'/$(SHAREDLIB); \ 154 + $(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(IMPLIB); \ 155 + fi 156 + -$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zlib.h 157 + -$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zconf.h 158 + -$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(STATICLIB) 159 + 160 +clean: 161 + -$(RM) $(STATICLIB) 162 + -$(RM) $(SHAREDLIB) 163 + -$(RM) $(IMPLIB) 164 + -$(RM) *.o 165 + -$(RM) *.exe 166 + -$(RM) foo.gz 167 + 168 +adler32.o: zlib.h zconf.h 169 +compress.o: zlib.h zconf.h 170 +crc32.o: crc32.h zlib.h zconf.h 171 +deflate.o: deflate.h zutil.h zlib.h zconf.h 172 +gzclose.o: zlib.h zconf.h gzguts.h 173 +gzlib.o: zlib.h zconf.h gzguts.h 174 +gzread.o: zlib.h zconf.h gzguts.h 175 +gzwrite.o: zlib.h zconf.h gzguts.h 176 +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 177 +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 178 +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h 179 +inftrees.o: zutil.h zlib.h zconf.h inftrees.h 180 +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h 181 +uncompr.o: zlib.h zconf.h 182 +zutil.o: zutil.h zlib.h zconf.h
Added compat/zlib/win32/Makefile.msc.
1 +# Makefile for zlib using Microsoft (Visual) C 2 +# zlib is copyright (C) 1995-2006 Jean-loup Gailly and Mark Adler 3 +# 4 +# Usage: 5 +# nmake -f win32/Makefile.msc (standard build) 6 +# nmake -f win32/Makefile.msc LOC=-DFOO (nonstandard build) 7 +# nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" \ 8 +# OBJA="inffas32.obj match686.obj" (use ASM code, x86) 9 +# nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." \ 10 +# OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" (use ASM code, x64) 11 + 12 +# optional build flags 13 +LOC = 14 + 15 +# variables 16 +STATICLIB = zlib.lib 17 +SHAREDLIB = zlib1.dll 18 +IMPLIB = zdll.lib 19 + 20 +CC = cl 21 +AS = ml 22 +LD = link 23 +AR = lib 24 +RC = rc 25 +CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) 26 +WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE 27 +ASFLAGS = -coff -Zi $(LOC) 28 +LDFLAGS = -nologo -debug -incremental:no -opt:ref 29 +ARFLAGS = -nologo 30 +RCFLAGS = /dWIN32 /r 31 + 32 +OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj \ 33 + gzwrite.obj infback.obj inflate.obj inftrees.obj inffast.obj trees.obj uncompr.obj zutil.obj 34 +OBJA = 35 + 36 + 37 +# targets 38 +all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \ 39 + example.exe minigzip.exe example_d.exe minigzip_d.exe 40 + 41 +$(STATICLIB): $(OBJS) $(OBJA) 42 + $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA) 43 + 44 +$(IMPLIB): $(SHAREDLIB) 45 + 46 +$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlib1.res 47 + $(LD) $(LDFLAGS) -def:win32/zlib.def -dll -implib:$(IMPLIB) \ 48 + -out:$@ -base:0x5A4C0000 $(OBJS) $(OBJA) zlib1.res 49 + if exist $@.manifest \ 50 + mt -nologo -manifest $@.manifest -outputresource:$@;2 51 + 52 +example.exe: example.obj $(STATICLIB) 53 + $(LD) $(LDFLAGS) example.obj $(STATICLIB) 54 + if exist $@.manifest \ 55 + mt -nologo -manifest $@.manifest -outputresource:$@;1 56 + 57 +minigzip.exe: minigzip.obj $(STATICLIB) 58 + $(LD) $(LDFLAGS) minigzip.obj $(STATICLIB) 59 + if exist $@.manifest \ 60 + mt -nologo -manifest $@.manifest -outputresource:$@;1 61 + 62 +example_d.exe: example.obj $(IMPLIB) 63 + $(LD) $(LDFLAGS) -out:$@ example.obj $(IMPLIB) 64 + if exist $@.manifest \ 65 + mt -nologo -manifest $@.manifest -outputresource:$@;1 66 + 67 +minigzip_d.exe: minigzip.obj $(IMPLIB) 68 + $(LD) $(LDFLAGS) -out:$@ minigzip.obj $(IMPLIB) 69 + if exist $@.manifest \ 70 + mt -nologo -manifest $@.manifest -outputresource:$@;1 71 + 72 +.c.obj: 73 + $(CC) -c $(WFLAGS) $(CFLAGS) $< 74 + 75 +{test}.c.obj: 76 + $(CC) -c -I. $(WFLAGS) $(CFLAGS) $< 77 + 78 +{contrib/masmx64}.c.obj: 79 + $(CC) -c $(WFLAGS) $(CFLAGS) $< 80 + 81 +{contrib/masmx64}.asm.obj: 82 + $(AS) -c $(ASFLAGS) $< 83 + 84 +{contrib/masmx86}.asm.obj: 85 + $(AS) -c $(ASFLAGS) $< 86 + 87 +adler32.obj: adler32.c zlib.h zconf.h 88 + 89 +compress.obj: compress.c zlib.h zconf.h 90 + 91 +crc32.obj: crc32.c zlib.h zconf.h crc32.h 92 + 93 +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h 94 + 95 +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h 96 + 97 +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h 98 + 99 +gzread.obj: gzread.c zlib.h zconf.h gzguts.h 100 + 101 +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h 102 + 103 +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 104 + inffast.h inffixed.h 105 + 106 +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 107 + inffast.h 108 + 109 +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ 110 + inffast.h inffixed.h 111 + 112 +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h 113 + 114 +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h 115 + 116 +uncompr.obj: uncompr.c zlib.h zconf.h 117 + 118 +zutil.obj: zutil.c zutil.h zlib.h zconf.h 119 + 120 +gvmat64.obj: contrib\masmx64\gvmat64.asm 121 + 122 +inffasx64.obj: contrib\masmx64\inffasx64.asm 123 + 124 +inffas8664.obj: contrib\masmx64\inffas8664.c zutil.h zlib.h zconf.h \ 125 + inftrees.h inflate.h inffast.h 126 + 127 +inffas32.obj: contrib\masmx86\inffas32.asm 128 + 129 +match686.obj: contrib\masmx86\match686.asm 130 + 131 +example.obj: test/example.c zlib.h zconf.h 132 + 133 +minigzip.obj: test/minigzip.c zlib.h zconf.h 134 + 135 +zlib1.res: win32/zlib1.rc 136 + $(RC) $(RCFLAGS) /fo$@ win32/zlib1.rc 137 + 138 + 139 +# testing 140 +test: example.exe minigzip.exe 141 + example 142 + echo hello world | minigzip | minigzip -d 143 + 144 +testdll: example_d.exe minigzip_d.exe 145 + example_d 146 + echo hello world | minigzip_d | minigzip_d -d 147 + 148 + 149 +# cleanup 150 +clean: 151 + -del $(STATICLIB) 152 + -del $(SHAREDLIB) 153 + -del $(IMPLIB) 154 + -del *.obj 155 + -del *.res 156 + -del *.exp 157 + -del *.exe 158 + -del *.pdb 159 + -del *.manifest 160 + -del foo.gz
Added compat/zlib/win32/README-WIN32.txt.
1 +ZLIB DATA COMPRESSION LIBRARY 2 + 3 +zlib 1.2.7 is a general purpose data compression library. All the code is 4 +thread safe. The data format used by the zlib library is described by RFCs 5 +(Request for Comments) 1950 to 1952 in the files 6 +http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) 7 +and rfc1952.txt (gzip format). 8 + 9 +All functions of the compression library are documented in the file zlib.h 10 +(volunteer to write man pages welcome, contact zlib@gzip.org). Two compiled 11 +examples are distributed in this package, example and minigzip. The example_d 12 +and minigzip_d flavors validate that the zlib1.dll file is working correctly. 13 + 14 +Questions about zlib should be sent to <zlib@gzip.org>. The zlib home page 15 +is http://zlib.net/ . Before reporting a problem, please check this site to 16 +verify that you have the latest version of zlib; otherwise get the latest 17 +version and check whether the problem still exists or not. 18 + 19 +PLEASE read DLL_FAQ.txt, and the the zlib FAQ http://zlib.net/zlib_faq.html 20 +before asking for help. 21 + 22 + 23 +Manifest: 24 + 25 +The package zlib-1.2.7-win32-x86.zip will contain the following files: 26 + 27 + README-WIN32.txt This document 28 + ChangeLog Changes since previous zlib packages 29 + DLL_FAQ.txt Frequently asked questions about zlib1.dll 30 + zlib.3.pdf Documentation of this library in Adobe Acrobat format 31 + 32 + example.exe A statically-bound example (using zlib.lib, not the dll) 33 + example.pdb Symbolic information for debugging example.exe 34 + 35 + example_d.exe A zlib1.dll bound example (using zdll.lib) 36 + example_d.pdb Symbolic information for debugging example_d.exe 37 + 38 + minigzip.exe A statically-bound test program (using zlib.lib, not the dll) 39 + minigzip.pdb Symbolic information for debugging minigzip.exe 40 + 41 + minigzip_d.exe A zlib1.dll bound test program (using zdll.lib) 42 + minigzip_d.pdb Symbolic information for debugging minigzip_d.exe 43 + 44 + zlib.h Install these files into the compilers' INCLUDE path to 45 + zconf.h compile programs which use zlib.lib or zdll.lib 46 + 47 + zdll.lib Install these files into the compilers' LIB path if linking 48 + zdll.exp a compiled program to the zlib1.dll binary 49 + 50 + zlib.lib Install these files into the compilers' LIB path to link zlib 51 + zlib.pdb into compiled programs, without zlib1.dll runtime dependency 52 + (zlib.pdb provides debugging info to the compile time linker) 53 + 54 + zlib1.dll Install this binary shared library into the system PATH, or 55 + the program's runtime directory (where the .exe resides) 56 + zlib1.pdb Install in the same directory as zlib1.dll, in order to debug 57 + an application crash using WinDbg or similar tools. 58 + 59 +All .pdb files above are entirely optional, but are very useful to a developer 60 +attempting to diagnose program misbehavior or a crash. Many additional 61 +important files for developers can be found in the zlib127.zip source package 62 +available from http://zlib.net/ - review that package's README file for details. 63 + 64 + 65 +Acknowledgments: 66 + 67 +The deflate format used by zlib was defined by Phil Katz. The deflate and 68 +zlib specifications were written by L. Peter Deutsch. Thanks to all the 69 +people who reported problems and suggested various improvements in zlib; they 70 +are too numerous to cite here. 71 + 72 + 73 +Copyright notice: 74 + 75 + (C) 1995-2012 Jean-loup Gailly and Mark Adler 76 + 77 + This software is provided 'as-is', without any express or implied 78 + warranty. In no event will the authors be held liable for any damages 79 + arising from the use of this software. 80 + 81 + Permission is granted to anyone to use this software for any purpose, 82 + including commercial applications, and to alter it and redistribute it 83 + freely, subject to the following restrictions: 84 + 85 + 1. The origin of this software must not be misrepresented; you must not 86 + claim that you wrote the original software. If you use this software 87 + in a product, an acknowledgment in the product documentation would be 88 + appreciated but is not required. 89 + 2. Altered source versions must be plainly marked as such, and must not be 90 + misrepresented as being the original software. 91 + 3. This notice may not be removed or altered from any source distribution. 92 + 93 + Jean-loup Gailly Mark Adler 94 + jloup@gzip.org madler@alumni.caltech.edu 95 + 96 +If you use the zlib library in a product, we would appreciate *not* receiving 97 +lengthy legal documents to sign. The sources are provided for free but without 98 +warranty of any kind. The library has been entirely written by Jean-loup 99 +Gailly and Mark Adler; it does not include third-party code. 100 + 101 +If you redistribute modified sources, we would appreciate that you include in 102 +the file ChangeLog history information documenting your changes. Please read 103 +the FAQ for more information on the distribution of modified source versions.
Added compat/zlib/win32/VisualC.txt.
1 + 2 +To build zlib using the Microsoft Visual C++ environment, 3 +use the appropriate project from the projects/ directory.
Added compat/zlib/win32/zlib.def.
1 +; zlib data compression library 2 +EXPORTS 3 +; basic functions 4 + zlibVersion 5 + deflate 6 + deflateEnd 7 + inflate 8 + inflateEnd 9 +; advanced functions 10 + deflateSetDictionary 11 + deflateCopy 12 + deflateReset 13 + deflateParams 14 + deflateTune 15 + deflateBound 16 + deflatePending 17 + deflatePrime 18 + deflateSetHeader 19 + inflateSetDictionary 20 + inflateSync 21 + inflateCopy 22 + inflateReset 23 + inflateReset2 24 + inflatePrime 25 + inflateMark 26 + inflateGetHeader 27 + inflateBack 28 + inflateBackEnd 29 + zlibCompileFlags 30 +; utility functions 31 + compress 32 + compress2 33 + compressBound 34 + uncompress 35 + gzopen 36 + gzdopen 37 + gzbuffer 38 + gzsetparams 39 + gzread 40 + gzwrite 41 + gzprintf 42 + gzputs 43 + gzgets 44 + gzputc 45 + gzgetc 46 + gzungetc 47 + gzflush 48 + gzseek 49 + gzrewind 50 + gztell 51 + gzoffset 52 + gzeof 53 + gzdirect 54 + gzclose 55 + gzclose_r 56 + gzclose_w 57 + gzerror 58 + gzclearerr 59 +; large file functions 60 + gzopen64 61 + gzseek64 62 + gztell64 63 + gzoffset64 64 + adler32_combine64 65 + crc32_combine64 66 +; checksum functions 67 + adler32 68 + crc32 69 + adler32_combine 70 + crc32_combine 71 +; various hacks, don't look :) 72 + deflateInit_ 73 + deflateInit2_ 74 + inflateInit_ 75 + inflateInit2_ 76 + inflateBackInit_ 77 + gzgetc_ 78 + zError 79 + inflateSyncPoint 80 + get_crc_table 81 + inflateUndermine 82 + inflateResetKeep 83 + deflateResetKeep 84 + gzopen_w
Added compat/zlib/win32/zlib1.rc.
1 +#include <winver.h> 2 +#include "../zlib.h" 3 + 4 +#ifdef GCC_WINDRES 5 +VS_VERSION_INFO VERSIONINFO 6 +#else 7 +VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 8 +#endif 9 + FILEVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 10 + PRODUCTVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 11 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 12 +#ifdef _DEBUG 13 + FILEFLAGS 1 14 +#else 15 + FILEFLAGS 0 16 +#endif 17 + FILEOS VOS__WINDOWS32 18 + FILETYPE VFT_DLL 19 + FILESUBTYPE 0 // not used 20 +BEGIN 21 + BLOCK "StringFileInfo" 22 + BEGIN 23 + BLOCK "040904E4" 24 + //language ID = U.S. English, char set = Windows, Multilingual 25 + BEGIN 26 + VALUE "FileDescription", "zlib data compression library\0" 27 + VALUE "FileVersion", ZLIB_VERSION "\0" 28 + VALUE "InternalName", "zlib1.dll\0" 29 + VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0" 30 + VALUE "OriginalFilename", "zlib1.dll\0" 31 + VALUE "ProductName", "zlib\0" 32 + VALUE "ProductVersion", ZLIB_VERSION "\0" 33 + VALUE "Comments", "For more information visit http://www.zlib.net/\0" 34 + END 35 + END 36 + BLOCK "VarFileInfo" 37 + BEGIN 38 + VALUE "Translation", 0x0409, 1252 39 + END 40 +END
Added compat/zlib/zconf.h.
1 +/* zconf.h -- configuration of the zlib compression library 2 + * Copyright (C) 1995-2012 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#ifndef ZCONF_H 9 +#define ZCONF_H 10 + 11 +/* 12 + * If you *really* need a unique prefix for all types and library functions, 13 + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 + * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 + * this permanently in zconf.h using "./configure --zprefix". 16 + */ 17 +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 +# define Z_PREFIX_SET 19 + 20 +/* all linked symbols */ 21 +# define _dist_code z__dist_code 22 +# define _length_code z__length_code 23 +# define _tr_align z__tr_align 24 +# define _tr_flush_block z__tr_flush_block 25 +# define _tr_init z__tr_init 26 +# define _tr_stored_block z__tr_stored_block 27 +# define _tr_tally z__tr_tally 28 +# define adler32 z_adler32 29 +# define adler32_combine z_adler32_combine 30 +# define adler32_combine64 z_adler32_combine64 31 +# ifndef Z_SOLO 32 +# define compress z_compress 33 +# define compress2 z_compress2 34 +# define compressBound z_compressBound 35 +# endif 36 +# define crc32 z_crc32 37 +# define crc32_combine z_crc32_combine 38 +# define crc32_combine64 z_crc32_combine64 39 +# define deflate z_deflate 40 +# define deflateBound z_deflateBound 41 +# define deflateCopy z_deflateCopy 42 +# define deflateEnd z_deflateEnd 43 +# define deflateInit2_ z_deflateInit2_ 44 +# define deflateInit_ z_deflateInit_ 45 +# define deflateParams z_deflateParams 46 +# define deflatePending z_deflatePending 47 +# define deflatePrime z_deflatePrime 48 +# define deflateReset z_deflateReset 49 +# define deflateResetKeep z_deflateResetKeep 50 +# define deflateSetDictionary z_deflateSetDictionary 51 +# define deflateSetHeader z_deflateSetHeader 52 +# define deflateTune z_deflateTune 53 +# define deflate_copyright z_deflate_copyright 54 +# define get_crc_table z_get_crc_table 55 +# ifndef Z_SOLO 56 +# define gz_error z_gz_error 57 +# define gz_intmax z_gz_intmax 58 +# define gz_strwinerror z_gz_strwinerror 59 +# define gzbuffer z_gzbuffer 60 +# define gzclearerr z_gzclearerr 61 +# define gzclose z_gzclose 62 +# define gzclose_r z_gzclose_r 63 +# define gzclose_w z_gzclose_w 64 +# define gzdirect z_gzdirect 65 +# define gzdopen z_gzdopen 66 +# define gzeof z_gzeof 67 +# define gzerror z_gzerror 68 +# define gzflush z_gzflush 69 +# define gzgetc z_gzgetc 70 +# define gzgetc_ z_gzgetc_ 71 +# define gzgets z_gzgets 72 +# define gzoffset z_gzoffset 73 +# define gzoffset64 z_gzoffset64 74 +# define gzopen z_gzopen 75 +# define gzopen64 z_gzopen64 76 +# ifdef _WIN32 77 +# define gzopen_w z_gzopen_w 78 +# endif 79 +# define gzprintf z_gzprintf 80 +# define gzputc z_gzputc 81 +# define gzputs z_gzputs 82 +# define gzread z_gzread 83 +# define gzrewind z_gzrewind 84 +# define gzseek z_gzseek 85 +# define gzseek64 z_gzseek64 86 +# define gzsetparams z_gzsetparams 87 +# define gztell z_gztell 88 +# define gztell64 z_gztell64 89 +# define gzungetc z_gzungetc 90 +# define gzwrite z_gzwrite 91 +# endif 92 +# define inflate z_inflate 93 +# define inflateBack z_inflateBack 94 +# define inflateBackEnd z_inflateBackEnd 95 +# define inflateBackInit_ z_inflateBackInit_ 96 +# define inflateCopy z_inflateCopy 97 +# define inflateEnd z_inflateEnd 98 +# define inflateGetHeader z_inflateGetHeader 99 +# define inflateInit2_ z_inflateInit2_ 100 +# define inflateInit_ z_inflateInit_ 101 +# define inflateMark z_inflateMark 102 +# define inflatePrime z_inflatePrime 103 +# define inflateReset z_inflateReset 104 +# define inflateReset2 z_inflateReset2 105 +# define inflateSetDictionary z_inflateSetDictionary 106 +# define inflateSync z_inflateSync 107 +# define inflateSyncPoint z_inflateSyncPoint 108 +# define inflateUndermine z_inflateUndermine 109 +# define inflateResetKeep z_inflateResetKeep 110 +# define inflate_copyright z_inflate_copyright 111 +# define inflate_fast z_inflate_fast 112 +# define inflate_table z_inflate_table 113 +# ifndef Z_SOLO 114 +# define uncompress z_uncompress 115 +# endif 116 +# define zError z_zError 117 +# ifndef Z_SOLO 118 +# define zcalloc z_zcalloc 119 +# define zcfree z_zcfree 120 +# endif 121 +# define zlibCompileFlags z_zlibCompileFlags 122 +# define zlibVersion z_zlibVersion 123 + 124 +/* all zlib typedefs in zlib.h and zconf.h */ 125 +# define Byte z_Byte 126 +# define Bytef z_Bytef 127 +# define alloc_func z_alloc_func 128 +# define charf z_charf 129 +# define free_func z_free_func 130 +# ifndef Z_SOLO 131 +# define gzFile z_gzFile 132 +# endif 133 +# define gz_header z_gz_header 134 +# define gz_headerp z_gz_headerp 135 +# define in_func z_in_func 136 +# define intf z_intf 137 +# define out_func z_out_func 138 +# define uInt z_uInt 139 +# define uIntf z_uIntf 140 +# define uLong z_uLong 141 +# define uLongf z_uLongf 142 +# define voidp z_voidp 143 +# define voidpc z_voidpc 144 +# define voidpf z_voidpf 145 + 146 +/* all zlib structs in zlib.h and zconf.h */ 147 +# define gz_header_s z_gz_header_s 148 +# define internal_state z_internal_state 149 + 150 +#endif 151 + 152 +#if defined(__MSDOS__) && !defined(MSDOS) 153 +# define MSDOS 154 +#endif 155 +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 156 +# define OS2 157 +#endif 158 +#if defined(_WINDOWS) && !defined(WINDOWS) 159 +# define WINDOWS 160 +#endif 161 +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 162 +# ifndef WIN32 163 +# define WIN32 164 +# endif 165 +#endif 166 +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 167 +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 168 +# ifndef SYS16BIT 169 +# define SYS16BIT 170 +# endif 171 +# endif 172 +#endif 173 + 174 +/* 175 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 176 + * than 64k bytes at a time (needed on systems with 16-bit int). 177 + */ 178 +#ifdef SYS16BIT 179 +# define MAXSEG_64K 180 +#endif 181 +#ifdef MSDOS 182 +# define UNALIGNED_OK 183 +#endif 184 + 185 +#ifdef __STDC_VERSION__ 186 +# ifndef STDC 187 +# define STDC 188 +# endif 189 +# if __STDC_VERSION__ >= 199901L 190 +# ifndef STDC99 191 +# define STDC99 192 +# endif 193 +# endif 194 +#endif 195 +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 196 +# define STDC 197 +#endif 198 +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 199 +# define STDC 200 +#endif 201 +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 202 +# define STDC 203 +#endif 204 +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 205 +# define STDC 206 +#endif 207 + 208 +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 209 +# define STDC 210 +#endif 211 + 212 +#ifndef STDC 213 +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 214 +# define const /* note: need a more gentle solution here */ 215 +# endif 216 +#endif 217 + 218 +#if defined(ZLIB_CONST) && !defined(z_const) 219 +# define z_const const 220 +#else 221 +# define z_const 222 +#endif 223 + 224 +/* Some Mac compilers merge all .h files incorrectly: */ 225 +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 226 +# define NO_DUMMY_DECL 227 +#endif 228 + 229 +/* Maximum value for memLevel in deflateInit2 */ 230 +#ifndef MAX_MEM_LEVEL 231 +# ifdef MAXSEG_64K 232 +# define MAX_MEM_LEVEL 8 233 +# else 234 +# define MAX_MEM_LEVEL 9 235 +# endif 236 +#endif 237 + 238 +/* Maximum value for windowBits in deflateInit2 and inflateInit2. 239 + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 240 + * created by gzip. (Files created by minigzip can still be extracted by 241 + * gzip.) 242 + */ 243 +#ifndef MAX_WBITS 244 +# define MAX_WBITS 15 /* 32K LZ77 window */ 245 +#endif 246 + 247 +/* The memory requirements for deflate are (in bytes): 248 + (1 << (windowBits+2)) + (1 << (memLevel+9)) 249 + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 250 + plus a few kilobytes for small objects. For example, if you want to reduce 251 + the default memory requirements from 256K to 128K, compile with 252 + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 253 + Of course this will generally degrade compression (there's no free lunch). 254 + 255 + The memory requirements for inflate are (in bytes) 1 << windowBits 256 + that is, 32K for windowBits=15 (default value) plus a few kilobytes 257 + for small objects. 258 +*/ 259 + 260 + /* Type declarations */ 261 + 262 +#ifndef OF /* function prototypes */ 263 +# ifdef STDC 264 +# define OF(args) args 265 +# else 266 +# define OF(args) () 267 +# endif 268 +#endif 269 + 270 +#ifndef Z_ARG /* function prototypes for stdarg */ 271 +# if defined(STDC) || defined(Z_HAVE_STDARG_H) 272 +# define Z_ARG(args) args 273 +# else 274 +# define Z_ARG(args) () 275 +# endif 276 +#endif 277 + 278 +/* The following definitions for FAR are needed only for MSDOS mixed 279 + * model programming (small or medium model with some far allocations). 280 + * This was tested only with MSC; for other MSDOS compilers you may have 281 + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 282 + * just define FAR to be empty. 283 + */ 284 +#ifdef SYS16BIT 285 +# if defined(M_I86SM) || defined(M_I86MM) 286 + /* MSC small or medium model */ 287 +# define SMALL_MEDIUM 288 +# ifdef _MSC_VER 289 +# define FAR _far 290 +# else 291 +# define FAR far 292 +# endif 293 +# endif 294 +# if (defined(__SMALL__) || defined(__MEDIUM__)) 295 + /* Turbo C small or medium model */ 296 +# define SMALL_MEDIUM 297 +# ifdef __BORLANDC__ 298 +# define FAR _far 299 +# else 300 +# define FAR far 301 +# endif 302 +# endif 303 +#endif 304 + 305 +#if defined(WINDOWS) || defined(WIN32) 306 + /* If building or using zlib as a DLL, define ZLIB_DLL. 307 + * This is not mandatory, but it offers a little performance increase. 308 + */ 309 +# ifdef ZLIB_DLL 310 +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 311 +# ifdef ZLIB_INTERNAL 312 +# define ZEXTERN extern __declspec(dllexport) 313 +# else 314 +# define ZEXTERN extern __declspec(dllimport) 315 +# endif 316 +# endif 317 +# endif /* ZLIB_DLL */ 318 + /* If building or using zlib with the WINAPI/WINAPIV calling convention, 319 + * define ZLIB_WINAPI. 320 + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 321 + */ 322 +# ifdef ZLIB_WINAPI 323 +# ifdef FAR 324 +# undef FAR 325 +# endif 326 +# include <windows.h> 327 + /* No need for _export, use ZLIB.DEF instead. */ 328 + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 329 +# define ZEXPORT WINAPI 330 +# ifdef WIN32 331 +# define ZEXPORTVA WINAPIV 332 +# else 333 +# define ZEXPORTVA FAR CDECL 334 +# endif 335 +# endif 336 +#endif 337 + 338 +#if defined (__BEOS__) 339 +# ifdef ZLIB_DLL 340 +# ifdef ZLIB_INTERNAL 341 +# define ZEXPORT __declspec(dllexport) 342 +# define ZEXPORTVA __declspec(dllexport) 343 +# else 344 +# define ZEXPORT __declspec(dllimport) 345 +# define ZEXPORTVA __declspec(dllimport) 346 +# endif 347 +# endif 348 +#endif 349 + 350 +#ifndef ZEXTERN 351 +# define ZEXTERN extern 352 +#endif 353 +#ifndef ZEXPORT 354 +# define ZEXPORT 355 +#endif 356 +#ifndef ZEXPORTVA 357 +# define ZEXPORTVA 358 +#endif 359 + 360 +#ifndef FAR 361 +# define FAR 362 +#endif 363 + 364 +#if !defined(__MACTYPES__) 365 +typedef unsigned char Byte; /* 8 bits */ 366 +#endif 367 +typedef unsigned int uInt; /* 16 bits or more */ 368 +typedef unsigned long uLong; /* 32 bits or more */ 369 + 370 +#ifdef SMALL_MEDIUM 371 + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 372 +# define Bytef Byte FAR 373 +#else 374 + typedef Byte FAR Bytef; 375 +#endif 376 +typedef char FAR charf; 377 +typedef int FAR intf; 378 +typedef uInt FAR uIntf; 379 +typedef uLong FAR uLongf; 380 + 381 +#ifdef STDC 382 + typedef void const *voidpc; 383 + typedef void FAR *voidpf; 384 + typedef void *voidp; 385 +#else 386 + typedef Byte const *voidpc; 387 + typedef Byte FAR *voidpf; 388 + typedef Byte *voidp; 389 +#endif 390 + 391 +/* ./configure may #define Z_U4 here */ 392 + 393 +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 394 +# include <limits.h> 395 +# if (UINT_MAX == 0xffffffffUL) 396 +# define Z_U4 unsigned 397 +# else 398 +# if (ULONG_MAX == 0xffffffffUL) 399 +# define Z_U4 unsigned long 400 +# else 401 +# if (USHRT_MAX == 0xffffffffUL) 402 +# define Z_U4 unsigned short 403 +# endif 404 +# endif 405 +# endif 406 +#endif 407 + 408 +#ifdef Z_U4 409 + typedef Z_U4 z_crc_t; 410 +#else 411 + typedef unsigned long z_crc_t; 412 +#endif 413 + 414 +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 415 +# define Z_HAVE_UNISTD_H 416 +#endif 417 + 418 +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 419 +# define Z_HAVE_STDARG_H 420 +#endif 421 + 422 +#ifdef STDC 423 +# ifndef Z_SOLO 424 +# include <sys/types.h> /* for off_t */ 425 +# endif 426 +#endif 427 + 428 +#ifdef _WIN32 429 +# include <stddef.h> /* for wchar_t */ 430 +#endif 431 + 432 +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 433 + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 434 + * though the former does not conform to the LFS document), but considering 435 + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 436 + * equivalently requesting no 64-bit operations 437 + */ 438 +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 439 +# undef _LARGEFILE64_SOURCE 440 +#endif 441 + 442 +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 443 +# define Z_HAVE_UNISTD_H 444 +#endif 445 +#ifndef Z_SOLO 446 +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) 447 +# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 448 +# ifdef VMS 449 +# include <unixio.h> /* for off_t */ 450 +# endif 451 +# ifndef z_off_t 452 +# define z_off_t off_t 453 +# endif 454 +# endif 455 +#endif 456 + 457 +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 458 +# define Z_LFS64 459 +#endif 460 + 461 +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 462 +# define Z_LARGE64 463 +#endif 464 + 465 +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 466 +# define Z_WANT64 467 +#endif 468 + 469 +#if !defined(SEEK_SET) && !defined(Z_SOLO) 470 +# define SEEK_SET 0 /* Seek from beginning of file. */ 471 +# define SEEK_CUR 1 /* Seek from current position. */ 472 +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 473 +#endif 474 + 475 +#ifndef z_off_t 476 +# define z_off_t long 477 +#endif 478 + 479 +#if !defined(_WIN32) && defined(Z_LARGE64) 480 +# define z_off64_t off64_t 481 +#else 482 +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 483 +# define z_off64_t __int64 484 +# else 485 +# define z_off64_t z_off_t 486 +# endif 487 +#endif 488 + 489 +/* MVS linker does not support external names larger than 8 bytes */ 490 +#if defined(__MVS__) 491 + #pragma map(deflateInit_,"DEIN") 492 + #pragma map(deflateInit2_,"DEIN2") 493 + #pragma map(deflateEnd,"DEEND") 494 + #pragma map(deflateBound,"DEBND") 495 + #pragma map(inflateInit_,"ININ") 496 + #pragma map(inflateInit2_,"ININ2") 497 + #pragma map(inflateEnd,"INEND") 498 + #pragma map(inflateSync,"INSY") 499 + #pragma map(inflateSetDictionary,"INSEDI") 500 + #pragma map(compressBound,"CMBND") 501 + #pragma map(inflate_table,"INTABL") 502 + #pragma map(inflate_fast,"INFA") 503 + #pragma map(inflate_copyright,"INCOPY") 504 +#endif 505 + 506 +#endif /* ZCONF_H */
Added compat/zlib/zconf.h.cmakein.
1 +/* zconf.h -- configuration of the zlib compression library 2 + * Copyright (C) 1995-2012 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#ifndef ZCONF_H 9 +#define ZCONF_H 10 +#cmakedefine Z_PREFIX 11 +#cmakedefine Z_HAVE_UNISTD_H 12 + 13 +/* 14 + * If you *really* need a unique prefix for all types and library functions, 15 + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 16 + * Even better than compiling with -DZ_PREFIX would be to use configure to set 17 + * this permanently in zconf.h using "./configure --zprefix". 18 + */ 19 +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 20 +# define Z_PREFIX_SET 21 + 22 +/* all linked symbols */ 23 +# define _dist_code z__dist_code 24 +# define _length_code z__length_code 25 +# define _tr_align z__tr_align 26 +# define _tr_flush_block z__tr_flush_block 27 +# define _tr_init z__tr_init 28 +# define _tr_stored_block z__tr_stored_block 29 +# define _tr_tally z__tr_tally 30 +# define adler32 z_adler32 31 +# define adler32_combine z_adler32_combine 32 +# define adler32_combine64 z_adler32_combine64 33 +# ifndef Z_SOLO 34 +# define compress z_compress 35 +# define compress2 z_compress2 36 +# define compressBound z_compressBound 37 +# endif 38 +# define crc32 z_crc32 39 +# define crc32_combine z_crc32_combine 40 +# define crc32_combine64 z_crc32_combine64 41 +# define deflate z_deflate 42 +# define deflateBound z_deflateBound 43 +# define deflateCopy z_deflateCopy 44 +# define deflateEnd z_deflateEnd 45 +# define deflateInit2_ z_deflateInit2_ 46 +# define deflateInit_ z_deflateInit_ 47 +# define deflateParams z_deflateParams 48 +# define deflatePending z_deflatePending 49 +# define deflatePrime z_deflatePrime 50 +# define deflateReset z_deflateReset 51 +# define deflateResetKeep z_deflateResetKeep 52 +# define deflateSetDictionary z_deflateSetDictionary 53 +# define deflateSetHeader z_deflateSetHeader 54 +# define deflateTune z_deflateTune 55 +# define deflate_copyright z_deflate_copyright 56 +# define get_crc_table z_get_crc_table 57 +# ifndef Z_SOLO 58 +# define gz_error z_gz_error 59 +# define gz_intmax z_gz_intmax 60 +# define gz_strwinerror z_gz_strwinerror 61 +# define gzbuffer z_gzbuffer 62 +# define gzclearerr z_gzclearerr 63 +# define gzclose z_gzclose 64 +# define gzclose_r z_gzclose_r 65 +# define gzclose_w z_gzclose_w 66 +# define gzdirect z_gzdirect 67 +# define gzdopen z_gzdopen 68 +# define gzeof z_gzeof 69 +# define gzerror z_gzerror 70 +# define gzflush z_gzflush 71 +# define gzgetc z_gzgetc 72 +# define gzgetc_ z_gzgetc_ 73 +# define gzgets z_gzgets 74 +# define gzoffset z_gzoffset 75 +# define gzoffset64 z_gzoffset64 76 +# define gzopen z_gzopen 77 +# define gzopen64 z_gzopen64 78 +# ifdef _WIN32 79 +# define gzopen_w z_gzopen_w 80 +# endif 81 +# define gzprintf z_gzprintf 82 +# define gzputc z_gzputc 83 +# define gzputs z_gzputs 84 +# define gzread z_gzread 85 +# define gzrewind z_gzrewind 86 +# define gzseek z_gzseek 87 +# define gzseek64 z_gzseek64 88 +# define gzsetparams z_gzsetparams 89 +# define gztell z_gztell 90 +# define gztell64 z_gztell64 91 +# define gzungetc z_gzungetc 92 +# define gzwrite z_gzwrite 93 +# endif 94 +# define inflate z_inflate 95 +# define inflateBack z_inflateBack 96 +# define inflateBackEnd z_inflateBackEnd 97 +# define inflateBackInit_ z_inflateBackInit_ 98 +# define inflateCopy z_inflateCopy 99 +# define inflateEnd z_inflateEnd 100 +# define inflateGetHeader z_inflateGetHeader 101 +# define inflateInit2_ z_inflateInit2_ 102 +# define inflateInit_ z_inflateInit_ 103 +# define inflateMark z_inflateMark 104 +# define inflatePrime z_inflatePrime 105 +# define inflateReset z_inflateReset 106 +# define inflateReset2 z_inflateReset2 107 +# define inflateSetDictionary z_inflateSetDictionary 108 +# define inflateSync z_inflateSync 109 +# define inflateSyncPoint z_inflateSyncPoint 110 +# define inflateUndermine z_inflateUndermine 111 +# define inflateResetKeep z_inflateResetKeep 112 +# define inflate_copyright z_inflate_copyright 113 +# define inflate_fast z_inflate_fast 114 +# define inflate_table z_inflate_table 115 +# ifndef Z_SOLO 116 +# define uncompress z_uncompress 117 +# endif 118 +# define zError z_zError 119 +# ifndef Z_SOLO 120 +# define zcalloc z_zcalloc 121 +# define zcfree z_zcfree 122 +# endif 123 +# define zlibCompileFlags z_zlibCompileFlags 124 +# define zlibVersion z_zlibVersion 125 + 126 +/* all zlib typedefs in zlib.h and zconf.h */ 127 +# define Byte z_Byte 128 +# define Bytef z_Bytef 129 +# define alloc_func z_alloc_func 130 +# define charf z_charf 131 +# define free_func z_free_func 132 +# ifndef Z_SOLO 133 +# define gzFile z_gzFile 134 +# endif 135 +# define gz_header z_gz_header 136 +# define gz_headerp z_gz_headerp 137 +# define in_func z_in_func 138 +# define intf z_intf 139 +# define out_func z_out_func 140 +# define uInt z_uInt 141 +# define uIntf z_uIntf 142 +# define uLong z_uLong 143 +# define uLongf z_uLongf 144 +# define voidp z_voidp 145 +# define voidpc z_voidpc 146 +# define voidpf z_voidpf 147 + 148 +/* all zlib structs in zlib.h and zconf.h */ 149 +# define gz_header_s z_gz_header_s 150 +# define internal_state z_internal_state 151 + 152 +#endif 153 + 154 +#if defined(__MSDOS__) && !defined(MSDOS) 155 +# define MSDOS 156 +#endif 157 +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 158 +# define OS2 159 +#endif 160 +#if defined(_WINDOWS) && !defined(WINDOWS) 161 +# define WINDOWS 162 +#endif 163 +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 164 +# ifndef WIN32 165 +# define WIN32 166 +# endif 167 +#endif 168 +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 169 +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 170 +# ifndef SYS16BIT 171 +# define SYS16BIT 172 +# endif 173 +# endif 174 +#endif 175 + 176 +/* 177 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 178 + * than 64k bytes at a time (needed on systems with 16-bit int). 179 + */ 180 +#ifdef SYS16BIT 181 +# define MAXSEG_64K 182 +#endif 183 +#ifdef MSDOS 184 +# define UNALIGNED_OK 185 +#endif 186 + 187 +#ifdef __STDC_VERSION__ 188 +# ifndef STDC 189 +# define STDC 190 +# endif 191 +# if __STDC_VERSION__ >= 199901L 192 +# ifndef STDC99 193 +# define STDC99 194 +# endif 195 +# endif 196 +#endif 197 +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 198 +# define STDC 199 +#endif 200 +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 201 +# define STDC 202 +#endif 203 +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 204 +# define STDC 205 +#endif 206 +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 207 +# define STDC 208 +#endif 209 + 210 +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 211 +# define STDC 212 +#endif 213 + 214 +#ifndef STDC 215 +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 216 +# define const /* note: need a more gentle solution here */ 217 +# endif 218 +#endif 219 + 220 +#if defined(ZLIB_CONST) && !defined(z_const) 221 +# define z_const const 222 +#else 223 +# define z_const 224 +#endif 225 + 226 +/* Some Mac compilers merge all .h files incorrectly: */ 227 +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 228 +# define NO_DUMMY_DECL 229 +#endif 230 + 231 +/* Maximum value for memLevel in deflateInit2 */ 232 +#ifndef MAX_MEM_LEVEL 233 +# ifdef MAXSEG_64K 234 +# define MAX_MEM_LEVEL 8 235 +# else 236 +# define MAX_MEM_LEVEL 9 237 +# endif 238 +#endif 239 + 240 +/* Maximum value for windowBits in deflateInit2 and inflateInit2. 241 + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 242 + * created by gzip. (Files created by minigzip can still be extracted by 243 + * gzip.) 244 + */ 245 +#ifndef MAX_WBITS 246 +# define MAX_WBITS 15 /* 32K LZ77 window */ 247 +#endif 248 + 249 +/* The memory requirements for deflate are (in bytes): 250 + (1 << (windowBits+2)) + (1 << (memLevel+9)) 251 + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 252 + plus a few kilobytes for small objects. For example, if you want to reduce 253 + the default memory requirements from 256K to 128K, compile with 254 + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 255 + Of course this will generally degrade compression (there's no free lunch). 256 + 257 + The memory requirements for inflate are (in bytes) 1 << windowBits 258 + that is, 32K for windowBits=15 (default value) plus a few kilobytes 259 + for small objects. 260 +*/ 261 + 262 + /* Type declarations */ 263 + 264 +#ifndef OF /* function prototypes */ 265 +# ifdef STDC 266 +# define OF(args) args 267 +# else 268 +# define OF(args) () 269 +# endif 270 +#endif 271 + 272 +#ifndef Z_ARG /* function prototypes for stdarg */ 273 +# if defined(STDC) || defined(Z_HAVE_STDARG_H) 274 +# define Z_ARG(args) args 275 +# else 276 +# define Z_ARG(args) () 277 +# endif 278 +#endif 279 + 280 +/* The following definitions for FAR are needed only for MSDOS mixed 281 + * model programming (small or medium model with some far allocations). 282 + * This was tested only with MSC; for other MSDOS compilers you may have 283 + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 284 + * just define FAR to be empty. 285 + */ 286 +#ifdef SYS16BIT 287 +# if defined(M_I86SM) || defined(M_I86MM) 288 + /* MSC small or medium model */ 289 +# define SMALL_MEDIUM 290 +# ifdef _MSC_VER 291 +# define FAR _far 292 +# else 293 +# define FAR far 294 +# endif 295 +# endif 296 +# if (defined(__SMALL__) || defined(__MEDIUM__)) 297 + /* Turbo C small or medium model */ 298 +# define SMALL_MEDIUM 299 +# ifdef __BORLANDC__ 300 +# define FAR _far 301 +# else 302 +# define FAR far 303 +# endif 304 +# endif 305 +#endif 306 + 307 +#if defined(WINDOWS) || defined(WIN32) 308 + /* If building or using zlib as a DLL, define ZLIB_DLL. 309 + * This is not mandatory, but it offers a little performance increase. 310 + */ 311 +# ifdef ZLIB_DLL 312 +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 313 +# ifdef ZLIB_INTERNAL 314 +# define ZEXTERN extern __declspec(dllexport) 315 +# else 316 +# define ZEXTERN extern __declspec(dllimport) 317 +# endif 318 +# endif 319 +# endif /* ZLIB_DLL */ 320 + /* If building or using zlib with the WINAPI/WINAPIV calling convention, 321 + * define ZLIB_WINAPI. 322 + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 323 + */ 324 +# ifdef ZLIB_WINAPI 325 +# ifdef FAR 326 +# undef FAR 327 +# endif 328 +# include <windows.h> 329 + /* No need for _export, use ZLIB.DEF instead. */ 330 + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 331 +# define ZEXPORT WINAPI 332 +# ifdef WIN32 333 +# define ZEXPORTVA WINAPIV 334 +# else 335 +# define ZEXPORTVA FAR CDECL 336 +# endif 337 +# endif 338 +#endif 339 + 340 +#if defined (__BEOS__) 341 +# ifdef ZLIB_DLL 342 +# ifdef ZLIB_INTERNAL 343 +# define ZEXPORT __declspec(dllexport) 344 +# define ZEXPORTVA __declspec(dllexport) 345 +# else 346 +# define ZEXPORT __declspec(dllimport) 347 +# define ZEXPORTVA __declspec(dllimport) 348 +# endif 349 +# endif 350 +#endif 351 + 352 +#ifndef ZEXTERN 353 +# define ZEXTERN extern 354 +#endif 355 +#ifndef ZEXPORT 356 +# define ZEXPORT 357 +#endif 358 +#ifndef ZEXPORTVA 359 +# define ZEXPORTVA 360 +#endif 361 + 362 +#ifndef FAR 363 +# define FAR 364 +#endif 365 + 366 +#if !defined(__MACTYPES__) 367 +typedef unsigned char Byte; /* 8 bits */ 368 +#endif 369 +typedef unsigned int uInt; /* 16 bits or more */ 370 +typedef unsigned long uLong; /* 32 bits or more */ 371 + 372 +#ifdef SMALL_MEDIUM 373 + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 374 +# define Bytef Byte FAR 375 +#else 376 + typedef Byte FAR Bytef; 377 +#endif 378 +typedef char FAR charf; 379 +typedef int FAR intf; 380 +typedef uInt FAR uIntf; 381 +typedef uLong FAR uLongf; 382 + 383 +#ifdef STDC 384 + typedef void const *voidpc; 385 + typedef void FAR *voidpf; 386 + typedef void *voidp; 387 +#else 388 + typedef Byte const *voidpc; 389 + typedef Byte FAR *voidpf; 390 + typedef Byte *voidp; 391 +#endif 392 + 393 +/* ./configure may #define Z_U4 here */ 394 + 395 +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 396 +# include <limits.h> 397 +# if (UINT_MAX == 0xffffffffUL) 398 +# define Z_U4 unsigned 399 +# else 400 +# if (ULONG_MAX == 0xffffffffUL) 401 +# define Z_U4 unsigned long 402 +# else 403 +# if (USHRT_MAX == 0xffffffffUL) 404 +# define Z_U4 unsigned short 405 +# endif 406 +# endif 407 +# endif 408 +#endif 409 + 410 +#ifdef Z_U4 411 + typedef Z_U4 z_crc_t; 412 +#else 413 + typedef unsigned long z_crc_t; 414 +#endif 415 + 416 +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 417 +# define Z_HAVE_UNISTD_H 418 +#endif 419 + 420 +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 421 +# define Z_HAVE_STDARG_H 422 +#endif 423 + 424 +#ifdef STDC 425 +# ifndef Z_SOLO 426 +# include <sys/types.h> /* for off_t */ 427 +# endif 428 +#endif 429 + 430 +#ifdef _WIN32 431 +# include <stddef.h> /* for wchar_t */ 432 +#endif 433 + 434 +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 435 + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 436 + * though the former does not conform to the LFS document), but considering 437 + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 438 + * equivalently requesting no 64-bit operations 439 + */ 440 +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 441 +# undef _LARGEFILE64_SOURCE 442 +#endif 443 + 444 +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 445 +# define Z_HAVE_UNISTD_H 446 +#endif 447 +#ifndef Z_SOLO 448 +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) 449 +# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 450 +# ifdef VMS 451 +# include <unixio.h> /* for off_t */ 452 +# endif 453 +# ifndef z_off_t 454 +# define z_off_t off_t 455 +# endif 456 +# endif 457 +#endif 458 + 459 +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 460 +# define Z_LFS64 461 +#endif 462 + 463 +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 464 +# define Z_LARGE64 465 +#endif 466 + 467 +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 468 +# define Z_WANT64 469 +#endif 470 + 471 +#if !defined(SEEK_SET) && !defined(Z_SOLO) 472 +# define SEEK_SET 0 /* Seek from beginning of file. */ 473 +# define SEEK_CUR 1 /* Seek from current position. */ 474 +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 475 +#endif 476 + 477 +#ifndef z_off_t 478 +# define z_off_t long 479 +#endif 480 + 481 +#if !defined(_WIN32) && defined(Z_LARGE64) 482 +# define z_off64_t off64_t 483 +#else 484 +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 485 +# define z_off64_t __int64 486 +# else 487 +# define z_off64_t z_off_t 488 +# endif 489 +#endif 490 + 491 +/* MVS linker does not support external names larger than 8 bytes */ 492 +#if defined(__MVS__) 493 + #pragma map(deflateInit_,"DEIN") 494 + #pragma map(deflateInit2_,"DEIN2") 495 + #pragma map(deflateEnd,"DEEND") 496 + #pragma map(deflateBound,"DEBND") 497 + #pragma map(inflateInit_,"ININ") 498 + #pragma map(inflateInit2_,"ININ2") 499 + #pragma map(inflateEnd,"INEND") 500 + #pragma map(inflateSync,"INSY") 501 + #pragma map(inflateSetDictionary,"INSEDI") 502 + #pragma map(compressBound,"CMBND") 503 + #pragma map(inflate_table,"INTABL") 504 + #pragma map(inflate_fast,"INFA") 505 + #pragma map(inflate_copyright,"INCOPY") 506 +#endif 507 + 508 +#endif /* ZCONF_H */
Added compat/zlib/zconf.h.in.
1 +/* zconf.h -- configuration of the zlib compression library 2 + * Copyright (C) 1995-2012 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#ifndef ZCONF_H 9 +#define ZCONF_H 10 + 11 +/* 12 + * If you *really* need a unique prefix for all types and library functions, 13 + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 + * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 + * this permanently in zconf.h using "./configure --zprefix". 16 + */ 17 +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 +# define Z_PREFIX_SET 19 + 20 +/* all linked symbols */ 21 +# define _dist_code z__dist_code 22 +# define _length_code z__length_code 23 +# define _tr_align z__tr_align 24 +# define _tr_flush_block z__tr_flush_block 25 +# define _tr_init z__tr_init 26 +# define _tr_stored_block z__tr_stored_block 27 +# define _tr_tally z__tr_tally 28 +# define adler32 z_adler32 29 +# define adler32_combine z_adler32_combine 30 +# define adler32_combine64 z_adler32_combine64 31 +# ifndef Z_SOLO 32 +# define compress z_compress 33 +# define compress2 z_compress2 34 +# define compressBound z_compressBound 35 +# endif 36 +# define crc32 z_crc32 37 +# define crc32_combine z_crc32_combine 38 +# define crc32_combine64 z_crc32_combine64 39 +# define deflate z_deflate 40 +# define deflateBound z_deflateBound 41 +# define deflateCopy z_deflateCopy 42 +# define deflateEnd z_deflateEnd 43 +# define deflateInit2_ z_deflateInit2_ 44 +# define deflateInit_ z_deflateInit_ 45 +# define deflateParams z_deflateParams 46 +# define deflatePending z_deflatePending 47 +# define deflatePrime z_deflatePrime 48 +# define deflateReset z_deflateReset 49 +# define deflateResetKeep z_deflateResetKeep 50 +# define deflateSetDictionary z_deflateSetDictionary 51 +# define deflateSetHeader z_deflateSetHeader 52 +# define deflateTune z_deflateTune 53 +# define deflate_copyright z_deflate_copyright 54 +# define get_crc_table z_get_crc_table 55 +# ifndef Z_SOLO 56 +# define gz_error z_gz_error 57 +# define gz_intmax z_gz_intmax 58 +# define gz_strwinerror z_gz_strwinerror 59 +# define gzbuffer z_gzbuffer 60 +# define gzclearerr z_gzclearerr 61 +# define gzclose z_gzclose 62 +# define gzclose_r z_gzclose_r 63 +# define gzclose_w z_gzclose_w 64 +# define gzdirect z_gzdirect 65 +# define gzdopen z_gzdopen 66 +# define gzeof z_gzeof 67 +# define gzerror z_gzerror 68 +# define gzflush z_gzflush 69 +# define gzgetc z_gzgetc 70 +# define gzgetc_ z_gzgetc_ 71 +# define gzgets z_gzgets 72 +# define gzoffset z_gzoffset 73 +# define gzoffset64 z_gzoffset64 74 +# define gzopen z_gzopen 75 +# define gzopen64 z_gzopen64 76 +# ifdef _WIN32 77 +# define gzopen_w z_gzopen_w 78 +# endif 79 +# define gzprintf z_gzprintf 80 +# define gzputc z_gzputc 81 +# define gzputs z_gzputs 82 +# define gzread z_gzread 83 +# define gzrewind z_gzrewind 84 +# define gzseek z_gzseek 85 +# define gzseek64 z_gzseek64 86 +# define gzsetparams z_gzsetparams 87 +# define gztell z_gztell 88 +# define gztell64 z_gztell64 89 +# define gzungetc z_gzungetc 90 +# define gzwrite z_gzwrite 91 +# endif 92 +# define inflate z_inflate 93 +# define inflateBack z_inflateBack 94 +# define inflateBackEnd z_inflateBackEnd 95 +# define inflateBackInit_ z_inflateBackInit_ 96 +# define inflateCopy z_inflateCopy 97 +# define inflateEnd z_inflateEnd 98 +# define inflateGetHeader z_inflateGetHeader 99 +# define inflateInit2_ z_inflateInit2_ 100 +# define inflateInit_ z_inflateInit_ 101 +# define inflateMark z_inflateMark 102 +# define inflatePrime z_inflatePrime 103 +# define inflateReset z_inflateReset 104 +# define inflateReset2 z_inflateReset2 105 +# define inflateSetDictionary z_inflateSetDictionary 106 +# define inflateSync z_inflateSync 107 +# define inflateSyncPoint z_inflateSyncPoint 108 +# define inflateUndermine z_inflateUndermine 109 +# define inflateResetKeep z_inflateResetKeep 110 +# define inflate_copyright z_inflate_copyright 111 +# define inflate_fast z_inflate_fast 112 +# define inflate_table z_inflate_table 113 +# ifndef Z_SOLO 114 +# define uncompress z_uncompress 115 +# endif 116 +# define zError z_zError 117 +# ifndef Z_SOLO 118 +# define zcalloc z_zcalloc 119 +# define zcfree z_zcfree 120 +# endif 121 +# define zlibCompileFlags z_zlibCompileFlags 122 +# define zlibVersion z_zlibVersion 123 + 124 +/* all zlib typedefs in zlib.h and zconf.h */ 125 +# define Byte z_Byte 126 +# define Bytef z_Bytef 127 +# define alloc_func z_alloc_func 128 +# define charf z_charf 129 +# define free_func z_free_func 130 +# ifndef Z_SOLO 131 +# define gzFile z_gzFile 132 +# endif 133 +# define gz_header z_gz_header 134 +# define gz_headerp z_gz_headerp 135 +# define in_func z_in_func 136 +# define intf z_intf 137 +# define out_func z_out_func 138 +# define uInt z_uInt 139 +# define uIntf z_uIntf 140 +# define uLong z_uLong 141 +# define uLongf z_uLongf 142 +# define voidp z_voidp 143 +# define voidpc z_voidpc 144 +# define voidpf z_voidpf 145 + 146 +/* all zlib structs in zlib.h and zconf.h */ 147 +# define gz_header_s z_gz_header_s 148 +# define internal_state z_internal_state 149 + 150 +#endif 151 + 152 +#if defined(__MSDOS__) && !defined(MSDOS) 153 +# define MSDOS 154 +#endif 155 +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 156 +# define OS2 157 +#endif 158 +#if defined(_WINDOWS) && !defined(WINDOWS) 159 +# define WINDOWS 160 +#endif 161 +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 162 +# ifndef WIN32 163 +# define WIN32 164 +# endif 165 +#endif 166 +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 167 +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 168 +# ifndef SYS16BIT 169 +# define SYS16BIT 170 +# endif 171 +# endif 172 +#endif 173 + 174 +/* 175 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 176 + * than 64k bytes at a time (needed on systems with 16-bit int). 177 + */ 178 +#ifdef SYS16BIT 179 +# define MAXSEG_64K 180 +#endif 181 +#ifdef MSDOS 182 +# define UNALIGNED_OK 183 +#endif 184 + 185 +#ifdef __STDC_VERSION__ 186 +# ifndef STDC 187 +# define STDC 188 +# endif 189 +# if __STDC_VERSION__ >= 199901L 190 +# ifndef STDC99 191 +# define STDC99 192 +# endif 193 +# endif 194 +#endif 195 +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 196 +# define STDC 197 +#endif 198 +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 199 +# define STDC 200 +#endif 201 +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 202 +# define STDC 203 +#endif 204 +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 205 +# define STDC 206 +#endif 207 + 208 +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 209 +# define STDC 210 +#endif 211 + 212 +#ifndef STDC 213 +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 214 +# define const /* note: need a more gentle solution here */ 215 +# endif 216 +#endif 217 + 218 +#if defined(ZLIB_CONST) && !defined(z_const) 219 +# define z_const const 220 +#else 221 +# define z_const 222 +#endif 223 + 224 +/* Some Mac compilers merge all .h files incorrectly: */ 225 +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 226 +# define NO_DUMMY_DECL 227 +#endif 228 + 229 +/* Maximum value for memLevel in deflateInit2 */ 230 +#ifndef MAX_MEM_LEVEL 231 +# ifdef MAXSEG_64K 232 +# define MAX_MEM_LEVEL 8 233 +# else 234 +# define MAX_MEM_LEVEL 9 235 +# endif 236 +#endif 237 + 238 +/* Maximum value for windowBits in deflateInit2 and inflateInit2. 239 + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 240 + * created by gzip. (Files created by minigzip can still be extracted by 241 + * gzip.) 242 + */ 243 +#ifndef MAX_WBITS 244 +# define MAX_WBITS 15 /* 32K LZ77 window */ 245 +#endif 246 + 247 +/* The memory requirements for deflate are (in bytes): 248 + (1 << (windowBits+2)) + (1 << (memLevel+9)) 249 + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 250 + plus a few kilobytes for small objects. For example, if you want to reduce 251 + the default memory requirements from 256K to 128K, compile with 252 + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 253 + Of course this will generally degrade compression (there's no free lunch). 254 + 255 + The memory requirements for inflate are (in bytes) 1 << windowBits 256 + that is, 32K for windowBits=15 (default value) plus a few kilobytes 257 + for small objects. 258 +*/ 259 + 260 + /* Type declarations */ 261 + 262 +#ifndef OF /* function prototypes */ 263 +# ifdef STDC 264 +# define OF(args) args 265 +# else 266 +# define OF(args) () 267 +# endif 268 +#endif 269 + 270 +#ifndef Z_ARG /* function prototypes for stdarg */ 271 +# if defined(STDC) || defined(Z_HAVE_STDARG_H) 272 +# define Z_ARG(args) args 273 +# else 274 +# define Z_ARG(args) () 275 +# endif 276 +#endif 277 + 278 +/* The following definitions for FAR are needed only for MSDOS mixed 279 + * model programming (small or medium model with some far allocations). 280 + * This was tested only with MSC; for other MSDOS compilers you may have 281 + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 282 + * just define FAR to be empty. 283 + */ 284 +#ifdef SYS16BIT 285 +# if defined(M_I86SM) || defined(M_I86MM) 286 + /* MSC small or medium model */ 287 +# define SMALL_MEDIUM 288 +# ifdef _MSC_VER 289 +# define FAR _far 290 +# else 291 +# define FAR far 292 +# endif 293 +# endif 294 +# if (defined(__SMALL__) || defined(__MEDIUM__)) 295 + /* Turbo C small or medium model */ 296 +# define SMALL_MEDIUM 297 +# ifdef __BORLANDC__ 298 +# define FAR _far 299 +# else 300 +# define FAR far 301 +# endif 302 +# endif 303 +#endif 304 + 305 +#if defined(WINDOWS) || defined(WIN32) 306 + /* If building or using zlib as a DLL, define ZLIB_DLL. 307 + * This is not mandatory, but it offers a little performance increase. 308 + */ 309 +# ifdef ZLIB_DLL 310 +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 311 +# ifdef ZLIB_INTERNAL 312 +# define ZEXTERN extern __declspec(dllexport) 313 +# else 314 +# define ZEXTERN extern __declspec(dllimport) 315 +# endif 316 +# endif 317 +# endif /* ZLIB_DLL */ 318 + /* If building or using zlib with the WINAPI/WINAPIV calling convention, 319 + * define ZLIB_WINAPI. 320 + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 321 + */ 322 +# ifdef ZLIB_WINAPI 323 +# ifdef FAR 324 +# undef FAR 325 +# endif 326 +# include <windows.h> 327 + /* No need for _export, use ZLIB.DEF instead. */ 328 + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 329 +# define ZEXPORT WINAPI 330 +# ifdef WIN32 331 +# define ZEXPORTVA WINAPIV 332 +# else 333 +# define ZEXPORTVA FAR CDECL 334 +# endif 335 +# endif 336 +#endif 337 + 338 +#if defined (__BEOS__) 339 +# ifdef ZLIB_DLL 340 +# ifdef ZLIB_INTERNAL 341 +# define ZEXPORT __declspec(dllexport) 342 +# define ZEXPORTVA __declspec(dllexport) 343 +# else 344 +# define ZEXPORT __declspec(dllimport) 345 +# define ZEXPORTVA __declspec(dllimport) 346 +# endif 347 +# endif 348 +#endif 349 + 350 +#ifndef ZEXTERN 351 +# define ZEXTERN extern 352 +#endif 353 +#ifndef ZEXPORT 354 +# define ZEXPORT 355 +#endif 356 +#ifndef ZEXPORTVA 357 +# define ZEXPORTVA 358 +#endif 359 + 360 +#ifndef FAR 361 +# define FAR 362 +#endif 363 + 364 +#if !defined(__MACTYPES__) 365 +typedef unsigned char Byte; /* 8 bits */ 366 +#endif 367 +typedef unsigned int uInt; /* 16 bits or more */ 368 +typedef unsigned long uLong; /* 32 bits or more */ 369 + 370 +#ifdef SMALL_MEDIUM 371 + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 372 +# define Bytef Byte FAR 373 +#else 374 + typedef Byte FAR Bytef; 375 +#endif 376 +typedef char FAR charf; 377 +typedef int FAR intf; 378 +typedef uInt FAR uIntf; 379 +typedef uLong FAR uLongf; 380 + 381 +#ifdef STDC 382 + typedef void const *voidpc; 383 + typedef void FAR *voidpf; 384 + typedef void *voidp; 385 +#else 386 + typedef Byte const *voidpc; 387 + typedef Byte FAR *voidpf; 388 + typedef Byte *voidp; 389 +#endif 390 + 391 +/* ./configure may #define Z_U4 here */ 392 + 393 +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 394 +# include <limits.h> 395 +# if (UINT_MAX == 0xffffffffUL) 396 +# define Z_U4 unsigned 397 +# else 398 +# if (ULONG_MAX == 0xffffffffUL) 399 +# define Z_U4 unsigned long 400 +# else 401 +# if (USHRT_MAX == 0xffffffffUL) 402 +# define Z_U4 unsigned short 403 +# endif 404 +# endif 405 +# endif 406 +#endif 407 + 408 +#ifdef Z_U4 409 + typedef Z_U4 z_crc_t; 410 +#else 411 + typedef unsigned long z_crc_t; 412 +#endif 413 + 414 +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 415 +# define Z_HAVE_UNISTD_H 416 +#endif 417 + 418 +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 419 +# define Z_HAVE_STDARG_H 420 +#endif 421 + 422 +#ifdef STDC 423 +# ifndef Z_SOLO 424 +# include <sys/types.h> /* for off_t */ 425 +# endif 426 +#endif 427 + 428 +#ifdef _WIN32 429 +# include <stddef.h> /* for wchar_t */ 430 +#endif 431 + 432 +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 433 + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 434 + * though the former does not conform to the LFS document), but considering 435 + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 436 + * equivalently requesting no 64-bit operations 437 + */ 438 +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 439 +# undef _LARGEFILE64_SOURCE 440 +#endif 441 + 442 +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 443 +# define Z_HAVE_UNISTD_H 444 +#endif 445 +#ifndef Z_SOLO 446 +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) 447 +# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 448 +# ifdef VMS 449 +# include <unixio.h> /* for off_t */ 450 +# endif 451 +# ifndef z_off_t 452 +# define z_off_t off_t 453 +# endif 454 +# endif 455 +#endif 456 + 457 +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 458 +# define Z_LFS64 459 +#endif 460 + 461 +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 462 +# define Z_LARGE64 463 +#endif 464 + 465 +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 466 +# define Z_WANT64 467 +#endif 468 + 469 +#if !defined(SEEK_SET) && !defined(Z_SOLO) 470 +# define SEEK_SET 0 /* Seek from beginning of file. */ 471 +# define SEEK_CUR 1 /* Seek from current position. */ 472 +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 473 +#endif 474 + 475 +#ifndef z_off_t 476 +# define z_off_t long 477 +#endif 478 + 479 +#if !defined(_WIN32) && defined(Z_LARGE64) 480 +# define z_off64_t off64_t 481 +#else 482 +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 483 +# define z_off64_t __int64 484 +# else 485 +# define z_off64_t z_off_t 486 +# endif 487 +#endif 488 + 489 +/* MVS linker does not support external names larger than 8 bytes */ 490 +#if defined(__MVS__) 491 + #pragma map(deflateInit_,"DEIN") 492 + #pragma map(deflateInit2_,"DEIN2") 493 + #pragma map(deflateEnd,"DEEND") 494 + #pragma map(deflateBound,"DEBND") 495 + #pragma map(inflateInit_,"ININ") 496 + #pragma map(inflateInit2_,"ININ2") 497 + #pragma map(inflateEnd,"INEND") 498 + #pragma map(inflateSync,"INSY") 499 + #pragma map(inflateSetDictionary,"INSEDI") 500 + #pragma map(compressBound,"CMBND") 501 + #pragma map(inflate_table,"INTABL") 502 + #pragma map(inflate_fast,"INFA") 503 + #pragma map(inflate_copyright,"INCOPY") 504 +#endif 505 + 506 +#endif /* ZCONF_H */
Added compat/zlib/zlib.3.
1 +.TH ZLIB 3 "2 May 2012" 2 +.SH NAME 3 +zlib \- compression/decompression library 4 +.SH SYNOPSIS 5 +[see 6 +.I zlib.h 7 +for full description] 8 +.SH DESCRIPTION 9 +The 10 +.I zlib 11 +library is a general purpose data compression library. 12 +The code is thread safe, assuming that the standard library functions 13 +used are thread safe, such as memory allocation routines. 14 +It provides in-memory compression and decompression functions, 15 +including integrity checks of the uncompressed data. 16 +This version of the library supports only one compression method (deflation) 17 +but other algorithms may be added later 18 +with the same stream interface. 19 +.LP 20 +Compression can be done in a single step if the buffers are large enough 21 +or can be done by repeated calls of the compression function. 22 +In the latter case, 23 +the application must provide more input and/or consume the output 24 +(providing more output space) before each call. 25 +.LP 26 +The library also supports reading and writing files in 27 +.IR gzip (1) 28 +(.gz) format 29 +with an interface similar to that of stdio. 30 +.LP 31 +The library does not install any signal handler. 32 +The decoder checks the consistency of the compressed data, 33 +so the library should never crash even in the case of corrupted input. 34 +.LP 35 +All functions of the compression library are documented in the file 36 +.IR zlib.h . 37 +The distribution source includes examples of use of the library 38 +in the files 39 +.I test/example.c 40 +and 41 +.IR test/minigzip.c, 42 +as well as other examples in the 43 +.IR examples/ 44 +directory. 45 +.LP 46 +Changes to this version are documented in the file 47 +.I ChangeLog 48 +that accompanies the source. 49 +.LP 50 +.I zlib 51 +is available in Java using the java.util.zip package: 52 +.IP 53 +http://java.sun.com/developer/technicalArticles/Programming/compression/ 54 +.LP 55 +A Perl interface to 56 +.IR zlib , 57 +written by Paul Marquess (pmqs@cpan.org), 58 +is available at CPAN (Comprehensive Perl Archive Network) sites, 59 +including: 60 +.IP 61 +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ 62 +.LP 63 +A Python interface to 64 +.IR zlib , 65 +written by A.M. Kuchling (amk@magnet.com), 66 +is available in Python 1.5 and later versions: 67 +.IP 68 +http://docs.python.org/library/zlib.html 69 +.LP 70 +.I zlib 71 +is built into 72 +.IR tcl: 73 +.IP 74 +http://wiki.tcl.tk/4610 75 +.LP 76 +An experimental package to read and write files in .zip format, 77 +written on top of 78 +.I zlib 79 +by Gilles Vollant (info@winimage.com), 80 +is available at: 81 +.IP 82 +http://www.winimage.com/zLibDll/minizip.html 83 +and also in the 84 +.I contrib/minizip 85 +directory of the main 86 +.I zlib 87 +source distribution. 88 +.SH "SEE ALSO" 89 +The 90 +.I zlib 91 +web site can be found at: 92 +.IP 93 +http://zlib.net/ 94 +.LP 95 +The data format used by the zlib library is described by RFC 96 +(Request for Comments) 1950 to 1952 in the files: 97 +.IP 98 +http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format) 99 +.br 100 +http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format) 101 +.br 102 +http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format) 103 +.LP 104 +Mark Nelson wrote an article about 105 +.I zlib 106 +for the Jan. 1997 issue of Dr. Dobb's Journal; 107 +a copy of the article is available at: 108 +.IP 109 +http://marknelson.us/1997/01/01/zlib-engine/ 110 +.SH "REPORTING PROBLEMS" 111 +Before reporting a problem, 112 +please check the 113 +.I zlib 114 +web site to verify that you have the latest version of 115 +.IR zlib ; 116 +otherwise, 117 +obtain the latest version and see if the problem still exists. 118 +Please read the 119 +.I zlib 120 +FAQ at: 121 +.IP 122 +http://zlib.net/zlib_faq.html 123 +.LP 124 +before asking for help. 125 +Send questions and/or comments to zlib@gzip.org, 126 +or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). 127 +.SH AUTHORS 128 +Version 1.2.7 129 +Copyright (C) 1995-2012 Jean-loup Gailly (jloup@gzip.org) 130 +and Mark Adler (madler@alumni.caltech.edu). 131 +.LP 132 +This software is provided "as-is," 133 +without any express or implied warranty. 134 +In no event will the authors be held liable for any damages 135 +arising from the use of this software. 136 +See the distribution directory with respect to requirements 137 +governing redistribution. 138 +The deflate format used by 139 +.I zlib 140 +was defined by Phil Katz. 141 +The deflate and 142 +.I zlib 143 +specifications were written by L. Peter Deutsch. 144 +Thanks to all the people who reported problems and suggested various 145 +improvements in 146 +.IR zlib ; 147 +who are too numerous to cite here. 148 +.LP 149 +UNIX manual page by R. P. C. Rodgers, 150 +U.S. National Library of Medicine (rodgers@nlm.nih.gov). 151 +.\" end of man page
Added compat/zlib/zlib.3.pdf.
cannot compute difference between binary files
Added compat/zlib/zlib.h.
1 +/* zlib.h -- interface of the 'zlib' general purpose compression library 2 + version 1.2.7, May 2nd, 2012 3 + 4 + Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler 5 + 6 + This software is provided 'as-is', without any express or implied 7 + warranty. In no event will the authors be held liable for any damages 8 + arising from the use of this software. 9 + 10 + Permission is granted to anyone to use this software for any purpose, 11 + including commercial applications, and to alter it and redistribute it 12 + freely, subject to the following restrictions: 13 + 14 + 1. The origin of this software must not be misrepresented; you must not 15 + claim that you wrote the original software. If you use this software 16 + in a product, an acknowledgment in the product documentation would be 17 + appreciated but is not required. 18 + 2. Altered source versions must be plainly marked as such, and must not be 19 + misrepresented as being the original software. 20 + 3. This notice may not be removed or altered from any source distribution. 21 + 22 + Jean-loup Gailly Mark Adler 23 + jloup@gzip.org madler@alumni.caltech.edu 24 + 25 + 26 + The data format used by the zlib library is described by RFCs (Request for 27 + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 28 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). 29 +*/ 30 + 31 +#ifndef ZLIB_H 32 +#define ZLIB_H 33 + 34 +#include "zconf.h" 35 + 36 +#ifdef __cplusplus 37 +extern "C" { 38 +#endif 39 + 40 +#define ZLIB_VERSION "1.2.7" 41 +#define ZLIB_VERNUM 0x1270 42 +#define ZLIB_VER_MAJOR 1 43 +#define ZLIB_VER_MINOR 2 44 +#define ZLIB_VER_REVISION 7 45 +#define ZLIB_VER_SUBREVISION 0 46 + 47 +/* 48 + The 'zlib' compression library provides in-memory compression and 49 + decompression functions, including integrity checks of the uncompressed data. 50 + This version of the library supports only one compression method (deflation) 51 + but other algorithms will be added later and will have the same stream 52 + interface. 53 + 54 + Compression can be done in a single step if the buffers are large enough, 55 + or can be done by repeated calls of the compression function. In the latter 56 + case, the application must provide more input and/or consume the output 57 + (providing more output space) before each call. 58 + 59 + The compressed data format used by default by the in-memory functions is 60 + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 61 + around a deflate stream, which is itself documented in RFC 1951. 62 + 63 + The library also supports reading and writing files in gzip (.gz) format 64 + with an interface similar to that of stdio using the functions that start 65 + with "gz". The gzip format is different from the zlib format. gzip is a 66 + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 67 + 68 + This library can optionally read and write gzip streams in memory as well. 69 + 70 + The zlib format was designed to be compact and fast for use in memory 71 + and on communications channels. The gzip format was designed for single- 72 + file compression on file systems, has a larger header than zlib to maintain 73 + directory information, and uses a different, slower check method than zlib. 74 + 75 + The library does not install any signal handler. The decoder checks 76 + the consistency of the compressed data, so the library should never crash 77 + even in case of corrupted input. 78 +*/ 79 + 80 +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 81 +typedef void (*free_func) OF((voidpf opaque, voidpf address)); 82 + 83 +struct internal_state; 84 + 85 +typedef struct z_stream_s { 86 + z_const Bytef *next_in; /* next input byte */ 87 + uInt avail_in; /* number of bytes available at next_in */ 88 + uLong total_in; /* total number of input bytes read so far */ 89 + 90 + Bytef *next_out; /* next output byte should be put there */ 91 + uInt avail_out; /* remaining free space at next_out */ 92 + uLong total_out; /* total number of bytes output so far */ 93 + 94 + z_const char *msg; /* last error message, NULL if no error */ 95 + struct internal_state FAR *state; /* not visible by applications */ 96 + 97 + alloc_func zalloc; /* used to allocate the internal state */ 98 + free_func zfree; /* used to free the internal state */ 99 + voidpf opaque; /* private data object passed to zalloc and zfree */ 100 + 101 + int data_type; /* best guess about the data type: binary or text */ 102 + uLong adler; /* adler32 value of the uncompressed data */ 103 + uLong reserved; /* reserved for future use */ 104 +} z_stream; 105 + 106 +typedef z_stream FAR *z_streamp; 107 + 108 +/* 109 + gzip header information passed to and from zlib routines. See RFC 1952 110 + for more details on the meanings of these fields. 111 +*/ 112 +typedef struct gz_header_s { 113 + int text; /* true if compressed data believed to be text */ 114 + uLong time; /* modification time */ 115 + int xflags; /* extra flags (not used when writing a gzip file) */ 116 + int os; /* operating system */ 117 + Bytef *extra; /* pointer to extra field or Z_NULL if none */ 118 + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 119 + uInt extra_max; /* space at extra (only when reading header) */ 120 + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 121 + uInt name_max; /* space at name (only when reading header) */ 122 + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 123 + uInt comm_max; /* space at comment (only when reading header) */ 124 + int hcrc; /* true if there was or will be a header crc */ 125 + int done; /* true when done reading gzip header (not used 126 + when writing a gzip file) */ 127 +} gz_header; 128 + 129 +typedef gz_header FAR *gz_headerp; 130 + 131 +/* 132 + The application must update next_in and avail_in when avail_in has dropped 133 + to zero. It must update next_out and avail_out when avail_out has dropped 134 + to zero. The application must initialize zalloc, zfree and opaque before 135 + calling the init function. All other fields are set by the compression 136 + library and must not be updated by the application. 137 + 138 + The opaque value provided by the application will be passed as the first 139 + parameter for calls of zalloc and zfree. This can be useful for custom 140 + memory management. The compression library attaches no meaning to the 141 + opaque value. 142 + 143 + zalloc must return Z_NULL if there is not enough memory for the object. 144 + If zlib is used in a multi-threaded application, zalloc and zfree must be 145 + thread safe. 146 + 147 + On 16-bit systems, the functions zalloc and zfree must be able to allocate 148 + exactly 65536 bytes, but will not be required to allocate more than this if 149 + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers 150 + returned by zalloc for objects of exactly 65536 bytes *must* have their 151 + offset normalized to zero. The default allocation function provided by this 152 + library ensures this (see zutil.c). To reduce memory requirements and avoid 153 + any allocation of 64K objects, at the expense of compression ratio, compile 154 + the library with -DMAX_WBITS=14 (see zconf.h). 155 + 156 + The fields total_in and total_out can be used for statistics or progress 157 + reports. After compression, total_in holds the total size of the 158 + uncompressed data and may be saved for use in the decompressor (particularly 159 + if the decompressor wants to decompress everything in a single step). 160 +*/ 161 + 162 + /* constants */ 163 + 164 +#define Z_NO_FLUSH 0 165 +#define Z_PARTIAL_FLUSH 1 166 +#define Z_SYNC_FLUSH 2 167 +#define Z_FULL_FLUSH 3 168 +#define Z_FINISH 4 169 +#define Z_BLOCK 5 170 +#define Z_TREES 6 171 +/* Allowed flush values; see deflate() and inflate() below for details */ 172 + 173 +#define Z_OK 0 174 +#define Z_STREAM_END 1 175 +#define Z_NEED_DICT 2 176 +#define Z_ERRNO (-1) 177 +#define Z_STREAM_ERROR (-2) 178 +#define Z_DATA_ERROR (-3) 179 +#define Z_MEM_ERROR (-4) 180 +#define Z_BUF_ERROR (-5) 181 +#define Z_VERSION_ERROR (-6) 182 +/* Return codes for the compression/decompression functions. Negative values 183 + * are errors, positive values are used for special but normal events. 184 + */ 185 + 186 +#define Z_NO_COMPRESSION 0 187 +#define Z_BEST_SPEED 1 188 +#define Z_BEST_COMPRESSION 9 189 +#define Z_DEFAULT_COMPRESSION (-1) 190 +/* compression levels */ 191 + 192 +#define Z_FILTERED 1 193 +#define Z_HUFFMAN_ONLY 2 194 +#define Z_RLE 3 195 +#define Z_FIXED 4 196 +#define Z_DEFAULT_STRATEGY 0 197 +/* compression strategy; see deflateInit2() below for details */ 198 + 199 +#define Z_BINARY 0 200 +#define Z_TEXT 1 201 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 202 +#define Z_UNKNOWN 2 203 +/* Possible values of the data_type field (though see inflate()) */ 204 + 205 +#define Z_DEFLATED 8 206 +/* The deflate compression method (the only one supported in this version) */ 207 + 208 +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 209 + 210 +#define zlib_version zlibVersion() 211 +/* for compatibility with versions < 1.0.2 */ 212 + 213 + 214 + /* basic functions */ 215 + 216 +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 217 +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 218 + If the first character differs, the library code actually used is not 219 + compatible with the zlib.h header file used by the application. This check 220 + is automatically made by deflateInit and inflateInit. 221 + */ 222 + 223 +/* 224 +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 225 + 226 + Initializes the internal stream state for compression. The fields 227 + zalloc, zfree and opaque must be initialized before by the caller. If 228 + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default 229 + allocation functions. 230 + 231 + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 232 + 1 gives best speed, 9 gives best compression, 0 gives no compression at all 233 + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION 234 + requests a default compromise between speed and compression (currently 235 + equivalent to level 6). 236 + 237 + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 238 + memory, Z_STREAM_ERROR if level is not a valid compression level, or 239 + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 240 + with the version assumed by the caller (ZLIB_VERSION). msg is set to null 241 + if there is no error message. deflateInit does not perform any compression: 242 + this will be done by deflate(). 243 +*/ 244 + 245 + 246 +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 247 +/* 248 + deflate compresses as much data as possible, and stops when the input 249 + buffer becomes empty or the output buffer becomes full. It may introduce 250 + some output latency (reading input without producing any output) except when 251 + forced to flush. 252 + 253 + The detailed semantics are as follows. deflate performs one or both of the 254 + following actions: 255 + 256 + - Compress more input starting at next_in and update next_in and avail_in 257 + accordingly. If not all input can be processed (because there is not 258 + enough room in the output buffer), next_in and avail_in are updated and 259 + processing will resume at this point for the next call of deflate(). 260 + 261 + - Provide more output starting at next_out and update next_out and avail_out 262 + accordingly. This action is forced if the parameter flush is non zero. 263 + Forcing flush frequently degrades the compression ratio, so this parameter 264 + should be set only when necessary (in interactive applications). Some 265 + output may be provided even if flush is not set. 266 + 267 + Before the call of deflate(), the application should ensure that at least 268 + one of the actions is possible, by providing more input and/or consuming more 269 + output, and updating avail_in or avail_out accordingly; avail_out should 270 + never be zero before the call. The application can consume the compressed 271 + output when it wants, for example when the output buffer is full (avail_out 272 + == 0), or after each call of deflate(). If deflate returns Z_OK and with 273 + zero avail_out, it must be called again after making room in the output 274 + buffer because there might be more output pending. 275 + 276 + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 277 + decide how much data to accumulate before producing output, in order to 278 + maximize compression. 279 + 280 + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 281 + flushed to the output buffer and the output is aligned on a byte boundary, so 282 + that the decompressor can get all input data available so far. (In 283 + particular avail_in is zero after the call if enough output space has been 284 + provided before the call.) Flushing may degrade compression for some 285 + compression algorithms and so it should be used only when necessary. This 286 + completes the current deflate block and follows it with an empty stored block 287 + that is three bits plus filler bits to the next byte, followed by four bytes 288 + (00 00 ff ff). 289 + 290 + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 291 + output buffer, but the output is not aligned to a byte boundary. All of the 292 + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. 293 + This completes the current deflate block and follows it with an empty fixed 294 + codes block that is 10 bits long. This assures that enough bytes are output 295 + in order for the decompressor to finish the block before the empty fixed code 296 + block. 297 + 298 + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as 299 + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to 300 + seven bits of the current block are held to be written as the next byte after 301 + the next deflate block is completed. In this case, the decompressor may not 302 + be provided enough bits at this point in order to complete decompression of 303 + the data provided so far to the compressor. It may need to wait for the next 304 + block to be emitted. This is for advanced applications that need to control 305 + the emission of deflate blocks. 306 + 307 + If flush is set to Z_FULL_FLUSH, all output is flushed as with 308 + Z_SYNC_FLUSH, and the compression state is reset so that decompression can 309 + restart from this point if previous compressed data has been damaged or if 310 + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 311 + compression. 312 + 313 + If deflate returns with avail_out == 0, this function must be called again 314 + with the same value of the flush parameter and more output space (updated 315 + avail_out), until the flush is complete (deflate returns with non-zero 316 + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 317 + avail_out is greater than six to avoid repeated flush markers due to 318 + avail_out == 0 on return. 319 + 320 + If the parameter flush is set to Z_FINISH, pending input is processed, 321 + pending output is flushed and deflate returns with Z_STREAM_END if there was 322 + enough output space; if deflate returns with Z_OK, this function must be 323 + called again with Z_FINISH and more output space (updated avail_out) but no 324 + more input data, until it returns with Z_STREAM_END or an error. After 325 + deflate has returned Z_STREAM_END, the only possible operations on the stream 326 + are deflateReset or deflateEnd. 327 + 328 + Z_FINISH can be used immediately after deflateInit if all the compression 329 + is to be done in a single step. In this case, avail_out must be at least the 330 + value returned by deflateBound (see below). Then deflate is guaranteed to 331 + return Z_STREAM_END. If not enough output space is provided, deflate will 332 + not return Z_STREAM_END, and it must be called again as described above. 333 + 334 + deflate() sets strm->adler to the adler32 checksum of all input read 335 + so far (that is, total_in bytes). 336 + 337 + deflate() may update strm->data_type if it can make a good guess about 338 + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 339 + binary. This field is only for information purposes and does not affect the 340 + compression algorithm in any manner. 341 + 342 + deflate() returns Z_OK if some progress has been made (more input 343 + processed or more output produced), Z_STREAM_END if all input has been 344 + consumed and all output has been produced (only when flush is set to 345 + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 346 + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible 347 + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 348 + fatal, and deflate() can be called again with more input and more output 349 + space to continue compressing. 350 +*/ 351 + 352 + 353 +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 354 +/* 355 + All dynamically allocated data structures for this stream are freed. 356 + This function discards any unprocessed input and does not flush any pending 357 + output. 358 + 359 + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 360 + stream state was inconsistent, Z_DATA_ERROR if the stream was freed 361 + prematurely (some input or output was discarded). In the error case, msg 362 + may be set but then points to a static string (which must not be 363 + deallocated). 364 +*/ 365 + 366 + 367 +/* 368 +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 369 + 370 + Initializes the internal stream state for decompression. The fields 371 + next_in, avail_in, zalloc, zfree and opaque must be initialized before by 372 + the caller. If next_in is not Z_NULL and avail_in is large enough (the 373 + exact value depends on the compression method), inflateInit determines the 374 + compression method from the zlib header and allocates all data structures 375 + accordingly; otherwise the allocation will be deferred to the first call of 376 + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 377 + use default allocation functions. 378 + 379 + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 380 + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 381 + version assumed by the caller, or Z_STREAM_ERROR if the parameters are 382 + invalid, such as a null pointer to the structure. msg is set to null if 383 + there is no error message. inflateInit does not perform any decompression 384 + apart from possibly reading the zlib header if present: actual decompression 385 + will be done by inflate(). (So next_in and avail_in may be modified, but 386 + next_out and avail_out are unused and unchanged.) The current implementation 387 + of inflateInit() does not process any header information -- that is deferred 388 + until inflate() is called. 389 +*/ 390 + 391 + 392 +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 393 +/* 394 + inflate decompresses as much data as possible, and stops when the input 395 + buffer becomes empty or the output buffer becomes full. It may introduce 396 + some output latency (reading input without producing any output) except when 397 + forced to flush. 398 + 399 + The detailed semantics are as follows. inflate performs one or both of the 400 + following actions: 401 + 402 + - Decompress more input starting at next_in and update next_in and avail_in 403 + accordingly. If not all input can be processed (because there is not 404 + enough room in the output buffer), next_in is updated and processing will 405 + resume at this point for the next call of inflate(). 406 + 407 + - Provide more output starting at next_out and update next_out and avail_out 408 + accordingly. inflate() provides as much output as possible, until there is 409 + no more input data or no more space in the output buffer (see below about 410 + the flush parameter). 411 + 412 + Before the call of inflate(), the application should ensure that at least 413 + one of the actions is possible, by providing more input and/or consuming more 414 + output, and updating the next_* and avail_* values accordingly. The 415 + application can consume the uncompressed output when it wants, for example 416 + when the output buffer is full (avail_out == 0), or after each call of 417 + inflate(). If inflate returns Z_OK and with zero avail_out, it must be 418 + called again after making room in the output buffer because there might be 419 + more output pending. 420 + 421 + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 422 + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 423 + output as possible to the output buffer. Z_BLOCK requests that inflate() 424 + stop if and when it gets to the next deflate block boundary. When decoding 425 + the zlib or gzip format, this will cause inflate() to return immediately 426 + after the header and before the first block. When doing a raw inflate, 427 + inflate() will go ahead and process the first block, and will return when it 428 + gets to the end of that block, or when it runs out of data. 429 + 430 + The Z_BLOCK option assists in appending to or combining deflate streams. 431 + Also to assist in this, on return inflate() will set strm->data_type to the 432 + number of unused bits in the last byte taken from strm->next_in, plus 64 if 433 + inflate() is currently decoding the last block in the deflate stream, plus 434 + 128 if inflate() returned immediately after decoding an end-of-block code or 435 + decoding the complete header up to just before the first byte of the deflate 436 + stream. The end-of-block will not be indicated until all of the uncompressed 437 + data from that block has been written to strm->next_out. The number of 438 + unused bits may in general be greater than seven, except when bit 7 of 439 + data_type is set, in which case the number of unused bits will be less than 440 + eight. data_type is set as noted here every time inflate() returns for all 441 + flush options, and so can be used to determine the amount of currently 442 + consumed input in bits. 443 + 444 + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 445 + end of each deflate block header is reached, before any actual data in that 446 + block is decoded. This allows the caller to determine the length of the 447 + deflate block header for later use in random access within a deflate block. 448 + 256 is added to the value of strm->data_type when inflate() returns 449 + immediately after reaching the end of the deflate block header. 450 + 451 + inflate() should normally be called until it returns Z_STREAM_END or an 452 + error. However if all decompression is to be performed in a single step (a 453 + single call of inflate), the parameter flush should be set to Z_FINISH. In 454 + this case all pending input is processed and all pending output is flushed; 455 + avail_out must be large enough to hold all of the uncompressed data for the 456 + operation to complete. (The size of the uncompressed data may have been 457 + saved by the compressor for this purpose.) The use of Z_FINISH is not 458 + required to perform an inflation in one step. However it may be used to 459 + inform inflate that a faster approach can be used for the single inflate() 460 + call. Z_FINISH also informs inflate to not maintain a sliding window if the 461 + stream completes, which reduces inflate's memory footprint. If the stream 462 + does not complete, either because not all of the stream is provided or not 463 + enough output space is provided, then a sliding window will be allocated and 464 + inflate() can be called again to continue the operation as if Z_NO_FLUSH had 465 + been used. 466 + 467 + In this implementation, inflate() always flushes as much output as 468 + possible to the output buffer, and always uses the faster approach on the 469 + first call. So the effects of the flush parameter in this implementation are 470 + on the return value of inflate() as noted below, when inflate() returns early 471 + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of 472 + memory for a sliding window when Z_FINISH is used. 473 + 474 + If a preset dictionary is needed after this call (see inflateSetDictionary 475 + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary 476 + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 477 + strm->adler to the Adler-32 checksum of all output produced so far (that is, 478 + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 479 + below. At the end of the stream, inflate() checks that its computed adler32 480 + checksum is equal to that saved by the compressor and returns Z_STREAM_END 481 + only if the checksum is correct. 482 + 483 + inflate() can decompress and check either zlib-wrapped or gzip-wrapped 484 + deflate data. The header type is detected automatically, if requested when 485 + initializing with inflateInit2(). Any information contained in the gzip 486 + header is not retained, so applications that need that information should 487 + instead use raw inflate, see inflateInit2() below, or inflateBack() and 488 + perform their own processing of the gzip header and trailer. When processing 489 + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output 490 + producted so far. The CRC-32 is checked against the gzip trailer. 491 + 492 + inflate() returns Z_OK if some progress has been made (more input processed 493 + or more output produced), Z_STREAM_END if the end of the compressed data has 494 + been reached and all uncompressed output has been produced, Z_NEED_DICT if a 495 + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 496 + corrupted (input stream not conforming to the zlib format or incorrect check 497 + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 498 + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, 499 + Z_BUF_ERROR if no progress is possible or if there was not enough room in the 500 + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 501 + inflate() can be called again with more input and more output space to 502 + continue decompressing. If Z_DATA_ERROR is returned, the application may 503 + then call inflateSync() to look for a good compression block if a partial 504 + recovery of the data is desired. 505 +*/ 506 + 507 + 508 +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 509 +/* 510 + All dynamically allocated data structures for this stream are freed. 511 + This function discards any unprocessed input and does not flush any pending 512 + output. 513 + 514 + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 515 + was inconsistent. In the error case, msg may be set but then points to a 516 + static string (which must not be deallocated). 517 +*/ 518 + 519 + 520 + /* Advanced functions */ 521 + 522 +/* 523 + The following functions are needed only in some special applications. 524 +*/ 525 + 526 +/* 527 +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 528 + int level, 529 + int method, 530 + int windowBits, 531 + int memLevel, 532 + int strategy)); 533 + 534 + This is another version of deflateInit with more compression options. The 535 + fields next_in, zalloc, zfree and opaque must be initialized before by the 536 + caller. 537 + 538 + The method parameter is the compression method. It must be Z_DEFLATED in 539 + this version of the library. 540 + 541 + The windowBits parameter is the base two logarithm of the window size 542 + (the size of the history buffer). It should be in the range 8..15 for this 543 + version of the library. Larger values of this parameter result in better 544 + compression at the expense of memory usage. The default value is 15 if 545 + deflateInit is used instead. 546 + 547 + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 548 + determines the window size. deflate() will then generate raw deflate data 549 + with no zlib header or trailer, and will not compute an adler32 check value. 550 + 551 + windowBits can also be greater than 15 for optional gzip encoding. Add 552 + 16 to windowBits to write a simple gzip header and trailer around the 553 + compressed data instead of a zlib wrapper. The gzip header will have no 554 + file name, no extra data, no comment, no modification time (set to zero), no 555 + header crc, and the operating system will be set to 255 (unknown). If a 556 + gzip stream is being written, strm->adler is a crc32 instead of an adler32. 557 + 558 + The memLevel parameter specifies how much memory should be allocated 559 + for the internal compression state. memLevel=1 uses minimum memory but is 560 + slow and reduces compression ratio; memLevel=9 uses maximum memory for 561 + optimal speed. The default value is 8. See zconf.h for total memory usage 562 + as a function of windowBits and memLevel. 563 + 564 + The strategy parameter is used to tune the compression algorithm. Use the 565 + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 566 + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 567 + string match), or Z_RLE to limit match distances to one (run-length 568 + encoding). Filtered data consists mostly of small values with a somewhat 569 + random distribution. In this case, the compression algorithm is tuned to 570 + compress them better. The effect of Z_FILTERED is to force more Huffman 571 + coding and less string matching; it is somewhat intermediate between 572 + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 573 + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 574 + strategy parameter only affects the compression ratio but not the 575 + correctness of the compressed output even if it is not set appropriately. 576 + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 577 + decoder for special applications. 578 + 579 + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 580 + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid 581 + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is 582 + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is 583 + set to null if there is no error message. deflateInit2 does not perform any 584 + compression: this will be done by deflate(). 585 +*/ 586 + 587 +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 588 + const Bytef *dictionary, 589 + uInt dictLength)); 590 +/* 591 + Initializes the compression dictionary from the given byte sequence 592 + without producing any compressed output. When using the zlib format, this 593 + function must be called immediately after deflateInit, deflateInit2 or 594 + deflateReset, and before any call of deflate. When doing raw deflate, this 595 + function must be called either before any call of deflate, or immediately 596 + after the completion of a deflate block, i.e. after all input has been 597 + consumed and all output has been delivered when using any of the flush 598 + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The 599 + compressor and decompressor must use exactly the same dictionary (see 600 + inflateSetDictionary). 601 + 602 + The dictionary should consist of strings (byte sequences) that are likely 603 + to be encountered later in the data to be compressed, with the most commonly 604 + used strings preferably put towards the end of the dictionary. Using a 605 + dictionary is most useful when the data to be compressed is short and can be 606 + predicted with good accuracy; the data can then be compressed better than 607 + with the default empty dictionary. 608 + 609 + Depending on the size of the compression data structures selected by 610 + deflateInit or deflateInit2, a part of the dictionary may in effect be 611 + discarded, for example if the dictionary is larger than the window size 612 + provided in deflateInit or deflateInit2. Thus the strings most likely to be 613 + useful should be put at the end of the dictionary, not at the front. In 614 + addition, the current implementation of deflate will use at most the window 615 + size minus 262 bytes of the provided dictionary. 616 + 617 + Upon return of this function, strm->adler is set to the adler32 value 618 + of the dictionary; the decompressor may later use this value to determine 619 + which dictionary has been used by the compressor. (The adler32 value 620 + applies to the whole dictionary even if only a subset of the dictionary is 621 + actually used by the compressor.) If a raw deflate was requested, then the 622 + adler32 value is not computed and strm->adler is not set. 623 + 624 + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 625 + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 626 + inconsistent (for example if deflate has already been called for this stream 627 + or if not at a block boundary for raw deflate). deflateSetDictionary does 628 + not perform any compression: this will be done by deflate(). 629 +*/ 630 + 631 +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 632 + z_streamp source)); 633 +/* 634 + Sets the destination stream as a complete copy of the source stream. 635 + 636 + This function can be useful when several compression strategies will be 637 + tried, for example when there are several ways of pre-processing the input 638 + data with a filter. The streams that will be discarded should then be freed 639 + by calling deflateEnd. Note that deflateCopy duplicates the internal 640 + compression state which can be quite large, so this strategy is slow and can 641 + consume lots of memory. 642 + 643 + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 644 + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 645 + (such as zalloc being Z_NULL). msg is left unchanged in both source and 646 + destination. 647 +*/ 648 + 649 +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 650 +/* 651 + This function is equivalent to deflateEnd followed by deflateInit, 652 + but does not free and reallocate all the internal compression state. The 653 + stream will keep the same compression level and any other attributes that 654 + may have been set by deflateInit2. 655 + 656 + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 657 + stream state was inconsistent (such as zalloc or state being Z_NULL). 658 +*/ 659 + 660 +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 661 + int level, 662 + int strategy)); 663 +/* 664 + Dynamically update the compression level and compression strategy. The 665 + interpretation of level and strategy is as in deflateInit2. This can be 666 + used to switch between compression and straight copy of the input data, or 667 + to switch to a different kind of input data requiring a different strategy. 668 + If the compression level is changed, the input available so far is 669 + compressed with the old level (and may be flushed); the new level will take 670 + effect only at the next call of deflate(). 671 + 672 + Before the call of deflateParams, the stream state must be set as for 673 + a call of deflate(), since the currently available input may have to be 674 + compressed and flushed. In particular, strm->avail_out must be non-zero. 675 + 676 + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 677 + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if 678 + strm->avail_out was zero. 679 +*/ 680 + 681 +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 682 + int good_length, 683 + int max_lazy, 684 + int nice_length, 685 + int max_chain)); 686 +/* 687 + Fine tune deflate's internal compression parameters. This should only be 688 + used by someone who understands the algorithm used by zlib's deflate for 689 + searching for the best matching string, and even then only by the most 690 + fanatic optimizer trying to squeeze out the last compressed bit for their 691 + specific input data. Read the deflate.c source code for the meaning of the 692 + max_lazy, good_length, nice_length, and max_chain parameters. 693 + 694 + deflateTune() can be called after deflateInit() or deflateInit2(), and 695 + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 696 + */ 697 + 698 +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 699 + uLong sourceLen)); 700 +/* 701 + deflateBound() returns an upper bound on the compressed size after 702 + deflation of sourceLen bytes. It must be called after deflateInit() or 703 + deflateInit2(), and after deflateSetHeader(), if used. This would be used 704 + to allocate an output buffer for deflation in a single pass, and so would be 705 + called before deflate(). If that first deflate() call is provided the 706 + sourceLen input bytes, an output buffer allocated to the size returned by 707 + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed 708 + to return Z_STREAM_END. Note that it is possible for the compressed size to 709 + be larger than the value returned by deflateBound() if flush options other 710 + than Z_FINISH or Z_NO_FLUSH are used. 711 +*/ 712 + 713 +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, 714 + unsigned *pending, 715 + int *bits)); 716 +/* 717 + deflatePending() returns the number of bytes and bits of output that have 718 + been generated, but not yet provided in the available output. The bytes not 719 + provided would be due to the available output space having being consumed. 720 + The number of bits of output not provided are between 0 and 7, where they 721 + await more bits to join them in order to fill out a full byte. If pending 722 + or bits are Z_NULL, then those values are not set. 723 + 724 + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source 725 + stream state was inconsistent. 726 + */ 727 + 728 +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 729 + int bits, 730 + int value)); 731 +/* 732 + deflatePrime() inserts bits in the deflate output stream. The intent 733 + is that this function is used to start off the deflate output with the bits 734 + leftover from a previous deflate stream when appending to it. As such, this 735 + function can only be used for raw deflate, and must be used before the first 736 + deflate() call after a deflateInit2() or deflateReset(). bits must be less 737 + than or equal to 16, and that many of the least significant bits of value 738 + will be inserted in the output. 739 + 740 + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough 741 + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the 742 + source stream state was inconsistent. 743 +*/ 744 + 745 +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 746 + gz_headerp head)); 747 +/* 748 + deflateSetHeader() provides gzip header information for when a gzip 749 + stream is requested by deflateInit2(). deflateSetHeader() may be called 750 + after deflateInit2() or deflateReset() and before the first call of 751 + deflate(). The text, time, os, extra field, name, and comment information 752 + in the provided gz_header structure are written to the gzip header (xflag is 753 + ignored -- the extra flags are set according to the compression level). The 754 + caller must assure that, if not Z_NULL, name and comment are terminated with 755 + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 756 + available there. If hcrc is true, a gzip header crc is included. Note that 757 + the current versions of the command-line version of gzip (up through version 758 + 1.3.x) do not support header crc's, and will report that it is a "multi-part 759 + gzip file" and give up. 760 + 761 + If deflateSetHeader is not used, the default gzip header has text false, 762 + the time set to zero, and os set to 255, with no extra, name, or comment 763 + fields. The gzip header is returned to the default state by deflateReset(). 764 + 765 + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 766 + stream state was inconsistent. 767 +*/ 768 + 769 +/* 770 +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 771 + int windowBits)); 772 + 773 + This is another version of inflateInit with an extra parameter. The 774 + fields next_in, avail_in, zalloc, zfree and opaque must be initialized 775 + before by the caller. 776 + 777 + The windowBits parameter is the base two logarithm of the maximum window 778 + size (the size of the history buffer). It should be in the range 8..15 for 779 + this version of the library. The default value is 15 if inflateInit is used 780 + instead. windowBits must be greater than or equal to the windowBits value 781 + provided to deflateInit2() while compressing, or it must be equal to 15 if 782 + deflateInit2() was not used. If a compressed stream with a larger window 783 + size is given as input, inflate() will return with the error code 784 + Z_DATA_ERROR instead of trying to allocate a larger window. 785 + 786 + windowBits can also be zero to request that inflate use the window size in 787 + the zlib header of the compressed stream. 788 + 789 + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 790 + determines the window size. inflate() will then process raw deflate data, 791 + not looking for a zlib or gzip header, not generating a check value, and not 792 + looking for any check values for comparison at the end of the stream. This 793 + is for use with other formats that use the deflate compressed data format 794 + such as zip. Those formats provide their own check values. If a custom 795 + format is developed using the raw deflate format for compressed data, it is 796 + recommended that a check value such as an adler32 or a crc32 be applied to 797 + the uncompressed data as is done in the zlib, gzip, and zip formats. For 798 + most applications, the zlib format should be used as is. Note that comments 799 + above on the use in deflateInit2() applies to the magnitude of windowBits. 800 + 801 + windowBits can also be greater than 15 for optional gzip decoding. Add 802 + 32 to windowBits to enable zlib and gzip decoding with automatic header 803 + detection, or add 16 to decode only the gzip format (the zlib format will 804 + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a 805 + crc32 instead of an adler32. 806 + 807 + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 808 + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 809 + version assumed by the caller, or Z_STREAM_ERROR if the parameters are 810 + invalid, such as a null pointer to the structure. msg is set to null if 811 + there is no error message. inflateInit2 does not perform any decompression 812 + apart from possibly reading the zlib header if present: actual decompression 813 + will be done by inflate(). (So next_in and avail_in may be modified, but 814 + next_out and avail_out are unused and unchanged.) The current implementation 815 + of inflateInit2() does not process any header information -- that is 816 + deferred until inflate() is called. 817 +*/ 818 + 819 +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 820 + const Bytef *dictionary, 821 + uInt dictLength)); 822 +/* 823 + Initializes the decompression dictionary from the given uncompressed byte 824 + sequence. This function must be called immediately after a call of inflate, 825 + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 826 + can be determined from the adler32 value returned by that call of inflate. 827 + The compressor and decompressor must use exactly the same dictionary (see 828 + deflateSetDictionary). For raw inflate, this function can be called at any 829 + time to set the dictionary. If the provided dictionary is smaller than the 830 + window and there is already data in the window, then the provided dictionary 831 + will amend what's there. The application must insure that the dictionary 832 + that was used for compression is provided. 833 + 834 + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 835 + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 836 + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 837 + expected one (incorrect adler32 value). inflateSetDictionary does not 838 + perform any decompression: this will be done by subsequent calls of 839 + inflate(). 840 +*/ 841 + 842 +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 843 +/* 844 + Skips invalid compressed data until a possible full flush point (see above 845 + for the description of deflate with Z_FULL_FLUSH) can be found, or until all 846 + available input is skipped. No output is provided. 847 + 848 + inflateSync searches for a 00 00 FF FF pattern in the compressed data. 849 + All full flush points have this pattern, but not all occurences of this 850 + pattern are full flush points. 851 + 852 + inflateSync returns Z_OK if a possible full flush point has been found, 853 + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point 854 + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. 855 + In the success case, the application may save the current current value of 856 + total_in which indicates where valid compressed data was found. In the 857 + error case, the application may repeatedly call inflateSync, providing more 858 + input each time, until success or end of the input data. 859 +*/ 860 + 861 +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 862 + z_streamp source)); 863 +/* 864 + Sets the destination stream as a complete copy of the source stream. 865 + 866 + This function can be useful when randomly accessing a large stream. The 867 + first pass through the stream can periodically record the inflate state, 868 + allowing restarting inflate at those points when randomly accessing the 869 + stream. 870 + 871 + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 872 + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 873 + (such as zalloc being Z_NULL). msg is left unchanged in both source and 874 + destination. 875 +*/ 876 + 877 +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 878 +/* 879 + This function is equivalent to inflateEnd followed by inflateInit, 880 + but does not free and reallocate all the internal decompression state. The 881 + stream will keep attributes that may have been set by inflateInit2. 882 + 883 + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 884 + stream state was inconsistent (such as zalloc or state being Z_NULL). 885 +*/ 886 + 887 +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, 888 + int windowBits)); 889 +/* 890 + This function is the same as inflateReset, but it also permits changing 891 + the wrap and window size requests. The windowBits parameter is interpreted 892 + the same as it is for inflateInit2. 893 + 894 + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 895 + stream state was inconsistent (such as zalloc or state being Z_NULL), or if 896 + the windowBits parameter is invalid. 897 +*/ 898 + 899 +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 900 + int bits, 901 + int value)); 902 +/* 903 + This function inserts bits in the inflate input stream. The intent is 904 + that this function is used to start inflating at a bit position in the 905 + middle of a byte. The provided bits will be used before any bytes are used 906 + from next_in. This function should only be used with raw inflate, and 907 + should be used before the first inflate() call after inflateInit2() or 908 + inflateReset(). bits must be less than or equal to 16, and that many of the 909 + least significant bits of value will be inserted in the input. 910 + 911 + If bits is negative, then the input stream bit buffer is emptied. Then 912 + inflatePrime() can be called again to put bits in the buffer. This is used 913 + to clear out bits leftover after feeding inflate a block description prior 914 + to feeding inflate codes. 915 + 916 + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 917 + stream state was inconsistent. 918 +*/ 919 + 920 +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); 921 +/* 922 + This function returns two values, one in the lower 16 bits of the return 923 + value, and the other in the remaining upper bits, obtained by shifting the 924 + return value down 16 bits. If the upper value is -1 and the lower value is 925 + zero, then inflate() is currently decoding information outside of a block. 926 + If the upper value is -1 and the lower value is non-zero, then inflate is in 927 + the middle of a stored block, with the lower value equaling the number of 928 + bytes from the input remaining to copy. If the upper value is not -1, then 929 + it is the number of bits back from the current bit position in the input of 930 + the code (literal or length/distance pair) currently being processed. In 931 + that case the lower value is the number of bytes already emitted for that 932 + code. 933 + 934 + A code is being processed if inflate is waiting for more input to complete 935 + decoding of the code, or if it has completed decoding but is waiting for 936 + more output space to write the literal or match data. 937 + 938 + inflateMark() is used to mark locations in the input data for random 939 + access, which may be at bit positions, and to note those cases where the 940 + output of a code may span boundaries of random access blocks. The current 941 + location in the input stream can be determined from avail_in and data_type 942 + as noted in the description for the Z_BLOCK flush parameter for inflate. 943 + 944 + inflateMark returns the value noted above or -1 << 16 if the provided 945 + source stream state was inconsistent. 946 +*/ 947 + 948 +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 949 + gz_headerp head)); 950 +/* 951 + inflateGetHeader() requests that gzip header information be stored in the 952 + provided gz_header structure. inflateGetHeader() may be called after 953 + inflateInit2() or inflateReset(), and before the first call of inflate(). 954 + As inflate() processes the gzip stream, head->done is zero until the header 955 + is completed, at which time head->done is set to one. If a zlib stream is 956 + being decoded, then head->done is set to -1 to indicate that there will be 957 + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be 958 + used to force inflate() to return immediately after header processing is 959 + complete and before any actual data is decompressed. 960 + 961 + The text, time, xflags, and os fields are filled in with the gzip header 962 + contents. hcrc is set to true if there is a header CRC. (The header CRC 963 + was valid if done is set to one.) If extra is not Z_NULL, then extra_max 964 + contains the maximum number of bytes to write to extra. Once done is true, 965 + extra_len contains the actual extra field length, and extra contains the 966 + extra field, or that field truncated if extra_max is less than extra_len. 967 + If name is not Z_NULL, then up to name_max characters are written there, 968 + terminated with a zero unless the length is greater than name_max. If 969 + comment is not Z_NULL, then up to comm_max characters are written there, 970 + terminated with a zero unless the length is greater than comm_max. When any 971 + of extra, name, or comment are not Z_NULL and the respective field is not 972 + present in the header, then that field is set to Z_NULL to signal its 973 + absence. This allows the use of deflateSetHeader() with the returned 974 + structure to duplicate the header. However if those fields are set to 975 + allocated memory, then the application will need to save those pointers 976 + elsewhere so that they can be eventually freed. 977 + 978 + If inflateGetHeader is not used, then the header information is simply 979 + discarded. The header is always checked for validity, including the header 980 + CRC if present. inflateReset() will reset the process to discard the header 981 + information. The application would need to call inflateGetHeader() again to 982 + retrieve the header from the next gzip stream. 983 + 984 + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 985 + stream state was inconsistent. 986 +*/ 987 + 988 +/* 989 +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 990 + unsigned char FAR *window)); 991 + 992 + Initialize the internal stream state for decompression using inflateBack() 993 + calls. The fields zalloc, zfree and opaque in strm must be initialized 994 + before the call. If zalloc and zfree are Z_NULL, then the default library- 995 + derived memory allocation routines are used. windowBits is the base two 996 + logarithm of the window size, in the range 8..15. window is a caller 997 + supplied buffer of that size. Except for special applications where it is 998 + assured that deflate was used with small window sizes, windowBits must be 15 999 + and a 32K byte window must be supplied to be able to decompress general 1000 + deflate streams. 1001 + 1002 + See inflateBack() for the usage of these routines. 1003 + 1004 + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 1005 + the parameters are invalid, Z_MEM_ERROR if the internal state could not be 1006 + allocated, or Z_VERSION_ERROR if the version of the library does not match 1007 + the version of the header file. 1008 +*/ 1009 + 1010 +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 1011 +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 1012 + 1013 +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 1014 + in_func in, void FAR *in_desc, 1015 + out_func out, void FAR *out_desc)); 1016 +/* 1017 + inflateBack() does a raw inflate with a single call using a call-back 1018 + interface for input and output. This is more efficient than inflate() for 1019 + file i/o applications in that it avoids copying between the output and the 1020 + sliding window by simply making the window itself the output buffer. This 1021 + function trusts the application to not change the output buffer passed by 1022 + the output function, at least until inflateBack() returns. 1023 + 1024 + inflateBackInit() must be called first to allocate the internal state 1025 + and to initialize the state with the user-provided window buffer. 1026 + inflateBack() may then be used multiple times to inflate a complete, raw 1027 + deflate stream with each call. inflateBackEnd() is then called to free the 1028 + allocated state. 1029 + 1030 + A raw deflate stream is one with no zlib or gzip header or trailer. 1031 + This routine would normally be used in a utility that reads zip or gzip 1032 + files and writes out uncompressed files. The utility would decode the 1033 + header and process the trailer on its own, hence this routine expects only 1034 + the raw deflate stream to decompress. This is different from the normal 1035 + behavior of inflate(), which expects either a zlib or gzip header and 1036 + trailer around the deflate stream. 1037 + 1038 + inflateBack() uses two subroutines supplied by the caller that are then 1039 + called by inflateBack() for input and output. inflateBack() calls those 1040 + routines until it reads a complete deflate stream and writes out all of the 1041 + uncompressed data, or until it encounters an error. The function's 1042 + parameters and return types are defined above in the in_func and out_func 1043 + typedefs. inflateBack() will call in(in_desc, &buf) which should return the 1044 + number of bytes of provided input, and a pointer to that input in buf. If 1045 + there is no input available, in() must return zero--buf is ignored in that 1046 + case--and inflateBack() will return a buffer error. inflateBack() will call 1047 + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 1048 + should return zero on success, or non-zero on failure. If out() returns 1049 + non-zero, inflateBack() will return with an error. Neither in() nor out() 1050 + are permitted to change the contents of the window provided to 1051 + inflateBackInit(), which is also the buffer that out() uses to write from. 1052 + The length written by out() will be at most the window size. Any non-zero 1053 + amount of input may be provided by in(). 1054 + 1055 + For convenience, inflateBack() can be provided input on the first call by 1056 + setting strm->next_in and strm->avail_in. If that input is exhausted, then 1057 + in() will be called. Therefore strm->next_in must be initialized before 1058 + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 1059 + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 1060 + must also be initialized, and then if strm->avail_in is not zero, input will 1061 + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 1062 + 1063 + The in_desc and out_desc parameters of inflateBack() is passed as the 1064 + first parameter of in() and out() respectively when they are called. These 1065 + descriptors can be optionally used to pass any information that the caller- 1066 + supplied in() and out() functions need to do their job. 1067 + 1068 + On return, inflateBack() will set strm->next_in and strm->avail_in to 1069 + pass back any unused input that was provided by the last in() call. The 1070 + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 1071 + if in() or out() returned an error, Z_DATA_ERROR if there was a format error 1072 + in the deflate stream (in which case strm->msg is set to indicate the nature 1073 + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. 1074 + In the case of Z_BUF_ERROR, an input or output error can be distinguished 1075 + using strm->next_in which will be Z_NULL only if in() returned an error. If 1076 + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning 1077 + non-zero. (in() will always be called before out(), so strm->next_in is 1078 + assured to be defined if out() returns non-zero.) Note that inflateBack() 1079 + cannot return Z_OK. 1080 +*/ 1081 + 1082 +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 1083 +/* 1084 + All memory allocated by inflateBackInit() is freed. 1085 + 1086 + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 1087 + state was inconsistent. 1088 +*/ 1089 + 1090 +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 1091 +/* Return flags indicating compile-time options. 1092 + 1093 + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 1094 + 1.0: size of uInt 1095 + 3.2: size of uLong 1096 + 5.4: size of voidpf (pointer) 1097 + 7.6: size of z_off_t 1098 + 1099 + Compiler, assembler, and debug options: 1100 + 8: DEBUG 1101 + 9: ASMV or ASMINF -- use ASM code 1102 + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 1103 + 11: 0 (reserved) 1104 + 1105 + One-time table building (smaller code, but not thread-safe if true): 1106 + 12: BUILDFIXED -- build static block decoding tables when needed 1107 + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 1108 + 14,15: 0 (reserved) 1109 + 1110 + Library content (indicates missing functionality): 1111 + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 1112 + deflate code when not needed) 1113 + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 1114 + and decode gzip streams (to avoid linking crc code) 1115 + 18-19: 0 (reserved) 1116 + 1117 + Operation variations (changes in library functionality): 1118 + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 1119 + 21: FASTEST -- deflate algorithm with only one, lowest compression level 1120 + 22,23: 0 (reserved) 1121 + 1122 + The sprintf variant used by gzprintf (zero is best): 1123 + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 1124 + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 1125 + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 1126 + 1127 + Remainder: 1128 + 27-31: 0 (reserved) 1129 + */ 1130 + 1131 +#ifndef Z_SOLO 1132 + 1133 + /* utility functions */ 1134 + 1135 +/* 1136 + The following utility functions are implemented on top of the basic 1137 + stream-oriented functions. To simplify the interface, some default options 1138 + are assumed (compression level and memory usage, standard memory allocation 1139 + functions). The source code of these utility functions can be modified if 1140 + you need special options. 1141 +*/ 1142 + 1143 +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1144 + const Bytef *source, uLong sourceLen)); 1145 +/* 1146 + Compresses the source buffer into the destination buffer. sourceLen is 1147 + the byte length of the source buffer. Upon entry, destLen is the total size 1148 + of the destination buffer, which must be at least the value returned by 1149 + compressBound(sourceLen). Upon exit, destLen is the actual size of the 1150 + compressed buffer. 1151 + 1152 + compress returns Z_OK if success, Z_MEM_ERROR if there was not 1153 + enough memory, Z_BUF_ERROR if there was not enough room in the output 1154 + buffer. 1155 +*/ 1156 + 1157 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 1158 + const Bytef *source, uLong sourceLen, 1159 + int level)); 1160 +/* 1161 + Compresses the source buffer into the destination buffer. The level 1162 + parameter has the same meaning as in deflateInit. sourceLen is the byte 1163 + length of the source buffer. Upon entry, destLen is the total size of the 1164 + destination buffer, which must be at least the value returned by 1165 + compressBound(sourceLen). Upon exit, destLen is the actual size of the 1166 + compressed buffer. 1167 + 1168 + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1169 + memory, Z_BUF_ERROR if there was not enough room in the output buffer, 1170 + Z_STREAM_ERROR if the level parameter is invalid. 1171 +*/ 1172 + 1173 +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1174 +/* 1175 + compressBound() returns an upper bound on the compressed size after 1176 + compress() or compress2() on sourceLen bytes. It would be used before a 1177 + compress() or compress2() call to allocate the destination buffer. 1178 +*/ 1179 + 1180 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1181 + const Bytef *source, uLong sourceLen)); 1182 +/* 1183 + Decompresses the source buffer into the destination buffer. sourceLen is 1184 + the byte length of the source buffer. Upon entry, destLen is the total size 1185 + of the destination buffer, which must be large enough to hold the entire 1186 + uncompressed data. (The size of the uncompressed data must have been saved 1187 + previously by the compressor and transmitted to the decompressor by some 1188 + mechanism outside the scope of this compression library.) Upon exit, destLen 1189 + is the actual size of the uncompressed buffer. 1190 + 1191 + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1192 + enough memory, Z_BUF_ERROR if there was not enough room in the output 1193 + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In 1194 + the case where there is not enough room, uncompress() will fill the output 1195 + buffer with the uncompressed data up to that point. 1196 +*/ 1197 + 1198 + /* gzip file access functions */ 1199 + 1200 +/* 1201 + This library supports reading and writing files in gzip (.gz) format with 1202 + an interface similar to that of stdio, using the functions that start with 1203 + "gz". The gzip format is different from the zlib format. gzip is a gzip 1204 + wrapper, documented in RFC 1952, wrapped around a deflate stream. 1205 +*/ 1206 + 1207 +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ 1208 + 1209 +/* 1210 +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1211 + 1212 + Opens a gzip (.gz) file for reading or writing. The mode parameter is as 1213 + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or 1214 + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only 1215 + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' 1216 + for fixed code compression as in "wb9F". (See the description of 1217 + deflateInit2 for more information about the strategy parameter.) 'T' will 1218 + request transparent writing or appending with no compression and not using 1219 + the gzip format. 1220 + 1221 + "a" can be used instead of "w" to request that the gzip stream that will 1222 + be written be appended to the file. "+" will result in an error, since 1223 + reading and writing to the same gzip file is not supported. The addition of 1224 + "x" when writing will create the file exclusively, which fails if the file 1225 + already exists. On systems that support it, the addition of "e" when 1226 + reading or writing will set the flag to close the file on an execve() call. 1227 + 1228 + These functions, as well as gzip, will read and decode a sequence of gzip 1229 + streams in a file. The append function of gzopen() can be used to create 1230 + such a file. (Also see gzflush() for another way to do this.) When 1231 + appending, gzopen does not test whether the file begins with a gzip stream, 1232 + nor does it look for the end of the gzip streams to begin appending. gzopen 1233 + will simply append a gzip stream to the existing file. 1234 + 1235 + gzopen can be used to read a file which is not in gzip format; in this 1236 + case gzread will directly read from the file without decompression. When 1237 + reading, this will be detected automatically by looking for the magic two- 1238 + byte gzip header. 1239 + 1240 + gzopen returns NULL if the file could not be opened, if there was 1241 + insufficient memory to allocate the gzFile state, or if an invalid mode was 1242 + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). 1243 + errno can be checked to determine if the reason gzopen failed was that the 1244 + file could not be opened. 1245 +*/ 1246 + 1247 +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1248 +/* 1249 + gzdopen associates a gzFile with the file descriptor fd. File descriptors 1250 + are obtained from calls like open, dup, creat, pipe or fileno (if the file 1251 + has been previously opened with fopen). The mode parameter is as in gzopen. 1252 + 1253 + The next call of gzclose on the returned gzFile will also close the file 1254 + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor 1255 + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, 1256 + mode);. The duplicated descriptor should be saved to avoid a leak, since 1257 + gzdopen does not close fd if it fails. If you are using fileno() to get the 1258 + file descriptor from a FILE *, then you will have to use dup() to avoid 1259 + double-close()ing the file descriptor. Both gzclose() and fclose() will 1260 + close the associated file descriptor, so they need to have different file 1261 + descriptors. 1262 + 1263 + gzdopen returns NULL if there was insufficient memory to allocate the 1264 + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not 1265 + provided, or '+' was provided), or if fd is -1. The file descriptor is not 1266 + used until the next gz* read, write, seek, or close operation, so gzdopen 1267 + will not detect if fd is invalid (unless fd is -1). 1268 +*/ 1269 + 1270 +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); 1271 +/* 1272 + Set the internal buffer size used by this library's functions. The 1273 + default buffer size is 8192 bytes. This function must be called after 1274 + gzopen() or gzdopen(), and before any other calls that read or write the 1275 + file. The buffer memory allocation is always deferred to the first read or 1276 + write. Two buffers are allocated, either both of the specified size when 1277 + writing, or one of the specified size and the other twice that size when 1278 + reading. A larger buffer size of, for example, 64K or 128K bytes will 1279 + noticeably increase the speed of decompression (reading). 1280 + 1281 + The new buffer size also affects the maximum length for gzprintf(). 1282 + 1283 + gzbuffer() returns 0 on success, or -1 on failure, such as being called 1284 + too late. 1285 +*/ 1286 + 1287 +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1288 +/* 1289 + Dynamically update the compression level or strategy. See the description 1290 + of deflateInit2 for the meaning of these parameters. 1291 + 1292 + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 1293 + opened for writing. 1294 +*/ 1295 + 1296 +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1297 +/* 1298 + Reads the given number of uncompressed bytes from the compressed file. If 1299 + the input file is not in gzip format, gzread copies the given number of 1300 + bytes into the buffer directly from the file. 1301 + 1302 + After reaching the end of a gzip stream in the input, gzread will continue 1303 + to read, looking for another gzip stream. Any number of gzip streams may be 1304 + concatenated in the input file, and will all be decompressed by gzread(). 1305 + If something other than a gzip stream is encountered after a gzip stream, 1306 + that remaining trailing garbage is ignored (and no error is returned). 1307 + 1308 + gzread can be used to read a gzip file that is being concurrently written. 1309 + Upon reaching the end of the input, gzread will return with the available 1310 + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then 1311 + gzclearerr can be used to clear the end of file indicator in order to permit 1312 + gzread to be tried again. Z_OK indicates that a gzip stream was completed 1313 + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the 1314 + middle of a gzip stream. Note that gzread does not return -1 in the event 1315 + of an incomplete gzip stream. This error is deferred until gzclose(), which 1316 + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip 1317 + stream. Alternatively, gzerror can be used before gzclose to detect this 1318 + case. 1319 + 1320 + gzread returns the number of uncompressed bytes actually read, less than 1321 + len for end of file, or -1 for error. 1322 +*/ 1323 + 1324 +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 1325 + voidpc buf, unsigned len)); 1326 +/* 1327 + Writes the given number of uncompressed bytes into the compressed file. 1328 + gzwrite returns the number of uncompressed bytes written or 0 in case of 1329 + error. 1330 +*/ 1331 + 1332 +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); 1333 +/* 1334 + Converts, formats, and writes the arguments to the compressed file under 1335 + control of the format string, as in fprintf. gzprintf returns the number of 1336 + uncompressed bytes actually written, or 0 in case of error. The number of 1337 + uncompressed bytes written is limited to 8191, or one less than the buffer 1338 + size given to gzbuffer(). The caller should assure that this limit is not 1339 + exceeded. If it is exceeded, then gzprintf() will return an error (0) with 1340 + nothing written. In this case, there may also be a buffer overflow with 1341 + unpredictable consequences, which is possible only if zlib was compiled with 1342 + the insecure functions sprintf() or vsprintf() because the secure snprintf() 1343 + or vsnprintf() functions were not available. This can be determined using 1344 + zlibCompileFlags(). 1345 +*/ 1346 + 1347 +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1348 +/* 1349 + Writes the given null-terminated string to the compressed file, excluding 1350 + the terminating null character. 1351 + 1352 + gzputs returns the number of characters written, or -1 in case of error. 1353 +*/ 1354 + 1355 +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1356 +/* 1357 + Reads bytes from the compressed file until len-1 characters are read, or a 1358 + newline character is read and transferred to buf, or an end-of-file 1359 + condition is encountered. If any characters are read or if len == 1, the 1360 + string is terminated with a null character. If no characters are read due 1361 + to an end-of-file or len < 1, then the buffer is left untouched. 1362 + 1363 + gzgets returns buf which is a null-terminated string, or it returns NULL 1364 + for end-of-file or in case of error. If there was an error, the contents at 1365 + buf are indeterminate. 1366 +*/ 1367 + 1368 +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1369 +/* 1370 + Writes c, converted to an unsigned char, into the compressed file. gzputc 1371 + returns the value that was written, or -1 in case of error. 1372 +*/ 1373 + 1374 +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1375 +/* 1376 + Reads one byte from the compressed file. gzgetc returns this byte or -1 1377 + in case of end of file or error. This is implemented as a macro for speed. 1378 + As such, it does not do all of the checking the other functions do. I.e. 1379 + it does not check to see if file is NULL, nor whether the structure file 1380 + points to has been clobbered or not. 1381 +*/ 1382 + 1383 +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1384 +/* 1385 + Push one character back onto the stream to be read as the first character 1386 + on the next read. At least one character of push-back is allowed. 1387 + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will 1388 + fail if c is -1, and may fail if a character has been pushed but not read 1389 + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the 1390 + output buffer size of pushed characters is allowed. (See gzbuffer above.) 1391 + The pushed character will be discarded if the stream is repositioned with 1392 + gzseek() or gzrewind(). 1393 +*/ 1394 + 1395 +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1396 +/* 1397 + Flushes all pending output into the compressed file. The parameter flush 1398 + is as in the deflate() function. The return value is the zlib error number 1399 + (see function gzerror below). gzflush is only permitted when writing. 1400 + 1401 + If the flush parameter is Z_FINISH, the remaining data is written and the 1402 + gzip stream is completed in the output. If gzwrite() is called again, a new 1403 + gzip stream will be started in the output. gzread() is able to read such 1404 + concatented gzip streams. 1405 + 1406 + gzflush should be called only when strictly necessary because it will 1407 + degrade compression if called too often. 1408 +*/ 1409 + 1410 +/* 1411 +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1412 + z_off_t offset, int whence)); 1413 + 1414 + Sets the starting position for the next gzread or gzwrite on the given 1415 + compressed file. The offset represents a number of bytes in the 1416 + uncompressed data stream. The whence parameter is defined as in lseek(2); 1417 + the value SEEK_END is not supported. 1418 + 1419 + If the file is opened for reading, this function is emulated but can be 1420 + extremely slow. If the file is opened for writing, only forward seeks are 1421 + supported; gzseek then compresses a sequence of zeroes up to the new 1422 + starting position. 1423 + 1424 + gzseek returns the resulting offset location as measured in bytes from 1425 + the beginning of the uncompressed stream, or -1 in case of error, in 1426 + particular if the file is opened for writing and the new starting position 1427 + would be before the current position. 1428 +*/ 1429 + 1430 +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 1431 +/* 1432 + Rewinds the given file. This function is supported only for reading. 1433 + 1434 + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 1435 +*/ 1436 + 1437 +/* 1438 +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1439 + 1440 + Returns the starting position for the next gzread or gzwrite on the given 1441 + compressed file. This position represents a number of bytes in the 1442 + uncompressed data stream, and is zero when starting, even if appending or 1443 + reading a gzip stream from the middle of a file using gzdopen(). 1444 + 1445 + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1446 +*/ 1447 + 1448 +/* 1449 +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); 1450 + 1451 + Returns the current offset in the file being read or written. This offset 1452 + includes the count of bytes that precede the gzip stream, for example when 1453 + appending or when using gzdopen() for reading. When reading, the offset 1454 + does not include as yet unused buffered input. This information can be used 1455 + for a progress indicator. On error, gzoffset() returns -1. 1456 +*/ 1457 + 1458 +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1459 +/* 1460 + Returns true (1) if the end-of-file indicator has been set while reading, 1461 + false (0) otherwise. Note that the end-of-file indicator is set only if the 1462 + read tried to go past the end of the input, but came up short. Therefore, 1463 + just like feof(), gzeof() may return false even if there is no more data to 1464 + read, in the event that the last read request was for the exact number of 1465 + bytes remaining in the input file. This will happen if the input file size 1466 + is an exact multiple of the buffer size. 1467 + 1468 + If gzeof() returns true, then the read functions will return no more data, 1469 + unless the end-of-file indicator is reset by gzclearerr() and the input file 1470 + has grown since the previous end of file was detected. 1471 +*/ 1472 + 1473 +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1474 +/* 1475 + Returns true (1) if file is being copied directly while reading, or false 1476 + (0) if file is a gzip stream being decompressed. 1477 + 1478 + If the input file is empty, gzdirect() will return true, since the input 1479 + does not contain a gzip stream. 1480 + 1481 + If gzdirect() is used immediately after gzopen() or gzdopen() it will 1482 + cause buffers to be allocated to allow reading the file to determine if it 1483 + is a gzip file. Therefore if gzbuffer() is used, it should be called before 1484 + gzdirect(). 1485 + 1486 + When writing, gzdirect() returns true (1) if transparent writing was 1487 + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: 1488 + gzdirect() is not needed when writing. Transparent writing must be 1489 + explicitly requested, so the application already knows the answer. When 1490 + linking statically, using gzdirect() will include all of the zlib code for 1491 + gzip file reading and decompression, which may not be desired.) 1492 +*/ 1493 + 1494 +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1495 +/* 1496 + Flushes all pending output if necessary, closes the compressed file and 1497 + deallocates the (de)compression state. Note that once file is closed, you 1498 + cannot call gzerror with file, since its structures have been deallocated. 1499 + gzclose must not be called more than once on the same file, just as free 1500 + must not be called more than once on the same allocation. 1501 + 1502 + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a 1503 + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the 1504 + last read ended in the middle of a gzip stream, or Z_OK on success. 1505 +*/ 1506 + 1507 +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); 1508 +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); 1509 +/* 1510 + Same as gzclose(), but gzclose_r() is only for use when reading, and 1511 + gzclose_w() is only for use when writing or appending. The advantage to 1512 + using these instead of gzclose() is that they avoid linking in zlib 1513 + compression or decompression code that is not used when only reading or only 1514 + writing respectively. If gzclose() is used, then both compression and 1515 + decompression code will be included the application when linking to a static 1516 + zlib library. 1517 +*/ 1518 + 1519 +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1520 +/* 1521 + Returns the error message for the last error which occurred on the given 1522 + compressed file. errnum is set to zlib error number. If an error occurred 1523 + in the file system and not in the compression library, errnum is set to 1524 + Z_ERRNO and the application may consult errno to get the exact error code. 1525 + 1526 + The application must not modify the returned string. Future calls to 1527 + this function may invalidate the previously returned string. If file is 1528 + closed, then the string previously returned by gzerror will no longer be 1529 + available. 1530 + 1531 + gzerror() should be used to distinguish errors from end-of-file for those 1532 + functions above that do not distinguish those cases in their return values. 1533 +*/ 1534 + 1535 +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1536 +/* 1537 + Clears the error and end-of-file flags for file. This is analogous to the 1538 + clearerr() function in stdio. This is useful for continuing to read a gzip 1539 + file that is being written concurrently. 1540 +*/ 1541 + 1542 +#endif /* !Z_SOLO */ 1543 + 1544 + /* checksum functions */ 1545 + 1546 +/* 1547 + These functions are not related to compression but are exported 1548 + anyway because they might be useful in applications using the compression 1549 + library. 1550 +*/ 1551 + 1552 +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 1553 +/* 1554 + Update a running Adler-32 checksum with the bytes buf[0..len-1] and 1555 + return the updated checksum. If buf is Z_NULL, this function returns the 1556 + required initial value for the checksum. 1557 + 1558 + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1559 + much faster. 1560 + 1561 + Usage example: 1562 + 1563 + uLong adler = adler32(0L, Z_NULL, 0); 1564 + 1565 + while (read_buffer(buffer, length) != EOF) { 1566 + adler = adler32(adler, buffer, length); 1567 + } 1568 + if (adler != original_adler) error(); 1569 +*/ 1570 + 1571 +/* 1572 +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 1573 + z_off_t len2)); 1574 + 1575 + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 1576 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 1577 + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 1578 + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note 1579 + that the z_off_t type (like off_t) is a signed integer. If len2 is 1580 + negative, the result has no meaning or utility. 1581 +*/ 1582 + 1583 +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 1584 +/* 1585 + Update a running CRC-32 with the bytes buf[0..len-1] and return the 1586 + updated CRC-32. If buf is Z_NULL, this function returns the required 1587 + initial value for the crc. Pre- and post-conditioning (one's complement) is 1588 + performed within this function so it shouldn't be done by the application. 1589 + 1590 + Usage example: 1591 + 1592 + uLong crc = crc32(0L, Z_NULL, 0); 1593 + 1594 + while (read_buffer(buffer, length) != EOF) { 1595 + crc = crc32(crc, buffer, length); 1596 + } 1597 + if (crc != original_crc) error(); 1598 +*/ 1599 + 1600 +/* 1601 +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 1602 + 1603 + Combine two CRC-32 check values into one. For two sequences of bytes, 1604 + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 1605 + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 1606 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 1607 + len2. 1608 +*/ 1609 + 1610 + 1611 + /* various hacks, don't look :) */ 1612 + 1613 +/* deflateInit and inflateInit are macros to allow checking the zlib version 1614 + * and the compiler's view of z_stream: 1615 + */ 1616 +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 1617 + const char *version, int stream_size)); 1618 +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 1619 + const char *version, int stream_size)); 1620 +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 1621 + int windowBits, int memLevel, 1622 + int strategy, const char *version, 1623 + int stream_size)); 1624 +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 1625 + const char *version, int stream_size)); 1626 +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 1627 + unsigned char FAR *window, 1628 + const char *version, 1629 + int stream_size)); 1630 +#define deflateInit(strm, level) \ 1631 + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 1632 +#define inflateInit(strm) \ 1633 + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 1634 +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 1635 + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 1636 + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 1637 +#define inflateInit2(strm, windowBits) \ 1638 + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 1639 + (int)sizeof(z_stream)) 1640 +#define inflateBackInit(strm, windowBits, window) \ 1641 + inflateBackInit_((strm), (windowBits), (window), \ 1642 + ZLIB_VERSION, (int)sizeof(z_stream)) 1643 + 1644 +#ifndef Z_SOLO 1645 + 1646 +/* gzgetc() macro and its supporting function and exposed data structure. Note 1647 + * that the real internal state is much larger than the exposed structure. 1648 + * This abbreviated structure exposes just enough for the gzgetc() macro. The 1649 + * user should not mess with these exposed elements, since their names or 1650 + * behavior could change in the future, perhaps even capriciously. They can 1651 + * only be used by the gzgetc() macro. You have been warned. 1652 + */ 1653 +struct gzFile_s { 1654 + unsigned have; 1655 + unsigned char *next; 1656 + z_off64_t pos; 1657 +}; 1658 +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ 1659 +#ifdef Z_PREFIX_SET 1660 +# undef z_gzgetc 1661 +# define z_gzgetc(g) \ 1662 + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) 1663 +#else 1664 +# define gzgetc(g) \ 1665 + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) 1666 +#endif 1667 + 1668 +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or 1669 + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if 1670 + * both are true, the application gets the *64 functions, and the regular 1671 + * functions are changed to 64 bits) -- in case these are set on systems 1672 + * without large file support, _LFS64_LARGEFILE must also be true 1673 + */ 1674 +#ifdef Z_LARGE64 1675 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1676 + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 1677 + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 1678 + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 1679 + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); 1680 + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); 1681 +#endif 1682 + 1683 +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) 1684 +# ifdef Z_PREFIX_SET 1685 +# define z_gzopen z_gzopen64 1686 +# define z_gzseek z_gzseek64 1687 +# define z_gztell z_gztell64 1688 +# define z_gzoffset z_gzoffset64 1689 +# define z_adler32_combine z_adler32_combine64 1690 +# define z_crc32_combine z_crc32_combine64 1691 +# else 1692 +# define gzopen gzopen64 1693 +# define gzseek gzseek64 1694 +# define gztell gztell64 1695 +# define gzoffset gzoffset64 1696 +# define adler32_combine adler32_combine64 1697 +# define crc32_combine crc32_combine64 1698 +# endif 1699 +# ifndef Z_LARGE64 1700 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1701 + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); 1702 + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); 1703 + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); 1704 + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 1705 + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 1706 +# endif 1707 +#else 1708 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 1709 + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); 1710 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 1711 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 1712 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1713 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1714 +#endif 1715 + 1716 +#else /* Z_SOLO */ 1717 + 1718 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1719 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1720 + 1721 +#endif /* !Z_SOLO */ 1722 + 1723 +/* hack for buggy compilers */ 1724 +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 1725 + struct internal_state {int dummy;}; 1726 +#endif 1727 + 1728 +/* undocumented functions */ 1729 +ZEXTERN const char * ZEXPORT zError OF((int)); 1730 +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); 1731 +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); 1732 +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); 1733 +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); 1734 +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); 1735 +#if defined(_WIN32) && !defined(Z_SOLO) 1736 +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, 1737 + const char *mode)); 1738 +#endif 1739 + 1740 +#ifdef __cplusplus 1741 +} 1742 +#endif 1743 + 1744 +#endif /* ZLIB_H */
Added compat/zlib/zlib.map.
1 +ZLIB_1.2.0 { 2 + global: 3 + compressBound; 4 + deflateBound; 5 + inflateBack; 6 + inflateBackEnd; 7 + inflateBackInit_; 8 + inflateCopy; 9 + local: 10 + deflate_copyright; 11 + inflate_copyright; 12 + inflate_fast; 13 + inflate_table; 14 + zcalloc; 15 + zcfree; 16 + z_errmsg; 17 + gz_error; 18 + gz_intmax; 19 + _*; 20 +}; 21 + 22 +ZLIB_1.2.0.2 { 23 + gzclearerr; 24 + gzungetc; 25 + zlibCompileFlags; 26 +} ZLIB_1.2.0; 27 + 28 +ZLIB_1.2.0.8 { 29 + deflatePrime; 30 +} ZLIB_1.2.0.2; 31 + 32 +ZLIB_1.2.2 { 33 + adler32_combine; 34 + crc32_combine; 35 + deflateSetHeader; 36 + inflateGetHeader; 37 +} ZLIB_1.2.0.8; 38 + 39 +ZLIB_1.2.2.3 { 40 + deflateTune; 41 + gzdirect; 42 +} ZLIB_1.2.2; 43 + 44 +ZLIB_1.2.2.4 { 45 + inflatePrime; 46 +} ZLIB_1.2.2.3; 47 + 48 +ZLIB_1.2.3.3 { 49 + adler32_combine64; 50 + crc32_combine64; 51 + gzopen64; 52 + gzseek64; 53 + gztell64; 54 + inflateUndermine; 55 +} ZLIB_1.2.2.4; 56 + 57 +ZLIB_1.2.3.4 { 58 + inflateReset2; 59 + inflateMark; 60 +} ZLIB_1.2.3.3; 61 + 62 +ZLIB_1.2.3.5 { 63 + gzbuffer; 64 + gzoffset; 65 + gzoffset64; 66 + gzclose_r; 67 + gzclose_w; 68 +} ZLIB_1.2.3.4; 69 + 70 +ZLIB_1.2.5.1 { 71 + deflatePending; 72 +} ZLIB_1.2.3.5; 73 + 74 +ZLIB_1.2.5.2 { 75 + deflateResetKeep; 76 + gzgetc_; 77 + inflateResetKeep; 78 +} ZLIB_1.2.5.1;
Added compat/zlib/zlib.pc.cmakein.
1 +prefix=@CMAKE_INSTALL_PREFIX@ 2 +exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 +libdir=@INSTALL_LIB_DIR@ 4 +sharedlibdir=@INSTALL_LIB_DIR@ 5 +includedir=@INSTALL_INC_DIR@ 6 + 7 +Name: zlib 8 +Description: zlib compression library 9 +Version: @VERSION@ 10 + 11 +Requires: 12 +Libs: -L${libdir} -L${sharedlibdir} -lz 13 +Cflags: -I${includedir}
Added compat/zlib/zlib.pc.in.
1 +prefix=@prefix@ 2 +exec_prefix=@exec_prefix@ 3 +libdir=@libdir@ 4 +sharedlibdir=@sharedlibdir@ 5 +includedir=@includedir@ 6 + 7 +Name: zlib 8 +Description: zlib compression library 9 +Version: @VERSION@ 10 + 11 +Requires: 12 +Libs: -L${libdir} -L${sharedlibdir} -lz 13 +Cflags: -I${includedir}
Added compat/zlib/zlib2ansi.
1 +#!/usr/bin/perl 2 + 3 +# Transform K&R C function definitions into ANSI equivalent. 4 +# 5 +# Author: Paul Marquess 6 +# Version: 1.0 7 +# Date: 3 October 2006 8 + 9 +# TODO 10 +# 11 +# Asumes no function pointer parameters. unless they are typedefed. 12 +# Assumes no literal strings that look like function definitions 13 +# Assumes functions start at the beginning of a line 14 + 15 +use strict; 16 +use warnings; 17 + 18 +local $/; 19 +$_ = <>; 20 + 21 +my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments 22 + 23 +my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ; 24 +my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ; 25 +my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ; 26 + 27 + 28 +while (s/^ 29 + ( # Start $1 30 + ( # Start $2 31 + .*? # Minimal eat content 32 + ( ^ \w [\w\s\*]+ ) # $3 -- function name 33 + \s* # optional whitespace 34 + ) # $2 - Matched up to before parameter list 35 + 36 + \( \s* # Literal "(" + optional whitespace 37 + ( [^\)]+ ) # $4 - one or more anythings except ")" 38 + \s* \) # optional whitespace surrounding a Literal ")" 39 + 40 + ( (?: $dList )+ ) # $5 41 + 42 + $sp ^ { # literal "{" at start of line 43 + ) # Remember to $1 44 + //xsom 45 + ) 46 +{ 47 + my $all = $1 ; 48 + my $prefix = $2; 49 + my $param_list = $4 ; 50 + my $params = $5; 51 + 52 + StripComments($params); 53 + StripComments($param_list); 54 + $param_list =~ s/^\s+//; 55 + $param_list =~ s/\s+$//; 56 + 57 + my $i = 0 ; 58 + my %pList = map { $_ => $i++ } 59 + split /\s*,\s*/, $param_list; 60 + my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ; 61 + 62 + my @params = split /\s*;\s*/, $params; 63 + my @outParams = (); 64 + foreach my $p (@params) 65 + { 66 + if ($p =~ /,/) 67 + { 68 + my @bits = split /\s*,\s*/, $p; 69 + my $first = shift @bits; 70 + $first =~ s/^\s*//; 71 + push @outParams, $first; 72 + $first =~ /^(\w+\s*)/; 73 + my $type = $1 ; 74 + push @outParams, map { $type . $_ } @bits; 75 + } 76 + else 77 + { 78 + $p =~ s/^\s+//; 79 + push @outParams, $p; 80 + } 81 + } 82 + 83 + 84 + my %tmp = map { /$pMatch/; $_ => $pList{$1} } 85 + @outParams ; 86 + 87 + @outParams = map { " $_" } 88 + sort { $tmp{$a} <=> $tmp{$b} } 89 + @outParams ; 90 + 91 + print $prefix ; 92 + print "(\n" . join(",\n", @outParams) . ")\n"; 93 + print "{" ; 94 + 95 +} 96 + 97 +# Output any trailing code. 98 +print ; 99 +exit 0; 100 + 101 + 102 +sub StripComments 103 +{ 104 + 105 + no warnings; 106 + 107 + # Strip C & C++ coments 108 + # From the perlfaq 109 + $_[0] =~ 110 + 111 + s{ 112 + /\* ## Start of /* ... */ comment 113 + [^*]*\*+ ## Non-* followed by 1-or-more *'s 114 + ( 115 + [^/*][^*]*\*+ 116 + )* ## 0-or-more things which don't start with / 117 + ## but do end with '*' 118 + / ## End of /* ... */ comment 119 + 120 + | ## OR C++ Comment 121 + // ## Start of C++ comment // 122 + [^\n]* ## followed by 0-or-more non end of line characters 123 + 124 + | ## OR various things which aren't comments: 125 + 126 + ( 127 + " ## Start of " ... " string 128 + ( 129 + \\. ## Escaped char 130 + | ## OR 131 + [^"\\] ## Non "\ 132 + )* 133 + " ## End of " ... " string 134 + 135 + | ## OR 136 + 137 + ' ## Start of ' ... ' string 138 + ( 139 + \\. ## Escaped char 140 + | ## OR 141 + [^'\\] ## Non '\ 142 + )* 143 + ' ## End of ' ... ' string 144 + 145 + | ## OR 146 + 147 + . ## Anything other char 148 + [^/"'\\]* ## Chars which doesn't start a comment, string or escape 149 + ) 150 + }{$2}gxs; 151 + 152 +}
Added compat/zlib/zutil.c.
1 +/* zutil.c -- target dependent utility functions for the compression library 2 + * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* @(#) $Id$ */ 7 + 8 +#include "zutil.h" 9 +#ifndef Z_SOLO 10 +# include "gzguts.h" 11 +#endif 12 + 13 +#ifndef NO_DUMMY_DECL 14 +struct internal_state {int dummy;}; /* for buggy compilers */ 15 +#endif 16 + 17 +const char * const z_errmsg[10] = { 18 +"need dictionary", /* Z_NEED_DICT 2 */ 19 +"stream end", /* Z_STREAM_END 1 */ 20 +"", /* Z_OK 0 */ 21 +"file error", /* Z_ERRNO (-1) */ 22 +"stream error", /* Z_STREAM_ERROR (-2) */ 23 +"data error", /* Z_DATA_ERROR (-3) */ 24 +"insufficient memory", /* Z_MEM_ERROR (-4) */ 25 +"buffer error", /* Z_BUF_ERROR (-5) */ 26 +"incompatible version",/* Z_VERSION_ERROR (-6) */ 27 +""}; 28 + 29 + 30 +const char * ZEXPORT zlibVersion() 31 +{ 32 + return ZLIB_VERSION; 33 +} 34 + 35 +uLong ZEXPORT zlibCompileFlags() 36 +{ 37 + uLong flags; 38 + 39 + flags = 0; 40 + switch ((int)(sizeof(uInt))) { 41 + case 2: break; 42 + case 4: flags += 1; break; 43 + case 8: flags += 2; break; 44 + default: flags += 3; 45 + } 46 + switch ((int)(sizeof(uLong))) { 47 + case 2: break; 48 + case 4: flags += 1 << 2; break; 49 + case 8: flags += 2 << 2; break; 50 + default: flags += 3 << 2; 51 + } 52 + switch ((int)(sizeof(voidpf))) { 53 + case 2: break; 54 + case 4: flags += 1 << 4; break; 55 + case 8: flags += 2 << 4; break; 56 + default: flags += 3 << 4; 57 + } 58 + switch ((int)(sizeof(z_off_t))) { 59 + case 2: break; 60 + case 4: flags += 1 << 6; break; 61 + case 8: flags += 2 << 6; break; 62 + default: flags += 3 << 6; 63 + } 64 +#ifdef DEBUG 65 + flags += 1 << 8; 66 +#endif 67 +#if defined(ASMV) || defined(ASMINF) 68 + flags += 1 << 9; 69 +#endif 70 +#ifdef ZLIB_WINAPI 71 + flags += 1 << 10; 72 +#endif 73 +#ifdef BUILDFIXED 74 + flags += 1 << 12; 75 +#endif 76 +#ifdef DYNAMIC_CRC_TABLE 77 + flags += 1 << 13; 78 +#endif 79 +#ifdef NO_GZCOMPRESS 80 + flags += 1L << 16; 81 +#endif 82 +#ifdef NO_GZIP 83 + flags += 1L << 17; 84 +#endif 85 +#ifdef PKZIP_BUG_WORKAROUND 86 + flags += 1L << 20; 87 +#endif 88 +#ifdef FASTEST 89 + flags += 1L << 21; 90 +#endif 91 +#if defined(STDC) || defined(Z_HAVE_STDARG_H) 92 +# ifdef NO_vsnprintf 93 + flags += 1L << 25; 94 +# ifdef HAS_vsprintf_void 95 + flags += 1L << 26; 96 +# endif 97 +# else 98 +# ifdef HAS_vsnprintf_void 99 + flags += 1L << 26; 100 +# endif 101 +# endif 102 +#else 103 + flags += 1L << 24; 104 +# ifdef NO_snprintf 105 + flags += 1L << 25; 106 +# ifdef HAS_sprintf_void 107 + flags += 1L << 26; 108 +# endif 109 +# else 110 +# ifdef HAS_snprintf_void 111 + flags += 1L << 26; 112 +# endif 113 +# endif 114 +#endif 115 + return flags; 116 +} 117 + 118 +#ifdef DEBUG 119 + 120 +# ifndef verbose 121 +# define verbose 0 122 +# endif 123 +int ZLIB_INTERNAL z_verbose = verbose; 124 + 125 +void ZLIB_INTERNAL z_error (m) 126 + char *m; 127 +{ 128 + fprintf(stderr, "%s\n", m); 129 + exit(1); 130 +} 131 +#endif 132 + 133 +/* exported to allow conversion of error code to string for compress() and 134 + * uncompress() 135 + */ 136 +const char * ZEXPORT zError(err) 137 + int err; 138 +{ 139 + return ERR_MSG(err); 140 +} 141 + 142 +#if defined(_WIN32_WCE) 143 + /* The Microsoft C Run-Time Library for Windows CE doesn't have 144 + * errno. We define it as a global variable to simplify porting. 145 + * Its value is always 0 and should not be used. 146 + */ 147 + int errno = 0; 148 +#endif 149 + 150 +#ifndef HAVE_MEMCPY 151 + 152 +void ZLIB_INTERNAL zmemcpy(dest, source, len) 153 + Bytef* dest; 154 + const Bytef* source; 155 + uInt len; 156 +{ 157 + if (len == 0) return; 158 + do { 159 + *dest++ = *source++; /* ??? to be unrolled */ 160 + } while (--len != 0); 161 +} 162 + 163 +int ZLIB_INTERNAL zmemcmp(s1, s2, len) 164 + const Bytef* s1; 165 + const Bytef* s2; 166 + uInt len; 167 +{ 168 + uInt j; 169 + 170 + for (j = 0; j < len; j++) { 171 + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 172 + } 173 + return 0; 174 +} 175 + 176 +void ZLIB_INTERNAL zmemzero(dest, len) 177 + Bytef* dest; 178 + uInt len; 179 +{ 180 + if (len == 0) return; 181 + do { 182 + *dest++ = 0; /* ??? to be unrolled */ 183 + } while (--len != 0); 184 +} 185 +#endif 186 + 187 +#ifndef Z_SOLO 188 + 189 +#ifdef SYS16BIT 190 + 191 +#ifdef __TURBOC__ 192 +/* Turbo C in 16-bit mode */ 193 + 194 +# define MY_ZCALLOC 195 + 196 +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes 197 + * and farmalloc(64K) returns a pointer with an offset of 8, so we 198 + * must fix the pointer. Warning: the pointer must be put back to its 199 + * original form in order to free it, use zcfree(). 200 + */ 201 + 202 +#define MAX_PTR 10 203 +/* 10*64K = 640K */ 204 + 205 +local int next_ptr = 0; 206 + 207 +typedef struct ptr_table_s { 208 + voidpf org_ptr; 209 + voidpf new_ptr; 210 +} ptr_table; 211 + 212 +local ptr_table table[MAX_PTR]; 213 +/* This table is used to remember the original form of pointers 214 + * to large buffers (64K). Such pointers are normalized with a zero offset. 215 + * Since MSDOS is not a preemptive multitasking OS, this table is not 216 + * protected from concurrent access. This hack doesn't work anyway on 217 + * a protected system like OS/2. Use Microsoft C instead. 218 + */ 219 + 220 +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 221 +{ 222 + voidpf buf = opaque; /* just to make some compilers happy */ 223 + ulg bsize = (ulg)items*size; 224 + 225 + /* If we allocate less than 65520 bytes, we assume that farmalloc 226 + * will return a usable pointer which doesn't have to be normalized. 227 + */ 228 + if (bsize < 65520L) { 229 + buf = farmalloc(bsize); 230 + if (*(ush*)&buf != 0) return buf; 231 + } else { 232 + buf = farmalloc(bsize + 16L); 233 + } 234 + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 235 + table[next_ptr].org_ptr = buf; 236 + 237 + /* Normalize the pointer to seg:0 */ 238 + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 239 + *(ush*)&buf = 0; 240 + table[next_ptr++].new_ptr = buf; 241 + return buf; 242 +} 243 + 244 +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 245 +{ 246 + int n; 247 + if (*(ush*)&ptr != 0) { /* object < 64K */ 248 + farfree(ptr); 249 + return; 250 + } 251 + /* Find the original pointer */ 252 + for (n = 0; n < next_ptr; n++) { 253 + if (ptr != table[n].new_ptr) continue; 254 + 255 + farfree(table[n].org_ptr); 256 + while (++n < next_ptr) { 257 + table[n-1] = table[n]; 258 + } 259 + next_ptr--; 260 + return; 261 + } 262 + ptr = opaque; /* just to make some compilers happy */ 263 + Assert(0, "zcfree: ptr not found"); 264 +} 265 + 266 +#endif /* __TURBOC__ */ 267 + 268 + 269 +#ifdef M_I86 270 +/* Microsoft C in 16-bit mode */ 271 + 272 +# define MY_ZCALLOC 273 + 274 +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 275 +# define _halloc halloc 276 +# define _hfree hfree 277 +#endif 278 + 279 +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 280 +{ 281 + if (opaque) opaque = 0; /* to make compiler happy */ 282 + return _halloc((long)items, size); 283 +} 284 + 285 +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 286 +{ 287 + if (opaque) opaque = 0; /* to make compiler happy */ 288 + _hfree(ptr); 289 +} 290 + 291 +#endif /* M_I86 */ 292 + 293 +#endif /* SYS16BIT */ 294 + 295 + 296 +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ 297 + 298 +#ifndef STDC 299 +extern voidp malloc OF((uInt size)); 300 +extern voidp calloc OF((uInt items, uInt size)); 301 +extern void free OF((voidpf ptr)); 302 +#endif 303 + 304 +voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 305 + voidpf opaque; 306 + unsigned items; 307 + unsigned size; 308 +{ 309 + if (opaque) items += size - size; /* make compiler happy */ 310 + return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 311 + (voidpf)calloc(items, size); 312 +} 313 + 314 +void ZLIB_INTERNAL zcfree (opaque, ptr) 315 + voidpf opaque; 316 + voidpf ptr; 317 +{ 318 + free(ptr); 319 + if (opaque) return; /* make compiler happy */ 320 +} 321 + 322 +#endif /* MY_ZCALLOC */ 323 + 324 +#endif /* !Z_SOLO */
Added compat/zlib/zutil.h.
1 +/* zutil.h -- internal interface and configuration of the compression library 2 + * Copyright (C) 1995-2012 Jean-loup Gailly. 3 + * For conditions of distribution and use, see copyright notice in zlib.h 4 + */ 5 + 6 +/* WARNING: this file should *not* be used by applications. It is 7 + part of the implementation of the compression library and is 8 + subject to change. Applications should only use zlib.h. 9 + */ 10 + 11 +/* @(#) $Id$ */ 12 + 13 +#ifndef ZUTIL_H 14 +#define ZUTIL_H 15 + 16 +#ifdef HAVE_HIDDEN 17 +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 +#else 19 +# define ZLIB_INTERNAL 20 +#endif 21 + 22 +#include "zlib.h" 23 + 24 +#if defined(STDC) && !defined(Z_SOLO) 25 +# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 +# include <stddef.h> 27 +# endif 28 +# include <string.h> 29 +# include <stdlib.h> 30 +#endif 31 + 32 +#ifdef Z_SOLO 33 + typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 34 +#endif 35 + 36 +#ifndef local 37 +# define local static 38 +#endif 39 +/* compile with -Dlocal if your debugger can't find static symbols */ 40 + 41 +typedef unsigned char uch; 42 +typedef uch FAR uchf; 43 +typedef unsigned short ush; 44 +typedef ush FAR ushf; 45 +typedef unsigned long ulg; 46 + 47 +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 48 +/* (size given to avoid silly warnings with Visual C++) */ 49 + 50 +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 51 + 52 +#define ERR_RETURN(strm,err) \ 53 + return (strm->msg = (char*)ERR_MSG(err), (err)) 54 +/* To be used only when the state is known to be valid */ 55 + 56 + /* common constants */ 57 + 58 +#ifndef DEF_WBITS 59 +# define DEF_WBITS MAX_WBITS 60 +#endif 61 +/* default windowBits for decompression. MAX_WBITS is for compression only */ 62 + 63 +#if MAX_MEM_LEVEL >= 8 64 +# define DEF_MEM_LEVEL 8 65 +#else 66 +# define DEF_MEM_LEVEL MAX_MEM_LEVEL 67 +#endif 68 +/* default memLevel */ 69 + 70 +#define STORED_BLOCK 0 71 +#define STATIC_TREES 1 72 +#define DYN_TREES 2 73 +/* The three kinds of block type */ 74 + 75 +#define MIN_MATCH 3 76 +#define MAX_MATCH 258 77 +/* The minimum and maximum match lengths */ 78 + 79 +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 80 + 81 + /* target dependencies */ 82 + 83 +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 84 +# define OS_CODE 0x00 85 +# ifndef Z_SOLO 86 +# if defined(__TURBOC__) || defined(__BORLANDC__) 87 +# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 88 + /* Allow compilation with ANSI keywords only enabled */ 89 + void _Cdecl farfree( void *block ); 90 + void *_Cdecl farmalloc( unsigned long nbytes ); 91 +# else 92 +# include <alloc.h> 93 +# endif 94 +# else /* MSC or DJGPP */ 95 +# include <malloc.h> 96 +# endif 97 +# endif 98 +#endif 99 + 100 +#ifdef AMIGA 101 +# define OS_CODE 0x01 102 +#endif 103 + 104 +#if defined(VAXC) || defined(VMS) 105 +# define OS_CODE 0x02 106 +# define F_OPEN(name, mode) \ 107 + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 108 +#endif 109 + 110 +#if defined(ATARI) || defined(atarist) 111 +# define OS_CODE 0x05 112 +#endif 113 + 114 +#ifdef OS2 115 +# define OS_CODE 0x06 116 +# if defined(M_I86) && !defined(Z_SOLO) 117 +# include <malloc.h> 118 +# endif 119 +#endif 120 + 121 +#if defined(MACOS) || defined(TARGET_OS_MAC) 122 +# define OS_CODE 0x07 123 +# ifndef Z_SOLO 124 +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 125 +# include <unix.h> /* for fdopen */ 126 +# else 127 +# ifndef fdopen 128 +# define fdopen(fd,mode) NULL /* No fdopen() */ 129 +# endif 130 +# endif 131 +# endif 132 +#endif 133 + 134 +#ifdef TOPS20 135 +# define OS_CODE 0x0a 136 +#endif 137 + 138 +#ifdef WIN32 139 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 140 +# define OS_CODE 0x0b 141 +# endif 142 +#endif 143 + 144 +#ifdef __50SERIES /* Prime/PRIMOS */ 145 +# define OS_CODE 0x0f 146 +#endif 147 + 148 +#if defined(_BEOS_) || defined(RISCOS) 149 +# define fdopen(fd,mode) NULL /* No fdopen() */ 150 +#endif 151 + 152 +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 153 +# if defined(_WIN32_WCE) 154 +# define fdopen(fd,mode) NULL /* No fdopen() */ 155 +# ifndef _PTRDIFF_T_DEFINED 156 + typedef int ptrdiff_t; 157 +# define _PTRDIFF_T_DEFINED 158 +# endif 159 +# else 160 +# define fdopen(fd,type) _fdopen(fd,type) 161 +# endif 162 +#endif 163 + 164 +#if defined(__BORLANDC__) && !defined(MSDOS) 165 + #pragma warn -8004 166 + #pragma warn -8008 167 + #pragma warn -8066 168 +#endif 169 + 170 +/* provide prototypes for these when building zlib without LFS */ 171 +#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 172 + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 173 + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 174 +#endif 175 + 176 + /* common defaults */ 177 + 178 +#ifndef OS_CODE 179 +# define OS_CODE 0x03 /* assume Unix */ 180 +#endif 181 + 182 +#ifndef F_OPEN 183 +# define F_OPEN(name, mode) fopen((name), (mode)) 184 +#endif 185 + 186 + /* functions */ 187 + 188 +#if defined(pyr) || defined(Z_SOLO) 189 +# define NO_MEMCPY 190 +#endif 191 +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 192 + /* Use our own functions for small and medium model with MSC <= 5.0. 193 + * You may have to use the same strategy for Borland C (untested). 194 + * The __SC__ check is for Symantec. 195 + */ 196 +# define NO_MEMCPY 197 +#endif 198 +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 199 +# define HAVE_MEMCPY 200 +#endif 201 +#ifdef HAVE_MEMCPY 202 +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 203 +# define zmemcpy _fmemcpy 204 +# define zmemcmp _fmemcmp 205 +# define zmemzero(dest, len) _fmemset(dest, 0, len) 206 +# else 207 +# define zmemcpy memcpy 208 +# define zmemcmp memcmp 209 +# define zmemzero(dest, len) memset(dest, 0, len) 210 +# endif 211 +#else 212 + void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 213 + int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 214 + void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 215 +#endif 216 + 217 +/* Diagnostic functions */ 218 +#ifdef DEBUG 219 +# include <stdio.h> 220 + extern int ZLIB_INTERNAL z_verbose; 221 + extern void ZLIB_INTERNAL z_error OF((char *m)); 222 +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} 223 +# define Trace(x) {if (z_verbose>=0) fprintf x ;} 224 +# define Tracev(x) {if (z_verbose>0) fprintf x ;} 225 +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} 226 +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 227 +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 228 +#else 229 +# define Assert(cond,msg) 230 +# define Trace(x) 231 +# define Tracev(x) 232 +# define Tracevv(x) 233 +# define Tracec(c,x) 234 +# define Tracecv(c,x) 235 +#endif 236 + 237 +#ifndef Z_SOLO 238 + voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 239 + unsigned size)); 240 + void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 241 +#endif 242 + 243 +#define ZALLOC(strm, items, size) \ 244 + (*((strm)->zalloc))((strm)->opaque, (items), (size)) 245 +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 246 +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 247 + 248 +/* Reverse the bytes in a 32-bit value */ 249 +#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 250 + (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 251 + 252 +#endif /* ZUTIL_H */
Changes to src/makemake.tcl.
389 389 390 390 #### Use the Tcl source directory instead of the install directory? 391 391 # This is useful when Tcl has been compiled statically with MinGW. 392 392 # 393 393 FOSSIL_TCL_SOURCE = 1 394 394 395 395 #### The directories where the zlib include and library files are located. 396 -# The recommended usage here is to use the Sysinternals junction tool 397 -# to create a hard link between an "zlib-1.x.y" sub-directory of the 398 -# Fossil source code directory and the target zlib source directory. 399 396 # 400 -ZINCDIR = $(SRCDIR)/../zlib-1.2.7 401 -ZLIBDIR = $(SRCDIR)/../zlib-1.2.7 397 +ZINCDIR = $(SRCDIR)/../compat/zlib 398 +ZLIBDIR = $(SRCDIR)/../compat/zlib 402 399 403 400 #### The directories where the OpenSSL include and library files are located. 404 401 # The recommended usage here is to use the Sysinternals junction tool 405 402 # to create a hard link between an "openssl-1.x" sub-directory of the 406 403 # Fossil source code directory and the target OpenSSL source directory. 407 404 # 408 405 OPENSSLINCDIR = $(SRCDIR)/../openssl-1.0.1c/include ................................................................................ 659 656 $(OBJDIR)/th_lang.o \ 660 657 $(OBJDIR)/cson_amalgamation.o 661 658 662 659 ifdef FOSSIL_ENABLE_TCL 663 660 EXTRAOBJ += $(OBJDIR)/th_tcl.o 664 661 endif 665 662 666 -$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o 663 +zlib: 664 + make -C $(ZLIBDIR) -f win32/Makefile.gcc libz.a 665 + 666 +$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o zlib 667 667 $(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/fossil.o 668 668 669 669 # This rule prevents make from using its default rules to try build 670 670 # an executable named "manifest" out of the file named "manifest.c" 671 671 # 672 672 $(SRCDIR)/../manifest: 673 673 # noop ................................................................................ 911 911 B = .. 912 912 SRCDIR = $B\src 913 913 OBJDIR = . 914 914 OX = . 915 915 O = .obj 916 916 E = .exe 917 917 918 -# Maybe MSCDIR, SSL, ZLIB, or INCL needs adjustment 919 -MSCDIR = c:\msc 920 - 921 918 # Uncomment below for SSL support 922 919 SSL = 923 920 SSLLIB = 924 -#SSL = -DFOSSIL_ENABLE_SSL=1 925 -#SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib advapi32.lib 921 +# SSL = -DFOSSIL_ENABLE_SSL=1 922 +# SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib advapi32.lib 926 923 927 924 # zlib options 928 -# When using precompiled from http://zlib.net/zlib125-dll.zip 929 -#ZINCDIR = C:\zlib125-dll\include 930 -#ZLIBDIR = C:\zlib125-dll\lib 931 -#ZLIB = zdll.lib 932 -ZINCDIR = $(MSCDIR)\extra\include 933 -ZLIBDIR = $(MSCDIR)\extra\lib 925 +ZINCDIR = $(B)\compat\zlib 926 +ZLIBDIR = $(B)\compat\zlib 934 927 ZLIB = zlib.lib 935 928 936 -INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(MSCDIR)\extra\include -I$(ZINCDIR) 929 +INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR) 937 930 938 931 CFLAGS = -nologo -MT -O2 939 932 BCC = $(CC) $(CFLAGS) 940 933 TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) 941 934 LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) 942 -LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) 935 +LIBDIR = -LIBPATH:$(ZLIBDIR) 943 936 } 944 937 regsub -all {[-]D} $SQLITE_OPTIONS {/D} MSC_SQLITE_OPTIONS 945 -writeln "SQLITE_OPTIONS = $MSC_SQLITE_OPTIONS\n" 938 +set j " \\\n " 939 +writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n" 946 940 writeln -nonewline "SRC = " 941 +set i 0 947 942 foreach s [lsort $src] { 948 - writeln -nonewline "${s}_.c " 943 + if {$i > 0} { 944 + writeln " \\" 945 + writeln -nonewline " " 946 + } 947 + writeln -nonewline "${s}_.c"; incr i 949 948 } 950 949 writeln "\n" 951 950 writeln -nonewline "OBJ = " 951 +set i 0 952 952 foreach s [lsort $src] { 953 - writeln -nonewline "\$(OX)\\$s\$O " 953 + if {$i > 0} { 954 + writeln " \\" 955 + writeln -nonewline " " 956 + } 957 + writeln -nonewline "\$(OX)\\$s\$O"; incr i 954 958 } 955 -writeln "\$(OX)\\shell\$O \$(OX)\\sqlite3\$O \$(OX)\\th\$O \$(OX)\\th_lang\$O " 959 +writeln " \\" 960 +writeln " \$(OX)\\shell\$O \\" 961 +writeln " \$(OX)\\sqlite3\$O \\" 962 +writeln " \$(OX)\\th\$O \\" 963 +writeln " \$(OX)\\th_lang\$O" 956 964 writeln { 957 - 958 965 APPNAME = $(OX)\fossil$(E) 959 966 960 967 all: $(OX) $(APPNAME) 961 968 962 -$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts 969 +zlib: 970 + @echo Building zlib from "$(ZLIBDIR)"... 971 + @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd 972 + 973 +$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib 963 974 cd $(OX) 964 975 link /NODEFAULTLIB:msvcrt -OUT:$@ $(LIBDIR) @linkopts 965 976 966 977 $(OX)\linkopts: $B\win\Makefile.msc} 967 978 set redir {>} 968 979 foreach s [lsort [concat $src {shell sqlite3 th th_lang}]] { 969 980 writeln "\techo \$(OX)\\$s.obj $redir \$@" ................................................................................ 1006 1017 cp $(SRCDIR)\cson_amalgamation.h $@ 1007 1018 1008 1019 page_index.h: mkindex$E $(SRC) 1009 1020 $** > $@ 1010 1021 1011 1022 clean: 1012 1023 -del $(OX)\*.obj 1013 - -del *.obj *_.c *.h *.map 1014 - -del headers linkopts 1024 + -del *.obj 1025 + -del *_.c 1026 + -del *.h 1027 + -del *.map 1028 + -del *.manifest 1029 + -del headers 1030 + -del linkopts 1015 1031 1016 -realclean: 1017 - -del $(APPNAME) translate$E mkindex$E makeheaders$E mkversion$E 1032 +realclean: clean 1033 + -del $(APPNAME) 1034 + -del translate$E 1035 + -del mkindex$E 1036 + -del makeheaders$E 1037 + -del mkversion$E 1018 1038 1019 1039 $(OBJDIR)\json$O : $(SRCDIR)\json_detail.h 1020 1040 $(OBJDIR)\json_artifact$O : $(SRCDIR)\json_detail.h 1021 1041 $(OBJDIR)\json_branch$O : $(SRCDIR)\json_detail.h 1022 1042 $(OBJDIR)\json_config$O : $(SRCDIR)\json_detail.h 1023 1043 $(OBJDIR)\json_diff$O : $(SRCDIR)\json_detail.h 1024 1044 $(OBJDIR)\json_dir$O : $(SRCDIR)\json_detail.h ................................................................................ 1035 1055 foreach s [lsort $src] { 1036 1056 writeln "\$(OX)\\$s\$O : ${s}_.c ${s}.h" 1037 1057 writeln "\t\$(TCC) /Fo\$@ -c ${s}_.c\n" 1038 1058 writeln "${s}_.c : \$(SRCDIR)\\$s.c" 1039 1059 writeln "\ttranslate\$E \$** > \$@\n" 1040 1060 } 1041 1061 1042 -writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\tmakeheaders\$E " 1062 +writeln "headers: makeheaders\$E page_index.h VERSION.h" 1063 +writeln -nonewline "\tmakeheaders\$E " 1064 +set i 0 1043 1065 foreach s [lsort $src] { 1044 - writeln -nonewline "${s}_.c:$s.h " 1066 + if {$i > 0} { 1067 + writeln " \\" 1068 + writeln -nonewline "\t\t\t" 1069 + } 1070 + writeln -nonewline "${s}_.c:$s.h"; incr i 1045 1071 } 1046 -writeln "\$(SRCDIR)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h" 1072 +writeln " \\\n\t\t\t\$(SRCDIR)\\sqlite3.h \\" 1073 +writeln "\t\t\t\$(SRCDIR)\\th.h \\" 1074 +writeln "\t\t\tVERSION.h \\" 1075 +writeln "\t\t\t\$(SRCDIR)\\cson_amalgamation.h" 1047 1076 writeln "\t@copy /Y nul: headers" 1048 1077 1049 1078 1050 1079 close $output_file 1051 1080 # 1052 1081 # End of the win/Makefile.msc output 1053 1082 ##############################################################################
Changes to win/Makefile.mingw.
60 60 61 61 #### Use the Tcl source directory instead of the install directory? 62 62 # This is useful when Tcl has been compiled statically with MinGW. 63 63 # 64 64 FOSSIL_TCL_SOURCE = 1 65 65 66 66 #### The directories where the zlib include and library files are located. 67 -# The recommended usage here is to use the Sysinternals junction tool 68 -# to create a hard link between an "zlib-1.x.y" sub-directory of the 69 -# Fossil source code directory and the target zlib source directory. 70 67 # 71 -ZINCDIR = $(SRCDIR)/../zlib-1.2.7 72 -ZLIBDIR = $(SRCDIR)/../zlib-1.2.7 68 +ZINCDIR = $(SRCDIR)/../compat/zlib 69 +ZLIBDIR = $(SRCDIR)/../compat/zlib 73 70 74 71 #### The directories where the OpenSSL include and library files are located. 75 72 # The recommended usage here is to use the Sysinternals junction tool 76 73 # to create a hard link between an "openssl-1.x" sub-directory of the 77 74 # Fossil source code directory and the target OpenSSL source directory. 78 75 # 79 76 OPENSSLINCDIR = $(SRCDIR)/../openssl-1.0.1c/include ................................................................................ 612 609 613 610 EXTRAOBJ = $(OBJDIR)/sqlite3.o $(OBJDIR)/shell.o $(OBJDIR)/th.o $(OBJDIR)/th_lang.o $(OBJDIR)/cson_amalgamation.o 614 611 615 612 ifdef FOSSIL_ENABLE_TCL 616 613 EXTRAOBJ += $(OBJDIR)/th_tcl.o 617 614 endif 618 615 619 -$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o 616 +zlib: 617 + make -C $(ZLIBDIR) -f win32/Makefile.gcc libz.a 618 + 619 +$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o zlib 620 620 $(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/fossil.o 621 621 622 622 # This rule prevents make from using its default rules to try build 623 623 # an executable named "manifest" out of the file named "manifest.c" 624 624 # 625 625 $(SRCDIR)/../manifest: 626 626 # noop
Changes to win/Makefile.mingw.mistachkin.
60 60 61 61 #### Use the Tcl source directory instead of the install directory? 62 62 # This is useful when Tcl has been compiled statically with MinGW. 63 63 # 64 64 FOSSIL_TCL_SOURCE = 1 65 65 66 66 #### The directories where the zlib include and library files are located. 67 -# The recommended usage here is to use the Sysinternals junction tool 68 -# to create a hard link between an "zlib-1.x.y" sub-directory of the 69 -# Fossil source code directory and the target zlib source directory. 70 67 # 71 -ZINCDIR = $(SRCDIR)/../zlib-1.2.7 72 -ZLIBDIR = $(SRCDIR)/../zlib-1.2.7 68 +ZINCDIR = $(SRCDIR)/../compat/zlib 69 +ZLIBDIR = $(SRCDIR)/../compat/zlib 73 70 74 71 #### The directories where the OpenSSL include and library files are located. 75 72 # The recommended usage here is to use the Sysinternals junction tool 76 73 # to create a hard link between an "openssl-1.x" sub-directory of the 77 74 # Fossil source code directory and the target OpenSSL source directory. 78 75 # 79 76 OPENSSLINCDIR = $(SRCDIR)/../openssl-1.0.1c/include ................................................................................ 612 609 613 610 EXTRAOBJ = $(OBJDIR)/sqlite3.o $(OBJDIR)/shell.o $(OBJDIR)/th.o $(OBJDIR)/th_lang.o $(OBJDIR)/cson_amalgamation.o 614 611 615 612 ifdef FOSSIL_ENABLE_TCL 616 613 EXTRAOBJ += $(OBJDIR)/th_tcl.o 617 614 endif 618 615 619 -$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o 616 +zlib: 617 + make -C $(ZLIBDIR) -f win32/Makefile.gcc libz.a 618 + 619 +$(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/fossil.o zlib 620 620 $(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/fossil.o 621 621 622 622 # This rule prevents make from using its default rules to try build 623 623 # an executable named "manifest" out of the file named "manifest.c" 624 624 # 625 625 $(SRCDIR)/../manifest: 626 626 # noop
Changes to win/Makefile.msc.
10 10 B = .. 11 11 SRCDIR = $B\src 12 12 OBJDIR = . 13 13 OX = . 14 14 O = .obj 15 15 E = .exe 16 16 17 -# Maybe MSCDIR, SSL, ZLIB, or INCL needs adjustment 18 -MSCDIR = c:\msc 19 - 20 17 # Uncomment below for SSL support 21 18 SSL = 22 19 SSLLIB = 23 -#SSL = -DFOSSIL_ENABLE_SSL=1 24 -#SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib advapi32.lib 20 +# SSL = -DFOSSIL_ENABLE_SSL=1 21 +# SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib advapi32.lib 25 22 26 23 # zlib options 27 -# When using precompiled from http://zlib.net/zlib125-dll.zip 28 -#ZINCDIR = C:\zlib125-dll\include 29 -#ZLIBDIR = C:\zlib125-dll\lib 30 -#ZLIB = zdll.lib 31 -ZINCDIR = $(MSCDIR)\extra\include 32 -ZLIBDIR = $(MSCDIR)\extra\lib 24 +ZINCDIR = $(B)\compat\zlib 25 +ZLIBDIR = $(B)\compat\zlib 33 26 ZLIB = zlib.lib 34 27 35 -INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(MSCDIR)\extra\include -I$(ZINCDIR) 28 +INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR) 36 29 37 30 CFLAGS = -nologo -MT -O2 38 31 BCC = $(CC) $(CFLAGS) 39 32 TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) 40 33 LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) 41 -LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) 42 - 43 -SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 /DSQLITE_THREADSAFE=0 /DSQLITE_DEFAULT_FILE_FORMAT=4 /DSQLITE_ENABLE_STAT3 /Dlocaltime=fossil_localtime /DSQLITE_ENABLE_LOCKING_STYLE=0 44 - 45 -SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c 46 - 47 -OBJ = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\json$O $(OX)\json_artifact$O $(OX)\json_branch$O $(OX)\json_config$O $(OX)\json_diff$O $(OX)\json_dir$O $(OX)\json_finfo$O $(OX)\json_login$O $(OX)\json_query$O $(OX)\json_report$O $(OX)\json_tag$O $(OX)\json_timeline$O $(OX)\json_user$O $(OX)\json_wiki$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\moderate$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\wysiwyg$O $(OX)\xfer$O $(OX)\xfersetup$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite3$O $(OX)\th$O $(OX)\th_lang$O 48 - 34 +LIBDIR = -LIBPATH:$(ZLIBDIR) 35 + 36 +SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 \ 37 + /DSQLITE_THREADSAFE=0 \ 38 + /DSQLITE_DEFAULT_FILE_FORMAT=4 \ 39 + /DSQLITE_ENABLE_STAT3 \ 40 + /Dlocaltime=fossil_localtime \ 41 + /DSQLITE_ENABLE_LOCKING_STYLE=0 42 + 43 +SRC = add_.c \ 44 + allrepo_.c \ 45 + attach_.c \ 46 + bag_.c \ 47 + bisect_.c \ 48 + blob_.c \ 49 + branch_.c \ 50 + browse_.c \ 51 + captcha_.c \ 52 + cgi_.c \ 53 + checkin_.c \ 54 + checkout_.c \ 55 + clearsign_.c \ 56 + clone_.c \ 57 + comformat_.c \ 58 + configure_.c \ 59 + content_.c \ 60 + db_.c \ 61 + delta_.c \ 62 + deltacmd_.c \ 63 + descendants_.c \ 64 + diff_.c \ 65 + diffcmd_.c \ 66 + doc_.c \ 67 + encode_.c \ 68 + event_.c \ 69 + export_.c \ 70 + file_.c \ 71 + finfo_.c \ 72 + glob_.c \ 73 + graph_.c \ 74 + gzip_.c \ 75 + http_.c \ 76 + http_socket_.c \ 77 + http_ssl_.c \ 78 + http_transport_.c \ 79 + import_.c \ 80 + info_.c \ 81 + json_.c \ 82 + json_artifact_.c \ 83 + json_branch_.c \ 84 + json_config_.c \ 85 + json_diff_.c \ 86 + json_dir_.c \ 87 + json_finfo_.c \ 88 + json_login_.c \ 89 + json_query_.c \ 90 + json_report_.c \ 91 + json_tag_.c \ 92 + json_timeline_.c \ 93 + json_user_.c \ 94 + json_wiki_.c \ 95 + leaf_.c \ 96 + login_.c \ 97 + main_.c \ 98 + manifest_.c \ 99 + md5_.c \ 100 + merge_.c \ 101 + merge3_.c \ 102 + moderate_.c \ 103 + name_.c \ 104 + path_.c \ 105 + pivot_.c \ 106 + popen_.c \ 107 + pqueue_.c \ 108 + printf_.c \ 109 + rebuild_.c \ 110 + report_.c \ 111 + rss_.c \ 112 + schema_.c \ 113 + search_.c \ 114 + setup_.c \ 115 + sha1_.c \ 116 + shun_.c \ 117 + skins_.c \ 118 + sqlcmd_.c \ 119 + stash_.c \ 120 + stat_.c \ 121 + style_.c \ 122 + sync_.c \ 123 + tag_.c \ 124 + tar_.c \ 125 + th_main_.c \ 126 + timeline_.c \ 127 + tkt_.c \ 128 + tktsetup_.c \ 129 + undo_.c \ 130 + update_.c \ 131 + url_.c \ 132 + user_.c \ 133 + verify_.c \ 134 + vfile_.c \ 135 + wiki_.c \ 136 + wikiformat_.c \ 137 + winhttp_.c \ 138 + wysiwyg_.c \ 139 + xfer_.c \ 140 + xfersetup_.c \ 141 + zip_.c 142 + 143 +OBJ = $(OX)\add$O \ 144 + $(OX)\allrepo$O \ 145 + $(OX)\attach$O \ 146 + $(OX)\bag$O \ 147 + $(OX)\bisect$O \ 148 + $(OX)\blob$O \ 149 + $(OX)\branch$O \ 150 + $(OX)\browse$O \ 151 + $(OX)\captcha$O \ 152 + $(OX)\cgi$O \ 153 + $(OX)\checkin$O \ 154 + $(OX)\checkout$O \ 155 + $(OX)\clearsign$O \ 156 + $(OX)\clone$O \ 157 + $(OX)\comformat$O \ 158 + $(OX)\configure$O \ 159 + $(OX)\content$O \ 160 + $(OX)\db$O \ 161 + $(OX)\delta$O \ 162 + $(OX)\deltacmd$O \ 163 + $(OX)\descendants$O \ 164 + $(OX)\diff$O \ 165 + $(OX)\diffcmd$O \ 166 + $(OX)\doc$O \ 167 + $(OX)\encode$O \ 168 + $(OX)\event$O \ 169 + $(OX)\export$O \ 170 + $(OX)\file$O \ 171 + $(OX)\finfo$O \ 172 + $(OX)\glob$O \ 173 + $(OX)\graph$O \ 174 + $(OX)\gzip$O \ 175 + $(OX)\http$O \ 176 + $(OX)\http_socket$O \ 177 + $(OX)\http_ssl$O \ 178 + $(OX)\http_transport$O \ 179 + $(OX)\import$O \ 180 + $(OX)\info$O \ 181 + $(OX)\json$O \ 182 + $(OX)\json_artifact$O \ 183 + $(OX)\json_branch$O \ 184 + $(OX)\json_config$O \ 185 + $(OX)\json_diff$O \ 186 + $(OX)\json_dir$O \ 187 + $(OX)\json_finfo$O \ 188 + $(OX)\json_login$O \ 189 + $(OX)\json_query$O \ 190 + $(OX)\json_report$O \ 191 + $(OX)\json_tag$O \ 192 + $(OX)\json_timeline$O \ 193 + $(OX)\json_user$O \ 194 + $(OX)\json_wiki$O \ 195 + $(OX)\leaf$O \ 196 + $(OX)\login$O \ 197 + $(OX)\main$O \ 198 + $(OX)\manifest$O \ 199 + $(OX)\md5$O \ 200 + $(OX)\merge$O \ 201 + $(OX)\merge3$O \ 202 + $(OX)\moderate$O \ 203 + $(OX)\name$O \ 204 + $(OX)\path$O \ 205 + $(OX)\pivot$O \ 206 + $(OX)\popen$O \ 207 + $(OX)\pqueue$O \ 208 + $(OX)\printf$O \ 209 + $(OX)\rebuild$O \ 210 + $(OX)\report$O \ 211 + $(OX)\rss$O \ 212 + $(OX)\schema$O \ 213 + $(OX)\search$O \ 214 + $(OX)\setup$O \ 215 + $(OX)\sha1$O \ 216 + $(OX)\shun$O \ 217 + $(OX)\skins$O \ 218 + $(OX)\sqlcmd$O \ 219 + $(OX)\stash$O \ 220 + $(OX)\stat$O \ 221 + $(OX)\style$O \ 222 + $(OX)\sync$O \ 223 + $(OX)\tag$O \ 224 + $(OX)\tar$O \ 225 + $(OX)\th_main$O \ 226 + $(OX)\timeline$O \ 227 + $(OX)\tkt$O \ 228 + $(OX)\tktsetup$O \ 229 + $(OX)\undo$O \ 230 + $(OX)\update$O \ 231 + $(OX)\url$O \ 232 + $(OX)\user$O \ 233 + $(OX)\verify$O \ 234 + $(OX)\vfile$O \ 235 + $(OX)\wiki$O \ 236 + $(OX)\wikiformat$O \ 237 + $(OX)\winhttp$O \ 238 + $(OX)\wysiwyg$O \ 239 + $(OX)\xfer$O \ 240 + $(OX)\xfersetup$O \ 241 + $(OX)\zip$O \ 242 + $(OX)\shell$O \ 243 + $(OX)\sqlite3$O \ 244 + $(OX)\th$O \ 245 + $(OX)\th_lang$O 49 246 50 247 APPNAME = $(OX)\fossil$(E) 51 248 52 249 all: $(OX) $(APPNAME) 53 250 54 -$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts 251 +zlib: 252 + @echo Building zlib from "$(ZLIBDIR)"... 253 + @pushd "$(ZLIBDIR)" && nmake /f win32\Makefile.msc $(ZLIB) && popd 254 + 255 +$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts zlib 55 256 cd $(OX) 56 257 link /NODEFAULTLIB:msvcrt -OUT:$@ $(LIBDIR) @linkopts 57 258 58 259 $(OX)\linkopts: $B\win\Makefile.msc 59 260 echo $(OX)\add.obj > $@ 60 261 echo $(OX)\allrepo.obj >> $@ 61 262 echo $(OX)\attach.obj >> $@ ................................................................................ 197 398 cp $(SRCDIR)\cson_amalgamation.h $@ 198 399 199 400 page_index.h: mkindex$E $(SRC) 200 401 $** > $@ 201 402 202 403 clean: 203 404 -del $(OX)\*.obj 204 - -del *.obj *_.c *.h *.map 205 - -del headers linkopts 405 + -del *.obj 406 + -del *_.c 407 + -del *.h 408 + -del *.map 409 + -del *.manifest 410 + -del headers 411 + -del linkopts 206 412 207 -realclean: 208 - -del $(APPNAME) translate$E mkindex$E makeheaders$E mkversion$E 413 +realclean: clean 414 + -del $(APPNAME) 415 + -del translate$E 416 + -del mkindex$E 417 + -del makeheaders$E 418 + -del mkversion$E 209 419 210 420 $(OBJDIR)\json$O : $(SRCDIR)\json_detail.h 211 421 $(OBJDIR)\json_artifact$O : $(SRCDIR)\json_detail.h 212 422 $(OBJDIR)\json_branch$O : $(SRCDIR)\json_detail.h 213 423 $(OBJDIR)\json_config$O : $(SRCDIR)\json_detail.h 214 424 $(OBJDIR)\json_diff$O : $(SRCDIR)\json_detail.h 215 425 $(OBJDIR)\json_dir$O : $(SRCDIR)\json_detail.h ................................................................................ 814 1024 $(OX)\zip$O : zip_.c zip.h 815 1025 $(TCC) /Fo$@ -c zip_.c 816 1026 817 1027 zip_.c : $(SRCDIR)\zip.c 818 1028 translate$E $** > $@ 819 1029 820 1030 headers: makeheaders$E page_index.h VERSION.h 821 - makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h 1031 + makeheaders$E add_.c:add.h \ 1032 + allrepo_.c:allrepo.h \ 1033 + attach_.c:attach.h \ 1034 + bag_.c:bag.h \ 1035 + bisect_.c:bisect.h \ 1036 + blob_.c:blob.h \ 1037 + branch_.c:branch.h \ 1038 + browse_.c:browse.h \ 1039 + captcha_.c:captcha.h \ 1040 + cgi_.c:cgi.h \ 1041 + checkin_.c:checkin.h \ 1042 + checkout_.c:checkout.h \ 1043 + clearsign_.c:clearsign.h \ 1044 + clone_.c:clone.h \ 1045 + comformat_.c:comformat.h \ 1046 + configure_.c:configure.h \ 1047 + content_.c:content.h \ 1048 + db_.c:db.h \ 1049 + delta_.c:delta.h \ 1050 + deltacmd_.c:deltacmd.h \ 1051 + descendants_.c:descendants.h \ 1052 + diff_.c:diff.h \ 1053 + diffcmd_.c:diffcmd.h \ 1054 + doc_.c:doc.h \ 1055 + encode_.c:encode.h \ 1056 + event_.c:event.h \ 1057 + export_.c:export.h \ 1058 + file_.c:file.h \ 1059 + finfo_.c:finfo.h \ 1060 + glob_.c:glob.h \ 1061 + graph_.c:graph.h \ 1062 + gzip_.c:gzip.h \ 1063 + http_.c:http.h \ 1064 + http_socket_.c:http_socket.h \ 1065 + http_ssl_.c:http_ssl.h \ 1066 + http_transport_.c:http_transport.h \ 1067 + import_.c:import.h \ 1068 + info_.c:info.h \ 1069 + json_.c:json.h \ 1070 + json_artifact_.c:json_artifact.h \ 1071 + json_branch_.c:json_branch.h \ 1072 + json_config_.c:json_config.h \ 1073 + json_diff_.c:json_diff.h \ 1074 + json_dir_.c:json_dir.h \ 1075 + json_finfo_.c:json_finfo.h \ 1076 + json_login_.c:json_login.h \ 1077 + json_query_.c:json_query.h \ 1078 + json_report_.c:json_report.h \ 1079 + json_tag_.c:json_tag.h \ 1080 + json_timeline_.c:json_timeline.h \ 1081 + json_user_.c:json_user.h \ 1082 + json_wiki_.c:json_wiki.h \ 1083 + leaf_.c:leaf.h \ 1084 + login_.c:login.h \ 1085 + main_.c:main.h \ 1086 + manifest_.c:manifest.h \ 1087 + md5_.c:md5.h \ 1088 + merge_.c:merge.h \ 1089 + merge3_.c:merge3.h \ 1090 + moderate_.c:moderate.h \ 1091 + name_.c:name.h \ 1092 + path_.c:path.h \ 1093 + pivot_.c:pivot.h \ 1094 + popen_.c:popen.h \ 1095 + pqueue_.c:pqueue.h \ 1096 + printf_.c:printf.h \ 1097 + rebuild_.c:rebuild.h \ 1098 + report_.c:report.h \ 1099 + rss_.c:rss.h \ 1100 + schema_.c:schema.h \ 1101 + search_.c:search.h \ 1102 + setup_.c:setup.h \ 1103 + sha1_.c:sha1.h \ 1104 + shun_.c:shun.h \ 1105 + skins_.c:skins.h \ 1106 + sqlcmd_.c:sqlcmd.h \ 1107 + stash_.c:stash.h \ 1108 + stat_.c:stat.h \ 1109 + style_.c:style.h \ 1110 + sync_.c:sync.h \ 1111 + tag_.c:tag.h \ 1112 + tar_.c:tar.h \ 1113 + th_main_.c:th_main.h \ 1114 + timeline_.c:timeline.h \ 1115 + tkt_.c:tkt.h \ 1116 + tktsetup_.c:tktsetup.h \ 1117 + undo_.c:undo.h \ 1118 + update_.c:update.h \ 1119 + url_.c:url.h \ 1120 + user_.c:user.h \ 1121 + verify_.c:verify.h \ 1122 + vfile_.c:vfile.h \ 1123 + wiki_.c:wiki.h \ 1124 + wikiformat_.c:wikiformat.h \ 1125 + winhttp_.c:winhttp.h \ 1126 + wysiwyg_.c:wysiwyg.h \ 1127 + xfer_.c:xfer.h \ 1128 + xfersetup_.c:xfersetup.h \ 1129 + zip_.c:zip.h \ 1130 + $(SRCDIR)\sqlite3.h \ 1131 + $(SRCDIR)\th.h \ 1132 + VERSION.h \ 1133 + $(SRCDIR)\cson_amalgamation.h 822 1134 @copy /Y nul: headers
Deleted win/Makefile.msc.mistachkin.
1 -# 2 -############################################################################## 3 -# WARNING: DO NOT EDIT, AUTOMATICALLY GENERATED FILE (SEE "src/makemake.tcl") 4 -############################################################################## 5 -# 6 -# This file is automatically generated. Instead of editing this 7 -# file, edit "makemake.tcl" then run "tclsh makemake.tcl" 8 -# to regenerate this file. 9 -# 10 -B = .. 11 -SRCDIR = $B\src 12 -OBJDIR = . 13 -OX = . 14 -O = .obj 15 -E = .exe 16 - 17 -# Uncomment below for SSL support 18 -SSL = 19 -SSLLIB = 20 -#SSL = -DFOSSIL_ENABLE_SSL=1 21 -#SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib advapi32.lib 22 - 23 -# zlib options 24 -# When using precompiled from http://zlib.net/zlib125-dll.zip 25 -#ZINCDIR = C:\zlib125-dll\include 26 -#ZLIBDIR = C:\zlib125-dll\lib 27 -#ZLIB = zdll.lib 28 -ZINCDIR = $(SRCDIR)\..\zlib-1.2.7 29 -ZLIBDIR = $(SRCDIR)\..\zlib-1.2.7 30 -ZLIB = zlib.lib 31 - 32 -INCL = -I. -I$(SRCDIR) -I$B\win\include -I$(ZINCDIR) 33 - 34 -CFLAGS = -nologo -MT -O2 35 -BCC = $(CC) $(CFLAGS) 36 -TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) 37 -LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) 38 -LIBDIR = -LIBPATH:$(ZLIBDIR) 39 - 40 -SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 /DSQLITE_THREADSAFE=0 /DSQLITE_DEFAULT_FILE_FORMAT=4 /DSQLITE_ENABLE_STAT3 /Dlocaltime=fossil_localtime /DSQLITE_ENABLE_LOCKING_STYLE=0 41 - 42 -SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c 43 - 44 -OBJ = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\json$O $(OX)\json_artifact$O $(OX)\json_branch$O $(OX)\json_config$O $(OX)\json_diff$O $(OX)\json_dir$O $(OX)\json_finfo$O $(OX)\json_login$O $(OX)\json_query$O $(OX)\json_report$O $(OX)\json_tag$O $(OX)\json_timeline$O $(OX)\json_user$O $(OX)\json_wiki$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\wysiwyg$O $(OX)\xfer$O $(OX)\xfersetup$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite3$O $(OX)\th$O $(OX)\th_lang$O 45 - 46 - 47 -APPNAME = $(OX)\fossil$(E) 48 - 49 -all: $(OX) $(APPNAME) 50 - 51 -$(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts 52 - cd $(OX) 53 - link /NODEFAULTLIB:msvcrt -OUT:$@ $(LIBDIR) @linkopts 54 - 55 -$(OX)\linkopts: $B\win\Makefile.msc 56 - echo $(OX)\add.obj > $@ 57 - echo $(OX)\allrepo.obj >> $@ 58 - echo $(OX)\attach.obj >> $@ 59 - echo $(OX)\bag.obj >> $@ 60 - echo $(OX)\bisect.obj >> $@ 61 - echo $(OX)\blob.obj >> $@ 62 - echo $(OX)\branch.obj >> $@ 63 - echo $(OX)\browse.obj >> $@ 64 - echo $(OX)\captcha.obj >> $@ 65 - echo $(OX)\cgi.obj >> $@ 66 - echo $(OX)\checkin.obj >> $@ 67 - echo $(OX)\checkout.obj >> $@ 68 - echo $(OX)\clearsign.obj >> $@ 69 - echo $(OX)\clone.obj >> $@ 70 - echo $(OX)\comformat.obj >> $@ 71 - echo $(OX)\configure.obj >> $@ 72 - echo $(OX)\content.obj >> $@ 73 - echo $(OX)\db.obj >> $@ 74 - echo $(OX)\delta.obj >> $@ 75 - echo $(OX)\deltacmd.obj >> $@ 76 - echo $(OX)\descendants.obj >> $@ 77 - echo $(OX)\diff.obj >> $@ 78 - echo $(OX)\diffcmd.obj >> $@ 79 - echo $(OX)\doc.obj >> $@ 80 - echo $(OX)\encode.obj >> $@ 81 - echo $(OX)\event.obj >> $@ 82 - echo $(OX)\export.obj >> $@ 83 - echo $(OX)\file.obj >> $@ 84 - echo $(OX)\finfo.obj >> $@ 85 - echo $(OX)\glob.obj >> $@ 86 - echo $(OX)\graph.obj >> $@ 87 - echo $(OX)\gzip.obj >> $@ 88 - echo $(OX)\http.obj >> $@ 89 - echo $(OX)\http_socket.obj >> $@ 90 - echo $(OX)\http_ssl.obj >> $@ 91 - echo $(OX)\http_transport.obj >> $@ 92 - echo $(OX)\import.obj >> $@ 93 - echo $(OX)\info.obj >> $@ 94 - echo $(OX)\json.obj >> $@ 95 - echo $(OX)\json_artifact.obj >> $@ 96 - echo $(OX)\json_branch.obj >> $@ 97 - echo $(OX)\json_config.obj >> $@ 98 - echo $(OX)\json_diff.obj >> $@ 99 - echo $(OX)\json_dir.obj >> $@ 100 - echo $(OX)\json_finfo.obj >> $@ 101 - echo $(OX)\json_login.obj >> $@ 102 - echo $(OX)\json_query.obj >> $@ 103 - echo $(OX)\json_report.obj >> $@ 104 - echo $(OX)\json_tag.obj >> $@ 105 - echo $(OX)\json_timeline.obj >> $@ 106 - echo $(OX)\json_user.obj >> $@ 107 - echo $(OX)\json_wiki.obj >> $@ 108 - echo $(OX)\leaf.obj >> $@ 109 - echo $(OX)\login.obj >> $@ 110 - echo $(OX)\main.obj >> $@ 111 - echo $(OX)\manifest.obj >> $@ 112 - echo $(OX)\md5.obj >> $@ 113 - echo $(OX)\merge.obj >> $@ 114 - echo $(OX)\merge3.obj >> $@ 115 - echo $(OX)\name.obj >> $@ 116 - echo $(OX)\path.obj >> $@ 117 - echo $(OX)\pivot.obj >> $@ 118 - echo $(OX)\popen.obj >> $@ 119 - echo $(OX)\pqueue.obj >> $@ 120 - echo $(OX)\printf.obj >> $@ 121 - echo $(OX)\rebuild.obj >> $@ 122 - echo $(OX)\report.obj >> $@ 123 - echo $(OX)\rss.obj >> $@ 124 - echo $(OX)\schema.obj >> $@ 125 - echo $(OX)\search.obj >> $@ 126 - echo $(OX)\setup.obj >> $@ 127 - echo $(OX)\sha1.obj >> $@ 128 - echo $(OX)\shell.obj >> $@ 129 - echo $(OX)\shun.obj >> $@ 130 - echo $(OX)\skins.obj >> $@ 131 - echo $(OX)\sqlcmd.obj >> $@ 132 - echo $(OX)\sqlite3.obj >> $@ 133 - echo $(OX)\stash.obj >> $@ 134 - echo $(OX)\stat.obj >> $@ 135 - echo $(OX)\style.obj >> $@ 136 - echo $(OX)\sync.obj >> $@ 137 - echo $(OX)\tag.obj >> $@ 138 - echo $(OX)\tar.obj >> $@ 139 - echo $(OX)\th.obj >> $@ 140 - echo $(OX)\th_lang.obj >> $@ 141 - echo $(OX)\th_main.obj >> $@ 142 - echo $(OX)\timeline.obj >> $@ 143 - echo $(OX)\tkt.obj >> $@ 144 - echo $(OX)\tktsetup.obj >> $@ 145 - echo $(OX)\undo.obj >> $@ 146 - echo $(OX)\update.obj >> $@ 147 - echo $(OX)\url.obj >> $@ 148 - echo $(OX)\user.obj >> $@ 149 - echo $(OX)\verify.obj >> $@ 150 - echo $(OX)\vfile.obj >> $@ 151 - echo $(OX)\wiki.obj >> $@ 152 - echo $(OX)\wikiformat.obj >> $@ 153 - echo $(OX)\winhttp.obj >> $@ 154 - echo $(OX)\wysiwyg.obj >> $@ 155 - echo $(OX)\xfer.obj >> $@ 156 - echo $(OX)\xfersetup.obj >> $@ 157 - echo $(OX)\zip.obj >> $@ 158 - echo $(LIBS) >> $@ 159 - 160 - 161 - 162 - 163 -$(OX): 164 - @-mkdir $@ 165 - 166 -translate$E: $(SRCDIR)\translate.c 167 - $(BCC) $** 168 - 169 -makeheaders$E: $(SRCDIR)\makeheaders.c 170 - $(BCC) $** 171 - 172 -mkindex$E: $(SRCDIR)\mkindex.c 173 - $(BCC) $** 174 - 175 -mkversion$E: $B\src\mkversion.c 176 - $(BCC) $** 177 - 178 -$(OX)\shell$O : $(SRCDIR)\shell.c 179 - $(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c 180 - 181 -$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c 182 - $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $** 183 - 184 -$(OX)\th$O : $(SRCDIR)\th.c 185 - $(TCC) /Fo$@ -c $** 186 - 187 -$(OX)\th_lang$O : $(SRCDIR)\th_lang.c 188 - $(TCC) /Fo$@ -c $** 189 - 190 -VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION 191 - $** > $@ 192 -$(OBJDIR)\cson_amalgamation.h : $(SRCDIR)\cson_amalgamation.h 193 - cp $(SRCDIR)\cson_amalgamation.h $@ 194 - 195 -page_index.h: mkindex$E $(SRC) 196 - $** > $@ 197 - 198 -clean: 199 - -del $(OX)\*.obj 200 - -del *.obj *_.c *.h *.map 201 - -del headers linkopts 202 - 203 -realclean: 204 - -del $(APPNAME) translate$E mkindex$E makeheaders$E mkversion$E 205 - 206 -$(OBJDIR)\json$O : $(SRCDIR)\json_detail.h 207 -$(OBJDIR)\json_artifact$O : $(SRCDIR)\json_detail.h 208 -$(OBJDIR)\json_branch$O : $(SRCDIR)\json_detail.h 209 -$(OBJDIR)\json_config$O : $(SRCDIR)\json_detail.h 210 -$(OBJDIR)\json_diff$O : $(SRCDIR)\json_detail.h 211 -$(OBJDIR)\json_dir$O : $(SRCDIR)\json_detail.h 212 -$(OBJDIR)\json_finfo$O : $(SRCDIR)\json_detail.h 213 -$(OBJDIR)\json_login$O : $(SRCDIR)\json_detail.h 214 -$(OBJDIR)\json_query$O : $(SRCDIR)\json_detail.h 215 -$(OBJDIR)\json_report$O : $(SRCDIR)\json_detail.h 216 -$(OBJDIR)\json_tag$O : $(SRCDIR)\json_detail.h 217 -$(OBJDIR)\json_timeline$O : $(SRCDIR)\json_detail.h 218 -$(OBJDIR)\json_user$O : $(SRCDIR)\json_detail.h 219 -$(OBJDIR)\json_wiki$O : $(SRCDIR)\json_detail.h 220 - 221 - 222 -$(OX)\add$O : add_.c add.h 223 - $(TCC) /Fo$@ -c add_.c 224 - 225 -add_.c : $(SRCDIR)\add.c 226 - translate$E $** > $@ 227 - 228 -$(OX)\allrepo$O : allrepo_.c allrepo.h 229 - $(TCC) /Fo$@ -c allrepo_.c 230 - 231 -allrepo_.c : $(SRCDIR)\allrepo.c 232 - translate$E $** > $@ 233 - 234 -$(OX)\attach$O : attach_.c attach.h 235 - $(TCC) /Fo$@ -c attach_.c 236 - 237 -attach_.c : $(SRCDIR)\attach.c 238 - translate$E $** > $@ 239 - 240 -$(OX)\bag$O : bag_.c bag.h 241 - $(TCC) /Fo$@ -c bag_.c 242 - 243 -bag_.c : $(SRCDIR)\bag.c 244 - translate$E $** > $@ 245 - 246 -$(OX)\bisect$O : bisect_.c bisect.h 247 - $(TCC) /Fo$@ -c bisect_.c 248 - 249 -bisect_.c : $(SRCDIR)\bisect.c 250 - translate$E $** > $@ 251 - 252 -$(OX)\blob$O : blob_.c blob.h 253 - $(TCC) /Fo$@ -c blob_.c 254 - 255 -blob_.c : $(SRCDIR)\blob.c 256 - translate$E $** > $@ 257 - 258 -$(OX)\branch$O : branch_.c branch.h 259 - $(TCC) /Fo$@ -c branch_.c 260 - 261 -branch_.c : $(SRCDIR)\branch.c 262 - translate$E $** > $@ 263 - 264 -$(OX)\browse$O : browse_.c browse.h 265 - $(TCC) /Fo$@ -c browse_.c 266 - 267 -browse_.c : $(SRCDIR)\browse.c 268 - translate$E $** > $@ 269 - 270 -$(OX)\captcha$O : captcha_.c captcha.h 271 - $(TCC) /Fo$@ -c captcha_.c 272 - 273 -captcha_.c : $(SRCDIR)\captcha.c 274 - translate$E $** > $@ 275 - 276 -$(OX)\cgi$O : cgi_.c cgi.h 277 - $(TCC) /Fo$@ -c cgi_.c 278 - 279 -cgi_.c : $(SRCDIR)\cgi.c 280 - translate$E $** > $@ 281 - 282 -$(OX)\checkin$O : checkin_.c checkin.h 283 - $(TCC) /Fo$@ -c checkin_.c 284 - 285 -checkin_.c : $(SRCDIR)\checkin.c 286 - translate$E $** > $@ 287 - 288 -$(OX)\checkout$O : checkout_.c checkout.h 289 - $(TCC) /Fo$@ -c checkout_.c 290 - 291 -checkout_.c : $(SRCDIR)\checkout.c 292 - translate$E $** > $@ 293 - 294 -$(OX)\clearsign$O : clearsign_.c clearsign.h 295 - $(TCC) /Fo$@ -c clearsign_.c 296 - 297 -clearsign_.c : $(SRCDIR)\clearsign.c 298 - translate$E $** > $@ 299 - 300 -$(OX)\clone$O : clone_.c clone.h 301 - $(TCC) /Fo$@ -c clone_.c 302 - 303 -clone_.c : $(SRCDIR)\clone.c 304 - translate$E $** > $@ 305 - 306 -$(OX)\comformat$O : comformat_.c comformat.h 307 - $(TCC) /Fo$@ -c comformat_.c 308 - 309 -comformat_.c : $(SRCDIR)\comformat.c 310 - translate$E $** > $@ 311 - 312 -$(OX)\configure$O : configure_.c configure.h 313 - $(TCC) /Fo$@ -c configure_.c 314 - 315 -configure_.c : $(SRCDIR)\configure.c 316 - translate$E $** > $@ 317 - 318 -$(OX)\content$O : content_.c content.h 319 - $(TCC) /Fo$@ -c content_.c 320 - 321 -content_.c : $(SRCDIR)\content.c 322 - translate$E $** > $@ 323 - 324 -$(OX)\db$O : db_.c db.h 325 - $(TCC) /Fo$@ -c db_.c 326 - 327 -db_.c : $(SRCDIR)\db.c 328 - translate$E $** > $@ 329 - 330 -$(OX)\delta$O : delta_.c delta.h 331 - $(TCC) /Fo$@ -c delta_.c 332 - 333 -delta_.c : $(SRCDIR)\delta.c 334 - translate$E $** > $@ 335 - 336 -$(OX)\deltacmd$O : deltacmd_.c deltacmd.h 337 - $(TCC) /Fo$@ -c deltacmd_.c 338 - 339 -deltacmd_.c : $(SRCDIR)\deltacmd.c 340 - translate$E $** > $@ 341 - 342 -$(OX)\descendants$O : descendants_.c descendants.h 343 - $(TCC) /Fo$@ -c descendants_.c 344 - 345 -descendants_.c : $(SRCDIR)\descendants.c 346 - translate$E $** > $@ 347 - 348 -$(OX)\diff$O : diff_.c diff.h 349 - $(TCC) /Fo$@ -c diff_.c 350 - 351 -diff_.c : $(SRCDIR)\diff.c 352 - translate$E $** > $@ 353 - 354 -$(OX)\diffcmd$O : diffcmd_.c diffcmd.h 355 - $(TCC) /Fo$@ -c diffcmd_.c 356 - 357 -diffcmd_.c : $(SRCDIR)\diffcmd.c 358 - translate$E $** > $@ 359 - 360 -$(OX)\doc$O : doc_.c doc.h 361 - $(TCC) /Fo$@ -c doc_.c 362 - 363 -doc_.c : $(SRCDIR)\doc.c 364 - translate$E $** > $@ 365 - 366 -$(OX)\encode$O : encode_.c encode.h 367 - $(TCC) /Fo$@ -c encode_.c 368 - 369 -encode_.c : $(SRCDIR)\encode.c 370 - translate$E $** > $@ 371 - 372 -$(OX)\event$O : event_.c event.h 373 - $(TCC) /Fo$@ -c event_.c 374 - 375 -event_.c : $(SRCDIR)\event.c 376 - translate$E $** > $@ 377 - 378 -$(OX)\export$O : export_.c export.h 379 - $(TCC) /Fo$@ -c export_.c 380 - 381 -export_.c : $(SRCDIR)\export.c 382 - translate$E $** > $@ 383 - 384 -$(OX)\file$O : file_.c file.h 385 - $(TCC) /Fo$@ -c file_.c 386 - 387 -file_.c : $(SRCDIR)\file.c 388 - translate$E $** > $@ 389 - 390 -$(OX)\finfo$O : finfo_.c finfo.h 391 - $(TCC) /Fo$@ -c finfo_.c 392 - 393 -finfo_.c : $(SRCDIR)\finfo.c 394 - translate$E $** > $@ 395 - 396 -$(OX)\glob$O : glob_.c glob.h 397 - $(TCC) /Fo$@ -c glob_.c 398 - 399 -glob_.c : $(SRCDIR)\glob.c 400 - translate$E $** > $@ 401 - 402 -$(OX)\graph$O : graph_.c graph.h 403 - $(TCC) /Fo$@ -c graph_.c 404 - 405 -graph_.c : $(SRCDIR)\graph.c 406 - translate$E $** > $@ 407 - 408 -$(OX)\gzip$O : gzip_.c gzip.h 409 - $(TCC) /Fo$@ -c gzip_.c 410 - 411 -gzip_.c : $(SRCDIR)\gzip.c 412 - translate$E $** > $@ 413 - 414 -$(OX)\http$O : http_.c http.h 415 - $(TCC) /Fo$@ -c http_.c 416 - 417 -http_.c : $(SRCDIR)\http.c 418 - translate$E $** > $@ 419 - 420 -$(OX)\http_socket$O : http_socket_.c http_socket.h 421 - $(TCC) /Fo$@ -c http_socket_.c 422 - 423 -http_socket_.c : $(SRCDIR)\http_socket.c 424 - translate$E $** > $@ 425 - 426 -$(OX)\http_ssl$O : http_ssl_.c http_ssl.h 427 - $(TCC) /Fo$@ -c http_ssl_.c 428 - 429 -http_ssl_.c : $(SRCDIR)\http_ssl.c 430 - translate$E $** > $@ 431 - 432 -$(OX)\http_transport$O : http_transport_.c http_transport.h 433 - $(TCC) /Fo$@ -c http_transport_.c 434 - 435 -http_transport_.c : $(SRCDIR)\http_transport.c 436 - translate$E $** > $@ 437 - 438 -$(OX)\import$O : import_.c import.h 439 - $(TCC) /Fo$@ -c import_.c 440 - 441 -import_.c : $(SRCDIR)\import.c 442 - translate$E $** > $@ 443 - 444 -$(OX)\info$O : info_.c info.h 445 - $(TCC) /Fo$@ -c info_.c 446 - 447 -info_.c : $(SRCDIR)\info.c 448 - translate$E $** > $@ 449 - 450 -$(OX)\json$O : json_.c json.h 451 - $(TCC) /Fo$@ -c json_.c 452 - 453 -json_.c : $(SRCDIR)\json.c 454 - translate$E $** > $@ 455 - 456 -$(OX)\json_artifact$O : json_artifact_.c json_artifact.h 457 - $(TCC) /Fo$@ -c json_artifact_.c 458 - 459 -json_artifact_.c : $(SRCDIR)\json_artifact.c 460 - translate$E $** > $@ 461 - 462 -$(OX)\json_branch$O : json_branch_.c json_branch.h 463 - $(TCC) /Fo$@ -c json_branch_.c 464 - 465 -json_branch_.c : $(SRCDIR)\json_branch.c 466 - translate$E $** > $@ 467 - 468 -$(OX)\json_config$O : json_config_.c json_config.h 469 - $(TCC) /Fo$@ -c json_config_.c 470 - 471 -json_config_.c : $(SRCDIR)\json_config.c 472 - translate$E $** > $@ 473 - 474 -$(OX)\json_diff$O : json_diff_.c json_diff.h 475 - $(TCC) /Fo$@ -c json_diff_.c 476 - 477 -json_diff_.c : $(SRCDIR)\json_diff.c 478 - translate$E $** > $@ 479 - 480 -$(OX)\json_dir$O : json_dir_.c json_dir.h 481 - $(TCC) /Fo$@ -c json_dir_.c 482 - 483 -json_dir_.c : $(SRCDIR)\json_dir.c 484 - translate$E $** > $@ 485 - 486 -$(OX)\json_finfo$O : json_finfo_.c json_finfo.h 487 - $(TCC) /Fo$@ -c json_finfo_.c 488 - 489 -json_finfo_.c : $(SRCDIR)\json_finfo.c 490 - translate$E $** > $@ 491 - 492 -$(OX)\json_login$O : json_login_.c json_login.h 493 - $(TCC) /Fo$@ -c json_login_.c 494 - 495 -json_login_.c : $(SRCDIR)\json_login.c 496 - translate$E $** > $@ 497 - 498 -$(OX)\json_query$O : json_query_.c json_query.h 499 - $(TCC) /Fo$@ -c json_query_.c 500 - 501 -json_query_.c : $(SRCDIR)\json_query.c 502 - translate$E $** > $@ 503 - 504 -$(OX)\json_report$O : json_report_.c json_report.h 505 - $(TCC) /Fo$@ -c json_report_.c 506 - 507 -json_report_.c : $(SRCDIR)\json_report.c 508 - translate$E $** > $@ 509 - 510 -$(OX)\json_tag$O : json_tag_.c json_tag.h 511 - $(TCC) /Fo$@ -c json_tag_.c 512 - 513 -json_tag_.c : $(SRCDIR)\json_tag.c 514 - translate$E $** > $@ 515 - 516 -$(OX)\json_timeline$O : json_timeline_.c json_timeline.h 517 - $(TCC) /Fo$@ -c json_timeline_.c 518 - 519 -json_timeline_.c : $(SRCDIR)\json_timeline.c 520 - translate$E $** > $@ 521 - 522 -$(OX)\json_user$O : json_user_.c json_user.h 523 - $(TCC) /Fo$@ -c json_user_.c 524 - 525 -json_user_.c : $(SRCDIR)\json_user.c 526 - translate$E $** > $@ 527 - 528 -$(OX)\json_wiki$O : json_wiki_.c json_wiki.h 529 - $(TCC) /Fo$@ -c json_wiki_.c 530 - 531 -json_wiki_.c : $(SRCDIR)\json_wiki.c 532 - translate$E $** > $@ 533 - 534 -$(OX)\leaf$O : leaf_.c leaf.h 535 - $(TCC) /Fo$@ -c leaf_.c 536 - 537 -leaf_.c : $(SRCDIR)\leaf.c 538 - translate$E $** > $@ 539 - 540 -$(OX)\login$O : login_.c login.h 541 - $(TCC) /Fo$@ -c login_.c 542 - 543 -login_.c : $(SRCDIR)\login.c 544 - translate$E $** > $@ 545 - 546 -$(OX)\main$O : main_.c main.h 547 - $(TCC) /Fo$@ -c main_.c 548 - 549 -main_.c : $(SRCDIR)\main.c 550 - translate$E $** > $@ 551 - 552 -$(OX)\manifest$O : manifest_.c manifest.h 553 - $(TCC) /Fo$@ -c manifest_.c 554 - 555 -manifest_.c : $(SRCDIR)\manifest.c 556 - translate$E $** > $@ 557 - 558 -$(OX)\md5$O : md5_.c md5.h 559 - $(TCC) /Fo$@ -c md5_.c 560 - 561 -md5_.c : $(SRCDIR)\md5.c 562 - translate$E $** > $@ 563 - 564 -$(OX)\merge$O : merge_.c merge.h 565 - $(TCC) /Fo$@ -c merge_.c 566 - 567 -merge_.c : $(SRCDIR)\merge.c 568 - translate$E $** > $@ 569 - 570 -$(OX)\merge3$O : merge3_.c merge3.h 571 - $(TCC) /Fo$@ -c merge3_.c 572 - 573 -merge3_.c : $(SRCDIR)\merge3.c 574 - translate$E $** > $@ 575 - 576 -$(OX)\name$O : name_.c name.h 577 - $(TCC) /Fo$@ -c name_.c 578 - 579 -name_.c : $(SRCDIR)\name.c 580 - translate$E $** > $@ 581 - 582 -$(OX)\path$O : path_.c path.h 583 - $(TCC) /Fo$@ -c path_.c 584 - 585 -path_.c : $(SRCDIR)\path.c 586 - translate$E $** > $@ 587 - 588 -$(OX)\pivot$O : pivot_.c pivot.h 589 - $(TCC) /Fo$@ -c pivot_.c 590 - 591 -pivot_.c : $(SRCDIR)\pivot.c 592 - translate$E $** > $@ 593 - 594 -$(OX)\popen$O : popen_.c popen.h 595 - $(TCC) /Fo$@ -c popen_.c 596 - 597 -popen_.c : $(SRCDIR)\popen.c 598 - translate$E $** > $@ 599 - 600 -$(OX)\pqueue$O : pqueue_.c pqueue.h 601 - $(TCC) /Fo$@ -c pqueue_.c 602 - 603 -pqueue_.c : $(SRCDIR)\pqueue.c 604 - translate$E $** > $@ 605 - 606 -$(OX)\printf$O : printf_.c printf.h 607 - $(TCC) /Fo$@ -c printf_.c 608 - 609 -printf_.c : $(SRCDIR)\printf.c 610 - translate$E $** > $@ 611 - 612 -$(OX)\rebuild$O : rebuild_.c rebuild.h 613 - $(TCC) /Fo$@ -c rebuild_.c 614 - 615 -rebuild_.c : $(SRCDIR)\rebuild.c 616 - translate$E $** > $@ 617 - 618 -$(OX)\report$O : report_.c report.h 619 - $(TCC) /Fo$@ -c report_.c 620 - 621 -report_.c : $(SRCDIR)\report.c 622 - translate$E $** > $@ 623 - 624 -$(OX)\rss$O : rss_.c rss.h 625 - $(TCC) /Fo$@ -c rss_.c 626 - 627 -rss_.c : $(SRCDIR)\rss.c 628 - translate$E $** > $@ 629 - 630 -$(OX)\schema$O : schema_.c schema.h 631 - $(TCC) /Fo$@ -c schema_.c 632 - 633 -schema_.c : $(SRCDIR)\schema.c 634 - translate$E $** > $@ 635 - 636 -$(OX)\search$O : search_.c search.h 637 - $(TCC) /Fo$@ -c search_.c 638 - 639 -search_.c : $(SRCDIR)\search.c 640 - translate$E $** > $@ 641 - 642 -$(OX)\setup$O : setup_.c setup.h 643 - $(TCC) /Fo$@ -c setup_.c 644 - 645 -setup_.c : $(SRCDIR)\setup.c 646 - translate$E $** > $@ 647 - 648 -$(OX)\sha1$O : sha1_.c sha1.h 649 - $(TCC) /Fo$@ -c sha1_.c 650 - 651 -sha1_.c : $(SRCDIR)\sha1.c 652 - translate$E $** > $@ 653 - 654 -$(OX)\shun$O : shun_.c shun.h 655 - $(TCC) /Fo$@ -c shun_.c 656 - 657 -shun_.c : $(SRCDIR)\shun.c 658 - translate$E $** > $@ 659 - 660 -$(OX)\skins$O : skins_.c skins.h 661 - $(TCC) /Fo$@ -c skins_.c 662 - 663 -skins_.c : $(SRCDIR)\skins.c 664 - translate$E $** > $@ 665 - 666 -$(OX)\sqlcmd$O : sqlcmd_.c sqlcmd.h 667 - $(TCC) /Fo$@ -c sqlcmd_.c 668 - 669 -sqlcmd_.c : $(SRCDIR)\sqlcmd.c 670 - translate$E $** > $@ 671 - 672 -$(OX)\stash$O : stash_.c stash.h 673 - $(TCC) /Fo$@ -c stash_.c 674 - 675 -stash_.c : $(SRCDIR)\stash.c 676 - translate$E $** > $@ 677 - 678 -$(OX)\stat$O : stat_.c stat.h 679 - $(TCC) /Fo$@ -c stat_.c 680 - 681 -stat_.c : $(SRCDIR)\stat.c 682 - translate$E $** > $@ 683 - 684 -$(OX)\style$O : style_.c style.h 685 - $(TCC) /Fo$@ -c style_.c 686 - 687 -style_.c : $(SRCDIR)\style.c 688 - translate$E $** > $@ 689 - 690 -$(OX)\sync$O : sync_.c sync.h 691 - $(TCC) /Fo$@ -c sync_.c 692 - 693 -sync_.c : $(SRCDIR)\sync.c 694 - translate$E $** > $@ 695 - 696 -$(OX)\tag$O : tag_.c tag.h 697 - $(TCC) /Fo$@ -c tag_.c 698 - 699 -tag_.c : $(SRCDIR)\tag.c 700 - translate$E $** > $@ 701 - 702 -$(OX)\tar$O : tar_.c tar.h 703 - $(TCC) /Fo$@ -c tar_.c 704 - 705 -tar_.c : $(SRCDIR)\tar.c 706 - translate$E $** > $@ 707 - 708 -$(OX)\th_main$O : th_main_.c th_main.h 709 - $(TCC) /Fo$@ -c th_main_.c 710 - 711 -th_main_.c : $(SRCDIR)\th_main.c 712 - translate$E $** > $@ 713 - 714 -$(OX)\timeline$O : timeline_.c timeline.h 715 - $(TCC) /Fo$@ -c timeline_.c 716 - 717 -timeline_.c : $(SRCDIR)\timeline.c 718 - translate$E $** > $@ 719 - 720 -$(OX)\tkt$O : tkt_.c tkt.h 721 - $(TCC) /Fo$@ -c tkt_.c 722 - 723 -tkt_.c : $(SRCDIR)\tkt.c 724 - translate$E $** > $@ 725 - 726 -$(OX)\tktsetup$O : tktsetup_.c tktsetup.h 727 - $(TCC) /Fo$@ -c tktsetup_.c 728 - 729 -tktsetup_.c : $(SRCDIR)\tktsetup.c 730 - translate$E $** > $@ 731 - 732 -$(OX)\undo$O : undo_.c undo.h 733 - $(TCC) /Fo$@ -c undo_.c 734 - 735 -undo_.c : $(SRCDIR)\undo.c 736 - translate$E $** > $@ 737 - 738 -$(OX)\update$O : update_.c update.h 739 - $(TCC) /Fo$@ -c update_.c 740 - 741 -update_.c : $(SRCDIR)\update.c 742 - translate$E $** > $@ 743 - 744 -$(OX)\url$O : url_.c url.h 745 - $(TCC) /Fo$@ -c url_.c 746 - 747 -url_.c : $(SRCDIR)\url.c 748 - translate$E $** > $@ 749 - 750 -$(OX)\user$O : user_.c user.h 751 - $(TCC) /Fo$@ -c user_.c 752 - 753 -user_.c : $(SRCDIR)\user.c 754 - translate$E $** > $@ 755 - 756 -$(OX)\verify$O : verify_.c verify.h 757 - $(TCC) /Fo$@ -c verify_.c 758 - 759 -verify_.c : $(SRCDIR)\verify.c 760 - translate$E $** > $@ 761 - 762 -$(OX)\vfile$O : vfile_.c vfile.h 763 - $(TCC) /Fo$@ -c vfile_.c 764 - 765 -vfile_.c : $(SRCDIR)\vfile.c 766 - translate$E $** > $@ 767 - 768 -$(OX)\wiki$O : wiki_.c wiki.h 769 - $(TCC) /Fo$@ -c wiki_.c 770 - 771 -wiki_.c : $(SRCDIR)\wiki.c 772 - translate$E $** > $@ 773 - 774 -$(OX)\wikiformat$O : wikiformat_.c wikiformat.h 775 - $(TCC) /Fo$@ -c wikiformat_.c 776 - 777 -wikiformat_.c : $(SRCDIR)\wikiformat.c 778 - translate$E $** > $@ 779 - 780 -$(OX)\winhttp$O : winhttp_.c winhttp.h 781 - $(TCC) /Fo$@ -c winhttp_.c 782 - 783 -winhttp_.c : $(SRCDIR)\winhttp.c 784 - translate$E $** > $@ 785 - 786 -$(OX)\wysiwyg$O : wysiwyg_.c wysiwyg.h 787 - $(TCC) /Fo$@ -c wysiwyg_.c 788 - 789 -wysiwyg_.c : $(SRCDIR)\wysiwyg.c 790 - translate$E $** > $@ 791 - 792 -$(OX)\xfer$O : xfer_.c xfer.h 793 - $(TCC) /Fo$@ -c xfer_.c 794 - 795 -xfer_.c : $(SRCDIR)\xfer.c 796 - translate$E $** > $@ 797 - 798 -$(OX)\xfersetup$O : xfersetup_.c xfersetup.h 799 - $(TCC) /Fo$@ -c xfersetup_.c 800 - 801 -xfersetup_.c : $(SRCDIR)\xfersetup.c 802 - translate$E $** > $@ 803 - 804 -$(OX)\zip$O : zip_.c zip.h 805 - $(TCC) /Fo$@ -c zip_.c 806 - 807 -zip_.c : $(SRCDIR)\zip.c 808 - translate$E $** > $@ 809 - 810 -headers: makeheaders$E page_index.h VERSION.h 811 - makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h 812 - @copy /Y nul: headers