summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
commit8e34b3a8024c028dd9fd21d70525fc6d215efde5 (patch)
tree896a32f54abdf42ae3c1bb3c5d5627668b481ce4
parent13a294f044ef0a89b2dcbfbb5d4d4c792673348e (diff)
downloadzlib-1.2.0.2.tar.gz
zlib-1.2.0.2.tar.bz2
zlib-1.2.0.2.zip
zlib 1.2.0.2v1.2.0.2
-rw-r--r--ChangeLog36
-rw-r--r--FAQ3
-rw-r--r--Makefile2
-rw-r--r--Makefile.in2
-rw-r--r--README4
-rw-r--r--adler32.c1
-rw-r--r--aix/README9
-rw-r--r--aix/configure.diff57
-rw-r--r--aix/mkexps37
-rw-r--r--algorithm.txt2
-rw-r--r--compress.c1
-rwxr-xr-xconfigure10
-rw-r--r--contrib/iostream3/README35
-rw-r--r--contrib/iostream3/TODO17
-rw-r--r--contrib/iostream3/test.cc50
-rw-r--r--contrib/iostream3/zfstream.cc479
-rw-r--r--contrib/iostream3/zfstream.h466
-rw-r--r--contrib/minizip/ChangeLogUnzip98
-rw-r--r--contrib/minizip/Makefile50
-rw-r--r--contrib/minizip/crypt.h208
-rw-r--r--contrib/minizip/ioapi.c354
-rw-r--r--contrib/minizip/ioapi.h150
-rw-r--r--contrib/minizip/iowin32.c542
-rw-r--r--contrib/minizip/iowin32.h38
-rw-r--r--contrib/minizip/miniunz.c1099
-rw-r--r--contrib/minizip/minizip.c789
-rw-r--r--contrib/minizip/unzip.c3060
-rw-r--r--contrib/minizip/unzip.h684
-rw-r--r--contrib/minizip/zconf.h326
-rw-r--r--contrib/minizip/zip.c2336
-rw-r--r--contrib/minizip/zip.h470
-rw-r--r--contrib/vstudio/readme.txt7
-rw-r--r--contrib/vstudio/vc15_16/zlib16.def2
-rw-r--r--contrib/vstudio/vc15_16/zlib16.rc6
-rw-r--r--contrib/vstudio/vc70_32/zlib.rc6
-rw-r--r--contrib/vstudio/vc70_32/zlibvc.def2
-rw-r--r--contrib/zlib_dll_FAQ.txt257
-rw-r--r--crc32.c28
-rw-r--r--deflate.c54
-rw-r--r--deflate.h6
-rw-r--r--example.c12
-rw-r--r--gzio.c90
-rw-r--r--infback.c12
-rw-r--r--inflate.c61
-rw-r--r--inflate.h2
-rw-r--r--inftrees.c4
-rw-r--r--minigzip.c4
-rw-r--r--old/zlib.3107
-rw-r--r--uncompr.c1
-rw-r--r--win32/Makefile.gcc15
-rw-r--r--win32/Makefile.msc33
-rw-r--r--win32/zlib.def13
-rw-r--r--zconf.h89
-rw-r--r--zconf.in.h89
-rw-r--r--zlib.3159
-rw-r--r--zlib.h109
-rw-r--r--zutil.c83
-rw-r--r--zutil.h15
58 files changed, 7305 insertions, 5376 deletions
diff --git a/ChangeLog b/ChangeLog
index 55c29c1..af4a655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,39 @@
1 1
2 ChangeLog file for zlib 2 ChangeLog file for zlib
3Changes in 1.2.0.2 (13 July 2003)
4- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
5- Attempt to avoid warnings in crc32.c for pointer-int conversion
6- Add AIX to configure, remove aix directory [Bakker]
7- Add some casts to minigzip.c
8- Improve checking after insecure sprintf() or vsprintf() calls
9- Remove #elif's from crc32.c
10- Change leave label to inf_leave in inflate.c and infback.c to avoid
11 library conflicts
12- Remove inflate gzip decoding by default--only enable gzip decoding by
13 special request for stricter backward compatibility
14- Add zlibCompileFlags() function to return compilation information
15- More typecasting in deflate.c to avoid warnings
16- Remove leading underscore from _Capital #defines [Truta]
17- Fix configure to link shared library when testing
18- Add some Windows CE target adjustments [Mai]
19- Remove #define ZLIB_DLL in zconf.h [Vollant]
20- Add zlib.3 [Rodgers]
21- Update RFC URL in deflate.c and algorithm.txt [Mai]
22- Add zlib_dll_FAQ.txt to contrib [Truta]
23- Add UL to some constants [Truta]
24- Update minizip and vstudio [Vollant]
25- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
26- Expand use of NO_DUMMY_DECL to avoid all dummy structures
27- Added iostream3 to contrib [Schwardt]
28- Replace rewind() with fseek() for WinCE [Truta]
29- Improve setting of zlib format compression level flags
30 - Report 0 for huffman and rle strategies and for level == 0 or 1
31 - Report 2 only for level == 6
32- Only deal with 64K limit when necessary at compile time [Truta]
33- Allow TOO_FAR check to be turned off at compile time [Truta]
34- Added gzclearerr() function [Souza]
35- Added gzungetc() function
36
3Changes in 1.2.0.1 (17 March 2003) 37Changes in 1.2.0.1 (17 March 2003)
4- Add Z_RLE strategy for run-length encoding [Truta] 38- Add Z_RLE strategy for run-length encoding [Truta]
5 - When Z_RLE requested, restrict matches to distance one 39 - When Z_RLE requested, restrict matches to distance one
@@ -12,7 +46,7 @@ Changes in 1.2.0.1 (17 March 2003)
12 - Include additional header file on VMS for off_t typedef 46 - Include additional header file on VMS for off_t typedef
13- Try to use _vsnprintf where it supplants vsprintf [Vollant] 47- Try to use _vsnprintf where it supplants vsprintf [Vollant]
14- Add some casts in inffast.c 48- Add some casts in inffast.c
15- Enchance comments in zlib.h on what happens if the gzprintf() tries to 49- Enchance comments in zlib.h on what happens if gzprintf() tries to
16 write more than 4095 bytes before compression 50 write more than 4095 bytes before compression
17- Remove unused state from inflateBackEnd() 51- Remove unused state from inflateBackEnd()
18- Remove exit(0) from minigzip.c, example.c 52- Remove exit(0) from minigzip.c, example.c
diff --git a/FAQ b/FAQ
index 2a8247c..b439bd9 100644
--- a/FAQ
+++ b/FAQ
@@ -228,7 +228,8 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
228 hand, if zlib is compiled to use snprintf() or vsnprintf(), which should 228 hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
229 normally be the case, then there is no vulnerability. The ./configure 229 normally be the case, then there is no vulnerability. The ./configure
230 script will display warnings if an insecure variation of sprintf() will 230 script will display warnings if an insecure variation of sprintf() will
231 be used by gzprintf(). 231 be used by gzprintf(). Also the zlibCompileFlags() functions will return
232 information on what variant of sprintf() is used by gzprintf().
232 233
233 If you don't have snprintf() or vsnprintf() and would like one, you can 234 If you don't have snprintf() or vsnprintf() and would like one, you can
234 find a portable implementation here: 235 find a portable implementation here:
diff --git a/Makefile b/Makefile
index 05540e9..6fbe392 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25CPP=$(CC) -E 25CPP=$(CC) -E
26 26
27VER=1.2.0.1 27VER=1.2.0.2
28LIBS=libz.a 28LIBS=libz.a
29SHAREDLIB=libz.so 29SHAREDLIB=libz.so
30 30
diff --git a/Makefile.in b/Makefile.in
index 05540e9..6fbe392 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25CPP=$(CC) -E 25CPP=$(CC) -E
26 26
27VER=1.2.0.1 27VER=1.2.0.2
28LIBS=libz.a 28LIBS=libz.a
29SHAREDLIB=libz.so 29SHAREDLIB=libz.so
30 30
diff --git a/README b/README
index 8ac79a1..cc489ac 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
1ZLIB DATA COMPRESSION LIBRARY 1ZLIB DATA COMPRESSION LIBRARY
2 2
3zlib 1.2.0.1 is a general purpose data compression library. All the code is 3zlib 1.2.0.2 is a general purpose data compression library. All the code is
4thread safe. The data format used by the zlib library is described by RFCs 4thread safe. The data format used by the zlib library is described by RFCs
5(Request for Comments) 1950 to 1952 in the files 5(Request for Comments) 1950 to 1952 in the files
6http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) 6http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
@@ -34,7 +34,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
34issue of Dr. Dobb's Journal; a copy of the article is available in 34issue of Dr. Dobb's Journal; a copy of the article is available in
35http://dogma.net/markn/articles/zlibtool/zlibtool.htm 35http://dogma.net/markn/articles/zlibtool/zlibtool.htm
36 36
37The changes made in version 1.2.0.1 are documented in the file ChangeLog. 37The changes made in version 1.2.0.2 are documented in the file ChangeLog.
38 38
39Unsupported third party contributions are provided in directory "contrib". 39Unsupported third party contributions are provided in directory "contrib".
40 40
diff --git a/adler32.c b/adler32.c
index 28c65ba..5506363 100644
--- a/adler32.c
+++ b/adler32.c
@@ -5,6 +5,7 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#define ZLIB_INTERNAL
8#include "zlib.h" 9#include "zlib.h"
9 10
10#define BASE 65521L /* largest prime smaller than 65536 */ 11#define BASE 65521L /* largest prime smaller than 65536 */
diff --git a/aix/README b/aix/README
deleted file mode 100644
index 235ba59..0000000
--- a/aix/README
+++ /dev/null
@@ -1,9 +0,0 @@
1To make a shared library:
2
31. Compile a static library
42. Use mkexps on that to create libz.exp
53. Apply the configure.diff patch to configure
64. Run the new configure to make a new Makefile
75. Use the new Makefile to make the shared library
8
9Courtesy of dbakker@arrayasolutions.com
diff --git a/aix/configure.diff b/aix/configure.diff
deleted file mode 100644
index c699129..0000000
--- a/aix/configure.diff
+++ /dev/null
@@ -1,57 +0,0 @@
1*** ../orig/zlib-1.1.4/configure Wed Jul 8 14:19:35 1998
2--- configure Sun Feb 9 11:11:19 2003
3***************
4*** 18,23 ****
5--- 18,24 ----
6 # If you have problems, try without defining CC and CFLAGS before reporting
7 # an error.
8
9+ LDFLAGS="-L. -lz"
10 LIBS=libz.a
11 SHAREDLIB=libz.so
12 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
13***************
14*** 116,121 ****
15--- 117,128 ----
16 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
17 CFLAGS=${CFLAGS-"-O"}
18 LDSHARED=${LDSHARED-"cc -G"};;
19+ AIX*)
20+ SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
21+ CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
22+ LDTESTSHARED=${LDSHARED-"cc -G"}
23+ LDSHAREDFLAGS="-L. libz.so"
24+ LDSHARED=${LDSHARED-"cc -G"};;
25 # send working options for other systems to support@gzip.org
26 *) SFLAGS=${CFLAGS-"-O"}
27 CFLAGS=${CFLAGS-"-O"}
28***************
29*** 127,135 ****
30 echo Checking for shared library support...
31 # we must test in two steps (cc then ld), required at least on SunOS 4.x
32 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
33! test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
34 CFLAGS="$SFLAGS"
35 LIBS="$SHAREDLIB.$VER"
36 echo Building shared library $SHAREDLIB.$VER with $CC.
37 elif test -z "$old_cc" -a -z "$old_cflags"; then
38 echo No shared library suppport.
39--- 134,143 ----
40 echo Checking for shared library support...
41 # we must test in two steps (cc then ld), required at least on SunOS 4.x
42 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
43! test "`($LDTESTSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
44 CFLAGS="$SFLAGS"
45 LIBS="$SHAREDLIB.$VER"
46+ LDFLAGS="$LDSHAREDFLAGS"
47 echo Building shared library $SHAREDLIB.$VER with $CC.
48 elif test -z "$old_cc" -a -z "$old_cflags"; then
49 echo No shared library suppport.
50***************
51*** 209,212 ****
52--- 217,221 ----
53 /^exec_prefix *=/s%=.*%=$exec_prefix%
54 /^libdir *=/s%=.*%=$libdir%
55 /^includedir *=/s%=.*%=$includedir%
56+ /^LDFLAGS *=/s%=.*%=$LDFLAGS%
57 " > Makefile
diff --git a/aix/mkexps b/aix/mkexps
deleted file mode 100644
index 6c55eae..0000000
--- a/aix/mkexps
+++ /dev/null
@@ -1,37 +0,0 @@
1#!/bin/ksh
2#
3# mkexps - make export list
4# This program creates an export list by combining all the "." and normal names
5# into one list.
6#
7if [[ "$#" -ne 1 ]]
8then
9 print "Usage: mkexps ArchiveFile"
10 exit -2
11fi
12if [[ ! -f $1 ]]
13then
14 print "mkexps: Cannot open file \"$1\""
15 exit -1
16fi
17
18dump -g $1 | awk '
19BEGIN {
20 top = 1
21}
22/^[ ]*[0-9][0-9]*/ {
23 if ( (n = index( $2, "." )) > 0 ) {
24 export_array[ top++ ] = substr( $2, n+1, length( $2 ))
25 }
26 else {
27 export_array[ top++ ] = $2
28 }
29}
30
31END {
32 for ( i = 1; i < top; i++ )
33 {
34 print export_array[ i ]
35 }
36
37}' | sort | uniq
diff --git a/algorithm.txt b/algorithm.txt
index f64f7c3..a049765 100644
--- a/algorithm.txt
+++ b/algorithm.txt
@@ -206,4 +206,4 @@ Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
206pp. 337-343. 206pp. 337-343.
207 207
208``DEFLATE Compressed Data Format Specification'' available in 208``DEFLATE Compressed Data Format Specification'' available in
209ftp://ds.internic.net/rfc/rfc1951.txt 209http://www.ietf.org/rfc/rfc1951.txt
diff --git a/compress.c b/compress.c
index f10e234..fbee085 100644
--- a/compress.c
+++ b/compress.c
@@ -5,6 +5,7 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#define ZLIB_INTERNAL
8#include "zlib.h" 9#include "zlib.h"
9 10
10/* =========================================================================== 11/* ===========================================================================
diff --git a/configure b/configure
index 51ef10f..68bfc88 100755
--- a/configure
+++ b/configure
@@ -19,6 +19,7 @@
19# an error. 19# an error.
20 20
21LIBS=libz.a 21LIBS=libz.a
22LDFLAGS="-L. ${LIBS}"
22SHAREDLIB=libz.so 23SHAREDLIB=libz.so
23VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` 24VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
24AR=${AR-"ar rc"} 25AR=${AR-"ar rc"}
@@ -53,6 +54,10 @@ case "$1" in
53 esac 54 esac
54done 55done
55 56
57if [ $shared -eq 1 ]; then
58 LDFLAGS="-L. ${SHAREDLIB}"
59fi
60
56test=ztest$$ 61test=ztest$$
57cat > $test.c <<EOF 62cat > $test.c <<EOF
58extern int getchar(); 63extern int getchar();
@@ -123,6 +128,10 @@ else
123 SFLAGS=${CFLAGS-"-KPIC -O"} 128 SFLAGS=${CFLAGS-"-KPIC -O"}
124 CFLAGS=${CFLAGS-"-O"} 129 CFLAGS=${CFLAGS-"-O"}
125 LDSHARED=${LDSHARED-"cc -G"};; 130 LDSHARED=${LDSHARED-"cc -G"};;
131 AIX*) # Courtesy of dbakker@arrayasolutions.com
132 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
133 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
134 LDSHARED=${LDSHARED-"xlc -G"};;
126 # send working options for other systems to support@gzip.org 135 # send working options for other systems to support@gzip.org
127 *) SFLAGS=${CFLAGS-"-O"} 136 *) SFLAGS=${CFLAGS-"-O"}
128 CFLAGS=${CFLAGS-"-O"} 137 CFLAGS=${CFLAGS-"-O"}
@@ -422,4 +431,5 @@ sed < Makefile.in "
422/^exec_prefix *=/s%=.*%=$exec_prefix% 431/^exec_prefix *=/s%=.*%=$exec_prefix%
423/^libdir *=/s%=.*%=$libdir% 432/^libdir *=/s%=.*%=$libdir%
424/^includedir *=/s%=.*%=$includedir% 433/^includedir *=/s%=.*%=$includedir%
434/^LDFLAGS *=/s%=.*%=$LDFLAGS%
425" > Makefile 435" > Makefile
diff --git a/contrib/iostream3/README b/contrib/iostream3/README
new file mode 100644
index 0000000..6f73d58
--- /dev/null
+++ b/contrib/iostream3/README
@@ -0,0 +1,35 @@
1These classes provide a C++ stream interface to the zlib library. It allows you
2to do things like:
3
4 gzofstream outf("blah.gz");
5 outf << "These go into the gzip file " << 123 << endl;
6
7It does this by deriving a specialized stream buffer for gzipped files, which is
8the way Stroustrup would have done it. :->
9
10The gzifstream and gzofstream classes were originally written by Kevin Ruland
11and made available in the zlib contrib/iostream directory. The older version still
12compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of
13this version.
14
15The new classes are as standard-compliant as possible, closely following the
16approach of the standard library's fstream classes. It compiles under gcc versions
173.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard
18library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs
19from the previous one in the following respects:
20- added showmanyc
21- added setbuf, with support for unbuffered output via setbuf(0,0)
22- a few bug fixes of stream behavior
23- gzipped output file opened with default compression level instead of maximum level
24- setcompressionlevel()/strategy() members replaced by single setcompression()
25
26The code is provided "as is", with the permission to use, copy, modify, distribute
27and sell it for any purpose without fee.
28
29Ludwig Schwardt
30<schwardt@sun.ac.za>
31
32DSP Lab
33Electrical & Electronic Engineering Department
34University of Stellenbosch
35South Africa
diff --git a/contrib/iostream3/TODO b/contrib/iostream3/TODO
new file mode 100644
index 0000000..4578326
--- /dev/null
+++ b/contrib/iostream3/TODO
@@ -0,0 +1,17 @@
1Possible upgrades to gzfilebuf:
2
3- The ability to do putback (e.g. putbackfail)
4
5- The ability to seek (zlib supports this, but could be slow/tricky)
6
7- Simultaneous read/write access (does it make sense?)
8
9- Support for ios_base::ate open mode
10
11- Locale support?
12
13- Check public interface to see which calls give problems
14 (due to dependence on library internals)
15
16- Override operator<<(ostream&, gzfilebuf*) to allow direct copying
17 of stream buffer to stream ( i.e. os << is.rdbuf(); )
diff --git a/contrib/iostream3/test.cc b/contrib/iostream3/test.cc
new file mode 100644
index 0000000..9ffa8be
--- /dev/null
+++ b/contrib/iostream3/test.cc
@@ -0,0 +1,50 @@
1/*
2 * Test program for gzifstream and gzofstream
3 *
4 * by Ludwig Schwardt <schwardt@sun.ac.za>
5 * original version by Kevin Ruland <kevin@rodin.wustl.edu>
6 */
7
8#include "zfstream.h"
9#include <iostream> // for cout
10
11int main() {
12
13 gzofstream outf;
14 gzifstream inf;
15 char buf[80];
16
17 outf.open("test1.txt.gz");
18 outf << "The quick brown fox sidestepped the lazy canine\n"
19 << 1.3 << "\nPlan " << 9 << std::endl;
20 outf.close();
21 std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n"
22 << "The quick brown fox sidestepped the lazy canine\n"
23 << 1.3 << "\nPlan " << 9 << std::endl;
24
25 std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n";
26 inf.open("test1.txt.gz");
27 while (inf.getline(buf,80,'\n')) {
28 std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
29 }
30 inf.close();
31
32 outf.rdbuf()->pubsetbuf(0,0);
33 outf.open("test2.txt.gz");
34 outf << setcompression(Z_NO_COMPRESSION)
35 << "The quick brown fox sidestepped the lazy canine\n"
36 << 1.3 << "\nPlan " << 9 << std::endl;
37 outf.close();
38 std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form";
39
40 std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n";
41 inf.rdbuf()->pubsetbuf(0,0);
42 inf.open("test2.txt.gz");
43 while (inf.getline(buf,80,'\n')) {
44 std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
45 }
46 inf.close();
47
48 return 0;
49
50}
diff --git a/contrib/iostream3/zfstream.cc b/contrib/iostream3/zfstream.cc
new file mode 100644
index 0000000..24d15fa
--- /dev/null
+++ b/contrib/iostream3/zfstream.cc
@@ -0,0 +1,479 @@
1/*
2 * A C++ I/O streams interface to the zlib gz* functions
3 *
4 * by Ludwig Schwardt <schwardt@sun.ac.za>
5 * original version by Kevin Ruland <kevin@rodin.wustl.edu>
6 *
7 * This version is standard-compliant and compatible with gcc 3.x.
8 */
9
10#include "zfstream.h"
11#include <cstring> // for strcpy, strcat, strlen (mode strings)
12#include <cstdio> // for BUFSIZ
13
14// Internal buffer sizes (default and "unbuffered" versions)
15#define BIGBUFSIZE BUFSIZ
16#define SMALLBUFSIZE 1
17
18/*****************************************************************************/
19
20// Default constructor
21gzfilebuf::gzfilebuf()
22: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false),
23 buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true)
24{
25 // No buffers to start with
26 this->disable_buffer();
27}
28
29// Destructor
30gzfilebuf::~gzfilebuf()
31{
32 // Sync output buffer and close only if responsible for file
33 // (i.e. attached streams should be left open at this stage)
34 this->sync();
35 if (own_fd)
36 this->close();
37 // Make sure internal buffer is deallocated
38 this->disable_buffer();
39}
40
41// Set compression level and strategy
42int
43gzfilebuf::setcompression(int comp_level,
44 int comp_strategy)
45{
46 return gzsetparams(file, comp_level, comp_strategy);
47}
48
49// Open gzipped file
50gzfilebuf*
51gzfilebuf::open(const char *name,
52 std::ios_base::openmode mode)
53{
54 // Fail if file already open
55 if (this->is_open())
56 return NULL;
57 // Don't support simultaneous read/write access (yet)
58 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
59 return NULL;
60
61 // Build mode string for gzopen and check it [27.8.1.3.2]
62 char char_mode[6] = "\0\0\0\0\0";
63 if (!this->open_mode(mode, char_mode))
64 return NULL;
65
66 // Attempt to open file
67 if ((file = gzopen(name, char_mode)) == NULL)
68 return NULL;
69
70 // On success, allocate internal buffer and set flags
71 this->enable_buffer();
72 io_mode = mode;
73 own_fd = true;
74 return this;
75}
76
77// Attach to gzipped file
78gzfilebuf*
79gzfilebuf::attach(int fd,
80 std::ios_base::openmode mode)
81{
82 // Fail if file already open
83 if (this->is_open())
84 return NULL;
85 // Don't support simultaneous read/write access (yet)
86 if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
87 return NULL;
88
89 // Build mode string for gzdopen and check it [27.8.1.3.2]
90 char char_mode[6] = "\0\0\0\0\0";
91 if (!this->open_mode(mode, char_mode))
92 return NULL;
93
94 // Attempt to attach to file
95 if ((file = gzdopen(fd, char_mode)) == NULL)
96 return NULL;
97
98 // On success, allocate internal buffer and set flags
99 this->enable_buffer();
100 io_mode = mode;
101 own_fd = false;
102 return this;
103}
104
105// Close gzipped file
106gzfilebuf*
107gzfilebuf::close()
108{
109 // Fail immediately if no file is open
110 if (!this->is_open())
111 return NULL;
112 // Assume success
113 gzfilebuf* retval = this;
114 // Attempt to sync and close gzipped file
115 if (this->sync() == -1)
116 retval = NULL;
117 if (gzclose(file) < 0)
118 retval = NULL;
119 // File is now gone anyway (postcondition [27.8.1.3.8])
120 file = NULL;
121 own_fd = false;
122 // Destroy internal buffer if it exists
123 this->disable_buffer();
124 return retval;
125}
126
127/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
128
129// Convert int open mode to mode string
130bool
131gzfilebuf::open_mode(std::ios_base::openmode mode,
132 char* c_mode) const
133{
134 bool testb = mode & std::ios_base::binary;
135 bool testi = mode & std::ios_base::in;
136 bool testo = mode & std::ios_base::out;
137 bool testt = mode & std::ios_base::trunc;
138 bool testa = mode & std::ios_base::app;
139
140 // Check for valid flag combinations - see [27.8.1.3.2] (Table 92)
141 // Original zfstream hardcoded the compression level to maximum here...
142 // Double the time for less than 1% size improvement seems
143 // excessive though - keeping it at the default level
144 // To change back, just append "9" to the next three mode strings
145 if (!testi && testo && !testt && !testa)
146 strcpy(c_mode, "w");
147 if (!testi && testo && !testt && testa)
148 strcpy(c_mode, "a");
149 if (!testi && testo && testt && !testa)
150 strcpy(c_mode, "w");
151 if (testi && !testo && !testt && !testa)
152 strcpy(c_mode, "r");
153 // No read/write mode yet
154// if (testi && testo && !testt && !testa)
155// strcpy(c_mode, "r+");
156// if (testi && testo && testt && !testa)
157// strcpy(c_mode, "w+");
158
159 // Mode string should be empty for invalid combination of flags
160 if (strlen(c_mode) == 0)
161 return false;
162 if (testb)
163 strcat(c_mode, "b");
164 return true;
165}
166
167// Determine number of characters in internal get buffer
168std::streamsize
169gzfilebuf::showmanyc()
170{
171 // Calls to underflow will fail if file not opened for reading
172 if (!this->is_open() || !(io_mode & std::ios_base::in))
173 return -1;
174 // Make sure get area is in use
175 if (this->gptr() && (this->gptr() < this->egptr()))
176 return std::streamsize(this->egptr() - this->gptr());
177 else
178 return 0;
179}
180
181// Fill get area from gzipped file
182gzfilebuf::int_type
183gzfilebuf::underflow()
184{
185 // If something is left in the get area by chance, return it
186 // (this shouldn't normally happen, as underflow is only supposed
187 // to be called when gptr >= egptr, but it serves as error check)
188 if (this->gptr() && (this->gptr() < this->egptr()))
189 return traits_type::to_int_type(*(this->gptr()));
190
191 // If the file hasn't been opened for reading, produce error
192 if (!this->is_open() || !(io_mode & std::ios_base::in))
193 return traits_type::eof();
194
195 // Attempt to fill internal buffer from gzipped file
196 // (buffer must be guaranteed to exist...)
197 int bytes_read = gzread(file, buffer, buffer_size);
198 // Indicates error or EOF
199 if (bytes_read <= 0)
200 {
201 // Reset get area
202 this->setg(buffer, buffer, buffer);
203 return traits_type::eof();
204 }
205 // Make all bytes read from file available as get area
206 this->setg(buffer, buffer, buffer + bytes_read);
207
208 // Return next character in get area
209 return traits_type::to_int_type(*(this->gptr()));
210}
211
212// Write put area to gzipped file
213gzfilebuf::int_type
214gzfilebuf::overflow(int_type c)
215{
216 // Determine whether put area is in use
217 if (this->pbase())
218 {
219 // Double-check pointer range
220 if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
221 return traits_type::eof();
222 // Add extra character to buffer if not EOF
223 if (!traits_type::eq_int_type(c, traits_type::eof()))
224 {
225 *(this->pptr()) = traits_type::to_char_type(c);
226 this->pbump(1);
227 }
228 // Number of characters to write to file
229 int bytes_to_write = this->pptr() - this->pbase();
230 // Overflow doesn't fail if nothing is to be written
231 if (bytes_to_write > 0)
232 {
233 // If the file hasn't been opened for writing, produce error
234 if (!this->is_open() || !(io_mode & std::ios_base::out))
235 return traits_type::eof();
236 // If gzipped file won't accept all bytes written to it, fail
237 if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write)
238 return traits_type::eof();
239 // Reset next pointer to point to pbase on success
240 this->pbump(-bytes_to_write);
241 }
242 }
243 // Write extra character to file if not EOF
244 else if (!traits_type::eq_int_type(c, traits_type::eof()))
245 {
246 // If the file hasn't been opened for writing, produce error
247 if (!this->is_open() || !(io_mode & std::ios_base::out))
248 return traits_type::eof();
249 // Impromptu char buffer (allows "unbuffered" output)
250 char_type last_char = traits_type::to_char_type(c);
251 // If gzipped file won't accept this character, fail
252 if (gzwrite(file, &last_char, 1) != 1)
253 return traits_type::eof();
254 }
255
256 // If you got here, you have succeeded (even if c was EOF)
257 // The return value should therefore be non-EOF
258 if (traits_type::eq_int_type(c, traits_type::eof()))
259 return traits_type::not_eof(c);
260 else
261 return c;
262}
263
264// Assign new buffer
265std::streambuf*
266gzfilebuf::setbuf(char_type* p,
267 std::streamsize n)
268{
269 // First make sure stuff is sync'ed, for safety
270 if (this->sync() == -1)
271 return NULL;
272 // If buffering is turned off on purpose via setbuf(0,0), still allocate one...
273 // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at
274 // least a buffer of size 1 (very inefficient though, therefore make it bigger?)
275 // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems)
276 if (!p || !n)
277 {
278 // Replace existing buffer (if any) with small internal buffer
279 this->disable_buffer();
280 buffer = NULL;
281 buffer_size = 0;
282 own_buffer = true;
283 this->enable_buffer();
284 }
285 else
286 {
287 // Replace existing buffer (if any) with external buffer
288 this->disable_buffer();
289 buffer = p;
290 buffer_size = n;
291 own_buffer = false;
292 this->enable_buffer();
293 }
294 return this;
295}
296
297// Write put area to gzipped file (i.e. ensures that put area is empty)
298int
299gzfilebuf::sync()
300{
301 return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0;
302}
303
304/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
305
306// Allocate internal buffer
307void
308gzfilebuf::enable_buffer()
309{
310 // If internal buffer required, allocate one
311 if (own_buffer && !buffer)
312 {
313 // Check for buffered vs. "unbuffered"
314 if (buffer_size > 0)
315 {
316 // Allocate internal buffer
317 buffer = new char_type[buffer_size];
318 // Get area starts empty and will be expanded by underflow as need arises
319 this->setg(buffer, buffer, buffer);
320 // Setup entire internal buffer as put area.
321 // The one-past-end pointer actually points to the last element of the buffer,
322 // so that overflow(c) can safely add the extra character c to the sequence.
323 // These pointers remain in place for the duration of the buffer
324 this->setp(buffer, buffer + buffer_size - 1);
325 }
326 else
327 {
328 // Even in "unbuffered" case, (small?) get buffer is still required
329 buffer_size = SMALLBUFSIZE;
330 buffer = new char_type[buffer_size];
331 this->setg(buffer, buffer, buffer);
332 // "Unbuffered" means no put buffer
333 this->setp(0, 0);
334 }
335 }
336 else
337 {
338 // If buffer already allocated, reset buffer pointers just to make sure no
339 // stale chars are lying around
340 this->setg(buffer, buffer, buffer);
341 this->setp(buffer, buffer + buffer_size - 1);
342 }
343}
344
345// Destroy internal buffer
346void
347gzfilebuf::disable_buffer()
348{
349 // If internal buffer exists, deallocate it
350 if (own_buffer && buffer)
351 {
352 // Preserve unbuffered status by zeroing size
353 if (!this->pbase())
354 buffer_size = 0;
355 delete[] buffer;
356 buffer = NULL;
357 this->setg(0, 0, 0);
358 this->setp(0, 0);
359 }
360 else
361 {
362 // Reset buffer pointers to initial state if external buffer exists
363 this->setg(buffer, buffer, buffer);
364 if (buffer)
365 this->setp(buffer, buffer + buffer_size - 1);
366 else
367 this->setp(0, 0);
368 }
369}
370
371/*****************************************************************************/
372
373// Default constructor initializes stream buffer
374gzifstream::gzifstream()
375: std::istream(NULL), sb()
376{ this->init(&sb); }
377
378// Initialize stream buffer and open file
379gzifstream::gzifstream(const char* name,
380 std::ios_base::openmode mode)
381: std::istream(NULL), sb()
382{
383 this->init(&sb);
384 this->open(name, mode);
385}
386
387// Initialize stream buffer and attach to file
388gzifstream::gzifstream(int fd,
389 std::ios_base::openmode mode)
390: std::istream(NULL), sb()
391{
392 this->init(&sb);
393 this->attach(fd, mode);
394}
395
396// Open file and go into fail() state if unsuccessful
397void
398gzifstream::open(const char* name,
399 std::ios_base::openmode mode)
400{
401 if (!sb.open(name, mode | std::ios_base::in))
402 this->setstate(std::ios_base::failbit);
403 else
404 this->clear();
405}
406
407// Attach to file and go into fail() state if unsuccessful
408void
409gzifstream::attach(int fd,
410 std::ios_base::openmode mode)
411{
412 if (!sb.attach(fd, mode | std::ios_base::in))
413 this->setstate(std::ios_base::failbit);
414 else
415 this->clear();
416}
417
418// Close file
419void
420gzifstream::close()
421{
422 if (!sb.close())
423 this->setstate(std::ios_base::failbit);
424}
425
426/*****************************************************************************/
427
428// Default constructor initializes stream buffer
429gzofstream::gzofstream()
430: std::ostream(NULL), sb()
431{ this->init(&sb); }
432
433// Initialize stream buffer and open file
434gzofstream::gzofstream(const char* name,
435 std::ios_base::openmode mode)
436: std::ostream(NULL), sb()
437{
438 this->init(&sb);
439 this->open(name, mode);
440}
441
442// Initialize stream buffer and attach to file
443gzofstream::gzofstream(int fd,
444 std::ios_base::openmode mode)
445: std::ostream(NULL), sb()
446{
447 this->init(&sb);
448 this->attach(fd, mode);
449}
450
451// Open file and go into fail() state if unsuccessful
452void
453gzofstream::open(const char* name,
454 std::ios_base::openmode mode)
455{
456 if (!sb.open(name, mode | std::ios_base::out))
457 this->setstate(std::ios_base::failbit);
458 else
459 this->clear();
460}
461
462// Attach to file and go into fail() state if unsuccessful
463void
464gzofstream::attach(int fd,
465 std::ios_base::openmode mode)
466{
467 if (!sb.attach(fd, mode | std::ios_base::out))
468 this->setstate(std::ios_base::failbit);
469 else
470 this->clear();
471}
472
473// Close file
474void
475gzofstream::close()
476{
477 if (!sb.close())
478 this->setstate(std::ios_base::failbit);
479}
diff --git a/contrib/iostream3/zfstream.h b/contrib/iostream3/zfstream.h
new file mode 100644
index 0000000..ad76e8b
--- /dev/null
+++ b/contrib/iostream3/zfstream.h
@@ -0,0 +1,466 @@
1/*
2 * A C++ I/O streams interface to the zlib gz* functions
3 *
4 * by Ludwig Schwardt <schwardt@sun.ac.za>
5 * original version by Kevin Ruland <kevin@rodin.wustl.edu>
6 *
7 * This version is standard-compliant and compatible with gcc 3.x.
8 */
9
10#ifndef ZFSTREAM_H
11#define ZFSTREAM_H
12
13#include <istream> // not iostream, since we don't need cin/cout
14#include <ostream>
15#include "zlib.h"
16
17/*****************************************************************************/
18
19/**
20 * @brief Gzipped file stream buffer class.
21 *
22 * This class implements basic_filebuf for gzipped files. It doesn't yet support
23 * seeking (allowed by zlib but slow/limited), putback and read/write access
24 * (tricky). Otherwise, it attempts to be a drop-in replacement for the standard
25 * file streambuf.
26*/
27class gzfilebuf : public std::streambuf
28{
29public:
30 // Default constructor.
31 gzfilebuf();
32
33 // Destructor.
34 virtual
35 ~gzfilebuf();
36
37 /**
38 * @brief Set compression level and strategy on the fly.
39 * @param comp_level Compression level (see zlib.h for allowed values)
40 * @param comp_strategy Compression strategy (see zlib.h for allowed values)
41 * @return Z_OK on success, Z_STREAM_ERROR otherwise.
42 *
43 * Unfortunately, these parameters cannot be modified separately, as the
44 * previous zfstream version assumed. Since the strategy is seldom changed,
45 * it can default and setcompression(level) then becomes like the old
46 * setcompressionlevel(level).
47 */
48 int
49 setcompression(int comp_level,
50 int comp_strategy = Z_DEFAULT_STRATEGY);
51
52 /**
53 * @brief Check if file is open.
54 * @return True if file is open.
55 */
56 bool
57 is_open() const { return (file != NULL); }
58
59 /**
60 * @brief Open gzipped file.
61 * @param name File name.
62 * @param mode Open mode flags.
63 * @return @c this on success, NULL on failure.
64 */
65 gzfilebuf*
66 open(const char* name,
67 std::ios_base::openmode mode);
68
69 /**
70 * @brief Attach to already open gzipped file.
71 * @param fd File descriptor.
72 * @param mode Open mode flags.
73 * @return @c this on success, NULL on failure.
74 */
75 gzfilebuf*
76 attach(int fd,
77 std::ios_base::openmode mode);
78
79 /**
80 * @brief Close gzipped file.
81 * @return @c this on success, NULL on failure.
82 */
83 gzfilebuf*
84 close();
85
86protected:
87 /**
88 * @brief Convert ios open mode int to mode string used by zlib.
89 * @return True if valid mode flag combination.
90 */
91 bool
92 open_mode(std::ios_base::openmode mode,
93 char* c_mode) const;
94
95 /**
96 * @brief Number of characters available in stream buffer.
97 * @return Number of characters.
98 *
99 * This indicates number of characters in get area of stream buffer.
100 * These characters can be read without accessing the gzipped file.
101 */
102 virtual std::streamsize
103 showmanyc();
104
105 /**
106 * @brief Fill get area from gzipped file.
107 * @return First character in get area on success, EOF on error.
108 *
109 * This actually reads characters from gzipped file to stream
110 * buffer. Always buffered.
111 */
112 virtual int_type
113 underflow();
114
115 /**
116 * @brief Write put area to gzipped file.
117 * @param c Extra character to add to buffer contents.
118 * @return Non-EOF on success, EOF on error.
119 *
120 * This actually writes characters in stream buffer to
121 * gzipped file. With unbuffered output this is done one
122 * character at a time.
123 */
124 virtual int_type
125 overflow(int_type c = traits_type::eof());
126
127 /**
128 * @brief Installs external stream buffer.
129 * @param p Pointer to char buffer.
130 * @param n Size of external buffer.
131 * @return @c this on success, NULL on failure.
132 *
133 * Call setbuf(0,0) to enable unbuffered output.
134 */
135 virtual std::streambuf*
136 setbuf(char_type* p,
137 std::streamsize n);
138
139 /**
140 * @brief Flush stream buffer to file.
141 * @return 0 on success, -1 on error.
142 *
143 * This calls underflow(EOF) to do the job.
144 */
145 virtual int
146 sync();
147
148//
149// Some future enhancements
150//
151// virtual int_type uflow();
152// virtual int_type pbackfail(int_type c = traits_type::eof());
153// virtual pos_type
154// seekoff(off_type off,
155// std::ios_base::seekdir way,
156// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
157// virtual pos_type
158// seekpos(pos_type sp,
159// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
160
161private:
162 /**
163 * @brief Allocate internal buffer.
164 *
165 * This function is safe to call multiple times. It will ensure
166 * that a proper internal buffer exists if it is required. If the
167 * buffer already exists or is external, the buffer pointers will be
168 * reset to their original state.
169 */
170 void
171 enable_buffer();
172
173 /**
174 * @brief Destroy internal buffer.
175 *
176 * This function is safe to call multiple times. It will ensure
177 * that the internal buffer is deallocated if it exists. In any
178 * case, it will also reset the buffer pointers.
179 */
180 void
181 disable_buffer();
182
183 /**
184 * Underlying file pointer.
185 */
186 gzFile file;
187
188 /**
189 * Mode in which file was opened.
190 */
191 std::ios_base::openmode io_mode;
192
193 /**
194 * @brief True if this object owns file descriptor.
195 *
196 * This makes the class responsible for closing the file
197 * upon destruction.
198 */
199 bool own_fd;
200
201 /**
202 * @brief Stream buffer.
203 *
204 * For simplicity this remains allocated on the free store for the
205 * entire life span of the gzfilebuf object, unless replaced by setbuf.
206 */
207 char_type* buffer;
208
209 /**
210 * @brief Stream buffer size.
211 *
212 * Defaults to system default buffer size (typically 8192 bytes).
213 * Modified by setbuf.
214 */
215 std::streamsize buffer_size;
216
217 /**
218 * @brief True if this object owns stream buffer.
219 *
220 * This makes the class responsible for deleting the buffer
221 * upon destruction.
222 */
223 bool own_buffer;
224};
225
226/*****************************************************************************/
227
228/**
229 * @brief Gzipped file input stream class.
230 *
231 * This class implements ifstream for gzipped files. Seeking and putback
232 * is not supported yet.
233*/
234class gzifstream : public std::istream
235{
236public:
237 // Default constructor
238 gzifstream();
239
240 /**
241 * @brief Construct stream on gzipped file to be opened.
242 * @param name File name.
243 * @param mode Open mode flags (forced to contain ios::in).
244 */
245 explicit
246 gzifstream(const char* name,
247 std::ios_base::openmode mode = std::ios_base::in);
248
249 /**
250 * @brief Construct stream on already open gzipped file.
251 * @param fd File descriptor.
252 * @param mode Open mode flags (forced to contain ios::in).
253 */
254 explicit
255 gzifstream(int fd,
256 std::ios_base::openmode mode = std::ios_base::in);
257
258 /**
259 * Obtain underlying stream buffer.
260 */
261 gzfilebuf*
262 rdbuf() const
263 { return const_cast<gzfilebuf*>(&sb); }
264
265 /**
266 * @brief Check if file is open.
267 * @return True if file is open.
268 */
269 bool
270 is_open() { return sb.is_open(); }
271
272 /**
273 * @brief Open gzipped file.
274 * @param name File name.
275 * @param mode Open mode flags (forced to contain ios::in).
276 *
277 * Stream will be in state good() if file opens successfully;
278 * otherwise in state fail(). This differs from the behavior of
279 * ifstream, which never sets the state to good() and therefore
280 * won't allow you to reuse the stream for a second file unless
281 * you manually clear() the state. The choice is a matter of
282 * convenience.
283 */
284 void
285 open(const char* name,
286 std::ios_base::openmode mode = std::ios_base::in);
287
288 /**
289 * @brief Attach to already open gzipped file.
290 * @param fd File descriptor.
291 * @param mode Open mode flags (forced to contain ios::in).
292 *
293 * Stream will be in state good() if attach succeeded; otherwise
294 * in state fail().
295 */
296 void
297 attach(int fd,
298 std::ios_base::openmode mode = std::ios_base::in);
299
300 /**
301 * @brief Close gzipped file.
302 *
303 * Stream will be in state fail() if close failed.
304 */
305 void
306 close();
307
308private:
309 /**
310 * Underlying stream buffer.
311 */
312 gzfilebuf sb;
313};
314
315/*****************************************************************************/
316
317/**
318 * @brief Gzipped file output stream class.
319 *
320 * This class implements ofstream for gzipped files. Seeking and putback
321 * is not supported yet.
322*/
323class gzofstream : public std::ostream
324{
325public:
326 // Default constructor
327 gzofstream();
328
329 /**
330 * @brief Construct stream on gzipped file to be opened.
331 * @param name File name.
332 * @param mode Open mode flags (forced to contain ios::out).
333 */
334 explicit
335 gzofstream(const char* name,
336 std::ios_base::openmode mode = std::ios_base::out);
337
338 /**
339 * @brief Construct stream on already open gzipped file.
340 * @param fd File descriptor.
341 * @param mode Open mode flags (forced to contain ios::out).
342 */
343 explicit
344 gzofstream(int fd,
345 std::ios_base::openmode mode = std::ios_base::out);
346
347 /**
348 * Obtain underlying stream buffer.
349 */
350 gzfilebuf*
351 rdbuf() const
352 { return const_cast<gzfilebuf*>(&sb); }
353
354 /**
355 * @brief Check if file is open.
356 * @return True if file is open.
357 */
358 bool
359 is_open() { return sb.is_open(); }
360
361 /**
362 * @brief Open gzipped file.
363 * @param name File name.
364 * @param mode Open mode flags (forced to contain ios::out).
365 *
366 * Stream will be in state good() if file opens successfully;
367 * otherwise in state fail(). This differs from the behavior of
368 * ofstream, which never sets the state to good() and therefore
369 * won't allow you to reuse the stream for a second file unless
370 * you manually clear() the state. The choice is a matter of
371 * convenience.
372 */
373 void
374 open(const char* name,
375 std::ios_base::openmode mode = std::ios_base::out);
376
377 /**
378 * @brief Attach to already open gzipped file.
379 * @param fd File descriptor.
380 * @param mode Open mode flags (forced to contain ios::out).
381 *
382 * Stream will be in state good() if attach succeeded; otherwise
383 * in state fail().
384 */
385 void
386 attach(int fd,
387 std::ios_base::openmode mode = std::ios_base::out);
388
389 /**
390 * @brief Close gzipped file.
391 *
392 * Stream will be in state fail() if close failed.
393 */
394 void
395 close();
396
397private:
398 /**
399 * Underlying stream buffer.
400 */
401 gzfilebuf sb;
402};
403
404/*****************************************************************************/
405
406/**
407 * @brief Gzipped file output stream manipulator class.
408 *
409 * This class defines a two-argument manipulator for gzofstream. It is used
410 * as base for the setcompression(int,int) manipulator.
411*/
412template<typename T1, typename T2>
413 class gzomanip2
414 {
415 public:
416 // Allows insertor to peek at internals
417 template <typename Ta, typename Tb>
418 friend gzofstream&
419 operator<<(gzofstream&,
420 const gzomanip2<Ta,Tb>&);
421
422 // Constructor
423 gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2),
424 T1 v1,
425 T2 v2);
426 private:
427 // Underlying manipulator function
428 gzofstream&
429 (*func)(gzofstream&, T1, T2);
430
431 // Arguments for manipulator function
432 T1 val1;
433 T2 val2;
434 };
435
436/*****************************************************************************/
437
438// Manipulator function thunks through to stream buffer
439inline gzofstream&
440setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY)
441{
442 (gzs.rdbuf())->setcompression(l, s);
443 return gzs;
444}
445
446// Manipulator constructor stores arguments
447template<typename T1, typename T2>
448 inline
449 gzomanip2<T1,T2>::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2),
450 T1 v1,
451 T2 v2)
452 : func(f), val1(v1), val2(v2)
453 { }
454
455// Insertor applies underlying manipulator function to stream
456template<typename T1, typename T2>
457 inline gzofstream&
458 operator<<(gzofstream& s, const gzomanip2<T1,T2>& m)
459 { return (*m.func)(s, m.val1, m.val2); }
460
461// Insert this onto stream to simplify setting of compression level
462inline gzomanip2<int,int>
463setcompression(int l, int s = Z_DEFAULT_STRATEGY)
464{ return gzomanip2<int,int>(&setcompression, l, s); }
465
466#endif // ZFSTREAM_H
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip
index 18316fc..45fd099 100644
--- a/contrib/minizip/ChangeLogUnzip
+++ b/contrib/minizip/ChangeLogUnzip
@@ -1,47 +1,51 @@
1Change in 0.21: (10 Mar 03) 1Change in 0.22: (19 May 03)
2- bug fixes 2- crypting support (unless you define NOCRYPT)
3 3- append file in existing zipfile
4Change in 0.17: (27 Jan 02) 4
5- bug fixes 5Change in 0.21: (10 Mar 03)
6 6- bug fixes
7Change in 0.16: (19 Jan 02) 7
8- Support of ioapi for virtualize zip file access 8Change in 0.17: (27 Jan 02)
9 9- bug fixes
10Change in 0.15: (19 Mar 98) 10
11- fix memory leak in minizip.c 11Change in 0.16: (19 Jan 02)
12 12- Support of ioapi for virtualize zip file access
13Change in 0.14: (10 Mar 98) 13
14- fix bugs in minizip.c sample for zipping big file 14Change in 0.15: (19 Mar 98)
15- fix problem in month in date handling 15- fix memory leak in minizip.c
16- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for 16
17 comment handling 17Change in 0.14: (10 Mar 98)
18 18- fix bugs in minizip.c sample for zipping big file
19Change in 0.13: (6 Mar 98) 19- fix problem in month in date handling
20- fix bugs in zip.c 20- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
21- add real minizip sample 21 comment handling
22 22
23Change in 0.12: (4 Mar 98) 23Change in 0.13: (6 Mar 98)
24- add zip.c and zip.h for creates .zip file 24- fix bugs in zip.c
25- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) 25- add real minizip sample
26- fix miniunz.c for file without specific record for directory 26
27 27Change in 0.12: (4 Mar 98)
28Change in 0.11: (3 Mar 98) 28- add zip.c and zip.h for creates .zip file
29- fix bug in unzGetCurrentFileInfo for get extra field and comment 29- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
30- enhance miniunz sample, remove the bad unztst.c sample 30- fix miniunz.c for file without specific record for directory
31 31
32Change in 0.10: (2 Mar 98) 32Change in 0.11: (3 Mar 98)
33- fix bug in unzReadCurrentFile 33- fix bug in unzGetCurrentFileInfo for get extra field and comment
34- rename unzip* to unz* function and structure 34- enhance miniunz sample, remove the bad unztst.c sample
35- remove Windows-like hungary notation variable name 35
36- modify some structure in unzip.h 36Change in 0.10: (2 Mar 98)
37- add somes comment in source 37- fix bug in unzReadCurrentFile
38- remove unzipGetcCurrentFile function 38- rename unzip* to unz* function and structure
39- replace ZUNZEXPORT by ZEXPORT 39- remove Windows-like hungary notation variable name
40- add unzGetLocalExtrafield for get the local extrafield info 40- modify some structure in unzip.h
41- add a new sample, miniunz.c 41- add somes comment in source
42 42- remove unzipGetcCurrentFile function
43Change in 0.4: (25 Feb 98) 43- replace ZUNZEXPORT by ZEXPORT
44- suppress the type unzipFileInZip. 44- add unzGetLocalExtrafield for get the local extrafield info
45 Only on file in the zipfile can be open at the same time 45- add a new sample, miniunz.c
46- fix somes typo in code 46
47- added tm_unz structure in unzip_file_info (date/time in readable format) 47Change in 0.4: (25 Feb 98)
48- suppress the type unzipFileInZip.
49 Only on file in the zipfile can be open at the same time
50- fix somes typo in code
51- 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 @@
1CC=cc 1CC=cc
2CFLAGS=-O -I../.. 2CFLAGS=-O -I../..
3 3
4UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a 4UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
5ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a 5ZIP_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
10all: miniunz minizip 10all: miniunz minizip
11 11
12miniunz: $(UNZ_OBJS) 12miniunz: $(UNZ_OBJS)
13 $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) 13 $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
14 14
15minizip: $(ZIP_OBJS) 15minizip: $(ZIP_OBJS)
16 $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) 16 $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
17 17
18test: miniunz minizip 18test: 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
24clean: 24clean:
25 /bin/rm -f *.o *~ minizip miniunz 25 /bin/rm -f *.o *~ minizip miniunz
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h
index e5bc627..83e763c 100644
--- a/contrib/minizip/crypt.h
+++ b/contrib/minizip/crypt.h
@@ -1,104 +1,104 @@
1 1
2#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 2#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
3 3
4/*********************************************************************** 4/***********************************************************************
5 * Return the next byte in the pseudo-random sequence 5 * Return the next byte in the pseudo-random sequence
6 */ 6 */
7static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 7static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
8{ 8{
9 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 9 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
10 * unpredictable manner on 16-bit systems; not a problem 10 * unpredictable manner on 16-bit systems; not a problem
11 * with any known compiler so far, though */ 11 * with any known compiler so far, though */
12 12
13 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 13 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
14 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 14 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
15} 15}
16 16
17/*********************************************************************** 17/***********************************************************************
18 * Update the encryption keys with the next byte of plain text 18 * Update the encryption keys with the next byte of plain text
19 */ 19 */
20static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 20static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
21{ 21{
22 (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 22 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
23 (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 23 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
24 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 24 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
25 { 25 {
26 register int keyshift = (int)((*(pkeys+1)) >> 24); 26 register int keyshift = (int)((*(pkeys+1)) >> 24);
27 (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 27 (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
28 } 28 }
29 return c; 29 return c;
30} 30}
31 31
32 32
33/*********************************************************************** 33/***********************************************************************
34 * Initialize the encryption keys and the random header according to 34 * Initialize the encryption keys and the random header according to
35 * the given password. 35 * the given password.
36 */ 36 */
37static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 37static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
38{ 38{
39 *(pkeys+0) = 305419896L; 39 *(pkeys+0) = 305419896L;
40 *(pkeys+1) = 591751049L; 40 *(pkeys+1) = 591751049L;
41 *(pkeys+2) = 878082192L; 41 *(pkeys+2) = 878082192L;
42 while (*passwd != '\0') { 42 while (*passwd != '\0') {
43 update_keys(pkeys,pcrc_32_tab,(int)*passwd); 43 update_keys(pkeys,pcrc_32_tab,(int)*passwd);
44 passwd++; 44 passwd++;
45 } 45 }
46} 46}
47 47
48#define zdecode(pkeys,pcrc_32_tab,c) \ 48#define zdecode(pkeys,pcrc_32_tab,c) \
49 (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 49 (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
50 50
51#define zencode(pkeys,pcrc_32_tab,c,t) \ 51#define zencode(pkeys,pcrc_32_tab,c,t) \
52 (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 52 (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
53 53
54#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 54#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
55 55
56#define RAND_HEAD_LEN 12 56#define RAND_HEAD_LEN 12
57 /* "last resort" source for second part of crypt seed pattern */ 57 /* "last resort" source for second part of crypt seed pattern */
58# ifndef ZCR_SEED2 58# ifndef ZCR_SEED2
59# define ZCR_SEED2 (unsigned long)3141592654L /* use PI as default pattern */ 59# define ZCR_SEED2 (unsigned long)3141592654L /* use PI as default pattern */
60# endif 60# endif
61 61
62static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 62static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
63 const char *passwd; /* password string */ 63 const char *passwd; /* password string */
64 unsigned char *buf; /* where to write header */ 64 unsigned char *buf; /* where to write header */
65 int bufSize; 65 int bufSize;
66 unsigned long* pkeys; 66 unsigned long* pkeys;
67 const unsigned long* pcrc_32_tab; 67 const unsigned long* pcrc_32_tab;
68 unsigned long crcForCrypting; 68 unsigned long crcForCrypting;
69{ 69{
70 int n; /* index in random header */ 70 int n; /* index in random header */
71 int t; /* temporary */ 71 int t; /* temporary */
72 int c; /* random byte */ 72 int c; /* random byte */
73 unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 73 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
74 static unsigned calls = 0; /* ensure different random header each time */ 74 static unsigned calls = 0; /* ensure different random header each time */
75 75
76 if (bufSize<RAND_HEAD_LEN) 76 if (bufSize<RAND_HEAD_LEN)
77 return 0; 77 return 0;
78 78
79 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the 79 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
80 * output of rand() to get less predictability, since rand() is 80 * output of rand() to get less predictability, since rand() is
81 * often poorly implemented. 81 * often poorly implemented.
82 */ 82 */
83 if (++calls == 1) 83 if (++calls == 1)
84 { 84 {
85 srand((unsigned)(time(NULL) ^ ZCR_SEED2)); 85 srand((unsigned)(time(NULL) ^ ZCR_SEED2));
86 } 86 }
87 init_keys(passwd, pkeys, pcrc_32_tab); 87 init_keys(passwd, pkeys, pcrc_32_tab);
88 for (n = 0; n < RAND_HEAD_LEN-2; n++) 88 for (n = 0; n < RAND_HEAD_LEN-2; n++)
89 { 89 {
90 c = (rand() >> 7) & 0xff; 90 c = (rand() >> 7) & 0xff;
91 header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 91 header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
92 } 92 }
93 /* Encrypt random header (last two bytes is high word of crc) */ 93 /* Encrypt random header (last two bytes is high word of crc) */
94 init_keys(passwd, pkeys, pcrc_32_tab); 94 init_keys(passwd, pkeys, pcrc_32_tab);
95 for (n = 0; n < RAND_HEAD_LEN-2; n++) 95 for (n = 0; n < RAND_HEAD_LEN-2; n++)
96 { 96 {
97 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 97 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
98 } 98 }
99 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 99 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
100 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 100 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
101 return n; 101 return n;
102} 102}
103 103
104#endif 104#endif
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
index d35d5f5..61c6e2b 100644
--- a/contrib/minizip/ioapi.c
+++ b/contrib/minizip/ioapi.c
@@ -1,177 +1,177 @@
1/* ioapi.c -- IO base function header for compress/uncompress .zip 1/* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 files using zlib + zip or unzip API
3 3
4 Version 0.21, March 10th, 2003 4 Version 0.22, May 19th, 2003
5 5
6 Copyright (C) 1998-2003 Gilles Vollant 6 Copyright (C) 1998-2003 Gilles Vollant
7*/ 7*/
8 8
9#include <stdio.h> 9#include <stdio.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <string.h> 11#include <string.h>
12 12
13#include "zlib.h" 13#include "zlib.h"
14#include "ioapi.h" 14#include "ioapi.h"
15 15
16 16
17 17
18/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 18/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
19 19
20#ifndef SEEK_CUR 20#ifndef SEEK_CUR
21#define SEEK_CUR 1 21#define SEEK_CUR 1
22#endif 22#endif
23 23
24#ifndef SEEK_END 24#ifndef SEEK_END
25#define SEEK_END 2 25#define SEEK_END 2
26#endif 26#endif
27 27
28#ifndef SEEK_SET 28#ifndef SEEK_SET
29#define SEEK_SET 0 29#define SEEK_SET 0
30#endif 30#endif
31 31
32voidpf ZCALLBACK fopen_file_func OF(( 32voidpf ZCALLBACK fopen_file_func OF((
33 voidpf opaque, 33 voidpf opaque,
34 const char* filename, 34 const char* filename,
35 int mode)); 35 int mode));
36 36
37uLong ZCALLBACK fread_file_func OF(( 37uLong ZCALLBACK fread_file_func OF((
38 voidpf opaque, 38 voidpf opaque,
39 voidpf stream, 39 voidpf stream,
40 void* buf, 40 void* buf,
41 uLong size)); 41 uLong size));
42 42
43uLong ZCALLBACK fwrite_file_func OF(( 43uLong ZCALLBACK fwrite_file_func OF((
44 voidpf opaque, 44 voidpf opaque,
45 voidpf stream, 45 voidpf stream,
46 const void* buf, 46 const void* buf,
47 uLong size)); 47 uLong size));
48 48
49long ZCALLBACK ftell_file_func OF(( 49long ZCALLBACK ftell_file_func OF((
50 voidpf opaque, 50 voidpf opaque,
51 voidpf stream)); 51 voidpf stream));
52 52
53long ZCALLBACK fseek_file_func OF(( 53long ZCALLBACK fseek_file_func OF((
54 voidpf opaque, 54 voidpf opaque,
55 voidpf stream, 55 voidpf stream,
56 uLong offset, 56 uLong offset,
57 int origin)); 57 int origin));
58 58
59int ZCALLBACK fclose_file_func OF(( 59int ZCALLBACK fclose_file_func OF((
60 voidpf opaque, 60 voidpf opaque,
61 voidpf stream)); 61 voidpf stream));
62 62
63int ZCALLBACK ferror_file_func OF(( 63int ZCALLBACK ferror_file_func OF((
64 voidpf opaque, 64 voidpf opaque,
65 voidpf stream)); 65 voidpf stream));
66 66
67 67
68voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 68voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
69 voidpf opaque; 69 voidpf opaque;
70 const char* filename; 70 const char* filename;
71 int mode; 71 int mode;
72{ 72{
73 FILE* file = NULL; 73 FILE* file = NULL;
74 const char* mode_fopen = NULL; 74 const char* mode_fopen = NULL;
75 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 75 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
76 mode_fopen = "rb"; 76 mode_fopen = "rb";
77 else 77 else
78 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 78 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
79 mode_fopen = "r+b"; 79 mode_fopen = "r+b";
80 else 80 else
81 if (mode & ZLIB_FILEFUNC_MODE_CREATE) 81 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
82 mode_fopen = "wb"; 82 mode_fopen = "wb";
83 83
84 if ((filename!=NULL) && (mode_fopen != NULL)) 84 if ((filename!=NULL) && (mode_fopen != NULL))
85 file = fopen(filename, mode_fopen); 85 file = fopen(filename, mode_fopen);
86 return file; 86 return file;
87} 87}
88 88
89 89
90uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 90uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
91 voidpf opaque; 91 voidpf opaque;
92 voidpf stream; 92 voidpf stream;
93 void* buf; 93 void* buf;
94 uLong size; 94 uLong size;
95{ 95{
96 uLong ret; 96 uLong ret;
97 ret = fread(buf, 1, (size_t)size, (FILE *)stream); 97 ret = fread(buf, 1, (size_t)size, (FILE *)stream);
98 return ret; 98 return ret;
99} 99}
100 100
101 101
102uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) 102uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
103 voidpf opaque; 103 voidpf opaque;
104 voidpf stream; 104 voidpf stream;
105 const void* buf; 105 const void* buf;
106 uLong size; 106 uLong size;
107{ 107{
108 uLong ret; 108 uLong ret;
109 ret = fwrite(buf, 1, (size_t)size, (FILE *)stream); 109 ret = fwrite(buf, 1, (size_t)size, (FILE *)stream);
110 return ret; 110 return ret;
111} 111}
112 112
113long ZCALLBACK ftell_file_func (opaque, stream) 113long ZCALLBACK ftell_file_func (opaque, stream)
114 voidpf opaque; 114 voidpf opaque;
115 voidpf stream; 115 voidpf stream;
116{ 116{
117 long ret; 117 long ret;
118 ret = ftell((FILE *)stream); 118 ret = ftell((FILE *)stream);
119 return ret; 119 return ret;
120} 120}
121 121
122long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 122long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
123 voidpf opaque; 123 voidpf opaque;
124 voidpf stream; 124 voidpf stream;
125 uLong offset; 125 uLong offset;
126 int origin; 126 int origin;
127{ 127{
128 int fseek_origin=0; 128 int fseek_origin=0;
129 long ret; 129 long ret;
130 switch (origin) 130 switch (origin)
131 { 131 {
132 case ZLIB_FILEFUNC_SEEK_CUR : 132 case ZLIB_FILEFUNC_SEEK_CUR :
133 fseek_origin = SEEK_CUR; 133 fseek_origin = SEEK_CUR;
134 break; 134 break;
135 case ZLIB_FILEFUNC_SEEK_END : 135 case ZLIB_FILEFUNC_SEEK_END :
136 fseek_origin = SEEK_END; 136 fseek_origin = SEEK_END;
137 break; 137 break;
138 case ZLIB_FILEFUNC_SEEK_SET : 138 case ZLIB_FILEFUNC_SEEK_SET :
139 fseek_origin = SEEK_SET; 139 fseek_origin = SEEK_SET;
140 break; 140 break;
141 default: return -1; 141 default: return -1;
142 } 142 }
143 ret = 0; 143 ret = 0;
144 fseek((FILE *)stream, offset, fseek_origin); 144 fseek((FILE *)stream, offset, fseek_origin);
145 return ret; 145 return ret;
146} 146}
147 147
148int ZCALLBACK fclose_file_func (opaque, stream) 148int ZCALLBACK fclose_file_func (opaque, stream)
149 voidpf opaque; 149 voidpf opaque;
150 voidpf stream; 150 voidpf stream;
151{ 151{
152 int ret; 152 int ret;
153 ret = fclose((FILE *)stream); 153 ret = fclose((FILE *)stream);
154 return ret; 154 return ret;
155} 155}
156 156
157int ZCALLBACK ferror_file_func (opaque, stream) 157int ZCALLBACK ferror_file_func (opaque, stream)
158 voidpf opaque; 158 voidpf opaque;
159 voidpf stream; 159 voidpf stream;
160{ 160{
161 int ret; 161 int ret;
162 ret = ferror((FILE *)stream); 162 ret = ferror((FILE *)stream);
163 return ret; 163 return ret;
164} 164}
165 165
166void fill_fopen_filefunc (pzlib_filefunc_def) 166void fill_fopen_filefunc (pzlib_filefunc_def)
167 zlib_filefunc_def* pzlib_filefunc_def; 167 zlib_filefunc_def* pzlib_filefunc_def;
168{ 168{
169 pzlib_filefunc_def->zopen_file = fopen_file_func; 169 pzlib_filefunc_def->zopen_file = fopen_file_func;
170 pzlib_filefunc_def->zread_file = fread_file_func; 170 pzlib_filefunc_def->zread_file = fread_file_func;
171 pzlib_filefunc_def->zwrite_file = fwrite_file_func; 171 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
172 pzlib_filefunc_def->ztell_file = ftell_file_func; 172 pzlib_filefunc_def->ztell_file = ftell_file_func;
173 pzlib_filefunc_def->zseek_file = fseek_file_func; 173 pzlib_filefunc_def->zseek_file = fseek_file_func;
174 pzlib_filefunc_def->zclose_file = fclose_file_func; 174 pzlib_filefunc_def->zclose_file = fclose_file_func;
175 pzlib_filefunc_def->zerror_file = ferror_file_func; 175 pzlib_filefunc_def->zerror_file = ferror_file_func;
176 pzlib_filefunc_def->opaque = NULL; 176 pzlib_filefunc_def->opaque = NULL;
177} 177}
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h
index f30fe7a..6b8f1f1 100644
--- a/contrib/minizip/ioapi.h
+++ b/contrib/minizip/ioapi.h
@@ -1,75 +1,75 @@
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 files using zlib + zip or unzip API
3 3
4 Version 0.21, March 10th, 2003 4 Version 0.22, May 19th, 2003
5 5
6 Copyright (C) 1998-2003 Gilles Vollant 6 Copyright (C) 1998-2003 Gilles Vollant
7*/ 7*/
8 8
9#ifndef _ZLIBIOAPI_H 9#ifndef _ZLIBIOAPI_H
10#define _ZLIBIOAPI_H 10#define _ZLIBIOAPI_H
11 11
12 12
13#define ZLIB_FILEFUNC_SEEK_CUR (1) 13#define ZLIB_FILEFUNC_SEEK_CUR (1)
14#define ZLIB_FILEFUNC_SEEK_END (2) 14#define ZLIB_FILEFUNC_SEEK_END (2)
15#define ZLIB_FILEFUNC_SEEK_SET (0) 15#define ZLIB_FILEFUNC_SEEK_SET (0)
16 16
17#define ZLIB_FILEFUNC_MODE_READ (1) 17#define ZLIB_FILEFUNC_MODE_READ (1)
18#define ZLIB_FILEFUNC_MODE_WRITE (2) 18#define ZLIB_FILEFUNC_MODE_WRITE (2)
19#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 19#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
20 20
21#define ZLIB_FILEFUNC_MODE_EXISTING (4) 21#define ZLIB_FILEFUNC_MODE_EXISTING (4)
22#define ZLIB_FILEFUNC_MODE_CREATE (8) 22#define ZLIB_FILEFUNC_MODE_CREATE (8)
23 23
24 24
25#ifndef ZCALLBACK 25#ifndef ZCALLBACK
26 26
27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
28#define ZCALLBACK CALLBACK 28#define ZCALLBACK CALLBACK
29#else 29#else
30#define ZCALLBACK 30#define ZCALLBACK
31#endif 31#endif
32#endif 32#endif
33 33
34#ifdef __cplusplus 34#ifdef __cplusplus
35extern "C" { 35extern "C" {
36#endif 36#endif
37 37
38typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 38typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
39typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 39typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
40typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 40typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
41typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 41typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
42typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 42typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
43typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 43typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
44typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 44typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
45 45
46typedef struct zlib_filefunc_def_s 46typedef struct zlib_filefunc_def_s
47{ 47{
48 open_file_func zopen_file; 48 open_file_func zopen_file;
49 read_file_func zread_file; 49 read_file_func zread_file;
50 write_file_func zwrite_file; 50 write_file_func zwrite_file;
51 tell_file_func ztell_file; 51 tell_file_func ztell_file;
52 seek_file_func zseek_file; 52 seek_file_func zseek_file;
53 close_file_func zclose_file; 53 close_file_func zclose_file;
54 testerror_file_func zerror_file; 54 testerror_file_func zerror_file;
55 voidpf opaque; 55 voidpf opaque;
56} zlib_filefunc_def; 56} zlib_filefunc_def;
57 57
58 58
59 59
60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
61 61
62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
68 68
69 69
70#ifdef __cplusplus 70#ifdef __cplusplus
71} 71}
72#endif 72#endif
73 73
74#endif 74#endif
75 75
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
index f1f5546..53198b6 100644
--- a/contrib/minizip/iowin32.c
+++ b/contrib/minizip/iowin32.c
@@ -1,271 +1,271 @@
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 files using zlib + zip or unzip API
3 This IO API version uses the Win32 API (for Microsoft Windows) 3 This IO API version uses the Win32 API (for Microsoft Windows)
4 4
5 Version 0.21, March 10th, 2003 5 Version 0.22, May 19th, 2003
6 6
7 Copyright (C) 1998-2003 Gilles Vollant 7 Copyright (C) 1998-2003 Gilles Vollant
8*/ 8*/
9 9
10#include <windows.h> 10#include <windows.h>
11#include <stdlib.h> 11#include <stdlib.h>
12 12
13#include "zlib.h" 13#include "zlib.h"
14#include "ioapi.h" 14#include "ioapi.h"
15#include "iowin32.h" 15#include "iowin32.h"
16 16
17#ifndef INVALID_HANDLE_VALUE 17#ifndef INVALID_HANDLE_VALUE
18#define INVALID_HANDLE_VALUE (0xFFFFFFFF) 18#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
19#endif 19#endif
20 20
21#ifndef INVALID_SET_FILE_POINTER 21#ifndef INVALID_SET_FILE_POINTER
22#define INVALID_SET_FILE_POINTER ((DWORD)-1) 22#define INVALID_SET_FILE_POINTER ((DWORD)-1)
23#endif 23#endif
24 24
25voidpf ZCALLBACK win32_open_file_func OF(( 25voidpf ZCALLBACK win32_open_file_func OF((
26 voidpf opaque, 26 voidpf opaque,
27 const char* filename, 27 const char* filename,
28 int mode)); 28 int mode));
29 29
30uLong ZCALLBACK win32_read_file_func OF(( 30uLong ZCALLBACK win32_read_file_func OF((
31 voidpf opaque, 31 voidpf opaque,
32 voidpf stream, 32 voidpf stream,
33 void* buf, 33 void* buf,
34 uLong size)); 34 uLong size));
35 35
36uLong ZCALLBACK win32_write_file_func OF(( 36uLong ZCALLBACK win32_write_file_func OF((
37 voidpf opaque, 37 voidpf opaque,
38 voidpf stream, 38 voidpf stream,
39 const void* buf, 39 const void* buf,
40 uLong size)); 40 uLong size));
41 41
42long ZCALLBACK win32_tell_file_func OF(( 42long ZCALLBACK win32_tell_file_func OF((
43 voidpf opaque, 43 voidpf opaque,
44 voidpf stream)); 44 voidpf stream));
45 45
46long ZCALLBACK win32_seek_file_func OF(( 46long ZCALLBACK win32_seek_file_func OF((
47 voidpf opaque, 47 voidpf opaque,
48 voidpf stream, 48 voidpf stream,
49 uLong offset, 49 uLong offset,
50 int origin)); 50 int origin));
51 51
52long ZCALLBACK win32_close_file_func OF(( 52long ZCALLBACK win32_close_file_func OF((
53 voidpf opaque, 53 voidpf opaque,
54 voidpf stream)); 54 voidpf stream));
55 55
56int ZCALLBACK win32_error_file_func OF(( 56int ZCALLBACK win32_error_file_func OF((
57 voidpf opaque, 57 voidpf opaque,
58 voidpf stream)); 58 voidpf stream));
59 59
60typedef struct 60typedef struct
61{ 61{
62 HANDLE hf; 62 HANDLE hf;
63 int error; 63 int error;
64} WIN32FILE_IOWIN; 64} WIN32FILE_IOWIN;
65 65
66voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) 66voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
67 voidpf opaque; 67 voidpf opaque;
68 const char* filename; 68 const char* filename;
69 int mode; 69 int mode;
70{ 70{
71 const char* mode_fopen = NULL; 71 const char* mode_fopen = NULL;
72 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 72 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
73 HANDLE hFile = 0; 73 HANDLE hFile = 0;
74 voidpf ret=NULL; 74 voidpf ret=NULL;
75 75
76 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; 76 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
77 77
78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
79 { 79 {
80 dwDesiredAccess = GENERIC_READ; 80 dwDesiredAccess = GENERIC_READ;
81 dwCreationDisposition = OPEN_EXISTING; 81 dwCreationDisposition = OPEN_EXISTING;
82 dwShareMode = FILE_SHARE_READ; 82 dwShareMode = FILE_SHARE_READ;
83 } 83 }
84 else 84 else
85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
86 { 86 {
87 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 87 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
88 dwCreationDisposition = OPEN_EXISTING; 88 dwCreationDisposition = OPEN_EXISTING;
89 } 89 }
90 else 90 else
91 if (mode & ZLIB_FILEFUNC_MODE_CREATE) 91 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
92 { 92 {
93 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 93 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
94 dwCreationDisposition = CREATE_ALWAYS; 94 dwCreationDisposition = CREATE_ALWAYS;
95 } 95 }
96 96
97 if ((filename!=NULL) && (dwDesiredAccess != 0)) 97 if ((filename!=NULL) && (dwDesiredAccess != 0))
98 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, 98 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
99 dwCreationDisposition, dwFlagsAndAttributes, NULL); 99 dwCreationDisposition, dwFlagsAndAttributes, NULL);
100 100
101 if (hFile == INVALID_HANDLE_VALUE) 101 if (hFile == INVALID_HANDLE_VALUE)
102 hFile = NULL; 102 hFile = NULL;
103 103
104 if (hFile != NULL) 104 if (hFile != NULL)
105 { 105 {
106 WIN32FILE_IOWIN w32fiow; 106 WIN32FILE_IOWIN w32fiow;
107 w32fiow.hf = hFile; 107 w32fiow.hf = hFile;
108 w32fiow.error = 0; 108 w32fiow.error = 0;
109 ret = malloc(sizeof(WIN32FILE_IOWIN)); 109 ret = malloc(sizeof(WIN32FILE_IOWIN));
110 if (ret==NULL) 110 if (ret==NULL)
111 CloseHandle(hFile); 111 CloseHandle(hFile);
112 else *((WIN32FILE_IOWIN*)ret) = w32fiow; 112 else *((WIN32FILE_IOWIN*)ret) = w32fiow;
113 } 113 }
114 return ret; 114 return ret;
115} 115}
116 116
117 117
118uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) 118uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
119 voidpf opaque; 119 voidpf opaque;
120 voidpf stream; 120 voidpf stream;
121 void* buf; 121 void* buf;
122 uLong size; 122 uLong size;
123{ 123{
124 uLong ret=0; 124 uLong ret=0;
125 HANDLE hFile = NULL; 125 HANDLE hFile = NULL;
126 if (stream!=NULL) 126 if (stream!=NULL)
127 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 127 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
128 if (hFile != NULL) 128 if (hFile != NULL)
129 if (!ReadFile(hFile, buf, size, &ret, NULL)) 129 if (!ReadFile(hFile, buf, size, &ret, NULL))
130 { 130 {
131 DWORD dwErr = GetLastError(); 131 DWORD dwErr = GetLastError();
132 if (dwErr == ERROR_HANDLE_EOF) 132 if (dwErr == ERROR_HANDLE_EOF)
133 dwErr = 0; 133 dwErr = 0;
134 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 134 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
135 } 135 }
136 136
137 return ret; 137 return ret;
138} 138}
139 139
140 140
141uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) 141uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
142 voidpf opaque; 142 voidpf opaque;
143 voidpf stream; 143 voidpf stream;
144 const void* buf; 144 const void* buf;
145 uLong size; 145 uLong size;
146{ 146{
147 uLong ret=0; 147 uLong ret=0;
148 HANDLE hFile = NULL; 148 HANDLE hFile = NULL;
149 if (stream!=NULL) 149 if (stream!=NULL)
150 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 150 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
151 151
152 if (hFile !=NULL) 152 if (hFile !=NULL)
153 if (!WriteFile(hFile, buf, size, &ret, NULL)) 153 if (!WriteFile(hFile, buf, size, &ret, NULL))
154 { 154 {
155 DWORD dwErr = GetLastError(); 155 DWORD dwErr = GetLastError();
156 if (dwErr == ERROR_HANDLE_EOF) 156 if (dwErr == ERROR_HANDLE_EOF)
157 dwErr = 0; 157 dwErr = 0;
158 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 158 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
159 } 159 }
160 160
161 return ret; 161 return ret;
162} 162}
163 163
164long ZCALLBACK win32_tell_file_func (opaque, stream) 164long ZCALLBACK win32_tell_file_func (opaque, stream)
165 voidpf opaque; 165 voidpf opaque;
166 voidpf stream; 166 voidpf stream;
167{ 167{
168 long ret=-1; 168 long ret=-1;
169 HANDLE hFile = NULL; 169 HANDLE hFile = NULL;
170 if (stream!=NULL) 170 if (stream!=NULL)
171 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 171 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
172 if (hFile != NULL) 172 if (hFile != NULL)
173 { 173 {
174 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); 174 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
175 if (dwSet == INVALID_SET_FILE_POINTER) 175 if (dwSet == INVALID_SET_FILE_POINTER)
176 { 176 {
177 DWORD dwErr = GetLastError(); 177 DWORD dwErr = GetLastError();
178 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 178 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
179 ret = -1; 179 ret = -1;
180 } 180 }
181 else 181 else
182 ret=(long)dwSet; 182 ret=(long)dwSet;
183 } 183 }
184 return ret; 184 return ret;
185} 185}
186 186
187long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) 187long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
188 voidpf opaque; 188 voidpf opaque;
189 voidpf stream; 189 voidpf stream;
190 uLong offset; 190 uLong offset;
191 int origin; 191 int origin;
192{ 192{
193 DWORD dwMoveMethod=0xFFFFFFFF; 193 DWORD dwMoveMethod=0xFFFFFFFF;
194 HANDLE hFile = NULL; 194 HANDLE hFile = NULL;
195 195
196 long ret=-1; 196 long ret=-1;
197 if (stream!=NULL) 197 if (stream!=NULL)
198 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 198 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
199 switch (origin) 199 switch (origin)
200 { 200 {
201 case ZLIB_FILEFUNC_SEEK_CUR : 201 case ZLIB_FILEFUNC_SEEK_CUR :
202 dwMoveMethod = FILE_CURRENT; 202 dwMoveMethod = FILE_CURRENT;
203 break; 203 break;
204 case ZLIB_FILEFUNC_SEEK_END : 204 case ZLIB_FILEFUNC_SEEK_END :
205 dwMoveMethod = FILE_END; 205 dwMoveMethod = FILE_END;
206 break; 206 break;
207 case ZLIB_FILEFUNC_SEEK_SET : 207 case ZLIB_FILEFUNC_SEEK_SET :
208 dwMoveMethod = FILE_BEGIN; 208 dwMoveMethod = FILE_BEGIN;
209 break; 209 break;
210 default: return -1; 210 default: return -1;
211 } 211 }
212 212
213 if (hFile != NULL) 213 if (hFile != NULL)
214 { 214 {
215 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); 215 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
216 if (dwSet == INVALID_SET_FILE_POINTER) 216 if (dwSet == INVALID_SET_FILE_POINTER)
217 { 217 {
218 DWORD dwErr = GetLastError(); 218 DWORD dwErr = GetLastError();
219 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 219 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
220 ret = -1; 220 ret = -1;
221 } 221 }
222 else 222 else
223 ret=0; 223 ret=0;
224 } 224 }
225 return ret; 225 return ret;
226} 226}
227 227
228long ZCALLBACK win32_close_file_func (opaque, stream) 228long ZCALLBACK win32_close_file_func (opaque, stream)
229 voidpf opaque; 229 voidpf opaque;
230 voidpf stream; 230 voidpf stream;
231{ 231{
232 long ret=-1; 232 long ret=-1;
233 233
234 if (stream!=NULL) 234 if (stream!=NULL)
235 { 235 {
236 HANDLE hFile; 236 HANDLE hFile;
237 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 237 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
238 if (hFile != NULL) 238 if (hFile != NULL)
239 { 239 {
240 CloseHandle(hFile); 240 CloseHandle(hFile);
241 ret=0; 241 ret=0;
242 } 242 }
243 free(stream); 243 free(stream);
244 } 244 }
245 return ret; 245 return ret;
246} 246}
247 247
248int ZCALLBACK win32_error_file_func (opaque, stream) 248int ZCALLBACK win32_error_file_func (opaque, stream)
249 voidpf opaque; 249 voidpf opaque;
250 voidpf stream; 250 voidpf stream;
251{ 251{
252 int ret=-1; 252 int ret=-1;
253 if (stream!=NULL) 253 if (stream!=NULL)
254 { 254 {
255 ret = ((WIN32FILE_IOWIN*)stream) -> error; 255 ret = ((WIN32FILE_IOWIN*)stream) -> error;
256 } 256 }
257 return ret; 257 return ret;
258} 258}
259 259
260void fill_win32_filefunc (pzlib_filefunc_def) 260void fill_win32_filefunc (pzlib_filefunc_def)
261 zlib_filefunc_def* pzlib_filefunc_def; 261 zlib_filefunc_def* pzlib_filefunc_def;
262{ 262{
263 pzlib_filefunc_def->zopen_file = win32_open_file_func; 263 pzlib_filefunc_def->zopen_file = win32_open_file_func;
264 pzlib_filefunc_def->zread_file = win32_read_file_func; 264 pzlib_filefunc_def->zread_file = win32_read_file_func;
265 pzlib_filefunc_def->zwrite_file = win32_write_file_func; 265 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
266 pzlib_filefunc_def->ztell_file = win32_tell_file_func; 266 pzlib_filefunc_def->ztell_file = win32_tell_file_func;
267 pzlib_filefunc_def->zseek_file = win32_seek_file_func; 267 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
268 pzlib_filefunc_def->zclose_file = win32_close_file_func; 268 pzlib_filefunc_def->zclose_file = win32_close_file_func;
269 pzlib_filefunc_def->zerror_file = win32_error_file_func; 269 pzlib_filefunc_def->zerror_file = win32_error_file_func;
270 pzlib_filefunc_def->opaque=NULL; 270 pzlib_filefunc_def->opaque=NULL;
271} 271}
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h
index d2f5e37..713fc02 100644
--- a/contrib/minizip/iowin32.h
+++ b/contrib/minizip/iowin32.h
@@ -1,19 +1,19 @@
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 files using zlib + zip or unzip API
3 This IO API version uses the Win32 API (for Microsoft Windows) 3 This IO API version uses the Win32 API (for Microsoft Windows)
4 4
5 Version 0.21, March 10th, 2003 5 Version 0.22, May 19th, 2003
6 6
7 Copyright (C) 1998-2003 Gilles Vollant 7 Copyright (C) 1998-2003 Gilles Vollant
8*/ 8*/
9 9
10#ifdef __cplusplus 10#ifdef __cplusplus
11extern "C" { 11extern "C" {
12#endif 12#endif
13 13
14void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 14void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
15 15
16 16
17#ifdef __cplusplus 17#ifdef __cplusplus
18} 18}
19#endif 19#endif
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c
index 938d4ef..ea23e40 100644
--- a/contrib/minizip/miniunz.c
+++ b/contrib/minizip/miniunz.c
@@ -1,543 +1,556 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <time.h> 4#include <time.h>
5#include <errno.h> 5#include <errno.h>
6#include <fcntl.h> 6#include <fcntl.h>
7 7
8#ifdef unix 8#ifdef unix
9# include <unistd.h> 9# include <unistd.h>
10# include <utime.h> 10# include <utime.h>
11#else 11#else
12# include <direct.h> 12# include <direct.h>
13# include <io.h> 13# include <io.h>
14#endif 14#endif
15 15
16#include "unzip.h" 16#include "unzip.h"
17 17
18#define CASESENSITIVITY (0) 18#define CASESENSITIVITY (0)
19#define WRITEBUFFERSIZE (8192) 19#define WRITEBUFFERSIZE (8192)
20#define MAXFILENAME (256) 20#define MAXFILENAME (256)
21 21
22#ifdef WIN32 22#ifdef WIN32
23#define USEWIN32IOAPI 23#define USEWIN32IOAPI
24#include "iowin32.h" 24#include "iowin32.h"
25#endif 25#endif
26/* 26/*
27 mini unzip, demo of unzip package 27 mini unzip, demo of unzip package
28 28
29 usage : 29 usage :
30 Usage : miniunz [-exvlo] file.zip [file_to_extract] 30 Usage : miniunz [-exvlo] file.zip [file_to_extract]
31 31
32 list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT 32 list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
33 if it exists 33 if it exists
34*/ 34*/
35 35
36 36
37/* change_file_date : change the date/time of a file 37/* change_file_date : change the date/time of a file
38 filename : the filename of the file where date/time must be modified 38 filename : the filename of the file where date/time must be modified
39 dosdate : the new date at the MSDos format (4 bytes) 39 dosdate : the new date at the MSDos format (4 bytes)
40 tmu_date : the SAME new date at the tm_unz format */ 40 tmu_date : the SAME new date at the tm_unz format */
41void change_file_date(filename,dosdate,tmu_date) 41void change_file_date(filename,dosdate,tmu_date)
42 const char *filename; 42 const char *filename;
43 uLong dosdate; 43 uLong dosdate;
44 tm_unz tmu_date; 44 tm_unz tmu_date;
45{ 45{
46#ifdef WIN32 46#ifdef WIN32
47 HANDLE hFile; 47 HANDLE hFile;
48 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; 48 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
49 49
50 hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, 50 hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE,
51 0,NULL,OPEN_EXISTING,0,NULL); 51 0,NULL,OPEN_EXISTING,0,NULL);
52 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); 52 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
53 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); 53 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
54 LocalFileTimeToFileTime(&ftLocal,&ftm); 54 LocalFileTimeToFileTime(&ftLocal,&ftm);
55 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); 55 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
56 CloseHandle(hFile); 56 CloseHandle(hFile);
57#else 57#else
58#ifdef unix 58#ifdef unix
59 struct utimbuf ut; 59 struct utimbuf ut;
60 struct tm newdate; 60 struct tm newdate;
61 newdate.tm_sec = tmu_date.tm_sec; 61 newdate.tm_sec = tmu_date.tm_sec;
62 newdate.tm_min=tmu_date.tm_min; 62 newdate.tm_min=tmu_date.tm_min;
63 newdate.tm_hour=tmu_date.tm_hour; 63 newdate.tm_hour=tmu_date.tm_hour;
64 newdate.tm_mday=tmu_date.tm_mday; 64 newdate.tm_mday=tmu_date.tm_mday;
65 newdate.tm_mon=tmu_date.tm_mon; 65 newdate.tm_mon=tmu_date.tm_mon;
66 if (tmu_date.tm_year > 1900) 66 if (tmu_date.tm_year > 1900)
67 newdate.tm_year=tmu_date.tm_year - 1900; 67 newdate.tm_year=tmu_date.tm_year - 1900;
68 else 68 else
69 newdate.tm_year=tmu_date.tm_year ; 69 newdate.tm_year=tmu_date.tm_year ;
70 newdate.tm_isdst=-1; 70 newdate.tm_isdst=-1;
71 71
72 ut.actime=ut.modtime=mktime(&newdate); 72 ut.actime=ut.modtime=mktime(&newdate);
73 utime(filename,&ut); 73 utime(filename,&ut);
74#endif 74#endif
75#endif 75#endif
76} 76}
77 77
78 78
79/* mymkdir and change_file_date are not 100 % portable 79/* mymkdir and change_file_date are not 100 % portable
80 As I don't know well Unix, I wait feedback for the unix portion */ 80 As I don't know well Unix, I wait feedback for the unix portion */
81 81
82int mymkdir(dirname) 82int mymkdir(dirname)
83 const char* dirname; 83 const char* dirname;
84{ 84{
85 int ret=0; 85 int ret=0;
86#ifdef WIN32 86#ifdef WIN32
87 ret = mkdir(dirname); 87 ret = mkdir(dirname);
88#else 88#else
89#ifdef unix 89#ifdef unix
90 ret = mkdir (dirname,0775); 90 ret = mkdir (dirname,0775);
91#endif 91#endif
92#endif 92#endif
93 return ret; 93 return ret;
94} 94}
95 95
96int makedir (newdir) 96int makedir (newdir)
97 char *newdir; 97 char *newdir;
98{ 98{
99 char *buffer ; 99 char *buffer ;
100 char *p; 100 char *p;
101 int len = (int)strlen(newdir); 101 int len = (int)strlen(newdir);
102 102
103 if (len <= 0) 103 if (len <= 0)
104 return 0; 104 return 0;
105 105
106 buffer = (char*)malloc(len+1); 106 buffer = (char*)malloc(len+1);
107 strcpy(buffer,newdir); 107 strcpy(buffer,newdir);
108 108
109 if (buffer[len-1] == '/') { 109 if (buffer[len-1] == '/') {
110 buffer[len-1] = '\0'; 110 buffer[len-1] = '\0';
111 } 111 }
112 if (mymkdir(buffer) == 0) 112 if (mymkdir(buffer) == 0)
113 { 113 {
114 free(buffer); 114 free(buffer);
115 return 1; 115 return 1;
116 } 116 }
117 117
118 p = buffer+1; 118 p = buffer+1;
119 while (1) 119 while (1)
120 { 120 {
121 char hold; 121 char hold;
122 122
123 while(*p && *p != '\\' && *p != '/') 123 while(*p && *p != '\\' && *p != '/')
124 p++; 124 p++;
125 hold = *p; 125 hold = *p;
126 *p = 0; 126 *p = 0;
127 if ((mymkdir(buffer) == -1) && (errno == ENOENT)) 127 if ((mymkdir(buffer) == -1) && (errno == ENOENT))
128 { 128 {
129 printf("couldn't create directory %s\n",buffer); 129 printf("couldn't create directory %s\n",buffer);
130 free(buffer); 130 free(buffer);
131 return 0; 131 return 0;
132 } 132 }
133 if (hold == 0) 133 if (hold == 0)
134 break; 134 break;
135 *p++ = hold; 135 *p++ = hold;
136 } 136 }
137 free(buffer); 137 free(buffer);
138 return 1; 138 return 1;
139} 139}
140 140
141void do_banner() 141void do_banner()
142{ 142{
143 printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n"); 143 printf("MiniUnz 0.22, demo of zLib + Unz package written by Gilles Vollant\n");
144 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); 144 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
145} 145}
146 146
147void do_help() 147void do_help()
148{ 148{
149 printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ; 149 printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \
150} 150 " -e Extract without pathname (junk paths)\n" \
151 151 " -x Extract with pathname\n" \
152 152 " -v list files\n" \
153int do_list(uf) 153 " -l list files\n" \
154 unzFile uf; 154 " -o overwrite files without prompting\n" \
155{ 155 " -p extract crypted file using password\n\n");
156 uLong i; 156}
157 unz_global_info gi; 157
158 int err; 158
159 159int do_list(uf)
160 err = unzGetGlobalInfo (uf,&gi); 160 unzFile uf;
161 if (err!=UNZ_OK) 161{
162 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 162 uLong i;
163 printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); 163 unz_global_info gi;
164 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); 164 int err;
165 for (i=0;i<gi.number_entry;i++) 165
166 { 166 err = unzGetGlobalInfo (uf,&gi);
167 char filename_inzip[256]; 167 if (err!=UNZ_OK)
168 unz_file_info file_info; 168 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
169 uLong ratio=0; 169 printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
170 const char *string_method; 170 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
171 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 171 for (i=0;i<gi.number_entry;i++)
172 if (err!=UNZ_OK) 172 {
173 { 173 char filename_inzip[256];
174 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 174 unz_file_info file_info;
175 break; 175 uLong ratio=0;
176 } 176 const char *string_method;
177 if (file_info.uncompressed_size>0) 177 char charCrypt=' ';
178 ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; 178 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
179 179 if (err!=UNZ_OK)
180 if (file_info.compression_method==0) 180 {
181 string_method="Stored"; 181 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
182 else 182 break;
183 if (file_info.compression_method==Z_DEFLATED) 183 }
184 { 184 if (file_info.uncompressed_size>0)
185 uInt iLevel=(uInt)((file_info.flag & 0x6)/2); 185 ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
186 if (iLevel==0) 186
187 string_method="Defl:N"; 187 /* display a '*' if the file is crypted */
188 else if (iLevel==1) 188 if ((file_info.flag & 1) != 0)
189 string_method="Defl:X"; 189 charCrypt='*';
190 else if ((iLevel==2) || (iLevel==3)) 190
191 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ 191 if (file_info.compression_method==0)
192 } 192 string_method="Stored";
193 else 193 else
194 string_method="Unkn. "; 194 if (file_info.compression_method==Z_DEFLATED)
195 195 {
196 printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", 196 uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
197 file_info.uncompressed_size,string_method,file_info.compressed_size, 197 if (iLevel==0)
198 ratio, 198 string_method="Defl:N";
199 (uLong)file_info.tmu_date.tm_mon + 1, 199 else if (iLevel==1)
200 (uLong)file_info.tmu_date.tm_mday, 200 string_method="Defl:X";
201 (uLong)file_info.tmu_date.tm_year % 100, 201 else if ((iLevel==2) || (iLevel==3))
202 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, 202 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
203 (uLong)file_info.crc,filename_inzip); 203 }
204 if ((i+1)<gi.number_entry) 204 else
205 { 205 string_method="Unkn. ";
206 err = unzGoToNextFile(uf); 206
207 if (err!=UNZ_OK) 207 printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
208 { 208 file_info.uncompressed_size,string_method,
209 printf("error %d with zipfile in unzGoToNextFile\n",err); 209 charCrypt,
210 break; 210 file_info.compressed_size,
211 } 211 ratio,
212 } 212 (uLong)file_info.tmu_date.tm_mon + 1,
213 } 213 (uLong)file_info.tmu_date.tm_mday,
214 214 (uLong)file_info.tmu_date.tm_year % 100,
215 return 0; 215 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
216} 216 (uLong)file_info.crc,filename_inzip);
217 217 if ((i+1)<gi.number_entry)
218 218 {
219int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) 219 err = unzGoToNextFile(uf);
220 unzFile uf; 220 if (err!=UNZ_OK)
221 const int* popt_extract_without_path; 221 {
222 int* popt_overwrite; 222 printf("error %d with zipfile in unzGoToNextFile\n",err);
223 const char* password; 223 break;
224{ 224 }
225 char filename_inzip[256]; 225 }
226 char* filename_withoutpath; 226 }
227 char* p; 227
228 int err=UNZ_OK; 228 return 0;
229 FILE *fout=NULL; 229}
230 void* buf; 230
231 uInt size_buf; 231
232 232int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
233 unz_file_info file_info; 233 unzFile uf;
234 uLong ratio=0; 234 const int* popt_extract_without_path;
235 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 235 int* popt_overwrite;
236 236 const char* password;
237 if (err!=UNZ_OK) 237{
238 { 238 char filename_inzip[256];
239 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 239 char* filename_withoutpath;
240 return err; 240 char* p;
241 } 241 int err=UNZ_OK;
242 242 FILE *fout=NULL;
243 size_buf = WRITEBUFFERSIZE; 243 void* buf;
244 buf = (void*)malloc(size_buf); 244 uInt size_buf;
245 if (buf==NULL) 245
246 { 246 unz_file_info file_info;
247 printf("Error allocating memory\n"); 247 uLong ratio=0;
248 return UNZ_INTERNALERROR; 248 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
249 } 249
250 250 if (err!=UNZ_OK)
251 p = filename_withoutpath = filename_inzip; 251 {
252 while ((*p) != '\0') 252 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
253 { 253 return err;
254 if (((*p)=='/') || ((*p)=='\\')) 254 }
255 filename_withoutpath = p+1; 255
256 p++; 256 size_buf = WRITEBUFFERSIZE;
257 } 257 buf = (void*)malloc(size_buf);
258 258 if (buf==NULL)
259 if ((*filename_withoutpath)=='\0') 259 {
260 { 260 printf("Error allocating memory\n");
261 if ((*popt_extract_without_path)==0) 261 return UNZ_INTERNALERROR;
262 { 262 }
263 printf("creating directory: %s\n",filename_inzip); 263
264 mymkdir(filename_inzip); 264 p = filename_withoutpath = filename_inzip;
265 } 265 while ((*p) != '\0')
266 } 266 {
267 else 267 if (((*p)=='/') || ((*p)=='\\'))
268 { 268 filename_withoutpath = p+1;
269 const char* write_filename; 269 p++;
270 int skip=0; 270 }
271 271
272 if ((*popt_extract_without_path)==0) 272 if ((*filename_withoutpath)=='\0')
273 write_filename = filename_inzip; 273 {
274 else 274 if ((*popt_extract_without_path)==0)
275 write_filename = filename_withoutpath; 275 {
276 276 printf("creating directory: %s\n",filename_inzip);
277 err = unzOpenCurrentFilePassword(uf,password); 277 mymkdir(filename_inzip);
278 if (err!=UNZ_OK) 278 }
279 { 279 }
280 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); 280 else
281 } 281 {
282 282 const char* write_filename;
283 if (((*popt_overwrite)==0) && (err==UNZ_OK)) 283 int skip=0;
284 { 284
285 char rep=0; 285 if ((*popt_extract_without_path)==0)
286 FILE* ftestexist; 286 write_filename = filename_inzip;
287 ftestexist = fopen(write_filename,"rb"); 287 else
288 if (ftestexist!=NULL) 288 write_filename = filename_withoutpath;
289 { 289
290 fclose(ftestexist); 290 err = unzOpenCurrentFilePassword(uf,password);
291 do 291 if (err!=UNZ_OK)
292 { 292 {
293 char answer[128]; 293 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
294 printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); 294 }
295 scanf("%1s",answer); 295
296 rep = answer[0] ; 296 if (((*popt_overwrite)==0) && (err==UNZ_OK))
297 if ((rep>='a') && (rep<='z')) 297 {
298 rep -= 0x20; 298 char rep=0;
299 } 299 FILE* ftestexist;
300 while ((rep!='Y') && (rep!='N') && (rep!='A')); 300 ftestexist = fopen(write_filename,"rb");
301 } 301 if (ftestexist!=NULL)
302 302 {
303 if (rep == 'N') 303 fclose(ftestexist);
304 skip = 1; 304 do
305 305 {
306 if (rep == 'A') 306 char answer[128];
307 *popt_overwrite=1; 307 printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
308 } 308 scanf("%1s",answer);
309 309 rep = answer[0] ;
310 if ((skip==0) && (err==UNZ_OK)) 310 if ((rep>='a') && (rep<='z'))
311 { 311 rep -= 0x20;
312 fout=fopen(write_filename,"wb"); 312 }
313 313 while ((rep!='Y') && (rep!='N') && (rep!='A'));
314 /* some zipfile don't contain directory alone before file */ 314 }
315 if ((fout==NULL) && ((*popt_extract_without_path)==0) && 315
316 (filename_withoutpath!=(char*)filename_inzip)) 316 if (rep == 'N')
317 { 317 skip = 1;
318 char c=*(filename_withoutpath-1); 318
319 *(filename_withoutpath-1)='\0'; 319 if (rep == 'A')
320 makedir(write_filename); 320 *popt_overwrite=1;
321 *(filename_withoutpath-1)=c; 321 }
322 fout=fopen(write_filename,"wb"); 322
323 } 323 if ((skip==0) && (err==UNZ_OK))
324 324 {
325 if (fout==NULL) 325 fout=fopen(write_filename,"wb");
326 { 326
327 printf("error opening %s\n",write_filename); 327 /* some zipfile don't contain directory alone before file */
328 } 328 if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
329 } 329 (filename_withoutpath!=(char*)filename_inzip))
330 330 {
331 if (fout!=NULL) 331 char c=*(filename_withoutpath-1);
332 { 332 *(filename_withoutpath-1)='\0';
333 printf(" extracting: %s\n",write_filename); 333 makedir(write_filename);
334 334 *(filename_withoutpath-1)=c;
335 do 335 fout=fopen(write_filename,"wb");
336 { 336 }
337 err = unzReadCurrentFile(uf,buf,size_buf); 337
338 if (err<0) 338 if (fout==NULL)
339 { 339 {
340 printf("error %d with zipfile in unzReadCurrentFile\n",err); 340 printf("error opening %s\n",write_filename);
341 break; 341 }
342 } 342 }
343 if (err>0) 343
344 if (fwrite(buf,err,1,fout)!=1) 344 if (fout!=NULL)
345 { 345 {
346 printf("error in writing extracted file\n"); 346 printf(" extracting: %s\n",write_filename);
347 err=UNZ_ERRNO; 347
348 break; 348 do
349 } 349 {
350 } 350 err = unzReadCurrentFile(uf,buf,size_buf);
351 while (err>0); 351 if (err<0)
352 if (fout) 352 {
353 fclose(fout); 353 printf("error %d with zipfile in unzReadCurrentFile\n",err);
354 354 break;
355 if (err==0) 355 }
356 change_file_date(write_filename,file_info.dosDate, 356 if (err>0)
357 file_info.tmu_date); 357 if (fwrite(buf,err,1,fout)!=1)
358 } 358 {
359 359 printf("error in writing extracted file\n");
360 if (err==UNZ_OK) 360 err=UNZ_ERRNO;
361 { 361 break;
362 err = unzCloseCurrentFile (uf); 362 }
363 if (err!=UNZ_OK) 363 }
364 { 364 while (err>0);
365 printf("error %d with zipfile in unzCloseCurrentFile\n",err); 365 if (fout)
366 } 366 fclose(fout);
367 } 367
368 else 368 if (err==0)
369 unzCloseCurrentFile(uf); /* don't lose the error */ 369 change_file_date(write_filename,file_info.dosDate,
370 } 370 file_info.tmu_date);
371 371 }
372 free(buf); 372
373 return err; 373 if (err==UNZ_OK)
374} 374 {
375 375 err = unzCloseCurrentFile (uf);
376 376 if (err!=UNZ_OK)
377int do_extract(uf,opt_extract_without_path,opt_overwrite,password) 377 {
378 unzFile uf; 378 printf("error %d with zipfile in unzCloseCurrentFile\n",err);
379 int opt_extract_without_path; 379 }
380 int opt_overwrite; 380 }
381 const char* password; 381 else
382{ 382 unzCloseCurrentFile(uf); /* don't lose the error */
383 uLong i; 383 }
384 unz_global_info gi; 384
385 int err; 385 free(buf);
386 FILE* fout=NULL; 386 return err;
387 387}
388 err = unzGetGlobalInfo (uf,&gi); 388
389 if (err!=UNZ_OK) 389
390 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 390int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
391 391 unzFile uf;
392 for (i=0;i<gi.number_entry;i++) 392 int opt_extract_without_path;
393 { 393 int opt_overwrite;
394 if (do_extract_currentfile(uf,&opt_extract_without_path, 394 const char* password;
395 &opt_overwrite, 395{
396 password) != UNZ_OK) 396 uLong i;
397 break; 397 unz_global_info gi;
398 398 int err;
399 if ((i+1)<gi.number_entry) 399 FILE* fout=NULL;
400 { 400
401 err = unzGoToNextFile(uf); 401 err = unzGetGlobalInfo (uf,&gi);
402 if (err!=UNZ_OK) 402 if (err!=UNZ_OK)
403 { 403 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
404 printf("error %d with zipfile in unzGoToNextFile\n",err); 404
405 break; 405 for (i=0;i<gi.number_entry;i++)
406 } 406 {
407 } 407 if (do_extract_currentfile(uf,&opt_extract_without_path,
408 } 408 &opt_overwrite,
409 409 password) != UNZ_OK)
410 return 0; 410 break;
411} 411
412 412 if ((i+1)<gi.number_entry)
413int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password) 413 {
414 unzFile uf; 414 err = unzGoToNextFile(uf);
415 const char* filename; 415 if (err!=UNZ_OK)
416 int opt_extract_without_path; 416 {
417 int opt_overwrite; 417 printf("error %d with zipfile in unzGoToNextFile\n",err);
418 const char* password; 418 break;
419{ 419 }
420 int err = UNZ_OK; 420 }
421 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) 421 }
422 { 422
423 printf("file %s not found in the zipfile\n",filename); 423 return 0;
424 return 2; 424}
425 } 425
426 426int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
427 if (do_extract_currentfile(uf,&opt_extract_without_path, 427 unzFile uf;
428 &opt_overwrite, 428 const char* filename;
429 password) == UNZ_OK) 429 int opt_extract_without_path;
430 return 0; 430 int opt_overwrite;
431 else 431 const char* password;
432 return 1; 432{
433} 433 int err = UNZ_OK;
434 434 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
435 435 {
436int main(argc,argv) 436 printf("file %s not found in the zipfile\n",filename);
437 int argc; 437 return 2;
438 char *argv[]; 438 }
439{ 439
440 const char *zipfilename=NULL; 440 if (do_extract_currentfile(uf,&opt_extract_without_path,
441 const char *filename_to_extract=NULL; 441 &opt_overwrite,
442 const char *password=NULL; 442 password) == UNZ_OK)
443 char filename_try[MAXFILENAME+16] = ""; 443 return 0;
444 int i; 444 else
445 int opt_do_list=0; 445 return 1;
446 int opt_do_extract=1; 446}
447 int opt_do_extract_withoutpath=0; 447
448 int opt_overwrite=0; 448
449 unzFile uf=NULL; 449int main(argc,argv)
450 450 int argc;
451 do_banner(); 451 char *argv[];
452 if (argc==1) 452{
453 { 453 const char *zipfilename=NULL;
454 do_help(); 454 const char *filename_to_extract=NULL;
455 return 0; 455 const char *password=NULL;
456 } 456 char filename_try[MAXFILENAME+16] = "";
457 else 457 int i;
458 { 458 int opt_do_list=0;
459 for (i=1;i<argc;i++) 459 int opt_do_extract=1;
460 { 460 int opt_do_extract_withoutpath=0;
461 if ((*argv[i])=='-') 461 int opt_overwrite=0;
462 { 462 unzFile uf=NULL;
463 const char *p=argv[i]+1; 463
464 464 do_banner();
465 while ((*p)!='\0') 465 if (argc==1)
466 { 466 {
467 char c=*(p++);; 467 do_help();
468 if ((c=='l') || (c=='L')) 468 return 0;
469 opt_do_list = 1; 469 }
470 if ((c=='v') || (c=='V')) 470 else
471 opt_do_list = 1; 471 {
472 if ((c=='x') || (c=='X')) 472 for (i=1;i<argc;i++)
473 opt_do_extract = 1; 473 {
474 if ((c=='e') || (c=='E')) 474 if ((*argv[i])=='-')
475 opt_do_extract = opt_do_extract_withoutpath = 1; 475 {
476 if ((c=='o') || (c=='O')) 476 const char *p=argv[i]+1;
477 opt_overwrite=1; 477
478 if (((c=='p') || (c=='P')) && (i+1<argc)) 478 while ((*p)!='\0')
479 { 479 {
480 password=argv[i+1]; 480 char c=*(p++);;
481 i++; 481 if ((c=='l') || (c=='L'))
482 } 482 opt_do_list = 1;
483 } 483 if ((c=='v') || (c=='V'))
484 } 484 opt_do_list = 1;
485 else 485 if ((c=='x') || (c=='X'))
486 { 486 opt_do_extract = 1;
487 if (zipfilename == NULL) 487 if ((c=='e') || (c=='E'))
488 zipfilename = argv[i]; 488 opt_do_extract = opt_do_extract_withoutpath = 1;
489 else if (filename_to_extract==NULL) 489 if ((c=='o') || (c=='O'))
490 filename_to_extract = argv[i] ; 490 opt_overwrite=1;
491 } 491 if (((c=='p') || (c=='P')) && (i+1<argc))
492 } 492 {
493 } 493 password=argv[i+1];
494 494 i++;
495 if (zipfilename!=NULL) 495 }
496 { 496 }
497 497 }
498 #ifdef USEWIN32IOAPI 498 else
499 zlib_filefunc_def ffunc; 499 {
500 #endif 500 if (zipfilename == NULL)
501 501 zipfilename = argv[i];
502 strncpy(filename_try, zipfilename,MAXFILENAME-1); 502 else if (filename_to_extract==NULL)
503 /* strncpy doesnt append the trailing NULL, of the string is too long. */ 503 filename_to_extract = argv[i] ;
504 filename_try[ MAXFILENAME ] = '\0'; 504 }
505 505 }
506 #ifdef USEWIN32IOAPI 506 }
507 fill_win32_filefunc(&ffunc); 507
508 uf = unzOpen2(zipfilename,&ffunc); 508 if (zipfilename!=NULL)
509 #else 509 {
510 uf = unzOpen(zipfilename); 510
511 #endif 511 #ifdef USEWIN32IOAPI
512 if (uf==NULL) 512 zlib_filefunc_def ffunc;
513 { 513 #endif
514 strcat(filename_try,".zip"); 514
515 #ifdef USEWIN32IOAPI 515 strncpy(filename_try, zipfilename,MAXFILENAME-1);
516 uf = unzOpen2(filename_try,&ffunc); 516 /* strncpy doesnt append the trailing NULL, of the string is too long. */
517 #else 517 filename_try[ MAXFILENAME ] = '\0';
518 uf = unzOpen(filename_try); 518
519 #endif 519 #ifdef USEWIN32IOAPI
520 } 520 fill_win32_filefunc(&ffunc);
521 } 521 uf = unzOpen2(zipfilename,&ffunc);
522 522 #else
523 if (uf==NULL) 523 uf = unzOpen(zipfilename);
524 { 524 #endif
525 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); 525 if (uf==NULL)
526 return 1; 526 {
527 } 527 strcat(filename_try,".zip");
528 printf("%s opened\n",filename_try); 528 #ifdef USEWIN32IOAPI
529 529 uf = unzOpen2(filename_try,&ffunc);
530 if (opt_do_list==1) 530 #else
531 return do_list(uf); 531 uf = unzOpen(filename_try);
532 else if (opt_do_extract==1) 532 #endif
533 { 533 }
534 if (filename_to_extract == NULL) 534 }
535 return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); 535
536 else 536 if (uf==NULL)
537 return do_extract_onefile(uf,filename_to_extract, 537 {
538 opt_do_extract_withoutpath,opt_overwrite,password); 538 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
539 } 539 return 1;
540 unzCloseCurrentFile(uf); 540 }
541 541 printf("%s opened\n",filename_try);
542 return 0; 542
543} 543 if (opt_do_list==1)
544 return do_list(uf);
545 else if (opt_do_extract==1)
546 {
547 if (filename_to_extract == NULL)
548 return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
549 else
550 return do_extract_onefile(uf,filename_to_extract,
551 opt_do_extract_withoutpath,opt_overwrite,password);
552 }
553 unzCloseCurrentFile(uf);
554
555 return 0;
556}
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c
index 5792a1e..79e541d 100644
--- a/contrib/minizip/minizip.c
+++ b/contrib/minizip/minizip.c
@@ -1,392 +1,397 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <time.h> 4#include <time.h>
5#include <errno.h> 5#include <errno.h>
6#include <fcntl.h> 6#include <fcntl.h>
7 7
8#ifdef unix 8#ifdef unix
9# include <unistd.h> 9# include <unistd.h>
10# include <utime.h> 10# include <utime.h>
11# include <sys/types.h> 11# include <sys/types.h>
12# include <sys/stat.h> 12# include <sys/stat.h>
13#else 13#else
14# include <direct.h> 14# include <direct.h>
15# include <io.h> 15# include <io.h>
16#endif 16#endif
17 17
18#include "zip.h" 18#include "zip.h"
19 19
20#ifdef WIN32 20#ifdef WIN32
21#define USEWIN32IOAPI 21#define USEWIN32IOAPI
22#include "iowin32.h" 22#include "iowin32.h"
23#endif 23#endif
24 24
25 25
26 26
27#define WRITEBUFFERSIZE (16384) 27#define WRITEBUFFERSIZE (16384)
28#define MAXFILENAME (256) 28#define MAXFILENAME (256)
29 29
30#ifdef WIN32 30#ifdef WIN32
31uLong filetime(f, tmzip, dt) 31uLong filetime(f, tmzip, dt)
32 char *f; /* name of file to get info on */ 32 char *f; /* name of file to get info on */
33 tm_zip *tmzip; /* return value: access, modific. and creation times */ 33 tm_zip *tmzip; /* return value: access, modific. and creation times */
34 uLong *dt; /* dostime */ 34 uLong *dt; /* dostime */
35{ 35{
36 int ret = 0; 36 int ret = 0;
37 { 37 {
38 FILETIME ftLocal; 38 FILETIME ftLocal;
39 HANDLE hFind; 39 HANDLE hFind;
40 WIN32_FIND_DATA ff32; 40 WIN32_FIND_DATA ff32;
41 41
42 hFind = FindFirstFile(f,&ff32); 42 hFind = FindFirstFile(f,&ff32);
43 if (hFind != INVALID_HANDLE_VALUE) 43 if (hFind != INVALID_HANDLE_VALUE)
44 { 44 {
45 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); 45 FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
46 FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); 46 FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
47 FindClose(hFind); 47 FindClose(hFind);
48 ret = 1; 48 ret = 1;
49 } 49 }
50 } 50 }
51 return ret; 51 return ret;
52} 52}
53#else 53#else
54#ifdef unix 54#ifdef unix
55uLong filetime(f, tmzip, dt) 55uLong filetime(f, tmzip, dt)
56 char *f; /* name of file to get info on */ 56 char *f; /* name of file to get info on */
57 tm_zip *tmzip; /* return value: access, modific. and creation times */ 57 tm_zip *tmzip; /* return value: access, modific. and creation times */
58 uLong *dt; /* dostime */ 58 uLong *dt; /* dostime */
59{ 59{
60 int ret=0; 60 int ret=0;
61 struct stat s; /* results of stat() */ 61 struct stat s; /* results of stat() */
62 struct tm* filedate; 62 struct tm* filedate;
63 time_t tm_t=0; 63 time_t tm_t=0;
64 64
65 if (strcmp(f,"-")!=0) 65 if (strcmp(f,"-")!=0)
66 { 66 {
67 char name[MAXFILENAME+1]; 67 char name[MAXFILENAME+1];
68 int len = strlen(f); 68 int len = strlen(f);
69 69
70 strncpy(name, f,MAXFILENAME-1); 70 strncpy(name, f,MAXFILENAME-1);
71 /* strncpy doesnt append the trailing NULL, of the string is too long. */ 71 /* strncpy doesnt append the trailing NULL, of the string is too long. */
72 name[ MAXFILENAME ] = '\0'; 72 name[ MAXFILENAME ] = '\0';
73 73
74 if (name[len - 1] == '/') 74 if (name[len - 1] == '/')
75 name[len - 1] = '\0'; 75 name[len - 1] = '\0';
76 /* not all systems allow stat'ing a file with / appended */ 76 /* not all systems allow stat'ing a file with / appended */
77 if (stat(name,&s)==0) 77 if (stat(name,&s)==0)
78 { 78 {
79 tm_t = s.st_mtime; 79 tm_t = s.st_mtime;
80 ret = 1; 80 ret = 1;
81 } 81 }
82 } 82 }
83 filedate = localtime(&tm_t); 83 filedate = localtime(&tm_t);
84 84
85 tmzip->tm_sec = filedate->tm_sec; 85 tmzip->tm_sec = filedate->tm_sec;
86 tmzip->tm_min = filedate->tm_min; 86 tmzip->tm_min = filedate->tm_min;
87 tmzip->tm_hour = filedate->tm_hour; 87 tmzip->tm_hour = filedate->tm_hour;
88 tmzip->tm_mday = filedate->tm_mday; 88 tmzip->tm_mday = filedate->tm_mday;
89 tmzip->tm_mon = filedate->tm_mon ; 89 tmzip->tm_mon = filedate->tm_mon ;
90 tmzip->tm_year = filedate->tm_year; 90 tmzip->tm_year = filedate->tm_year;
91 91
92 return ret; 92 return ret;
93} 93}
94#else 94#else
95uLong filetime(f, tmzip, dt) 95uLong filetime(f, tmzip, dt)
96 char *f; /* name of file to get info on */ 96 char *f; /* name of file to get info on */
97 tm_zip *tmzip; /* return value: access, modific. and creation times */ 97 tm_zip *tmzip; /* return value: access, modific. and creation times */
98 uLong *dt; /* dostime */ 98 uLong *dt; /* dostime */
99{ 99{
100 return 0; 100 return 0;
101} 101}
102#endif 102#endif
103#endif 103#endif
104 104
105 105
106 106
107 107
108int check_exist_file(filename) 108int check_exist_file(filename)
109 const char* filename; 109 const char* filename;
110{ 110{
111 FILE* ftestexist; 111 FILE* ftestexist;
112 int ret = 1; 112 int ret = 1;
113 ftestexist = fopen(filename,"rb"); 113 ftestexist = fopen(filename,"rb");
114 if (ftestexist==NULL) 114 if (ftestexist==NULL)
115 ret = 0; 115 ret = 0;
116 else 116 else
117 fclose(ftestexist); 117 fclose(ftestexist);
118 return ret; 118 return ret;
119} 119}
120 120
121void do_banner() 121void do_banner()
122{ 122{
123 printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n"); 123 printf("MiniZip 0.22, demo of zLib + Zip package written by Gilles Vollant\n");
124 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); 124 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
125} 125}
126 126
127void do_help() 127void do_help()
128{ 128{
129 printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ; 129 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
130} 130 " -o Overwrite existing file.zip\n" \
131 131 " -a Append to existing file.zip\n" \
132/* calculate the CRC32 of a file, 132 " -0 Store only\n" \
133 because to encrypt a file, we need known the CRC32 of the file before */ 133 " -1 Compress faster\n" \
134int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) 134 " -9 Compress better\n\n");
135{ 135}
136 unsigned long calculate_crc=0; 136
137 int err=ZIP_OK; 137/* calculate the CRC32 of a file,
138 FILE * fin = fopen(filenameinzip,"rb"); 138 because to encrypt a file, we need known the CRC32 of the file before */
139 unsigned long size_read = 0; 139int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
140 unsigned long total_read = 0; 140{
141 if (fin==NULL) 141 unsigned long calculate_crc=0;
142 { 142 int err=ZIP_OK;
143 err = ZIP_ERRNO; 143 FILE * fin = fopen(filenameinzip,"rb");
144 } 144 unsigned long size_read = 0;
145 145 unsigned long total_read = 0;
146 if (err == ZIP_OK) 146 if (fin==NULL)
147 do 147 {
148 { 148 err = ZIP_ERRNO;
149 err = ZIP_OK; 149 }
150 size_read = (int)fread(buf,1,size_buf,fin); 150
151 if (size_read < size_buf) 151 if (err == ZIP_OK)
152 if (feof(fin)==0) 152 do
153 { 153 {
154 printf("error in reading %s\n",filenameinzip); 154 err = ZIP_OK;
155 err = ZIP_ERRNO; 155 size_read = (int)fread(buf,1,size_buf,fin);
156 } 156 if (size_read < size_buf)
157 157 if (feof(fin)==0)
158 if (size_read>0) 158 {
159 calculate_crc = crc32(calculate_crc,buf,size_read); 159 printf("error in reading %s\n",filenameinzip);
160 total_read += size_read; 160 err = ZIP_ERRNO;
161 161 }
162 } while ((err == ZIP_OK) && (size_read>0)); 162
163 163 if (size_read>0)
164 if (fin) 164 calculate_crc = crc32(calculate_crc,buf,size_read);
165 fclose(fin); 165 total_read += size_read;
166 166
167 *result_crc=calculate_crc; 167 } while ((err == ZIP_OK) && (size_read>0));
168 printf("file %s crc %x\n",filenameinzip,calculate_crc); 168
169 return err; 169 if (fin)
170} 170 fclose(fin);
171 171
172int main(argc,argv) 172 *result_crc=calculate_crc;
173 int argc; 173 printf("file %s crc %x\n",filenameinzip,calculate_crc);
174 char *argv[]; 174 return err;
175{ 175}
176 int i; 176
177 int opt_overwrite=0; 177int main(argc,argv)
178 int opt_compress_level=Z_DEFAULT_COMPRESSION; 178 int argc;
179 int zipfilenamearg = 0; 179 char *argv[];
180 char filename_try[MAXFILENAME+16]; 180{
181 int zipok; 181 int i;
182 int err=0; 182 int opt_overwrite=0;
183 int size_buf=0; 183 int opt_compress_level=Z_DEFAULT_COMPRESSION;
184 void* buf=NULL; 184 int zipfilenamearg = 0;
185 const char* password=NULL; 185 char filename_try[MAXFILENAME+16];
186 186 int zipok;
187 187 int err=0;
188 do_banner(); 188 int size_buf=0;
189 if (argc==1) 189 void* buf=NULL;
190 { 190 const char* password=NULL;
191 do_help(); 191
192 return 0; 192
193 } 193 do_banner();
194 else 194 if (argc==1)
195 { 195 {
196 for (i=1;i<argc;i++) 196 do_help();
197 { 197 return 0;
198 if ((*argv[i])=='-') 198 }
199 { 199 else
200 const char *p=argv[i]+1; 200 {
201 201 for (i=1;i<argc;i++)
202 while ((*p)!='\0') 202 {
203 { 203 if ((*argv[i])=='-')
204 char c=*(p++);; 204 {
205 if ((c=='o') || (c=='O')) 205 const char *p=argv[i]+1;
206 opt_overwrite = 1; 206
207 if ((c=='a') || (c=='A')) 207 while ((*p)!='\0')
208 opt_overwrite = 2; 208 {
209 if ((c>='0') && (c<='9')) 209 char c=*(p++);;
210 opt_compress_level = c-'0'; 210 if ((c=='o') || (c=='O'))
211 211 opt_overwrite = 1;
212 if (((c=='p') || (c=='P')) && (i+1<argc)) 212 if ((c=='a') || (c=='A'))
213 { 213 opt_overwrite = 2;
214 password=argv[i+1]; 214 if ((c>='0') && (c<='9'))
215 i++; 215 opt_compress_level = c-'0';
216 } 216
217 } 217 if (((c=='p') || (c=='P')) && (i+1<argc))
218 } 218 {
219 else 219 password=argv[i+1];
220 if (zipfilenamearg == 0) 220 i++;
221 zipfilenamearg = i ; 221 }
222 } 222 }
223 } 223 }
224 224 else
225 size_buf = WRITEBUFFERSIZE; 225 if (zipfilenamearg == 0)
226 buf = (void*)malloc(size_buf); 226 zipfilenamearg = i ;
227 if (buf==NULL) 227 }
228 { 228 }
229 printf("Error allocating memory\n"); 229
230 return ZIP_INTERNALERROR; 230 size_buf = WRITEBUFFERSIZE;
231 } 231 buf = (void*)malloc(size_buf);
232 232 if (buf==NULL)
233 if (zipfilenamearg==0) 233 {
234 zipok=0; 234 printf("Error allocating memory\n");
235 else 235 return ZIP_INTERNALERROR;
236 { 236 }
237 int i,len; 237
238 int dot_found=0; 238 if (zipfilenamearg==0)
239 239 zipok=0;
240 zipok = 1 ; 240 else
241 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); 241 {
242 /* strncpy doesnt append the trailing NULL, of the string is too long. */ 242 int i,len;
243 filename_try[ MAXFILENAME ] = '\0'; 243 int dot_found=0;
244 244
245 len=(int)strlen(filename_try); 245 zipok = 1 ;
246 for (i=0;i<len;i++) 246 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
247 if (filename_try[i]=='.') 247 /* strncpy doesnt append the trailing NULL, of the string is too long. */
248 dot_found=1; 248 filename_try[ MAXFILENAME ] = '\0';
249 249
250 if (dot_found==0) 250 len=(int)strlen(filename_try);
251 strcat(filename_try,".zip"); 251 for (i=0;i<len;i++)
252 252 if (filename_try[i]=='.')
253 if (opt_overwrite==2) 253 dot_found=1;
254 { 254
255 /* if the file don't exist, we not append file */ 255 if (dot_found==0)
256 if (check_exist_file(filename_try)==0) 256 strcat(filename_try,".zip");
257 opt_overwrite=1; 257
258 } 258 if (opt_overwrite==2)
259 else 259 {
260 if (opt_overwrite==0) 260 /* if the file don't exist, we not append file */
261 if (check_exist_file(filename_try)!=0) 261 if (check_exist_file(filename_try)==0)
262 { 262 opt_overwrite=1;
263 char rep=0; 263 }
264 do 264 else
265 { 265 if (opt_overwrite==0)
266 char answer[128]; 266 if (check_exist_file(filename_try)!=0)
267 printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); 267 {
268 scanf("%1s",answer); 268 char rep=0;
269 rep = answer[0] ; 269 do
270 if ((rep>='a') && (rep<='z')) 270 {
271 rep -= 0x20; 271 char answer[128];
272 } 272 printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
273 while ((rep!='Y') && (rep!='N') && (rep!='A')); 273 scanf("%1s",answer);
274 if (rep=='N') 274 rep = answer[0] ;
275 zipok = 0; 275 if ((rep>='a') && (rep<='z'))
276 if (rep=='A') 276 rep -= 0x20;
277 opt_overwrite = 2; 277 }
278 } 278 while ((rep!='Y') && (rep!='N') && (rep!='A'));
279 } 279 if (rep=='N')
280 280 zipok = 0;
281 if (zipok==1) 281 if (rep=='A')
282 { 282 opt_overwrite = 2;
283 zipFile zf; 283 }
284 int errclose; 284 }
285 #ifdef USEWIN32IOAPI 285
286 zlib_filefunc_def ffunc; 286 if (zipok==1)
287 fill_win32_filefunc(&ffunc); 287 {
288 zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); 288 zipFile zf;
289 #else 289 int errclose;
290 zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); 290 #ifdef USEWIN32IOAPI
291 #endif 291 zlib_filefunc_def ffunc;
292 292 fill_win32_filefunc(&ffunc);
293 if (zf == NULL) 293 zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
294 { 294 #else
295 printf("error opening %s\n",filename_try); 295 zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
296 err= ZIP_ERRNO; 296 #endif
297 } 297
298 else 298 if (zf == NULL)
299 printf("creating %s\n",filename_try); 299 {
300 300 printf("error opening %s\n",filename_try);
301 for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) 301 err= ZIP_ERRNO;
302 { 302 }
303 if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) 303 else
304 { 304 printf("creating %s\n",filename_try);
305 FILE * fin; 305
306 int size_read; 306 for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
307 const char* filenameinzip = argv[i]; 307 {
308 zip_fileinfo zi; 308 if (((*(argv[i]))!='-') && ((*(argv[i]))!='/'))
309 unsigned long crcFile=0; 309 {
310 310 FILE * fin;
311 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = 311 int size_read;
312 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; 312 const char* filenameinzip = argv[i];
313 zi.dosDate = 0; 313 zip_fileinfo zi;
314 zi.internal_fa = 0; 314 unsigned long crcFile=0;
315 zi.external_fa = 0; 315
316 filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); 316 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
317 317 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
318/* 318 zi.dosDate = 0;
319 err = zipOpenNewFileInZip(zf,filenameinzip,&zi, 319 zi.internal_fa = 0;
320 NULL,0,NULL,0,NULL / * comment * /, 320 zi.external_fa = 0;
321 (opt_compress_level != 0) ? Z_DEFLATED : 0, 321 filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
322 opt_compress_level); 322
323*/ 323/*
324 if ((password != NULL) && (err==ZIP_OK)) 324 err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
325 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); 325 NULL,0,NULL,0,NULL / * comment * /,
326 326 (opt_compress_level != 0) ? Z_DEFLATED : 0,
327 err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, 327 opt_compress_level);
328 NULL,0,NULL,0,NULL /* comment*/, 328*/
329 (opt_compress_level != 0) ? Z_DEFLATED : 0, 329 if ((password != NULL) && (err==ZIP_OK))
330 opt_compress_level,0, 330 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
331 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ 331
332 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 332 err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
333 password,crcFile); 333 NULL,0,NULL,0,NULL /* comment*/,
334 334 (opt_compress_level != 0) ? Z_DEFLATED : 0,
335 if (err != ZIP_OK) 335 opt_compress_level,0,
336 printf("error in opening %s in zipfile\n",filenameinzip); 336 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
337 else 337 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
338 { 338 password,crcFile);
339 fin = fopen(filenameinzip,"rb"); 339
340 if (fin==NULL) 340 if (err != ZIP_OK)
341 { 341 printf("error in opening %s in zipfile\n",filenameinzip);
342 err=ZIP_ERRNO; 342 else
343 printf("error in opening %s for reading\n",filenameinzip); 343 {
344 } 344 fin = fopen(filenameinzip,"rb");
345 } 345 if (fin==NULL)
346 346 {
347 if (err == ZIP_OK) 347 err=ZIP_ERRNO;
348 do 348 printf("error in opening %s for reading\n",filenameinzip);
349 { 349 }
350 err = ZIP_OK; 350 }
351 size_read = (int)fread(buf,1,size_buf,fin); 351
352 if (size_read < size_buf) 352 if (err == ZIP_OK)
353 if (feof(fin)==0) 353 do
354 { 354 {
355 printf("error in reading %s\n",filenameinzip); 355 err = ZIP_OK;
356 err = ZIP_ERRNO; 356 size_read = (int)fread(buf,1,size_buf,fin);
357 } 357 if (size_read < size_buf)
358 358 if (feof(fin)==0)
359 if (size_read>0) 359 {
360 { 360 printf("error in reading %s\n",filenameinzip);
361 err = zipWriteInFileInZip (zf,buf,size_read); 361 err = ZIP_ERRNO;
362 if (err<0) 362 }
363 { 363
364 printf("error in writing %s in the zipfile\n", 364 if (size_read>0)
365 filenameinzip); 365 {
366 } 366 err = zipWriteInFileInZip (zf,buf,size_read);
367 367 if (err<0)
368 } 368 {
369 } while ((err == ZIP_OK) && (size_read>0)); 369 printf("error in writing %s in the zipfile\n",
370 370 filenameinzip);
371 if (fin) 371 }
372 fclose(fin); 372
373 373 }
374 if (err<0) 374 } while ((err == ZIP_OK) && (size_read>0));
375 err=ZIP_ERRNO; 375
376 else 376 if (fin)
377 { 377 fclose(fin);
378 err = zipCloseFileInZip(zf); 378
379 if (err!=ZIP_OK) 379 if (err<0)
380 printf("error in closing %s in the zipfile\n", 380 err=ZIP_ERRNO;
381 filenameinzip); 381 else
382 } 382 {
383 } 383 err = zipCloseFileInZip(zf);
384 } 384 if (err!=ZIP_OK)
385 errclose = zipClose(zf,NULL); 385 printf("error in closing %s in the zipfile\n",
386 if (errclose != ZIP_OK) 386 filenameinzip);
387 printf("error in closing %s\n",filename_try); 387 }
388 } 388 }
389 389 }
390 free(buf); 390 errclose = zipClose(zf,NULL);
391 return 0; 391 if (errclose != ZIP_OK)
392} 392 printf("error in closing %s\n",filename_try);
393 }
394
395 free(buf);
396 return 0;
397}
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index 7244523..07d869e 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -1,1529 +1,1531 @@
1/* unzip.c -- IO for uncompress .zip files using zlib 1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 0.21 with encryption, March 10th, 2003 2 Version 0.22, May 19th, 2003
3 3
4 Copyright (C) 1998-2003 Gilles Vollant 4 Copyright (C) 1998-2003 Gilles Vollant
5 5
6 Read unzip.h for more info 6 Read unzip.h for more info
7*/ 7*/
8 8
9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of 9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
10compatibility with older software. The following is from the original crypt.c. Code 10compatibility with older software. The following is from the original crypt.c. Code
11woven in by Terry Thorsen 1/2003. 11woven in by Terry Thorsen 1/2003.
12*/ 12*/
13/* 13/*
14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15 15
16 See the accompanying file LICENSE, version 2000-Apr-09 or later 16 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. 17 (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 18 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 19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/ 20*/
21/* 21/*
22 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 23
24 The encryption/decryption parts of this source code (as opposed to the 24 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The 25 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA. 26 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.) 27 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */ 28 */
29 29
30/* 30/*
31 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 32 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 33 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities). 34 version without encryption capabilities).
35 */ 35 */
36 36
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <string.h> 40#include <string.h>
41#include "zlib.h" 41#include "zlib.h"
42#include "unzip.h" 42#include "unzip.h"
43 43
44#ifdef STDC 44#ifdef STDC
45# include <stddef.h> 45# include <stddef.h>
46# include <string.h> 46# include <string.h>
47# include <stdlib.h> 47# include <stdlib.h>
48#endif 48#endif
49#ifdef NO_ERRNO_H 49#ifdef NO_ERRNO_H
50 extern int errno; 50 extern int errno;
51#else 51#else
52# include <errno.h> 52# include <errno.h>
53#endif 53#endif
54 54
55 55
56#ifndef local 56#ifndef local
57# define local static 57# define local static
58#endif 58#endif
59/* compile with -Dlocal if your debugger can't find static symbols */ 59/* compile with -Dlocal if your debugger can't find static symbols */
60 60
61 61
62 62
63#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ 63#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
64 !defined(CASESENSITIVITYDEFAULT_NO) 64 !defined(CASESENSITIVITYDEFAULT_NO)
65#define CASESENSITIVITYDEFAULT_NO 65#define CASESENSITIVITYDEFAULT_NO
66#endif 66#endif
67 67
68 68
69#ifndef UNZ_BUFSIZE 69#ifndef UNZ_BUFSIZE
70#define UNZ_BUFSIZE (16384) 70#define UNZ_BUFSIZE (16384)
71#endif 71#endif
72 72
73#ifndef UNZ_MAXFILENAMEINZIP 73#ifndef UNZ_MAXFILENAMEINZIP
74#define UNZ_MAXFILENAMEINZIP (256) 74#define UNZ_MAXFILENAMEINZIP (256)
75#endif 75#endif
76 76
77#ifndef ALLOC 77#ifndef ALLOC
78# define ALLOC(size) (malloc(size)) 78# define ALLOC(size) (malloc(size))
79#endif 79#endif
80#ifndef TRYFREE 80#ifndef TRYFREE
81# define TRYFREE(p) {if (p) free(p);} 81# define TRYFREE(p) {if (p) free(p);}
82#endif 82#endif
83 83
84#define SIZECENTRALDIRITEM (0x2e) 84#define SIZECENTRALDIRITEM (0x2e)
85#define SIZEZIPLOCALHEADER (0x1e) 85#define SIZEZIPLOCALHEADER (0x1e)
86 86
87 87
88 88
89 89
90const char unz_copyright[] = 90const char unz_copyright[] =
91 " unzip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; 91 " unzip 0.22 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
92 92
93/* unz_file_info_interntal contain internal info about a file in zipfile*/ 93/* unz_file_info_interntal contain internal info about a file in zipfile*/
94typedef struct unz_file_info_internal_s 94typedef struct unz_file_info_internal_s
95{ 95{
96 uLong offset_curfile;/* relative offset of local header 4 bytes */ 96 uLong offset_curfile;/* relative offset of local header 4 bytes */
97} unz_file_info_internal; 97} unz_file_info_internal;
98 98
99 99
100/* file_in_zip_read_info_s contain internal information about a file in zipfile, 100/* file_in_zip_read_info_s contain internal information about a file in zipfile,
101 when reading and decompress it */ 101 when reading and decompress it */
102typedef struct 102typedef struct
103{ 103{
104 char *read_buffer; /* internal buffer for compressed data */ 104 char *read_buffer; /* internal buffer for compressed data */
105 z_stream stream; /* zLib stream structure for inflate */ 105 z_stream stream; /* zLib stream structure for inflate */
106 106
107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
108 uLong stream_initialised; /* flag set if stream structure is initialised*/ 108 uLong stream_initialised; /* flag set if stream structure is initialised*/
109 109
110 uLong offset_local_extrafield;/* offset of the local extra field */ 110 uLong offset_local_extrafield;/* offset of the local extra field */
111 uInt size_local_extrafield;/* size of the local extra field */ 111 uInt size_local_extrafield;/* size of the local extra field */
112 uLong pos_local_extrafield; /* position in the local extra field in read*/ 112 uLong pos_local_extrafield; /* position in the local extra field in read*/
113 113
114 uLong crc32; /* crc32 of all data uncompressed */ 114 uLong crc32; /* crc32 of all data uncompressed */
115 uLong crc32_wait; /* crc32 we must obtain after decompress all */ 115 uLong crc32_wait; /* crc32 we must obtain after decompress all */
116 uLong rest_read_compressed; /* number of byte to be decompressed */ 116 uLong rest_read_compressed; /* number of byte to be decompressed */
117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
118 zlib_filefunc_def z_filefunc; 118 zlib_filefunc_def z_filefunc;
119 voidpf filestream; /* io structore of the zipfile */ 119 voidpf filestream; /* io structore of the zipfile */
120 uLong compression_method; /* compression method (0==store) */ 120 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw; 122 int raw;
123} file_in_zip_read_info_s; 123} file_in_zip_read_info_s;
124 124
125 125
126/* unz_s contain internal information about the zipfile 126/* unz_s contain internal information about the zipfile
127*/ 127*/
128typedef struct 128typedef struct
129{ 129{
130 zlib_filefunc_def z_filefunc; 130 zlib_filefunc_def z_filefunc;
131 voidpf filestream; /* io structore of the zipfile */ 131 voidpf filestream; /* io structore of the zipfile */
132 unz_global_info gi; /* public global information */ 132 unz_global_info gi; /* public global information */
133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
134 uLong num_file; /* number of the current file in the zipfile*/ 134 uLong 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*/ 135 uLong 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*/ 136 uLong current_file_ok; /* flag about the usability of the current file*/
137 uLong central_pos; /* position of the beginning of the central dir*/ 137 uLong central_pos; /* position of the beginning of the central dir*/
138 138
139 uLong size_central_dir; /* size of the central directory */ 139 uLong size_central_dir; /* size of the central directory */
140 uLong offset_central_dir; /* offset of start of central directory with 140 uLong offset_central_dir; /* offset of start of central directory with
141 respect to the starting disk number */ 141 respect to the starting disk number */
142 142
143 unz_file_info cur_file_info; /* public info about the current file in zip*/ 143 unz_file_info cur_file_info; /* public info about the current file in zip*/
144 unz_file_info_internal cur_file_info_internal; /* private info about it*/ 144 unz_file_info_internal cur_file_info_internal; /* private info about it*/
145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current 145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
146 file if we are decompressing it */ 146 file if we are decompressing it */
147 int encrypted; 147 int encrypted;
148 #ifndef NOUNCRPYT 148 #ifndef NOUNCRYPT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab; 150 const unsigned long* pcrc_32_tab;
151 #endif 151 #endif
152} unz_s; 152} unz_s;
153 153
154 154
155#ifndef NOUNCRPYT 155#ifndef NOUNCRYPT
156#include "crypt.h" 156#include "crypt.h"
157#endif 157#endif
158 158
159/* =========================================================================== 159/* ===========================================================================
160 Read a byte from a gz_stream; update next_in and avail_in. Return EOF 160 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
161 for end of file. 161 for end of file.
162 IN assertion: the stream s has been sucessfully opened for reading. 162 IN assertion: the stream s has been sucessfully opened for reading.
163*/ 163*/
164 164
165 165
166local int unzlocal_getByte OF(( 166local int unzlocal_getByte OF((
167 const zlib_filefunc_def* pzlib_filefunc_def, 167 const zlib_filefunc_def* pzlib_filefunc_def,
168 voidpf filestream, 168 voidpf filestream,
169 int *pi)); 169 int *pi));
170 170
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) 171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
172 const zlib_filefunc_def* pzlib_filefunc_def; 172 const zlib_filefunc_def* pzlib_filefunc_def;
173 voidpf filestream; 173 voidpf filestream;
174 int *pi; 174 int *pi;
175{ 175{
176 unsigned char c; 176 unsigned char c;
177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
178 if (err==1) 178 if (err==1)
179 { 179 {
180 *pi = (int)c; 180 *pi = (int)c;
181 return UNZ_OK; 181 return UNZ_OK;
182 } 182 }
183 else 183 else
184 { 184 {
185 if (ZERROR(*pzlib_filefunc_def,filestream)) 185 if (ZERROR(*pzlib_filefunc_def,filestream))
186 return UNZ_ERRNO; 186 return UNZ_ERRNO;
187 else 187 else
188 return UNZ_EOF; 188 return UNZ_EOF;
189 } 189 }
190} 190}
191 191
192 192
193/* =========================================================================== 193/* ===========================================================================
194 Reads a long in LSB order from the given gz_stream. Sets 194 Reads a long in LSB order from the given gz_stream. Sets
195*/ 195*/
196local int unzlocal_getShort OF(( 196local int unzlocal_getShort OF((
197 const zlib_filefunc_def* pzlib_filefunc_def, 197 const zlib_filefunc_def* pzlib_filefunc_def,
198 voidpf filestream, 198 voidpf filestream,
199 uLong *pX)); 199 uLong *pX));
200 200
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) 201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
202 const zlib_filefunc_def* pzlib_filefunc_def; 202 const zlib_filefunc_def* pzlib_filefunc_def;
203 voidpf filestream; 203 voidpf filestream;
204 uLong *pX; 204 uLong *pX;
205{ 205{
206 uLong x ; 206 uLong x ;
207 int i; 207 int i;
208 int err; 208 int err;
209 209
210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
211 x = (uLong)i; 211 x = (uLong)i;
212 212
213 if (err==UNZ_OK) 213 if (err==UNZ_OK)
214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
215 x += ((uLong)i)<<8; 215 x += ((uLong)i)<<8;
216 216
217 if (err==UNZ_OK) 217 if (err==UNZ_OK)
218 *pX = x; 218 *pX = x;
219 else 219 else
220 *pX = 0; 220 *pX = 0;
221 return err; 221 return err;
222} 222}
223 223
224local int unzlocal_getLong OF(( 224local int unzlocal_getLong OF((
225 const zlib_filefunc_def* pzlib_filefunc_def, 225 const zlib_filefunc_def* pzlib_filefunc_def,
226 voidpf filestream, 226 voidpf filestream,
227 uLong *pX)); 227 uLong *pX));
228 228
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) 229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
230 const zlib_filefunc_def* pzlib_filefunc_def; 230 const zlib_filefunc_def* pzlib_filefunc_def;
231 voidpf filestream; 231 voidpf filestream;
232 uLong *pX; 232 uLong *pX;
233{ 233{
234 uLong x ; 234 uLong x ;
235 int i; 235 int i;
236 int err; 236 int err;
237 237
238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
239 x = (uLong)i; 239 x = (uLong)i;
240 240
241 if (err==UNZ_OK) 241 if (err==UNZ_OK)
242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
243 x += ((uLong)i)<<8; 243 x += ((uLong)i)<<8;
244 244
245 if (err==UNZ_OK) 245 if (err==UNZ_OK)
246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
247 x += ((uLong)i)<<16; 247 x += ((uLong)i)<<16;
248 248
249 if (err==UNZ_OK) 249 if (err==UNZ_OK)
250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
251 x += ((uLong)i)<<24; 251 x += ((uLong)i)<<24;
252 252
253 if (err==UNZ_OK) 253 if (err==UNZ_OK)
254 *pX = x; 254 *pX = x;
255 else 255 else
256 *pX = 0; 256 *pX = 0;
257 return err; 257 return err;
258} 258}
259 259
260 260
261/* My own strcmpi / strcasecmp */ 261/* My own strcmpi / strcasecmp */
262local int strcmpcasenosensitive_internal (fileName1,fileName2) 262local int strcmpcasenosensitive_internal (fileName1,fileName2)
263 const char* fileName1; 263 const char* fileName1;
264 const char* fileName2; 264 const char* fileName2;
265{ 265{
266 for (;;) 266 for (;;)
267 { 267 {
268 char c1=*(fileName1++); 268 char c1=*(fileName1++);
269 char c2=*(fileName2++); 269 char c2=*(fileName2++);
270 if ((c1>='a') && (c1<='z')) 270 if ((c1>='a') && (c1<='z'))
271 c1 -= 0x20; 271 c1 -= 0x20;
272 if ((c2>='a') && (c2<='z')) 272 if ((c2>='a') && (c2<='z'))
273 c2 -= 0x20; 273 c2 -= 0x20;
274 if (c1=='\0') 274 if (c1=='\0')
275 return ((c2=='\0') ? 0 : -1); 275 return ((c2=='\0') ? 0 : -1);
276 if (c2=='\0') 276 if (c2=='\0')
277 return 1; 277 return 1;
278 if (c1<c2) 278 if (c1<c2)
279 return -1; 279 return -1;
280 if (c1>c2) 280 if (c1>c2)
281 return 1; 281 return 1;
282 } 282 }
283} 283}
284 284
285 285
286#ifdef CASESENSITIVITYDEFAULT_NO 286#ifdef CASESENSITIVITYDEFAULT_NO
287#define CASESENSITIVITYDEFAULTVALUE 2 287#define CASESENSITIVITYDEFAULTVALUE 2
288#else 288#else
289#define CASESENSITIVITYDEFAULTVALUE 1 289#define CASESENSITIVITYDEFAULTVALUE 1
290#endif 290#endif
291 291
292#ifndef STRCMPCASENOSENTIVEFUNCTION 292#ifndef STRCMPCASENOSENTIVEFUNCTION
293#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal 293#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
294#endif 294#endif
295 295
296/* 296/*
297 Compare two filename (fileName1,fileName2). 297 Compare two filename (fileName1,fileName2).
298 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 298 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
299 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 299 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
300 or strcasecmp) 300 or strcasecmp)
301 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 301 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
302 (like 1 on Unix, 2 on Windows) 302 (like 1 on Unix, 2 on Windows)
303 303
304*/ 304*/
305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) 305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
306 const char* fileName1; 306 const char* fileName1;
307 const char* fileName2; 307 const char* fileName2;
308 int iCaseSensitivity; 308 int iCaseSensitivity;
309{ 309{
310 if (iCaseSensitivity==0) 310 if (iCaseSensitivity==0)
311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
312 312
313 if (iCaseSensitivity==1) 313 if (iCaseSensitivity==1)
314 return strcmp(fileName1,fileName2); 314 return strcmp(fileName1,fileName2);
315 315
316 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); 316 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
317} 317}
318 318
319#ifndef BUFREADCOMMENT 319#ifndef BUFREADCOMMENT
320#define BUFREADCOMMENT (0x400) 320#define BUFREADCOMMENT (0x400)
321#endif 321#endif
322 322
323/* 323/*
324 Locate the Central directory of a zipfile (at the end, just before 324 Locate the Central directory of a zipfile (at the end, just before
325 the global comment) 325 the global comment)
326*/ 326*/
327local uLong unzlocal_SearchCentralDir OF(( 327local uLong unzlocal_SearchCentralDir OF((
328 const zlib_filefunc_def* pzlib_filefunc_def, 328 const zlib_filefunc_def* pzlib_filefunc_def,
329 voidpf filestream)); 329 voidpf filestream));
330 330
331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) 331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
332 const zlib_filefunc_def* pzlib_filefunc_def; 332 const zlib_filefunc_def* pzlib_filefunc_def;
333 voidpf filestream; 333 voidpf filestream;
334{ 334{
335 unsigned char* buf; 335 unsigned char* buf;
336 uLong uSizeFile; 336 uLong uSizeFile;
337 uLong uBackRead; 337 uLong uBackRead;
338 uLong uMaxBack=0xffff; /* maximum size of global comment */ 338 uLong uMaxBack=0xffff; /* maximum size of global comment */
339 uLong uPosFound=0; 339 uLong uPosFound=0;
340 340
341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
342 return 0; 342 return 0;
343 343
344 344
345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
346 346
347 if (uMaxBack>uSizeFile) 347 if (uMaxBack>uSizeFile)
348 uMaxBack = uSizeFile; 348 uMaxBack = uSizeFile;
349 349
350 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 350 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
351 if (buf==NULL) 351 if (buf==NULL)
352 return 0; 352 return 0;
353 353
354 uBackRead = 4; 354 uBackRead = 4;
355 while (uBackRead<uMaxBack) 355 while (uBackRead<uMaxBack)
356 { 356 {
357 uLong uReadSize,uReadPos ; 357 uLong uReadSize,uReadPos ;
358 int i; 358 int i;
359 if (uBackRead+BUFREADCOMMENT>uMaxBack) 359 if (uBackRead+BUFREADCOMMENT>uMaxBack)
360 uBackRead = uMaxBack; 360 uBackRead = uMaxBack;
361 else 361 else
362 uBackRead+=BUFREADCOMMENT; 362 uBackRead+=BUFREADCOMMENT;
363 uReadPos = uSizeFile-uBackRead ; 363 uReadPos = uSizeFile-uBackRead ;
364 364
365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
368 break; 368 break;
369 369
370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
371 break; 371 break;
372 372
373 for (i=(int)uReadSize-3; (i--)>0;) 373 for (i=(int)uReadSize-3; (i--)>0;)
374 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 374 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
375 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 375 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
376 { 376 {
377 uPosFound = uReadPos+i; 377 uPosFound = uReadPos+i;
378 break; 378 break;
379 } 379 }
380 380
381 if (uPosFound!=0) 381 if (uPosFound!=0)
382 break; 382 break;
383 } 383 }
384 TRYFREE(buf); 384 TRYFREE(buf);
385 return uPosFound; 385 return uPosFound;
386} 386}
387 387
388/* 388/*
389 Open a Zip file. path contain the full pathname (by example, 389 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 390 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
391 "zlib/zlib114.zip". 391 "zlib/zlib114.zip".
392 If the zipfile cannot be opened (file doesn't exist or in not valid), the 392 If the zipfile cannot be opened (file doesn't exist or in not valid), the
393 return value is NULL. 393 return value is NULL.
394 Else, the return value is a unzFile Handle, usable with other function 394 Else, the return value is a unzFile Handle, usable with other function
395 of this unzip package. 395 of this unzip package.
396*/ 396*/
397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) 397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
398 const char *path; 398 const char *path;
399 zlib_filefunc_def* pzlib_filefunc_def; 399 zlib_filefunc_def* pzlib_filefunc_def;
400{ 400{
401 unz_s us; 401 unz_s us;
402 unz_s *s; 402 unz_s *s;
403 uLong central_pos,uL; 403 uLong central_pos,uL;
404 404
405 uLong number_disk; /* number of the current dist, used for 405 uLong number_disk; /* number of the current dist, used for
406 spaning ZIP, unsupported, always 0*/ 406 spaning ZIP, unsupported, always 0*/
407 uLong number_disk_with_CD; /* number the the disk with central dir, used 407 uLong number_disk_with_CD; /* number the the disk with central dir, used
408 for spaning ZIP, unsupported, always 0*/ 408 for spaning ZIP, unsupported, always 0*/
409 uLong number_entry_CD; /* total number of entries in 409 uLong number_entry_CD; /* total number of entries in
410 the central dir 410 the central dir
411 (same than number_entry on nospan) */ 411 (same than number_entry on nospan) */
412 412
413 int err=UNZ_OK; 413 int err=UNZ_OK;
414 414
415 if (unz_copyright[0]!=' ') 415 if (unz_copyright[0]!=' ')
416 return NULL; 416 return NULL;
417 417
418 if (pzlib_filefunc_def==NULL) 418 if (pzlib_filefunc_def==NULL)
419 fill_fopen_filefunc(&us.z_filefunc); 419 fill_fopen_filefunc(&us.z_filefunc);
420 else 420 else
421 us.z_filefunc = *pzlib_filefunc_def; 421 us.z_filefunc = *pzlib_filefunc_def;
422 422
423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, 423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
424 path, 424 path,
425 ZLIB_FILEFUNC_MODE_READ | 425 ZLIB_FILEFUNC_MODE_READ |
426 ZLIB_FILEFUNC_MODE_EXISTING); 426 ZLIB_FILEFUNC_MODE_EXISTING);
427 if (us.filestream==NULL) 427 if (us.filestream==NULL)
428 return NULL; 428 return NULL;
429 429
430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); 430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
431 if (central_pos==0) 431 if (central_pos==0)
432 err=UNZ_ERRNO; 432 err=UNZ_ERRNO;
433 433
434 if (ZSEEK(us.z_filefunc, us.filestream, 434 if (ZSEEK(us.z_filefunc, us.filestream,
435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
436 err=UNZ_ERRNO; 436 err=UNZ_ERRNO;
437 437
438 /* the signature, already checked */ 438 /* the signature, already checked */
439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
440 err=UNZ_ERRNO; 440 err=UNZ_ERRNO;
441 441
442 /* number of this disk */ 442 /* number of this disk */
443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
444 err=UNZ_ERRNO; 444 err=UNZ_ERRNO;
445 445
446 /* number of the disk with the start of the central directory */ 446 /* number of the disk with the start of the central directory */
447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
448 err=UNZ_ERRNO; 448 err=UNZ_ERRNO;
449 449
450 /* total number of entries in the central dir on this disk */ 450 /* total number of entries in the central dir on this disk */
451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
452 err=UNZ_ERRNO; 452 err=UNZ_ERRNO;
453 453
454 /* total number of entries in the central dir */ 454 /* total number of entries in the central dir */
455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
456 err=UNZ_ERRNO; 456 err=UNZ_ERRNO;
457 457
458 if ((number_entry_CD!=us.gi.number_entry) || 458 if ((number_entry_CD!=us.gi.number_entry) ||
459 (number_disk_with_CD!=0) || 459 (number_disk_with_CD!=0) ||
460 (number_disk!=0)) 460 (number_disk!=0))
461 err=UNZ_BADZIPFILE; 461 err=UNZ_BADZIPFILE;
462 462
463 /* size of the central directory */ 463 /* size of the central directory */
464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) 464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
465 err=UNZ_ERRNO; 465 err=UNZ_ERRNO;
466 466
467 /* offset of start of central directory with respect to the 467 /* offset of start of central directory with respect to the
468 starting disk number */ 468 starting disk number */
469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
470 err=UNZ_ERRNO; 470 err=UNZ_ERRNO;
471 471
472 /* zipfile comment length */ 472 /* zipfile comment length */
473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
474 err=UNZ_ERRNO; 474 err=UNZ_ERRNO;
475 475
476 if ((central_pos<us.offset_central_dir+us.size_central_dir) && 476 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
477 (err==UNZ_OK)) 477 (err==UNZ_OK))
478 err=UNZ_BADZIPFILE; 478 err=UNZ_BADZIPFILE;
479 479
480 if (err!=UNZ_OK) 480 if (err!=UNZ_OK)
481 { 481 {
482 ZCLOSE(us.z_filefunc, us.filestream); 482 ZCLOSE(us.z_filefunc, us.filestream);
483 return NULL; 483 return NULL;
484 } 484 }
485 485
486 us.byte_before_the_zipfile = central_pos - 486 us.byte_before_the_zipfile = central_pos -
487 (us.offset_central_dir+us.size_central_dir); 487 (us.offset_central_dir+us.size_central_dir);
488 us.central_pos = central_pos; 488 us.central_pos = central_pos;
489 us.pfile_in_zip_read = NULL; 489 us.pfile_in_zip_read = NULL;
490 us.encrypted = 0; 490 us.encrypted = 0;
491 491
492 492
493 s=(unz_s*)ALLOC(sizeof(unz_s)); 493 s=(unz_s*)ALLOC(sizeof(unz_s));
494 *s=us; 494 *s=us;
495 unzGoToFirstFile((unzFile)s); 495 unzGoToFirstFile((unzFile)s);
496 return (unzFile)s; 496 return (unzFile)s;
497} 497}
498 498
499 499
500extern unzFile ZEXPORT unzOpen (path) 500extern unzFile ZEXPORT unzOpen (path)
501 const char *path; 501 const char *path;
502{ 502{
503 return unzOpen2(path, NULL); 503 return unzOpen2(path, NULL);
504} 504}
505 505
506/* 506/*
507 Close a ZipFile opened with unzipOpen. 507 Close a ZipFile opened with unzipOpen.
508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
510 return UNZ_OK if there is no problem. */ 510 return UNZ_OK if there is no problem. */
511extern int ZEXPORT unzClose (file) 511extern int ZEXPORT unzClose (file)
512 unzFile file; 512 unzFile file;
513{ 513{
514 unz_s* s; 514 unz_s* s;
515 if (file==NULL) 515 if (file==NULL)
516 return UNZ_PARAMERROR; 516 return UNZ_PARAMERROR;
517 s=(unz_s*)file; 517 s=(unz_s*)file;
518 518
519 if (s->pfile_in_zip_read!=NULL) 519 if (s->pfile_in_zip_read!=NULL)
520 unzCloseCurrentFile(file); 520 unzCloseCurrentFile(file);
521 521
522 ZCLOSE(s->z_filefunc, s->filestream); 522 ZCLOSE(s->z_filefunc, s->filestream);
523 TRYFREE(s); 523 TRYFREE(s);
524 return UNZ_OK; 524 return UNZ_OK;
525} 525}
526 526
527 527
528/* 528/*
529 Write info about the ZipFile in the *pglobal_info structure. 529 Write info about the ZipFile in the *pglobal_info structure.
530 No preparation of the structure is needed 530 No preparation of the structure is needed
531 return UNZ_OK if there is no problem. */ 531 return UNZ_OK if there is no problem. */
532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) 532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
533 unzFile file; 533 unzFile file;
534 unz_global_info *pglobal_info; 534 unz_global_info *pglobal_info;
535{ 535{
536 unz_s* s; 536 unz_s* s;
537 if (file==NULL) 537 if (file==NULL)
538 return UNZ_PARAMERROR; 538 return UNZ_PARAMERROR;
539 s=(unz_s*)file; 539 s=(unz_s*)file;
540 *pglobal_info=s->gi; 540 *pglobal_info=s->gi;
541 return UNZ_OK; 541 return UNZ_OK;
542} 542}
543 543
544 544
545/* 545/*
546 Translate date/time from Dos format to tm_unz (readable more easilty) 546 Translate date/time from Dos format to tm_unz (readable more easilty)
547*/ 547*/
548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) 548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
549 uLong ulDosDate; 549 uLong ulDosDate;
550 tm_unz* ptm; 550 tm_unz* ptm;
551{ 551{
552 uLong uDate; 552 uLong uDate;
553 uDate = (uLong)(ulDosDate>>16); 553 uDate = (uLong)(ulDosDate>>16);
554 ptm->tm_mday = (uInt)(uDate&0x1f) ; 554 ptm->tm_mday = (uInt)(uDate&0x1f) ;
555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
557 557
558 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); 558 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
559 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; 559 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
560 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; 560 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
561} 561}
562 562
563/* 563/*
564 Get Info about the current file in the zipfile, with internal only info 564 Get Info about the current file in the zipfile, with internal only info
565*/ 565*/
566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, 566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
567 unz_file_info *pfile_info, 567 unz_file_info *pfile_info,
568 unz_file_info_internal 568 unz_file_info_internal
569 *pfile_info_internal, 569 *pfile_info_internal,
570 char *szFileName, 570 char *szFileName,
571 uLong fileNameBufferSize, 571 uLong fileNameBufferSize,
572 void *extraField, 572 void *extraField,
573 uLong extraFieldBufferSize, 573 uLong extraFieldBufferSize,
574 char *szComment, 574 char *szComment,
575 uLong commentBufferSize)); 575 uLong commentBufferSize));
576 576
577local int unzlocal_GetCurrentFileInfoInternal (file, 577local int unzlocal_GetCurrentFileInfoInternal (file,
578 pfile_info, 578 pfile_info,
579 pfile_info_internal, 579 pfile_info_internal,
580 szFileName, fileNameBufferSize, 580 szFileName, fileNameBufferSize,
581 extraField, extraFieldBufferSize, 581 extraField, extraFieldBufferSize,
582 szComment, commentBufferSize) 582 szComment, commentBufferSize)
583 unzFile file; 583 unzFile file;
584 unz_file_info *pfile_info; 584 unz_file_info *pfile_info;
585 unz_file_info_internal *pfile_info_internal; 585 unz_file_info_internal *pfile_info_internal;
586 char *szFileName; 586 char *szFileName;
587 uLong fileNameBufferSize; 587 uLong fileNameBufferSize;
588 void *extraField; 588 void *extraField;
589 uLong extraFieldBufferSize; 589 uLong extraFieldBufferSize;
590 char *szComment; 590 char *szComment;
591 uLong commentBufferSize; 591 uLong commentBufferSize;
592{ 592{
593 unz_s* s; 593 unz_s* s;
594 unz_file_info file_info; 594 unz_file_info file_info;
595 unz_file_info_internal file_info_internal; 595 unz_file_info_internal file_info_internal;
596 int err=UNZ_OK; 596 int err=UNZ_OK;
597 uLong uMagic; 597 uLong uMagic;
598 long lSeek=0; 598 long lSeek=0;
599 599
600 if (file==NULL) 600 if (file==NULL)
601 return UNZ_PARAMERROR; 601 return UNZ_PARAMERROR;
602 s=(unz_s*)file; 602 s=(unz_s*)file;
603 if (ZSEEK(s->z_filefunc, s->filestream, 603 if (ZSEEK(s->z_filefunc, s->filestream,
604 s->pos_in_central_dir+s->byte_before_the_zipfile, 604 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0) 605 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO; 606 err=UNZ_ERRNO;
607 607
608 608
609 /* we check the magic */ 609 /* we check the magic */
610 if (err==UNZ_OK) 610 if (err==UNZ_OK)
611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
612 err=UNZ_ERRNO; 612 err=UNZ_ERRNO;
613 else if (uMagic!=0x02014b50) 613 else if (uMagic!=0x02014b50)
614 err=UNZ_BADZIPFILE; 614 err=UNZ_BADZIPFILE;
615 615
616 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 616 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
617 err=UNZ_ERRNO; 617 err=UNZ_ERRNO;
618 618
619 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 619 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
620 err=UNZ_ERRNO; 620 err=UNZ_ERRNO;
621 621
622 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 622 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
623 err=UNZ_ERRNO; 623 err=UNZ_ERRNO;
624 624
625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
626 err=UNZ_ERRNO; 626 err=UNZ_ERRNO;
627 627
628 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 628 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
629 err=UNZ_ERRNO; 629 err=UNZ_ERRNO;
630 630
631 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 631 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
632 632
633 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 633 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
634 err=UNZ_ERRNO; 634 err=UNZ_ERRNO;
635 635
636 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 636 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
637 err=UNZ_ERRNO; 637 err=UNZ_ERRNO;
638 638
639 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 639 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
640 err=UNZ_ERRNO; 640 err=UNZ_ERRNO;
641 641
642 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 642 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
643 err=UNZ_ERRNO; 643 err=UNZ_ERRNO;
644 644
645 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 645 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
646 err=UNZ_ERRNO; 646 err=UNZ_ERRNO;
647 647
648 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 648 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
649 err=UNZ_ERRNO; 649 err=UNZ_ERRNO;
650 650
651 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 651 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
652 err=UNZ_ERRNO; 652 err=UNZ_ERRNO;
653 653
654 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 654 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
655 err=UNZ_ERRNO; 655 err=UNZ_ERRNO;
656 656
657 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 657 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
658 err=UNZ_ERRNO; 658 err=UNZ_ERRNO;
659 659
660 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 660 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
661 err=UNZ_ERRNO; 661 err=UNZ_ERRNO;
662 662
663 lSeek+=file_info.size_filename; 663 lSeek+=file_info.size_filename;
664 if ((err==UNZ_OK) && (szFileName!=NULL)) 664 if ((err==UNZ_OK) && (szFileName!=NULL))
665 { 665 {
666 uLong uSizeRead ; 666 uLong uSizeRead ;
667 if (file_info.size_filename<fileNameBufferSize) 667 if (file_info.size_filename<fileNameBufferSize)
668 { 668 {
669 *(szFileName+file_info.size_filename)='\0'; 669 *(szFileName+file_info.size_filename)='\0';
670 uSizeRead = file_info.size_filename; 670 uSizeRead = file_info.size_filename;
671 } 671 }
672 else 672 else
673 uSizeRead = fileNameBufferSize; 673 uSizeRead = fileNameBufferSize;
674 674
675 if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 675 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
676 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 676 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
677 err=UNZ_ERRNO; 677 err=UNZ_ERRNO;
678 lSeek -= uSizeRead; 678 lSeek -= uSizeRead;
679 } 679 }
680 680
681 681
682 if ((err==UNZ_OK) && (extraField!=NULL)) 682 if ((err==UNZ_OK) && (extraField!=NULL))
683 { 683 {
684 uLong uSizeRead ; 684 uLong uSizeRead ;
685 if (file_info.size_file_extra<extraFieldBufferSize) 685 if (file_info.size_file_extra<extraFieldBufferSize)
686 uSizeRead = file_info.size_file_extra; 686 uSizeRead = file_info.size_file_extra;
687 else 687 else
688 uSizeRead = extraFieldBufferSize; 688 uSizeRead = extraFieldBufferSize;
689 689
690 if (lSeek!=0) 690 if (lSeek!=0)
691 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 691 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
692 lSeek=0; 692 lSeek=0;
693 else 693 else
694 err=UNZ_ERRNO; 694 err=UNZ_ERRNO;
695 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 695 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
696 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) 696 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
697 err=UNZ_ERRNO; 697 err=UNZ_ERRNO;
698 lSeek += file_info.size_file_extra - uSizeRead; 698 lSeek += file_info.size_file_extra - uSizeRead;
699 } 699 }
700 else 700 else
701 lSeek+=file_info.size_file_extra; 701 lSeek+=file_info.size_file_extra;
702 702
703 703
704 if ((err==UNZ_OK) && (szComment!=NULL)) 704 if ((err==UNZ_OK) && (szComment!=NULL))
705 { 705 {
706 uLong uSizeRead ; 706 uLong uSizeRead ;
707 if (file_info.size_file_comment<commentBufferSize) 707 if (file_info.size_file_comment<commentBufferSize)
708 { 708 {
709 *(szComment+file_info.size_file_comment)='\0'; 709 *(szComment+file_info.size_file_comment)='\0';
710 uSizeRead = file_info.size_file_comment; 710 uSizeRead = file_info.size_file_comment;
711 } 711 }
712 else 712 else
713 uSizeRead = commentBufferSize; 713 uSizeRead = commentBufferSize;
714 714
715 if (lSeek!=0) 715 if (lSeek!=0)
716 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 716 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
717 lSeek=0; 717 lSeek=0;
718 else 718 else
719 err=UNZ_ERRNO; 719 err=UNZ_ERRNO;
720 if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 720 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
721 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 721 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
722 err=UNZ_ERRNO; 722 err=UNZ_ERRNO;
723 lSeek+=file_info.size_file_comment - uSizeRead; 723 lSeek+=file_info.size_file_comment - uSizeRead;
724 } 724 }
725 else 725 else
726 lSeek+=file_info.size_file_comment; 726 lSeek+=file_info.size_file_comment;
727 727
728 if ((err==UNZ_OK) && (pfile_info!=NULL)) 728 if ((err==UNZ_OK) && (pfile_info!=NULL))
729 *pfile_info=file_info; 729 *pfile_info=file_info;
730 730
731 if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) 731 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
732 *pfile_info_internal=file_info_internal; 732 *pfile_info_internal=file_info_internal;
733 733
734 return err; 734 return err;
735} 735}
736 736
737 737
738 738
739/* 739/*
740 Write info about the ZipFile in the *pglobal_info structure. 740 Write info about the ZipFile in the *pglobal_info structure.
741 No preparation of the structure is needed 741 No preparation of the structure is needed
742 return UNZ_OK if there is no problem. 742 return UNZ_OK if there is no problem.
743*/ 743*/
744extern int ZEXPORT unzGetCurrentFileInfo (file, 744extern int ZEXPORT unzGetCurrentFileInfo (file,
745 pfile_info, 745 pfile_info,
746 szFileName, fileNameBufferSize, 746 szFileName, fileNameBufferSize,
747 extraField, extraFieldBufferSize, 747 extraField, extraFieldBufferSize,
748 szComment, commentBufferSize) 748 szComment, commentBufferSize)
749 unzFile file; 749 unzFile file;
750 unz_file_info *pfile_info; 750 unz_file_info *pfile_info;
751 char *szFileName; 751 char *szFileName;
752 uLong fileNameBufferSize; 752 uLong fileNameBufferSize;
753 void *extraField; 753 void *extraField;
754 uLong extraFieldBufferSize; 754 uLong extraFieldBufferSize;
755 char *szComment; 755 char *szComment;
756 uLong commentBufferSize; 756 uLong commentBufferSize;
757{ 757{
758 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, 758 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
759 szFileName,fileNameBufferSize, 759 szFileName,fileNameBufferSize,
760 extraField,extraFieldBufferSize, 760 extraField,extraFieldBufferSize,
761 szComment,commentBufferSize); 761 szComment,commentBufferSize);
762} 762}
763 763
764/* 764/*
765 Set the current file of the zipfile to the first file. 765 Set the current file of the zipfile to the first file.
766 return UNZ_OK if there is no problem 766 return UNZ_OK if there is no problem
767*/ 767*/
768extern int ZEXPORT unzGoToFirstFile (file) 768extern int ZEXPORT unzGoToFirstFile (file)
769 unzFile file; 769 unzFile file;
770{ 770{
771 int err=UNZ_OK; 771 int err=UNZ_OK;
772 unz_s* s; 772 unz_s* s;
773 if (file==NULL) 773 if (file==NULL)
774 return UNZ_PARAMERROR; 774 return UNZ_PARAMERROR;
775 s=(unz_s*)file; 775 s=(unz_s*)file;
776 s->pos_in_central_dir=s->offset_central_dir; 776 s->pos_in_central_dir=s->offset_central_dir;
777 s->num_file=0; 777 s->num_file=0;
778 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 778 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
779 &s->cur_file_info_internal, 779 &s->cur_file_info_internal,
780 NULL,0,NULL,0,NULL,0); 780 NULL,0,NULL,0,NULL,0);
781 s->current_file_ok = (err == UNZ_OK); 781 s->current_file_ok = (err == UNZ_OK);
782 return err; 782 return err;
783} 783}
784 784
785/* 785/*
786 Set the current file of the zipfile to the next file. 786 Set the current file of the zipfile to the next file.
787 return UNZ_OK if there is no problem 787 return UNZ_OK if there is no problem
788 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 788 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
789*/ 789*/
790extern int ZEXPORT unzGoToNextFile (file) 790extern int ZEXPORT unzGoToNextFile (file)
791 unzFile file; 791 unzFile file;
792{ 792{
793 unz_s* s; 793 unz_s* s;
794 int err; 794 int err;
795 795
796 if (file==NULL) 796 if (file==NULL)
797 return UNZ_PARAMERROR; 797 return UNZ_PARAMERROR;
798 s=(unz_s*)file; 798 s=(unz_s*)file;
799 if (!s->current_file_ok) 799 if (!s->current_file_ok)
800 return UNZ_END_OF_LIST_OF_FILE; 800 return UNZ_END_OF_LIST_OF_FILE;
801 if (s->num_file+1==s->gi.number_entry) 801 if (s->num_file+1==s->gi.number_entry)
802 return UNZ_END_OF_LIST_OF_FILE; 802 return UNZ_END_OF_LIST_OF_FILE;
803 803
804 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 804 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
805 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 805 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
806 s->num_file++; 806 s->num_file++;
807 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 807 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
808 &s->cur_file_info_internal, 808 &s->cur_file_info_internal,
809 NULL,0,NULL,0,NULL,0); 809 NULL,0,NULL,0,NULL,0);
810 s->current_file_ok = (err == UNZ_OK); 810 s->current_file_ok = (err == UNZ_OK);
811 return err; 811 return err;
812} 812}
813 813
814 814
815/* 815/*
816 Try locate the file szFileName in the zipfile. 816 Try locate the file szFileName in the zipfile.
817 For the iCaseSensitivity signification, see unzipStringFileNameCompare 817 For the iCaseSensitivity signification, see unzipStringFileNameCompare
818 818
819 return value : 819 return value :
820 UNZ_OK if the file is found. It becomes the current file. 820 UNZ_OK if the file is found. It becomes the current file.
821 UNZ_END_OF_LIST_OF_FILE if the file is not found 821 UNZ_END_OF_LIST_OF_FILE if the file is not found
822*/ 822*/
823extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) 823extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
824 unzFile file; 824 unzFile file;
825 const char *szFileName; 825 const char *szFileName;
826 int iCaseSensitivity; 826 int iCaseSensitivity;
827{ 827{
828 unz_s* s; 828 unz_s* s;
829 int err; 829 int err;
830 830
831 831
832 uLong num_fileSaved; 832 uLong num_fileSaved;
833 uLong pos_in_central_dirSaved; 833 uLong pos_in_central_dirSaved;
834 834
835 835
836 if (file==NULL) 836 if (file==NULL)
837 return UNZ_PARAMERROR; 837 return UNZ_PARAMERROR;
838 838
839 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 839 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
840 return UNZ_PARAMERROR; 840 return UNZ_PARAMERROR;
841 841
842 s=(unz_s*)file; 842 s=(unz_s*)file;
843 if (!s->current_file_ok) 843 if (!s->current_file_ok)
844 return UNZ_END_OF_LIST_OF_FILE; 844 return UNZ_END_OF_LIST_OF_FILE;
845 845
846 num_fileSaved = s->num_file; 846 num_fileSaved = s->num_file;
847 pos_in_central_dirSaved = s->pos_in_central_dir; 847 pos_in_central_dirSaved = s->pos_in_central_dir;
848 848
849 err = unzGoToFirstFile(file); 849 err = unzGoToFirstFile(file);
850 850
851 while (err == UNZ_OK) 851 while (err == UNZ_OK)
852 { 852 {
853 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 853 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
854 unzGetCurrentFileInfo(file,NULL, 854 unzGetCurrentFileInfo(file,NULL,
855 szCurrentFileName,sizeof(szCurrentFileName)-1, 855 szCurrentFileName,sizeof(szCurrentFileName)-1,
856 NULL,0,NULL,0); 856 NULL,0,NULL,0);
857 if (unzStringFileNameCompare(szCurrentFileName, 857 if (unzStringFileNameCompare(szCurrentFileName,
858 szFileName,iCaseSensitivity)==0) 858 szFileName,iCaseSensitivity)==0)
859 return UNZ_OK; 859 return UNZ_OK;
860 err = unzGoToNextFile(file); 860 err = unzGoToNextFile(file);
861 } 861 }
862 862
863 s->num_file = num_fileSaved ; 863 s->num_file = num_fileSaved ;
864 s->pos_in_central_dir = pos_in_central_dirSaved ; 864 s->pos_in_central_dir = pos_in_central_dirSaved ;
865 return err; 865 return err;
866} 866}
867 867
868 868
869/* 869/*
870/////////////////////////////////////////// 870///////////////////////////////////////////
871// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) 871// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
872// I need random access 872// I need random access
873// 873//
874// Further optimization could be realized by adding an ability 874// Further optimization could be realized by adding an ability
875// to cache the directory in memory. The goal being a single 875// to cache the directory in memory. The goal being a single
876// comprehensive file read to put the file I need in a memory. 876// comprehensive file read to put the file I need in a memory.
877*/ 877*/
878 878
879/* 879/*
880typedef struct unz_file_pos_s 880typedef struct unz_file_pos_s
881{ 881{
882 uLong pos_in_zip_directory; // offset in file 882 uLong pos_in_zip_directory; // offset in file
883 uLong num_of_file; // # of file 883 uLong num_of_file; // # of file
884} unz_file_pos; 884} unz_file_pos;
885*/ 885*/
886 886
887extern int ZEXPORT unzGetFilePos(file, file_pos) 887extern int ZEXPORT unzGetFilePos(file, file_pos)
888 unzFile file; 888 unzFile file;
889 unz_file_pos* file_pos; 889 unz_file_pos* file_pos;
890{ 890{
891 unz_s* s; 891 unz_s* s;
892 892
893 if (file==NULL || file_pos==NULL) 893 if (file==NULL || file_pos==NULL)
894 return UNZ_PARAMERROR; 894 return UNZ_PARAMERROR;
895 s=(unz_s*)file; 895 s=(unz_s*)file;
896 if (!s->current_file_ok) 896 if (!s->current_file_ok)
897 return UNZ_END_OF_LIST_OF_FILE; 897 return UNZ_END_OF_LIST_OF_FILE;
898 898
899 file_pos->pos_in_zip_directory = s->pos_in_central_dir; 899 file_pos->pos_in_zip_directory = s->pos_in_central_dir;
900 file_pos->num_of_file = s->num_file; 900 file_pos->num_of_file = s->num_file;
901 901
902 return UNZ_OK; 902 return UNZ_OK;
903} 903}
904 904
905extern int ZEXPORT unzGoToFilePos(file, file_pos) 905extern int ZEXPORT unzGoToFilePos(file, file_pos)
906 unzFile file; 906 unzFile file;
907 unz_file_pos* file_pos; 907 unz_file_pos* file_pos;
908{ 908{
909 unz_s* s; 909 unz_s* s;
910 int err; 910 int err;
911 911
912 if (file==NULL || file_pos==NULL) 912 if (file==NULL || file_pos==NULL)
913 return UNZ_PARAMERROR; 913 return UNZ_PARAMERROR;
914 s=(unz_s*)file; 914 s=(unz_s*)file;
915 915
916 /* jump to the right spot */ 916 /* jump to the right spot */
917 s->pos_in_central_dir = file_pos->pos_in_zip_directory; 917 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
918 s->num_file = file_pos->num_of_file; 918 s->num_file = file_pos->num_of_file;
919 919
920 /* set the current file */ 920 /* set the current file */
921 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 921 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
922 &s->cur_file_info_internal, 922 &s->cur_file_info_internal,
923 NULL,0,NULL,0,NULL,0); 923 NULL,0,NULL,0,NULL,0);
924 /* return results */ 924 /* return results */
925 s->current_file_ok = (err == UNZ_OK); 925 s->current_file_ok = (err == UNZ_OK);
926 return err; 926 return err;
927} 927}
928 928
929/* 929/*
930// Unzip Helper Functions - should be here? 930// Unzip Helper Functions - should be here?
931/////////////////////////////////////////// 931///////////////////////////////////////////
932*/ 932*/
933 933
934/* 934/*
935 Read the local header of the current zipfile 935 Read the local header of the current zipfile
936 Check the coherency of the local header and info in the end of central 936 Check the coherency of the local header and info in the end of central
937 directory about this file 937 directory about this file
938 store in *piSizeVar the size of extra info in local header 938 store in *piSizeVar the size of extra info in local header
939 (filename and size of extra field data) 939 (filename and size of extra field data)
940*/ 940*/
941local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, 941local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
942 poffset_local_extrafield, 942 poffset_local_extrafield,
943 psize_local_extrafield) 943 psize_local_extrafield)
944 unz_s* s; 944 unz_s* s;
945 uInt* piSizeVar; 945 uInt* piSizeVar;
946 uLong *poffset_local_extrafield; 946 uLong *poffset_local_extrafield;
947 uInt *psize_local_extrafield; 947 uInt *psize_local_extrafield;
948{ 948{
949 uLong uMagic,uData,uFlags; 949 uLong uMagic,uData,uFlags;
950 uLong size_filename; 950 uLong size_filename;
951 uLong size_extra_field; 951 uLong size_extra_field;
952 int err=UNZ_OK; 952 int err=UNZ_OK;
953 953
954 *piSizeVar = 0; 954 *piSizeVar = 0;
955 *poffset_local_extrafield = 0; 955 *poffset_local_extrafield = 0;
956 *psize_local_extrafield = 0; 956 *psize_local_extrafield = 0;
957 957
958 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 958 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
959 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 959 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
960 return UNZ_ERRNO; 960 return UNZ_ERRNO;
961 961
962 962
963 if (err==UNZ_OK) 963 if (err==UNZ_OK)
964 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 964 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
965 err=UNZ_ERRNO; 965 err=UNZ_ERRNO;
966 else if (uMagic!=0x04034b50) 966 else if (uMagic!=0x04034b50)
967 err=UNZ_BADZIPFILE; 967 err=UNZ_BADZIPFILE;
968 968
969 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 969 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
970 err=UNZ_ERRNO; 970 err=UNZ_ERRNO;
971/* 971/*
972 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 972 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
973 err=UNZ_BADZIPFILE; 973 err=UNZ_BADZIPFILE;
974*/ 974*/
975 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 975 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
976 err=UNZ_ERRNO; 976 err=UNZ_ERRNO;
977 977
978 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 978 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
979 err=UNZ_ERRNO; 979 err=UNZ_ERRNO;
980 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 980 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
981 err=UNZ_BADZIPFILE; 981 err=UNZ_BADZIPFILE;
982 982
983 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 983 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
984 (s->cur_file_info.compression_method!=Z_DEFLATED)) 984 (s->cur_file_info.compression_method!=Z_DEFLATED))
985 err=UNZ_BADZIPFILE; 985 err=UNZ_BADZIPFILE;
986 986
987 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 987 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
988 err=UNZ_ERRNO; 988 err=UNZ_ERRNO;
989 989
990 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 990 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
991 err=UNZ_ERRNO; 991 err=UNZ_ERRNO;
992 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && 992 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
993 ((uFlags & 8)==0)) 993 ((uFlags & 8)==0))
994 err=UNZ_BADZIPFILE; 994 err=UNZ_BADZIPFILE;
995 995
996 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 996 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
997 err=UNZ_ERRNO; 997 err=UNZ_ERRNO;
998 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && 998 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
999 ((uFlags & 8)==0)) 999 ((uFlags & 8)==0))
1000 err=UNZ_BADZIPFILE; 1000 err=UNZ_BADZIPFILE;
1001 1001
1002 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1002 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1003 err=UNZ_ERRNO; 1003 err=UNZ_ERRNO;
1004 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 1004 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1005 ((uFlags & 8)==0)) 1005 ((uFlags & 8)==0))
1006 err=UNZ_BADZIPFILE; 1006 err=UNZ_BADZIPFILE;
1007 1007
1008 1008
1009 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) 1009 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1010 err=UNZ_ERRNO; 1010 err=UNZ_ERRNO;
1011 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1011 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1012 err=UNZ_BADZIPFILE; 1012 err=UNZ_BADZIPFILE;
1013 1013
1014 *piSizeVar += (uInt)size_filename; 1014 *piSizeVar += (uInt)size_filename;
1015 1015
1016 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1016 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1017 err=UNZ_ERRNO; 1017 err=UNZ_ERRNO;
1018 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1018 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1019 SIZEZIPLOCALHEADER + size_filename; 1019 SIZEZIPLOCALHEADER + size_filename;
1020 *psize_local_extrafield = (uInt)size_extra_field; 1020 *psize_local_extrafield = (uInt)size_extra_field;
1021 1021
1022 *piSizeVar += (uInt)size_extra_field; 1022 *piSizeVar += (uInt)size_extra_field;
1023 1023
1024 return err; 1024 return err;
1025} 1025}
1026 1026
1027/* 1027/*
1028 Open for reading data the current file in the zipfile. 1028 Open for reading data the current file in the zipfile.
1029 If there is no error and the file is opened, the return value is UNZ_OK. 1029 If there is no error and the file is opened, the return value is UNZ_OK.
1030*/ 1030*/
1031extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) 1031extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1032 unzFile file; 1032 unzFile file;
1033 int* method; 1033 int* method;
1034 int* level; 1034 int* level;
1035 int raw; 1035 int raw;
1036 const char* password; 1036 const char* password;
1037{ 1037{
1038 int err=UNZ_OK; 1038 int err=UNZ_OK;
1039 uInt iSizeVar; 1039 uInt iSizeVar;
1040 unz_s* s; 1040 unz_s* s;
1041 file_in_zip_read_info_s* pfile_in_zip_read_info; 1041 file_in_zip_read_info_s* pfile_in_zip_read_info;
1042 uLong offset_local_extrafield; /* offset of the local extra field */ 1042 uLong offset_local_extrafield; /* offset of the local extra field */
1043 uInt size_local_extrafield; /* size of the local extra field */ 1043 uInt size_local_extrafield; /* size of the local extra field */
1044 #ifndef NOUNCRPYT 1044 #ifndef NOUNCRYPT
1045 char source[12]; 1045 char source[12];
1046 #else 1046 #else
1047 if (password != NULL) 1047 if (password != NULL)
1048 return UNZ_PARAMERROR; 1048 return UNZ_PARAMERROR;
1049 #endif 1049 #endif
1050 1050
1051 if (file==NULL) 1051 if (file==NULL)
1052 return UNZ_PARAMERROR; 1052 return UNZ_PARAMERROR;
1053 s=(unz_s*)file; 1053 s=(unz_s*)file;
1054 if (!s->current_file_ok) 1054 if (!s->current_file_ok)
1055 return UNZ_PARAMERROR; 1055 return UNZ_PARAMERROR;
1056 1056
1057 if (s->pfile_in_zip_read != NULL) 1057 if (s->pfile_in_zip_read != NULL)
1058 unzCloseCurrentFile(file); 1058 unzCloseCurrentFile(file);
1059 1059
1060 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, 1060 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1061 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) 1061 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1062 return UNZ_BADZIPFILE; 1062 return UNZ_BADZIPFILE;
1063 1063
1064 pfile_in_zip_read_info = (file_in_zip_read_info_s*) 1064 pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1065 ALLOC(sizeof(file_in_zip_read_info_s)); 1065 ALLOC(sizeof(file_in_zip_read_info_s));
1066 if (pfile_in_zip_read_info==NULL) 1066 if (pfile_in_zip_read_info==NULL)
1067 return UNZ_INTERNALERROR; 1067 return UNZ_INTERNALERROR;
1068 1068
1069 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); 1069 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1070 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; 1070 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1071 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; 1071 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1072 pfile_in_zip_read_info->pos_local_extrafield=0; 1072 pfile_in_zip_read_info->pos_local_extrafield=0;
1073 pfile_in_zip_read_info->raw=raw; 1073 pfile_in_zip_read_info->raw=raw;
1074 1074
1075 if (pfile_in_zip_read_info->read_buffer==NULL) 1075 if (pfile_in_zip_read_info->read_buffer==NULL)
1076 { 1076 {
1077 TRYFREE(pfile_in_zip_read_info); 1077 TRYFREE(pfile_in_zip_read_info);
1078 return UNZ_INTERNALERROR; 1078 return UNZ_INTERNALERROR;
1079 } 1079 }
1080 1080
1081 pfile_in_zip_read_info->stream_initialised=0; 1081 pfile_in_zip_read_info->stream_initialised=0;
1082 1082
1083 if (method!=NULL) 1083 if (method!=NULL)
1084 *method = (int)s->cur_file_info.compression_method; 1084 *method = (int)s->cur_file_info.compression_method;
1085 1085
1086 if (level!=NULL) 1086 if (level!=NULL)
1087 { 1087 {
1088 *level = 6; 1088 *level = 6;
1089 switch (s->cur_file_info.flag & 0x06) 1089 switch (s->cur_file_info.flag & 0x06)
1090 { 1090 {
1091 case 6 : *level = 1; break; 1091 case 6 : *level = 1; break;
1092 case 4 : *level = 2; break; 1092 case 4 : *level = 2; break;
1093 case 2 : *level = 9; break; 1093 case 2 : *level = 9; break;
1094 } 1094 }
1095 } 1095 }
1096 1096
1097 if ((s->cur_file_info.compression_method!=0) && 1097 if ((s->cur_file_info.compression_method!=0) &&
1098 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1098 (s->cur_file_info.compression_method!=Z_DEFLATED))
1099 err=UNZ_BADZIPFILE; 1099 err=UNZ_BADZIPFILE;
1100 1100
1101 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1101 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1102 pfile_in_zip_read_info->crc32=0; 1102 pfile_in_zip_read_info->crc32=0;
1103 pfile_in_zip_read_info->compression_method = 1103 pfile_in_zip_read_info->compression_method =
1104 s->cur_file_info.compression_method; 1104 s->cur_file_info.compression_method;
1105 pfile_in_zip_read_info->filestream=s->filestream; 1105 pfile_in_zip_read_info->filestream=s->filestream;
1106 pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1106 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1107 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1107 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1108 1108
1109 pfile_in_zip_read_info->stream.total_out = 0; 1109 pfile_in_zip_read_info->stream.total_out = 0;
1110 1110
1111 if ((s->cur_file_info.compression_method==Z_DEFLATED) && 1111 if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1112 (!raw)) 1112 (!raw))
1113 { 1113 {
1114 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1114 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1115 pfile_in_zip_read_info->stream.zfree = (free_func)0; 1115 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1116 pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1116 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1117 1117 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1118 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1118 pfile_in_zip_read_info->stream.avail_in = 0;
1119 if (err == Z_OK) 1119
1120 pfile_in_zip_read_info->stream_initialised=1; 1120 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1121 else 1121 if (err == Z_OK)
1122 return err; 1122 pfile_in_zip_read_info->stream_initialised=1;
1123 /* windowBits is passed < 0 to tell that there is no zlib header. 1123 else
1124 * Note that in this case inflate *requires* an extra "dummy" byte 1124 return err;
1125 * after the compressed stream in order to complete decompression and 1125 /* windowBits is passed < 0 to tell that there is no zlib header.
1126 * return Z_STREAM_END. 1126 * Note that in this case inflate *requires* an extra "dummy" byte
1127 * In unzip, i don't wait absolutely Z_STREAM_END because I known the 1127 * after the compressed stream in order to complete decompression and
1128 * size of both compressed and uncompressed data 1128 * return Z_STREAM_END.
1129 */ 1129 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1130 } 1130 * size of both compressed and uncompressed data
1131 pfile_in_zip_read_info->rest_read_compressed = 1131 */
1132 s->cur_file_info.compressed_size ; 1132 }
1133 pfile_in_zip_read_info->rest_read_uncompressed = 1133 pfile_in_zip_read_info->rest_read_compressed =
1134 s->cur_file_info.uncompressed_size ; 1134 s->cur_file_info.compressed_size ;
1135 1135 pfile_in_zip_read_info->rest_read_uncompressed =
1136 1136 s->cur_file_info.uncompressed_size ;
1137 pfile_in_zip_read_info->pos_in_zipfile = 1137
1138 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 1138
1139 iSizeVar; 1139 pfile_in_zip_read_info->pos_in_zipfile =
1140 1140 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1141 pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1141 iSizeVar;
1142 1142
1143 s->pfile_in_zip_read = pfile_in_zip_read_info; 1143 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1144 1144
1145 #ifndef NOUNCRPYT 1145 s->pfile_in_zip_read = pfile_in_zip_read_info;
1146 if (password != NULL) 1146
1147 { 1147 #ifndef NOUNCRYPT
1148 int i; 1148 if (password != NULL)
1149 s->pcrc_32_tab = get_crc_table(); 1149 {
1150 init_keys(password,s->keys,s->pcrc_32_tab); 1150 int i;
1151 if (ZSEEK(s->z_filefunc, s->filestream, 1151 s->pcrc_32_tab = get_crc_table();
1152 s->pfile_in_zip_read->pos_in_zipfile + 1152 init_keys(password,s->keys,s->pcrc_32_tab);
1153 s->pfile_in_zip_read->byte_before_the_zipfile, 1153 if (ZSEEK(s->z_filefunc, s->filestream,
1154 SEEK_SET)!=0) 1154 s->pfile_in_zip_read->pos_in_zipfile +
1155 return UNZ_INTERNALERROR; 1155 s->pfile_in_zip_read->byte_before_the_zipfile,
1156 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) 1156 SEEK_SET)!=0)
1157 return UNZ_INTERNALERROR; 1157 return UNZ_INTERNALERROR;
1158 1158 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1159 for (i = 0; i<12; i++) 1159 return UNZ_INTERNALERROR;
1160 zdecode(s->keys,s->pcrc_32_tab,source[i]); 1160
1161 1161 for (i = 0; i<12; i++)
1162 s->pfile_in_zip_read->pos_in_zipfile+=12; 1162 zdecode(s->keys,s->pcrc_32_tab,source[i]);
1163 s->encrypted=1; 1163
1164 } 1164 s->pfile_in_zip_read->pos_in_zipfile+=12;
1165 #endif 1165 s->encrypted=1;
1166 1166 }
1167 1167 #endif
1168 return UNZ_OK; 1168
1169} 1169
1170 1170 return UNZ_OK;
1171extern int ZEXPORT unzOpenCurrentFile (file) 1171}
1172 unzFile file; 1172
1173{ 1173extern int ZEXPORT unzOpenCurrentFile (file)
1174 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1174 unzFile file;
1175} 1175{
1176 1176 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1177extern int ZEXPORT unzOpenCurrentFilePassword (file, password) 1177}
1178 unzFile file; 1178
1179 const char* password; 1179extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1180{ 1180 unzFile file;
1181 return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1181 const char* password;
1182} 1182{
1183 1183 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1184extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) 1184}
1185 unzFile file; 1185
1186 int* method; 1186extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1187 int* level; 1187 unzFile file;
1188 int raw; 1188 int* method;
1189{ 1189 int* level;
1190 return unzOpenCurrentFile3(file, method, level, raw, NULL); 1190 int raw;
1191} 1191{
1192 1192 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1193/* 1193}
1194 Read bytes from the current file. 1194
1195 buf contain buffer where data must be copied 1195/*
1196 len the size of buf. 1196 Read bytes from the current file.
1197 1197 buf contain buffer where data must be copied
1198 return the number of byte copied if somes bytes are copied 1198 len the size of buf.
1199 return 0 if the end of file was reached 1199
1200 return <0 with error code if there is an error 1200 return the number of byte copied if somes bytes are copied
1201 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1201 return 0 if the end of file was reached
1202*/ 1202 return <0 with error code if there is an error
1203extern int ZEXPORT unzReadCurrentFile (file, buf, len) 1203 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1204 unzFile file; 1204*/
1205 voidp buf; 1205extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1206 unsigned len; 1206 unzFile file;
1207{ 1207 voidp buf;
1208 int err=UNZ_OK; 1208 unsigned len;
1209 uInt iRead = 0; 1209{
1210 unz_s* s; 1210 int err=UNZ_OK;
1211 file_in_zip_read_info_s* pfile_in_zip_read_info; 1211 uInt iRead = 0;
1212 if (file==NULL) 1212 unz_s* s;
1213 return UNZ_PARAMERROR; 1213 file_in_zip_read_info_s* pfile_in_zip_read_info;
1214 s=(unz_s*)file; 1214 if (file==NULL)
1215 pfile_in_zip_read_info=s->pfile_in_zip_read; 1215 return UNZ_PARAMERROR;
1216 1216 s=(unz_s*)file;
1217 if (pfile_in_zip_read_info==NULL) 1217 pfile_in_zip_read_info=s->pfile_in_zip_read;
1218 return UNZ_PARAMERROR; 1218
1219 1219 if (pfile_in_zip_read_info==NULL)
1220 1220 return UNZ_PARAMERROR;
1221 if ((pfile_in_zip_read_info->read_buffer == NULL)) 1221
1222 return UNZ_END_OF_LIST_OF_FILE; 1222
1223 if (len==0) 1223 if ((pfile_in_zip_read_info->read_buffer == NULL))
1224 return 0; 1224 return UNZ_END_OF_LIST_OF_FILE;
1225 1225 if (len==0)
1226 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; 1226 return 0;
1227 1227
1228 pfile_in_zip_read_info->stream.avail_out = (uInt)len; 1228 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1229 1229
1230 if (len>pfile_in_zip_read_info->rest_read_uncompressed) 1230 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1231 pfile_in_zip_read_info->stream.avail_out = 1231
1232 (uInt)pfile_in_zip_read_info->rest_read_uncompressed; 1232 if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1233 1233 pfile_in_zip_read_info->stream.avail_out =
1234 while (pfile_in_zip_read_info->stream.avail_out>0) 1234 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1235 { 1235
1236 if ((pfile_in_zip_read_info->stream.avail_in==0) && 1236 while (pfile_in_zip_read_info->stream.avail_out>0)
1237 (pfile_in_zip_read_info->rest_read_compressed>0)) 1237 {
1238 { 1238 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1239 uInt uReadThis = UNZ_BUFSIZE; 1239 (pfile_in_zip_read_info->rest_read_compressed>0))
1240 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) 1240 {
1241 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1241 uInt uReadThis = UNZ_BUFSIZE;
1242 if (uReadThis == 0) 1242 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1243 return UNZ_EOF; 1243 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1244 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1244 if (uReadThis == 0)
1245 pfile_in_zip_read_info->filestream, 1245 return UNZ_EOF;
1246 pfile_in_zip_read_info->pos_in_zipfile + 1246 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1247 pfile_in_zip_read_info->byte_before_the_zipfile, 1247 pfile_in_zip_read_info->filestream,
1248 ZLIB_FILEFUNC_SEEK_SET)!=0) 1248 pfile_in_zip_read_info->pos_in_zipfile +
1249 return UNZ_ERRNO; 1249 pfile_in_zip_read_info->byte_before_the_zipfile,
1250 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1250 ZLIB_FILEFUNC_SEEK_SET)!=0)
1251 pfile_in_zip_read_info->filestream, 1251 return UNZ_ERRNO;
1252 pfile_in_zip_read_info->read_buffer, 1252 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1253 uReadThis)!=uReadThis) 1253 pfile_in_zip_read_info->filestream,
1254 return UNZ_ERRNO; 1254 pfile_in_zip_read_info->read_buffer,
1255 1255 uReadThis)!=uReadThis)
1256 1256 return UNZ_ERRNO;
1257 #ifndef NOUNCRPYT 1257
1258 if(s->encrypted) 1258
1259 { 1259 #ifndef NOUNCRYPT
1260 uInt i; 1260 if(s->encrypted)
1261 for(i=0;i<uReadThis;i++) 1261 {
1262 pfile_in_zip_read_info->read_buffer[i] = 1262 uInt i;
1263 zdecode(s->keys,s->pcrc_32_tab, 1263 for(i=0;i<uReadThis;i++)
1264 pfile_in_zip_read_info->read_buffer[i]); 1264 pfile_in_zip_read_info->read_buffer[i] =
1265 } 1265 zdecode(s->keys,s->pcrc_32_tab,
1266 #endif 1266 pfile_in_zip_read_info->read_buffer[i]);
1267 1267 }
1268 1268 #endif
1269 pfile_in_zip_read_info->pos_in_zipfile += uReadThis; 1269
1270 1270
1271 pfile_in_zip_read_info->rest_read_compressed-=uReadThis; 1271 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1272 1272
1273 pfile_in_zip_read_info->stream.next_in = 1273 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1274 (Bytef*)pfile_in_zip_read_info->read_buffer; 1274
1275 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; 1275 pfile_in_zip_read_info->stream.next_in =
1276 } 1276 (Bytef*)pfile_in_zip_read_info->read_buffer;
1277 1277 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1278 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) 1278 }
1279 { 1279
1280 uInt uDoCopy,i ; 1280 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1281 1281 {
1282 if ((pfile_in_zip_read_info->stream.avail_in == 0) && 1282 uInt uDoCopy,i ;
1283 (pfile_in_zip_read_info->rest_read_compressed == 0)) 1283
1284 return (iRead==0) ? UNZ_EOF : iRead; 1284 if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1285 1285 (pfile_in_zip_read_info->rest_read_compressed == 0))
1286 if (pfile_in_zip_read_info->stream.avail_out < 1286 return (iRead==0) ? UNZ_EOF : iRead;
1287 pfile_in_zip_read_info->stream.avail_in) 1287
1288 uDoCopy = pfile_in_zip_read_info->stream.avail_out ; 1288 if (pfile_in_zip_read_info->stream.avail_out <
1289 else 1289 pfile_in_zip_read_info->stream.avail_in)
1290 uDoCopy = pfile_in_zip_read_info->stream.avail_in ; 1290 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1291 1291 else
1292 for (i=0;i<uDoCopy;i++) 1292 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1293 *(pfile_in_zip_read_info->stream.next_out+i) = 1293
1294 *(pfile_in_zip_read_info->stream.next_in+i); 1294 for (i=0;i<uDoCopy;i++)
1295 1295 *(pfile_in_zip_read_info->stream.next_out+i) =
1296 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1296 *(pfile_in_zip_read_info->stream.next_in+i);
1297 pfile_in_zip_read_info->stream.next_out, 1297
1298 uDoCopy); 1298 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1299 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; 1299 pfile_in_zip_read_info->stream.next_out,
1300 pfile_in_zip_read_info->stream.avail_in -= uDoCopy; 1300 uDoCopy);
1301 pfile_in_zip_read_info->stream.avail_out -= uDoCopy; 1301 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1302 pfile_in_zip_read_info->stream.next_out += uDoCopy; 1302 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1303 pfile_in_zip_read_info->stream.next_in += uDoCopy; 1303 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1304 pfile_in_zip_read_info->stream.total_out += uDoCopy; 1304 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1305 iRead += uDoCopy; 1305 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1306 } 1306 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1307 else 1307 iRead += uDoCopy;
1308 { 1308 }
1309 uLong uTotalOutBefore,uTotalOutAfter; 1309 else
1310 const Bytef *bufBefore; 1310 {
1311 uLong uOutThis; 1311 uLong uTotalOutBefore,uTotalOutAfter;
1312 int flush=Z_SYNC_FLUSH; 1312 const Bytef *bufBefore;
1313 1313 uLong uOutThis;
1314 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1314 int flush=Z_SYNC_FLUSH;
1315 bufBefore = pfile_in_zip_read_info->stream.next_out; 1315
1316 1316 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1317 /* 1317 bufBefore = pfile_in_zip_read_info->stream.next_out;
1318 if ((pfile_in_zip_read_info->rest_read_uncompressed == 1318
1319 pfile_in_zip_read_info->stream.avail_out) && 1319 /*
1320 (pfile_in_zip_read_info->rest_read_compressed == 0)) 1320 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1321 flush = Z_FINISH; 1321 pfile_in_zip_read_info->stream.avail_out) &&
1322 */ 1322 (pfile_in_zip_read_info->rest_read_compressed == 0))
1323 err=inflate(&pfile_in_zip_read_info->stream,flush); 1323 flush = Z_FINISH;
1324 1324 */
1325 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1325 err=inflate(&pfile_in_zip_read_info->stream,flush);
1326 uOutThis = uTotalOutAfter-uTotalOutBefore; 1326
1327 1327 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1328 pfile_in_zip_read_info->crc32 = 1328 uOutThis = uTotalOutAfter-uTotalOutBefore;
1329 crc32(pfile_in_zip_read_info->crc32,bufBefore, 1329
1330 (uInt)(uOutThis)); 1330 pfile_in_zip_read_info->crc32 =
1331 1331 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1332 pfile_in_zip_read_info->rest_read_uncompressed -= 1332 (uInt)(uOutThis));
1333 uOutThis; 1333
1334 1334 pfile_in_zip_read_info->rest_read_uncompressed -=
1335 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1335 uOutThis;
1336 1336
1337 if (err==Z_STREAM_END) 1337 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1338 return (iRead==0) ? UNZ_EOF : iRead; 1338
1339 if (err!=Z_OK) 1339 if (err==Z_STREAM_END)
1340 break; 1340 return (iRead==0) ? UNZ_EOF : iRead;
1341 } 1341 if (err!=Z_OK)
1342 } 1342 break;
1343 1343 }
1344 if (err==Z_OK) 1344 }
1345 return iRead; 1345
1346 return err; 1346 if (err==Z_OK)
1347} 1347 return iRead;
1348 1348 return err;
1349 1349}
1350/* 1350
1351 Give the current position in uncompressed data 1351
1352*/ 1352/*
1353extern z_off_t ZEXPORT unztell (file) 1353 Give the current position in uncompressed data
1354 unzFile file; 1354*/
1355{ 1355extern z_off_t ZEXPORT unztell (file)
1356 unz_s* s; 1356 unzFile file;
1357 file_in_zip_read_info_s* pfile_in_zip_read_info; 1357{
1358 if (file==NULL) 1358 unz_s* s;
1359 return UNZ_PARAMERROR; 1359 file_in_zip_read_info_s* pfile_in_zip_read_info;
1360 s=(unz_s*)file; 1360 if (file==NULL)
1361 pfile_in_zip_read_info=s->pfile_in_zip_read; 1361 return UNZ_PARAMERROR;
1362 1362 s=(unz_s*)file;
1363 if (pfile_in_zip_read_info==NULL) 1363 pfile_in_zip_read_info=s->pfile_in_zip_read;
1364 return UNZ_PARAMERROR; 1364
1365 1365 if (pfile_in_zip_read_info==NULL)
1366 return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1366 return UNZ_PARAMERROR;
1367} 1367
1368 1368 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1369 1369}
1370/* 1370
1371 return 1 if the end of file was reached, 0 elsewhere 1371
1372*/ 1372/*
1373extern int ZEXPORT unzeof (file) 1373 return 1 if the end of file was reached, 0 elsewhere
1374 unzFile file; 1374*/
1375{ 1375extern int ZEXPORT unzeof (file)
1376 unz_s* s; 1376 unzFile file;
1377 file_in_zip_read_info_s* pfile_in_zip_read_info; 1377{
1378 if (file==NULL) 1378 unz_s* s;
1379 return UNZ_PARAMERROR; 1379 file_in_zip_read_info_s* pfile_in_zip_read_info;
1380 s=(unz_s*)file; 1380 if (file==NULL)
1381 pfile_in_zip_read_info=s->pfile_in_zip_read; 1381 return UNZ_PARAMERROR;
1382 1382 s=(unz_s*)file;
1383 if (pfile_in_zip_read_info==NULL) 1383 pfile_in_zip_read_info=s->pfile_in_zip_read;
1384 return UNZ_PARAMERROR; 1384
1385 1385 if (pfile_in_zip_read_info==NULL)
1386 if (pfile_in_zip_read_info->rest_read_uncompressed == 0) 1386 return UNZ_PARAMERROR;
1387 return 1; 1387
1388 else 1388 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1389 return 0; 1389 return 1;
1390} 1390 else
1391 1391 return 0;
1392 1392}
1393 1393
1394/* 1394
1395 Read extra field from the current file (opened by unzOpenCurrentFile) 1395
1396 This is the local-header version of the extra field (sometimes, there is 1396/*
1397 more info in the local-header version than in the central-header) 1397 Read extra field from the current file (opened by unzOpenCurrentFile)
1398 1398 This is the local-header version of the extra field (sometimes, there is
1399 if buf==NULL, it return the size of the local extra field that can be read 1399 more info in the local-header version than in the central-header)
1400 1400
1401 if buf!=NULL, len is the size of the buffer, the extra header is copied in 1401 if buf==NULL, it return the size of the local extra field that can be read
1402 buf. 1402
1403 the return value is the number of bytes copied in buf, or (if <0) 1403 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1404 the error code 1404 buf.
1405*/ 1405 the return value is the number of bytes copied in buf, or (if <0)
1406extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) 1406 the error code
1407 unzFile file; 1407*/
1408 voidp buf; 1408extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1409 unsigned len; 1409 unzFile file;
1410{ 1410 voidp buf;
1411 unz_s* s; 1411 unsigned len;
1412 file_in_zip_read_info_s* pfile_in_zip_read_info; 1412{
1413 uInt read_now; 1413 unz_s* s;
1414 uLong size_to_read; 1414 file_in_zip_read_info_s* pfile_in_zip_read_info;
1415 1415 uInt read_now;
1416 if (file==NULL) 1416 uLong size_to_read;
1417 return UNZ_PARAMERROR; 1417
1418 s=(unz_s*)file; 1418 if (file==NULL)
1419 pfile_in_zip_read_info=s->pfile_in_zip_read; 1419 return UNZ_PARAMERROR;
1420 1420 s=(unz_s*)file;
1421 if (pfile_in_zip_read_info==NULL) 1421 pfile_in_zip_read_info=s->pfile_in_zip_read;
1422 return UNZ_PARAMERROR; 1422
1423 1423 if (pfile_in_zip_read_info==NULL)
1424 size_to_read = (pfile_in_zip_read_info->size_local_extrafield - 1424 return UNZ_PARAMERROR;
1425 pfile_in_zip_read_info->pos_local_extrafield); 1425
1426 1426 size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1427 if (buf==NULL) 1427 pfile_in_zip_read_info->pos_local_extrafield);
1428 return (int)size_to_read; 1428
1429 1429 if (buf==NULL)
1430 if (len>size_to_read) 1430 return (int)size_to_read;
1431 read_now = (uInt)size_to_read; 1431
1432 else 1432 if (len>size_to_read)
1433 read_now = (uInt)len ; 1433 read_now = (uInt)size_to_read;
1434 1434 else
1435 if (read_now==0) 1435 read_now = (uInt)len ;
1436 return 0; 1436
1437 1437 if (read_now==0)
1438 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1438 return 0;
1439 pfile_in_zip_read_info->filestream, 1439
1440 pfile_in_zip_read_info->offset_local_extrafield + 1440 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1441 pfile_in_zip_read_info->pos_local_extrafield, 1441 pfile_in_zip_read_info->filestream,
1442 ZLIB_FILEFUNC_SEEK_SET)!=0) 1442 pfile_in_zip_read_info->offset_local_extrafield +
1443 return UNZ_ERRNO; 1443 pfile_in_zip_read_info->pos_local_extrafield,
1444 1444 ZLIB_FILEFUNC_SEEK_SET)!=0)
1445 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1445 return UNZ_ERRNO;
1446 pfile_in_zip_read_info->filestream, 1446
1447 buf,size_to_read)!=size_to_read) 1447 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1448 return UNZ_ERRNO; 1448 pfile_in_zip_read_info->filestream,
1449 1449 buf,size_to_read)!=size_to_read)
1450 return (int)read_now; 1450 return UNZ_ERRNO;
1451} 1451
1452 1452 return (int)read_now;
1453/* 1453}
1454 Close the file in zip opened with unzipOpenCurrentFile 1454
1455 Return UNZ_CRCERROR if all the file was read but the CRC is not good 1455/*
1456*/ 1456 Close the file in zip opened with unzipOpenCurrentFile
1457extern int ZEXPORT unzCloseCurrentFile (file) 1457 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1458 unzFile file; 1458*/
1459{ 1459extern int ZEXPORT unzCloseCurrentFile (file)
1460 int err=UNZ_OK; 1460 unzFile file;
1461 1461{
1462 unz_s* s; 1462 int err=UNZ_OK;
1463 file_in_zip_read_info_s* pfile_in_zip_read_info; 1463
1464 if (file==NULL) 1464 unz_s* s;
1465 return UNZ_PARAMERROR; 1465 file_in_zip_read_info_s* pfile_in_zip_read_info;
1466 s=(unz_s*)file; 1466 if (file==NULL)
1467 pfile_in_zip_read_info=s->pfile_in_zip_read; 1467 return UNZ_PARAMERROR;
1468 1468 s=(unz_s*)file;
1469 if (pfile_in_zip_read_info==NULL) 1469 pfile_in_zip_read_info=s->pfile_in_zip_read;
1470 return UNZ_PARAMERROR; 1470
1471 1471 if (pfile_in_zip_read_info==NULL)
1472 1472 return UNZ_PARAMERROR;
1473 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && 1473
1474 (!pfile_in_zip_read_info->raw)) 1474
1475 { 1475 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1476 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) 1476 (!pfile_in_zip_read_info->raw))
1477 err=UNZ_CRCERROR; 1477 {
1478 } 1478 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1479 1479 err=UNZ_CRCERROR;
1480 1480 }
1481 TRYFREE(pfile_in_zip_read_info->read_buffer); 1481
1482 pfile_in_zip_read_info->read_buffer = NULL; 1482
1483 if (pfile_in_zip_read_info->stream_initialised) 1483 TRYFREE(pfile_in_zip_read_info->read_buffer);
1484 inflateEnd(&pfile_in_zip_read_info->stream); 1484 pfile_in_zip_read_info->read_buffer = NULL;
1485 1485 if (pfile_in_zip_read_info->stream_initialised)
1486 pfile_in_zip_read_info->stream_initialised = 0; 1486 inflateEnd(&pfile_in_zip_read_info->stream);
1487 TRYFREE(pfile_in_zip_read_info); 1487
1488 1488 pfile_in_zip_read_info->stream_initialised = 0;
1489 s->pfile_in_zip_read=NULL; 1489 TRYFREE(pfile_in_zip_read_info);
1490 1490
1491 return err; 1491 s->pfile_in_zip_read=NULL;
1492} 1492
1493 1493 return err;
1494 1494}
1495/* 1495
1496 Get the global comment string of the ZipFile, in the szComment buffer. 1496
1497 uSizeBuf is the size of the szComment buffer. 1497/*
1498 return the number of byte copied or an error code <0 1498 Get the global comment string of the ZipFile, in the szComment buffer.
1499*/ 1499 uSizeBuf is the size of the szComment buffer.
1500extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) 1500 return the number of byte copied or an error code <0
1501 unzFile file; 1501*/
1502 char *szComment; 1502extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1503 uLong uSizeBuf; 1503 unzFile file;
1504{ 1504 char *szComment;
1505 int err=UNZ_OK; 1505 uLong uSizeBuf;
1506 unz_s* s; 1506{
1507 uLong uReadThis ; 1507 int err=UNZ_OK;
1508 if (file==NULL) 1508 unz_s* s;
1509 return UNZ_PARAMERROR; 1509 uLong uReadThis ;
1510 s=(unz_s*)file; 1510 if (file==NULL)
1511 1511 return UNZ_PARAMERROR;
1512 uReadThis = uSizeBuf; 1512 s=(unz_s*)file;
1513 if (uReadThis>s->gi.size_comment) 1513
1514 uReadThis = s->gi.size_comment; 1514 uReadThis = uSizeBuf;
1515 1515 if (uReadThis>s->gi.size_comment)
1516 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 1516 uReadThis = s->gi.size_comment;
1517 return UNZ_ERRNO; 1517
1518 1518 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1519 if (uReadThis>0) 1519 return UNZ_ERRNO;
1520 { 1520
1521 *szComment='\0'; 1521 if (uReadThis>0)
1522 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 1522 {
1523 return UNZ_ERRNO; 1523 *szComment='\0';
1524 } 1524 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1525 1525 return UNZ_ERRNO;
1526 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) 1526 }
1527 *(szComment+s->gi.size_comment)='\0'; 1527
1528 return (int)uReadThis; 1528 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1529} 1529 *(szComment+s->gi.size_comment)='\0';
1530 return (int)uReadThis;
1531}
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h
index 67ca851..48e6832 100644
--- a/contrib/minizip/unzip.h
+++ b/contrib/minizip/unzip.h
@@ -1,342 +1,342 @@
1/* unzip.h -- IO for uncompress .zip files using zlib 1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 0.21, March 10th, 2003 2 Version 0.22, May 19th, 2003
3 3
4 Copyright (C) 1998-2003 Gilles Vollant 4 Copyright (C) 1998-2003 Gilles Vollant
5 5
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g 6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible. 7 WinZip, InfoZip tools and compatible.
8 Encryption and multi volume ZipFile (span) are not supported. 8 Encryption and multi volume ZipFile (span) are not supported.
9 Old compressions used by old PKZip 1.x are not supported 9 Old compressions used by old PKZip 1.x are not supported
10 10
11 11
12 I WAIT FEEDBACK at mail info@winimage.com 12 I WAIT FEEDBACK at mail info@winimage.com
13 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution 13 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
14 14
15 Condition of use and distribution are the same than zlib : 15 Condition of use and distribution are the same than zlib :
16 16
17 This software is provided 'as-is', without any express or implied 17 This software is provided 'as-is', without any express or implied
18 warranty. In no event will the authors be held liable for any damages 18 warranty. In no event will the authors be held liable for any damages
19 arising from the use of this software. 19 arising from the use of this software.
20 20
21 Permission is granted to anyone to use this software for any purpose, 21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute it 22 including commercial applications, and to alter it and redistribute it
23 freely, subject to the following restrictions: 23 freely, subject to the following restrictions:
24 24
25 1. The origin of this software must not be misrepresented; you must not 25 1. The origin of this software must not be misrepresented; you must not
26 claim that you wrote the original software. If you use this software 26 claim that you wrote the original software. If you use this software
27 in a product, an acknowledgment in the product documentation would be 27 in a product, an acknowledgment in the product documentation would be
28 appreciated but is not required. 28 appreciated but is not required.
29 2. Altered source versions must be plainly marked as such, and must not be 29 2. Altered source versions must be plainly marked as such, and must not be
30 misrepresented as being the original software. 30 misrepresented as being the original software.
31 3. This notice may not be removed or altered from any source distribution. 31 3. This notice may not be removed or altered from any source distribution.
32 32
33 33
34*/ 34*/
35 35
36/* for more info about .ZIP format, see 36/* for more info about .ZIP format, see
37 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip 37 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
38 http://www.info-zip.org/pub/infozip/doc/ 38 http://www.info-zip.org/pub/infozip/doc/
39 PkWare has also a specification at : 39 PkWare has also a specification at :
40 ftp://ftp.pkware.com/probdesc.zip 40 ftp://ftp.pkware.com/probdesc.zip
41*/ 41*/
42 42
43#ifndef _unz_H 43#ifndef _unz_H
44#define _unz_H 44#define _unz_H
45 45
46#ifdef __cplusplus 46#ifdef __cplusplus
47extern "C" { 47extern "C" {
48#endif 48#endif
49 49
50#ifndef _ZLIB_H 50#ifndef _ZLIB_H
51#include "zlib.h" 51#include "zlib.h"
52#endif 52#endif
53 53
54#ifndef _ZLIBIOAPI_H 54#ifndef _ZLIBIOAPI_H
55#include "ioapi.h" 55#include "ioapi.h"
56#endif 56#endif
57 57
58#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 58#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
59/* like the STRICT of WIN32, we define a pointer that cannot be converted 59/* like the STRICT of WIN32, we define a pointer that cannot be converted
60 from (void*) without cast */ 60 from (void*) without cast */
61typedef struct TagunzFile__ { int unused; } unzFile__; 61typedef struct TagunzFile__ { int unused; } unzFile__;
62typedef unzFile__ *unzFile; 62typedef unzFile__ *unzFile;
63#else 63#else
64typedef voidp unzFile; 64typedef voidp unzFile;
65#endif 65#endif
66 66
67 67
68#define UNZ_OK (0) 68#define UNZ_OK (0)
69#define UNZ_END_OF_LIST_OF_FILE (-100) 69#define UNZ_END_OF_LIST_OF_FILE (-100)
70#define UNZ_ERRNO (Z_ERRNO) 70#define UNZ_ERRNO (Z_ERRNO)
71#define UNZ_EOF (0) 71#define UNZ_EOF (0)
72#define UNZ_PARAMERROR (-102) 72#define UNZ_PARAMERROR (-102)
73#define UNZ_BADZIPFILE (-103) 73#define UNZ_BADZIPFILE (-103)
74#define UNZ_INTERNALERROR (-104) 74#define UNZ_INTERNALERROR (-104)
75#define UNZ_CRCERROR (-105) 75#define UNZ_CRCERROR (-105)
76 76
77/* tm_unz contain date/time info */ 77/* tm_unz contain date/time info */
78typedef struct tm_unz_s 78typedef struct tm_unz_s
79{ 79{
80 uInt tm_sec; /* seconds after the minute - [0,59] */ 80 uInt tm_sec; /* seconds after the minute - [0,59] */
81 uInt tm_min; /* minutes after the hour - [0,59] */ 81 uInt tm_min; /* minutes after the hour - [0,59] */
82 uInt tm_hour; /* hours since midnight - [0,23] */ 82 uInt tm_hour; /* hours since midnight - [0,23] */
83 uInt tm_mday; /* day of the month - [1,31] */ 83 uInt tm_mday; /* day of the month - [1,31] */
84 uInt tm_mon; /* months since January - [0,11] */ 84 uInt tm_mon; /* months since January - [0,11] */
85 uInt tm_year; /* years - [1980..2044] */ 85 uInt tm_year; /* years - [1980..2044] */
86} tm_unz; 86} tm_unz;
87 87
88/* unz_global_info structure contain global data about the ZIPfile 88/* unz_global_info structure contain global data about the ZIPfile
89 These data comes from the end of central dir */ 89 These data comes from the end of central dir */
90typedef struct unz_global_info_s 90typedef struct unz_global_info_s
91{ 91{
92 uLong number_entry; /* total number of entries in 92 uLong number_entry; /* total number of entries in
93 the central dir on this disk */ 93 the central dir on this disk */
94 uLong size_comment; /* size of the global comment of the zipfile */ 94 uLong size_comment; /* size of the global comment of the zipfile */
95} unz_global_info; 95} unz_global_info;
96 96
97 97
98/* unz_file_info contain information about a file in the zipfile */ 98/* unz_file_info contain information about a file in the zipfile */
99typedef struct unz_file_info_s 99typedef struct unz_file_info_s
100{ 100{
101 uLong version; /* version made by 2 bytes */ 101 uLong version; /* version made by 2 bytes */
102 uLong version_needed; /* version needed to extract 2 bytes */ 102 uLong version_needed; /* version needed to extract 2 bytes */
103 uLong flag; /* general purpose bit flag 2 bytes */ 103 uLong flag; /* general purpose bit flag 2 bytes */
104 uLong compression_method; /* compression method 2 bytes */ 104 uLong compression_method; /* compression method 2 bytes */
105 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 105 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
106 uLong crc; /* crc-32 4 bytes */ 106 uLong crc; /* crc-32 4 bytes */
107 uLong compressed_size; /* compressed size 4 bytes */ 107 uLong compressed_size; /* compressed size 4 bytes */
108 uLong uncompressed_size; /* uncompressed size 4 bytes */ 108 uLong uncompressed_size; /* uncompressed size 4 bytes */
109 uLong size_filename; /* filename length 2 bytes */ 109 uLong size_filename; /* filename length 2 bytes */
110 uLong size_file_extra; /* extra field length 2 bytes */ 110 uLong size_file_extra; /* extra field length 2 bytes */
111 uLong size_file_comment; /* file comment length 2 bytes */ 111 uLong size_file_comment; /* file comment length 2 bytes */
112 112
113 uLong disk_num_start; /* disk number start 2 bytes */ 113 uLong disk_num_start; /* disk number start 2 bytes */
114 uLong internal_fa; /* internal file attributes 2 bytes */ 114 uLong internal_fa; /* internal file attributes 2 bytes */
115 uLong external_fa; /* external file attributes 4 bytes */ 115 uLong external_fa; /* external file attributes 4 bytes */
116 116
117 tm_unz tmu_date; 117 tm_unz tmu_date;
118} unz_file_info; 118} unz_file_info;
119 119
120extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 120extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
121 const char* fileName2, 121 const char* fileName2,
122 int iCaseSensitivity)); 122 int iCaseSensitivity));
123/* 123/*
124 Compare two filename (fileName1,fileName2). 124 Compare two filename (fileName1,fileName2).
125 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 125 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
126 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 126 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
127 or strcasecmp) 127 or strcasecmp)
128 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 128 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
129 (like 1 on Unix, 2 on Windows) 129 (like 1 on Unix, 2 on Windows)
130*/ 130*/
131 131
132 132
133extern unzFile ZEXPORT unzOpen OF((const char *path)); 133extern unzFile ZEXPORT unzOpen OF((const char *path));
134/* 134/*
135 Open a Zip file. path contain the full pathname (by example, 135 Open a Zip file. path contain the full pathname (by example,
136 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 136 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
137 "zlib/zlib113.zip". 137 "zlib/zlib113.zip".
138 If the zipfile cannot be opened (file don't exist or in not valid), the 138 If the zipfile cannot be opened (file don't exist or in not valid), the
139 return value is NULL. 139 return value is NULL.
140 Else, the return value is a unzFile Handle, usable with other function 140 Else, the return value is a unzFile Handle, usable with other function
141 of this unzip package. 141 of this unzip package.
142*/ 142*/
143 143
144extern unzFile ZEXPORT unzOpen2 OF((const char *path, 144extern unzFile ZEXPORT unzOpen2 OF((const char *path,
145 zlib_filefunc_def* pzlib_filefunc_def)); 145 zlib_filefunc_def* pzlib_filefunc_def));
146/* 146/*
147 Open a Zip file, like unzOpen, but provide a set of file low level API 147 Open a Zip file, like unzOpen, but provide a set of file low level API
148 for read/write the zip file (see ioapi.h) 148 for read/write the zip file (see ioapi.h)
149*/ 149*/
150 150
151extern int ZEXPORT unzClose OF((unzFile file)); 151extern int ZEXPORT unzClose OF((unzFile file));
152/* 152/*
153 Close a ZipFile opened with unzipOpen. 153 Close a ZipFile opened with unzipOpen.
154 If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 154 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
155 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 155 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
156 return UNZ_OK if there is no problem. */ 156 return UNZ_OK if there is no problem. */
157 157
158extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 158extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
159 unz_global_info *pglobal_info)); 159 unz_global_info *pglobal_info));
160/* 160/*
161 Write info about the ZipFile in the *pglobal_info structure. 161 Write info about the ZipFile in the *pglobal_info structure.
162 No preparation of the structure is needed 162 No preparation of the structure is needed
163 return UNZ_OK if there is no problem. */ 163 return UNZ_OK if there is no problem. */
164 164
165 165
166extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 166extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
167 char *szComment, 167 char *szComment,
168 uLong uSizeBuf)); 168 uLong uSizeBuf));
169/* 169/*
170 Get the global comment string of the ZipFile, in the szComment buffer. 170 Get the global comment string of the ZipFile, in the szComment buffer.
171 uSizeBuf is the size of the szComment buffer. 171 uSizeBuf is the size of the szComment buffer.
172 return the number of byte copied or an error code <0 172 return the number of byte copied or an error code <0
173*/ 173*/
174 174
175 175
176/***************************************************************************/ 176/***************************************************************************/
177/* Unzip package allow you browse the directory of the zipfile */ 177/* Unzip package allow you browse the directory of the zipfile */
178 178
179extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 179extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
180/* 180/*
181 Set the current file of the zipfile to the first file. 181 Set the current file of the zipfile to the first file.
182 return UNZ_OK if there is no problem 182 return UNZ_OK if there is no problem
183*/ 183*/
184 184
185extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 185extern int ZEXPORT unzGoToNextFile OF((unzFile file));
186/* 186/*
187 Set the current file of the zipfile to the next file. 187 Set the current file of the zipfile to the next file.
188 return UNZ_OK if there is no problem 188 return UNZ_OK if there is no problem
189 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 189 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
190*/ 190*/
191 191
192extern int ZEXPORT unzLocateFile OF((unzFile file, 192extern int ZEXPORT unzLocateFile OF((unzFile file,
193 const char *szFileName, 193 const char *szFileName,
194 int iCaseSensitivity)); 194 int iCaseSensitivity));
195/* 195/*
196 Try locate the file szFileName in the zipfile. 196 Try locate the file szFileName in the zipfile.
197 For the iCaseSensitivity signification, see unzStringFileNameCompare 197 For the iCaseSensitivity signification, see unzStringFileNameCompare
198 198
199 return value : 199 return value :
200 UNZ_OK if the file is found. It becomes the current file. 200 UNZ_OK if the file is found. It becomes the current file.
201 UNZ_END_OF_LIST_OF_FILE if the file is not found 201 UNZ_END_OF_LIST_OF_FILE if the file is not found
202*/ 202*/
203 203
204 204
205/* ****************************************** */ 205/* ****************************************** */
206/* Ryan supplied functions */ 206/* Ryan supplied functions */
207/* unz_file_info contain information about a file in the zipfile */ 207/* unz_file_info contain information about a file in the zipfile */
208typedef struct unz_file_pos_s 208typedef struct unz_file_pos_s
209{ 209{
210 uLong pos_in_zip_directory; /* offset in zip file directory */ 210 uLong pos_in_zip_directory; /* offset in zip file directory */
211 uLong num_of_file; /* # of file */ 211 uLong num_of_file; /* # of file */
212} unz_file_pos; 212} unz_file_pos;
213 213
214extern int ZEXPORT unzGetFilePos( 214extern int ZEXPORT unzGetFilePos(
215 unzFile file, 215 unzFile file,
216 unz_file_pos* file_pos); 216 unz_file_pos* file_pos);
217 217
218extern int ZEXPORT unzGoToFilePos( 218extern int ZEXPORT unzGoToFilePos(
219 unzFile file, 219 unzFile file,
220 unz_file_pos* file_pos); 220 unz_file_pos* file_pos);
221 221
222/* ****************************************** */ 222/* ****************************************** */
223 223
224extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 224extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
225 unz_file_info *pfile_info, 225 unz_file_info *pfile_info,
226 char *szFileName, 226 char *szFileName,
227 uLong fileNameBufferSize, 227 uLong fileNameBufferSize,
228 void *extraField, 228 void *extraField,
229 uLong extraFieldBufferSize, 229 uLong extraFieldBufferSize,
230 char *szComment, 230 char *szComment,
231 uLong commentBufferSize)); 231 uLong commentBufferSize));
232/* 232/*
233 Get Info about the current file 233 Get Info about the current file
234 if pfile_info!=NULL, the *pfile_info structure will contain somes info about 234 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
235 the current file 235 the current file
236 if szFileName!=NULL, the filemane string will be copied in szFileName 236 if szFileName!=NULL, the filemane string will be copied in szFileName
237 (fileNameBufferSize is the size of the buffer) 237 (fileNameBufferSize is the size of the buffer)
238 if extraField!=NULL, the extra field information will be copied in extraField 238 if extraField!=NULL, the extra field information will be copied in extraField
239 (extraFieldBufferSize is the size of the buffer). 239 (extraFieldBufferSize is the size of the buffer).
240 This is the Central-header version of the extra field 240 This is the Central-header version of the extra field
241 if szComment!=NULL, the comment string of the file will be copied in szComment 241 if szComment!=NULL, the comment string of the file will be copied in szComment
242 (commentBufferSize is the size of the buffer) 242 (commentBufferSize is the size of the buffer)
243*/ 243*/
244 244
245/***************************************************************************/ 245/***************************************************************************/
246/* for reading the content of the current zipfile, you can open it, read data 246/* for reading the content of the current zipfile, you can open it, read data
247 from it, and close it (you can close it before reading all the file) 247 from it, and close it (you can close it before reading all the file)
248 */ 248 */
249 249
250extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 250extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
251/* 251/*
252 Open for reading data the current file in the zipfile. 252 Open for reading data the current file in the zipfile.
253 If there is no error, the return value is UNZ_OK. 253 If there is no error, the return value is UNZ_OK.
254*/ 254*/
255 255
256extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 256extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
257 const char* password)); 257 const char* password));
258/* 258/*
259 Open for reading data the current file in the zipfile. 259 Open for reading data the current file in the zipfile.
260 password is a crypting password 260 password is a crypting password
261 If there is no error, the return value is UNZ_OK. 261 If there is no error, the return value is UNZ_OK.
262*/ 262*/
263 263
264extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 264extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
265 int* method, 265 int* method,
266 int* level, 266 int* level,
267 int raw)); 267 int raw));
268/* 268/*
269 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 269 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
270 if raw==1 270 if raw==1
271 *method will receive method of compression, *level will receive level of 271 *method will receive method of compression, *level will receive level of
272 compression 272 compression
273 note : you can set level parameter as NULL (if you did not want known level, 273 note : you can set level parameter as NULL (if you did not want known level,
274 but you CANNOT set method parameter as NULL 274 but you CANNOT set method parameter as NULL
275*/ 275*/
276 276
277extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 277extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
278 int* method, 278 int* method,
279 int* level, 279 int* level,
280 int raw, 280 int raw,
281 const char* password)); 281 const char* password));
282/* 282/*
283 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 283 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
284 if raw==1 284 if raw==1
285 *method will receive method of compression, *level will receive level of 285 *method will receive method of compression, *level will receive level of
286 compression 286 compression
287 note : you can set level parameter as NULL (if you did not want known level, 287 note : you can set level parameter as NULL (if you did not want known level,
288 but you CANNOT set method parameter as NULL 288 but you CANNOT set method parameter as NULL
289*/ 289*/
290 290
291 291
292extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 292extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
293/* 293/*
294 Close the file in zip opened with unzOpenCurrentFile 294 Close the file in zip opened with unzOpenCurrentFile
295 Return UNZ_CRCERROR if all the file was read but the CRC is not good 295 Return UNZ_CRCERROR if all the file was read but the CRC is not good
296*/ 296*/
297 297
298extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 298extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
299 voidp buf, 299 voidp buf,
300 unsigned len)); 300 unsigned len));
301/* 301/*
302 Read bytes from the current file (opened by unzOpenCurrentFile) 302 Read bytes from the current file (opened by unzOpenCurrentFile)
303 buf contain buffer where data must be copied 303 buf contain buffer where data must be copied
304 len the size of buf. 304 len the size of buf.
305 305
306 return the number of byte copied if somes bytes are copied 306 return the number of byte copied if somes bytes are copied
307 return 0 if the end of file was reached 307 return 0 if the end of file was reached
308 return <0 with error code if there is an error 308 return <0 with error code if there is an error
309 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 309 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
310*/ 310*/
311 311
312extern z_off_t ZEXPORT unztell OF((unzFile file)); 312extern z_off_t ZEXPORT unztell OF((unzFile file));
313/* 313/*
314 Give the current position in uncompressed data 314 Give the current position in uncompressed data
315*/ 315*/
316 316
317extern int ZEXPORT unzeof OF((unzFile file)); 317extern int ZEXPORT unzeof OF((unzFile file));
318/* 318/*
319 return 1 if the end of file was reached, 0 elsewhere 319 return 1 if the end of file was reached, 0 elsewhere
320*/ 320*/
321 321
322extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 322extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
323 voidp buf, 323 voidp buf,
324 unsigned len)); 324 unsigned len));
325/* 325/*
326 Read extra field from the current file (opened by unzOpenCurrentFile) 326 Read extra field from the current file (opened by unzOpenCurrentFile)
327 This is the local-header version of the extra field (sometimes, there is 327 This is the local-header version of the extra field (sometimes, there is
328 more info in the local-header version than in the central-header) 328 more info in the local-header version than in the central-header)
329 329
330 if buf==NULL, it return the size of the local extra field 330 if buf==NULL, it return the size of the local extra field
331 331
332 if buf!=NULL, len is the size of the buffer, the extra header is copied in 332 if buf!=NULL, len is the size of the buffer, the extra header is copied in
333 buf. 333 buf.
334 the return value is the number of bytes copied in buf, or (if <0) 334 the return value is the number of bytes copied in buf, or (if <0)
335 the error code 335 the error code
336*/ 336*/
337 337
338#ifdef __cplusplus 338#ifdef __cplusplus
339} 339}
340#endif 340#endif
341 341
342#endif /* _unz_H */ 342#endif /* _unz_H */
diff --git a/contrib/minizip/zconf.h b/contrib/minizip/zconf.h
new file mode 100644
index 0000000..8e6215a
--- /dev/null
+++ b/contrib/minizip/zconf.h
@@ -0,0 +1,326 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2003 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
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 inflateInit2_ z_inflateInit2_
29# define inflateSetDictionary z_inflateSetDictionary
30# define inflateSync z_inflateSync
31# define inflateSyncPoint z_inflateSyncPoint
32# define inflateCopy z_inflateCopy
33# define inflateReset z_inflateReset
34# define compress z_compress
35# define compress2 z_compress2
36# define compressBound z_compressBound
37# define uncompress z_uncompress
38# define adler32 z_adler32
39# define crc32 z_crc32
40# define get_crc_table z_get_crc_table
41
42# define Byte z_Byte
43# define uInt z_uInt
44# define uLong z_uLong
45# define Bytef z_Bytef
46# define charf z_charf
47# define intf z_intf
48# define uIntf z_uIntf
49# define uLongf z_uLongf
50# define voidpf z_voidpf
51# define voidp z_voidp
52#endif
53
54
55#ifdef __STDC_VERSION__
56# ifndef STDC
57# define STDC
58# endif
59# if __STDC_VERSION__ >= 199901L
60# ifndef STDC99
61# define STDC99
62# endif
63# endif
64#endif
65
66
67#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
68# define WIN32
69#endif
70#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
71# ifndef __32BIT__
72# define __32BIT__
73# endif
74#endif
75#if defined(__MSDOS__) && !defined(MSDOS)
76# define MSDOS
77#endif
78
79/*
80 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
81 * than 64k bytes at a time (needed on systems with 16-bit int).
82 */
83#if defined(MSDOS) && !defined(__32BIT__)
84# define MAXSEG_64K
85#endif
86#ifdef MSDOS
87# define UNALIGNED_OK
88#endif
89
90#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
91# define STDC
92#endif
93#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
94# ifndef STDC
95# define STDC
96# endif
97#endif
98
99#if defined __HOS_AIX__
100# ifndef STDC
101# define STDC
102# endif
103#endif
104
105#ifndef STDC
106# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
107# define const /* note: need a more gentle solution here */
108# endif
109#endif
110
111/* Some Mac compilers merge all .h files incorrectly: */
112#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
113# define NO_DUMMY_DECL
114#endif
115
116/* Old Borland C incorrectly complains about missing returns: */
117#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
118# define NEED_DUMMY_RETURN
119#endif
120#if defined(__TURBOC__) && !defined(__BORLANDC__)
121# define NEED_DUMMY_RETURN
122#endif
123
124
125/* Maximum value for memLevel in deflateInit2 */
126#ifndef MAX_MEM_LEVEL
127# ifdef MAXSEG_64K
128# define MAX_MEM_LEVEL 8
129# else
130# define MAX_MEM_LEVEL 9
131# endif
132#endif
133
134/* Maximum value for windowBits in deflateInit2 and inflateInit2.
135 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
136 * created by gzip. (Files created by minigzip can still be extracted by
137 * gzip.)
138 */
139#ifndef MAX_WBITS
140# define MAX_WBITS 15 /* 32K LZ77 window */
141#endif
142
143/* The memory requirements for deflate are (in bytes):
144 (1 << (windowBits+2)) + (1 << (memLevel+9))
145 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
146 plus a few kilobytes for small objects. For example, if you want to reduce
147 the default memory requirements from 256K to 128K, compile with
148 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
149 Of course this will generally degrade compression (there's no free lunch).
150
151 The memory requirements for inflate are (in bytes) 1 << windowBits
152 that is, 32K for windowBits=15 (default value) plus a few kilobytes
153 for small objects.
154*/
155
156 /* Type declarations */
157
158#ifndef OF /* function prototypes */
159# ifdef STDC
160# define OF(args) args
161# else
162# define OF(args) ()
163# endif
164#endif
165
166/*
167 * Microsoft Visual Studio define _vsnprintf but not vsnprintf
168 */
169#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED)
170# ifdef MSDOS
171 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
172 but for now we just assume it doesn't. */
173# define NO_vsnprintf
174# endif
175# ifdef WIN32
176 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
177# if !defined(vsnprintf) && !defined(__TURBOC__)
178# define vsnprintf _vsnprintf
179# endif
180# endif
181# ifdef __TURBOC__
182# define NO_vsnprintf
183# endif
184#endif
185
186/* The following definitions for FAR are needed only for MSDOS mixed
187 * model programming (small or medium model with some far allocations).
188 * This was tested only with MSC; for other MSDOS compilers you may have
189 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
190 * just define FAR to be empty.
191 */
192#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
193 /* MSC small or medium model */
194# define SMALL_MEDIUM
195# ifdef _MSC_VER
196# define FAR _far
197# else
198# define FAR far
199# endif
200#endif
201#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
202# ifndef __32BIT__
203# define SMALL_MEDIUM
204# define FAR _far
205# endif
206#endif
207
208#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))
209# define ZLIB_DLL
210#endif
211
212/* Compile with -DZLIB_DLL for Windows DLL support */
213#if defined(ZLIB_DLL)
214# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
215# ifndef WINAPIV
216# ifdef FAR
217# undef FAR
218# endif
219# include <windows.h>
220# endif
221# ifdef WIN32
222# define ZEXPORT WINAPI
223# define ZEXPORTVA WINAPIV
224# else
225# define ZEXPORT WINAPI _export
226# define ZEXPORTVA FAR _cdecl _export
227# endif
228# endif
229# if defined (__BORLANDC__)
230# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
231# include <windows.h>
232# define ZEXPORT __declspec(dllexport) WINAPI
233# define ZEXPORTVA __declspec(dllexport) WINAPIV
234# else
235# if defined (_Windows) && defined (__DLL__)
236# define ZEXPORT _export
237# define ZEXPORTVA _export
238# endif
239# endif
240# endif
241#endif
242
243#if defined (__BEOS__)
244# if defined (ZLIB_DLL)
245# define ZEXTERN extern __declspec(dllexport)
246# else
247# define ZEXTERN extern __declspec(dllimport)
248# endif
249#endif
250
251#ifndef ZEXPORT
252# define ZEXPORT
253#endif
254#ifndef ZEXPORTVA
255# define ZEXPORTVA
256#endif
257#ifndef ZEXTERN
258# define ZEXTERN extern
259#endif
260
261#ifndef FAR
262# define FAR
263#endif
264
265#if !defined(__MACTYPES__)
266typedef unsigned char Byte; /* 8 bits */
267#endif
268typedef unsigned int uInt; /* 16 bits or more */
269typedef unsigned long uLong; /* 32 bits or more */
270
271#ifdef SMALL_MEDIUM
272 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
273# define Bytef Byte FAR
274#else
275 typedef Byte FAR Bytef;
276#endif
277typedef char FAR charf;
278typedef int FAR intf;
279typedef uInt FAR uIntf;
280typedef uLong FAR uLongf;
281
282#ifdef STDC
283 typedef void const *voidpc;
284 typedef void FAR *voidpf;
285 typedef void *voidp;
286#else
287 typedef Byte const *voidpc;
288 typedef Byte FAR *voidpf;
289 typedef Byte *voidp;
290#endif
291
292#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
293# include <sys/types.h> /* for off_t */
294# include <unistd.h> /* for SEEK_* and off_t */
295# ifdef VMS
296# include <unixio.h> /* for off_t */
297# endif
298# define z_off_t off_t
299#endif
300#ifndef SEEK_SET
301# define SEEK_SET 0 /* Seek from beginning of file. */
302# define SEEK_CUR 1 /* Seek from current position. */
303# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
304#endif
305#ifndef z_off_t
306# define z_off_t long
307#endif
308
309/* MVS linker does not support external names larger than 8 bytes */
310#if defined(__MVS__)
311# pragma map(deflateInit_,"DEIN")
312# pragma map(deflateInit2_,"DEIN2")
313# pragma map(deflateEnd,"DEEND")
314# pragma map(deflateBound,"DEBND")
315# pragma map(inflateInit_,"ININ")
316# pragma map(inflateInit2_,"ININ2")
317# pragma map(inflateEnd,"INEND")
318# pragma map(inflateSync,"INSY")
319# pragma map(inflateSetDictionary,"INSEDI")
320# pragma map(compressBound,"CMBND")
321# pragma map(inflate_table,"INTABL")
322# pragma map(inflate_fast,"INFA")
323# pragma map(inflate_copyright,"INCOPY")
324#endif
325
326#endif /* _ZCONF_H */
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 29c17d8..00587fb 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -1,1168 +1,1168 @@
1/* zip.c -- IO on .zip files using zlib 1/* zip.c -- IO on .zip files using zlib
2 Version 0.21, March 10th, 2003 2 Version 0.22, May 19th, 2003
3 3
4 Read zip.h for more info 4 Read zip.h for more info
5*/ 5*/
6 6
7 7
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 <time.h> 11#include <time.h>
12#include "zlib.h" 12#include "zlib.h"
13#include "zip.h" 13#include "zip.h"
14 14
15#ifdef STDC 15#ifdef STDC
16# include <stddef.h> 16# include <stddef.h>
17# include <string.h> 17# include <string.h>
18# include <stdlib.h> 18# include <stdlib.h>
19#endif 19#endif
20#ifdef NO_ERRNO_H 20#ifdef NO_ERRNO_H
21 extern int errno; 21 extern int errno;
22#else 22#else
23# include <errno.h> 23# include <errno.h>
24#endif 24#endif
25 25
26 26
27#ifndef local 27#ifndef local
28# define local static 28# define local static
29#endif 29#endif
30/* compile with -Dlocal if your debugger can't find static symbols */ 30/* compile with -Dlocal if your debugger can't find static symbols */
31 31
32#ifndef VERSIONMADEBY 32#ifndef VERSIONMADEBY
33# define VERSIONMADEBY (0x0) /* platform depedent */ 33# define VERSIONMADEBY (0x0) /* platform depedent */
34#endif 34#endif
35 35
36#ifndef Z_BUFSIZE 36#ifndef Z_BUFSIZE
37#define Z_BUFSIZE (16384) 37#define Z_BUFSIZE (16384)
38#endif 38#endif
39 39
40#ifndef Z_MAXFILENAMEINZIP 40#ifndef Z_MAXFILENAMEINZIP
41#define Z_MAXFILENAMEINZIP (256) 41#define Z_MAXFILENAMEINZIP (256)
42#endif 42#endif
43 43
44#ifndef ALLOC 44#ifndef ALLOC
45# define ALLOC(size) (malloc(size)) 45# define ALLOC(size) (malloc(size))
46#endif 46#endif
47#ifndef TRYFREE 47#ifndef TRYFREE
48# define TRYFREE(p) {if (p) free(p);} 48# define TRYFREE(p) {if (p) free(p);}
49#endif 49#endif
50 50
51/* 51/*
52#define SIZECENTRALDIRITEM (0x2e) 52#define SIZECENTRALDIRITEM (0x2e)
53#define SIZEZIPLOCALHEADER (0x1e) 53#define SIZEZIPLOCALHEADER (0x1e)
54*/ 54*/
55 55
56/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 56/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
57 57
58#ifndef SEEK_CUR 58#ifndef SEEK_CUR
59#define SEEK_CUR 1 59#define SEEK_CUR 1
60#endif 60#endif
61 61
62#ifndef SEEK_END 62#ifndef SEEK_END
63#define SEEK_END 2 63#define SEEK_END 2
64#endif 64#endif
65 65
66#ifndef SEEK_SET 66#ifndef SEEK_SET
67#define SEEK_SET 0 67#define SEEK_SET 0
68#endif 68#endif
69 69
70#ifndef DEF_MEM_LEVEL 70#ifndef DEF_MEM_LEVEL
71#if MAX_MEM_LEVEL >= 8 71#if MAX_MEM_LEVEL >= 8
72# define DEF_MEM_LEVEL 8 72# define DEF_MEM_LEVEL 8
73#else 73#else
74# define DEF_MEM_LEVEL MAX_MEM_LEVEL 74# define DEF_MEM_LEVEL MAX_MEM_LEVEL
75#endif 75#endif
76#endif 76#endif
77const char zip_copyright[] = 77const char zip_copyright[] =
78 " zip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; 78 " zip 0.22 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
79 79
80 80
81#define SIZEDATA_INDATABLOCK (4096-(4*4)) 81#define SIZEDATA_INDATABLOCK (4096-(4*4))
82 82
83#define LOCALHEADERMAGIC (0x04034b50) 83#define LOCALHEADERMAGIC (0x04034b50)
84#define CENTRALHEADERMAGIC (0x02014b50) 84#define CENTRALHEADERMAGIC (0x02014b50)
85#define ENDHEADERMAGIC (0x06054b50) 85#define ENDHEADERMAGIC (0x06054b50)
86 86
87#define FLAG_LOCALHEADER_OFFSET (0x06) 87#define FLAG_LOCALHEADER_OFFSET (0x06)
88#define CRC_LOCALHEADER_OFFSET (0x0e) 88#define CRC_LOCALHEADER_OFFSET (0x0e)
89 89
90#define SIZECENTRALHEADER (0x2e) /* 46 */ 90#define SIZECENTRALHEADER (0x2e) /* 46 */
91 91
92typedef struct linkedlist_datablock_internal_s 92typedef struct linkedlist_datablock_internal_s
93{ 93{
94 struct linkedlist_datablock_internal_s* next_datablock; 94 struct linkedlist_datablock_internal_s* next_datablock;
95 uLong avail_in_this_block; 95 uLong avail_in_this_block;
96 uLong filled_in_this_block; 96 uLong filled_in_this_block;
97 uLong unused; /* for future use and alignement */ 97 uLong unused; /* for future use and alignement */
98 unsigned char data[SIZEDATA_INDATABLOCK]; 98 unsigned char data[SIZEDATA_INDATABLOCK];
99} linkedlist_datablock_internal; 99} linkedlist_datablock_internal;
100 100
101typedef struct linkedlist_data_s 101typedef struct linkedlist_data_s
102{ 102{
103 linkedlist_datablock_internal* first_block; 103 linkedlist_datablock_internal* first_block;
104 linkedlist_datablock_internal* last_block; 104 linkedlist_datablock_internal* last_block;
105} linkedlist_data; 105} linkedlist_data;
106 106
107 107
108typedef struct 108typedef struct
109{ 109{
110 z_stream stream; /* zLib stream structure for inflate */ 110 z_stream stream; /* zLib stream structure for inflate */
111 int stream_initialised; /* 1 is stream is initialised */ 111 int stream_initialised; /* 1 is stream is initialised */
112 uInt pos_in_buffered_data; /* last written byte in buffered_data */ 112 uInt pos_in_buffered_data; /* last written byte in buffered_data */
113 113
114 uLong pos_local_header; /* offset of the local header of the file 114 uLong pos_local_header; /* offset of the local header of the file
115 currenty writing */ 115 currenty writing */
116 char* central_header; /* central header data for the current file */ 116 char* central_header; /* central header data for the current file */
117 uLong size_centralheader; /* size of the central header for cur file */ 117 uLong size_centralheader; /* size of the central header for cur file */
118 uLong flag; /* flag of the file currently writing */ 118 uLong flag; /* flag of the file currently writing */
119 119
120 int method; /* compression method of file currenty wr.*/ 120 int method; /* compression method of file currenty wr.*/
121 int raw; /* 1 for directly writing raw data */ 121 int raw; /* 1 for directly writing raw data */
122 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ 122 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
123 uLong dosDate; 123 uLong dosDate;
124 uLong crc32; 124 uLong crc32;
125 int encrypt; 125 int encrypt;
126#ifndef NOCRPYT 126#ifndef NOCRYPT
127 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 127 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
128 const unsigned long* pcrc_32_tab; 128 const unsigned long* pcrc_32_tab;
129 int crypt_header_size; 129 int crypt_header_size;
130#endif 130#endif
131} curfile_info; 131} curfile_info;
132 132
133typedef struct 133typedef struct
134{ 134{
135 zlib_filefunc_def z_filefunc; 135 zlib_filefunc_def z_filefunc;
136 voidpf filestream; /* io structore of the zipfile */ 136 voidpf filestream; /* io structore of the zipfile */
137 linkedlist_data central_dir;/* datablock with central dir in construction*/ 137 linkedlist_data central_dir;/* datablock with central dir in construction*/
138 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ 138 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
139 curfile_info ci; /* info on the file curretly writing */ 139 curfile_info ci; /* info on the file curretly writing */
140 140
141 uLong begin_pos; /* position of the beginning of the zipfile */ 141 uLong begin_pos; /* position of the beginning of the zipfile */
142 uLong add_position_when_writting_offset; 142 uLong add_position_when_writting_offset;
143 uLong number_entry; 143 uLong number_entry;
144} zip_internal; 144} zip_internal;
145 145
146 146
147 147
148#ifndef NOCRPYT 148#ifndef NOCRYPT
149#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED 149#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
150#include "crypt.h" 150#include "crypt.h"
151#endif 151#endif
152 152
153local linkedlist_datablock_internal* allocate_new_datablock() 153local linkedlist_datablock_internal* allocate_new_datablock()
154{ 154{
155 linkedlist_datablock_internal* ldi; 155 linkedlist_datablock_internal* ldi;
156 ldi = (linkedlist_datablock_internal*) 156 ldi = (linkedlist_datablock_internal*)
157 ALLOC(sizeof(linkedlist_datablock_internal)); 157 ALLOC(sizeof(linkedlist_datablock_internal));
158 if (ldi!=NULL) 158 if (ldi!=NULL)
159 { 159 {
160 ldi->next_datablock = NULL ; 160 ldi->next_datablock = NULL ;
161 ldi->filled_in_this_block = 0 ; 161 ldi->filled_in_this_block = 0 ;
162 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; 162 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
163 } 163 }
164 return ldi; 164 return ldi;
165} 165}
166 166
167local void free_datablock(ldi) 167local void free_datablock(ldi)
168 linkedlist_datablock_internal* ldi; 168 linkedlist_datablock_internal* ldi;
169{ 169{
170 while (ldi!=NULL) 170 while (ldi!=NULL)
171 { 171 {
172 linkedlist_datablock_internal* ldinext = ldi->next_datablock; 172 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
173 TRYFREE(ldi); 173 TRYFREE(ldi);
174 ldi = ldinext; 174 ldi = ldinext;
175 } 175 }
176} 176}
177 177
178local void init_linkedlist(ll) 178local void init_linkedlist(ll)
179 linkedlist_data* ll; 179 linkedlist_data* ll;
180{ 180{
181 ll->first_block = ll->last_block = NULL; 181 ll->first_block = ll->last_block = NULL;
182} 182}
183 183
184local void free_linkedlist(ll) 184local void free_linkedlist(ll)
185 linkedlist_data* ll; 185 linkedlist_data* ll;
186{ 186{
187 free_datablock(ll->first_block); 187 free_datablock(ll->first_block);
188 ll->first_block = ll->last_block = NULL; 188 ll->first_block = ll->last_block = NULL;
189} 189}
190 190
191 191
192local int add_data_in_datablock(ll,buf,len) 192local int add_data_in_datablock(ll,buf,len)
193 linkedlist_data* ll; 193 linkedlist_data* ll;
194 const void* buf; 194 const void* buf;
195 uLong len; 195 uLong len;
196{ 196{
197 linkedlist_datablock_internal* ldi; 197 linkedlist_datablock_internal* ldi;
198 const unsigned char* from_copy; 198 const unsigned char* from_copy;
199 199
200 if (ll==NULL) 200 if (ll==NULL)
201 return ZIP_INTERNALERROR; 201 return ZIP_INTERNALERROR;
202 202
203 if (ll->last_block == NULL) 203 if (ll->last_block == NULL)
204 { 204 {
205 ll->first_block = ll->last_block = allocate_new_datablock(); 205 ll->first_block = ll->last_block = allocate_new_datablock();
206 if (ll->first_block == NULL) 206 if (ll->first_block == NULL)
207 return ZIP_INTERNALERROR; 207 return ZIP_INTERNALERROR;
208 } 208 }
209 209
210 ldi = ll->last_block; 210 ldi = ll->last_block;
211 from_copy = (unsigned char*)buf; 211 from_copy = (unsigned char*)buf;
212 212
213 while (len>0) 213 while (len>0)
214 { 214 {
215 uInt copy_this; 215 uInt copy_this;
216 uInt i; 216 uInt i;
217 unsigned char* to_copy; 217 unsigned char* to_copy;
218 218
219 if (ldi->avail_in_this_block==0) 219 if (ldi->avail_in_this_block==0)
220 { 220 {
221 ldi->next_datablock = allocate_new_datablock(); 221 ldi->next_datablock = allocate_new_datablock();
222 if (ldi->next_datablock == NULL) 222 if (ldi->next_datablock == NULL)
223 return ZIP_INTERNALERROR; 223 return ZIP_INTERNALERROR;
224 ldi = ldi->next_datablock ; 224 ldi = ldi->next_datablock ;
225 ll->last_block = ldi; 225 ll->last_block = ldi;
226 } 226 }
227 227
228 if (ldi->avail_in_this_block < len) 228 if (ldi->avail_in_this_block < len)
229 copy_this = (uInt)ldi->avail_in_this_block; 229 copy_this = (uInt)ldi->avail_in_this_block;
230 else 230 else
231 copy_this = (uInt)len; 231 copy_this = (uInt)len;
232 232
233 to_copy = &(ldi->data[ldi->filled_in_this_block]); 233 to_copy = &(ldi->data[ldi->filled_in_this_block]);
234 234
235 for (i=0;i<copy_this;i++) 235 for (i=0;i<copy_this;i++)
236 *(to_copy+i)=*(from_copy+i); 236 *(to_copy+i)=*(from_copy+i);
237 237
238 ldi->filled_in_this_block += copy_this; 238 ldi->filled_in_this_block += copy_this;
239 ldi->avail_in_this_block -= copy_this; 239 ldi->avail_in_this_block -= copy_this;
240 from_copy += copy_this ; 240 from_copy += copy_this ;
241 len -= copy_this; 241 len -= copy_this;
242 } 242 }
243 return ZIP_OK; 243 return ZIP_OK;
244} 244}
245 245
246 246
247 247
248/****************************************************************************/ 248/****************************************************************************/
249 249
250#ifndef NO_ADDFILEINEXISTINGZIP 250#ifndef NO_ADDFILEINEXISTINGZIP
251/* =========================================================================== 251/* ===========================================================================
252 Inputs a long in LSB order to the given file 252 Inputs a long in LSB order to the given file
253 nbByte == 1, 2 or 4 (byte, short or long) 253 nbByte == 1, 2 or 4 (byte, short or long)
254*/ 254*/
255 255
256local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, 256local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,
257 voidpf filestream, uLong x, int nbByte)); 257 voidpf filestream, uLong x, int nbByte));
258local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) 258local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
259 const zlib_filefunc_def* pzlib_filefunc_def; 259 const zlib_filefunc_def* pzlib_filefunc_def;
260 voidpf filestream; 260 voidpf filestream;
261 uLong x; 261 uLong x;
262 int nbByte; 262 int nbByte;
263{ 263{
264 unsigned char buf[4]; 264 unsigned char buf[4];
265 int n; 265 int n;
266 for (n = 0; n < nbByte; n++) { 266 for (n = 0; n < nbByte; n++) {
267 buf[n] = (unsigned char)(x & 0xff); 267 buf[n] = (unsigned char)(x & 0xff);
268 x >>= 8; 268 x >>= 8;
269 } 269 }
270 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) 270 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
271 return ZIP_ERRNO; 271 return ZIP_ERRNO;
272 else 272 else
273 return ZIP_OK; 273 return ZIP_OK;
274} 274}
275 275
276local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); 276local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
277local void ziplocal_putValue_inmemory (dest, x, nbByte) 277local void ziplocal_putValue_inmemory (dest, x, nbByte)
278 void* dest; 278 void* dest;
279 uLong x; 279 uLong x;
280 int nbByte; 280 int nbByte;
281{ 281{
282 unsigned char* buf=(unsigned char*)dest; 282 unsigned char* buf=(unsigned char*)dest;
283 int n; 283 int n;
284 for (n = 0; n < nbByte; n++) { 284 for (n = 0; n < nbByte; n++) {
285 buf[n] = (unsigned char)(x & 0xff); 285 buf[n] = (unsigned char)(x & 0xff);
286 x >>= 8; 286 x >>= 8;
287 } 287 }
288} 288}
289/****************************************************************************/ 289/****************************************************************************/
290 290
291 291
292local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) 292local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
293 const tm_zip* ptm; 293 const tm_zip* ptm;
294 uLong dosDate; 294 uLong dosDate;
295{ 295{
296 uLong year = (uLong)ptm->tm_year; 296 uLong year = (uLong)ptm->tm_year;
297 if (year>1980) 297 if (year>1980)
298 year-=1980; 298 year-=1980;
299 else if (year>80) 299 else if (year>80)
300 year-=80; 300 year-=80;
301 return 301 return
302 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | 302 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
303 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); 303 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
304} 304}
305 305
306 306
307/****************************************************************************/ 307/****************************************************************************/
308 308
309local int ziplocal_getByte OF(( 309local int ziplocal_getByte OF((
310 const zlib_filefunc_def* pzlib_filefunc_def, 310 const zlib_filefunc_def* pzlib_filefunc_def,
311 voidpf filestream, 311 voidpf filestream,
312 int *pi)); 312 int *pi));
313 313
314local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) 314local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
315 const zlib_filefunc_def* pzlib_filefunc_def; 315 const zlib_filefunc_def* pzlib_filefunc_def;
316 voidpf filestream; 316 voidpf filestream;
317 int *pi; 317 int *pi;
318{ 318{
319 unsigned char c; 319 unsigned char c;
320 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 320 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
321 if (err==1) 321 if (err==1)
322 { 322 {
323 *pi = (int)c; 323 *pi = (int)c;
324 return ZIP_OK; 324 return ZIP_OK;
325 } 325 }
326 else 326 else
327 { 327 {
328 if (ZERROR(*pzlib_filefunc_def,filestream)) 328 if (ZERROR(*pzlib_filefunc_def,filestream))
329 return ZIP_ERRNO; 329 return ZIP_ERRNO;
330 else 330 else
331 return ZIP_EOF; 331 return ZIP_EOF;
332 } 332 }
333} 333}
334 334
335 335
336/* =========================================================================== 336/* ===========================================================================
337 Reads a long in LSB order from the given gz_stream. Sets 337 Reads a long in LSB order from the given gz_stream. Sets
338*/ 338*/
339local int ziplocal_getShort OF(( 339local int ziplocal_getShort OF((
340 const zlib_filefunc_def* pzlib_filefunc_def, 340 const zlib_filefunc_def* pzlib_filefunc_def,
341 voidpf filestream, 341 voidpf filestream,
342 uLong *pX)); 342 uLong *pX));
343 343
344local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) 344local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
345 const zlib_filefunc_def* pzlib_filefunc_def; 345 const zlib_filefunc_def* pzlib_filefunc_def;
346 voidpf filestream; 346 voidpf filestream;
347 uLong *pX; 347 uLong *pX;
348{ 348{
349 uLong x ; 349 uLong x ;
350 int i; 350 int i;
351 int err; 351 int err;
352 352
353 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 353 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
354 x = (uLong)i; 354 x = (uLong)i;
355 355
356 if (err==ZIP_OK) 356 if (err==ZIP_OK)
357 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 357 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
358 x += ((uLong)i)<<8; 358 x += ((uLong)i)<<8;
359 359
360 if (err==ZIP_OK) 360 if (err==ZIP_OK)
361 *pX = x; 361 *pX = x;
362 else 362 else
363 *pX = 0; 363 *pX = 0;
364 return err; 364 return err;
365} 365}
366 366
367local int ziplocal_getLong OF(( 367local int ziplocal_getLong OF((
368 const zlib_filefunc_def* pzlib_filefunc_def, 368 const zlib_filefunc_def* pzlib_filefunc_def,
369 voidpf filestream, 369 voidpf filestream,
370 uLong *pX)); 370 uLong *pX));
371 371
372local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) 372local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
373 const zlib_filefunc_def* pzlib_filefunc_def; 373 const zlib_filefunc_def* pzlib_filefunc_def;
374 voidpf filestream; 374 voidpf filestream;
375 uLong *pX; 375 uLong *pX;
376{ 376{
377 uLong x ; 377 uLong x ;
378 int i; 378 int i;
379 int err; 379 int err;
380 380
381 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 381 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
382 x = (uLong)i; 382 x = (uLong)i;
383 383
384 if (err==ZIP_OK) 384 if (err==ZIP_OK)
385 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 385 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
386 x += ((uLong)i)<<8; 386 x += ((uLong)i)<<8;
387 387
388 if (err==ZIP_OK) 388 if (err==ZIP_OK)
389 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 389 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
390 x += ((uLong)i)<<16; 390 x += ((uLong)i)<<16;
391 391
392 if (err==ZIP_OK) 392 if (err==ZIP_OK)
393 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 393 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
394 x += ((uLong)i)<<24; 394 x += ((uLong)i)<<24;
395 395
396 if (err==ZIP_OK) 396 if (err==ZIP_OK)
397 *pX = x; 397 *pX = x;
398 else 398 else
399 *pX = 0; 399 *pX = 0;
400 return err; 400 return err;
401} 401}
402 402
403#ifndef BUFREADCOMMENT 403#ifndef BUFREADCOMMENT
404#define BUFREADCOMMENT (0x400) 404#define BUFREADCOMMENT (0x400)
405#endif 405#endif
406/* 406/*
407 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
408 the global comment) 408 the global comment)
409*/ 409*/
410local uLong ziplocal_SearchCentralDir OF(( 410local uLong ziplocal_SearchCentralDir OF((
411 const zlib_filefunc_def* pzlib_filefunc_def, 411 const zlib_filefunc_def* pzlib_filefunc_def,
412 voidpf filestream)); 412 voidpf filestream));
413 413
414local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) 414local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
415 const zlib_filefunc_def* pzlib_filefunc_def; 415 const zlib_filefunc_def* pzlib_filefunc_def;
416 voidpf filestream; 416 voidpf filestream;
417{ 417{
418 unsigned char* buf; 418 unsigned char* buf;
419 uLong uSizeFile; 419 uLong uSizeFile;
420 uLong uBackRead; 420 uLong uBackRead;
421 uLong uMaxBack=0xffff; /* maximum size of global comment */ 421 uLong uMaxBack=0xffff; /* maximum size of global comment */
422 uLong uPosFound=0; 422 uLong uPosFound=0;
423 423
424 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 424 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
425 return 0; 425 return 0;
426 426
427 427
428 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 428 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
429 429
430 if (uMaxBack>uSizeFile) 430 if (uMaxBack>uSizeFile)
431 uMaxBack = uSizeFile; 431 uMaxBack = uSizeFile;
432 432
433 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 433 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
434 if (buf==NULL) 434 if (buf==NULL)
435 return 0; 435 return 0;
436 436
437 uBackRead = 4; 437 uBackRead = 4;
438 while (uBackRead<uMaxBack) 438 while (uBackRead<uMaxBack)
439 { 439 {
440 uLong uReadSize,uReadPos ; 440 uLong uReadSize,uReadPos ;
441 int i; 441 int i;
442 if (uBackRead+BUFREADCOMMENT>uMaxBack) 442 if (uBackRead+BUFREADCOMMENT>uMaxBack)
443 uBackRead = uMaxBack; 443 uBackRead = uMaxBack;
444 else 444 else
445 uBackRead+=BUFREADCOMMENT; 445 uBackRead+=BUFREADCOMMENT;
446 uReadPos = uSizeFile-uBackRead ; 446 uReadPos = uSizeFile-uBackRead ;
447 447
448 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 448 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
449 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 449 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
450 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 450 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
451 break; 451 break;
452 452
453 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 453 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
454 break; 454 break;
455 455
456 for (i=(int)uReadSize-3; (i--)>0;) 456 for (i=(int)uReadSize-3; (i--)>0;)
457 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 457 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
458 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 458 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
459 { 459 {
460 uPosFound = uReadPos+i; 460 uPosFound = uReadPos+i;
461 break; 461 break;
462 } 462 }
463 463
464 if (uPosFound!=0) 464 if (uPosFound!=0)
465 break; 465 break;
466 } 466 }
467 TRYFREE(buf); 467 TRYFREE(buf);
468 return uPosFound; 468 return uPosFound;
469} 469}
470#endif /* !NO_ADDFILEINEXISTINGZIP*/ 470#endif /* !NO_ADDFILEINEXISTINGZIP*/
471 471
472/************************************************************/ 472/************************************************************/
473extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) 473extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)
474 const char *pathname; 474 const char *pathname;
475 int append; 475 int append;
476 zipcharpc* globalcomment; 476 zipcharpc* globalcomment;
477 zlib_filefunc_def* pzlib_filefunc_def; 477 zlib_filefunc_def* pzlib_filefunc_def;
478{ 478{
479 zip_internal ziinit; 479 zip_internal ziinit;
480 zip_internal* zi; 480 zip_internal* zi;
481 int err=ZIP_OK; 481 int err=ZIP_OK;
482 482
483 483
484 if (pzlib_filefunc_def==NULL) 484 if (pzlib_filefunc_def==NULL)
485 fill_fopen_filefunc(&ziinit.z_filefunc); 485 fill_fopen_filefunc(&ziinit.z_filefunc);
486 else 486 else
487 ziinit.z_filefunc = *pzlib_filefunc_def; 487 ziinit.z_filefunc = *pzlib_filefunc_def;
488 488
489 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) 489 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))
490 (ziinit.z_filefunc.opaque, 490 (ziinit.z_filefunc.opaque,
491 pathname, 491 pathname,
492 (append == APPEND_STATUS_CREATE) ? 492 (append == APPEND_STATUS_CREATE) ?
493 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : 493 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
494 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); 494 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
495 495
496 if (ziinit.filestream == NULL) 496 if (ziinit.filestream == NULL)
497 return NULL; 497 return NULL;
498 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); 498 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
499 ziinit.in_opened_file_inzip = 0; 499 ziinit.in_opened_file_inzip = 0;
500 ziinit.ci.stream_initialised = 0; 500 ziinit.ci.stream_initialised = 0;
501 ziinit.number_entry = 0; 501 ziinit.number_entry = 0;
502 ziinit.add_position_when_writting_offset = 0; 502 ziinit.add_position_when_writting_offset = 0;
503 init_linkedlist(&(ziinit.central_dir)); 503 init_linkedlist(&(ziinit.central_dir));
504 504
505 505
506 zi = (zip_internal*)ALLOC(sizeof(zip_internal)); 506 zi = (zip_internal*)ALLOC(sizeof(zip_internal));
507 if (zi==NULL) 507 if (zi==NULL)
508 { 508 {
509 ZCLOSE(ziinit.z_filefunc,ziinit.filestream); 509 ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
510 return NULL; 510 return NULL;
511 } 511 }
512 512
513 /* now we add file in a zipfile */ 513 /* now we add file in a zipfile */
514 #ifndef NO_ADDFILEINEXISTINGZIP 514 #ifndef NO_ADDFILEINEXISTINGZIP
515 if (append == APPEND_STATUS_ADDINZIP) 515 if (append == APPEND_STATUS_ADDINZIP)
516 { 516 {
517 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 517 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
518 518
519 uLong size_central_dir; /* size of the central directory */ 519 uLong size_central_dir; /* size of the central directory */
520 uLong offset_central_dir; /* offset of start of central directory */ 520 uLong offset_central_dir; /* offset of start of central directory */
521 uLong central_pos,uL; 521 uLong central_pos,uL;
522 522
523 uLong number_disk; /* number of the current dist, used for 523 uLong number_disk; /* number of the current dist, used for
524 spaning ZIP, unsupported, always 0*/ 524 spaning ZIP, unsupported, always 0*/
525 uLong number_disk_with_CD; /* number the the disk with central dir, used 525 uLong number_disk_with_CD; /* number the the disk with central dir, used
526 for spaning ZIP, unsupported, always 0*/ 526 for spaning ZIP, unsupported, always 0*/
527 uLong number_entry; 527 uLong number_entry;
528 uLong number_entry_CD; /* total number of entries in 528 uLong number_entry_CD; /* total number of entries in
529 the central dir 529 the central dir
530 (same than number_entry on nospan) */ 530 (same than number_entry on nospan) */
531 uLong size_comment; 531 uLong size_comment;
532 532
533 central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); 533 central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
534 if (central_pos==0) 534 if (central_pos==0)
535 err=ZIP_ERRNO; 535 err=ZIP_ERRNO;
536 536
537 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, 537 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
538 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 538 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
539 err=ZIP_ERRNO; 539 err=ZIP_ERRNO;
540 540
541 /* the signature, already checked */ 541 /* the signature, already checked */
542 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) 542 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
543 err=ZIP_ERRNO; 543 err=ZIP_ERRNO;
544 544
545 /* number of this disk */ 545 /* number of this disk */
546 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) 546 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
547 err=ZIP_ERRNO; 547 err=ZIP_ERRNO;
548 548
549 /* number of the disk with the start of the central directory */ 549 /* number of the disk with the start of the central directory */
550 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) 550 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
551 err=ZIP_ERRNO; 551 err=ZIP_ERRNO;
552 552
553 /* total number of entries in the central dir on this disk */ 553 /* total number of entries in the central dir on this disk */
554 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) 554 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
555 err=ZIP_ERRNO; 555 err=ZIP_ERRNO;
556 556
557 /* total number of entries in the central dir */ 557 /* total number of entries in the central dir */
558 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) 558 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
559 err=ZIP_ERRNO; 559 err=ZIP_ERRNO;
560 560
561 if ((number_entry_CD!=number_entry) || 561 if ((number_entry_CD!=number_entry) ||
562 (number_disk_with_CD!=0) || 562 (number_disk_with_CD!=0) ||
563 (number_disk!=0)) 563 (number_disk!=0))
564 err=ZIP_BADZIPFILE; 564 err=ZIP_BADZIPFILE;
565 565
566 /* size of the central directory */ 566 /* size of the central directory */
567 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK) 567 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
568 err=ZIP_ERRNO; 568 err=ZIP_ERRNO;
569 569
570 /* offset of start of central directory with respect to the 570 /* offset of start of central directory with respect to the
571 starting disk number */ 571 starting disk number */
572 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) 572 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
573 err=ZIP_ERRNO; 573 err=ZIP_ERRNO;
574 574
575 /* zipfile comment length */ 575 /* zipfile comment length */
576 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) 576 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
577 err=ZIP_ERRNO; 577 err=ZIP_ERRNO;
578 578
579 if ((central_pos<offset_central_dir+size_central_dir) && 579 if ((central_pos<offset_central_dir+size_central_dir) &&
580 (err==ZIP_OK)) 580 (err==ZIP_OK))
581 err=ZIP_BADZIPFILE; 581 err=ZIP_BADZIPFILE;
582 582
583 if (err!=ZIP_OK) 583 if (err!=ZIP_OK)
584 { 584 {
585 ZCLOSE(ziinit.z_filefunc, ziinit.filestream); 585 ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
586 return NULL; 586 return NULL;
587 } 587 }
588 588
589 byte_before_the_zipfile = central_pos - 589 byte_before_the_zipfile = central_pos -
590 (offset_central_dir+size_central_dir); 590 (offset_central_dir+size_central_dir);
591 ziinit.add_position_when_writting_offset = byte_before_the_zipfile ; 591 ziinit.add_position_when_writting_offset = byte_before_the_zipfile ;
592 592
593 { 593 {
594 uLong size_central_dir_to_read = size_central_dir; 594 uLong size_central_dir_to_read = size_central_dir;
595 size_t buf_size = SIZEDATA_INDATABLOCK; 595 size_t buf_size = SIZEDATA_INDATABLOCK;
596 void* buf_read = (void*)ALLOC(buf_size); 596 void* buf_read = (void*)ALLOC(buf_size);
597 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, 597 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
598 offset_central_dir + byte_before_the_zipfile, 598 offset_central_dir + byte_before_the_zipfile,
599 ZLIB_FILEFUNC_SEEK_SET) != 0) 599 ZLIB_FILEFUNC_SEEK_SET) != 0)
600 err=ZIP_ERRNO; 600 err=ZIP_ERRNO;
601 601
602 while ((size_central_dir_to_read>0) && (err==ZIP_OK)) 602 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
603 { 603 {
604 uLong read_this = SIZEDATA_INDATABLOCK; 604 uLong read_this = SIZEDATA_INDATABLOCK;
605 if (read_this > size_central_dir_to_read) 605 if (read_this > size_central_dir_to_read)
606 read_this = size_central_dir_to_read; 606 read_this = size_central_dir_to_read;
607 if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) 607 if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
608 err=ZIP_ERRNO; 608 err=ZIP_ERRNO;
609 609
610 if (err==ZIP_OK) 610 if (err==ZIP_OK)
611 err = add_data_in_datablock(&ziinit.central_dir,buf_read, 611 err = add_data_in_datablock(&ziinit.central_dir,buf_read,
612 (uLong)read_this); 612 (uLong)read_this);
613 size_central_dir_to_read-=read_this; 613 size_central_dir_to_read-=read_this;
614 } 614 }
615 TRYFREE(buf_read); 615 TRYFREE(buf_read);
616 } 616 }
617 ziinit.begin_pos = byte_before_the_zipfile; 617 ziinit.begin_pos = byte_before_the_zipfile;
618 ziinit.number_entry = number_entry_CD; 618 ziinit.number_entry = number_entry_CD;
619 619
620 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, 620 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
621 offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 621 offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
622 err=ZIP_ERRNO; 622 err=ZIP_ERRNO;
623 } 623 }
624 #endif /* !NO_ADDFILEINEXISTINGZIP*/ 624 #endif /* !NO_ADDFILEINEXISTINGZIP*/
625 625
626 if (err != ZIP_OK) 626 if (err != ZIP_OK)
627 { 627 {
628 TRYFREE(zi); 628 TRYFREE(zi);
629 return NULL; 629 return NULL;
630 } 630 }
631 else 631 else
632 { 632 {
633 *zi = ziinit; 633 *zi = ziinit;
634 return (zipFile)zi; 634 return (zipFile)zi;
635 } 635 }
636} 636}
637 637
638extern zipFile ZEXPORT zipOpen (pathname, append) 638extern zipFile ZEXPORT zipOpen (pathname, append)
639 const char *pathname; 639 const char *pathname;
640 int append; 640 int append;
641{ 641{
642 return zipOpen2(pathname,append,NULL,NULL); 642 return zipOpen2(pathname,append,NULL,NULL);
643} 643}
644 644
645extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, 645extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
646 extrafield_local, size_extrafield_local, 646 extrafield_local, size_extrafield_local,
647 extrafield_global, size_extrafield_global, 647 extrafield_global, size_extrafield_global,
648 comment, method, level, raw, 648 comment, method, level, raw,
649 windowBits, memLevel, strategy, 649 windowBits, memLevel, strategy,
650 password, crcForCrypting) 650 password, crcForCrypting)
651 zipFile file; 651 zipFile file;
652 const char* filename; 652 const char* filename;
653 const zip_fileinfo* zipfi; 653 const zip_fileinfo* zipfi;
654 const void* extrafield_local; 654 const void* extrafield_local;
655 uInt size_extrafield_local; 655 uInt size_extrafield_local;
656 const void* extrafield_global; 656 const void* extrafield_global;
657 uInt size_extrafield_global; 657 uInt size_extrafield_global;
658 const char* comment; 658 const char* comment;
659 int method; 659 int method;
660 int level; 660 int level;
661 int raw; 661 int raw;
662 int windowBits; 662 int windowBits;
663 int memLevel; 663 int memLevel;
664 int strategy; 664 int strategy;
665 const char* password; 665 const char* password;
666 uLong crcForCrypting; 666 uLong crcForCrypting;
667{ 667{
668 zip_internal* zi; 668 zip_internal* zi;
669 uInt size_filename; 669 uInt size_filename;
670 uInt size_comment; 670 uInt size_comment;
671 uInt i; 671 uInt i;
672 int err = ZIP_OK; 672 int err = ZIP_OK;
673 673
674 #ifdef NOCRPYT 674 #ifdef NOCRYPT
675 if (password != NULL) 675 if (password != NULL)
676 return ZIP_PARAMERROR; 676 return ZIP_PARAMERROR;
677 #endif 677 #endif
678 678
679 if (file == NULL) 679 if (file == NULL)
680 return ZIP_PARAMERROR; 680 return ZIP_PARAMERROR;
681 if ((method!=0) && (method!=Z_DEFLATED)) 681 if ((method!=0) && (method!=Z_DEFLATED))
682 return ZIP_PARAMERROR; 682 return ZIP_PARAMERROR;
683 683
684 zi = (zip_internal*)file; 684 zi = (zip_internal*)file;
685 685
686 if (zi->in_opened_file_inzip == 1) 686 if (zi->in_opened_file_inzip == 1)
687 { 687 {
688 err = zipCloseFileInZip (file); 688 err = zipCloseFileInZip (file);
689 if (err != ZIP_OK) 689 if (err != ZIP_OK)
690 return err; 690 return err;
691 } 691 }
692 692
693 693
694 if (filename==NULL) 694 if (filename==NULL)
695 filename="-"; 695 filename="-";
696 696
697 if (comment==NULL) 697 if (comment==NULL)
698 size_comment = 0; 698 size_comment = 0;
699 else 699 else
700 size_comment = strlen(comment); 700 size_comment = strlen(comment);
701 701
702 size_filename = strlen(filename); 702 size_filename = strlen(filename);
703 703
704 if (zipfi == NULL) 704 if (zipfi == NULL)
705 zi->ci.dosDate = 0; 705 zi->ci.dosDate = 0;
706 else 706 else
707 { 707 {
708 if (zipfi->dosDate != 0) 708 if (zipfi->dosDate != 0)
709 zi->ci.dosDate = zipfi->dosDate; 709 zi->ci.dosDate = zipfi->dosDate;
710 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); 710 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
711 } 711 }
712 712
713 zi->ci.flag = 0; 713 zi->ci.flag = 0;
714 if ((level==8) || (level==9)) 714 if ((level==8) || (level==9))
715 zi->ci.flag |= 2; 715 zi->ci.flag |= 2;
716 if ((level==2)) 716 if ((level==2))
717 zi->ci.flag |= 4; 717 zi->ci.flag |= 4;
718 if ((level==1)) 718 if ((level==1))
719 zi->ci.flag |= 6; 719 zi->ci.flag |= 6;
720 if (password != NULL) 720 if (password != NULL)
721 zi->ci.flag |= 1; 721 zi->ci.flag |= 1;
722 722
723 zi->ci.crc32 = 0; 723 zi->ci.crc32 = 0;
724 zi->ci.method = method; 724 zi->ci.method = method;
725 zi->ci.encrypt = 0; 725 zi->ci.encrypt = 0;
726 zi->ci.stream_initialised = 0; 726 zi->ci.stream_initialised = 0;
727 zi->ci.pos_in_buffered_data = 0; 727 zi->ci.pos_in_buffered_data = 0;
728 zi->ci.raw = raw; 728 zi->ci.raw = raw;
729 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; 729 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;
730 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + 730 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
731 size_extrafield_global + size_comment; 731 size_extrafield_global + size_comment;
732 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); 732 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
733 733
734 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); 734 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
735 /* version info */ 735 /* version info */
736 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); 736 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
737 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); 737 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
738 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); 738 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
739 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); 739 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
740 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); 740 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
741 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ 741 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
742 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ 742 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
743 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ 743 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
744 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); 744 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
745 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); 745 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
746 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); 746 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
747 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ 747 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
748 748
749 if (zipfi==NULL) 749 if (zipfi==NULL)
750 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); 750 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
751 else 751 else
752 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); 752 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
753 753
754 if (zipfi==NULL) 754 if (zipfi==NULL)
755 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); 755 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
756 else 756 else
757 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); 757 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
758 758
759 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); 759 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);
760 760
761 for (i=0;i<size_filename;i++) 761 for (i=0;i<size_filename;i++)
762 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 762 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
763 763
764 for (i=0;i<size_extrafield_global;i++) 764 for (i=0;i<size_extrafield_global;i++)
765 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) = 765 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
766 *(((const char*)extrafield_global)+i); 766 *(((const char*)extrafield_global)+i);
767 767
768 for (i=0;i<size_comment;i++) 768 for (i=0;i<size_comment;i++)
769 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+ 769 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
770 size_extrafield_global+i) = *(comment+i); 770 size_extrafield_global+i) = *(comment+i);
771 if (zi->ci.central_header == NULL) 771 if (zi->ci.central_header == NULL)
772 return ZIP_INTERNALERROR; 772 return ZIP_INTERNALERROR;
773 773
774 /* write the local header */ 774 /* write the local header */
775 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); 775 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
776 776
777 if (err==ZIP_OK) 777 if (err==ZIP_OK)
778 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ 778 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
779 if (err==ZIP_OK) 779 if (err==ZIP_OK)
780 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); 780 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
781 781
782 if (err==ZIP_OK) 782 if (err==ZIP_OK)
783 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); 783 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
784 784
785 if (err==ZIP_OK) 785 if (err==ZIP_OK)
786 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); 786 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
787 787
788 if (err==ZIP_OK) 788 if (err==ZIP_OK)
789 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ 789 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
790 if (err==ZIP_OK) 790 if (err==ZIP_OK)
791 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ 791 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
792 if (err==ZIP_OK) 792 if (err==ZIP_OK)
793 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ 793 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
794 794
795 if (err==ZIP_OK) 795 if (err==ZIP_OK)
796 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); 796 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
797 797
798 if (err==ZIP_OK) 798 if (err==ZIP_OK)
799 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); 799 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
800 800
801 if ((err==ZIP_OK) && (size_filename>0)) 801 if ((err==ZIP_OK) && (size_filename>0))
802 if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) 802 if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
803 err = ZIP_ERRNO; 803 err = ZIP_ERRNO;
804 804
805 if ((err==ZIP_OK) && (size_extrafield_local>0)) 805 if ((err==ZIP_OK) && (size_extrafield_local>0))
806 if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) 806 if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
807 !=size_extrafield_local) 807 !=size_extrafield_local)
808 err = ZIP_ERRNO; 808 err = ZIP_ERRNO;
809 809
810 zi->ci.stream.avail_in = (uInt)0; 810 zi->ci.stream.avail_in = (uInt)0;
811 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 811 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
812 zi->ci.stream.next_out = zi->ci.buffered_data; 812 zi->ci.stream.next_out = zi->ci.buffered_data;
813 zi->ci.stream.total_in = 0; 813 zi->ci.stream.total_in = 0;
814 zi->ci.stream.total_out = 0; 814 zi->ci.stream.total_out = 0;
815 815
816 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 816 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
817 { 817 {
818 zi->ci.stream.zalloc = (alloc_func)0; 818 zi->ci.stream.zalloc = (alloc_func)0;
819 zi->ci.stream.zfree = (free_func)0; 819 zi->ci.stream.zfree = (free_func)0;
820 zi->ci.stream.opaque = (voidpf)0; 820 zi->ci.stream.opaque = (voidpf)0;
821 821
822 if (windowBits>0) 822 if (windowBits>0)
823 windowBits = -windowBits; 823 windowBits = -windowBits;
824 824
825 err = deflateInit2(&zi->ci.stream, level, 825 err = deflateInit2(&zi->ci.stream, level,
826 Z_DEFLATED, windowBits, memLevel, strategy); 826 Z_DEFLATED, windowBits, memLevel, strategy);
827 827
828 if (err==Z_OK) 828 if (err==Z_OK)
829 zi->ci.stream_initialised = 1; 829 zi->ci.stream_initialised = 1;
830 830 }
831 #ifndef NOCRPYT 831 #ifndef NOCRYPT
832 zi->ci.crypt_header_size = 0; 832 zi->ci.crypt_header_size = 0;
833 if ((err==Z_OK) && (password != NULL)) 833 if ((err==Z_OK) && (password != NULL))
834 { 834 {
835 unsigned char bufHead[RAND_HEAD_LEN]; 835 unsigned char bufHead[RAND_HEAD_LEN];
836 unsigned int sizeHead; 836 unsigned int sizeHead;
837 zi->ci.encrypt = 1; 837 zi->ci.encrypt = 1;
838 zi->ci.pcrc_32_tab = get_crc_table(); 838 zi->ci.pcrc_32_tab = get_crc_table();
839 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ 839 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
840 840
841 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); 841 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
842 zi->ci.crypt_header_size = sizeHead; 842 zi->ci.crypt_header_size = sizeHead;
843 843
844 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) 844 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
845 err = ZIP_ERRNO; 845 err = ZIP_ERRNO;
846 } 846 }
847 #endif 847 #endif
848 } 848
849 849 if (err==Z_OK)
850 850 zi->in_opened_file_inzip = 1;
851 if (err==Z_OK) 851 return err;
852 zi->in_opened_file_inzip = 1; 852}
853 return err; 853
854} 854extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
855 855 extrafield_local, size_extrafield_local,
856extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, 856 extrafield_global, size_extrafield_global,
857 extrafield_local, size_extrafield_local, 857 comment, method, level, raw)
858 extrafield_global, size_extrafield_global, 858 zipFile file;
859 comment, method, level, raw) 859 const char* filename;
860 zipFile file; 860 const zip_fileinfo* zipfi;
861 const char* filename; 861 const void* extrafield_local;
862 const zip_fileinfo* zipfi; 862 uInt size_extrafield_local;
863 const void* extrafield_local; 863 const void* extrafield_global;
864 uInt size_extrafield_local; 864 uInt size_extrafield_global;
865 const void* extrafield_global; 865 const char* comment;
866 uInt size_extrafield_global; 866 int method;
867 const char* comment; 867 int level;
868 int method; 868 int raw;
869 int level; 869{
870 int raw; 870 return zipOpenNewFileInZip3 (file, filename, zipfi,
871{ 871 extrafield_local, size_extrafield_local,
872 return zipOpenNewFileInZip3 (file, filename, zipfi, 872 extrafield_global, size_extrafield_global,
873 extrafield_local, size_extrafield_local, 873 comment, method, level, raw,
874 extrafield_global, size_extrafield_global, 874 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
875 comment, method, level, raw, 875 NULL, 0);
876 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 876}
877 NULL, 0); 877
878} 878extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
879 879 extrafield_local, size_extrafield_local,
880extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, 880 extrafield_global, size_extrafield_global,
881 extrafield_local, size_extrafield_local, 881 comment, method, level)
882 extrafield_global, size_extrafield_global, 882 zipFile file;
883 comment, method, level) 883 const char* filename;
884 zipFile file; 884 const zip_fileinfo* zipfi;
885 const char* filename; 885 const void* extrafield_local;
886 const zip_fileinfo* zipfi; 886 uInt size_extrafield_local;
887 const void* extrafield_local; 887 const void* extrafield_global;
888 uInt size_extrafield_local; 888 uInt size_extrafield_global;
889 const void* extrafield_global; 889 const char* comment;
890 uInt size_extrafield_global; 890 int method;
891 const char* comment; 891 int level;
892 int method; 892{
893 int level; 893 return zipOpenNewFileInZip2 (file, filename, zipfi,
894{ 894 extrafield_local, size_extrafield_local,
895 return zipOpenNewFileInZip2 (file, filename, zipfi, 895 extrafield_global, size_extrafield_global,
896 extrafield_local, size_extrafield_local, 896 comment, method, level, 0);
897 extrafield_global, size_extrafield_global, 897}
898 comment, method, level, 0); 898
899} 899local int zipFlushWriteBuffer(zi)
900 900 zip_internal* zi;
901local int zipFlushWriteBuffer(zi) 901{
902 zip_internal* zi; 902 int err=ZIP_OK;
903{ 903
904 int err=ZIP_OK; 904 if (zi->ci.encrypt != 0)
905 905 {
906 if (zi->ci.encrypt != 0) 906#ifndef NOCRYPT
907 { 907 uInt i;
908 uInt i; 908 int t;
909 int t; 909 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
910 for (i=0;i<zi->ci.pos_in_buffered_data;i++) 910 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
911 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, 911 zi->ci.buffered_data[i],t);
912 zi->ci.buffered_data[i],t); 912#endif
913 } 913 }
914 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) 914 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
915 !=zi->ci.pos_in_buffered_data) 915 !=zi->ci.pos_in_buffered_data)
916 err = ZIP_ERRNO; 916 err = ZIP_ERRNO;
917 zi->ci.pos_in_buffered_data = 0; 917 zi->ci.pos_in_buffered_data = 0;
918 return err; 918 return err;
919} 919}
920 920
921extern int ZEXPORT zipWriteInFileInZip (file, buf, len) 921extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
922 zipFile file; 922 zipFile file;
923 const void* buf; 923 const void* buf;
924 unsigned len; 924 unsigned len;
925{ 925{
926 zip_internal* zi; 926 zip_internal* zi;
927 int err=ZIP_OK; 927 int err=ZIP_OK;
928 928
929 if (file == NULL) 929 if (file == NULL)
930 return ZIP_PARAMERROR; 930 return ZIP_PARAMERROR;
931 zi = (zip_internal*)file; 931 zi = (zip_internal*)file;
932 932
933 if (zi->in_opened_file_inzip == 0) 933 if (zi->in_opened_file_inzip == 0)
934 return ZIP_PARAMERROR; 934 return ZIP_PARAMERROR;
935 935
936 zi->ci.stream.next_in = (void*)buf; 936 zi->ci.stream.next_in = (void*)buf;
937 zi->ci.stream.avail_in = len; 937 zi->ci.stream.avail_in = len;
938 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); 938 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
939 939
940 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) 940 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
941 { 941 {
942 if (zi->ci.stream.avail_out == 0) 942 if (zi->ci.stream.avail_out == 0)
943 { 943 {
944 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 944 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
945 err = ZIP_ERRNO; 945 err = ZIP_ERRNO;
946 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 946 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
947 zi->ci.stream.next_out = zi->ci.buffered_data; 947 zi->ci.stream.next_out = zi->ci.buffered_data;
948 } 948 }
949 949
950 950
951 if(err != ZIP_OK) 951 if(err != ZIP_OK)
952 break; 952 break;
953 953
954 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 954 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
955 { 955 {
956 uLong uTotalOutBefore = zi->ci.stream.total_out; 956 uLong uTotalOutBefore = zi->ci.stream.total_out;
957 err=deflate(&zi->ci.stream, Z_NO_FLUSH); 957 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
958 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 958 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
959 959
960 } 960 }
961 else 961 else
962 { 962 {
963 uInt copy_this,i; 963 uInt copy_this,i;
964 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) 964 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
965 copy_this = zi->ci.stream.avail_in; 965 copy_this = zi->ci.stream.avail_in;
966 else 966 else
967 copy_this = zi->ci.stream.avail_out; 967 copy_this = zi->ci.stream.avail_out;
968 for (i=0;i<copy_this;i++) 968 for (i=0;i<copy_this;i++)
969 *(((char*)zi->ci.stream.next_out)+i) = 969 *(((char*)zi->ci.stream.next_out)+i) =
970 *(((const char*)zi->ci.stream.next_in)+i); 970 *(((const char*)zi->ci.stream.next_in)+i);
971 { 971 {
972 zi->ci.stream.avail_in -= copy_this; 972 zi->ci.stream.avail_in -= copy_this;
973 zi->ci.stream.avail_out-= copy_this; 973 zi->ci.stream.avail_out-= copy_this;
974 zi->ci.stream.next_in+= copy_this; 974 zi->ci.stream.next_in+= copy_this;
975 zi->ci.stream.next_out+= copy_this; 975 zi->ci.stream.next_out+= copy_this;
976 zi->ci.stream.total_in+= copy_this; 976 zi->ci.stream.total_in+= copy_this;
977 zi->ci.stream.total_out+= copy_this; 977 zi->ci.stream.total_out+= copy_this;
978 zi->ci.pos_in_buffered_data += copy_this; 978 zi->ci.pos_in_buffered_data += copy_this;
979 } 979 }
980 } 980 }
981 } 981 }
982 982
983 return err; 983 return err;
984} 984}
985 985
986extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) 986extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
987 zipFile file; 987 zipFile file;
988 uLong uncompressed_size; 988 uLong uncompressed_size;
989 uLong crc32; 989 uLong crc32;
990{ 990{
991 zip_internal* zi; 991 zip_internal* zi;
992 uLong compressed_size; 992 uLong compressed_size;
993 int err=ZIP_OK; 993 int err=ZIP_OK;
994 994
995 if (file == NULL) 995 if (file == NULL)
996 return ZIP_PARAMERROR; 996 return ZIP_PARAMERROR;
997 zi = (zip_internal*)file; 997 zi = (zip_internal*)file;
998 998
999 if (zi->in_opened_file_inzip == 0) 999 if (zi->in_opened_file_inzip == 0)
1000 return ZIP_PARAMERROR; 1000 return ZIP_PARAMERROR;
1001 zi->ci.stream.avail_in = 0; 1001 zi->ci.stream.avail_in = 0;
1002 1002
1003 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1003 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1004 while (err==ZIP_OK) 1004 while (err==ZIP_OK)
1005 { 1005 {
1006 uLong uTotalOutBefore; 1006 uLong uTotalOutBefore;
1007 if (zi->ci.stream.avail_out == 0) 1007 if (zi->ci.stream.avail_out == 0)
1008 { 1008 {
1009 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 1009 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
1010 err = ZIP_ERRNO; 1010 err = ZIP_ERRNO;
1011 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1011 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1012 zi->ci.stream.next_out = zi->ci.buffered_data; 1012 zi->ci.stream.next_out = zi->ci.buffered_data;
1013 } 1013 }
1014 uTotalOutBefore = zi->ci.stream.total_out; 1014 uTotalOutBefore = zi->ci.stream.total_out;
1015 err=deflate(&zi->ci.stream, Z_FINISH); 1015 err=deflate(&zi->ci.stream, Z_FINISH);
1016 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1016 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1017 } 1017 }
1018 1018
1019 if (err==Z_STREAM_END) 1019 if (err==Z_STREAM_END)
1020 err=ZIP_OK; /* this is normal */ 1020 err=ZIP_OK; /* this is normal */
1021 1021
1022 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) 1022 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1023 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) 1023 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
1024 err = ZIP_ERRNO; 1024 err = ZIP_ERRNO;
1025 1025
1026 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1026 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1027 { 1027 {
1028 err=deflateEnd(&zi->ci.stream); 1028 err=deflateEnd(&zi->ci.stream);
1029 zi->ci.stream_initialised = 0; 1029 zi->ci.stream_initialised = 0;
1030 } 1030 }
1031 1031
1032 if (!zi->ci.raw) 1032 if (!zi->ci.raw)
1033 { 1033 {
1034 crc32 = (uLong)zi->ci.crc32; 1034 crc32 = (uLong)zi->ci.crc32;
1035 uncompressed_size = (uLong)zi->ci.stream.total_in; 1035 uncompressed_size = (uLong)zi->ci.stream.total_in;
1036 } 1036 }
1037 compressed_size = (uLong)zi->ci.stream.total_out; 1037 compressed_size = (uLong)zi->ci.stream.total_out;
1038 #ifndef NOCRPYT 1038 #ifndef NOCRYPT
1039 compressed_size += zi->ci.crypt_header_size; 1039 compressed_size += zi->ci.crypt_header_size;
1040 #endif 1040 #endif
1041 1041
1042 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ 1042 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
1043 ziplocal_putValue_inmemory(zi->ci.central_header+20, 1043 ziplocal_putValue_inmemory(zi->ci.central_header+20,
1044 compressed_size,4); /*compr size*/ 1044 compressed_size,4); /*compr size*/
1045 if (zi->ci.stream.data_type == Z_ASCII) 1045 if (zi->ci.stream.data_type == Z_ASCII)
1046 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); 1046 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1047 ziplocal_putValue_inmemory(zi->ci.central_header+24, 1047 ziplocal_putValue_inmemory(zi->ci.central_header+24,
1048 uncompressed_size,4); /*uncompr size*/ 1048 uncompressed_size,4); /*uncompr size*/
1049 1049
1050 if (err==ZIP_OK) 1050 if (err==ZIP_OK)
1051 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, 1051 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
1052 (uLong)zi->ci.size_centralheader); 1052 (uLong)zi->ci.size_centralheader);
1053 free(zi->ci.central_header); 1053 free(zi->ci.central_header);
1054 1054
1055 if (err==ZIP_OK) 1055 if (err==ZIP_OK)
1056 { 1056 {
1057 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); 1057 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
1058 if (ZSEEK(zi->z_filefunc,zi->filestream, 1058 if (ZSEEK(zi->z_filefunc,zi->filestream,
1059 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) 1059 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
1060 err = ZIP_ERRNO; 1060 err = ZIP_ERRNO;
1061 1061
1062 if (err==ZIP_OK) 1062 if (err==ZIP_OK)
1063 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ 1063 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1064 1064
1065 if (err==ZIP_OK) /* compressed size, unknown */ 1065 if (err==ZIP_OK) /* compressed size, unknown */
1066 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); 1066 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1067 1067
1068 if (err==ZIP_OK) /* uncompressed size, unknown */ 1068 if (err==ZIP_OK) /* uncompressed size, unknown */
1069 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); 1069 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1070 1070
1071 if (ZSEEK(zi->z_filefunc,zi->filestream, 1071 if (ZSEEK(zi->z_filefunc,zi->filestream,
1072 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) 1072 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1073 err = ZIP_ERRNO; 1073 err = ZIP_ERRNO;
1074 } 1074 }
1075 1075
1076 zi->number_entry ++; 1076 zi->number_entry ++;
1077 zi->in_opened_file_inzip = 0; 1077 zi->in_opened_file_inzip = 0;
1078 1078
1079 return err; 1079 return err;
1080} 1080}
1081 1081
1082extern int ZEXPORT zipCloseFileInZip (file) 1082extern int ZEXPORT zipCloseFileInZip (file)
1083 zipFile file; 1083 zipFile file;
1084{ 1084{
1085 return zipCloseFileInZipRaw (file,0,0); 1085 return zipCloseFileInZipRaw (file,0,0);
1086} 1086}
1087 1087
1088extern int ZEXPORT zipClose (file, global_comment) 1088extern int ZEXPORT zipClose (file, global_comment)
1089 zipFile file; 1089 zipFile file;
1090 const char* global_comment; 1090 const char* global_comment;
1091{ 1091{
1092 zip_internal* zi; 1092 zip_internal* zi;
1093 int err = 0; 1093 int err = 0;
1094 uLong size_centraldir = 0; 1094 uLong size_centraldir = 0;
1095 uLong centraldir_pos_inzip ; 1095 uLong centraldir_pos_inzip ;
1096 uInt size_global_comment; 1096 uInt size_global_comment;
1097 if (file == NULL) 1097 if (file == NULL)
1098 return ZIP_PARAMERROR; 1098 return ZIP_PARAMERROR;
1099 zi = (zip_internal*)file; 1099 zi = (zip_internal*)file;
1100 1100
1101 if (zi->in_opened_file_inzip == 1) 1101 if (zi->in_opened_file_inzip == 1)
1102 { 1102 {
1103 err = zipCloseFileInZip (file); 1103 err = zipCloseFileInZip (file);
1104 } 1104 }
1105 1105
1106 if (global_comment==NULL) 1106 if (global_comment==NULL)
1107 size_global_comment = 0; 1107 size_global_comment = 0;
1108 else 1108 else
1109 size_global_comment = strlen(global_comment); 1109 size_global_comment = strlen(global_comment);
1110 1110
1111 1111
1112 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); 1112 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
1113 if (err==ZIP_OK) 1113 if (err==ZIP_OK)
1114 { 1114 {
1115 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; 1115 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
1116 while (ldi!=NULL) 1116 while (ldi!=NULL)
1117 { 1117 {
1118 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) 1118 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1119 if (ZWRITE(zi->z_filefunc,zi->filestream, 1119 if (ZWRITE(zi->z_filefunc,zi->filestream,
1120 ldi->data,ldi->filled_in_this_block) 1120 ldi->data,ldi->filled_in_this_block)
1121 !=ldi->filled_in_this_block ) 1121 !=ldi->filled_in_this_block )
1122 err = ZIP_ERRNO; 1122 err = ZIP_ERRNO;
1123 1123
1124 size_centraldir += ldi->filled_in_this_block; 1124 size_centraldir += ldi->filled_in_this_block;
1125 ldi = ldi->next_datablock; 1125 ldi = ldi->next_datablock;
1126 } 1126 }
1127 } 1127 }
1128 free_datablock(zi->central_dir.first_block); 1128 free_datablock(zi->central_dir.first_block);
1129 1129
1130 if (err==ZIP_OK) /* Magic End */ 1130 if (err==ZIP_OK) /* Magic End */
1131 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); 1131 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1132 1132
1133 if (err==ZIP_OK) /* number of this disk */ 1133 if (err==ZIP_OK) /* number of this disk */
1134 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1134 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1135 1135
1136 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1136 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1137 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1137 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1138 1138
1139 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ 1139 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1140 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 1140 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1141 1141
1142 if (err==ZIP_OK) /* total number of entries in the central dir */ 1142 if (err==ZIP_OK) /* total number of entries in the central dir */
1143 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); 1143 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1144 1144
1145 if (err==ZIP_OK) /* size of the central directory */ 1145 if (err==ZIP_OK) /* size of the central directory */
1146 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); 1146 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1147 1147
1148 if (err==ZIP_OK) /* offset of start of central directory with respect to the 1148 if (err==ZIP_OK) /* offset of start of central directory with respect to the
1149 starting disk number */ 1149 starting disk number */
1150 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, 1150 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
1151 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); 1151 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1152 1152
1153 if (err==ZIP_OK) /* zipfile comment length */ 1153 if (err==ZIP_OK) /* zipfile comment length */
1154 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); 1154 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1155 1155
1156 if ((err==ZIP_OK) && (size_global_comment>0)) 1156 if ((err==ZIP_OK) && (size_global_comment>0))
1157 if (ZWRITE(zi->z_filefunc,zi->filestream, 1157 if (ZWRITE(zi->z_filefunc,zi->filestream,
1158 global_comment,size_global_comment) != size_global_comment) 1158 global_comment,size_global_comment) != size_global_comment)
1159 err = ZIP_ERRNO; 1159 err = ZIP_ERRNO;
1160 1160
1161 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) 1161 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
1162 if (err == ZIP_OK) 1162 if (err == ZIP_OK)
1163 err = ZIP_ERRNO; 1163 err = ZIP_ERRNO;
1164 1164
1165 TRYFREE(zi); 1165 TRYFREE(zi);
1166 1166
1167 return err; 1167 return err;
1168} 1168}
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h
index 4bc6aa4..d863e1a 100644
--- a/contrib/minizip/zip.h
+++ b/contrib/minizip/zip.h
@@ -1,235 +1,235 @@
1/* zip.h -- IO for compress .zip files using zlib 1/* zip.h -- IO for compress .zip files using zlib
2 Version 0.21, March 10th, 2003 2 Version 0.22, May 19th, 2003
3 3
4 Copyright (C) 1998-2003 Gilles Vollant 4 Copyright (C) 1998-2003 Gilles Vollant
5 5
6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g 6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible. 7 WinZip, InfoZip tools and compatible.
8 Encryption and multi volume ZipFile (span) are not supported. 8 Encryption and multi volume ZipFile (span) are not supported.
9 Old compressions used by old PKZip 1.x are not supported 9 Old compressions used by old PKZip 1.x are not supported
10 10
11 For uncompress .zip file, look at unzip.h 11 For uncompress .zip file, look at unzip.h
12 12
13 13
14 I WAIT FEEDBACK at mail info@winimage.com 14 I WAIT FEEDBACK at mail info@winimage.com
15 Visit also http://www.winimage.com/zLibDll/unzip.html for evolution 15 Visit also http://www.winimage.com/zLibDll/unzip.html 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
21 arising from the use of this software. 21 arising from the use of this software.
22 22
23 Permission is granted to anyone to use this software for any purpose, 23 Permission is granted to anyone to use this software for any purpose,
24 including commercial applications, and to alter it and redistribute it 24 including commercial applications, and to alter it and redistribute it
25 freely, subject to the following restrictions: 25 freely, subject to the following restrictions:
26 26
27 1. The origin of this software must not be misrepresented; you must not 27 1. The origin of this software must not be misrepresented; you must not
28 claim that you wrote the original software. If you use this software 28 claim that you wrote the original software. If you use this software
29 in a product, an acknowledgment in the product documentation would be 29 in a product, an acknowledgment in the product documentation would be
30 appreciated but is not required. 30 appreciated but is not required.
31 2. Altered source versions must be plainly marked as such, and must not be 31 2. Altered source versions must be plainly marked as such, and must not be
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 37
38/* for more info about .ZIP format, see 38/* for more info about .ZIP format, see
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip 39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40 http://www.info-zip.org/pub/infozip/doc/ 40 http://www.info-zip.org/pub/infozip/doc/
41 PkWare has also a specification at : 41 PkWare has also a specification at :
42 ftp://ftp.pkware.com/probdesc.zip 42 ftp://ftp.pkware.com/probdesc.zip
43*/ 43*/
44 44
45#ifndef _zip_H 45#ifndef _zip_H
46#define _zip_H 46#define _zip_H
47 47
48#ifdef __cplusplus 48#ifdef __cplusplus
49extern "C" { 49extern "C" {
50#endif 50#endif
51 51
52#ifndef _ZLIB_H 52#ifndef _ZLIB_H
53#include "zlib.h" 53#include "zlib.h"
54#endif 54#endif
55 55
56#ifndef _ZLIBIOAPI_H 56#ifndef _ZLIBIOAPI_H
57#include "ioapi.h" 57#include "ioapi.h"
58#endif 58#endif
59 59
60#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 60#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
61/* like the STRICT of WIN32, we define a pointer that cannot be converted 61/* like the STRICT of WIN32, we define a pointer that cannot be converted
62 from (void*) without cast */ 62 from (void*) without cast */
63typedef struct TagzipFile__ { int unused; } zipFile__; 63typedef struct TagzipFile__ { int unused; } zipFile__;
64typedef zipFile__ *zipFile; 64typedef zipFile__ *zipFile;
65#else 65#else
66typedef voidp zipFile; 66typedef voidp zipFile;
67#endif 67#endif
68 68
69#define ZIP_OK (0) 69#define ZIP_OK (0)
70#define ZIP_EOF (0) 70#define ZIP_EOF (0)
71#define ZIP_ERRNO (Z_ERRNO) 71#define ZIP_ERRNO (Z_ERRNO)
72#define ZIP_PARAMERROR (-102) 72#define ZIP_PARAMERROR (-102)
73#define ZIP_BADZIPFILE (-103) 73#define ZIP_BADZIPFILE (-103)
74#define ZIP_INTERNALERROR (-104) 74#define ZIP_INTERNALERROR (-104)
75 75
76#ifndef DEF_MEM_LEVEL 76#ifndef DEF_MEM_LEVEL
77# if MAX_MEM_LEVEL >= 8 77# if MAX_MEM_LEVEL >= 8
78# define DEF_MEM_LEVEL 8 78# define DEF_MEM_LEVEL 8
79# else 79# else
80# define DEF_MEM_LEVEL MAX_MEM_LEVEL 80# define DEF_MEM_LEVEL MAX_MEM_LEVEL
81# endif 81# endif
82#endif 82#endif
83/* default memLevel */ 83/* default memLevel */
84 84
85/* tm_zip contain date/time info */ 85/* tm_zip contain date/time info */
86typedef struct tm_zip_s 86typedef struct tm_zip_s
87{ 87{
88 uInt tm_sec; /* seconds after the minute - [0,59] */ 88 uInt tm_sec; /* seconds after the minute - [0,59] */
89 uInt tm_min; /* minutes after the hour - [0,59] */ 89 uInt tm_min; /* minutes after the hour - [0,59] */
90 uInt tm_hour; /* hours since midnight - [0,23] */ 90 uInt tm_hour; /* hours since midnight - [0,23] */
91 uInt tm_mday; /* day of the month - [1,31] */ 91 uInt tm_mday; /* day of the month - [1,31] */
92 uInt tm_mon; /* months since January - [0,11] */ 92 uInt tm_mon; /* months since January - [0,11] */
93 uInt tm_year; /* years - [1980..2044] */ 93 uInt tm_year; /* years - [1980..2044] */
94} tm_zip; 94} tm_zip;
95 95
96typedef struct 96typedef struct
97{ 97{
98 tm_zip tmz_date; /* date in understandable format */ 98 tm_zip tmz_date; /* date in understandable format */
99 uLong dosDate; /* if dos_date == 0, tmu_date is used */ 99 uLong dosDate; /* if dos_date == 0, tmu_date is used */
100/* uLong flag; */ /* general purpose bit flag 2 bytes */ 100/* uLong flag; */ /* general purpose bit flag 2 bytes */
101 101
102 uLong internal_fa; /* internal file attributes 2 bytes */ 102 uLong internal_fa; /* internal file attributes 2 bytes */
103 uLong external_fa; /* external file attributes 4 bytes */ 103 uLong external_fa; /* external file attributes 4 bytes */
104} zip_fileinfo; 104} zip_fileinfo;
105 105
106typedef const char* zipcharpc; 106typedef const char* zipcharpc;
107 107
108 108
109#define APPEND_STATUS_CREATE (0) 109#define APPEND_STATUS_CREATE (0)
110#define APPEND_STATUS_CREATEAFTER (1) 110#define APPEND_STATUS_CREATEAFTER (1)
111#define APPEND_STATUS_ADDINZIP (2) 111#define APPEND_STATUS_ADDINZIP (2)
112 112
113extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 113extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
114/* 114/*
115 Create a zipfile. 115 Create a zipfile.
116 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 116 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
117 an Unix computer "zlib/zlib113.zip". 117 an Unix computer "zlib/zlib113.zip".
118 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip 118 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
119 will be created at the end of the file. 119 will be created at the end of the file.
120 (useful if the file contain a self extractor code) 120 (useful if the file contain a self extractor code)
121 if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will 121 if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
122 add files in existing zip (be sure you don't add file that doesn't exist) 122 add files in existing zip (be sure you don't add file that doesn't exist)
123 If the zipfile cannot be opened, the return value is NULL. 123 If the zipfile cannot be opened, the return value is NULL.
124 Else, the return value is a zipFile Handle, usable with other function 124 Else, the return value is a zipFile Handle, usable with other function
125 of this zip package. 125 of this zip package.
126*/ 126*/
127 127
128/* Note : there is no delete function into a zipfile. 128/* Note : there is no delete function into a zipfile.
129 If you want delete file into a zipfile, you must open a zipfile, and create another 129 If you want delete file into a zipfile, you must open a zipfile, and create another
130 Of couse, you can use RAW reading and writing to copy the file you did not want delte 130 Of couse, you can use RAW reading and writing to copy the file you did not want delte
131*/ 131*/
132 132
133extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, 133extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
134 int append, 134 int append,
135 zipcharpc* globalcomment, 135 zipcharpc* globalcomment,
136 zlib_filefunc_def* pzlib_filefunc_def)); 136 zlib_filefunc_def* pzlib_filefunc_def));
137 137
138extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 138extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
139 const char* filename, 139 const char* filename,
140 const zip_fileinfo* zipfi, 140 const zip_fileinfo* zipfi,
141 const void* extrafield_local, 141 const void* extrafield_local,
142 uInt size_extrafield_local, 142 uInt size_extrafield_local,
143 const void* extrafield_global, 143 const void* extrafield_global,
144 uInt size_extrafield_global, 144 uInt size_extrafield_global,
145 const char* comment, 145 const char* comment,
146 int method, 146 int method,
147 int level)); 147 int level));
148/* 148/*
149 Open a file in the ZIP for writing. 149 Open a file in the ZIP for writing.
150 filename : the filename in zip (if NULL, '-' without quote will be used 150 filename : the filename in zip (if NULL, '-' without quote will be used
151 *zipfi contain supplemental information 151 *zipfi contain supplemental information
152 if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local 152 if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
153 contains the extrafield data the the local header 153 contains the extrafield data the the local header
154 if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global 154 if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
155 contains the extrafield data the the local header 155 contains the extrafield data the the local header
156 if comment != NULL, comment contain the comment string 156 if comment != NULL, comment contain the comment string
157 method contain the compression method (0 for store, Z_DEFLATED for deflate) 157 method contain the compression method (0 for store, Z_DEFLATED for deflate)
158 level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 158 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
159*/ 159*/
160 160
161 161
162extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, 162extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
163 const char* filename, 163 const char* filename,
164 const zip_fileinfo* zipfi, 164 const zip_fileinfo* zipfi,
165 const void* extrafield_local, 165 const void* extrafield_local,
166 uInt size_extrafield_local, 166 uInt size_extrafield_local,
167 const void* extrafield_global, 167 const void* extrafield_global,
168 uInt size_extrafield_global, 168 uInt size_extrafield_global,
169 const char* comment, 169 const char* comment,
170 int method, 170 int method,
171 int level, 171 int level,
172 int raw)); 172 int raw));
173 173
174/* 174/*
175 Same than zipOpenNewFileInZip, except if raw=1, we write raw file 175 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
176 */ 176 */
177 177
178extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, 178extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
179 const char* filename, 179 const char* filename,
180 const zip_fileinfo* zipfi, 180 const zip_fileinfo* zipfi,
181 const void* extrafield_local, 181 const void* extrafield_local,
182 uInt size_extrafield_local, 182 uInt size_extrafield_local,
183 const void* extrafield_global, 183 const void* extrafield_global,
184 uInt size_extrafield_global, 184 uInt size_extrafield_global,
185 const char* comment, 185 const char* comment,
186 int method, 186 int method,
187 int level, 187 int level,
188 int raw, 188 int raw,
189 int windowBits, 189 int windowBits,
190 int memLevel, 190 int memLevel,
191 int strategy, 191 int strategy,
192 const char* password, 192 const char* password,
193 uLong crcForCtypting)); 193 uLong crcForCtypting));
194 194
195/* 195/*
196 Same than zipOpenNewFileInZip2, except 196 Same than zipOpenNewFileInZip2, except
197 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 197 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
198 password : crypting password (NULL for no crypting) 198 password : crypting password (NULL for no crypting)
199 crcForCtypting : crc of file to compress (needed for crypting) 199 crcForCtypting : crc of file to compress (needed for crypting)
200 */ 200 */
201 201
202 202
203extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, 203extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
204 const void* buf, 204 const void* buf,
205 unsigned len)); 205 unsigned len));
206/* 206/*
207 Write data in the zipfile 207 Write data in the zipfile
208*/ 208*/
209 209
210extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 210extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
211/* 211/*
212 Close the current file in the zipfile 212 Close the current file in the zipfile
213*/ 213*/
214 214
215 215
216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
217 uLong uncompressed_size, 217 uLong uncompressed_size,
218 uLong crc32)); 218 uLong crc32));
219/* 219/*
220 Close the current file in the zipfile, for fiel opened with 220 Close the current file in the zipfile, for fiel opened with
221 parameter raw=1 in zipOpenNewFileInZip2 221 parameter raw=1 in zipOpenNewFileInZip2
222 uncompressed_size and crc32 are value for the uncompressed size 222 uncompressed_size and crc32 are value for the uncompressed size
223*/ 223*/
224 224
225extern int ZEXPORT zipClose OF((zipFile file, 225extern int ZEXPORT zipClose OF((zipFile file,
226 const char* global_comment)); 226 const char* global_comment));
227/* 227/*
228 Close the zipfile 228 Close the zipfile
229*/ 229*/
230 230
231#ifdef __cplusplus 231#ifdef __cplusplus
232} 232}
233#endif 233#endif
234 234
235#endif /* _zip_H */ 235#endif /* _zip_H */
diff --git a/contrib/vstudio/readme.txt b/contrib/vstudio/readme.txt
index a619b96..c22ec34 100644
--- a/contrib/vstudio/readme.txt
+++ b/contrib/vstudio/readme.txt
@@ -14,4 +14,9 @@ open zlibvc.sln with Microsoft Visual C++ 7.0 (Visual Studio .net)
14 14
15 15
16Note : You don't need recompile yourself. There is compiled .LIB in 16Note : You don't need recompile yourself. There is compiled .LIB in
17 http://www.winimage.com/zLibDll 17 http://www.winimage.com/zLibDll . See this page for more information
18
19
20
21Gilles Vollant
22info@winimage.com
diff --git a/contrib/vstudio/vc15_16/zlib16.def b/contrib/vstudio/vc15_16/zlib16.def
index 89cb8d1..fdae3d4 100644
--- a/contrib/vstudio/vc15_16/zlib16.def
+++ b/contrib/vstudio/vc15_16/zlib16.def
@@ -4,7 +4,7 @@ DESCRIPTION '"""zlib data compression library"""'
4 4
5EXETYPE WINDOWS 5EXETYPE WINDOWS
6 6
7VERSION 1.20 7VERSION 1.21
8 8
9CODE PRELOAD MOVEABLE DISCARDABLE 9CODE PRELOAD MOVEABLE DISCARDABLE
10DATA PRELOAD MOVEABLE SINGLE 10DATA PRELOAD MOVEABLE SINGLE
diff --git a/contrib/vstudio/vc15_16/zlib16.rc b/contrib/vstudio/vc15_16/zlib16.rc
index 13d0d66..514585c 100644
--- a/contrib/vstudio/vc15_16/zlib16.rc
+++ b/contrib/vstudio/vc15_16/zlib16.rc
@@ -3,8 +3,8 @@
3 3
4#define IDR_VERSION1 1 4#define IDR_VERSION1 1
5IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 5IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
6 FILEVERSION 1,2,0,0 6 FILEVERSION 1,2,1,0
7 PRODUCTVERSION 1,2,0,0 7 PRODUCTVERSION 1,2,1,0
8 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
9 FILEFLAGS 0 9 FILEFLAGS 0
10 FILEOS VOS_DOS_WINDOWS16 10 FILEOS VOS_DOS_WINDOWS16
@@ -18,7 +18,7 @@ BEGIN
18 18
19 BEGIN 19 BEGIN
20 VALUE "FileDescription", "zlib data compression library\0" 20 VALUE "FileDescription", "zlib data compression library\0"
21 VALUE "FileVersion", "1.2.0\0" 21 VALUE "FileVersion", "1.2.1\0"
22 VALUE "InternalName", "zlib16\0" 22 VALUE "InternalName", "zlib16\0"
23 VALUE "OriginalFilename", "zlib16.dll\0" 23 VALUE "OriginalFilename", "zlib16.dll\0"
24 VALUE "ProductName", "ZLib16.DLL\0" 24 VALUE "ProductName", "ZLib16.DLL\0"
diff --git a/contrib/vstudio/vc70_32/zlib.rc b/contrib/vstudio/vc70_32/zlib.rc
index 5d86e03..6c51679 100644
--- a/contrib/vstudio/vc70_32/zlib.rc
+++ b/contrib/vstudio/vc70_32/zlib.rc
@@ -2,8 +2,8 @@
2 2
3#define IDR_VERSION1 1 3#define IDR_VERSION1 1
4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE 4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1,2,0,0 5 FILEVERSION 1,2,1,0
6 PRODUCTVERSION 1,2,0,0 6 PRODUCTVERSION 1,2,1,0
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.0.0\0" 20 VALUE "FileVersion", "1.2.1.0\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/vc70_32/zlibvc.def b/contrib/vstudio/vc70_32/zlibvc.def
index 90109d6..c2804a8 100644
--- a/contrib/vstudio/vc70_32/zlibvc.def
+++ b/contrib/vstudio/vc70_32/zlibvc.def
@@ -1,6 +1,6 @@
1LIBRARY "zlib" 1LIBRARY "zlib"
2 2
3VERSION 1.20 3VERSION 1.21
4 4
5HEAPSIZE 1048576,8192 5HEAPSIZE 1048576,8192
6 6
diff --git a/contrib/zlib_dll_FAQ.txt b/contrib/zlib_dll_FAQ.txt
new file mode 100644
index 0000000..bc1fd59
--- /dev/null
+++ b/contrib/zlib_dll_FAQ.txt
@@ -0,0 +1,257 @@
1
2 Frequently Asked Questions about ZLIB.DLL
3
4
5This FAQ is about the design, the rationale, and the use of
6ZLIB.DLL. If you have general questions about zlib, you should
7check the file "FAQ" found in the zlib distribution, or at the
8location http://www.gzip.org/zlib/zlib_faq.html
9
10
11 1. Why am I having problems using ZLIB.DLL? My application works
12 with the static build of zlib just fine, and I didn't make any
13 modification when recompiling it for ZLIB.DLL.
14
15 - Make sure you define ZLIB_DLL before including "zlib.h".
16 Applications that link to ZLIB.DLL will work properly if
17 the source files are compiled in this (or in a compatible)
18 way, and the executables are linked to MSVCRT.DLL.
19
20
21 2. Why do I have to do this? When I use other libraries, I can
22 link my code to their static or dynamic versions, without
23 needing any source code modification or recompilation.
24
25 - In order to preserve the backwards compatibility with the
26 older versions of ZLIB.DLL, and give the ability to use zlib
27 to the non-C programmers at the same time, we had to do this
28 compromise.
29
30
31 3. What exactly is this mess about, and why is it happening?
32
33 - It's about the calling convention used for the zlib functions.
34 If linked in statically, zlib uses the C (CDECL) convention.
35 If linked in dynamically (via ZLIB.DLL), it uses the STDCALL
36 convention. The ZLIB_DLL macro switches on the use of STDCALL.
37
38 It happens because we need to preserve compatibility with the
39 old releases of ZLIB.DLL that use STDCALL, and, at the same
40 time, we must provide support for programmers who use other
41 programming languages with bindings that require CDECL.
42
43
44 4. Why not use the STDCALL convention all the time?
45 It's the standard convention in Win32, and I need it in my
46 Visual Basic project!
47
48 - Most of the Win32 API functions (without varargs) use indeed
49 the STDCALL (WINAPI) convention, but the standard C functions
50 use the default CDECL. If one calls Win32 functions such as
51 CreateFile(), sometimes it makes sense to decorate one's own
52 functions with STDCALL. But if one is aiming at ANSI C or
53 POSIX portability, and calls functions such as fopen(), it is
54 not a sound decision to include <windows.h> or to use non-ANSI
55 constructs only to make one's functions STDCALL-able. This is
56 not the biggest problem, however.
57
58 Technically, STDCALL is not bad; it is even a little faster
59 than CDECL. The problem of using STDCALL is actually a problem
60 of using any explicit calling convention. FASTCALL falls into
61 the same category.
62
63 Explicit specification of calling conventions, whether it's
64 direct or indirect via a macro, happens commonly in Windows,
65 but it is regarded as a noisy, non-standard C quirk on other
66 platforms. It isn't possible to write an ANSI C -conforming
67 program, for example, if it is necessary to specify calling
68 conventions. Libraries can hide the dirty stuff in header
69 files, under macros, but callbacks will still remain exposed.
70 This is why the zlib callbacks will not be decorated.
71 (The old Windows callbacks, such as WndProc, are decorated,
72 but the newer ones are not.)
73
74 There is one more problem with explicit, non-default calling
75 conventions: the ability to use zlib in other programming
76 languages. Some of them, like Ada (GNAT) and Fortran (GNU G77)
77 have C bindings implemented initially on Unix, hence relying
78 on the C calling convention.
79
80 So we are decorating the functions using STDCALL in ZLIB.DLL
81 to maintain compatibility with the old versions, but we are
82 using the default CDECL in the static library, to allow other
83 programming languages to use zlib in a portable fashion, via
84 C bindings.
85
86
87 5. Why not use the default (CDECL) convention all the time?
88 It's the standard convention in C, and I need it in my Ada
89 project!
90
91 - Originally, ZLIB.DLL was intended to run under Visual Basic,
92 and VB6 and earlier need STDCALL.
93
94 We admit that cluttering the main zlib sources, for the sake
95 of interfacing with Visual Basic and at the expense of other
96 programming languages, is not fair. It would have been better
97 to maintain a "VB-only" project in the contrib/ directory, and
98 to build a custom ZLIBVB.DLL, for example -- as we did with
99 the Delphi projects. Another possible solution would have been
100 to build STDCALL wrappers around the CDECL-exported functions.
101
102 But this was the accident that we have to live with, in order
103 to maintain binary compatibility with the older versions of
104 ZLIB.DLL.
105
106
107 6. If my application uses ZLIB.DLL, do I have to link it to
108 MSVCRT.DLL? Why?
109
110 - The executables (.EXE, .DLL, etc.) that are involved in the
111 same process and are using the C run-time library (i.e. they
112 are calling any standard C function), must link to the same
113 library. There are several libraries in the Win32 system:
114 CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
115 Since ZLIB.DLL is linked to MSVCRT.DLL, the executables that
116 depend on it must also link to MSVCRT.DLL.
117
118
119 7. Why are you saying that ZLIB.DLL and my application must be
120 linked to the same C run-time library (CRT)? I linked my
121 application and my DLLs to different C libraries (e.g. my
122 application to a static library, and my DLLs to MSVCRT.DLL),
123 and everything works fine.
124
125 - If a library invokes only pure Win32 API (i.e. accessible
126 via <windows.h>), its DLL build will work in any context.
127 But if a library invokes standard C functions, things get
128 more complicated.
129
130 There is a single Win32 library in a Win32 system. Every
131 function in this library resides in a single DLL module, that
132 is safe to call from anywhere. On the other hand, there are
133 multiple versions of the C library that are all at the same
134 time in the system, and all of them have internal states,
135 therefore it is dangerous to intermix them with each other.
136
137 Intermixing multiple C libraries is possible, as long as their
138 internal states are kept intact. The Microsoft Knowledge Base
139 article Q140584 "HOWTO: Link with the Correct C Run-Time (CRT)
140 Library" enumerates some of the potential problems raised by
141 intermixing, but does not offer a complete description of how
142 to avoid them, except by advising not to mix the C libraries.
143 If you can send us more information about this issue, we will
144 highly appreciate it. (But please do NOT send us source code
145 from Microsoft, even if it comes with your legitimate copy of
146 Visual C++!)
147
148 If this kind of intermixing works for you, it's because your
149 application and DLLs are avoiding the corruption of the CRT's
150 internal states, due to a fortunate accident. It's not because
151 those libraries really work together.
152
153 Also note that linking ZLIB.DLL to non-Microsoft C libraries
154 (such as Borland's) raises similar problems.
155
156
157 8. Why are you linking ZLIB.DLL to MSVCRT.DLL?
158
159 - MSVCRT.DLL exists on every Windows 95 with a new service pack
160 installed, or with Microsoft Internet Explorer 4 or later, and
161 on all other Windows 4.x or later (Windows 98, Windows NT 4,
162 or later). It is freely distributable; if not present in the
163 system, it can be downloaded from Microsoft or from other
164 software provider for free.
165
166 The fact that MSVCRT.DLL does not exist on a virgin Windows 95
167 is not so problematic. The number of Windows 95 installations
168 is rapidly decreasing, Microsoft stopped supporting it a long
169 time ago, and many recent applications from various vendors
170 including Microsoft, do not even run on it. Even without these
171 arguments, no serious user should run Windows 95 without a
172 proper update installed.
173
174 There is also the fact that the mainstream C compilers for
175 Windows are Microsoft Visual C++ 6.0, and gcc/MinGW. Both
176 are producing executables that link to MSVCRT.DLL by default,
177 without offering other dynamic CRTs as alternatives easy to
178 select by users.
179
180
181 9. Why are you not linking ZLIB.DLL to
182 <<my favorite C run-time library>> ?
183
184 - We considered and abandoned the following alternatives:
185
186 * Linking ZLIB.DLL to a static C library (LIBC.LIB, or
187 LIBCMT.LIB) is not a good option. People are using ZLIB.DLL
188 mainly to save disk space. If you are linking your program
189 to a static C library, you may as well consider linking zlib
190 in statically, too.
191
192 * Linking ZLIB.DLL to CRTDLL.DLL looks very appealing,
193 because CRTDLL.DLL is present on every Win32 installation.
194 Unfortunately, it has a series of problems: it raises
195 difficulties when linking to the Microsoft C++ libraries,
196 it is not thread-safe, and Microsoft has discontinued its
197 support a long time ago.
198
199 * Linking ZLIB.DLL to MSVCRT70.DLL, supplied with the
200 Microsoft .NET platform and Visual C++ 7.0, is not a good
201 option. Although it can be downloaded and distributed
202 freely, it is hardly present on today's Win32 installations.
203 If it will become more popular than MSVCRT.DLL, and will be
204 pre-installed on the future Win32 systems, we will probably
205 think again about it.
206
207 * Linking ZLIB.DLL to NTDLL.DLL is not possible.
208 NTDLL.DLL exports only a part of the C library, and only
209 on Windows NT systems.
210
211
21210. I understand your reasons. However, my project needs ZLIB.DLL
213 linked to something different than MSVCRT.DLL. What can I do?
214
215 Feel free to rebuild this DLL from the zlib sources, and link
216 it the way you want. It is required, however, to clearly
217 state that your build is unofficial. Another thing that is not
218 required, but highly recommended, is to name that custom DLL
219 differently, and/or to install it in a private directory that
220 can be accessed by your application, but is not visible to the
221 others (e.g. it's not the SYSTEM or the SYSTEM32 directory,
222 and it's not in the PATH). Otherwise, your build may clash
223 with applications that link to the official build.
224
225 For example, in Cygwin, zlib is linked to their runtime
226 CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
227
228
22911. My I include additional pieces of code that I find useful,
230 link them in ZLIB.DLL, and export them?
231
232 No. A legitimate build of ZLIB.DLL must not include code that
233 does not originate from the official zlib sources. But you can
234 make your own private build, and give it a different name, as
235 suggested in the previous answer.
236
237 For example, in Borland Delphi and C++ Builder, zlib is part
238 of the standard VCL library. If an application links to VCL
239 dynamically, the name of the distributable binary (VCLxx.DLL)
240 does not posess any danger of clashing with a legitimate but
241 incompatible ZLIB.DLL.
242
243
24412. I see that I may have all kinds of problems if I use ZLIB.DLL.
245 Do you recommend to link zlib in statically? Do I get rid of
246 problems?
247
248 - Yes, definitely. In fact, unless you are distributing a large
249 number of executables, each of them linking to zlib, you will
250 save space by linking zlib in statically (assuming that you
251 would otherwise distribute ZLIB.DLL with your application).
252 zlib is not a big library, and the space saved by ZLIB.DLL is
253 little. Much of the actual size of the DLL is due to the 4KB
254 alignment in the binary.
255
256 But you may have reasons, other than size, to use the DLL.
257 That is entirely up to you.
diff --git a/crc32.c b/crc32.c
index d0a9f5e..f163fe1 100644
--- a/crc32.c
+++ b/crc32.c
@@ -18,25 +18,29 @@
18# endif /* !DYNAMIC_CRC_TABLE */ 18# endif /* !DYNAMIC_CRC_TABLE */
19#endif /* MAKECRCH */ 19#endif /* MAKECRCH */
20 20
21#include "zlib.h" 21#include "zutil.h"
22 22
23#define local static 23#define local static
24 24
25/* Find a four-byte integer type for crc32_little() and crc32_big(). */ 25/* Find a four-byte integer type for crc32_little() and crc32_big(). */
26#ifndef NOBYFOUR 26#ifndef NOBYFOUR
27# ifdef __STDC__ /* need ANSI C limits.h to determine sizes */ 27# ifdef STDC /* need ANSI C limits.h to determine sizes */
28# include <limits.h> 28# include <limits.h>
29# define BYFOUR 29# define BYFOUR
30# if (UINT_MAX == 4294967295) 30# if (UINT_MAX == 0xffffffffUL)
31 typedef unsigned int u4; 31 typedef unsigned int u4;
32# elif (ULONG_MAX == 4294967295)
33 typedef unsigned long u4;
34# elif (USHRT_MAX == 4294967295)
35 typedef unsigned short u4;
36# else 32# else
37# undef BYFOUR /* can't find a four-byte integer type! */ 33# if (ULONG_MAX == 0xffffffffUL)
34 typedef unsigned long u4;
35# else
36# if (USHRT_MAX == 0xffffffffUL)
37 typedef unsigned short u4;
38# else
39# undef BYFOUR /* can't find a four-byte integer type! */
40# endif
41# endif
38# endif 42# endif
39# endif /* __STDC__ */ 43# endif /* STDC */
40#endif /* !NOBYFOUR */ 44#endif /* !NOBYFOUR */
41 45
42/* Definitions for doing the crc four data bytes at a time. */ 46/* Definitions for doing the crc four data bytes at a time. */
@@ -95,7 +99,7 @@ local void make_crc_table()
95 /* terms of polynomial defining this crc (except x^32): */ 99 /* terms of polynomial defining this crc (except x^32): */
96 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 100 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
97 101
98 /* make exclusive-or pattern from polynomial (0xedb88320L) */ 102 /* make exclusive-or pattern from polynomial (0xedb88320UL) */
99 poly = 0UL; 103 poly = 0UL;
100 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) 104 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
101 poly |= 1UL << (31 - p[n]); 105 poly |= 1UL << (31 - p[n]);
@@ -240,7 +244,7 @@ local unsigned long crc32_little(crc, buf, len)
240 244
241 c = (u4)crc; 245 c = (u4)crc;
242 c = ~c; 246 c = ~c;
243 while (len && ((int)buf & 3)) { 247 while (len && ((size_t)buf & 3)) {
244 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 248 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
245 len--; 249 len--;
246 } 250 }
@@ -280,7 +284,7 @@ local unsigned long crc32_big(crc, buf, len)
280 284
281 c = REV((u4)crc); 285 c = REV((u4)crc);
282 c = ~c; 286 c = ~c;
283 while (len && ((int)buf & 3)) { 287 while (len && ((size_t)buf & 3)) {
284 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 288 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
285 len--; 289 len--;
286 } 290 }
diff --git a/deflate.c b/deflate.c
index 97a080c..bb160d8 100644
--- a/deflate.c
+++ b/deflate.c
@@ -37,7 +37,7 @@
37 * REFERENCES 37 * REFERENCES
38 * 38 *
39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". 39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
40 * Available in ftp://ds.internic.net/rfc/rfc1951.txt 40 * Available in http://www.ietf.org/rfc/rfc1951.txt
41 * 41 *
42 * A description of the Rabin and Karp algorithm is given in the book 42 * A description of the Rabin and Karp algorithm is given in the book
43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@@ -52,7 +52,7 @@
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.2.0.1 Copyright 1995-2003 Jean-loup Gailly "; 55 " deflate 1.2.0.2 Copyright 1995-2003 Jean-loup Gailly ";
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
@@ -157,7 +157,9 @@ local const config configuration_table[10] = {
157#define EQUAL 0 157#define EQUAL 0
158/* result of memcmp for equal strings */ 158/* result of memcmp for equal strings */
159 159
160#ifndef NO_DUMMY_DECL
160struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ 161struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
162#endif
161 163
162/* =========================================================================== 164/* ===========================================================================
163 * Update a hash value with the given input byte 165 * Update a hash value with the given input byte
@@ -255,10 +257,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
255 windowBits = -windowBits; 257 windowBits = -windowBits;
256 } 258 }
257 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 259 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
258 windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || 260 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
259 strategy < 0 || strategy > Z_RLE) { 261 strategy < 0 || strategy > Z_RLE) {
260 return Z_STREAM_ERROR; 262 return Z_STREAM_ERROR;
261 } 263 }
264 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
262 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); 265 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
263 if (s == Z_NULL) return Z_MEM_ERROR; 266 if (s == Z_NULL) return Z_MEM_ERROR;
264 strm->state = (struct internal_state FAR *)s; 267 strm->state = (struct internal_state FAR *)s;
@@ -520,9 +523,16 @@ int ZEXPORT deflate (strm, flush)
520 if (s->status == INIT_STATE) { 523 if (s->status == INIT_STATE) {
521 524
522 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; 525 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
523 uInt level_flags = (s->level-1) >> 1; 526 uInt level_flags;
524 527
525 if (level_flags > 3) level_flags = 3; 528 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
529 level_flags = 0;
530 else if (s->level < 6)
531 level_flags = 1;
532 else if (s->level == 6)
533 level_flags = 2;
534 else
535 level_flags = 3;
526 header |= (level_flags << 6); 536 header |= (level_flags << 6);
527 if (s->strstart != 0) header |= PRESET_DICT; 537 if (s->strstart != 0) header |= PRESET_DICT;
528 header += 31 - (header % 31); 538 header += 31 - (header % 31);
@@ -975,7 +985,7 @@ local uInt longest_match_fast(s, cur_match)
975 if (len < MIN_MATCH) return MIN_MATCH - 1; 985 if (len < MIN_MATCH) return MIN_MATCH - 1;
976 986
977 s->match_start = cur_match; 987 s->match_start = cur_match;
978 return len <= s->lookahead ? len : s->lookahead; 988 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
979} 989}
980 990
981#ifdef DEBUG 991#ifdef DEBUG
@@ -1028,19 +1038,22 @@ local void fill_window(s)
1028 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); 1038 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1029 1039
1030 /* Deal with !@#$% 64K limit: */ 1040 /* Deal with !@#$% 64K limit: */
1031 if (more == 0 && s->strstart == 0 && s->lookahead == 0) { 1041 if (sizeof(int) <= 2) {
1032 more = wsize; 1042 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1033 1043 more = wsize;
1034 } else if (more == (unsigned)(-1)) { 1044
1035 /* Very unlikely, but possible on 16 bit machine if strstart == 0 1045 } else if (more == (unsigned)(-1)) {
1036 * and lookahead == 1 (input done one byte at time) 1046 /* Very unlikely, but possible on 16 bit machine if
1037 */ 1047 * strstart == 0 && lookahead == 1 (input done one byte at time)
1038 more--; 1048 */
1049 more--;
1050 }
1051 }
1039 1052
1040 /* If the window is almost full and there is insufficient lookahead, 1053 /* If the window is almost full and there is insufficient lookahead,
1041 * move the upper half to the lower one to make room in the upper half. 1054 * move the upper half to the lower one to make room in the upper half.
1042 */ 1055 */
1043 } else if (s->strstart >= wsize+MAX_DIST(s)) { 1056 if (s->strstart >= wsize+MAX_DIST(s)) {
1044 1057
1045 zmemcpy(s->window, s->window+wsize, (unsigned)wsize); 1058 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1046 s->match_start -= wsize; 1059 s->match_start -= wsize;
@@ -1347,9 +1360,12 @@ local block_state deflate_slow(s, flush)
1347 } 1360 }
1348 /* longest_match() or longest_match_fast() sets match_start */ 1361 /* longest_match() or longest_match_fast() sets match_start */
1349 1362
1350 if (s->match_length <= 5 && (s->strategy == Z_FILTERED || 1363 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
1351 (s->match_length == MIN_MATCH && 1364#if TOO_FAR < 32768
1352 s->strstart - s->match_start > TOO_FAR))) { 1365 || (s->match_length == MIN_MATCH &&
1366 s->strstart - s->match_start > TOO_FAR)
1367#endif
1368 )) {
1353 1369
1354 /* If prev_match is also MIN_MATCH, match_start is garbage 1370 /* If prev_match is also MIN_MATCH, match_start is garbage
1355 * but we will ignore the current match anyway. 1371 * but we will ignore the current match anyway.
diff --git a/deflate.h b/deflate.h
index c3f8858..0e8417d 100644
--- a/deflate.h
+++ b/deflate.h
@@ -10,8 +10,8 @@
10 10
11/* @(#) $Id$ */ 11/* @(#) $Id$ */
12 12
13#ifndef _DEFLATE_H 13#ifndef DEFLATE_H
14#define _DEFLATE_H 14#define DEFLATE_H
15 15
16#include "zutil.h" 16#include "zutil.h"
17 17
@@ -315,4 +315,4 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
315 flush = _tr_tally(s, distance, length) 315 flush = _tr_tally(s, distance, length)
316#endif 316#endif
317 317
318#endif 318#endif /* DEFLATE_H */
diff --git a/example.c b/example.c
index 9fd13ce..3c53a93 100644
--- a/example.c
+++ b/example.c
@@ -142,13 +142,18 @@ void test_gzio(out, in, uncompr, uncomprLen)
142 exit(1); 142 exit(1);
143 } 143 }
144 144
145 if (gzungetc(' ', file) != ' ') {
146 fprintf(stderr, "gzungetc error\n");
147 exit(1);
148 }
149
145 gzgets(file, (char*)uncompr, uncomprLen); 150 gzgets(file, (char*)uncompr, uncomprLen);
146 uncomprLen = strlen((char*)uncompr); 151 uncomprLen = strlen((char*)uncompr);
147 if (uncomprLen != 6) { /* "hello!" */ 152 if (uncomprLen != 7) { /* " hello!" */
148 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); 153 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
149 exit(1); 154 exit(1);
150 } 155 }
151 if (strcmp((char*)uncompr, hello+7)) { 156 if (strcmp((char*)uncompr, hello+6)) {
152 fprintf(stderr, "bad gzgets after gzseek\n"); 157 fprintf(stderr, "bad gzgets after gzseek\n");
153 exit(1); 158 exit(1);
154 } else { 159 } else {
@@ -523,6 +528,9 @@ int main(argc, argv)
523 fprintf(stderr, "warning: different zlib version\n"); 528 fprintf(stderr, "warning: different zlib version\n");
524 } 529 }
525 530
531 printf("zlib version %s = 0x%04x, compile flags = 0x%x\n",
532 ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
533
526 compr = (Byte*)calloc((uInt)comprLen, 1); 534 compr = (Byte*)calloc((uInt)comprLen, 1);
527 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); 535 uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
528 /* compr and uncompr are cleared to avoid reading uninitialized 536 /* compr and uncompr are cleared to avoid reading uninitialized
diff --git a/gzio.c b/gzio.c
index 1f561ac..14fc33c 100644
--- a/gzio.c
+++ b/gzio.c
@@ -11,7 +11,9 @@
11 11
12#include "zutil.h" 12#include "zutil.h"
13 13
14#ifndef NO_DUMMY_DECL
14struct internal_state {int dummy;}; /* for buggy compilers */ 15struct internal_state {int dummy;}; /* for buggy compilers */
16#endif
15 17
16#ifndef Z_BUFSIZE 18#ifndef Z_BUFSIZE
17# ifdef MAXSEG_64K 19# ifdef MAXSEG_64K
@@ -55,6 +57,8 @@ typedef struct gz_stream {
55 int transparent; /* 1 if input file is not a .gz file */ 57 int transparent; /* 1 if input file is not a .gz file */
56 char mode; /* 'w' or 'r' */ 58 char mode; /* 'w' or 'r' */
57 long startpos; /* start of compressed data in file (header skipped) */ 59 long startpos; /* start of compressed data in file (header skipped) */
60 int back; /* one character push-back */
61 int last; /* true if push-back is last character */
58} gz_stream; 62} gz_stream;
59 63
60 64
@@ -102,6 +106,7 @@ local gzFile gz_open (path, mode, fd)
102 s->file = NULL; 106 s->file = NULL;
103 s->z_err = Z_OK; 107 s->z_err = Z_OK;
104 s->z_eof = 0; 108 s->z_eof = 0;
109 s->back = EOF;
105 s->crc = crc32(0L, Z_NULL, 0); 110 s->crc = crc32(0L, Z_NULL, 0);
106 s->msg = NULL; 111 s->msg = NULL;
107 s->transparent = 0; 112 s->transparent = 0;
@@ -391,6 +396,18 @@ int ZEXPORT gzread (file, buf, len)
391 s->stream.next_out = (Bytef*)buf; 396 s->stream.next_out = (Bytef*)buf;
392 s->stream.avail_out = len; 397 s->stream.avail_out = len;
393 398
399 if (s->stream.avail_out && s->back != EOF) {
400 *next_out++ = s->back;
401 s->stream.next_out++;
402 s->stream.avail_out--;
403 s->back = EOF;
404 s->stream.total_out++;
405 if (s->last) {
406 s->z_err = Z_STREAM_END;
407 return 1;
408 }
409 }
410
394 while (s->stream.avail_out != 0) { 411 while (s->stream.avail_out != 0) {
395 412
396 if (s->transparent) { 413 if (s->transparent) {
@@ -477,6 +494,24 @@ int ZEXPORT gzgetc(file)
477 494
478 495
479/* =========================================================================== 496/* ===========================================================================
497 Push one byte back onto the stream.
498*/
499int ZEXPORT gzungetc(c, file)
500 int c;
501 gzFile file;
502{
503 gz_stream *s = (gz_stream*)file;
504
505 if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
506 s->back = c;
507 s->stream.total_out--;
508 s->last = (s->z_err == Z_STREAM_END);
509 if (s->z_eof) s->z_eof = 0;
510 return c;
511}
512
513
514/* ===========================================================================
480 Reads bytes from the compressed file until len-1 characters are 515 Reads bytes from the compressed file until len-1 characters are
481 read, or a newline character is read and transferred to buf, or an 516 read, or a newline character is read and transferred to buf, or an
482 end-of-file condition is encountered. The string is then terminated 517 end-of-file condition is encountered. The string is then terminated
@@ -535,6 +570,7 @@ int ZEXPORT gzwrite (file, buf, len)
535 return (int)(len - s->stream.avail_in); 570 return (int)(len - s->stream.avail_in);
536} 571}
537 572
573
538/* =========================================================================== 574/* ===========================================================================
539 Converts, formats, and writes the args to the compressed file under 575 Converts, formats, and writes the args to the compressed file under
540 control of the format string, as in fprintf. gzprintf returns the number of 576 control of the format string, as in fprintf. gzprintf returns the number of
@@ -549,34 +585,30 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
549 va_list va; 585 va_list va;
550 int len; 586 int len;
551 587
588 buf[sizeof(buf) - 1] = 0;
552 va_start(va, format); 589 va_start(va, format);
553#ifdef NO_vsnprintf 590#ifdef NO_vsnprintf
554# ifdef HAS_vsprintf_void 591# ifdef HAS_vsprintf_void
555 (void)vsprintf(buf, format, va); 592 (void)vsprintf(buf, format, va);
556 va_end(va); 593 va_end(va);
557 len = strlen(buf); /* some *sprintf don't return the nb of bytes written */ 594 for (len = 0; len < sizeof(buf); len++)
558 if (len <= 0) return 0; 595 if (buf[len] == 0) break;
559# else 596# else
560 len = vsprintf(buf, format, va); 597 len = vsprintf(buf, format, va);
561 va_end(va); 598 va_end(va);
562 if (len <= 0 || len >= sizeof(buf))
563 return 0;
564# endif 599# endif
565#else 600#else
566# ifdef HAS_vsnprintf_void 601# ifdef HAS_vsnprintf_void
567 (void)vsnprintf(buf, sizeof(buf), format, va); 602 (void)vsnprintf(buf, sizeof(buf), format, va);
568 va_end(va); 603 va_end(va);
569 len = strlen(buf); 604 len = strlen(buf);
570 if (len <= 0)
571 return 0;
572# else 605# else
573 len = vsnprintf(buf, sizeof(buf), format, va); 606 len = vsnprintf(buf, sizeof(buf), format, va);
574 va_end(va); 607 va_end(va);
575 if (len <= 0 || len >= sizeof(buf))
576 return 0;
577# endif 608# endif
578#endif 609#endif
579 610 if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
611 return 0;
580 return gzwrite(file, buf, (unsigned)len); 612 return gzwrite(file, buf, (unsigned)len);
581} 613}
582#else /* not ANSI C */ 614#else /* not ANSI C */
@@ -591,33 +623,29 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
591 char buf[Z_PRINTF_BUFSIZE]; 623 char buf[Z_PRINTF_BUFSIZE];
592 int len; 624 int len;
593 625
626 buf[sizeof(buf) - 1] = 0;
594#ifdef NO_snprintf 627#ifdef NO_snprintf
595# ifdef HAS_sprintf_void 628# ifdef HAS_sprintf_void
596 sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 629 sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
597 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 630 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
598 len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */ 631 for (len = 0; len < sizeof(buf); len++)
599 if (len <= 0) return 0; 632 if (buf[len] == 0) break;
600# else 633# else
601 len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 634 len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
602 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 635 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
603 if (len <= 0 || len >= sizeof(buf))
604 return 0;
605# endif 636# endif
606#else 637#else
607# ifdef HAS_snprintf_void 638# ifdef HAS_snprintf_void
608 snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 639 snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
609 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 640 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
610 len = strlen(buf); 641 len = strlen(buf);
611 if (len <= 0)
612 return 0;
613# else 642# else
614 len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 643 len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
615 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 644 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
616 if (len <= 0 || len >= sizeof(buf))
617 return 0;
618# endif 645# endif
619#endif 646#endif
620 647 if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
648 return 0;
621 return gzwrite(file, buf, len); 649 return gzwrite(file, buf, len);
622} 650}
623#endif 651#endif
@@ -762,6 +790,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
762 790
763 if (s->transparent) { 791 if (s->transparent) {
764 /* map to fseek */ 792 /* map to fseek */
793 s->back = EOF;
765 s->stream.avail_in = 0; 794 s->stream.avail_in = 0;
766 s->stream.next_in = s->inbuf; 795 s->stream.next_in = s->inbuf;
767 if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; 796 if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
@@ -782,6 +811,12 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
782 s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); 811 s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
783 if (s->outbuf == Z_NULL) return -1L; 812 if (s->outbuf == Z_NULL) return -1L;
784 } 813 }
814 if (offset && s->back != EOF) {
815 s->back == EOF;
816 s->stream.total_out++;
817 offset--;
818 if (s->last) s->z_err = Z_STREAM_END;
819 }
785 while (offset > 0) { 820 while (offset > 0) {
786 int size = Z_BUFSIZE; 821 int size = Z_BUFSIZE;
787 if (offset < Z_BUFSIZE) size = (int)offset; 822 if (offset < Z_BUFSIZE) size = (int)offset;
@@ -805,12 +840,13 @@ int ZEXPORT gzrewind (file)
805 840
806 s->z_err = Z_OK; 841 s->z_err = Z_OK;
807 s->z_eof = 0; 842 s->z_eof = 0;
843 s->back = EOF;
808 s->stream.avail_in = 0; 844 s->stream.avail_in = 0;
809 s->stream.next_in = s->inbuf; 845 s->stream.next_in = s->inbuf;
810 s->crc = crc32(0L, Z_NULL, 0); 846 s->crc = crc32(0L, Z_NULL, 0);
811 847
812 if (s->startpos == 0) { /* not a compressed file */ 848 if (s->startpos == 0) { /* not a compressed file */
813 rewind(s->file); 849 fseek(s->file, 0L, SEEK_SET); /* rewind() is not always available */
814 return 0; 850 return 0;
815 } 851 }
816 852
@@ -906,7 +942,7 @@ int ZEXPORT gzclose (file)
906 errnum is set to Z_ERRNO and the application may consult errno 942 errnum is set to Z_ERRNO and the application may consult errno
907 to get the exact error code. 943 to get the exact error code.
908*/ 944*/
909const char* ZEXPORT gzerror (file, errnum) 945const char * ZEXPORT gzerror (file, errnum)
910 gzFile file; 946 gzFile file;
911 int *errnum; 947 int *errnum;
912{ 948{
@@ -932,3 +968,17 @@ const char* ZEXPORT gzerror (file, errnum)
932 strcat(s->msg, m); 968 strcat(s->msg, m);
933 return (const char*)s->msg; 969 return (const char*)s->msg;
934} 970}
971
972/* ===========================================================================
973 Clear the error and end-of-file flags, and do the same for the real file.
974*/
975void ZEXPORT gzclearerr (file)
976 gzFile file;
977{
978 gz_stream *s = (gz_stream*)file;
979
980 if (s == NULL) return;
981 if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
982 s->z_eof = 0;
983 clearerr(s->file);
984}
diff --git a/infback.c b/infback.c
index fdd7d89..0aef86d 100644
--- a/infback.c
+++ b/infback.c
@@ -151,7 +151,7 @@ struct inflate_state FAR *state;
151 if (have == 0) { \ 151 if (have == 0) { \
152 next = Z_NULL; \ 152 next = Z_NULL; \
153 ret = Z_BUF_ERROR; \ 153 ret = Z_BUF_ERROR; \
154 goto leave; \ 154 goto inf_leave; \
155 } \ 155 } \
156 } \ 156 } \
157 } while (0) 157 } while (0)
@@ -203,7 +203,7 @@ struct inflate_state FAR *state;
203 left = state->wsize; \ 203 left = state->wsize; \
204 if (out(out_desc, put, left)) { \ 204 if (out(out_desc, put, left)) { \
205 ret = Z_BUF_ERROR; \ 205 ret = Z_BUF_ERROR; \
206 goto leave; \ 206 goto inf_leave; \
207 } \ 207 } \
208 } \ 208 } \
209 } while (0) 209 } while (0)
@@ -582,19 +582,19 @@ void FAR *out_desc;
582 if (out(out_desc, state->window, state->wsize - left)) 582 if (out(out_desc, state->window, state->wsize - left))
583 ret = Z_BUF_ERROR; 583 ret = Z_BUF_ERROR;
584 } 584 }
585 goto leave; 585 goto inf_leave;
586 586
587 case BAD: 587 case BAD:
588 ret = Z_DATA_ERROR; 588 ret = Z_DATA_ERROR;
589 goto leave; 589 goto inf_leave;
590 590
591 default: /* can't happen, but makes compilers happy */ 591 default: /* can't happen, but makes compilers happy */
592 ret = Z_STREAM_ERROR; 592 ret = Z_STREAM_ERROR;
593 goto leave; 593 goto inf_leave;
594 } 594 }
595 595
596 /* Return unused input */ 596 /* Return unused input */
597 leave: 597 inf_leave:
598 strm->next_in = next; 598 strm->next_in = next;
599 strm->avail_in = have; 599 strm->avail_in = have;
600 return ret; 600 return ret;
diff --git a/inflate.c b/inflate.c
index 1da2776..0fd158d 100644
--- a/inflate.c
+++ b/inflate.c
@@ -77,7 +77,7 @@
77 * and buffer address return values for the input function 77 * and buffer address return values for the input function
78 * - Check next_in and next_out for Z_NULL on entry to inflate() 78 * - Check next_in and next_out for Z_NULL on entry to inflate()
79 * 79 *
80 * The history for versions past 1.2.0 are in ChangeLog in zlib distribution. 80 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
81 */ 81 */
82 82
83#include "zutil.h" 83#include "zutil.h"
@@ -147,8 +147,12 @@ int stream_size;
147 state->wrap = 0; 147 state->wrap = 0;
148 windowBits = -windowBits; 148 windowBits = -windowBits;
149 } 149 }
150 else 150 else {
151 state->wrap = 1; 151 state->wrap = (windowBits >> 4) + 1;
152#ifdef GUNZIP
153 windowBits &= 15;
154#endif
155 }
152 if (windowBits < 8 || windowBits > 15) { 156 if (windowBits < 8 || windowBits > 15) {
153 ZFREE(strm, state); 157 ZFREE(strm, state);
154 strm->state = Z_NULL; 158 strm->state = Z_NULL;
@@ -403,7 +407,7 @@ unsigned out;
403 if there is no input available. */ 407 if there is no input available. */
404#define PULLBYTE() \ 408#define PULLBYTE() \
405 do { \ 409 do { \
406 if (have == 0) goto leave; \ 410 if (have == 0) goto inf_leave; \
407 have--; \ 411 have--; \
408 hold += (unsigned long)(*next++) << bits; \ 412 hold += (unsigned long)(*next++) << bits; \
409 bits += 8; \ 413 bits += 8; \
@@ -502,14 +506,14 @@ unsigned out;
502 complete that state. Those states are copying stored data, writing a 506 complete that state. Those states are copying stored data, writing a
503 literal byte, and copying a matching string. 507 literal byte, and copying a matching string.
504 508
505 When returning, a "goto leave" is used to update the total counters, update 509 When returning, a "goto inf_leave" is used to update the total counters,
506 the check value, and determine whether any progress has been made during 510 update the check value, and determine whether any progress has been made
507 that inflate() call in order to return the proper return code. Progress is 511 during that inflate() call in order to return the proper return code.
508 defined as a change in either strm->avail_in or strm->avail_out. When there 512 Progress is defined as a change in either strm->avail_in or strm->avail_out.
509 is a window, goto leave will update the window with the last output written. 513 When there is a window, goto inf_leave will update the window with the last
510 If a goto leave occurs in the middle of decompression and there is no window 514 output written. If a goto inf_leave occurs in the middle of decompression
511 currently, goto leave will create one and copy output to the window for the 515 and there is no window currently, goto inf_leave will create one and copy
512 next call of inflate(). 516 output to the window for the next call of inflate().
513 517
514 In this implementation, the flush parameter of inflate() only affects the 518 In this implementation, the flush parameter of inflate() only affects the
515 return code (per zlib.h). inflate() always writes as much as possible to 519 return code (per zlib.h). inflate() always writes as much as possible to
@@ -562,16 +566,19 @@ int flush;
562 } 566 }
563 NEEDBITS(16); 567 NEEDBITS(16);
564#ifdef GUNZIP 568#ifdef GUNZIP
565 if (hold == 0x8b1f) { /* gzip header */ 569 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
566 state->check = crc32(0L, Z_NULL, 0); 570 state->check = crc32(0L, Z_NULL, 0);
567 CRC2(state->check, hold); 571 CRC2(state->check, hold);
568 INITBITS(); 572 INITBITS();
569 state->mode = FLAGS; 573 state->mode = FLAGS;
570 break; 574 break;
571 } 575 }
572 state->flags = 0; /* expect zlib header */ 576 state->flags = 0; /* expect zlib header */
577 if (!(state->wrap & 1) || /* check if zlib header allowed */
578#else
579 if (
573#endif 580#endif
574 if (((BITS(8) << 8) + (hold >> 8)) % 31) { 581 ((BITS(8) << 8) + (hold >> 8)) % 31) {
575 strm->msg = (char *)"incorrect header check"; 582 strm->msg = (char *)"incorrect header check";
576 state->mode = BAD; 583 state->mode = BAD;
577 break; 584 break;
@@ -638,12 +645,12 @@ int flush;
638 next += copy; 645 next += copy;
639 state->length -= copy; 646 state->length -= copy;
640 } 647 }
641 if (state->length) goto leave; 648 if (state->length) goto inf_leave;
642 } 649 }
643 state->mode = NAME; 650 state->mode = NAME;
644 case NAME: 651 case NAME:
645 if (state->flags & 0x0800) { 652 if (state->flags & 0x0800) {
646 if (have == 0) goto leave; 653 if (have == 0) goto inf_leave;
647 copy = 0; 654 copy = 0;
648 do { 655 do {
649 len = (unsigned)(next[copy++]); 656 len = (unsigned)(next[copy++]);
@@ -652,12 +659,12 @@ int flush;
652 state->check = crc32(state->check, next, copy); 659 state->check = crc32(state->check, next, copy);
653 have -= copy; 660 have -= copy;
654 next += copy; 661 next += copy;
655 if (len) goto leave; 662 if (len) goto inf_leave;
656 } 663 }
657 state->mode = COMMENT; 664 state->mode = COMMENT;
658 case COMMENT: 665 case COMMENT:
659 if (state->flags & 0x1000) { 666 if (state->flags & 0x1000) {
660 if (have == 0) goto leave; 667 if (have == 0) goto inf_leave;
661 copy = 0; 668 copy = 0;
662 do { 669 do {
663 len = (unsigned)(next[copy++]); 670 len = (unsigned)(next[copy++]);
@@ -666,7 +673,7 @@ int flush;
666 state->check = crc32(state->check, next, copy); 673 state->check = crc32(state->check, next, copy);
667 have -= copy; 674 have -= copy;
668 next += copy; 675 next += copy;
669 if (len) goto leave; 676 if (len) goto inf_leave;
670 } 677 }
671 state->mode = HCRC; 678 state->mode = HCRC;
672 case HCRC: 679 case HCRC:
@@ -745,7 +752,7 @@ int flush;
745 if (copy) { 752 if (copy) {
746 if (copy > have) copy = have; 753 if (copy > have) copy = have;
747 if (copy > left) copy = left; 754 if (copy > left) copy = left;
748 if (copy == 0) goto leave; 755 if (copy == 0) goto inf_leave;
749 zmemcpy(put, next, copy); 756 zmemcpy(put, next, copy);
750 have -= copy; 757 have -= copy;
751 next += copy; 758 next += copy;
@@ -958,7 +965,7 @@ int flush;
958 Tracevv((stderr, "inflate: distance %u\n", state->offset)); 965 Tracevv((stderr, "inflate: distance %u\n", state->offset));
959 state->mode = MATCH; 966 state->mode = MATCH;
960 case MATCH: 967 case MATCH:
961 if (left == 0) goto leave; 968 if (left == 0) goto inf_leave;
962 copy = out - left; 969 copy = out - left;
963 if (state->offset > copy) { /* copy from window */ 970 if (state->offset > copy) { /* copy from window */
964 copy = state->offset - copy; 971 copy = state->offset - copy;
@@ -983,7 +990,7 @@ int flush;
983 if (state->length == 0) state->mode = LEN; 990 if (state->length == 0) state->mode = LEN;
984 break; 991 break;
985 case LIT: 992 case LIT:
986 if (left == 0) goto leave; 993 if (left == 0) goto inf_leave;
987 *put++ = (unsigned char)(state->length); 994 *put++ = (unsigned char)(state->length);
988 left--; 995 left--;
989 state->mode = LEN; 996 state->mode = LEN;
@@ -1015,7 +1022,7 @@ int flush;
1015 case LENGTH: 1022 case LENGTH:
1016 if (state->wrap && state->flags) { 1023 if (state->wrap && state->flags) {
1017 NEEDBITS(32); 1024 NEEDBITS(32);
1018 if (hold != (state->total & 0xffffffff)) { 1025 if (hold != (state->total & 0xffffffffUL)) {
1019 strm->msg = (char *)"incorrect length check"; 1026 strm->msg = (char *)"incorrect length check";
1020 state->mode = BAD; 1027 state->mode = BAD;
1021 break; 1028 break;
@@ -1027,10 +1034,10 @@ int flush;
1027 state->mode = DONE; 1034 state->mode = DONE;
1028 case DONE: 1035 case DONE:
1029 ret = Z_STREAM_END; 1036 ret = Z_STREAM_END;
1030 goto leave; 1037 goto inf_leave;
1031 case BAD: 1038 case BAD:
1032 ret = Z_DATA_ERROR; 1039 ret = Z_DATA_ERROR;
1033 goto leave; 1040 goto inf_leave;
1034 case MEM: 1041 case MEM:
1035 return Z_MEM_ERROR; 1042 return Z_MEM_ERROR;
1036 case SYNC: 1043 case SYNC:
@@ -1044,7 +1051,7 @@ int flush;
1044 error. Call updatewindow() to create and/or update the window state. 1051 error. Call updatewindow() to create and/or update the window state.
1045 Note: a memory error from inflate() is non-recoverable. 1052 Note: a memory error from inflate() is non-recoverable.
1046 */ 1053 */
1047 leave: 1054 inf_leave:
1048 RESTORE(); 1055 RESTORE();
1049 if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) 1056 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1050 if (updatewindow(strm, out)) { 1057 if (updatewindow(strm, out)) {
diff --git a/inflate.h b/inflate.h
index 5bcc82b..2221b23 100644
--- a/inflate.h
+++ b/inflate.h
@@ -80,7 +80,7 @@ typedef enum {
80struct inflate_state { 80struct inflate_state {
81 inflate_mode mode; /* current inflate mode */ 81 inflate_mode mode; /* current inflate mode */
82 int last; /* true if processing last block */ 82 int last; /* true if processing last block */
83 int wrap; /* true to process header and trailer */ 83 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
84 int havedict; /* true if dictionary provided */ 84 int havedict; /* true if dictionary provided */
85 int flags; /* gzip header method and flags (0 if zlib) */ 85 int flags; /* gzip header method and flags (0 if zlib) */
86 unsigned long check; /* protected copy of check value */ 86 unsigned long check; /* protected copy of check value */
diff --git a/inftrees.c b/inftrees.c
index a4e0745..fda5537 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate_copyright[] = 11const char inflate_copyright[] =
12 " inflate 1.2.0.1 Copyright 1995-2003 Mark Adler "; 12 " inflate 1.2.0.2 Copyright 1995-2003 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, 205, 64}; 65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 67, 201};
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/minigzip.c b/minigzip.c
index 3918cbc..e75108f 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -113,7 +113,7 @@ void gz_compress(in, out)
113 if (gz_compress_mmap(in, out) == Z_OK) return; 113 if (gz_compress_mmap(in, out) == Z_OK) return;
114#endif 114#endif
115 for (;;) { 115 for (;;) {
116 len = fread(buf, 1, sizeof(buf), in); 116 len = (int)fread(buf, 1, sizeof(buf), in);
117 if (ferror(in)) { 117 if (ferror(in)) {
118 perror("fread"); 118 perror("fread");
119 exit(1); 119 exit(1);
@@ -230,7 +230,7 @@ void file_uncompress(file)
230 char *infile, *outfile; 230 char *infile, *outfile;
231 FILE *out; 231 FILE *out;
232 gzFile in; 232 gzFile in;
233 int len = strlen(file); 233 int len = (int)strlen(file);
234 234
235 strcpy(buf, file); 235 strcpy(buf, file);
236 236
diff --git a/old/zlib.3 b/old/zlib.3
deleted file mode 100644
index 3a6e450..0000000
--- a/old/zlib.3
+++ /dev/null
@@ -1,107 +0,0 @@
1.TH ZLIB 3 "11 March 2002"
2.SH NAME
3zlib \- compression/decompression library
4.SH SYNOPSIS
5[see
6.I zlib.h
7for full description]
8.SH DESCRIPTION
9The
10.I zlib
11library is a general purpose data compression library.
12The code is thread safe.
13It provides in-memory compression and decompression functions,
14including integrity checks of the uncompressed data.
15This version of the library supports only one compression method (deflation)
16but other algorithms will be added later and will have the same stream interface.
17.LP
18Compression can be done in a single step if the buffers are large enough
19(for example if an input file is mmap'ed),
20or can be done by repeated calls of the compression function.
21In the latter case,
22the application must provide more input and/or consume the output
23(providing more output space) before each call.
24.LP
25The library also supports reading and writing files in
26.I gzip
27(.gz) format
28with an interface similar to that of stdio.
29.LP
30The library does not install any signal handler. The decoder checks
31the consistency of the compressed data, so the library should never
32crash even in case of corrupted input.
33.LP
34All functions of the compression library are documented in the file
35.IR zlib.h.
36The distribution source includes examples of use of the library
37the files
38.I example.c
39and
40.IR minigzip.c .
41.LP
42A Java implementation of
43.IR zlib
44is available in the Java Development Kit 1.1
45.IP
46http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
47.LP
48A Perl interface to
49.IR zlib ,
50written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
51is available at CPAN (Comprehensive Perl Archive Network) sites,
52such as:
53.IP
54ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
55.LP
56A Python interface to
57.IR zlib
58written by A.M. Kuchling <amk@magnet.com>
59is available from the Python Software Association sites, such as:
60.IP
61ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
62.SH "SEE ALSO"
63Questions about zlib should be sent to:
64.IP
65zlib@quest.jpl.nasa.gov
66or, if this fails, to the author addresses given below.
67The zlib home page is:
68.IP
69http://www.cdrom.com/pub/infozip/zlib/
70.LP
71The data format used by the zlib library is described by RFC
72(Request for Comments) 1950 to 1952 in the files:
73.IP
74ftp://ds.internic.net/rfc/rfc1950.txt (zlib format)
75.br
76rfc1951.txt (deflate format)
77.br
78rfc1952.txt (gzip format)
79.LP
80These documents are also available in other formats from:
81.IP
82ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
83.SH AUTHORS
84Version 1.1.4
85Copyright (C) 1995-2002 Jean-loup Gailly (jloup@gzip.org)
86and Mark Adler (madler@alumni.caltech.edu).
87.LP
88This software is provided "as-is,"
89without any express or implied warranty.
90In no event will the authors be held liable for any damages
91arising from the use of this software.
92See the distribution directory with respect to requirements
93governing redistribution.
94The deflate format used by
95.I zlib
96was defined by Phil Katz.
97The deflate and
98.I zlib
99specifications were written by L. Peter Deutsch.
100Thanks to all the people who reported problems and suggested various
101improvements in
102.IR zlib ;
103who are too numerous to cite here.
104.LP
105UNIX manual page by R. P. C. Rodgers,
106U.S. National Library of Medicine (rodgers@nlm.nih.gov).
107.\" end of man page
diff --git a/uncompr.c b/uncompr.c
index e4e52ce..5200ebd 100644
--- a/uncompr.c
+++ b/uncompr.c
@@ -5,6 +5,7 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#define ZLIB_INTERNAL
8#include "zlib.h" 9#include "zlib.h"
9 10
10/* =========================================================================== 11/* ===========================================================================
diff --git a/win32/Makefile.gcc b/win32/Makefile.gcc
index 7f9973b..da32859 100644
--- a/win32/Makefile.gcc
+++ b/win32/Makefile.gcc
@@ -16,7 +16,7 @@
16# 16#
17 17
18LIB = libz.a 18LIB = libz.a
19SHAREDLIB = libz.so 19SHAREDLIB = zlib.dll
20VER = 1.2.0 20VER = 1.2.0
21 21
22CC = gcc 22CC = gcc
@@ -32,6 +32,8 @@ LDFLAGS = $(LOC) -s
32AR = ar 32AR = ar
33ARFLAGS = rcs 33ARFLAGS = rcs
34 34
35RC = windres
36
35CP = cp -fp 37CP = cp -fp
36# If GNU install is available, replace $(CP) with install. 38# If GNU install is available, replace $(CP) with install.
37INSTALL = $(CP) 39INSTALL = $(CP)
@@ -43,12 +45,14 @@ exec_prefix = $(prefix)
43OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \ 45OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
44 inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 46 inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
45 47
48DLLDEF = win32/zlibgcc.def
49
46# to use the asm code: make OBJA=match.o 50# to use the asm code: make OBJA=match.o
47OBJA = 51OBJA =
48 52
49TEST_OBJS = example.o minigzip.o 53TEST_OBJS = example.o minigzip.o
50 54
51all: $(LIB) example minigzip 55all: $(LIB) $(SHAREDLIB) example minigzip
52 56
53test: all 57test: all
54 ./example 58 ./example
@@ -60,12 +64,18 @@ test: all
60libz.a: $(OBJS) 64libz.a: $(OBJS)
61 $(AR) $(ARFLAGS) $@ $(OBJS) 65 $(AR) $(ARFLAGS) $@ $(OBJS)
62 66
67$(SHAREDLIB): $(OBJS) $(DLLDEF) zlibrc.o
68 dllwrap --driver-name $(CC) --def $(DLLDEF) -o $@ $(OBJS) zlibrc.o
69
63example: example.o $(LIB) 70example: example.o $(LIB)
64 $(LD) -o $@ $< $(LIB) 71 $(LD) -o $@ $< $(LIB)
65 72
66minigzip: minigzip.o $(LIB) 73minigzip: minigzip.o $(LIB)
67 $(LD) -o $@ $< $(LIB) 74 $(LD) -o $@ $< $(LIB)
68 75
76zlibrc.o: win32/zlib.rc
77 -$(RC) -o $@ --define GCC_WINDRES win32/zlib.rc
78
69 79
70# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env . 80# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env .
71 81
@@ -87,6 +97,7 @@ clean:
87 $(RM) *.o 97 $(RM) *.o
88 $(RM) *.exe 98 $(RM) *.exe
89 $(RM) libz.a 99 $(RM) libz.a
100 $(RM) zlib.dll
90 $(RM) foo.gz 101 $(RM) foo.gz
91 102
92adler32.o: zlib.h zconf.h 103adler32.o: zlib.h zconf.h
diff --git a/win32/Makefile.msc b/win32/Makefile.msc
index 9760208..4dc8819 100644
--- a/win32/Makefile.msc
+++ b/win32/Makefile.msc
@@ -1,10 +1,13 @@
1# Makefile for (static) zlib -- Microsoft (Visual) C. 1# Makefile for Win32 zlib.dll and the static library zlibstat.lib
2# Author: Cosmin Truta, 11-Mar-2003. 2# -- Microsoft (Visual) C.
3# Author: Cosmin Truta, 11-Mar-2003
4# Christian Spieler, 19-Mar-2003
3# 5#
4# Usage: nmake -f win32/Makefile.msc 6# Usage: nmake -f win32/Makefile.msc
5 7
6CC = cl 8CC = cl
7LD = cl 9LD = cl
10RC = rc
8CFLAGS = -nologo -MD -O2 11CFLAGS = -nologo -MD -O2
9LDFLAGS = -nologo 12LDFLAGS = -nologo
10 13
@@ -12,19 +15,33 @@ OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \
12 inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj 15 inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
13 16
14# targets 17# targets
15all: zlib.lib example.exe minigzip.exe 18all: zlib.dll zlibstat.lib example.exe minigzip.exe exampl_s.exe minigz_s.exe
16 19
17zlib.lib: $(OBJS) 20zlibstat.lib: $(OBJS)
18 lib -out:$@ $(OBJS) 21 lib -out:$@ $(OBJS)
19 22
23zlib.dll: $(OBJS) zlib.res win32/zlib.def
24 link -release -def:win32/zlib.def -dll -out:$@ $(OBJS) zlib.res
25
26zlib.lib: zlib.dll
27
20example.exe: example.obj zlib.lib 28example.exe: example.obj zlib.lib
21 $(LD) $(LDFLAGS) example.obj zlib.lib 29 $(LD) $(LDFLAGS) example.obj zlib.lib
22 30
23minigzip.exe: minigzip.obj zlib.lib 31minigzip.exe: minigzip.obj zlib.lib
24 $(LD) $(LDFLAGS) minigzip.obj zlib.lib 32 $(LD) $(LDFLAGS) minigzip.obj zlib.lib
25 33
34exampl_s.exe: example.obj zlibstat.lib
35 $(LD) $(LDFLAGS) -o $@ example.obj zlibstat.lib
36
37minigz_s.exe: minigzip.obj zlibstat.lib
38 $(LD) $(LDFLAGS) -o $@ minigzip.obj zlibstat.lib
39
26.c.obj: 40.c.obj:
27 $(CC) -c $(CFLAGS) $*.c 41 $(CC) -c $(CFLAGS) $<
42
43zlib.res: win32/zlib.rc
44 $(RC) /l 0x409 /fo$@ /d WIN32 win32/zlib.rc
28 45
29adler32.obj: adler32.c zlib.h zconf.h 46adler32.obj: adler32.c zlib.h zconf.h
30 47
@@ -62,8 +79,14 @@ test: example.exe minigzip.exe
62 example 79 example
63 echo hello world | minigzip | minigzip -d 80 echo hello world | minigzip | minigzip -d
64 81
82teststat: exampl_s.exe minigz_s.exe
83 exampl_s
84 echo hello world | minigz_s | minigz_s -d
85
65# cleanup 86# cleanup
66clean: 87clean:
67 del *.obj 88 del *.obj
89 del *.dll
68 del *.lib 90 del *.lib
91 del *.exp
69 del *.exe 92 del *.exe
diff --git a/win32/zlib.def b/win32/zlib.def
index 3b4b05a..d299ed5 100644
--- a/win32/zlib.def
+++ b/win32/zlib.def
@@ -1,5 +1,5 @@
1LIBRARY zlib.dll 1LIBRARY zlib.dll
2DESCRIPTION "zlib compression library for Windows" 2DESCRIPTION "zlib data compression library"
3 3
4EXPORTS 4EXPORTS
5 adler32 @1 5 adler32 @1
@@ -43,7 +43,10 @@ EXPORTS
43 compress2 @39 43 compress2 @39
44 gzputs @40 44 gzputs @40
45 gzgets @41 45 gzgets @41
46; The following functions exist since zlib-1.2.0 46; since zlib-1.2.0:
47; deflateBound @42 47 inflateCopy @42
48; compressBound @43 48 inflateBackInit_ @43
49; etc. 49 inflateBack @44
50 inflateBackEnd @45
51 compressBound @46
52 deflateBound @47
diff --git a/zconf.h b/zconf.h
index f3c4430..b17d420 100644
--- a/zconf.h
+++ b/zconf.h
@@ -5,8 +5,8 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#ifndef _ZCONF_H 8#ifndef ZCONF_H
9#define _ZCONF_H 9#define ZCONF_H
10 10
11/* 11/*
12 * If you *really* need a unique prefix for all types and library functions, 12 * If you *really* need a unique prefix for all types and library functions,
@@ -100,15 +100,6 @@
100# define NO_DUMMY_DECL 100# define NO_DUMMY_DECL
101#endif 101#endif
102 102
103/* Old Borland C incorrectly complains about missing returns: */
104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
105# define NEED_DUMMY_RETURN
106#endif
107#if defined(__TURBOC__) && !defined(__BORLANDC__)
108# define NEED_DUMMY_RETURN
109#endif
110
111
112/* Maximum value for memLevel in deflateInit2 */ 103/* Maximum value for memLevel in deflateInit2 */
113#ifndef MAX_MEM_LEVEL 104#ifndef MAX_MEM_LEVEL
114# ifdef MAXSEG_64K 105# ifdef MAXSEG_64K
@@ -172,46 +163,54 @@
172# endif 163# endif
173#endif 164#endif
174 165
175#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL)) 166/* If building or using a Windows DLL, compile with -DZLIB_DLL.
176# define ZLIB_DLL 167 * The calls to ZEXTERN functions will be more efficient this way.
177#endif 168 */
178 169#if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
179/* Compile with -DZLIB_DLL for Windows DLL support */ 170# ifdef FAR
180#if defined(ZLIB_DLL) 171# undef FAR
181# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32) 172# endif
182# ifndef WINAPIV 173 /* For zlib, the basic Win32 API declarations are sufficient. Whenever
183# ifdef FAR 174 * a program that uses zlib requires the full Win32 API set, it has
184# undef FAR 175 * to include <windows.h> prior to "zlib.h".
185# endif 176 */
186# include <windows.h> 177# if defined(WIN32) && (!defined(WIN32_LEAN_AND_MEAN))
187# endif 178# define WIN32_LEAN_AND_MEAN
188# ifdef WIN32
189# define ZEXPORT WINAPI
190# define ZEXPORTVA WINAPIV
191# else
192# define ZEXPORT WINAPI _export
193# define ZEXPORTVA FAR _cdecl _export
194# endif
195# endif 179# endif
196# if defined (__BORLANDC__) 180# include <windows.h>
197# if (__BORLANDC__ >= 0x0500) && defined (WIN32) 181# if !defined(WIN32) || (defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
198# include <windows.h> 182# if defined(ZLIB_DLL) && defined(ZLIB_INTERNAL)
199# define ZEXPORT __declspec(dllexport) WINAPI 183# define ZEXPORT WINAPI _export
200# define ZEXPORTVA __declspec(dllexport) WINAPIV 184# define ZEXPORTVA FAR _cdecl _export
201# else 185# else
202# if defined (_Windows) && defined (__DLL__) 186# define ZEXPORT WINAPI
203# define ZEXPORT _export 187# define ZEXPORTVA FAR _cdecl
204# define ZEXPORTVA _export 188# endif
189# else
190 /* a fully Win32-compliant compiler */
191# define ZEXPORT WINAPI
192# define ZEXPORTVA CDECL
193# ifdef ZLIB_DLL
194# ifdef ZLIB_INTERNAL
195# define ZEXTERN extern __declspec(dllexport)
196# else
197# define ZEXTERN extern __declspec(dllimport)
205# endif 198# endif
199# else
200# define ZEXTERN extern
206# endif 201# endif
207# endif 202# endif
208#endif 203#endif
209 204
210#if defined (__BEOS__) 205#if defined (__BEOS__)
211# if defined (ZLIB_DLL) 206# ifdef ZLIB_DLL
212# define ZEXTERN extern __declspec(dllexport) 207# ifdef ZLIB_INTERNAL
213# else 208# define ZEXPORT __declspec(dllexport)
214# define ZEXTERN extern __declspec(dllimport) 209# define ZEXPORTVA __declspec(dllexport)
210# else
211# define ZEXPORT __declspec(dllimport)
212# define ZEXPORTVA __declspec(dllimport)
213# endif
215# endif 214# endif
216#endif 215#endif
217 216
@@ -226,7 +225,7 @@
226#endif 225#endif
227 226
228#ifndef FAR 227#ifndef FAR
229# define FAR 228# define FAR
230#endif 229#endif
231 230
232#if !defined(__MACTYPES__) 231#if !defined(__MACTYPES__)
@@ -290,4 +289,4 @@ typedef uLong FAR uLongf;
290# pragma map(inflate_copyright,"INCOPY") 289# pragma map(inflate_copyright,"INCOPY")
291#endif 290#endif
292 291
293#endif /* _ZCONF_H */ 292#endif /* ZCONF_H */
diff --git a/zconf.in.h b/zconf.in.h
index f3c4430..b17d420 100644
--- a/zconf.in.h
+++ b/zconf.in.h
@@ -5,8 +5,8 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#ifndef _ZCONF_H 8#ifndef ZCONF_H
9#define _ZCONF_H 9#define ZCONF_H
10 10
11/* 11/*
12 * If you *really* need a unique prefix for all types and library functions, 12 * If you *really* need a unique prefix for all types and library functions,
@@ -100,15 +100,6 @@
100# define NO_DUMMY_DECL 100# define NO_DUMMY_DECL
101#endif 101#endif
102 102
103/* Old Borland C incorrectly complains about missing returns: */
104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
105# define NEED_DUMMY_RETURN
106#endif
107#if defined(__TURBOC__) && !defined(__BORLANDC__)
108# define NEED_DUMMY_RETURN
109#endif
110
111
112/* Maximum value for memLevel in deflateInit2 */ 103/* Maximum value for memLevel in deflateInit2 */
113#ifndef MAX_MEM_LEVEL 104#ifndef MAX_MEM_LEVEL
114# ifdef MAXSEG_64K 105# ifdef MAXSEG_64K
@@ -172,46 +163,54 @@
172# endif 163# endif
173#endif 164#endif
174 165
175#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL)) 166/* If building or using a Windows DLL, compile with -DZLIB_DLL.
176# define ZLIB_DLL 167 * The calls to ZEXTERN functions will be more efficient this way.
177#endif 168 */
178 169#if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
179/* Compile with -DZLIB_DLL for Windows DLL support */ 170# ifdef FAR
180#if defined(ZLIB_DLL) 171# undef FAR
181# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32) 172# endif
182# ifndef WINAPIV 173 /* For zlib, the basic Win32 API declarations are sufficient. Whenever
183# ifdef FAR 174 * a program that uses zlib requires the full Win32 API set, it has
184# undef FAR 175 * to include <windows.h> prior to "zlib.h".
185# endif 176 */
186# include <windows.h> 177# if defined(WIN32) && (!defined(WIN32_LEAN_AND_MEAN))
187# endif 178# define WIN32_LEAN_AND_MEAN
188# ifdef WIN32
189# define ZEXPORT WINAPI
190# define ZEXPORTVA WINAPIV
191# else
192# define ZEXPORT WINAPI _export
193# define ZEXPORTVA FAR _cdecl _export
194# endif
195# endif 179# endif
196# if defined (__BORLANDC__) 180# include <windows.h>
197# if (__BORLANDC__ >= 0x0500) && defined (WIN32) 181# if !defined(WIN32) || (defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
198# include <windows.h> 182# if defined(ZLIB_DLL) && defined(ZLIB_INTERNAL)
199# define ZEXPORT __declspec(dllexport) WINAPI 183# define ZEXPORT WINAPI _export
200# define ZEXPORTVA __declspec(dllexport) WINAPIV 184# define ZEXPORTVA FAR _cdecl _export
201# else 185# else
202# if defined (_Windows) && defined (__DLL__) 186# define ZEXPORT WINAPI
203# define ZEXPORT _export 187# define ZEXPORTVA FAR _cdecl
204# define ZEXPORTVA _export 188# endif
189# else
190 /* a fully Win32-compliant compiler */
191# define ZEXPORT WINAPI
192# define ZEXPORTVA CDECL
193# ifdef ZLIB_DLL
194# ifdef ZLIB_INTERNAL
195# define ZEXTERN extern __declspec(dllexport)
196# else
197# define ZEXTERN extern __declspec(dllimport)
205# endif 198# endif
199# else
200# define ZEXTERN extern
206# endif 201# endif
207# endif 202# endif
208#endif 203#endif
209 204
210#if defined (__BEOS__) 205#if defined (__BEOS__)
211# if defined (ZLIB_DLL) 206# ifdef ZLIB_DLL
212# define ZEXTERN extern __declspec(dllexport) 207# ifdef ZLIB_INTERNAL
213# else 208# define ZEXPORT __declspec(dllexport)
214# define ZEXTERN extern __declspec(dllimport) 209# define ZEXPORTVA __declspec(dllexport)
210# else
211# define ZEXPORT __declspec(dllimport)
212# define ZEXPORTVA __declspec(dllimport)
213# endif
215# endif 214# endif
216#endif 215#endif
217 216
@@ -226,7 +225,7 @@
226#endif 225#endif
227 226
228#ifndef FAR 227#ifndef FAR
229# define FAR 228# define FAR
230#endif 229#endif
231 230
232#if !defined(__MACTYPES__) 231#if !defined(__MACTYPES__)
@@ -290,4 +289,4 @@ typedef uLong FAR uLongf;
290# pragma map(inflate_copyright,"INCOPY") 289# pragma map(inflate_copyright,"INCOPY")
291#endif 290#endif
292 291
293#endif /* _ZCONF_H */ 292#endif /* ZCONF_H */
diff --git a/zlib.3 b/zlib.3
new file mode 100644
index 0000000..949c87e
--- /dev/null
+++ b/zlib.3
@@ -0,0 +1,159 @@
1.TH ZLIB 3 "12 May 2003"
2.SH NAME
3zlib \- compression/decompression library
4.SH SYNOPSIS
5[see
6.I zlib.h
7for full description]
8.SH DESCRIPTION
9The
10.I zlib
11library is a general purpose data compression library.
12The code is thread safe.
13It provides in-memory compression and decompression functions,
14including integrity checks of the uncompressed data.
15This version of the library supports only one compression method (deflation)
16but other algorithms will be added later
17and will have the same stream interface.
18.LP
19Compression can be done in a single step if the buffers are large enough
20(for example if an input file is mmap'ed),
21or can be done by repeated calls of the compression function.
22In the latter case,
23the application must provide more input and/or consume the output
24(providing more output space) before each call.
25.LP
26The library also supports reading and writing files in
27.IR gzip (1)
28(.gz) format
29with an interface similar to that of stdio.
30.LP
31The library does not install any signal handler.
32The decoder checks the consistency of the compressed data,
33so the library should never crash even in case of corrupted input.
34.LP
35All functions of the compression library are documented in the file
36.IR zlib.h .
37The distribution source includes examples of use of the library
38in the files
39.I example.c
40and
41.IR minigzip.c .
42.LP
43Changes to this version are documented in the file
44.I ChangeLog
45that accompanies the source,
46and are concerned primarily with bug fixes and portability enhancements.
47.LP
48A Java implementation of
49.I zlib
50is available in the Java Development Kit 1.1:
51.IP
52http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
53.LP
54A Perl interface to
55.IR zlib ,
56written by Paul Marquess (pmqs@cpan.org),
57is available at CPAN (Comprehensive Perl Archive Network) sites,
58including:
59.IP
60http://www.cpan.org/modules/by-module/Compress/
61.LP
62A Python interface to
63.IR zlib ,
64written by A.M. Kuchling (amk@magnet.com),
65is available in Python 1.5 and later versions:
66.IP
67http://www.python.org/doc/lib/module-zlib.html
68.LP
69A
70.I zlib
71binding for
72.IR tcl (1),
73written by Andreas Kupries (a.kupries@westend.com),
74is availlable at:
75.IP
76http://www.westend.com/~kupries/doc/trf/man/man.html
77.LP
78An experimental package to read and write files in .zip format,
79written on top of
80.I zlib
81by Gilles Vollant (info@winimage.com),
82is available at:
83.IP
84http://www.winimage.com/zLibDll/unzip.html
85and also in the
86.I contrib/minizip
87directory of the main
88.I zlib
89web site.
90.SH "SEE ALSO"
91The
92.I zlib
93web site can be found at either of these locations:
94.IP
95http://www.zlib.org
96.br
97http://www.gzip.org/zlib/
98.LP
99The data format used by the zlib library is described by RFC
100(Request for Comments) 1950 to 1952 in the files:
101.IP
102http://www.ietf.org/rfc/rfc1950.txt (concerning zlib format)
103.br
104http://www.ietf.org/rfc/rfc1951.txt (concerning deflate format)
105.br
106http://www.ietf.org/rfc/rfc1952.txt (concerning gzip format)
107.LP
108These documents are also available in other formats from:
109.IP
110ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
111.LP
112Mark Nelson (markn@ieee.org) wrote an article about
113.I zlib
114for the Jan. 1997 issue of Dr. Dobb's Journal;
115a copy of the article is available at:
116.IP
117http://dogma.net/markn/articles/zlibtool/zlibtool.htm
118.SH "REPORTING PROBLEMS"
119Before reporting a problem,
120please check the
121.I zlib
122web site to verify that you have the latest version of
123.IR zlib ;
124otherwise,
125obtain the latest version and see if the problem still exists.
126Please read the
127.I zlib
128FAQ at:
129.IP
130http://www.gzip.org/zlib/zlib_faq.html
131.LP
132before asking for help.
133Send questions and/or comments to zlib@gzip.org,
134or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
135.SH AUTHORS
136Version 1.2.0.1
137Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org)
138and Mark Adler (madler@alumni.caltech.edu).
139.LP
140This software is provided "as-is,"
141without any express or implied warranty.
142In no event will the authors be held liable for any damages
143arising from the use of this software.
144See the distribution directory with respect to requirements
145governing redistribution.
146The deflate format used by
147.I zlib
148was defined by Phil Katz.
149The deflate and
150.I zlib
151specifications were written by L. Peter Deutsch.
152Thanks to all the people who reported problems and suggested various
153improvements in
154.IR zlib ;
155who are too numerous to cite here.
156.LP
157UNIX manual page by R. P. C. Rodgers,
158U.S. National Library of Medicine (rodgers@nlm.nih.gov).
159.\" end of man page
diff --git a/zlib.h b/zlib.h
index 2d239a2..95370d4 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.0.1, March 17th, 2003 2 version 1.2.0.2, July 13th, 2003
3 3
4 Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
5 5
@@ -28,8 +28,8 @@
28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*/ 29*/
30 30
31#ifndef _ZLIB_H 31#ifndef ZLIB_H
32#define _ZLIB_H 32#define ZLIB_H
33 33
34#include "zconf.h" 34#include "zconf.h"
35 35
@@ -37,7 +37,8 @@
37extern "C" { 37extern "C" {
38#endif 38#endif
39 39
40#define ZLIB_VERSION "1.2.0.1" 40#define ZLIB_VERSION "1.2.0.2"
41#define ZLIB_VERNUM 0x1202
41 42
42/* 43/*
43 The 'zlib' compression library provides in-memory compression and 44 The 'zlib' compression library provides in-memory compression and
@@ -334,9 +335,9 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
334ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 335ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
335/* 336/*
336 inflate decompresses as much data as possible, and stops when the input 337 inflate decompresses as much data as possible, and stops when the input
337 buffer becomes empty or the output buffer becomes full. It may some 338 buffer becomes empty or the output buffer becomes full. It may introduce
338 introduce some output latency (reading input without producing any output) 339 some output latency (reading input without producing any output) except when
339 except when forced to flush. 340 forced to flush.
340 341
341 The detailed semantics are as follows. inflate performs one or both of the 342 The detailed semantics are as follows. inflate performs one or both of the
342 following actions: 343 following actions:
@@ -586,20 +587,28 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
586 The windowBits parameter is the base two logarithm of the maximum window 587 The windowBits parameter is the base two logarithm of the maximum window
587 size (the size of the history buffer). It should be in the range 8..15 for 588 size (the size of the history buffer). It should be in the range 8..15 for
588 this version of the library. The default value is 15 if inflateInit is used 589 this version of the library. The default value is 15 if inflateInit is used
589 instead. If a compressed stream with a larger window size is given as 590 instead. windowBits must be greater than or equal to the windowBits value
590 input, inflate() will return with the error code Z_DATA_ERROR instead of 591 provided to deflateInit2() while compressing, or it must be equal to 15 if
591 trying to allocate a larger window. 592 deflateInit2() was not used. If a compressed stream with a larger window
592 593 size is given as input, inflate() will return with the error code
593 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 594 Z_DATA_ERROR instead of trying to allocate a larger window.
594 determines the window size. inflate() will then process raw deflate data, 595
596 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
597 determines the window size. inflate() will then process raw deflate data,
595 not looking for a zlib or gzip header, not generating a check value, and not 598 not looking for a zlib or gzip header, not generating a check value, and not
596 looking for any check values for comparison at the end of the stream. This 599 looking for any check values for comparison at the end of the stream. This
597 is for use with other formats that use the deflate compressed data format 600 is for use with other formats that use the deflate compressed data format
598 such as zip. Those formats provide their own check values. If a custom 601 such as zip. Those formats provide their own check values. If a custom
599 format is developed using the raw deflate format for compressed data, it is 602 format is developed using the raw deflate format for compressed data, it is
600 recommended that a check value such as an adler32 or a crc32 be applied to 603 recommended that a check value such as an adler32 or a crc32 be applied to
601 the uncompressed data as is done in the zlib, gzip, and zip formats. For 604 the uncompressed data as is done in the zlib, gzip, and zip formats. For
602 most applications, the zlib format should be used as is. 605 most applications, the zlib format should be used as is. Note that comments
606 above on the use in deflateInit2() applies to the magnitude of windowBits.
607
608 windowBits can also be greater than 15 for optional gzip decoding. Add
609 32 to windowBits to enable zlib and gzip decoding with automatic header
610 detection, or add 16 to decode only the gzip format (the zlib format will
611 return a Z_DATA_ERROR).
603 612
604 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 613 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
605 memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative 614 memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
@@ -771,6 +780,45 @@ ZEXTERN int ZEXPORT inflateBackEnd(z_stream FAR *strm);
771 state was inconsistent. 780 state was inconsistent.
772*/ 781*/
773 782
783ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
784/* Return flags indicating compile-time options.
785
786 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
787 1.0: size of uInt
788 3.2: size of uLong
789 5.4: size of voidpf (pointers)
790 7.6: size of z_off_t
791
792 Debug options:
793 8: DEBUG
794 9-11: 0 (reserved)
795
796 One-time table building (smaller code, but not thread-safe if true):
797 12: BUILDFIXED -- build static block decoding tables when needed
798 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
799 14,15: 0 (reserved)
800
801 Library content (indicates missing functionality):
802 16: NO_DEFLATE -- gz* functions cannot compress (to avoid linking deflate
803 code when not needed)
804 17: NO_GUNZIP -- inflate can't detect and decode gzip streams, to avoid
805 linking crc code
806 18-19: 0 (reserved)
807
808 Operation variations (changes in library functionality):
809 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
810 21: FASTEST -- deflate algorithm with only one, lowest compression level
811 22,23: 0 (reserved)
812
813 The sprintf variant used by gzprintf (zero is best):
814 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
815 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
816 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
817
818 Remainder:
819 27-31: 0 (reserved)
820 */
821
774 822
775 /* utility functions */ 823 /* utility functions */
776 824
@@ -901,10 +949,10 @@ ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
901 control of the format string, as in fprintf. gzprintf returns the number of 949 control of the format string, as in fprintf. gzprintf returns the number of
902 uncompressed bytes actually written (0 in case of error). The number of 950 uncompressed bytes actually written (0 in case of error). The number of
903 uncompressed bytes written is limited to 4095. The caller should assure that 951 uncompressed bytes written is limited to 4095. The caller should assure that
904 this limit is not exceeded. If it is exceeded, then either gzprintf() will 952 this limit is not exceeded. If it is exceeded, then gzprintf() will return
905 return an error (0) with nothing written, or there will be a buffer overflow 953 return an error (0) with nothing written. In this case, there may also be a
906 with unpredictable consequences. The latter is possible only if zlib was 954 buffer overflow with unpredictable consequences, which is possible only if
907 compiled with insecure variants of printf, i.e. sprintf() or vsprintf() 955 zlib was compiled with the insecure functions sprintf() or vsprintf()
908 because the secure snprintf() or vsnprintf() functions were not available. 956 because the secure snprintf() or vsnprintf() functions were not available.
909*/ 957*/
910 958
@@ -936,6 +984,16 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
936 or -1 in case of end of file or error. 984 or -1 in case of end of file or error.
937*/ 985*/
938 986
987ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
988/*
989 Push one character back onto the stream to be read again later.
990 Only one character of push-back is allowed. gzungetc() returns the
991 character pushed, or -1 on failure. gzungetc() will fail if a
992 character has been pushed but not read yet, or if c is -1. The pushed
993 character will be discarded if the stream is repositioned with gzseek()
994 or gzrewind().
995*/
996
939ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 997ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
940/* 998/*
941 Flushes all pending output into the compressed file. The parameter 999 Flushes all pending output into the compressed file. The parameter
@@ -1002,6 +1060,13 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1002 to get the exact error code. 1060 to get the exact error code.
1003*/ 1061*/
1004 1062
1063ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1064/*
1065 Clears the error and end-of-file flags for file. This is analogous to the
1066 clearerr() function in stdio. This is useful for continuing to read a gzip
1067 file that is being written concurrently.
1068*/
1069
1005 /* checksum functions */ 1070 /* checksum functions */
1006 1071
1007/* 1072/*
@@ -1077,7 +1142,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
1077 ZLIB_VERSION, sizeof(z_stream)) 1142 ZLIB_VERSION, sizeof(z_stream))
1078 1143
1079 1144
1080#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) 1145#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1081 struct internal_state {int dummy;}; /* hack for buggy compilers */ 1146 struct internal_state {int dummy;}; /* hack for buggy compilers */
1082#endif 1147#endif
1083 1148
@@ -1089,4 +1154,4 @@ ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
1089} 1154}
1090#endif 1155#endif
1091 1156
1092#endif /* _ZLIB_H */ 1157#endif /* ZLIB_H */
diff --git a/zutil.c b/zutil.c
index 4a8118d..b8d11a1 100644
--- a/zutil.c
+++ b/zutil.c
@@ -7,7 +7,9 @@
7 7
8#include "zutil.h" 8#include "zutil.h"
9 9
10#ifndef NO_DUMMY_DECL
10struct internal_state {int dummy;}; /* for buggy compilers */ 11struct internal_state {int dummy;}; /* for buggy compilers */
12#endif
11 13
12#ifndef STDC 14#ifndef STDC
13extern void exit OF((int)); 15extern void exit OF((int));
@@ -31,6 +33,83 @@ const char * ZEXPORT zlibVersion()
31 return ZLIB_VERSION; 33 return ZLIB_VERSION;
32} 34}
33 35
36uLong ZEXPORT zlibCompileFlags()
37{
38 uLong flags;
39
40 flags = 0;
41 switch (sizeof(uInt)) {
42 case 2: break;
43 case 4: flags += 1; break;
44 case 8: flags += 2; break;
45 default: flags += 3;
46 }
47 switch (sizeof(uLong)) {
48 case 2: break;
49 case 4: flags += 1 << 2; break;
50 case 8: flags += 2 << 2; break;
51 default: flags += 3 << 2;
52 }
53 switch (sizeof(voidpf)) {
54 case 2: break;
55 case 4: flags += 1 << 4; break;
56 case 8: flags += 2 << 4; break;
57 default: flags += 3 << 4;
58 }
59 switch (sizeof(z_off_t)) {
60 case 2: break;
61 case 4: flags += 1 << 6; break;
62 case 8: flags += 2 << 6; break;
63 default: flags += 3 << 6;
64 }
65#ifdef DEBUG
66 flags += 1 << 8;
67#endif
68#ifdef BUILDFIXED
69 flags += 1 << 12;
70#endif
71#ifdef DYNAMIC_CRC_TABLE
72 flags += 1 << 13;
73#endif
74#ifdef NO_DEFLATE
75 flags += 1 << 16;
76#endif
77#ifdef NO_GUNZIP
78 flags += 1 << 17;
79#endif
80#ifdef PKZIP_BUG_WORKAROUND
81 flags += 1 << 20;
82#endif
83#ifdef FASTEST
84 flags += 1 << 21;
85#endif
86#ifdef STDC
87# ifdef NO_vsnprintf
88 flags += 1 << 25;
89# ifdef HAS_vsprintf_void
90 flags += 1 << 26;
91# endif
92# else
93# ifdef HAS_vsnprintf_void
94 flags += 1 << 26;
95# endif
96# endif
97#else
98 flags += 1 << 24;
99# ifdef NO_snprintf
100 flags += 1 << 25;
101# ifdef HAS_sprintf_void
102 flags += 1 << 26;
103# endif
104# else
105# ifdef HAS_snprintf_void
106 flags += 1 << 26;
107# endif
108# endif
109#endif
110 return flags;
111}
112
34#ifdef DEBUG 113#ifdef DEBUG
35 114
36# ifndef verbose 115# ifndef verbose
@@ -55,6 +134,10 @@ const char * ZEXPORT zError(err)
55 return ERR_MSG(err); 134 return ERR_MSG(err);
56} 135}
57 136
137#if defined(_WIN32_WCE)
138 /* does not exist on WCE */
139 int errno = 0;
140#endif
58 141
59#ifndef HAVE_MEMCPY 142#ifndef HAVE_MEMCPY
60 143
diff --git a/zutil.h b/zutil.h
index 91083ed..0eda40c 100644
--- a/zutil.h
+++ b/zutil.h
@@ -10,9 +10,10 @@
10 10
11/* @(#) $Id$ */ 11/* @(#) $Id$ */
12 12
13#ifndef _Z_UTIL_H 13#ifndef ZUTIL_H
14#define _Z_UTIL_H 14#define ZUTIL_H
15 15
16#define ZLIB_INTERNAL
16#include "zlib.h" 17#include "zlib.h"
17 18
18#ifdef STDC 19#ifdef STDC
@@ -134,7 +135,11 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
134#endif 135#endif
135 136
136#if (defined(_MSC_VER) && (_MSC_VER > 600)) 137#if (defined(_MSC_VER) && (_MSC_VER > 600))
137# define fdopen(fd,type) _fdopen(fd,type) 138# if defined(_WIN32_WCE)
139# define fdopen(fd,mode) NULL /* No fdopen() */
140# else
141# define fdopen(fd,type) _fdopen(fd,type)
142# endif
138#endif 143#endif
139 144
140 145
@@ -157,7 +162,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
157# endif 162# endif
158# endif 163# endif
159#endif 164#endif
160#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED) 165#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(HAVE_VSNPRINTF)
161# ifdef MSDOS 166# ifdef MSDOS
162 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 167 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
163 but for now we just assume it doesn't. */ 168 but for now we just assume it doesn't. */
@@ -239,4 +244,4 @@ void zcfree OF((voidpf opaque, voidpf ptr));
239#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 244#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
240#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 245#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
241 246
242#endif /* _Z_UTIL_H */ 247#endif /* ZUTIL_H */