diff options
74 files changed, 7120 insertions, 1855 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..19deaa5 --- /dev/null +++ b/CMakeLists.txt | |||
| @@ -0,0 +1,177 @@ | |||
| 1 | cmake_minimum_required(VERSION 2.4.4) | ||
| 2 | set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) | ||
| 3 | |||
| 4 | project(zlib C) | ||
| 5 | |||
| 6 | if(NOT DEFINED BUILD_SHARED_LIBS) | ||
| 7 | option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON) | ||
| 8 | endif() | ||
| 9 | |||
| 10 | include(CheckTypeSize) | ||
| 11 | include(CheckFunctionExists) | ||
| 12 | include(CheckIncludeFile) | ||
| 13 | include(CheckCSourceCompiles) | ||
| 14 | enable_testing() | ||
| 15 | |||
| 16 | check_include_file(sys/types.h HAVE_SYS_TYPES_H) | ||
| 17 | check_include_file(stdint.h HAVE_STDINT_H) | ||
| 18 | check_include_file(stddef.h HAVE_STDDEF_H) | ||
| 19 | |||
| 20 | # | ||
| 21 | # Check to see if we have large file support | ||
| 22 | # | ||
| 23 | set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE) | ||
| 24 | |||
| 25 | # We add these other definitions here because CheckTypeSize.cmake | ||
| 26 | # in CMake 2.4.x does not automatically do so and we want | ||
| 27 | # compatibility with CMake 2.4.x. | ||
| 28 | if(HAVE_SYS_TYPES_H) | ||
| 29 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) | ||
| 30 | endif() | ||
| 31 | if(HAVE_STDINT_H) | ||
| 32 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) | ||
| 33 | endif() | ||
| 34 | if(HAVE_STDDEF_H) | ||
| 35 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) | ||
| 36 | endif() | ||
| 37 | |||
| 38 | check_type_size(off64_t OFF64_T) | ||
| 39 | |||
| 40 | if(HAVE_OFF64_T) | ||
| 41 | add_definitions(-D_LARGEFILE64_SOURCE) | ||
| 42 | endif() | ||
| 43 | set(CMAKE_REQUIRED_DEFINITIONS) # clear variable | ||
| 44 | |||
| 45 | # | ||
| 46 | # Check for fseeko | ||
| 47 | # | ||
| 48 | check_function_exists(fseeko HAVE_FSEEKO) | ||
| 49 | if(NOT HAVE_FSEEKO) | ||
| 50 | add_definitions(-DNO_FSEEKO) | ||
| 51 | endif() | ||
| 52 | |||
| 53 | # | ||
| 54 | # Check for unistd.h | ||
| 55 | # | ||
| 56 | check_include_file(unistd.h HAVE_UNISTD_H) | ||
| 57 | |||
| 58 | # | ||
| 59 | # Check for errno.h | ||
| 60 | check_include_file(errno.h HAVE_ERRNO_H) | ||
| 61 | if(NOT HAVE_ERRNO_H) | ||
| 62 | add_definitions(-DNO_ERRNO_H) | ||
| 63 | endif() | ||
| 64 | |||
| 65 | # | ||
| 66 | # Check for mmap support | ||
| 67 | # | ||
| 68 | set(mmap_test_code " | ||
| 69 | #include <sys/types.h> | ||
| 70 | #include <sys/mman.h> | ||
| 71 | #include <sys/stat.h> | ||
| 72 | caddr_t hello() { | ||
| 73 | return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); | ||
| 74 | } | ||
| 75 | int main() { return 0; } | ||
| 76 | ") | ||
| 77 | check_c_source_compiles("${mmap_test_code}" USE_MMAP) | ||
| 78 | if(USE_MMAP) | ||
| 79 | add_definitions(-DUSE_MMAP) | ||
| 80 | endif() | ||
| 81 | |||
| 82 | # | ||
| 83 | # Create the zlibdefs.h file. | ||
| 84 | # Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead | ||
| 85 | # of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h | ||
| 86 | # is shipped with zlib in the source tree. | ||
| 87 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein | ||
| 88 | ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h) | ||
| 89 | |||
| 90 | if(MSVC) | ||
| 91 | set(CMAKE_DEBUG_POSTFIX "D") | ||
| 92 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE) | ||
| 93 | add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) | ||
| 94 | endif() | ||
| 95 | |||
| 96 | #============================================================================ | ||
| 97 | # zlib | ||
| 98 | #============================================================================ | ||
| 99 | |||
| 100 | set(ZLIB_PUBLIC_HDRS | ||
| 101 | zconf.h | ||
| 102 | zlib.h | ||
| 103 | zlibdefs.h | ||
| 104 | ) | ||
| 105 | set(ZLIB_PRIVATE_HDRS | ||
| 106 | crc32.h | ||
| 107 | deflate.h | ||
| 108 | gzguts.h | ||
| 109 | inffast.h | ||
| 110 | inffixed.h | ||
| 111 | inflate.h | ||
| 112 | inftrees.h | ||
| 113 | trees.h | ||
| 114 | zutil.h | ||
| 115 | ) | ||
| 116 | set(ZLIB_SRCS | ||
| 117 | adler32.c | ||
| 118 | compress.c | ||
| 119 | crc32.c | ||
| 120 | deflate.c | ||
| 121 | gzclose.c | ||
| 122 | gzio.c | ||
| 123 | gzlib.c | ||
| 124 | gzread.c | ||
| 125 | gzwrite.c | ||
| 126 | inflate.c | ||
| 127 | infback.c | ||
| 128 | inftrees.c | ||
| 129 | inffast.c | ||
| 130 | trees.c | ||
| 131 | uncompr.c | ||
| 132 | zutil.c | ||
| 133 | ) | ||
| 134 | |||
| 135 | add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) | ||
| 136 | set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) | ||
| 137 | set_target_properties(zlib PROPERTIES VERSION 1.2.3.4) | ||
| 138 | set_target_properties(zlib PROPERTIES SOVERSION 1) | ||
| 139 | if(UNIX) | ||
| 140 | # On unix like platforms the library is almost always called libz | ||
| 141 | set_target_properties(zlib PROPERTIES OUTPUT_NAME z) | ||
| 142 | endif() | ||
| 143 | |||
| 144 | if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) | ||
| 145 | install(TARGETS zlib | ||
| 146 | RUNTIME DESTINATION bin | ||
| 147 | ARCHIVE DESTINATION lib | ||
| 148 | LIBRARY DESTINATION lib ) | ||
| 149 | endif() | ||
| 150 | if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) | ||
| 151 | install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include) | ||
| 152 | endif() | ||
| 153 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) | ||
| 154 | install(FILES zlib.3 DESTINATION share/man/man3) | ||
| 155 | endif() | ||
| 156 | |||
| 157 | #============================================================================ | ||
| 158 | # Example binaries | ||
| 159 | #============================================================================ | ||
| 160 | |||
| 161 | add_executable(example example.c) | ||
| 162 | target_link_libraries(example zlib) | ||
| 163 | add_test(example example) | ||
| 164 | |||
| 165 | add_executable(minigzip minigzip.c) | ||
| 166 | target_link_libraries(minigzip zlib) | ||
| 167 | |||
| 168 | if(HAVE_OFF64_T) | ||
| 169 | add_executable(example64 example.c) | ||
| 170 | target_link_libraries(example64 zlib) | ||
| 171 | set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") | ||
| 172 | add_test(example64 example64) | ||
| 173 | |||
| 174 | add_executable(minigzip64 minigzip.c) | ||
| 175 | target_link_libraries(minigzip64 zlib) | ||
| 176 | set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") | ||
| 177 | endif() | ||
| @@ -1,6 +1,27 @@ | |||
| 1 | 1 | ||
| 2 | ChangeLog file for zlib | 2 | ChangeLog file for zlib |
| 3 | 3 | ||
| 4 | Changes in 1.2.3.5 (8 Jan 2010) | ||
| 5 | - Add space after #if in zutil.h for some compilers | ||
| 6 | - Fix relatively harmless bug in deflate_fast() [Exarevsky] | ||
| 7 | - Fix same problem in deflate_slow() | ||
| 8 | - Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] | ||
| 9 | - Add deflate_rle() for faster Z_RLE strategy run-length encoding | ||
| 10 | - Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding | ||
| 11 | - Change name of "write" variable in inffast.c to avoid library collisions | ||
| 12 | - Fix premature EOF from gzread() in gzio.c [Brown] | ||
| 13 | - Use zlib header window size if windowBits is 0 in inflateInit2() | ||
| 14 | - Remove compressBound() call in deflate.c to avoid linking compress.o | ||
| 15 | - Replace use of errno in gz* with functions, support WinCE [Alves] | ||
| 16 | - Provide alternative to perror() in minigzip.c for WinCE [Alves] | ||
| 17 | - Don't use _vsnprintf on later versions of MSVC [Lowman] | ||
| 18 | - Add CMake build script and input file [Lowman] | ||
| 19 | - Update contrib/minizip to 1.1 [Svensson, Vollant] | ||
| 20 | - Moved nintendods directory from contrib to . | ||
| 21 | - Replace gzio.c with a new set of routines with the same functionality | ||
| 22 | - Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above | ||
| 23 | - Update contrib/minizip to 1.1b | ||
| 24 | |||
| 4 | Changes in 1.2.3.4 (21 Dec 2009) | 25 | Changes in 1.2.3.4 (21 Dec 2009) |
| 5 | - Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility | 26 | - Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility |
| 6 | - Update comments in configure and Makefile.in for default --shared | 27 | - Update comments in configure and Makefile.in for default --shared |
| @@ -25,7 +46,7 @@ Changes in 1.2.3.4 (21 Dec 2009) | |||
| 25 | - Fix static and shared Makefile.in targets to be independent | 46 | - Fix static and shared Makefile.in targets to be independent |
| 26 | - Correct error return bug in gz_open() by setting state [Brown] | 47 | - Correct error return bug in gz_open() by setting state [Brown] |
| 27 | - Put spaces before ;;'s in configure for better sh compatibility | 48 | - Put spaces before ;;'s in configure for better sh compatibility |
| 28 | - Added pigz.c (parallel implementation of gzip) to examples/ | 49 | - Add pigz.c (parallel implementation of gzip) to examples/ |
| 29 | - Correct constant in crc32.c to UL [Leventhal] | 50 | - Correct constant in crc32.c to UL [Leventhal] |
| 30 | - Reject negative lengths in crc32_combine() | 51 | - Reject negative lengths in crc32_combine() |
| 31 | - Add inflateReset2() function to work like inflateEnd()/inflateInit2() | 52 | - Add inflateReset2() function to work like inflateEnd()/inflateInit2() |
| @@ -57,7 +78,7 @@ Changes in 1.2.3.4 (21 Dec 2009) | |||
| 57 | - Allow negative bits in inflatePrime() to delete existing bit buffer | 78 | - Allow negative bits in inflatePrime() to delete existing bit buffer |
| 58 | - Add Z_TREES flush option to inflate() to return at end of trees | 79 | - Add Z_TREES flush option to inflate() to return at end of trees |
| 59 | - Add inflateMark() to return current state information for random access | 80 | - Add inflateMark() to return current state information for random access |
| 60 | - Added Makefile for NintendoDS to contrib [Costa] | 81 | - Add Makefile for NintendoDS to contrib [Costa] |
| 61 | - Add -w in configure compile tests to avoid spurious warnings [Beucler] | 82 | - Add -w in configure compile tests to avoid spurious warnings [Beucler] |
| 62 | - Fix typos in zlib.h comments for deflateSetDictionary() | 83 | - Fix typos in zlib.h comments for deflateSetDictionary() |
| 63 | - Fix EOF detection in transparent gzread() [Maier] | 84 | - Fix EOF detection in transparent gzread() [Maier] |
| @@ -1,3 +1,4 @@ | |||
| 1 | CMakeLists.txt cmake build file | ||
| 1 | ChangeLog history of changes | 2 | ChangeLog history of changes |
| 2 | FAQ Frequently Asked Questions about zlib | 3 | FAQ Frequently Asked Questions about zlib |
| 3 | INDEX this file | 4 | INDEX this file |
| @@ -6,7 +7,7 @@ Makefile.in makefile for Unix (template for configure) | |||
| 6 | README guess what | 7 | README guess what |
| 7 | configure configure script for Unix | 8 | configure configure script for Unix |
| 8 | make_vms.com makefile for VMS | 9 | make_vms.com makefile for VMS |
| 9 | treebuild.xml see http://treebuild.metux.de/ | 10 | treebuild.xml XML description of source file dependencies |
| 10 | zlib.3 Man page for zlib | 11 | zlib.3 Man page for zlib |
| 11 | zlib.map Linux symbol information | 12 | zlib.map Linux symbol information |
| 12 | zlib.pc.in Template for pkg-config descriptor | 13 | zlib.pc.in Template for pkg-config descriptor |
| @@ -16,12 +17,14 @@ amiga/ makefiles for Amiga SAS C | |||
| 16 | as400/ makefiles for IBM AS/400 | 17 | as400/ makefiles for IBM AS/400 |
| 17 | doc/ documentation for formats and algorithms | 18 | doc/ documentation for formats and algorithms |
| 18 | msdos/ makefiles for MSDOS | 19 | msdos/ makefiles for MSDOS |
| 20 | nintendods/ makefile for Nintendo DS | ||
| 19 | old/ makefiles for various architectures and zlib documentation | 21 | old/ makefiles for various architectures and zlib documentation |
| 20 | files that have not yet been updated for zlib 1.2.x | 22 | files that have not yet been updated for zlib 1.2.x |
| 21 | projects/ projects for various Integrated Development Environments | 23 | projects/ projects for various Integrated Development Environments |
| 22 | qnx/ makefiles for QNX | 24 | qnx/ makefiles for QNX |
| 23 | watcom/ makefiles for OpenWatcom | 25 | watcom/ makefiles for OpenWatcom |
| 24 | win32/ makefiles for Windows | 26 | win32/ makefiles for Windows |
| 27 | zlibdefs.h.cmakein input file for cmake build | ||
| 25 | 28 | ||
| 26 | zlib public header files (required for library use): | 29 | zlib public header files (required for library use): |
| 27 | zconf.h | 30 | zconf.h |
| @@ -35,7 +38,12 @@ crc32.c | |||
| 35 | crc32.h | 38 | crc32.h |
| 36 | deflate.c | 39 | deflate.c |
| 37 | deflate.h | 40 | deflate.h |
| 41 | gzclose.c | ||
| 42 | gzguts.h | ||
| 38 | gzio.c | 43 | gzio.c |
| 44 | gzlib.c | ||
| 45 | gzread.c | ||
| 46 | gzwrite.c | ||
| 39 | infback.c | 47 | infback.c |
| 40 | inffast.c | 48 | inffast.c |
| 41 | inffast.h | 49 | inffast.h |
| @@ -32,9 +32,9 @@ CPP=$(CC) -E | |||
| 32 | 32 | ||
| 33 | STATICLIB=libz.a | 33 | STATICLIB=libz.a |
| 34 | SHAREDLIB=libz.so | 34 | SHAREDLIB=libz.so |
| 35 | SHAREDLIBV=libz.so.1.2.3.4 | 35 | SHAREDLIBV=libz.so.1.2.3.5 |
| 36 | SHAREDLIBM=libz.so.1 | 36 | SHAREDLIBM=libz.so.1 |
| 37 | LIBS=$(STATICLIB) $(SHAREDLIB) | 37 | LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) |
| 38 | 38 | ||
| 39 | AR=ar rc | 39 | AR=ar rc |
| 40 | RANLIB=ranlib | 40 | RANLIB=ranlib |
| @@ -50,11 +50,11 @@ mandir = ${prefix}/share/man | |||
| 50 | man3dir = ${mandir}/man3 | 50 | man3dir = ${mandir}/man3 |
| 51 | pkgconfigdir = ${libdir}/pkgconfig | 51 | pkgconfigdir = ${libdir}/pkgconfig |
| 52 | 52 | ||
| 53 | OBJC = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 53 | OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \ |
| 54 | zutil.o inflate.o infback.o inftrees.o inffast.o | 54 | gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o |
| 55 | 55 | ||
| 56 | PIC_OBJC = adler32.lo compress.lo crc32.lo gzio.lo uncompr.lo deflate.lo trees.lo \ | 56 | PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzio.lo gzlib.lo gzread.lo \ |
| 57 | zutil.lo inflate.lo infback.lo inftrees.lo inffast.lo | 57 | gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo |
| 58 | 58 | ||
| 59 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo | 59 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo |
| 60 | OBJA = | 60 | OBJA = |
| @@ -221,6 +221,7 @@ depend: | |||
| 221 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 221 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
| 222 | 222 | ||
| 223 | adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h | 223 | adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h |
| 224 | gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 224 | compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h | 225 | compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h |
| 225 | crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h | 226 | crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h |
| 226 | deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h | 227 | deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h |
| @@ -230,6 +231,7 @@ inftrees.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h | |||
| 230 | trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h | 231 | trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h |
| 231 | 232 | ||
| 232 | adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h | 233 | adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h |
| 234 | gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 233 | compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h | 235 | compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h |
| 234 | crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h | 236 | crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h |
| 235 | deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h | 237 | deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h |
diff --git a/Makefile.in b/Makefile.in index 6ad7a5c..0941228 100644 --- a/Makefile.in +++ b/Makefile.in | |||
| @@ -32,9 +32,9 @@ CPP=$(CC) -E | |||
| 32 | 32 | ||
| 33 | STATICLIB=libz.a | 33 | STATICLIB=libz.a |
| 34 | SHAREDLIB=libz.so | 34 | SHAREDLIB=libz.so |
| 35 | SHAREDLIBV=libz.so.1.2.3.4 | 35 | SHAREDLIBV=libz.so.1.2.3.5 |
| 36 | SHAREDLIBM=libz.so.1 | 36 | SHAREDLIBM=libz.so.1 |
| 37 | LIBS=$(STATICLIB) $(SHAREDLIB) | 37 | LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV) |
| 38 | 38 | ||
| 39 | AR=ar rc | 39 | AR=ar rc |
| 40 | RANLIB=ranlib | 40 | RANLIB=ranlib |
| @@ -50,11 +50,11 @@ mandir = ${prefix}/share/man | |||
| 50 | man3dir = ${mandir}/man3 | 50 | man3dir = ${mandir}/man3 |
| 51 | pkgconfigdir = ${libdir}/pkgconfig | 51 | pkgconfigdir = ${libdir}/pkgconfig |
| 52 | 52 | ||
| 53 | OBJC = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 53 | OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \ |
| 54 | zutil.o inflate.o infback.o inftrees.o inffast.o | 54 | gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o |
| 55 | 55 | ||
| 56 | PIC_OBJC = adler32.lo compress.lo crc32.lo gzio.lo uncompr.lo deflate.lo trees.lo \ | 56 | PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzio.lo gzlib.lo gzread.lo \ |
| 57 | zutil.lo inflate.lo infback.lo inftrees.lo inffast.lo | 57 | gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo |
| 58 | 58 | ||
| 59 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo | 59 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo |
| 60 | OBJA = | 60 | OBJA = |
| @@ -221,6 +221,7 @@ depend: | |||
| 221 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 221 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
| 222 | 222 | ||
| 223 | adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h | 223 | adler32.o gzio.o zutil.o: zutil.h zlib.h zconf.h zlibdefs.h |
| 224 | gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 224 | compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h | 225 | compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h zlibdefs.h |
| 225 | crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h | 226 | crc32.o: zutil.h zlib.h zconf.h zlibdefs.h crc32.h |
| 226 | deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h | 227 | deflate.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h |
| @@ -230,6 +231,7 @@ inftrees.o: zutil.h zlib.h zconf.h zlibdefs.h inftrees.h | |||
| 230 | trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h | 231 | trees.o: deflate.h zutil.h zlib.h zconf.h zlibdefs.h trees.h |
| 231 | 232 | ||
| 232 | adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h | 233 | adler32.lo gzio.lo zutil.lo: zutil.h zlib.h zconf.h zlibdefs.h |
| 234 | gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 233 | compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h | 235 | compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h zlibdefs.h |
| 234 | crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h | 236 | crc32.lo: zutil.h zlib.h zconf.h zlibdefs.h crc32.h |
| 235 | deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h | 237 | deflate.lo: deflate.h zutil.h zlib.h zconf.h zlibdefs.h |
| @@ -1,6 +1,6 @@ | |||
| 1 | ZLIB DATA COMPRESSION LIBRARY | 1 | ZLIB DATA COMPRESSION LIBRARY |
| 2 | 2 | ||
| 3 | zlib 1.2.3.4 is a general purpose data compression library. All the code is | 3 | zlib 1.2.3.5 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 | 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 | 5 | (Request for Comments) 1950 to 1952 in the files |
| 6 | http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) | 6 | http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) |
| @@ -33,7 +33,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997 | |||
| 33 | issue of Dr. Dobb's Journal; a copy of the article is available in | 33 | issue of Dr. Dobb's Journal; a copy of the article is available in |
| 34 | http://dogma.net/markn/articles/zlibtool/zlibtool.htm | 34 | http://dogma.net/markn/articles/zlibtool/zlibtool.htm |
| 35 | 35 | ||
| 36 | The changes made in version 1.2.3.4 are documented in the file ChangeLog. | 36 | The changes made in version 1.2.3.5 are documented in the file ChangeLog. |
| 37 | 37 | ||
| 38 | Unsupported third party contributions are provided in directory "contrib". | 38 | Unsupported third party contributions are provided in directory "contrib". |
| 39 | 39 | ||
diff --git a/amiga/Makefile.pup b/amiga/Makefile.pup index 3f7e155..2916391 100644 --- a/amiga/Makefile.pup +++ b/amiga/Makefile.pup | |||
| @@ -14,8 +14,8 @@ LDFLAGS = -o | |||
| 14 | LDLIBS = LIB:scppc.a LIB:end.o | 14 | LDLIBS = LIB:scppc.a LIB:end.o |
| 15 | RM = delete quiet | 15 | RM = delete quiet |
| 16 | 16 | ||
| 17 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 17 | OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \ |
| 18 | zutil.o inflate.o infback.o inftrees.o inffast.o | 18 | uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o |
| 19 | 19 | ||
| 20 | TEST_OBJS = example.o minigzip.o | 20 | TEST_OBJS = example.o minigzip.o |
| 21 | 21 | ||
| @@ -55,7 +55,11 @@ compress.o: zlib.h zconf.h | |||
| 55 | crc32.o: crc32.h zlib.h zconf.h | 55 | crc32.o: crc32.h zlib.h zconf.h |
| 56 | deflate.o: deflate.h zutil.h zlib.h zconf.h | 56 | deflate.o: deflate.h zutil.h zlib.h zconf.h |
| 57 | example.o: zlib.h zconf.h | 57 | example.o: zlib.h zconf.h |
| 58 | gzclose.o: zlib.h zconf.h gzguts.h | ||
| 58 | gzio.o: zutil.h zlib.h zconf.h | 59 | gzio.o: zutil.h zlib.h zconf.h |
| 60 | gzlib.o: zlib.h zconf.h gzguts.h | ||
| 61 | gzread.o: zlib.h zconf.h gzguts.h | ||
| 62 | gzwrite.o: zlib.h zconf.h gzguts.h | ||
| 59 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 63 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
| 60 | inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 64 | inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
| 61 | infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 65 | infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
diff --git a/amiga/Makefile.sas b/amiga/Makefile.sas index 296ef48..cefe83d 100644 --- a/amiga/Makefile.sas +++ b/amiga/Makefile.sas | |||
| @@ -13,8 +13,8 @@ SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \ | |||
| 13 | NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \ | 13 | NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \ |
| 14 | DEF=POSTINC | 14 | DEF=POSTINC |
| 15 | 15 | ||
| 16 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 16 | OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \ |
| 17 | zutil.o inflate.o infback.o inftrees.o inffast.o | 17 | uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o |
| 18 | 18 | ||
| 19 | TEST_OBJS = example.o minigzip.o | 19 | TEST_OBJS = example.o minigzip.o |
| 20 | 20 | ||
| @@ -54,7 +54,11 @@ compress.o: zlib.h zconf.h | |||
| 54 | crc32.o: crc32.h zlib.h zconf.h | 54 | crc32.o: crc32.h zlib.h zconf.h |
| 55 | deflate.o: deflate.h zutil.h zlib.h zconf.h | 55 | deflate.o: deflate.h zutil.h zlib.h zconf.h |
| 56 | example.o: zlib.h zconf.h | 56 | example.o: zlib.h zconf.h |
| 57 | gzclose.o: zlib.h zconf.h gzguts.h | ||
| 57 | gzio.o: zutil.h zlib.h zconf.h | 58 | gzio.o: zutil.h zlib.h zconf.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 | ||
| 58 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 62 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
| 59 | inflate.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 |
| 60 | infback.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 |
diff --git a/as400/zlib.inc b/as400/zlib.inc index 9ef0b14..38c47ac 100644 --- a/as400/zlib.inc +++ b/as400/zlib.inc | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | * ZLIB.INC - Interface to the general purpose compression library | 1 | * ZLIB.INC - Interface to the general purpose compression library |
| 2 | * | 2 | * |
| 3 | * ILE RPG400 version by Patrick Monnerat, DATASPHERE. | 3 | * ILE RPG400 version by Patrick Monnerat, DATASPHERE. |
| 4 | * Version 1.2.3.4 | 4 | * Version 1.2.3.5 |
| 5 | * | 5 | * |
| 6 | * | 6 | * |
| 7 | * WARNING: | 7 | * WARNING: |
| @@ -22,8 +22,8 @@ | |||
| 22 | * | 22 | * |
| 23 | * Versioning information. | 23 | * Versioning information. |
| 24 | * | 24 | * |
| 25 | D ZLIB_VERSION C '1.2.3.4' | 25 | D ZLIB_VERSION C '1.2.3.5' |
| 26 | D ZLIB_VERNUM C X'1234' | 26 | D ZLIB_VERNUM C X'1235' |
| 27 | * | 27 | * |
| 28 | * Other equates. | 28 | * Other equates. |
| 29 | * | 29 | * |
diff --git a/contrib/README.contrib b/contrib/README.contrib index f9c1665..17fc8f6 100644 --- a/contrib/README.contrib +++ b/contrib/README.contrib | |||
| @@ -56,6 +56,7 @@ masmx86/ by Gilles Vollant <info@winimage.com> | |||
| 56 | 56 | ||
| 57 | minizip/ by Gilles Vollant <info@winimage.com> | 57 | minizip/ by Gilles Vollant <info@winimage.com> |
| 58 | Mini zip and unzip based on zlib | 58 | Mini zip and unzip based on zlib |
| 59 | Includes Zip64 support by Mathias Svensson <mathias@result42.com> | ||
| 59 | See http://www.winimage.com/zLibDll/unzip.html | 60 | See http://www.winimage.com/zLibDll/unzip.html |
| 60 | 61 | ||
| 61 | pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al. | 62 | pascal/ by Bob Dellaca <bobdl@xtra.co.nz> et al. |
diff --git a/contrib/delphi/zlibd32.mak b/contrib/delphi/zlibd32.mak index 88fafa0..203a4c9 100644 --- a/contrib/delphi/zlibd32.mak +++ b/contrib/delphi/zlibd32.mak | |||
| @@ -18,10 +18,10 @@ LDFLAGS = | |||
| 18 | # variables | 18 | # variables |
| 19 | ZLIB_LIB = zlib.lib | 19 | ZLIB_LIB = zlib.lib |
| 20 | 20 | ||
| 21 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 21 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 22 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.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+gzio.obj+infback.obj | 23 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj |
| 24 | OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj | 24 | OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | # targets | 27 | # targets |
| @@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 38 | 38 | ||
| 39 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 39 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 40 | 40 | ||
| 41 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 42 | |||
| 41 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 43 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 42 | 44 | ||
| 45 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 46 | |||
| 47 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 48 | |||
| 49 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 50 | |||
| 43 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 51 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 44 | inffast.h inffixed.h | 52 | inffast.h inffixed.h |
| 45 | 53 | ||
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index 18353cb..9b0f46c 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define MAXBITS 15 | 9 | #define MAXBITS 15 |
| 10 | 10 | ||
| 11 | const char inflate9_copyright[] = | 11 | const char inflate9_copyright[] = |
| 12 | " inflate9 1.2.3.4 Copyright 1995-2008 Mark Adler "; | 12 | " inflate9 1.2.3.5 Copyright 1995-2009 Mark Adler "; |
| 13 | /* | 13 | /* |
| 14 | If you use the zlib library in a product, an acknowledgment is welcome | 14 | If you use the zlib library in a product, an acknowledgment is welcome |
| 15 | in the documentation of your product. If for some reason you cannot | 15 | in the documentation of your product. If for some reason you cannot |
| @@ -64,7 +64,7 @@ unsigned short FAR *work; | |||
| 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
| 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, | 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, |
| 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, | 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, |
| 67 | 133, 133, 133, 133, 144, 72, 200}; | 67 | 133, 133, 133, 133, 144, 69, 199}; |
| 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ | 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ |
| 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, | 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, |
| 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, | 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, |
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip deleted file mode 100644 index 50ca6a9..0000000 --- a/contrib/minizip/ChangeLogUnzip +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | Change in 1.01e (12 feb 05) | ||
| 2 | - Fix in zipOpen2 for globalcomment (Rolf Kalbermatter) | ||
| 3 | - Fix possible memory leak in unzip.c (Zoran Stevanovic) | ||
| 4 | |||
| 5 | Change in 1.01b (20 may 04) | ||
| 6 | - Integrate patch from Debian package (submited by Mark Brown) | ||
| 7 | - Add tools mztools from Xavier Roche | ||
| 8 | |||
| 9 | Change in 1.01 (8 may 04) | ||
| 10 | - fix buffer overrun risk in unzip.c (Xavier Roche) | ||
| 11 | - fix a minor buffer insecurity in minizip.c (Mike Whittaker) | ||
| 12 | |||
| 13 | Change in 1.00: (10 sept 03) | ||
| 14 | - rename to 1.00 | ||
| 15 | - cosmetic code change | ||
| 16 | |||
| 17 | Change in 0.22: (19 May 03) | ||
| 18 | - crypting support (unless you define NOCRYPT) | ||
| 19 | - append file in existing zipfile | ||
| 20 | |||
| 21 | Change in 0.21: (10 Mar 03) | ||
| 22 | - bug fixes | ||
| 23 | |||
| 24 | Change in 0.17: (27 Jan 02) | ||
| 25 | - bug fixes | ||
| 26 | |||
| 27 | Change in 0.16: (19 Jan 02) | ||
| 28 | - Support of ioapi for virtualize zip file access | ||
| 29 | |||
| 30 | Change in 0.15: (19 Mar 98) | ||
| 31 | - fix memory leak in minizip.c | ||
| 32 | |||
| 33 | Change in 0.14: (10 Mar 98) | ||
| 34 | - fix bugs in minizip.c sample for zipping big file | ||
| 35 | - fix problem in month in date handling | ||
| 36 | - fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for | ||
| 37 | comment handling | ||
| 38 | |||
| 39 | Change in 0.13: (6 Mar 98) | ||
| 40 | - fix bugs in zip.c | ||
| 41 | - add real minizip sample | ||
| 42 | |||
| 43 | Change in 0.12: (4 Mar 98) | ||
| 44 | - add zip.c and zip.h for creates .zip file | ||
| 45 | - fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) | ||
| 46 | - fix miniunz.c for file without specific record for directory | ||
| 47 | |||
| 48 | Change in 0.11: (3 Mar 98) | ||
| 49 | - fix bug in unzGetCurrentFileInfo for get extra field and comment | ||
| 50 | - enhance miniunz sample, remove the bad unztst.c sample | ||
| 51 | |||
| 52 | Change in 0.10: (2 Mar 98) | ||
| 53 | - fix bug in unzReadCurrentFile | ||
| 54 | - rename unzip* to unz* function and structure | ||
| 55 | - remove Windows-like hungary notation variable name | ||
| 56 | - modify some structure in unzip.h | ||
| 57 | - add somes comment in source | ||
| 58 | - remove unzipGetcCurrentFile function | ||
| 59 | - replace ZUNZEXPORT by ZEXPORT | ||
| 60 | - add unzGetLocalExtrafield for get the local extrafield info | ||
| 61 | - add a new sample, miniunz.c | ||
| 62 | |||
| 63 | Change in 0.4: (25 Feb 98) | ||
| 64 | - suppress the type unzipFileInZip. | ||
| 65 | Only on file in the zipfile can be open at the same time | ||
| 66 | - fix somes typo in code | ||
| 67 | - added tm_unz structure in unzip_file_info (date/time in readable format) | ||
diff --git a/contrib/minizip/Makefile b/contrib/minizip/Makefile index 84eaad2..fbba3ac 100644 --- a/contrib/minizip/Makefile +++ b/contrib/minizip/Makefile | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | CC=cc | 1 | CC=cc |
| 2 | CFLAGS=-O -I../.. | 2 | CFLAGS=-O -I../.. |
| 3 | 3 | ||
| 4 | UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a | 4 | UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a |
| 5 | ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a | 5 | ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a |
| 6 | 6 | ||
| 7 | .c.o: | 7 | .c.o: |
| 8 | $(CC) -c $(CFLAGS) $*.c | 8 | $(CC) -c $(CFLAGS) $*.c |
| 9 | 9 | ||
| 10 | all: miniunz minizip | 10 | all: miniunz minizip |
| 11 | 11 | ||
| 12 | miniunz: $(UNZ_OBJS) | 12 | miniunz: $(UNZ_OBJS) |
| 13 | $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) | 13 | $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) |
| 14 | 14 | ||
| 15 | minizip: $(ZIP_OBJS) | 15 | minizip: $(ZIP_OBJS) |
| 16 | $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) | 16 | $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) |
| 17 | 17 | ||
| 18 | test: miniunz minizip | 18 | test: miniunz minizip |
| 19 | ./minizip test readme.txt | 19 | ./minizip test readme.txt |
| 20 | ./miniunz -l test.zip | 20 | ./miniunz -l test.zip |
| 21 | mv readme.txt readme.old | 21 | mv readme.txt readme.old |
| 22 | ./miniunz test.zip | 22 | ./miniunz test.zip |
| 23 | 23 | ||
| 24 | clean: | 24 | clean: |
| 25 | /bin/rm -f *.o *~ minizip miniunz | 25 | /bin/rm -f *.o *~ minizip miniunz |
diff --git a/contrib/minizip/MiniZip64_Changes.txt b/contrib/minizip/MiniZip64_Changes.txt new file mode 100644 index 0000000..9d370df --- /dev/null +++ b/contrib/minizip/MiniZip64_Changes.txt | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | |||
| 2 | MiniZip64 was derrived from MiniZip at version 1.01f | ||
| 3 | |||
| 4 | Change in 1.0 (Okt 2009) | ||
| 5 | - **TODO - Add history** | ||
| 6 | |||
| 7 | \ No newline at end of file | ||
diff --git a/contrib/minizip/MiniZip64_info.txt b/contrib/minizip/MiniZip64_info.txt new file mode 100644 index 0000000..f4eef25 --- /dev/null +++ b/contrib/minizip/MiniZip64_info.txt | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | MiniZip64 - Copyright (c) 2009-2010 - Mathias Svensson - Built from MiniZip by Gilles Vollant | ||
| 2 | |||
| 3 | Introduction | ||
| 4 | --------------------- | ||
| 5 | MiniZip64 is built from MiniZip by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 6 | |||
| 7 | When adding ZIP64 support into minizip it would result into breaking compatibility with current minizip. | ||
| 8 | And since breaking compatibility in minizip is not wanted. I decided to create a fork of minizip | ||
| 9 | and create minizip64. | ||
| 10 | |||
| 11 | Even though MiniZip64 is build from MiniZip, all functions and struct's have changed name so that it | ||
| 12 | would not collide with each other. | ||
| 13 | |||
| 14 | |||
| 15 | Background | ||
| 16 | --------------------- | ||
| 17 | When adding ZIP64 support I found that Even Rouault have added ZIP64 support for unzip.c into minizip | ||
| 18 | for a open source project called gdal ( http://www.gdal.org/ ) | ||
| 19 | |||
| 20 | That was used as a starting point. And after that ZIP64 support was added to zip.c | ||
| 21 | some refactoring and code cleanup was also done. | ||
| 22 | |||
| 23 | |||
| 24 | Changed from MiniZip to MiniZip64 | ||
| 25 | ------------------------------------- | ||
| 26 | * Filenames has got a '64' at the end of them . eg unzip.c is now called unzip64.c | ||
| 27 | * Added ZIP64 support for unzip ( by Even Rouault ) | ||
| 28 | * Added ZIP64 support for zip ( by Mathias Svensson ) | ||
| 29 | * Reverted some changed that Even Rouault did. | ||
| 30 | * Bunch of patches received from Gulles Vollant that he received for MiniZip from various users. | ||
| 31 | * Added unzip patch for BZIP Compression method (patch create by Daniel Borca) | ||
| 32 | * Added BZIP Compress method for zip | ||
| 33 | * Did some refactoring and code cleanup | ||
| 34 | |||
| 35 | |||
| 36 | Credits | ||
| 37 | |||
| 38 | Gilles Vollant - Original MiniZip author | ||
| 39 | Even Rouault - ZIP64 unzip Support | ||
| 40 | Daniel Borca - BZip Compression method support in unzip | ||
| 41 | Mathias Svensson - ZIP64 zip support | ||
| 42 | Mathias Svensson - BZip Compression method support in zip | ||
| 43 | |||
| 44 | Resources | ||
| 45 | |||
| 46 | ZipLayout http://result42.com/projects/ZipFileLayout | ||
| 47 | Command line tool for Windows that shows the layout and information of the headers in a zip archive. | ||
| 48 | Used when debugging and validating the creation of zip files using MiniZip64 | ||
| 49 | |||
| 50 | |||
| 51 | ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT | ||
| 52 | Zip File specification | ||
| 53 | |||
| 54 | |||
| 55 | Notes. | ||
| 56 | * 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. | ||
| 57 | |||
| 58 | License | ||
| 59 | ---------------------------------------------------------- | ||
| 60 | Condition of use and distribution are the same than zlib : | ||
| 61 | |||
| 62 | This software is provided 'as-is', without any express or implied | ||
| 63 | warranty. In no event will the authors be held liable for any damages | ||
| 64 | arising from the use of this software. | ||
| 65 | |||
| 66 | Permission is granted to anyone to use this software for any purpose, | ||
| 67 | including commercial applications, and to alter it and redistribute it | ||
| 68 | freely, subject to the following restrictions: | ||
| 69 | |||
| 70 | 1. The origin of this software must not be misrepresented; you must not | ||
| 71 | claim that you wrote the original software. If you use this software | ||
| 72 | in a product, an acknowledgment in the product documentation would be | ||
| 73 | appreciated but is not required. | ||
| 74 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 75 | misrepresented as being the original software. | ||
| 76 | 3. This notice may not be removed or altered from any source distribution. | ||
| 77 | |||
| 78 | ---------------------------------------------------------- | ||
| 79 | |||
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h index 622f4bc..679e2a1 100644 --- a/contrib/minizip/crypt.h +++ b/contrib/minizip/crypt.h | |||
| @@ -87,13 +87,12 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon | |||
| 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ | 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ |
| 88 | # endif | 88 | # endif |
| 89 | 89 | ||
| 90 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) | 90 | static int crypthead(const char* passwd, /* password string */ |
| 91 | const char *passwd; /* password string */ | 91 | unsigned char* buf, /* where to write header */ |
| 92 | unsigned char *buf; /* where to write header */ | 92 | int bufSize, |
| 93 | int bufSize; | 93 | unsigned long* pkeys, |
| 94 | unsigned long* pkeys; | 94 | const unsigned long* pcrc_32_tab, |
| 95 | const unsigned long* pcrc_32_tab; | 95 | unsigned long crcForCrypting) |
| 96 | unsigned long crcForCrypting; | ||
| 97 | { | 96 | { |
| 98 | int n; /* index in random header */ | 97 | int n; /* index in random header */ |
| 99 | int t; /* temporary */ | 98 | int t; /* temporary */ |
| @@ -124,8 +123,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) | |||
| 124 | { | 123 | { |
| 125 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); | 124 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); |
| 126 | } | 125 | } |
| 127 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); | 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); |
| 128 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); | 127 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); |
| 129 | return n; | 128 | return n; |
| 130 | } | 129 | } |
| 131 | 130 | ||
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c index f1bee23..36ed0e0 100644 --- a/contrib/minizip/ioapi.c +++ b/contrib/minizip/ioapi.c | |||
| @@ -1,74 +1,104 @@ | |||
| 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip |
| 2 | files using zlib + zip or unzip API | 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) |
| 3 | 3 | ||
| 4 | Version 1.01e, February 12th, 2005 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
| 5 | |||
| 6 | Copyright (C) 1998-2005 Gilles Vollant | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #include "zlib.h" | ||
| 14 | #include "ioapi.h" | ||
| 15 | 5 | ||
| 6 | Modifications for Zip64 support | ||
| 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | ||
| 16 | 8 | ||
| 9 | For more info read MiniZip_info.txt | ||
| 17 | 10 | ||
| 18 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ | 11 | */ |
| 19 | 12 | ||
| 20 | #ifndef SEEK_CUR | 13 | #if (defined(_WIN32)) |
| 21 | #define SEEK_CUR 1 | 14 | #define _CRT_SECURE_NO_WARNINGS |
| 22 | #endif | 15 | #endif |
| 23 | 16 | ||
| 24 | #ifndef SEEK_END | 17 | #include "ioapi.h" |
| 25 | #define SEEK_END 2 | ||
| 26 | #endif | ||
| 27 | 18 | ||
| 28 | #ifndef SEEK_SET | 19 | voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) |
| 29 | #define SEEK_SET 0 | 20 | { |
| 30 | #endif | 21 | if (pfilefunc->zfile_func64.zopen64_file != NULL) |
| 22 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); | ||
| 23 | else | ||
| 24 | { | ||
| 25 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); | ||
| 26 | } | ||
| 27 | } | ||
| 31 | 28 | ||
| 32 | voidpf ZCALLBACK fopen_file_func OF(( | 29 | long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) |
| 33 | voidpf opaque, | 30 | { |
| 34 | const char* filename, | 31 | if (pfilefunc->zfile_func64.zseek64_file != NULL) |
| 35 | int mode)); | 32 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); |
| 33 | else | ||
| 34 | { | ||
| 35 | uLong offsetTruncated = (uLong)offset; | ||
| 36 | if (offsetTruncated != offset) | ||
| 37 | return -1; | ||
| 38 | else | ||
| 39 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); | ||
| 40 | } | ||
| 41 | } | ||
| 36 | 42 | ||
| 37 | uLong ZCALLBACK fread_file_func OF(( | 43 | ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) |
| 38 | voidpf opaque, | 44 | { |
| 39 | voidpf stream, | 45 | if (pfilefunc->zfile_func64.zseek64_file != NULL) |
| 40 | void* buf, | 46 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); |
| 41 | uLong size)); | 47 | else |
| 48 | { | ||
| 49 | uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); | ||
| 50 | if ((tell_uLong) == ((uLong)-1)) | ||
| 51 | return (ZPOS64_T)-1; | ||
| 52 | else | ||
| 53 | return tell_uLong; | ||
| 54 | } | ||
| 55 | } | ||
| 42 | 56 | ||
| 43 | uLong ZCALLBACK fwrite_file_func OF(( | 57 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) |
| 44 | voidpf opaque, | 58 | { |
| 45 | voidpf stream, | 59 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; |
| 46 | const void* buf, | 60 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; |
| 47 | uLong size)); | 61 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; |
| 62 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; | ||
| 63 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; | ||
| 64 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; | ||
| 65 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; | ||
| 66 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; | ||
| 67 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; | ||
| 68 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; | ||
| 69 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; | ||
| 70 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; | ||
| 71 | } | ||
| 48 | 72 | ||
| 49 | long ZCALLBACK ftell_file_func OF(( | ||
| 50 | voidpf opaque, | ||
| 51 | voidpf stream)); | ||
| 52 | 73 | ||
| 53 | long ZCALLBACK fseek_file_func OF(( | ||
| 54 | voidpf opaque, | ||
| 55 | voidpf stream, | ||
| 56 | uLong offset, | ||
| 57 | int origin)); | ||
| 58 | 74 | ||
| 59 | int ZCALLBACK fclose_file_func OF(( | 75 | static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); |
| 60 | voidpf opaque, | 76 | static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); |
| 61 | voidpf stream)); | 77 | static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); |
| 78 | static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); | ||
| 79 | static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | ||
| 80 | static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); | ||
| 81 | static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); | ||
| 62 | 82 | ||
| 63 | int ZCALLBACK ferror_file_func OF(( | 83 | static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) |
| 64 | voidpf opaque, | 84 | { |
| 65 | voidpf stream)); | 85 | FILE* file = NULL; |
| 86 | const char* mode_fopen = NULL; | ||
| 87 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | ||
| 88 | mode_fopen = "rb"; | ||
| 89 | else | ||
| 90 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | ||
| 91 | mode_fopen = "r+b"; | ||
| 92 | else | ||
| 93 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) | ||
| 94 | mode_fopen = "wb"; | ||
| 66 | 95 | ||
| 96 | if ((filename!=NULL) && (mode_fopen != NULL)) | ||
| 97 | file = fopen(filename, mode_fopen); | ||
| 98 | return file; | ||
| 99 | } | ||
| 67 | 100 | ||
| 68 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) | 101 | static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) |
| 69 | voidpf opaque; | ||
| 70 | const char* filename; | ||
| 71 | int mode; | ||
| 72 | { | 102 | { |
| 73 | FILE* file = NULL; | 103 | FILE* file = NULL; |
| 74 | const char* mode_fopen = NULL; | 104 | const char* mode_fopen = NULL; |
| @@ -82,48 +112,41 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) | |||
| 82 | mode_fopen = "wb"; | 112 | mode_fopen = "wb"; |
| 83 | 113 | ||
| 84 | if ((filename!=NULL) && (mode_fopen != NULL)) | 114 | if ((filename!=NULL) && (mode_fopen != NULL)) |
| 85 | file = fopen(filename, mode_fopen); | 115 | file = fopen64((const char*)filename, mode_fopen); |
| 86 | return file; | 116 | return file; |
| 87 | } | 117 | } |
| 88 | 118 | ||
| 89 | 119 | ||
| 90 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) | 120 | static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) |
| 91 | voidpf opaque; | ||
| 92 | voidpf stream; | ||
| 93 | void* buf; | ||
| 94 | uLong size; | ||
| 95 | { | 121 | { |
| 96 | uLong ret; | 122 | uLong ret; |
| 97 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | 123 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); |
| 98 | return ret; | 124 | return ret; |
| 99 | } | 125 | } |
| 100 | 126 | ||
| 101 | 127 | static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) | |
| 102 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) | ||
| 103 | voidpf opaque; | ||
| 104 | voidpf stream; | ||
| 105 | const void* buf; | ||
| 106 | uLong size; | ||
| 107 | { | 128 | { |
| 108 | uLong ret; | 129 | uLong ret; |
| 109 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | 130 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); |
| 110 | return ret; | 131 | return ret; |
| 111 | } | 132 | } |
| 112 | 133 | ||
| 113 | long ZCALLBACK ftell_file_func (opaque, stream) | 134 | static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) |
| 114 | voidpf opaque; | ||
| 115 | voidpf stream; | ||
| 116 | { | 135 | { |
| 117 | long ret; | 136 | long ret; |
| 118 | ret = ftell((FILE *)stream); | 137 | ret = ftell((FILE *)stream); |
| 119 | return ret; | 138 | return ret; |
| 120 | } | 139 | } |
| 121 | 140 | ||
| 122 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) | 141 | |
| 123 | voidpf opaque; | 142 | static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) |
| 124 | voidpf stream; | 143 | { |
| 125 | uLong offset; | 144 | ZPOS64_T ret; |
| 126 | int origin; | 145 | ret = ftello64((FILE *)stream); |
| 146 | return ret; | ||
| 147 | } | ||
| 148 | |||
| 149 | static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) | ||
| 127 | { | 150 | { |
| 128 | int fseek_origin=0; | 151 | int fseek_origin=0; |
| 129 | long ret; | 152 | long ret; |
| @@ -141,22 +164,45 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) | |||
| 141 | default: return -1; | 164 | default: return -1; |
| 142 | } | 165 | } |
| 143 | ret = 0; | 166 | ret = 0; |
| 144 | fseek((FILE *)stream, offset, fseek_origin); | 167 | if (fseek((FILE *)stream, offset, fseek_origin) != 0) |
| 168 | ret = -1; | ||
| 145 | return ret; | 169 | return ret; |
| 146 | } | 170 | } |
| 147 | 171 | ||
| 148 | int ZCALLBACK fclose_file_func (opaque, stream) | 172 | static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) |
| 149 | voidpf opaque; | 173 | { |
| 150 | voidpf stream; | 174 | int fseek_origin=0; |
| 175 | long ret; | ||
| 176 | switch (origin) | ||
| 177 | { | ||
| 178 | case ZLIB_FILEFUNC_SEEK_CUR : | ||
| 179 | fseek_origin = SEEK_CUR; | ||
| 180 | break; | ||
| 181 | case ZLIB_FILEFUNC_SEEK_END : | ||
| 182 | fseek_origin = SEEK_END; | ||
| 183 | break; | ||
| 184 | case ZLIB_FILEFUNC_SEEK_SET : | ||
| 185 | fseek_origin = SEEK_SET; | ||
| 186 | break; | ||
| 187 | default: return -1; | ||
| 188 | } | ||
| 189 | ret = 0; | ||
| 190 | |||
| 191 | if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) | ||
| 192 | ret = -1; | ||
| 193 | |||
| 194 | return ret; | ||
| 195 | } | ||
| 196 | |||
| 197 | |||
| 198 | static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) | ||
| 151 | { | 199 | { |
| 152 | int ret; | 200 | int ret; |
| 153 | ret = fclose((FILE *)stream); | 201 | ret = fclose((FILE *)stream); |
| 154 | return ret; | 202 | return ret; |
| 155 | } | 203 | } |
| 156 | 204 | ||
| 157 | int ZCALLBACK ferror_file_func (opaque, stream) | 205 | static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) |
| 158 | voidpf opaque; | ||
| 159 | voidpf stream; | ||
| 160 | { | 206 | { |
| 161 | int ret; | 207 | int ret; |
| 162 | ret = ferror((FILE *)stream); | 208 | ret = ferror((FILE *)stream); |
| @@ -175,3 +221,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def) | |||
| 175 | pzlib_filefunc_def->zerror_file = ferror_file_func; | 221 | pzlib_filefunc_def->zerror_file = ferror_file_func; |
| 176 | pzlib_filefunc_def->opaque = NULL; | 222 | pzlib_filefunc_def->opaque = NULL; |
| 177 | } | 223 | } |
| 224 | |||
| 225 | void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) | ||
| 226 | { | ||
| 227 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; | ||
| 228 | pzlib_filefunc_def->zread_file = fread_file_func; | ||
| 229 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; | ||
| 230 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; | ||
| 231 | pzlib_filefunc_def->zseek64_file = fseek64_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 | } | ||
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h index 7d457ba..f443d82 100644 --- a/contrib/minizip/ioapi.h +++ b/contrib/minizip/ioapi.h | |||
| @@ -1,13 +1,98 @@ | |||
| 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip |
| 2 | files using zlib + zip or unzip API | 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) |
| 3 | 3 | ||
| 4 | Version 1.01e, February 12th, 2005 | 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) | ||
| 5 | 18 | ||
| 6 | Copyright (C) 1998-2005 Gilles Vollant | ||
| 7 | */ | 19 | */ |
| 8 | 20 | ||
| 9 | #ifndef _ZLIBIOAPI_H | 21 | #ifndef _ZLIBIOAPI64_H |
| 10 | #define _ZLIBIOAPI_H | 22 | #define _ZLIBIOAPI64_H |
| 23 | |||
| 24 | #ifndef _WIN32 | ||
| 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 | #endif | ||
| 42 | |||
| 43 | #include <stdio.h> | ||
| 44 | #include <stdlib.h> | ||
| 45 | #include "zlib.h" | ||
| 46 | |||
| 47 | #ifdef _MSC_VER | ||
| 48 | #define fopen64 fopen | ||
| 49 | #if _MSC_VER >= 1400 | ||
| 50 | #define ftello64 _ftelli64 | ||
| 51 | #define fseeko64 _fseeki64 | ||
| 52 | #else // old MSC | ||
| 53 | #define ftello64 ftell | ||
| 54 | #define fseeko64 fseek | ||
| 55 | #endif | ||
| 56 | #endif | ||
| 57 | |||
| 58 | /* | ||
| 59 | #ifndef ZPOS64_T | ||
| 60 | #ifdef _WIN32 | ||
| 61 | #define ZPOS64_T fpos_t | ||
| 62 | #else | ||
| 63 | #include <stdint.h> | ||
| 64 | #define ZPOS64_T uint64_t | ||
| 65 | #endif | ||
| 66 | #endif | ||
| 67 | */ | ||
| 68 | |||
| 69 | #ifdef HAVE_MINIZIP64_CONF_H | ||
| 70 | #include "mz64conf.h" | ||
| 71 | #endif | ||
| 72 | |||
| 73 | /* a type choosen by DEFINE */ | ||
| 74 | #ifdef HAVE_64BIT_INT_CUSTOM | ||
| 75 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; | ||
| 76 | #else | ||
| 77 | #ifdef HAS_STDINT_H | ||
| 78 | #include "stdint.h" | ||
| 79 | typedef uint64_t ZPOS64_T; | ||
| 80 | #else | ||
| 81 | |||
| 82 | |||
| 83 | #if defined(_MSC_VER) || defined(__BORLANDC__) | ||
| 84 | typedef unsigned __int64 ZPOS64_T; | ||
| 85 | #else | ||
| 86 | typedef unsigned long long int ZPOS64_T; | ||
| 87 | #endif | ||
| 88 | #endif | ||
| 89 | #endif | ||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | #ifdef __cplusplus | ||
| 94 | extern "C" { | ||
| 95 | #endif | ||
| 11 | 96 | ||
| 12 | 97 | ||
| 13 | #define ZLIB_FILEFUNC_SEEK_CUR (1) | 98 | #define ZLIB_FILEFUNC_SEEK_CUR (1) |
| @@ -23,26 +108,27 @@ | |||
| 23 | 108 | ||
| 24 | 109 | ||
| 25 | #ifndef ZCALLBACK | 110 | #ifndef ZCALLBACK |
| 26 | 111 | #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) | |
| 27 | #if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) | 112 | #define ZCALLBACK CALLBACK |
| 28 | #define ZCALLBACK CALLBACK | 113 | #else |
| 29 | #else | 114 | #define ZCALLBACK |
| 30 | #define ZCALLBACK | 115 | #endif |
| 31 | #endif | ||
| 32 | #endif | 116 | #endif |
| 33 | 117 | ||
| 34 | #ifdef __cplusplus | ||
| 35 | extern "C" { | ||
| 36 | #endif | ||
| 37 | 118 | ||
| 38 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); | ||
| 39 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | ||
| 40 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); | ||
| 41 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 42 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); | ||
| 43 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 44 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 45 | 119 | ||
| 120 | |||
| 121 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); | ||
| 122 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | ||
| 123 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); | ||
| 124 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 125 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 126 | |||
| 127 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 128 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); | ||
| 129 | |||
| 130 | |||
| 131 | /* here is the "old" 32 bits structure structure */ | ||
| 46 | typedef struct zlib_filefunc_def_s | 132 | typedef struct zlib_filefunc_def_s |
| 47 | { | 133 | { |
| 48 | open_file_func zopen_file; | 134 | open_file_func zopen_file; |
| @@ -55,21 +141,54 @@ typedef struct zlib_filefunc_def_s | |||
| 55 | voidpf opaque; | 141 | voidpf opaque; |
| 56 | } zlib_filefunc_def; | 142 | } zlib_filefunc_def; |
| 57 | 143 | ||
| 144 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); | ||
| 145 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | ||
| 146 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); | ||
| 58 | 147 | ||
| 148 | typedef struct zlib_filefunc64_def_s | ||
| 149 | { | ||
| 150 | open64_file_func zopen64_file; | ||
| 151 | read_file_func zread_file; | ||
| 152 | write_file_func zwrite_file; | ||
| 153 | tell64_file_func ztell64_file; | ||
| 154 | seek64_file_func zseek64_file; | ||
| 155 | close_file_func zclose_file; | ||
| 156 | testerror_file_func zerror_file; | ||
| 157 | voidpf opaque; | ||
| 158 | } zlib_filefunc64_def; | ||
| 59 | 159 | ||
| 160 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); | ||
| 60 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); | 161 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); |
| 61 | 162 | ||
| 62 | #define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) | 163 | /* now internal definition, only for zip.c and unzip.h */ |
| 63 | #define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) | 164 | typedef struct zlib_filefunc64_32_def_s |
| 64 | #define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) | 165 | { |
| 65 | #define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) | 166 | zlib_filefunc64_def zfile_func64; |
| 66 | #define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) | 167 | open_file_func zopen32_file; |
| 67 | #define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) | 168 | tell_file_func ztell32_file; |
| 169 | seek_file_func zseek32_file; | ||
| 170 | } zlib_filefunc64_32_def; | ||
| 171 | |||
| 172 | |||
| 173 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) | ||
| 174 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) | ||
| 175 | //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) | ||
| 176 | //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) | ||
| 177 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) | ||
| 178 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) | ||
| 68 | 179 | ||
| 180 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); | ||
| 181 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); | ||
| 182 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); | ||
| 183 | |||
| 184 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); | ||
| 185 | |||
| 186 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) | ||
| 187 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) | ||
| 188 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) | ||
| 69 | 189 | ||
| 70 | #ifdef __cplusplus | 190 | #ifdef __cplusplus |
| 71 | } | 191 | } |
| 72 | #endif | 192 | #endif |
| 73 | 193 | ||
| 74 | #endif | 194 | #endif |
| 75 | |||
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c index a9b5f78..92b9352 100644 --- a/contrib/minizip/iowin32.c +++ b/contrib/minizip/iowin32.c | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | /* iowin32.c -- IO base function header for compress/uncompress .zip | 1 | /* iowin32.c -- IO base function header for compress/uncompress .zip |
| 2 | files using zlib + zip or unzip API | 2 | Version 1.1, January 7th, 2010 |
| 3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) |
| 4 | 4 | ||
| 5 | Version 1.01e, February 12th, 2005 | 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 | ||
| 6 | 11 | ||
| 7 | Copyright (C) 1998-2005 Gilles Vollant | ||
| 8 | */ | 12 | */ |
| 9 | 13 | ||
| 10 | #include <stdlib.h> | 14 | #include <stdlib.h> |
| @@ -21,40 +25,13 @@ | |||
| 21 | #define INVALID_SET_FILE_POINTER ((DWORD)-1) | 25 | #define INVALID_SET_FILE_POINTER ((DWORD)-1) |
| 22 | #endif | 26 | #endif |
| 23 | 27 | ||
| 24 | voidpf ZCALLBACK win32_open_file_func OF(( | 28 | voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); |
| 25 | voidpf opaque, | 29 | uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); |
| 26 | const char* filename, | 30 | uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); |
| 27 | int mode)); | 31 | ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); |
| 28 | 32 | long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | |
| 29 | uLong ZCALLBACK win32_read_file_func OF(( | 33 | int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); |
| 30 | voidpf opaque, | 34 | int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); |
| 31 | voidpf stream, | ||
| 32 | void* buf, | ||
| 33 | uLong size)); | ||
| 34 | |||
| 35 | uLong ZCALLBACK win32_write_file_func OF(( | ||
| 36 | voidpf opaque, | ||
| 37 | voidpf stream, | ||
| 38 | const void* buf, | ||
| 39 | uLong size)); | ||
| 40 | |||
| 41 | long ZCALLBACK win32_tell_file_func OF(( | ||
| 42 | voidpf opaque, | ||
| 43 | voidpf stream)); | ||
| 44 | |||
| 45 | long ZCALLBACK win32_seek_file_func OF(( | ||
| 46 | voidpf opaque, | ||
| 47 | voidpf stream, | ||
| 48 | uLong offset, | ||
| 49 | int origin)); | ||
| 50 | |||
| 51 | int ZCALLBACK win32_close_file_func OF(( | ||
| 52 | voidpf opaque, | ||
| 53 | voidpf stream)); | ||
| 54 | |||
| 55 | int ZCALLBACK win32_error_file_func OF(( | ||
| 56 | voidpf opaque, | ||
| 57 | voidpf stream)); | ||
| 58 | 35 | ||
| 59 | typedef struct | 36 | typedef struct |
| 60 | { | 37 | { |
| @@ -62,69 +39,121 @@ typedef struct | |||
| 62 | int error; | 39 | int error; |
| 63 | } WIN32FILE_IOWIN; | 40 | } WIN32FILE_IOWIN; |
| 64 | 41 | ||
| 65 | voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) | ||
| 66 | voidpf opaque; | ||
| 67 | const char* filename; | ||
| 68 | int mode; | ||
| 69 | { | ||
| 70 | const char* mode_fopen = NULL; | ||
| 71 | DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; | ||
| 72 | HANDLE hFile = 0; | ||
| 73 | voidpf ret=NULL; | ||
| 74 | 42 | ||
| 75 | dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; | 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; | ||
| 76 | 50 | ||
| 77 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | 51 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
| 78 | { | 52 | { |
| 79 | dwDesiredAccess = GENERIC_READ; | 53 | *lpdwDesiredAccess = GENERIC_READ; |
| 80 | dwCreationDisposition = OPEN_EXISTING; | 54 | *lpdwCreationDisposition = OPEN_EXISTING; |
| 81 | dwShareMode = FILE_SHARE_READ; | 55 | *lpdwShareMode = FILE_SHARE_READ; |
| 82 | } | 56 | } |
| 83 | else | 57 | else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
| 84 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | ||
| 85 | { | 58 | { |
| 86 | dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; | 59 | *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
| 87 | dwCreationDisposition = OPEN_EXISTING; | 60 | *lpdwCreationDisposition = OPEN_EXISTING; |
| 88 | } | 61 | } |
| 89 | else | 62 | else if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
| 90 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) | ||
| 91 | { | 63 | { |
| 92 | dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; | 64 | *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
| 93 | dwCreationDisposition = CREATE_ALWAYS; | 65 | *lpdwCreationDisposition = CREATE_ALWAYS; |
| 94 | } | 66 | } |
| 67 | } | ||
| 95 | 68 | ||
| 96 | if ((filename!=NULL) && (dwDesiredAccess != 0)) | 69 | static voidpf win32_build_iowin(HANDLE hFile) |
| 97 | hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, | 70 | { |
| 98 | dwCreationDisposition, dwFlagsAndAttributes, NULL); | 71 | voidpf ret=NULL; |
| 99 | |||
| 100 | if (hFile == INVALID_HANDLE_VALUE) | ||
| 101 | hFile = NULL; | ||
| 102 | 72 | ||
| 103 | if (hFile != NULL) | 73 | if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) |
| 104 | { | 74 | { |
| 105 | WIN32FILE_IOWIN w32fiow; | 75 | WIN32FILE_IOWIN w32fiow; |
| 106 | w32fiow.hf = hFile; | 76 | w32fiow.hf = hFile; |
| 107 | w32fiow.error = 0; | 77 | w32fiow.error = 0; |
| 108 | ret = malloc(sizeof(WIN32FILE_IOWIN)); | 78 | ret = malloc(sizeof(WIN32FILE_IOWIN)); |
| 79 | |||
| 109 | if (ret==NULL) | 80 | if (ret==NULL) |
| 110 | CloseHandle(hFile); | 81 | CloseHandle(hFile); |
| 111 | else *((WIN32FILE_IOWIN*)ret) = w32fiow; | 82 | else |
| 83 | *((WIN32FILE_IOWIN*)ret) = w32fiow; | ||
| 112 | } | 84 | } |
| 113 | return ret; | 85 | return ret; |
| 114 | } | 86 | } |
| 115 | 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 | |||
| 116 | 102 | ||
| 117 | uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) | 103 | voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) |
| 118 | voidpf opaque; | 104 | { |
| 119 | voidpf stream; | 105 | const char* mode_fopen = NULL; |
| 120 | void* buf; | 106 | DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
| 121 | uLong size; | 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) | ||
| 122 | { | 149 | { |
| 123 | uLong ret=0; | 150 | uLong ret=0; |
| 124 | HANDLE hFile = NULL; | 151 | HANDLE hFile = NULL; |
| 125 | if (stream!=NULL) | 152 | if (stream!=NULL) |
| 126 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; | 153 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
| 154 | |||
| 127 | if (hFile != NULL) | 155 | if (hFile != NULL) |
| 156 | { | ||
| 128 | if (!ReadFile(hFile, buf, size, &ret, NULL)) | 157 | if (!ReadFile(hFile, buf, size, &ret, NULL)) |
| 129 | { | 158 | { |
| 130 | DWORD dwErr = GetLastError(); | 159 | DWORD dwErr = GetLastError(); |
| @@ -132,23 +161,21 @@ uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) | |||
| 132 | dwErr = 0; | 161 | dwErr = 0; |
| 133 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; | 162 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
| 134 | } | 163 | } |
| 164 | } | ||
| 135 | 165 | ||
| 136 | return ret; | 166 | return ret; |
| 137 | } | 167 | } |
| 138 | 168 | ||
| 139 | 169 | ||
| 140 | uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) | 170 | uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) |
| 141 | voidpf opaque; | ||
| 142 | voidpf stream; | ||
| 143 | const void* buf; | ||
| 144 | uLong size; | ||
| 145 | { | 171 | { |
| 146 | uLong ret=0; | 172 | uLong ret=0; |
| 147 | HANDLE hFile = NULL; | 173 | HANDLE hFile = NULL; |
| 148 | if (stream!=NULL) | 174 | if (stream!=NULL) |
| 149 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; | 175 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
| 150 | 176 | ||
| 151 | if (hFile !=NULL) | 177 | if (hFile != NULL) |
| 178 | { | ||
| 152 | if (!WriteFile(hFile, buf, size, &ret, NULL)) | 179 | if (!WriteFile(hFile, buf, size, &ret, NULL)) |
| 153 | { | 180 | { |
| 154 | DWORD dwErr = GetLastError(); | 181 | DWORD dwErr = GetLastError(); |
| @@ -156,13 +183,12 @@ uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) | |||
| 156 | dwErr = 0; | 183 | dwErr = 0; |
| 157 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; | 184 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
| 158 | } | 185 | } |
| 186 | } | ||
| 159 | 187 | ||
| 160 | return ret; | 188 | return ret; |
| 161 | } | 189 | } |
| 162 | 190 | ||
| 163 | long ZCALLBACK win32_tell_file_func (opaque, stream) | 191 | long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) |
| 164 | voidpf opaque; | ||
| 165 | voidpf stream; | ||
| 166 | { | 192 | { |
| 167 | long ret=-1; | 193 | long ret=-1; |
| 168 | HANDLE hFile = NULL; | 194 | HANDLE hFile = NULL; |
| @@ -183,11 +209,32 @@ long ZCALLBACK win32_tell_file_func (opaque, stream) | |||
| 183 | return ret; | 209 | return ret; |
| 184 | } | 210 | } |
| 185 | 211 | ||
| 186 | long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) | 212 | ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) |
| 187 | voidpf opaque; | 213 | { |
| 188 | voidpf stream; | 214 | ZPOS64_T ret= (ZPOS64_T)-1; |
| 189 | uLong offset; | 215 | HANDLE hFile = NULL; |
| 190 | int origin; | 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) | ||
| 191 | { | 238 | { |
| 192 | DWORD dwMoveMethod=0xFFFFFFFF; | 239 | DWORD dwMoveMethod=0xFFFFFFFF; |
| 193 | HANDLE hFile = NULL; | 240 | HANDLE hFile = NULL; |
| @@ -224,9 +271,46 @@ long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) | |||
| 224 | return ret; | 271 | return ret; |
| 225 | } | 272 | } |
| 226 | 273 | ||
| 227 | int ZCALLBACK win32_close_file_func (opaque, stream) | 274 | long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) |
| 228 | voidpf opaque; | 275 | { |
| 229 | voidpf stream; | 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) | ||
| 230 | { | 314 | { |
| 231 | int ret=-1; | 315 | int ret=-1; |
| 232 | 316 | ||
| @@ -244,9 +328,7 @@ int ZCALLBACK win32_close_file_func (opaque, stream) | |||
| 244 | return ret; | 328 | return ret; |
| 245 | } | 329 | } |
| 246 | 330 | ||
| 247 | int ZCALLBACK win32_error_file_func (opaque, stream) | 331 | int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) |
| 248 | voidpf opaque; | ||
| 249 | voidpf stream; | ||
| 250 | { | 332 | { |
| 251 | int ret=-1; | 333 | int ret=-1; |
| 252 | if (stream!=NULL) | 334 | if (stream!=NULL) |
| @@ -256,8 +338,7 @@ int ZCALLBACK win32_error_file_func (opaque, stream) | |||
| 256 | return ret; | 338 | return ret; |
| 257 | } | 339 | } |
| 258 | 340 | ||
| 259 | void fill_win32_filefunc (pzlib_filefunc_def) | 341 | void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) |
| 260 | zlib_filefunc_def* pzlib_filefunc_def; | ||
| 261 | { | 342 | { |
| 262 | pzlib_filefunc_def->zopen_file = win32_open_file_func; | 343 | pzlib_filefunc_def->zopen_file = win32_open_file_func; |
| 263 | pzlib_filefunc_def->zread_file = win32_read_file_func; | 344 | pzlib_filefunc_def->zread_file = win32_read_file_func; |
| @@ -266,5 +347,43 @@ void fill_win32_filefunc (pzlib_filefunc_def) | |||
| 266 | pzlib_filefunc_def->zseek_file = win32_seek_file_func; | 347 | pzlib_filefunc_def->zseek_file = win32_seek_file_func; |
| 267 | pzlib_filefunc_def->zclose_file = win32_close_file_func; | 348 | pzlib_filefunc_def->zclose_file = win32_close_file_func; |
| 268 | pzlib_filefunc_def->zerror_file = win32_error_file_func; | 349 | pzlib_filefunc_def->zerror_file = win32_error_file_func; |
| 269 | pzlib_filefunc_def->opaque=NULL; | 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; | ||
| 270 | } | 389 | } |
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h index a3a437a..cc77ec4 100644 --- a/contrib/minizip/iowin32.h +++ b/contrib/minizip/iowin32.h | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | /* iowin32.h -- IO base function header for compress/uncompress .zip | 1 | /* iowin32.h -- IO base function header for compress/uncompress .zip |
| 2 | files using zlib + zip or unzip API | 2 | Version 1.1, January 7th, 2010 |
| 3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) |
| 4 | 4 | ||
| 5 | Version 1.01e, February 12th, 2005 | 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 | ||
| 6 | 11 | ||
| 7 | Copyright (C) 1998-2005 Gilles Vollant | ||
| 8 | */ | 12 | */ |
| 9 | 13 | ||
| 10 | #include <windows.h> | 14 | #include <windows.h> |
| @@ -15,6 +19,9 @@ extern "C" { | |||
| 15 | #endif | 19 | #endif |
| 16 | 20 | ||
| 17 | void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); | 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)); | ||
| 18 | 25 | ||
| 19 | #ifdef __cplusplus | 26 | #ifdef __cplusplus |
| 20 | } | 27 | } |
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index f599938..c0a07ab 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c | |||
| @@ -1,10 +1,31 @@ | |||
| 1 | /* | 1 | /* |
| 2 | miniunz.c | 2 | miniunz.c |
| 3 | Version 1.01e, February 12th, 2005 | 3 | Version 1.1, January 7th, 2010 |
| 4 | sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 4 | 5 | ||
| 5 | Copyright (C) 1998-2005 Gilles Vollant | 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 ) | ||
| 6 | */ | 13 | */ |
| 7 | 14 | ||
| 15 | #ifndef _WIN32 | ||
| 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 | ||
| 8 | 29 | ||
| 9 | #include <stdio.h> | 30 | #include <stdio.h> |
| 10 | #include <stdlib.h> | 31 | #include <stdlib.h> |
| @@ -27,7 +48,7 @@ | |||
| 27 | #define WRITEBUFFERSIZE (8192) | 48 | #define WRITEBUFFERSIZE (8192) |
| 28 | #define MAXFILENAME (256) | 49 | #define MAXFILENAME (256) |
| 29 | 50 | ||
| 30 | #ifdef WIN32 | 51 | #ifdef _WIN32 |
| 31 | #define USEWIN32IOAPI | 52 | #define USEWIN32IOAPI |
| 32 | #include "iowin32.h" | 53 | #include "iowin32.h" |
| 33 | #endif | 54 | #endif |
| @@ -51,11 +72,11 @@ void change_file_date(filename,dosdate,tmu_date) | |||
| 51 | uLong dosdate; | 72 | uLong dosdate; |
| 52 | tm_unz tmu_date; | 73 | tm_unz tmu_date; |
| 53 | { | 74 | { |
| 54 | #ifdef WIN32 | 75 | #ifdef _WIN32 |
| 55 | HANDLE hFile; | 76 | HANDLE hFile; |
| 56 | FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; | 77 | FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; |
| 57 | 78 | ||
| 58 | hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, | 79 | hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, |
| 59 | 0,NULL,OPEN_EXISTING,0,NULL); | 80 | 0,NULL,OPEN_EXISTING,0,NULL); |
| 60 | GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); | 81 | GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); |
| 61 | DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); | 82 | DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); |
| @@ -91,8 +112,8 @@ int mymkdir(dirname) | |||
| 91 | const char* dirname; | 112 | const char* dirname; |
| 92 | { | 113 | { |
| 93 | int ret=0; | 114 | int ret=0; |
| 94 | #ifdef WIN32 | 115 | #ifdef _WIN32 |
| 95 | ret = mkdir(dirname); | 116 | ret = _mkdir(dirname); |
| 96 | #else | 117 | #else |
| 97 | #ifdef unix | 118 | #ifdef unix |
| 98 | ret = mkdir (dirname,0775); | 119 | ret = mkdir (dirname,0775); |
| @@ -112,6 +133,11 @@ int makedir (newdir) | |||
| 112 | return 0; | 133 | return 0; |
| 113 | 134 | ||
| 114 | buffer = (char*)malloc(len+1); | 135 | buffer = (char*)malloc(len+1); |
| 136 | if (buffer==NULL) | ||
| 137 | { | ||
| 138 | printf("Error allocating memory\n"); | ||
| 139 | return UNZ_INTERNALERROR; | ||
| 140 | } | ||
| 115 | strcpy(buffer,newdir); | 141 | strcpy(buffer,newdir); |
| 116 | 142 | ||
| 117 | if (buffer[len-1] == '/') { | 143 | if (buffer[len-1] == '/') { |
| @@ -164,34 +190,61 @@ void do_help() | |||
| 164 | " -p extract crypted file using password\n\n"); | 190 | " -p extract crypted file using password\n\n"); |
| 165 | } | 191 | } |
| 166 | 192 | ||
| 193 | void Display64BitsSize(ZPOS64_T n, int size_char) | ||
| 194 | { | ||
| 195 | /* to avoid compatibility problem , we do here the conversion */ | ||
| 196 | char number[21]; | ||
| 197 | int offset=19; | ||
| 198 | int pos_string = 19; | ||
| 199 | number[20]=0; | ||
| 200 | for (;;) { | ||
| 201 | number[offset]=(char)((n%10)+'0'); | ||
| 202 | if (number[offset] != '0') | ||
| 203 | pos_string=offset; | ||
| 204 | n/=10; | ||
| 205 | if (offset==0) | ||
| 206 | break; | ||
| 207 | offset--; | ||
| 208 | } | ||
| 209 | { | ||
| 210 | int size_display_string = 19-pos_string; | ||
| 211 | while (size_char > size_display_string) | ||
| 212 | { | ||
| 213 | size_char--; | ||
| 214 | printf(" "); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | printf("%s",&number[pos_string]); | ||
| 219 | } | ||
| 167 | 220 | ||
| 168 | int do_list(uf) | 221 | int do_list(uf) |
| 169 | unzFile uf; | 222 | unzFile uf; |
| 170 | { | 223 | { |
| 171 | uLong i; | 224 | uLong i; |
| 172 | unz_global_info gi; | 225 | unz_global_info64 gi; |
| 173 | int err; | 226 | int err; |
| 174 | 227 | ||
| 175 | err = unzGetGlobalInfo (uf,&gi); | 228 | err = unzGetGlobalInfo64(uf,&gi); |
| 176 | if (err!=UNZ_OK) | 229 | if (err!=UNZ_OK) |
| 177 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); | 230 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); |
| 178 | printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); | 231 | printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); |
| 179 | printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); | 232 | printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); |
| 180 | for (i=0;i<gi.number_entry;i++) | 233 | for (i=0;i<gi.number_entry;i++) |
| 181 | { | 234 | { |
| 182 | char filename_inzip[256]; | 235 | char filename_inzip[256]; |
| 183 | unz_file_info file_info; | 236 | unz_file_info64 file_info; |
| 184 | uLong ratio=0; | 237 | uLong ratio=0; |
| 185 | const char *string_method; | 238 | const char *string_method; |
| 186 | char charCrypt=' '; | 239 | char charCrypt=' '; |
| 187 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); | 240 | err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); |
| 188 | if (err!=UNZ_OK) | 241 | if (err!=UNZ_OK) |
| 189 | { | 242 | { |
| 190 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); | 243 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); |
| 191 | break; | 244 | break; |
| 192 | } | 245 | } |
| 193 | if (file_info.uncompressed_size>0) | 246 | if (file_info.uncompressed_size>0) |
| 194 | ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; | 247 | ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); |
| 195 | 248 | ||
| 196 | /* display a '*' if the file is crypted */ | 249 | /* display a '*' if the file is crypted */ |
| 197 | if ((file_info.flag & 1) != 0) | 250 | if ((file_info.flag & 1) != 0) |
| @@ -211,12 +264,17 @@ int do_list(uf) | |||
| 211 | string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ | 264 | string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ |
| 212 | } | 265 | } |
| 213 | else | 266 | else |
| 267 | if (file_info.compression_method==Z_BZIP2ED) | ||
| 268 | { | ||
| 269 | string_method="BZip2 "; | ||
| 270 | } | ||
| 271 | else | ||
| 214 | string_method="Unkn. "; | 272 | string_method="Unkn. "; |
| 215 | 273 | ||
| 216 | printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", | 274 | Display64BitsSize(file_info.uncompressed_size,7); |
| 217 | file_info.uncompressed_size,string_method, | 275 | printf(" %6s%c",string_method,charCrypt); |
| 218 | charCrypt, | 276 | Display64BitsSize(file_info.compressed_size,7); |
| 219 | file_info.compressed_size, | 277 | printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", |
| 220 | ratio, | 278 | ratio, |
| 221 | (uLong)file_info.tmu_date.tm_mon + 1, | 279 | (uLong)file_info.tmu_date.tm_mon + 1, |
| 222 | (uLong)file_info.tmu_date.tm_mday, | 280 | (uLong)file_info.tmu_date.tm_mday, |
| @@ -252,9 +310,9 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
| 252 | void* buf; | 310 | void* buf; |
| 253 | uInt size_buf; | 311 | uInt size_buf; |
| 254 | 312 | ||
| 255 | unz_file_info file_info; | 313 | unz_file_info64 file_info; |
| 256 | uLong ratio=0; | 314 | uLong ratio=0; |
| 257 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); | 315 | err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); |
| 258 | 316 | ||
| 259 | if (err!=UNZ_OK) | 317 | if (err!=UNZ_OK) |
| 260 | { | 318 | { |
| @@ -306,7 +364,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
| 306 | { | 364 | { |
| 307 | char rep=0; | 365 | char rep=0; |
| 308 | FILE* ftestexist; | 366 | FILE* ftestexist; |
| 309 | ftestexist = fopen(write_filename,"rb"); | 367 | ftestexist = fopen64(write_filename,"rb"); |
| 310 | if (ftestexist!=NULL) | 368 | if (ftestexist!=NULL) |
| 311 | { | 369 | { |
| 312 | fclose(ftestexist); | 370 | fclose(ftestexist); |
| @@ -337,7 +395,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
| 337 | 395 | ||
| 338 | if ((skip==0) && (err==UNZ_OK)) | 396 | if ((skip==0) && (err==UNZ_OK)) |
| 339 | { | 397 | { |
| 340 | fout=fopen(write_filename,"wb"); | 398 | fout=fopen64(write_filename,"wb"); |
| 341 | 399 | ||
| 342 | /* some zipfile don't contain directory alone before file */ | 400 | /* some zipfile don't contain directory alone before file */ |
| 343 | if ((fout==NULL) && ((*popt_extract_without_path)==0) && | 401 | if ((fout==NULL) && ((*popt_extract_without_path)==0) && |
| @@ -347,7 +405,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
| 347 | *(filename_withoutpath-1)='\0'; | 405 | *(filename_withoutpath-1)='\0'; |
| 348 | makedir(write_filename); | 406 | makedir(write_filename); |
| 349 | *(filename_withoutpath-1)=c; | 407 | *(filename_withoutpath-1)=c; |
| 350 | fout=fopen(write_filename,"wb"); | 408 | fout=fopen64(write_filename,"wb"); |
| 351 | } | 409 | } |
| 352 | 410 | ||
| 353 | if (fout==NULL) | 411 | if (fout==NULL) |
| @@ -409,11 +467,11 @@ int do_extract(uf,opt_extract_without_path,opt_overwrite,password) | |||
| 409 | const char* password; | 467 | const char* password; |
| 410 | { | 468 | { |
| 411 | uLong i; | 469 | uLong i; |
| 412 | unz_global_info gi; | 470 | unz_global_info64 gi; |
| 413 | int err; | 471 | int err; |
| 414 | FILE* fout=NULL; | 472 | FILE* fout=NULL; |
| 415 | 473 | ||
| 416 | err = unzGetGlobalInfo (uf,&gi); | 474 | err = unzGetGlobalInfo64(uf,&gi); |
| 417 | if (err!=UNZ_OK) | 475 | if (err!=UNZ_OK) |
| 418 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); | 476 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); |
| 419 | 477 | ||
| @@ -470,6 +528,7 @@ int main(argc,argv) | |||
| 470 | const char *password=NULL; | 528 | const char *password=NULL; |
| 471 | char filename_try[MAXFILENAME+16] = ""; | 529 | char filename_try[MAXFILENAME+16] = ""; |
| 472 | int i; | 530 | int i; |
| 531 | int ret_value=0; | ||
| 473 | int opt_do_list=0; | 532 | int opt_do_list=0; |
| 474 | int opt_do_extract=1; | 533 | int opt_do_extract=1; |
| 475 | int opt_do_extract_withoutpath=0; | 534 | int opt_do_extract_withoutpath=0; |
| @@ -532,7 +591,7 @@ int main(argc,argv) | |||
| 532 | { | 591 | { |
| 533 | 592 | ||
| 534 | # ifdef USEWIN32IOAPI | 593 | # ifdef USEWIN32IOAPI |
| 535 | zlib_filefunc_def ffunc; | 594 | zlib_filefunc64_def ffunc; |
| 536 | # endif | 595 | # endif |
| 537 | 596 | ||
| 538 | strncpy(filename_try, zipfilename,MAXFILENAME-1); | 597 | strncpy(filename_try, zipfilename,MAXFILENAME-1); |
| @@ -540,18 +599,18 @@ int main(argc,argv) | |||
| 540 | filename_try[ MAXFILENAME ] = '\0'; | 599 | filename_try[ MAXFILENAME ] = '\0'; |
| 541 | 600 | ||
| 542 | # ifdef USEWIN32IOAPI | 601 | # ifdef USEWIN32IOAPI |
| 543 | fill_win32_filefunc(&ffunc); | 602 | fill_win32_filefunc64A(&ffunc); |
| 544 | uf = unzOpen2(zipfilename,&ffunc); | 603 | uf = unzOpen2_64(zipfilename,&ffunc); |
| 545 | # else | 604 | # else |
| 546 | uf = unzOpen(zipfilename); | 605 | uf = unzOpen64(zipfilename); |
| 547 | # endif | 606 | # endif |
| 548 | if (uf==NULL) | 607 | if (uf==NULL) |
| 549 | { | 608 | { |
| 550 | strcat(filename_try,".zip"); | 609 | strcat(filename_try,".zip"); |
| 551 | # ifdef USEWIN32IOAPI | 610 | # ifdef USEWIN32IOAPI |
| 552 | uf = unzOpen2(filename_try,&ffunc); | 611 | uf = unzOpen2_64(filename_try,&ffunc); |
| 553 | # else | 612 | # else |
| 554 | uf = unzOpen(filename_try); | 613 | uf = unzOpen64(filename_try); |
| 555 | # endif | 614 | # endif |
| 556 | } | 615 | } |
| 557 | } | 616 | } |
| @@ -564,22 +623,26 @@ int main(argc,argv) | |||
| 564 | printf("%s opened\n",filename_try); | 623 | printf("%s opened\n",filename_try); |
| 565 | 624 | ||
| 566 | if (opt_do_list==1) | 625 | if (opt_do_list==1) |
| 567 | return do_list(uf); | 626 | ret_value = do_list(uf); |
| 568 | else if (opt_do_extract==1) | 627 | else if (opt_do_extract==1) |
| 569 | { | 628 | { |
| 629 | #ifdef _WIN32 | ||
| 630 | if (opt_extractdir && _chdir(dirname)) | ||
| 631 | #else | ||
| 570 | if (opt_extractdir && chdir(dirname)) | 632 | if (opt_extractdir && chdir(dirname)) |
| 633 | #endif | ||
| 571 | { | 634 | { |
| 572 | printf("Error changing into %s, aborting\n", dirname); | 635 | printf("Error changing into %s, aborting\n", dirname); |
| 573 | exit(-1); | 636 | exit(-1); |
| 574 | } | 637 | } |
| 575 | 638 | ||
| 576 | if (filename_to_extract == NULL) | 639 | if (filename_to_extract == NULL) |
| 577 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); | 640 | ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password); |
| 578 | else | 641 | else |
| 579 | return do_extract_onefile(uf,filename_to_extract, | 642 | ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password); |
| 580 | opt_do_extract_withoutpath,opt_overwrite,password); | ||
| 581 | } | 643 | } |
| 582 | unzCloseCurrentFile(uf); | ||
| 583 | 644 | ||
| 584 | return 0; | 645 | unzClose(uf); |
| 646 | |||
| 647 | return ret_value; | ||
| 585 | } | 648 | } |
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index f2dfecd..4ce33af 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
| @@ -1,10 +1,33 @@ | |||
| 1 | /* | 1 | /* |
| 2 | minizip.c | 2 | minizip.c |
| 3 | Version 1.01e, February 12th, 2005 | 3 | Version 1.1, January 7th, 2010 |
| 4 | sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 4 | 5 | ||
| 5 | Copyright (C) 1998-2005 Gilles Vollant | 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 ) | ||
| 6 | */ | 13 | */ |
| 7 | 14 | ||
| 15 | |||
| 16 | #ifndef _WIN32 | ||
| 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 | |||
| 8 | #include <stdio.h> | 31 | #include <stdio.h> |
| 9 | #include <stdlib.h> | 32 | #include <stdlib.h> |
| 10 | #include <string.h> | 33 | #include <string.h> |
| @@ -24,9 +47,9 @@ | |||
| 24 | 47 | ||
| 25 | #include "zip.h" | 48 | #include "zip.h" |
| 26 | 49 | ||
| 27 | #ifdef WIN32 | 50 | #ifdef _WIN32 |
| 28 | #define USEWIN32IOAPI | 51 | #define USEWIN32IOAPI |
| 29 | #include "iowin32.h" | 52 | #include "iowin32.h" |
| 30 | #endif | 53 | #endif |
| 31 | 54 | ||
| 32 | 55 | ||
| @@ -34,7 +57,7 @@ | |||
| 34 | #define WRITEBUFFERSIZE (16384) | 57 | #define WRITEBUFFERSIZE (16384) |
| 35 | #define MAXFILENAME (256) | 58 | #define MAXFILENAME (256) |
| 36 | 59 | ||
| 37 | #ifdef WIN32 | 60 | #ifdef _WIN32 |
| 38 | uLong filetime(f, tmzip, dt) | 61 | uLong filetime(f, tmzip, dt) |
| 39 | char *f; /* name of file to get info on */ | 62 | char *f; /* name of file to get info on */ |
| 40 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 63 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
| @@ -44,9 +67,9 @@ uLong filetime(f, tmzip, dt) | |||
| 44 | { | 67 | { |
| 45 | FILETIME ftLocal; | 68 | FILETIME ftLocal; |
| 46 | HANDLE hFind; | 69 | HANDLE hFind; |
| 47 | WIN32_FIND_DATA ff32; | 70 | WIN32_FIND_DATAA ff32; |
| 48 | 71 | ||
| 49 | hFind = FindFirstFile(f,&ff32); | 72 | hFind = FindFirstFileA(f,&ff32); |
| 50 | if (hFind != INVALID_HANDLE_VALUE) | 73 | if (hFind != INVALID_HANDLE_VALUE) |
| 51 | { | 74 | { |
| 52 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); | 75 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); |
| @@ -119,7 +142,7 @@ int check_exist_file(filename) | |||
| 119 | { | 142 | { |
| 120 | FILE* ftestexist; | 143 | FILE* ftestexist; |
| 121 | int ret = 1; | 144 | int ret = 1; |
| 122 | ftestexist = fopen(filename,"rb"); | 145 | ftestexist = fopen64(filename,"rb"); |
| 123 | if (ftestexist==NULL) | 146 | if (ftestexist==NULL) |
| 124 | ret = 0; | 147 | ret = 0; |
| 125 | else | 148 | else |
| @@ -129,18 +152,20 @@ int check_exist_file(filename) | |||
| 129 | 152 | ||
| 130 | void do_banner() | 153 | void do_banner() |
| 131 | { | 154 | { |
| 132 | printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); | 155 | printf("MiniZip64 1.0, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); |
| 133 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 156 | printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); |
| 157 | printf("more info on MiniZip64 at http://result42.com/projects/MiniZip64\n\n"); | ||
| 134 | } | 158 | } |
| 135 | 159 | ||
| 136 | void do_help() | 160 | void do_help() |
| 137 | { | 161 | { |
| 138 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ | 162 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ |
| 139 | " -o Overwrite existing file.zip\n" \ | 163 | " -o Overwrite existing file.zip\n" \ |
| 140 | " -a Append to existing file.zip\n" \ | 164 | " -a Append to existing file.zip\n" \ |
| 141 | " -0 Store only\n" \ | 165 | " -0 Store only\n" \ |
| 142 | " -1 Compress faster\n" \ | 166 | " -1 Compress faster\n" \ |
| 143 | " -9 Compress better\n\n"); | 167 | " -9 Compress better\n\n" \ |
| 168 | " -j exclude path. store only the file name.\n\n"); | ||
| 144 | } | 169 | } |
| 145 | 170 | ||
| 146 | /* calculate the CRC32 of a file, | 171 | /* calculate the CRC32 of a file, |
| @@ -149,7 +174,7 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne | |||
| 149 | { | 174 | { |
| 150 | unsigned long calculate_crc=0; | 175 | unsigned long calculate_crc=0; |
| 151 | int err=ZIP_OK; | 176 | int err=ZIP_OK; |
| 152 | FILE * fin = fopen(filenameinzip,"rb"); | 177 | FILE * fin = fopen64(filenameinzip,"rb"); |
| 153 | unsigned long size_read = 0; | 178 | unsigned long size_read = 0; |
| 154 | unsigned long total_read = 0; | 179 | unsigned long total_read = 0; |
| 155 | if (fin==NULL) | 180 | if (fin==NULL) |
| @@ -179,10 +204,33 @@ int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigne | |||
| 179 | fclose(fin); | 204 | fclose(fin); |
| 180 | 205 | ||
| 181 | *result_crc=calculate_crc; | 206 | *result_crc=calculate_crc; |
| 182 | printf("file %s crc %x\n",filenameinzip,calculate_crc); | 207 | printf("file %s crc %lx\n", filenameinzip, calculate_crc); |
| 183 | return err; | 208 | return err; |
| 184 | } | 209 | } |
| 185 | 210 | ||
| 211 | int isLargeFile(const char* filename) | ||
| 212 | { | ||
| 213 | int largeFile = 0; | ||
| 214 | ZPOS64_T pos = 0; | ||
| 215 | FILE* pFile = fopen64(filename, "rb"); | ||
| 216 | |||
| 217 | if(pFile != NULL) | ||
| 218 | { | ||
| 219 | int n = fseeko64(pFile, 0, SEEK_END); | ||
| 220 | |||
| 221 | pos = ftello64(pFile); | ||
| 222 | |||
| 223 | printf("File : %s is %lld bytes\n", filename, pos); | ||
| 224 | |||
| 225 | if(pos >= 0xffffffff) | ||
| 226 | largeFile = 1; | ||
| 227 | |||
| 228 | fclose(pFile); | ||
| 229 | } | ||
| 230 | |||
| 231 | return largeFile; | ||
| 232 | } | ||
| 233 | |||
| 186 | int main(argc,argv) | 234 | int main(argc,argv) |
| 187 | int argc; | 235 | int argc; |
| 188 | char *argv[]; | 236 | char *argv[]; |
| @@ -190,6 +238,7 @@ int main(argc,argv) | |||
| 190 | int i; | 238 | int i; |
| 191 | int opt_overwrite=0; | 239 | int opt_overwrite=0; |
| 192 | int opt_compress_level=Z_DEFAULT_COMPRESSION; | 240 | int opt_compress_level=Z_DEFAULT_COMPRESSION; |
| 241 | int opt_exclude_path=0; | ||
| 193 | int zipfilenamearg = 0; | 242 | int zipfilenamearg = 0; |
| 194 | char filename_try[MAXFILENAME+16]; | 243 | char filename_try[MAXFILENAME+16]; |
| 195 | int zipok; | 244 | int zipok; |
| @@ -222,6 +271,8 @@ int main(argc,argv) | |||
| 222 | opt_overwrite = 2; | 271 | opt_overwrite = 2; |
| 223 | if ((c>='0') && (c<='9')) | 272 | if ((c>='0') && (c<='9')) |
| 224 | opt_compress_level = c-'0'; | 273 | opt_compress_level = c-'0'; |
| 274 | if ((c=='j') || (c=='J')) | ||
| 275 | opt_exclude_path = 1; | ||
| 225 | 276 | ||
| 226 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 277 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
| 227 | { | 278 | { |
| @@ -231,8 +282,12 @@ int main(argc,argv) | |||
| 231 | } | 282 | } |
| 232 | } | 283 | } |
| 233 | else | 284 | else |
| 285 | { | ||
| 234 | if (zipfilenamearg == 0) | 286 | if (zipfilenamearg == 0) |
| 287 | { | ||
| 235 | zipfilenamearg = i ; | 288 | zipfilenamearg = i ; |
| 289 | } | ||
| 290 | } | ||
| 236 | } | 291 | } |
| 237 | } | 292 | } |
| 238 | 293 | ||
| @@ -245,7 +300,9 @@ int main(argc,argv) | |||
| 245 | } | 300 | } |
| 246 | 301 | ||
| 247 | if (zipfilenamearg==0) | 302 | if (zipfilenamearg==0) |
| 303 | { | ||
| 248 | zipok=0; | 304 | zipok=0; |
| 305 | } | ||
| 249 | else | 306 | else |
| 250 | { | 307 | { |
| 251 | int i,len; | 308 | int i,len; |
| @@ -302,11 +359,11 @@ int main(argc,argv) | |||
| 302 | zipFile zf; | 359 | zipFile zf; |
| 303 | int errclose; | 360 | int errclose; |
| 304 | # ifdef USEWIN32IOAPI | 361 | # ifdef USEWIN32IOAPI |
| 305 | zlib_filefunc_def ffunc; | 362 | zlib_filefunc64_def ffunc; |
| 306 | fill_win32_filefunc(&ffunc); | 363 | fill_win32_filefunc64A(&ffunc); |
| 307 | zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); | 364 | zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); |
| 308 | # else | 365 | # else |
| 309 | zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); | 366 | zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); |
| 310 | # endif | 367 | # endif |
| 311 | 368 | ||
| 312 | if (zf == NULL) | 369 | if (zf == NULL) |
| @@ -329,8 +386,10 @@ int main(argc,argv) | |||
| 329 | FILE * fin; | 386 | FILE * fin; |
| 330 | int size_read; | 387 | int size_read; |
| 331 | const char* filenameinzip = argv[i]; | 388 | const char* filenameinzip = argv[i]; |
| 389 | const char *savefilenameinzip; | ||
| 332 | zip_fileinfo zi; | 390 | zip_fileinfo zi; |
| 333 | unsigned long crcFile=0; | 391 | unsigned long crcFile=0; |
| 392 | int zip64 = 0; | ||
| 334 | 393 | ||
| 335 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = | 394 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = |
| 336 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; | 395 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; |
| @@ -347,20 +406,49 @@ int main(argc,argv) | |||
| 347 | */ | 406 | */ |
| 348 | if ((password != NULL) && (err==ZIP_OK)) | 407 | if ((password != NULL) && (err==ZIP_OK)) |
| 349 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); | 408 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); |
| 350 | 409 | ||
| 351 | err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, | 410 | zip64 = isLargeFile(filenameinzip); |
| 411 | |||
| 412 | /* The path name saved, should not include a leading slash. */ | ||
| 413 | /*if it did, windows/xp and dynazip couldn't read the zip file. */ | ||
| 414 | savefilenameinzip = filenameinzip; | ||
| 415 | while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) | ||
| 416 | { | ||
| 417 | savefilenameinzip++; | ||
| 418 | } | ||
| 419 | |||
| 420 | /*should the zip file contain any path at all?*/ | ||
| 421 | if( opt_exclude_path ) | ||
| 422 | { | ||
| 423 | const char *tmpptr; | ||
| 424 | const char *lastslash = 0; | ||
| 425 | for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) | ||
| 426 | { | ||
| 427 | if( *tmpptr == '\\' || *tmpptr == '/') | ||
| 428 | { | ||
| 429 | lastslash = tmpptr; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | if( lastslash != NULL ) | ||
| 433 | { | ||
| 434 | savefilenameinzip = lastslash+1; // base filename follows last slash. | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | /**/ | ||
| 439 | err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, | ||
| 352 | NULL,0,NULL,0,NULL /* comment*/, | 440 | NULL,0,NULL,0,NULL /* comment*/, |
| 353 | (opt_compress_level != 0) ? Z_DEFLATED : 0, | 441 | (opt_compress_level != 0) ? Z_DEFLATED : 0, |
| 354 | opt_compress_level,0, | 442 | opt_compress_level,0, |
| 355 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ | 443 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ |
| 356 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | 444 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
| 357 | password,crcFile); | 445 | password,crcFile, zip64); |
| 358 | 446 | ||
| 359 | if (err != ZIP_OK) | 447 | if (err != ZIP_OK) |
| 360 | printf("error in opening %s in zipfile\n",filenameinzip); | 448 | printf("error in opening %s in zipfile\n",filenameinzip); |
| 361 | else | 449 | else |
| 362 | { | 450 | { |
| 363 | fin = fopen(filenameinzip,"rb"); | 451 | fin = fopen64(filenameinzip,"rb"); |
| 364 | if (fin==NULL) | 452 | if (fin==NULL) |
| 365 | { | 453 | { |
| 366 | err=ZIP_ERRNO; | 454 | err=ZIP_ERRNO; |
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c index 8a50ee4..bc5c798 100644 --- a/contrib/minizip/mztools.c +++ b/contrib/minizip/mztools.c | |||
| @@ -1,281 +1,281 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Additional tools for Minizip | 2 | Additional tools for Minizip |
| 3 | Code: Xavier Roche '2004 | 3 | Code: Xavier Roche '2004 |
| 4 | License: Same as ZLIB (www.gzip.org) | 4 | License: Same as ZLIB (www.gzip.org) |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | /* Code */ | 7 | /* Code */ |
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | #include "zlib.h" | 11 | #include "zlib.h" |
| 12 | #include "unzip.h" | 12 | #include "unzip.h" |
| 13 | 13 | ||
| 14 | #define READ_8(adr) ((unsigned char)*(adr)) | 14 | #define READ_8(adr) ((unsigned char)*(adr)) |
| 15 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) | 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) ) | 16 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) |
| 17 | 17 | ||
| 18 | #define WRITE_8(buff, n) do { \ | 18 | #define WRITE_8(buff, n) do { \ |
| 19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ | 19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ |
| 20 | } while(0) | 20 | } while(0) |
| 21 | #define WRITE_16(buff, n) do { \ | 21 | #define WRITE_16(buff, n) do { \ |
| 22 | WRITE_8((unsigned char*)(buff), n); \ | 22 | WRITE_8((unsigned char*)(buff), n); \ |
| 23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ | 23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ |
| 24 | } while(0) | 24 | } while(0) |
| 25 | #define WRITE_32(buff, n) do { \ | 25 | #define WRITE_32(buff, n) do { \ |
| 26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ | 26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ |
| 27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ | 27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ |
| 28 | } while(0) | 28 | } while(0) |
| 29 | 29 | ||
| 30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) | 30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) |
| 31 | const char* file; | 31 | const char* file; |
| 32 | const char* fileOut; | 32 | const char* fileOut; |
| 33 | const char* fileOutTmp; | 33 | const char* fileOutTmp; |
| 34 | uLong* nRecovered; | 34 | uLong* nRecovered; |
| 35 | uLong* bytesRecovered; | 35 | uLong* bytesRecovered; |
| 36 | { | 36 | { |
| 37 | int err = Z_OK; | 37 | int err = Z_OK; |
| 38 | FILE* fpZip = fopen(file, "rb"); | 38 | FILE* fpZip = fopen(file, "rb"); |
| 39 | FILE* fpOut = fopen(fileOut, "wb"); | 39 | FILE* fpOut = fopen(fileOut, "wb"); |
| 40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); | 40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); |
| 41 | if (fpZip != NULL && fpOut != NULL) { | 41 | if (fpZip != NULL && fpOut != NULL) { |
| 42 | int entries = 0; | 42 | int entries = 0; |
| 43 | uLong totalBytes = 0; | 43 | uLong totalBytes = 0; |
| 44 | char header[30]; | 44 | char header[30]; |
| 45 | char filename[256]; | 45 | char filename[256]; |
| 46 | char extra[1024]; | 46 | char extra[1024]; |
| 47 | int offset = 0; | 47 | int offset = 0; |
| 48 | int offsetCD = 0; | 48 | int offsetCD = 0; |
| 49 | while ( fread(header, 1, 30, fpZip) == 30 ) { | 49 | while ( fread(header, 1, 30, fpZip) == 30 ) { |
| 50 | int currentOffset = offset; | 50 | int currentOffset = offset; |
| 51 | 51 | ||
| 52 | /* File entry */ | 52 | /* File entry */ |
| 53 | if (READ_32(header) == 0x04034b50) { | 53 | if (READ_32(header) == 0x04034b50) { |
| 54 | unsigned int version = READ_16(header + 4); | 54 | unsigned int version = READ_16(header + 4); |
| 55 | unsigned int gpflag = READ_16(header + 6); | 55 | unsigned int gpflag = READ_16(header + 6); |
| 56 | unsigned int method = READ_16(header + 8); | 56 | unsigned int method = READ_16(header + 8); |
| 57 | unsigned int filetime = READ_16(header + 10); | 57 | unsigned int filetime = READ_16(header + 10); |
| 58 | unsigned int filedate = READ_16(header + 12); | 58 | unsigned int filedate = READ_16(header + 12); |
| 59 | unsigned int crc = READ_32(header + 14); /* crc */ | 59 | unsigned int crc = READ_32(header + 14); /* crc */ |
| 60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ | 60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ |
| 61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ | 61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ |
| 62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ | 62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ |
| 63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ | 63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ |
| 64 | filename[0] = extra[0] = '\0'; | 64 | filename[0] = extra[0] = '\0'; |
| 65 | 65 | ||
| 66 | /* Header */ | 66 | /* Header */ |
| 67 | if (fwrite(header, 1, 30, fpOut) == 30) { | 67 | if (fwrite(header, 1, 30, fpOut) == 30) { |
| 68 | offset += 30; | 68 | offset += 30; |
| 69 | } else { | 69 | } else { |
| 70 | err = Z_ERRNO; | 70 | err = Z_ERRNO; |
| 71 | break; | 71 | break; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | /* Filename */ | 74 | /* Filename */ |
| 75 | if (fnsize > 0) { | 75 | if (fnsize > 0) { |
| 76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { | 76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { |
| 77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { | 77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { |
| 78 | offset += fnsize; | 78 | offset += fnsize; |
| 79 | } else { | 79 | } else { |
| 80 | err = Z_ERRNO; | 80 | err = Z_ERRNO; |
| 81 | break; | 81 | break; |
| 82 | } | 82 | } |
| 83 | } else { | 83 | } else { |
| 84 | err = Z_ERRNO; | 84 | err = Z_ERRNO; |
| 85 | break; | 85 | break; |
| 86 | } | 86 | } |
| 87 | } else { | 87 | } else { |
| 88 | err = Z_STREAM_ERROR; | 88 | err = Z_STREAM_ERROR; |
| 89 | break; | 89 | break; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | /* Extra field */ | 92 | /* Extra field */ |
| 93 | if (extsize > 0) { | 93 | if (extsize > 0) { |
| 94 | if (fread(extra, 1, extsize, fpZip) == extsize) { | 94 | if (fread(extra, 1, extsize, fpZip) == extsize) { |
| 95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { | 95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { |
| 96 | offset += extsize; | 96 | offset += extsize; |
| 97 | } else { | 97 | } else { |
| 98 | err = Z_ERRNO; | 98 | err = Z_ERRNO; |
| 99 | break; | 99 | break; |
| 100 | } | 100 | } |
| 101 | } else { | 101 | } else { |
| 102 | err = Z_ERRNO; | 102 | err = Z_ERRNO; |
| 103 | break; | 103 | break; |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /* Data */ | 107 | /* Data */ |
| 108 | { | 108 | { |
| 109 | int dataSize = cpsize; | 109 | int dataSize = cpsize; |
| 110 | if (dataSize == 0) { | 110 | if (dataSize == 0) { |
| 111 | dataSize = uncpsize; | 111 | dataSize = uncpsize; |
| 112 | } | 112 | } |
| 113 | if (dataSize > 0) { | 113 | if (dataSize > 0) { |
| 114 | char* data = malloc(dataSize); | 114 | char* data = malloc(dataSize); |
| 115 | if (data != NULL) { | 115 | if (data != NULL) { |
| 116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { | 116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { |
| 117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { | 117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { |
| 118 | offset += dataSize; | 118 | offset += dataSize; |
| 119 | totalBytes += dataSize; | 119 | totalBytes += dataSize; |
| 120 | } else { | 120 | } else { |
| 121 | err = Z_ERRNO; | 121 | err = Z_ERRNO; |
| 122 | } | 122 | } |
| 123 | } else { | 123 | } else { |
| 124 | err = Z_ERRNO; | 124 | err = Z_ERRNO; |
| 125 | } | 125 | } |
| 126 | free(data); | 126 | free(data); |
| 127 | if (err != Z_OK) { | 127 | if (err != Z_OK) { |
| 128 | break; | 128 | break; |
| 129 | } | 129 | } |
| 130 | } else { | 130 | } else { |
| 131 | err = Z_MEM_ERROR; | 131 | err = Z_MEM_ERROR; |
| 132 | break; | 132 | break; |
| 133 | } | 133 | } |
| 134 | } | 134 | } |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | /* Central directory entry */ | 137 | /* Central directory entry */ |
| 138 | { | 138 | { |
| 139 | char header[46]; | 139 | char header[46]; |
| 140 | char* comment = ""; | 140 | char* comment = ""; |
| 141 | int comsize = (int) strlen(comment); | 141 | int comsize = (int) strlen(comment); |
| 142 | WRITE_32(header, 0x02014b50); | 142 | WRITE_32(header, 0x02014b50); |
| 143 | WRITE_16(header + 4, version); | 143 | WRITE_16(header + 4, version); |
| 144 | WRITE_16(header + 6, version); | 144 | WRITE_16(header + 6, version); |
| 145 | WRITE_16(header + 8, gpflag); | 145 | WRITE_16(header + 8, gpflag); |
| 146 | WRITE_16(header + 10, method); | 146 | WRITE_16(header + 10, method); |
| 147 | WRITE_16(header + 12, filetime); | 147 | WRITE_16(header + 12, filetime); |
| 148 | WRITE_16(header + 14, filedate); | 148 | WRITE_16(header + 14, filedate); |
| 149 | WRITE_32(header + 16, crc); | 149 | WRITE_32(header + 16, crc); |
| 150 | WRITE_32(header + 20, cpsize); | 150 | WRITE_32(header + 20, cpsize); |
| 151 | WRITE_32(header + 24, uncpsize); | 151 | WRITE_32(header + 24, uncpsize); |
| 152 | WRITE_16(header + 28, fnsize); | 152 | WRITE_16(header + 28, fnsize); |
| 153 | WRITE_16(header + 30, extsize); | 153 | WRITE_16(header + 30, extsize); |
| 154 | WRITE_16(header + 32, comsize); | 154 | WRITE_16(header + 32, comsize); |
| 155 | WRITE_16(header + 34, 0); /* disk # */ | 155 | WRITE_16(header + 34, 0); /* disk # */ |
| 156 | WRITE_16(header + 36, 0); /* int attrb */ | 156 | WRITE_16(header + 36, 0); /* int attrb */ |
| 157 | WRITE_32(header + 38, 0); /* ext attrb */ | 157 | WRITE_32(header + 38, 0); /* ext attrb */ |
| 158 | WRITE_32(header + 42, currentOffset); | 158 | WRITE_32(header + 42, currentOffset); |
| 159 | /* Header */ | 159 | /* Header */ |
| 160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { | 160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { |
| 161 | offsetCD += 46; | 161 | offsetCD += 46; |
| 162 | 162 | ||
| 163 | /* Filename */ | 163 | /* Filename */ |
| 164 | if (fnsize > 0) { | 164 | if (fnsize > 0) { |
| 165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { | 165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { |
| 166 | offsetCD += fnsize; | 166 | offsetCD += fnsize; |
| 167 | } else { | 167 | } else { |
| 168 | err = Z_ERRNO; | 168 | err = Z_ERRNO; |
| 169 | break; | 169 | break; |
| 170 | } | 170 | } |
| 171 | } else { | 171 | } else { |
| 172 | err = Z_STREAM_ERROR; | 172 | err = Z_STREAM_ERROR; |
| 173 | break; | 173 | break; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | /* Extra field */ | 176 | /* Extra field */ |
| 177 | if (extsize > 0) { | 177 | if (extsize > 0) { |
| 178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { | 178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { |
| 179 | offsetCD += extsize; | 179 | offsetCD += extsize; |
| 180 | } else { | 180 | } else { |
| 181 | err = Z_ERRNO; | 181 | err = Z_ERRNO; |
| 182 | break; | 182 | break; |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | /* Comment field */ | 186 | /* Comment field */ |
| 187 | if (comsize > 0) { | 187 | if (comsize > 0) { |
| 188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { | 188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { |
| 189 | offsetCD += comsize; | 189 | offsetCD += comsize; |
| 190 | } else { | 190 | } else { |
| 191 | err = Z_ERRNO; | 191 | err = Z_ERRNO; |
| 192 | break; | 192 | break; |
| 193 | } | 193 | } |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | 196 | ||
| 197 | } else { | 197 | } else { |
| 198 | err = Z_ERRNO; | 198 | err = Z_ERRNO; |
| 199 | break; | 199 | break; |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | /* Success */ | 203 | /* Success */ |
| 204 | entries++; | 204 | entries++; |
| 205 | 205 | ||
| 206 | } else { | 206 | } else { |
| 207 | break; | 207 | break; |
| 208 | } | 208 | } |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | /* Final central directory */ | 211 | /* Final central directory */ |
| 212 | { | 212 | { |
| 213 | int entriesZip = entries; | 213 | int entriesZip = entries; |
| 214 | char header[22]; | 214 | char header[22]; |
| 215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; | 215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; |
| 216 | int comsize = (int) strlen(comment); | 216 | int comsize = (int) strlen(comment); |
| 217 | if (entriesZip > 0xffff) { | 217 | if (entriesZip > 0xffff) { |
| 218 | entriesZip = 0xffff; | 218 | entriesZip = 0xffff; |
| 219 | } | 219 | } |
| 220 | WRITE_32(header, 0x06054b50); | 220 | WRITE_32(header, 0x06054b50); |
| 221 | WRITE_16(header + 4, 0); /* disk # */ | 221 | WRITE_16(header + 4, 0); /* disk # */ |
| 222 | WRITE_16(header + 6, 0); /* disk # */ | 222 | WRITE_16(header + 6, 0); /* disk # */ |
| 223 | WRITE_16(header + 8, entriesZip); /* hack */ | 223 | WRITE_16(header + 8, entriesZip); /* hack */ |
| 224 | WRITE_16(header + 10, entriesZip); /* hack */ | 224 | WRITE_16(header + 10, entriesZip); /* hack */ |
| 225 | WRITE_32(header + 12, offsetCD); /* size of CD */ | 225 | WRITE_32(header + 12, offsetCD); /* size of CD */ |
| 226 | WRITE_32(header + 16, offset); /* offset to CD */ | 226 | WRITE_32(header + 16, offset); /* offset to CD */ |
| 227 | WRITE_16(header + 20, comsize); /* comment */ | 227 | WRITE_16(header + 20, comsize); /* comment */ |
| 228 | 228 | ||
| 229 | /* Header */ | 229 | /* Header */ |
| 230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { | 230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { |
| 231 | 231 | ||
| 232 | /* Comment field */ | 232 | /* Comment field */ |
| 233 | if (comsize > 0) { | 233 | if (comsize > 0) { |
| 234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { | 234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { |
| 235 | err = Z_ERRNO; | 235 | err = Z_ERRNO; |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | } else { | 239 | } else { |
| 240 | err = Z_ERRNO; | 240 | err = Z_ERRNO; |
| 241 | } | 241 | } |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | /* Final merge (file + central directory) */ | 244 | /* Final merge (file + central directory) */ |
| 245 | fclose(fpOutCD); | 245 | fclose(fpOutCD); |
| 246 | if (err == Z_OK) { | 246 | if (err == Z_OK) { |
| 247 | fpOutCD = fopen(fileOutTmp, "rb"); | 247 | fpOutCD = fopen(fileOutTmp, "rb"); |
| 248 | if (fpOutCD != NULL) { | 248 | if (fpOutCD != NULL) { |
| 249 | int nRead; | 249 | int nRead; |
| 250 | char buffer[8192]; | 250 | char buffer[8192]; |
| 251 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { | 251 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { |
| 252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { | 252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { |
| 253 | err = Z_ERRNO; | 253 | err = Z_ERRNO; |
| 254 | break; | 254 | break; |
| 255 | } | 255 | } |
| 256 | } | 256 | } |
| 257 | fclose(fpOutCD); | 257 | fclose(fpOutCD); |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | /* Close */ | 261 | /* Close */ |
| 262 | fclose(fpZip); | 262 | fclose(fpZip); |
| 263 | fclose(fpOut); | 263 | fclose(fpOut); |
| 264 | 264 | ||
| 265 | /* Wipe temporary file */ | 265 | /* Wipe temporary file */ |
| 266 | (void)remove(fileOutTmp); | 266 | (void)remove(fileOutTmp); |
| 267 | 267 | ||
| 268 | /* Number of recovered entries */ | 268 | /* Number of recovered entries */ |
| 269 | if (err == Z_OK) { | 269 | if (err == Z_OK) { |
| 270 | if (nRecovered != NULL) { | 270 | if (nRecovered != NULL) { |
| 271 | *nRecovered = entries; | 271 | *nRecovered = entries; |
| 272 | } | 272 | } |
| 273 | if (bytesRecovered != NULL) { | 273 | if (bytesRecovered != NULL) { |
| 274 | *bytesRecovered = totalBytes; | 274 | *bytesRecovered = totalBytes; |
| 275 | } | 275 | } |
| 276 | } | 276 | } |
| 277 | } else { | 277 | } else { |
| 278 | err = Z_STREAM_ERROR; | 278 | err = Z_STREAM_ERROR; |
| 279 | } | 279 | } |
| 280 | return err; | 280 | return err; |
| 281 | } | 281 | } |
diff --git a/contrib/minizip/mztools.h b/contrib/minizip/mztools.h index eee78dc..82d1597 100644 --- a/contrib/minizip/mztools.h +++ b/contrib/minizip/mztools.h | |||
| @@ -1,31 +1,31 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Additional tools for Minizip | 2 | Additional tools for Minizip |
| 3 | Code: Xavier Roche '2004 | 3 | Code: Xavier Roche '2004 |
| 4 | License: Same as ZLIB (www.gzip.org) | 4 | License: Same as ZLIB (www.gzip.org) |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #ifndef _zip_tools_H | 7 | #ifndef _zip_tools_H |
| 8 | #define _zip_tools_H | 8 | #define _zip_tools_H |
| 9 | 9 | ||
| 10 | #ifdef __cplusplus | 10 | #ifdef __cplusplus |
| 11 | extern "C" { | 11 | extern "C" { |
| 12 | #endif | 12 | #endif |
| 13 | 13 | ||
| 14 | #ifndef _ZLIB_H | 14 | #ifndef _ZLIB_H |
| 15 | #include "zlib.h" | 15 | #include "zlib.h" |
| 16 | #endif | 16 | #endif |
| 17 | 17 | ||
| 18 | #include "unzip.h" | 18 | #include "unzip.h" |
| 19 | 19 | ||
| 20 | /* Repair a ZIP file (missing central directory) | 20 | /* Repair a ZIP file (missing central directory) |
| 21 | file: file to recover | 21 | file: file to recover |
| 22 | fileOut: output file after recovery | 22 | fileOut: output file after recovery |
| 23 | fileOutTmp: temporary file name used for recovery | 23 | fileOutTmp: temporary file name used for recovery |
| 24 | */ | 24 | */ |
| 25 | extern int ZEXPORT unzRepair(const char* file, | 25 | extern int ZEXPORT unzRepair(const char* file, |
| 26 | const char* fileOut, | 26 | const char* fileOut, |
| 27 | const char* fileOutTmp, | 27 | const char* fileOutTmp, |
| 28 | uLong* nRecovered, | 28 | uLong* nRecovered, |
| 29 | uLong* bytesRecovered); | 29 | uLong* bytesRecovered); |
| 30 | 30 | ||
| 31 | #endif | 31 | #endif |
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index e115663..050d506 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c | |||
| @@ -1,43 +1,75 @@ | |||
| 1 | /* unzip.c -- IO for uncompress .zip files using zlib | 1 | /* unzip.c -- IO for uncompress .zip files using zlib |
| 2 | Version 1.01e, February 12th, 2005 | 2 | Version 1.1, January 7th, 2010 |
| 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 3 | 4 | ||
| 4 | Copyright (C) 1998-2005 Gilles Vollant | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
| 5 | 6 | ||
| 6 | Read unzip.h for more info | 7 | Modifications of Unzip for Zip64 |
| 7 | */ | 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. | ||
| 8 | 20 | ||
| 9 | /* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of | ||
| 10 | compatibility with older software. The following is from the original crypt.c. Code | ||
| 11 | woven in by Terry Thorsen 1/2003. | ||
| 12 | */ | ||
| 13 | /* | ||
| 14 | Copyright (c) 1990-2000 Info-ZIP. All rights reserved. | 21 | Copyright (c) 1990-2000 Info-ZIP. All rights reserved. |
| 15 | 22 | ||
| 16 | See the accompanying file LICENSE, version 2000-Apr-09 or later | 23 | See the accompanying file LICENSE, version 2000-Apr-09 or later |
| 17 | (the contents of which are also included in zip.h) for terms of use. | 24 | (the contents of which are also included in zip.h) for terms of use. |
| 18 | If, for some reason, all these files are missing, the Info-ZIP license | 25 | If, for some reason, all these files are missing, the Info-ZIP license |
| 19 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html | 26 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
| 20 | */ | 27 | |
| 21 | /* | 28 | crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] |
| 22 | crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] | ||
| 23 | 29 | ||
| 24 | The encryption/decryption parts of this source code (as opposed to the | 30 | The encryption/decryption parts of this source code (as opposed to the |
| 25 | non-echoing password parts) were originally written in Europe. The | 31 | non-echoing password parts) were originally written in Europe. The |
| 26 | whole source package can be freely distributed, including from the USA. | 32 | whole source package can be freely distributed, including from the USA. |
| 27 | (Prior to January 2000, re-export from the US was a violation of US law.) | 33 | (Prior to January 2000, re-export from the US was a violation of US law.) |
| 28 | */ | ||
| 29 | 34 | ||
| 30 | /* | 35 | This encryption code is a direct transcription of the algorithm from |
| 31 | This encryption code is a direct transcription of the algorithm from | ||
| 32 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This | 36 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This |
| 33 | file (appnote.txt) is distributed with the PKZIP program (even in the | 37 | file (appnote.txt) is distributed with the PKZIP program (even in the |
| 34 | version without encryption capabilities). | 38 | version without encryption capabilities). |
| 35 | */ | 39 | |
| 40 | ------------------------------------------------------------------------------------ | ||
| 41 | |||
| 42 | Changes in unzip64.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 | Okt-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 | Okt-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 | Okt-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant | ||
| 57 | Okt-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) | ||
| 58 | Patch created by Daniel Borca | ||
| 59 | |||
| 60 | Copyright (C) 2009 Mathias Svensson | ||
| 61 | |||
| 62 | */ | ||
| 36 | 63 | ||
| 37 | 64 | ||
| 38 | #include <stdio.h> | 65 | #include <stdio.h> |
| 39 | #include <stdlib.h> | 66 | #include <stdlib.h> |
| 40 | #include <string.h> | 67 | #include <string.h> |
| 68 | |||
| 69 | #ifndef NOUNCRYPT | ||
| 70 | #define NOUNCRYPT | ||
| 71 | #endif | ||
| 72 | |||
| 41 | #include "zlib.h" | 73 | #include "zlib.h" |
| 42 | #include "unzip.h" | 74 | #include "unzip.h" |
| 43 | 75 | ||
| @@ -85,16 +117,14 @@ woven in by Terry Thorsen 1/2003. | |||
| 85 | #define SIZEZIPLOCALHEADER (0x1e) | 117 | #define SIZEZIPLOCALHEADER (0x1e) |
| 86 | 118 | ||
| 87 | 119 | ||
| 88 | |||
| 89 | |||
| 90 | const char unz_copyright[] = | 120 | const char unz_copyright[] = |
| 91 | " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; | 121 | " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
| 92 | 122 | ||
| 93 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ | 123 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ |
| 94 | typedef struct unz_file_info_internal_s | 124 | typedef struct unz_file_info64_internal_s |
| 95 | { | 125 | { |
| 96 | uLong offset_curfile;/* relative offset of local header 4 bytes */ | 126 | ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ |
| 97 | } unz_file_info_internal; | 127 | } unz_file_info64_internal; |
| 98 | 128 | ||
| 99 | 129 | ||
| 100 | /* file_in_zip_read_info_s contain internal information about a file in zipfile, | 130 | /* file_in_zip_read_info_s contain internal information about a file in zipfile, |
| @@ -104,52 +134,61 @@ typedef struct | |||
| 104 | char *read_buffer; /* internal buffer for compressed data */ | 134 | char *read_buffer; /* internal buffer for compressed data */ |
| 105 | z_stream stream; /* zLib stream structure for inflate */ | 135 | z_stream stream; /* zLib stream structure for inflate */ |
| 106 | 136 | ||
| 107 | uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ | 137 | #ifdef HAVE_BZIP2 |
| 138 | bz_stream bstream; /* bzLib stream structure for bziped */ | ||
| 139 | #endif | ||
| 140 | |||
| 141 | ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ | ||
| 108 | uLong stream_initialised; /* flag set if stream structure is initialised*/ | 142 | uLong stream_initialised; /* flag set if stream structure is initialised*/ |
| 109 | 143 | ||
| 110 | uLong offset_local_extrafield;/* offset of the local extra field */ | 144 | ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ |
| 111 | uInt size_local_extrafield;/* size of the local extra field */ | 145 | uInt size_local_extrafield;/* size of the local extra field */ |
| 112 | uLong pos_local_extrafield; /* position in the local extra field in read*/ | 146 | ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ |
| 147 | ZPOS64_T total_out_64; | ||
| 113 | 148 | ||
| 114 | uLong crc32; /* crc32 of all data uncompressed */ | 149 | uLong crc32; /* crc32 of all data uncompressed */ |
| 115 | uLong crc32_wait; /* crc32 we must obtain after decompress all */ | 150 | uLong crc32_wait; /* crc32 we must obtain after decompress all */ |
| 116 | uLong rest_read_compressed; /* number of byte to be decompressed */ | 151 | ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ |
| 117 | uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ | 152 | ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ |
| 118 | zlib_filefunc_def z_filefunc; | 153 | zlib_filefunc64_32_def z_filefunc; |
| 119 | voidpf filestream; /* io structore of the zipfile */ | 154 | voidpf filestream; /* io structore of the zipfile */ |
| 120 | uLong compression_method; /* compression method (0==store) */ | 155 | uLong compression_method; /* compression method (0==store) */ |
| 121 | uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | 156 | ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ |
| 122 | int raw; | 157 | int raw; |
| 123 | } file_in_zip_read_info_s; | 158 | } file_in_zip64_read_info_s; |
| 124 | 159 | ||
| 125 | 160 | ||
| 126 | /* unz_s contain internal information about the zipfile | 161 | /* unz64_s contain internal information about the zipfile |
| 127 | */ | 162 | */ |
| 128 | typedef struct | 163 | typedef struct |
| 129 | { | 164 | { |
| 130 | zlib_filefunc_def z_filefunc; | 165 | zlib_filefunc64_32_def z_filefunc; |
| 166 | int is64bitOpenFunction; | ||
| 131 | voidpf filestream; /* io structore of the zipfile */ | 167 | voidpf filestream; /* io structore of the zipfile */ |
| 132 | unz_global_info gi; /* public global information */ | 168 | unz_global_info64 gi; /* public global information */ |
| 133 | uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | 169 | ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ |
| 134 | uLong num_file; /* number of the current file in the zipfile*/ | 170 | ZPOS64_T num_file; /* number of the current file in the zipfile*/ |
| 135 | uLong pos_in_central_dir; /* pos of the current file in the central dir*/ | 171 | ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ |
| 136 | uLong current_file_ok; /* flag about the usability of the current file*/ | 172 | ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ |
| 137 | uLong central_pos; /* position of the beginning of the central dir*/ | 173 | ZPOS64_T central_pos; /* position of the beginning of the central dir*/ |
| 138 | 174 | ||
| 139 | uLong size_central_dir; /* size of the central directory */ | 175 | ZPOS64_T size_central_dir; /* size of the central directory */ |
| 140 | uLong offset_central_dir; /* offset of start of central directory with | 176 | ZPOS64_T offset_central_dir; /* offset of start of central directory with |
| 141 | respect to the starting disk number */ | 177 | respect to the starting disk number */ |
| 142 | 178 | ||
| 143 | unz_file_info cur_file_info; /* public info about the current file in zip*/ | 179 | unz_file_info64 cur_file_info; /* public info about the current file in zip*/ |
| 144 | unz_file_info_internal cur_file_info_internal; /* private info about it*/ | 180 | unz_file_info64_internal cur_file_info_internal; /* private info about it*/ |
| 145 | file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current | 181 | file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current |
| 146 | file if we are decompressing it */ | 182 | file if we are decompressing it */ |
| 147 | int encrypted; | 183 | int encrypted; |
| 184 | |||
| 185 | int isZip64; | ||
| 186 | |||
| 148 | # ifndef NOUNCRYPT | 187 | # ifndef NOUNCRYPT |
| 149 | unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | 188 | unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
| 150 | const unsigned long* pcrc_32_tab; | 189 | const unsigned long* pcrc_32_tab; |
| 151 | # endif | 190 | # endif |
| 152 | } unz_s; | 191 | } unz64_s; |
| 153 | 192 | ||
| 154 | 193 | ||
| 155 | #ifndef NOUNCRYPT | 194 | #ifndef NOUNCRYPT |
| @@ -163,18 +202,15 @@ typedef struct | |||
| 163 | */ | 202 | */ |
| 164 | 203 | ||
| 165 | 204 | ||
| 166 | local int unzlocal_getByte OF(( | 205 | local int unz64local_getByte OF(( |
| 167 | const zlib_filefunc_def* pzlib_filefunc_def, | 206 | const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 168 | voidpf filestream, | 207 | voidpf filestream, |
| 169 | int *pi)); | 208 | int *pi)); |
| 170 | 209 | ||
| 171 | local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | 210 | local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) |
| 172 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 173 | voidpf filestream; | ||
| 174 | int *pi; | ||
| 175 | { | 211 | { |
| 176 | unsigned char c; | 212 | unsigned char c; |
| 177 | int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); | 213 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); |
| 178 | if (err==1) | 214 | if (err==1) |
| 179 | { | 215 | { |
| 180 | *pi = (int)c; | 216 | *pi = (int)c; |
| @@ -182,7 +218,7 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | |||
| 182 | } | 218 | } |
| 183 | else | 219 | else |
| 184 | { | 220 | { |
| 185 | if (ZERROR(*pzlib_filefunc_def,filestream)) | 221 | if (ZERROR64(*pzlib_filefunc_def,filestream)) |
| 186 | return UNZ_ERRNO; | 222 | return UNZ_ERRNO; |
| 187 | else | 223 | else |
| 188 | return UNZ_EOF; | 224 | return UNZ_EOF; |
| @@ -193,26 +229,25 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) | |||
| 193 | /* =========================================================================== | 229 | /* =========================================================================== |
| 194 | Reads a long in LSB order from the given gz_stream. Sets | 230 | Reads a long in LSB order from the given gz_stream. Sets |
| 195 | */ | 231 | */ |
| 196 | local int unzlocal_getShort OF(( | 232 | local int unz64local_getShort OF(( |
| 197 | const zlib_filefunc_def* pzlib_filefunc_def, | 233 | const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 198 | voidpf filestream, | 234 | voidpf filestream, |
| 199 | uLong *pX)); | 235 | uLong *pX)); |
| 200 | 236 | ||
| 201 | local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) | 237 | local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 202 | const zlib_filefunc_def* pzlib_filefunc_def; | 238 | voidpf filestream, |
| 203 | voidpf filestream; | 239 | uLong *pX) |
| 204 | uLong *pX; | ||
| 205 | { | 240 | { |
| 206 | uLong x ; | 241 | uLong x ; |
| 207 | int i; | 242 | int i = 0; |
| 208 | int err; | 243 | int err; |
| 209 | 244 | ||
| 210 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 245 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 211 | x = (uLong)i; | 246 | x = (uLong)i; |
| 212 | 247 | ||
| 213 | if (err==UNZ_OK) | 248 | if (err==UNZ_OK) |
| 214 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 249 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 215 | x += ((uLong)i)<<8; | 250 | x |= ((uLong)i)<<8; |
| 216 | 251 | ||
| 217 | if (err==UNZ_OK) | 252 | if (err==UNZ_OK) |
| 218 | *pX = x; | 253 | *pX = x; |
| @@ -221,33 +256,32 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) | |||
| 221 | return err; | 256 | return err; |
| 222 | } | 257 | } |
| 223 | 258 | ||
| 224 | local int unzlocal_getLong OF(( | 259 | local int unz64local_getLong OF(( |
| 225 | const zlib_filefunc_def* pzlib_filefunc_def, | 260 | const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 226 | voidpf filestream, | 261 | voidpf filestream, |
| 227 | uLong *pX)); | 262 | uLong *pX)); |
| 228 | 263 | ||
| 229 | local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) | 264 | local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 230 | const zlib_filefunc_def* pzlib_filefunc_def; | 265 | voidpf filestream, |
| 231 | voidpf filestream; | 266 | uLong *pX) |
| 232 | uLong *pX; | ||
| 233 | { | 267 | { |
| 234 | uLong x ; | 268 | uLong x ; |
| 235 | int i; | 269 | int i = 0; |
| 236 | int err; | 270 | int err; |
| 237 | 271 | ||
| 238 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 272 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 239 | x = (uLong)i; | 273 | x = (uLong)i; |
| 240 | 274 | ||
| 241 | if (err==UNZ_OK) | 275 | if (err==UNZ_OK) |
| 242 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 276 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 243 | x += ((uLong)i)<<8; | 277 | x |= ((uLong)i)<<8; |
| 244 | 278 | ||
| 245 | if (err==UNZ_OK) | 279 | if (err==UNZ_OK) |
| 246 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 280 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 247 | x += ((uLong)i)<<16; | 281 | x |= ((uLong)i)<<16; |
| 248 | 282 | ||
| 249 | if (err==UNZ_OK) | 283 | if (err==UNZ_OK) |
| 250 | err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); | 284 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 251 | x += ((uLong)i)<<24; | 285 | x += ((uLong)i)<<24; |
| 252 | 286 | ||
| 253 | if (err==UNZ_OK) | 287 | if (err==UNZ_OK) |
| @@ -257,11 +291,60 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) | |||
| 257 | return err; | 291 | return err; |
| 258 | } | 292 | } |
| 259 | 293 | ||
| 294 | local int unz64local_getLong64 OF(( | ||
| 295 | const zlib_filefunc64_32_def* pzlib_filefunc_def, | ||
| 296 | voidpf filestream, | ||
| 297 | ZPOS64_T *pX)); | ||
| 298 | |||
| 299 | |||
| 300 | local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, | ||
| 301 | voidpf filestream, | ||
| 302 | ZPOS64_T *pX) | ||
| 303 | { | ||
| 304 | ZPOS64_T x ; | ||
| 305 | int i = 0; | ||
| 306 | int err; | ||
| 307 | |||
| 308 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 309 | x = (ZPOS64_T)i; | ||
| 310 | |||
| 311 | if (err==UNZ_OK) | ||
| 312 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 313 | x |= ((ZPOS64_T)i)<<8; | ||
| 314 | |||
| 315 | if (err==UNZ_OK) | ||
| 316 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 317 | x |= ((ZPOS64_T)i)<<16; | ||
| 318 | |||
| 319 | if (err==UNZ_OK) | ||
| 320 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 321 | x |= ((ZPOS64_T)i)<<24; | ||
| 322 | |||
| 323 | if (err==UNZ_OK) | ||
| 324 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 325 | x |= ((ZPOS64_T)i)<<32; | ||
| 326 | |||
| 327 | if (err==UNZ_OK) | ||
| 328 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 329 | x |= ((ZPOS64_T)i)<<40; | ||
| 330 | |||
| 331 | if (err==UNZ_OK) | ||
| 332 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 333 | x |= ((ZPOS64_T)i)<<48; | ||
| 334 | |||
| 335 | if (err==UNZ_OK) | ||
| 336 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 337 | x |= ((ZPOS64_T)i)<<56; | ||
| 338 | |||
| 339 | if (err==UNZ_OK) | ||
| 340 | *pX = x; | ||
| 341 | else | ||
| 342 | *pX = 0; | ||
| 343 | return err; | ||
| 344 | } | ||
| 260 | 345 | ||
| 261 | /* My own strcmpi / strcasecmp */ | 346 | /* My own strcmpi / strcasecmp */ |
| 262 | local int strcmpcasenosensitive_internal (fileName1,fileName2) | 347 | local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) |
| 263 | const char* fileName1; | ||
| 264 | const char* fileName2; | ||
| 265 | { | 348 | { |
| 266 | for (;;) | 349 | for (;;) |
| 267 | { | 350 | { |
| @@ -302,10 +385,10 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2) | |||
| 302 | (like 1 on Unix, 2 on Windows) | 385 | (like 1 on Unix, 2 on Windows) |
| 303 | 386 | ||
| 304 | */ | 387 | */ |
| 305 | extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) | 388 | extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, |
| 306 | const char* fileName1; | 389 | const char* fileName2, |
| 307 | const char* fileName2; | 390 | int iCaseSensitivity) |
| 308 | int iCaseSensitivity; | 391 | |
| 309 | { | 392 | { |
| 310 | if (iCaseSensitivity==0) | 393 | if (iCaseSensitivity==0) |
| 311 | iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; | 394 | iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; |
| @@ -324,25 +407,20 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit | |||
| 324 | Locate the Central directory of a zipfile (at the end, just before | 407 | Locate the Central directory of a zipfile (at the end, just before |
| 325 | the global comment) | 408 | the global comment) |
| 326 | */ | 409 | */ |
| 327 | local uLong unzlocal_SearchCentralDir OF(( | 410 | local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); |
| 328 | const zlib_filefunc_def* pzlib_filefunc_def, | 411 | local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) |
| 329 | voidpf filestream)); | ||
| 330 | |||
| 331 | local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | ||
| 332 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 333 | voidpf filestream; | ||
| 334 | { | 412 | { |
| 335 | unsigned char* buf; | 413 | unsigned char* buf; |
| 336 | uLong uSizeFile; | 414 | ZPOS64_T uSizeFile; |
| 337 | uLong uBackRead; | 415 | ZPOS64_T uBackRead; |
| 338 | uLong uMaxBack=0xffff; /* maximum size of global comment */ | 416 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ |
| 339 | uLong uPosFound=0; | 417 | ZPOS64_T uPosFound=0; |
| 340 | 418 | ||
| 341 | if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | 419 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) |
| 342 | return 0; | 420 | return 0; |
| 343 | 421 | ||
| 344 | 422 | ||
| 345 | uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); | 423 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); |
| 346 | 424 | ||
| 347 | if (uMaxBack>uSizeFile) | 425 | if (uMaxBack>uSizeFile) |
| 348 | uMaxBack = uSizeFile; | 426 | uMaxBack = uSizeFile; |
| @@ -354,7 +432,8 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |||
| 354 | uBackRead = 4; | 432 | uBackRead = 4; |
| 355 | while (uBackRead<uMaxBack) | 433 | while (uBackRead<uMaxBack) |
| 356 | { | 434 | { |
| 357 | uLong uReadSize,uReadPos ; | 435 | uLong uReadSize; |
| 436 | ZPOS64_T uReadPos ; | ||
| 358 | int i; | 437 | int i; |
| 359 | if (uBackRead+BUFREADCOMMENT>uMaxBack) | 438 | if (uBackRead+BUFREADCOMMENT>uMaxBack) |
| 360 | uBackRead = uMaxBack; | 439 | uBackRead = uMaxBack; |
| @@ -363,11 +442,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |||
| 363 | uReadPos = uSizeFile-uBackRead ; | 442 | uReadPos = uSizeFile-uBackRead ; |
| 364 | 443 | ||
| 365 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | 444 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? |
| 366 | (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); | 445 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); |
| 367 | if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | 446 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 368 | break; | 447 | break; |
| 369 | 448 | ||
| 370 | if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | 449 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) |
| 371 | break; | 450 | break; |
| 372 | 451 | ||
| 373 | for (i=(int)uReadSize-3; (i--)>0;) | 452 | for (i=(int)uReadSize-3; (i--)>0;) |
| @@ -385,6 +464,112 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |||
| 385 | return uPosFound; | 464 | return uPosFound; |
| 386 | } | 465 | } |
| 387 | 466 | ||
| 467 | |||
| 468 | /* | ||
| 469 | Locate the Central directory 64 of a zipfile (at the end, just before | ||
| 470 | the global comment) | ||
| 471 | */ | ||
| 472 | local ZPOS64_T unz64local_SearchCentralDir64 OF(( | ||
| 473 | const zlib_filefunc64_32_def* pzlib_filefunc_def, | ||
| 474 | voidpf filestream)); | ||
| 475 | |||
| 476 | local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, | ||
| 477 | voidpf filestream) | ||
| 478 | { | ||
| 479 | unsigned char* buf; | ||
| 480 | ZPOS64_T uSizeFile; | ||
| 481 | ZPOS64_T uBackRead; | ||
| 482 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ | ||
| 483 | ZPOS64_T uPosFound=0; | ||
| 484 | uLong uL; | ||
| 485 | ZPOS64_T relativeOffset; | ||
| 486 | |||
| 487 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | ||
| 488 | return 0; | ||
| 489 | |||
| 490 | |||
| 491 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); | ||
| 492 | |||
| 493 | if (uMaxBack>uSizeFile) | ||
| 494 | uMaxBack = uSizeFile; | ||
| 495 | |||
| 496 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | ||
| 497 | if (buf==NULL) | ||
| 498 | return 0; | ||
| 499 | |||
| 500 | uBackRead = 4; | ||
| 501 | while (uBackRead<uMaxBack) | ||
| 502 | { | ||
| 503 | uLong uReadSize; | ||
| 504 | ZPOS64_T uReadPos; | ||
| 505 | int i; | ||
| 506 | if (uBackRead+BUFREADCOMMENT>uMaxBack) | ||
| 507 | uBackRead = uMaxBack; | ||
| 508 | else | ||
| 509 | uBackRead+=BUFREADCOMMENT; | ||
| 510 | uReadPos = uSizeFile-uBackRead ; | ||
| 511 | |||
| 512 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | ||
| 513 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); | ||
| 514 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 515 | break; | ||
| 516 | |||
| 517 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | ||
| 518 | break; | ||
| 519 | |||
| 520 | for (i=(int)uReadSize-3; (i--)>0;) | ||
| 521 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && | ||
| 522 | ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) | ||
| 523 | { | ||
| 524 | uPosFound = uReadPos+i; | ||
| 525 | break; | ||
| 526 | } | ||
| 527 | |||
| 528 | if (uPosFound!=0) | ||
| 529 | break; | ||
| 530 | } | ||
| 531 | TRYFREE(buf); | ||
| 532 | if (uPosFound == 0) | ||
| 533 | return 0; | ||
| 534 | |||
| 535 | /* Zip64 end of central directory locator */ | ||
| 536 | if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 537 | return 0; | ||
| 538 | |||
| 539 | /* the signature, already checked */ | ||
| 540 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) | ||
| 541 | return 0; | ||
| 542 | |||
| 543 | /* number of the disk with the start of the zip64 end of central directory */ | ||
| 544 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) | ||
| 545 | return 0; | ||
| 546 | if (uL != 0) | ||
| 547 | return 0; | ||
| 548 | |||
| 549 | /* relative offset of the zip64 end of central directory record */ | ||
| 550 | if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) | ||
| 551 | return 0; | ||
| 552 | |||
| 553 | /* total number of disks */ | ||
| 554 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) | ||
| 555 | return 0; | ||
| 556 | if (uL != 1) | ||
| 557 | return 0; | ||
| 558 | |||
| 559 | /* Goto end of central directory record */ | ||
| 560 | if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 561 | return 0; | ||
| 562 | |||
| 563 | /* the signature */ | ||
| 564 | if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) | ||
| 565 | return 0; | ||
| 566 | |||
| 567 | if (uL != 0x06064b50) | ||
| 568 | return 0; | ||
| 569 | |||
| 570 | return relativeOffset; | ||
| 571 | } | ||
| 572 | |||
| 388 | /* | 573 | /* |
| 389 | Open a Zip file. path contain the full pathname (by example, | 574 | Open a Zip file. path contain the full pathname (by example, |
| 390 | on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer | 575 | on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer |
| @@ -394,19 +579,20 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) | |||
| 394 | Else, the return value is a unzFile Handle, usable with other function | 579 | Else, the return value is a unzFile Handle, usable with other function |
| 395 | of this unzip package. | 580 | of this unzip package. |
| 396 | */ | 581 | */ |
| 397 | extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) | 582 | local unzFile unzOpenInternal (const void *path, |
| 398 | const char *path; | 583 | zlib_filefunc64_32_def* pzlib_filefunc64_32_def, |
| 399 | zlib_filefunc_def* pzlib_filefunc_def; | 584 | int is64bitOpenFunction) |
| 400 | { | 585 | { |
| 401 | unz_s us; | 586 | unz64_s us; |
| 402 | unz_s *s; | 587 | unz64_s *s; |
| 403 | uLong central_pos,uL; | 588 | ZPOS64_T central_pos; |
| 589 | uLong uL; | ||
| 404 | 590 | ||
| 405 | uLong number_disk; /* number of the current dist, used for | 591 | uLong number_disk; /* number of the current dist, used for |
| 406 | spaning ZIP, unsupported, always 0*/ | 592 | spaning ZIP, unsupported, always 0*/ |
| 407 | uLong number_disk_with_CD; /* number the the disk with central dir, used | 593 | uLong number_disk_with_CD; /* number the the disk with central dir, used |
| 408 | for spaning ZIP, unsupported, always 0*/ | 594 | for spaning ZIP, unsupported, always 0*/ |
| 409 | uLong number_entry_CD; /* total number of entries in | 595 | ZPOS64_T number_entry_CD; /* total number of entries in |
| 410 | the central dir | 596 | the central dir |
| 411 | (same than number_entry on nospan) */ | 597 | (same than number_entry on nospan) */ |
| 412 | 598 | ||
| @@ -415,63 +601,137 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) | |||
| 415 | if (unz_copyright[0]!=' ') | 601 | if (unz_copyright[0]!=' ') |
| 416 | return NULL; | 602 | return NULL; |
| 417 | 603 | ||
| 418 | if (pzlib_filefunc_def==NULL) | 604 | us.z_filefunc.zseek32_file = NULL; |
| 419 | fill_fopen_filefunc(&us.z_filefunc); | 605 | us.z_filefunc.ztell32_file = NULL; |
| 606 | if (pzlib_filefunc64_32_def==NULL) | ||
| 607 | fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); | ||
| 420 | else | 608 | else |
| 421 | us.z_filefunc = *pzlib_filefunc_def; | 609 | us.z_filefunc = *pzlib_filefunc64_32_def; |
| 610 | us.is64bitOpenFunction = is64bitOpenFunction; | ||
| 611 | |||
| 612 | |||
| 422 | 613 | ||
| 423 | us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, | 614 | us.filestream = ZOPEN64(us.z_filefunc, |
| 424 | path, | 615 | path, |
| 425 | ZLIB_FILEFUNC_MODE_READ | | 616 | ZLIB_FILEFUNC_MODE_READ | |
| 426 | ZLIB_FILEFUNC_MODE_EXISTING); | 617 | ZLIB_FILEFUNC_MODE_EXISTING); |
| 427 | if (us.filestream==NULL) | 618 | if (us.filestream==NULL) |
| 428 | return NULL; | 619 | return NULL; |
| 429 | 620 | ||
| 430 | central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); | 621 | central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); |
| 431 | if (central_pos==0) | 622 | if (central_pos) |
| 432 | err=UNZ_ERRNO; | 623 | { |
| 624 | uLong uS; | ||
| 625 | ZPOS64_T uL64; | ||
| 626 | |||
| 627 | us.isZip64 = 1; | ||
| 433 | 628 | ||
| 434 | if (ZSEEK(us.z_filefunc, us.filestream, | 629 | if (ZSEEK64(us.z_filefunc, us.filestream, |
| 435 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | 630 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 436 | err=UNZ_ERRNO; | 631 | err=UNZ_ERRNO; |
| 437 | 632 | ||
| 438 | /* the signature, already checked */ | 633 | /* the signature, already checked */ |
| 439 | if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | 634 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) |
| 440 | err=UNZ_ERRNO; | 635 | err=UNZ_ERRNO; |
| 441 | 636 | ||
| 442 | /* number of this disk */ | 637 | /* size of zip64 end of central directory record */ |
| 443 | if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) | 638 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) |
| 444 | err=UNZ_ERRNO; | 639 | err=UNZ_ERRNO; |
| 445 | 640 | ||
| 446 | /* number of the disk with the start of the central directory */ | 641 | /* version made by */ |
| 447 | if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) | 642 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) |
| 448 | err=UNZ_ERRNO; | 643 | err=UNZ_ERRNO; |
| 449 | 644 | ||
| 450 | /* total number of entries in the central dir on this disk */ | 645 | /* version needed to extract */ |
| 451 | if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) | 646 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) |
| 452 | err=UNZ_ERRNO; | 647 | err=UNZ_ERRNO; |
| 453 | 648 | ||
| 454 | /* total number of entries in the central dir */ | 649 | /* number of this disk */ |
| 455 | if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) | 650 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) |
| 456 | err=UNZ_ERRNO; | 651 | err=UNZ_ERRNO; |
| 457 | 652 | ||
| 458 | if ((number_entry_CD!=us.gi.number_entry) || | 653 | /* number of the disk with the start of the central directory */ |
| 459 | (number_disk_with_CD!=0) || | 654 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) |
| 460 | (number_disk!=0)) | 655 | err=UNZ_ERRNO; |
| 461 | err=UNZ_BADZIPFILE; | ||
| 462 | 656 | ||
| 463 | /* size of the central directory */ | 657 | /* total number of entries in the central directory on this disk */ |
| 464 | if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) | 658 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) |
| 465 | err=UNZ_ERRNO; | 659 | err=UNZ_ERRNO; |
| 660 | |||
| 661 | /* total number of entries in the central directory */ | ||
| 662 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) | ||
| 663 | err=UNZ_ERRNO; | ||
| 664 | |||
| 665 | if ((number_entry_CD!=us.gi.number_entry) || | ||
| 666 | (number_disk_with_CD!=0) || | ||
| 667 | (number_disk!=0)) | ||
| 668 | err=UNZ_BADZIPFILE; | ||
| 669 | |||
| 670 | /* size of the central directory */ | ||
| 671 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) | ||
| 672 | err=UNZ_ERRNO; | ||
| 466 | 673 | ||
| 467 | /* offset of start of central directory with respect to the | 674 | /* offset of start of central directory with respect to the |
| 468 | starting disk number */ | 675 | starting disk number */ |
| 469 | if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) | 676 | if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) |
| 470 | err=UNZ_ERRNO; | 677 | err=UNZ_ERRNO; |
| 471 | 678 | ||
| 472 | /* zipfile comment length */ | 679 | us.gi.size_comment = 0; |
| 473 | if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) | 680 | } |
| 474 | err=UNZ_ERRNO; | 681 | else |
| 682 | { | ||
| 683 | central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); | ||
| 684 | if (central_pos==0) | ||
| 685 | err=UNZ_ERRNO; | ||
| 686 | |||
| 687 | us.isZip64 = 0; | ||
| 688 | |||
| 689 | if (ZSEEK64(us.z_filefunc, us.filestream, | ||
| 690 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 691 | err=UNZ_ERRNO; | ||
| 692 | |||
| 693 | /* the signature, already checked */ | ||
| 694 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | ||
| 695 | err=UNZ_ERRNO; | ||
| 696 | |||
| 697 | /* number of this disk */ | ||
| 698 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) | ||
| 699 | err=UNZ_ERRNO; | ||
| 700 | |||
| 701 | /* number of the disk with the start of the central directory */ | ||
| 702 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) | ||
| 703 | err=UNZ_ERRNO; | ||
| 704 | |||
| 705 | /* total number of entries in the central dir on this disk */ | ||
| 706 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | ||
| 707 | err=UNZ_ERRNO; | ||
| 708 | us.gi.number_entry = uL; | ||
| 709 | |||
| 710 | /* total number of entries in the central dir */ | ||
| 711 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | ||
| 712 | err=UNZ_ERRNO; | ||
| 713 | number_entry_CD = uL; | ||
| 714 | |||
| 715 | if ((number_entry_CD!=us.gi.number_entry) || | ||
| 716 | (number_disk_with_CD!=0) || | ||
| 717 | (number_disk!=0)) | ||
| 718 | err=UNZ_BADZIPFILE; | ||
| 719 | |||
| 720 | /* size of the central directory */ | ||
| 721 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | ||
| 722 | err=UNZ_ERRNO; | ||
| 723 | us.size_central_dir = uL; | ||
| 724 | |||
| 725 | /* offset of start of central directory with respect to the | ||
| 726 | starting disk number */ | ||
| 727 | if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) | ||
| 728 | err=UNZ_ERRNO; | ||
| 729 | us.offset_central_dir = uL; | ||
| 730 | |||
| 731 | /* zipfile comment length */ | ||
| 732 | if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) | ||
| 733 | err=UNZ_ERRNO; | ||
| 734 | } | ||
| 475 | 735 | ||
| 476 | if ((central_pos<us.offset_central_dir+us.size_central_dir) && | 736 | if ((central_pos<us.offset_central_dir+us.size_central_dir) && |
| 477 | (err==UNZ_OK)) | 737 | (err==UNZ_OK)) |
| @@ -479,7 +739,7 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) | |||
| 479 | 739 | ||
| 480 | if (err!=UNZ_OK) | 740 | if (err!=UNZ_OK) |
| 481 | { | 741 | { |
| 482 | ZCLOSE(us.z_filefunc, us.filestream); | 742 | ZCLOSE64(us.z_filefunc, us.filestream); |
| 483 | return NULL; | 743 | return NULL; |
| 484 | } | 744 | } |
| 485 | 745 | ||
| @@ -490,17 +750,52 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) | |||
| 490 | us.encrypted = 0; | 750 | us.encrypted = 0; |
| 491 | 751 | ||
| 492 | 752 | ||
| 493 | s=(unz_s*)ALLOC(sizeof(unz_s)); | 753 | s=(unz64_s*)ALLOC(sizeof(unz64_s)); |
| 494 | *s=us; | 754 | if( s != NULL) |
| 495 | unzGoToFirstFile((unzFile)s); | 755 | { |
| 756 | *s=us; | ||
| 757 | unzGoToFirstFile((unzFile)s); | ||
| 758 | } | ||
| 496 | return (unzFile)s; | 759 | return (unzFile)s; |
| 497 | } | 760 | } |
| 498 | 761 | ||
| 499 | 762 | ||
| 500 | extern unzFile ZEXPORT unzOpen (path) | 763 | extern unzFile ZEXPORT unzOpen2 (const char *path, |
| 501 | const char *path; | 764 | zlib_filefunc_def* pzlib_filefunc32_def) |
| 502 | { | 765 | { |
| 503 | return unzOpen2(path, NULL); | 766 | if (pzlib_filefunc32_def != NULL) |
| 767 | { | ||
| 768 | zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; | ||
| 769 | fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); | ||
| 770 | return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0); | ||
| 771 | } | ||
| 772 | else | ||
| 773 | return unzOpenInternal(path, NULL, 0); | ||
| 774 | } | ||
| 775 | |||
| 776 | extern unzFile ZEXPORT unzOpen2_64 (const void *path, | ||
| 777 | zlib_filefunc64_def* pzlib_filefunc_def) | ||
| 778 | { | ||
| 779 | if (pzlib_filefunc_def != NULL) | ||
| 780 | { | ||
| 781 | zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; | ||
| 782 | zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; | ||
| 783 | zlib_filefunc64_32_def_fill.ztell32_file = NULL; | ||
| 784 | zlib_filefunc64_32_def_fill.zseek32_file = NULL; | ||
| 785 | return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1); | ||
| 786 | } | ||
| 787 | else | ||
| 788 | return unzOpenInternal(path, NULL, 1); | ||
| 789 | } | ||
| 790 | |||
| 791 | extern unzFile ZEXPORT unzOpen (const char *path) | ||
| 792 | { | ||
| 793 | return unzOpenInternal(path, NULL, 0); | ||
| 794 | } | ||
| 795 | |||
| 796 | extern unzFile ZEXPORT unzOpen64 (const void *path) | ||
| 797 | { | ||
| 798 | return unzOpenInternal(path, NULL, 1); | ||
| 504 | } | 799 | } |
| 505 | 800 | ||
| 506 | /* | 801 | /* |
| @@ -508,18 +803,17 @@ extern unzFile ZEXPORT unzOpen (path) | |||
| 508 | If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), | 803 | If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), |
| 509 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. | 804 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. |
| 510 | return UNZ_OK if there is no problem. */ | 805 | return UNZ_OK if there is no problem. */ |
| 511 | extern int ZEXPORT unzClose (file) | 806 | extern int ZEXPORT unzClose (unzFile file) |
| 512 | unzFile file; | ||
| 513 | { | 807 | { |
| 514 | unz_s* s; | 808 | unz64_s* s; |
| 515 | if (file==NULL) | 809 | if (file==NULL) |
| 516 | return UNZ_PARAMERROR; | 810 | return UNZ_PARAMERROR; |
| 517 | s=(unz_s*)file; | 811 | s=(unz64_s*)file; |
| 518 | 812 | ||
| 519 | if (s->pfile_in_zip_read!=NULL) | 813 | if (s->pfile_in_zip_read!=NULL) |
| 520 | unzCloseCurrentFile(file); | 814 | unzCloseCurrentFile(file); |
| 521 | 815 | ||
| 522 | ZCLOSE(s->z_filefunc, s->filestream); | 816 | ZCLOSE64(s->z_filefunc, s->filestream); |
| 523 | TRYFREE(s); | 817 | TRYFREE(s); |
| 524 | return UNZ_OK; | 818 | return UNZ_OK; |
| 525 | } | 819 | } |
| @@ -529,28 +823,34 @@ extern int ZEXPORT unzClose (file) | |||
| 529 | Write info about the ZipFile in the *pglobal_info structure. | 823 | Write info about the ZipFile in the *pglobal_info structure. |
| 530 | No preparation of the structure is needed | 824 | No preparation of the structure is needed |
| 531 | return UNZ_OK if there is no problem. */ | 825 | return UNZ_OK if there is no problem. */ |
| 532 | extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) | 826 | extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) |
| 533 | unzFile file; | ||
| 534 | unz_global_info *pglobal_info; | ||
| 535 | { | 827 | { |
| 536 | unz_s* s; | 828 | unz64_s* s; |
| 537 | if (file==NULL) | 829 | if (file==NULL) |
| 538 | return UNZ_PARAMERROR; | 830 | return UNZ_PARAMERROR; |
| 539 | s=(unz_s*)file; | 831 | s=(unz64_s*)file; |
| 540 | *pglobal_info=s->gi; | 832 | *pglobal_info=s->gi; |
| 541 | return UNZ_OK; | 833 | return UNZ_OK; |
| 542 | } | 834 | } |
| 543 | 835 | ||
| 544 | 836 | extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) | |
| 837 | { | ||
| 838 | unz64_s* s; | ||
| 839 | if (file==NULL) | ||
| 840 | return UNZ_PARAMERROR; | ||
| 841 | s=(unz64_s*)file; | ||
| 842 | /* to do : check if number_entry is not truncated */ | ||
| 843 | pglobal_info32->number_entry = (uLong)s->gi.number_entry; | ||
| 844 | pglobal_info32->size_comment = s->gi.size_comment; | ||
| 845 | return UNZ_OK; | ||
| 846 | } | ||
| 545 | /* | 847 | /* |
| 546 | Translate date/time from Dos format to tm_unz (readable more easilty) | 848 | Translate date/time from Dos format to tm_unz (readable more easilty) |
| 547 | */ | 849 | */ |
| 548 | local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) | 850 | local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) |
| 549 | uLong ulDosDate; | ||
| 550 | tm_unz* ptm; | ||
| 551 | { | 851 | { |
| 552 | uLong uDate; | 852 | ZPOS64_T uDate; |
| 553 | uDate = (uLong)(ulDosDate>>16); | 853 | uDate = (ZPOS64_T)(ulDosDate>>16); |
| 554 | ptm->tm_mday = (uInt)(uDate&0x1f) ; | 854 | ptm->tm_mday = (uInt)(uDate&0x1f) ; |
| 555 | ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; | 855 | ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; |
| 556 | ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; | 856 | ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; |
| @@ -563,9 +863,9 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) | |||
| 563 | /* | 863 | /* |
| 564 | Get Info about the current file in the zipfile, with internal only info | 864 | Get Info about the current file in the zipfile, with internal only info |
| 565 | */ | 865 | */ |
| 566 | local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, | 866 | local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, |
| 567 | unz_file_info *pfile_info, | 867 | unz_file_info64 *pfile_info, |
| 568 | unz_file_info_internal | 868 | unz_file_info64_internal |
| 569 | *pfile_info_internal, | 869 | *pfile_info_internal, |
| 570 | char *szFileName, | 870 | char *szFileName, |
| 571 | uLong fileNameBufferSize, | 871 | uLong fileNameBufferSize, |
| @@ -574,33 +874,29 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, | |||
| 574 | char *szComment, | 874 | char *szComment, |
| 575 | uLong commentBufferSize)); | 875 | uLong commentBufferSize)); |
| 576 | 876 | ||
| 577 | local int unzlocal_GetCurrentFileInfoInternal (file, | 877 | local int unz64local_GetCurrentFileInfoInternal (unzFile file, |
| 578 | pfile_info, | 878 | unz_file_info64 *pfile_info, |
| 579 | pfile_info_internal, | 879 | unz_file_info64_internal |
| 580 | szFileName, fileNameBufferSize, | 880 | *pfile_info_internal, |
| 581 | extraField, extraFieldBufferSize, | 881 | char *szFileName, |
| 582 | szComment, commentBufferSize) | 882 | uLong fileNameBufferSize, |
| 583 | unzFile file; | 883 | void *extraField, |
| 584 | unz_file_info *pfile_info; | 884 | uLong extraFieldBufferSize, |
| 585 | unz_file_info_internal *pfile_info_internal; | 885 | char *szComment, |
| 586 | char *szFileName; | 886 | uLong commentBufferSize) |
| 587 | uLong fileNameBufferSize; | ||
| 588 | void *extraField; | ||
| 589 | uLong extraFieldBufferSize; | ||
| 590 | char *szComment; | ||
| 591 | uLong commentBufferSize; | ||
| 592 | { | 887 | { |
| 593 | unz_s* s; | 888 | unz64_s* s; |
| 594 | unz_file_info file_info; | 889 | unz_file_info64 file_info; |
| 595 | unz_file_info_internal file_info_internal; | 890 | unz_file_info64_internal file_info_internal; |
| 596 | int err=UNZ_OK; | 891 | int err=UNZ_OK; |
| 597 | uLong uMagic; | 892 | uLong uMagic; |
| 598 | long lSeek=0; | 893 | long lSeek=0; |
| 894 | uLong uL; | ||
| 599 | 895 | ||
| 600 | if (file==NULL) | 896 | if (file==NULL) |
| 601 | return UNZ_PARAMERROR; | 897 | return UNZ_PARAMERROR; |
| 602 | s=(unz_s*)file; | 898 | s=(unz64_s*)file; |
| 603 | if (ZSEEK(s->z_filefunc, s->filestream, | 899 | if (ZSEEK64(s->z_filefunc, s->filestream, |
| 604 | s->pos_in_central_dir+s->byte_before_the_zipfile, | 900 | s->pos_in_central_dir+s->byte_before_the_zipfile, |
| 605 | ZLIB_FILEFUNC_SEEK_SET)!=0) | 901 | ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 606 | err=UNZ_ERRNO; | 902 | err=UNZ_ERRNO; |
| @@ -608,57 +904,63 @@ local int unzlocal_GetCurrentFileInfoInternal (file, | |||
| 608 | 904 | ||
| 609 | /* we check the magic */ | 905 | /* we check the magic */ |
| 610 | if (err==UNZ_OK) | 906 | if (err==UNZ_OK) |
| 611 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | 907 | { |
| 908 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | ||
| 612 | err=UNZ_ERRNO; | 909 | err=UNZ_ERRNO; |
| 613 | else if (uMagic!=0x02014b50) | 910 | else if (uMagic!=0x02014b50) |
| 614 | err=UNZ_BADZIPFILE; | 911 | err=UNZ_BADZIPFILE; |
| 912 | } | ||
| 615 | 913 | ||
| 616 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) | 914 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) |
| 617 | err=UNZ_ERRNO; | 915 | err=UNZ_ERRNO; |
| 618 | 916 | ||
| 619 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) | 917 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) |
| 620 | err=UNZ_ERRNO; | 918 | err=UNZ_ERRNO; |
| 621 | 919 | ||
| 622 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) | 920 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) |
| 623 | err=UNZ_ERRNO; | 921 | err=UNZ_ERRNO; |
| 624 | 922 | ||
| 625 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) | 923 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) |
| 626 | err=UNZ_ERRNO; | 924 | err=UNZ_ERRNO; |
| 627 | 925 | ||
| 628 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) | 926 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) |
| 629 | err=UNZ_ERRNO; | 927 | err=UNZ_ERRNO; |
| 630 | 928 | ||
| 631 | unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); | 929 | unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); |
| 632 | 930 | ||
| 633 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) | 931 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) |
| 634 | err=UNZ_ERRNO; | 932 | err=UNZ_ERRNO; |
| 635 | 933 | ||
| 636 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) | 934 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
| 637 | err=UNZ_ERRNO; | 935 | err=UNZ_ERRNO; |
| 936 | file_info.compressed_size = uL; | ||
| 638 | 937 | ||
| 639 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) | 938 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
| 640 | err=UNZ_ERRNO; | 939 | err=UNZ_ERRNO; |
| 940 | file_info.uncompressed_size = uL; | ||
| 641 | 941 | ||
| 642 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) | 942 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) |
| 643 | err=UNZ_ERRNO; | 943 | err=UNZ_ERRNO; |
| 644 | 944 | ||
| 645 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) | 945 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) |
| 646 | err=UNZ_ERRNO; | 946 | err=UNZ_ERRNO; |
| 647 | 947 | ||
| 648 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) | 948 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) |
| 649 | err=UNZ_ERRNO; | 949 | err=UNZ_ERRNO; |
| 650 | 950 | ||
| 651 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) | 951 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) |
| 652 | err=UNZ_ERRNO; | 952 | err=UNZ_ERRNO; |
| 653 | 953 | ||
| 654 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) | 954 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) |
| 655 | err=UNZ_ERRNO; | 955 | err=UNZ_ERRNO; |
| 656 | 956 | ||
| 657 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) | 957 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) |
| 658 | err=UNZ_ERRNO; | 958 | err=UNZ_ERRNO; |
| 659 | 959 | ||
| 660 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) | 960 | // relative offset of local header |
| 961 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) | ||
| 661 | err=UNZ_ERRNO; | 962 | err=UNZ_ERRNO; |
| 963 | file_info_internal.offset_curfile = uL; | ||
| 662 | 964 | ||
| 663 | lSeek+=file_info.size_filename; | 965 | lSeek+=file_info.size_filename; |
| 664 | if ((err==UNZ_OK) && (szFileName!=NULL)) | 966 | if ((err==UNZ_OK) && (szFileName!=NULL)) |
| @@ -673,33 +975,105 @@ local int unzlocal_GetCurrentFileInfoInternal (file, | |||
| 673 | uSizeRead = fileNameBufferSize; | 975 | uSizeRead = fileNameBufferSize; |
| 674 | 976 | ||
| 675 | if ((file_info.size_filename>0) && (fileNameBufferSize>0)) | 977 | if ((file_info.size_filename>0) && (fileNameBufferSize>0)) |
| 676 | if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) | 978 | if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) |
| 677 | err=UNZ_ERRNO; | 979 | err=UNZ_ERRNO; |
| 678 | lSeek -= uSizeRead; | 980 | lSeek -= uSizeRead; |
| 679 | } | 981 | } |
| 680 | 982 | ||
| 681 | 983 | // Read extrafield | |
| 682 | if ((err==UNZ_OK) && (extraField!=NULL)) | 984 | if ((err==UNZ_OK) && (extraField!=NULL)) |
| 683 | { | 985 | { |
| 684 | uLong uSizeRead ; | 986 | ZPOS64_T uSizeRead ; |
| 685 | if (file_info.size_file_extra<extraFieldBufferSize) | 987 | if (file_info.size_file_extra<extraFieldBufferSize) |
| 686 | uSizeRead = file_info.size_file_extra; | 988 | uSizeRead = file_info.size_file_extra; |
| 687 | else | 989 | else |
| 688 | uSizeRead = extraFieldBufferSize; | 990 | uSizeRead = extraFieldBufferSize; |
| 689 | 991 | ||
| 690 | if (lSeek!=0) | 992 | if (lSeek!=0) |
| 691 | if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | 993 | { |
| 994 | if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | ||
| 692 | lSeek=0; | 995 | lSeek=0; |
| 693 | else | 996 | else |
| 694 | err=UNZ_ERRNO; | 997 | err=UNZ_ERRNO; |
| 998 | } | ||
| 999 | |||
| 695 | if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) | 1000 | if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) |
| 696 | if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) | 1001 | if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) |
| 697 | err=UNZ_ERRNO; | 1002 | err=UNZ_ERRNO; |
| 698 | lSeek += file_info.size_file_extra - uSizeRead; | 1003 | |
| 1004 | lSeek += file_info.size_file_extra - (uLong)uSizeRead; | ||
| 699 | } | 1005 | } |
| 700 | else | 1006 | else |
| 701 | lSeek+=file_info.size_file_extra; | 1007 | lSeek += file_info.size_file_extra; |
| 1008 | |||
| 1009 | |||
| 1010 | if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) | ||
| 1011 | { | ||
| 1012 | uLong acc = 0; | ||
| 1013 | |||
| 1014 | // since lSeek now points to after the extra field we need to move back | ||
| 1015 | lSeek -= file_info.size_file_extra; | ||
| 1016 | |||
| 1017 | if (lSeek!=0) | ||
| 1018 | { | ||
| 1019 | if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | ||
| 1020 | lSeek=0; | ||
| 1021 | else | ||
| 1022 | err=UNZ_ERRNO; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | while(acc < file_info.size_file_extra) | ||
| 1026 | { | ||
| 1027 | uLong headerId; | ||
| 1028 | uLong dataSize; | ||
| 702 | 1029 | ||
| 1030 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) | ||
| 1031 | err=UNZ_ERRNO; | ||
| 1032 | |||
| 1033 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) | ||
| 1034 | err=UNZ_ERRNO; | ||
| 1035 | |||
| 1036 | /* ZIP64 extra fields */ | ||
| 1037 | if (headerId == 0x0001) | ||
| 1038 | { | ||
| 1039 | uLong uL; | ||
| 1040 | |||
| 1041 | if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) | ||
| 1042 | { | ||
| 1043 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) | ||
| 1044 | err=UNZ_ERRNO; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) | ||
| 1048 | { | ||
| 1049 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) | ||
| 1050 | err=UNZ_ERRNO; | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) | ||
| 1054 | { | ||
| 1055 | /* Relative Header offset */ | ||
| 1056 | if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) | ||
| 1057 | err=UNZ_ERRNO; | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | if(file_info.disk_num_start == (unsigned long)-1) | ||
| 1061 | { | ||
| 1062 | /* Disk Start Number */ | ||
| 1063 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) | ||
| 1064 | err=UNZ_ERRNO; | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | } | ||
| 1068 | else | ||
| 1069 | { | ||
| 1070 | if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) | ||
| 1071 | err=UNZ_ERRNO; | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | acc += 2 + 2 + dataSize; | ||
| 1075 | } | ||
| 1076 | } | ||
| 703 | 1077 | ||
| 704 | if ((err==UNZ_OK) && (szComment!=NULL)) | 1078 | if ((err==UNZ_OK) && (szComment!=NULL)) |
| 705 | { | 1079 | { |
| @@ -713,18 +1087,22 @@ local int unzlocal_GetCurrentFileInfoInternal (file, | |||
| 713 | uSizeRead = commentBufferSize; | 1087 | uSizeRead = commentBufferSize; |
| 714 | 1088 | ||
| 715 | if (lSeek!=0) | 1089 | if (lSeek!=0) |
| 716 | if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | 1090 | { |
| 1091 | if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) | ||
| 717 | lSeek=0; | 1092 | lSeek=0; |
| 718 | else | 1093 | else |
| 719 | err=UNZ_ERRNO; | 1094 | err=UNZ_ERRNO; |
| 1095 | } | ||
| 1096 | |||
| 720 | if ((file_info.size_file_comment>0) && (commentBufferSize>0)) | 1097 | if ((file_info.size_file_comment>0) && (commentBufferSize>0)) |
| 721 | if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) | 1098 | if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) |
| 722 | err=UNZ_ERRNO; | 1099 | err=UNZ_ERRNO; |
| 723 | lSeek+=file_info.size_file_comment - uSizeRead; | 1100 | lSeek+=file_info.size_file_comment - uSizeRead; |
| 724 | } | 1101 | } |
| 725 | else | 1102 | else |
| 726 | lSeek+=file_info.size_file_comment; | 1103 | lSeek+=file_info.size_file_comment; |
| 727 | 1104 | ||
| 1105 | |||
| 728 | if ((err==UNZ_OK) && (pfile_info!=NULL)) | 1106 | if ((err==UNZ_OK) && (pfile_info!=NULL)) |
| 729 | *pfile_info=file_info; | 1107 | *pfile_info=file_info; |
| 730 | 1108 | ||
| @@ -741,41 +1119,70 @@ local int unzlocal_GetCurrentFileInfoInternal (file, | |||
| 741 | No preparation of the structure is needed | 1119 | No preparation of the structure is needed |
| 742 | return UNZ_OK if there is no problem. | 1120 | return UNZ_OK if there is no problem. |
| 743 | */ | 1121 | */ |
| 744 | extern int ZEXPORT unzGetCurrentFileInfo (file, | 1122 | extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, |
| 745 | pfile_info, | 1123 | unz_file_info64 * pfile_info, |
| 746 | szFileName, fileNameBufferSize, | 1124 | char * szFileName, uLong fileNameBufferSize, |
| 747 | extraField, extraFieldBufferSize, | 1125 | void *extraField, uLong extraFieldBufferSize, |
| 748 | szComment, commentBufferSize) | 1126 | char* szComment, uLong commentBufferSize) |
| 749 | unzFile file; | ||
| 750 | unz_file_info *pfile_info; | ||
| 751 | char *szFileName; | ||
| 752 | uLong fileNameBufferSize; | ||
| 753 | void *extraField; | ||
| 754 | uLong extraFieldBufferSize; | ||
| 755 | char *szComment; | ||
| 756 | uLong commentBufferSize; | ||
| 757 | { | 1127 | { |
| 758 | return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, | 1128 | return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, |
| 759 | szFileName,fileNameBufferSize, | 1129 | szFileName,fileNameBufferSize, |
| 760 | extraField,extraFieldBufferSize, | 1130 | extraField,extraFieldBufferSize, |
| 761 | szComment,commentBufferSize); | 1131 | szComment,commentBufferSize); |
| 762 | } | 1132 | } |
| 763 | 1133 | ||
| 1134 | extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, | ||
| 1135 | unz_file_info * pfile_info, | ||
| 1136 | char * szFileName, uLong fileNameBufferSize, | ||
| 1137 | void *extraField, uLong extraFieldBufferSize, | ||
| 1138 | char* szComment, uLong commentBufferSize) | ||
| 1139 | { | ||
| 1140 | int err; | ||
| 1141 | unz_file_info64 file_info64; | ||
| 1142 | err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, | ||
| 1143 | szFileName,fileNameBufferSize, | ||
| 1144 | extraField,extraFieldBufferSize, | ||
| 1145 | szComment,commentBufferSize); | ||
| 1146 | if (err==UNZ_OK) | ||
| 1147 | { | ||
| 1148 | pfile_info->version = file_info64.version; | ||
| 1149 | pfile_info->version_needed = file_info64.version_needed; | ||
| 1150 | pfile_info->flag = file_info64.flag; | ||
| 1151 | pfile_info->compression_method = file_info64.compression_method; | ||
| 1152 | pfile_info->dosDate = file_info64.dosDate; | ||
| 1153 | pfile_info->crc = file_info64.crc; | ||
| 1154 | |||
| 1155 | pfile_info->size_filename = file_info64.size_filename; | ||
| 1156 | pfile_info->size_file_extra = file_info64.size_file_extra; | ||
| 1157 | pfile_info->size_file_comment = file_info64.size_file_comment; | ||
| 1158 | |||
| 1159 | pfile_info->disk_num_start = file_info64.disk_num_start; | ||
| 1160 | pfile_info->internal_fa = file_info64.internal_fa; | ||
| 1161 | pfile_info->external_fa = file_info64.external_fa; | ||
| 1162 | |||
| 1163 | pfile_info->tmu_date = file_info64.tmu_date, | ||
| 1164 | |||
| 1165 | |||
| 1166 | pfile_info->compressed_size = (uLong)file_info64.compressed_size; | ||
| 1167 | pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; | ||
| 1168 | |||
| 1169 | } | ||
| 1170 | return err; | ||
| 1171 | } | ||
| 764 | /* | 1172 | /* |
| 765 | Set the current file of the zipfile to the first file. | 1173 | Set the current file of the zipfile to the first file. |
| 766 | return UNZ_OK if there is no problem | 1174 | return UNZ_OK if there is no problem |
| 767 | */ | 1175 | */ |
| 768 | extern int ZEXPORT unzGoToFirstFile (file) | 1176 | extern int ZEXPORT unzGoToFirstFile (unzFile file) |
| 769 | unzFile file; | ||
| 770 | { | 1177 | { |
| 771 | int err=UNZ_OK; | 1178 | int err=UNZ_OK; |
| 772 | unz_s* s; | 1179 | unz64_s* s; |
| 773 | if (file==NULL) | 1180 | if (file==NULL) |
| 774 | return UNZ_PARAMERROR; | 1181 | return UNZ_PARAMERROR; |
| 775 | s=(unz_s*)file; | 1182 | s=(unz64_s*)file; |
| 776 | s->pos_in_central_dir=s->offset_central_dir; | 1183 | s->pos_in_central_dir=s->offset_central_dir; |
| 777 | s->num_file=0; | 1184 | s->num_file=0; |
| 778 | err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | 1185 | err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
| 779 | &s->cur_file_info_internal, | 1186 | &s->cur_file_info_internal, |
| 780 | NULL,0,NULL,0,NULL,0); | 1187 | NULL,0,NULL,0,NULL,0); |
| 781 | s->current_file_ok = (err == UNZ_OK); | 1188 | s->current_file_ok = (err == UNZ_OK); |
| @@ -787,15 +1194,14 @@ extern int ZEXPORT unzGoToFirstFile (file) | |||
| 787 | return UNZ_OK if there is no problem | 1194 | return UNZ_OK if there is no problem |
| 788 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. | 1195 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. |
| 789 | */ | 1196 | */ |
| 790 | extern int ZEXPORT unzGoToNextFile (file) | 1197 | extern int ZEXPORT unzGoToNextFile (unzFile file) |
| 791 | unzFile file; | ||
| 792 | { | 1198 | { |
| 793 | unz_s* s; | 1199 | unz64_s* s; |
| 794 | int err; | 1200 | int err; |
| 795 | 1201 | ||
| 796 | if (file==NULL) | 1202 | if (file==NULL) |
| 797 | return UNZ_PARAMERROR; | 1203 | return UNZ_PARAMERROR; |
| 798 | s=(unz_s*)file; | 1204 | s=(unz64_s*)file; |
| 799 | if (!s->current_file_ok) | 1205 | if (!s->current_file_ok) |
| 800 | return UNZ_END_OF_LIST_OF_FILE; | 1206 | return UNZ_END_OF_LIST_OF_FILE; |
| 801 | if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ | 1207 | if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ |
| @@ -805,7 +1211,7 @@ extern int ZEXPORT unzGoToNextFile (file) | |||
| 805 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + | 1211 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + |
| 806 | s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; | 1212 | s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; |
| 807 | s->num_file++; | 1213 | s->num_file++; |
| 808 | err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | 1214 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
| 809 | &s->cur_file_info_internal, | 1215 | &s->cur_file_info_internal, |
| 810 | NULL,0,NULL,0,NULL,0); | 1216 | NULL,0,NULL,0,NULL,0); |
| 811 | s->current_file_ok = (err == UNZ_OK); | 1217 | s->current_file_ok = (err == UNZ_OK); |
| @@ -821,21 +1227,18 @@ extern int ZEXPORT unzGoToNextFile (file) | |||
| 821 | UNZ_OK if the file is found. It becomes the current file. | 1227 | UNZ_OK if the file is found. It becomes the current file. |
| 822 | UNZ_END_OF_LIST_OF_FILE if the file is not found | 1228 | UNZ_END_OF_LIST_OF_FILE if the file is not found |
| 823 | */ | 1229 | */ |
| 824 | extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) | 1230 | extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) |
| 825 | unzFile file; | ||
| 826 | const char *szFileName; | ||
| 827 | int iCaseSensitivity; | ||
| 828 | { | 1231 | { |
| 829 | unz_s* s; | 1232 | unz64_s* s; |
| 830 | int err; | 1233 | int err; |
| 831 | 1234 | ||
| 832 | /* We remember the 'current' position in the file so that we can jump | 1235 | /* We remember the 'current' position in the file so that we can jump |
| 833 | * back there if we fail. | 1236 | * back there if we fail. |
| 834 | */ | 1237 | */ |
| 835 | unz_file_info cur_file_infoSaved; | 1238 | unz_file_info64 cur_file_infoSaved; |
| 836 | unz_file_info_internal cur_file_info_internalSaved; | 1239 | unz_file_info64_internal cur_file_info_internalSaved; |
| 837 | uLong num_fileSaved; | 1240 | ZPOS64_T num_fileSaved; |
| 838 | uLong pos_in_central_dirSaved; | 1241 | ZPOS64_T pos_in_central_dirSaved; |
| 839 | 1242 | ||
| 840 | 1243 | ||
| 841 | if (file==NULL) | 1244 | if (file==NULL) |
| @@ -844,7 +1247,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) | |||
| 844 | if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) | 1247 | if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) |
| 845 | return UNZ_PARAMERROR; | 1248 | return UNZ_PARAMERROR; |
| 846 | 1249 | ||
| 847 | s=(unz_s*)file; | 1250 | s=(unz64_s*)file; |
| 848 | if (!s->current_file_ok) | 1251 | if (!s->current_file_ok) |
| 849 | return UNZ_END_OF_LIST_OF_FILE; | 1252 | return UNZ_END_OF_LIST_OF_FILE; |
| 850 | 1253 | ||
| @@ -859,7 +1262,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) | |||
| 859 | while (err == UNZ_OK) | 1262 | while (err == UNZ_OK) |
| 860 | { | 1263 | { |
| 861 | char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; | 1264 | char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; |
| 862 | err = unzGetCurrentFileInfo(file,NULL, | 1265 | err = unzGetCurrentFileInfo64(file,NULL, |
| 863 | szCurrentFileName,sizeof(szCurrentFileName)-1, | 1266 | szCurrentFileName,sizeof(szCurrentFileName)-1, |
| 864 | NULL,0,NULL,0); | 1267 | NULL,0,NULL,0); |
| 865 | if (err == UNZ_OK) | 1268 | if (err == UNZ_OK) |
| @@ -895,20 +1298,18 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) | |||
| 895 | /* | 1298 | /* |
| 896 | typedef struct unz_file_pos_s | 1299 | typedef struct unz_file_pos_s |
| 897 | { | 1300 | { |
| 898 | uLong pos_in_zip_directory; // offset in file | 1301 | ZPOS64_T pos_in_zip_directory; // offset in file |
| 899 | uLong num_of_file; // # of file | 1302 | ZPOS64_T num_of_file; // # of file |
| 900 | } unz_file_pos; | 1303 | } unz_file_pos; |
| 901 | */ | 1304 | */ |
| 902 | 1305 | ||
| 903 | extern int ZEXPORT unzGetFilePos(file, file_pos) | 1306 | extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) |
| 904 | unzFile file; | ||
| 905 | unz_file_pos* file_pos; | ||
| 906 | { | 1307 | { |
| 907 | unz_s* s; | 1308 | unz64_s* s; |
| 908 | 1309 | ||
| 909 | if (file==NULL || file_pos==NULL) | 1310 | if (file==NULL || file_pos==NULL) |
| 910 | return UNZ_PARAMERROR; | 1311 | return UNZ_PARAMERROR; |
| 911 | s=(unz_s*)file; | 1312 | s=(unz64_s*)file; |
| 912 | if (!s->current_file_ok) | 1313 | if (!s->current_file_ok) |
| 913 | return UNZ_END_OF_LIST_OF_FILE; | 1314 | return UNZ_END_OF_LIST_OF_FILE; |
| 914 | 1315 | ||
| @@ -918,23 +1319,35 @@ extern int ZEXPORT unzGetFilePos(file, file_pos) | |||
| 918 | return UNZ_OK; | 1319 | return UNZ_OK; |
| 919 | } | 1320 | } |
| 920 | 1321 | ||
| 921 | extern int ZEXPORT unzGoToFilePos(file, file_pos) | 1322 | extern int ZEXPORT unzGetFilePos( |
| 922 | unzFile file; | 1323 | unzFile file, |
| 923 | unz_file_pos* file_pos; | 1324 | unz_file_pos* file_pos) |
| 1325 | { | ||
| 1326 | unz64_file_pos file_pos64; | ||
| 1327 | int err = unzGetFilePos64(file,&file_pos64); | ||
| 1328 | if (err==UNZ_OK) | ||
| 1329 | { | ||
| 1330 | file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; | ||
| 1331 | file_pos->num_of_file = (uLong)file_pos64.num_of_file; | ||
| 1332 | } | ||
| 1333 | return err; | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) | ||
| 924 | { | 1337 | { |
| 925 | unz_s* s; | 1338 | unz64_s* s; |
| 926 | int err; | 1339 | int err; |
| 927 | 1340 | ||
| 928 | if (file==NULL || file_pos==NULL) | 1341 | if (file==NULL || file_pos==NULL) |
| 929 | return UNZ_PARAMERROR; | 1342 | return UNZ_PARAMERROR; |
| 930 | s=(unz_s*)file; | 1343 | s=(unz64_s*)file; |
| 931 | 1344 | ||
| 932 | /* jump to the right spot */ | 1345 | /* jump to the right spot */ |
| 933 | s->pos_in_central_dir = file_pos->pos_in_zip_directory; | 1346 | s->pos_in_central_dir = file_pos->pos_in_zip_directory; |
| 934 | s->num_file = file_pos->num_of_file; | 1347 | s->num_file = file_pos->num_of_file; |
| 935 | 1348 | ||
| 936 | /* set the current file */ | 1349 | /* set the current file */ |
| 937 | err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | 1350 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
| 938 | &s->cur_file_info_internal, | 1351 | &s->cur_file_info_internal, |
| 939 | NULL,0,NULL,0,NULL,0); | 1352 | NULL,0,NULL,0,NULL,0); |
| 940 | /* return results */ | 1353 | /* return results */ |
| @@ -942,6 +1355,19 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos) | |||
| 942 | return err; | 1355 | return err; |
| 943 | } | 1356 | } |
| 944 | 1357 | ||
| 1358 | extern int ZEXPORT unzGoToFilePos( | ||
| 1359 | unzFile file, | ||
| 1360 | unz_file_pos* file_pos) | ||
| 1361 | { | ||
| 1362 | unz64_file_pos file_pos64; | ||
| 1363 | if (file_pos == NULL) | ||
| 1364 | return UNZ_PARAMERROR; | ||
| 1365 | |||
| 1366 | file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; | ||
| 1367 | file_pos64.num_of_file = file_pos->num_of_file; | ||
| 1368 | return unzGoToFilePos64(file,&file_pos64); | ||
| 1369 | } | ||
| 1370 | |||
| 945 | /* | 1371 | /* |
| 946 | // Unzip Helper Functions - should be here? | 1372 | // Unzip Helper Functions - should be here? |
| 947 | /////////////////////////////////////////// | 1373 | /////////////////////////////////////////// |
| @@ -954,13 +1380,9 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos) | |||
| 954 | store in *piSizeVar the size of extra info in local header | 1380 | store in *piSizeVar the size of extra info in local header |
| 955 | (filename and size of extra field data) | 1381 | (filename and size of extra field data) |
| 956 | */ | 1382 | */ |
| 957 | local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | 1383 | local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, |
| 958 | poffset_local_extrafield, | 1384 | ZPOS64_T * poffset_local_extrafield, |
| 959 | psize_local_extrafield) | 1385 | uInt * psize_local_extrafield) |
| 960 | unz_s* s; | ||
| 961 | uInt* piSizeVar; | ||
| 962 | uLong *poffset_local_extrafield; | ||
| 963 | uInt *psize_local_extrafield; | ||
| 964 | { | 1386 | { |
| 965 | uLong uMagic,uData,uFlags; | 1387 | uLong uMagic,uData,uFlags; |
| 966 | uLong size_filename; | 1388 | uLong size_filename; |
| @@ -971,65 +1393,66 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | |||
| 971 | *poffset_local_extrafield = 0; | 1393 | *poffset_local_extrafield = 0; |
| 972 | *psize_local_extrafield = 0; | 1394 | *psize_local_extrafield = 0; |
| 973 | 1395 | ||
| 974 | if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + | 1396 | if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + |
| 975 | s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) | 1397 | s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 976 | return UNZ_ERRNO; | 1398 | return UNZ_ERRNO; |
| 977 | 1399 | ||
| 978 | 1400 | ||
| 979 | if (err==UNZ_OK) | 1401 | if (err==UNZ_OK) |
| 980 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | 1402 | { |
| 1403 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) | ||
| 981 | err=UNZ_ERRNO; | 1404 | err=UNZ_ERRNO; |
| 982 | else if (uMagic!=0x04034b50) | 1405 | else if (uMagic!=0x04034b50) |
| 983 | err=UNZ_BADZIPFILE; | 1406 | err=UNZ_BADZIPFILE; |
| 1407 | } | ||
| 984 | 1408 | ||
| 985 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | 1409 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) |
| 986 | err=UNZ_ERRNO; | 1410 | err=UNZ_ERRNO; |
| 987 | /* | 1411 | /* |
| 988 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) | 1412 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) |
| 989 | err=UNZ_BADZIPFILE; | 1413 | err=UNZ_BADZIPFILE; |
| 990 | */ | 1414 | */ |
| 991 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) | 1415 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) |
| 992 | err=UNZ_ERRNO; | 1416 | err=UNZ_ERRNO; |
| 993 | 1417 | ||
| 994 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | 1418 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) |
| 995 | err=UNZ_ERRNO; | 1419 | err=UNZ_ERRNO; |
| 996 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) | 1420 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) |
| 997 | err=UNZ_BADZIPFILE; | 1421 | err=UNZ_BADZIPFILE; |
| 998 | 1422 | ||
| 999 | if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && | 1423 | if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && |
| 1424 | /* #ifdef HAVE_BZIP2 */ | ||
| 1425 | (s->cur_file_info.compression_method!=Z_BZIP2ED) && | ||
| 1426 | /* #endif */ | ||
| 1000 | (s->cur_file_info.compression_method!=Z_DEFLATED)) | 1427 | (s->cur_file_info.compression_method!=Z_DEFLATED)) |
| 1001 | err=UNZ_BADZIPFILE; | 1428 | err=UNZ_BADZIPFILE; |
| 1002 | 1429 | ||
| 1003 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ | 1430 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ |
| 1004 | err=UNZ_ERRNO; | 1431 | err=UNZ_ERRNO; |
| 1005 | 1432 | ||
| 1006 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ | 1433 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ |
| 1007 | err=UNZ_ERRNO; | 1434 | err=UNZ_ERRNO; |
| 1008 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && | 1435 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) |
| 1009 | ((uFlags & 8)==0)) | ||
| 1010 | err=UNZ_BADZIPFILE; | 1436 | err=UNZ_BADZIPFILE; |
| 1011 | 1437 | ||
| 1012 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ | 1438 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ |
| 1013 | err=UNZ_ERRNO; | 1439 | err=UNZ_ERRNO; |
| 1014 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && | 1440 | else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) |
| 1015 | ((uFlags & 8)==0)) | ||
| 1016 | err=UNZ_BADZIPFILE; | 1441 | err=UNZ_BADZIPFILE; |
| 1017 | 1442 | ||
| 1018 | if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ | 1443 | if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ |
| 1019 | err=UNZ_ERRNO; | 1444 | err=UNZ_ERRNO; |
| 1020 | else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && | 1445 | else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) |
| 1021 | ((uFlags & 8)==0)) | ||
| 1022 | err=UNZ_BADZIPFILE; | 1446 | err=UNZ_BADZIPFILE; |
| 1023 | 1447 | ||
| 1024 | 1448 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) | |
| 1025 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) | ||
| 1026 | err=UNZ_ERRNO; | 1449 | err=UNZ_ERRNO; |
| 1027 | else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) | 1450 | else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) |
| 1028 | err=UNZ_BADZIPFILE; | 1451 | err=UNZ_BADZIPFILE; |
| 1029 | 1452 | ||
| 1030 | *piSizeVar += (uInt)size_filename; | 1453 | *piSizeVar += (uInt)size_filename; |
| 1031 | 1454 | ||
| 1032 | if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) | 1455 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) |
| 1033 | err=UNZ_ERRNO; | 1456 | err=UNZ_ERRNO; |
| 1034 | *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + | 1457 | *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + |
| 1035 | SIZEZIPLOCALHEADER + size_filename; | 1458 | SIZEZIPLOCALHEADER + size_filename; |
| @@ -1044,18 +1467,14 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, | |||
| 1044 | Open for reading data the current file in the zipfile. | 1467 | Open for reading data the current file in the zipfile. |
| 1045 | If there is no error and the file is opened, the return value is UNZ_OK. | 1468 | If there is no error and the file is opened, the return value is UNZ_OK. |
| 1046 | */ | 1469 | */ |
| 1047 | extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | 1470 | extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, |
| 1048 | unzFile file; | 1471 | int* level, int raw, const char* password) |
| 1049 | int* method; | ||
| 1050 | int* level; | ||
| 1051 | int raw; | ||
| 1052 | const char* password; | ||
| 1053 | { | 1472 | { |
| 1054 | int err=UNZ_OK; | 1473 | int err=UNZ_OK; |
| 1055 | uInt iSizeVar; | 1474 | uInt iSizeVar; |
| 1056 | unz_s* s; | 1475 | unz64_s* s; |
| 1057 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 1476 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1058 | uLong offset_local_extrafield; /* offset of the local extra field */ | 1477 | ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ |
| 1059 | uInt size_local_extrafield; /* size of the local extra field */ | 1478 | uInt size_local_extrafield; /* size of the local extra field */ |
| 1060 | # ifndef NOUNCRYPT | 1479 | # ifndef NOUNCRYPT |
| 1061 | char source[12]; | 1480 | char source[12]; |
| @@ -1066,19 +1485,17 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |||
| 1066 | 1485 | ||
| 1067 | if (file==NULL) | 1486 | if (file==NULL) |
| 1068 | return UNZ_PARAMERROR; | 1487 | return UNZ_PARAMERROR; |
| 1069 | s=(unz_s*)file; | 1488 | s=(unz64_s*)file; |
| 1070 | if (!s->current_file_ok) | 1489 | if (!s->current_file_ok) |
| 1071 | return UNZ_PARAMERROR; | 1490 | return UNZ_PARAMERROR; |
| 1072 | 1491 | ||
| 1073 | if (s->pfile_in_zip_read != NULL) | 1492 | if (s->pfile_in_zip_read != NULL) |
| 1074 | unzCloseCurrentFile(file); | 1493 | unzCloseCurrentFile(file); |
| 1075 | 1494 | ||
| 1076 | if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, | 1495 | if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) |
| 1077 | &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) | ||
| 1078 | return UNZ_BADZIPFILE; | 1496 | return UNZ_BADZIPFILE; |
| 1079 | 1497 | ||
| 1080 | pfile_in_zip_read_info = (file_in_zip_read_info_s*) | 1498 | pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); |
| 1081 | ALLOC(sizeof(file_in_zip_read_info_s)); | ||
| 1082 | if (pfile_in_zip_read_info==NULL) | 1499 | if (pfile_in_zip_read_info==NULL) |
| 1083 | return UNZ_INTERNALERROR; | 1500 | return UNZ_INTERNALERROR; |
| 1084 | 1501 | ||
| @@ -1111,31 +1528,60 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |||
| 1111 | } | 1528 | } |
| 1112 | 1529 | ||
| 1113 | if ((s->cur_file_info.compression_method!=0) && | 1530 | if ((s->cur_file_info.compression_method!=0) && |
| 1531 | /* #ifdef HAVE_BZIP2 */ | ||
| 1532 | (s->cur_file_info.compression_method!=Z_BZIP2ED) && | ||
| 1533 | /* #endif */ | ||
| 1114 | (s->cur_file_info.compression_method!=Z_DEFLATED)) | 1534 | (s->cur_file_info.compression_method!=Z_DEFLATED)) |
| 1535 | |||
| 1115 | err=UNZ_BADZIPFILE; | 1536 | err=UNZ_BADZIPFILE; |
| 1116 | 1537 | ||
| 1117 | pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; | 1538 | pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; |
| 1118 | pfile_in_zip_read_info->crc32=0; | 1539 | pfile_in_zip_read_info->crc32=0; |
| 1119 | pfile_in_zip_read_info->compression_method = | 1540 | pfile_in_zip_read_info->total_out_64=0; |
| 1120 | s->cur_file_info.compression_method; | 1541 | pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; |
| 1121 | pfile_in_zip_read_info->filestream=s->filestream; | 1542 | pfile_in_zip_read_info->filestream=s->filestream; |
| 1122 | pfile_in_zip_read_info->z_filefunc=s->z_filefunc; | 1543 | pfile_in_zip_read_info->z_filefunc=s->z_filefunc; |
| 1123 | pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; | 1544 | pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; |
| 1124 | 1545 | ||
| 1125 | pfile_in_zip_read_info->stream.total_out = 0; | 1546 | pfile_in_zip_read_info->stream.total_out = 0; |
| 1126 | 1547 | ||
| 1127 | if ((s->cur_file_info.compression_method==Z_DEFLATED) && | 1548 | if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) |
| 1128 | (!raw)) | ||
| 1129 | { | 1549 | { |
| 1550 | #ifdef HAVE_BZIP2 | ||
| 1551 | pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; | ||
| 1552 | pfile_in_zip_read_info->bstream.bzfree = (free_func)0; | ||
| 1553 | pfile_in_zip_read_info->bstream.opaque = (voidpf)0; | ||
| 1554 | pfile_in_zip_read_info->bstream.state = (voidpf)0; | ||
| 1555 | |||
| 1130 | pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; | 1556 | pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; |
| 1131 | pfile_in_zip_read_info->stream.zfree = (free_func)0; | 1557 | pfile_in_zip_read_info->stream.zfree = (free_func)0; |
| 1132 | pfile_in_zip_read_info->stream.opaque = (voidpf)0; | 1558 | pfile_in_zip_read_info->stream.opaque = (voidpf)0; |
| 1133 | pfile_in_zip_read_info->stream.next_in = (voidpf)0; | 1559 | pfile_in_zip_read_info->stream.next_in = (voidpf)0; |
| 1134 | pfile_in_zip_read_info->stream.avail_in = 0; | 1560 | pfile_in_zip_read_info->stream.avail_in = 0; |
| 1135 | 1561 | ||
| 1562 | err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); | ||
| 1563 | if (err == Z_OK) | ||
| 1564 | pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; | ||
| 1565 | else | ||
| 1566 | { | ||
| 1567 | TRYFREE(pfile_in_zip_read_info); | ||
| 1568 | return err; | ||
| 1569 | } | ||
| 1570 | #else | ||
| 1571 | pfile_in_zip_read_info->raw=1; | ||
| 1572 | #endif | ||
| 1573 | } | ||
| 1574 | else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) | ||
| 1575 | { | ||
| 1576 | pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; | ||
| 1577 | pfile_in_zip_read_info->stream.zfree = (free_func)0; | ||
| 1578 | pfile_in_zip_read_info->stream.opaque = (voidpf)0; | ||
| 1579 | pfile_in_zip_read_info->stream.next_in = 0; | ||
| 1580 | pfile_in_zip_read_info->stream.avail_in = 0; | ||
| 1581 | |||
| 1136 | err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); | 1582 | err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); |
| 1137 | if (err == Z_OK) | 1583 | if (err == Z_OK) |
| 1138 | pfile_in_zip_read_info->stream_initialised=1; | 1584 | pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; |
| 1139 | else | 1585 | else |
| 1140 | { | 1586 | { |
| 1141 | TRYFREE(pfile_in_zip_read_info); | 1587 | TRYFREE(pfile_in_zip_read_info); |
| @@ -1162,8 +1608,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |||
| 1162 | pfile_in_zip_read_info->stream.avail_in = (uInt)0; | 1608 | pfile_in_zip_read_info->stream.avail_in = (uInt)0; |
| 1163 | 1609 | ||
| 1164 | s->pfile_in_zip_read = pfile_in_zip_read_info; | 1610 | s->pfile_in_zip_read = pfile_in_zip_read_info; |
| 1165 | 1611 | s->encrypted = 0; | |
| 1166 | s->encrypted = 0; | ||
| 1167 | 1612 | ||
| 1168 | # ifndef NOUNCRYPT | 1613 | # ifndef NOUNCRYPT |
| 1169 | if (password != NULL) | 1614 | if (password != NULL) |
| @@ -1171,12 +1616,12 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |||
| 1171 | int i; | 1616 | int i; |
| 1172 | s->pcrc_32_tab = get_crc_table(); | 1617 | s->pcrc_32_tab = get_crc_table(); |
| 1173 | init_keys(password,s->keys,s->pcrc_32_tab); | 1618 | init_keys(password,s->keys,s->pcrc_32_tab); |
| 1174 | if (ZSEEK(s->z_filefunc, s->filestream, | 1619 | if (ZSEEK64(s->z_filefunc, s->filestream, |
| 1175 | s->pfile_in_zip_read->pos_in_zipfile + | 1620 | s->pfile_in_zip_read->pos_in_zipfile + |
| 1176 | s->pfile_in_zip_read->byte_before_the_zipfile, | 1621 | s->pfile_in_zip_read->byte_before_the_zipfile, |
| 1177 | SEEK_SET)!=0) | 1622 | SEEK_SET)!=0) |
| 1178 | return UNZ_INTERNALERROR; | 1623 | return UNZ_INTERNALERROR; |
| 1179 | if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) | 1624 | if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) |
| 1180 | return UNZ_INTERNALERROR; | 1625 | return UNZ_INTERNALERROR; |
| 1181 | 1626 | ||
| 1182 | for (i = 0; i<12; i++) | 1627 | for (i = 0; i<12; i++) |
| @@ -1191,28 +1636,39 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) | |||
| 1191 | return UNZ_OK; | 1636 | return UNZ_OK; |
| 1192 | } | 1637 | } |
| 1193 | 1638 | ||
| 1194 | extern int ZEXPORT unzOpenCurrentFile (file) | 1639 | extern int ZEXPORT unzOpenCurrentFile (unzFile file) |
| 1195 | unzFile file; | ||
| 1196 | { | 1640 | { |
| 1197 | return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); | 1641 | return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); |
| 1198 | } | 1642 | } |
| 1199 | 1643 | ||
| 1200 | extern int ZEXPORT unzOpenCurrentFilePassword (file, password) | 1644 | extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) |
| 1201 | unzFile file; | ||
| 1202 | const char* password; | ||
| 1203 | { | 1645 | { |
| 1204 | return unzOpenCurrentFile3(file, NULL, NULL, 0, password); | 1646 | return unzOpenCurrentFile3(file, NULL, NULL, 0, password); |
| 1205 | } | 1647 | } |
| 1206 | 1648 | ||
| 1207 | extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) | 1649 | extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) |
| 1208 | unzFile file; | ||
| 1209 | int* method; | ||
| 1210 | int* level; | ||
| 1211 | int raw; | ||
| 1212 | { | 1650 | { |
| 1213 | return unzOpenCurrentFile3(file, method, level, raw, NULL); | 1651 | return unzOpenCurrentFile3(file, method, level, raw, NULL); |
| 1214 | } | 1652 | } |
| 1215 | 1653 | ||
| 1654 | /** Addition for GDAL : START */ | ||
| 1655 | |||
| 1656 | extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) | ||
| 1657 | { | ||
| 1658 | unz64_s* s; | ||
| 1659 | file_in_zip64_read_info_s* pfile_in_zip_read_info; | ||
| 1660 | s=(unz64_s*)file; | ||
| 1661 | if (file==NULL) | ||
| 1662 | return 0; //UNZ_PARAMERROR; | ||
| 1663 | pfile_in_zip_read_info=s->pfile_in_zip_read; | ||
| 1664 | if (pfile_in_zip_read_info==NULL) | ||
| 1665 | return 0; //UNZ_PARAMERROR; | ||
| 1666 | return pfile_in_zip_read_info->pos_in_zipfile + | ||
| 1667 | pfile_in_zip_read_info->byte_before_the_zipfile; | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | /** Addition for GDAL : END */ | ||
| 1671 | |||
| 1216 | /* | 1672 | /* |
| 1217 | Read bytes from the current file. | 1673 | Read bytes from the current file. |
| 1218 | buf contain buffer where data must be copied | 1674 | buf contain buffer where data must be copied |
| @@ -1223,18 +1679,15 @@ extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) | |||
| 1223 | return <0 with error code if there is an error | 1679 | return <0 with error code if there is an error |
| 1224 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) | 1680 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) |
| 1225 | */ | 1681 | */ |
| 1226 | extern int ZEXPORT unzReadCurrentFile (file, buf, len) | 1682 | extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) |
| 1227 | unzFile file; | ||
| 1228 | voidp buf; | ||
| 1229 | unsigned len; | ||
| 1230 | { | 1683 | { |
| 1231 | int err=UNZ_OK; | 1684 | int err=UNZ_OK; |
| 1232 | uInt iRead = 0; | 1685 | uInt iRead = 0; |
| 1233 | unz_s* s; | 1686 | unz64_s* s; |
| 1234 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 1687 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1235 | if (file==NULL) | 1688 | if (file==NULL) |
| 1236 | return UNZ_PARAMERROR; | 1689 | return UNZ_PARAMERROR; |
| 1237 | s=(unz_s*)file; | 1690 | s=(unz64_s*)file; |
| 1238 | pfile_in_zip_read_info=s->pfile_in_zip_read; | 1691 | pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1239 | 1692 | ||
| 1240 | if (pfile_in_zip_read_info==NULL) | 1693 | if (pfile_in_zip_read_info==NULL) |
| @@ -1272,13 +1725,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
| 1272 | uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; | 1725 | uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; |
| 1273 | if (uReadThis == 0) | 1726 | if (uReadThis == 0) |
| 1274 | return UNZ_EOF; | 1727 | return UNZ_EOF; |
| 1275 | if (ZSEEK(pfile_in_zip_read_info->z_filefunc, | 1728 | if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, |
| 1276 | pfile_in_zip_read_info->filestream, | 1729 | pfile_in_zip_read_info->filestream, |
| 1277 | pfile_in_zip_read_info->pos_in_zipfile + | 1730 | pfile_in_zip_read_info->pos_in_zipfile + |
| 1278 | pfile_in_zip_read_info->byte_before_the_zipfile, | 1731 | pfile_in_zip_read_info->byte_before_the_zipfile, |
| 1279 | ZLIB_FILEFUNC_SEEK_SET)!=0) | 1732 | ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1280 | return UNZ_ERRNO; | 1733 | return UNZ_ERRNO; |
| 1281 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, | 1734 | if (ZREAD64(pfile_in_zip_read_info->z_filefunc, |
| 1282 | pfile_in_zip_read_info->filestream, | 1735 | pfile_in_zip_read_info->filestream, |
| 1283 | pfile_in_zip_read_info->read_buffer, | 1736 | pfile_in_zip_read_info->read_buffer, |
| 1284 | uReadThis)!=uReadThis) | 1737 | uReadThis)!=uReadThis) |
| @@ -1324,6 +1777,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
| 1324 | *(pfile_in_zip_read_info->stream.next_out+i) = | 1777 | *(pfile_in_zip_read_info->stream.next_out+i) = |
| 1325 | *(pfile_in_zip_read_info->stream.next_in+i); | 1778 | *(pfile_in_zip_read_info->stream.next_in+i); |
| 1326 | 1779 | ||
| 1780 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; | ||
| 1781 | |||
| 1327 | pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, | 1782 | pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, |
| 1328 | pfile_in_zip_read_info->stream.next_out, | 1783 | pfile_in_zip_read_info->stream.next_out, |
| 1329 | uDoCopy); | 1784 | uDoCopy); |
| @@ -1335,11 +1790,54 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
| 1335 | pfile_in_zip_read_info->stream.total_out += uDoCopy; | 1790 | pfile_in_zip_read_info->stream.total_out += uDoCopy; |
| 1336 | iRead += uDoCopy; | 1791 | iRead += uDoCopy; |
| 1337 | } | 1792 | } |
| 1338 | else | 1793 | else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) |
| 1339 | { | 1794 | { |
| 1795 | #ifdef HAVE_BZIP2 | ||
| 1340 | uLong uTotalOutBefore,uTotalOutAfter; | 1796 | uLong uTotalOutBefore,uTotalOutAfter; |
| 1341 | const Bytef *bufBefore; | 1797 | const Bytef *bufBefore; |
| 1342 | uLong uOutThis; | 1798 | uLong uOutThis; |
| 1799 | |||
| 1800 | pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; | ||
| 1801 | pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; | ||
| 1802 | pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; | ||
| 1803 | pfile_in_zip_read_info->bstream.total_in_hi32 = 0; | ||
| 1804 | pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; | ||
| 1805 | pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; | ||
| 1806 | pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; | ||
| 1807 | pfile_in_zip_read_info->bstream.total_out_hi32 = 0; | ||
| 1808 | |||
| 1809 | uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; | ||
| 1810 | bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; | ||
| 1811 | |||
| 1812 | err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); | ||
| 1813 | |||
| 1814 | uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; | ||
| 1815 | uOutThis = uTotalOutAfter-uTotalOutBefore; | ||
| 1816 | |||
| 1817 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; | ||
| 1818 | |||
| 1819 | pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); | ||
| 1820 | pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; | ||
| 1821 | iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); | ||
| 1822 | |||
| 1823 | pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; | ||
| 1824 | pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; | ||
| 1825 | pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; | ||
| 1826 | pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; | ||
| 1827 | pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; | ||
| 1828 | pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; | ||
| 1829 | |||
| 1830 | if (err==BZ_STREAM_END) | ||
| 1831 | return (iRead==0) ? UNZ_EOF : iRead; | ||
| 1832 | if (err!=BZ_OK) | ||
| 1833 | break; | ||
| 1834 | #endif | ||
| 1835 | } // end Z_BZIP2ED | ||
| 1836 | else | ||
| 1837 | { | ||
| 1838 | ZPOS64_T uTotalOutBefore,uTotalOutAfter; | ||
| 1839 | const Bytef *bufBefore; | ||
| 1840 | ZPOS64_T uOutThis; | ||
| 1343 | int flush=Z_SYNC_FLUSH; | 1841 | int flush=Z_SYNC_FLUSH; |
| 1344 | 1842 | ||
| 1345 | uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; | 1843 | uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; |
| @@ -1359,6 +1857,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
| 1359 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; | 1857 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; |
| 1360 | uOutThis = uTotalOutAfter-uTotalOutBefore; | 1858 | uOutThis = uTotalOutAfter-uTotalOutBefore; |
| 1361 | 1859 | ||
| 1860 | pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; | ||
| 1861 | |||
| 1362 | pfile_in_zip_read_info->crc32 = | 1862 | pfile_in_zip_read_info->crc32 = |
| 1363 | crc32(pfile_in_zip_read_info->crc32,bufBefore, | 1863 | crc32(pfile_in_zip_read_info->crc32,bufBefore, |
| 1364 | (uInt)(uOutThis)); | 1864 | (uInt)(uOutThis)); |
| @@ -1384,14 +1884,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
| 1384 | /* | 1884 | /* |
| 1385 | Give the current position in uncompressed data | 1885 | Give the current position in uncompressed data |
| 1386 | */ | 1886 | */ |
| 1387 | extern z_off_t ZEXPORT unztell (file) | 1887 | extern z_off_t ZEXPORT unztell (unzFile file) |
| 1388 | unzFile file; | ||
| 1389 | { | 1888 | { |
| 1390 | unz_s* s; | 1889 | unz64_s* s; |
| 1391 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 1890 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1392 | if (file==NULL) | 1891 | if (file==NULL) |
| 1393 | return UNZ_PARAMERROR; | 1892 | return UNZ_PARAMERROR; |
| 1394 | s=(unz_s*)file; | 1893 | s=(unz64_s*)file; |
| 1395 | pfile_in_zip_read_info=s->pfile_in_zip_read; | 1894 | pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1396 | 1895 | ||
| 1397 | if (pfile_in_zip_read_info==NULL) | 1896 | if (pfile_in_zip_read_info==NULL) |
| @@ -1400,18 +1899,33 @@ extern z_off_t ZEXPORT unztell (file) | |||
| 1400 | return (z_off_t)pfile_in_zip_read_info->stream.total_out; | 1899 | return (z_off_t)pfile_in_zip_read_info->stream.total_out; |
| 1401 | } | 1900 | } |
| 1402 | 1901 | ||
| 1902 | extern ZPOS64_T ZEXPORT unztell64 (unzFile file) | ||
| 1903 | { | ||
| 1904 | |||
| 1905 | unz64_s* s; | ||
| 1906 | file_in_zip64_read_info_s* pfile_in_zip_read_info; | ||
| 1907 | if (file==NULL) | ||
| 1908 | return (ZPOS64_T)-1; | ||
| 1909 | s=(unz64_s*)file; | ||
| 1910 | pfile_in_zip_read_info=s->pfile_in_zip_read; | ||
| 1911 | |||
| 1912 | if (pfile_in_zip_read_info==NULL) | ||
| 1913 | return (ZPOS64_T)-1; | ||
| 1914 | |||
| 1915 | return pfile_in_zip_read_info->total_out_64; | ||
| 1916 | } | ||
| 1917 | |||
| 1403 | 1918 | ||
| 1404 | /* | 1919 | /* |
| 1405 | return 1 if the end of file was reached, 0 elsewhere | 1920 | return 1 if the end of file was reached, 0 elsewhere |
| 1406 | */ | 1921 | */ |
| 1407 | extern int ZEXPORT unzeof (file) | 1922 | extern int ZEXPORT unzeof (unzFile file) |
| 1408 | unzFile file; | ||
| 1409 | { | 1923 | { |
| 1410 | unz_s* s; | 1924 | unz64_s* s; |
| 1411 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 1925 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1412 | if (file==NULL) | 1926 | if (file==NULL) |
| 1413 | return UNZ_PARAMERROR; | 1927 | return UNZ_PARAMERROR; |
| 1414 | s=(unz_s*)file; | 1928 | s=(unz64_s*)file; |
| 1415 | pfile_in_zip_read_info=s->pfile_in_zip_read; | 1929 | pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1416 | 1930 | ||
| 1417 | if (pfile_in_zip_read_info==NULL) | 1931 | if (pfile_in_zip_read_info==NULL) |
| @@ -1426,9 +1940,9 @@ extern int ZEXPORT unzeof (file) | |||
| 1426 | 1940 | ||
| 1427 | 1941 | ||
| 1428 | /* | 1942 | /* |
| 1429 | Read extra field from the current file (opened by unzOpenCurrentFile) | 1943 | Read extra field from the current file (opened by unzOpenCurrentFile) |
| 1430 | This is the local-header version of the extra field (sometimes, there is | 1944 | This is the local-header version of the extra field (sometimes, there is |
| 1431 | more info in the local-header version than in the central-header) | 1945 | more info in the local-header version than in the central-header) |
| 1432 | 1946 | ||
| 1433 | if buf==NULL, it return the size of the local extra field that can be read | 1947 | if buf==NULL, it return the size of the local extra field that can be read |
| 1434 | 1948 | ||
| @@ -1437,19 +1951,16 @@ extern int ZEXPORT unzeof (file) | |||
| 1437 | the return value is the number of bytes copied in buf, or (if <0) | 1951 | the return value is the number of bytes copied in buf, or (if <0) |
| 1438 | the error code | 1952 | the error code |
| 1439 | */ | 1953 | */ |
| 1440 | extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | 1954 | extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) |
| 1441 | unzFile file; | ||
| 1442 | voidp buf; | ||
| 1443 | unsigned len; | ||
| 1444 | { | 1955 | { |
| 1445 | unz_s* s; | 1956 | unz64_s* s; |
| 1446 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 1957 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1447 | uInt read_now; | 1958 | uInt read_now; |
| 1448 | uLong size_to_read; | 1959 | ZPOS64_T size_to_read; |
| 1449 | 1960 | ||
| 1450 | if (file==NULL) | 1961 | if (file==NULL) |
| 1451 | return UNZ_PARAMERROR; | 1962 | return UNZ_PARAMERROR; |
| 1452 | s=(unz_s*)file; | 1963 | s=(unz64_s*)file; |
| 1453 | pfile_in_zip_read_info=s->pfile_in_zip_read; | 1964 | pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1454 | 1965 | ||
| 1455 | if (pfile_in_zip_read_info==NULL) | 1966 | if (pfile_in_zip_read_info==NULL) |
| @@ -1469,14 +1980,14 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | |||
| 1469 | if (read_now==0) | 1980 | if (read_now==0) |
| 1470 | return 0; | 1981 | return 0; |
| 1471 | 1982 | ||
| 1472 | if (ZSEEK(pfile_in_zip_read_info->z_filefunc, | 1983 | if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, |
| 1473 | pfile_in_zip_read_info->filestream, | 1984 | pfile_in_zip_read_info->filestream, |
| 1474 | pfile_in_zip_read_info->offset_local_extrafield + | 1985 | pfile_in_zip_read_info->offset_local_extrafield + |
| 1475 | pfile_in_zip_read_info->pos_local_extrafield, | 1986 | pfile_in_zip_read_info->pos_local_extrafield, |
| 1476 | ZLIB_FILEFUNC_SEEK_SET)!=0) | 1987 | ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1477 | return UNZ_ERRNO; | 1988 | return UNZ_ERRNO; |
| 1478 | 1989 | ||
| 1479 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, | 1990 | if (ZREAD64(pfile_in_zip_read_info->z_filefunc, |
| 1480 | pfile_in_zip_read_info->filestream, | 1991 | pfile_in_zip_read_info->filestream, |
| 1481 | buf,read_now)!=read_now) | 1992 | buf,read_now)!=read_now) |
| 1482 | return UNZ_ERRNO; | 1993 | return UNZ_ERRNO; |
| @@ -1488,16 +1999,15 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | |||
| 1488 | Close the file in zip opened with unzipOpenCurrentFile | 1999 | Close the file in zip opened with unzipOpenCurrentFile |
| 1489 | Return UNZ_CRCERROR if all the file was read but the CRC is not good | 2000 | Return UNZ_CRCERROR if all the file was read but the CRC is not good |
| 1490 | */ | 2001 | */ |
| 1491 | extern int ZEXPORT unzCloseCurrentFile (file) | 2002 | extern int ZEXPORT unzCloseCurrentFile (unzFile file) |
| 1492 | unzFile file; | ||
| 1493 | { | 2003 | { |
| 1494 | int err=UNZ_OK; | 2004 | int err=UNZ_OK; |
| 1495 | 2005 | ||
| 1496 | unz_s* s; | 2006 | unz64_s* s; |
| 1497 | file_in_zip_read_info_s* pfile_in_zip_read_info; | 2007 | file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1498 | if (file==NULL) | 2008 | if (file==NULL) |
| 1499 | return UNZ_PARAMERROR; | 2009 | return UNZ_PARAMERROR; |
| 1500 | s=(unz_s*)file; | 2010 | s=(unz64_s*)file; |
| 1501 | pfile_in_zip_read_info=s->pfile_in_zip_read; | 2011 | pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1502 | 2012 | ||
| 1503 | if (pfile_in_zip_read_info==NULL) | 2013 | if (pfile_in_zip_read_info==NULL) |
| @@ -1514,8 +2024,13 @@ extern int ZEXPORT unzCloseCurrentFile (file) | |||
| 1514 | 2024 | ||
| 1515 | TRYFREE(pfile_in_zip_read_info->read_buffer); | 2025 | TRYFREE(pfile_in_zip_read_info->read_buffer); |
| 1516 | pfile_in_zip_read_info->read_buffer = NULL; | 2026 | pfile_in_zip_read_info->read_buffer = NULL; |
| 1517 | if (pfile_in_zip_read_info->stream_initialised) | 2027 | if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) |
| 1518 | inflateEnd(&pfile_in_zip_read_info->stream); | 2028 | inflateEnd(&pfile_in_zip_read_info->stream); |
| 2029 | #ifdef HAVE_BZIP2 | ||
| 2030 | else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) | ||
| 2031 | BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); | ||
| 2032 | #endif | ||
| 2033 | |||
| 1519 | 2034 | ||
| 1520 | pfile_in_zip_read_info->stream_initialised = 0; | 2035 | pfile_in_zip_read_info->stream_initialised = 0; |
| 1521 | TRYFREE(pfile_in_zip_read_info); | 2036 | TRYFREE(pfile_in_zip_read_info); |
| @@ -1531,29 +2046,25 @@ extern int ZEXPORT unzCloseCurrentFile (file) | |||
| 1531 | uSizeBuf is the size of the szComment buffer. | 2046 | uSizeBuf is the size of the szComment buffer. |
| 1532 | return the number of byte copied or an error code <0 | 2047 | return the number of byte copied or an error code <0 |
| 1533 | */ | 2048 | */ |
| 1534 | extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) | 2049 | extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) |
| 1535 | unzFile file; | ||
| 1536 | char *szComment; | ||
| 1537 | uLong uSizeBuf; | ||
| 1538 | { | 2050 | { |
| 1539 | int err=UNZ_OK; | 2051 | unz64_s* s; |
| 1540 | unz_s* s; | ||
| 1541 | uLong uReadThis ; | 2052 | uLong uReadThis ; |
| 1542 | if (file==NULL) | 2053 | if (file==NULL) |
| 1543 | return UNZ_PARAMERROR; | 2054 | return (uLong)UNZ_PARAMERROR; |
| 1544 | s=(unz_s*)file; | 2055 | s=(unz64_s*)file; |
| 1545 | 2056 | ||
| 1546 | uReadThis = uSizeBuf; | 2057 | uReadThis = uSizeBuf; |
| 1547 | if (uReadThis>s->gi.size_comment) | 2058 | if (uReadThis>s->gi.size_comment) |
| 1548 | uReadThis = s->gi.size_comment; | 2059 | uReadThis = s->gi.size_comment; |
| 1549 | 2060 | ||
| 1550 | if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) | 2061 | if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1551 | return UNZ_ERRNO; | 2062 | return UNZ_ERRNO; |
| 1552 | 2063 | ||
| 1553 | if (uReadThis>0) | 2064 | if (uReadThis>0) |
| 1554 | { | 2065 | { |
| 1555 | *szComment='\0'; | 2066 | *szComment='\0'; |
| 1556 | if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) | 2067 | if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) |
| 1557 | return UNZ_ERRNO; | 2068 | return UNZ_ERRNO; |
| 1558 | } | 2069 | } |
| 1559 | 2070 | ||
| @@ -1563,14 +2074,13 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) | |||
| 1563 | } | 2074 | } |
| 1564 | 2075 | ||
| 1565 | /* Additions by RX '2004 */ | 2076 | /* Additions by RX '2004 */ |
| 1566 | extern uLong ZEXPORT unzGetOffset (file) | 2077 | extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) |
| 1567 | unzFile file; | ||
| 1568 | { | 2078 | { |
| 1569 | unz_s* s; | 2079 | unz64_s* s; |
| 1570 | 2080 | ||
| 1571 | if (file==NULL) | 2081 | if (file==NULL) |
| 1572 | return UNZ_PARAMERROR; | 2082 | return 0; //UNZ_PARAMERROR; |
| 1573 | s=(unz_s*)file; | 2083 | s=(unz64_s*)file; |
| 1574 | if (!s->current_file_ok) | 2084 | if (!s->current_file_ok) |
| 1575 | return 0; | 2085 | return 0; |
| 1576 | if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) | 2086 | if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) |
| @@ -1579,22 +2089,35 @@ extern uLong ZEXPORT unzGetOffset (file) | |||
| 1579 | return s->pos_in_central_dir; | 2089 | return s->pos_in_central_dir; |
| 1580 | } | 2090 | } |
| 1581 | 2091 | ||
| 1582 | extern int ZEXPORT unzSetOffset (file, pos) | 2092 | extern uLong ZEXPORT unzGetOffset (unzFile file) |
| 1583 | unzFile file; | 2093 | { |
| 1584 | uLong pos; | 2094 | ZPOS64_T offset64; |
| 2095 | |||
| 2096 | if (file==NULL) | ||
| 2097 | return 0; //UNZ_PARAMERROR; | ||
| 2098 | offset64 = unzGetOffset64(file); | ||
| 2099 | return (uLong)offset64; | ||
| 2100 | } | ||
| 2101 | |||
| 2102 | extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) | ||
| 1585 | { | 2103 | { |
| 1586 | unz_s* s; | 2104 | unz64_s* s; |
| 1587 | int err; | 2105 | int err; |
| 1588 | 2106 | ||
| 1589 | if (file==NULL) | 2107 | if (file==NULL) |
| 1590 | return UNZ_PARAMERROR; | 2108 | return UNZ_PARAMERROR; |
| 1591 | s=(unz_s*)file; | 2109 | s=(unz64_s*)file; |
| 1592 | 2110 | ||
| 1593 | s->pos_in_central_dir = pos; | 2111 | s->pos_in_central_dir = pos; |
| 1594 | s->num_file = s->gi.number_entry; /* hack */ | 2112 | s->num_file = s->gi.number_entry; /* hack */ |
| 1595 | err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | 2113 | err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
| 1596 | &s->cur_file_info_internal, | 2114 | &s->cur_file_info_internal, |
| 1597 | NULL,0,NULL,0,NULL,0); | 2115 | NULL,0,NULL,0,NULL,0); |
| 1598 | s->current_file_ok = (err == UNZ_OK); | 2116 | s->current_file_ok = (err == UNZ_OK); |
| 1599 | return err; | 2117 | return err; |
| 1600 | } | 2118 | } |
| 2119 | |||
| 2120 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) | ||
| 2121 | { | ||
| 2122 | return unzSetOffset64(file,pos); | ||
| 2123 | } | ||
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h index b247937..a2e698f 100644 --- a/contrib/minizip/unzip.h +++ b/contrib/minizip/unzip.h | |||
| @@ -1,20 +1,20 @@ | |||
| 1 | /* unzip.h -- IO for uncompress .zip files using zlib | 1 | /* unzip.h -- IO for uncompress .zip files using zlib |
| 2 | Version 1.01e, February 12th, 2005 | 2 | Version 1.1, January 7th, 2010 |
| 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 3 | 4 | ||
| 4 | Copyright (C) 1998-2005 Gilles Vollant | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
| 5 | 6 | ||
| 6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g | 7 | Modifications of Unzip for Zip64 |
| 7 | WinZip, InfoZip tools and compatible. | 8 | Copyright (C) 2007-2008 Even Rouault |
| 8 | 9 | ||
| 9 | Multi volume ZipFile (span) are not supported. | 10 | Modifications for Zip64 support on both zip and unzip |
| 10 | Encryption compatible with pkzip 2.04g only supported | 11 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) |
| 11 | Old compressions used by old PKZip 1.x are not supported | ||
| 12 | 12 | ||
| 13 | For more info read MiniZip_info.txt | ||
| 13 | 14 | ||
| 14 | I WAIT FEEDBACK at mail info@winimage.com | 15 | --------------------------------------------------------------------------------- |
| 15 | Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution | 16 | |
| 16 | 17 | Condition of use and distribution are the same than zlib : | |
| 17 | Condition of use and distribution are the same than zlib : | ||
| 18 | 18 | ||
| 19 | This software is provided 'as-is', without any express or implied | 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 | 20 | warranty. In no event will the authors be held liable for any damages |
| @@ -32,18 +32,16 @@ | |||
| 32 | misrepresented as being the original software. | 32 | misrepresented as being the original software. |
| 33 | 3. This notice may not be removed or altered from any source distribution. | 33 | 3. This notice may not be removed or altered from any source distribution. |
| 34 | 34 | ||
| 35 | --------------------------------------------------------------------------------- | ||
| 35 | 36 | ||
| 36 | */ | 37 | Changes |
| 38 | |||
| 39 | See header of unzip64.c | ||
| 37 | 40 | ||
| 38 | /* for more info about .ZIP format, see | ||
| 39 | http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip | ||
| 40 | http://www.info-zip.org/pub/infozip/doc/ | ||
| 41 | PkWare has also a specification at : | ||
| 42 | ftp://ftp.pkware.com/probdesc.zip | ||
| 43 | */ | 41 | */ |
| 44 | 42 | ||
| 45 | #ifndef _unz_H | 43 | #ifndef _unz64_H |
| 46 | #define _unz_H | 44 | #define _unz64_H |
| 47 | 45 | ||
| 48 | #ifdef __cplusplus | 46 | #ifdef __cplusplus |
| 49 | extern "C" { | 47 | extern "C" { |
| @@ -53,10 +51,16 @@ extern "C" { | |||
| 53 | #include "zlib.h" | 51 | #include "zlib.h" |
| 54 | #endif | 52 | #endif |
| 55 | 53 | ||
| 56 | #ifndef _ZLIBIOAPI_H | 54 | #ifndef _ZLIBIOAPI_H |
| 57 | #include "ioapi.h" | 55 | #include "ioapi.h" |
| 58 | #endif | 56 | #endif |
| 59 | 57 | ||
| 58 | #ifdef HAVE_BZIP2 | ||
| 59 | #include "bzlib.h" | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #define Z_BZIP2ED 12 | ||
| 63 | |||
| 60 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) | 64 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) |
| 61 | /* like the STRICT of WIN32, we define a pointer that cannot be converted | 65 | /* like the STRICT of WIN32, we define a pointer that cannot be converted |
| 62 | from (void*) without cast */ | 66 | from (void*) without cast */ |
| @@ -89,15 +93,42 @@ typedef struct tm_unz_s | |||
| 89 | 93 | ||
| 90 | /* unz_global_info structure contain global data about the ZIPfile | 94 | /* unz_global_info structure contain global data about the ZIPfile |
| 91 | These data comes from the end of central dir */ | 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 | |||
| 92 | typedef struct unz_global_info_s | 103 | typedef struct unz_global_info_s |
| 93 | { | 104 | { |
| 94 | uLong number_entry; /* total number of entries in | 105 | uLong number_entry; /* total number of entries in |
| 95 | the central dir on this disk */ | 106 | the central dir on this disk */ |
| 96 | uLong size_comment; /* size of the global comment of the zipfile */ | 107 | uLong size_comment; /* size of the global comment of the zipfile */ |
| 97 | } unz_global_info; | 108 | } unz_global_info; |
| 98 | 109 | ||
| 99 | |||
| 100 | /* unz_file_info contain information about a file in the zipfile */ | 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 | |||
| 101 | typedef struct unz_file_info_s | 132 | typedef struct unz_file_info_s |
| 102 | { | 133 | { |
| 103 | uLong version; /* version made by 2 bytes */ | 134 | uLong version; /* version made by 2 bytes */ |
| @@ -133,6 +164,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, | |||
| 133 | 164 | ||
| 134 | 165 | ||
| 135 | extern unzFile ZEXPORT unzOpen OF((const char *path)); | 166 | extern unzFile ZEXPORT unzOpen OF((const char *path)); |
| 167 | extern unzFile ZEXPORT unzOpen64 OF((const void *path)); | ||
| 136 | /* | 168 | /* |
| 137 | Open a Zip file. path contain the full pathname (by example, | 169 | Open a Zip file. path contain the full pathname (by example, |
| 138 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer | 170 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer |
| @@ -141,8 +173,14 @@ extern unzFile ZEXPORT unzOpen OF((const char *path)); | |||
| 141 | return value is NULL. | 173 | return value is NULL. |
| 142 | Else, the return value is a unzFile Handle, usable with other function | 174 | Else, the return value is a unzFile Handle, usable with other function |
| 143 | of this unzip package. | 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 | ||
| 144 | */ | 181 | */ |
| 145 | 182 | ||
| 183 | |||
| 146 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, | 184 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, |
| 147 | zlib_filefunc_def* pzlib_filefunc_def)); | 185 | zlib_filefunc_def* pzlib_filefunc_def)); |
| 148 | /* | 186 | /* |
| @@ -150,6 +188,13 @@ extern unzFile ZEXPORT unzOpen2 OF((const char *path, | |||
| 150 | for read/write the zip file (see ioapi.h) | 188 | for read/write the zip file (see ioapi.h) |
| 151 | */ | 189 | */ |
| 152 | 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 | |||
| 153 | extern int ZEXPORT unzClose OF((unzFile file)); | 198 | extern int ZEXPORT unzClose OF((unzFile file)); |
| 154 | /* | 199 | /* |
| 155 | Close a ZipFile opened with unzipOpen. | 200 | Close a ZipFile opened with unzipOpen. |
| @@ -159,6 +204,9 @@ extern int ZEXPORT unzClose OF((unzFile file)); | |||
| 159 | 204 | ||
| 160 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, | 205 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, |
| 161 | unz_global_info *pglobal_info)); | 206 | unz_global_info *pglobal_info)); |
| 207 | |||
| 208 | extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, | ||
| 209 | unz_global_info64 *pglobal_info)); | ||
| 162 | /* | 210 | /* |
| 163 | Write info about the ZipFile in the *pglobal_info structure. | 211 | Write info about the ZipFile in the *pglobal_info structure. |
| 164 | No preparation of the structure is needed | 212 | No preparation of the structure is needed |
| @@ -221,8 +269,31 @@ extern int ZEXPORT unzGoToFilePos( | |||
| 221 | unzFile file, | 269 | unzFile file, |
| 222 | unz_file_pos* file_pos); | 270 | unz_file_pos* file_pos); |
| 223 | 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 | |||
| 224 | /* ****************************************** */ | 286 | /* ****************************************** */ |
| 225 | 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 | |||
| 226 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, | 297 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, |
| 227 | unz_file_info *pfile_info, | 298 | unz_file_info *pfile_info, |
| 228 | char *szFileName, | 299 | char *szFileName, |
| @@ -244,6 +315,14 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, | |||
| 244 | (commentBufferSize is the size of the buffer) | 315 | (commentBufferSize is the size of the buffer) |
| 245 | */ | 316 | */ |
| 246 | 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 | |||
| 247 | /***************************************************************************/ | 326 | /***************************************************************************/ |
| 248 | /* for reading the content of the current zipfile, you can open it, read data | 327 | /* for reading the content of the current zipfile, you can open it, read data |
| 249 | from it, and close it (you can close it before reading all the file) | 328 | from it, and close it (you can close it before reading all the file) |
| @@ -312,6 +391,8 @@ extern int ZEXPORT unzReadCurrentFile OF((unzFile file, | |||
| 312 | */ | 391 | */ |
| 313 | 392 | ||
| 314 | extern z_off_t ZEXPORT unztell OF((unzFile file)); | 393 | extern z_off_t ZEXPORT unztell OF((unzFile file)); |
| 394 | |||
| 395 | extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); | ||
| 315 | /* | 396 | /* |
| 316 | Give the current position in uncompressed data | 397 | Give the current position in uncompressed data |
| 317 | */ | 398 | */ |
| @@ -340,9 +421,11 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, | |||
| 340 | /***************************************************************************/ | 421 | /***************************************************************************/ |
| 341 | 422 | ||
| 342 | /* Get the current file offset */ | 423 | /* Get the current file offset */ |
| 424 | extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); | ||
| 343 | extern uLong ZEXPORT unzGetOffset (unzFile file); | 425 | extern uLong ZEXPORT unzGetOffset (unzFile file); |
| 344 | 426 | ||
| 345 | /* Set the current file offset */ | 427 | /* Set the current file offset */ |
| 428 | extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); | ||
| 346 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); | 429 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); |
| 347 | 430 | ||
| 348 | 431 | ||
| @@ -351,4 +434,4 @@ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); | |||
| 351 | } | 434 | } |
| 352 | #endif | 435 | #endif |
| 353 | 436 | ||
| 354 | #endif /* _unz_H */ | 437 | #endif /* _unz64_H */ |
diff --git a/contrib/minizip/zconf.h b/contrib/minizip/zconf.h new file mode 100644 index 0000000..03a9431 --- /dev/null +++ b/contrib/minizip/zconf.h | |||
| @@ -0,0 +1,332 @@ | |||
| 1 | /* zconf.h -- configuration of the zlib compression library | ||
| 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 | #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 | */ | ||
| 15 | #ifdef Z_PREFIX | ||
| 16 | # define deflateInit_ z_deflateInit_ | ||
| 17 | # define deflate z_deflate | ||
| 18 | # define deflateEnd z_deflateEnd | ||
| 19 | # define inflateInit_ z_inflateInit_ | ||
| 20 | # define inflate z_inflate | ||
| 21 | # define inflateEnd z_inflateEnd | ||
| 22 | # define deflateInit2_ z_deflateInit2_ | ||
| 23 | # define deflateSetDictionary z_deflateSetDictionary | ||
| 24 | # define deflateCopy z_deflateCopy | ||
| 25 | # define deflateReset z_deflateReset | ||
| 26 | # define deflateParams z_deflateParams | ||
| 27 | # define deflateBound z_deflateBound | ||
| 28 | # define deflatePrime z_deflatePrime | ||
| 29 | # define inflateInit2_ z_inflateInit2_ | ||
| 30 | # define inflateSetDictionary z_inflateSetDictionary | ||
| 31 | # define inflateSync z_inflateSync | ||
| 32 | # define inflateSyncPoint z_inflateSyncPoint | ||
| 33 | # define inflateCopy z_inflateCopy | ||
| 34 | # define inflateReset z_inflateReset | ||
| 35 | # define inflateBack z_inflateBack | ||
| 36 | # define inflateBackEnd z_inflateBackEnd | ||
| 37 | # define compress z_compress | ||
| 38 | # define compress2 z_compress2 | ||
| 39 | # define compressBound z_compressBound | ||
| 40 | # define uncompress z_uncompress | ||
| 41 | # define adler32 z_adler32 | ||
| 42 | # define crc32 z_crc32 | ||
| 43 | # define get_crc_table z_get_crc_table | ||
| 44 | # define zError z_zError | ||
| 45 | |||
| 46 | # define alloc_func z_alloc_func | ||
| 47 | # define free_func z_free_func | ||
| 48 | # define in_func z_in_func | ||
| 49 | # define out_func z_out_func | ||
| 50 | # define Byte z_Byte | ||
| 51 | # define uInt z_uInt | ||
| 52 | # define uLong z_uLong | ||
| 53 | # define Bytef z_Bytef | ||
| 54 | # define charf z_charf | ||
| 55 | # define intf z_intf | ||
| 56 | # define uIntf z_uIntf | ||
| 57 | # define uLongf z_uLongf | ||
| 58 | # define voidpf z_voidpf | ||
| 59 | # define voidp z_voidp | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #if defined(__MSDOS__) && !defined(MSDOS) | ||
| 63 | # define MSDOS | ||
| 64 | #endif | ||
| 65 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) | ||
| 66 | # define OS2 | ||
| 67 | #endif | ||
| 68 | #if defined(_WINDOWS) && !defined(WINDOWS) | ||
| 69 | # define WINDOWS | ||
| 70 | #endif | ||
| 71 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) | ||
| 72 | # ifndef WIN32 | ||
| 73 | # define WIN32 | ||
| 74 | # endif | ||
| 75 | #endif | ||
| 76 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) | ||
| 77 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) | ||
| 78 | # ifndef SYS16BIT | ||
| 79 | # define SYS16BIT | ||
| 80 | # endif | ||
| 81 | # endif | ||
| 82 | #endif | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more | ||
| 86 | * than 64k bytes at a time (needed on systems with 16-bit int). | ||
| 87 | */ | ||
| 88 | #ifdef SYS16BIT | ||
| 89 | # define MAXSEG_64K | ||
| 90 | #endif | ||
| 91 | #ifdef MSDOS | ||
| 92 | # define UNALIGNED_OK | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #ifdef __STDC_VERSION__ | ||
| 96 | # ifndef STDC | ||
| 97 | # define STDC | ||
| 98 | # endif | ||
| 99 | # if __STDC_VERSION__ >= 199901L | ||
| 100 | # ifndef STDC99 | ||
| 101 | # define STDC99 | ||
| 102 | # endif | ||
| 103 | # endif | ||
| 104 | #endif | ||
| 105 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) | ||
| 106 | # define STDC | ||
| 107 | #endif | ||
| 108 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) | ||
| 109 | # define STDC | ||
| 110 | #endif | ||
| 111 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) | ||
| 112 | # define STDC | ||
| 113 | #endif | ||
| 114 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) | ||
| 115 | # define STDC | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ | ||
| 119 | # define STDC | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef STDC | ||
| 123 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ | ||
| 124 | # define const /* note: need a more gentle solution here */ | ||
| 125 | # endif | ||
| 126 | #endif | ||
| 127 | |||
| 128 | /* Some Mac compilers merge all .h files incorrectly: */ | ||
| 129 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) | ||
| 130 | # define NO_DUMMY_DECL | ||
| 131 | #endif | ||
| 132 | |||
| 133 | /* Maximum value for memLevel in deflateInit2 */ | ||
| 134 | #ifndef MAX_MEM_LEVEL | ||
| 135 | # ifdef MAXSEG_64K | ||
| 136 | # define MAX_MEM_LEVEL 8 | ||
| 137 | # else | ||
| 138 | # define MAX_MEM_LEVEL 9 | ||
| 139 | # endif | ||
| 140 | #endif | ||
| 141 | |||
| 142 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. | ||
| 143 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files | ||
| 144 | * created by gzip. (Files created by minigzip can still be extracted by | ||
| 145 | * gzip.) | ||
| 146 | */ | ||
| 147 | #ifndef MAX_WBITS | ||
| 148 | # define MAX_WBITS 15 /* 32K LZ77 window */ | ||
| 149 | #endif | ||
| 150 | |||
| 151 | /* The memory requirements for deflate are (in bytes): | ||
| 152 | (1 << (windowBits+2)) + (1 << (memLevel+9)) | ||
| 153 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) | ||
| 154 | plus a few kilobytes for small objects. For example, if you want to reduce | ||
| 155 | the default memory requirements from 256K to 128K, compile with | ||
| 156 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" | ||
| 157 | Of course this will generally degrade compression (there's no free lunch). | ||
| 158 | |||
| 159 | The memory requirements for inflate are (in bytes) 1 << windowBits | ||
| 160 | that is, 32K for windowBits=15 (default value) plus a few kilobytes | ||
| 161 | for small objects. | ||
| 162 | */ | ||
| 163 | |||
| 164 | /* Type declarations */ | ||
| 165 | |||
| 166 | #ifndef OF /* function prototypes */ | ||
| 167 | # ifdef STDC | ||
| 168 | # define OF(args) args | ||
| 169 | # else | ||
| 170 | # define OF(args) () | ||
| 171 | # endif | ||
| 172 | #endif | ||
| 173 | |||
| 174 | /* The following definitions for FAR are needed only for MSDOS mixed | ||
| 175 | * model programming (small or medium model with some far allocations). | ||
| 176 | * This was tested only with MSC; for other MSDOS compilers you may have | ||
| 177 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, | ||
| 178 | * just define FAR to be empty. | ||
| 179 | */ | ||
| 180 | #ifdef SYS16BIT | ||
| 181 | # if defined(M_I86SM) || defined(M_I86MM) | ||
| 182 | /* MSC small or medium model */ | ||
| 183 | # define SMALL_MEDIUM | ||
| 184 | # ifdef _MSC_VER | ||
| 185 | # define FAR _far | ||
| 186 | # else | ||
| 187 | # define FAR far | ||
| 188 | # endif | ||
| 189 | # endif | ||
| 190 | # if (defined(__SMALL__) || defined(__MEDIUM__)) | ||
| 191 | /* Turbo C small or medium model */ | ||
| 192 | # define SMALL_MEDIUM | ||
| 193 | # ifdef __BORLANDC__ | ||
| 194 | # define FAR _far | ||
| 195 | # else | ||
| 196 | # define FAR far | ||
| 197 | # endif | ||
| 198 | # endif | ||
| 199 | #endif | ||
| 200 | |||
| 201 | #if defined(WINDOWS) || defined(WIN32) | ||
| 202 | /* If building or using zlib as a DLL, define ZLIB_DLL. | ||
| 203 | * This is not mandatory, but it offers a little performance increase. | ||
| 204 | */ | ||
| 205 | # ifdef ZLIB_DLL | ||
| 206 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) | ||
| 207 | # ifdef ZLIB_INTERNAL | ||
| 208 | # define ZEXTERN extern __declspec(dllexport) | ||
| 209 | # else | ||
| 210 | # define ZEXTERN extern __declspec(dllimport) | ||
| 211 | # endif | ||
| 212 | # endif | ||
| 213 | # endif /* ZLIB_DLL */ | ||
| 214 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, | ||
| 215 | * define ZLIB_WINAPI. | ||
| 216 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. | ||
| 217 | */ | ||
| 218 | # ifdef ZLIB_WINAPI | ||
| 219 | # ifdef FAR | ||
| 220 | # undef FAR | ||
| 221 | # endif | ||
| 222 | # include <windows.h> | ||
| 223 | /* No need for _export, use ZLIB.DEF instead. */ | ||
| 224 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ | ||
| 225 | # define ZEXPORT WINAPI | ||
| 226 | # ifdef WIN32 | ||
| 227 | # define ZEXPORTVA WINAPIV | ||
| 228 | # else | ||
| 229 | # define ZEXPORTVA FAR CDECL | ||
| 230 | # endif | ||
| 231 | # endif | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if defined (__BEOS__) | ||
| 235 | # ifdef ZLIB_DLL | ||
| 236 | # ifdef ZLIB_INTERNAL | ||
| 237 | # define ZEXPORT __declspec(dllexport) | ||
| 238 | # define ZEXPORTVA __declspec(dllexport) | ||
| 239 | # else | ||
| 240 | # define ZEXPORT __declspec(dllimport) | ||
| 241 | # define ZEXPORTVA __declspec(dllimport) | ||
| 242 | # endif | ||
| 243 | # endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifndef ZEXTERN | ||
| 247 | # define ZEXTERN extern | ||
| 248 | #endif | ||
| 249 | #ifndef ZEXPORT | ||
| 250 | # define ZEXPORT | ||
| 251 | #endif | ||
| 252 | #ifndef ZEXPORTVA | ||
| 253 | # define ZEXPORTVA | ||
| 254 | #endif | ||
| 255 | |||
| 256 | #ifndef FAR | ||
| 257 | # define FAR | ||
| 258 | #endif | ||
| 259 | |||
| 260 | #if !defined(__MACTYPES__) | ||
| 261 | typedef unsigned char Byte; /* 8 bits */ | ||
| 262 | #endif | ||
| 263 | typedef unsigned int uInt; /* 16 bits or more */ | ||
| 264 | typedef unsigned long uLong; /* 32 bits or more */ | ||
| 265 | |||
| 266 | #ifdef SMALL_MEDIUM | ||
| 267 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ | ||
| 268 | # define Bytef Byte FAR | ||
| 269 | #else | ||
| 270 | typedef Byte FAR Bytef; | ||
| 271 | #endif | ||
| 272 | typedef char FAR charf; | ||
| 273 | typedef int FAR intf; | ||
| 274 | typedef uInt FAR uIntf; | ||
| 275 | typedef uLong FAR uLongf; | ||
| 276 | |||
| 277 | #ifdef STDC | ||
| 278 | typedef void const *voidpc; | ||
| 279 | typedef void FAR *voidpf; | ||
| 280 | typedef void *voidp; | ||
| 281 | #else | ||
| 282 | typedef Byte const *voidpc; | ||
| 283 | typedef Byte FAR *voidpf; | ||
| 284 | typedef Byte *voidp; | ||
| 285 | #endif | ||
| 286 | |||
| 287 | #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ | ||
| 288 | # include <sys/types.h> /* for off_t */ | ||
| 289 | # include <unistd.h> /* for SEEK_* and off_t */ | ||
| 290 | # ifdef VMS | ||
| 291 | # include <unixio.h> /* for off_t */ | ||
| 292 | # endif | ||
| 293 | # define z_off_t off_t | ||
| 294 | #endif | ||
| 295 | #ifndef SEEK_SET | ||
| 296 | # define SEEK_SET 0 /* Seek from beginning of file. */ | ||
| 297 | # define SEEK_CUR 1 /* Seek from current position. */ | ||
| 298 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ | ||
| 299 | #endif | ||
| 300 | #ifndef z_off_t | ||
| 301 | # define z_off_t long | ||
| 302 | #endif | ||
| 303 | |||
| 304 | #if defined(__OS400__) | ||
| 305 | # define NO_vsnprintf | ||
| 306 | #endif | ||
| 307 | |||
| 308 | #if defined(__MVS__) | ||
| 309 | # define NO_vsnprintf | ||
| 310 | # ifdef FAR | ||
| 311 | # undef FAR | ||
| 312 | # endif | ||
| 313 | #endif | ||
| 314 | |||
| 315 | /* MVS linker does not support external names larger than 8 bytes */ | ||
| 316 | #if defined(__MVS__) | ||
| 317 | # pragma map(deflateInit_,"DEIN") | ||
| 318 | # pragma map(deflateInit2_,"DEIN2") | ||
| 319 | # pragma map(deflateEnd,"DEEND") | ||
| 320 | # pragma map(deflateBound,"DEBND") | ||
| 321 | # pragma map(inflateInit_,"ININ") | ||
| 322 | # pragma map(inflateInit2_,"ININ2") | ||
| 323 | # pragma map(inflateEnd,"INEND") | ||
| 324 | # pragma map(inflateSync,"INSY") | ||
| 325 | # pragma map(inflateSetDictionary,"INSEDI") | ||
| 326 | # pragma map(compressBound,"CMBND") | ||
| 327 | # pragma map(inflate_table,"INTABL") | ||
| 328 | # pragma map(inflate_fast,"INFA") | ||
| 329 | # pragma map(inflate_copyright,"INCOPY") | ||
| 330 | #endif | ||
| 331 | |||
| 332 | #endif /* ZCONF_H */ | ||
diff --git a/contrib/minizip/zconf.in.h b/contrib/minizip/zconf.in.h new file mode 100644 index 0000000..03a9431 --- /dev/null +++ b/contrib/minizip/zconf.in.h | |||
| @@ -0,0 +1,332 @@ | |||
| 1 | /* zconf.h -- configuration of the zlib compression library | ||
| 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 | #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 | */ | ||
| 15 | #ifdef Z_PREFIX | ||
| 16 | # define deflateInit_ z_deflateInit_ | ||
| 17 | # define deflate z_deflate | ||
| 18 | # define deflateEnd z_deflateEnd | ||
| 19 | # define inflateInit_ z_inflateInit_ | ||
| 20 | # define inflate z_inflate | ||
| 21 | # define inflateEnd z_inflateEnd | ||
| 22 | # define deflateInit2_ z_deflateInit2_ | ||
| 23 | # define deflateSetDictionary z_deflateSetDictionary | ||
| 24 | # define deflateCopy z_deflateCopy | ||
| 25 | # define deflateReset z_deflateReset | ||
| 26 | # define deflateParams z_deflateParams | ||
| 27 | # define deflateBound z_deflateBound | ||
| 28 | # define deflatePrime z_deflatePrime | ||
| 29 | # define inflateInit2_ z_inflateInit2_ | ||
| 30 | # define inflateSetDictionary z_inflateSetDictionary | ||
| 31 | # define inflateSync z_inflateSync | ||
| 32 | # define inflateSyncPoint z_inflateSyncPoint | ||
| 33 | # define inflateCopy z_inflateCopy | ||
| 34 | # define inflateReset z_inflateReset | ||
| 35 | # define inflateBack z_inflateBack | ||
| 36 | # define inflateBackEnd z_inflateBackEnd | ||
| 37 | # define compress z_compress | ||
| 38 | # define compress2 z_compress2 | ||
| 39 | # define compressBound z_compressBound | ||
| 40 | # define uncompress z_uncompress | ||
| 41 | # define adler32 z_adler32 | ||
| 42 | # define crc32 z_crc32 | ||
| 43 | # define get_crc_table z_get_crc_table | ||
| 44 | # define zError z_zError | ||
| 45 | |||
| 46 | # define alloc_func z_alloc_func | ||
| 47 | # define free_func z_free_func | ||
| 48 | # define in_func z_in_func | ||
| 49 | # define out_func z_out_func | ||
| 50 | # define Byte z_Byte | ||
| 51 | # define uInt z_uInt | ||
| 52 | # define uLong z_uLong | ||
| 53 | # define Bytef z_Bytef | ||
| 54 | # define charf z_charf | ||
| 55 | # define intf z_intf | ||
| 56 | # define uIntf z_uIntf | ||
| 57 | # define uLongf z_uLongf | ||
| 58 | # define voidpf z_voidpf | ||
| 59 | # define voidp z_voidp | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #if defined(__MSDOS__) && !defined(MSDOS) | ||
| 63 | # define MSDOS | ||
| 64 | #endif | ||
| 65 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) | ||
| 66 | # define OS2 | ||
| 67 | #endif | ||
| 68 | #if defined(_WINDOWS) && !defined(WINDOWS) | ||
| 69 | # define WINDOWS | ||
| 70 | #endif | ||
| 71 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) | ||
| 72 | # ifndef WIN32 | ||
| 73 | # define WIN32 | ||
| 74 | # endif | ||
| 75 | #endif | ||
| 76 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) | ||
| 77 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) | ||
| 78 | # ifndef SYS16BIT | ||
| 79 | # define SYS16BIT | ||
| 80 | # endif | ||
| 81 | # endif | ||
| 82 | #endif | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more | ||
| 86 | * than 64k bytes at a time (needed on systems with 16-bit int). | ||
| 87 | */ | ||
| 88 | #ifdef SYS16BIT | ||
| 89 | # define MAXSEG_64K | ||
| 90 | #endif | ||
| 91 | #ifdef MSDOS | ||
| 92 | # define UNALIGNED_OK | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #ifdef __STDC_VERSION__ | ||
| 96 | # ifndef STDC | ||
| 97 | # define STDC | ||
| 98 | # endif | ||
| 99 | # if __STDC_VERSION__ >= 199901L | ||
| 100 | # ifndef STDC99 | ||
| 101 | # define STDC99 | ||
| 102 | # endif | ||
| 103 | # endif | ||
| 104 | #endif | ||
| 105 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) | ||
| 106 | # define STDC | ||
| 107 | #endif | ||
| 108 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) | ||
| 109 | # define STDC | ||
| 110 | #endif | ||
| 111 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) | ||
| 112 | # define STDC | ||
| 113 | #endif | ||
| 114 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) | ||
| 115 | # define STDC | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ | ||
| 119 | # define STDC | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef STDC | ||
| 123 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ | ||
| 124 | # define const /* note: need a more gentle solution here */ | ||
| 125 | # endif | ||
| 126 | #endif | ||
| 127 | |||
| 128 | /* Some Mac compilers merge all .h files incorrectly: */ | ||
| 129 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) | ||
| 130 | # define NO_DUMMY_DECL | ||
| 131 | #endif | ||
| 132 | |||
| 133 | /* Maximum value for memLevel in deflateInit2 */ | ||
| 134 | #ifndef MAX_MEM_LEVEL | ||
| 135 | # ifdef MAXSEG_64K | ||
| 136 | # define MAX_MEM_LEVEL 8 | ||
| 137 | # else | ||
| 138 | # define MAX_MEM_LEVEL 9 | ||
| 139 | # endif | ||
| 140 | #endif | ||
| 141 | |||
| 142 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. | ||
| 143 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files | ||
| 144 | * created by gzip. (Files created by minigzip can still be extracted by | ||
| 145 | * gzip.) | ||
| 146 | */ | ||
| 147 | #ifndef MAX_WBITS | ||
| 148 | # define MAX_WBITS 15 /* 32K LZ77 window */ | ||
| 149 | #endif | ||
| 150 | |||
| 151 | /* The memory requirements for deflate are (in bytes): | ||
| 152 | (1 << (windowBits+2)) + (1 << (memLevel+9)) | ||
| 153 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) | ||
| 154 | plus a few kilobytes for small objects. For example, if you want to reduce | ||
| 155 | the default memory requirements from 256K to 128K, compile with | ||
| 156 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" | ||
| 157 | Of course this will generally degrade compression (there's no free lunch). | ||
| 158 | |||
| 159 | The memory requirements for inflate are (in bytes) 1 << windowBits | ||
| 160 | that is, 32K for windowBits=15 (default value) plus a few kilobytes | ||
| 161 | for small objects. | ||
| 162 | */ | ||
| 163 | |||
| 164 | /* Type declarations */ | ||
| 165 | |||
| 166 | #ifndef OF /* function prototypes */ | ||
| 167 | # ifdef STDC | ||
| 168 | # define OF(args) args | ||
| 169 | # else | ||
| 170 | # define OF(args) () | ||
| 171 | # endif | ||
| 172 | #endif | ||
| 173 | |||
| 174 | /* The following definitions for FAR are needed only for MSDOS mixed | ||
| 175 | * model programming (small or medium model with some far allocations). | ||
| 176 | * This was tested only with MSC; for other MSDOS compilers you may have | ||
| 177 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, | ||
| 178 | * just define FAR to be empty. | ||
| 179 | */ | ||
| 180 | #ifdef SYS16BIT | ||
| 181 | # if defined(M_I86SM) || defined(M_I86MM) | ||
| 182 | /* MSC small or medium model */ | ||
| 183 | # define SMALL_MEDIUM | ||
| 184 | # ifdef _MSC_VER | ||
| 185 | # define FAR _far | ||
| 186 | # else | ||
| 187 | # define FAR far | ||
| 188 | # endif | ||
| 189 | # endif | ||
| 190 | # if (defined(__SMALL__) || defined(__MEDIUM__)) | ||
| 191 | /* Turbo C small or medium model */ | ||
| 192 | # define SMALL_MEDIUM | ||
| 193 | # ifdef __BORLANDC__ | ||
| 194 | # define FAR _far | ||
| 195 | # else | ||
| 196 | # define FAR far | ||
| 197 | # endif | ||
| 198 | # endif | ||
| 199 | #endif | ||
| 200 | |||
| 201 | #if defined(WINDOWS) || defined(WIN32) | ||
| 202 | /* If building or using zlib as a DLL, define ZLIB_DLL. | ||
| 203 | * This is not mandatory, but it offers a little performance increase. | ||
| 204 | */ | ||
| 205 | # ifdef ZLIB_DLL | ||
| 206 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) | ||
| 207 | # ifdef ZLIB_INTERNAL | ||
| 208 | # define ZEXTERN extern __declspec(dllexport) | ||
| 209 | # else | ||
| 210 | # define ZEXTERN extern __declspec(dllimport) | ||
| 211 | # endif | ||
| 212 | # endif | ||
| 213 | # endif /* ZLIB_DLL */ | ||
| 214 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, | ||
| 215 | * define ZLIB_WINAPI. | ||
| 216 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. | ||
| 217 | */ | ||
| 218 | # ifdef ZLIB_WINAPI | ||
| 219 | # ifdef FAR | ||
| 220 | # undef FAR | ||
| 221 | # endif | ||
| 222 | # include <windows.h> | ||
| 223 | /* No need for _export, use ZLIB.DEF instead. */ | ||
| 224 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ | ||
| 225 | # define ZEXPORT WINAPI | ||
| 226 | # ifdef WIN32 | ||
| 227 | # define ZEXPORTVA WINAPIV | ||
| 228 | # else | ||
| 229 | # define ZEXPORTVA FAR CDECL | ||
| 230 | # endif | ||
| 231 | # endif | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if defined (__BEOS__) | ||
| 235 | # ifdef ZLIB_DLL | ||
| 236 | # ifdef ZLIB_INTERNAL | ||
| 237 | # define ZEXPORT __declspec(dllexport) | ||
| 238 | # define ZEXPORTVA __declspec(dllexport) | ||
| 239 | # else | ||
| 240 | # define ZEXPORT __declspec(dllimport) | ||
| 241 | # define ZEXPORTVA __declspec(dllimport) | ||
| 242 | # endif | ||
| 243 | # endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifndef ZEXTERN | ||
| 247 | # define ZEXTERN extern | ||
| 248 | #endif | ||
| 249 | #ifndef ZEXPORT | ||
| 250 | # define ZEXPORT | ||
| 251 | #endif | ||
| 252 | #ifndef ZEXPORTVA | ||
| 253 | # define ZEXPORTVA | ||
| 254 | #endif | ||
| 255 | |||
| 256 | #ifndef FAR | ||
| 257 | # define FAR | ||
| 258 | #endif | ||
| 259 | |||
| 260 | #if !defined(__MACTYPES__) | ||
| 261 | typedef unsigned char Byte; /* 8 bits */ | ||
| 262 | #endif | ||
| 263 | typedef unsigned int uInt; /* 16 bits or more */ | ||
| 264 | typedef unsigned long uLong; /* 32 bits or more */ | ||
| 265 | |||
| 266 | #ifdef SMALL_MEDIUM | ||
| 267 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ | ||
| 268 | # define Bytef Byte FAR | ||
| 269 | #else | ||
| 270 | typedef Byte FAR Bytef; | ||
| 271 | #endif | ||
| 272 | typedef char FAR charf; | ||
| 273 | typedef int FAR intf; | ||
| 274 | typedef uInt FAR uIntf; | ||
| 275 | typedef uLong FAR uLongf; | ||
| 276 | |||
| 277 | #ifdef STDC | ||
| 278 | typedef void const *voidpc; | ||
| 279 | typedef void FAR *voidpf; | ||
| 280 | typedef void *voidp; | ||
| 281 | #else | ||
| 282 | typedef Byte const *voidpc; | ||
| 283 | typedef Byte FAR *voidpf; | ||
| 284 | typedef Byte *voidp; | ||
| 285 | #endif | ||
| 286 | |||
| 287 | #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ | ||
| 288 | # include <sys/types.h> /* for off_t */ | ||
| 289 | # include <unistd.h> /* for SEEK_* and off_t */ | ||
| 290 | # ifdef VMS | ||
| 291 | # include <unixio.h> /* for off_t */ | ||
| 292 | # endif | ||
| 293 | # define z_off_t off_t | ||
| 294 | #endif | ||
| 295 | #ifndef SEEK_SET | ||
| 296 | # define SEEK_SET 0 /* Seek from beginning of file. */ | ||
| 297 | # define SEEK_CUR 1 /* Seek from current position. */ | ||
| 298 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ | ||
| 299 | #endif | ||
| 300 | #ifndef z_off_t | ||
| 301 | # define z_off_t long | ||
| 302 | #endif | ||
| 303 | |||
| 304 | #if defined(__OS400__) | ||
| 305 | # define NO_vsnprintf | ||
| 306 | #endif | ||
| 307 | |||
| 308 | #if defined(__MVS__) | ||
| 309 | # define NO_vsnprintf | ||
| 310 | # ifdef FAR | ||
| 311 | # undef FAR | ||
| 312 | # endif | ||
| 313 | #endif | ||
| 314 | |||
| 315 | /* MVS linker does not support external names larger than 8 bytes */ | ||
| 316 | #if defined(__MVS__) | ||
| 317 | # pragma map(deflateInit_,"DEIN") | ||
| 318 | # pragma map(deflateInit2_,"DEIN2") | ||
| 319 | # pragma map(deflateEnd,"DEEND") | ||
| 320 | # pragma map(deflateBound,"DEBND") | ||
| 321 | # pragma map(inflateInit_,"ININ") | ||
| 322 | # pragma map(inflateInit2_,"ININ2") | ||
| 323 | # pragma map(inflateEnd,"INEND") | ||
| 324 | # pragma map(inflateSync,"INSY") | ||
| 325 | # pragma map(inflateSetDictionary,"INSEDI") | ||
| 326 | # pragma map(compressBound,"CMBND") | ||
| 327 | # pragma map(inflate_table,"INTABL") | ||
| 328 | # pragma map(inflate_fast,"INFA") | ||
| 329 | # pragma map(inflate_copyright,"INCOPY") | ||
| 330 | #endif | ||
| 331 | |||
| 332 | #endif /* ZCONF_H */ | ||
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index 7fbe002..e12da4c 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c | |||
| @@ -1,12 +1,23 @@ | |||
| 1 | /* zip.c -- IO on .zip files using zlib | 1 | /* zip.c -- IO on .zip files using zlib |
| 2 | Version 1.01e, February 12th, 2005 | 2 | Version 1.1, January 7th, 2010 |
| 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 3 | 4 | ||
| 4 | 27 Dec 2004 Rolf Kalbermatter | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
| 5 | Modification to zipOpen2 to support globalComment retrieval. | ||
| 6 | 6 | ||
| 7 | Copyright (C) 1998-2005 Gilles Vollant | 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 | Okt-2009 - Mathias Svensson - Remove old C style function prototypes | ||
| 14 | Okt-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives | ||
| 15 | Okt-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. | ||
| 16 | Okt-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 | Okt-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) | ||
| 8 | 20 | ||
| 9 | Read zip.h for more info | ||
| 10 | */ | 21 | */ |
| 11 | 22 | ||
| 12 | 23 | ||
| @@ -39,7 +50,7 @@ | |||
| 39 | #endif | 50 | #endif |
| 40 | 51 | ||
| 41 | #ifndef Z_BUFSIZE | 52 | #ifndef Z_BUFSIZE |
| 42 | #define Z_BUFSIZE (16384) | 53 | #define Z_BUFSIZE (64*1024) //(16384) |
| 43 | #endif | 54 | #endif |
| 44 | 55 | ||
| 45 | #ifndef Z_MAXFILENAMEINZIP | 56 | #ifndef Z_MAXFILENAMEINZIP |
| @@ -60,6 +71,10 @@ | |||
| 60 | 71 | ||
| 61 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ | 72 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ |
| 62 | 73 | ||
| 74 | |||
| 75 | // NOT sure that this work on ALL platform | ||
| 76 | #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) | ||
| 77 | |||
| 63 | #ifndef SEEK_CUR | 78 | #ifndef SEEK_CUR |
| 64 | #define SEEK_CUR 1 | 79 | #define SEEK_CUR 1 |
| 65 | #endif | 80 | #endif |
| @@ -79,8 +94,7 @@ | |||
| 79 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL | 94 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
| 80 | #endif | 95 | #endif |
| 81 | #endif | 96 | #endif |
| 82 | const char zip_copyright[] = | 97 | const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
| 83 | " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; | ||
| 84 | 98 | ||
| 85 | 99 | ||
| 86 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) | 100 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) |
| @@ -88,6 +102,8 @@ const char zip_copyright[] = | |||
| 88 | #define LOCALHEADERMAGIC (0x04034b50) | 102 | #define LOCALHEADERMAGIC (0x04034b50) |
| 89 | #define CENTRALHEADERMAGIC (0x02014b50) | 103 | #define CENTRALHEADERMAGIC (0x02014b50) |
| 90 | #define ENDHEADERMAGIC (0x06054b50) | 104 | #define ENDHEADERMAGIC (0x06054b50) |
| 105 | #define ZIP64ENDHEADERMAGIC (0x6064b50) | ||
| 106 | #define ZIP64ENDLOCHEADERMAGIC (0x7064b50) | ||
| 91 | 107 | ||
| 92 | #define FLAG_LOCALHEADER_OFFSET (0x06) | 108 | #define FLAG_LOCALHEADER_OFFSET (0x06) |
| 93 | #define CRC_LOCALHEADER_OFFSET (0x0e) | 109 | #define CRC_LOCALHEADER_OFFSET (0x0e) |
| @@ -113,13 +129,19 @@ typedef struct linkedlist_data_s | |||
| 113 | typedef struct | 129 | typedef struct |
| 114 | { | 130 | { |
| 115 | z_stream stream; /* zLib stream structure for inflate */ | 131 | z_stream stream; /* zLib stream structure for inflate */ |
| 132 | #ifdef HAVE_BZIP2 | ||
| 133 | bz_stream bstream; /* bzLib stream structure for bziped */ | ||
| 134 | #endif | ||
| 135 | |||
| 116 | int stream_initialised; /* 1 is stream is initialised */ | 136 | int stream_initialised; /* 1 is stream is initialised */ |
| 117 | uInt pos_in_buffered_data; /* last written byte in buffered_data */ | 137 | uInt pos_in_buffered_data; /* last written byte in buffered_data */ |
| 118 | 138 | ||
| 119 | uLong pos_local_header; /* offset of the local header of the file | 139 | ZPOS64_T pos_local_header; /* offset of the local header of the file |
| 120 | currenty writing */ | 140 | currenty writing */ |
| 121 | char* central_header; /* central header data for the current file */ | 141 | char* central_header; /* central header data for the current file */ |
| 142 | uLong size_centralExtra; | ||
| 122 | uLong size_centralheader; /* size of the central header for cur file */ | 143 | uLong size_centralheader; /* size of the central header for cur file */ |
| 144 | uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ | ||
| 123 | uLong flag; /* flag of the file currently writing */ | 145 | uLong flag; /* flag of the file currently writing */ |
| 124 | 146 | ||
| 125 | int method; /* compression method of file currenty wr.*/ | 147 | int method; /* compression method of file currenty wr.*/ |
| @@ -128,29 +150,34 @@ typedef struct | |||
| 128 | uLong dosDate; | 150 | uLong dosDate; |
| 129 | uLong crc32; | 151 | uLong crc32; |
| 130 | int encrypt; | 152 | int encrypt; |
| 153 | int zip64; /* Add ZIP64 extened information in the extra field */ | ||
| 154 | ZPOS64_T pos_zip64extrainfo; | ||
| 155 | ZPOS64_T totalCompressedData; | ||
| 156 | ZPOS64_T totalUncompressedData; | ||
| 131 | #ifndef NOCRYPT | 157 | #ifndef NOCRYPT |
| 132 | unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | 158 | unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
| 133 | const unsigned long* pcrc_32_tab; | 159 | const unsigned long* pcrc_32_tab; |
| 134 | int crypt_header_size; | 160 | int crypt_header_size; |
| 135 | #endif | 161 | #endif |
| 136 | } curfile_info; | 162 | } curfile64_info; |
| 137 | 163 | ||
| 138 | typedef struct | 164 | typedef struct |
| 139 | { | 165 | { |
| 140 | zlib_filefunc_def z_filefunc; | 166 | zlib_filefunc64_32_def z_filefunc; |
| 141 | voidpf filestream; /* io structore of the zipfile */ | 167 | voidpf filestream; /* io structore of the zipfile */ |
| 142 | linkedlist_data central_dir;/* datablock with central dir in construction*/ | 168 | linkedlist_data central_dir;/* datablock with central dir in construction*/ |
| 143 | int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ | 169 | int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ |
| 144 | curfile_info ci; /* info on the file curretly writing */ | 170 | curfile64_info ci; /* info on the file curretly writing */ |
| 171 | |||
| 172 | ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ | ||
| 173 | ZPOS64_T add_position_when_writting_offset; | ||
| 174 | ZPOS64_T number_entry; | ||
| 145 | 175 | ||
| 146 | uLong begin_pos; /* position of the beginning of the zipfile */ | ||
| 147 | uLong add_position_when_writting_offset; | ||
| 148 | uLong number_entry; | ||
| 149 | #ifndef NO_ADDFILEINEXISTINGZIP | 176 | #ifndef NO_ADDFILEINEXISTINGZIP |
| 150 | char *globalcomment; | 177 | char *globalcomment; |
| 151 | #endif | 178 | #endif |
| 152 | } zip_internal; | ||
| 153 | 179 | ||
| 180 | } zip64_internal; | ||
| 154 | 181 | ||
| 155 | 182 | ||
| 156 | #ifndef NOCRYPT | 183 | #ifndef NOCRYPT |
| @@ -172,8 +199,7 @@ local linkedlist_datablock_internal* allocate_new_datablock() | |||
| 172 | return ldi; | 199 | return ldi; |
| 173 | } | 200 | } |
| 174 | 201 | ||
| 175 | local void free_datablock(ldi) | 202 | local void free_datablock(linkedlist_datablock_internal* ldi) |
| 176 | linkedlist_datablock_internal* ldi; | ||
| 177 | { | 203 | { |
| 178 | while (ldi!=NULL) | 204 | while (ldi!=NULL) |
| 179 | { | 205 | { |
| @@ -183,24 +209,19 @@ local void free_datablock(ldi) | |||
| 183 | } | 209 | } |
| 184 | } | 210 | } |
| 185 | 211 | ||
| 186 | local void init_linkedlist(ll) | 212 | local void init_linkedlist(linkedlist_data* ll) |
| 187 | linkedlist_data* ll; | ||
| 188 | { | 213 | { |
| 189 | ll->first_block = ll->last_block = NULL; | 214 | ll->first_block = ll->last_block = NULL; |
| 190 | } | 215 | } |
| 191 | 216 | ||
| 192 | local void free_linkedlist(ll) | 217 | local void free_linkedlist(linkedlist_data* ll) |
| 193 | linkedlist_data* ll; | ||
| 194 | { | 218 | { |
| 195 | free_datablock(ll->first_block); | 219 | free_datablock(ll->first_block); |
| 196 | ll->first_block = ll->last_block = NULL; | 220 | ll->first_block = ll->last_block = NULL; |
| 197 | } | 221 | } |
| 198 | 222 | ||
| 199 | 223 | ||
| 200 | local int add_data_in_datablock(ll,buf,len) | 224 | local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) |
| 201 | linkedlist_data* ll; | ||
| 202 | const void* buf; | ||
| 203 | uLong len; | ||
| 204 | { | 225 | { |
| 205 | linkedlist_datablock_internal* ldi; | 226 | linkedlist_datablock_internal* ldi; |
| 206 | const unsigned char* from_copy; | 227 | const unsigned char* from_copy; |
| @@ -258,18 +279,13 @@ local int add_data_in_datablock(ll,buf,len) | |||
| 258 | #ifndef NO_ADDFILEINEXISTINGZIP | 279 | #ifndef NO_ADDFILEINEXISTINGZIP |
| 259 | /* =========================================================================== | 280 | /* =========================================================================== |
| 260 | Inputs a long in LSB order to the given file | 281 | Inputs a long in LSB order to the given file |
| 261 | nbByte == 1, 2 or 4 (byte, short or long) | 282 | nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) |
| 262 | */ | 283 | */ |
| 263 | 284 | ||
| 264 | local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, | 285 | local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); |
| 265 | voidpf filestream, uLong x, int nbByte)); | 286 | local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) |
| 266 | local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) | ||
| 267 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 268 | voidpf filestream; | ||
| 269 | uLong x; | ||
| 270 | int nbByte; | ||
| 271 | { | 287 | { |
| 272 | unsigned char buf[4]; | 288 | unsigned char buf[8]; |
| 273 | int n; | 289 | int n; |
| 274 | for (n = 0; n < nbByte; n++) | 290 | for (n = 0; n < nbByte; n++) |
| 275 | { | 291 | { |
| @@ -284,17 +300,14 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) | |||
| 284 | } | 300 | } |
| 285 | } | 301 | } |
| 286 | 302 | ||
| 287 | if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) | 303 | if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) |
| 288 | return ZIP_ERRNO; | 304 | return ZIP_ERRNO; |
| 289 | else | 305 | else |
| 290 | return ZIP_OK; | 306 | return ZIP_OK; |
| 291 | } | 307 | } |
| 292 | 308 | ||
| 293 | local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); | 309 | local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); |
| 294 | local void ziplocal_putValue_inmemory (dest, x, nbByte) | 310 | local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) |
| 295 | void* dest; | ||
| 296 | uLong x; | ||
| 297 | int nbByte; | ||
| 298 | { | 311 | { |
| 299 | unsigned char* buf=(unsigned char*)dest; | 312 | unsigned char* buf=(unsigned char*)dest; |
| 300 | int n; | 313 | int n; |
| @@ -315,14 +328,12 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte) | |||
| 315 | /****************************************************************************/ | 328 | /****************************************************************************/ |
| 316 | 329 | ||
| 317 | 330 | ||
| 318 | local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) | 331 | local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) |
| 319 | const tm_zip* ptm; | ||
| 320 | uLong dosDate; | ||
| 321 | { | 332 | { |
| 322 | uLong year = (uLong)ptm->tm_year; | 333 | uLong year = (uLong)ptm->tm_year; |
| 323 | if (year>1980) | 334 | if (year>=1980) |
| 324 | year-=1980; | 335 | year-=1980; |
| 325 | else if (year>80) | 336 | else if (year>=80) |
| 326 | year-=80; | 337 | year-=80; |
| 327 | return | 338 | return |
| 328 | (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | | 339 | (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | |
| @@ -332,18 +343,12 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) | |||
| 332 | 343 | ||
| 333 | /****************************************************************************/ | 344 | /****************************************************************************/ |
| 334 | 345 | ||
| 335 | local int ziplocal_getByte OF(( | 346 | local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); |
| 336 | const zlib_filefunc_def* pzlib_filefunc_def, | ||
| 337 | voidpf filestream, | ||
| 338 | int *pi)); | ||
| 339 | 347 | ||
| 340 | local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) | 348 | local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) |
| 341 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 342 | voidpf filestream; | ||
| 343 | int *pi; | ||
| 344 | { | 349 | { |
| 345 | unsigned char c; | 350 | unsigned char c; |
| 346 | int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); | 351 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); |
| 347 | if (err==1) | 352 | if (err==1) |
| 348 | { | 353 | { |
| 349 | *pi = (int)c; | 354 | *pi = (int)c; |
| @@ -351,7 +356,7 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) | |||
| 351 | } | 356 | } |
| 352 | else | 357 | else |
| 353 | { | 358 | { |
| 354 | if (ZERROR(*pzlib_filefunc_def,filestream)) | 359 | if (ZERROR64(*pzlib_filefunc_def,filestream)) |
| 355 | return ZIP_ERRNO; | 360 | return ZIP_ERRNO; |
| 356 | else | 361 | else |
| 357 | return ZIP_EOF; | 362 | return ZIP_EOF; |
| @@ -362,25 +367,19 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) | |||
| 362 | /* =========================================================================== | 367 | /* =========================================================================== |
| 363 | Reads a long in LSB order from the given gz_stream. Sets | 368 | Reads a long in LSB order from the given gz_stream. Sets |
| 364 | */ | 369 | */ |
| 365 | local int ziplocal_getShort OF(( | 370 | local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); |
| 366 | const zlib_filefunc_def* pzlib_filefunc_def, | 371 | |
| 367 | voidpf filestream, | 372 | local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) |
| 368 | uLong *pX)); | ||
| 369 | |||
| 370 | local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) | ||
| 371 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 372 | voidpf filestream; | ||
| 373 | uLong *pX; | ||
| 374 | { | 373 | { |
| 375 | uLong x ; | 374 | uLong x ; |
| 376 | int i; | 375 | int i = 0; |
| 377 | int err; | 376 | int err; |
| 378 | 377 | ||
| 379 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 378 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 380 | x = (uLong)i; | 379 | x = (uLong)i; |
| 381 | 380 | ||
| 382 | if (err==ZIP_OK) | 381 | if (err==ZIP_OK) |
| 383 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 382 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 384 | x += ((uLong)i)<<8; | 383 | x += ((uLong)i)<<8; |
| 385 | 384 | ||
| 386 | if (err==ZIP_OK) | 385 | if (err==ZIP_OK) |
| @@ -390,33 +389,27 @@ local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) | |||
| 390 | return err; | 389 | return err; |
| 391 | } | 390 | } |
| 392 | 391 | ||
| 393 | local int ziplocal_getLong OF(( | 392 | local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); |
| 394 | const zlib_filefunc_def* pzlib_filefunc_def, | ||
| 395 | voidpf filestream, | ||
| 396 | uLong *pX)); | ||
| 397 | 393 | ||
| 398 | local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) | 394 | local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) |
| 399 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 400 | voidpf filestream; | ||
| 401 | uLong *pX; | ||
| 402 | { | 395 | { |
| 403 | uLong x ; | 396 | uLong x ; |
| 404 | int i; | 397 | int i = 0; |
| 405 | int err; | 398 | int err; |
| 406 | 399 | ||
| 407 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 400 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 408 | x = (uLong)i; | 401 | x = (uLong)i; |
| 409 | 402 | ||
| 410 | if (err==ZIP_OK) | 403 | if (err==ZIP_OK) |
| 411 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 404 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 412 | x += ((uLong)i)<<8; | 405 | x += ((uLong)i)<<8; |
| 413 | 406 | ||
| 414 | if (err==ZIP_OK) | 407 | if (err==ZIP_OK) |
| 415 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 408 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 416 | x += ((uLong)i)<<16; | 409 | x += ((uLong)i)<<16; |
| 417 | 410 | ||
| 418 | if (err==ZIP_OK) | 411 | if (err==ZIP_OK) |
| 419 | err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); | 412 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); |
| 420 | x += ((uLong)i)<<24; | 413 | x += ((uLong)i)<<24; |
| 421 | 414 | ||
| 422 | if (err==ZIP_OK) | 415 | if (err==ZIP_OK) |
| @@ -426,6 +419,54 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) | |||
| 426 | return err; | 419 | return err; |
| 427 | } | 420 | } |
| 428 | 421 | ||
| 422 | local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); | ||
| 423 | |||
| 424 | |||
| 425 | local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) | ||
| 426 | { | ||
| 427 | ZPOS64_T x; | ||
| 428 | int i = 0; | ||
| 429 | int err; | ||
| 430 | |||
| 431 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 432 | x = (ZPOS64_T)i; | ||
| 433 | |||
| 434 | if (err==ZIP_OK) | ||
| 435 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 436 | x += ((ZPOS64_T)i)<<8; | ||
| 437 | |||
| 438 | if (err==ZIP_OK) | ||
| 439 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 440 | x += ((ZPOS64_T)i)<<16; | ||
| 441 | |||
| 442 | if (err==ZIP_OK) | ||
| 443 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 444 | x += ((ZPOS64_T)i)<<24; | ||
| 445 | |||
| 446 | if (err==ZIP_OK) | ||
| 447 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 448 | x += ((ZPOS64_T)i)<<32; | ||
| 449 | |||
| 450 | if (err==ZIP_OK) | ||
| 451 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 452 | x += ((ZPOS64_T)i)<<40; | ||
| 453 | |||
| 454 | if (err==ZIP_OK) | ||
| 455 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 456 | x += ((ZPOS64_T)i)<<48; | ||
| 457 | |||
| 458 | if (err==ZIP_OK) | ||
| 459 | err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 460 | x += ((ZPOS64_T)i)<<56; | ||
| 461 | |||
| 462 | if (err==ZIP_OK) | ||
| 463 | *pX = x; | ||
| 464 | else | ||
| 465 | *pX = 0; | ||
| 466 | |||
| 467 | return err; | ||
| 468 | } | ||
| 469 | |||
| 429 | #ifndef BUFREADCOMMENT | 470 | #ifndef BUFREADCOMMENT |
| 430 | #define BUFREADCOMMENT (0x400) | 471 | #define BUFREADCOMMENT (0x400) |
| 431 | #endif | 472 | #endif |
| @@ -433,87 +474,391 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) | |||
| 433 | Locate the Central directory of a zipfile (at the end, just before | 474 | Locate the Central directory of a zipfile (at the end, just before |
| 434 | the global comment) | 475 | the global comment) |
| 435 | */ | 476 | */ |
| 436 | local uLong ziplocal_SearchCentralDir OF(( | 477 | local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); |
| 437 | const zlib_filefunc_def* pzlib_filefunc_def, | ||
| 438 | voidpf filestream)); | ||
| 439 | 478 | ||
| 440 | local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) | 479 | local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) |
| 441 | const zlib_filefunc_def* pzlib_filefunc_def; | ||
| 442 | voidpf filestream; | ||
| 443 | { | 480 | { |
| 444 | unsigned char* buf; | 481 | unsigned char* buf; |
| 445 | uLong uSizeFile; | 482 | ZPOS64_T uSizeFile; |
| 446 | uLong uBackRead; | 483 | ZPOS64_T uBackRead; |
| 447 | uLong uMaxBack=0xffff; /* maximum size of global comment */ | 484 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ |
| 448 | uLong uPosFound=0; | 485 | ZPOS64_T uPosFound=0; |
| 486 | |||
| 487 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | ||
| 488 | return 0; | ||
| 489 | |||
| 490 | |||
| 491 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); | ||
| 492 | |||
| 493 | if (uMaxBack>uSizeFile) | ||
| 494 | uMaxBack = uSizeFile; | ||
| 495 | |||
| 496 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | ||
| 497 | if (buf==NULL) | ||
| 498 | return 0; | ||
| 499 | |||
| 500 | uBackRead = 4; | ||
| 501 | while (uBackRead<uMaxBack) | ||
| 502 | { | ||
| 503 | uLong uReadSize; | ||
| 504 | ZPOS64_T uReadPos ; | ||
| 505 | int i; | ||
| 506 | if (uBackRead+BUFREADCOMMENT>uMaxBack) | ||
| 507 | uBackRead = uMaxBack; | ||
| 508 | else | ||
| 509 | uBackRead+=BUFREADCOMMENT; | ||
| 510 | uReadPos = uSizeFile-uBackRead ; | ||
| 511 | |||
| 512 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | ||
| 513 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); | ||
| 514 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 515 | break; | ||
| 516 | |||
| 517 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | ||
| 518 | break; | ||
| 519 | |||
| 520 | for (i=(int)uReadSize-3; (i--)>0;) | ||
| 521 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && | ||
| 522 | ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) | ||
| 523 | { | ||
| 524 | uPosFound = uReadPos+i; | ||
| 525 | break; | ||
| 526 | } | ||
| 449 | 527 | ||
| 450 | if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | 528 | if (uPosFound!=0) |
| 451 | return 0; | 529 | break; |
| 530 | } | ||
| 531 | TRYFREE(buf); | ||
| 532 | return uPosFound; | ||
| 533 | } | ||
| 452 | 534 | ||
| 535 | /* | ||
| 536 | Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before | ||
| 537 | the global comment) | ||
| 538 | */ | ||
| 539 | local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); | ||
| 453 | 540 | ||
| 454 | uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); | 541 | local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) |
| 542 | { | ||
| 543 | unsigned char* buf; | ||
| 544 | ZPOS64_T uSizeFile; | ||
| 545 | ZPOS64_T uBackRead; | ||
| 546 | ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ | ||
| 547 | ZPOS64_T uPosFound=0; | ||
| 548 | uLong uL; | ||
| 549 | ZPOS64_T relativeOffset; | ||
| 550 | |||
| 551 | if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) | ||
| 552 | return 0; | ||
| 553 | |||
| 554 | uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); | ||
| 555 | |||
| 556 | if (uMaxBack>uSizeFile) | ||
| 557 | uMaxBack = uSizeFile; | ||
| 558 | |||
| 559 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | ||
| 560 | if (buf==NULL) | ||
| 561 | return 0; | ||
| 562 | |||
| 563 | uBackRead = 4; | ||
| 564 | while (uBackRead<uMaxBack) | ||
| 565 | { | ||
| 566 | uLong uReadSize; | ||
| 567 | ZPOS64_T uReadPos; | ||
| 568 | int i; | ||
| 569 | if (uBackRead+BUFREADCOMMENT>uMaxBack) | ||
| 570 | uBackRead = uMaxBack; | ||
| 571 | else | ||
| 572 | uBackRead+=BUFREADCOMMENT; | ||
| 573 | uReadPos = uSizeFile-uBackRead ; | ||
| 455 | 574 | ||
| 456 | if (uMaxBack>uSizeFile) | 575 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? |
| 457 | uMaxBack = uSizeFile; | 576 | (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); |
| 577 | if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 578 | break; | ||
| 458 | 579 | ||
| 459 | buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); | 580 | if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) |
| 460 | if (buf==NULL) | 581 | break; |
| 461 | return 0; | ||
| 462 | 582 | ||
| 463 | uBackRead = 4; | 583 | for (i=(int)uReadSize-3; (i--)>0;) |
| 464 | while (uBackRead<uMaxBack) | ||
| 465 | { | 584 | { |
| 466 | uLong uReadSize,uReadPos ; | 585 | // Signature "0x07064b50" Zip64 end of central directory locater |
| 467 | int i; | 586 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) |
| 468 | if (uBackRead+BUFREADCOMMENT>uMaxBack) | 587 | { |
| 469 | uBackRead = uMaxBack; | 588 | uPosFound = uReadPos+i; |
| 470 | else | 589 | break; |
| 471 | uBackRead+=BUFREADCOMMENT; | 590 | } |
| 472 | uReadPos = uSizeFile-uBackRead ; | 591 | } |
| 473 | 592 | ||
| 474 | uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? | 593 | if (uPosFound!=0) |
| 475 | (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); | 594 | break; |
| 476 | if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) | 595 | } |
| 477 | break; | ||
| 478 | 596 | ||
| 479 | if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) | 597 | TRYFREE(buf); |
| 480 | break; | 598 | if (uPosFound == 0) |
| 599 | return 0; | ||
| 481 | 600 | ||
| 482 | for (i=(int)uReadSize-3; (i--)>0;) | 601 | /* Zip64 end of central directory locator */ |
| 483 | if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && | 602 | if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 484 | ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) | 603 | return 0; |
| 485 | { | 604 | |
| 486 | uPosFound = uReadPos+i; | 605 | /* the signature, already checked */ |
| 487 | break; | 606 | if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) |
| 488 | } | 607 | return 0; |
| 489 | 608 | ||
| 490 | if (uPosFound!=0) | 609 | /* number of the disk with the start of the zip64 end of central directory */ |
| 491 | break; | 610 | if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) |
| 611 | return 0; | ||
| 612 | if (uL != 0) | ||
| 613 | return 0; | ||
| 614 | |||
| 615 | /* relative offset of the zip64 end of central directory record */ | ||
| 616 | if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) | ||
| 617 | return 0; | ||
| 618 | |||
| 619 | /* total number of disks */ | ||
| 620 | if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) | ||
| 621 | return 0; | ||
| 622 | if (uL != 1) | ||
| 623 | return 0; | ||
| 624 | |||
| 625 | /* Goto Zip64 end of central directory record */ | ||
| 626 | if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 627 | return 0; | ||
| 628 | |||
| 629 | /* the signature */ | ||
| 630 | if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) | ||
| 631 | return 0; | ||
| 632 | |||
| 633 | if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' | ||
| 634 | return 0; | ||
| 635 | |||
| 636 | return relativeOffset; | ||
| 637 | } | ||
| 638 | |||
| 639 | int LoadCentralDirectoryRecord(zip64_internal* pziinit) | ||
| 640 | { | ||
| 641 | int err=ZIP_OK; | ||
| 642 | ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | ||
| 643 | |||
| 644 | ZPOS64_T size_central_dir; /* size of the central directory */ | ||
| 645 | ZPOS64_T offset_central_dir; /* offset of start of central directory */ | ||
| 646 | ZPOS64_T central_pos; | ||
| 647 | uLong uL; | ||
| 648 | |||
| 649 | uLong number_disk; /* number of the current dist, used for | ||
| 650 | spaning ZIP, unsupported, always 0*/ | ||
| 651 | uLong number_disk_with_CD; /* number the the disk with central dir, used | ||
| 652 | for spaning ZIP, unsupported, always 0*/ | ||
| 653 | ZPOS64_T number_entry; | ||
| 654 | ZPOS64_T number_entry_CD; /* total number of entries in | ||
| 655 | the central dir | ||
| 656 | (same than number_entry on nospan) */ | ||
| 657 | uLong VersionMadeBy; | ||
| 658 | uLong VersionNeeded; | ||
| 659 | uLong size_comment; | ||
| 660 | |||
| 661 | int hasZIP64Record = 0; | ||
| 662 | |||
| 663 | // check first if we find a ZIP64 record | ||
| 664 | central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); | ||
| 665 | if(central_pos > 0) | ||
| 666 | { | ||
| 667 | hasZIP64Record = 1; | ||
| 668 | } | ||
| 669 | else if(central_pos == 0) | ||
| 670 | { | ||
| 671 | central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); | ||
| 672 | } | ||
| 673 | |||
| 674 | /* disable to allow appending to empty ZIP archive | ||
| 675 | if (central_pos==0) | ||
| 676 | err=ZIP_ERRNO; | ||
| 677 | */ | ||
| 678 | |||
| 679 | if(hasZIP64Record) | ||
| 680 | { | ||
| 681 | ZPOS64_T sizeEndOfCentralDirectory; | ||
| 682 | if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) | ||
| 683 | err=ZIP_ERRNO; | ||
| 684 | |||
| 685 | /* the signature, already checked */ | ||
| 686 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) | ||
| 687 | err=ZIP_ERRNO; | ||
| 688 | |||
| 689 | /* size of zip64 end of central directory record */ | ||
| 690 | if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) | ||
| 691 | err=ZIP_ERRNO; | ||
| 692 | |||
| 693 | /* version made by */ | ||
| 694 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) | ||
| 695 | err=ZIP_ERRNO; | ||
| 696 | |||
| 697 | /* version needed to extract */ | ||
| 698 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) | ||
| 699 | err=ZIP_ERRNO; | ||
| 700 | |||
| 701 | /* number of this disk */ | ||
| 702 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) | ||
| 703 | err=ZIP_ERRNO; | ||
| 704 | |||
| 705 | /* number of the disk with the start of the central directory */ | ||
| 706 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) | ||
| 707 | err=ZIP_ERRNO; | ||
| 708 | |||
| 709 | /* total number of entries in the central directory on this disk */ | ||
| 710 | if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) | ||
| 711 | err=ZIP_ERRNO; | ||
| 712 | |||
| 713 | /* total number of entries in the central directory */ | ||
| 714 | if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) | ||
| 715 | err=ZIP_ERRNO; | ||
| 716 | |||
| 717 | if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) | ||
| 718 | err=ZIP_BADZIPFILE; | ||
| 719 | |||
| 720 | /* size of the central directory */ | ||
| 721 | if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) | ||
| 722 | err=ZIP_ERRNO; | ||
| 723 | |||
| 724 | /* offset of start of central directory with respect to the | ||
| 725 | starting disk number */ | ||
| 726 | if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) | ||
| 727 | err=ZIP_ERRNO; | ||
| 728 | |||
| 729 | // TODO.. | ||
| 730 | // read the comment from the standard central header. | ||
| 731 | size_comment = 0; | ||
| 732 | } | ||
| 733 | else | ||
| 734 | { | ||
| 735 | // Read End of central Directory info | ||
| 736 | if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 737 | err=ZIP_ERRNO; | ||
| 738 | |||
| 739 | /* the signature, already checked */ | ||
| 740 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) | ||
| 741 | err=ZIP_ERRNO; | ||
| 742 | |||
| 743 | /* number of this disk */ | ||
| 744 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) | ||
| 745 | err=ZIP_ERRNO; | ||
| 746 | |||
| 747 | /* number of the disk with the start of the central directory */ | ||
| 748 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) | ||
| 749 | err=ZIP_ERRNO; | ||
| 750 | |||
| 751 | /* total number of entries in the central dir on this disk */ | ||
| 752 | number_entry = 0; | ||
| 753 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) | ||
| 754 | err=ZIP_ERRNO; | ||
| 755 | else | ||
| 756 | number_entry = uL; | ||
| 757 | |||
| 758 | /* total number of entries in the central dir */ | ||
| 759 | number_entry_CD = 0; | ||
| 760 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) | ||
| 761 | err=ZIP_ERRNO; | ||
| 762 | else | ||
| 763 | number_entry_CD = uL; | ||
| 764 | |||
| 765 | if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) | ||
| 766 | err=ZIP_BADZIPFILE; | ||
| 767 | |||
| 768 | /* size of the central directory */ | ||
| 769 | size_central_dir = 0; | ||
| 770 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) | ||
| 771 | err=ZIP_ERRNO; | ||
| 772 | else | ||
| 773 | size_central_dir = uL; | ||
| 774 | |||
| 775 | /* offset of start of central directory with respect to the starting disk number */ | ||
| 776 | offset_central_dir = 0; | ||
| 777 | if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) | ||
| 778 | err=ZIP_ERRNO; | ||
| 779 | else | ||
| 780 | offset_central_dir = uL; | ||
| 781 | |||
| 782 | |||
| 783 | /* zipfile global comment length */ | ||
| 784 | if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) | ||
| 785 | err=ZIP_ERRNO; | ||
| 786 | } | ||
| 787 | |||
| 788 | if ((central_pos<offset_central_dir+size_central_dir) && | ||
| 789 | (err==ZIP_OK)) | ||
| 790 | err=ZIP_BADZIPFILE; | ||
| 791 | |||
| 792 | if (err!=ZIP_OK) | ||
| 793 | { | ||
| 794 | ZCLOSE64(pziinit->z_filefunc, pziinit->filestream); | ||
| 795 | return ZIP_ERRNO; | ||
| 796 | } | ||
| 797 | |||
| 798 | if (size_comment>0) | ||
| 799 | { | ||
| 800 | pziinit->globalcomment = (char*)ALLOC(size_comment+1); | ||
| 801 | if (pziinit->globalcomment) | ||
| 802 | { | ||
| 803 | size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); | ||
| 804 | pziinit->globalcomment[size_comment]=0; | ||
| 805 | } | ||
| 806 | } | ||
| 807 | |||
| 808 | byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); | ||
| 809 | pziinit->add_position_when_writting_offset = byte_before_the_zipfile; | ||
| 810 | |||
| 811 | { | ||
| 812 | ZPOS64_T size_central_dir_to_read = size_central_dir; | ||
| 813 | size_t buf_size = SIZEDATA_INDATABLOCK; | ||
| 814 | void* buf_read = (void*)ALLOC(buf_size); | ||
| 815 | if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) | ||
| 816 | err=ZIP_ERRNO; | ||
| 817 | |||
| 818 | while ((size_central_dir_to_read>0) && (err==ZIP_OK)) | ||
| 819 | { | ||
| 820 | ZPOS64_T read_this = SIZEDATA_INDATABLOCK; | ||
| 821 | if (read_this > size_central_dir_to_read) | ||
| 822 | read_this = size_central_dir_to_read; | ||
| 823 | |||
| 824 | if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) | ||
| 825 | err=ZIP_ERRNO; | ||
| 826 | |||
| 827 | if (err==ZIP_OK) | ||
| 828 | err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); | ||
| 829 | |||
| 830 | size_central_dir_to_read-=read_this; | ||
| 492 | } | 831 | } |
| 493 | TRYFREE(buf); | 832 | TRYFREE(buf_read); |
| 494 | return uPosFound; | 833 | } |
| 834 | pziinit->begin_pos = byte_before_the_zipfile; | ||
| 835 | pziinit->number_entry = number_entry_CD; | ||
| 836 | |||
| 837 | if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) | ||
| 838 | err=ZIP_ERRNO; | ||
| 839 | |||
| 840 | return err; | ||
| 495 | } | 841 | } |
| 842 | |||
| 843 | |||
| 496 | #endif /* !NO_ADDFILEINEXISTINGZIP*/ | 844 | #endif /* !NO_ADDFILEINEXISTINGZIP*/ |
| 497 | 845 | ||
| 846 | |||
| 498 | /************************************************************/ | 847 | /************************************************************/ |
| 499 | extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) | 848 | extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) |
| 500 | const char *pathname; | ||
| 501 | int append; | ||
| 502 | zipcharpc* globalcomment; | ||
| 503 | zlib_filefunc_def* pzlib_filefunc_def; | ||
| 504 | { | 849 | { |
| 505 | zip_internal ziinit; | 850 | zip64_internal ziinit; |
| 506 | zip_internal* zi; | 851 | zip64_internal* zi; |
| 507 | int err=ZIP_OK; | 852 | int err=ZIP_OK; |
| 508 | 853 | ||
| 509 | 854 | ziinit.z_filefunc.zseek32_file = NULL; | |
| 510 | if (pzlib_filefunc_def==NULL) | 855 | ziinit.z_filefunc.ztell32_file = NULL; |
| 511 | fill_fopen_filefunc(&ziinit.z_filefunc); | 856 | if (pzlib_filefunc64_32_def==NULL) |
| 857 | fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); | ||
| 512 | else | 858 | else |
| 513 | ziinit.z_filefunc = *pzlib_filefunc_def; | 859 | ziinit.z_filefunc = *pzlib_filefunc64_32_def; |
| 514 | 860 | ||
| 515 | ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) | 861 | ziinit.filestream = ZOPEN64(ziinit.z_filefunc, |
| 516 | (ziinit.z_filefunc.opaque, | ||
| 517 | pathname, | 862 | pathname, |
| 518 | (append == APPEND_STATUS_CREATE) ? | 863 | (append == APPEND_STATUS_CREATE) ? |
| 519 | (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : | 864 | (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : |
| @@ -521,7 +866,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc | |||
| 521 | 866 | ||
| 522 | if (ziinit.filestream == NULL) | 867 | if (ziinit.filestream == NULL) |
| 523 | return NULL; | 868 | return NULL; |
| 524 | ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); | 869 | |
| 870 | if (append == APPEND_STATUS_CREATEAFTER) | ||
| 871 | ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); | ||
| 872 | |||
| 873 | ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); | ||
| 525 | ziinit.in_opened_file_inzip = 0; | 874 | ziinit.in_opened_file_inzip = 0; |
| 526 | ziinit.ci.stream_initialised = 0; | 875 | ziinit.ci.stream_initialised = 0; |
| 527 | ziinit.number_entry = 0; | 876 | ziinit.number_entry = 0; |
| @@ -529,10 +878,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc | |||
| 529 | init_linkedlist(&(ziinit.central_dir)); | 878 | init_linkedlist(&(ziinit.central_dir)); |
| 530 | 879 | ||
| 531 | 880 | ||
| 532 | zi = (zip_internal*)ALLOC(sizeof(zip_internal)); | 881 | |
| 882 | zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); | ||
| 533 | if (zi==NULL) | 883 | if (zi==NULL) |
| 534 | { | 884 | { |
| 535 | ZCLOSE(ziinit.z_filefunc,ziinit.filestream); | 885 | ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); |
| 536 | return NULL; | 886 | return NULL; |
| 537 | } | 887 | } |
| 538 | 888 | ||
| @@ -541,122 +891,8 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc | |||
| 541 | ziinit.globalcomment = NULL; | 891 | ziinit.globalcomment = NULL; |
| 542 | if (append == APPEND_STATUS_ADDINZIP) | 892 | if (append == APPEND_STATUS_ADDINZIP) |
| 543 | { | 893 | { |
| 544 | uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ | 894 | // Read and Cache Central Directory Records |
| 545 | 895 | err = LoadCentralDirectoryRecord(&ziinit); | |
| 546 | uLong size_central_dir; /* size of the central directory */ | ||
| 547 | uLong offset_central_dir; /* offset of start of central directory */ | ||
| 548 | uLong central_pos,uL; | ||
| 549 | |||
| 550 | uLong number_disk; /* number of the current dist, used for | ||
| 551 | spaning ZIP, unsupported, always 0*/ | ||
| 552 | uLong number_disk_with_CD; /* number the the disk with central dir, used | ||
| 553 | for spaning ZIP, unsupported, always 0*/ | ||
| 554 | uLong number_entry; | ||
| 555 | uLong number_entry_CD; /* total number of entries in | ||
| 556 | the central dir | ||
| 557 | (same than number_entry on nospan) */ | ||
| 558 | uLong size_comment; | ||
| 559 | |||
| 560 | central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); | ||
| 561 | if (central_pos==0) | ||
| 562 | err=ZIP_ERRNO; | ||
| 563 | |||
| 564 | if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | ||
| 565 | central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 566 | err=ZIP_ERRNO; | ||
| 567 | |||
| 568 | /* the signature, already checked */ | ||
| 569 | if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) | ||
| 570 | err=ZIP_ERRNO; | ||
| 571 | |||
| 572 | /* number of this disk */ | ||
| 573 | if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) | ||
| 574 | err=ZIP_ERRNO; | ||
| 575 | |||
| 576 | /* number of the disk with the start of the central directory */ | ||
| 577 | if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) | ||
| 578 | err=ZIP_ERRNO; | ||
| 579 | |||
| 580 | /* total number of entries in the central dir on this disk */ | ||
| 581 | if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) | ||
| 582 | err=ZIP_ERRNO; | ||
| 583 | |||
| 584 | /* total number of entries in the central dir */ | ||
| 585 | if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) | ||
| 586 | err=ZIP_ERRNO; | ||
| 587 | |||
| 588 | if ((number_entry_CD!=number_entry) || | ||
| 589 | (number_disk_with_CD!=0) || | ||
| 590 | (number_disk!=0)) | ||
| 591 | err=ZIP_BADZIPFILE; | ||
| 592 | |||
| 593 | /* size of the central directory */ | ||
| 594 | if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK) | ||
| 595 | err=ZIP_ERRNO; | ||
| 596 | |||
| 597 | /* offset of start of central directory with respect to the | ||
| 598 | starting disk number */ | ||
| 599 | if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) | ||
| 600 | err=ZIP_ERRNO; | ||
| 601 | |||
| 602 | /* zipfile global comment length */ | ||
| 603 | if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) | ||
| 604 | err=ZIP_ERRNO; | ||
| 605 | |||
| 606 | if ((central_pos<offset_central_dir+size_central_dir) && | ||
| 607 | (err==ZIP_OK)) | ||
| 608 | err=ZIP_BADZIPFILE; | ||
| 609 | |||
| 610 | if (err!=ZIP_OK) | ||
| 611 | { | ||
| 612 | ZCLOSE(ziinit.z_filefunc, ziinit.filestream); | ||
| 613 | return NULL; | ||
| 614 | } | ||
| 615 | |||
| 616 | if (size_comment>0) | ||
| 617 | { | ||
| 618 | ziinit.globalcomment = ALLOC(size_comment+1); | ||
| 619 | if (ziinit.globalcomment) | ||
| 620 | { | ||
| 621 | size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment); | ||
| 622 | ziinit.globalcomment[size_comment]=0; | ||
| 623 | } | ||
| 624 | } | ||
| 625 | |||
| 626 | byte_before_the_zipfile = central_pos - | ||
| 627 | (offset_central_dir+size_central_dir); | ||
| 628 | ziinit.add_position_when_writting_offset = byte_before_the_zipfile; | ||
| 629 | |||
| 630 | { | ||
| 631 | uLong size_central_dir_to_read = size_central_dir; | ||
| 632 | size_t buf_size = SIZEDATA_INDATABLOCK; | ||
| 633 | void* buf_read = (void*)ALLOC(buf_size); | ||
| 634 | if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | ||
| 635 | offset_central_dir + byte_before_the_zipfile, | ||
| 636 | ZLIB_FILEFUNC_SEEK_SET) != 0) | ||
| 637 | err=ZIP_ERRNO; | ||
| 638 | |||
| 639 | while ((size_central_dir_to_read>0) && (err==ZIP_OK)) | ||
| 640 | { | ||
| 641 | uLong read_this = SIZEDATA_INDATABLOCK; | ||
| 642 | if (read_this > size_central_dir_to_read) | ||
| 643 | read_this = size_central_dir_to_read; | ||
| 644 | if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) | ||
| 645 | err=ZIP_ERRNO; | ||
| 646 | |||
| 647 | if (err==ZIP_OK) | ||
| 648 | err = add_data_in_datablock(&ziinit.central_dir,buf_read, | ||
| 649 | (uLong)read_this); | ||
| 650 | size_central_dir_to_read-=read_this; | ||
| 651 | } | ||
| 652 | TRYFREE(buf_read); | ||
| 653 | } | ||
| 654 | ziinit.begin_pos = byte_before_the_zipfile; | ||
| 655 | ziinit.number_entry = number_entry_CD; | ||
| 656 | |||
| 657 | if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, | ||
| 658 | offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 659 | err=ZIP_ERRNO; | ||
| 660 | } | 896 | } |
| 661 | 897 | ||
| 662 | if (globalcomment) | 898 | if (globalcomment) |
| @@ -680,37 +916,150 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc | |||
| 680 | } | 916 | } |
| 681 | } | 917 | } |
| 682 | 918 | ||
| 683 | extern zipFile ZEXPORT zipOpen (pathname, append) | 919 | extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) |
| 684 | const char *pathname; | 920 | { |
| 685 | int append; | 921 | if (pzlib_filefunc32_def != NULL) |
| 922 | { | ||
| 923 | zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; | ||
| 924 | fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); | ||
| 925 | return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); | ||
| 926 | } | ||
| 927 | else | ||
| 928 | return zipOpen3(pathname, append, globalcomment, NULL); | ||
| 929 | } | ||
| 930 | |||
| 931 | extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) | ||
| 932 | { | ||
| 933 | if (pzlib_filefunc_def != NULL) | ||
| 934 | { | ||
| 935 | zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; | ||
| 936 | zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; | ||
| 937 | zlib_filefunc64_32_def_fill.ztell32_file = NULL; | ||
| 938 | zlib_filefunc64_32_def_fill.zseek32_file = NULL; | ||
| 939 | return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); | ||
| 940 | } | ||
| 941 | else | ||
| 942 | return zipOpen3(pathname, append, globalcomment, NULL); | ||
| 943 | } | ||
| 944 | |||
| 945 | |||
| 946 | |||
| 947 | extern zipFile ZEXPORT zipOpen (const char* pathname, int append) | ||
| 948 | { | ||
| 949 | return zipOpen3((const void*)pathname,append,NULL,NULL); | ||
| 950 | } | ||
| 951 | |||
| 952 | extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) | ||
| 686 | { | 953 | { |
| 687 | return zipOpen2(pathname,append,NULL,NULL); | 954 | return zipOpen3(pathname,append,NULL,NULL); |
| 688 | } | 955 | } |
| 689 | 956 | ||
| 690 | extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | 957 | int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) |
| 691 | extrafield_local, size_extrafield_local, | ||
| 692 | extrafield_global, size_extrafield_global, | ||
| 693 | comment, method, level, raw, | ||
| 694 | windowBits, memLevel, strategy, | ||
| 695 | password, crcForCrypting) | ||
| 696 | zipFile file; | ||
| 697 | const char* filename; | ||
| 698 | const zip_fileinfo* zipfi; | ||
| 699 | const void* extrafield_local; | ||
| 700 | uInt size_extrafield_local; | ||
| 701 | const void* extrafield_global; | ||
| 702 | uInt size_extrafield_global; | ||
| 703 | const char* comment; | ||
| 704 | int method; | ||
| 705 | int level; | ||
| 706 | int raw; | ||
| 707 | int windowBits; | ||
| 708 | int memLevel; | ||
| 709 | int strategy; | ||
| 710 | const char* password; | ||
| 711 | uLong crcForCrypting; | ||
| 712 | { | 958 | { |
| 713 | zip_internal* zi; | 959 | /* write the local header */ |
| 960 | int err; | ||
| 961 | uInt size_filename = (uInt)strlen(filename); | ||
| 962 | uInt size_extrafield = size_extrafield_local; | ||
| 963 | |||
| 964 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); | ||
| 965 | |||
| 966 | if (err==ZIP_OK) | ||
| 967 | { | ||
| 968 | if(zi->ci.zip64) | ||
| 969 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ | ||
| 970 | else | ||
| 971 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ | ||
| 972 | } | ||
| 973 | |||
| 974 | if (err==ZIP_OK) | ||
| 975 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); | ||
| 976 | |||
| 977 | if (err==ZIP_OK) | ||
| 978 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); | ||
| 979 | |||
| 980 | if (err==ZIP_OK) | ||
| 981 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); | ||
| 982 | |||
| 983 | // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later | ||
| 984 | if (err==ZIP_OK) | ||
| 985 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ | ||
| 986 | if (err==ZIP_OK) | ||
| 987 | { | ||
| 988 | if(zi->ci.zip64) | ||
| 989 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */ | ||
| 990 | else | ||
| 991 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ | ||
| 992 | } | ||
| 993 | if (err==ZIP_OK) | ||
| 994 | { | ||
| 995 | if(zi->ci.zip64) | ||
| 996 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ | ||
| 997 | else | ||
| 998 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ | ||
| 999 | } | ||
| 1000 | |||
| 1001 | if (err==ZIP_OK) | ||
| 1002 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); | ||
| 1003 | |||
| 1004 | if(zi->ci.zip64) | ||
| 1005 | { | ||
| 1006 | size_extrafield += 20; | ||
| 1007 | } | ||
| 1008 | |||
| 1009 | if (err==ZIP_OK) | ||
| 1010 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); | ||
| 1011 | |||
| 1012 | if ((err==ZIP_OK) && (size_filename > 0)) | ||
| 1013 | { | ||
| 1014 | if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) | ||
| 1015 | err = ZIP_ERRNO; | ||
| 1016 | } | ||
| 1017 | |||
| 1018 | if ((err==ZIP_OK) && (size_extrafield_local > 0)) | ||
| 1019 | { | ||
| 1020 | if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) | ||
| 1021 | err = ZIP_ERRNO; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | |||
| 1025 | if ((err==ZIP_OK) && (zi->ci.zip64)) | ||
| 1026 | { | ||
| 1027 | // write the Zip64 extended info | ||
| 1028 | short HeaderID = 1; | ||
| 1029 | short DataSize = 16; | ||
| 1030 | ZPOS64_T CompressedSize = 0; | ||
| 1031 | ZPOS64_T UncompressedSize = 0; | ||
| 1032 | |||
| 1033 | // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) | ||
| 1034 | zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); | ||
| 1035 | |||
| 1036 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); | ||
| 1037 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); | ||
| 1038 | |||
| 1039 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); | ||
| 1040 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | return err; | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | /* | ||
| 1047 | NOTE. | ||
| 1048 | When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped | ||
| 1049 | before calling this function it can be done with zipRemoveExtraInfoBlock | ||
| 1050 | |||
| 1051 | It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize | ||
| 1052 | unnecessary allocations. | ||
| 1053 | */ | ||
| 1054 | extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1055 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1056 | const void* extrafield_global, uInt size_extrafield_global, | ||
| 1057 | const char* comment, int method, int level, int raw, | ||
| 1058 | int windowBits,int memLevel, int strategy, | ||
| 1059 | const char* password, uLong crcForCrypting, | ||
| 1060 | uLong versionMadeBy, uLong flagBase, int zip64) | ||
| 1061 | { | ||
| 1062 | zip64_internal* zi; | ||
| 714 | uInt size_filename; | 1063 | uInt size_filename; |
| 715 | uInt size_comment; | 1064 | uInt size_comment; |
| 716 | uInt i; | 1065 | uInt i; |
| @@ -723,10 +1072,16 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 723 | 1072 | ||
| 724 | if (file == NULL) | 1073 | if (file == NULL) |
| 725 | return ZIP_PARAMERROR; | 1074 | return ZIP_PARAMERROR; |
| 1075 | |||
| 1076 | #ifdef HAVE_BZIP2 | ||
| 1077 | if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) | ||
| 1078 | return ZIP_PARAMERROR; | ||
| 1079 | #else | ||
| 726 | if ((method!=0) && (method!=Z_DEFLATED)) | 1080 | if ((method!=0) && (method!=Z_DEFLATED)) |
| 727 | return ZIP_PARAMERROR; | 1081 | return ZIP_PARAMERROR; |
| 1082 | #endif | ||
| 728 | 1083 | ||
| 729 | zi = (zip_internal*)file; | 1084 | zi = (zip64_internal*)file; |
| 730 | 1085 | ||
| 731 | if (zi->in_opened_file_inzip == 1) | 1086 | if (zi->in_opened_file_inzip == 1) |
| 732 | { | 1087 | { |
| @@ -735,7 +1090,6 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 735 | return err; | 1090 | return err; |
| 736 | } | 1091 | } |
| 737 | 1092 | ||
| 738 | |||
| 739 | if (filename==NULL) | 1093 | if (filename==NULL) |
| 740 | filename="-"; | 1094 | filename="-"; |
| 741 | 1095 | ||
| @@ -752,10 +1106,11 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 752 | { | 1106 | { |
| 753 | if (zipfi->dosDate != 0) | 1107 | if (zipfi->dosDate != 0) |
| 754 | zi->ci.dosDate = zipfi->dosDate; | 1108 | zi->ci.dosDate = zipfi->dosDate; |
| 755 | else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); | 1109 | else |
| 1110 | zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); | ||
| 756 | } | 1111 | } |
| 757 | 1112 | ||
| 758 | zi->ci.flag = 0; | 1113 | zi->ci.flag = flagBase; |
| 759 | if ((level==8) || (level==9)) | 1114 | if ((level==8) || (level==9)) |
| 760 | zi->ci.flag |= 2; | 1115 | zi->ci.flag |= 2; |
| 761 | if ((level==2)) | 1116 | if ((level==2)) |
| @@ -771,37 +1126,43 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 771 | zi->ci.stream_initialised = 0; | 1126 | zi->ci.stream_initialised = 0; |
| 772 | zi->ci.pos_in_buffered_data = 0; | 1127 | zi->ci.pos_in_buffered_data = 0; |
| 773 | zi->ci.raw = raw; | 1128 | zi->ci.raw = raw; |
| 774 | zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; | 1129 | zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); |
| 775 | zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + | ||
| 776 | size_extrafield_global + size_comment; | ||
| 777 | zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); | ||
| 778 | 1130 | ||
| 779 | ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); | 1131 | zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; |
| 1132 | zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data | ||
| 1133 | |||
| 1134 | zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); | ||
| 1135 | |||
| 1136 | zi->ci.size_centralExtra = size_extrafield_global; | ||
| 1137 | zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); | ||
| 780 | /* version info */ | 1138 | /* version info */ |
| 781 | ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); | 1139 | zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2); |
| 782 | ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); | 1140 | zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); |
| 783 | ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); | 1141 | zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); |
| 784 | ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); | 1142 | zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); |
| 785 | ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); | 1143 | zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); |
| 786 | ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ | 1144 | zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ |
| 787 | ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ | 1145 | zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ |
| 788 | ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ | 1146 | zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ |
| 789 | ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); | 1147 | zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); |
| 790 | ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); | 1148 | zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); |
| 791 | ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); | 1149 | zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); |
| 792 | ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ | 1150 | zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ |
| 793 | 1151 | ||
| 794 | if (zipfi==NULL) | 1152 | if (zipfi==NULL) |
| 795 | ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); | 1153 | zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); |
| 796 | else | 1154 | else |
| 797 | ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); | 1155 | zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); |
| 798 | 1156 | ||
| 799 | if (zipfi==NULL) | 1157 | if (zipfi==NULL) |
| 800 | ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); | 1158 | zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); |
| 801 | else | 1159 | else |
| 802 | ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); | 1160 | zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); |
| 803 | 1161 | ||
| 804 | ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); | 1162 | if(zi->ci.pos_local_header >= 0xffffffff) |
| 1163 | zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); | ||
| 1164 | else | ||
| 1165 | zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); | ||
| 805 | 1166 | ||
| 806 | for (i=0;i<size_filename;i++) | 1167 | for (i=0;i<size_filename;i++) |
| 807 | *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); | 1168 | *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); |
| @@ -816,63 +1177,66 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 816 | if (zi->ci.central_header == NULL) | 1177 | if (zi->ci.central_header == NULL) |
| 817 | return ZIP_INTERNALERROR; | 1178 | return ZIP_INTERNALERROR; |
| 818 | 1179 | ||
| 819 | /* write the local header */ | 1180 | zi->ci.zip64 = zip64; |
| 820 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); | 1181 | zi->ci.totalCompressedData = 0; |
| 821 | 1182 | zi->ci.totalUncompressedData = 0; | |
| 822 | if (err==ZIP_OK) | 1183 | zi->ci.pos_zip64extrainfo = 0; |
| 823 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ | 1184 | |
| 824 | if (err==ZIP_OK) | 1185 | err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); |
| 825 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); | 1186 | |
| 826 | 1187 | #ifdef HAVE_BZIP2 | |
| 827 | if (err==ZIP_OK) | 1188 | zi->ci.bstream.avail_in = (uInt)0; |
| 828 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); | 1189 | zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; |
| 829 | 1190 | zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; | |
| 830 | if (err==ZIP_OK) | 1191 | zi->ci.bstream.total_in_hi32 = 0; |
| 831 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); | 1192 | zi->ci.bstream.total_in_lo32 = 0; |
| 832 | 1193 | zi->ci.bstream.total_out_hi32 = 0; | |
| 833 | if (err==ZIP_OK) | 1194 | zi->ci.bstream.total_out_lo32 = 0; |
| 834 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ | 1195 | #endif |
| 835 | if (err==ZIP_OK) | ||
| 836 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ | ||
| 837 | if (err==ZIP_OK) | ||
| 838 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ | ||
| 839 | |||
| 840 | if (err==ZIP_OK) | ||
| 841 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); | ||
| 842 | |||
| 843 | if (err==ZIP_OK) | ||
| 844 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); | ||
| 845 | |||
| 846 | if ((err==ZIP_OK) && (size_filename>0)) | ||
| 847 | if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) | ||
| 848 | err = ZIP_ERRNO; | ||
| 849 | |||
| 850 | if ((err==ZIP_OK) && (size_extrafield_local>0)) | ||
| 851 | if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) | ||
| 852 | !=size_extrafield_local) | ||
| 853 | err = ZIP_ERRNO; | ||
| 854 | 1196 | ||
| 855 | zi->ci.stream.avail_in = (uInt)0; | 1197 | zi->ci.stream.avail_in = (uInt)0; |
| 856 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | 1198 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; |
| 857 | zi->ci.stream.next_out = zi->ci.buffered_data; | 1199 | zi->ci.stream.next_out = zi->ci.buffered_data; |
| 858 | zi->ci.stream.total_in = 0; | 1200 | zi->ci.stream.total_in = 0; |
| 859 | zi->ci.stream.total_out = 0; | 1201 | zi->ci.stream.total_out = 0; |
| 1202 | zi->ci.stream.data_type = Z_BINARY; | ||
| 860 | 1203 | ||
| 1204 | #ifdef HAVE_BZIP2 | ||
| 1205 | if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) | ||
| 1206 | #else | ||
| 861 | if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | 1207 | if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) |
| 1208 | #endif | ||
| 862 | { | 1209 | { |
| 863 | zi->ci.stream.zalloc = (alloc_func)0; | 1210 | if(zi->ci.method == Z_DEFLATED) |
| 864 | zi->ci.stream.zfree = (free_func)0; | 1211 | { |
| 865 | zi->ci.stream.opaque = (voidpf)0; | 1212 | zi->ci.stream.zalloc = (alloc_func)0; |
| 1213 | zi->ci.stream.zfree = (free_func)0; | ||
| 1214 | zi->ci.stream.opaque = (voidpf)0; | ||
| 866 | 1215 | ||
| 867 | if (windowBits>0) | 1216 | if (windowBits>0) |
| 868 | windowBits = -windowBits; | 1217 | windowBits = -windowBits; |
| 869 | 1218 | ||
| 870 | err = deflateInit2(&zi->ci.stream, level, | 1219 | err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); |
| 871 | Z_DEFLATED, windowBits, memLevel, strategy); | 1220 | |
| 1221 | if (err==Z_OK) | ||
| 1222 | zi->ci.stream_initialised = Z_DEFLATED; | ||
| 1223 | } | ||
| 1224 | else if(zi->ci.method == Z_BZIP2ED) | ||
| 1225 | { | ||
| 1226 | #ifdef HAVE_BZIP2 | ||
| 1227 | // Init BZip stuff here | ||
| 1228 | zi->ci.bstream.bzalloc = 0; | ||
| 1229 | zi->ci.bstream.bzfree = 0; | ||
| 1230 | zi->ci.bstream.opaque = (voidpf)0; | ||
| 1231 | |||
| 1232 | err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); | ||
| 1233 | if(err == BZ_OK) | ||
| 1234 | zi->ci.stream_initialised = Z_BZIP2ED; | ||
| 1235 | #endif | ||
| 1236 | } | ||
| 872 | 1237 | ||
| 873 | if (err==Z_OK) | ||
| 874 | zi->ci.stream_initialised = 1; | ||
| 875 | } | 1238 | } |
| 1239 | |||
| 876 | # ifndef NOCRYPT | 1240 | # ifndef NOCRYPT |
| 877 | zi->ci.crypt_header_size = 0; | 1241 | zi->ci.crypt_header_size = 0; |
| 878 | if ((err==Z_OK) && (password != NULL)) | 1242 | if ((err==Z_OK) && (password != NULL)) |
| @@ -886,7 +1250,7 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 886 | sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); | 1250 | sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); |
| 887 | zi->ci.crypt_header_size = sizeHead; | 1251 | zi->ci.crypt_header_size = sizeHead; |
| 888 | 1252 | ||
| 889 | if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) | 1253 | if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) |
| 890 | err = ZIP_ERRNO; | 1254 | err = ZIP_ERRNO; |
| 891 | } | 1255 | } |
| 892 | # endif | 1256 | # endif |
| @@ -896,53 +1260,105 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, | |||
| 896 | return err; | 1260 | return err; |
| 897 | } | 1261 | } |
| 898 | 1262 | ||
| 899 | extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, | 1263 | extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, |
| 900 | extrafield_local, size_extrafield_local, | 1264 | const void* extrafield_local, uInt size_extrafield_local, |
| 901 | extrafield_global, size_extrafield_global, | 1265 | const void* extrafield_global, uInt size_extrafield_global, |
| 902 | comment, method, level, raw) | 1266 | const char* comment, int method, int level, int raw, |
| 903 | zipFile file; | 1267 | int windowBits,int memLevel, int strategy, |
| 904 | const char* filename; | 1268 | const char* password, uLong crcForCrypting, |
| 905 | const zip_fileinfo* zipfi; | 1269 | uLong versionMadeBy, uLong flagBase) |
| 906 | const void* extrafield_local; | 1270 | { |
| 907 | uInt size_extrafield_local; | 1271 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, |
| 908 | const void* extrafield_global; | 1272 | extrafield_local, size_extrafield_local, |
| 909 | uInt size_extrafield_global; | 1273 | extrafield_global, size_extrafield_global, |
| 910 | const char* comment; | 1274 | comment, method, level, raw, |
| 911 | int method; | 1275 | windowBits, memLevel, strategy, |
| 912 | int level; | 1276 | password, crcForCrypting, versionMadeBy, flagBase, 0); |
| 913 | int raw; | 1277 | } |
| 1278 | |||
| 1279 | extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1280 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1281 | const void* extrafield_global, uInt size_extrafield_global, | ||
| 1282 | const char* comment, int method, int level, int raw, | ||
| 1283 | int windowBits,int memLevel, int strategy, | ||
| 1284 | const char* password, uLong crcForCrypting) | ||
| 1285 | { | ||
| 1286 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, | ||
| 1287 | extrafield_local, size_extrafield_local, | ||
| 1288 | extrafield_global, size_extrafield_global, | ||
| 1289 | comment, method, level, raw, | ||
| 1290 | windowBits, memLevel, strategy, | ||
| 1291 | password, crcForCrypting, VERSIONMADEBY, 0, 0); | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1295 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1296 | const void* extrafield_global, uInt size_extrafield_global, | ||
| 1297 | const char* comment, int method, int level, int raw, | ||
| 1298 | int windowBits,int memLevel, int strategy, | ||
| 1299 | const char* password, uLong crcForCrypting, int zip64) | ||
| 1300 | { | ||
| 1301 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, | ||
| 1302 | extrafield_local, size_extrafield_local, | ||
| 1303 | extrafield_global, size_extrafield_global, | ||
| 1304 | comment, method, level, raw, | ||
| 1305 | windowBits, memLevel, strategy, | ||
| 1306 | password, crcForCrypting, VERSIONMADEBY, 0, zip64); | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1310 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1311 | const void* extrafield_global, uInt size_extrafield_global, | ||
| 1312 | const char* comment, int method, int level, int raw) | ||
| 1313 | { | ||
| 1314 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, | ||
| 1315 | extrafield_local, size_extrafield_local, | ||
| 1316 | extrafield_global, size_extrafield_global, | ||
| 1317 | comment, method, level, raw, | ||
| 1318 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | ||
| 1319 | NULL, 0, VERSIONMADEBY, 0, 0); | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1323 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1324 | const void* extrafield_global, uInt size_extrafield_global, | ||
| 1325 | const char* comment, int method, int level, int raw, int zip64) | ||
| 914 | { | 1326 | { |
| 915 | return zipOpenNewFileInZip3 (file, filename, zipfi, | 1327 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, |
| 916 | extrafield_local, size_extrafield_local, | 1328 | extrafield_local, size_extrafield_local, |
| 917 | extrafield_global, size_extrafield_global, | 1329 | extrafield_global, size_extrafield_global, |
| 918 | comment, method, level, raw, | 1330 | comment, method, level, raw, |
| 919 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | 1331 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
| 920 | NULL, 0); | 1332 | NULL, 0, VERSIONMADEBY, 0, zip64); |
| 1333 | } | ||
| 1334 | |||
| 1335 | extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, | ||
| 1336 | const void* extrafield_local, uInt size_extrafield_local, | ||
| 1337 | const void*extrafield_global, uInt size_extrafield_global, | ||
| 1338 | const char* comment, int method, int level, int zip64) | ||
| 1339 | { | ||
| 1340 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, | ||
| 1341 | extrafield_local, size_extrafield_local, | ||
| 1342 | extrafield_global, size_extrafield_global, | ||
| 1343 | comment, method, level, 0, | ||
| 1344 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | ||
| 1345 | NULL, 0, VERSIONMADEBY, 0, zip64); | ||
| 921 | } | 1346 | } |
| 922 | 1347 | ||
| 923 | extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, | 1348 | extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, |
| 924 | extrafield_local, size_extrafield_local, | 1349 | const void* extrafield_local, uInt size_extrafield_local, |
| 925 | extrafield_global, size_extrafield_global, | 1350 | const void*extrafield_global, uInt size_extrafield_global, |
| 926 | comment, method, level) | 1351 | const char* comment, int method, int level) |
| 927 | zipFile file; | ||
| 928 | const char* filename; | ||
| 929 | const zip_fileinfo* zipfi; | ||
| 930 | const void* extrafield_local; | ||
| 931 | uInt size_extrafield_local; | ||
| 932 | const void* extrafield_global; | ||
| 933 | uInt size_extrafield_global; | ||
| 934 | const char* comment; | ||
| 935 | int method; | ||
| 936 | int level; | ||
| 937 | { | 1352 | { |
| 938 | return zipOpenNewFileInZip2 (file, filename, zipfi, | 1353 | return zipOpenNewFileInZip4_64 (file, filename, zipfi, |
| 939 | extrafield_local, size_extrafield_local, | 1354 | extrafield_local, size_extrafield_local, |
| 940 | extrafield_global, size_extrafield_global, | 1355 | extrafield_global, size_extrafield_global, |
| 941 | comment, method, level, 0); | 1356 | comment, method, level, 0, |
| 1357 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, | ||
| 1358 | NULL, 0, VERSIONMADEBY, 0, 0); | ||
| 942 | } | 1359 | } |
| 943 | 1360 | ||
| 944 | local int zipFlushWriteBuffer(zi) | 1361 | local int zip64FlushWriteBuffer(zip64_internal* zi) |
| 945 | zip_internal* zi; | ||
| 946 | { | 1362 | { |
| 947 | int err=ZIP_OK; | 1363 | int err=ZIP_OK; |
| 948 | 1364 | ||
| @@ -952,169 +1368,372 @@ local int zipFlushWriteBuffer(zi) | |||
| 952 | uInt i; | 1368 | uInt i; |
| 953 | int t; | 1369 | int t; |
| 954 | for (i=0;i<zi->ci.pos_in_buffered_data;i++) | 1370 | for (i=0;i<zi->ci.pos_in_buffered_data;i++) |
| 955 | zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, | 1371 | zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); |
| 956 | zi->ci.buffered_data[i],t); | ||
| 957 | #endif | 1372 | #endif |
| 958 | } | 1373 | } |
| 959 | if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) | 1374 | |
| 960 | !=zi->ci.pos_in_buffered_data) | 1375 | if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) |
| 961 | err = ZIP_ERRNO; | 1376 | err = ZIP_ERRNO; |
| 1377 | |||
| 1378 | zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; | ||
| 1379 | |||
| 1380 | #ifdef HAVE_BZIP2 | ||
| 1381 | if(zi->ci.method == Z_BZIP2ED) | ||
| 1382 | { | ||
| 1383 | zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; | ||
| 1384 | zi->ci.bstream.total_in_lo32 = 0; | ||
| 1385 | zi->ci.bstream.total_in_hi32 = 0; | ||
| 1386 | } | ||
| 1387 | else | ||
| 1388 | #endif | ||
| 1389 | { | ||
| 1390 | zi->ci.totalUncompressedData += zi->ci.stream.total_in; | ||
| 1391 | zi->ci.stream.total_in = 0; | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | |||
| 962 | zi->ci.pos_in_buffered_data = 0; | 1395 | zi->ci.pos_in_buffered_data = 0; |
| 1396 | |||
| 963 | return err; | 1397 | return err; |
| 964 | } | 1398 | } |
| 965 | 1399 | ||
| 966 | extern int ZEXPORT zipWriteInFileInZip (file, buf, len) | 1400 | extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) |
| 967 | zipFile file; | ||
| 968 | const void* buf; | ||
| 969 | unsigned len; | ||
| 970 | { | 1401 | { |
| 971 | zip_internal* zi; | 1402 | zip64_internal* zi; |
| 972 | int err=ZIP_OK; | 1403 | int err=ZIP_OK; |
| 973 | 1404 | ||
| 974 | if (file == NULL) | 1405 | if (file == NULL) |
| 975 | return ZIP_PARAMERROR; | 1406 | return ZIP_PARAMERROR; |
| 976 | zi = (zip_internal*)file; | 1407 | zi = (zip64_internal*)file; |
| 977 | 1408 | ||
| 978 | if (zi->in_opened_file_inzip == 0) | 1409 | if (zi->in_opened_file_inzip == 0) |
| 979 | return ZIP_PARAMERROR; | 1410 | return ZIP_PARAMERROR; |
| 980 | 1411 | ||
| 981 | zi->ci.stream.next_in = (void*)buf; | 1412 | zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); |
| 982 | zi->ci.stream.avail_in = len; | ||
| 983 | zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); | ||
| 984 | 1413 | ||
| 985 | while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) | 1414 | #ifdef HAVE_BZIP2 |
| 1415 | if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw)) | ||
| 986 | { | 1416 | { |
| 987 | if (zi->ci.stream.avail_out == 0) | 1417 | zi->ci.bstream.next_in = (void*)buf; |
| 1418 | zi->ci.bstream.avail_in = len; | ||
| 1419 | err = BZ_RUN_OK; | ||
| 1420 | |||
| 1421 | while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0)) | ||
| 1422 | { | ||
| 1423 | if (zi->ci.bstream.avail_out == 0) | ||
| 988 | { | 1424 | { |
| 989 | if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) | 1425 | if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) |
| 990 | err = ZIP_ERRNO; | 1426 | err = ZIP_ERRNO; |
| 991 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | 1427 | zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; |
| 992 | zi->ci.stream.next_out = zi->ci.buffered_data; | 1428 | zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; |
| 993 | } | 1429 | } |
| 994 | 1430 | ||
| 995 | 1431 | ||
| 996 | if(err != ZIP_OK) | 1432 | if(err != BZ_RUN_OK) |
| 997 | break; | 1433 | break; |
| 998 | 1434 | ||
| 999 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | 1435 | if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) |
| 1000 | { | 1436 | { |
| 1001 | uLong uTotalOutBefore = zi->ci.stream.total_out; | 1437 | uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; |
| 1002 | err=deflate(&zi->ci.stream, Z_NO_FLUSH); | 1438 | // uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; |
| 1003 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | 1439 | err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); |
| 1004 | 1440 | ||
| 1441 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; | ||
| 1005 | } | 1442 | } |
| 1006 | else | 1443 | } |
| 1007 | { | 1444 | |
| 1008 | uInt copy_this,i; | 1445 | if(err == BZ_RUN_OK) |
| 1009 | if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) | 1446 | err = ZIP_OK; |
| 1010 | copy_this = zi->ci.stream.avail_in; | 1447 | } |
| 1011 | else | 1448 | else |
| 1012 | copy_this = zi->ci.stream.avail_out; | 1449 | #endif |
| 1013 | for (i=0;i<copy_this;i++) | 1450 | { |
| 1014 | *(((char*)zi->ci.stream.next_out)+i) = | 1451 | zi->ci.stream.next_in = (Bytef*)buf; |
| 1015 | *(((const char*)zi->ci.stream.next_in)+i); | 1452 | zi->ci.stream.avail_in = len; |
| 1016 | { | 1453 | |
| 1017 | zi->ci.stream.avail_in -= copy_this; | 1454 | while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) |
| 1018 | zi->ci.stream.avail_out-= copy_this; | 1455 | { |
| 1019 | zi->ci.stream.next_in+= copy_this; | 1456 | if (zi->ci.stream.avail_out == 0) |
| 1020 | zi->ci.stream.next_out+= copy_this; | 1457 | { |
| 1021 | zi->ci.stream.total_in+= copy_this; | 1458 | if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) |
| 1022 | zi->ci.stream.total_out+= copy_this; | 1459 | err = ZIP_ERRNO; |
| 1023 | zi->ci.pos_in_buffered_data += copy_this; | 1460 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; |
| 1024 | } | 1461 | zi->ci.stream.next_out = zi->ci.buffered_data; |
| 1025 | } | 1462 | } |
| 1463 | |||
| 1464 | |||
| 1465 | if(err != ZIP_OK) | ||
| 1466 | break; | ||
| 1467 | |||
| 1468 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | ||
| 1469 | { | ||
| 1470 | uLong uTotalOutBefore = zi->ci.stream.total_out; | ||
| 1471 | err=deflate(&zi->ci.stream, Z_NO_FLUSH); | ||
| 1472 | if(uTotalOutBefore > zi->ci.stream.total_out) | ||
| 1473 | { | ||
| 1474 | int bBreak = 0; | ||
| 1475 | bBreak++; | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | ||
| 1479 | } | ||
| 1480 | else | ||
| 1481 | { | ||
| 1482 | uInt copy_this,i; | ||
| 1483 | if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) | ||
| 1484 | copy_this = zi->ci.stream.avail_in; | ||
| 1485 | else | ||
| 1486 | copy_this = zi->ci.stream.avail_out; | ||
| 1487 | |||
| 1488 | for (i = 0; i < copy_this; i++) | ||
| 1489 | *(((char*)zi->ci.stream.next_out)+i) = | ||
| 1490 | *(((const char*)zi->ci.stream.next_in)+i); | ||
| 1491 | { | ||
| 1492 | zi->ci.stream.avail_in -= copy_this; | ||
| 1493 | zi->ci.stream.avail_out-= copy_this; | ||
| 1494 | zi->ci.stream.next_in+= copy_this; | ||
| 1495 | zi->ci.stream.next_out+= copy_this; | ||
| 1496 | zi->ci.stream.total_in+= copy_this; | ||
| 1497 | zi->ci.stream.total_out+= copy_this; | ||
| 1498 | zi->ci.pos_in_buffered_data += copy_this; | ||
| 1499 | } | ||
| 1500 | } | ||
| 1501 | }// while(...) | ||
| 1026 | } | 1502 | } |
| 1027 | 1503 | ||
| 1028 | return err; | 1504 | return err; |
| 1029 | } | 1505 | } |
| 1030 | 1506 | ||
| 1031 | extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) | 1507 | extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) |
| 1032 | zipFile file; | ||
| 1033 | uLong uncompressed_size; | ||
| 1034 | uLong crc32; | ||
| 1035 | { | 1508 | { |
| 1036 | zip_internal* zi; | 1509 | return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); |
| 1037 | uLong compressed_size; | 1510 | } |
| 1511 | |||
| 1512 | extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) | ||
| 1513 | { | ||
| 1514 | zip64_internal* zi; | ||
| 1515 | ZPOS64_T compressed_size; | ||
| 1516 | uLong invalidValue = 0xffffffff; | ||
| 1517 | short datasize = 0; | ||
| 1038 | int err=ZIP_OK; | 1518 | int err=ZIP_OK; |
| 1039 | 1519 | ||
| 1040 | if (file == NULL) | 1520 | if (file == NULL) |
| 1041 | return ZIP_PARAMERROR; | 1521 | return ZIP_PARAMERROR; |
| 1042 | zi = (zip_internal*)file; | 1522 | zi = (zip64_internal*)file; |
| 1043 | 1523 | ||
| 1044 | if (zi->in_opened_file_inzip == 0) | 1524 | if (zi->in_opened_file_inzip == 0) |
| 1045 | return ZIP_PARAMERROR; | 1525 | return ZIP_PARAMERROR; |
| 1046 | zi->ci.stream.avail_in = 0; | 1526 | zi->ci.stream.avail_in = 0; |
| 1047 | 1527 | ||
| 1048 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | 1528 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) |
| 1049 | while (err==ZIP_OK) | 1529 | { |
| 1530 | while (err==ZIP_OK) | ||
| 1531 | { | ||
| 1532 | uLong uTotalOutBefore; | ||
| 1533 | if (zi->ci.stream.avail_out == 0) | ||
| 1534 | { | ||
| 1535 | if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) | ||
| 1536 | err = ZIP_ERRNO; | ||
| 1537 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | ||
| 1538 | zi->ci.stream.next_out = zi->ci.buffered_data; | ||
| 1539 | } | ||
| 1540 | uTotalOutBefore = zi->ci.stream.total_out; | ||
| 1541 | err=deflate(&zi->ci.stream, Z_FINISH); | ||
| 1542 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | ||
| 1543 | } | ||
| 1544 | } | ||
| 1545 | else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) | ||
| 1050 | { | 1546 | { |
| 1547 | #ifdef HAVE_BZIP2 | ||
| 1548 | err = BZ_FINISH_OK; | ||
| 1549 | while (err==BZ_FINISH_OK) | ||
| 1550 | { | ||
| 1051 | uLong uTotalOutBefore; | 1551 | uLong uTotalOutBefore; |
| 1052 | if (zi->ci.stream.avail_out == 0) | 1552 | if (zi->ci.bstream.avail_out == 0) |
| 1053 | { | 1553 | { |
| 1054 | if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) | 1554 | if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) |
| 1055 | err = ZIP_ERRNO; | 1555 | err = ZIP_ERRNO; |
| 1056 | zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; | 1556 | zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; |
| 1057 | zi->ci.stream.next_out = zi->ci.buffered_data; | 1557 | zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; |
| 1058 | } | 1558 | } |
| 1059 | uTotalOutBefore = zi->ci.stream.total_out; | 1559 | uTotalOutBefore = zi->ci.bstream.total_out_lo32; |
| 1060 | err=deflate(&zi->ci.stream, Z_FINISH); | 1560 | err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); |
| 1061 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; | 1561 | if(err == BZ_STREAM_END) |
| 1562 | err = Z_STREAM_END; | ||
| 1563 | |||
| 1564 | zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); | ||
| 1565 | } | ||
| 1566 | |||
| 1567 | if(err == BZ_FINISH_OK) | ||
| 1568 | err = ZIP_OK; | ||
| 1569 | #endif | ||
| 1062 | } | 1570 | } |
| 1063 | 1571 | ||
| 1064 | if (err==Z_STREAM_END) | 1572 | if (err==Z_STREAM_END) |
| 1065 | err=ZIP_OK; /* this is normal */ | 1573 | err=ZIP_OK; /* this is normal */ |
| 1066 | 1574 | ||
| 1067 | if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) | 1575 | if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) |
| 1068 | if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) | 1576 | { |
| 1577 | if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) | ||
| 1069 | err = ZIP_ERRNO; | 1578 | err = ZIP_ERRNO; |
| 1579 | } | ||
| 1070 | 1580 | ||
| 1071 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) | 1581 | if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) |
| 1072 | { | 1582 | { |
| 1073 | err=deflateEnd(&zi->ci.stream); | 1583 | int tmp_err = deflateEnd(&zi->ci.stream); |
| 1584 | if (err == ZIP_OK) | ||
| 1585 | err = tmp_err; | ||
| 1074 | zi->ci.stream_initialised = 0; | 1586 | zi->ci.stream_initialised = 0; |
| 1075 | } | 1587 | } |
| 1588 | #ifdef HAVE_BZIP2 | ||
| 1589 | else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) | ||
| 1590 | { | ||
| 1591 | int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); | ||
| 1592 | if (err==ZIP_OK) | ||
| 1593 | err = tmperr; | ||
| 1594 | zi->ci.stream_initialised = 0; | ||
| 1595 | } | ||
| 1596 | #endif | ||
| 1076 | 1597 | ||
| 1077 | if (!zi->ci.raw) | 1598 | if (!zi->ci.raw) |
| 1078 | { | 1599 | { |
| 1079 | crc32 = (uLong)zi->ci.crc32; | 1600 | crc32 = (uLong)zi->ci.crc32; |
| 1080 | uncompressed_size = (uLong)zi->ci.stream.total_in; | 1601 | uncompressed_size = zi->ci.totalUncompressedData; |
| 1081 | } | 1602 | } |
| 1082 | compressed_size = (uLong)zi->ci.stream.total_out; | 1603 | compressed_size = zi->ci.totalCompressedData; |
| 1604 | |||
| 1083 | # ifndef NOCRYPT | 1605 | # ifndef NOCRYPT |
| 1084 | compressed_size += zi->ci.crypt_header_size; | 1606 | compressed_size += zi->ci.crypt_header_size; |
| 1085 | # endif | 1607 | # endif |
| 1086 | 1608 | ||
| 1087 | ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ | 1609 | // update Current Item crc and sizes, |
| 1088 | ziplocal_putValue_inmemory(zi->ci.central_header+20, | 1610 | if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) |
| 1089 | compressed_size,4); /*compr size*/ | 1611 | { |
| 1612 | /*version Made by*/ | ||
| 1613 | zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); | ||
| 1614 | /*version needed*/ | ||
| 1615 | zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); | ||
| 1616 | |||
| 1617 | } | ||
| 1618 | |||
| 1619 | zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ | ||
| 1620 | |||
| 1621 | |||
| 1622 | if(compressed_size >= 0xffffffff) | ||
| 1623 | zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/ | ||
| 1624 | else | ||
| 1625 | zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ | ||
| 1626 | |||
| 1627 | /// set internal file attributes field | ||
| 1090 | if (zi->ci.stream.data_type == Z_ASCII) | 1628 | if (zi->ci.stream.data_type == Z_ASCII) |
| 1091 | ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); | 1629 | zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); |
| 1092 | ziplocal_putValue_inmemory(zi->ci.central_header+24, | 1630 | |
| 1093 | uncompressed_size,4); /*uncompr size*/ | 1631 | if(uncompressed_size >= 0xffffffff) |
| 1632 | zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/ | ||
| 1633 | else | ||
| 1634 | zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ | ||
| 1635 | |||
| 1636 | // Add ZIP64 extra info field for uncompressed size | ||
| 1637 | if(uncompressed_size >= 0xffffffff) | ||
| 1638 | datasize += 8; | ||
| 1639 | |||
| 1640 | // Add ZIP64 extra info field for compressed size | ||
| 1641 | if(compressed_size >= 0xffffffff) | ||
| 1642 | datasize += 8; | ||
| 1643 | |||
| 1644 | // Add ZIP64 extra info field for relative offset to local file header of current file | ||
| 1645 | if(zi->ci.pos_local_header >= 0xffffffff) | ||
| 1646 | datasize += 8; | ||
| 1647 | |||
| 1648 | if(datasize > 0) | ||
| 1649 | { | ||
| 1650 | char* p = NULL; | ||
| 1651 | |||
| 1652 | if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) | ||
| 1653 | { | ||
| 1654 | // we can not write more data to the buffer that we have room for. | ||
| 1655 | return ZIP_BADZIPFILE; | ||
| 1656 | } | ||
| 1657 | |||
| 1658 | p = zi->ci.central_header + zi->ci.size_centralheader; | ||
| 1659 | |||
| 1660 | // Add Extra Information Header for 'ZIP64 information' | ||
| 1661 | zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID | ||
| 1662 | p += 2; | ||
| 1663 | zip64local_putValue_inmemory(p, datasize, 2); // DataSize | ||
| 1664 | p += 2; | ||
| 1665 | |||
| 1666 | if(uncompressed_size >= 0xffffffff) | ||
| 1667 | { | ||
| 1668 | zip64local_putValue_inmemory(p, uncompressed_size, 8); | ||
| 1669 | p += 8; | ||
| 1670 | } | ||
| 1094 | 1671 | ||
| 1672 | if(compressed_size >= 0xffffffff) | ||
| 1673 | { | ||
| 1674 | zip64local_putValue_inmemory(p, compressed_size, 8); | ||
| 1675 | p += 8; | ||
| 1676 | } | ||
| 1677 | |||
| 1678 | if(zi->ci.pos_local_header >= 0xffffffff) | ||
| 1679 | { | ||
| 1680 | zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); | ||
| 1681 | p += 8; | ||
| 1682 | } | ||
| 1683 | |||
| 1684 | // Update how much extra free space we got in the memory buffer | ||
| 1685 | // and increase the centralheader size so the new ZIP64 fields are included | ||
| 1686 | // ( 4 below is the size of HeaderID and DataSize field ) | ||
| 1687 | zi->ci.size_centralExtraFree -= datasize + 4; | ||
| 1688 | zi->ci.size_centralheader += datasize + 4; | ||
| 1689 | |||
| 1690 | // Update the extra info size field | ||
| 1691 | zi->ci.size_centralExtra += datasize + 4; | ||
| 1692 | zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); | ||
| 1693 | } | ||
| 1694 | |||
| 1095 | if (err==ZIP_OK) | 1695 | if (err==ZIP_OK) |
| 1096 | err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, | 1696 | err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); |
| 1097 | (uLong)zi->ci.size_centralheader); | 1697 | |
| 1098 | free(zi->ci.central_header); | 1698 | free(zi->ci.central_header); |
| 1099 | 1699 | ||
| 1100 | if (err==ZIP_OK) | 1700 | if (err==ZIP_OK) |
| 1101 | { | 1701 | { |
| 1102 | long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); | 1702 | // Update the LocalFileHeader with the new values. |
| 1103 | if (ZSEEK(zi->z_filefunc,zi->filestream, | 1703 | |
| 1104 | zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) | 1704 | ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); |
| 1705 | |||
| 1706 | if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 1105 | err = ZIP_ERRNO; | 1707 | err = ZIP_ERRNO; |
| 1106 | 1708 | ||
| 1107 | if (err==ZIP_OK) | 1709 | if (err==ZIP_OK) |
| 1108 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ | 1710 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ |
| 1109 | 1711 | ||
| 1110 | if (err==ZIP_OK) /* compressed size, unknown */ | 1712 | if(uncompressed_size >= 0xffffffff) |
| 1111 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); | 1713 | { |
| 1714 | if(zi->ci.pos_zip64extrainfo > 0) | ||
| 1715 | { | ||
| 1716 | // Update the size in the ZIP64 extended field. | ||
| 1717 | if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 1718 | err = ZIP_ERRNO; | ||
| 1719 | |||
| 1720 | if (err==ZIP_OK) /* compressed size, unknown */ | ||
| 1721 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); | ||
| 1722 | |||
| 1723 | if (err==ZIP_OK) /* uncompressed size, unknown */ | ||
| 1724 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); | ||
| 1725 | } | ||
| 1726 | } | ||
| 1727 | else | ||
| 1728 | { | ||
| 1729 | if (err==ZIP_OK) /* compressed size, unknown */ | ||
| 1730 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); | ||
| 1112 | 1731 | ||
| 1113 | if (err==ZIP_OK) /* uncompressed size, unknown */ | 1732 | if (err==ZIP_OK) /* uncompressed size, unknown */ |
| 1114 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); | 1733 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); |
| 1734 | } | ||
| 1115 | 1735 | ||
| 1116 | if (ZSEEK(zi->z_filefunc,zi->filestream, | 1736 | if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1117 | cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) | ||
| 1118 | err = ZIP_ERRNO; | 1737 | err = ZIP_ERRNO; |
| 1119 | } | 1738 | } |
| 1120 | 1739 | ||
| @@ -1124,24 +1743,150 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) | |||
| 1124 | return err; | 1743 | return err; |
| 1125 | } | 1744 | } |
| 1126 | 1745 | ||
| 1127 | extern int ZEXPORT zipCloseFileInZip (file) | 1746 | extern int ZEXPORT zipCloseFileInZip (zipFile file) |
| 1128 | zipFile file; | ||
| 1129 | { | 1747 | { |
| 1130 | return zipCloseFileInZipRaw (file,0,0); | 1748 | return zipCloseFileInZipRaw (file,0,0); |
| 1131 | } | 1749 | } |
| 1132 | 1750 | ||
| 1133 | extern int ZEXPORT zipClose (file, global_comment) | 1751 | int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) |
| 1134 | zipFile file; | 1752 | { |
| 1135 | const char* global_comment; | 1753 | int err = ZIP_OK; |
| 1754 | ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; | ||
| 1755 | |||
| 1756 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); | ||
| 1757 | |||
| 1758 | /*num disks*/ | ||
| 1759 | if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | ||
| 1760 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); | ||
| 1761 | |||
| 1762 | /*relative offset*/ | ||
| 1763 | if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ | ||
| 1764 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); | ||
| 1765 | |||
| 1766 | /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ | ||
| 1767 | if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | ||
| 1768 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); | ||
| 1769 | |||
| 1770 | return err; | ||
| 1771 | } | ||
| 1772 | |||
| 1773 | int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) | ||
| 1136 | { | 1774 | { |
| 1137 | zip_internal* zi; | 1775 | int err = ZIP_OK; |
| 1776 | |||
| 1777 | uLong Zip64DataSize = 44; | ||
| 1778 | |||
| 1779 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); | ||
| 1780 | |||
| 1781 | if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ | ||
| 1782 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? | ||
| 1783 | |||
| 1784 | if (err==ZIP_OK) /* version made by */ | ||
| 1785 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); | ||
| 1786 | |||
| 1787 | if (err==ZIP_OK) /* version needed */ | ||
| 1788 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); | ||
| 1789 | |||
| 1790 | if (err==ZIP_OK) /* number of this disk */ | ||
| 1791 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); | ||
| 1792 | |||
| 1793 | if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | ||
| 1794 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); | ||
| 1795 | |||
| 1796 | if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ | ||
| 1797 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); | ||
| 1798 | |||
| 1799 | if (err==ZIP_OK) /* total number of entries in the central dir */ | ||
| 1800 | err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); | ||
| 1801 | |||
| 1802 | if (err==ZIP_OK) /* size of the central directory */ | ||
| 1803 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); | ||
| 1804 | |||
| 1805 | if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ | ||
| 1806 | { | ||
| 1807 | ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | ||
| 1808 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); | ||
| 1809 | } | ||
| 1810 | return err; | ||
| 1811 | } | ||
| 1812 | int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) | ||
| 1813 | { | ||
| 1814 | int err = ZIP_OK; | ||
| 1815 | |||
| 1816 | /*signature*/ | ||
| 1817 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); | ||
| 1818 | |||
| 1819 | if (err==ZIP_OK) /* number of this disk */ | ||
| 1820 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | ||
| 1821 | |||
| 1822 | if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | ||
| 1823 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | ||
| 1824 | |||
| 1825 | if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ | ||
| 1826 | { | ||
| 1827 | { | ||
| 1828 | if(zi->number_entry >= 0xFFFF) | ||
| 1829 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record | ||
| 1830 | else | ||
| 1831 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | ||
| 1832 | } | ||
| 1833 | } | ||
| 1834 | |||
| 1835 | if (err==ZIP_OK) /* total number of entries in the central dir */ | ||
| 1836 | { | ||
| 1837 | if(zi->number_entry >= 0xFFFF) | ||
| 1838 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record | ||
| 1839 | else | ||
| 1840 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | if (err==ZIP_OK) /* size of the central directory */ | ||
| 1844 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); | ||
| 1845 | |||
| 1846 | if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ | ||
| 1847 | { | ||
| 1848 | ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | ||
| 1849 | if(pos >= 0xffffffff) | ||
| 1850 | { | ||
| 1851 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); | ||
| 1852 | } | ||
| 1853 | else | ||
| 1854 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | return err; | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | int Write_GlobalComment(zip64_internal* zi, const char* global_comment) | ||
| 1861 | { | ||
| 1862 | int err = ZIP_OK; | ||
| 1863 | uInt size_global_comment = 0; | ||
| 1864 | |||
| 1865 | if(global_comment != NULL) | ||
| 1866 | size_global_comment = (uInt)strlen(global_comment); | ||
| 1867 | |||
| 1868 | err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); | ||
| 1869 | |||
| 1870 | if (err == ZIP_OK && size_global_comment > 0) | ||
| 1871 | { | ||
| 1872 | if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment) | ||
| 1873 | err = ZIP_ERRNO; | ||
| 1874 | } | ||
| 1875 | return err; | ||
| 1876 | } | ||
| 1877 | |||
| 1878 | extern int ZEXPORT zipClose (zipFile file, const char* global_comment) | ||
| 1879 | { | ||
| 1880 | zip64_internal* zi; | ||
| 1138 | int err = 0; | 1881 | int err = 0; |
| 1139 | uLong size_centraldir = 0; | 1882 | uLong size_centraldir = 0; |
| 1140 | uLong centraldir_pos_inzip; | 1883 | ZPOS64_T centraldir_pos_inzip; |
| 1141 | uInt size_global_comment; | 1884 | ZPOS64_T pos; |
| 1885 | |||
| 1142 | if (file == NULL) | 1886 | if (file == NULL) |
| 1143 | return ZIP_PARAMERROR; | 1887 | return ZIP_PARAMERROR; |
| 1144 | zi = (zip_internal*)file; | 1888 | |
| 1889 | zi = (zip64_internal*)file; | ||
| 1145 | 1890 | ||
| 1146 | if (zi->in_opened_file_inzip == 1) | 1891 | if (zi->in_opened_file_inzip == 1) |
| 1147 | { | 1892 | { |
| @@ -1152,61 +1897,42 @@ extern int ZEXPORT zipClose (file, global_comment) | |||
| 1152 | if (global_comment==NULL) | 1897 | if (global_comment==NULL) |
| 1153 | global_comment = zi->globalcomment; | 1898 | global_comment = zi->globalcomment; |
| 1154 | #endif | 1899 | #endif |
| 1155 | if (global_comment==NULL) | 1900 | |
| 1156 | size_global_comment = 0; | 1901 | centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); |
| 1157 | else | ||
| 1158 | size_global_comment = (uInt)strlen(global_comment); | ||
| 1159 | 1902 | ||
| 1160 | centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); | ||
| 1161 | if (err==ZIP_OK) | 1903 | if (err==ZIP_OK) |
| 1162 | { | 1904 | { |
| 1163 | linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; | 1905 | linkedlist_datablock_internal* ldi = zi->central_dir.first_block; |
| 1164 | while (ldi!=NULL) | 1906 | while (ldi!=NULL) |
| 1165 | { | 1907 | { |
| 1166 | if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) | 1908 | if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) |
| 1167 | if (ZWRITE(zi->z_filefunc,zi->filestream, | 1909 | { |
| 1168 | ldi->data,ldi->filled_in_this_block) | 1910 | if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) |
| 1169 | !=ldi->filled_in_this_block ) | ||
| 1170 | err = ZIP_ERRNO; | 1911 | err = ZIP_ERRNO; |
| 1912 | } | ||
| 1171 | 1913 | ||
| 1172 | size_centraldir += ldi->filled_in_this_block; | 1914 | size_centraldir += ldi->filled_in_this_block; |
| 1173 | ldi = ldi->next_datablock; | 1915 | ldi = ldi->next_datablock; |
| 1174 | } | 1916 | } |
| 1175 | } | 1917 | } |
| 1176 | free_datablock(zi->central_dir.first_block); | 1918 | free_linkedlist(&(zi->central_dir)); |
| 1177 | |||
| 1178 | if (err==ZIP_OK) /* Magic End */ | ||
| 1179 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); | ||
| 1180 | |||
| 1181 | if (err==ZIP_OK) /* number of this disk */ | ||
| 1182 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | ||
| 1183 | |||
| 1184 | if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | ||
| 1185 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); | ||
| 1186 | |||
| 1187 | if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ | ||
| 1188 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | ||
| 1189 | |||
| 1190 | if (err==ZIP_OK) /* total number of entries in the central dir */ | ||
| 1191 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); | ||
| 1192 | |||
| 1193 | if (err==ZIP_OK) /* size of the central directory */ | ||
| 1194 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); | ||
| 1195 | 1919 | ||
| 1196 | if (err==ZIP_OK) /* offset of start of central directory with respect to the | 1920 | pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; |
| 1197 | starting disk number */ | 1921 | if(pos >= 0xffffffff) |
| 1198 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, | 1922 | { |
| 1199 | (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); | 1923 | ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); |
| 1924 | Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); | ||
| 1925 | |||
| 1926 | Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); | ||
| 1927 | } | ||
| 1200 | 1928 | ||
| 1201 | if (err==ZIP_OK) /* zipfile comment length */ | 1929 | if (err==ZIP_OK) |
| 1202 | err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); | 1930 | err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); |
| 1203 | 1931 | ||
| 1204 | if ((err==ZIP_OK) && (size_global_comment>0)) | 1932 | if(err == ZIP_OK) |
| 1205 | if (ZWRITE(zi->z_filefunc,zi->filestream, | 1933 | err = Write_GlobalComment(zi, global_comment); |
| 1206 | global_comment,size_global_comment) != size_global_comment) | ||
| 1207 | err = ZIP_ERRNO; | ||
| 1208 | 1934 | ||
| 1209 | if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) | 1935 | if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) |
| 1210 | if (err == ZIP_OK) | 1936 | if (err == ZIP_OK) |
| 1211 | err = ZIP_ERRNO; | 1937 | err = ZIP_ERRNO; |
| 1212 | 1938 | ||
| @@ -1217,3 +1943,61 @@ extern int ZEXPORT zipClose (file, global_comment) | |||
| 1217 | 1943 | ||
| 1218 | return err; | 1944 | return err; |
| 1219 | } | 1945 | } |
| 1946 | |||
| 1947 | extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) | ||
| 1948 | { | ||
| 1949 | char* p = pData; | ||
| 1950 | int size = 0; | ||
| 1951 | char* pNewHeader; | ||
| 1952 | char* pTmp; | ||
| 1953 | short header; | ||
| 1954 | short dataSize; | ||
| 1955 | |||
| 1956 | int retVal = ZIP_OK; | ||
| 1957 | |||
| 1958 | if(pData == NULL || *dataLen < 4) | ||
| 1959 | return ZIP_PARAMERROR; | ||
| 1960 | |||
| 1961 | pNewHeader = (char*)ALLOC(*dataLen); | ||
| 1962 | pTmp = pNewHeader; | ||
| 1963 | |||
| 1964 | while(p < (pData + *dataLen)) | ||
| 1965 | { | ||
| 1966 | header = *(short*)p; | ||
| 1967 | dataSize = *(((short*)p)+1); | ||
| 1968 | |||
| 1969 | if( header == sHeader ) // Header found. | ||
| 1970 | { | ||
| 1971 | p += dataSize + 4; // skip it. do not copy to temp buffer | ||
| 1972 | } | ||
| 1973 | else | ||
| 1974 | { | ||
| 1975 | // Extra Info block should not be removed, So copy it to the temp buffer. | ||
| 1976 | memcpy(pTmp, p, dataSize + 4); | ||
| 1977 | p += dataSize + 4; | ||
| 1978 | size += dataSize + 4; | ||
| 1979 | } | ||
| 1980 | |||
| 1981 | } | ||
| 1982 | |||
| 1983 | if(size < *dataLen) | ||
| 1984 | { | ||
| 1985 | // clean old extra info block. | ||
| 1986 | memset(pData,0, *dataLen); | ||
| 1987 | |||
| 1988 | // copy the new extra info block over the old | ||
| 1989 | if(size > 0) | ||
| 1990 | memcpy(pData, pNewHeader, size); | ||
| 1991 | |||
| 1992 | // set the new extra info size | ||
| 1993 | *dataLen = size; | ||
| 1994 | |||
| 1995 | retVal = ZIP_OK; | ||
| 1996 | } | ||
| 1997 | else | ||
| 1998 | retVal = ZIP_ERRNO; | ||
| 1999 | |||
| 2000 | TRYFREE(pNewHeader); | ||
| 2001 | |||
| 2002 | return retVal; | ||
| 2003 | } | ||
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h index acacce8..a33a52d 100644 --- a/contrib/minizip/zip.h +++ b/contrib/minizip/zip.h | |||
| @@ -1,19 +1,15 @@ | |||
| 1 | /* zip.h -- IO for compress .zip files using zlib | 1 | /* zip.h -- IO on .zip files using zlib |
| 2 | Version 1.01e, February 12th, 2005 | 2 | Version 1.1, January 7th, 2010 |
| 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | ||
| 3 | 4 | ||
| 4 | Copyright (C) 1998-2005 Gilles Vollant | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) |
| 5 | 6 | ||
| 6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g | 7 | Modifications for Zip64 support |
| 7 | WinZip, InfoZip tools and compatible. | 8 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) |
| 8 | Multi volume ZipFile (span) are not supported. | ||
| 9 | Encryption compatible with pkzip 2.04g only supported | ||
| 10 | Old compressions used by old PKZip 1.x are not supported | ||
| 11 | 9 | ||
| 12 | For uncompress .zip file, look at unzip.h | 10 | For more info read MiniZip_info.txt |
| 13 | 11 | ||
| 14 | 12 | --------------------------------------------------------------------------- | |
| 15 | I WAIT FEEDBACK at mail info@winimage.com | ||
| 16 | Visit also http://www.winimage.com/zLibDll/unzip.html for evolution | ||
| 17 | 13 | ||
| 18 | Condition of use and distribution are the same than zlib : | 14 | Condition of use and distribution are the same than zlib : |
| 19 | 15 | ||
| @@ -33,23 +29,23 @@ | |||
| 33 | misrepresented as being the original software. | 29 | misrepresented as being the original software. |
| 34 | 3. This notice may not be removed or altered from any source distribution. | 30 | 3. This notice may not be removed or altered from any source distribution. |
| 35 | 31 | ||
| 32 | --------------------------------------------------------------------------- | ||
| 36 | 33 | ||
| 37 | */ | 34 | Changes |
| 35 | |||
| 36 | See header of zip.h | ||
| 38 | 37 | ||
| 39 | /* for more info about .ZIP format, see | ||
| 40 | http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip | ||
| 41 | http://www.info-zip.org/pub/infozip/doc/ | ||
| 42 | PkWare has also a specification at : | ||
| 43 | ftp://ftp.pkware.com/probdesc.zip | ||
| 44 | */ | 38 | */ |
| 45 | 39 | ||
| 46 | #ifndef _zip_H | 40 | #ifndef _zip12_H |
| 47 | #define _zip_H | 41 | #define _zip12_H |
| 48 | 42 | ||
| 49 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |
| 50 | extern "C" { | 44 | extern "C" { |
| 51 | #endif | 45 | #endif |
| 52 | 46 | ||
| 47 | //#define HAVE_BZIP2 | ||
| 48 | |||
| 53 | #ifndef _ZLIB_H | 49 | #ifndef _ZLIB_H |
| 54 | #include "zlib.h" | 50 | #include "zlib.h" |
| 55 | #endif | 51 | #endif |
| @@ -58,6 +54,12 @@ extern "C" { | |||
| 58 | #include "ioapi.h" | 54 | #include "ioapi.h" |
| 59 | #endif | 55 | #endif |
| 60 | 56 | ||
| 57 | #ifdef HAVE_BZIP2 | ||
| 58 | #include "bzlib.h" | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #define Z_BZIP2ED 12 | ||
| 62 | |||
| 61 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) | 63 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) |
| 62 | /* like the STRICT of WIN32, we define a pointer that cannot be converted | 64 | /* like the STRICT of WIN32, we define a pointer that cannot be converted |
| 63 | from (void*) without cast */ | 65 | from (void*) without cast */ |
| @@ -112,6 +114,7 @@ typedef const char* zipcharpc; | |||
| 112 | #define APPEND_STATUS_ADDINZIP (2) | 114 | #define APPEND_STATUS_ADDINZIP (2) |
| 113 | 115 | ||
| 114 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); | 116 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); |
| 117 | extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); | ||
| 115 | /* | 118 | /* |
| 116 | Create a zipfile. | 119 | Create a zipfile. |
| 117 | pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on | 120 | pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on |
| @@ -136,6 +139,11 @@ extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, | |||
| 136 | zipcharpc* globalcomment, | 139 | zipcharpc* globalcomment, |
| 137 | zlib_filefunc_def* pzlib_filefunc_def)); | 140 | zlib_filefunc_def* pzlib_filefunc_def)); |
| 138 | 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 | |||
| 139 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, | 147 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, |
| 140 | const char* filename, | 148 | const char* filename, |
| 141 | const zip_fileinfo* zipfi, | 149 | const zip_fileinfo* zipfi, |
| @@ -146,6 +154,19 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, | |||
| 146 | const char* comment, | 154 | const char* comment, |
| 147 | int method, | 155 | int method, |
| 148 | int level)); | 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 | |||
| 149 | /* | 170 | /* |
| 150 | Open a file in the ZIP for writing. | 171 | Open a file in the ZIP for writing. |
| 151 | filename : the filename in zip (if NULL, '-' without quote will be used | 172 | filename : the filename in zip (if NULL, '-' without quote will be used |
| @@ -157,6 +178,9 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, | |||
| 157 | if comment != NULL, comment contain the comment string | 178 | if comment != NULL, comment contain the comment string |
| 158 | method contain the compression method (0 for store, Z_DEFLATED for deflate) | 179 | method contain the compression method (0 for store, Z_DEFLATED for deflate) |
| 159 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) | 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 | |||
| 160 | */ | 184 | */ |
| 161 | 185 | ||
| 162 | 186 | ||
| @@ -172,6 +196,19 @@ extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, | |||
| 172 | int level, | 196 | int level, |
| 173 | int raw)); | 197 | int raw)); |
| 174 | 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)); | ||
| 175 | /* | 212 | /* |
| 176 | Same than zipOpenNewFileInZip, except if raw=1, we write raw file | 213 | Same than zipOpenNewFileInZip, except if raw=1, we write raw file |
| 177 | */ | 214 | */ |
| @@ -191,13 +228,79 @@ extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, | |||
| 191 | int memLevel, | 228 | int memLevel, |
| 192 | int strategy, | 229 | int strategy, |
| 193 | const char* password, | 230 | const char* password, |
| 194 | uLong crcForCtypting)); | 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 | )); | ||
| 195 | 251 | ||
| 196 | /* | 252 | /* |
| 197 | Same than zipOpenNewFileInZip2, except | 253 | Same than zipOpenNewFileInZip2, except |
| 198 | windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 | 254 | windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 |
| 199 | password : crypting password (NULL for no crypting) | 255 | password : crypting password (NULL for no crypting) |
| 200 | crcForCtypting : crc of file to compress (needed for 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) | ||
| 201 | */ | 304 | */ |
| 202 | 305 | ||
| 203 | 306 | ||
| @@ -216,8 +319,13 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); | |||
| 216 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, | 319 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, |
| 217 | uLong uncompressed_size, | 320 | uLong uncompressed_size, |
| 218 | uLong crc32)); | 321 | uLong crc32)); |
| 322 | |||
| 323 | extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, | ||
| 324 | ZPOS64_T uncompressed_size, | ||
| 325 | uLong crc32)); | ||
| 326 | |||
| 219 | /* | 327 | /* |
| 220 | Close the current file in the zipfile, for fiel opened with | 328 | Close the current file in the zipfile, for file opened with |
| 221 | parameter raw=1 in zipOpenNewFileInZip2 | 329 | parameter raw=1 in zipOpenNewFileInZip2 |
| 222 | uncompressed_size and crc32 are value for the uncompressed size | 330 | uncompressed_size and crc32 are value for the uncompressed size |
| 223 | */ | 331 | */ |
| @@ -228,8 +336,27 @@ extern int ZEXPORT zipClose OF((zipFile file, | |||
| 228 | Close the zipfile | 336 | Close the zipfile |
| 229 | */ | 337 | */ |
| 230 | 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 | |||
| 231 | #ifdef __cplusplus | 358 | #ifdef __cplusplus |
| 232 | } | 359 | } |
| 233 | #endif | 360 | #endif |
| 234 | 361 | ||
| 235 | #endif /* _zip_H */ | 362 | #endif /* _zip64_H */ |
diff --git a/contrib/pascal/zlibd32.mak b/contrib/pascal/zlibd32.mak index 88fafa0..203a4c9 100644 --- a/contrib/pascal/zlibd32.mak +++ b/contrib/pascal/zlibd32.mak | |||
| @@ -18,10 +18,10 @@ LDFLAGS = | |||
| 18 | # variables | 18 | # variables |
| 19 | ZLIB_LIB = zlib.lib | 19 | ZLIB_LIB = zlib.lib |
| 20 | 20 | ||
| 21 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 21 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 22 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.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+gzio.obj+infback.obj | 23 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj |
| 24 | OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj | 24 | OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | # targets | 27 | # targets |
| @@ -38,8 +38,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 38 | 38 | ||
| 39 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 39 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 40 | 40 | ||
| 41 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 42 | |||
| 41 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 43 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 42 | 44 | ||
| 45 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 46 | |||
| 47 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 48 | |||
| 49 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 50 | |||
| 43 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 51 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 44 | inffast.h inffixed.h | 52 | inffast.h inffixed.h |
| 45 | 53 | ||
diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc index 98ca20b..7bb4bb7 100644 --- a/contrib/vstudio/vc7/zlib.rc +++ b/contrib/vstudio/vc7/zlib.rc | |||
| @@ -2,8 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | #define IDR_VERSION1 1 | 3 | #define IDR_VERSION1 1 |
| 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE | 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE |
| 5 | FILEVERSION 1,2,3,4 | 5 | FILEVERSION 1,2,3,5 |
| 6 | PRODUCTVERSION 1,2,3,4 | 6 | PRODUCTVERSION 1,2,3,5 |
| 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK |
| 8 | FILEFLAGS 0 | 8 | FILEFLAGS 0 |
| 9 | FILEOS VOS_DOS_WINDOWS32 | 9 | FILEOS VOS_DOS_WINDOWS32 |
| @@ -17,7 +17,7 @@ BEGIN | |||
| 17 | 17 | ||
| 18 | BEGIN | 18 | BEGIN |
| 19 | VALUE "FileDescription", "zlib data compression library\0" | 19 | VALUE "FileDescription", "zlib data compression library\0" |
| 20 | VALUE "FileVersion", "1.2.3.4\0" | 20 | VALUE "FileVersion", "1.2.3.5\0" |
| 21 | VALUE "InternalName", "zlib\0" | 21 | VALUE "InternalName", "zlib\0" |
| 22 | VALUE "OriginalFilename", "zlib.dll\0" | 22 | VALUE "OriginalFilename", "zlib.dll\0" |
| 23 | VALUE "ProductName", "ZLib.DLL\0" | 23 | VALUE "ProductName", "ZLib.DLL\0" |
diff --git a/contrib/vstudio/vc7/zlibstat.vcproj b/contrib/vstudio/vc7/zlibstat.vcproj index 766d7a4..3c37959 100644 --- a/contrib/vstudio/vc7/zlibstat.vcproj +++ b/contrib/vstudio/vc7/zlibstat.vcproj | |||
| @@ -201,9 +201,21 @@ | |||
| 201 | RelativePath="..\..\masmx86\gvmat32c.c"> | 201 | RelativePath="..\..\masmx86\gvmat32c.c"> |
| 202 | </File> | 202 | </File> |
| 203 | <File | 203 | <File |
| 204 | RelativePath="..\..\..\gzclose.c"> | ||
| 205 | </File> | ||
| 206 | <File | ||
| 204 | RelativePath="..\..\..\gzio.c"> | 207 | RelativePath="..\..\..\gzio.c"> |
| 205 | </File> | 208 | </File> |
| 206 | <File | 209 | <File |
| 210 | RelativePath="..\..\..\gzlib.c"> | ||
| 211 | </File> | ||
| 212 | <File | ||
| 213 | RelativePath="..\..\..\gzread.c"> | ||
| 214 | </File> | ||
| 215 | <File | ||
| 216 | RelativePath="..\..\..\gzwrite.c"> | ||
| 217 | </File> | ||
| 218 | <File | ||
| 207 | RelativePath="..\..\..\infback.c"> | 219 | RelativePath="..\..\..\infback.c"> |
| 208 | </File> | 220 | </File> |
| 209 | <File | 221 | <File |
diff --git a/contrib/vstudio/vc7/zlibvc.vcproj b/contrib/vstudio/vc7/zlibvc.vcproj index 8533b49..2c66643 100644 --- a/contrib/vstudio/vc7/zlibvc.vcproj +++ b/contrib/vstudio/vc7/zlibvc.vcproj | |||
| @@ -348,9 +348,21 @@ | |||
| 348 | </FileConfiguration> | 348 | </FileConfiguration> |
| 349 | </File> | 349 | </File> |
| 350 | <File | 350 | <File |
| 351 | RelativePath="..\..\..\gzclose.c"> | ||
| 352 | </File> | ||
| 353 | <File | ||
| 351 | RelativePath="..\..\..\gzio.c"> | 354 | RelativePath="..\..\..\gzio.c"> |
| 352 | </File> | 355 | </File> |
| 353 | <File | 356 | <File |
| 357 | RelativePath="..\..\..\gzlib.c"> | ||
| 358 | </File> | ||
| 359 | <File | ||
| 360 | RelativePath="..\..\..\gzread.c"> | ||
| 361 | </File> | ||
| 362 | <File | ||
| 363 | RelativePath="..\..\..\gzwrite.c"> | ||
| 364 | </File> | ||
| 365 | <File | ||
| 354 | RelativePath="..\..\..\infback.c"> | 366 | RelativePath="..\..\..\infback.c"> |
| 355 | </File> | 367 | </File> |
| 356 | <File | 368 | <File |
diff --git a/contrib/vstudio/vc8/zlibstat.vcproj b/contrib/vstudio/vc8/zlibstat.vcproj index fb97037..51a4073 100644 --- a/contrib/vstudio/vc8/zlibstat.vcproj +++ b/contrib/vstudio/vc8/zlibstat.vcproj | |||
| @@ -760,8 +760,19 @@ | |||
| 760 | </FileConfiguration> | 760 | </FileConfiguration> |
| 761 | </File> | 761 | </File> |
| 762 | <File | 762 | <File |
| 763 | RelativePath="..\..\..\gzio.c" | 763 | RelativePath="..\..\..\gzclose.c"> |
| 764 | > | 764 | </File> |
| 765 | <File | ||
| 766 | RelativePath="..\..\..\gzio.c"> | ||
| 767 | </File> | ||
| 768 | <File | ||
| 769 | RelativePath="..\..\..\gzlib.c"> | ||
| 770 | </File> | ||
| 771 | <File | ||
| 772 | RelativePath="..\..\..\gzread.c"> | ||
| 773 | </File> | ||
| 774 | <File | ||
| 775 | RelativePath="..\..\..\gzwrite.c"> | ||
| 765 | </File> | 776 | </File> |
| 766 | <File | 777 | <File |
| 767 | RelativePath="..\..\..\infback.c" | 778 | RelativePath="..\..\..\infback.c" |
diff --git a/contrib/vstudio/vc8/zlibvc.vcproj b/contrib/vstudio/vc8/zlibvc.vcproj index e717011..f06273b 100644 --- a/contrib/vstudio/vc8/zlibvc.vcproj +++ b/contrib/vstudio/vc8/zlibvc.vcproj | |||
| @@ -1005,8 +1005,19 @@ | |||
| 1005 | </FileConfiguration> | 1005 | </FileConfiguration> |
| 1006 | </File> | 1006 | </File> |
| 1007 | <File | 1007 | <File |
| 1008 | RelativePath="..\..\..\gzio.c" | 1008 | RelativePath="..\..\..\gzclose.c"> |
| 1009 | > | 1009 | </File> |
| 1010 | <File | ||
| 1011 | RelativePath="..\..\..\gzio.c"> | ||
| 1012 | </File> | ||
| 1013 | <File | ||
| 1014 | RelativePath="..\..\..\gzlib.c"> | ||
| 1015 | </File> | ||
| 1016 | <File | ||
| 1017 | RelativePath="..\..\..\gzread.c"> | ||
| 1018 | </File> | ||
| 1019 | <File | ||
| 1020 | RelativePath="..\..\..\gzwrite.c"> | ||
| 1010 | </File> | 1021 | </File> |
| 1011 | <File | 1022 | <File |
| 1012 | RelativePath="..\..\..\infback.c" | 1023 | RelativePath="..\..\..\infback.c" |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* deflate.c -- compress data using the deflation algorithm | 1 | /* deflate.c -- compress data using the deflation algorithm |
| 2 | * Copyright (C) 1995-2009 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -52,7 +52,7 @@ | |||
| 52 | #include "deflate.h" | 52 | #include "deflate.h" |
| 53 | 53 | ||
| 54 | const char deflate_copyright[] = | 54 | const char deflate_copyright[] = |
| 55 | " deflate 1.2.3.4 Copyright 1995-2009 Jean-loup Gailly "; | 55 | " deflate 1.2.3.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; |
| 56 | /* | 56 | /* |
| 57 | If you use the zlib library in a product, an acknowledgment is welcome | 57 | If you use the zlib library in a product, an acknowledgment is welcome |
| 58 | in the documentation of your product. If for some reason you cannot | 58 | in the documentation of your product. If for some reason you cannot |
| @@ -79,19 +79,18 @@ local block_state deflate_fast OF((deflate_state *s, int flush)); | |||
| 79 | #ifndef FASTEST | 79 | #ifndef FASTEST |
| 80 | local block_state deflate_slow OF((deflate_state *s, int flush)); | 80 | local block_state deflate_slow OF((deflate_state *s, int flush)); |
| 81 | #endif | 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)); | ||
| 82 | local void lm_init OF((deflate_state *s)); | 84 | local void lm_init OF((deflate_state *s)); |
| 83 | local void putShortMSB OF((deflate_state *s, uInt b)); | 85 | local void putShortMSB OF((deflate_state *s, uInt b)); |
| 84 | local void flush_pending OF((z_streamp strm)); | 86 | local void flush_pending OF((z_streamp strm)); |
| 85 | local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); | 87 | local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
| 86 | #ifndef FASTEST | ||
| 87 | #ifdef ASMV | 88 | #ifdef ASMV |
| 88 | void match_init OF((void)); /* asm code initialization */ | 89 | void match_init OF((void)); /* asm code initialization */ |
| 89 | uInt longest_match OF((deflate_state *s, IPos cur_match)); | 90 | uInt longest_match OF((deflate_state *s, IPos cur_match)); |
| 90 | #else | 91 | #else |
| 91 | local uInt longest_match OF((deflate_state *s, IPos cur_match)); | 92 | local uInt longest_match OF((deflate_state *s, IPos cur_match)); |
| 92 | #endif | 93 | #endif |
| 93 | #endif | ||
| 94 | local uInt longest_match_fast OF((deflate_state *s, IPos cur_match)); | ||
| 95 | 94 | ||
| 96 | #ifdef DEBUG | 95 | #ifdef DEBUG |
| 97 | local void check_match OF((deflate_state *s, IPos start, IPos match, | 96 | local void check_match OF((deflate_state *s, IPos start, IPos match, |
| @@ -432,9 +431,10 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
| 432 | } | 431 | } |
| 433 | func = configuration_table[s->level].func; | 432 | func = configuration_table[s->level].func; |
| 434 | 433 | ||
| 435 | if (func != configuration_table[level].func && strm->total_in != 0) { | 434 | if ((strategy != s->strategy || func != configuration_table[level].func) && |
| 435 | strm->total_in != 0) { | ||
| 436 | /* Flush the last buffer: */ | 436 | /* Flush the last buffer: */ |
| 437 | err = deflate(strm, Z_PARTIAL_FLUSH); | 437 | err = deflate(strm, Z_BLOCK); |
| 438 | } | 438 | } |
| 439 | if (s->level != level) { | 439 | if (s->level != level) { |
| 440 | s->level = level; | 440 | s->level = level; |
| @@ -536,7 +536,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen) | |||
| 536 | return complen + wraplen; | 536 | return complen + wraplen; |
| 537 | 537 | ||
| 538 | /* default settings: return tight bound for that case */ | 538 | /* default settings: return tight bound for that case */ |
| 539 | return compressBound(sourceLen) - 6 + wraplen; | 539 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + |
| 540 | (sourceLen >> 25) + 13 - 6 + wraplen; | ||
| 540 | } | 541 | } |
| 541 | 542 | ||
| 542 | /* ========================================================================= | 543 | /* ========================================================================= |
| @@ -816,7 +817,9 @@ int ZEXPORT deflate (strm, flush) | |||
| 816 | (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { | 817 | (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { |
| 817 | block_state bstate; | 818 | block_state bstate; |
| 818 | 819 | ||
| 819 | bstate = (*(configuration_table[s->level].func))(s, flush); | 820 | bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : |
| 821 | (s->strategy == Z_RLE ? deflate_rle(s, flush) : | ||
| 822 | (*(configuration_table[s->level].func))(s, flush)); | ||
| 820 | 823 | ||
| 821 | if (bstate == finish_started || bstate == finish_done) { | 824 | if (bstate == finish_started || bstate == finish_done) { |
| 822 | s->status = FINISH_STATE; | 825 | s->status = FINISH_STATE; |
| @@ -1200,12 +1203,13 @@ local uInt longest_match(s, cur_match) | |||
| 1200 | return s->lookahead; | 1203 | return s->lookahead; |
| 1201 | } | 1204 | } |
| 1202 | #endif /* ASMV */ | 1205 | #endif /* ASMV */ |
| 1203 | #endif /* FASTEST */ | 1206 | |
| 1207 | #else /* FASTEST */ | ||
| 1204 | 1208 | ||
| 1205 | /* --------------------------------------------------------------------------- | 1209 | /* --------------------------------------------------------------------------- |
| 1206 | * Optimized version for level == 1 or strategy == Z_RLE only | 1210 | * Optimized version for FASTEST only |
| 1207 | */ | 1211 | */ |
| 1208 | local uInt longest_match_fast(s, cur_match) | 1212 | local uInt longest_match(s, cur_match) |
| 1209 | deflate_state *s; | 1213 | deflate_state *s; |
| 1210 | IPos cur_match; /* current match */ | 1214 | IPos cur_match; /* current match */ |
| 1211 | { | 1215 | { |
| @@ -1258,6 +1262,8 @@ local uInt longest_match_fast(s, cur_match) | |||
| 1258 | return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; | 1262 | return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; |
| 1259 | } | 1263 | } |
| 1260 | 1264 | ||
| 1265 | #endif /* FASTEST */ | ||
| 1266 | |||
| 1261 | #ifdef DEBUG | 1267 | #ifdef DEBUG |
| 1262 | /* =========================================================================== | 1268 | /* =========================================================================== |
| 1263 | * Check that the match at match_start is indeed a match. | 1269 | * Check that the match at match_start is indeed a match. |
| @@ -1336,7 +1342,6 @@ local void fill_window(s) | |||
| 1336 | later. (Using level 0 permanently is not an optimal usage of | 1342 | later. (Using level 0 permanently is not an optimal usage of |
| 1337 | zlib, so we don't care about this pathological case.) | 1343 | zlib, so we don't care about this pathological case.) |
| 1338 | */ | 1344 | */ |
| 1339 | /* %%% avoid this when Z_RLE */ | ||
| 1340 | n = s->hash_size; | 1345 | n = s->hash_size; |
| 1341 | p = &s->head[n]; | 1346 | p = &s->head[n]; |
| 1342 | do { | 1347 | do { |
| @@ -1516,7 +1521,7 @@ local block_state deflate_fast(s, flush) | |||
| 1516 | deflate_state *s; | 1521 | deflate_state *s; |
| 1517 | int flush; | 1522 | int flush; |
| 1518 | { | 1523 | { |
| 1519 | IPos hash_head = NIL; /* head of the hash chain */ | 1524 | IPos hash_head; /* head of the hash chain */ |
| 1520 | int bflush; /* set if current block must be flushed */ | 1525 | int bflush; /* set if current block must be flushed */ |
| 1521 | 1526 | ||
| 1522 | for (;;) { | 1527 | for (;;) { |
| @@ -1536,6 +1541,7 @@ local block_state deflate_fast(s, flush) | |||
| 1536 | /* Insert the string window[strstart .. strstart+2] in the | 1541 | /* Insert the string window[strstart .. strstart+2] in the |
| 1537 | * dictionary, and set hash_head to the head of the hash chain: | 1542 | * dictionary, and set hash_head to the head of the hash chain: |
| 1538 | */ | 1543 | */ |
| 1544 | hash_head = NIL; | ||
| 1539 | if (s->lookahead >= MIN_MATCH) { | 1545 | if (s->lookahead >= MIN_MATCH) { |
| 1540 | INSERT_STRING(s, s->strstart, hash_head); | 1546 | INSERT_STRING(s, s->strstart, hash_head); |
| 1541 | } | 1547 | } |
| @@ -1548,19 +1554,8 @@ local block_state deflate_fast(s, flush) | |||
| 1548 | * of window index 0 (in particular we have to avoid a match | 1554 | * of window index 0 (in particular we have to avoid a match |
| 1549 | * of the string with itself at the start of the input file). | 1555 | * of the string with itself at the start of the input file). |
| 1550 | */ | 1556 | */ |
| 1551 | #ifdef FASTEST | 1557 | s->match_length = longest_match (s, hash_head); |
| 1552 | if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || | 1558 | /* longest_match() sets match_start */ |
| 1553 | (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { | ||
| 1554 | s->match_length = longest_match_fast (s, hash_head); | ||
| 1555 | } | ||
| 1556 | #else | ||
| 1557 | if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { | ||
| 1558 | s->match_length = longest_match (s, hash_head); | ||
| 1559 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { | ||
| 1560 | s->match_length = longest_match_fast (s, hash_head); | ||
| 1561 | } | ||
| 1562 | #endif | ||
| 1563 | /* longest_match() or longest_match_fast() sets match_start */ | ||
| 1564 | } | 1559 | } |
| 1565 | if (s->match_length >= MIN_MATCH) { | 1560 | if (s->match_length >= MIN_MATCH) { |
| 1566 | check_match(s, s->strstart, s->match_start, s->match_length); | 1561 | check_match(s, s->strstart, s->match_start, s->match_length); |
| @@ -1622,7 +1617,7 @@ local block_state deflate_slow(s, flush) | |||
| 1622 | deflate_state *s; | 1617 | deflate_state *s; |
| 1623 | int flush; | 1618 | int flush; |
| 1624 | { | 1619 | { |
| 1625 | IPos hash_head = NIL; /* head of hash chain */ | 1620 | IPos hash_head; /* head of hash chain */ |
| 1626 | int bflush; /* set if current block must be flushed */ | 1621 | int bflush; /* set if current block must be flushed */ |
| 1627 | 1622 | ||
| 1628 | /* Process the input block. */ | 1623 | /* Process the input block. */ |
| @@ -1643,6 +1638,7 @@ local block_state deflate_slow(s, flush) | |||
| 1643 | /* Insert the string window[strstart .. strstart+2] in the | 1638 | /* Insert the string window[strstart .. strstart+2] in the |
| 1644 | * dictionary, and set hash_head to the head of the hash chain: | 1639 | * dictionary, and set hash_head to the head of the hash chain: |
| 1645 | */ | 1640 | */ |
| 1641 | hash_head = NIL; | ||
| 1646 | if (s->lookahead >= MIN_MATCH) { | 1642 | if (s->lookahead >= MIN_MATCH) { |
| 1647 | INSERT_STRING(s, s->strstart, hash_head); | 1643 | INSERT_STRING(s, s->strstart, hash_head); |
| 1648 | } | 1644 | } |
| @@ -1658,12 +1654,8 @@ local block_state deflate_slow(s, flush) | |||
| 1658 | * of window index 0 (in particular we have to avoid a match | 1654 | * of window index 0 (in particular we have to avoid a match |
| 1659 | * of the string with itself at the start of the input file). | 1655 | * of the string with itself at the start of the input file). |
| 1660 | */ | 1656 | */ |
| 1661 | if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { | 1657 | s->match_length = longest_match (s, hash_head); |
| 1662 | s->match_length = longest_match (s, hash_head); | 1658 | /* longest_match() sets match_start */ |
| 1663 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { | ||
| 1664 | s->match_length = longest_match_fast (s, hash_head); | ||
| 1665 | } | ||
| 1666 | /* longest_match() or longest_match_fast() sets match_start */ | ||
| 1667 | 1659 | ||
| 1668 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED | 1660 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED |
| 1669 | #if TOO_FAR <= 32767 | 1661 | #if TOO_FAR <= 32767 |
| @@ -1741,7 +1733,6 @@ local block_state deflate_slow(s, flush) | |||
| 1741 | } | 1733 | } |
| 1742 | #endif /* FASTEST */ | 1734 | #endif /* FASTEST */ |
| 1743 | 1735 | ||
| 1744 | #if 0 | ||
| 1745 | /* =========================================================================== | 1736 | /* =========================================================================== |
| 1746 | * For Z_RLE, simply look for runs of bytes, generate matches only of distance | 1737 | * For Z_RLE, simply look for runs of bytes, generate matches only of distance |
| 1747 | * one. Do not maintain a hash table. (It will be regenerated if this run of | 1738 | * one. Do not maintain a hash table. (It will be regenerated if this run of |
| @@ -1751,11 +1742,9 @@ local block_state deflate_rle(s, flush) | |||
| 1751 | deflate_state *s; | 1742 | deflate_state *s; |
| 1752 | int flush; | 1743 | int flush; |
| 1753 | { | 1744 | { |
| 1754 | int bflush; /* set if current block must be flushed */ | 1745 | int bflush; /* set if current block must be flushed */ |
| 1755 | uInt run; /* length of run */ | 1746 | uInt prev; /* byte at distance one to match */ |
| 1756 | uInt max; /* maximum length of run */ | 1747 | Bytef *scan, *strend; /* scan goes up to strend for length of run */ |
| 1757 | uInt prev; /* byte at distance one to match */ | ||
| 1758 | Bytef *scan; /* scan for end of run */ | ||
| 1759 | 1748 | ||
| 1760 | for (;;) { | 1749 | for (;;) { |
| 1761 | /* Make sure that we always have enough lookahead, except | 1750 | /* Make sure that we always have enough lookahead, except |
| @@ -1771,23 +1760,33 @@ local block_state deflate_rle(s, flush) | |||
| 1771 | } | 1760 | } |
| 1772 | 1761 | ||
| 1773 | /* See how many times the previous byte repeats */ | 1762 | /* See how many times the previous byte repeats */ |
| 1774 | run = 0; | 1763 | s->match_length = 0; |
| 1775 | if (s->strstart > 0) { /* if there is a previous byte, that is */ | 1764 | if (s->lookahead >= MIN_MATCH && s->strstart > 0) { |
| 1776 | max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; | ||
| 1777 | scan = s->window + s->strstart - 1; | 1765 | scan = s->window + s->strstart - 1; |
| 1778 | prev = *scan++; | 1766 | prev = *scan; |
| 1779 | do { | 1767 | if (prev == *++scan && prev == *++scan && prev == *++scan) { |
| 1780 | if (*scan++ != prev) | 1768 | strend = s->window + s->strstart + MAX_MATCH; |
| 1781 | break; | 1769 | do { |
| 1782 | } while (++run < max); | 1770 | } while (prev == *++scan && prev == *++scan && |
| 1771 | prev == *++scan && prev == *++scan && | ||
| 1772 | prev == *++scan && prev == *++scan && | ||
| 1773 | prev == *++scan && prev == *++scan && | ||
| 1774 | scan < strend); | ||
| 1775 | s->match_length = MAX_MATCH - (int)(strend - scan); | ||
| 1776 | if (s->match_length > s->lookahead) | ||
| 1777 | s->match_length = s->lookahead; | ||
| 1778 | } | ||
| 1783 | } | 1779 | } |
| 1784 | 1780 | ||
| 1785 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ | 1781 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ |
| 1786 | if (run >= MIN_MATCH) { | 1782 | if (s->match_length >= MIN_MATCH) { |
| 1787 | check_match(s, s->strstart, s->strstart - 1, run); | 1783 | check_match(s, s->strstart, s->strstart - 1, s->match_length); |
| 1788 | _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); | 1784 | |
| 1789 | s->lookahead -= run; | 1785 | _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); |
| 1790 | s->strstart += run; | 1786 | |
| 1787 | s->lookahead -= s->match_length; | ||
| 1788 | s->strstart += s->match_length; | ||
| 1789 | s->match_length = 0; | ||
| 1791 | } else { | 1790 | } else { |
| 1792 | /* No match, output a literal byte */ | 1791 | /* No match, output a literal byte */ |
| 1793 | Tracevv((stderr,"%c", s->window[s->strstart])); | 1792 | Tracevv((stderr,"%c", s->window[s->strstart])); |
| @@ -1800,4 +1799,36 @@ local block_state deflate_rle(s, flush) | |||
| 1800 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1799 | FLUSH_BLOCK(s, flush == Z_FINISH); |
| 1801 | return flush == Z_FINISH ? finish_done : block_done; | 1800 | return flush == Z_FINISH ? finish_done : block_done; |
| 1802 | } | 1801 | } |
| 1803 | #endif | 1802 | |
| 1803 | /* =========================================================================== | ||
| 1804 | * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. | ||
| 1805 | * (It will be regenerated if this run of deflate switches away from Huffman.) | ||
| 1806 | */ | ||
| 1807 | local block_state deflate_huff(s, flush) | ||
| 1808 | deflate_state *s; | ||
| 1809 | int flush; | ||
| 1810 | { | ||
| 1811 | int bflush; /* set if current block must be flushed */ | ||
| 1812 | |||
| 1813 | for (;;) { | ||
| 1814 | /* Make sure that we have a literal to write. */ | ||
| 1815 | if (s->lookahead == 0) { | ||
| 1816 | fill_window(s); | ||
| 1817 | if (s->lookahead == 0) { | ||
| 1818 | if (flush == Z_NO_FLUSH) | ||
| 1819 | return need_more; | ||
| 1820 | break; /* flush the current block */ | ||
| 1821 | } | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | /* Output a literal byte */ | ||
| 1825 | s->match_length = 0; | ||
| 1826 | Tracevv((stderr,"%c", s->window[s->strstart])); | ||
| 1827 | _tr_tally_lit (s, s->window[s->strstart], bflush); | ||
| 1828 | s->lookahead--; | ||
| 1829 | s->strstart++; | ||
| 1830 | if (bflush) FLUSH_BLOCK(s, 0); | ||
| 1831 | } | ||
| 1832 | FLUSH_BLOCK(s, flush == Z_FINISH); | ||
| 1833 | return flush == Z_FINISH ? finish_done : block_done; | ||
| 1834 | } | ||
diff --git a/gzclose.c b/gzclose.c new file mode 100644 index 0000000..2cf2843 --- /dev/null +++ b/gzclose.c | |||
| @@ -0,0 +1,29 @@ | |||
| 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 | #ifndef OLD_GZIO | ||
| 7 | |||
| 8 | #include "gzguts.h" | ||
| 9 | |||
| 10 | /* gzclose() is in a separate file so that it is linked in only if it is used. | ||
| 11 | That way the other gzclose functions can be used instead to avoid linking in | ||
| 12 | unneeded compression or decompression routines. */ | ||
| 13 | int ZEXPORT gzclose(file) | ||
| 14 | gzFile file; | ||
| 15 | { | ||
| 16 | #ifndef NO_GZCOMPRESS | ||
| 17 | gz_statep state; | ||
| 18 | |||
| 19 | if (file == NULL) | ||
| 20 | return EOF; | ||
| 21 | state = (gz_statep)file; | ||
| 22 | |||
| 23 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); | ||
| 24 | #else | ||
| 25 | return gzclose_r(file); | ||
| 26 | #endif | ||
| 27 | } | ||
| 28 | |||
| 29 | #endif /* !OLD_GZIO */ | ||
diff --git a/gzguts.h b/gzguts.h new file mode 100644 index 0000000..429c21b --- /dev/null +++ b/gzguts.h | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* gzguts.h -- zlib internal header definitions for gz* operations | ||
| 2 | * Copyright (C) 2004, 2005, 2010 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 | ||
| 9 | # endif | ||
| 10 | # ifdef _FILE_OFFSET_BITS | ||
| 11 | # undef _FILE_OFFSET_BITS | ||
| 12 | # endif | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #define ZLIB_INTERNAL | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | #include <fcntl.h> | ||
| 21 | #include "zlib.h" | ||
| 22 | |||
| 23 | #ifdef NO_DEFLATE /* for compatibility with old definition */ | ||
| 24 | # define NO_GZCOMPRESS | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifdef WIN32 | ||
| 28 | # include <io.h> | ||
| 29 | # define vsnprintf _vsnprintf | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #ifndef local | ||
| 33 | # define local static | ||
| 34 | #endif | ||
| 35 | /* compile with -Dlocal if your debugger can't find static symbols */ | ||
| 36 | |||
| 37 | /* gz* functions always use library allocation functions */ | ||
| 38 | #ifndef STDC | ||
| 39 | extern voidp malloc OF((uInt size)); | ||
| 40 | extern void free OF((voidpf ptr)); | ||
| 41 | #endif | ||
| 42 | |||
| 43 | /* get errno and strerror definition */ | ||
| 44 | #if defined UNDER_CE && defined NO_ERRNO_H | ||
| 45 | # define zstrerror(errnum) strwinerror((DWORD)errnum) | ||
| 46 | #else | ||
| 47 | # ifdef STDC | ||
| 48 | # include <errno.h> | ||
| 49 | # define zstrerror() strerror(errno) | ||
| 50 | # else | ||
| 51 | # define zstrerror() "stdio error (consult errno)" | ||
| 52 | # endif | ||
| 53 | #endif | ||
| 54 | |||
| 55 | /* MVS fdopen() */ | ||
| 56 | #ifdef __MVS__ | ||
| 57 | # pragma map (fdopen , "\174\174FDOPEN") | ||
| 58 | FILE *fdopen(int, const char *); | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #ifdef _LARGEFILE64_SOURCE | ||
| 62 | # define z_off64_t off64_t | ||
| 63 | #else | ||
| 64 | # define z_off64_t z_off_t | ||
| 65 | #endif | ||
| 66 | |||
| 67 | /* default i/o buffer size -- double this for output when reading */ | ||
| 68 | #define GZBUFSIZE 8192 | ||
| 69 | |||
| 70 | /* gzip modes, also provide a little integrity check on the passed structure */ | ||
| 71 | #define GZ_NONE 0 | ||
| 72 | #define GZ_READ 7247 | ||
| 73 | #define GZ_WRITE 31153 | ||
| 74 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ | ||
| 75 | |||
| 76 | /* internal gzip file state data structure */ | ||
| 77 | typedef struct { | ||
| 78 | /* used for both reading and writing */ | ||
| 79 | int mode; /* see gzip modes above */ | ||
| 80 | int fd; /* file descriptor */ | ||
| 81 | char *path; /* path or fd for error messages */ | ||
| 82 | z_off64_t pos; /* current position in uncompressed data */ | ||
| 83 | unsigned size; /* buffer size, zero if not allocated yet */ | ||
| 84 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ | ||
| 85 | unsigned char *in; /* input buffer */ | ||
| 86 | unsigned char *out; /* output buffer (double-sized when reading) */ | ||
| 87 | unsigned char *next; /* next output data to deliver or write */ | ||
| 88 | /* just for reading */ | ||
| 89 | int how; /* 0: get header, 1: copy, 2: decompress */ | ||
| 90 | unsigned have; /* amount of output data unused */ | ||
| 91 | z_off64_t start; /* where the gzip data started, for rewinding */ | ||
| 92 | z_off64_t raw; /* where the raw data started, for seeking */ | ||
| 93 | int eof; /* true if end of input file reached */ | ||
| 94 | /* just for writing */ | ||
| 95 | int level; /* compression level */ | ||
| 96 | int strategy; /* compression strategy */ | ||
| 97 | /* seek request */ | ||
| 98 | int seek; /* true if seek request pending */ | ||
| 99 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ | ||
| 100 | /* error information */ | ||
| 101 | int err; /* error code */ | ||
| 102 | char *msg; /* error message */ | ||
| 103 | /* zlib inflate or deflate stream */ | ||
| 104 | z_stream strm; /* stream structure in-place (not a pointer) */ | ||
| 105 | } gz_state; | ||
| 106 | typedef gz_state FAR *gz_statep; | ||
| 107 | |||
| 108 | /* shared functions */ | ||
| 109 | ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *)); | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* gzio.c -- IO on .gz files | 1 | /* gzio.c -- IO on .gz files |
| 2 | * Copyright (C) 1995-2009 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2010 Jean-loup Gailly. |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | * | 4 | * |
| 5 | * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. | 5 | * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. |
| @@ -7,6 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | /* @(#) $Id$ */ | 8 | /* @(#) $Id$ */ |
| 9 | 9 | ||
| 10 | #ifdef OLD_GZIO | ||
| 11 | |||
| 10 | #ifdef _LARGEFILE64_SOURCE | 12 | #ifdef _LARGEFILE64_SOURCE |
| 11 | # ifndef _LARGEFILE_SOURCE | 13 | # ifndef _LARGEFILE_SOURCE |
| 12 | # define _LARGEFILE_SOURCE | 14 | # define _LARGEFILE_SOURCE |
| @@ -38,6 +40,60 @@ struct internal_state {int dummy;}; /* for buggy compilers */ | |||
| 38 | # define Z_PRINTF_BUFSIZE 4096 | 40 | # define Z_PRINTF_BUFSIZE 4096 |
| 39 | #endif | 41 | #endif |
| 40 | 42 | ||
| 43 | #if defined UNDER_CE && defined NO_ERRNO_H | ||
| 44 | # include <windows.h> | ||
| 45 | |||
| 46 | /* Map the Windows error number in ERROR to a locale-dependent error | ||
| 47 | message string and return a pointer to it. Typically, the values | ||
| 48 | for ERROR come from GetLastError. | ||
| 49 | |||
| 50 | The string pointed to shall not be modified by the application, | ||
| 51 | but may be overwritten by a subsequent call to strwinerror | ||
| 52 | |||
| 53 | The strwinerror function does not change the current setting | ||
| 54 | of GetLastError. */ | ||
| 55 | |||
| 56 | local char *strwinerror (error) | ||
| 57 | DWORD error; | ||
| 58 | { | ||
| 59 | static char buf[1024]; | ||
| 60 | |||
| 61 | wchar_t *msgbuf; | ||
| 62 | DWORD lasterr = GetLastError(); | ||
| 63 | DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | ||
| 64 | | FORMAT_MESSAGE_ALLOCATE_BUFFER, | ||
| 65 | NULL, | ||
| 66 | error, | ||
| 67 | 0, /* Default language */ | ||
| 68 | (LPVOID)&msgbuf, | ||
| 69 | 0, | ||
| 70 | NULL); | ||
| 71 | if (chars != 0) { | ||
| 72 | /* If there is an \r\n appended, zap it. */ | ||
| 73 | if (chars >= 2 | ||
| 74 | && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { | ||
| 75 | chars -= 2; | ||
| 76 | msgbuf[chars] = 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | if (chars > sizeof (buf) - 1) { | ||
| 80 | chars = sizeof (buf) - 1; | ||
| 81 | msgbuf[chars] = 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | wcstombs(buf, msgbuf, chars + 1); | ||
| 85 | LocalFree(msgbuf); | ||
| 86 | } | ||
| 87 | else { | ||
| 88 | sprintf(buf, "unknown win32 error (%ld)", error); | ||
| 89 | } | ||
| 90 | |||
| 91 | SetLastError(lasterr); | ||
| 92 | return buf; | ||
| 93 | } | ||
| 94 | |||
| 95 | #endif /* UNDER_CE && NO_ERRNO_H */ | ||
| 96 | |||
| 41 | #ifdef __MVS__ | 97 | #ifdef __MVS__ |
| 42 | # pragma map (fdopen , "\174\174FDOPEN") | 98 | # pragma map (fdopen , "\174\174FDOPEN") |
| 43 | FILE *fdopen(int, const char *); | 99 | FILE *fdopen(int, const char *); |
| @@ -191,9 +247,10 @@ local gzFile gz_open (path, mode, fd, use64) | |||
| 191 | } | 247 | } |
| 192 | s->stream.avail_out = Z_BUFSIZE; | 248 | s->stream.avail_out = Z_BUFSIZE; |
| 193 | 249 | ||
| 194 | errno = 0; | 250 | zseterrno(0); |
| 195 | s->file = fd < 0 ? (use64 ? F_OPEN64(path, fmode) : F_OPEN(path, fmode)) : | 251 | s->file = fd == -1 ? |
| 196 | (FILE*)fdopen(fd, fmode); | 252 | (use64 ? F_OPEN64(path, fmode) : F_OPEN(path, fmode)) : |
| 253 | (FILE*)fdopen(fd, fmode); | ||
| 197 | 254 | ||
| 198 | if (s->file == NULL) { | 255 | if (s->file == NULL) { |
| 199 | return destroy(s), (gzFile)Z_NULL; | 256 | return destroy(s), (gzFile)Z_NULL; |
| @@ -250,7 +307,7 @@ gzFile ZEXPORT gzdopen (fd, mode) | |||
| 250 | { | 307 | { |
| 251 | char name[46]; /* allow for up to 128-bit integers */ | 308 | char name[46]; /* allow for up to 128-bit integers */ |
| 252 | 309 | ||
| 253 | if (fd < 0) return (gzFile)Z_NULL; | 310 | if (fd == -1) return (gzFile)Z_NULL; |
| 254 | sprintf(name, "<fd:%d>", fd); /* for debugging */ | 311 | sprintf(name, "<fd:%d>", fd); /* for debugging */ |
| 255 | 312 | ||
| 256 | return gz_open (name, mode, fd, 0); | 313 | return gz_open (name, mode, fd, 0); |
| @@ -291,7 +348,7 @@ local int get_byte(s) | |||
| 291 | { | 348 | { |
| 292 | if (s->z_eof) return EOF; | 349 | if (s->z_eof) return EOF; |
| 293 | if (s->stream.avail_in == 0) { | 350 | if (s->stream.avail_in == 0) { |
| 294 | errno = 0; | 351 | zseterrno(0); |
| 295 | s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); | 352 | s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); |
| 296 | if (s->stream.avail_in == 0) { | 353 | if (s->stream.avail_in == 0) { |
| 297 | s->z_eof = 1; | 354 | s->z_eof = 1; |
| @@ -327,7 +384,7 @@ local void check_header(s) | |||
| 327 | len = s->stream.avail_in; | 384 | len = s->stream.avail_in; |
| 328 | if (len < 2) { | 385 | if (len < 2) { |
| 329 | if (len) s->inbuf[0] = s->stream.next_in[0]; | 386 | if (len) s->inbuf[0] = s->stream.next_in[0]; |
| 330 | errno = 0; | 387 | zseterrno(0); |
| 331 | len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); | 388 | len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); |
| 332 | if (len == 0) s->z_eof = 1; | 389 | if (len == 0) s->z_eof = 1; |
| 333 | if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; | 390 | if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; |
| @@ -403,7 +460,7 @@ local int destroy (s) | |||
| 403 | } | 460 | } |
| 404 | if (s->file != NULL && fclose(s->file)) { | 461 | if (s->file != NULL && fclose(s->file)) { |
| 405 | #ifdef ESPIPE | 462 | #ifdef ESPIPE |
| 406 | if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ | 463 | if (zerrno() != ESPIPE) /* fclose is broken for pipes in HP/UX */ |
| 407 | #endif | 464 | #endif |
| 408 | err = Z_ERRNO; | 465 | err = Z_ERRNO; |
| 409 | } | 466 | } |
| @@ -432,7 +489,7 @@ int ZEXPORT gzread (file, buf, len) | |||
| 432 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; | 489 | if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; |
| 433 | 490 | ||
| 434 | if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; | 491 | if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; |
| 435 | if (s->z_err == Z_STREAM_END || s->z_eof) return 0; /* EOF */ | 492 | if (s->z_err == Z_STREAM_END) return 0; /* EOF */ |
| 436 | 493 | ||
| 437 | next_out = (Byte*)buf; | 494 | next_out = (Byte*)buf; |
| 438 | s->stream.next_out = (Bytef*)buf; | 495 | s->stream.next_out = (Bytef*)buf; |
| @@ -472,12 +529,12 @@ int ZEXPORT gzread (file, buf, len) | |||
| 472 | len -= s->stream.avail_out; | 529 | len -= s->stream.avail_out; |
| 473 | s->in += len; | 530 | s->in += len; |
| 474 | s->out += len; | 531 | s->out += len; |
| 475 | if (feof(s->file)) s->z_eof = 1; | 532 | if (len == 0 && feof(s->file)) s->z_eof = 1; |
| 476 | return (int)len; | 533 | return (int)len; |
| 477 | } | 534 | } |
| 478 | if (s->stream.avail_in == 0 && !s->z_eof) { | 535 | if (s->stream.avail_in == 0 && !s->z_eof) { |
| 479 | 536 | ||
| 480 | errno = 0; | 537 | zseterrno(0); |
| 481 | s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); | 538 | s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); |
| 482 | if (s->stream.avail_in == 0) { | 539 | if (s->stream.avail_in == 0) { |
| 483 | s->z_eof = 1; | 540 | s->z_eof = 1; |
| @@ -1039,10 +1096,14 @@ int ZEXPORT gzclose (file) | |||
| 1039 | return destroy((gz_stream*)file); | 1096 | return destroy((gz_stream*)file); |
| 1040 | } | 1097 | } |
| 1041 | 1098 | ||
| 1042 | #if defined(STDC) && !defined(_WIN32_WCE) | 1099 | #if defined UNDER_CE && defined NO_ERRNO_H |
| 1043 | # define zstrerror(errnum) strerror(errnum) | 1100 | # define zstrerror(errnum) strwinerror((DWORD)errnum) |
| 1044 | #else | 1101 | #else |
| 1045 | # define zstrerror(errnum) "" | 1102 | # if defined (STDC) |
| 1103 | # define zstrerror(errnum) strerror(errnum) | ||
| 1104 | # else | ||
| 1105 | # define zstrerror(errnum) "" | ||
| 1106 | # endif | ||
| 1046 | #endif | 1107 | #endif |
| 1047 | 1108 | ||
| 1048 | /* =========================================================================== | 1109 | /* =========================================================================== |
| @@ -1066,7 +1127,7 @@ const char * ZEXPORT gzerror (file, errnum) | |||
| 1066 | *errnum = s->z_err; | 1127 | *errnum = s->z_err; |
| 1067 | if (*errnum == Z_OK) return (const char*)""; | 1128 | if (*errnum == Z_OK) return (const char*)""; |
| 1068 | 1129 | ||
| 1069 | m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); | 1130 | m = (char*)(*errnum == Z_ERRNO ? zstrerror(zerrno()) : s->stream.msg); |
| 1070 | 1131 | ||
| 1071 | if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); | 1132 | if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); |
| 1072 | 1133 | ||
| @@ -1092,3 +1153,44 @@ void ZEXPORT gzclearerr (file) | |||
| 1092 | s->z_eof = 0; | 1153 | s->z_eof = 0; |
| 1093 | clearerr(s->file); | 1154 | clearerr(s->file); |
| 1094 | } | 1155 | } |
| 1156 | |||
| 1157 | /* new functions in gzlib, but only partially implemented here */ | ||
| 1158 | |||
| 1159 | int ZEXPORT gzbuffer (file, size) | ||
| 1160 | gzFile file; | ||
| 1161 | unsigned size; | ||
| 1162 | { | ||
| 1163 | return -1; | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | z_off_t ZEXPORT gzoffset (file) | ||
| 1167 | gzFile file; | ||
| 1168 | { | ||
| 1169 | return -1; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | z_off64_t ZEXPORT gzoffset64 (file) | ||
| 1173 | gzFile file; | ||
| 1174 | { | ||
| 1175 | return -1; | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | int ZEXPORT gzclose_r (file) | ||
| 1179 | gzFile file; | ||
| 1180 | { | ||
| 1181 | return gzclose(file); | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | int ZEXPORT gzclose_w (file) | ||
| 1185 | gzFile file; | ||
| 1186 | { | ||
| 1187 | return gzclose(file); | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | int gzio_old = 1; | ||
| 1191 | |||
| 1192 | #else /* !OLD_GZIO */ | ||
| 1193 | |||
| 1194 | int gzio_old = 0; | ||
| 1195 | |||
| 1196 | #endif /* OLD_GZIO */ | ||
| @@ -0,0 +1,513 @@ | |||
| 1 | /* gzlib.c -- zlib functions common to reading and writing gzip files | ||
| 2 | * Copyright (C) 2004, 2010 Mark Adler | ||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef OLD_GZIO | ||
| 7 | |||
| 8 | #include "gzguts.h" | ||
| 9 | |||
| 10 | #ifdef _LARGEFILE64_SOURCE | ||
| 11 | # define LSEEK lseek64 | ||
| 12 | #else | ||
| 13 | # define LSEEK lseek | ||
| 14 | #endif | ||
| 15 | |||
| 16 | /* Local functions */ | ||
| 17 | local void gz_reset OF((gz_statep)); | ||
| 18 | local gzFile gz_open OF((const char *, int, const char *, int)); | ||
| 19 | |||
| 20 | #if defined UNDER_CE && defined NO_ERRNO_H | ||
| 21 | local char *strwinerror OF((DWORD error)); | ||
| 22 | |||
| 23 | # include <windows.h> | ||
| 24 | |||
| 25 | /* Map the Windows error number in ERROR to a locale-dependent error | ||
| 26 | message string and return a pointer to it. Typically, the values | ||
| 27 | for ERROR come from GetLastError. | ||
| 28 | |||
| 29 | The string pointed to shall not be modified by the application, | ||
| 30 | but may be overwritten by a subsequent call to strwinerror | ||
| 31 | |||
| 32 | The strwinerror function does not change the current setting | ||
| 33 | of GetLastError. */ | ||
| 34 | |||
| 35 | local char *strwinerror (error) | ||
| 36 | DWORD error; | ||
| 37 | { | ||
| 38 | static char buf[1024]; | ||
| 39 | |||
| 40 | wchar_t *msgbuf; | ||
| 41 | DWORD lasterr = GetLastError(); | ||
| 42 | DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | ||
| 43 | | FORMAT_MESSAGE_ALLOCATE_BUFFER, | ||
| 44 | NULL, | ||
| 45 | error, | ||
| 46 | 0, /* Default language */ | ||
| 47 | (LPVOID)&msgbuf, | ||
| 48 | 0, | ||
| 49 | NULL); | ||
| 50 | if (chars != 0) { | ||
| 51 | /* If there is an \r\n appended, zap it. */ | ||
| 52 | if (chars >= 2 | ||
| 53 | && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { | ||
| 54 | chars -= 2; | ||
| 55 | msgbuf[chars] = 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | if (chars > sizeof (buf) - 1) { | ||
| 59 | chars = sizeof (buf) - 1; | ||
| 60 | msgbuf[chars] = 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | wcstombs(buf, msgbuf, chars + 1); | ||
| 64 | LocalFree(msgbuf); | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | sprintf(buf, "unknown win32 error (%ld)", error); | ||
| 68 | } | ||
| 69 | |||
| 70 | SetLastError(lasterr); | ||
| 71 | return buf; | ||
| 72 | } | ||
| 73 | |||
| 74 | #endif /* UNDER_CE && NO_ERRNO_H */ | ||
| 75 | |||
| 76 | /* Reset gzip file state */ | ||
| 77 | local void gz_reset(state) | ||
| 78 | gz_statep state; | ||
| 79 | { | ||
| 80 | state->how = 0; /* look for gzip header */ | ||
| 81 | if (state->mode == GZ_READ) { /* for reading ... */ | ||
| 82 | state->have = 0; /* no output data available */ | ||
| 83 | state->eof = 0; /* not at end of file */ | ||
| 84 | } | ||
| 85 | state->seek = 0; /* no seek request pending */ | ||
| 86 | gz_error(state, Z_OK, NULL); /* clear error */ | ||
| 87 | state->pos = 0; /* no uncompressed data yet */ | ||
| 88 | state->strm.avail_in = 0; /* no input data yet */ | ||
| 89 | } | ||
| 90 | |||
| 91 | /* Open a gzip file either by name or file descriptor. */ | ||
| 92 | local gzFile gz_open(path, fd, mode, use64) | ||
| 93 | const char *path; | ||
| 94 | int fd; | ||
| 95 | const char *mode; | ||
| 96 | int use64; | ||
| 97 | { | ||
| 98 | gz_statep state; | ||
| 99 | |||
| 100 | /* allocate gzFile structure to return */ | ||
| 101 | state = malloc(sizeof(gz_state)); | ||
| 102 | if (state == NULL) | ||
| 103 | return NULL; | ||
| 104 | state->size = 0; /* no buffers allocated yet */ | ||
| 105 | state->want = GZBUFSIZE; /* requested buffer size */ | ||
| 106 | state->msg = NULL; /* no error message yet */ | ||
| 107 | |||
| 108 | /* interpret mode */ | ||
| 109 | state->mode = GZ_NONE; | ||
| 110 | state->level = Z_DEFAULT_COMPRESSION; | ||
| 111 | state->strategy = Z_DEFAULT_STRATEGY; | ||
| 112 | while (*mode) { | ||
| 113 | if (*mode >= '0' && *mode <= '9') | ||
| 114 | state->level = *mode - '0'; | ||
| 115 | else | ||
| 116 | switch (*mode) { | ||
| 117 | case 'r': | ||
| 118 | state->mode = GZ_READ; | ||
| 119 | break; | ||
| 120 | #ifndef NO_GZCOMPRESS | ||
| 121 | case 'w': | ||
| 122 | state->mode = GZ_WRITE; | ||
| 123 | break; | ||
| 124 | case 'a': | ||
| 125 | state->mode = GZ_APPEND; | ||
| 126 | break; | ||
| 127 | #endif | ||
| 128 | case '+': /* can't read and write at the same time */ | ||
| 129 | free(state); | ||
| 130 | return NULL; | ||
| 131 | case 'b': /* ignore -- will request binary anyway */ | ||
| 132 | break; | ||
| 133 | case 'f': | ||
| 134 | state->strategy = Z_FILTERED; | ||
| 135 | break; | ||
| 136 | case 'h': | ||
| 137 | state->strategy = Z_HUFFMAN_ONLY; | ||
| 138 | break; | ||
| 139 | case 'R': | ||
| 140 | state->strategy = Z_RLE; | ||
| 141 | break; | ||
| 142 | case 'F': | ||
| 143 | state->strategy = Z_FIXED; | ||
| 144 | default: /* could consider as an error, but just ignore */ | ||
| 145 | ; | ||
| 146 | } | ||
| 147 | mode++; | ||
| 148 | } | ||
| 149 | |||
| 150 | /* must provide an "r", "w", or "a" */ | ||
| 151 | if (state->mode == GZ_NONE) { | ||
| 152 | free(state); | ||
| 153 | return NULL; | ||
| 154 | } | ||
| 155 | |||
| 156 | /* open the file with the appropriate mode (or just use fd) */ | ||
| 157 | state->fd = fd != -1 ? fd : | ||
| 158 | open(path, | ||
| 159 | #ifdef O_LARGEFILE | ||
| 160 | (use64 ? O_LARGEFILE : 0) | | ||
| 161 | #endif | ||
| 162 | #ifdef O_BINARY | ||
| 163 | O_BINARY | | ||
| 164 | #endif | ||
| 165 | (state->mode == GZ_READ ? | ||
| 166 | O_RDONLY : | ||
| 167 | (O_WRONLY | O_CREAT | ( | ||
| 168 | state->mode == GZ_WRITE ? | ||
| 169 | O_TRUNC : | ||
| 170 | O_APPEND))), | ||
| 171 | 0666); | ||
| 172 | if (state->fd == -1) { | ||
| 173 | free(state); | ||
| 174 | return NULL; | ||
| 175 | } | ||
| 176 | if (state->mode == GZ_APPEND) | ||
| 177 | state->mode = GZ_WRITE; /* simplify later checks */ | ||
| 178 | |||
| 179 | /* save the path name for error messages */ | ||
| 180 | state->path = malloc(strlen(path) + 1); | ||
| 181 | strcpy(state->path, path); | ||
| 182 | |||
| 183 | /* save the current position for rewinding (only if reading) */ | ||
| 184 | if (state->mode == GZ_READ) { | ||
| 185 | state->start = LSEEK(state->fd, 0, SEEK_CUR); | ||
| 186 | if (state->start == -1) state->start = 0; | ||
| 187 | } | ||
| 188 | |||
| 189 | /* initialize stream */ | ||
| 190 | gz_reset(state); | ||
| 191 | |||
| 192 | /* return stream */ | ||
| 193 | return (gzFile)state; | ||
| 194 | } | ||
| 195 | |||
| 196 | /* -- see zlib.h -- */ | ||
| 197 | gzFile ZEXPORT gzopen(path, mode) | ||
| 198 | const char *path; | ||
| 199 | const char *mode; | ||
| 200 | { | ||
| 201 | return gz_open(path, -1, mode, 0); | ||
| 202 | } | ||
| 203 | |||
| 204 | /* -- see zlib.h -- */ | ||
| 205 | gzFile ZEXPORT gzopen64(path, mode) | ||
| 206 | const char *path; | ||
| 207 | const char *mode; | ||
| 208 | { | ||
| 209 | return gz_open(path, -1, mode, 1); | ||
| 210 | } | ||
| 211 | |||
| 212 | /* -- see zlib.h -- */ | ||
| 213 | gzFile ZEXPORT gzdopen(fd, mode) | ||
| 214 | int fd; | ||
| 215 | const char *mode; | ||
| 216 | { | ||
| 217 | char path[46]; /* allow up to 128-bit integers, so don't worry -- | ||
| 218 | the sprintf() is safe */ | ||
| 219 | |||
| 220 | if (fd < 0) | ||
| 221 | return NULL; | ||
| 222 | sprintf(path, "<fd:%d>", fd); /* for error messages */ | ||
| 223 | return gz_open(path, fd, mode, 1); | ||
| 224 | } | ||
| 225 | |||
| 226 | /* -- see zlib.h -- */ | ||
| 227 | int ZEXPORT gzbuffer(file, size) | ||
| 228 | gzFile file; | ||
| 229 | unsigned size; | ||
| 230 | { | ||
| 231 | gz_statep state; | ||
| 232 | |||
| 233 | /* get internal structure and check integrity */ | ||
| 234 | if (file == NULL) | ||
| 235 | return -1; | ||
| 236 | state = (gz_statep)file; | ||
| 237 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 238 | return -1; | ||
| 239 | |||
| 240 | /* make sure we haven't already allocated memory */ | ||
| 241 | if (state->size != 0) | ||
| 242 | return -1; | ||
| 243 | |||
| 244 | /* check and set requested size */ | ||
| 245 | if (size == 0) | ||
| 246 | return -1; | ||
| 247 | state->want = size; | ||
| 248 | return 0; | ||
| 249 | } | ||
| 250 | |||
| 251 | /* -- see zlib.h -- */ | ||
| 252 | int ZEXPORT gzrewind(file) | ||
| 253 | gzFile file; | ||
| 254 | { | ||
| 255 | gz_statep state; | ||
| 256 | |||
| 257 | /* get internal structure */ | ||
| 258 | if (file == NULL) | ||
| 259 | return -1; | ||
| 260 | state = (gz_statep)file; | ||
| 261 | |||
| 262 | /* check that we're reading and that there's no error */ | ||
| 263 | if (state->mode != GZ_READ || state->err != Z_OK) | ||
| 264 | return -1; | ||
| 265 | |||
| 266 | /* back up and start over */ | ||
| 267 | if (LSEEK(state->fd, state->start, SEEK_SET) == -1) | ||
| 268 | return -1; | ||
| 269 | gz_reset(state); | ||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | |||
| 273 | /* -- see zlib.h -- */ | ||
| 274 | z_off64_t ZEXPORT gzseek64(file, offset, whence) | ||
| 275 | gzFile file; | ||
| 276 | z_off64_t offset; | ||
| 277 | int whence; | ||
| 278 | { | ||
| 279 | unsigned n; | ||
| 280 | z_off64_t ret; | ||
| 281 | gz_statep state; | ||
| 282 | |||
| 283 | /* get internal structure and check integrity */ | ||
| 284 | if (file == NULL) | ||
| 285 | return -1; | ||
| 286 | state = (gz_statep)file; | ||
| 287 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 288 | return -1; | ||
| 289 | |||
| 290 | /* check that there's no error */ | ||
| 291 | if (state->err != Z_OK) | ||
| 292 | return -1; | ||
| 293 | |||
| 294 | /* can only seek from start or relative to current position */ | ||
| 295 | if (whence != SEEK_SET && whence != SEEK_CUR) | ||
| 296 | return -1; | ||
| 297 | |||
| 298 | /* normalize offset to a SEEK_CUR specification */ | ||
| 299 | if (whence == SEEK_SET) | ||
| 300 | offset -= state->pos; | ||
| 301 | |||
| 302 | /* if within raw area while reading, just go there */ | ||
| 303 | if (state->mode == GZ_READ && state->how == 1 && | ||
| 304 | state->pos + offset >= state->raw) { | ||
| 305 | ret = LSEEK(state->fd, offset, SEEK_CUR); | ||
| 306 | if (ret == -1) | ||
| 307 | return -1; | ||
| 308 | state->have = 0; | ||
| 309 | state->eof = 0; | ||
| 310 | state->seek = 0; | ||
| 311 | gz_error(state, Z_OK, NULL); | ||
| 312 | state->strm.avail_in = 0; | ||
| 313 | state->pos += offset; | ||
| 314 | return state->pos; | ||
| 315 | } | ||
| 316 | |||
| 317 | /* calculate skip amount, rewinding if needed for back seek when reading */ | ||
| 318 | if (offset < 0) { | ||
| 319 | if (state->mode != GZ_READ) /* writing -- can't go backwards */ | ||
| 320 | return -1; | ||
| 321 | offset += state->pos; | ||
| 322 | if (offset < 0) /* before start of file! */ | ||
| 323 | return -1; | ||
| 324 | if (gzrewind(file) == -1) /* rewind, then skip to offset */ | ||
| 325 | return -1; | ||
| 326 | } | ||
| 327 | |||
| 328 | /* if reading, skip what's in output buffer (one less gz_getc() check) */ | ||
| 329 | if (state->mode == GZ_READ) { | ||
| 330 | n = state->have > offset ? (unsigned)offset : state->have; | ||
| 331 | state->have -= n; | ||
| 332 | state->next += n; | ||
| 333 | state->pos += n; | ||
| 334 | offset -= n; | ||
| 335 | } | ||
| 336 | |||
| 337 | /* request skip (if not zero) */ | ||
| 338 | if (offset) { | ||
| 339 | state->seek = 1; | ||
| 340 | state->skip = offset; | ||
| 341 | } | ||
| 342 | return state->pos + offset; | ||
| 343 | } | ||
| 344 | |||
| 345 | /* -- see zlib.h -- */ | ||
| 346 | z_off_t ZEXPORT gzseek(file, offset, whence) | ||
| 347 | gzFile file; | ||
| 348 | z_off_t offset; | ||
| 349 | int whence; | ||
| 350 | { | ||
| 351 | z_off64_t ret; | ||
| 352 | |||
| 353 | ret = gzseek64(file, (z_off64_t)offset, whence); | ||
| 354 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; | ||
| 355 | } | ||
| 356 | |||
| 357 | /* -- see zlib.h -- */ | ||
| 358 | z_off64_t ZEXPORT gztell64(file) | ||
| 359 | gzFile file; | ||
| 360 | { | ||
| 361 | gz_statep state; | ||
| 362 | |||
| 363 | /* get internal structure and check integrity */ | ||
| 364 | if (file == NULL) | ||
| 365 | return -1; | ||
| 366 | state = (gz_statep)file; | ||
| 367 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 368 | return -1; | ||
| 369 | |||
| 370 | /* return position */ | ||
| 371 | return state->pos + (state->seek ? state->skip : 0); | ||
| 372 | } | ||
| 373 | |||
| 374 | /* -- see zlib.h -- */ | ||
| 375 | z_off_t ZEXPORT gztell(file) | ||
| 376 | gzFile file; | ||
| 377 | { | ||
| 378 | z_off64_t ret; | ||
| 379 | |||
| 380 | ret = gztell64(file); | ||
| 381 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; | ||
| 382 | } | ||
| 383 | |||
| 384 | /* -- see zlib.h -- */ | ||
| 385 | z_off64_t ZEXPORT gzoffset64(file) | ||
| 386 | gzFile file; | ||
| 387 | { | ||
| 388 | z_off64_t offset; | ||
| 389 | gz_statep state; | ||
| 390 | |||
| 391 | /* get internal structure and check integrity */ | ||
| 392 | if (file == NULL) | ||
| 393 | return -1; | ||
| 394 | state = (gz_statep)file; | ||
| 395 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 396 | return -1; | ||
| 397 | |||
| 398 | /* compute and return effective offset in file */ | ||
| 399 | offset = LSEEK(state->fd, 0, SEEK_CUR); | ||
| 400 | if (offset == -1) | ||
| 401 | return -1; | ||
| 402 | if (state->mode == GZ_READ) /* reading */ | ||
| 403 | offset -= state->strm.avail_in; /* don't count buffered input */ | ||
| 404 | return offset; | ||
| 405 | } | ||
| 406 | |||
| 407 | /* -- see zlib.h -- */ | ||
| 408 | z_off_t ZEXPORT gzoffset(file) | ||
| 409 | gzFile file; | ||
| 410 | { | ||
| 411 | z_off64_t ret; | ||
| 412 | |||
| 413 | ret = gzoffset64(file); | ||
| 414 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; | ||
| 415 | } | ||
| 416 | |||
| 417 | /* -- see zlib.h -- */ | ||
| 418 | int ZEXPORT gzeof(file) | ||
| 419 | gzFile file; | ||
| 420 | { | ||
| 421 | gz_statep state; | ||
| 422 | |||
| 423 | /* get internal structure and check integrity */ | ||
| 424 | if (file == NULL) | ||
| 425 | return -1; | ||
| 426 | state = (gz_statep)file; | ||
| 427 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 428 | return -1; | ||
| 429 | |||
| 430 | /* return end-of-file state */ | ||
| 431 | return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; | ||
| 432 | } | ||
| 433 | |||
| 434 | /* -- see zlib.h -- */ | ||
| 435 | const char * ZEXPORT gzerror(file, errnum) | ||
| 436 | gzFile file; | ||
| 437 | int *errnum; | ||
| 438 | { | ||
| 439 | gz_statep state; | ||
| 440 | |||
| 441 | /* get internal structure and check integrity */ | ||
| 442 | if (file == NULL) | ||
| 443 | return NULL; | ||
| 444 | state = (gz_statep)file; | ||
| 445 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 446 | return NULL; | ||
| 447 | |||
| 448 | /* return error information */ | ||
| 449 | *errnum = state->err; | ||
| 450 | return state->msg == NULL ? "" : state->msg; | ||
| 451 | } | ||
| 452 | |||
| 453 | /* -- see zlib.h -- */ | ||
| 454 | void ZEXPORT gzclearerr(file) | ||
| 455 | gzFile file; | ||
| 456 | { | ||
| 457 | gz_statep state; | ||
| 458 | |||
| 459 | /* get internal structure and check integrity */ | ||
| 460 | if (file == NULL) | ||
| 461 | return; | ||
| 462 | state = (gz_statep)file; | ||
| 463 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | ||
| 464 | return; | ||
| 465 | |||
| 466 | /* clear error and end-of-file */ | ||
| 467 | if (state->mode == GZ_READ) | ||
| 468 | state->eof = 0; | ||
| 469 | gz_error(state, Z_OK, NULL); | ||
| 470 | } | ||
| 471 | |||
| 472 | /* Create an error message in allocated memory and set state->err and | ||
| 473 | state->msg accordingly. Free any previous error message already there. Do | ||
| 474 | not try to free or allocate space if the error is Z_MEM_ERROR (out of | ||
| 475 | memory). Simply save the error message as a static string. If there is | ||
| 476 | an allocation failure constructing the error message, then convert the | ||
| 477 | error to out of memory. */ | ||
| 478 | void ZEXPORT gz_error(state, err, msg) | ||
| 479 | gz_statep state; | ||
| 480 | int err; | ||
| 481 | char *msg; | ||
| 482 | { | ||
| 483 | /* free previously allocated message and clear */ | ||
| 484 | if (state->msg != NULL) { | ||
| 485 | if (state->err != Z_MEM_ERROR) | ||
| 486 | free(state->msg); | ||
| 487 | state->msg = NULL; | ||
| 488 | } | ||
| 489 | |||
| 490 | /* set error code, and if no message, then done */ | ||
| 491 | state->err = err; | ||
| 492 | if (msg == NULL) | ||
| 493 | return; | ||
| 494 | |||
| 495 | /* for an out of memory error, save as static string */ | ||
| 496 | if (err == Z_MEM_ERROR) { | ||
| 497 | state->msg = msg; | ||
| 498 | return; | ||
| 499 | } | ||
| 500 | |||
| 501 | /* construct error message with path */ | ||
| 502 | if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { | ||
| 503 | state->err = Z_MEM_ERROR; | ||
| 504 | state->msg = "out of memory"; | ||
| 505 | return; | ||
| 506 | } | ||
| 507 | strcpy(state->msg, state->path); | ||
| 508 | strcat(state->msg, ": "); | ||
| 509 | strcat(state->msg, msg); | ||
| 510 | return; | ||
| 511 | } | ||
| 512 | |||
| 513 | #endif /* !OLD_GZIO */ | ||
diff --git a/gzread.c b/gzread.c new file mode 100644 index 0000000..836c57c --- /dev/null +++ b/gzread.c | |||
| @@ -0,0 +1,632 @@ | |||
| 1 | /* gzread.c -- zlib functions for reading gzip files | ||
| 2 | * Copyright (C) 2004, 2005, 2010 Mark Adler | ||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef OLD_GZIO | ||
| 7 | |||
| 8 | #include "gzguts.h" | ||
| 9 | |||
| 10 | /* Local functions */ | ||
| 11 | local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); | ||
| 12 | local int gz_avail OF((gz_statep)); | ||
| 13 | local int gz_next4 OF((gz_statep, unsigned long *)); | ||
| 14 | local int gz_head OF((gz_statep)); | ||
| 15 | local int gz_decomp OF((gz_statep)); | ||
| 16 | local int gz_make OF((gz_statep)); | ||
| 17 | local int gz_skip OF((gz_statep, z_off_t)); | ||
| 18 | |||
| 19 | /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from | ||
| 20 | state->fd, and update state->eof, state->err, and state->msg as appropriate. | ||
| 21 | This function needs to loop on read(), since read() is not guaranteed to | ||
| 22 | read the number of bytes requested, depending on the type of descriptor. */ | ||
| 23 | local int gz_load(state, buf, len, have) | ||
| 24 | gz_statep state; | ||
| 25 | unsigned char *buf; | ||
| 26 | unsigned len; | ||
| 27 | unsigned *have; | ||
| 28 | { | ||
| 29 | int ret; | ||
| 30 | |||
| 31 | *have = 0; | ||
| 32 | do { | ||
| 33 | ret = read(state->fd, buf + *have, len - *have); | ||
| 34 | if (ret <= 0) | ||
| 35 | break; | ||
| 36 | *have += ret; | ||
| 37 | } while (*have < len); | ||
| 38 | if (ret < 0) { | ||
| 39 | gz_error(state, Z_ERRNO, zstrerror()); | ||
| 40 | return -1; | ||
| 41 | } | ||
| 42 | if (ret == 0) | ||
| 43 | state->eof = 1; | ||
| 44 | return 0; | ||
| 45 | } | ||
| 46 | |||
| 47 | /* Load up input buffer and set eof flag if last data loaded -- return -1 on | ||
| 48 | error, 0 otherwise. Note that the eof flag is set when the end of the input | ||
| 49 | file is reached, even though there may be unused data in the buffer. Once | ||
| 50 | that data has been used, no more attempts will be made to read the file. | ||
| 51 | gz_avail() assumes that strm->avail_in == 0. */ | ||
| 52 | local int gz_avail(state) | ||
| 53 | gz_statep state; | ||
| 54 | { | ||
| 55 | z_streamp strm = &(state->strm); | ||
| 56 | |||
| 57 | if (state->err != Z_OK) | ||
| 58 | return -1; | ||
| 59 | if (state->eof == 0) { | ||
| 60 | if (gz_load(state, state->in, state->size, &(strm->avail_in)) == -1) | ||
| 61 | return -1; | ||
| 62 | strm->next_in = state->in; | ||
| 63 | } | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | /* Get next byte from input, or -1 if end or error. */ | ||
| 68 | #define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \ | ||
| 69 | (strm->avail_in == 0 ? -1 : \ | ||
| 70 | (strm->avail_in--, *(strm->next_in)++))) | ||
| 71 | |||
| 72 | /* Get a four-byte little-endian integer and return 0 on success and the | ||
| 73 | value in *ret. Otherwise -1 is returned and *ret is not modified. */ | ||
| 74 | local int gz_next4(state, ret) | ||
| 75 | gz_statep state; | ||
| 76 | unsigned long *ret; | ||
| 77 | { | ||
| 78 | int ch; | ||
| 79 | unsigned long val; | ||
| 80 | z_streamp strm = &(state->strm); | ||
| 81 | |||
| 82 | val = NEXT(); | ||
| 83 | val += (unsigned)NEXT() << 8; | ||
| 84 | val += (unsigned long)NEXT() << 16; | ||
| 85 | ch = NEXT(); | ||
| 86 | if (ch == -1) | ||
| 87 | return -1; | ||
| 88 | val += (unsigned long)ch << 24; | ||
| 89 | *ret = val; | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | /* Look for gzip header, set up for inflate or copy. state->have must be zero. | ||
| 94 | If this is the first time in, allocate required memory. state->how will be | ||
| 95 | left unchanged if there is no more input data available, will be set to 1 if | ||
| 96 | there is no gzip header and direct copying will be performned, or it will be | ||
| 97 | set to 2 for decompression, and the gzip header will be skipped so that the | ||
| 98 | next available input data is the raw deflate stream. If direct copying, | ||
| 99 | then leftover input data from the input buffer will be copied to the output | ||
| 100 | buffer. In that case, all further file reads will be directly to either the | ||
| 101 | output buffer or a user buffer. If decompressing, the inflate state and the | ||
| 102 | check value will be initialized. gz_head() will return 0 on success or -1 | ||
| 103 | on failure. Failures may include read errors or gzip header errors. */ | ||
| 104 | local int gz_head(state) | ||
| 105 | gz_statep state; | ||
| 106 | { | ||
| 107 | z_streamp strm = &(state->strm); | ||
| 108 | int flags; | ||
| 109 | unsigned len; | ||
| 110 | |||
| 111 | /* allocate read buffers and inflate memory */ | ||
| 112 | if (state->size == 0) { | ||
| 113 | /* allocate buffers */ | ||
| 114 | state->in = malloc(state->want); | ||
| 115 | state->out = malloc(state->want << 1); | ||
| 116 | if (state->in == NULL || state->out == NULL) { | ||
| 117 | if (state->out != NULL) | ||
| 118 | free(state->out); | ||
| 119 | if (state->in != NULL) | ||
| 120 | free(state->in); | ||
| 121 | gz_error(state, Z_MEM_ERROR, "out of memory"); | ||
| 122 | return -1; | ||
| 123 | } | ||
| 124 | state->size = state->want; | ||
| 125 | |||
| 126 | /* allocate inflate memory */ | ||
| 127 | state->strm.zalloc = Z_NULL; | ||
| 128 | state->strm.zfree = Z_NULL; | ||
| 129 | state->strm.opaque = Z_NULL; | ||
| 130 | state->strm.avail_in = 0; | ||
| 131 | state->strm.next_in = Z_NULL; | ||
| 132 | if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */ | ||
| 133 | free(state->out); | ||
| 134 | free(state->in); | ||
| 135 | state->size = 0; | ||
| 136 | gz_error(state, Z_MEM_ERROR, "out of memory"); | ||
| 137 | return -1; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | /* get some data in the input buffer */ | ||
| 142 | if (strm->avail_in == 0) { | ||
| 143 | if (gz_avail(state) == -1) | ||
| 144 | return -1; | ||
| 145 | if (strm->avail_in == 0) | ||
| 146 | return 0; | ||
| 147 | } | ||
| 148 | |||
| 149 | /* look for the gzip magic header bytes 31 and 139 */ | ||
| 150 | if (strm->next_in[0] == 31) { | ||
| 151 | strm->avail_in--; | ||
| 152 | strm->next_in++; | ||
| 153 | if (strm->avail_in == 0 && gz_avail(state) == -1) | ||
| 154 | return -1; | ||
| 155 | if (strm->avail_in && strm->next_in[0] == 139) { | ||
| 156 | /* we have a gzip header, woo hoo! */ | ||
| 157 | strm->avail_in--; | ||
| 158 | strm->next_in++; | ||
| 159 | |||
| 160 | /* skip rest of header */ | ||
| 161 | if (NEXT() != 8) { /* compression method */ | ||
| 162 | gz_error(state, Z_DATA_ERROR, "unknown compression method"); | ||
| 163 | return -1; | ||
| 164 | } | ||
| 165 | flags = NEXT(); | ||
| 166 | if (flags & 0xe0) { /* reserved flag bits */ | ||
| 167 | gz_error(state, Z_DATA_ERROR, "unknown header flags set"); | ||
| 168 | return -1; | ||
| 169 | } | ||
| 170 | NEXT(); /* modification time */ | ||
| 171 | NEXT(); | ||
| 172 | NEXT(); | ||
| 173 | NEXT(); | ||
| 174 | NEXT(); /* extra flags */ | ||
| 175 | NEXT(); /* operating system */ | ||
| 176 | if (flags & 4) { /* extra field */ | ||
| 177 | len = (unsigned)NEXT(); | ||
| 178 | len += (unsigned)NEXT() << 8; | ||
| 179 | while (len--) | ||
| 180 | if (NEXT() < 0) | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | if (flags & 8) /* file name */ | ||
| 184 | while (NEXT() > 0) | ||
| 185 | ; | ||
| 186 | if (flags & 16) /* comment */ | ||
| 187 | while (NEXT() > 0) | ||
| 188 | ; | ||
| 189 | if (flags & 2) { /* header crc */ | ||
| 190 | NEXT(); | ||
| 191 | NEXT(); | ||
| 192 | } | ||
| 193 | |||
| 194 | /* set up for decompression */ | ||
| 195 | inflateReset(strm); | ||
| 196 | strm->adler = crc32(0L, Z_NULL, 0); | ||
| 197 | state->how = 2; | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | else { | ||
| 201 | /* not a gzip file -- save first byte (31) and fall to raw i/o */ | ||
| 202 | state->out[0] = 31; | ||
| 203 | state->have = 1; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | /* doing raw i/o, save start of raw data for seeking, copy any leftover | ||
| 208 | input to output -- this assumes that the output buffer is larger than | ||
| 209 | the input buffer */ | ||
| 210 | state->raw = state->pos; | ||
| 211 | state->next = state->out; | ||
| 212 | if (strm->avail_in) { | ||
| 213 | memcpy(state->next + state->have, strm->next_in, strm->avail_in); | ||
| 214 | state->have += strm->avail_in; | ||
| 215 | strm->avail_in = 0; | ||
| 216 | } | ||
| 217 | state->how = 1; | ||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | /* Decompress from input to the provided next_out and avail_out in the state. | ||
| 222 | If the end of the compressed data is reached, then verify the gzip trailer | ||
| 223 | check value and length (modulo 2^32). state->have and state->next are | ||
| 224 | set to point to the just decompressed data, and the crc is updated. If the | ||
| 225 | trailer is verified, state->how is reset to zero to look for the next gzip | ||
| 226 | stream or raw data, once state->have is depleted. Returns 0 on success, -1 | ||
| 227 | on failure. Failures may include invalid compressed data or a failed gzip | ||
| 228 | trailer verification. */ | ||
| 229 | local int gz_decomp(state) | ||
| 230 | gz_statep state; | ||
| 231 | { | ||
| 232 | int ret; | ||
| 233 | unsigned had; | ||
| 234 | unsigned long crc, len; | ||
| 235 | z_streamp strm = &(state->strm); | ||
| 236 | |||
| 237 | /* fill output buffer up to end of deflate stream */ | ||
| 238 | had = strm->avail_out; | ||
| 239 | do { | ||
| 240 | /* get more input for inflate() */ | ||
| 241 | if (strm->avail_in == 0 && gz_avail(state) == -1) | ||
| 242 | return -1; | ||
| 243 | if (strm->avail_in == 0) { | ||
| 244 | gz_error(state, Z_DATA_ERROR, "unexpected end of file"); | ||
| 245 | return -1; | ||
| 246 | } | ||
| 247 | |||
| 248 | /* decompress and handle errors */ | ||
| 249 | ret = inflate(strm, Z_NO_FLUSH); | ||
| 250 | if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { | ||
| 251 | gz_error(state, Z_STREAM_ERROR, | ||
| 252 | "internal error: inflate stream corrupt"); | ||
| 253 | return -1; | ||
| 254 | } | ||
| 255 | if (ret == Z_MEM_ERROR) { | ||
| 256 | gz_error(state, Z_MEM_ERROR, "out of memory"); | ||
| 257 | return -1; | ||
| 258 | } | ||
| 259 | if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ | ||
| 260 | gz_error(state, Z_DATA_ERROR, | ||
| 261 | strm->msg == NULL ? "compressed data error" : strm->msg); | ||
| 262 | return -1; | ||
| 263 | } | ||
| 264 | } while (strm->avail_out && ret != Z_STREAM_END); | ||
| 265 | |||
| 266 | /* update available output and crc check value */ | ||
| 267 | state->have = had - strm->avail_out; | ||
| 268 | state->next = strm->next_out - state->have; | ||
| 269 | strm->adler = crc32(strm->adler, state->next, state->have); | ||
| 270 | |||
| 271 | /* check gzip trailer if at end of deflate stream */ | ||
| 272 | if (ret == Z_STREAM_END) { | ||
| 273 | if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { | ||
| 274 | gz_error(state, Z_DATA_ERROR, "unexpected end of file"); | ||
| 275 | return -1; | ||
| 276 | } | ||
| 277 | if (crc != strm->adler) { | ||
| 278 | gz_error(state, Z_DATA_ERROR, "incorrect data check"); | ||
| 279 | return -1; | ||
| 280 | } | ||
| 281 | if (len != (strm->total_out & 0xffffffffL)) { | ||
| 282 | gz_error(state, Z_DATA_ERROR, "incorrect length check"); | ||
| 283 | return -1; | ||
| 284 | } | ||
| 285 | state->how = 0; /* ready for next stream, once have is 0 */ | ||
| 286 | } | ||
| 287 | |||
| 288 | /* good decompression */ | ||
| 289 | return 0; | ||
| 290 | } | ||
| 291 | |||
| 292 | /* Make data and put in the output buffer. Assumes that state->have == 0. | ||
| 293 | Data is either copied from the input file or decompressed from the input | ||
| 294 | file depending on state->how. If state->how is zero, then a gzip header is | ||
| 295 | looked for (and skipped if found) to determine wither to copy or decompress. | ||
| 296 | Returns -1 on error, otherwise 0. gz_make() will leave state->have non-zero | ||
| 297 | unless the end of the input file has been reached and all data has been | ||
| 298 | processed. */ | ||
| 299 | local int gz_make(state) | ||
| 300 | gz_statep state; | ||
| 301 | { | ||
| 302 | z_streamp strm = &(state->strm); | ||
| 303 | |||
| 304 | if (state->how == 0) { /* look for gzip header */ | ||
| 305 | if (gz_head(state) == -1) | ||
| 306 | return -1; | ||
| 307 | if (state->have) /* got some data from gz_head() */ | ||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | if (state->how == 1) { /* straight copy */ | ||
| 311 | if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1) | ||
| 312 | return -1; | ||
| 313 | state->next = state->out; | ||
| 314 | } | ||
| 315 | else if (state->how == 2) { /* decompress */ | ||
| 316 | strm->avail_out = state->size << 1; | ||
| 317 | strm->next_out = state->out; | ||
| 318 | if (gz_decomp(state) == -1) | ||
| 319 | return -1; | ||
| 320 | } | ||
| 321 | return 0; | ||
| 322 | } | ||
| 323 | |||
| 324 | /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ | ||
| 325 | local int gz_skip(state, len) | ||
| 326 | gz_statep state; | ||
| 327 | z_off_t len; | ||
| 328 | { | ||
| 329 | unsigned n; | ||
| 330 | |||
| 331 | /* skip over len bytes or reach end-of-file, whichever comes first */ | ||
| 332 | while (len) | ||
| 333 | /* skip over whatever is in output buffer */ | ||
| 334 | if (state->have) { | ||
| 335 | n = state->have > len ? (unsigned)len : state->have; | ||
| 336 | state->have -= n; | ||
| 337 | state->next += n; | ||
| 338 | state->pos += n; | ||
| 339 | len -= n; | ||
| 340 | } | ||
| 341 | |||
| 342 | /* output buffer empty -- return if we're at the end of the input */ | ||
| 343 | else if (state->eof && state->strm.avail_in == 0) | ||
| 344 | break; | ||
| 345 | |||
| 346 | /* need more data to skip -- load up output buffer */ | ||
| 347 | else { | ||
| 348 | /* get more output, looking for header if required */ | ||
| 349 | if (gz_make(state) == -1) | ||
| 350 | return -1; | ||
| 351 | } | ||
| 352 | return 0; | ||
| 353 | } | ||
| 354 | |||
| 355 | /* -- see zlib.h -- */ | ||
| 356 | int ZEXPORT gzread(file, buf, len) | ||
| 357 | gzFile file; | ||
| 358 | voidp buf; | ||
| 359 | unsigned len; | ||
| 360 | { | ||
| 361 | unsigned got, n; | ||
| 362 | gz_statep state; | ||
| 363 | z_streamp strm; | ||
| 364 | |||
| 365 | /* get internal structure */ | ||
| 366 | if (file == NULL) | ||
| 367 | return -1; | ||
| 368 | state = (gz_statep)file; | ||
| 369 | strm = &(state->strm); | ||
| 370 | |||
| 371 | /* check that we're reading and that there's no error */ | ||
| 372 | if (state->mode != GZ_READ || state->err != Z_OK) | ||
| 373 | return -1; | ||
| 374 | |||
| 375 | /* process a skip request */ | ||
| 376 | if (state->seek) { | ||
| 377 | state->seek = 0; | ||
| 378 | if (gz_skip(state, state->skip) == -1) | ||
| 379 | return -1; | ||
| 380 | } | ||
| 381 | |||
| 382 | /* get len bytes to buf, or less than len if at the end */ | ||
| 383 | got = 0; | ||
| 384 | while (len) { | ||
| 385 | |||
| 386 | /* first just try copying data from the output buffer */ | ||
| 387 | if (state->have) { | ||
| 388 | n = state->have > len ? len : state->have; | ||
| 389 | memcpy(buf, state->next, n); | ||
| 390 | state->next += n; | ||
| 391 | state->have -= n; | ||
| 392 | } | ||
| 393 | |||
| 394 | /* output buffer empty -- return if we're at the end of the input */ | ||
| 395 | else if (state->eof && strm->avail_in == 0) | ||
| 396 | break; | ||
| 397 | |||
| 398 | /* need output data -- for small len or new stream load up our output | ||
| 399 | buffer */ | ||
| 400 | else if (state->how == 0 || len < (state->size << 1)) { | ||
| 401 | /* get more output, looking for header if required */ | ||
| 402 | if (gz_make(state) == -1) | ||
| 403 | return -1; | ||
| 404 | continue; /* no progress yet -- go back to memcpy() above */ | ||
| 405 | } | ||
| 406 | |||
| 407 | /* large len -- read directly into user buffer */ | ||
| 408 | else if (state->how == 1) { /* read directly */ | ||
| 409 | if (gz_load(state, buf, len, &n) == -1) | ||
| 410 | return -1; | ||
| 411 | } | ||
| 412 | |||
| 413 | /* large len -- decompress directly into user buffer */ | ||
| 414 | else { /* state->how == 2 */ | ||
| 415 | strm->avail_out = len; | ||
| 416 | strm->next_out = buf; | ||
| 417 | if (gz_decomp(state) == -1) | ||
| 418 | return -1; | ||
| 419 | n = state->have; | ||
| 420 | state->have = 0; | ||
| 421 | } | ||
| 422 | |||
| 423 | /* update progress */ | ||
| 424 | len -= n; | ||
| 425 | buf += n; | ||
| 426 | got += n; | ||
| 427 | state->pos += n; | ||
| 428 | } | ||
| 429 | |||
| 430 | /* return number of bytes read into user buffer */ | ||
| 431 | return (int)got; /* len had better fit in int -- interface flaw */ | ||
| 432 | } | ||
| 433 | |||
| 434 | /* -- see zlib.h -- */ | ||
| 435 | int ZEXPORT gzgetc(file) | ||
| 436 | gzFile file; | ||
| 437 | { | ||
| 438 | int ret; | ||
| 439 | unsigned char buf[1]; | ||
| 440 | gz_statep state; | ||
| 441 | |||
| 442 | /* get internal structure */ | ||
| 443 | if (file == NULL) | ||
| 444 | return -1; | ||
| 445 | state = (gz_statep)file; | ||
| 446 | |||
| 447 | /* check that we're reading and that there's no error */ | ||
| 448 | if (state->mode != GZ_READ || state->err != Z_OK) | ||
| 449 | return -1; | ||
| 450 | |||
| 451 | /* try output buffer */ | ||
| 452 | if (state->have) { | ||
| 453 | state->have--; | ||
| 454 | state->pos++; | ||
| 455 | return *(state->next)++; | ||
| 456 | } | ||
| 457 | |||
| 458 | /* nothing there -- try gzread() */ | ||
| 459 | ret = gzread(file, buf, 1); | ||
| 460 | return ret < 1 ? -1 : buf[0]; | ||
| 461 | } | ||
| 462 | |||
| 463 | /* -- see zlib.h -- */ | ||
| 464 | int ZEXPORT gzungetc(c, file) | ||
| 465 | int c; | ||
| 466 | gzFile file; | ||
| 467 | { | ||
| 468 | gz_statep state; | ||
| 469 | |||
| 470 | /* get internal structure */ | ||
| 471 | if (file == NULL) | ||
| 472 | return -1; | ||
| 473 | state = (gz_statep)file; | ||
| 474 | |||
| 475 | /* check that we're reading and that there's no error */ | ||
| 476 | if (state->mode != GZ_READ || state->err != Z_OK) | ||
| 477 | return -1; | ||
| 478 | |||
| 479 | /* process a skip request */ | ||
| 480 | if (state->seek) { | ||
| 481 | state->seek = 0; | ||
| 482 | if (gz_skip(state, state->skip) == -1) | ||
| 483 | return -1; | ||
| 484 | } | ||
| 485 | |||
| 486 | /* can't push EOF */ | ||
| 487 | if (c < 0) | ||
| 488 | return -1; | ||
| 489 | |||
| 490 | /* if output buffer empty, put byte at end (allows more pushing) */ | ||
| 491 | if (state->have == 0) { | ||
| 492 | state->have = 1; | ||
| 493 | state->next = state->out + (state->size << 1) - 1; | ||
| 494 | state->next[0] = c; | ||
| 495 | state->pos--; | ||
| 496 | return c; | ||
| 497 | } | ||
| 498 | |||
| 499 | /* if no room, give up (must have already done a gz_ungetc()) */ | ||
| 500 | if (state->have == (state->size << 1)) | ||
| 501 | return -1; | ||
| 502 | |||
| 503 | /* slide output data if needed and insert byte before existing data */ | ||
| 504 | if (state->next == state->out) { | ||
| 505 | unsigned char *src = state->out + state->have; | ||
| 506 | unsigned char *dest = state->out + (state->size << 1); | ||
| 507 | while (src > state->out) | ||
| 508 | *--dest = *--src; | ||
| 509 | state->next = dest; | ||
| 510 | } | ||
| 511 | state->have++; | ||
| 512 | state->next--; | ||
| 513 | state->next[0] = c; | ||
| 514 | state->pos--; | ||
| 515 | return c; | ||
| 516 | } | ||
| 517 | |||
| 518 | /* -- see zlib.h -- */ | ||
| 519 | char * ZEXPORT gzgets(file, buf, len) | ||
| 520 | gzFile file; | ||
| 521 | char *buf; | ||
| 522 | int len; | ||
| 523 | { | ||
| 524 | unsigned left, n; | ||
| 525 | char *str; | ||
| 526 | unsigned char *eol; | ||
| 527 | gz_statep state; | ||
| 528 | |||
| 529 | /* get internal structure */ | ||
| 530 | if (file == NULL) | ||
| 531 | return NULL; | ||
| 532 | state = (gz_statep)file; | ||
| 533 | |||
| 534 | /* check that we're reading and that there's no error */ | ||
| 535 | if (state->mode != GZ_READ || state->err != Z_OK) | ||
| 536 | return NULL; | ||
| 537 | |||
| 538 | /* process a skip request */ | ||
| 539 | if (state->seek) { | ||
| 540 | state->seek = 0; | ||
| 541 | if (gz_skip(state, state->skip) == -1) | ||
| 542 | return NULL; | ||
| 543 | } | ||
| 544 | |||
| 545 | /* check for a dumb length */ | ||
| 546 | if (len < 2) | ||
| 547 | return NULL; | ||
| 548 | |||
| 549 | /* copy output bytes up to new line or len - 1, whichever comes first -- | ||
| 550 | append a terminating zero to the string (we don't check for a zero in | ||
| 551 | the contents, let the user worry about that) */ | ||
| 552 | str = buf; | ||
| 553 | left = (unsigned)len - 1; | ||
| 554 | do { | ||
| 555 | /* assure that something is in the output buffer */ | ||
| 556 | if (state->have == 0) { | ||
| 557 | if (gz_make(state) == -1) | ||
| 558 | return NULL; /* error */ | ||
| 559 | if (state->have == 0) { /* end of file */ | ||
| 560 | if (buf == str) /* got bupkus */ | ||
| 561 | return NULL; | ||
| 562 | break; /* got something -- return it */ | ||
| 563 | } | ||
| 564 | } | ||
| 565 | |||
| 566 | /* look for end-of-line in current output buffer */ | ||
| 567 | n = state->have > left ? left : state->have; | ||
| 568 | eol = memchr(state->next, '\n', n); | ||
| 569 | if (eol != NULL) | ||
| 570 | n = (eol - state->next) + 1; | ||
| 571 | |||
| 572 | /* copy through end-of-line, or remainder if not found */ | ||
| 573 | memcpy(buf, state->next, n); | ||
| 574 | state->have -= n; | ||
| 575 | state->next += n; | ||
| 576 | state->pos += n; | ||
| 577 | left -= n; | ||
| 578 | buf += n; | ||
| 579 | } while (left && eol == NULL); | ||
| 580 | |||
| 581 | /* found end-of-line or out of space -- terminate string and return it */ | ||
| 582 | buf[0] = 0; | ||
| 583 | return str; | ||
| 584 | } | ||
| 585 | |||
| 586 | /* -- see zlib.h -- */ | ||
| 587 | int ZEXPORT gzdirect(file) | ||
| 588 | gzFile file; | ||
| 589 | { | ||
| 590 | gz_statep state; | ||
| 591 | |||
| 592 | /* get internal structure */ | ||
| 593 | if (file == NULL) | ||
| 594 | return 0; | ||
| 595 | state = (gz_statep)file; | ||
| 596 | |||
| 597 | /* check that we're reading */ | ||
| 598 | if (state->mode != GZ_READ) | ||
| 599 | return 0; | ||
| 600 | |||
| 601 | /* return true if reading without decompression */ | ||
| 602 | return state->how == 1; | ||
| 603 | } | ||
| 604 | |||
| 605 | /* -- see zlib.h -- */ | ||
| 606 | int ZEXPORT gzclose_r(file) | ||
| 607 | gzFile file; | ||
| 608 | { | ||
| 609 | gz_statep state; | ||
| 610 | |||
| 611 | /* get internal structure */ | ||
| 612 | if (file == NULL) | ||
| 613 | return Z_STREAM_ERROR; | ||
| 614 | state = (gz_statep)file; | ||
| 615 | |||
| 616 | /* check that we're reading */ | ||
| 617 | if (state->mode != GZ_READ) | ||
| 618 | return Z_STREAM_ERROR; | ||
| 619 | |||
| 620 | /* free memory and close file */ | ||
| 621 | if (state->size) { | ||
| 622 | inflateEnd(&(state->strm)); | ||
| 623 | free(state->out); | ||
| 624 | free(state->in); | ||
| 625 | } | ||
| 626 | gz_error(state, Z_OK, NULL); | ||
| 627 | close(state->fd); | ||
| 628 | free(state); | ||
| 629 | return Z_OK; | ||
| 630 | } | ||
| 631 | |||
| 632 | #endif /* !OLD_GZIO */ | ||
diff --git a/gzwrite.c b/gzwrite.c new file mode 100644 index 0000000..65a13c3 --- /dev/null +++ b/gzwrite.c | |||
| @@ -0,0 +1,529 @@ | |||
| 1 | /* gzwrite.c -- zlib functions for writing gzip files | ||
| 2 | * Copyright (C) 2004, 2005, 2010 Mark Adler | ||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef OLD_GZIO | ||
| 7 | |||
| 8 | #include "gzguts.h" | ||
| 9 | |||
| 10 | /* Local functions */ | ||
| 11 | local int gz_init OF((gz_statep)); | ||
| 12 | local int gz_comp OF((gz_statep, int)); | ||
| 13 | local int gz_zero OF((gz_statep, z_off_t)); | ||
| 14 | |||
| 15 | /* Initialize state for writing a gzip file. Mark initialization by setting | ||
| 16 | state->size to non-zero. Return -1 on failure or 0 on success. */ | ||
| 17 | local int gz_init(state) | ||
| 18 | gz_statep state; | ||
| 19 | { | ||
| 20 | int ret; | ||
| 21 | z_streamp strm = &(state->strm); | ||
| 22 | |||
| 23 | /* check version of zlib -- need 1.2.1 or later for gzip deflate() */ | ||
| 24 | #ifdef ZLIB_VERNUM | ||
| 25 | if (ZLIB_VERNUM < 0x1210) | ||
| 26 | #endif | ||
| 27 | { | ||
| 28 | gz_error(state, Z_VERSION_ERROR, "need zlib 1.2.1 or later"); | ||
| 29 | return -1; | ||
| 30 | } | ||
| 31 | |||
| 32 | /* allocate input and output buffers */ | ||
| 33 | state->in = malloc(state->want); | ||
| 34 | state->out = malloc(state->want); | ||
| 35 | if (state->in == NULL || state->out == NULL) { | ||
| 36 | if (state->out != NULL) | ||
| 37 | free(state->out); | ||
| 38 | if (state->in != NULL) | ||
| 39 | free(state->in); | ||
| 40 | gz_error(state, Z_MEM_ERROR, "out of memory"); | ||
| 41 | return -1; | ||
| 42 | } | ||
| 43 | |||
| 44 | /* allocate deflate memory, set up for gzip compression */ | ||
| 45 | strm->zalloc = Z_NULL; | ||
| 46 | strm->zfree = Z_NULL; | ||
| 47 | strm->opaque = Z_NULL; | ||
| 48 | ret = deflateInit2(strm, state->level, Z_DEFLATED, | ||
| 49 | 15 + 16, 8, state->strategy); | ||
| 50 | if (ret != Z_OK) { | ||
| 51 | free(state->in); | ||
| 52 | gz_error(state, Z_MEM_ERROR, "out of memory"); | ||
| 53 | return -1; | ||
| 54 | } | ||
| 55 | |||
| 56 | /* mark state as initialized */ | ||
| 57 | state->size = state->want; | ||
| 58 | |||
| 59 | /* initialize write buffer */ | ||
| 60 | strm->avail_out = state->size; | ||
| 61 | strm->next_out = state->out; | ||
| 62 | state->next = strm->next_out; | ||
| 63 | return 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | /* Compress whatever is at avail_in and next_in and write to the output file. | ||
| 67 | Return -1 if there is an error writing to the output file, otherwise 0. | ||
| 68 | flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, | ||
| 69 | then the deflate() state is reset to start a new gzip stream. */ | ||
| 70 | local int gz_comp(state, flush) | ||
| 71 | gz_statep state; | ||
| 72 | int flush; | ||
| 73 | { | ||
| 74 | int ret; | ||
| 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 | /* run deflate() on provided input until it produces no more output */ | ||
| 83 | ret = Z_OK; | ||
| 84 | do { | ||
| 85 | /* write out current buffer contents if full, or if flushing, but if | ||
| 86 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ | ||
| 87 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && | ||
| 88 | (flush != Z_FINISH || ret == Z_STREAM_END))) { | ||
| 89 | have = strm->next_out - state->next; | ||
| 90 | if (have && write(state->fd, state->next, have) != have) { | ||
| 91 | gz_error(state, Z_ERRNO, zstrerror()); | ||
| 92 | return -1; | ||
| 93 | } | ||
| 94 | if (strm->avail_out == 0) { | ||
| 95 | strm->avail_out = state->size; | ||
| 96 | strm->next_out = state->out; | ||
| 97 | } | ||
| 98 | state->next = strm->next_out; | ||
| 99 | } | ||
| 100 | |||
| 101 | /* compress */ | ||
| 102 | have = strm->avail_out; | ||
| 103 | ret = deflate(strm, flush); | ||
| 104 | if (ret == Z_STREAM_ERROR) { | ||
| 105 | gz_error(state, Z_STREAM_ERROR, | ||
| 106 | "internal error: deflate stream corrupt"); | ||
| 107 | return -1; | ||
| 108 | } | ||
| 109 | have -= strm->avail_out; | ||
| 110 | } while (have); | ||
| 111 | |||
| 112 | /* if that completed a deflate stream, allow another to start */ | ||
| 113 | if (flush == Z_FINISH) | ||
| 114 | deflateReset(strm); | ||
| 115 | |||
| 116 | /* all done, no errors */ | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* Compress len zeros to output. Return -1 on error, 0 on success. */ | ||
| 121 | local int gz_zero(state, len) | ||
| 122 | gz_statep state; | ||
| 123 | z_off_t len; | ||
| 124 | { | ||
| 125 | int first; | ||
| 126 | unsigned n; | ||
| 127 | z_streamp strm = &(state->strm); | ||
| 128 | |||
| 129 | /* consume whatever's left in the input buffer */ | ||
| 130 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 131 | return -1; | ||
| 132 | |||
| 133 | /* compress len zeros */ | ||
| 134 | first = 1; | ||
| 135 | while (len) { | ||
| 136 | n = len < state->size ? (unsigned)len : state->size; | ||
| 137 | if (first) { | ||
| 138 | memset(state->in, 0, n); | ||
| 139 | first = 0; | ||
| 140 | } | ||
| 141 | strm->avail_in = n; | ||
| 142 | strm->next_in = state->in; | ||
| 143 | state->pos += n; | ||
| 144 | if (gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 145 | return -1; | ||
| 146 | len -= n; | ||
| 147 | } | ||
| 148 | return 0; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* -- see zlib.h -- */ | ||
| 152 | int ZEXPORT gzwrite(file, buf, len) | ||
| 153 | gzFile file; | ||
| 154 | voidpc buf; | ||
| 155 | unsigned len; | ||
| 156 | { | ||
| 157 | unsigned put = len; | ||
| 158 | unsigned n; | ||
| 159 | gz_statep state; | ||
| 160 | z_streamp strm; | ||
| 161 | |||
| 162 | /* get internal structure */ | ||
| 163 | if (file == NULL) | ||
| 164 | return -1; | ||
| 165 | state = (gz_statep)file; | ||
| 166 | strm = &(state->strm); | ||
| 167 | |||
| 168 | /* check that we're writing and that there's no error */ | ||
| 169 | if (state->mode != GZ_WRITE || state->err != Z_OK) | ||
| 170 | return -1; | ||
| 171 | |||
| 172 | /* allocate memory if this is the first time through */ | ||
| 173 | if (state->size == 0 && gz_init(state) == -1) | ||
| 174 | return -1; | ||
| 175 | |||
| 176 | /* check for seek request */ | ||
| 177 | if (state->seek) { | ||
| 178 | state->seek = 0; | ||
| 179 | if (gz_zero(state, state->skip) == -1) | ||
| 180 | return -1; | ||
| 181 | } | ||
| 182 | |||
| 183 | /* for small len, copy to input buffer, otherwise compress directly */ | ||
| 184 | if (len < state->size) { | ||
| 185 | /* copy to input buffer, compress when full */ | ||
| 186 | while (len) { | ||
| 187 | if (strm->avail_in == 0) | ||
| 188 | strm->next_in = state->in; | ||
| 189 | n = state->size - strm->avail_in; | ||
| 190 | if (n > len) | ||
| 191 | n = len; | ||
| 192 | memcpy(strm->next_in + strm->avail_in, buf, n); | ||
| 193 | strm->avail_in += n; | ||
| 194 | state->pos += n; | ||
| 195 | buf += n; | ||
| 196 | len -= n; | ||
| 197 | if (len && gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 198 | return -1; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | else { | ||
| 202 | /* consume whatever's left in the input buffer */ | ||
| 203 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 204 | return -1; | ||
| 205 | |||
| 206 | /* directly compress user buffer to file */ | ||
| 207 | strm->avail_in = len; | ||
| 208 | strm->next_in = (voidp)buf; | ||
| 209 | state->pos += len; | ||
| 210 | if (gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 211 | return -1; | ||
| 212 | } | ||
| 213 | |||
| 214 | /* input was all buffered or compressed */ | ||
| 215 | return (int)put; | ||
| 216 | } | ||
| 217 | |||
| 218 | /* -- see zlib.h -- */ | ||
| 219 | int ZEXPORT gzputc(file, c) | ||
| 220 | gzFile file; | ||
| 221 | int c; | ||
| 222 | { | ||
| 223 | unsigned char buf[1]; | ||
| 224 | gz_statep state; | ||
| 225 | z_streamp strm; | ||
| 226 | |||
| 227 | /* get internal structure */ | ||
| 228 | if (file == NULL) | ||
| 229 | return -1; | ||
| 230 | state = (gz_statep)file; | ||
| 231 | strm = &(state->strm); | ||
| 232 | |||
| 233 | /* check that we're writing and that there's no error */ | ||
| 234 | if (state->mode != GZ_WRITE || state->err != Z_OK) | ||
| 235 | return -1; | ||
| 236 | |||
| 237 | /* check for seek request */ | ||
| 238 | if (state->seek) { | ||
| 239 | state->seek = 0; | ||
| 240 | if (gz_zero(state, state->skip) == -1) | ||
| 241 | return -1; | ||
| 242 | } | ||
| 243 | |||
| 244 | /* try writing to input buffer for speed (state->size == 0 if buffer not | ||
| 245 | initialized) */ | ||
| 246 | if (strm->avail_in < state->size) { | ||
| 247 | if (strm->avail_in == 0) | ||
| 248 | strm->next_in = state->in; | ||
| 249 | strm->next_in[strm->avail_in++] = c; | ||
| 250 | state->pos++; | ||
| 251 | return c; | ||
| 252 | } | ||
| 253 | |||
| 254 | /* no room in buffer or not initialized, use gz_write() */ | ||
| 255 | buf[0] = c; | ||
| 256 | if (gzwrite(file, buf, 1) != 1) | ||
| 257 | return -1; | ||
| 258 | return c; | ||
| 259 | } | ||
| 260 | |||
| 261 | /* -- see zlib.h -- */ | ||
| 262 | int ZEXPORT gzputs(file, str) | ||
| 263 | gzFile file; | ||
| 264 | const char *str; | ||
| 265 | { | ||
| 266 | /* write string */ | ||
| 267 | return gzwrite(file, str, strlen(str)); | ||
| 268 | } | ||
| 269 | |||
| 270 | #ifdef STDC | ||
| 271 | #include <stdarg.h> | ||
| 272 | |||
| 273 | /* -- see zlib.h -- */ | ||
| 274 | int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) | ||
| 275 | { | ||
| 276 | int size, len; | ||
| 277 | gz_statep state; | ||
| 278 | z_streamp strm; | ||
| 279 | va_list va; | ||
| 280 | |||
| 281 | /* get internal structure */ | ||
| 282 | if (file == NULL) | ||
| 283 | return -1; | ||
| 284 | state = (gz_statep)file; | ||
| 285 | strm = &(state->strm); | ||
| 286 | |||
| 287 | /* check that we're writing and that there's no error */ | ||
| 288 | if (state->mode != GZ_WRITE || state->err != Z_OK) | ||
| 289 | return 0; | ||
| 290 | |||
| 291 | /* make sure we have some buffer space */ | ||
| 292 | if (state->size == 0 && gz_init(state) == -1) | ||
| 293 | return 0; | ||
| 294 | |||
| 295 | /* check for seek request */ | ||
| 296 | if (state->seek) { | ||
| 297 | state->seek = 0; | ||
| 298 | if (gz_zero(state, state->skip) == -1) | ||
| 299 | return 0; | ||
| 300 | } | ||
| 301 | |||
| 302 | /* consume whatever's left in the input buffer */ | ||
| 303 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 304 | return 0; | ||
| 305 | |||
| 306 | /* do the printf() into the input buffer, put length in len */ | ||
| 307 | size = (int)(state->size); | ||
| 308 | state->in[size - 1] = 0; | ||
| 309 | va_start(va, format); | ||
| 310 | #ifdef NO_vsnprintf | ||
| 311 | # ifdef HAS_vsprintf_void | ||
| 312 | (void)vsprintf(state->in, format, va); | ||
| 313 | va_end(va); | ||
| 314 | for (len = 0; len < state->in; len++) | ||
| 315 | if (state->in[len] == 0) break; | ||
| 316 | # else | ||
| 317 | len = vsprintf(state->in, format, va); | ||
| 318 | va_end(va); | ||
| 319 | # endif | ||
| 320 | #else | ||
| 321 | # ifdef HAS_vsnprintf_void | ||
| 322 | (void)vsnprintf(state->in, size, format, va); | ||
| 323 | va_end(va); | ||
| 324 | len = strlen(state->in); | ||
| 325 | # else | ||
| 326 | len = vsnprintf((char *)(state->in), size, format, va); | ||
| 327 | va_end(va); | ||
| 328 | # endif | ||
| 329 | #endif | ||
| 330 | |||
| 331 | /* check that printf() results fit in buffer */ | ||
| 332 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) | ||
| 333 | return 0; | ||
| 334 | |||
| 335 | /* write out result of printf() */ | ||
| 336 | strm->avail_in = (unsigned)len; | ||
| 337 | strm->next_in = state->in; | ||
| 338 | state->pos += len; | ||
| 339 | if (gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 340 | return 0; | ||
| 341 | return len; | ||
| 342 | } | ||
| 343 | |||
| 344 | #else /* !STDC */ | ||
| 345 | |||
| 346 | /* -- see zlib.h -- */ | ||
| 347 | int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | ||
| 348 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) | ||
| 349 | gzFile file; | ||
| 350 | const char *format; | ||
| 351 | int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, | ||
| 352 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; | ||
| 353 | { | ||
| 354 | int size, len; | ||
| 355 | gz_statep state; | ||
| 356 | z_streamp strm; | ||
| 357 | |||
| 358 | /* get internal structure */ | ||
| 359 | if (file == NULL) | ||
| 360 | return -1; | ||
| 361 | state = (gz_statep)file; | ||
| 362 | strm = &(state->strm); | ||
| 363 | |||
| 364 | /* check that we're writing and that there's no error */ | ||
| 365 | if (state->mode != GZ_WRITE || state->err != Z_OK) | ||
| 366 | return 0; | ||
| 367 | |||
| 368 | /* make sure we have some buffer space */ | ||
| 369 | if (state->size == 0 && gz_init(state) == -1) | ||
| 370 | return 0; | ||
| 371 | |||
| 372 | /* check for seek request */ | ||
| 373 | if (state->seek) { | ||
| 374 | state->seek = 0; | ||
| 375 | if (gz_zero(state, state->skip) == -1) | ||
| 376 | return 0; | ||
| 377 | } | ||
| 378 | |||
| 379 | /* consume whatever's left in the input buffer */ | ||
| 380 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 381 | return 0; | ||
| 382 | |||
| 383 | /* do the printf() into the input buffer, put length in len */ | ||
| 384 | size = (int)(state->size); | ||
| 385 | state->in[size - 1] = 0; | ||
| 386 | #ifdef NO_snprintf | ||
| 387 | # ifdef HAS_sprintf_void | ||
| 388 | sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
| 389 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
| 390 | for (len = 0; len < size; len++) | ||
| 391 | if (state->in[len] == 0) break; | ||
| 392 | # else | ||
| 393 | len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
| 394 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
| 395 | # endif | ||
| 396 | #else | ||
| 397 | # ifdef HAS_snprintf_void | ||
| 398 | snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
| 399 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
| 400 | len = strlen(state->in); | ||
| 401 | # else | ||
| 402 | len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, | ||
| 403 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | ||
| 404 | # endif | ||
| 405 | #endif | ||
| 406 | |||
| 407 | /* check that printf() results fit in buffer */ | ||
| 408 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) | ||
| 409 | return 0; | ||
| 410 | |||
| 411 | /* write out result of printf() */ | ||
| 412 | strm->avail_in = (unsigned)len; | ||
| 413 | strm->next_in = state->in; | ||
| 414 | state->pos += len; | ||
| 415 | if (gz_comp(state, Z_NO_FLUSH) == -1) | ||
| 416 | return 0; | ||
| 417 | return len; | ||
| 418 | } | ||
| 419 | |||
| 420 | #endif | ||
| 421 | |||
| 422 | /* -- see zlib.h -- */ | ||
| 423 | int ZEXPORT gzflush(file, flush) | ||
| 424 | gzFile file; | ||
| 425 | int flush; | ||
| 426 | { | ||
| 427 | gz_statep state; | ||
| 428 | |||
| 429 | /* get internal structure */ | ||
| 430 | if (file == NULL) | ||
| 431 | return -1; | ||
| 432 | state = (gz_statep)file; | ||
| 433 | |||
| 434 | /* check that we're writing and that there's no error */ | ||
| 435 | if (state->mode != GZ_WRITE|| state->err != Z_OK) | ||
| 436 | |||
| 437 | /* check flush parameter */ | ||
| 438 | if (flush < 0 || flush > Z_FINISH) | ||
| 439 | return Z_STREAM_ERROR; | ||
| 440 | |||
| 441 | /* check for seek request */ | ||
| 442 | if (state->seek) { | ||
| 443 | state->seek = 0; | ||
| 444 | if (gz_zero(state, state->skip) == -1) | ||
| 445 | return -1; | ||
| 446 | } | ||
| 447 | |||
| 448 | /* compress remaining data with requested flush */ | ||
| 449 | gz_comp(state, flush); | ||
| 450 | return state->err; | ||
| 451 | } | ||
| 452 | |||
| 453 | /* -- see zlib.h -- */ | ||
| 454 | int ZEXPORT gzsetparams(file, level, strategy) | ||
| 455 | gzFile file; | ||
| 456 | int level; | ||
| 457 | int strategy; | ||
| 458 | { | ||
| 459 | gz_statep state; | ||
| 460 | z_streamp strm; | ||
| 461 | |||
| 462 | /* get internal structure */ | ||
| 463 | if (file == NULL) | ||
| 464 | return Z_STREAM_ERROR; | ||
| 465 | state = (gz_statep)file; | ||
| 466 | strm = &(state->strm); | ||
| 467 | |||
| 468 | /* check that we're writing and that there's no error */ | ||
| 469 | if (state->mode != GZ_WRITE || state->err != Z_OK) | ||
| 470 | return Z_STREAM_ERROR; | ||
| 471 | |||
| 472 | /* if no change is requested, then do nothing */ | ||
| 473 | if (level == state->level && strategy == state->strategy) | ||
| 474 | return Z_OK; | ||
| 475 | |||
| 476 | /* check for seek request */ | ||
| 477 | if (state->seek) { | ||
| 478 | state->seek = 0; | ||
| 479 | if (gz_zero(state, state->skip) == -1) | ||
| 480 | return -1; | ||
| 481 | } | ||
| 482 | |||
| 483 | /* change compression parameters for subsequent input */ | ||
| 484 | if (state->size) { | ||
| 485 | /* flush previous input with previous parameters before changing */ | ||
| 486 | if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) | ||
| 487 | return state->err; | ||
| 488 | deflateParams(strm, level, strategy); | ||
| 489 | } | ||
| 490 | state->level = level; | ||
| 491 | state->strategy = strategy; | ||
| 492 | return Z_OK; | ||
| 493 | } | ||
| 494 | |||
| 495 | /* -- see zlib.h -- */ | ||
| 496 | int ZEXPORT gzclose_w(file) | ||
| 497 | gzFile file; | ||
| 498 | { | ||
| 499 | int ret; | ||
| 500 | gz_statep state; | ||
| 501 | |||
| 502 | /* get internal structure */ | ||
| 503 | if (file == NULL) | ||
| 504 | return Z_STREAM_ERROR; | ||
| 505 | state = (gz_statep)file; | ||
| 506 | |||
| 507 | /* check that we're writing */ | ||
| 508 | if (state->mode != GZ_WRITE) | ||
| 509 | return Z_STREAM_ERROR; | ||
| 510 | |||
| 511 | /* check for seek request */ | ||
| 512 | if (state->seek) { | ||
| 513 | state->seek = 0; | ||
| 514 | if (gz_zero(state, state->skip) == -1) | ||
| 515 | return -1; | ||
| 516 | } | ||
| 517 | |||
| 518 | /* flush, free memory, and close file */ | ||
| 519 | ret = gz_comp(state, Z_FINISH); | ||
| 520 | deflateEnd(&(state->strm)); | ||
| 521 | free(state->out); | ||
| 522 | free(state->in); | ||
| 523 | ret += close(state->fd); | ||
| 524 | gz_error(state, Z_OK, NULL); | ||
| 525 | free(state); | ||
| 526 | return ret ? Z_ERRNO : Z_OK; | ||
| 527 | } | ||
| 528 | |||
| 529 | #endif /* !OLD_GZIO */ | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* infback.c -- inflate using a call-back interface | 1 | /* infback.c -- inflate using a call-back interface |
| 2 | * Copyright (C) 1995-2008 Mark Adler | 2 | * Copyright (C) 1995-2009 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -55,7 +55,7 @@ int stream_size; | |||
| 55 | state->wbits = windowBits; | 55 | state->wbits = windowBits; |
| 56 | state->wsize = 1U << windowBits; | 56 | state->wsize = 1U << windowBits; |
| 57 | state->window = window; | 57 | state->window = window; |
| 58 | state->write = 0; | 58 | state->wnext = 0; |
| 59 | state->whave = 0; | 59 | state->whave = 0; |
| 60 | return Z_OK; | 60 | return Z_OK; |
| 61 | } | 61 | } |
| @@ -79,7 +79,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 79 | #endif | 79 | #endif |
| 80 | unsigned wsize; /* window size or zero if not using window */ | 80 | unsigned wsize; /* window size or zero if not using window */ |
| 81 | unsigned whave; /* valid bytes in the window */ | 81 | unsigned whave; /* valid bytes in the window */ |
| 82 | unsigned write; /* window write index */ | 82 | unsigned wnext; /* window write index */ |
| 83 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ | 83 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ |
| 84 | unsigned long hold; /* local strm->hold */ | 84 | unsigned long hold; /* local strm->hold */ |
| 85 | unsigned bits; /* local strm->bits */ | 85 | unsigned bits; /* local strm->bits */ |
| @@ -106,7 +106,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 106 | #endif | 106 | #endif |
| 107 | wsize = state->wsize; | 107 | wsize = state->wsize; |
| 108 | whave = state->whave; | 108 | whave = state->whave; |
| 109 | write = state->write; | 109 | wnext = state->wnext; |
| 110 | window = state->window; | 110 | window = state->window; |
| 111 | hold = state->hold; | 111 | hold = state->hold; |
| 112 | bits = state->bits; | 112 | bits = state->bits; |
| @@ -214,7 +214,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 214 | #endif | 214 | #endif |
| 215 | } | 215 | } |
| 216 | from = window - OFF; | 216 | from = window - OFF; |
| 217 | if (write == 0) { /* very common case */ | 217 | if (wnext == 0) { /* very common case */ |
| 218 | from += wsize - op; | 218 | from += wsize - op; |
| 219 | if (op < len) { /* some from window */ | 219 | if (op < len) { /* some from window */ |
| 220 | len -= op; | 220 | len -= op; |
| @@ -224,17 +224,17 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 224 | from = out - dist; /* rest from output */ | 224 | from = out - dist; /* rest from output */ |
| 225 | } | 225 | } |
| 226 | } | 226 | } |
| 227 | else if (write < op) { /* wrap around window */ | 227 | else if (wnext < op) { /* wrap around window */ |
| 228 | from += wsize + write - op; | 228 | from += wsize + wnext - op; |
| 229 | op -= write; | 229 | op -= wnext; |
| 230 | if (op < len) { /* some from end of window */ | 230 | if (op < len) { /* some from end of window */ |
| 231 | len -= op; | 231 | len -= op; |
| 232 | do { | 232 | do { |
| 233 | PUP(out) = PUP(from); | 233 | PUP(out) = PUP(from); |
| 234 | } while (--op); | 234 | } while (--op); |
| 235 | from = window - OFF; | 235 | from = window - OFF; |
| 236 | if (write < len) { /* some from start of window */ | 236 | if (wnext < len) { /* some from start of window */ |
| 237 | op = write; | 237 | op = wnext; |
| 238 | len -= op; | 238 | len -= op; |
| 239 | do { | 239 | do { |
| 240 | PUP(out) = PUP(from); | 240 | PUP(out) = PUP(from); |
| @@ -244,7 +244,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 244 | } | 244 | } |
| 245 | } | 245 | } |
| 246 | else { /* contiguous in window */ | 246 | else { /* contiguous in window */ |
| 247 | from += write - op; | 247 | from += wnext - op; |
| 248 | if (op < len) { /* some from window */ | 248 | if (op < len) { /* some from window */ |
| 249 | len -= op; | 249 | len -= op; |
| 250 | do { | 250 | do { |
| @@ -327,7 +327,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */ | |||
| 327 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): | 327 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): |
| 328 | - Using bit fields for code structure | 328 | - Using bit fields for code structure |
| 329 | - Different op definition to avoid & for extra bits (do & for table bits) | 329 | - Different op definition to avoid & for extra bits (do & for table bits) |
| 330 | - Three separate decoding do-loops for direct, window, and write == 0 | 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 | 331 | - Special case for distance > 1 copies to do overlapped load and store copy |
| 332 | - Explicit branch predictions (based on measured branch probabilities) | 332 | - Explicit branch predictions (based on measured branch probabilities) |
| 333 | - Deferring match copy and interspersed it with decoding subsequent codes | 333 | - Deferring match copy and interspersed it with decoding subsequent codes |
| @@ -45,7 +45,7 @@ | |||
| 45 | * - Rearrange window copies in inflate_fast() for speed and simplification | 45 | * - Rearrange window copies in inflate_fast() for speed and simplification |
| 46 | * - Unroll last copy for window match in inflate_fast() | 46 | * - Unroll last copy for window match in inflate_fast() |
| 47 | * - Use local copies of window variables in inflate_fast() for speed | 47 | * - Use local copies of window variables in inflate_fast() for speed |
| 48 | * - Pull out common write == 0 case for speed in inflate_fast() | 48 | * - Pull out common wnext == 0 case for speed in inflate_fast() |
| 49 | * - Make op and len in inflate_fast() unsigned for consistency | 49 | * - Make op and len in inflate_fast() unsigned for consistency |
| 50 | * - Add FAR to lcode and dcode declarations in inflate_fast() | 50 | * - Add FAR to lcode and dcode declarations in inflate_fast() |
| 51 | * - Simplified bad distance check in inflate_fast() | 51 | * - Simplified bad distance check in inflate_fast() |
| @@ -117,7 +117,7 @@ z_streamp strm; | |||
| 117 | state->head = Z_NULL; | 117 | state->head = Z_NULL; |
| 118 | state->wsize = 0; | 118 | state->wsize = 0; |
| 119 | state->whave = 0; | 119 | state->whave = 0; |
| 120 | state->write = 0; | 120 | state->wnext = 0; |
| 121 | state->hold = 0; | 121 | state->hold = 0; |
| 122 | state->bits = 0; | 122 | state->bits = 0; |
| 123 | state->lencode = state->distcode = state->next = state->codes; | 123 | state->lencode = state->distcode = state->next = state->codes; |
| @@ -152,7 +152,7 @@ int windowBits; | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | /* set number of window bits, free window if different */ | 154 | /* set number of window bits, free window if different */ |
| 155 | if (windowBits < 8 || windowBits > 15) | 155 | if (windowBits && (windowBits < 8 || windowBits > 15)) |
| 156 | return Z_STREAM_ERROR; | 156 | return Z_STREAM_ERROR; |
| 157 | if (state->wbits != windowBits && state->window != Z_NULL) { | 157 | if (state->wbits != windowBits && state->window != Z_NULL) { |
| 158 | ZFREE(strm, state->window); | 158 | ZFREE(strm, state->window); |
| @@ -375,7 +375,7 @@ unsigned out; | |||
| 375 | /* if window not in use yet, initialize */ | 375 | /* if window not in use yet, initialize */ |
| 376 | if (state->wsize == 0) { | 376 | if (state->wsize == 0) { |
| 377 | state->wsize = 1U << state->wbits; | 377 | state->wsize = 1U << state->wbits; |
| 378 | state->write = 0; | 378 | state->wnext = 0; |
| 379 | state->whave = 0; | 379 | state->whave = 0; |
| 380 | } | 380 | } |
| 381 | 381 | ||
| @@ -383,22 +383,22 @@ unsigned out; | |||
| 383 | copy = out - strm->avail_out; | 383 | copy = out - strm->avail_out; |
| 384 | if (copy >= state->wsize) { | 384 | if (copy >= state->wsize) { |
| 385 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); | 385 | zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); |
| 386 | state->write = 0; | 386 | state->wnext = 0; |
| 387 | state->whave = state->wsize; | 387 | state->whave = state->wsize; |
| 388 | } | 388 | } |
| 389 | else { | 389 | else { |
| 390 | dist = state->wsize - state->write; | 390 | dist = state->wsize - state->wnext; |
| 391 | if (dist > copy) dist = copy; | 391 | if (dist > copy) dist = copy; |
| 392 | zmemcpy(state->window + state->write, strm->next_out - copy, dist); | 392 | zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); |
| 393 | copy -= dist; | 393 | copy -= dist; |
| 394 | if (copy) { | 394 | if (copy) { |
| 395 | zmemcpy(state->window, strm->next_out - copy, copy); | 395 | zmemcpy(state->window, strm->next_out - copy, copy); |
| 396 | state->write = copy; | 396 | state->wnext = copy; |
| 397 | state->whave = state->wsize; | 397 | state->whave = state->wsize; |
| 398 | } | 398 | } |
| 399 | else { | 399 | else { |
| 400 | state->write += dist; | 400 | state->wnext += dist; |
| 401 | if (state->write == state->wsize) state->write = 0; | 401 | if (state->wnext == state->wsize) state->wnext = 0; |
| 402 | if (state->whave < state->wsize) state->whave += dist; | 402 | if (state->whave < state->wsize) state->whave += dist; |
| 403 | } | 403 | } |
| 404 | } | 404 | } |
| @@ -654,7 +654,9 @@ int flush; | |||
| 654 | } | 654 | } |
| 655 | DROPBITS(4); | 655 | DROPBITS(4); |
| 656 | len = BITS(4) + 8; | 656 | len = BITS(4) + 8; |
| 657 | if (len > state->wbits) { | 657 | if (state->wbits == 0) |
| 658 | state->wbits = len; | ||
| 659 | else if (len > state->wbits) { | ||
| 658 | strm->msg = (char *)"invalid window size"; | 660 | strm->msg = (char *)"invalid window size"; |
| 659 | state->mode = BAD; | 661 | state->mode = BAD; |
| 660 | break; | 662 | break; |
| @@ -1128,15 +1130,12 @@ int flush; | |||
| 1128 | break; | 1130 | break; |
| 1129 | #endif | 1131 | #endif |
| 1130 | } | 1132 | } |
| 1131 | if (copy > state->write) { | 1133 | if (copy > state->wnext) { |
| 1132 | copy -= state->write; | 1134 | copy -= state->wnext; |
| 1133 | /* %% problem here if copy > state->wsize -- avoid? */ | ||
| 1134 | /* %% or can (state->window + state->wsize) - copy */ | ||
| 1135 | /* %% but really should detect and reject this case */ | ||
| 1136 | from = state->window + (state->wsize - copy); | 1135 | from = state->window + (state->wsize - copy); |
| 1137 | } | 1136 | } |
| 1138 | else | 1137 | else |
| 1139 | from = state->window + (state->write - copy); | 1138 | from = state->window + (state->wnext - copy); |
| 1140 | if (copy > state->length) copy = state->length; | 1139 | if (copy > state->length) copy = state->length; |
| 1141 | } | 1140 | } |
| 1142 | else { /* copy from output */ | 1141 | else { /* copy from output */ |
| @@ -92,7 +92,7 @@ struct inflate_state { | |||
| 92 | unsigned wbits; /* log base 2 of requested window size */ | 92 | unsigned wbits; /* log base 2 of requested window size */ |
| 93 | unsigned wsize; /* window size or zero if not using window */ | 93 | unsigned wsize; /* window size or zero if not using window */ |
| 94 | unsigned whave; /* valid bytes in the window */ | 94 | unsigned whave; /* valid bytes in the window */ |
| 95 | unsigned write; /* window write index */ | 95 | unsigned wnext; /* window write index */ |
| 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ | 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ |
| 97 | /* bit accumulator */ | 97 | /* bit accumulator */ |
| 98 | unsigned long hold; /* input bit accumulator */ | 98 | unsigned long hold; /* input bit accumulator */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* inftrees.c -- generate Huffman trees for efficient decoding | 1 | /* inftrees.c -- generate Huffman trees for efficient decoding |
| 2 | * Copyright (C) 1995-2009 Mark Adler | 2 | * Copyright (C) 1995-2010 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define MAXBITS 15 | 9 | #define MAXBITS 15 |
| 10 | 10 | ||
| 11 | const char inflate_copyright[] = | 11 | const char inflate_copyright[] = |
| 12 | " inflate 1.2.3.4 Copyright 1995-2008 Mark Adler "; | 12 | " inflate 1.2.3.5 Copyright 1995-2010 Mark Adler "; |
| 13 | /* | 13 | /* |
| 14 | If you use the zlib library in a product, an acknowledgment is welcome | 14 | If you use the zlib library in a product, an acknowledgment is welcome |
| 15 | in the documentation of your product. If for some reason you cannot | 15 | in the documentation of your product. If for some reason you cannot |
| @@ -62,7 +62,7 @@ unsigned short FAR *work; | |||
| 62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; | 62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; |
| 63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | 63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
| 64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, | 64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, |
| 65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 200}; | 65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 69, 199}; |
| 66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ | 66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ |
| 67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, | 67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
| 68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, | 68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
diff --git a/make_vms.com b/make_vms.com index 87c480a..e3e8740 100644 --- a/make_vms.com +++ b/make_vms.com | |||
| @@ -85,8 +85,16 @@ $ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - | |||
| 85 | crc32.c zlib.h zconf.h zlibdefs.h | 85 | crc32.c zlib.h zconf.h zlibdefs.h |
| 86 | $ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - | 86 | $ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - |
| 87 | deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h | 87 | deflate.c deflate.h zutil.h zlib.h zconf.h zlibdefs.h |
| 88 | $ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - | ||
| 89 | gzclose.c zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 88 | $ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" - | 90 | $ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" - |
| 89 | gzio.c zutil.h zlib.h zconf.h zlibdefs.h | 91 | gzio.c zutil.h zlib.h zconf.h zlibdefs.h |
| 92 | $ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - | ||
| 93 | gzlib.c zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 94 | $ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - | ||
| 95 | gzread.c zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 96 | $ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - | ||
| 97 | gzwrite.c zlib.h zconf.h zlibdefs.h gzguts.h | ||
| 90 | $ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - | 98 | $ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - |
| 91 | infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h | 99 | infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h |
| 92 | $ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - | 100 | $ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* minigzip.c -- simulate gzip using the zlib compression library | 1 | /* minigzip.c -- simulate gzip using the zlib compression library |
| 2 | * Copyright (C) 1995-2006 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2006, 2010 Jean-loup Gailly. |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -54,6 +54,70 @@ | |||
| 54 | extern int unlink OF((const char *)); | 54 | extern int unlink OF((const char *)); |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | #if defined(UNDER_CE) && defined(NO_ERRNO_H) | ||
| 58 | # include <windows.h> | ||
| 59 | # define perror(s) pwinerror(s) | ||
| 60 | |||
| 61 | /* Map the Windows error number in ERROR to a locale-dependent error | ||
| 62 | message string and return a pointer to it. Typically, the values | ||
| 63 | for ERROR come from GetLastError. | ||
| 64 | |||
| 65 | The string pointed to shall not be modified by the application, | ||
| 66 | but may be overwritten by a subsequent call to strwinerror | ||
| 67 | |||
| 68 | The strwinerror function does not change the current setting | ||
| 69 | of GetLastError. */ | ||
| 70 | |||
| 71 | static char *strwinerror (error) | ||
| 72 | DWORD error; | ||
| 73 | { | ||
| 74 | static char buf[1024]; | ||
| 75 | |||
| 76 | wchar_t *msgbuf; | ||
| 77 | DWORD lasterr = GetLastError(); | ||
| 78 | DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | ||
| 79 | | FORMAT_MESSAGE_ALLOCATE_BUFFER, | ||
| 80 | NULL, | ||
| 81 | error, | ||
| 82 | 0, /* Default language */ | ||
| 83 | (LPVOID)&msgbuf, | ||
| 84 | 0, | ||
| 85 | NULL); | ||
| 86 | if (chars != 0) { | ||
| 87 | /* If there is an \r\n appended, zap it. */ | ||
| 88 | if (chars >= 2 | ||
| 89 | && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { | ||
| 90 | chars -= 2; | ||
| 91 | msgbuf[chars] = 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (chars > sizeof (buf) - 1) { | ||
| 95 | chars = sizeof (buf) - 1; | ||
| 96 | msgbuf[chars] = 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | wcstombs(buf, msgbuf, chars + 1); | ||
| 100 | LocalFree(msgbuf); | ||
| 101 | } | ||
| 102 | else { | ||
| 103 | sprintf(buf, "unknown win32 error (%ld)", error); | ||
| 104 | } | ||
| 105 | |||
| 106 | SetLastError(lasterr); | ||
| 107 | return buf; | ||
| 108 | } | ||
| 109 | |||
| 110 | static void pwinerror (s) | ||
| 111 | const char *s; | ||
| 112 | { | ||
| 113 | if (s && *s) | ||
| 114 | fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ())); | ||
| 115 | else | ||
| 116 | fprintf(stderr, "%s\n", strwinerror(GetLastError ())); | ||
| 117 | } | ||
| 118 | |||
| 119 | #endif /* UNDER_CE && NO_ERRNO_H */ | ||
| 120 | |||
| 57 | #ifndef GZ_SUFFIX | 121 | #ifndef GZ_SUFFIX |
| 58 | # define GZ_SUFFIX ".gz" | 122 | # define GZ_SUFFIX ".gz" |
| 59 | #endif | 123 | #endif |
diff --git a/msdos/Makefile.bor b/msdos/Makefile.bor index 8f8132d..328f5a7 100644 --- a/msdos/Makefile.bor +++ b/msdos/Makefile.bor | |||
| @@ -41,10 +41,10 @@ LDFLAGS=-m$(MODEL) -f- | |||
| 41 | # variables | 41 | # variables |
| 42 | ZLIB_LIB = zlib_$(MODEL).lib | 42 | ZLIB_LIB = zlib_$(MODEL).lib |
| 43 | 43 | ||
| 44 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 44 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 45 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.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+gzio.obj+infback.obj | 46 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj |
| 47 | OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj | 47 | OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | # targets | 50 | # targets |
| @@ -61,8 +61,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 61 | 61 | ||
| 62 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 62 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 63 | 63 | ||
| 64 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 65 | |||
| 64 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 66 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 65 | 67 | ||
| 68 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 69 | |||
| 70 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 71 | |||
| 72 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 73 | |||
| 66 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 74 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 67 | inffast.h inffixed.h | 75 | inffast.h inffixed.h |
| 68 | 76 | ||
diff --git a/msdos/Makefile.dj2 b/msdos/Makefile.dj2 index 283d1d9..84fa1cf 100644 --- a/msdos/Makefile.dj2 +++ b/msdos/Makefile.dj2 | |||
| @@ -51,8 +51,8 @@ AR=ar rcs | |||
| 51 | prefix=/usr/local | 51 | prefix=/usr/local |
| 52 | exec_prefix = $(prefix) | 52 | exec_prefix = $(prefix) |
| 53 | 53 | ||
| 54 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 54 | OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \ |
| 55 | zutil.o inflate.o infback.o inftrees.o inffast.o | 55 | uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o |
| 56 | 56 | ||
| 57 | OBJA = | 57 | OBJA = |
| 58 | # to use the asm code: make OBJA=match.o | 58 | # to use the asm code: make OBJA=match.o |
diff --git a/msdos/Makefile.emx b/msdos/Makefile.emx index ed4c31f..2d7b8b7 100644 --- a/msdos/Makefile.emx +++ b/msdos/Makefile.emx | |||
| @@ -33,8 +33,8 @@ AR=ar rcs | |||
| 33 | prefix=/usr/local | 33 | prefix=/usr/local |
| 34 | exec_prefix = $(prefix) | 34 | exec_prefix = $(prefix) |
| 35 | 35 | ||
| 36 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 36 | OBJS = adler32.o compress.o crc32.o gzclose.o gzio.o gzlib.o gzread.o gzwrite.o \ |
| 37 | zutil.o inflate.o infback.o inftrees.o inffast.o | 37 | uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o |
| 38 | 38 | ||
| 39 | TEST_OBJS = example.o minigzip.o | 39 | TEST_OBJS = example.o minigzip.o |
| 40 | 40 | ||
diff --git a/msdos/Makefile.msc b/msdos/Makefile.msc index b8fc665..c108d47 100644 --- a/msdos/Makefile.msc +++ b/msdos/Makefile.msc | |||
| @@ -37,8 +37,8 @@ LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode | |||
| 37 | # variables | 37 | # variables |
| 38 | ZLIB_LIB = zlib_$(MODEL).lib | 38 | ZLIB_LIB = zlib_$(MODEL).lib |
| 39 | 39 | ||
| 40 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 40 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 41 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj | 41 | OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | # targets | 44 | # targets |
| @@ -55,8 +55,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 55 | 55 | ||
| 56 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 56 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 57 | 57 | ||
| 58 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 59 | |||
| 58 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 60 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 59 | 61 | ||
| 62 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 63 | |||
| 64 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 65 | |||
| 66 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 67 | |||
| 60 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 68 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 61 | inffast.h inffixed.h | 69 | inffast.h inffixed.h |
| 62 | 70 | ||
diff --git a/msdos/Makefile.tc b/msdos/Makefile.tc index 480750a..b14fd0b 100644 --- a/msdos/Makefile.tc +++ b/msdos/Makefile.tc | |||
| @@ -26,10 +26,10 @@ LDFLAGS=-m$(MODEL) -f- | |||
| 26 | # variables | 26 | # variables |
| 27 | ZLIB_LIB = zlib_$(MODEL).lib | 27 | ZLIB_LIB = zlib_$(MODEL).lib |
| 28 | 28 | ||
| 29 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 29 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 30 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.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+gzio.obj+infback.obj | 31 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj |
| 32 | OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj | 32 | OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | # targets | 35 | # targets |
| @@ -46,8 +46,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 46 | 46 | ||
| 47 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 47 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 48 | 48 | ||
| 49 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 50 | |||
| 49 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 51 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 50 | 52 | ||
| 53 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 54 | |||
| 55 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 56 | |||
| 57 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 58 | |||
| 51 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 59 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 52 | inffast.h inffixed.h | 60 | inffast.h inffixed.h |
| 53 | 61 | ||
diff --git a/contrib/nintendods/Makefile b/nintendods/Makefile index 21337d0..21337d0 100644 --- a/contrib/nintendods/Makefile +++ b/nintendods/Makefile | |||
diff --git a/contrib/nintendods/README b/nintendods/README index ba7a37d..ba7a37d 100644 --- a/contrib/nintendods/README +++ b/nintendods/README | |||
diff --git a/projects/visualc6/zlib.dsp b/projects/visualc6/zlib.dsp index 1e5c499..3e98f3d 100644 --- a/projects/visualc6/zlib.dsp +++ b/projects/visualc6/zlib.dsp | |||
| @@ -298,10 +298,26 @@ SOURCE=..\..\deflate.c | |||
| 298 | # End Source File | 298 | # End Source File |
| 299 | # Begin Source File | 299 | # Begin Source File |
| 300 | 300 | ||
| 301 | SOURCE=..\..\gzclose.c | ||
| 302 | # End Source File | ||
| 303 | # Begin Source File | ||
| 304 | |||
| 301 | SOURCE=..\..\gzio.c | 305 | SOURCE=..\..\gzio.c |
| 302 | # End Source File | 306 | # End Source File |
| 303 | # Begin Source File | 307 | # Begin Source File |
| 304 | 308 | ||
| 309 | SOURCE=..\..\gzlib.c | ||
| 310 | # End Source File | ||
| 311 | # Begin Source File | ||
| 312 | |||
| 313 | SOURCE=..\..\gzread.c | ||
| 314 | # End Source File | ||
| 315 | # Begin Source File | ||
| 316 | |||
| 317 | SOURCE=..\..\gzwrite.c | ||
| 318 | # End Source File | ||
| 319 | # Begin Source File | ||
| 320 | |||
| 305 | SOURCE=..\..\infback.c | 321 | SOURCE=..\..\infback.c |
| 306 | # End Source File | 322 | # End Source File |
| 307 | # Begin Source File | 323 | # Begin Source File |
diff --git a/qnx/package.qpg b/qnx/package.qpg index c37e91b..a4872b0 100644 --- a/qnx/package.qpg +++ b/qnx/package.qpg | |||
| @@ -25,10 +25,10 @@ | |||
| 25 | <QPG:Files> | 25 | <QPG:Files> |
| 26 | <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/> | 26 | <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/> |
| 27 | <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/> | 27 | <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/> |
| 28 | <QPG:Add file="../libz.so.1.2.3.4" install="/opt/lib/" user="root:bin" permission="644"/> | 28 | <QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" user="root:bin" permission="644"/> |
| 29 | <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.4"/> | 29 | <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.3.5"/> |
| 30 | <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.4"/> | 30 | <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.3.5"/> |
| 31 | <QPG:Add file="../libz.so.1.2.3.4" install="/opt/lib/" component="slib"/> | 31 | <QPG:Add file="../libz.so.1.2.3.5" install="/opt/lib/" component="slib"/> |
| 32 | </QPG:Files> | 32 | </QPG:Files> |
| 33 | 33 | ||
| 34 | <QPG:PackageFilter> | 34 | <QPG:PackageFilter> |
| @@ -63,7 +63,7 @@ | |||
| 63 | </QPM:ProductDescription> | 63 | </QPM:ProductDescription> |
| 64 | 64 | ||
| 65 | <QPM:ReleaseDescription> | 65 | <QPM:ReleaseDescription> |
| 66 | <QPM:ReleaseVersion>1.2.3.4</QPM:ReleaseVersion> | 66 | <QPM:ReleaseVersion>1.2.3.5</QPM:ReleaseVersion> |
| 67 | <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency> | 67 | <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency> |
| 68 | <QPM:ReleaseStability>Stable</QPM:ReleaseStability> | 68 | <QPM:ReleaseStability>Stable</QPM:ReleaseStability> |
| 69 | <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor> | 69 | <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor> |
diff --git a/treebuild.xml b/treebuild.xml index 5ca9c9e..679570d 100644 --- a/treebuild.xml +++ b/treebuild.xml | |||
| @@ -27,12 +27,36 @@ | |||
| 27 | <depend name="zlibdefs.h" /> | 27 | <depend name="zlibdefs.h" /> |
| 28 | <depend name="crc32.h" /> | 28 | <depend name="crc32.h" /> |
| 29 | </source> | 29 | </source> |
| 30 | <source name="gzclose.c"> | ||
| 31 | <depend name="zlib.h" /> | ||
| 32 | <depend name="zconf.h" /> | ||
| 33 | <depend name="zlibdefs.h" /> | ||
| 34 | <depend name="gzguts.h" /> | ||
| 35 | </source> | ||
| 30 | <source name="gzio.c"> | 36 | <source name="gzio.c"> |
| 31 | <depend name="zlib.h" /> | 37 | <depend name="zlib.h" /> |
| 32 | <depend name="zconf.h" /> | 38 | <depend name="zconf.h" /> |
| 33 | <depend name="zlibdefs.h" /> | 39 | <depend name="zlibdefs.h" /> |
| 34 | <depend name="zutil.h" /> | 40 | <depend name="zutil.h" /> |
| 35 | </source> | 41 | </source> |
| 42 | <source name="gzlib.c"> | ||
| 43 | <depend name="zlib.h" /> | ||
| 44 | <depend name="zconf.h" /> | ||
| 45 | <depend name="zlibdefs.h" /> | ||
| 46 | <depend name="gzguts.h" /> | ||
| 47 | </source> | ||
| 48 | <source name="gzread.c"> | ||
| 49 | <depend name="zlib.h" /> | ||
| 50 | <depend name="zconf.h" /> | ||
| 51 | <depend name="zlibdefs.h" /> | ||
| 52 | <depend name="gzguts.h" /> | ||
| 53 | </source> | ||
| 54 | <source name="gzwrite.c"> | ||
| 55 | <depend name="zlib.h" /> | ||
| 56 | <depend name="zconf.h" /> | ||
| 57 | <depend name="zlibdefs.h" /> | ||
| 58 | <depend name="gzguts.h" /> | ||
| 59 | </source> | ||
| 36 | <source name="uncompr.c"> | 60 | <source name="uncompr.c"> |
| 37 | <depend name="zlib.h" /> | 61 | <depend name="zlib.h" /> |
| 38 | <depend name="zconf.h" /> | 62 | <depend name="zconf.h" /> |
diff --git a/watcom/watcom_f.mak b/watcom/watcom_f.mak index a52229a..ace6bcf 100644 --- a/watcom/watcom_f.mak +++ b/watcom/watcom_f.mak | |||
| @@ -5,10 +5,12 @@ | |||
| 5 | # To use, do "wmake -f watcom_f.mak" | 5 | # To use, do "wmake -f watcom_f.mak" |
| 6 | 6 | ||
| 7 | C_SOURCE = adler32.c compress.c crc32.c deflate.c & | 7 | C_SOURCE = adler32.c compress.c crc32.c deflate.c & |
| 8 | gzclose.c gzlib.c gzread.c gzwrite.c & | ||
| 8 | gzio.c infback.c inffast.c inflate.c & | 9 | gzio.c infback.c inffast.c inflate.c & |
| 9 | inftrees.c trees.c uncompr.c zutil.c | 10 | inftrees.c trees.c uncompr.c zutil.c |
| 10 | 11 | ||
| 11 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj & | 12 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj & |
| 13 | gzclose.obj gzlib.obj gzread.obj gzwrite.obj & | ||
| 12 | gzio.obj infback.obj inffast.obj inflate.obj & | 14 | gzio.obj infback.obj inffast.obj inflate.obj & |
| 13 | inftrees.obj trees.obj uncompr.obj zutil.obj | 15 | inftrees.obj trees.obj uncompr.obj zutil.obj |
| 14 | 16 | ||
| @@ -24,6 +26,7 @@ all: $(ZLIB_LIB) example.exe minigzip.exe | |||
| 24 | 26 | ||
| 25 | $(ZLIB_LIB): $(OBJS) | 27 | $(ZLIB_LIB): $(OBJS) |
| 26 | wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj | 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 | ||
| 27 | wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj | 30 | wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj |
| 28 | wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj | 31 | wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj |
| 29 | wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj | 32 | wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj |
diff --git a/watcom/watcom_l.mak b/watcom/watcom_l.mak index bf03edd..d8a106f 100644 --- a/watcom/watcom_l.mak +++ b/watcom/watcom_l.mak | |||
| @@ -5,10 +5,12 @@ | |||
| 5 | # To use, do "wmake -f watcom_l.mak" | 5 | # To use, do "wmake -f watcom_l.mak" |
| 6 | 6 | ||
| 7 | C_SOURCE = adler32.c compress.c crc32.c deflate.c & | 7 | C_SOURCE = adler32.c compress.c crc32.c deflate.c & |
| 8 | gzclose.c gzlib.c gzread.c gzwrite.c & | ||
| 8 | gzio.c infback.c inffast.c inflate.c & | 9 | gzio.c infback.c inffast.c inflate.c & |
| 9 | inftrees.c trees.c uncompr.c zutil.c | 10 | inftrees.c trees.c uncompr.c zutil.c |
| 10 | 11 | ||
| 11 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj & | 12 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj & |
| 13 | gzclose.obj gzlib.obj gzread.obj gzwrite.obj & | ||
| 12 | gzio.obj infback.obj inffast.obj inflate.obj & | 14 | gzio.obj infback.obj inffast.obj inflate.obj & |
| 13 | inftrees.obj trees.obj uncompr.obj zutil.obj | 15 | inftrees.obj trees.obj uncompr.obj zutil.obj |
| 14 | 16 | ||
| @@ -24,6 +26,7 @@ all: $(ZLIB_LIB) example.exe minigzip.exe | |||
| 24 | 26 | ||
| 25 | $(ZLIB_LIB): $(OBJS) | 27 | $(ZLIB_LIB): $(OBJS) |
| 26 | wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj | 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 | ||
| 27 | wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj | 30 | wlib -b -c $(ZLIB_LIB) -+deflate.obj -+gzio.obj -+infback.obj |
| 28 | wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj | 31 | wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj |
| 29 | wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj | 32 | wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj |
diff --git a/win32/Makefile.bor b/win32/Makefile.bor index 67dafaa..f975669 100644 --- a/win32/Makefile.bor +++ b/win32/Makefile.bor | |||
| @@ -24,11 +24,11 @@ LDFLAGS = $(LOC) | |||
| 24 | # variables | 24 | # variables |
| 25 | ZLIB_LIB = zlib.lib | 25 | ZLIB_LIB = zlib.lib |
| 26 | 26 | ||
| 27 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj | 27 | OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj |
| 28 | OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj | 28 | OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj |
| 29 | #OBJA = | 29 | #OBJA = |
| 30 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj | 30 | OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzio.obj+gzlib.obj+gzread.obj |
| 31 | OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj | 31 | OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj |
| 32 | #OBJPA= | 32 | #OBJPA= |
| 33 | 33 | ||
| 34 | 34 | ||
| @@ -49,8 +49,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 49 | 49 | ||
| 50 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 50 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 51 | 51 | ||
| 52 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 53 | |||
| 52 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 54 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 53 | 55 | ||
| 56 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 57 | |||
| 58 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 59 | |||
| 60 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 61 | |||
| 54 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 62 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 55 | inffast.h inffixed.h | 63 | inffast.h inffixed.h |
| 56 | 64 | ||
diff --git a/win32/Makefile.emx b/win32/Makefile.emx index 7b08424..6ec95e3 100644 --- a/win32/Makefile.emx +++ b/win32/Makefile.emx | |||
| @@ -33,8 +33,8 @@ AR=ar rcs | |||
| 33 | prefix=/usr/local | 33 | prefix=/usr/local |
| 34 | exec_prefix = $(prefix) | 34 | exec_prefix = $(prefix) |
| 35 | 35 | ||
| 36 | OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ | 36 | OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \ |
| 37 | zutil.o inflate.o infback.o inftrees.o inffast.o | 37 | gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o |
| 38 | 38 | ||
| 39 | TEST_OBJS = example.o minigzip.o | 39 | TEST_OBJS = example.o minigzip.o |
| 40 | 40 | ||
diff --git a/win32/Makefile.gcc b/win32/Makefile.gcc index 62a8430..4cc8625 100644 --- a/win32/Makefile.gcc +++ b/win32/Makefile.gcc | |||
| @@ -45,6 +45,8 @@ ARFLAGS = rcs | |||
| 45 | RC = windres | 45 | RC = windres |
| 46 | RCFLAGS = --define GCC_WINDRES | 46 | RCFLAGS = --define GCC_WINDRES |
| 47 | 47 | ||
| 48 | STRIP = strip | ||
| 49 | |||
| 48 | CP = cp -fp | 50 | CP = cp -fp |
| 49 | # If GNU install is available, replace $(CP) with install. | 51 | # If GNU install is available, replace $(CP) with install. |
| 50 | INSTALL = $(CP) | 52 | INSTALL = $(CP) |
| @@ -53,17 +55,17 @@ RM = rm -f | |||
| 53 | prefix = /usr/local | 55 | prefix = /usr/local |
| 54 | exec_prefix = $(prefix) | 56 | exec_prefix = $(prefix) |
| 55 | 57 | ||
| 56 | OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \ | 58 | OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzio.o gzlib.o gzread.o \ |
| 57 | inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o | 59 | gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o |
| 58 | OBJA = | 60 | OBJA = |
| 59 | 61 | ||
| 60 | all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example minigzip example_d minigzip_d | 62 | all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe |
| 61 | 63 | ||
| 62 | test: example minigzip | 64 | test: example.exe minigzip.exe |
| 63 | ./example | 65 | ./example |
| 64 | echo hello world | ./minigzip | ./minigzip -d | 66 | echo hello world | ./minigzip | ./minigzip -d |
| 65 | 67 | ||
| 66 | testdll: example_d minigzip_d | 68 | testdll: example_d.exe minigzip_d.exe |
| 67 | ./example_d | 69 | ./example_d |
| 68 | echo hello world | ./minigzip_d | ./minigzip_d -d | 70 | echo hello world | ./minigzip_d | ./minigzip_d -d |
| 69 | 71 | ||
| @@ -79,20 +81,20 @@ $(STATICLIB): $(OBJS) $(OBJA) | |||
| 79 | $(IMPLIB): $(SHAREDLIB) | 81 | $(IMPLIB): $(SHAREDLIB) |
| 80 | 82 | ||
| 81 | $(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o | 83 | $(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o |
| 82 | dllwrap --driver-name $(CC) --def win32/zlib.def \ | 84 | $(CC) -shared -Wl,--out-implib,$(IMPLIB) \ |
| 83 | --implib $(IMPLIB) -o $@ $(OBJS) $(OBJA) zlibrc.o | 85 | -o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o |
| 84 | strip $@ | 86 | $(STRIP) $@ |
| 85 | 87 | ||
| 86 | example: example.o $(STATICLIB) | 88 | example.exe: example.o $(STATICLIB) |
| 87 | $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) | 89 | $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) |
| 88 | 90 | ||
| 89 | minigzip: minigzip.o $(STATICLIB) | 91 | minigzip.exe: minigzip.o $(STATICLIB) |
| 90 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) | 92 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) |
| 91 | 93 | ||
| 92 | example_d: example.o $(IMPLIB) | 94 | example_d.exe: example.o $(IMPLIB) |
| 93 | $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) | 95 | $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) |
| 94 | 96 | ||
| 95 | minigzip_d: minigzip.o $(IMPLIB) | 97 | minigzip_d.exe: minigzip.o $(IMPLIB) |
| 96 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) | 98 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) |
| 97 | 99 | ||
| 98 | zlibrc.o: win32/zlib1.rc | 100 | zlibrc.o: win32/zlib1.rc |
| @@ -130,7 +132,11 @@ compress.o: zlib.h zconf.h | |||
| 130 | crc32.o: crc32.h zlib.h zconf.h | 132 | crc32.o: crc32.h zlib.h zconf.h |
| 131 | deflate.o: deflate.h zutil.h zlib.h zconf.h | 133 | deflate.o: deflate.h zutil.h zlib.h zconf.h |
| 132 | example.o: zlib.h zconf.h | 134 | example.o: zlib.h zconf.h |
| 135 | gzclose.o: zlib.h zconf.h gzguts.h | ||
| 133 | gzio.o: zutil.h zlib.h zconf.h | 136 | gzio.o: zutil.h zlib.h zconf.h |
| 137 | gzlib.o: zlib.h zconf.h gzguts.h | ||
| 138 | gzread.o: zlib.h zconf.h gzguts.h | ||
| 139 | gzwrite.o: zlib.h zconf.h gzguts.h | ||
| 134 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 140 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
| 135 | inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 141 | inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
| 136 | infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | 142 | infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
diff --git a/win32/Makefile.gcc.old b/win32/Makefile.gcc.old new file mode 100644 index 0000000..62a8430 --- /dev/null +++ b/win32/Makefile.gcc.old | |||
| @@ -0,0 +1,141 @@ | |||
| 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: 1-Aug-2003. | ||
| 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: | ||
| 11 | # | ||
| 12 | # make -fmakefile.gcc; make test testdll -fmakefile.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 -fmakefile.gcc | ||
| 17 | # | ||
| 18 | # To install libz.a, zconf.h and zlib.h in the system directories, type: | ||
| 19 | # | ||
| 20 | # make install -fmakefile.gcc | ||
| 21 | |||
| 22 | # Note: | ||
| 23 | # If the platform is *not* MinGW (e.g. it is Cygwin or UWIN), | ||
| 24 | # the DLL name should be changed from "zlib1.dll". | ||
| 25 | |||
| 26 | STATICLIB = libz.a | ||
| 27 | SHAREDLIB = zlib1.dll | ||
| 28 | IMPLIB = libzdll.a | ||
| 29 | |||
| 30 | #LOC = -DASMV | ||
| 31 | #LOC = -DDEBUG -g | ||
| 32 | |||
| 33 | CC = gcc | ||
| 34 | CFLAGS = $(LOC) -O3 -Wall | ||
| 35 | |||
| 36 | AS = $(CC) | ||
| 37 | ASFLAGS = $(LOC) -Wall | ||
| 38 | |||
| 39 | LD = $(CC) | ||
| 40 | LDFLAGS = $(LOC) -s | ||
| 41 | |||
| 42 | AR = ar | ||
| 43 | ARFLAGS = rcs | ||
| 44 | |||
| 45 | RC = windres | ||
| 46 | RCFLAGS = --define GCC_WINDRES | ||
| 47 | |||
| 48 | CP = cp -fp | ||
| 49 | # If GNU install is available, replace $(CP) with install. | ||
| 50 | INSTALL = $(CP) | ||
| 51 | RM = rm -f | ||
| 52 | |||
| 53 | prefix = /usr/local | ||
| 54 | exec_prefix = $(prefix) | ||
| 55 | |||
| 56 | OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \ | ||
| 57 | inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o | ||
| 58 | OBJA = | ||
| 59 | |||
| 60 | all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example minigzip example_d minigzip_d | ||
| 61 | |||
| 62 | test: example minigzip | ||
| 63 | ./example | ||
| 64 | echo hello world | ./minigzip | ./minigzip -d | ||
| 65 | |||
| 66 | testdll: example_d minigzip_d | ||
| 67 | ./example_d | ||
| 68 | echo hello world | ./minigzip_d | ./minigzip_d -d | ||
| 69 | |||
| 70 | .c.o: | ||
| 71 | $(CC) $(CFLAGS) -c -o $@ $< | ||
| 72 | |||
| 73 | .S.o: | ||
| 74 | $(AS) $(ASFLAGS) -c -o $@ $< | ||
| 75 | |||
| 76 | $(STATICLIB): $(OBJS) $(OBJA) | ||
| 77 | $(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA) | ||
| 78 | |||
| 79 | $(IMPLIB): $(SHAREDLIB) | ||
| 80 | |||
| 81 | $(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o | ||
| 82 | dllwrap --driver-name $(CC) --def win32/zlib.def \ | ||
| 83 | --implib $(IMPLIB) -o $@ $(OBJS) $(OBJA) zlibrc.o | ||
| 84 | strip $@ | ||
| 85 | |||
| 86 | example: example.o $(STATICLIB) | ||
| 87 | $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) | ||
| 88 | |||
| 89 | minigzip: minigzip.o $(STATICLIB) | ||
| 90 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) | ||
| 91 | |||
| 92 | example_d: example.o $(IMPLIB) | ||
| 93 | $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) | ||
| 94 | |||
| 95 | minigzip_d: minigzip.o $(IMPLIB) | ||
| 96 | $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) | ||
| 97 | |||
| 98 | zlibrc.o: win32/zlib1.rc | ||
| 99 | $(RC) $(RCFLAGS) -o $@ win32/zlib1.rc | ||
| 100 | |||
| 101 | |||
| 102 | # INCLUDE_PATH and LIBRARY_PATH must be set. | ||
| 103 | |||
| 104 | .PHONY: install uninstall clean | ||
| 105 | |||
| 106 | install: zlib.h zconf.h $(LIB) | ||
| 107 | -@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH) | ||
| 108 | -@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH) | ||
| 109 | -$(INSTALL) zlib.h $(INCLUDE_PATH) | ||
| 110 | -$(INSTALL) zconf.h $(INCLUDE_PATH) | ||
| 111 | -$(INSTALL) $(STATICLIB) $(LIBRARY_PATH) | ||
| 112 | -$(INSTALL) $(IMPLIB) $(LIBRARY_PATH) | ||
| 113 | |||
| 114 | uninstall: | ||
| 115 | -$(RM) $(INCLUDE_PATH)/zlib.h | ||
| 116 | -$(RM) $(INCLUDE_PATH)/zconf.h | ||
| 117 | -$(RM) $(LIBRARY_PATH)/$(STATICLIB) | ||
| 118 | -$(RM) $(LIBRARY_PATH)/$(IMPLIB) | ||
| 119 | |||
| 120 | clean: | ||
| 121 | -$(RM) $(STATICLIB) | ||
| 122 | -$(RM) $(SHAREDLIB) | ||
| 123 | -$(RM) $(IMPLIB) | ||
| 124 | -$(RM) *.o | ||
| 125 | -$(RM) *.exe | ||
| 126 | -$(RM) foo.gz | ||
| 127 | |||
| 128 | adler32.o: zlib.h zconf.h | ||
| 129 | compress.o: zlib.h zconf.h | ||
| 130 | crc32.o: crc32.h zlib.h zconf.h | ||
| 131 | deflate.o: deflate.h zutil.h zlib.h zconf.h | ||
| 132 | example.o: zlib.h zconf.h | ||
| 133 | gzio.o: zutil.h zlib.h zconf.h | ||
| 134 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | ||
| 135 | inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | ||
| 136 | infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h | ||
| 137 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h | ||
| 138 | minigzip.o: zlib.h zconf.h | ||
| 139 | trees.o: deflate.h zutil.h zlib.h zconf.h trees.h | ||
| 140 | uncompr.o: zlib.h zconf.h | ||
| 141 | zutil.o: zutil.h zlib.h zconf.h | ||
diff --git a/win32/Makefile.msc b/win32/Makefile.msc index 5900d66..66e9224 100644 --- a/win32/Makefile.msc +++ b/win32/Makefile.msc | |||
| @@ -28,8 +28,8 @@ LDFLAGS = -nologo -debug -release | |||
| 28 | ARFLAGS = -nologo | 28 | ARFLAGS = -nologo |
| 29 | RCFLAGS = /dWIN32 /r | 29 | RCFLAGS = /dWIN32 /r |
| 30 | 30 | ||
| 31 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \ | 31 | OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzio.obj gzlib.obj gzread.obj \ |
| 32 | inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj | 32 | gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj |
| 33 | OBJA = | 33 | OBJA = |
| 34 | 34 | ||
| 35 | 35 | ||
| @@ -82,8 +82,16 @@ crc32.obj: crc32.c zlib.h zconf.h crc32.h | |||
| 82 | 82 | ||
| 83 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h | 83 | deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h |
| 84 | 84 | ||
| 85 | gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h | ||
| 86 | |||
| 85 | gzio.obj: gzio.c zutil.h zlib.h zconf.h | 87 | gzio.obj: gzio.c zutil.h zlib.h zconf.h |
| 86 | 88 | ||
| 89 | gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h | ||
| 90 | |||
| 91 | gzread.obj: gzread.c zlib.h zconf.h gzguts.h | ||
| 92 | |||
| 93 | gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h | ||
| 94 | |||
| 87 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ | 95 | infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ |
| 88 | inffast.h inffixed.h | 96 | inffast.h inffixed.h |
| 89 | 97 | ||
diff --git a/win32/zlib.def b/win32/zlib.def index c148ecb..d247b79 100644 --- a/win32/zlib.def +++ b/win32/zlib.def | |||
| @@ -35,6 +35,7 @@ EXPORTS | |||
| 35 | uncompress | 35 | uncompress |
| 36 | gzopen | 36 | gzopen |
| 37 | gzdopen | 37 | gzdopen |
| 38 | gzbuffer | ||
| 38 | gzsetparams | 39 | gzsetparams |
| 39 | gzread | 40 | gzread |
| 40 | gzwrite | 41 | gzwrite |
| @@ -48,9 +49,12 @@ EXPORTS | |||
| 48 | gzseek | 49 | gzseek |
| 49 | gzrewind | 50 | gzrewind |
| 50 | gztell | 51 | gztell |
| 52 | gzoffset | ||
| 51 | gzeof | 53 | gzeof |
| 52 | gzdirect | 54 | gzdirect |
| 53 | gzclose | 55 | gzclose |
| 56 | gzclose_r | ||
| 57 | gzclose_w | ||
| 54 | gzerror | 58 | gzerror |
| 55 | gzclearerr | 59 | gzclearerr |
| 56 | ; checksum functions | 60 | ; checksum functions |
| @@ -67,6 +71,7 @@ EXPORTS | |||
| 67 | gzopen64 | 71 | gzopen64 |
| 68 | gzseek64 | 72 | gzseek64 |
| 69 | gztell64 | 73 | gztell64 |
| 74 | gzoffset64 | ||
| 70 | adler32_combine64 | 75 | adler32_combine64 |
| 71 | crc32_combine64 | 76 | crc32_combine64 |
| 72 | zError | 77 | zError |
| @@ -45,8 +45,11 @@ | |||
| 45 | # define deflateTune z_deflateTune | 45 | # define deflateTune z_deflateTune |
| 46 | # define deflate_copyright z_deflate_copyright | 46 | # define deflate_copyright z_deflate_copyright |
| 47 | # define get_crc_table z_get_crc_table | 47 | # define get_crc_table z_get_crc_table |
| 48 | # define gzbuffer z_gzbuffer | ||
| 48 | # define gzclearerr z_gzclearerr | 49 | # define gzclearerr z_gzclearerr |
| 49 | # define gzclose z_gzclose | 50 | # define gzclose z_gzclose |
| 51 | # define gzclose_r z_gzclose_r | ||
| 52 | # define gzclose_w z_gzclose_w | ||
| 50 | # define gzdirect z_gzdirect | 53 | # define gzdirect z_gzdirect |
| 51 | # define gzdopen z_gzdopen | 54 | # define gzdopen z_gzdopen |
| 52 | # define gzeof z_gzeof | 55 | # define gzeof z_gzeof |
| @@ -54,6 +57,7 @@ | |||
| 54 | # define gzflush z_gzflush | 57 | # define gzflush z_gzflush |
| 55 | # define gzgetc z_gzgetc | 58 | # define gzgetc z_gzgetc |
| 56 | # define gzgets z_gzgets | 59 | # define gzgets z_gzgets |
| 60 | # define gzoffset z_gzoffset | ||
| 57 | # define gzopen z_gzopen | 61 | # define gzopen z_gzopen |
| 58 | # define gzprintf z_gzprintf | 62 | # define gzprintf z_gzprintf |
| 59 | # define gzputc z_gzputc | 63 | # define gzputc z_gzputc |
| @@ -74,8 +78,10 @@ | |||
| 74 | # define inflateGetHeader z_inflateGetHeader | 78 | # define inflateGetHeader z_inflateGetHeader |
| 75 | # define inflateInit2_ z_inflateInit2_ | 79 | # define inflateInit2_ z_inflateInit2_ |
| 76 | # define inflateInit_ z_inflateInit_ | 80 | # define inflateInit_ z_inflateInit_ |
| 81 | # define inflateMark z_inflateMark | ||
| 77 | # define inflatePrime z_inflatePrime | 82 | # define inflatePrime z_inflatePrime |
| 78 | # define inflateReset z_inflateReset | 83 | # define inflateReset z_inflateReset |
| 84 | # define inflateReset2 z_inflateReset2 | ||
| 79 | # define inflateSetDictionary z_inflateSetDictionary | 85 | # define inflateSetDictionary z_inflateSetDictionary |
| 80 | # define inflateSync z_inflateSync | 86 | # define inflateSync z_inflateSync |
| 81 | # define inflateSyncPoint z_inflateSyncPoint | 87 | # define inflateSyncPoint z_inflateSyncPoint |
| @@ -1,4 +1,4 @@ | |||
| 1 | .TH ZLIB 3 "21 December 2009" | 1 | .TH ZLIB 3 "8 January 2010" |
| 2 | .SH NAME | 2 | .SH NAME |
| 3 | zlib \- compression/decompression library | 3 | zlib \- compression/decompression library |
| 4 | .SH SYNOPSIS | 4 | .SH SYNOPSIS |
| @@ -133,8 +133,8 @@ before asking for help. | |||
| 133 | Send questions and/or comments to zlib@gzip.org, | 133 | Send questions and/or comments to zlib@gzip.org, |
| 134 | or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). | 134 | or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). |
| 135 | .SH AUTHORS | 135 | .SH AUTHORS |
| 136 | Version 1.2.3.4 | 136 | Version 1.2.3.5 |
| 137 | Copyright (C) 1995-2006 Jean-loup Gailly (jloup@gzip.org) | 137 | Copyright (C) 1995-2009 Jean-loup Gailly (jloup@gzip.org) |
| 138 | and Mark Adler (madler@alumni.caltech.edu). | 138 | and Mark Adler (madler@alumni.caltech.edu). |
| 139 | .LP | 139 | .LP |
| 140 | This software is provided "as-is," | 140 | This software is provided "as-is," |
| @@ -1,7 +1,7 @@ | |||
| 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library | 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
| 2 | version 1.2.3.4, December 21st, 2009 | 2 | version 1.2.3.5, Jan 8th, 2010 |
| 3 | 3 | ||
| 4 | Copyright (C) 1995-2009 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler |
| 5 | 5 | ||
| 6 | This software is provided 'as-is', without any express or implied | 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 | 7 | warranty. In no event will the authors be held liable for any damages |
| @@ -37,8 +37,8 @@ | |||
| 37 | extern "C" { | 37 | extern "C" { |
| 38 | #endif | 38 | #endif |
| 39 | 39 | ||
| 40 | #define ZLIB_VERSION "1.2.3.4" | 40 | #define ZLIB_VERSION "1.2.3.5" |
| 41 | #define ZLIB_VERNUM 0x1234 | 41 | #define ZLIB_VERNUM 0x1235 |
| 42 | #define ZLIB_VER_MAJOR 1 | 42 | #define ZLIB_VER_MAJOR 1 |
| 43 | #define ZLIB_VER_MINOR 2 | 43 | #define ZLIB_VER_MINOR 2 |
| 44 | #define ZLIB_VER_REVISION 3 | 44 | #define ZLIB_VER_REVISION 3 |
| @@ -744,6 +744,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, | |||
| 744 | size is given as input, inflate() will return with the error code | 744 | size is given as input, inflate() will return with the error code |
| 745 | Z_DATA_ERROR instead of trying to allocate a larger window. | 745 | Z_DATA_ERROR instead of trying to allocate a larger window. |
| 746 | 746 | ||
| 747 | windowBits can also be zero to request that inflate use the window size in | ||
| 748 | the zlib header of the compressed stream. | ||
| 749 | |||
| 747 | windowBits can also be -8..-15 for raw inflate. In this case, -windowBits | 750 | windowBits can also be -8..-15 for raw inflate. In this case, -windowBits |
| 748 | determines the window size. inflate() will then process raw deflate data, | 751 | determines the window size. inflate() will then process raw deflate data, |
| 749 | not looking for a zlib or gzip header, not generating a check value, and not | 752 | not looking for a zlib or gzip header, not generating a check value, and not |
| @@ -1148,11 +1151,18 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, | |||
| 1148 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. | 1151 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. |
| 1149 | */ | 1152 | */ |
| 1150 | 1153 | ||
| 1154 | /* | ||
| 1155 | This library supports reading and writing files in gzip (.gz) format | ||
| 1156 | with an interface similar to that of stdio using the functions that start | ||
| 1157 | with "gz". The gzip format is different from the zlib format. gzip is a | ||
| 1158 | gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. | ||
| 1159 | |||
| 1160 | */ | ||
| 1151 | 1161 | ||
| 1152 | typedef voidp gzFile; | 1162 | typedef voidp gzFile; |
| 1153 | 1163 | ||
| 1154 | /* | 1164 | /* |
| 1155 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); | 1165 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); |
| 1156 | 1166 | ||
| 1157 | Opens a gzip (.gz) file for reading or writing. The mode parameter | 1167 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
| 1158 | is as in fopen ("rb" or "wb") but can also include a compression level | 1168 | is as in fopen ("rb" or "wb") but can also include a compression level |
| @@ -1169,7 +1179,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); | |||
| 1169 | can be checked to distinguish the two cases (if errno is zero, the | 1179 | can be checked to distinguish the two cases (if errno is zero, the |
| 1170 | zlib error is Z_MEM_ERROR). */ | 1180 | zlib error is Z_MEM_ERROR). */ |
| 1171 | 1181 | ||
| 1172 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); | 1182 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); |
| 1173 | /* | 1183 | /* |
| 1174 | gzdopen() associates a gzFile with the file descriptor fd. File | 1184 | gzdopen() associates a gzFile with the file descriptor fd. File |
| 1175 | descriptors are obtained from calls like open, dup, creat, pipe or | 1185 | descriptors are obtained from calls like open, dup, creat, pipe or |
| @@ -1182,6 +1192,20 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); | |||
| 1182 | the (de)compression state. | 1192 | the (de)compression state. |
| 1183 | */ | 1193 | */ |
| 1184 | 1194 | ||
| 1195 | ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); | ||
| 1196 | /* | ||
| 1197 | Set the internal buffer size used by this library's functions. The default | ||
| 1198 | buffer size is 8192 bytes. This function must be called after gz_open() or | ||
| 1199 | gz_dopen(), and before any other calls that read or write the file. The | ||
| 1200 | buffer memory allocation is always deferred to the first read or write. Two | ||
| 1201 | buffers are allocated, either both of the specified size when writing, or | ||
| 1202 | one of the specified size and the other twice that size when reading. A | ||
| 1203 | larger buffer size of, for example, 64K or 128K bytes will noticeably | ||
| 1204 | increase the speed of decompression (reading). | ||
| 1205 | gz_buffer() returns 0 on success, or -1 on failure, such as being called | ||
| 1206 | too late. | ||
| 1207 | */ | ||
| 1208 | |||
| 1185 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); | 1209 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); |
| 1186 | /* | 1210 | /* |
| 1187 | Dynamically update the compression level or strategy. See the description | 1211 | Dynamically update the compression level or strategy. See the description |
| @@ -1190,7 +1214,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); | |||
| 1190 | opened for writing. | 1214 | opened for writing. |
| 1191 | */ | 1215 | */ |
| 1192 | 1216 | ||
| 1193 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | 1217 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
| 1194 | /* | 1218 | /* |
| 1195 | Reads the given number of uncompressed bytes from the compressed file. | 1219 | Reads the given number of uncompressed bytes from the compressed file. |
| 1196 | If the input file was not in gzip format, gzread copies the given number | 1220 | If the input file was not in gzip format, gzread copies the given number |
| @@ -1198,25 +1222,26 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | |||
| 1198 | gzread returns the number of uncompressed bytes actually read (0 for | 1222 | gzread returns the number of uncompressed bytes actually read (0 for |
| 1199 | end of file, -1 for error). */ | 1223 | end of file, -1 for error). */ |
| 1200 | 1224 | ||
| 1201 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, | 1225 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
| 1202 | voidpc buf, unsigned len)); | 1226 | voidpc buf, unsigned len)); |
| 1203 | /* | 1227 | /* |
| 1204 | Writes the given number of uncompressed bytes into the compressed file. | 1228 | Writes the given number of uncompressed bytes into the compressed file. |
| 1205 | gzwrite returns the number of uncompressed bytes actually written | 1229 | gzwrite returns the number of uncompressed bytes actually written |
| 1206 | (0 in case of error). | 1230 | (0 in case of error). |
| 1207 | */ | 1231 | */ |
| 1208 | 1232 | ||
| 1209 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); | 1233 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); |
| 1210 | /* | 1234 | /* |
| 1211 | Converts, formats, and writes the args to the compressed file under | 1235 | Converts, formats, and writes the arguments to the compressed file under |
| 1212 | control of the format string, as in fprintf. gzprintf returns the number of | 1236 | control of the format string, as in fprintf. gzprintf returns the number of |
| 1213 | uncompressed bytes actually written (0 in case of error). The number of | 1237 | uncompressed bytes actually written, or 0 in case of error. The number of |
| 1214 | uncompressed bytes written is limited to 4095. The caller should assure that | 1238 | uncompressed bytes written is limited to 8191, or one less than the buffer |
| 1215 | this limit is not exceeded. If it is exceeded, then gzprintf() will return | 1239 | size given to gz_buffer(). The caller should assure that this limit is not |
| 1216 | return an error (0) with nothing written. In this case, there may also be a | 1240 | exceeded. If it is exceeded, then gzprintf() will return an error (0) with |
| 1217 | buffer overflow with unpredictable consequences, which is possible only if | 1241 | nothing written. In this case, there may also be a buffer overflow with |
| 1218 | zlib was compiled with the insecure functions sprintf() or vsprintf() | 1242 | unpredictable consequences, which is possible only if zlib was compiled |
| 1219 | because the secure snprintf() or vsnprintf() functions were not available. | 1243 | with the insecure functions sprintf() or vsprintf() because the secure |
| 1244 | snprintf() or vsnprintf() functions were not available. | ||
| 1220 | */ | 1245 | */ |
| 1221 | 1246 | ||
| 1222 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); | 1247 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); |
| @@ -1257,7 +1282,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); | |||
| 1257 | or gzrewind(). | 1282 | or gzrewind(). |
| 1258 | */ | 1283 | */ |
| 1259 | 1284 | ||
| 1260 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); | 1285 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); |
| 1261 | /* | 1286 | /* |
| 1262 | Flushes all pending output into the compressed file. The parameter | 1287 | Flushes all pending output into the compressed file. The parameter |
| 1263 | flush is as in the deflate() function. The return value is the zlib | 1288 | flush is as in the deflate() function. The return value is the zlib |
| @@ -1268,8 +1293,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); | |||
| 1268 | */ | 1293 | */ |
| 1269 | 1294 | ||
| 1270 | /* | 1295 | /* |
| 1271 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, | 1296 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, |
| 1272 | z_off_t offset, int whence)); | 1297 | z_off_t offset, int whence)); |
| 1273 | 1298 | ||
| 1274 | Sets the starting position for the next gzread or gzwrite on the | 1299 | Sets the starting position for the next gzread or gzwrite on the |
| 1275 | given compressed file. The offset represents a number of bytes in the | 1300 | given compressed file. The offset represents a number of bytes in the |
| @@ -1298,11 +1323,23 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); | |||
| 1298 | 1323 | ||
| 1299 | Returns the starting position for the next gzread or gzwrite on the | 1324 | Returns the starting position for the next gzread or gzwrite on the |
| 1300 | given compressed file. This position represents a number of bytes in the | 1325 | given compressed file. This position represents a number of bytes in the |
| 1301 | uncompressed data stream. | 1326 | uncompressed data stream, and is zero when starting, even if appending |
| 1327 | or reading a gzip stream from the middle of a file using gz_dopen(). | ||
| 1302 | 1328 | ||
| 1303 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) | 1329 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) |
| 1304 | */ | 1330 | */ |
| 1305 | 1331 | ||
| 1332 | /* | ||
| 1333 | ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); | ||
| 1334 | |||
| 1335 | Returns the current offset in the file being read or written. This offset | ||
| 1336 | includes the count of bytes that precede the gzip stream, for example when | ||
| 1337 | appending or when using gz_dopen() for reading. When reading, the offset | ||
| 1338 | includes data that has been used to generate what has been provided as | ||
| 1339 | uncompressed data so far, but does not include as yet unused buffered input. | ||
| 1340 | On error, gz_offset() returns -1. | ||
| 1341 | */ | ||
| 1342 | |||
| 1306 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); | 1343 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); |
| 1307 | /* | 1344 | /* |
| 1308 | Returns 1 when EOF has previously been detected reading the given | 1345 | Returns 1 when EOF has previously been detected reading the given |
| @@ -1319,10 +1356,22 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); | |||
| 1319 | /* | 1356 | /* |
| 1320 | Flushes all pending output if necessary, closes the compressed file | 1357 | Flushes all pending output if necessary, closes the compressed file |
| 1321 | and deallocates all the (de)compression state. The return value is the zlib | 1358 | and deallocates all the (de)compression state. The return value is the zlib |
| 1322 | error number. Note that once file is close, you cannot call gzerror with | 1359 | error number. Note that once file is closed, you cannot call gzerror with |
| 1323 | file, since its structures have been deallocated. | 1360 | file, since its structures have been deallocated. |
| 1324 | */ | 1361 | */ |
| 1325 | 1362 | ||
| 1363 | ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); | ||
| 1364 | ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); | ||
| 1365 | /* | ||
| 1366 | Same as gz_close(), but gz_close_r() is only for use when reading, and | ||
| 1367 | gz_close_w() is only for use when writing. The advantage to using these | ||
| 1368 | instead of gz_close() is that they avoid linking in zlib compression or | ||
| 1369 | decompression code that is not used when only reading or only writing | ||
| 1370 | respectively. If gz_close() is used, then both compression and | ||
| 1371 | decompression code will be included the application when linking to a | ||
| 1372 | static zlib library. | ||
| 1373 | */ | ||
| 1374 | |||
| 1326 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); | 1375 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); |
| 1327 | /* | 1376 | /* |
| 1328 | Returns the error message for the last error which occurred on the | 1377 | Returns the error message for the last error which occurred on the |
| @@ -1439,6 +1488,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, | |||
| 1439 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); | 1488 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); |
| 1440 | ZEXTERN off64_t ZEXPORT gzseek64 OF((gzFile, off64_t, int)); | 1489 | ZEXTERN off64_t ZEXPORT gzseek64 OF((gzFile, off64_t, int)); |
| 1441 | ZEXTERN off64_t ZEXPORT gztell64 OF((gzFile)); | 1490 | ZEXTERN off64_t ZEXPORT gztell64 OF((gzFile)); |
| 1491 | ZEXTERN off64_t ZEXPORT gzoffset64 OF((gzFile)); | ||
| 1442 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off64_t)); | 1492 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off64_t)); |
| 1443 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off64_t)); | 1493 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off64_t)); |
| 1444 | #endif | 1494 | #endif |
| @@ -1447,12 +1497,14 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, | |||
| 1447 | # define gzopen gzopen64 | 1497 | # define gzopen gzopen64 |
| 1448 | # define gzseek gzseek64 | 1498 | # define gzseek gzseek64 |
| 1449 | # define gztell gztell64 | 1499 | # define gztell gztell64 |
| 1500 | # define gzoffset gzoffset64 | ||
| 1450 | # define adler32_combine adler32_combine64 | 1501 | # define adler32_combine adler32_combine64 |
| 1451 | # define crc32_combine crc32_combine64 | 1502 | # define crc32_combine crc32_combine64 |
| 1452 | # ifndef _LARGEFILE64_SOURCE | 1503 | # ifndef _LARGEFILE64_SOURCE |
| 1453 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); | 1504 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); |
| 1454 | ZEXTERN off_t ZEXPORT gzseek64 OF((gzFile, off_t, int)); | 1505 | ZEXTERN off_t ZEXPORT gzseek64 OF((gzFile, off_t, int)); |
| 1455 | ZEXTERN off_t ZEXPORT gztell64 OF((gzFile)); | 1506 | ZEXTERN off_t ZEXPORT gztell64 OF((gzFile)); |
| 1507 | ZEXTERN off_t ZEXPORT gzoffset64 OF((gzFile)); | ||
| 1456 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off_t)); | 1508 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, off_t)); |
| 1457 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off_t)); | 1509 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, off_t)); |
| 1458 | # endif | 1510 | # endif |
| @@ -1460,6 +1512,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, | |||
| 1460 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); | 1512 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); |
| 1461 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); | 1513 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); |
| 1462 | ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); | 1514 | ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); |
| 1515 | ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); | ||
| 1463 | ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); | 1516 | ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); |
| 1464 | ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); | 1517 | ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); |
| 1465 | #endif | 1518 | #endif |
diff --git a/zlibdefs.h.cmakein b/zlibdefs.h.cmakein new file mode 100644 index 0000000..418bb6b --- /dev/null +++ b/zlibdefs.h.cmakein | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* zlibdefs.h -- compile-time definitions for the zlib compression library | ||
| 2 | * Copyright (C) 1995-2006 Jean-loup Gailly. | ||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #cmakedefine HAVE_UNISTD_H | ||
| 7 | #ifdef HAVE_UNISTD_H | ||
| 8 | #include <sys/types.h> /* for off_t */ | ||
| 9 | #include <unistd.h> /* for SEEK_* and off_t */ | ||
| 10 | #ifdef VMS | ||
| 11 | # include <unixio.h> /* for off_t */ | ||
| 12 | #endif | ||
| 13 | #ifndef z_off_t | ||
| 14 | # define z_off_t off_t | ||
| 15 | #endif | ||
| 16 | #endif | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* zutil.h -- internal interface and configuration of the compression library | 1 | /* zutil.h -- internal interface and configuration of the compression library |
| 2 | * Copyright (C) 1995-2006 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2010 Jean-loup Gailly. |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -17,24 +17,24 @@ | |||
| 17 | #include "zlib.h" | 17 | #include "zlib.h" |
| 18 | 18 | ||
| 19 | #ifdef STDC | 19 | #ifdef STDC |
| 20 | # ifndef _WIN32_WCE | 20 | # if !(defined(_WIN32_WCE) && defined(_MSV_VER)) |
| 21 | # include <stddef.h> | 21 | # include <stddef.h> |
| 22 | # endif | 22 | # endif |
| 23 | # include <string.h> | 23 | # include <string.h> |
| 24 | # include <stdlib.h> | 24 | # include <stdlib.h> |
| 25 | #endif | 25 | #endif |
| 26 | #if defined(NO_ERRNO_H) || defined(_WIN32_WCE) | 26 | |
| 27 | # ifdef _WIN32_WCE | 27 | #if defined(UNDER_CE) && defined(NO_ERRNO_H) |
| 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have | 28 | # define zseterrno(ERR) SetLastError((DWORD)(ERR)) |
| 29 | * errno. We define it as a global variable to simplify porting. | 29 | # define zerrno() ((int)GetLastError()) |
| 30 | * Its value is always 0 and should not be used. We rename it to | ||
| 31 | * avoid conflict with other libraries that use the same workaround. | ||
| 32 | */ | ||
| 33 | # define errno z_errno | ||
| 34 | # endif | ||
| 35 | extern int errno; | ||
| 36 | #else | 30 | #else |
| 37 | # include <errno.h> | 31 | # ifdef NO_ERRNO_H |
| 32 | extern int errno; | ||
| 33 | # else | ||
| 34 | # include <errno.h> | ||
| 35 | # endif | ||
| 36 | # define zseterrno(ERR) do { errno = (ERR); } while (0) | ||
| 37 | # define zerrno() errno | ||
| 38 | #endif | 38 | #endif |
| 39 | 39 | ||
| 40 | #ifndef local | 40 | #ifndef local |
| @@ -87,7 +87,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
| 87 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) | 87 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) |
| 88 | # define OS_CODE 0x00 | 88 | # define OS_CODE 0x00 |
| 89 | # if defined(__TURBOC__) || defined(__BORLANDC__) | 89 | # if defined(__TURBOC__) || defined(__BORLANDC__) |
| 90 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) | 90 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) |
| 91 | /* Allow compilation with ANSI keywords only enabled */ | 91 | /* Allow compilation with ANSI keywords only enabled */ |
| 92 | void _Cdecl farfree( void *block ); | 92 | void _Cdecl farfree( void *block ); |
| 93 | void *_Cdecl farmalloc( unsigned long nbytes ); | 93 | void *_Cdecl farmalloc( unsigned long nbytes ); |
| @@ -213,7 +213,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ | |||
| 213 | # ifdef WIN32 | 213 | # ifdef WIN32 |
| 214 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ | 214 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ |
| 215 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) | 215 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) |
| 216 | # define vsnprintf _vsnprintf | 216 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) |
| 217 | # define vsnprintf _vsnprintf | ||
| 218 | # endif | ||
| 217 | # endif | 219 | # endif |
| 218 | # endif | 220 | # endif |
| 219 | # ifdef __SASC | 221 | # ifdef __SASC |
