]> git.lizzy.rs Git - zlib.git/commitdiff
zlib 1.2.0.2 v1.2.0.2
authorMark Adler <madler@alumni.caltech.edu>
Sat, 10 Sep 2011 06:22:10 +0000 (23:22 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sat, 10 Sep 2011 06:22:10 +0000 (23:22 -0700)
58 files changed:
ChangeLog
FAQ
Makefile
Makefile.in
README
adler32.c
aix/README [deleted file]
aix/configure.diff [deleted file]
aix/mkexps [deleted file]
algorithm.txt
compress.c
configure
contrib/iostream3/README [new file with mode: 0644]
contrib/iostream3/TODO [new file with mode: 0644]
contrib/iostream3/test.cc [new file with mode: 0644]
contrib/iostream3/zfstream.cc [new file with mode: 0644]
contrib/iostream3/zfstream.h [new file with mode: 0644]
contrib/minizip/ChangeLogUnzip
contrib/minizip/Makefile
contrib/minizip/crypt.h
contrib/minizip/ioapi.c
contrib/minizip/ioapi.h
contrib/minizip/iowin32.c
contrib/minizip/iowin32.h
contrib/minizip/miniunz.c
contrib/minizip/minizip.c
contrib/minizip/unzip.c
contrib/minizip/unzip.h
contrib/minizip/zconf.h [new file with mode: 0644]
contrib/minizip/zip.c
contrib/minizip/zip.h
contrib/vstudio/readme.txt
contrib/vstudio/vc15_16/zlib16.def
contrib/vstudio/vc15_16/zlib16.rc
contrib/vstudio/vc70_32/zlib.rc
contrib/vstudio/vc70_32/zlibvc.def
contrib/zlib_dll_FAQ.txt [new file with mode: 0644]
crc32.c
deflate.c
deflate.h
example.c
gzio.c
infback.c
inflate.c
inflate.h
inftrees.c
minigzip.c
old/zlib.3 [deleted file]
uncompr.c
win32/Makefile.gcc
win32/Makefile.msc
win32/zlib.def
zconf.h
zconf.in.h
zlib.3 [new file with mode: 0644]
zlib.h
zutil.c
zutil.h

index 55c29c12ddb7513064fc915b8779bf37d495bd85..af4a65591fca99dca0aeee74f063f36874f98fe2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,39 @@
 
                 ChangeLog file for zlib
+Changes in 1.2.0.2 (13 July 2003)
+- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
+- Attempt to avoid warnings in crc32.c for pointer-int conversion
+- Add AIX to configure, remove aix directory [Bakker]
+- Add some casts to minigzip.c
+- Improve checking after insecure sprintf() or vsprintf() calls
+- Remove #elif's from crc32.c
+- Change leave label to inf_leave in inflate.c and infback.c to avoid
+  library conflicts
+- Remove inflate gzip decoding by default--only enable gzip decoding by
+  special request for stricter backward compatibility
+- Add zlibCompileFlags() function to return compilation information
+- More typecasting in deflate.c to avoid warnings
+- Remove leading underscore from _Capital #defines [Truta]
+- Fix configure to link shared library when testing
+- Add some Windows CE target adjustments [Mai]
+- Remove #define ZLIB_DLL in zconf.h [Vollant]
+- Add zlib.3 [Rodgers]
+- Update RFC URL in deflate.c and algorithm.txt [Mai]
+- Add zlib_dll_FAQ.txt to contrib [Truta]
+- Add UL to some constants [Truta]
+- Update minizip and vstudio [Vollant]
+- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
+- Expand use of NO_DUMMY_DECL to avoid all dummy structures
+- Added iostream3 to contrib [Schwardt]
+- Replace rewind() with fseek() for WinCE [Truta]
+- Improve setting of zlib format compression level flags
+    - Report 0 for huffman and rle strategies and for level == 0 or 1
+    - Report 2 only for level == 6
+- Only deal with 64K limit when necessary at compile time [Truta]
+- Allow TOO_FAR check to be turned off at compile time [Truta]
+- Added gzclearerr() function [Souza]
+- Added gzungetc() function
+
 Changes in 1.2.0.1 (17 March 2003)
 - Add Z_RLE strategy for run-length encoding [Truta]
     - When Z_RLE requested, restrict matches to distance one
@@ -12,7 +46,7 @@ Changes in 1.2.0.1 (17 March 2003)
     - Include additional header file on VMS for off_t typedef
 - Try to use _vsnprintf where it supplants vsprintf [Vollant]
 - Add some casts in inffast.c
-- Enchance comments in zlib.h on what happens if the gzprintf() tries to
+- Enchance comments in zlib.h on what happens if gzprintf() tries to
   write more than 4095 bytes before compression
 - Remove unused state from inflateBackEnd()
 - Remove exit(0) from minigzip.c, example.c
diff --git a/FAQ b/FAQ
index 2a8247c58505410089a19283f0b3529d3d95b867..b439bd942fef0a6e92b913ef6835ea0acee17883 100644 (file)
--- a/FAQ
+++ b/FAQ
@@ -228,7 +228,8 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
     hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
     normally be the case, then there is no vulnerability. The ./configure
     script will display warnings if an insecure variation of sprintf() will
-    be used by gzprintf().
+    be used by gzprintf(). Also the zlibCompileFlags() functions will return
+    information on what variant of sprintf() is used by gzprintf().
 
     If you don't have snprintf() or vsnprintf() and would like one, you can
     find a portable implementation here:
index 05540e94d5c483d7b616cffc81da8f92aa69f77a..6fbe392291eae4f245f11c7668b88c622ad4c266 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
 LDSHARED=$(CC)
 CPP=$(CC) -E
 
-VER=1.2.0.1
+VER=1.2.0.2
 LIBS=libz.a
 SHAREDLIB=libz.so
 
index 05540e94d5c483d7b616cffc81da8f92aa69f77a..6fbe392291eae4f245f11c7668b88c622ad4c266 100644 (file)
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
 LDSHARED=$(CC)
 CPP=$(CC) -E
 
-VER=1.2.0.1
+VER=1.2.0.2
 LIBS=libz.a
 SHAREDLIB=libz.so
 
diff --git a/README b/README
index 8ac79a171d8440b0138c5b1724d11b1ba66b36dd..cc489ac089b686037592c85d2efd96e85aaf044e 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 ZLIB DATA COMPRESSION LIBRARY
 
-zlib 1.2.0.1 is a general purpose data compression library.  All the code is
+zlib 1.2.0.2 is a general purpose data compression library.  All the code is
 thread safe.  The data format used by the zlib library is described by RFCs
 (Request for Comments) 1950 to 1952 in the files
 http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
@@ -34,7 +34,7 @@ Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
 issue of  Dr. Dobb's Journal; a copy of the article is available in
 http://dogma.net/markn/articles/zlibtool/zlibtool.htm
 
-The changes made in version 1.2.0.1 are documented in the file ChangeLog.
+The changes made in version 1.2.0.2 are documented in the file ChangeLog.
 
 Unsupported third party contributions are provided in directory "contrib".
 
index 28c65ba9dda107c9e108f1bf54f7e680be635edf..550636341f470641ea4e797c8cdc7b4b9a09dfe8 100644 (file)
--- a/adler32.c
+++ b/adler32.c
@@ -5,6 +5,7 @@
 
 /* @(#) $Id$ */
 
+#define ZLIB_INTERNAL
 #include "zlib.h"
 
 #define BASE 65521L /* largest prime smaller than 65536 */
diff --git a/aix/README b/aix/README
deleted file mode 100644 (file)
index 235ba59..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-To make a shared library:
-
-1. Compile a static library
-2. Use mkexps on that to create libz.exp
-3. Apply the configure.diff patch to configure
-4. Run the new configure to make a new Makefile
-5. Use the new Makefile to make the shared library
-
-Courtesy of dbakker@arrayasolutions.com
diff --git a/aix/configure.diff b/aix/configure.diff
deleted file mode 100644 (file)
index c699129..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-*** ../orig/zlib-1.1.4/configure       Wed Jul  8 14:19:35 1998
---- configure  Sun Feb  9 11:11:19 2003
-***************
-*** 18,23 ****
---- 18,24 ----
-  # If you have problems, try without defining CC and CFLAGS before reporting
-  # an error.
-  
-+ LDFLAGS="-L. -lz"
-  LIBS=libz.a
-  SHAREDLIB=libz.so
-  VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
-***************
-*** 116,121 ****
---- 117,128 ----
-            SFLAGS=${CFLAGS-"-Kconform_pic -O"}
-            CFLAGS=${CFLAGS-"-O"}
-            LDSHARED=${LDSHARED-"cc -G"};;
-+   AIX*)     
-+           SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
-+           CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
-+           LDTESTSHARED=${LDSHARED-"cc -G"}
-+           LDSHAREDFLAGS="-L. libz.so"
-+           LDSHARED=${LDSHARED-"cc -G"};;
-    # send working options for other systems to support@gzip.org
-    *)         SFLAGS=${CFLAGS-"-O"}
-            CFLAGS=${CFLAGS-"-O"}
-***************
-*** 127,135 ****
-    echo Checking for shared library support...
-    # we must test in two steps (cc then ld), required at least on SunOS 4.x
-    if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
-!      test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
-      CFLAGS="$SFLAGS"
-      LIBS="$SHAREDLIB.$VER"
-      echo Building shared library $SHAREDLIB.$VER with $CC.
-    elif test -z "$old_cc" -a -z "$old_cflags"; then
-      echo No shared library suppport.
---- 134,143 ----
-    echo Checking for shared library support...
-    # we must test in two steps (cc then ld), required at least on SunOS 4.x
-    if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
-!      test "`($LDTESTSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
-      CFLAGS="$SFLAGS"
-      LIBS="$SHAREDLIB.$VER"
-+      LDFLAGS="$LDSHAREDFLAGS"
-      echo Building shared library $SHAREDLIB.$VER with $CC.
-    elif test -z "$old_cc" -a -z "$old_cflags"; then
-      echo No shared library suppport.
-***************
-*** 209,212 ****
---- 217,221 ----
-  /^exec_prefix *=/s%=.*%=$exec_prefix%
-  /^libdir *=/s%=.*%=$libdir%
-  /^includedir *=/s%=.*%=$includedir%
-+ /^LDFLAGS *=/s%=.*%=$LDFLAGS%
-  " > Makefile
diff --git a/aix/mkexps b/aix/mkexps
deleted file mode 100644 (file)
index 6c55eae..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/ksh
-#
-# mkexps - make export list
-# This program creates an export list by combining all the "." and normal names
-# into one list.
-#
-if [[ "$#" -ne 1 ]]
-then
-    print "Usage: mkexps ArchiveFile"
-    exit -2
-fi
-if [[ ! -f $1 ]]
-then
-    print "mkexps: Cannot open file \"$1\""
-    exit -1
-fi
-
-dump -g $1 | awk '
-BEGIN {
-        top = 1
-}
-/^[ ]*[0-9][0-9]*/ {
-    if ( (n = index( $2, "." )) > 0 ) {
-        export_array[ top++ ] = substr( $2, n+1, length( $2 ))
-    }
-    else {
-       export_array[ top++ ] = $2
-    }
-}
-
-END {
-    for ( i = 1; i < top; i++ )
-    {
-       print export_array[ i ]
-    }
-
-}' | sort | uniq
index f64f7c35942ebcca9184bd744d2e76edaf921827..a049765458d2b5892f743133e3742e3a7727820e 100644 (file)
@@ -206,4 +206,4 @@ Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
 pp. 337-343.
 
 ``DEFLATE Compressed Data Format Specification'' available in
-ftp://ds.internic.net/rfc/rfc1951.txt
+http://www.ietf.org/rfc/rfc1951.txt
index f10e234874c1fa62e6a6f8a3e21ea79272f71096..fbee08598a5b2e8fbdd730fa96f7327d63ba627a 100644 (file)
@@ -5,6 +5,7 @@
 
 /* @(#) $Id$ */
 
+#define ZLIB_INTERNAL
 #include "zlib.h"
 
 /* ===========================================================================
index 51ef10ff12ffc46c6faa292f3b40bd83da3f788d..68bfc88b8b0759a133bb805518a288efe7488d49 100755 (executable)
--- a/configure
+++ b/configure
@@ -19,6 +19,7 @@
 # an error.
 
 LIBS=libz.a
+LDFLAGS="-L. ${LIBS}"
 SHAREDLIB=libz.so
 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
 AR=${AR-"ar rc"}
@@ -53,6 +54,10 @@ case "$1" in
     esac
 done
 
+if [ $shared -eq 1 ]; then
+  LDFLAGS="-L. ${SHAREDLIB}"
+fi
+
 test=ztest$$
 cat > $test.c <<EOF
 extern int getchar();
@@ -123,6 +128,10 @@ else
             SFLAGS=${CFLAGS-"-KPIC -O"}
             CFLAGS=${CFLAGS-"-O"}
             LDSHARED=${LDSHARED-"cc -G"};;
+  AIX*)  # Courtesy of dbakker@arrayasolutions.com
+            SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
+            CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
+            LDSHARED=${LDSHARED-"xlc -G"};;
   # send working options for other systems to support@gzip.org
   *)         SFLAGS=${CFLAGS-"-O"}
             CFLAGS=${CFLAGS-"-O"}
@@ -422,4 +431,5 @@ sed < Makefile.in "
 /^exec_prefix *=/s%=.*%=$exec_prefix%
 /^libdir *=/s%=.*%=$libdir%
 /^includedir *=/s%=.*%=$includedir%
+/^LDFLAGS *=/s%=.*%=$LDFLAGS%
 " > Makefile
diff --git a/contrib/iostream3/README b/contrib/iostream3/README
new file mode 100644 (file)
index 0000000..6f73d58
--- /dev/null
@@ -0,0 +1,35 @@
+These classes provide a C++ stream interface to the zlib library. It allows you
+to do things like:
+
+  gzofstream outf("blah.gz");
+  outf << "These go into the gzip file " << 123 << endl;
+  
+It does this by deriving a specialized stream buffer for gzipped files, which is
+the way Stroustrup would have done it. :-> 
+
+The gzifstream and gzofstream classes were originally written by Kevin Ruland
+and made available in the zlib contrib/iostream directory. The older version still
+compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of 
+this version.
+
+The new classes are as standard-compliant as possible, closely following the 
+approach of the standard library's fstream classes. It compiles under gcc versions 
+3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard 
+library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs 
+from the previous one in the following respects:
+- added showmanyc
+- added setbuf, with support for unbuffered output via setbuf(0,0)
+- a few bug fixes of stream behavior
+- gzipped output file opened with default compression level instead of maximum level
+- setcompressionlevel()/strategy() members replaced by single setcompression()
+
+The code is provided "as is", with the permission to use, copy, modify, distribute 
+and sell it for any purpose without fee.
+
+Ludwig Schwardt
+<schwardt@sun.ac.za>
+
+DSP Lab
+Electrical & Electronic Engineering Department
+University of Stellenbosch
+South Africa
diff --git a/contrib/iostream3/TODO b/contrib/iostream3/TODO
new file mode 100644 (file)
index 0000000..4578326
--- /dev/null
@@ -0,0 +1,17 @@
+Possible upgrades to gzfilebuf:
+
+- The ability to do putback (e.g. putbackfail)
+
+- The ability to seek (zlib supports this, but could be slow/tricky)
+
+- Simultaneous read/write access (does it make sense?)
+
+- Support for ios_base::ate open mode
+
+- Locale support?
+
+- Check public interface to see which calls give problems
+  (due to dependence on library internals)
+
+- Override operator<<(ostream&, gzfilebuf*) to allow direct copying 
+  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 (file)
index 0000000..9ffa8be
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Test program for gzifstream and gzofstream
+ * 
+ * by Ludwig Schwardt <schwardt@sun.ac.za>
+ * original version by Kevin Ruland <kevin@rodin.wustl.edu>
+ */
+
+#include "zfstream.h"
+#include <iostream>      // for cout
+
+int main() {
+
+  gzofstream outf;
+  gzifstream inf;
+  char buf[80];
+  
+  outf.open("test1.txt.gz");
+  outf << "The quick brown fox sidestepped the lazy canine\n" 
+       << 1.3 << "\nPlan " << 9 << std::endl;
+  outf.close();
+  std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n"
+            << "The quick brown fox sidestepped the lazy canine\n"
+            << 1.3 << "\nPlan " << 9 << std::endl;
+  
+  std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n";
+  inf.open("test1.txt.gz");
+  while (inf.getline(buf,80,'\n')) {
+    std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
+  }
+  inf.close();
+
+  outf.rdbuf()->pubsetbuf(0,0);
+  outf.open("test2.txt.gz");
+  outf << setcompression(Z_NO_COMPRESSION)
+       << "The quick brown fox sidestepped the lazy canine\n"
+       << 1.3 << "\nPlan " << 9 << std::endl;
+  outf.close();
+  std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form";
+
+  std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n";
+  inf.rdbuf()->pubsetbuf(0,0);
+  inf.open("test2.txt.gz");
+  while (inf.getline(buf,80,'\n')) {
+    std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
+  }
+  inf.close();
+
+  return 0;
+
+}
diff --git a/contrib/iostream3/zfstream.cc b/contrib/iostream3/zfstream.cc
new file mode 100644 (file)
index 0000000..24d15fa
--- /dev/null
@@ -0,0 +1,479 @@
+/*
+ * A C++ I/O streams interface to the zlib gz* functions
+ * 
+ * by Ludwig Schwardt <schwardt@sun.ac.za>
+ * original version by Kevin Ruland <kevin@rodin.wustl.edu>
+ * 
+ * This version is standard-compliant and compatible with gcc 3.x.
+ */
+
+#include "zfstream.h"
+#include <cstring>          // for strcpy, strcat, strlen (mode strings)
+#include <cstdio>           // for BUFSIZ
+
+// Internal buffer sizes (default and "unbuffered" versions)
+#define BIGBUFSIZE BUFSIZ
+#define SMALLBUFSIZE 1
+
+/*****************************************************************************/
+
+// Default constructor
+gzfilebuf::gzfilebuf() 
+: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false), 
+  buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true)
+{
+  // No buffers to start with
+  this->disable_buffer();
+}
+
+// Destructor
+gzfilebuf::~gzfilebuf() 
+{
+  // Sync output buffer and close only if responsible for file
+  // (i.e. attached streams should be left open at this stage)
+  this->sync();
+  if (own_fd) 
+    this->close();
+  // Make sure internal buffer is deallocated
+  this->disable_buffer();
+}
+
+// Set compression level and strategy
+int
+gzfilebuf::setcompression(int comp_level,
+                         int comp_strategy)
+{
+  return gzsetparams(file, comp_level, comp_strategy);
+}
+
+// Open gzipped file
+gzfilebuf* 
+gzfilebuf::open(const char *name, 
+               std::ios_base::openmode mode)
+{
+  // Fail if file already open
+  if (this->is_open()) 
+    return NULL;
+  // Don't support simultaneous read/write access (yet)
+  if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) 
+    return NULL;
+  
+  // Build mode string for gzopen and check it [27.8.1.3.2]
+  char char_mode[6] = "\0\0\0\0\0";
+  if (!this->open_mode(mode, char_mode))
+    return NULL;
+  
+  // Attempt to open file
+  if ((file = gzopen(name, char_mode)) == NULL) 
+    return NULL;
+
+  // On success, allocate internal buffer and set flags
+  this->enable_buffer();
+  io_mode = mode;
+  own_fd = true;
+  return this;
+}
+
+// Attach to gzipped file
+gzfilebuf*
+gzfilebuf::attach(int fd,
+                 std::ios_base::openmode mode) 
+{
+  // Fail if file already open
+  if (this->is_open()) 
+    return NULL;
+  // Don't support simultaneous read/write access (yet)
+  if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) 
+    return NULL;
+  
+  // Build mode string for gzdopen and check it [27.8.1.3.2]
+  char char_mode[6] = "\0\0\0\0\0";
+  if (!this->open_mode(mode, char_mode))
+    return NULL;
+  
+  // Attempt to attach to file
+  if ((file = gzdopen(fd, char_mode)) == NULL)
+    return NULL;
+  
+  // On success, allocate internal buffer and set flags
+  this->enable_buffer();
+  io_mode = mode;
+  own_fd = false;
+  return this;
+}
+
+// Close gzipped file
+gzfilebuf*
+gzfilebuf::close() 
+{
+  // Fail immediately if no file is open
+  if (!this->is_open())
+    return NULL;
+  // Assume success
+  gzfilebuf* retval = this;
+  // Attempt to sync and close gzipped file
+  if (this->sync() == -1)
+    retval = NULL;
+  if (gzclose(file) < 0)
+    retval = NULL;
+  // File is now gone anyway (postcondition [27.8.1.3.8])
+  file = NULL;
+  own_fd = false;
+  // Destroy internal buffer if it exists
+  this->disable_buffer();
+  return retval;
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+// Convert int open mode to mode string
+bool 
+gzfilebuf::open_mode(std::ios_base::openmode mode, 
+                    char* c_mode) const
+{
+  bool testb = mode & std::ios_base::binary;
+  bool testi = mode & std::ios_base::in;
+  bool testo = mode & std::ios_base::out;
+  bool testt = mode & std::ios_base::trunc;
+  bool testa = mode & std::ios_base::app;
+      
+  // Check for valid flag combinations - see [27.8.1.3.2] (Table 92)
+  // Original zfstream hardcoded the compression level to maximum here...
+  // Double the time for less than 1% size improvement seems
+  // excessive though - keeping it at the default level
+  // To change back, just append "9" to the next three mode strings
+  if (!testi && testo && !testt && !testa)
+    strcpy(c_mode, "w");
+  if (!testi && testo && !testt && testa)
+    strcpy(c_mode, "a");
+  if (!testi && testo && testt && !testa)
+    strcpy(c_mode, "w");
+  if (testi && !testo && !testt && !testa)
+    strcpy(c_mode, "r");
+  // No read/write mode yet
+//  if (testi && testo && !testt && !testa)
+//    strcpy(c_mode, "r+");
+//  if (testi && testo && testt && !testa)
+//    strcpy(c_mode, "w+");
+
+  // Mode string should be empty for invalid combination of flags    
+  if (strlen(c_mode) == 0)
+    return false;
+  if (testb)
+    strcat(c_mode, "b");
+  return true;
+}
+
+// Determine number of characters in internal get buffer
+std::streamsize 
+gzfilebuf::showmanyc()
+{
+  // Calls to underflow will fail if file not opened for reading
+  if (!this->is_open() || !(io_mode & std::ios_base::in))
+    return -1;
+  // Make sure get area is in use
+  if (this->gptr() && (this->gptr() < this->egptr()))
+    return std::streamsize(this->egptr() - this->gptr());
+  else
+    return 0;
+}
+
+// Fill get area from gzipped file
+gzfilebuf::int_type
+gzfilebuf::underflow() 
+{
+  // If something is left in the get area by chance, return it
+  // (this shouldn't normally happen, as underflow is only supposed 
+  // to be called when gptr >= egptr, but it serves as error check)
+  if (this->gptr() && (this->gptr() < this->egptr()))
+    return traits_type::to_int_type(*(this->gptr()));
+
+  // If the file hasn't been opened for reading, produce error
+  if (!this->is_open() || !(io_mode & std::ios_base::in))
+    return traits_type::eof();
+
+  // Attempt to fill internal buffer from gzipped file
+  // (buffer must be guaranteed to exist...)
+  int bytes_read = gzread(file, buffer, buffer_size);
+  // Indicates error or EOF
+  if (bytes_read <= 0)
+  {
+    // Reset get area
+    this->setg(buffer, buffer, buffer);
+    return traits_type::eof();
+  }
+  // Make all bytes read from file available as get area
+  this->setg(buffer, buffer, buffer + bytes_read);
+  
+  // Return next character in get area
+  return traits_type::to_int_type(*(this->gptr()));
+}
+
+// Write put area to gzipped file
+gzfilebuf::int_type
+gzfilebuf::overflow(int_type c) 
+{
+  // Determine whether put area is in use
+  if (this->pbase())
+  {
+    // Double-check pointer range
+    if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
+      return traits_type::eof();
+    // Add extra character to buffer if not EOF
+    if (!traits_type::eq_int_type(c, traits_type::eof()))
+    {
+      *(this->pptr()) = traits_type::to_char_type(c);
+      this->pbump(1);
+    }
+    // Number of characters to write to file
+    int bytes_to_write = this->pptr() - this->pbase();
+    // Overflow doesn't fail if nothing is to be written
+    if (bytes_to_write > 0)
+    {
+      // If the file hasn't been opened for writing, produce error
+      if (!this->is_open() || !(io_mode & std::ios_base::out))
+       return traits_type::eof();
+      // If gzipped file won't accept all bytes written to it, fail
+      if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write)
+       return traits_type::eof();
+      // Reset next pointer to point to pbase on success
+      this->pbump(-bytes_to_write);
+    }
+  }
+  // Write extra character to file if not EOF
+  else if (!traits_type::eq_int_type(c, traits_type::eof()))
+  {
+    // If the file hasn't been opened for writing, produce error
+    if (!this->is_open() || !(io_mode & std::ios_base::out))
+      return traits_type::eof();
+    // Impromptu char buffer (allows "unbuffered" output)
+    char_type last_char = traits_type::to_char_type(c);
+    // If gzipped file won't accept this character, fail
+    if (gzwrite(file, &last_char, 1) != 1)
+      return traits_type::eof();      
+  }
+
+  // If you got here, you have succeeded (even if c was EOF)
+  // The return value should therefore be non-EOF
+  if (traits_type::eq_int_type(c, traits_type::eof()))
+    return traits_type::not_eof(c);
+  else
+    return c;
+}
+
+// Assign new buffer
+std::streambuf* 
+gzfilebuf::setbuf(char_type* p,
+                 std::streamsize n)
+{
+  // First make sure stuff is sync'ed, for safety
+  if (this->sync() == -1)
+    return NULL;
+  // If buffering is turned off on purpose via setbuf(0,0), still allocate one...
+  // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at
+  // least a buffer of size 1 (very inefficient though, therefore make it bigger?)
+  // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems)
+  if (!p || !n)
+  {
+    // Replace existing buffer (if any) with small internal buffer
+    this->disable_buffer();
+    buffer = NULL;
+    buffer_size = 0;
+    own_buffer = true;
+    this->enable_buffer();
+  }
+  else
+  {
+    // Replace existing buffer (if any) with external buffer
+    this->disable_buffer();
+    buffer = p;
+    buffer_size = n;
+    own_buffer = false;
+    this->enable_buffer();
+  }
+  return this;
+}
+
+// Write put area to gzipped file (i.e. ensures that put area is empty)
+int 
+gzfilebuf::sync() 
+{
+  return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0;
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+// Allocate internal buffer
+void 
+gzfilebuf::enable_buffer() 
+{
+  // If internal buffer required, allocate one
+  if (own_buffer && !buffer) 
+  {
+    // Check for buffered vs. "unbuffered"
+    if (buffer_size > 0)
+    {
+      // Allocate internal buffer
+      buffer = new char_type[buffer_size];
+      // Get area starts empty and will be expanded by underflow as need arises
+      this->setg(buffer, buffer, buffer);
+      // Setup entire internal buffer as put area.
+      // The one-past-end pointer actually points to the last element of the buffer,
+      // so that overflow(c) can safely add the extra character c to the sequence.
+      // These pointers remain in place for the duration of the buffer
+      this->setp(buffer, buffer + buffer_size - 1);
+    }
+    else
+    {
+      // Even in "unbuffered" case, (small?) get buffer is still required
+      buffer_size = SMALLBUFSIZE;
+      buffer = new char_type[buffer_size];
+      this->setg(buffer, buffer, buffer);
+      // "Unbuffered" means no put buffer
+      this->setp(0, 0);
+    }
+  }
+  else
+  {
+    // If buffer already allocated, reset buffer pointers just to make sure no 
+    // stale chars are lying around
+    this->setg(buffer, buffer, buffer);
+    this->setp(buffer, buffer + buffer_size - 1);
+  }  
+}
+
+// Destroy internal buffer
+void 
+gzfilebuf::disable_buffer() 
+{
+  // If internal buffer exists, deallocate it
+  if (own_buffer && buffer)
+  {
+    // Preserve unbuffered status by zeroing size
+    if (!this->pbase())
+      buffer_size = 0;
+    delete[] buffer;
+    buffer = NULL;
+    this->setg(0, 0, 0);
+    this->setp(0, 0);
+  }
+  else
+  {
+    // Reset buffer pointers to initial state if external buffer exists
+    this->setg(buffer, buffer, buffer);
+    if (buffer)
+      this->setp(buffer, buffer + buffer_size - 1);
+    else
+      this->setp(0, 0);
+  }
+}
+
+/*****************************************************************************/
+
+// Default constructor initializes stream buffer
+gzifstream::gzifstream() 
+: std::istream(NULL), sb()
+{ this->init(&sb); }
+
+// Initialize stream buffer and open file
+gzifstream::gzifstream(const char* name,
+                      std::ios_base::openmode mode)
+: std::istream(NULL), sb()
+{
+  this->init(&sb);
+  this->open(name, mode);
+}
+
+// Initialize stream buffer and attach to file
+gzifstream::gzifstream(int fd,
+                      std::ios_base::openmode mode)
+: std::istream(NULL), sb()
+{
+  this->init(&sb);
+  this->attach(fd, mode);
+}
+
+// Open file and go into fail() state if unsuccessful
+void 
+gzifstream::open(const char* name, 
+                std::ios_base::openmode mode)
+{
+  if (!sb.open(name, mode | std::ios_base::in))
+    this->setstate(std::ios_base::failbit);
+  else
+    this->clear();
+}
+
+// Attach to file and go into fail() state if unsuccessful
+void 
+gzifstream::attach(int fd, 
+                  std::ios_base::openmode mode)
+{
+  if (!sb.attach(fd, mode | std::ios_base::in))
+    this->setstate(std::ios_base::failbit);
+  else
+    this->clear();
+}
+
+// Close file
+void 
+gzifstream::close()
+{
+  if (!sb.close())
+    this->setstate(std::ios_base::failbit);
+}
+
+/*****************************************************************************/
+
+// Default constructor initializes stream buffer
+gzofstream::gzofstream() 
+: std::ostream(NULL), sb()
+{ this->init(&sb); }
+
+// Initialize stream buffer and open file
+gzofstream::gzofstream(const char* name,
+                      std::ios_base::openmode mode)
+: std::ostream(NULL), sb()
+{
+  this->init(&sb);
+  this->open(name, mode);
+}
+
+// Initialize stream buffer and attach to file
+gzofstream::gzofstream(int fd,
+                      std::ios_base::openmode mode)
+: std::ostream(NULL), sb()
+{
+  this->init(&sb);
+  this->attach(fd, mode);
+}
+
+// Open file and go into fail() state if unsuccessful
+void 
+gzofstream::open(const char* name, 
+                std::ios_base::openmode mode)
+{
+  if (!sb.open(name, mode | std::ios_base::out))
+    this->setstate(std::ios_base::failbit);
+  else
+    this->clear();
+}
+
+// Attach to file and go into fail() state if unsuccessful
+void 
+gzofstream::attach(int fd, 
+                  std::ios_base::openmode mode)
+{
+  if (!sb.attach(fd, mode | std::ios_base::out))
+    this->setstate(std::ios_base::failbit);
+  else
+    this->clear();
+}
+
+// Close file
+void 
+gzofstream::close()
+{
+  if (!sb.close())
+    this->setstate(std::ios_base::failbit);
+}
diff --git a/contrib/iostream3/zfstream.h b/contrib/iostream3/zfstream.h
new file mode 100644 (file)
index 0000000..ad76e8b
--- /dev/null
@@ -0,0 +1,466 @@
+/*
+ * A C++ I/O streams interface to the zlib gz* functions
+ * 
+ * by Ludwig Schwardt <schwardt@sun.ac.za>
+ * original version by Kevin Ruland <kevin@rodin.wustl.edu>
+ * 
+ * This version is standard-compliant and compatible with gcc 3.x.
+ */
+
+#ifndef ZFSTREAM_H
+#define ZFSTREAM_H
+
+#include <istream>  // not iostream, since we don't need cin/cout
+#include <ostream>
+#include "zlib.h"
+
+/*****************************************************************************/
+
+/**
+ *  @brief  Gzipped file stream buffer class.
+ *
+ *  This class implements basic_filebuf for gzipped files. It doesn't yet support
+ *  seeking (allowed by zlib but slow/limited), putback and read/write access 
+ *  (tricky). Otherwise, it attempts to be a drop-in replacement for the standard 
+ *  file streambuf.
+*/
+class gzfilebuf : public std::streambuf 
+{
+public:   
+  //  Default constructor.
+  gzfilebuf();
+  
+  //  Destructor.
+  virtual 
+  ~gzfilebuf();
+
+  /**
+   *  @brief  Set compression level and strategy on the fly.
+   *  @param  comp_level  Compression level (see zlib.h for allowed values) 
+   *  @param  comp_strategy  Compression strategy (see zlib.h for allowed values) 
+   *  @return  Z_OK on success, Z_STREAM_ERROR otherwise.
+   * 
+   *  Unfortunately, these parameters cannot be modified separately, as the
+   *  previous zfstream version assumed. Since the strategy is seldom changed,
+   *  it can default and setcompression(level) then becomes like the old
+   *  setcompressionlevel(level).
+  */
+  int 
+  setcompression(int comp_level, 
+                int comp_strategy = Z_DEFAULT_STRATEGY);
+   
+  /**
+   *  @brief  Check if file is open.
+   *  @return  True if file is open.
+  */
+  bool 
+  is_open() const { return (file != NULL); }
+   
+  /**
+   *  @brief  Open gzipped file.
+   *  @param  name  File name.
+   *  @param  mode  Open mode flags.
+   *  @return  @c this on success, NULL on failure.
+  */
+  gzfilebuf* 
+  open(const char* name, 
+       std::ios_base::openmode mode);
+   
+  /**
+   *  @brief  Attach to already open gzipped file.
+   *  @param  fd  File descriptor.
+   *  @param  mode  Open mode flags.
+   *  @return  @c this on success, NULL on failure.
+  */
+  gzfilebuf* 
+  attach(int fd, 
+        std::ios_base::openmode mode);
+   
+  /**
+   *  @brief  Close gzipped file.
+   *  @return  @c this on success, NULL on failure.
+  */
+  gzfilebuf* 
+  close();
+   
+protected:
+  /**
+   *  @brief  Convert ios open mode int to mode string used by zlib.
+   *  @return  True if valid mode flag combination.
+  */
+  bool 
+  open_mode(std::ios_base::openmode mode, 
+           char* c_mode) const;
+  
+  /**
+   *  @brief  Number of characters available in stream buffer.
+   *  @return  Number of characters.
+   * 
+   *  This indicates number of characters in get area of stream buffer.
+   *  These characters can be read without accessing the gzipped file.
+  */
+  virtual std::streamsize
+  showmanyc();
+  
+  /**
+   *  @brief  Fill get area from gzipped file.
+   *  @return  First character in get area on success, EOF on error.
+   * 
+   *  This actually reads characters from gzipped file to stream
+   *  buffer. Always buffered.
+  */
+  virtual int_type
+  underflow();
+   
+  /**
+   *  @brief  Write put area to gzipped file.
+   *  @param  c  Extra character to add to buffer contents.
+   *  @return  Non-EOF on success, EOF on error.
+   * 
+   *  This actually writes characters in stream buffer to 
+   *  gzipped file. With unbuffered output this is done one 
+   *  character at a time.
+  */ 
+  virtual int_type 
+  overflow(int_type c = traits_type::eof());
+    
+  /**
+   *  @brief  Installs external stream buffer.
+   *  @param  p  Pointer to char buffer.
+   *  @param  n  Size of external buffer.
+   *  @return  @c this on success, NULL on failure.
+   * 
+   *  Call setbuf(0,0) to enable unbuffered output.
+  */
+  virtual std::streambuf* 
+  setbuf(char_type* p, 
+        std::streamsize n);
+
+  /**
+   *  @brief  Flush stream buffer to file.
+   *  @return  0 on success, -1 on error.
+   * 
+   *  This calls underflow(EOF) to do the job.
+  */
+  virtual int 
+  sync();
+   
+//
+// Some future enhancements
+// 
+//  virtual int_type uflow();
+//  virtual int_type pbackfail(int_type c = traits_type::eof());
+//  virtual pos_type 
+//  seekoff(off_type off, 
+//         std::ios_base::seekdir way,
+//         std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
+//  virtual pos_type 
+//  seekpos(pos_type sp, 
+//         std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
+   
+private:
+  /**
+   *  @brief  Allocate internal buffer.
+   * 
+   *  This function is safe to call multiple times. It will ensure
+   *  that a proper internal buffer exists if it is required. If the
+   *  buffer already exists or is external, the buffer pointers will be
+   *  reset to their original state.
+  */
+  void 
+  enable_buffer();
+   
+  /**
+   *  @brief  Destroy internal buffer.
+   * 
+   *  This function is safe to call multiple times. It will ensure
+   *  that the internal buffer is deallocated if it exists. In any
+   *  case, it will also reset the buffer pointers.
+  */
+  void 
+  disable_buffer();
+   
+  /**
+   *  Underlying file pointer.
+  */
+  gzFile file;
+  
+  /**
+   *  Mode in which file was opened.
+  */
+  std::ios_base::openmode io_mode;
+  
+  /**
+   *  @brief  True if this object owns file descriptor.
+   *
+   *  This makes the class responsible for closing the file 
+   *  upon destruction.
+  */
+  bool own_fd;
+   
+  /**
+   *  @brief  Stream buffer.
+   * 
+   *  For simplicity this remains allocated on the free store for the 
+   *  entire life span of the gzfilebuf object, unless replaced by setbuf.
+  */
+  char_type* buffer;
+   
+  /**
+   *  @brief  Stream buffer size.
+   * 
+   *  Defaults to system default buffer size (typically 8192 bytes).
+   *  Modified by setbuf.
+  */
+  std::streamsize buffer_size;
+  
+  /**
+   *  @brief  True if this object owns stream buffer.
+   *
+   *  This makes the class responsible for deleting the buffer 
+   *  upon destruction.
+  */
+  bool own_buffer;
+};
+
+/*****************************************************************************/
+
+/**
+ *  @brief  Gzipped file input stream class.
+ *
+ *  This class implements ifstream for gzipped files. Seeking and putback
+ *  is not supported yet.
+*/
+class gzifstream : public std::istream 
+{
+public:
+  //  Default constructor
+  gzifstream();
+   
+  /**
+   *  @brief  Construct stream on gzipped file to be opened.
+   *  @param  name  File name.
+   *  @param  mode  Open mode flags (forced to contain ios::in).
+  */
+  explicit
+  gzifstream(const char* name, 
+            std::ios_base::openmode mode = std::ios_base::in);
+   
+  /**
+   *  @brief  Construct stream on already open gzipped file.
+   *  @param  fd    File descriptor.
+   *  @param  mode  Open mode flags (forced to contain ios::in).
+  */
+  explicit 
+  gzifstream(int fd, 
+            std::ios_base::openmode mode = std::ios_base::in);
+
+  /**
+   *  Obtain underlying stream buffer.
+  */  
+  gzfilebuf* 
+  rdbuf() const
+  { return const_cast<gzfilebuf*>(&sb); }  
+
+  /**
+   *  @brief  Check if file is open.
+   *  @return  True if file is open.
+  */
+  bool 
+  is_open() { return sb.is_open(); }
+   
+  /**
+   *  @brief  Open gzipped file.
+   *  @param  name  File name.
+   *  @param  mode  Open mode flags (forced to contain ios::in).
+   *  
+   *  Stream will be in state good() if file opens successfully;
+   *  otherwise in state fail(). This differs from the behavior of
+   *  ifstream, which never sets the state to good() and therefore
+   *  won't allow you to reuse the stream for a second file unless
+   *  you manually clear() the state. The choice is a matter of
+   *  convenience.
+  */
+  void 
+  open(const char* name, 
+       std::ios_base::openmode mode = std::ios_base::in);
+
+  /**
+   *  @brief  Attach to already open gzipped file.
+   *  @param  fd  File descriptor.
+   *  @param  mode  Open mode flags (forced to contain ios::in).
+   *  
+   *  Stream will be in state good() if attach succeeded; otherwise
+   *  in state fail().
+  */
+  void 
+  attach(int fd, 
+        std::ios_base::openmode mode = std::ios_base::in);
+
+  /**
+   *  @brief  Close gzipped file.
+   *  
+   *  Stream will be in state fail() if close failed.
+  */
+  void 
+  close();
+   
+private:
+  /**
+   *  Underlying stream buffer.
+  */    
+  gzfilebuf sb;
+};
+
+/*****************************************************************************/
+
+/**
+ *  @brief  Gzipped file output stream class.
+ *
+ *  This class implements ofstream for gzipped files. Seeking and putback
+ *  is not supported yet.
+*/
+class gzofstream : public std::ostream
+{
+public:
+  //  Default constructor
+  gzofstream();
+   
+  /**
+   *  @brief  Construct stream on gzipped file to be opened.
+   *  @param  name  File name.
+   *  @param  mode  Open mode flags (forced to contain ios::out).
+  */
+  explicit
+  gzofstream(const char* name, 
+            std::ios_base::openmode mode = std::ios_base::out);
+   
+  /**
+   *  @brief  Construct stream on already open gzipped file.
+   *  @param  fd    File descriptor.
+   *  @param  mode  Open mode flags (forced to contain ios::out).
+  */
+  explicit 
+  gzofstream(int fd, 
+            std::ios_base::openmode mode = std::ios_base::out);
+
+  /**
+   *  Obtain underlying stream buffer.
+  */  
+  gzfilebuf* 
+  rdbuf() const
+  { return const_cast<gzfilebuf*>(&sb); }  
+
+  /**
+   *  @brief  Check if file is open.
+   *  @return  True if file is open.
+  */
+  bool 
+  is_open() { return sb.is_open(); }
+   
+  /**
+   *  @brief  Open gzipped file.
+   *  @param  name  File name.
+   *  @param  mode  Open mode flags (forced to contain ios::out).
+   *  
+   *  Stream will be in state good() if file opens successfully;
+   *  otherwise in state fail(). This differs from the behavior of
+   *  ofstream, which never sets the state to good() and therefore
+   *  won't allow you to reuse the stream for a second file unless
+   *  you manually clear() the state. The choice is a matter of
+   *  convenience.
+  */
+  void 
+  open(const char* name, 
+       std::ios_base::openmode mode = std::ios_base::out);
+
+  /**
+   *  @brief  Attach to already open gzipped file.
+   *  @param  fd  File descriptor.
+   *  @param  mode  Open mode flags (forced to contain ios::out).
+   *  
+   *  Stream will be in state good() if attach succeeded; otherwise
+   *  in state fail().
+  */
+  void 
+  attach(int fd, 
+        std::ios_base::openmode mode = std::ios_base::out);
+
+  /**
+   *  @brief  Close gzipped file.
+   *  
+   *  Stream will be in state fail() if close failed.
+  */
+  void 
+  close();
+   
+private:
+  /**
+   *  Underlying stream buffer.
+  */    
+  gzfilebuf sb;
+};
+
+/*****************************************************************************/
+  
+/**
+ *  @brief  Gzipped file output stream manipulator class.
+ *
+ *  This class defines a two-argument manipulator for gzofstream. It is used
+ *  as base for the setcompression(int,int) manipulator.
+*/
+template<typename T1, typename T2>
+  class gzomanip2
+  {
+  public:
+    // Allows insertor to peek at internals
+    template <typename Ta, typename Tb>
+      friend gzofstream& 
+      operator<<(gzofstream&, 
+                const gzomanip2<Ta,Tb>&);
+     
+    // Constructor
+    gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2),
+             T1 v1,
+             T2 v2);
+  private:
+    // Underlying manipulator function
+    gzofstream&
+    (*func)(gzofstream&, T1, T2);
+     
+    // Arguments for manipulator function 
+    T1 val1;
+    T2 val2;
+  };
+
+/*****************************************************************************/
+  
+// Manipulator function thunks through to stream buffer
+inline gzofstream& 
+setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY)
+{
+  (gzs.rdbuf())->setcompression(l, s);
+  return gzs;
+}
+
+// Manipulator constructor stores arguments
+template<typename T1, typename T2>
+  inline 
+  gzomanip2<T1,T2>::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2),
+                             T1 v1,
+                             T2 v2) 
+  : func(f), val1(v1), val2(v2)
+  { }
+
+// Insertor applies underlying manipulator function to stream
+template<typename T1, typename T2>
+  inline gzofstream& 
+  operator<<(gzofstream& s, const gzomanip2<T1,T2>& m) 
+  { return (*m.func)(s, m.val1, m.val2); }
+
+// Insert this onto stream to simplify setting of compression level
+inline gzomanip2<int,int> 
+setcompression(int l, int s = Z_DEFAULT_STRATEGY) 
+{ return gzomanip2<int,int>(&setcompression, l, s); }
+
+#endif // ZFSTREAM_H
index 18316fcf3ef0b49101f4c8c38482bb0fcd418423..45fd0999e5c3c4c021dcc400c7f890298f4c1107 100644 (file)
@@ -1,47 +1,51 @@
-Change in 0.21: (10 Mar 03)
-- bug fixes
-
-Change in 0.17: (27 Jan 02)
-- bug fixes
-
-Change in 0.16: (19 Jan 02)
-- Support of ioapi for virtualize zip file access
-
-Change in 0.15: (19 Mar 98)
-- fix memory leak in minizip.c
-
-Change in 0.14: (10 Mar 98)
-- fix bugs in minizip.c sample for zipping big file
-- fix problem in month in date handling
-- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for 
-    comment handling
-
-Change in 0.13: (6 Mar 98)
-- fix bugs in zip.c
-- add real minizip sample
-
-Change in 0.12: (4 Mar 98)
-- add zip.c and zip.h for creates .zip file
-- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
-- fix miniunz.c for file without specific record for directory
-
-Change in 0.11: (3 Mar 98)
-- fix bug in unzGetCurrentFileInfo for get extra field and comment
-- enhance miniunz sample, remove the bad unztst.c sample
-
-Change in 0.10: (2 Mar 98)
-- fix bug in unzReadCurrentFile
-- rename unzip* to unz* function and structure
-- remove Windows-like hungary notation variable name
-- modify some structure in unzip.h
-- add somes comment in source
-- remove unzipGetcCurrentFile function
-- replace ZUNZEXPORT by ZEXPORT
-- add unzGetLocalExtrafield for get the local extrafield info
-- add a new sample, miniunz.c
-
-Change in 0.4: (25 Feb 98)
-- suppress the type unzipFileInZip. 
-  Only on file in the zipfile can be open at the same time
-- fix somes typo in code
-- added tm_unz structure in unzip_file_info (date/time in readable format)
+Change in 0.22: (19 May 03)\r
+- crypting support (unless you define NOCRYPT)\r
+- append file in existing zipfile\r
+\r
+Change in 0.21: (10 Mar 03)\r
+- bug fixes\r
+\r
+Change in 0.17: (27 Jan 02)\r
+- bug fixes\r
+\r
+Change in 0.16: (19 Jan 02)\r
+- Support of ioapi for virtualize zip file access\r
+\r
+Change in 0.15: (19 Mar 98)\r
+- fix memory leak in minizip.c\r
+\r
+Change in 0.14: (10 Mar 98)\r
+- fix bugs in minizip.c sample for zipping big file\r
+- fix problem in month in date handling\r
+- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for \r
+    comment handling\r
+\r
+Change in 0.13: (6 Mar 98)\r
+- fix bugs in zip.c\r
+- add real minizip sample\r
+\r
+Change in 0.12: (4 Mar 98)\r
+- add zip.c and zip.h for creates .zip file\r
+- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)\r
+- fix miniunz.c for file without specific record for directory\r
+\r
+Change in 0.11: (3 Mar 98)\r
+- fix bug in unzGetCurrentFileInfo for get extra field and comment\r
+- enhance miniunz sample, remove the bad unztst.c sample\r
+\r
+Change in 0.10: (2 Mar 98)\r
+- fix bug in unzReadCurrentFile\r
+- rename unzip* to unz* function and structure\r
+- remove Windows-like hungary notation variable name\r
+- modify some structure in unzip.h\r
+- add somes comment in source\r
+- remove unzipGetcCurrentFile function\r
+- replace ZUNZEXPORT by ZEXPORT\r
+- add unzGetLocalExtrafield for get the local extrafield info\r
+- add a new sample, miniunz.c\r
+\r
+Change in 0.4: (25 Feb 98)\r
+- suppress the type unzipFileInZip. \r
+  Only on file in the zipfile can be open at the same time\r
+- fix somes typo in code\r
+- added tm_unz structure in unzip_file_info (date/time in readable format)\r
index 84eaad20d4fb19b00965268dd75d7e9b66c8cc21..fbba3ac95aa468de57b46736e6885cf40784b907 100644 (file)
@@ -1,25 +1,25 @@
-CC=cc
-CFLAGS=-O -I../..
-
-UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
-ZIP_OBJS = minizip.o zip.o   ioapi.o ../../libz.a
-
-.c.o:
-       $(CC) -c $(CFLAGS) $*.c
-
-all: miniunz minizip
-
-miniunz:  $(UNZ_OBJS)
-       $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
-
-minizip:  $(ZIP_OBJS)
-       $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
-
-test:  miniunz minizip
-       ./minizip test readme.txt
-       ./miniunz -l test.zip
-       mv readme.txt readme.old
-       ./miniunz test.zip
-
-clean:
-       /bin/rm -f *.o *~ minizip miniunz
+CC=cc\r
+CFLAGS=-O -I../..\r
+\r
+UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a\r
+ZIP_OBJS = minizip.o zip.o   ioapi.o ../../libz.a\r
+\r
+.c.o:\r
+       $(CC) -c $(CFLAGS) $*.c\r
+\r
+all: miniunz minizip\r
+\r
+miniunz:  $(UNZ_OBJS)\r
+       $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)\r
+\r
+minizip:  $(ZIP_OBJS)\r
+       $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)\r
+\r
+test:  miniunz minizip\r
+       ./minizip test readme.txt\r
+       ./miniunz -l test.zip\r
+       mv readme.txt readme.old\r
+       ./miniunz test.zip\r
+\r
+clean:\r
+       /bin/rm -f *.o *~ minizip miniunz\r
index e5bc6271e29949c09d3a7a28844d083a7b54658a..83e763c475b5e0293b3db4ae3a01eb2a8e03b146 100644 (file)
-
-#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
-
-/***********************************************************************
- * Return the next byte in the pseudo-random sequence
- */
-static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
-{
-    unsigned temp;  /* POTENTIAL BUG:  temp*(temp^1) may overflow in an
-                     * unpredictable manner on 16-bit systems; not a problem
-                     * with any known compiler so far, though */
-
-    temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
-    return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
-}
-
-/***********************************************************************
- * Update the encryption keys with the next byte of plain text
- */
-static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
-{
-    (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
-    (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
-    (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
-    {
-      register int keyshift = (int)((*(pkeys+1)) >> 24);
-      (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
-    }
-    return c;
-}
-
-
-/***********************************************************************
- * Initialize the encryption keys and the random header according to
- * the given password.
- */
-static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
-{
-    *(pkeys+0) = 305419896L;
-    *(pkeys+1) = 591751049L;
-    *(pkeys+2) = 878082192L;
-    while (*passwd != '\0') {
-        update_keys(pkeys,pcrc_32_tab,(int)*passwd);
-        passwd++;
-    }
-}
-
-#define zdecode(pkeys,pcrc_32_tab,c) \
-    (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
-
-#define zencode(pkeys,pcrc_32_tab,c,t) \
-    (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
-
-#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-
-#define RAND_HEAD_LEN  12
-   /* "last resort" source for second part of crypt seed pattern */
-#  ifndef ZCR_SEED2
-#    define ZCR_SEED2 (unsigned long)3141592654L     /* use PI as default pattern */
-#  endif
-
-static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
-    const char *passwd;         /* password string */
-    unsigned char *buf;         /* where to write header */
-    int bufSize;
-    unsigned long* pkeys;
-    const unsigned long* pcrc_32_tab;
-    unsigned long crcForCrypting;
-{
-    int n;                       /* index in random header */
-    int t;                       /* temporary */
-    int c;                       /* random byte */
-    unsigned char header[RAND_HEAD_LEN-2]; /* random header */
-    static unsigned calls = 0;   /* ensure different random header each time */
-
-    if (bufSize<RAND_HEAD_LEN)
-      return 0;
-
-    /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
-     * output of rand() to get less predictability, since rand() is
-     * often poorly implemented.
-     */
-    if (++calls == 1)
-    {
-        srand((unsigned)(time(NULL) ^ ZCR_SEED2));
-    }
-    init_keys(passwd, pkeys, pcrc_32_tab);
-    for (n = 0; n < RAND_HEAD_LEN-2; n++)
-    {
-        c = (rand() >> 7) & 0xff;
-        header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
-    }
-    /* Encrypt random header (last two bytes is high word of crc) */
-    init_keys(passwd, pkeys, pcrc_32_tab);
-    for (n = 0; n < RAND_HEAD_LEN-2; n++)
-    {
-        buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
-    }
-    buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
-    buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
-    return n;
-}
-
-#endif
+\r
+#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))\r
+\r
+/***********************************************************************\r
+ * Return the next byte in the pseudo-random sequence\r
+ */\r
+static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)\r
+{\r
+    unsigned temp;  /* POTENTIAL BUG:  temp*(temp^1) may overflow in an\r
+                     * unpredictable manner on 16-bit systems; not a problem\r
+                     * with any known compiler so far, though */\r
+\r
+    temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;\r
+    return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);\r
+}\r
+\r
+/***********************************************************************\r
+ * Update the encryption keys with the next byte of plain text\r
+ */\r
+static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)\r
+{\r
+    (*(pkeys+0)) = CRC32((*(pkeys+0)), c);\r
+    (*(pkeys+1)) += (*(pkeys+0)) & 0xff;\r
+    (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;\r
+    {\r
+      register int keyshift = (int)((*(pkeys+1)) >> 24);\r
+      (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);\r
+    }\r
+    return c;\r
+}\r
+\r
+\r
+/***********************************************************************\r
+ * Initialize the encryption keys and the random header according to\r
+ * the given password.\r
+ */\r
+static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)\r
+{\r
+    *(pkeys+0) = 305419896L;\r
+    *(pkeys+1) = 591751049L;\r
+    *(pkeys+2) = 878082192L;\r
+    while (*passwd != '\0') {\r
+        update_keys(pkeys,pcrc_32_tab,(int)*passwd);\r
+        passwd++;\r
+    }\r
+}\r
+\r
+#define zdecode(pkeys,pcrc_32_tab,c) \\r
+    (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))\r
+\r
+#define zencode(pkeys,pcrc_32_tab,c,t) \\r
+    (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))\r
+\r
+#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED\r
+\r
+#define RAND_HEAD_LEN  12\r
+   /* "last resort" source for second part of crypt seed pattern */\r
+#  ifndef ZCR_SEED2\r
+#    define ZCR_SEED2 (unsigned long)3141592654L     /* use PI as default pattern */\r
+#  endif\r
+\r
+static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)\r
+    const char *passwd;         /* password string */\r
+    unsigned char *buf;         /* where to write header */\r
+    int bufSize;\r
+    unsigned long* pkeys;\r
+    const unsigned long* pcrc_32_tab;\r
+    unsigned long crcForCrypting;\r
+{\r
+    int n;                       /* index in random header */\r
+    int t;                       /* temporary */\r
+    int c;                       /* random byte */\r
+    unsigned char header[RAND_HEAD_LEN-2]; /* random header */\r
+    static unsigned calls = 0;   /* ensure different random header each time */\r
+\r
+    if (bufSize<RAND_HEAD_LEN)\r
+      return 0;\r
+\r
+    /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the\r
+     * output of rand() to get less predictability, since rand() is\r
+     * often poorly implemented.\r
+     */\r
+    if (++calls == 1)\r
+    {\r
+        srand((unsigned)(time(NULL) ^ ZCR_SEED2));\r
+    }\r
+    init_keys(passwd, pkeys, pcrc_32_tab);\r
+    for (n = 0; n < RAND_HEAD_LEN-2; n++)\r
+    {\r
+        c = (rand() >> 7) & 0xff;\r
+        header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);\r
+    }\r
+    /* Encrypt random header (last two bytes is high word of crc) */\r
+    init_keys(passwd, pkeys, pcrc_32_tab);\r
+    for (n = 0; n < RAND_HEAD_LEN-2; n++)\r
+    {\r
+        buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);\r
+    }\r
+    buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);\r
+    buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);\r
+    return n;\r
+}\r
+\r
+#endif\r
index d35d5f5a4ed3740803451238ff4d2ef43aeff6ff..61c6e2bd687e356d9297585bfe5913cfbd146e83 100644 (file)
-/* ioapi.c -- IO base function header for compress/uncompress .zip
-   files using zlib + zip or unzip API
-
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "zlib.h"
-#include "ioapi.h"
-
-
-
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-#ifndef SEEK_CUR
-#define SEEK_CUR    1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END    2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET    0
-#endif
-
-voidpf ZCALLBACK fopen_file_func OF((
-   voidpf opaque,
-   const char* filename,
-   int mode));
-
-uLong ZCALLBACK fread_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   void* buf,
-   uLong size));
-
-uLong ZCALLBACK fwrite_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   const void* buf,
-   uLong size));
-
-long ZCALLBACK ftell_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-long ZCALLBACK fseek_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   uLong offset,
-   int origin));
-
-int ZCALLBACK fclose_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-int ZCALLBACK ferror_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-
-voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
-   voidpf opaque;
-   const char* filename;
-   int mode;
-{
-    FILE* file = NULL;
-    const char* mode_fopen = NULL;
-    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
-        mode_fopen = "rb";
-    else
-    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
-        mode_fopen = "r+b";
-    else
-    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
-        mode_fopen = "wb";
-
-    if ((filename!=NULL) && (mode_fopen != NULL))
-        file = fopen(filename, mode_fopen);
-    return file;
-}
-
-
-uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
-   voidpf opaque;
-   voidpf stream;
-   void* buf;
-   uLong size;
-{
-    uLong ret;
-    ret = fread(buf, 1, (size_t)size, (FILE *)stream);
-    return ret;
-}
-
-
-uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
-   voidpf opaque;
-   voidpf stream;
-   const void* buf;
-   uLong size;
-{
-    uLong ret;
-    ret = fwrite(buf, 1, (size_t)size, (FILE *)stream);
-    return ret;
-}
-
-long ZCALLBACK ftell_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    long ret;
-    ret = ftell((FILE *)stream);
-    return ret;
-}
-
-long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
-   voidpf opaque;
-   voidpf stream;
-   uLong offset;
-   int origin;
-{
-    int fseek_origin=0;
-    long ret;
-    switch (origin)
-    {
-    case ZLIB_FILEFUNC_SEEK_CUR :
-        fseek_origin = SEEK_CUR;
-        break;
-    case ZLIB_FILEFUNC_SEEK_END :
-        fseek_origin = SEEK_END;
-        break;
-    case ZLIB_FILEFUNC_SEEK_SET :
-        fseek_origin = SEEK_SET;
-        break;
-    default: return -1;
-    }
-    ret = 0;
-    fseek((FILE *)stream, offset, fseek_origin);
-    return ret;
-}
-
-int ZCALLBACK fclose_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    int ret;
-    ret = fclose((FILE *)stream);
-    return ret;
-}
-
-int ZCALLBACK ferror_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    int ret;
-    ret = ferror((FILE *)stream);
-    return ret;
-}
-
-void fill_fopen_filefunc (pzlib_filefunc_def)
-  zlib_filefunc_def* pzlib_filefunc_def;
-{
-    pzlib_filefunc_def->zopen_file = fopen_file_func;
-    pzlib_filefunc_def->zread_file = fread_file_func;
-    pzlib_filefunc_def->zwrite_file = fwrite_file_func;
-    pzlib_filefunc_def->ztell_file = ftell_file_func;
-    pzlib_filefunc_def->zseek_file = fseek_file_func;
-    pzlib_filefunc_def->zclose_file = fclose_file_func;
-    pzlib_filefunc_def->zerror_file = ferror_file_func;
-    pzlib_filefunc_def->opaque = NULL;
-}
+/* ioapi.c -- IO base function header for compress/uncompress .zip\r
+   files using zlib + zip or unzip API\r
+\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "zlib.h"\r
+#include "ioapi.h"\r
+\r
+\r
+\r
+/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */\r
+\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR    1\r
+#endif\r
+\r
+#ifndef SEEK_END\r
+#define SEEK_END    2\r
+#endif\r
+\r
+#ifndef SEEK_SET\r
+#define SEEK_SET    0\r
+#endif\r
+\r
+voidpf ZCALLBACK fopen_file_func OF((\r
+   voidpf opaque,\r
+   const char* filename,\r
+   int mode));\r
+\r
+uLong ZCALLBACK fread_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   void* buf,\r
+   uLong size));\r
+\r
+uLong ZCALLBACK fwrite_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   const void* buf,\r
+   uLong size));\r
+\r
+long ZCALLBACK ftell_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+long ZCALLBACK fseek_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   uLong offset,\r
+   int origin));\r
+\r
+int ZCALLBACK fclose_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+int ZCALLBACK ferror_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+\r
+voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)\r
+   voidpf opaque;\r
+   const char* filename;\r
+   int mode;\r
+{\r
+    FILE* file = NULL;\r
+    const char* mode_fopen = NULL;\r
+    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)\r
+        mode_fopen = "rb";\r
+    else\r
+    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)\r
+        mode_fopen = "r+b";\r
+    else\r
+    if (mode & ZLIB_FILEFUNC_MODE_CREATE)\r
+        mode_fopen = "wb";\r
+\r
+    if ((filename!=NULL) && (mode_fopen != NULL))\r
+        file = fopen(filename, mode_fopen);\r
+    return file;\r
+}\r
+\r
+\r
+uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   void* buf;\r
+   uLong size;\r
+{\r
+    uLong ret;\r
+    ret = fread(buf, 1, (size_t)size, (FILE *)stream);\r
+    return ret;\r
+}\r
+\r
+\r
+uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   const void* buf;\r
+   uLong size;\r
+{\r
+    uLong ret;\r
+    ret = fwrite(buf, 1, (size_t)size, (FILE *)stream);\r
+    return ret;\r
+}\r
+\r
+long ZCALLBACK ftell_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    long ret;\r
+    ret = ftell((FILE *)stream);\r
+    return ret;\r
+}\r
+\r
+long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   uLong offset;\r
+   int origin;\r
+{\r
+    int fseek_origin=0;\r
+    long ret;\r
+    switch (origin)\r
+    {\r
+    case ZLIB_FILEFUNC_SEEK_CUR :\r
+        fseek_origin = SEEK_CUR;\r
+        break;\r
+    case ZLIB_FILEFUNC_SEEK_END :\r
+        fseek_origin = SEEK_END;\r
+        break;\r
+    case ZLIB_FILEFUNC_SEEK_SET :\r
+        fseek_origin = SEEK_SET;\r
+        break;\r
+    default: return -1;\r
+    }\r
+    ret = 0;\r
+    fseek((FILE *)stream, offset, fseek_origin);\r
+    return ret;\r
+}\r
+\r
+int ZCALLBACK fclose_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    int ret;\r
+    ret = fclose((FILE *)stream);\r
+    return ret;\r
+}\r
+\r
+int ZCALLBACK ferror_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    int ret;\r
+    ret = ferror((FILE *)stream);\r
+    return ret;\r
+}\r
+\r
+void fill_fopen_filefunc (pzlib_filefunc_def)\r
+  zlib_filefunc_def* pzlib_filefunc_def;\r
+{\r
+    pzlib_filefunc_def->zopen_file = fopen_file_func;\r
+    pzlib_filefunc_def->zread_file = fread_file_func;\r
+    pzlib_filefunc_def->zwrite_file = fwrite_file_func;\r
+    pzlib_filefunc_def->ztell_file = ftell_file_func;\r
+    pzlib_filefunc_def->zseek_file = fseek_file_func;\r
+    pzlib_filefunc_def->zclose_file = fclose_file_func;\r
+    pzlib_filefunc_def->zerror_file = ferror_file_func;\r
+    pzlib_filefunc_def->opaque = NULL;\r
+}\r
index f30fe7a5fea6f97a5066d2475d779fa8bb471b6c..6b8f1f17c41e3da56520e891fd5069f5bf7291e2 100644 (file)
@@ -1,75 +1,75 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
-   files using zlib + zip or unzip API
-
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-*/
-
-#ifndef _ZLIBIOAPI_H
-#define _ZLIBIOAPI_H
-
-
-#define ZLIB_FILEFUNC_SEEK_CUR (1)
-#define ZLIB_FILEFUNC_SEEK_END (2)
-#define ZLIB_FILEFUNC_SEEK_SET (0)
-
-#define ZLIB_FILEFUNC_MODE_READ      (1)
-#define ZLIB_FILEFUNC_MODE_WRITE     (2)
-#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
-
-#define ZLIB_FILEFUNC_MODE_EXISTING (4)
-#define ZLIB_FILEFUNC_MODE_CREATE   (8)
-
-
-#ifndef ZCALLBACK
-
-#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
-#define ZCALLBACK CALLBACK
-#else
-#define ZCALLBACK
-#endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
-typedef uLong  (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-typedef uLong  (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-typedef long   (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
-typedef long   (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
-typedef int    (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
-typedef int    (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
-
-typedef struct zlib_filefunc_def_s
-{
-    open_file_func      zopen_file;
-    read_file_func      zread_file;
-    write_file_func     zwrite_file;
-    tell_file_func      ztell_file;
-    seek_file_func      zseek_file;
-    close_file_func     zclose_file;
-    testerror_file_func zerror_file;
-    voidpf              opaque;
-} zlib_filefunc_def;
-
-
-
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
-#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
-#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
-#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
-#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
-#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
+/* ioapi.h -- IO base function header for compress/uncompress .zip\r
+   files using zlib + zip or unzip API\r
+\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+*/\r
+\r
+#ifndef _ZLIBIOAPI_H\r
+#define _ZLIBIOAPI_H\r
+\r
+\r
+#define ZLIB_FILEFUNC_SEEK_CUR (1)\r
+#define ZLIB_FILEFUNC_SEEK_END (2)\r
+#define ZLIB_FILEFUNC_SEEK_SET (0)\r
+\r
+#define ZLIB_FILEFUNC_MODE_READ      (1)\r
+#define ZLIB_FILEFUNC_MODE_WRITE     (2)\r
+#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)\r
+\r
+#define ZLIB_FILEFUNC_MODE_EXISTING (4)\r
+#define ZLIB_FILEFUNC_MODE_CREATE   (8)\r
+\r
+\r
+#ifndef ZCALLBACK\r
+\r
+#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)\r
+#define ZCALLBACK CALLBACK\r
+#else\r
+#define ZCALLBACK\r
+#endif\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));\r
+typedef uLong  (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));\r
+typedef uLong  (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));\r
+typedef long   (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));\r
+typedef long   (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));\r
+typedef int    (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));\r
+typedef int    (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));\r
+\r
+typedef struct zlib_filefunc_def_s\r
+{\r
+    open_file_func      zopen_file;\r
+    read_file_func      zread_file;\r
+    write_file_func     zwrite_file;\r
+    tell_file_func      ztell_file;\r
+    seek_file_func      zseek_file;\r
+    close_file_func     zclose_file;\r
+    testerror_file_func zerror_file;\r
+    voidpf              opaque;\r
+} zlib_filefunc_def;\r
+\r
+\r
+\r
+void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));\r
+\r
+#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))\r
+#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))\r
+#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))\r
+#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))\r
+#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))\r
+#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
index f1f55460a19c63235f89e6853c35e84b16e96be7..53198b619c087ac78226f299faad967d97701394 100644 (file)
-/* iowin32.c -- IO base function header for compress/uncompress .zip
-   files using zlib + zip or unzip API
-   This IO API version uses the Win32 API (for Microsoft Windows)
-
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-*/
-
-#include <windows.h>
-#include <stdlib.h>
-
-#include "zlib.h"
-#include "ioapi.h"
-#include "iowin32.h"
-
-#ifndef INVALID_HANDLE_VALUE
-#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
-#endif
-
-#ifndef INVALID_SET_FILE_POINTER
-#define INVALID_SET_FILE_POINTER ((DWORD)-1)
-#endif
-
-voidpf ZCALLBACK win32_open_file_func OF((
-   voidpf opaque,
-   const char* filename,
-   int mode));
-
-uLong ZCALLBACK win32_read_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   void* buf,
-   uLong size));
-
-uLong ZCALLBACK win32_write_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   const void* buf,
-   uLong size));
-
-long ZCALLBACK win32_tell_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-long ZCALLBACK win32_seek_file_func OF((
-   voidpf opaque,
-   voidpf stream,
-   uLong offset,
-   int origin));
-
-long ZCALLBACK win32_close_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-int ZCALLBACK win32_error_file_func OF((
-   voidpf opaque,
-   voidpf stream));
-
-typedef struct
-{
-    HANDLE hf;
-    int error;
-} WIN32FILE_IOWIN;
-
-voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
-   voidpf opaque;
-   const char* filename;
-   int mode;
-{
-    const char* mode_fopen = NULL;
-    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
-    HANDLE hFile = 0;
-    voidpf ret=NULL;
-
-    dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
-
-    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
-    {
-        dwDesiredAccess = GENERIC_READ;
-        dwCreationDisposition = OPEN_EXISTING;
-        dwShareMode = FILE_SHARE_READ;
-    }
-    else
-    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
-    {
-        dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
-        dwCreationDisposition = OPEN_EXISTING;
-    }
-    else
-    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
-    {
-        dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
-        dwCreationDisposition = CREATE_ALWAYS;
-    }
-
-    if ((filename!=NULL) && (dwDesiredAccess != 0))
-        hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
-                      dwCreationDisposition, dwFlagsAndAttributes, NULL);
-
-    if (hFile == INVALID_HANDLE_VALUE)
-        hFile = NULL;
-
-    if (hFile != NULL)
-    {
-        WIN32FILE_IOWIN w32fiow;
-        w32fiow.hf = hFile;
-        w32fiow.error = 0;
-        ret = malloc(sizeof(WIN32FILE_IOWIN));
-        if (ret==NULL)
-            CloseHandle(hFile);
-        else *((WIN32FILE_IOWIN*)ret) = w32fiow;
-    }
-    return ret;
-}
-
-
-uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
-   voidpf opaque;
-   voidpf stream;
-   void* buf;
-   uLong size;
-{
-    uLong ret=0;
-    HANDLE hFile = NULL;
-    if (stream!=NULL)
-        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-    if (hFile != NULL)
-        if (!ReadFile(hFile, buf, size, &ret, NULL))
-        {
-            DWORD dwErr = GetLastError();
-            if (dwErr == ERROR_HANDLE_EOF)
-                dwErr = 0;
-            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
-        }
-
-    return ret;
-}
-
-
-uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
-   voidpf opaque;
-   voidpf stream;
-   const void* buf;
-   uLong size;
-{
-    uLong ret=0;
-    HANDLE hFile = NULL;
-    if (stream!=NULL)
-        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-
-    if (hFile !=NULL)
-        if (!WriteFile(hFile, buf, size, &ret, NULL))
-        {
-            DWORD dwErr = GetLastError();
-            if (dwErr == ERROR_HANDLE_EOF)
-                dwErr = 0;
-            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
-        }
-
-    return ret;
-}
-
-long ZCALLBACK win32_tell_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    long ret=-1;
-    HANDLE hFile = NULL;
-    if (stream!=NULL)
-        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-    if (hFile != NULL)
-    {
-        DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
-        if (dwSet == INVALID_SET_FILE_POINTER)
-        {
-            DWORD dwErr = GetLastError();
-            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
-            ret = -1;
-        }
-        else
-            ret=(long)dwSet;
-    }
-    return ret;
-}
-
-long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
-   voidpf opaque;
-   voidpf stream;
-   uLong offset;
-   int origin;
-{
-    DWORD dwMoveMethod=0xFFFFFFFF;
-    HANDLE hFile = NULL;
-
-    long ret=-1;
-    if (stream!=NULL)
-        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-    switch (origin)
-    {
-    case ZLIB_FILEFUNC_SEEK_CUR :
-        dwMoveMethod = FILE_CURRENT;
-        break;
-    case ZLIB_FILEFUNC_SEEK_END :
-        dwMoveMethod = FILE_END;
-        break;
-    case ZLIB_FILEFUNC_SEEK_SET :
-        dwMoveMethod = FILE_BEGIN;
-        break;
-    default: return -1;
-    }
-
-    if (hFile != NULL)
-    {
-        DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
-        if (dwSet == INVALID_SET_FILE_POINTER)
-        {
-            DWORD dwErr = GetLastError();
-            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
-            ret = -1;
-        }
-        else
-            ret=0;
-    }
-    return ret;
-}
-
-long ZCALLBACK win32_close_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    long ret=-1;
-
-    if (stream!=NULL)
-    {
-        HANDLE hFile;
-        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-        if (hFile != NULL)
-        {
-            CloseHandle(hFile);
-            ret=0;
-        }
-        free(stream);
-    }
-    return ret;
-}
-
-int ZCALLBACK win32_error_file_func (opaque, stream)
-   voidpf opaque;
-   voidpf stream;
-{
-    int ret=-1;
-    if (stream!=NULL)
-    {
-        ret = ((WIN32FILE_IOWIN*)stream) -> error;
-    }
-    return ret;
-}
-
-void fill_win32_filefunc (pzlib_filefunc_def)
-  zlib_filefunc_def* pzlib_filefunc_def;
-{
-    pzlib_filefunc_def->zopen_file = win32_open_file_func;
-    pzlib_filefunc_def->zread_file = win32_read_file_func;
-    pzlib_filefunc_def->zwrite_file = win32_write_file_func;
-    pzlib_filefunc_def->ztell_file = win32_tell_file_func;
-    pzlib_filefunc_def->zseek_file = win32_seek_file_func;
-    pzlib_filefunc_def->zclose_file = win32_close_file_func;
-    pzlib_filefunc_def->zerror_file = win32_error_file_func;
-    pzlib_filefunc_def->opaque=NULL;
-}
+/* iowin32.c -- IO base function header for compress/uncompress .zip\r
+   files using zlib + zip or unzip API\r
+   This IO API version uses the Win32 API (for Microsoft Windows)\r
+\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+*/\r
+\r
+#include <windows.h>\r
+#include <stdlib.h>\r
+\r
+#include "zlib.h"\r
+#include "ioapi.h"\r
+#include "iowin32.h"\r
+\r
+#ifndef INVALID_HANDLE_VALUE\r
+#define INVALID_HANDLE_VALUE (0xFFFFFFFF)\r
+#endif\r
+\r
+#ifndef INVALID_SET_FILE_POINTER\r
+#define INVALID_SET_FILE_POINTER ((DWORD)-1)\r
+#endif\r
+\r
+voidpf ZCALLBACK win32_open_file_func OF((\r
+   voidpf opaque,\r
+   const char* filename,\r
+   int mode));\r
+\r
+uLong ZCALLBACK win32_read_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   void* buf,\r
+   uLong size));\r
+\r
+uLong ZCALLBACK win32_write_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   const void* buf,\r
+   uLong size));\r
+\r
+long ZCALLBACK win32_tell_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+long ZCALLBACK win32_seek_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream,\r
+   uLong offset,\r
+   int origin));\r
+\r
+long ZCALLBACK win32_close_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+int ZCALLBACK win32_error_file_func OF((\r
+   voidpf opaque,\r
+   voidpf stream));\r
+\r
+typedef struct\r
+{\r
+    HANDLE hf;\r
+    int error;\r
+} WIN32FILE_IOWIN;\r
+\r
+voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)\r
+   voidpf opaque;\r
+   const char* filename;\r
+   int mode;\r
+{\r
+    const char* mode_fopen = NULL;\r
+    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;\r
+    HANDLE hFile = 0;\r
+    voidpf ret=NULL;\r
+\r
+    dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;\r
+\r
+    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)\r
+    {\r
+        dwDesiredAccess = GENERIC_READ;\r
+        dwCreationDisposition = OPEN_EXISTING;\r
+        dwShareMode = FILE_SHARE_READ;\r
+    }\r
+    else\r
+    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)\r
+    {\r
+        dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;\r
+        dwCreationDisposition = OPEN_EXISTING;\r
+    }\r
+    else\r
+    if (mode & ZLIB_FILEFUNC_MODE_CREATE)\r
+    {\r
+        dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;\r
+        dwCreationDisposition = CREATE_ALWAYS;\r
+    }\r
+\r
+    if ((filename!=NULL) && (dwDesiredAccess != 0))\r
+        hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,\r
+                      dwCreationDisposition, dwFlagsAndAttributes, NULL);\r
+\r
+    if (hFile == INVALID_HANDLE_VALUE)\r
+        hFile = NULL;\r
+\r
+    if (hFile != NULL)\r
+    {\r
+        WIN32FILE_IOWIN w32fiow;\r
+        w32fiow.hf = hFile;\r
+        w32fiow.error = 0;\r
+        ret = malloc(sizeof(WIN32FILE_IOWIN));\r
+        if (ret==NULL)\r
+            CloseHandle(hFile);\r
+        else *((WIN32FILE_IOWIN*)ret) = w32fiow;\r
+    }\r
+    return ret;\r
+}\r
+\r
+\r
+uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   void* buf;\r
+   uLong size;\r
+{\r
+    uLong ret=0;\r
+    HANDLE hFile = NULL;\r
+    if (stream!=NULL)\r
+        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;\r
+    if (hFile != NULL)\r
+        if (!ReadFile(hFile, buf, size, &ret, NULL))\r
+        {\r
+            DWORD dwErr = GetLastError();\r
+            if (dwErr == ERROR_HANDLE_EOF)\r
+                dwErr = 0;\r
+            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;\r
+        }\r
+\r
+    return ret;\r
+}\r
+\r
+\r
+uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   const void* buf;\r
+   uLong size;\r
+{\r
+    uLong ret=0;\r
+    HANDLE hFile = NULL;\r
+    if (stream!=NULL)\r
+        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;\r
+\r
+    if (hFile !=NULL)\r
+        if (!WriteFile(hFile, buf, size, &ret, NULL))\r
+        {\r
+            DWORD dwErr = GetLastError();\r
+            if (dwErr == ERROR_HANDLE_EOF)\r
+                dwErr = 0;\r
+            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;\r
+        }\r
+\r
+    return ret;\r
+}\r
+\r
+long ZCALLBACK win32_tell_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    long ret=-1;\r
+    HANDLE hFile = NULL;\r
+    if (stream!=NULL)\r
+        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;\r
+    if (hFile != NULL)\r
+    {\r
+        DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);\r
+        if (dwSet == INVALID_SET_FILE_POINTER)\r
+        {\r
+            DWORD dwErr = GetLastError();\r
+            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;\r
+            ret = -1;\r
+        }\r
+        else\r
+            ret=(long)dwSet;\r
+    }\r
+    return ret;\r
+}\r
+\r
+long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+   uLong offset;\r
+   int origin;\r
+{\r
+    DWORD dwMoveMethod=0xFFFFFFFF;\r
+    HANDLE hFile = NULL;\r
+\r
+    long ret=-1;\r
+    if (stream!=NULL)\r
+        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;\r
+    switch (origin)\r
+    {\r
+    case ZLIB_FILEFUNC_SEEK_CUR :\r
+        dwMoveMethod = FILE_CURRENT;\r
+        break;\r
+    case ZLIB_FILEFUNC_SEEK_END :\r
+        dwMoveMethod = FILE_END;\r
+        break;\r
+    case ZLIB_FILEFUNC_SEEK_SET :\r
+        dwMoveMethod = FILE_BEGIN;\r
+        break;\r
+    default: return -1;\r
+    }\r
+\r
+    if (hFile != NULL)\r
+    {\r
+        DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);\r
+        if (dwSet == INVALID_SET_FILE_POINTER)\r
+        {\r
+            DWORD dwErr = GetLastError();\r
+            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;\r
+            ret = -1;\r
+        }\r
+        else\r
+            ret=0;\r
+    }\r
+    return ret;\r
+}\r
+\r
+long ZCALLBACK win32_close_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    long ret=-1;\r
+\r
+    if (stream!=NULL)\r
+    {\r
+        HANDLE hFile;\r
+        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;\r
+        if (hFile != NULL)\r
+        {\r
+            CloseHandle(hFile);\r
+            ret=0;\r
+        }\r
+        free(stream);\r
+    }\r
+    return ret;\r
+}\r
+\r
+int ZCALLBACK win32_error_file_func (opaque, stream)\r
+   voidpf opaque;\r
+   voidpf stream;\r
+{\r
+    int ret=-1;\r
+    if (stream!=NULL)\r
+    {\r
+        ret = ((WIN32FILE_IOWIN*)stream) -> error;\r
+    }\r
+    return ret;\r
+}\r
+\r
+void fill_win32_filefunc (pzlib_filefunc_def)\r
+  zlib_filefunc_def* pzlib_filefunc_def;\r
+{\r
+    pzlib_filefunc_def->zopen_file = win32_open_file_func;\r
+    pzlib_filefunc_def->zread_file = win32_read_file_func;\r
+    pzlib_filefunc_def->zwrite_file = win32_write_file_func;\r
+    pzlib_filefunc_def->ztell_file = win32_tell_file_func;\r
+    pzlib_filefunc_def->zseek_file = win32_seek_file_func;\r
+    pzlib_filefunc_def->zclose_file = win32_close_file_func;\r
+    pzlib_filefunc_def->zerror_file = win32_error_file_func;\r
+    pzlib_filefunc_def->opaque=NULL;\r
+}\r
index d2f5e37b862a651997879ba19b472325402a85e0..713fc026f03bdf8325ab45fbdb1dd436d288132a 100644 (file)
@@ -1,19 +1,19 @@
-/* iowin32.h -- IO base function header for compress/uncompress .zip
-   files using zlib + zip or unzip API
-   This IO API version uses the Win32 API (for Microsoft Windows)
-
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-
-#ifdef __cplusplus
-}
-#endif
+/* iowin32.h -- IO base function header for compress/uncompress .zip\r
+   files using zlib + zip or unzip API\r
+   This IO API version uses the Win32 API (for Microsoft Windows)\r
+\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+*/\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
index 938d4ef5a36dfa5de685fde7f7aaf092a10b1de8..ea23e4090f146730669df0b45c562986ea28d33c 100644 (file)
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef unix
-# include <unistd.h>
-# include <utime.h>
-#else
-# include <direct.h>
-# include <io.h>
-#endif
-
-#include "unzip.h"
-
-#define CASESENSITIVITY (0)
-#define WRITEBUFFERSIZE (8192)
-#define MAXFILENAME (256)
-
-#ifdef WIN32
-#define USEWIN32IOAPI
-#include "iowin32.h"
-#endif
-/*
-  mini unzip, demo of unzip package
-
-  usage :
-  Usage : miniunz [-exvlo] file.zip [file_to_extract]
-
-  list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
-    if it exists
-*/
-
-
-/* change_file_date : change the date/time of a file
-    filename : the filename of the file where date/time must be modified
-    dosdate : the new date at the MSDos format (4 bytes)
-    tmu_date : the SAME new date at the tm_unz format */
-void change_file_date(filename,dosdate,tmu_date)
-    const char *filename;
-    uLong dosdate;
-    tm_unz tmu_date;
-{
-#ifdef WIN32
-  HANDLE hFile;
-  FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
-
-  hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE,
-                      0,NULL,OPEN_EXISTING,0,NULL);
-  GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
-  DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
-  LocalFileTimeToFileTime(&ftLocal,&ftm);
-  SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
-  CloseHandle(hFile);
-#else
-#ifdef unix
-  struct utimbuf ut;
-  struct tm newdate;
-  newdate.tm_sec = tmu_date.tm_sec;
-  newdate.tm_min=tmu_date.tm_min;
-  newdate.tm_hour=tmu_date.tm_hour;
-  newdate.tm_mday=tmu_date.tm_mday;
-  newdate.tm_mon=tmu_date.tm_mon;
-  if (tmu_date.tm_year > 1900)
-      newdate.tm_year=tmu_date.tm_year - 1900;
-  else
-      newdate.tm_year=tmu_date.tm_year ;
-  newdate.tm_isdst=-1;
-
-  ut.actime=ut.modtime=mktime(&newdate);
-  utime(filename,&ut);
-#endif
-#endif
-}
-
-
-/* mymkdir and change_file_date are not 100 % portable
-   As I don't know well Unix, I wait feedback for the unix portion */
-
-int mymkdir(dirname)
-    const char* dirname;
-{
-    int ret=0;
-#ifdef WIN32
-    ret = mkdir(dirname);
-#else
-#ifdef unix
-    ret = mkdir (dirname,0775);
-#endif
-#endif
-    return ret;
-}
-
-int makedir (newdir)
-    char *newdir;
-{
-  char *buffer ;
-  char *p;
-  int  len = (int)strlen(newdir);
-
-  if (len <= 0)
-    return 0;
-
-  buffer = (char*)malloc(len+1);
-  strcpy(buffer,newdir);
-
-  if (buffer[len-1] == '/') {
-    buffer[len-1] = '\0';
-  }
-  if (mymkdir(buffer) == 0)
-    {
-      free(buffer);
-      return 1;
-    }
-
-  p = buffer+1;
-  while (1)
-    {
-      char hold;
-
-      while(*p && *p != '\\' && *p != '/')
-        p++;
-      hold = *p;
-      *p = 0;
-      if ((mymkdir(buffer) == -1) && (errno == ENOENT))
-        {
-          printf("couldn't create directory %s\n",buffer);
-          free(buffer);
-          return 0;
-        }
-      if (hold == 0)
-        break;
-      *p++ = hold;
-    }
-  free(buffer);
-  return 1;
-}
-
-void do_banner()
-{
-    printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n");
-    printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
-}
-
-void do_help()
-{
-    printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ;
-}
-
-
-int do_list(uf)
-    unzFile uf;
-{
-    uLong i;
-    unz_global_info gi;
-    int err;
-
-    err = unzGetGlobalInfo (uf,&gi);
-    if (err!=UNZ_OK)
-        printf("error %d with zipfile in unzGetGlobalInfo \n",err);
-    printf(" Length  Method   Size  Ratio   Date    Time   CRC-32     Name\n");
-    printf(" ------  ------   ----  -----   ----    ----   ------     ----\n");
-    for (i=0;i<gi.number_entry;i++)
-    {
-        char filename_inzip[256];
-        unz_file_info file_info;
-        uLong ratio=0;
-        const char *string_method;
-        err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
-        if (err!=UNZ_OK)
-        {
-            printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
-            break;
-        }
-        if (file_info.uncompressed_size>0)
-            ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
-
-        if (file_info.compression_method==0)
-            string_method="Stored";
-        else
-        if (file_info.compression_method==Z_DEFLATED)
-        {
-            uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
-            if (iLevel==0)
-              string_method="Defl:N";
-            else if (iLevel==1)
-              string_method="Defl:X";
-            else if ((iLevel==2) || (iLevel==3))
-              string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
-        }
-        else
-            string_method="Unkn. ";
-
-        printf("%7lu  %6s %7lu %3lu%%  %2.2lu-%2.2lu-%2.2lu  %2.2lu:%2.2lu  %8.8lx   %s\n",
-                file_info.uncompressed_size,string_method,file_info.compressed_size,
-                ratio,
-                (uLong)file_info.tmu_date.tm_mon + 1,
-                (uLong)file_info.tmu_date.tm_mday,
-                (uLong)file_info.tmu_date.tm_year % 100,
-                (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
-                (uLong)file_info.crc,filename_inzip);
-        if ((i+1)<gi.number_entry)
-        {
-            err = unzGoToNextFile(uf);
-            if (err!=UNZ_OK)
-            {
-                printf("error %d with zipfile in unzGoToNextFile\n",err);
-                break;
-            }
-        }
-    }
-
-    return 0;
-}
-
-
-int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
-    unzFile uf;
-    const int* popt_extract_without_path;
-    int* popt_overwrite;
-    const char* password;
-{
-    char filename_inzip[256];
-    char* filename_withoutpath;
-    char* p;
-    int err=UNZ_OK;
-    FILE *fout=NULL;
-    void* buf;
-    uInt size_buf;
-
-    unz_file_info file_info;
-    uLong ratio=0;
-    err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
-
-    if (err!=UNZ_OK)
-    {
-        printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
-        return err;
-    }
-
-    size_buf = WRITEBUFFERSIZE;
-    buf = (void*)malloc(size_buf);
-    if (buf==NULL)
-    {
-        printf("Error allocating memory\n");
-        return UNZ_INTERNALERROR;
-    }
-
-    p = filename_withoutpath = filename_inzip;
-    while ((*p) != '\0')
-    {
-        if (((*p)=='/') || ((*p)=='\\'))
-            filename_withoutpath = p+1;
-        p++;
-    }
-
-    if ((*filename_withoutpath)=='\0')
-    {
-        if ((*popt_extract_without_path)==0)
-        {
-            printf("creating directory: %s\n",filename_inzip);
-            mymkdir(filename_inzip);
-        }
-    }
-    else
-    {
-        const char* write_filename;
-        int skip=0;
-
-        if ((*popt_extract_without_path)==0)
-            write_filename = filename_inzip;
-        else
-            write_filename = filename_withoutpath;
-
-        err = unzOpenCurrentFilePassword(uf,password);
-        if (err!=UNZ_OK)
-        {
-            printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
-        }
-
-        if (((*popt_overwrite)==0) && (err==UNZ_OK))
-        {
-            char rep=0;
-            FILE* ftestexist;
-            ftestexist = fopen(write_filename,"rb");
-            if (ftestexist!=NULL)
-            {
-                fclose(ftestexist);
-                do
-                {
-                    char answer[128];
-                    printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
-                    scanf("%1s",answer);
-                    rep = answer[0] ;
-                    if ((rep>='a') && (rep<='z'))
-                        rep -= 0x20;
-                }
-                while ((rep!='Y') && (rep!='N') && (rep!='A'));
-            }
-
-            if (rep == 'N')
-                skip = 1;
-
-            if (rep == 'A')
-                *popt_overwrite=1;
-        }
-
-        if ((skip==0) && (err==UNZ_OK))
-        {
-            fout=fopen(write_filename,"wb");
-
-            /* some zipfile don't contain directory alone before file */
-            if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
-                                (filename_withoutpath!=(char*)filename_inzip))
-            {
-                char c=*(filename_withoutpath-1);
-                *(filename_withoutpath-1)='\0';
-                makedir(write_filename);
-                *(filename_withoutpath-1)=c;
-                fout=fopen(write_filename,"wb");
-            }
-
-            if (fout==NULL)
-            {
-                printf("error opening %s\n",write_filename);
-            }
-        }
-
-        if (fout!=NULL)
-        {
-            printf(" extracting: %s\n",write_filename);
-
-            do
-            {
-                err = unzReadCurrentFile(uf,buf,size_buf);
-                if (err<0)
-                {
-                    printf("error %d with zipfile in unzReadCurrentFile\n",err);
-                    break;
-                }
-                if (err>0)
-                    if (fwrite(buf,err,1,fout)!=1)
-                    {
-                        printf("error in writing extracted file\n");
-                        err=UNZ_ERRNO;
-                        break;
-                    }
-            }
-            while (err>0);
-            if (fout)
-                    fclose(fout);
-
-            if (err==0)
-                change_file_date(write_filename,file_info.dosDate,
-                                 file_info.tmu_date);
-        }
-
-        if (err==UNZ_OK)
-        {
-            err = unzCloseCurrentFile (uf);
-            if (err!=UNZ_OK)
-            {
-                printf("error %d with zipfile in unzCloseCurrentFile\n",err);
-            }
-        }
-        else
-            unzCloseCurrentFile(uf); /* don't lose the error */
-    }
-
-    free(buf);
-    return err;
-}
-
-
-int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
-    unzFile uf;
-    int opt_extract_without_path;
-    int opt_overwrite;
-    const char* password;
-{
-    uLong i;
-    unz_global_info gi;
-    int err;
-    FILE* fout=NULL;
-
-    err = unzGetGlobalInfo (uf,&gi);
-    if (err!=UNZ_OK)
-        printf("error %d with zipfile in unzGetGlobalInfo \n",err);
-
-    for (i=0;i<gi.number_entry;i++)
-    {
-        if (do_extract_currentfile(uf,&opt_extract_without_path,
-                                      &opt_overwrite,
-                                      password) != UNZ_OK)
-            break;
-
-        if ((i+1)<gi.number_entry)
-        {
-            err = unzGoToNextFile(uf);
-            if (err!=UNZ_OK)
-            {
-                printf("error %d with zipfile in unzGoToNextFile\n",err);
-                break;
-            }
-        }
-    }
-
-    return 0;
-}
-
-int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
-    unzFile uf;
-    const char* filename;
-    int opt_extract_without_path;
-    int opt_overwrite;
-    const char* password;
-{
-    int err = UNZ_OK;
-    if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
-    {
-        printf("file %s not found in the zipfile\n",filename);
-        return 2;
-    }
-
-    if (do_extract_currentfile(uf,&opt_extract_without_path,
-                                      &opt_overwrite,
-                                      password) == UNZ_OK)
-        return 0;
-    else
-        return 1;
-}
-
-
-int main(argc,argv)
-    int argc;
-    char *argv[];
-{
-    const char *zipfilename=NULL;
-    const char *filename_to_extract=NULL;
-    const char *password=NULL;
-    char filename_try[MAXFILENAME+16] = "";
-    int i;
-    int opt_do_list=0;
-    int opt_do_extract=1;
-    int opt_do_extract_withoutpath=0;
-    int opt_overwrite=0;
-    unzFile uf=NULL;
-
-    do_banner();
-    if (argc==1)
-    {
-        do_help();
-        return 0;
-    }
-    else
-    {
-        for (i=1;i<argc;i++)
-        {
-            if ((*argv[i])=='-')
-            {
-                const char *p=argv[i]+1;
-
-                while ((*p)!='\0')
-                {
-                    char c=*(p++);;
-                    if ((c=='l') || (c=='L'))
-                        opt_do_list = 1;
-                    if ((c=='v') || (c=='V'))
-                        opt_do_list = 1;
-                    if ((c=='x') || (c=='X'))
-                        opt_do_extract = 1;
-                    if ((c=='e') || (c=='E'))
-                        opt_do_extract = opt_do_extract_withoutpath = 1;
-                    if ((c=='o') || (c=='O'))
-                        opt_overwrite=1;
-                    if (((c=='p') || (c=='P')) && (i+1<argc))
-                    {
-                        password=argv[i+1];
-                        i++;
-                    }
-                }
-            }
-            else
-            {
-                if (zipfilename == NULL)
-                    zipfilename = argv[i];
-                else if (filename_to_extract==NULL)
-                        filename_to_extract = argv[i] ;
-            }
-        }
-    }
-
-    if (zipfilename!=NULL)
-    {
-
-        #ifdef USEWIN32IOAPI
-        zlib_filefunc_def ffunc;
-        #endif
-
-        strncpy(filename_try, zipfilename,MAXFILENAME-1);
-        /* strncpy doesnt append the trailing NULL, of the string is too long. */
-        filename_try[ MAXFILENAME ] = '\0';
-
-        #ifdef USEWIN32IOAPI
-        fill_win32_filefunc(&ffunc);
-        uf = unzOpen2(zipfilename,&ffunc);
-        #else
-        uf = unzOpen(zipfilename);
-        #endif
-        if (uf==NULL)
-        {
-            strcat(filename_try,".zip");
-            #ifdef USEWIN32IOAPI
-            uf = unzOpen2(filename_try,&ffunc);
-            #else
-            uf = unzOpen(filename_try);
-            #endif
-        }
-    }
-
-    if (uf==NULL)
-    {
-        printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
-        return 1;
-    }
-    printf("%s opened\n",filename_try);
-
-    if (opt_do_list==1)
-        return do_list(uf);
-    else if (opt_do_extract==1)
-    {
-        if (filename_to_extract == NULL)
-            return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
-        else
-            return do_extract_onefile(uf,filename_to_extract,
-                                      opt_do_extract_withoutpath,opt_overwrite,password);
-    }
-    unzCloseCurrentFile(uf);
-
-    return 0;
-}
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <fcntl.h>\r
+\r
+#ifdef unix\r
+# include <unistd.h>\r
+# include <utime.h>\r
+#else\r
+# include <direct.h>\r
+# include <io.h>\r
+#endif\r
+\r
+#include "unzip.h"\r
+\r
+#define CASESENSITIVITY (0)\r
+#define WRITEBUFFERSIZE (8192)\r
+#define MAXFILENAME (256)\r
+\r
+#ifdef WIN32\r
+#define USEWIN32IOAPI\r
+#include "iowin32.h"\r
+#endif\r
+/*\r
+  mini unzip, demo of unzip package\r
+\r
+  usage :\r
+  Usage : miniunz [-exvlo] file.zip [file_to_extract]\r
+\r
+  list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT\r
+    if it exists\r
+*/\r
+\r
+\r
+/* change_file_date : change the date/time of a file\r
+    filename : the filename of the file where date/time must be modified\r
+    dosdate : the new date at the MSDos format (4 bytes)\r
+    tmu_date : the SAME new date at the tm_unz format */\r
+void change_file_date(filename,dosdate,tmu_date)\r
+    const char *filename;\r
+    uLong dosdate;\r
+    tm_unz tmu_date;\r
+{\r
+#ifdef WIN32\r
+  HANDLE hFile;\r
+  FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;\r
+\r
+  hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE,\r
+                      0,NULL,OPEN_EXISTING,0,NULL);\r
+  GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);\r
+  DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);\r
+  LocalFileTimeToFileTime(&ftLocal,&ftm);\r
+  SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);\r
+  CloseHandle(hFile);\r
+#else\r
+#ifdef unix\r
+  struct utimbuf ut;\r
+  struct tm newdate;\r
+  newdate.tm_sec = tmu_date.tm_sec;\r
+  newdate.tm_min=tmu_date.tm_min;\r
+  newdate.tm_hour=tmu_date.tm_hour;\r
+  newdate.tm_mday=tmu_date.tm_mday;\r
+  newdate.tm_mon=tmu_date.tm_mon;\r
+  if (tmu_date.tm_year > 1900)\r
+      newdate.tm_year=tmu_date.tm_year - 1900;\r
+  else\r
+      newdate.tm_year=tmu_date.tm_year ;\r
+  newdate.tm_isdst=-1;\r
+\r
+  ut.actime=ut.modtime=mktime(&newdate);\r
+  utime(filename,&ut);\r
+#endif\r
+#endif\r
+}\r
+\r
+\r
+/* mymkdir and change_file_date are not 100 % portable\r
+   As I don't know well Unix, I wait feedback for the unix portion */\r
+\r
+int mymkdir(dirname)\r
+    const char* dirname;\r
+{\r
+    int ret=0;\r
+#ifdef WIN32\r
+    ret = mkdir(dirname);\r
+#else\r
+#ifdef unix\r
+    ret = mkdir (dirname,0775);\r
+#endif\r
+#endif\r
+    return ret;\r
+}\r
+\r
+int makedir (newdir)\r
+    char *newdir;\r
+{\r
+  char *buffer ;\r
+  char *p;\r
+  int  len = (int)strlen(newdir);\r
+\r
+  if (len <= 0)\r
+    return 0;\r
+\r
+  buffer = (char*)malloc(len+1);\r
+  strcpy(buffer,newdir);\r
+\r
+  if (buffer[len-1] == '/') {\r
+    buffer[len-1] = '\0';\r
+  }\r
+  if (mymkdir(buffer) == 0)\r
+    {\r
+      free(buffer);\r
+      return 1;\r
+    }\r
+\r
+  p = buffer+1;\r
+  while (1)\r
+    {\r
+      char hold;\r
+\r
+      while(*p && *p != '\\' && *p != '/')\r
+        p++;\r
+      hold = *p;\r
+      *p = 0;\r
+      if ((mymkdir(buffer) == -1) && (errno == ENOENT))\r
+        {\r
+          printf("couldn't create directory %s\n",buffer);\r
+          free(buffer);\r
+          return 0;\r
+        }\r
+      if (hold == 0)\r
+        break;\r
+      *p++ = hold;\r
+    }\r
+  free(buffer);\r
+  return 1;\r
+}\r
+\r
+void do_banner()\r
+{\r
+    printf("MiniUnz 0.22, demo of zLib + Unz package written by Gilles Vollant\n");\r
+    printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");\r
+}\r
+\r
+void do_help()\r
+{\r
+    printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \\r
+           "  -e  Extract without pathname (junk paths)\n" \\r
+           "  -x  Extract with pathname\n" \\r
+           "  -v  list files\n" \\r
+           "  -l  list files\n" \\r
+           "  -o  overwrite files without prompting\n" \\r
+           "  -p  extract crypted file using password\n\n");\r
+}\r
+\r
+\r
+int do_list(uf)\r
+    unzFile uf;\r
+{\r
+    uLong i;\r
+    unz_global_info gi;\r
+    int err;\r
+\r
+    err = unzGetGlobalInfo (uf,&gi);\r
+    if (err!=UNZ_OK)\r
+        printf("error %d with zipfile in unzGetGlobalInfo \n",err);\r
+    printf(" Length  Method   Size  Ratio   Date    Time   CRC-32     Name\n");\r
+    printf(" ------  ------   ----  -----   ----    ----   ------     ----\n");\r
+    for (i=0;i<gi.number_entry;i++)\r
+    {\r
+        char filename_inzip[256];\r
+        unz_file_info file_info;\r
+        uLong ratio=0;\r
+        const char *string_method;\r
+        char charCrypt=' ';\r
+        err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);\r
+        if (err!=UNZ_OK)\r
+        {\r
+            printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);\r
+            break;\r
+        }\r
+        if (file_info.uncompressed_size>0)\r
+            ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;\r
+\r
+        /* display a '*' if the file is crypted */\r
+        if ((file_info.flag & 1) != 0)\r
+            charCrypt='*';\r
+\r
+        if (file_info.compression_method==0)\r
+            string_method="Stored";\r
+        else\r
+        if (file_info.compression_method==Z_DEFLATED)\r
+        {\r
+            uInt iLevel=(uInt)((file_info.flag & 0x6)/2);\r
+            if (iLevel==0)\r
+              string_method="Defl:N";\r
+            else if (iLevel==1)\r
+              string_method="Defl:X";\r
+            else if ((iLevel==2) || (iLevel==3))\r
+              string_method="Defl:F"; /* 2:fast , 3 : extra fast*/\r
+        }\r
+        else\r
+            string_method="Unkn. ";\r
+\r
+        printf("%7lu  %6s%c%7lu %3lu%%  %2.2lu-%2.2lu-%2.2lu  %2.2lu:%2.2lu  %8.8lx   %s\n",\r
+                file_info.uncompressed_size,string_method,\r
+                charCrypt,\r
+                file_info.compressed_size,\r
+                ratio,\r
+                (uLong)file_info.tmu_date.tm_mon + 1,\r
+                (uLong)file_info.tmu_date.tm_mday,\r
+                (uLong)file_info.tmu_date.tm_year % 100,\r
+                (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,\r
+                (uLong)file_info.crc,filename_inzip);\r
+        if ((i+1)<gi.number_entry)\r
+        {\r
+            err = unzGoToNextFile(uf);\r
+            if (err!=UNZ_OK)\r
+            {\r
+                printf("error %d with zipfile in unzGoToNextFile\n",err);\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+    return 0;\r
+}\r
+\r
+\r
+int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)\r
+    unzFile uf;\r
+    const int* popt_extract_without_path;\r
+    int* popt_overwrite;\r
+    const char* password;\r
+{\r
+    char filename_inzip[256];\r
+    char* filename_withoutpath;\r
+    char* p;\r
+    int err=UNZ_OK;\r
+    FILE *fout=NULL;\r
+    void* buf;\r
+    uInt size_buf;\r
+\r
+    unz_file_info file_info;\r
+    uLong ratio=0;\r
+    err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);\r
+\r
+    if (err!=UNZ_OK)\r
+    {\r
+        printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);\r
+        return err;\r
+    }\r
+\r
+    size_buf = WRITEBUFFERSIZE;\r
+    buf = (void*)malloc(size_buf);\r
+    if (buf==NULL)\r
+    {\r
+        printf("Error allocating memory\n");\r
+        return UNZ_INTERNALERROR;\r
+    }\r
+\r
+    p = filename_withoutpath = filename_inzip;\r
+    while ((*p) != '\0')\r
+    {\r
+        if (((*p)=='/') || ((*p)=='\\'))\r
+            filename_withoutpath = p+1;\r
+        p++;\r
+    }\r
+\r
+    if ((*filename_withoutpath)=='\0')\r
+    {\r
+        if ((*popt_extract_without_path)==0)\r
+        {\r
+            printf("creating directory: %s\n",filename_inzip);\r
+            mymkdir(filename_inzip);\r
+        }\r
+    }\r
+    else\r
+    {\r
+        const char* write_filename;\r
+        int skip=0;\r
+\r
+        if ((*popt_extract_without_path)==0)\r
+            write_filename = filename_inzip;\r
+        else\r
+            write_filename = filename_withoutpath;\r
+\r
+        err = unzOpenCurrentFilePassword(uf,password);\r
+        if (err!=UNZ_OK)\r
+        {\r
+            printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);\r
+        }\r
+\r
+        if (((*popt_overwrite)==0) && (err==UNZ_OK))\r
+        {\r
+            char rep=0;\r
+            FILE* ftestexist;\r
+            ftestexist = fopen(write_filename,"rb");\r
+            if (ftestexist!=NULL)\r
+            {\r
+                fclose(ftestexist);\r
+                do\r
+                {\r
+                    char answer[128];\r
+                    printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);\r
+                    scanf("%1s",answer);\r
+                    rep = answer[0] ;\r
+                    if ((rep>='a') && (rep<='z'))\r
+                        rep -= 0x20;\r
+                }\r
+                while ((rep!='Y') && (rep!='N') && (rep!='A'));\r
+            }\r
+\r
+            if (rep == 'N')\r
+                skip = 1;\r
+\r
+            if (rep == 'A')\r
+                *popt_overwrite=1;\r
+        }\r
+\r
+        if ((skip==0) && (err==UNZ_OK))\r
+        {\r
+            fout=fopen(write_filename,"wb");\r
+\r
+            /* some zipfile don't contain directory alone before file */\r
+            if ((fout==NULL) && ((*popt_extract_without_path)==0) &&\r
+                                (filename_withoutpath!=(char*)filename_inzip))\r
+            {\r
+                char c=*(filename_withoutpath-1);\r
+                *(filename_withoutpath-1)='\0';\r
+                makedir(write_filename);\r
+                *(filename_withoutpath-1)=c;\r
+                fout=fopen(write_filename,"wb");\r
+            }\r
+\r
+            if (fout==NULL)\r
+            {\r
+                printf("error opening %s\n",write_filename);\r
+            }\r
+        }\r
+\r
+        if (fout!=NULL)\r
+        {\r
+            printf(" extracting: %s\n",write_filename);\r
+\r
+            do\r
+            {\r
+                err = unzReadCurrentFile(uf,buf,size_buf);\r
+                if (err<0)\r
+                {\r
+                    printf("error %d with zipfile in unzReadCurrentFile\n",err);\r
+                    break;\r
+                }\r
+                if (err>0)\r
+                    if (fwrite(buf,err,1,fout)!=1)\r
+                    {\r
+                        printf("error in writing extracted file\n");\r
+                        err=UNZ_ERRNO;\r
+                        break;\r
+                    }\r
+            }\r
+            while (err>0);\r
+            if (fout)\r
+                    fclose(fout);\r
+\r
+            if (err==0)\r
+                change_file_date(write_filename,file_info.dosDate,\r
+                                 file_info.tmu_date);\r
+        }\r
+\r
+        if (err==UNZ_OK)\r
+        {\r
+            err = unzCloseCurrentFile (uf);\r
+            if (err!=UNZ_OK)\r
+            {\r
+                printf("error %d with zipfile in unzCloseCurrentFile\n",err);\r
+            }\r
+        }\r
+        else\r
+            unzCloseCurrentFile(uf); /* don't lose the error */\r
+    }\r
+\r
+    free(buf);\r
+    return err;\r
+}\r
+\r
+\r
+int do_extract(uf,opt_extract_without_path,opt_overwrite,password)\r
+    unzFile uf;\r
+    int opt_extract_without_path;\r
+    int opt_overwrite;\r
+    const char* password;\r
+{\r
+    uLong i;\r
+    unz_global_info gi;\r
+    int err;\r
+    FILE* fout=NULL;\r
+\r
+    err = unzGetGlobalInfo (uf,&gi);\r
+    if (err!=UNZ_OK)\r
+        printf("error %d with zipfile in unzGetGlobalInfo \n",err);\r
+\r
+    for (i=0;i<gi.number_entry;i++)\r
+    {\r
+        if (do_extract_currentfile(uf,&opt_extract_without_path,\r
+                                      &opt_overwrite,\r
+                                      password) != UNZ_OK)\r
+            break;\r
+\r
+        if ((i+1)<gi.number_entry)\r
+        {\r
+            err = unzGoToNextFile(uf);\r
+            if (err!=UNZ_OK)\r
+            {\r
+                printf("error %d with zipfile in unzGoToNextFile\n",err);\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+    return 0;\r
+}\r
+\r
+int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)\r
+    unzFile uf;\r
+    const char* filename;\r
+    int opt_extract_without_path;\r
+    int opt_overwrite;\r
+    const char* password;\r
+{\r
+    int err = UNZ_OK;\r
+    if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)\r
+    {\r
+        printf("file %s not found in the zipfile\n",filename);\r
+        return 2;\r
+    }\r
+\r
+    if (do_extract_currentfile(uf,&opt_extract_without_path,\r
+                                      &opt_overwrite,\r
+                                      password) == UNZ_OK)\r
+        return 0;\r
+    else\r
+        return 1;\r
+}\r
+\r
+\r
+int main(argc,argv)\r
+    int argc;\r
+    char *argv[];\r
+{\r
+    const char *zipfilename=NULL;\r
+    const char *filename_to_extract=NULL;\r
+    const char *password=NULL;\r
+    char filename_try[MAXFILENAME+16] = "";\r
+    int i;\r
+    int opt_do_list=0;\r
+    int opt_do_extract=1;\r
+    int opt_do_extract_withoutpath=0;\r
+    int opt_overwrite=0;\r
+    unzFile uf=NULL;\r
+\r
+    do_banner();\r
+    if (argc==1)\r
+    {\r
+        do_help();\r
+        return 0;\r
+    }\r
+    else\r
+    {\r
+        for (i=1;i<argc;i++)\r
+        {\r
+            if ((*argv[i])=='-')\r
+            {\r
+                const char *p=argv[i]+1;\r
+\r
+                while ((*p)!='\0')\r
+                {\r
+                    char c=*(p++);;\r
+                    if ((c=='l') || (c=='L'))\r
+                        opt_do_list = 1;\r
+                    if ((c=='v') || (c=='V'))\r
+                        opt_do_list = 1;\r
+                    if ((c=='x') || (c=='X'))\r
+                        opt_do_extract = 1;\r
+                    if ((c=='e') || (c=='E'))\r
+                        opt_do_extract = opt_do_extract_withoutpath = 1;\r
+                    if ((c=='o') || (c=='O'))\r
+                        opt_overwrite=1;\r
+                    if (((c=='p') || (c=='P')) && (i+1<argc))\r
+                    {\r
+                        password=argv[i+1];\r
+                        i++;\r
+                    }\r
+                }\r
+            }\r
+            else\r
+            {\r
+                if (zipfilename == NULL)\r
+                    zipfilename = argv[i];\r
+                else if (filename_to_extract==NULL)\r
+                        filename_to_extract = argv[i] ;\r
+            }\r
+        }\r
+    }\r
+\r
+    if (zipfilename!=NULL)\r
+    {\r
+\r
+        #ifdef USEWIN32IOAPI\r
+        zlib_filefunc_def ffunc;\r
+        #endif\r
+\r
+        strncpy(filename_try, zipfilename,MAXFILENAME-1);\r
+        /* strncpy doesnt append the trailing NULL, of the string is too long. */\r
+        filename_try[ MAXFILENAME ] = '\0';\r
+\r
+        #ifdef USEWIN32IOAPI\r
+        fill_win32_filefunc(&ffunc);\r
+        uf = unzOpen2(zipfilename,&ffunc);\r
+        #else\r
+        uf = unzOpen(zipfilename);\r
+        #endif\r
+        if (uf==NULL)\r
+        {\r
+            strcat(filename_try,".zip");\r
+            #ifdef USEWIN32IOAPI\r
+            uf = unzOpen2(filename_try,&ffunc);\r
+            #else\r
+            uf = unzOpen(filename_try);\r
+            #endif\r
+        }\r
+    }\r
+\r
+    if (uf==NULL)\r
+    {\r
+        printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);\r
+        return 1;\r
+    }\r
+    printf("%s opened\n",filename_try);\r
+\r
+    if (opt_do_list==1)\r
+        return do_list(uf);\r
+    else if (opt_do_extract==1)\r
+    {\r
+        if (filename_to_extract == NULL)\r
+            return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);\r
+        else\r
+            return do_extract_onefile(uf,filename_to_extract,\r
+                                      opt_do_extract_withoutpath,opt_overwrite,password);\r
+    }\r
+    unzCloseCurrentFile(uf);\r
+\r
+    return 0;\r
+}\r
index 5792a1ea9d313b0af4de6c0bda8ea8248238e7be..79e541d258a780c2c8aa68c1bdc59eabfcc83f06 100644 (file)
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef unix
-# include <unistd.h>
-# include <utime.h>
-# include <sys/types.h>
-# include <sys/stat.h>
-#else
-# include <direct.h>
-# include <io.h>
-#endif
-
-#include "zip.h"
-
-#ifdef WIN32
-#define USEWIN32IOAPI
-#include "iowin32.h"
-#endif
-
-
-
-#define WRITEBUFFERSIZE (16384)
-#define MAXFILENAME (256)
-
-#ifdef WIN32
-uLong filetime(f, tmzip, dt)
-    char *f;                /* name of file to get info on */
-    tm_zip *tmzip;             /* return value: access, modific. and creation times */
-    uLong *dt;             /* dostime */
-{
-  int ret = 0;
-  {
-      FILETIME ftLocal;
-      HANDLE hFind;
-      WIN32_FIND_DATA  ff32;
-
-      hFind = FindFirstFile(f,&ff32);
-      if (hFind != INVALID_HANDLE_VALUE)
-      {
-        FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
-        FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
-        FindClose(hFind);
-        ret = 1;
-      }
-  }
-  return ret;
-}
-#else
-#ifdef unix
-uLong filetime(f, tmzip, dt)
-    char *f;                /* name of file to get info on */
-    tm_zip *tmzip;             /* return value: access, modific. and creation times */
-    uLong *dt;             /* dostime */
-{
-  int ret=0;
-  struct stat s;        /* results of stat() */
-  struct tm* filedate;
-  time_t tm_t=0;
-
-  if (strcmp(f,"-")!=0)
-  {
-    char name[MAXFILENAME+1];
-    int len = strlen(f);
-
-    strncpy(name, f,MAXFILENAME-1);
-    /* strncpy doesnt append the trailing NULL, of the string is too long. */
-    name[ MAXFILENAME ] = '\0';
-
-    if (name[len - 1] == '/')
-      name[len - 1] = '\0';
-    /* not all systems allow stat'ing a file with / appended */
-    if (stat(name,&s)==0)
-    {
-      tm_t = s.st_mtime;
-      ret = 1;
-    }
-  }
-  filedate = localtime(&tm_t);
-
-  tmzip->tm_sec  = filedate->tm_sec;
-  tmzip->tm_min  = filedate->tm_min;
-  tmzip->tm_hour = filedate->tm_hour;
-  tmzip->tm_mday = filedate->tm_mday;
-  tmzip->tm_mon  = filedate->tm_mon ;
-  tmzip->tm_year = filedate->tm_year;
-
-  return ret;
-}
-#else
-uLong filetime(f, tmzip, dt)
-    char *f;                /* name of file to get info on */
-    tm_zip *tmzip;             /* return value: access, modific. and creation times */
-    uLong *dt;             /* dostime */
-{
-    return 0;
-}
-#endif
-#endif
-
-
-
-
-int check_exist_file(filename)
-    const char* filename;
-{
-    FILE* ftestexist;
-    int ret = 1;
-    ftestexist = fopen(filename,"rb");
-    if (ftestexist==NULL)
-        ret = 0;
-    else
-        fclose(ftestexist);
-    return ret;
-}
-
-void do_banner()
-{
-    printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
-    printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
-}
-
-void do_help()
-{
-    printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ;
-}
-
-/* calculate the CRC32 of a file,
-   because to encrypt a file, we need known the CRC32 of the file before */
-int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
-{
-   unsigned long calculate_crc=0;
-   int err=ZIP_OK;
-   FILE * fin = fopen(filenameinzip,"rb");
-   unsigned long size_read = 0;
-   unsigned long total_read = 0;
-   if (fin==NULL)
-   {
-       err = ZIP_ERRNO;
-   }
-
-    if (err == ZIP_OK)
-        do
-        {
-            err = ZIP_OK;
-            size_read = (int)fread(buf,1,size_buf,fin);
-            if (size_read < size_buf)
-                if (feof(fin)==0)
-            {
-                printf("error in reading %s\n",filenameinzip);
-                err = ZIP_ERRNO;
-            }
-
-            if (size_read>0)
-                calculate_crc = crc32(calculate_crc,buf,size_read);
-            total_read += size_read;
-
-        } while ((err == ZIP_OK) && (size_read>0));
-
-    if (fin)
-        fclose(fin);
-
-    *result_crc=calculate_crc;
-    printf("file %s crc %x\n",filenameinzip,calculate_crc);
-    return err;
-}
-
-int main(argc,argv)
-    int argc;
-    char *argv[];
-{
-    int i;
-    int opt_overwrite=0;
-    int opt_compress_level=Z_DEFAULT_COMPRESSION;
-    int zipfilenamearg = 0;
-    char filename_try[MAXFILENAME+16];
-    int zipok;
-    int err=0;
-    int size_buf=0;
-    void* buf=NULL;
-    const char* password=NULL;
-
-
-    do_banner();
-    if (argc==1)
-    {
-        do_help();
-        return 0;
-    }
-    else
-    {
-        for (i=1;i<argc;i++)
-        {
-            if ((*argv[i])=='-')
-            {
-                const char *p=argv[i]+1;
-
-                while ((*p)!='\0')
-                {
-                    char c=*(p++);;
-                    if ((c=='o') || (c=='O'))
-                        opt_overwrite = 1;
-                    if ((c=='a') || (c=='A'))
-                        opt_overwrite = 2;
-                    if ((c>='0') && (c<='9'))
-                        opt_compress_level = c-'0';
-
-                    if (((c=='p') || (c=='P')) && (i+1<argc))
-                    {
-                        password=argv[i+1];
-                        i++;
-                    }
-                }
-            }
-            else
-                if (zipfilenamearg == 0)
-                    zipfilenamearg = i ;
-        }
-    }
-
-    size_buf = WRITEBUFFERSIZE;
-    buf = (void*)malloc(size_buf);
-    if (buf==NULL)
-    {
-        printf("Error allocating memory\n");
-        return ZIP_INTERNALERROR;
-    }
-
-    if (zipfilenamearg==0)
-        zipok=0;
-    else
-    {
-        int i,len;
-        int dot_found=0;
-
-        zipok = 1 ;
-        strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
-        /* strncpy doesnt append the trailing NULL, of the string is too long. */
-        filename_try[ MAXFILENAME ] = '\0';
-
-        len=(int)strlen(filename_try);
-        for (i=0;i<len;i++)
-            if (filename_try[i]=='.')
-                dot_found=1;
-
-        if (dot_found==0)
-            strcat(filename_try,".zip");
-
-        if (opt_overwrite==2)
-        {
-            /* if the file don't exist, we not append file */
-            if (check_exist_file(filename_try)==0)
-                opt_overwrite=1;
-        }
-        else
-        if (opt_overwrite==0)
-            if (check_exist_file(filename_try)!=0)
-            {
-                char rep=0;
-                do
-                {
-                    char answer[128];
-                    printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
-                    scanf("%1s",answer);
-                    rep = answer[0] ;
-                    if ((rep>='a') && (rep<='z'))
-                        rep -= 0x20;
-                }
-                while ((rep!='Y') && (rep!='N') && (rep!='A'));
-                if (rep=='N')
-                    zipok = 0;
-                if (rep=='A')
-                    opt_overwrite = 2;
-            }
-    }
-
-    if (zipok==1)
-    {
-        zipFile zf;
-        int errclose;
-        #ifdef USEWIN32IOAPI
-        zlib_filefunc_def ffunc;
-        fill_win32_filefunc(&ffunc);
-        zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
-        #else
-        zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
-        #endif
-
-        if (zf == NULL)
-        {
-            printf("error opening %s\n",filename_try);
-            err= ZIP_ERRNO;
-        }
-        else
-            printf("creating %s\n",filename_try);
-
-        for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
-        {
-            if (((*(argv[i]))!='-') && ((*(argv[i]))!='/'))
-            {
-                FILE * fin;
-                int size_read;
-                const char* filenameinzip = argv[i];
-                zip_fileinfo zi;
-                unsigned long crcFile=0;
-
-                zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
-                zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
-                zi.dosDate = 0;
-                zi.internal_fa = 0;
-                zi.external_fa = 0;
-                filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
-
-/*
-                err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
-                                 NULL,0,NULL,0,NULL / * comment * /,
-                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,
-                                 opt_compress_level);
-*/
-                if ((password != NULL) && (err==ZIP_OK))
-                    err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
-
-                err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
-                                 NULL,0,NULL,0,NULL /* comment*/,
-                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,
-                                 opt_compress_level,0,
-                                 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
-                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
-                                 password,crcFile);
-
-                if (err != ZIP_OK)
-                    printf("error in opening %s in zipfile\n",filenameinzip);
-                else
-                {
-                    fin = fopen(filenameinzip,"rb");
-                    if (fin==NULL)
-                    {
-                        err=ZIP_ERRNO;
-                        printf("error in opening %s for reading\n",filenameinzip);
-                    }
-                }
-
-                if (err == ZIP_OK)
-                    do
-                    {
-                        err = ZIP_OK;
-                        size_read = (int)fread(buf,1,size_buf,fin);
-                        if (size_read < size_buf)
-                            if (feof(fin)==0)
-                        {
-                            printf("error in reading %s\n",filenameinzip);
-                            err = ZIP_ERRNO;
-                        }
-
-                        if (size_read>0)
-                        {
-                            err = zipWriteInFileInZip (zf,buf,size_read);
-                            if (err<0)
-                            {
-                                printf("error in writing %s in the zipfile\n",
-                                                 filenameinzip);
-                            }
-
-                        }
-                    } while ((err == ZIP_OK) && (size_read>0));
-
-                if (fin)
-                    fclose(fin);
-
-                if (err<0)
-                    err=ZIP_ERRNO;
-                else
-                {
-                    err = zipCloseFileInZip(zf);
-                    if (err!=ZIP_OK)
-                        printf("error in closing %s in the zipfile\n",
-                                    filenameinzip);
-                }
-            }
-        }
-        errclose = zipClose(zf,NULL);
-        if (errclose != ZIP_OK)
-            printf("error in closing %s\n",filename_try);
-   }
-
-    free(buf);
-    return 0;
-}
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <fcntl.h>\r
+\r
+#ifdef unix\r
+# include <unistd.h>\r
+# include <utime.h>\r
+# include <sys/types.h>\r
+# include <sys/stat.h>\r
+#else\r
+# include <direct.h>\r
+# include <io.h>\r
+#endif\r
+\r
+#include "zip.h"\r
+\r
+#ifdef WIN32\r
+#define USEWIN32IOAPI\r
+#include "iowin32.h"\r
+#endif\r
+\r
+\r
+\r
+#define WRITEBUFFERSIZE (16384)\r
+#define MAXFILENAME (256)\r
+\r
+#ifdef WIN32\r
+uLong filetime(f, tmzip, dt)\r
+    char *f;                /* name of file to get info on */\r
+    tm_zip *tmzip;             /* return value: access, modific. and creation times */\r
+    uLong *dt;             /* dostime */\r
+{\r
+  int ret = 0;\r
+  {\r
+      FILETIME ftLocal;\r
+      HANDLE hFind;\r
+      WIN32_FIND_DATA  ff32;\r
+\r
+      hFind = FindFirstFile(f,&ff32);\r
+      if (hFind != INVALID_HANDLE_VALUE)\r
+      {\r
+        FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);\r
+        FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);\r
+        FindClose(hFind);\r
+        ret = 1;\r
+      }\r
+  }\r
+  return ret;\r
+}\r
+#else\r
+#ifdef unix\r
+uLong filetime(f, tmzip, dt)\r
+    char *f;                /* name of file to get info on */\r
+    tm_zip *tmzip;             /* return value: access, modific. and creation times */\r
+    uLong *dt;             /* dostime */\r
+{\r
+  int ret=0;\r
+  struct stat s;        /* results of stat() */\r
+  struct tm* filedate;\r
+  time_t tm_t=0;\r
+\r
+  if (strcmp(f,"-")!=0)\r
+  {\r
+    char name[MAXFILENAME+1];\r
+    int len = strlen(f);\r
+\r
+    strncpy(name, f,MAXFILENAME-1);\r
+    /* strncpy doesnt append the trailing NULL, of the string is too long. */\r
+    name[ MAXFILENAME ] = '\0';\r
+\r
+    if (name[len - 1] == '/')\r
+      name[len - 1] = '\0';\r
+    /* not all systems allow stat'ing a file with / appended */\r
+    if (stat(name,&s)==0)\r
+    {\r
+      tm_t = s.st_mtime;\r
+      ret = 1;\r
+    }\r
+  }\r
+  filedate = localtime(&tm_t);\r
+\r
+  tmzip->tm_sec  = filedate->tm_sec;\r
+  tmzip->tm_min  = filedate->tm_min;\r
+  tmzip->tm_hour = filedate->tm_hour;\r
+  tmzip->tm_mday = filedate->tm_mday;\r
+  tmzip->tm_mon  = filedate->tm_mon ;\r
+  tmzip->tm_year = filedate->tm_year;\r
+\r
+  return ret;\r
+}\r
+#else\r
+uLong filetime(f, tmzip, dt)\r
+    char *f;                /* name of file to get info on */\r
+    tm_zip *tmzip;             /* return value: access, modific. and creation times */\r
+    uLong *dt;             /* dostime */\r
+{\r
+    return 0;\r
+}\r
+#endif\r
+#endif\r
+\r
+\r
+\r
+\r
+int check_exist_file(filename)\r
+    const char* filename;\r
+{\r
+    FILE* ftestexist;\r
+    int ret = 1;\r
+    ftestexist = fopen(filename,"rb");\r
+    if (ftestexist==NULL)\r
+        ret = 0;\r
+    else\r
+        fclose(ftestexist);\r
+    return ret;\r
+}\r
+\r
+void do_banner()\r
+{\r
+    printf("MiniZip 0.22, demo of zLib + Zip package written by Gilles Vollant\n");\r
+    printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");\r
+}\r
+\r
+void do_help()\r
+{\r
+    printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \\r
+           "  -o  Overwrite existing file.zip\n" \\r
+           "  -a  Append to existing file.zip\n" \\r
+           "  -0  Store only\n" \\r
+           "  -1  Compress faster\n" \\r
+           "  -9  Compress better\n\n");\r
+}\r
+\r
+/* calculate the CRC32 of a file,\r
+   because to encrypt a file, we need known the CRC32 of the file before */\r
+int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)\r
+{\r
+   unsigned long calculate_crc=0;\r
+   int err=ZIP_OK;\r
+   FILE * fin = fopen(filenameinzip,"rb");\r
+   unsigned long size_read = 0;\r
+   unsigned long total_read = 0;\r
+   if (fin==NULL)\r
+   {\r
+       err = ZIP_ERRNO;\r
+   }\r
+\r
+    if (err == ZIP_OK)\r
+        do\r
+        {\r
+            err = ZIP_OK;\r
+            size_read = (int)fread(buf,1,size_buf,fin);\r
+            if (size_read < size_buf)\r
+                if (feof(fin)==0)\r
+            {\r
+                printf("error in reading %s\n",filenameinzip);\r
+                err = ZIP_ERRNO;\r
+            }\r
+\r
+            if (size_read>0)\r
+                calculate_crc = crc32(calculate_crc,buf,size_read);\r
+            total_read += size_read;\r
+\r
+        } while ((err == ZIP_OK) && (size_read>0));\r
+\r
+    if (fin)\r
+        fclose(fin);\r
+\r
+    *result_crc=calculate_crc;\r
+    printf("file %s crc %x\n",filenameinzip,calculate_crc);\r
+    return err;\r
+}\r
+\r
+int main(argc,argv)\r
+    int argc;\r
+    char *argv[];\r
+{\r
+    int i;\r
+    int opt_overwrite=0;\r
+    int opt_compress_level=Z_DEFAULT_COMPRESSION;\r
+    int zipfilenamearg = 0;\r
+    char filename_try[MAXFILENAME+16];\r
+    int zipok;\r
+    int err=0;\r
+    int size_buf=0;\r
+    void* buf=NULL;\r
+    const char* password=NULL;\r
+\r
+\r
+    do_banner();\r
+    if (argc==1)\r
+    {\r
+        do_help();\r
+        return 0;\r
+    }\r
+    else\r
+    {\r
+        for (i=1;i<argc;i++)\r
+        {\r
+            if ((*argv[i])=='-')\r
+            {\r
+                const char *p=argv[i]+1;\r
+\r
+                while ((*p)!='\0')\r
+                {\r
+                    char c=*(p++);;\r
+                    if ((c=='o') || (c=='O'))\r
+                        opt_overwrite = 1;\r
+                    if ((c=='a') || (c=='A'))\r
+                        opt_overwrite = 2;\r
+                    if ((c>='0') && (c<='9'))\r
+                        opt_compress_level = c-'0';\r
+\r
+                    if (((c=='p') || (c=='P')) && (i+1<argc))\r
+                    {\r
+                        password=argv[i+1];\r
+                        i++;\r
+                    }\r
+                }\r
+            }\r
+            else\r
+                if (zipfilenamearg == 0)\r
+                    zipfilenamearg = i ;\r
+        }\r
+    }\r
+\r
+    size_buf = WRITEBUFFERSIZE;\r
+    buf = (void*)malloc(size_buf);\r
+    if (buf==NULL)\r
+    {\r
+        printf("Error allocating memory\n");\r
+        return ZIP_INTERNALERROR;\r
+    }\r
+\r
+    if (zipfilenamearg==0)\r
+        zipok=0;\r
+    else\r
+    {\r
+        int i,len;\r
+        int dot_found=0;\r
+\r
+        zipok = 1 ;\r
+        strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);\r
+        /* strncpy doesnt append the trailing NULL, of the string is too long. */\r
+        filename_try[ MAXFILENAME ] = '\0';\r
+\r
+        len=(int)strlen(filename_try);\r
+        for (i=0;i<len;i++)\r
+            if (filename_try[i]=='.')\r
+                dot_found=1;\r
+\r
+        if (dot_found==0)\r
+            strcat(filename_try,".zip");\r
+\r
+        if (opt_overwrite==2)\r
+        {\r
+            /* if the file don't exist, we not append file */\r
+            if (check_exist_file(filename_try)==0)\r
+                opt_overwrite=1;\r
+        }\r
+        else\r
+        if (opt_overwrite==0)\r
+            if (check_exist_file(filename_try)!=0)\r
+            {\r
+                char rep=0;\r
+                do\r
+                {\r
+                    char answer[128];\r
+                    printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);\r
+                    scanf("%1s",answer);\r
+                    rep = answer[0] ;\r
+                    if ((rep>='a') && (rep<='z'))\r
+                        rep -= 0x20;\r
+                }\r
+                while ((rep!='Y') && (rep!='N') && (rep!='A'));\r
+                if (rep=='N')\r
+                    zipok = 0;\r
+                if (rep=='A')\r
+                    opt_overwrite = 2;\r
+            }\r
+    }\r
+\r
+    if (zipok==1)\r
+    {\r
+        zipFile zf;\r
+        int errclose;\r
+        #ifdef USEWIN32IOAPI\r
+        zlib_filefunc_def ffunc;\r
+        fill_win32_filefunc(&ffunc);\r
+        zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);\r
+        #else\r
+        zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);\r
+        #endif\r
+\r
+        if (zf == NULL)\r
+        {\r
+            printf("error opening %s\n",filename_try);\r
+            err= ZIP_ERRNO;\r
+        }\r
+        else\r
+            printf("creating %s\n",filename_try);\r
+\r
+        for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)\r
+        {\r
+            if (((*(argv[i]))!='-') && ((*(argv[i]))!='/'))\r
+            {\r
+                FILE * fin;\r
+                int size_read;\r
+                const char* filenameinzip = argv[i];\r
+                zip_fileinfo zi;\r
+                unsigned long crcFile=0;\r
+\r
+                zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =\r
+                zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;\r
+                zi.dosDate = 0;\r
+                zi.internal_fa = 0;\r
+                zi.external_fa = 0;\r
+                filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);\r
+\r
+/*\r
+                err = zipOpenNewFileInZip(zf,filenameinzip,&zi,\r
+                                 NULL,0,NULL,0,NULL / * comment * /,\r
+                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,\r
+                                 opt_compress_level);\r
+*/\r
+                if ((password != NULL) && (err==ZIP_OK))\r
+                    err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);\r
+\r
+                err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,\r
+                                 NULL,0,NULL,0,NULL /* comment*/,\r
+                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,\r
+                                 opt_compress_level,0,\r
+                                 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */\r
+                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,\r
+                                 password,crcFile);\r
+\r
+                if (err != ZIP_OK)\r
+                    printf("error in opening %s in zipfile\n",filenameinzip);\r
+                else\r
+                {\r
+                    fin = fopen(filenameinzip,"rb");\r
+                    if (fin==NULL)\r
+                    {\r
+                        err=ZIP_ERRNO;\r
+                        printf("error in opening %s for reading\n",filenameinzip);\r
+                    }\r
+                }\r
+\r
+                if (err == ZIP_OK)\r
+                    do\r
+                    {\r
+                        err = ZIP_OK;\r
+                        size_read = (int)fread(buf,1,size_buf,fin);\r
+                        if (size_read < size_buf)\r
+                            if (feof(fin)==0)\r
+                        {\r
+                            printf("error in reading %s\n",filenameinzip);\r
+                            err = ZIP_ERRNO;\r
+                        }\r
+\r
+                        if (size_read>0)\r
+                        {\r
+                            err = zipWriteInFileInZip (zf,buf,size_read);\r
+                            if (err<0)\r
+                            {\r
+                                printf("error in writing %s in the zipfile\n",\r
+                                                 filenameinzip);\r
+                            }\r
+\r
+                        }\r
+                    } while ((err == ZIP_OK) && (size_read>0));\r
+\r
+                if (fin)\r
+                    fclose(fin);\r
+\r
+                if (err<0)\r
+                    err=ZIP_ERRNO;\r
+                else\r
+                {\r
+                    err = zipCloseFileInZip(zf);\r
+                    if (err!=ZIP_OK)\r
+                        printf("error in closing %s in the zipfile\n",\r
+                                    filenameinzip);\r
+                }\r
+            }\r
+        }\r
+        errclose = zipClose(zf,NULL);\r
+        if (errclose != ZIP_OK)\r
+            printf("error in closing %s\n",filename_try);\r
+   }\r
+\r
+    free(buf);\r
+    return 0;\r
+}\r
index 7244523cc4de415f819a348aba729af44f569dc7..07d869e83091010ba9a9bf3658e261ba86453cff 100644 (file)
-/* unzip.c -- IO for uncompress .zip files using zlib
-   Version 0.21 with encryption, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-
-   Read unzip.h for more info
-*/
-
-/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
-compatibility with older software. The following is from the original crypt.c. Code
-woven in by Terry Thorsen 1/2003.
-*/
-/*
-  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
-
-  See the accompanying file LICENSE, version 2000-Apr-09 or later
-  (the contents of which are also included in zip.h) for terms of use.
-  If, for some reason, all these files are missing, the Info-ZIP license
-  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
-*/
-/*
-  crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
-
-  The encryption/decryption parts of this source code (as opposed to the
-  non-echoing password parts) were originally written in Europe.  The
-  whole source package can be freely distributed, including from the USA.
-  (Prior to January 2000, re-export from the US was a violation of US law.)
- */
-
-/*
-  This encryption code is a direct transcription of the algorithm from
-  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
-  file (appnote.txt) is distributed with the PKZIP program (even in the
-  version without encryption capabilities).
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "zlib.h"
-#include "unzip.h"
-
-#ifdef STDC
-#  include <stddef.h>
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
-    extern int errno;
-#else
-#   include <errno.h>
-#endif
-
-
-#ifndef local
-#  define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-
-
-#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
-                      !defined(CASESENSITIVITYDEFAULT_NO)
-#define CASESENSITIVITYDEFAULT_NO
-#endif
-
-
-#ifndef UNZ_BUFSIZE
-#define UNZ_BUFSIZE (16384)
-#endif
-
-#ifndef UNZ_MAXFILENAMEINZIP
-#define UNZ_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-
-
-
-
-const char unz_copyright[] =
-   " unzip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info_internal_s
-{
-    uLong offset_curfile;/* relative offset of local header 4 bytes */
-} unz_file_info_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
-    when reading and decompress it */
-typedef struct
-{
-    char  *read_buffer;         /* internal buffer for compressed data */
-    z_stream stream;            /* zLib stream structure for inflate */
-
-    uLong pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
-    uLong stream_initialised;   /* flag set if stream structure is initialised*/
-
-    uLong offset_local_extrafield;/* offset of the local extra field */
-    uInt  size_local_extrafield;/* size of the local extra field */
-    uLong pos_local_extrafield;   /* position in the local extra field in read*/
-
-    uLong crc32;                /* crc32 of all data uncompressed */
-    uLong crc32_wait;           /* crc32 we must obtain after decompress all */
-    uLong rest_read_compressed; /* number of byte to be decompressed */
-    uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
-    zlib_filefunc_def z_filefunc;
-    voidpf filestream;        /* io structore of the zipfile */
-    uLong compression_method;   /* compression method (0==store) */
-    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-    int   raw;
-} file_in_zip_read_info_s;
-
-
-/* unz_s contain internal information about the zipfile
-*/
-typedef struct
-{
-    zlib_filefunc_def z_filefunc;
-    voidpf filestream;        /* io structore of the zipfile */
-    unz_global_info gi;       /* public global information */
-    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-    uLong num_file;             /* number of the current file in the zipfile*/
-    uLong pos_in_central_dir;   /* pos of the current file in the central dir*/
-    uLong current_file_ok;      /* flag about the usability of the current file*/
-    uLong central_pos;          /* position of the beginning of the central dir*/
-
-    uLong size_central_dir;     /* size of the central directory  */
-    uLong offset_central_dir;   /* offset of start of central directory with
-                                   respect to the starting disk number */
-
-    unz_file_info cur_file_info; /* public info about the current file in zip*/
-    unz_file_info_internal cur_file_info_internal; /* private info about it*/
-    file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
-                                        file if we are decompressing it */
-    int encrypted;
-    #ifndef NOUNCRPYT
-    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
-    const unsigned long* pcrc_32_tab;
-    #endif
-} unz_s;
-
-
-#ifndef NOUNCRPYT
-#include "crypt.h"
-#endif
-
-/* ===========================================================================
-     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
-   for end of file.
-   IN assertion: the stream s has been sucessfully opened for reading.
-*/
-
-
-local int unzlocal_getByte OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    int *pi));
-
-local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    int *pi;
-{
-    unsigned char c;
-    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
-    if (err==1)
-    {
-        *pi = (int)c;
-        return UNZ_OK;
-    }
-    else
-    {
-        if (ZERROR(*pzlib_filefunc_def,filestream))
-            return UNZ_ERRNO;
-        else
-            return UNZ_EOF;
-    }
-}
-
-
-/* ===========================================================================
-   Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int unzlocal_getShort OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    uLong *pX));
-
-local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    uLong *pX;
-{
-    uLong x ;
-    int i;
-    int err;
-
-    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x = (uLong)i;
-
-    if (err==UNZ_OK)
-        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<8;
-
-    if (err==UNZ_OK)
-        *pX = x;
-    else
-        *pX = 0;
-    return err;
-}
-
-local int unzlocal_getLong OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    uLong *pX));
-
-local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    uLong *pX;
-{
-    uLong x ;
-    int i;
-    int err;
-
-    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x = (uLong)i;
-
-    if (err==UNZ_OK)
-        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<8;
-
-    if (err==UNZ_OK)
-        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<16;
-
-    if (err==UNZ_OK)
-        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<24;
-
-    if (err==UNZ_OK)
-        *pX = x;
-    else
-        *pX = 0;
-    return err;
-}
-
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (fileName1,fileName2)
-    const char* fileName1;
-    const char* fileName2;
-{
-    for (;;)
-    {
-        char c1=*(fileName1++);
-        char c2=*(fileName2++);
-        if ((c1>='a') && (c1<='z'))
-            c1 -= 0x20;
-        if ((c2>='a') && (c2<='z'))
-            c2 -= 0x20;
-        if (c1=='\0')
-            return ((c2=='\0') ? 0 : -1);
-        if (c2=='\0')
-            return 1;
-        if (c1<c2)
-            return -1;
-        if (c1>c2)
-            return 1;
-    }
-}
-
-
-#ifdef  CASESENSITIVITYDEFAULT_NO
-#define CASESENSITIVITYDEFAULTVALUE 2
-#else
-#define CASESENSITIVITYDEFAULTVALUE 1
-#endif
-
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
-/*
-   Compare two filename (fileName1,fileName2).
-   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
-   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
-                                                                or strcasecmp)
-   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
-        (like 1 on Unix, 2 on Windows)
-
-*/
-extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
-    const char* fileName1;
-    const char* fileName2;
-    int iCaseSensitivity;
-{
-    if (iCaseSensitivity==0)
-        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
-
-    if (iCaseSensitivity==1)
-        return strcmp(fileName1,fileName2);
-
-    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-
-/*
-  Locate the Central directory of a zipfile (at the end, just before
-    the global comment)
-*/
-local uLong unzlocal_SearchCentralDir OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream));
-
-local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-{
-    unsigned char* buf;
-    uLong uSizeFile;
-    uLong uBackRead;
-    uLong uMaxBack=0xffff; /* maximum size of global comment */
-    uLong uPosFound=0;
-
-    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
-        return 0;
-
-
-    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
-
-    if (uMaxBack>uSizeFile)
-        uMaxBack = uSizeFile;
-
-    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
-    if (buf==NULL)
-        return 0;
-
-    uBackRead = 4;
-    while (uBackRead<uMaxBack)
-    {
-        uLong uReadSize,uReadPos ;
-        int i;
-        if (uBackRead+BUFREADCOMMENT>uMaxBack)
-            uBackRead = uMaxBack;
-        else
-            uBackRead+=BUFREADCOMMENT;
-        uReadPos = uSizeFile-uBackRead ;
-
-        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
-                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
-        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            break;
-
-        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
-            break;
-
-        for (i=(int)uReadSize-3; (i--)>0;)
-            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
-                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
-            {
-                uPosFound = uReadPos+i;
-                break;
-            }
-
-        if (uPosFound!=0)
-            break;
-    }
-    TRYFREE(buf);
-    return uPosFound;
-}
-
-/*
-  Open a Zip file. path contain the full pathname (by example,
-     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
-     "zlib/zlib114.zip".
-     If the zipfile cannot be opened (file doesn't exist or in not valid), the
-       return value is NULL.
-     Else, the return value is a unzFile Handle, usable with other function
-       of this unzip package.
-*/
-extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
-    const char *path;
-    zlib_filefunc_def* pzlib_filefunc_def;
-{
-    unz_s us;
-    unz_s *s;
-    uLong central_pos,uL;
-
-    uLong number_disk;          /* number of the current dist, used for
-                                   spaning ZIP, unsupported, always 0*/
-    uLong number_disk_with_CD;  /* number the the disk with central dir, used
-                                   for spaning ZIP, unsupported, always 0*/
-    uLong number_entry_CD;      /* total number of entries in
-                                   the central dir
-                                   (same than number_entry on nospan) */
-
-    int err=UNZ_OK;
-
-    if (unz_copyright[0]!=' ')
-        return NULL;
-
-    if (pzlib_filefunc_def==NULL)
-        fill_fopen_filefunc(&us.z_filefunc);
-    else
-        us.z_filefunc = *pzlib_filefunc_def;
-
-    us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
-                                                 path,
-                                                 ZLIB_FILEFUNC_MODE_READ |
-                                                 ZLIB_FILEFUNC_MODE_EXISTING);
-    if (us.filestream==NULL)
-        return NULL;
-
-    central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
-    if (central_pos==0)
-        err=UNZ_ERRNO;
-
-    if (ZSEEK(us.z_filefunc, us.filestream,
-                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-        err=UNZ_ERRNO;
-
-    /* the signature, already checked */
-    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* number of this disk */
-    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* number of the disk with the start of the central directory */
-    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* total number of entries in the central dir on this disk */
-    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* total number of entries in the central dir */
-    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if ((number_entry_CD!=us.gi.number_entry) ||
-        (number_disk_with_CD!=0) ||
-        (number_disk!=0))
-        err=UNZ_BADZIPFILE;
-
-    /* size of the central directory */
-    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* offset of start of central directory with respect to the
-          starting disk number */
-    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    /* zipfile comment length */
-    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
-        (err==UNZ_OK))
-        err=UNZ_BADZIPFILE;
-
-    if (err!=UNZ_OK)
-    {
-        ZCLOSE(us.z_filefunc, us.filestream);
-        return NULL;
-    }
-
-    us.byte_before_the_zipfile = central_pos -
-                            (us.offset_central_dir+us.size_central_dir);
-    us.central_pos = central_pos;
-    us.pfile_in_zip_read = NULL;
-    us.encrypted = 0;
-
-
-    s=(unz_s*)ALLOC(sizeof(unz_s));
-    *s=us;
-    unzGoToFirstFile((unzFile)s);
-    return (unzFile)s;
-}
-
-
-extern unzFile ZEXPORT unzOpen (path)
-    const char *path;
-{
-    return unzOpen2(path, NULL);
-}
-
-/*
-  Close a ZipFile opened with unzipOpen.
-  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
-    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
-  return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (file)
-    unzFile file;
-{
-    unz_s* s;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-
-    if (s->pfile_in_zip_read!=NULL)
-        unzCloseCurrentFile(file);
-
-    ZCLOSE(s->z_filefunc, s->filestream);
-    TRYFREE(s);
-    return UNZ_OK;
-}
-
-
-/*
-  Write info about the ZipFile in the *pglobal_info structure.
-  No preparation of the structure is needed
-  return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
-    unzFile file;
-    unz_global_info *pglobal_info;
-{
-    unz_s* s;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    *pglobal_info=s->gi;
-    return UNZ_OK;
-}
-
-
-/*
-   Translate date/time from Dos format to tm_unz (readable more easilty)
-*/
-local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
-    uLong ulDosDate;
-    tm_unz* ptm;
-{
-    uLong uDate;
-    uDate = (uLong)(ulDosDate>>16);
-    ptm->tm_mday = (uInt)(uDate&0x1f) ;
-    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
-    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
-
-    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
-    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
-    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
-}
-
-/*
-  Get Info about the current file in the zipfile, with internal only info
-*/
-local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
-                                                  unz_file_info *pfile_info,
-                                                  unz_file_info_internal
-                                                  *pfile_info_internal,
-                                                  char *szFileName,
-                                                  uLong fileNameBufferSize,
-                                                  void *extraField,
-                                                  uLong extraFieldBufferSize,
-                                                  char *szComment,
-                                                  uLong commentBufferSize));
-
-local int unzlocal_GetCurrentFileInfoInternal (file,
-                                              pfile_info,
-                                              pfile_info_internal,
-                                              szFileName, fileNameBufferSize,
-                                              extraField, extraFieldBufferSize,
-                                              szComment,  commentBufferSize)
-    unzFile file;
-    unz_file_info *pfile_info;
-    unz_file_info_internal *pfile_info_internal;
-    char *szFileName;
-    uLong fileNameBufferSize;
-    void *extraField;
-    uLong extraFieldBufferSize;
-    char *szComment;
-    uLong commentBufferSize;
-{
-    unz_s* s;
-    unz_file_info file_info;
-    unz_file_info_internal file_info_internal;
-    int err=UNZ_OK;
-    uLong uMagic;
-    long lSeek=0;
-
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    if (ZSEEK(s->z_filefunc, s->filestream,
-              s->pos_in_central_dir+s->byte_before_the_zipfile,
-              ZLIB_FILEFUNC_SEEK_SET)!=0)
-        err=UNZ_ERRNO;
-
-
-    /* we check the magic */
-    if (err==UNZ_OK)
-        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
-            err=UNZ_ERRNO;
-        else if (uMagic!=0x02014b50)
-            err=UNZ_BADZIPFILE;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    lSeek+=file_info.size_filename;
-    if ((err==UNZ_OK) && (szFileName!=NULL))
-    {
-        uLong uSizeRead ;
-        if (file_info.size_filename<fileNameBufferSize)
-        {
-            *(szFileName+file_info.size_filename)='\0';
-            uSizeRead = file_info.size_filename;
-        }
-        else
-            uSizeRead = fileNameBufferSize;
-
-        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
-            if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
-                err=UNZ_ERRNO;
-        lSeek -= uSizeRead;
-    }
-
-
-    if ((err==UNZ_OK) && (extraField!=NULL))
-    {
-        uLong uSizeRead ;
-        if (file_info.size_file_extra<extraFieldBufferSize)
-            uSizeRead = file_info.size_file_extra;
-        else
-            uSizeRead = extraFieldBufferSize;
-
-        if (lSeek!=0)
-            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
-                lSeek=0;
-            else
-                err=UNZ_ERRNO;
-        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
-            if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
-                err=UNZ_ERRNO;
-        lSeek += file_info.size_file_extra - uSizeRead;
-    }
-    else
-        lSeek+=file_info.size_file_extra;
-
-
-    if ((err==UNZ_OK) && (szComment!=NULL))
-    {
-        uLong uSizeRead ;
-        if (file_info.size_file_comment<commentBufferSize)
-        {
-            *(szComment+file_info.size_file_comment)='\0';
-            uSizeRead = file_info.size_file_comment;
-        }
-        else
-            uSizeRead = commentBufferSize;
-
-        if (lSeek!=0)
-            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
-                lSeek=0;
-            else
-                err=UNZ_ERRNO;
-        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
-            if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
-                err=UNZ_ERRNO;
-        lSeek+=file_info.size_file_comment - uSizeRead;
-    }
-    else
-        lSeek+=file_info.size_file_comment;
-
-    if ((err==UNZ_OK) && (pfile_info!=NULL))
-        *pfile_info=file_info;
-
-    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
-        *pfile_info_internal=file_info_internal;
-
-    return err;
-}
-
-
-
-/*
-  Write info about the ZipFile in the *pglobal_info structure.
-  No preparation of the structure is needed
-  return UNZ_OK if there is no problem.
-*/
-extern int ZEXPORT unzGetCurrentFileInfo (file,
-                                          pfile_info,
-                                          szFileName, fileNameBufferSize,
-                                          extraField, extraFieldBufferSize,
-                                          szComment,  commentBufferSize)
-    unzFile file;
-    unz_file_info *pfile_info;
-    char *szFileName;
-    uLong fileNameBufferSize;
-    void *extraField;
-    uLong extraFieldBufferSize;
-    char *szComment;
-    uLong commentBufferSize;
-{
-    return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
-                                                szFileName,fileNameBufferSize,
-                                                extraField,extraFieldBufferSize,
-                                                szComment,commentBufferSize);
-}
-
-/*
-  Set the current file of the zipfile to the first file.
-  return UNZ_OK if there is no problem
-*/
-extern int ZEXPORT unzGoToFirstFile (file)
-    unzFile file;
-{
-    int err=UNZ_OK;
-    unz_s* s;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    s->pos_in_central_dir=s->offset_central_dir;
-    s->num_file=0;
-    err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-                                             &s->cur_file_info_internal,
-                                             NULL,0,NULL,0,NULL,0);
-    s->current_file_ok = (err == UNZ_OK);
-    return err;
-}
-
-/*
-  Set the current file of the zipfile to the next file.
-  return UNZ_OK if there is no problem
-  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-extern int ZEXPORT unzGoToNextFile (file)
-    unzFile file;
-{
-    unz_s* s;
-    int err;
-
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    if (!s->current_file_ok)
-        return UNZ_END_OF_LIST_OF_FILE;
-    if (s->num_file+1==s->gi.number_entry)
-        return UNZ_END_OF_LIST_OF_FILE;
-
-    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
-            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
-    s->num_file++;
-    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-                                               &s->cur_file_info_internal,
-                                               NULL,0,NULL,0,NULL,0);
-    s->current_file_ok = (err == UNZ_OK);
-    return err;
-}
-
-
-/*
-  Try locate the file szFileName in the zipfile.
-  For the iCaseSensitivity signification, see unzipStringFileNameCompare
-
-  return value :
-  UNZ_OK if the file is found. It becomes the current file.
-  UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
-    unzFile file;
-    const char *szFileName;
-    int iCaseSensitivity;
-{
-    unz_s* s;
-    int err;
-
-
-    uLong num_fileSaved;
-    uLong pos_in_central_dirSaved;
-
-
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-
-    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
-        return UNZ_PARAMERROR;
-
-    s=(unz_s*)file;
-    if (!s->current_file_ok)
-        return UNZ_END_OF_LIST_OF_FILE;
-
-    num_fileSaved = s->num_file;
-    pos_in_central_dirSaved = s->pos_in_central_dir;
-
-    err = unzGoToFirstFile(file);
-
-    while (err == UNZ_OK)
-    {
-        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
-        unzGetCurrentFileInfo(file,NULL,
-                                szCurrentFileName,sizeof(szCurrentFileName)-1,
-                                NULL,0,NULL,0);
-        if (unzStringFileNameCompare(szCurrentFileName,
-                                        szFileName,iCaseSensitivity)==0)
-            return UNZ_OK;
-        err = unzGoToNextFile(file);
-    }
-
-    s->num_file = num_fileSaved ;
-    s->pos_in_central_dir = pos_in_central_dirSaved ;
-    return err;
-}
-
-
-/*
-///////////////////////////////////////////
-// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
-// I need random access
-//
-// Further optimization could be realized by adding an ability
-// to cache the directory in memory. The goal being a single
-// comprehensive file read to put the file I need in a memory.
-*/
-
-/*
-typedef struct unz_file_pos_s
-{
-    uLong pos_in_zip_directory;   // offset in file
-    uLong num_of_file;            // # of file
-} unz_file_pos;
-*/
-
-extern int ZEXPORT unzGetFilePos(file, file_pos)
-    unzFile file;
-    unz_file_pos* file_pos;
-{
-    unz_s* s;
-
-    if (file==NULL || file_pos==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    if (!s->current_file_ok)
-        return UNZ_END_OF_LIST_OF_FILE;
-
-    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
-    file_pos->num_of_file           = s->num_file;
-
-    return UNZ_OK;
-}
-
-extern int ZEXPORT unzGoToFilePos(file, file_pos)
-    unzFile file;
-    unz_file_pos* file_pos;
-{
-    unz_s* s;
-    int err;
-
-    if (file==NULL || file_pos==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-
-    /* jump to the right spot */
-    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
-    s->num_file           = file_pos->num_of_file;
-
-    /* set the current file */
-    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
-                                               &s->cur_file_info_internal,
-                                               NULL,0,NULL,0,NULL,0);
-    /* return results */
-    s->current_file_ok = (err == UNZ_OK);
-    return err;
-}
-
-/*
-// Unzip Helper Functions - should be here?
-///////////////////////////////////////////
-*/
-
-/*
-  Read the local header of the current zipfile
-  Check the coherency of the local header and info in the end of central
-        directory about this file
-  store in *piSizeVar the size of extra info in local header
-        (filename and size of extra field data)
-*/
-local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
-                                                    poffset_local_extrafield,
-                                                    psize_local_extrafield)
-    unz_s* s;
-    uInt* piSizeVar;
-    uLong *poffset_local_extrafield;
-    uInt  *psize_local_extrafield;
-{
-    uLong uMagic,uData,uFlags;
-    uLong size_filename;
-    uLong size_extra_field;
-    int err=UNZ_OK;
-
-    *piSizeVar = 0;
-    *poffset_local_extrafield = 0;
-    *psize_local_extrafield = 0;
-
-    if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
-                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
-        return UNZ_ERRNO;
-
-
-    if (err==UNZ_OK)
-        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
-            err=UNZ_ERRNO;
-        else if (uMagic!=0x04034b50)
-            err=UNZ_BADZIPFILE;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
-        err=UNZ_ERRNO;
-/*
-    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
-        err=UNZ_BADZIPFILE;
-*/
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
-        err=UNZ_ERRNO;
-    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
-        err=UNZ_BADZIPFILE;
-
-    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
-                         (s->cur_file_info.compression_method!=Z_DEFLATED))
-        err=UNZ_BADZIPFILE;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
-        err=UNZ_ERRNO;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
-        err=UNZ_ERRNO;
-    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
-                              ((uFlags & 8)==0))
-        err=UNZ_BADZIPFILE;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
-        err=UNZ_ERRNO;
-    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
-                              ((uFlags & 8)==0))
-        err=UNZ_BADZIPFILE;
-
-    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
-        err=UNZ_ERRNO;
-    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
-                              ((uFlags & 8)==0))
-        err=UNZ_BADZIPFILE;
-
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
-        err=UNZ_ERRNO;
-    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
-        err=UNZ_BADZIPFILE;
-
-    *piSizeVar += (uInt)size_filename;
-
-    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
-        err=UNZ_ERRNO;
-    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
-                                    SIZEZIPLOCALHEADER + size_filename;
-    *psize_local_extrafield = (uInt)size_extra_field;
-
-    *piSizeVar += (uInt)size_extra_field;
-
-    return err;
-}
-
-/*
-  Open for reading data the current file in the zipfile.
-  If there is no error and the file is opened, the return value is UNZ_OK.
-*/
-extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
-    unzFile file;
-    int* method;
-    int* level;
-    int raw;
-    const char* password;
-{
-    int err=UNZ_OK;
-    uInt iSizeVar;
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    uLong offset_local_extrafield;  /* offset of the local extra field */
-    uInt  size_local_extrafield;    /* size of the local extra field */
-    #ifndef NOUNCRPYT
-    char source[12];
-    #else
-    if (password != NULL)
-        return UNZ_PARAMERROR;
-    #endif
-
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    if (!s->current_file_ok)
-        return UNZ_PARAMERROR;
-
-    if (s->pfile_in_zip_read != NULL)
-        unzCloseCurrentFile(file);
-
-    if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
-                &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
-        return UNZ_BADZIPFILE;
-
-    pfile_in_zip_read_info = (file_in_zip_read_info_s*)
-                                        ALLOC(sizeof(file_in_zip_read_info_s));
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_INTERNALERROR;
-
-    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
-    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
-    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
-    pfile_in_zip_read_info->pos_local_extrafield=0;
-    pfile_in_zip_read_info->raw=raw;
-
-    if (pfile_in_zip_read_info->read_buffer==NULL)
-    {
-        TRYFREE(pfile_in_zip_read_info);
-        return UNZ_INTERNALERROR;
-    }
-
-    pfile_in_zip_read_info->stream_initialised=0;
-
-    if (method!=NULL)
-        *method = (int)s->cur_file_info.compression_method;
-
-    if (level!=NULL)
-    {
-        *level = 6;
-        switch (s->cur_file_info.flag & 0x06)
-        {
-          case 6 : *level = 1; break;
-          case 4 : *level = 2; break;
-          case 2 : *level = 9; break;
-        }
-    }
-
-    if ((s->cur_file_info.compression_method!=0) &&
-        (s->cur_file_info.compression_method!=Z_DEFLATED))
-        err=UNZ_BADZIPFILE;
-
-    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
-    pfile_in_zip_read_info->crc32=0;
-    pfile_in_zip_read_info->compression_method =
-            s->cur_file_info.compression_method;
-    pfile_in_zip_read_info->filestream=s->filestream;
-    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
-    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
-
-    pfile_in_zip_read_info->stream.total_out = 0;
-
-    if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
-        (!raw))
-    {
-      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
-      pfile_in_zip_read_info->stream.zfree = (free_func)0;
-      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
-
-      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
-      if (err == Z_OK)
-        pfile_in_zip_read_info->stream_initialised=1;
-      else
-        return err;
-        /* windowBits is passed < 0 to tell that there is no zlib header.
-         * Note that in this case inflate *requires* an extra "dummy" byte
-         * after the compressed stream in order to complete decompression and
-         * return Z_STREAM_END.
-         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
-         * size of both compressed and uncompressed data
-         */
-    }
-    pfile_in_zip_read_info->rest_read_compressed =
-            s->cur_file_info.compressed_size ;
-    pfile_in_zip_read_info->rest_read_uncompressed =
-            s->cur_file_info.uncompressed_size ;
-
-
-    pfile_in_zip_read_info->pos_in_zipfile =
-            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
-              iSizeVar;
-
-    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
-
-    s->pfile_in_zip_read = pfile_in_zip_read_info;
-
-    #ifndef NOUNCRPYT
-    if (password != NULL)
-    {
-        int i;
-        s->pcrc_32_tab = get_crc_table();
-        init_keys(password,s->keys,s->pcrc_32_tab);
-        if (ZSEEK(s->z_filefunc, s->filestream,
-                  s->pfile_in_zip_read->pos_in_zipfile +
-                     s->pfile_in_zip_read->byte_before_the_zipfile,
-                  SEEK_SET)!=0)
-            return UNZ_INTERNALERROR;
-        if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
-            return UNZ_INTERNALERROR;
-
-        for (i = 0; i<12; i++)
-            zdecode(s->keys,s->pcrc_32_tab,source[i]);
-
-        s->pfile_in_zip_read->pos_in_zipfile+=12;
-        s->encrypted=1;
-    }
-    #endif
-
-
-    return UNZ_OK;
-}
-
-extern int ZEXPORT unzOpenCurrentFile (file)
-    unzFile file;
-{
-    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
-}
-
-extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
-    unzFile file;
-    const char* password;
-{
-    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
-}
-
-extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
-    unzFile file;
-    int* method;
-    int* level;
-    int raw;
-{
-    return unzOpenCurrentFile3(file, method, level, raw, NULL);
-}
-
-/*
-  Read bytes from the current file.
-  buf contain buffer where data must be copied
-  len the size of buf.
-
-  return the number of byte copied if somes bytes are copied
-  return 0 if the end of file was reached
-  return <0 with error code if there is an error
-    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
-    unzFile file;
-    voidp buf;
-    unsigned len;
-{
-    int err=UNZ_OK;
-    uInt iRead = 0;
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_PARAMERROR;
-
-
-    if ((pfile_in_zip_read_info->read_buffer == NULL))
-        return UNZ_END_OF_LIST_OF_FILE;
-    if (len==0)
-        return 0;
-
-    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
-
-    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
-
-    if (len>pfile_in_zip_read_info->rest_read_uncompressed)
-        pfile_in_zip_read_info->stream.avail_out =
-          (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
-
-    while (pfile_in_zip_read_info->stream.avail_out>0)
-    {
-        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
-            (pfile_in_zip_read_info->rest_read_compressed>0))
-        {
-            uInt uReadThis = UNZ_BUFSIZE;
-            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
-                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
-            if (uReadThis == 0)
-                return UNZ_EOF;
-            if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
-                      pfile_in_zip_read_info->filestream,
-                      pfile_in_zip_read_info->pos_in_zipfile +
-                         pfile_in_zip_read_info->byte_before_the_zipfile,
-                         ZLIB_FILEFUNC_SEEK_SET)!=0)
-                return UNZ_ERRNO;
-            if (ZREAD(pfile_in_zip_read_info->z_filefunc,
-                      pfile_in_zip_read_info->filestream,
-                      pfile_in_zip_read_info->read_buffer,
-                      uReadThis)!=uReadThis)
-                return UNZ_ERRNO;
-
-
-            #ifndef NOUNCRPYT
-            if(s->encrypted)
-            {
-                uInt i;
-                for(i=0;i<uReadThis;i++)
-                  pfile_in_zip_read_info->read_buffer[i] =
-                      zdecode(s->keys,s->pcrc_32_tab,
-                              pfile_in_zip_read_info->read_buffer[i]);
-            }
-            #endif
-
-
-            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
-
-            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
-
-            pfile_in_zip_read_info->stream.next_in =
-                (Bytef*)pfile_in_zip_read_info->read_buffer;
-            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
-        }
-
-        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
-        {
-            uInt uDoCopy,i ;
-
-            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
-                (pfile_in_zip_read_info->rest_read_compressed == 0))
-                return (iRead==0) ? UNZ_EOF : iRead;
-
-            if (pfile_in_zip_read_info->stream.avail_out <
-                            pfile_in_zip_read_info->stream.avail_in)
-                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
-            else
-                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
-
-            for (i=0;i<uDoCopy;i++)
-                *(pfile_in_zip_read_info->stream.next_out+i) =
-                        *(pfile_in_zip_read_info->stream.next_in+i);
-
-            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
-                                pfile_in_zip_read_info->stream.next_out,
-                                uDoCopy);
-            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
-            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
-            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
-            pfile_in_zip_read_info->stream.next_out += uDoCopy;
-            pfile_in_zip_read_info->stream.next_in += uDoCopy;
-            pfile_in_zip_read_info->stream.total_out += uDoCopy;
-            iRead += uDoCopy;
-        }
-        else
-        {
-            uLong uTotalOutBefore,uTotalOutAfter;
-            const Bytef *bufBefore;
-            uLong uOutThis;
-            int flush=Z_SYNC_FLUSH;
-
-            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
-            bufBefore = pfile_in_zip_read_info->stream.next_out;
-
-            /*
-            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
-                     pfile_in_zip_read_info->stream.avail_out) &&
-                (pfile_in_zip_read_info->rest_read_compressed == 0))
-                flush = Z_FINISH;
-            */
-            err=inflate(&pfile_in_zip_read_info->stream,flush);
-
-            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
-            uOutThis = uTotalOutAfter-uTotalOutBefore;
-
-            pfile_in_zip_read_info->crc32 =
-                crc32(pfile_in_zip_read_info->crc32,bufBefore,
-                        (uInt)(uOutThis));
-
-            pfile_in_zip_read_info->rest_read_uncompressed -=
-                uOutThis;
-
-            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
-            if (err==Z_STREAM_END)
-                return (iRead==0) ? UNZ_EOF : iRead;
-            if (err!=Z_OK)
-                break;
-        }
-    }
-
-    if (err==Z_OK)
-        return iRead;
-    return err;
-}
-
-
-/*
-  Give the current position in uncompressed data
-*/
-extern z_off_t ZEXPORT unztell (file)
-    unzFile file;
-{
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_PARAMERROR;
-
-    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
-}
-
-
-/*
-  return 1 if the end of file was reached, 0 elsewhere
-*/
-extern int ZEXPORT unzeof (file)
-    unzFile file;
-{
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_PARAMERROR;
-
-    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
-        return 1;
-    else
-        return 0;
-}
-
-
-
-/*
-  Read extra field from the current file (opened by unzOpenCurrentFile)
-  This is the local-header version of the extra field (sometimes, there is
-    more info in the local-header version than in the central-header)
-
-  if buf==NULL, it return the size of the local extra field that can be read
-
-  if buf!=NULL, len is the size of the buffer, the extra header is copied in
-    buf.
-  the return value is the number of bytes copied in buf, or (if <0)
-    the error code
-*/
-extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
-    unzFile file;
-    voidp buf;
-    unsigned len;
-{
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    uInt read_now;
-    uLong size_to_read;
-
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_PARAMERROR;
-
-    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
-                pfile_in_zip_read_info->pos_local_extrafield);
-
-    if (buf==NULL)
-        return (int)size_to_read;
-
-    if (len>size_to_read)
-        read_now = (uInt)size_to_read;
-    else
-        read_now = (uInt)len ;
-
-    if (read_now==0)
-        return 0;
-
-    if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
-              pfile_in_zip_read_info->filestream,
-              pfile_in_zip_read_info->offset_local_extrafield +
-              pfile_in_zip_read_info->pos_local_extrafield,
-              ZLIB_FILEFUNC_SEEK_SET)!=0)
-        return UNZ_ERRNO;
-
-    if (ZREAD(pfile_in_zip_read_info->z_filefunc,
-              pfile_in_zip_read_info->filestream,
-              buf,size_to_read)!=size_to_read)
-        return UNZ_ERRNO;
-
-    return (int)read_now;
-}
-
-/*
-  Close the file in zip opened with unzipOpenCurrentFile
-  Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-extern int ZEXPORT unzCloseCurrentFile (file)
-    unzFile file;
-{
-    int err=UNZ_OK;
-
-    unz_s* s;
-    file_in_zip_read_info_s* pfile_in_zip_read_info;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-    pfile_in_zip_read_info=s->pfile_in_zip_read;
-
-    if (pfile_in_zip_read_info==NULL)
-        return UNZ_PARAMERROR;
-
-
-    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
-        (!pfile_in_zip_read_info->raw))
-    {
-        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
-            err=UNZ_CRCERROR;
-    }
-
-
-    TRYFREE(pfile_in_zip_read_info->read_buffer);
-    pfile_in_zip_read_info->read_buffer = NULL;
-    if (pfile_in_zip_read_info->stream_initialised)
-        inflateEnd(&pfile_in_zip_read_info->stream);
-
-    pfile_in_zip_read_info->stream_initialised = 0;
-    TRYFREE(pfile_in_zip_read_info);
-
-    s->pfile_in_zip_read=NULL;
-
-    return err;
-}
-
-
-/*
-  Get the global comment string of the ZipFile, in the szComment buffer.
-  uSizeBuf is the size of the szComment buffer.
-  return the number of byte copied or an error code <0
-*/
-extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
-    unzFile file;
-    char *szComment;
-    uLong uSizeBuf;
-{
-    int err=UNZ_OK;
-    unz_s* s;
-    uLong uReadThis ;
-    if (file==NULL)
-        return UNZ_PARAMERROR;
-    s=(unz_s*)file;
-
-    uReadThis = uSizeBuf;
-    if (uReadThis>s->gi.size_comment)
-        uReadThis = s->gi.size_comment;
-
-    if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
-        return UNZ_ERRNO;
-
-    if (uReadThis>0)
-    {
-      *szComment='\0';
-      if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
-        return UNZ_ERRNO;
-    }
-
-    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
-        *(szComment+s->gi.size_comment)='\0';
-    return (int)uReadThis;
-}
+/* unzip.c -- IO for uncompress .zip files using zlib\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+\r
+   Read unzip.h for more info\r
+*/\r
+\r
+/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of\r
+compatibility with older software. The following is from the original crypt.c. Code\r
+woven in by Terry Thorsen 1/2003.\r
+*/\r
+/*\r
+  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.\r
+\r
+  See the accompanying file LICENSE, version 2000-Apr-09 or later\r
+  (the contents of which are also included in zip.h) for terms of use.\r
+  If, for some reason, all these files are missing, the Info-ZIP license\r
+  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html\r
+*/\r
+/*\r
+  crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]\r
+\r
+  The encryption/decryption parts of this source code (as opposed to the\r
+  non-echoing password parts) were originally written in Europe.  The\r
+  whole source package can be freely distributed, including from the USA.\r
+  (Prior to January 2000, re-export from the US was a violation of US law.)\r
+ */\r
+\r
+/*\r
+  This encryption code is a direct transcription of the algorithm from\r
+  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This\r
+  file (appnote.txt) is distributed with the PKZIP program (even in the\r
+  version without encryption capabilities).\r
+ */\r
+\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include "zlib.h"\r
+#include "unzip.h"\r
+\r
+#ifdef STDC\r
+#  include <stddef.h>\r
+#  include <string.h>\r
+#  include <stdlib.h>\r
+#endif\r
+#ifdef NO_ERRNO_H\r
+    extern int errno;\r
+#else\r
+#   include <errno.h>\r
+#endif\r
+\r
+\r
+#ifndef local\r
+#  define local static\r
+#endif\r
+/* compile with -Dlocal if your debugger can't find static symbols */\r
+\r
+\r
+\r
+#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \\r
+                      !defined(CASESENSITIVITYDEFAULT_NO)\r
+#define CASESENSITIVITYDEFAULT_NO\r
+#endif\r
+\r
+\r
+#ifndef UNZ_BUFSIZE\r
+#define UNZ_BUFSIZE (16384)\r
+#endif\r
+\r
+#ifndef UNZ_MAXFILENAMEINZIP\r
+#define UNZ_MAXFILENAMEINZIP (256)\r
+#endif\r
+\r
+#ifndef ALLOC\r
+# define ALLOC(size) (malloc(size))\r
+#endif\r
+#ifndef TRYFREE\r
+# define TRYFREE(p) {if (p) free(p);}\r
+#endif\r
+\r
+#define SIZECENTRALDIRITEM (0x2e)\r
+#define SIZEZIPLOCALHEADER (0x1e)\r
+\r
+\r
+\r
+\r
+const char unz_copyright[] =\r
+   " unzip 0.22 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";\r
+\r
+/* unz_file_info_interntal contain internal info about a file in zipfile*/\r
+typedef struct unz_file_info_internal_s\r
+{\r
+    uLong offset_curfile;/* relative offset of local header 4 bytes */\r
+} unz_file_info_internal;\r
+\r
+\r
+/* file_in_zip_read_info_s contain internal information about a file in zipfile,\r
+    when reading and decompress it */\r
+typedef struct\r
+{\r
+    char  *read_buffer;         /* internal buffer for compressed data */\r
+    z_stream stream;            /* zLib stream structure for inflate */\r
+\r
+    uLong pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/\r
+    uLong stream_initialised;   /* flag set if stream structure is initialised*/\r
+\r
+    uLong offset_local_extrafield;/* offset of the local extra field */\r
+    uInt  size_local_extrafield;/* size of the local extra field */\r
+    uLong pos_local_extrafield;   /* position in the local extra field in read*/\r
+\r
+    uLong crc32;                /* crc32 of all data uncompressed */\r
+    uLong crc32_wait;           /* crc32 we must obtain after decompress all */\r
+    uLong rest_read_compressed; /* number of byte to be decompressed */\r
+    uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/\r
+    zlib_filefunc_def z_filefunc;\r
+    voidpf filestream;        /* io structore of the zipfile */\r
+    uLong compression_method;   /* compression method (0==store) */\r
+    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/\r
+    int   raw;\r
+} file_in_zip_read_info_s;\r
+\r
+\r
+/* unz_s contain internal information about the zipfile\r
+*/\r
+typedef struct\r
+{\r
+    zlib_filefunc_def z_filefunc;\r
+    voidpf filestream;        /* io structore of the zipfile */\r
+    unz_global_info gi;       /* public global information */\r
+    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/\r
+    uLong num_file;             /* number of the current file in the zipfile*/\r
+    uLong pos_in_central_dir;   /* pos of the current file in the central dir*/\r
+    uLong current_file_ok;      /* flag about the usability of the current file*/\r
+    uLong central_pos;          /* position of the beginning of the central dir*/\r
+\r
+    uLong size_central_dir;     /* size of the central directory  */\r
+    uLong offset_central_dir;   /* offset of start of central directory with\r
+                                   respect to the starting disk number */\r
+\r
+    unz_file_info cur_file_info; /* public info about the current file in zip*/\r
+    unz_file_info_internal cur_file_info_internal; /* private info about it*/\r
+    file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current\r
+                                        file if we are decompressing it */\r
+    int encrypted;\r
+    #ifndef NOUNCRYPT\r
+    unsigned long keys[3];     /* keys defining the pseudo-random sequence */\r
+    const unsigned long* pcrc_32_tab;\r
+    #endif\r
+} unz_s;\r
+\r
+\r
+#ifndef NOUNCRYPT\r
+#include "crypt.h"\r
+#endif\r
+\r
+/* ===========================================================================\r
+     Read a byte from a gz_stream; update next_in and avail_in. Return EOF\r
+   for end of file.\r
+   IN assertion: the stream s has been sucessfully opened for reading.\r
+*/\r
+\r
+\r
+local int unzlocal_getByte OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    int *pi));\r
+\r
+local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    int *pi;\r
+{\r
+    unsigned char c;\r
+    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);\r
+    if (err==1)\r
+    {\r
+        *pi = (int)c;\r
+        return UNZ_OK;\r
+    }\r
+    else\r
+    {\r
+        if (ZERROR(*pzlib_filefunc_def,filestream))\r
+            return UNZ_ERRNO;\r
+        else\r
+            return UNZ_EOF;\r
+    }\r
+}\r
+\r
+\r
+/* ===========================================================================\r
+   Reads a long in LSB order from the given gz_stream. Sets\r
+*/\r
+local int unzlocal_getShort OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    uLong *pX));\r
+\r
+local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    uLong *pX;\r
+{\r
+    uLong x ;\r
+    int i;\r
+    int err;\r
+\r
+    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x = (uLong)i;\r
+\r
+    if (err==UNZ_OK)\r
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<8;\r
+\r
+    if (err==UNZ_OK)\r
+        *pX = x;\r
+    else\r
+        *pX = 0;\r
+    return err;\r
+}\r
+\r
+local int unzlocal_getLong OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    uLong *pX));\r
+\r
+local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    uLong *pX;\r
+{\r
+    uLong x ;\r
+    int i;\r
+    int err;\r
+\r
+    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x = (uLong)i;\r
+\r
+    if (err==UNZ_OK)\r
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<8;\r
+\r
+    if (err==UNZ_OK)\r
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<16;\r
+\r
+    if (err==UNZ_OK)\r
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<24;\r
+\r
+    if (err==UNZ_OK)\r
+        *pX = x;\r
+    else\r
+        *pX = 0;\r
+    return err;\r
+}\r
+\r
+\r
+/* My own strcmpi / strcasecmp */\r
+local int strcmpcasenosensitive_internal (fileName1,fileName2)\r
+    const char* fileName1;\r
+    const char* fileName2;\r
+{\r
+    for (;;)\r
+    {\r
+        char c1=*(fileName1++);\r
+        char c2=*(fileName2++);\r
+        if ((c1>='a') && (c1<='z'))\r
+            c1 -= 0x20;\r
+        if ((c2>='a') && (c2<='z'))\r
+            c2 -= 0x20;\r
+        if (c1=='\0')\r
+            return ((c2=='\0') ? 0 : -1);\r
+        if (c2=='\0')\r
+            return 1;\r
+        if (c1<c2)\r
+            return -1;\r
+        if (c1>c2)\r
+            return 1;\r
+    }\r
+}\r
+\r
+\r
+#ifdef  CASESENSITIVITYDEFAULT_NO\r
+#define CASESENSITIVITYDEFAULTVALUE 2\r
+#else\r
+#define CASESENSITIVITYDEFAULTVALUE 1\r
+#endif\r
+\r
+#ifndef STRCMPCASENOSENTIVEFUNCTION\r
+#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal\r
+#endif\r
+\r
+/*\r
+   Compare two filename (fileName1,fileName2).\r
+   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)\r
+   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi\r
+                                                                or strcasecmp)\r
+   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system\r
+        (like 1 on Unix, 2 on Windows)\r
+\r
+*/\r
+extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)\r
+    const char* fileName1;\r
+    const char* fileName2;\r
+    int iCaseSensitivity;\r
+{\r
+    if (iCaseSensitivity==0)\r
+        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;\r
+\r
+    if (iCaseSensitivity==1)\r
+        return strcmp(fileName1,fileName2);\r
+\r
+    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);\r
+}\r
+\r
+#ifndef BUFREADCOMMENT\r
+#define BUFREADCOMMENT (0x400)\r
+#endif\r
+\r
+/*\r
+  Locate the Central directory of a zipfile (at the end, just before\r
+    the global comment)\r
+*/\r
+local uLong unzlocal_SearchCentralDir OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream));\r
+\r
+local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+{\r
+    unsigned char* buf;\r
+    uLong uSizeFile;\r
+    uLong uBackRead;\r
+    uLong uMaxBack=0xffff; /* maximum size of global comment */\r
+    uLong uPosFound=0;\r
+\r
+    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)\r
+        return 0;\r
+\r
+\r
+    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);\r
+\r
+    if (uMaxBack>uSizeFile)\r
+        uMaxBack = uSizeFile;\r
+\r
+    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);\r
+    if (buf==NULL)\r
+        return 0;\r
+\r
+    uBackRead = 4;\r
+    while (uBackRead<uMaxBack)\r
+    {\r
+        uLong uReadSize,uReadPos ;\r
+        int i;\r
+        if (uBackRead+BUFREADCOMMENT>uMaxBack)\r
+            uBackRead = uMaxBack;\r
+        else\r
+            uBackRead+=BUFREADCOMMENT;\r
+        uReadPos = uSizeFile-uBackRead ;\r
+\r
+        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?\r
+                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);\r
+        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            break;\r
+\r
+        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)\r
+            break;\r
+\r
+        for (i=(int)uReadSize-3; (i--)>0;)\r
+            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&\r
+                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))\r
+            {\r
+                uPosFound = uReadPos+i;\r
+                break;\r
+            }\r
+\r
+        if (uPosFound!=0)\r
+            break;\r
+    }\r
+    TRYFREE(buf);\r
+    return uPosFound;\r
+}\r
+\r
+/*\r
+  Open a Zip file. path contain the full pathname (by example,\r
+     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer\r
+     "zlib/zlib114.zip".\r
+     If the zipfile cannot be opened (file doesn't exist or in not valid), the\r
+       return value is NULL.\r
+     Else, the return value is a unzFile Handle, usable with other function\r
+       of this unzip package.\r
+*/\r
+extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)\r
+    const char *path;\r
+    zlib_filefunc_def* pzlib_filefunc_def;\r
+{\r
+    unz_s us;\r
+    unz_s *s;\r
+    uLong central_pos,uL;\r
+\r
+    uLong number_disk;          /* number of the current dist, used for\r
+                                   spaning ZIP, unsupported, always 0*/\r
+    uLong number_disk_with_CD;  /* number the the disk with central dir, used\r
+                                   for spaning ZIP, unsupported, always 0*/\r
+    uLong number_entry_CD;      /* total number of entries in\r
+                                   the central dir\r
+                                   (same than number_entry on nospan) */\r
+\r
+    int err=UNZ_OK;\r
+\r
+    if (unz_copyright[0]!=' ')\r
+        return NULL;\r
+\r
+    if (pzlib_filefunc_def==NULL)\r
+        fill_fopen_filefunc(&us.z_filefunc);\r
+    else\r
+        us.z_filefunc = *pzlib_filefunc_def;\r
+\r
+    us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,\r
+                                                 path,\r
+                                                 ZLIB_FILEFUNC_MODE_READ |\r
+                                                 ZLIB_FILEFUNC_MODE_EXISTING);\r
+    if (us.filestream==NULL)\r
+        return NULL;\r
+\r
+    central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);\r
+    if (central_pos==0)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (ZSEEK(us.z_filefunc, us.filestream,\r
+                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* the signature, already checked */\r
+    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* number of this disk */\r
+    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* number of the disk with the start of the central directory */\r
+    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* total number of entries in the central dir on this disk */\r
+    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* total number of entries in the central dir */\r
+    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if ((number_entry_CD!=us.gi.number_entry) ||\r
+        (number_disk_with_CD!=0) ||\r
+        (number_disk!=0))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    /* size of the central directory */\r
+    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* offset of start of central directory with respect to the\r
+          starting disk number */\r
+    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    /* zipfile comment length */\r
+    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&\r
+        (err==UNZ_OK))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    if (err!=UNZ_OK)\r
+    {\r
+        ZCLOSE(us.z_filefunc, us.filestream);\r
+        return NULL;\r
+    }\r
+\r
+    us.byte_before_the_zipfile = central_pos -\r
+                            (us.offset_central_dir+us.size_central_dir);\r
+    us.central_pos = central_pos;\r
+    us.pfile_in_zip_read = NULL;\r
+    us.encrypted = 0;\r
+\r
+\r
+    s=(unz_s*)ALLOC(sizeof(unz_s));\r
+    *s=us;\r
+    unzGoToFirstFile((unzFile)s);\r
+    return (unzFile)s;\r
+}\r
+\r
+\r
+extern unzFile ZEXPORT unzOpen (path)\r
+    const char *path;\r
+{\r
+    return unzOpen2(path, NULL);\r
+}\r
+\r
+/*\r
+  Close a ZipFile opened with unzipOpen.\r
+  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),\r
+    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.\r
+  return UNZ_OK if there is no problem. */\r
+extern int ZEXPORT unzClose (file)\r
+    unzFile file;\r
+{\r
+    unz_s* s;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+\r
+    if (s->pfile_in_zip_read!=NULL)\r
+        unzCloseCurrentFile(file);\r
+\r
+    ZCLOSE(s->z_filefunc, s->filestream);\r
+    TRYFREE(s);\r
+    return UNZ_OK;\r
+}\r
+\r
+\r
+/*\r
+  Write info about the ZipFile in the *pglobal_info structure.\r
+  No preparation of the structure is needed\r
+  return UNZ_OK if there is no problem. */\r
+extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)\r
+    unzFile file;\r
+    unz_global_info *pglobal_info;\r
+{\r
+    unz_s* s;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    *pglobal_info=s->gi;\r
+    return UNZ_OK;\r
+}\r
+\r
+\r
+/*\r
+   Translate date/time from Dos format to tm_unz (readable more easilty)\r
+*/\r
+local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)\r
+    uLong ulDosDate;\r
+    tm_unz* ptm;\r
+{\r
+    uLong uDate;\r
+    uDate = (uLong)(ulDosDate>>16);\r
+    ptm->tm_mday = (uInt)(uDate&0x1f) ;\r
+    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;\r
+    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;\r
+\r
+    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);\r
+    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;\r
+    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;\r
+}\r
+\r
+/*\r
+  Get Info about the current file in the zipfile, with internal only info\r
+*/\r
+local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,\r
+                                                  unz_file_info *pfile_info,\r
+                                                  unz_file_info_internal\r
+                                                  *pfile_info_internal,\r
+                                                  char *szFileName,\r
+                                                  uLong fileNameBufferSize,\r
+                                                  void *extraField,\r
+                                                  uLong extraFieldBufferSize,\r
+                                                  char *szComment,\r
+                                                  uLong commentBufferSize));\r
+\r
+local int unzlocal_GetCurrentFileInfoInternal (file,\r
+                                              pfile_info,\r
+                                              pfile_info_internal,\r
+                                              szFileName, fileNameBufferSize,\r
+                                              extraField, extraFieldBufferSize,\r
+                                              szComment,  commentBufferSize)\r
+    unzFile file;\r
+    unz_file_info *pfile_info;\r
+    unz_file_info_internal *pfile_info_internal;\r
+    char *szFileName;\r
+    uLong fileNameBufferSize;\r
+    void *extraField;\r
+    uLong extraFieldBufferSize;\r
+    char *szComment;\r
+    uLong commentBufferSize;\r
+{\r
+    unz_s* s;\r
+    unz_file_info file_info;\r
+    unz_file_info_internal file_info_internal;\r
+    int err=UNZ_OK;\r
+    uLong uMagic;\r
+    long lSeek=0;\r
+\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    if (ZSEEK(s->z_filefunc, s->filestream,\r
+              s->pos_in_central_dir+s->byte_before_the_zipfile,\r
+              ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+        err=UNZ_ERRNO;\r
+\r
+\r
+    /* we check the magic */\r
+    if (err==UNZ_OK)\r
+        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)\r
+            err=UNZ_ERRNO;\r
+        else if (uMagic!=0x02014b50)\r
+            err=UNZ_BADZIPFILE;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    lSeek+=file_info.size_filename;\r
+    if ((err==UNZ_OK) && (szFileName!=NULL))\r
+    {\r
+        uLong uSizeRead ;\r
+        if (file_info.size_filename<fileNameBufferSize)\r
+        {\r
+            *(szFileName+file_info.size_filename)='\0';\r
+            uSizeRead = file_info.size_filename;\r
+        }\r
+        else\r
+            uSizeRead = fileNameBufferSize;\r
+\r
+        if ((file_info.size_filename>0) && (fileNameBufferSize>0))\r
+            if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)\r
+                err=UNZ_ERRNO;\r
+        lSeek -= uSizeRead;\r
+    }\r
+\r
+\r
+    if ((err==UNZ_OK) && (extraField!=NULL))\r
+    {\r
+        uLong uSizeRead ;\r
+        if (file_info.size_file_extra<extraFieldBufferSize)\r
+            uSizeRead = file_info.size_file_extra;\r
+        else\r
+            uSizeRead = extraFieldBufferSize;\r
+\r
+        if (lSeek!=0)\r
+            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)\r
+                lSeek=0;\r
+            else\r
+                err=UNZ_ERRNO;\r
+        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))\r
+            if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)\r
+                err=UNZ_ERRNO;\r
+        lSeek += file_info.size_file_extra - uSizeRead;\r
+    }\r
+    else\r
+        lSeek+=file_info.size_file_extra;\r
+\r
+\r
+    if ((err==UNZ_OK) && (szComment!=NULL))\r
+    {\r
+        uLong uSizeRead ;\r
+        if (file_info.size_file_comment<commentBufferSize)\r
+        {\r
+            *(szComment+file_info.size_file_comment)='\0';\r
+            uSizeRead = file_info.size_file_comment;\r
+        }\r
+        else\r
+            uSizeRead = commentBufferSize;\r
+\r
+        if (lSeek!=0)\r
+            if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)\r
+                lSeek=0;\r
+            else\r
+                err=UNZ_ERRNO;\r
+        if ((file_info.size_file_comment>0) && (commentBufferSize>0))\r
+            if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)\r
+                err=UNZ_ERRNO;\r
+        lSeek+=file_info.size_file_comment - uSizeRead;\r
+    }\r
+    else\r
+        lSeek+=file_info.size_file_comment;\r
+\r
+    if ((err==UNZ_OK) && (pfile_info!=NULL))\r
+        *pfile_info=file_info;\r
+\r
+    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))\r
+        *pfile_info_internal=file_info_internal;\r
+\r
+    return err;\r
+}\r
+\r
+\r
+\r
+/*\r
+  Write info about the ZipFile in the *pglobal_info structure.\r
+  No preparation of the structure is needed\r
+  return UNZ_OK if there is no problem.\r
+*/\r
+extern int ZEXPORT unzGetCurrentFileInfo (file,\r
+                                          pfile_info,\r
+                                          szFileName, fileNameBufferSize,\r
+                                          extraField, extraFieldBufferSize,\r
+                                          szComment,  commentBufferSize)\r
+    unzFile file;\r
+    unz_file_info *pfile_info;\r
+    char *szFileName;\r
+    uLong fileNameBufferSize;\r
+    void *extraField;\r
+    uLong extraFieldBufferSize;\r
+    char *szComment;\r
+    uLong commentBufferSize;\r
+{\r
+    return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,\r
+                                                szFileName,fileNameBufferSize,\r
+                                                extraField,extraFieldBufferSize,\r
+                                                szComment,commentBufferSize);\r
+}\r
+\r
+/*\r
+  Set the current file of the zipfile to the first file.\r
+  return UNZ_OK if there is no problem\r
+*/\r
+extern int ZEXPORT unzGoToFirstFile (file)\r
+    unzFile file;\r
+{\r
+    int err=UNZ_OK;\r
+    unz_s* s;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    s->pos_in_central_dir=s->offset_central_dir;\r
+    s->num_file=0;\r
+    err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,\r
+                                             &s->cur_file_info_internal,\r
+                                             NULL,0,NULL,0,NULL,0);\r
+    s->current_file_ok = (err == UNZ_OK);\r
+    return err;\r
+}\r
+\r
+/*\r
+  Set the current file of the zipfile to the next file.\r
+  return UNZ_OK if there is no problem\r
+  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.\r
+*/\r
+extern int ZEXPORT unzGoToNextFile (file)\r
+    unzFile file;\r
+{\r
+    unz_s* s;\r
+    int err;\r
+\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    if (!s->current_file_ok)\r
+        return UNZ_END_OF_LIST_OF_FILE;\r
+    if (s->num_file+1==s->gi.number_entry)\r
+        return UNZ_END_OF_LIST_OF_FILE;\r
+\r
+    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +\r
+            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;\r
+    s->num_file++;\r
+    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,\r
+                                               &s->cur_file_info_internal,\r
+                                               NULL,0,NULL,0,NULL,0);\r
+    s->current_file_ok = (err == UNZ_OK);\r
+    return err;\r
+}\r
+\r
+\r
+/*\r
+  Try locate the file szFileName in the zipfile.\r
+  For the iCaseSensitivity signification, see unzipStringFileNameCompare\r
+\r
+  return value :\r
+  UNZ_OK if the file is found. It becomes the current file.\r
+  UNZ_END_OF_LIST_OF_FILE if the file is not found\r
+*/\r
+extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)\r
+    unzFile file;\r
+    const char *szFileName;\r
+    int iCaseSensitivity;\r
+{\r
+    unz_s* s;\r
+    int err;\r
+\r
+\r
+    uLong num_fileSaved;\r
+    uLong pos_in_central_dirSaved;\r
+\r
+\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)\r
+        return UNZ_PARAMERROR;\r
+\r
+    s=(unz_s*)file;\r
+    if (!s->current_file_ok)\r
+        return UNZ_END_OF_LIST_OF_FILE;\r
+\r
+    num_fileSaved = s->num_file;\r
+    pos_in_central_dirSaved = s->pos_in_central_dir;\r
+\r
+    err = unzGoToFirstFile(file);\r
+\r
+    while (err == UNZ_OK)\r
+    {\r
+        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];\r
+        unzGetCurrentFileInfo(file,NULL,\r
+                                szCurrentFileName,sizeof(szCurrentFileName)-1,\r
+                                NULL,0,NULL,0);\r
+        if (unzStringFileNameCompare(szCurrentFileName,\r
+                                        szFileName,iCaseSensitivity)==0)\r
+            return UNZ_OK;\r
+        err = unzGoToNextFile(file);\r
+    }\r
+\r
+    s->num_file = num_fileSaved ;\r
+    s->pos_in_central_dir = pos_in_central_dirSaved ;\r
+    return err;\r
+}\r
+\r
+\r
+/*\r
+///////////////////////////////////////////\r
+// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)\r
+// I need random access\r
+//\r
+// Further optimization could be realized by adding an ability\r
+// to cache the directory in memory. The goal being a single\r
+// comprehensive file read to put the file I need in a memory.\r
+*/\r
+\r
+/*\r
+typedef struct unz_file_pos_s\r
+{\r
+    uLong pos_in_zip_directory;   // offset in file\r
+    uLong num_of_file;            // # of file\r
+} unz_file_pos;\r
+*/\r
+\r
+extern int ZEXPORT unzGetFilePos(file, file_pos)\r
+    unzFile file;\r
+    unz_file_pos* file_pos;\r
+{\r
+    unz_s* s;\r
+\r
+    if (file==NULL || file_pos==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    if (!s->current_file_ok)\r
+        return UNZ_END_OF_LIST_OF_FILE;\r
+\r
+    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;\r
+    file_pos->num_of_file           = s->num_file;\r
+\r
+    return UNZ_OK;\r
+}\r
+\r
+extern int ZEXPORT unzGoToFilePos(file, file_pos)\r
+    unzFile file;\r
+    unz_file_pos* file_pos;\r
+{\r
+    unz_s* s;\r
+    int err;\r
+\r
+    if (file==NULL || file_pos==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+\r
+    /* jump to the right spot */\r
+    s->pos_in_central_dir = file_pos->pos_in_zip_directory;\r
+    s->num_file           = file_pos->num_of_file;\r
+\r
+    /* set the current file */\r
+    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,\r
+                                               &s->cur_file_info_internal,\r
+                                               NULL,0,NULL,0,NULL,0);\r
+    /* return results */\r
+    s->current_file_ok = (err == UNZ_OK);\r
+    return err;\r
+}\r
+\r
+/*\r
+// Unzip Helper Functions - should be here?\r
+///////////////////////////////////////////\r
+*/\r
+\r
+/*\r
+  Read the local header of the current zipfile\r
+  Check the coherency of the local header and info in the end of central\r
+        directory about this file\r
+  store in *piSizeVar the size of extra info in local header\r
+        (filename and size of extra field data)\r
+*/\r
+local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,\r
+                                                    poffset_local_extrafield,\r
+                                                    psize_local_extrafield)\r
+    unz_s* s;\r
+    uInt* piSizeVar;\r
+    uLong *poffset_local_extrafield;\r
+    uInt  *psize_local_extrafield;\r
+{\r
+    uLong uMagic,uData,uFlags;\r
+    uLong size_filename;\r
+    uLong size_extra_field;\r
+    int err=UNZ_OK;\r
+\r
+    *piSizeVar = 0;\r
+    *poffset_local_extrafield = 0;\r
+    *psize_local_extrafield = 0;\r
+\r
+    if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +\r
+                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+        return UNZ_ERRNO;\r
+\r
+\r
+    if (err==UNZ_OK)\r
+        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)\r
+            err=UNZ_ERRNO;\r
+        else if (uMagic!=0x04034b50)\r
+            err=UNZ_BADZIPFILE;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+/*\r
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))\r
+        err=UNZ_BADZIPFILE;\r
+*/\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&\r
+                         (s->cur_file_info.compression_method!=Z_DEFLATED))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */\r
+        err=UNZ_ERRNO;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */\r
+        err=UNZ_ERRNO;\r
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&\r
+                              ((uFlags & 8)==0))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */\r
+        err=UNZ_ERRNO;\r
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&\r
+                              ((uFlags & 8)==0))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */\r
+        err=UNZ_ERRNO;\r
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&\r
+                              ((uFlags & 8)==0))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    *piSizeVar += (uInt)size_filename;\r
+\r
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)\r
+        err=UNZ_ERRNO;\r
+    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +\r
+                                    SIZEZIPLOCALHEADER + size_filename;\r
+    *psize_local_extrafield = (uInt)size_extra_field;\r
+\r
+    *piSizeVar += (uInt)size_extra_field;\r
+\r
+    return err;\r
+}\r
+\r
+/*\r
+  Open for reading data the current file in the zipfile.\r
+  If there is no error and the file is opened, the return value is UNZ_OK.\r
+*/\r
+extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)\r
+    unzFile file;\r
+    int* method;\r
+    int* level;\r
+    int raw;\r
+    const char* password;\r
+{\r
+    int err=UNZ_OK;\r
+    uInt iSizeVar;\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    uLong offset_local_extrafield;  /* offset of the local extra field */\r
+    uInt  size_local_extrafield;    /* size of the local extra field */\r
+    #ifndef NOUNCRYPT\r
+    char source[12];\r
+    #else\r
+    if (password != NULL)\r
+        return UNZ_PARAMERROR;\r
+    #endif\r
+\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    if (!s->current_file_ok)\r
+        return UNZ_PARAMERROR;\r
+\r
+    if (s->pfile_in_zip_read != NULL)\r
+        unzCloseCurrentFile(file);\r
+\r
+    if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,\r
+                &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)\r
+        return UNZ_BADZIPFILE;\r
+\r
+    pfile_in_zip_read_info = (file_in_zip_read_info_s*)\r
+                                        ALLOC(sizeof(file_in_zip_read_info_s));\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_INTERNALERROR;\r
+\r
+    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);\r
+    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;\r
+    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;\r
+    pfile_in_zip_read_info->pos_local_extrafield=0;\r
+    pfile_in_zip_read_info->raw=raw;\r
+\r
+    if (pfile_in_zip_read_info->read_buffer==NULL)\r
+    {\r
+        TRYFREE(pfile_in_zip_read_info);\r
+        return UNZ_INTERNALERROR;\r
+    }\r
+\r
+    pfile_in_zip_read_info->stream_initialised=0;\r
+\r
+    if (method!=NULL)\r
+        *method = (int)s->cur_file_info.compression_method;\r
+\r
+    if (level!=NULL)\r
+    {\r
+        *level = 6;\r
+        switch (s->cur_file_info.flag & 0x06)\r
+        {\r
+          case 6 : *level = 1; break;\r
+          case 4 : *level = 2; break;\r
+          case 2 : *level = 9; break;\r
+        }\r
+    }\r
+\r
+    if ((s->cur_file_info.compression_method!=0) &&\r
+        (s->cur_file_info.compression_method!=Z_DEFLATED))\r
+        err=UNZ_BADZIPFILE;\r
+\r
+    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;\r
+    pfile_in_zip_read_info->crc32=0;\r
+    pfile_in_zip_read_info->compression_method =\r
+            s->cur_file_info.compression_method;\r
+    pfile_in_zip_read_info->filestream=s->filestream;\r
+    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;\r
+    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;\r
+\r
+    pfile_in_zip_read_info->stream.total_out = 0;\r
+\r
+    if ((s->cur_file_info.compression_method==Z_DEFLATED) &&\r
+        (!raw))\r
+    {\r
+      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;\r
+      pfile_in_zip_read_info->stream.zfree = (free_func)0;\r
+      pfile_in_zip_read_info->stream.opaque = (voidpf)0;\r
+      pfile_in_zip_read_info->stream.next_in = (voidpf)0;\r
+      pfile_in_zip_read_info->stream.avail_in = 0;\r
+\r
+      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);\r
+      if (err == Z_OK)\r
+        pfile_in_zip_read_info->stream_initialised=1;\r
+      else\r
+        return err;\r
+        /* windowBits is passed < 0 to tell that there is no zlib header.\r
+         * Note that in this case inflate *requires* an extra "dummy" byte\r
+         * after the compressed stream in order to complete decompression and\r
+         * return Z_STREAM_END.\r
+         * In unzip, i don't wait absolutely Z_STREAM_END because I known the\r
+         * size of both compressed and uncompressed data\r
+         */\r
+    }\r
+    pfile_in_zip_read_info->rest_read_compressed =\r
+            s->cur_file_info.compressed_size ;\r
+    pfile_in_zip_read_info->rest_read_uncompressed =\r
+            s->cur_file_info.uncompressed_size ;\r
+\r
+\r
+    pfile_in_zip_read_info->pos_in_zipfile =\r
+            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +\r
+              iSizeVar;\r
+\r
+    pfile_in_zip_read_info->stream.avail_in = (uInt)0;\r
+\r
+    s->pfile_in_zip_read = pfile_in_zip_read_info;\r
+\r
+    #ifndef NOUNCRYPT\r
+    if (password != NULL)\r
+    {\r
+        int i;\r
+        s->pcrc_32_tab = get_crc_table();\r
+        init_keys(password,s->keys,s->pcrc_32_tab);\r
+        if (ZSEEK(s->z_filefunc, s->filestream,\r
+                  s->pfile_in_zip_read->pos_in_zipfile +\r
+                     s->pfile_in_zip_read->byte_before_the_zipfile,\r
+                  SEEK_SET)!=0)\r
+            return UNZ_INTERNALERROR;\r
+        if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)\r
+            return UNZ_INTERNALERROR;\r
+\r
+        for (i = 0; i<12; i++)\r
+            zdecode(s->keys,s->pcrc_32_tab,source[i]);\r
+\r
+        s->pfile_in_zip_read->pos_in_zipfile+=12;\r
+        s->encrypted=1;\r
+    }\r
+    #endif\r
+\r
+\r
+    return UNZ_OK;\r
+}\r
+\r
+extern int ZEXPORT unzOpenCurrentFile (file)\r
+    unzFile file;\r
+{\r
+    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);\r
+}\r
+\r
+extern int ZEXPORT unzOpenCurrentFilePassword (file, password)\r
+    unzFile file;\r
+    const char* password;\r
+{\r
+    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);\r
+}\r
+\r
+extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)\r
+    unzFile file;\r
+    int* method;\r
+    int* level;\r
+    int raw;\r
+{\r
+    return unzOpenCurrentFile3(file, method, level, raw, NULL);\r
+}\r
+\r
+/*\r
+  Read bytes from the current file.\r
+  buf contain buffer where data must be copied\r
+  len the size of buf.\r
+\r
+  return the number of byte copied if somes bytes are copied\r
+  return 0 if the end of file was reached\r
+  return <0 with error code if there is an error\r
+    (UNZ_ERRNO for IO error, or zLib error for uncompress error)\r
+*/\r
+extern int ZEXPORT unzReadCurrentFile  (file, buf, len)\r
+    unzFile file;\r
+    voidp buf;\r
+    unsigned len;\r
+{\r
+    int err=UNZ_OK;\r
+    uInt iRead = 0;\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    pfile_in_zip_read_info=s->pfile_in_zip_read;\r
+\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+\r
+    if ((pfile_in_zip_read_info->read_buffer == NULL))\r
+        return UNZ_END_OF_LIST_OF_FILE;\r
+    if (len==0)\r
+        return 0;\r
+\r
+    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;\r
+\r
+    pfile_in_zip_read_info->stream.avail_out = (uInt)len;\r
+\r
+    if (len>pfile_in_zip_read_info->rest_read_uncompressed)\r
+        pfile_in_zip_read_info->stream.avail_out =\r
+          (uInt)pfile_in_zip_read_info->rest_read_uncompressed;\r
+\r
+    while (pfile_in_zip_read_info->stream.avail_out>0)\r
+    {\r
+        if ((pfile_in_zip_read_info->stream.avail_in==0) &&\r
+            (pfile_in_zip_read_info->rest_read_compressed>0))\r
+        {\r
+            uInt uReadThis = UNZ_BUFSIZE;\r
+            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)\r
+                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;\r
+            if (uReadThis == 0)\r
+                return UNZ_EOF;\r
+            if (ZSEEK(pfile_in_zip_read_info->z_filefunc,\r
+                      pfile_in_zip_read_info->filestream,\r
+                      pfile_in_zip_read_info->pos_in_zipfile +\r
+                         pfile_in_zip_read_info->byte_before_the_zipfile,\r
+                         ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+                return UNZ_ERRNO;\r
+            if (ZREAD(pfile_in_zip_read_info->z_filefunc,\r
+                      pfile_in_zip_read_info->filestream,\r
+                      pfile_in_zip_read_info->read_buffer,\r
+                      uReadThis)!=uReadThis)\r
+                return UNZ_ERRNO;\r
+\r
+\r
+            #ifndef NOUNCRYPT\r
+            if(s->encrypted)\r
+            {\r
+                uInt i;\r
+                for(i=0;i<uReadThis;i++)\r
+                  pfile_in_zip_read_info->read_buffer[i] =\r
+                      zdecode(s->keys,s->pcrc_32_tab,\r
+                              pfile_in_zip_read_info->read_buffer[i]);\r
+            }\r
+            #endif\r
+\r
+\r
+            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;\r
+\r
+            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;\r
+\r
+            pfile_in_zip_read_info->stream.next_in =\r
+                (Bytef*)pfile_in_zip_read_info->read_buffer;\r
+            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;\r
+        }\r
+\r
+        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))\r
+        {\r
+            uInt uDoCopy,i ;\r
+\r
+            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&\r
+                (pfile_in_zip_read_info->rest_read_compressed == 0))\r
+                return (iRead==0) ? UNZ_EOF : iRead;\r
+\r
+            if (pfile_in_zip_read_info->stream.avail_out <\r
+                            pfile_in_zip_read_info->stream.avail_in)\r
+                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;\r
+            else\r
+                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;\r
+\r
+            for (i=0;i<uDoCopy;i++)\r
+                *(pfile_in_zip_read_info->stream.next_out+i) =\r
+                        *(pfile_in_zip_read_info->stream.next_in+i);\r
+\r
+            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,\r
+                                pfile_in_zip_read_info->stream.next_out,\r
+                                uDoCopy);\r
+            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;\r
+            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;\r
+            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;\r
+            pfile_in_zip_read_info->stream.next_out += uDoCopy;\r
+            pfile_in_zip_read_info->stream.next_in += uDoCopy;\r
+            pfile_in_zip_read_info->stream.total_out += uDoCopy;\r
+            iRead += uDoCopy;\r
+        }\r
+        else\r
+        {\r
+            uLong uTotalOutBefore,uTotalOutAfter;\r
+            const Bytef *bufBefore;\r
+            uLong uOutThis;\r
+            int flush=Z_SYNC_FLUSH;\r
+\r
+            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;\r
+            bufBefore = pfile_in_zip_read_info->stream.next_out;\r
+\r
+            /*\r
+            if ((pfile_in_zip_read_info->rest_read_uncompressed ==\r
+                     pfile_in_zip_read_info->stream.avail_out) &&\r
+                (pfile_in_zip_read_info->rest_read_compressed == 0))\r
+                flush = Z_FINISH;\r
+            */\r
+            err=inflate(&pfile_in_zip_read_info->stream,flush);\r
+\r
+            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;\r
+            uOutThis = uTotalOutAfter-uTotalOutBefore;\r
+\r
+            pfile_in_zip_read_info->crc32 =\r
+                crc32(pfile_in_zip_read_info->crc32,bufBefore,\r
+                        (uInt)(uOutThis));\r
+\r
+            pfile_in_zip_read_info->rest_read_uncompressed -=\r
+                uOutThis;\r
+\r
+            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);\r
+\r
+            if (err==Z_STREAM_END)\r
+                return (iRead==0) ? UNZ_EOF : iRead;\r
+            if (err!=Z_OK)\r
+                break;\r
+        }\r
+    }\r
+\r
+    if (err==Z_OK)\r
+        return iRead;\r
+    return err;\r
+}\r
+\r
+\r
+/*\r
+  Give the current position in uncompressed data\r
+*/\r
+extern z_off_t ZEXPORT unztell (file)\r
+    unzFile file;\r
+{\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    pfile_in_zip_read_info=s->pfile_in_zip_read;\r
+\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+    return (z_off_t)pfile_in_zip_read_info->stream.total_out;\r
+}\r
+\r
+\r
+/*\r
+  return 1 if the end of file was reached, 0 elsewhere\r
+*/\r
+extern int ZEXPORT unzeof (file)\r
+    unzFile file;\r
+{\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    pfile_in_zip_read_info=s->pfile_in_zip_read;\r
+\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)\r
+        return 1;\r
+    else\r
+        return 0;\r
+}\r
+\r
+\r
+\r
+/*\r
+  Read extra field from the current file (opened by unzOpenCurrentFile)\r
+  This is the local-header version of the extra field (sometimes, there is\r
+    more info in the local-header version than in the central-header)\r
+\r
+  if buf==NULL, it return the size of the local extra field that can be read\r
+\r
+  if buf!=NULL, len is the size of the buffer, the extra header is copied in\r
+    buf.\r
+  the return value is the number of bytes copied in buf, or (if <0)\r
+    the error code\r
+*/\r
+extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)\r
+    unzFile file;\r
+    voidp buf;\r
+    unsigned len;\r
+{\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    uInt read_now;\r
+    uLong size_to_read;\r
+\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    pfile_in_zip_read_info=s->pfile_in_zip_read;\r
+\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -\r
+                pfile_in_zip_read_info->pos_local_extrafield);\r
+\r
+    if (buf==NULL)\r
+        return (int)size_to_read;\r
+\r
+    if (len>size_to_read)\r
+        read_now = (uInt)size_to_read;\r
+    else\r
+        read_now = (uInt)len ;\r
+\r
+    if (read_now==0)\r
+        return 0;\r
+\r
+    if (ZSEEK(pfile_in_zip_read_info->z_filefunc,\r
+              pfile_in_zip_read_info->filestream,\r
+              pfile_in_zip_read_info->offset_local_extrafield +\r
+              pfile_in_zip_read_info->pos_local_extrafield,\r
+              ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+        return UNZ_ERRNO;\r
+\r
+    if (ZREAD(pfile_in_zip_read_info->z_filefunc,\r
+              pfile_in_zip_read_info->filestream,\r
+              buf,size_to_read)!=size_to_read)\r
+        return UNZ_ERRNO;\r
+\r
+    return (int)read_now;\r
+}\r
+\r
+/*\r
+  Close the file in zip opened with unzipOpenCurrentFile\r
+  Return UNZ_CRCERROR if all the file was read but the CRC is not good\r
+*/\r
+extern int ZEXPORT unzCloseCurrentFile (file)\r
+    unzFile file;\r
+{\r
+    int err=UNZ_OK;\r
+\r
+    unz_s* s;\r
+    file_in_zip_read_info_s* pfile_in_zip_read_info;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+    pfile_in_zip_read_info=s->pfile_in_zip_read;\r
+\r
+    if (pfile_in_zip_read_info==NULL)\r
+        return UNZ_PARAMERROR;\r
+\r
+\r
+    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&\r
+        (!pfile_in_zip_read_info->raw))\r
+    {\r
+        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)\r
+            err=UNZ_CRCERROR;\r
+    }\r
+\r
+\r
+    TRYFREE(pfile_in_zip_read_info->read_buffer);\r
+    pfile_in_zip_read_info->read_buffer = NULL;\r
+    if (pfile_in_zip_read_info->stream_initialised)\r
+        inflateEnd(&pfile_in_zip_read_info->stream);\r
+\r
+    pfile_in_zip_read_info->stream_initialised = 0;\r
+    TRYFREE(pfile_in_zip_read_info);\r
+\r
+    s->pfile_in_zip_read=NULL;\r
+\r
+    return err;\r
+}\r
+\r
+\r
+/*\r
+  Get the global comment string of the ZipFile, in the szComment buffer.\r
+  uSizeBuf is the size of the szComment buffer.\r
+  return the number of byte copied or an error code <0\r
+*/\r
+extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)\r
+    unzFile file;\r
+    char *szComment;\r
+    uLong uSizeBuf;\r
+{\r
+    int err=UNZ_OK;\r
+    unz_s* s;\r
+    uLong uReadThis ;\r
+    if (file==NULL)\r
+        return UNZ_PARAMERROR;\r
+    s=(unz_s*)file;\r
+\r
+    uReadThis = uSizeBuf;\r
+    if (uReadThis>s->gi.size_comment)\r
+        uReadThis = s->gi.size_comment;\r
+\r
+    if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+        return UNZ_ERRNO;\r
+\r
+    if (uReadThis>0)\r
+    {\r
+      *szComment='\0';\r
+      if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)\r
+        return UNZ_ERRNO;\r
+    }\r
+\r
+    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))\r
+        *(szComment+s->gi.size_comment)='\0';\r
+    return (int)uReadThis;\r
+}\r
index 67ca851613905afe2cfcaa752e67488a334964d2..48e6832067850c887e4e89f8c5662e7bdceb6636 100644 (file)
-/* unzip.h -- IO for uncompress .zip files using zlib
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-
-   This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
-     WinZip, InfoZip tools and compatible.
-   Encryption and multi volume ZipFile (span) are not supported.
-   Old compressions used by old PKZip 1.x are not supported
-
-
-   I WAIT FEEDBACK at mail info@winimage.com
-   Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
-
-   Condition of use and distribution are the same than zlib :
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-
-*/
-
-/* for more info about .ZIP format, see
-      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
-      http://www.info-zip.org/pub/infozip/doc/
-   PkWare has also a specification at :
-      ftp://ftp.pkware.com/probdesc.zip
-*/
-
-#ifndef _unz_H
-#define _unz_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
-    from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK                          (0)
-#define UNZ_END_OF_LIST_OF_FILE         (-100)
-#define UNZ_ERRNO                       (Z_ERRNO)
-#define UNZ_EOF                         (0)
-#define UNZ_PARAMERROR                  (-102)
-#define UNZ_BADZIPFILE                  (-103)
-#define UNZ_INTERNALERROR               (-104)
-#define UNZ_CRCERROR                    (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
-    uInt tm_sec;            /* seconds after the minute - [0,59] */
-    uInt tm_min;            /* minutes after the hour - [0,59] */
-    uInt tm_hour;           /* hours since midnight - [0,23] */
-    uInt tm_mday;           /* day of the month - [1,31] */
-    uInt tm_mon;            /* months since January - [0,11] */
-    uInt tm_year;           /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
-   These data comes from the end of central dir */
-typedef struct unz_global_info_s
-{
-    uLong number_entry;         /* total number of entries in
-                       the central dir on this disk */
-    uLong size_comment;         /* size of the global comment of the zipfile */
-} unz_global_info;
-
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info_s
-{
-    uLong version;              /* version made by                 2 bytes */
-    uLong version_needed;       /* version needed to extract       2 bytes */
-    uLong flag;                 /* general purpose bit flag        2 bytes */
-    uLong compression_method;   /* compression method              2 bytes */
-    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
-    uLong crc;                  /* crc-32                          4 bytes */
-    uLong compressed_size;      /* compressed size                 4 bytes */
-    uLong uncompressed_size;    /* uncompressed size               4 bytes */
-    uLong size_filename;        /* filename length                 2 bytes */
-    uLong size_file_extra;      /* extra field length              2 bytes */
-    uLong size_file_comment;    /* file comment length             2 bytes */
-
-    uLong disk_num_start;       /* disk number start               2 bytes */
-    uLong internal_fa;          /* internal file attributes        2 bytes */
-    uLong external_fa;          /* external file attributes        4 bytes */
-
-    tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
-                                                 const char* fileName2,
-                                                 int iCaseSensitivity));
-/*
-   Compare two filename (fileName1,fileName2).
-   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
-   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
-                                or strcasecmp)
-   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
-    (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-/*
-  Open a Zip file. path contain the full pathname (by example,
-     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
-     "zlib/zlib113.zip".
-     If the zipfile cannot be opened (file don't exist or in not valid), the
-       return value is NULL.
-     Else, the return value is a unzFile Handle, usable with other function
-       of this unzip package.
-*/
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
-                                    zlib_filefunc_def* pzlib_filefunc_def));
-/*
-   Open a Zip file, like unzOpen, but provide a set of file low level API
-      for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
-  Close a ZipFile opened with unzipOpen.
-  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
-    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
-  return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
-                                        unz_global_info *pglobal_info));
-/*
-  Write info about the ZipFile in the *pglobal_info structure.
-  No preparation of the structure is needed
-  return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
-                                           char *szComment,
-                                           uLong uSizeBuf));
-/*
-  Get the global comment string of the ZipFile, in the szComment buffer.
-  uSizeBuf is the size of the szComment buffer.
-  return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
-  Set the current file of the zipfile to the first file.
-  return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
-  Set the current file of the zipfile to the next file.
-  return UNZ_OK if there is no problem
-  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
-                     const char *szFileName,
-                     int iCaseSensitivity));
-/*
-  Try locate the file szFileName in the zipfile.
-  For the iCaseSensitivity signification, see unzStringFileNameCompare
-
-  return value :
-  UNZ_OK if the file is found. It becomes the current file.
-  UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
-    uLong pos_in_zip_directory;   /* offset in zip file directory */
-    uLong num_of_file;            /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
-    unzFile file,
-    unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
-    unzFile file,
-    unz_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
-                         unz_file_info *pfile_info,
-                         char *szFileName,
-                         uLong fileNameBufferSize,
-                         void *extraField,
-                         uLong extraFieldBufferSize,
-                         char *szComment,
-                         uLong commentBufferSize));
-/*
-  Get Info about the current file
-  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
-        the current file
-  if szFileName!=NULL, the filemane string will be copied in szFileName
-            (fileNameBufferSize is the size of the buffer)
-  if extraField!=NULL, the extra field information will be copied in extraField
-            (extraFieldBufferSize is the size of the buffer).
-            This is the Central-header version of the extra field
-  if szComment!=NULL, the comment string of the file will be copied in szComment
-            (commentBufferSize is the size of the buffer)
-*/
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
-   from it, and close it (you can close it before reading all the file)
-   */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
-  Open for reading data the current file in the zipfile.
-  If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
-                                                  const char* password));
-/*
-  Open for reading data the current file in the zipfile.
-  password is a crypting password
-  If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
-                                           int* method,
-                                           int* level,
-                                           int raw));
-/*
-  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
-    if raw==1
-  *method will receive method of compression, *level will receive level of
-     compression
-  note : you can set level parameter as NULL (if you did not want known level,
-         but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
-                                           int* method,
-                                           int* level,
-                                           int raw,
-                                           const char* password));
-/*
-  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
-    if raw==1
-  *method will receive method of compression, *level will receive level of
-     compression
-  note : you can set level parameter as NULL (if you did not want known level,
-         but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
-  Close the file in zip opened with unzOpenCurrentFile
-  Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
-                      voidp buf,
-                      unsigned len));
-/*
-  Read bytes from the current file (opened by unzOpenCurrentFile)
-  buf contain buffer where data must be copied
-  len the size of buf.
-
-  return the number of byte copied if somes bytes are copied
-  return 0 if the end of file was reached
-  return <0 with error code if there is an error
-    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-/*
-  Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
-  return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
-                                             voidp buf,
-                                             unsigned len));
-/*
-  Read extra field from the current file (opened by unzOpenCurrentFile)
-  This is the local-header version of the extra field (sometimes, there is
-    more info in the local-header version than in the central-header)
-
-  if buf==NULL, it return the size of the local extra field
-
-  if buf!=NULL, len is the size of the buffer, the extra header is copied in
-    buf.
-  the return value is the number of bytes copied in buf, or (if <0)
-    the error code
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz_H */
+/* unzip.h -- IO for uncompress .zip files using zlib\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+\r
+   This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g\r
+     WinZip, InfoZip tools and compatible.\r
+   Encryption and multi volume ZipFile (span) are not supported.\r
+   Old compressions used by old PKZip 1.x are not supported\r
+\r
+\r
+   I WAIT FEEDBACK at mail info@winimage.com\r
+   Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution\r
+\r
+   Condition of use and distribution are the same than zlib :\r
+\r
+  This software is provided 'as-is', without any express or implied\r
+  warranty.  In no event will the authors be held liable for any damages\r
+  arising from the use of this software.\r
+\r
+  Permission is granted to anyone to use this software for any purpose,\r
+  including commercial applications, and to alter it and redistribute it\r
+  freely, subject to the following restrictions:\r
+\r
+  1. The origin of this software must not be misrepresented; you must not\r
+     claim that you wrote the original software. If you use this software\r
+     in a product, an acknowledgment in the product documentation would be\r
+     appreciated but is not required.\r
+  2. Altered source versions must be plainly marked as such, and must not be\r
+     misrepresented as being the original software.\r
+  3. This notice may not be removed or altered from any source distribution.\r
+\r
+\r
+*/\r
+\r
+/* for more info about .ZIP format, see\r
+      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip\r
+      http://www.info-zip.org/pub/infozip/doc/\r
+   PkWare has also a specification at :\r
+      ftp://ftp.pkware.com/probdesc.zip\r
+*/\r
+\r
+#ifndef _unz_H\r
+#define _unz_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifndef _ZLIB_H\r
+#include "zlib.h"\r
+#endif\r
+\r
+#ifndef _ZLIBIOAPI_H\r
+#include "ioapi.h"\r
+#endif\r
+\r
+#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)\r
+/* like the STRICT of WIN32, we define a pointer that cannot be converted\r
+    from (void*) without cast */\r
+typedef struct TagunzFile__ { int unused; } unzFile__;\r
+typedef unzFile__ *unzFile;\r
+#else\r
+typedef voidp unzFile;\r
+#endif\r
+\r
+\r
+#define UNZ_OK                          (0)\r
+#define UNZ_END_OF_LIST_OF_FILE         (-100)\r
+#define UNZ_ERRNO                       (Z_ERRNO)\r
+#define UNZ_EOF                         (0)\r
+#define UNZ_PARAMERROR                  (-102)\r
+#define UNZ_BADZIPFILE                  (-103)\r
+#define UNZ_INTERNALERROR               (-104)\r
+#define UNZ_CRCERROR                    (-105)\r
+\r
+/* tm_unz contain date/time info */\r
+typedef struct tm_unz_s\r
+{\r
+    uInt tm_sec;            /* seconds after the minute - [0,59] */\r
+    uInt tm_min;            /* minutes after the hour - [0,59] */\r
+    uInt tm_hour;           /* hours since midnight - [0,23] */\r
+    uInt tm_mday;           /* day of the month - [1,31] */\r
+    uInt tm_mon;            /* months since January - [0,11] */\r
+    uInt tm_year;           /* years - [1980..2044] */\r
+} tm_unz;\r
+\r
+/* unz_global_info structure contain global data about the ZIPfile\r
+   These data comes from the end of central dir */\r
+typedef struct unz_global_info_s\r
+{\r
+    uLong number_entry;         /* total number of entries in\r
+                       the central dir on this disk */\r
+    uLong size_comment;         /* size of the global comment of the zipfile */\r
+} unz_global_info;\r
+\r
+\r
+/* unz_file_info contain information about a file in the zipfile */\r
+typedef struct unz_file_info_s\r
+{\r
+    uLong version;              /* version made by                 2 bytes */\r
+    uLong version_needed;       /* version needed to extract       2 bytes */\r
+    uLong flag;                 /* general purpose bit flag        2 bytes */\r
+    uLong compression_method;   /* compression method              2 bytes */\r
+    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */\r
+    uLong crc;                  /* crc-32                          4 bytes */\r
+    uLong compressed_size;      /* compressed size                 4 bytes */\r
+    uLong uncompressed_size;    /* uncompressed size               4 bytes */\r
+    uLong size_filename;        /* filename length                 2 bytes */\r
+    uLong size_file_extra;      /* extra field length              2 bytes */\r
+    uLong size_file_comment;    /* file comment length             2 bytes */\r
+\r
+    uLong disk_num_start;       /* disk number start               2 bytes */\r
+    uLong internal_fa;          /* internal file attributes        2 bytes */\r
+    uLong external_fa;          /* external file attributes        4 bytes */\r
+\r
+    tm_unz tmu_date;\r
+} unz_file_info;\r
+\r
+extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,\r
+                                                 const char* fileName2,\r
+                                                 int iCaseSensitivity));\r
+/*\r
+   Compare two filename (fileName1,fileName2).\r
+   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)\r
+   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi\r
+                                or strcasecmp)\r
+   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system\r
+    (like 1 on Unix, 2 on Windows)\r
+*/\r
+\r
+\r
+extern unzFile ZEXPORT unzOpen OF((const char *path));\r
+/*\r
+  Open a Zip file. path contain the full pathname (by example,\r
+     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer\r
+     "zlib/zlib113.zip".\r
+     If the zipfile cannot be opened (file don't exist or in not valid), the\r
+       return value is NULL.\r
+     Else, the return value is a unzFile Handle, usable with other function\r
+       of this unzip package.\r
+*/\r
+\r
+extern unzFile ZEXPORT unzOpen2 OF((const char *path,\r
+                                    zlib_filefunc_def* pzlib_filefunc_def));\r
+/*\r
+   Open a Zip file, like unzOpen, but provide a set of file low level API\r
+      for read/write the zip file (see ioapi.h)\r
+*/\r
+\r
+extern int ZEXPORT unzClose OF((unzFile file));\r
+/*\r
+  Close a ZipFile opened with unzipOpen.\r
+  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),\r
+    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.\r
+  return UNZ_OK if there is no problem. */\r
+\r
+extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,\r
+                                        unz_global_info *pglobal_info));\r
+/*\r
+  Write info about the ZipFile in the *pglobal_info structure.\r
+  No preparation of the structure is needed\r
+  return UNZ_OK if there is no problem. */\r
+\r
+\r
+extern int ZEXPORT unzGetGlobalComment OF((unzFile file,\r
+                                           char *szComment,\r
+                                           uLong uSizeBuf));\r
+/*\r
+  Get the global comment string of the ZipFile, in the szComment buffer.\r
+  uSizeBuf is the size of the szComment buffer.\r
+  return the number of byte copied or an error code <0\r
+*/\r
+\r
+\r
+/***************************************************************************/\r
+/* Unzip package allow you browse the directory of the zipfile */\r
+\r
+extern int ZEXPORT unzGoToFirstFile OF((unzFile file));\r
+/*\r
+  Set the current file of the zipfile to the first file.\r
+  return UNZ_OK if there is no problem\r
+*/\r
+\r
+extern int ZEXPORT unzGoToNextFile OF((unzFile file));\r
+/*\r
+  Set the current file of the zipfile to the next file.\r
+  return UNZ_OK if there is no problem\r
+  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.\r
+*/\r
+\r
+extern int ZEXPORT unzLocateFile OF((unzFile file,\r
+                     const char *szFileName,\r
+                     int iCaseSensitivity));\r
+/*\r
+  Try locate the file szFileName in the zipfile.\r
+  For the iCaseSensitivity signification, see unzStringFileNameCompare\r
+\r
+  return value :\r
+  UNZ_OK if the file is found. It becomes the current file.\r
+  UNZ_END_OF_LIST_OF_FILE if the file is not found\r
+*/\r
+\r
+\r
+/* ****************************************** */\r
+/* Ryan supplied functions */\r
+/* unz_file_info contain information about a file in the zipfile */\r
+typedef struct unz_file_pos_s\r
+{\r
+    uLong pos_in_zip_directory;   /* offset in zip file directory */\r
+    uLong num_of_file;            /* # of file */\r
+} unz_file_pos;\r
+\r
+extern int ZEXPORT unzGetFilePos(\r
+    unzFile file,\r
+    unz_file_pos* file_pos);\r
+\r
+extern int ZEXPORT unzGoToFilePos(\r
+    unzFile file,\r
+    unz_file_pos* file_pos);\r
+\r
+/* ****************************************** */\r
+\r
+extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,\r
+                         unz_file_info *pfile_info,\r
+                         char *szFileName,\r
+                         uLong fileNameBufferSize,\r
+                         void *extraField,\r
+                         uLong extraFieldBufferSize,\r
+                         char *szComment,\r
+                         uLong commentBufferSize));\r
+/*\r
+  Get Info about the current file\r
+  if pfile_info!=NULL, the *pfile_info structure will contain somes info about\r
+        the current file\r
+  if szFileName!=NULL, the filemane string will be copied in szFileName\r
+            (fileNameBufferSize is the size of the buffer)\r
+  if extraField!=NULL, the extra field information will be copied in extraField\r
+            (extraFieldBufferSize is the size of the buffer).\r
+            This is the Central-header version of the extra field\r
+  if szComment!=NULL, the comment string of the file will be copied in szComment\r
+            (commentBufferSize is the size of the buffer)\r
+*/\r
+\r
+/***************************************************************************/\r
+/* for reading the content of the current zipfile, you can open it, read data\r
+   from it, and close it (you can close it before reading all the file)\r
+   */\r
+\r
+extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));\r
+/*\r
+  Open for reading data the current file in the zipfile.\r
+  If there is no error, the return value is UNZ_OK.\r
+*/\r
+\r
+extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,\r
+                                                  const char* password));\r
+/*\r
+  Open for reading data the current file in the zipfile.\r
+  password is a crypting password\r
+  If there is no error, the return value is UNZ_OK.\r
+*/\r
+\r
+extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,\r
+                                           int* method,\r
+                                           int* level,\r
+                                           int raw));\r
+/*\r
+  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)\r
+    if raw==1\r
+  *method will receive method of compression, *level will receive level of\r
+     compression\r
+  note : you can set level parameter as NULL (if you did not want known level,\r
+         but you CANNOT set method parameter as NULL\r
+*/\r
+\r
+extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,\r
+                                           int* method,\r
+                                           int* level,\r
+                                           int raw,\r
+                                           const char* password));\r
+/*\r
+  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)\r
+    if raw==1\r
+  *method will receive method of compression, *level will receive level of\r
+     compression\r
+  note : you can set level parameter as NULL (if you did not want known level,\r
+         but you CANNOT set method parameter as NULL\r
+*/\r
+\r
+\r
+extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));\r
+/*\r
+  Close the file in zip opened with unzOpenCurrentFile\r
+  Return UNZ_CRCERROR if all the file was read but the CRC is not good\r
+*/\r
+\r
+extern int ZEXPORT unzReadCurrentFile OF((unzFile file,\r
+                      voidp buf,\r
+                      unsigned len));\r
+/*\r
+  Read bytes from the current file (opened by unzOpenCurrentFile)\r
+  buf contain buffer where data must be copied\r
+  len the size of buf.\r
+\r
+  return the number of byte copied if somes bytes are copied\r
+  return 0 if the end of file was reached\r
+  return <0 with error code if there is an error\r
+    (UNZ_ERRNO for IO error, or zLib error for uncompress error)\r
+*/\r
+\r
+extern z_off_t ZEXPORT unztell OF((unzFile file));\r
+/*\r
+  Give the current position in uncompressed data\r
+*/\r
+\r
+extern int ZEXPORT unzeof OF((unzFile file));\r
+/*\r
+  return 1 if the end of file was reached, 0 elsewhere\r
+*/\r
+\r
+extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,\r
+                                             voidp buf,\r
+                                             unsigned len));\r
+/*\r
+  Read extra field from the current file (opened by unzOpenCurrentFile)\r
+  This is the local-header version of the extra field (sometimes, there is\r
+    more info in the local-header version than in the central-header)\r
+\r
+  if buf==NULL, it return the size of the local extra field\r
+\r
+  if buf!=NULL, len is the size of the buffer, the extra header is copied in\r
+    buf.\r
+  the return value is the number of bytes copied in buf, or (if <0)\r
+    the error code\r
+*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _unz_H */\r
diff --git a/contrib/minizip/zconf.h b/contrib/minizip/zconf.h
new file mode 100644 (file)
index 0000000..8e6215a
--- /dev/null
@@ -0,0 +1,326 @@
+/* zconf.h -- configuration of the zlib compression library\r
+ * Copyright (C) 1995-2003 Jean-loup Gailly.\r
+ * For conditions of distribution and use, see copyright notice in zlib.h\r
+ */\r
+\r
+/* @(#) $Id$ */\r
+\r
+#ifndef _ZCONF_H\r
+#define _ZCONF_H\r
+\r
+/*\r
+ * If you *really* need a unique prefix for all types and library functions,\r
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.\r
+ */\r
+#ifdef Z_PREFIX\r
+#  define deflateInit_  z_deflateInit_\r
+#  define deflate       z_deflate\r
+#  define deflateEnd    z_deflateEnd\r
+#  define inflateInit_  z_inflateInit_\r
+#  define inflate       z_inflate\r
+#  define inflateEnd    z_inflateEnd\r
+#  define deflateInit2_ z_deflateInit2_\r
+#  define deflateSetDictionary z_deflateSetDictionary\r
+#  define deflateCopy   z_deflateCopy\r
+#  define deflateReset  z_deflateReset\r
+#  define deflateParams z_deflateParams\r
+#  define deflateBound  z_deflateBound\r
+#  define inflateInit2_ z_inflateInit2_\r
+#  define inflateSetDictionary z_inflateSetDictionary\r
+#  define inflateSync   z_inflateSync\r
+#  define inflateSyncPoint z_inflateSyncPoint\r
+#  define inflateCopy   z_inflateCopy\r
+#  define inflateReset  z_inflateReset\r
+#  define compress      z_compress\r
+#  define compress2     z_compress2\r
+#  define compressBound z_compressBound\r
+#  define uncompress    z_uncompress\r
+#  define adler32       z_adler32\r
+#  define crc32         z_crc32\r
+#  define get_crc_table z_get_crc_table\r
+\r
+#  define Byte          z_Byte\r
+#  define uInt          z_uInt\r
+#  define uLong         z_uLong\r
+#  define Bytef         z_Bytef\r
+#  define charf         z_charf\r
+#  define intf          z_intf\r
+#  define uIntf         z_uIntf\r
+#  define uLongf        z_uLongf\r
+#  define voidpf        z_voidpf\r
+#  define voidp         z_voidp\r
+#endif\r
+\r
+\r
+#ifdef __STDC_VERSION__\r
+#  ifndef STDC\r
+#    define STDC\r
+#  endif\r
+#  if __STDC_VERSION__ >= 199901L\r
+#    ifndef STDC99\r
+#      define STDC99\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+\r
+#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)\r
+#  define WIN32\r
+#endif\r
+#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)\r
+#  ifndef __32BIT__\r
+#    define __32BIT__\r
+#  endif\r
+#endif\r
+#if defined(__MSDOS__) && !defined(MSDOS)\r
+#  define MSDOS\r
+#endif\r
+\r
+/*\r
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more\r
+ * than 64k bytes at a time (needed on systems with 16-bit int).\r
+ */\r
+#if defined(MSDOS) && !defined(__32BIT__)\r
+#  define MAXSEG_64K\r
+#endif\r
+#ifdef MSDOS\r
+#  define UNALIGNED_OK\r
+#endif\r
+\r
+#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)\r
+#  define STDC\r
+#endif\r
+#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)\r
+#  ifndef STDC\r
+#    define STDC\r
+#  endif\r
+#endif\r
+\r
+#if defined __HOS_AIX__\r
+#  ifndef STDC\r
+#    define STDC\r
+#  endif\r
+#endif\r
+\r
+#ifndef STDC\r
+#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */\r
+#    define const   /* note: need a more gentle solution here */\r
+#  endif\r
+#endif\r
+\r
+/* Some Mac compilers merge all .h files incorrectly: */\r
+#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)\r
+#  define NO_DUMMY_DECL\r
+#endif\r
+\r
+/* Old Borland C incorrectly complains about missing returns: */\r
+#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)\r
+#  define NEED_DUMMY_RETURN\r
+#endif\r
+#if defined(__TURBOC__) && !defined(__BORLANDC__)\r
+#  define NEED_DUMMY_RETURN\r
+#endif\r
+\r
+\r
+/* Maximum value for memLevel in deflateInit2 */\r
+#ifndef MAX_MEM_LEVEL\r
+#  ifdef MAXSEG_64K\r
+#    define MAX_MEM_LEVEL 8\r
+#  else\r
+#    define MAX_MEM_LEVEL 9\r
+#  endif\r
+#endif\r
+\r
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.\r
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files\r
+ * created by gzip. (Files created by minigzip can still be extracted by\r
+ * gzip.)\r
+ */\r
+#ifndef MAX_WBITS\r
+#  define MAX_WBITS   15 /* 32K LZ77 window */\r
+#endif\r
+\r
+/* The memory requirements for deflate are (in bytes):\r
+            (1 << (windowBits+2)) +  (1 << (memLevel+9))\r
+ that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)\r
+ plus a few kilobytes for small objects. For example, if you want to reduce\r
+ the default memory requirements from 256K to 128K, compile with\r
+     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"\r
+ Of course this will generally degrade compression (there's no free lunch).\r
+\r
+   The memory requirements for inflate are (in bytes) 1 << windowBits\r
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes\r
+ for small objects.\r
+*/\r
+\r
+                        /* Type declarations */\r
+\r
+#ifndef OF /* function prototypes */\r
+#  ifdef STDC\r
+#    define OF(args)  args\r
+#  else\r
+#    define OF(args)  ()\r
+#  endif\r
+#endif\r
+\r
+/*\r
+ * Microsoft Visual Studio define _vsnprintf but not vsnprintf\r
+ */\r
+#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED)\r
+#  ifdef MSDOS\r
+     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),\r
+        but for now we just assume it doesn't. */\r
+#    define NO_vsnprintf\r
+#  endif\r
+#  ifdef WIN32\r
+     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */\r
+#    if !defined(vsnprintf) && !defined(__TURBOC__)\r
+#      define vsnprintf _vsnprintf\r
+#    endif\r
+#  endif\r
+#  ifdef __TURBOC__\r
+#    define NO_vsnprintf\r
+#  endif\r
+#endif\r
+\r
+/* The following definitions for FAR are needed only for MSDOS mixed\r
+ * model programming (small or medium model with some far allocations).\r
+ * This was tested only with MSC; for other MSDOS compilers you may have\r
+ * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,\r
+ * just define FAR to be empty.\r
+ */\r
+#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)\r
+   /* MSC small or medium model */\r
+#  define SMALL_MEDIUM\r
+#  ifdef _MSC_VER\r
+#    define FAR _far\r
+#  else\r
+#    define FAR far\r
+#  endif\r
+#endif\r
+#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))\r
+#  ifndef __32BIT__\r
+#    define SMALL_MEDIUM\r
+#    define FAR _far\r
+#  endif\r
+#endif\r
+\r
+#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))\r
+#  define ZLIB_DLL\r
+#endif\r
+\r
+/* Compile with -DZLIB_DLL for Windows DLL support */\r
+#if defined(ZLIB_DLL)\r
+#  if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)\r
+#    ifndef WINAPIV\r
+#      ifdef FAR\r
+#        undef FAR\r
+#      endif\r
+#      include <windows.h>\r
+#    endif\r
+#    ifdef WIN32\r
+#      define ZEXPORT  WINAPI\r
+#      define ZEXPORTVA  WINAPIV\r
+#    else\r
+#      define ZEXPORT  WINAPI _export\r
+#      define ZEXPORTVA  FAR _cdecl _export\r
+#    endif\r
+#  endif\r
+#  if defined (__BORLANDC__)\r
+#    if (__BORLANDC__ >= 0x0500) && defined (WIN32)\r
+#      include <windows.h>\r
+#      define ZEXPORT __declspec(dllexport) WINAPI\r
+#      define ZEXPORTVA __declspec(dllexport) WINAPIV\r
+#    else\r
+#      if defined (_Windows) && defined (__DLL__)\r
+#        define ZEXPORT _export\r
+#        define ZEXPORTVA _export\r
+#      endif\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+#if defined (__BEOS__)\r
+#  if defined (ZLIB_DLL)\r
+#    define ZEXTERN extern __declspec(dllexport)\r
+#  else\r
+#    define ZEXTERN extern __declspec(dllimport)\r
+#  endif\r
+#endif\r
+\r
+#ifndef ZEXPORT\r
+#  define ZEXPORT\r
+#endif\r
+#ifndef ZEXPORTVA\r
+#  define ZEXPORTVA\r
+#endif\r
+#ifndef ZEXTERN\r
+#  define ZEXTERN extern\r
+#endif\r
+\r
+#ifndef FAR\r
+#   define FAR\r
+#endif\r
+\r
+#if !defined(__MACTYPES__)\r
+typedef unsigned char  Byte;  /* 8 bits */\r
+#endif\r
+typedef unsigned int   uInt;  /* 16 bits or more */\r
+typedef unsigned long  uLong; /* 32 bits or more */\r
+\r
+#ifdef SMALL_MEDIUM\r
+   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */\r
+#  define Bytef Byte FAR\r
+#else\r
+   typedef Byte  FAR Bytef;\r
+#endif\r
+typedef char  FAR charf;\r
+typedef int   FAR intf;\r
+typedef uInt  FAR uIntf;\r
+typedef uLong FAR uLongf;\r
+\r
+#ifdef STDC\r
+   typedef void const *voidpc;\r
+   typedef void FAR *voidpf;\r
+   typedef void     *voidp;\r
+#else\r
+   typedef Byte const *voidpc;\r
+   typedef Byte FAR *voidpf;\r
+   typedef Byte     *voidp;\r
+#endif\r
+\r
+#if 0   /* HAVE_UNISTD_H -- this line is updated by ./configure */\r
+#  include <sys/types.h> /* for off_t */\r
+#  include <unistd.h>    /* for SEEK_* and off_t */\r
+#  ifdef VMS\r
+#    include <unixio.h>   /* for off_t */\r
+#  endif\r
+#  define z_off_t  off_t\r
+#endif\r
+#ifndef SEEK_SET\r
+#  define SEEK_SET        0       /* Seek from beginning of file.  */\r
+#  define SEEK_CUR        1       /* Seek from current position.  */\r
+#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */\r
+#endif\r
+#ifndef z_off_t\r
+#  define  z_off_t long\r
+#endif\r
+\r
+/* MVS linker does not support external names larger than 8 bytes */\r
+#if defined(__MVS__)\r
+#   pragma map(deflateInit_,"DEIN")\r
+#   pragma map(deflateInit2_,"DEIN2")\r
+#   pragma map(deflateEnd,"DEEND")\r
+#   pragma map(deflateBound,"DEBND")\r
+#   pragma map(inflateInit_,"ININ")\r
+#   pragma map(inflateInit2_,"ININ2")\r
+#   pragma map(inflateEnd,"INEND")\r
+#   pragma map(inflateSync,"INSY")\r
+#   pragma map(inflateSetDictionary,"INSEDI")\r
+#   pragma map(compressBound,"CMBND")\r
+#   pragma map(inflate_table,"INTABL")\r
+#   pragma map(inflate_fast,"INFA")\r
+#   pragma map(inflate_copyright,"INCOPY")\r
+#endif\r
+\r
+#endif /* _ZCONF_H */\r
index 29c17d8b67122d19abacaeaaf2449440ed6d43bf..00587fbe8113071148956a55ed2a91e8d9231508 100644 (file)
-/* zip.c -- IO on .zip files using zlib
-   Version 0.21, March 10th, 2003
-
-   Read zip.h for more info
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "zlib.h"
-#include "zip.h"
-
-#ifdef STDC
-#  include <stddef.h>
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
-    extern int errno;
-#else
-#   include <errno.h>
-#endif
-
-
-#ifndef local
-#  define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-#ifndef VERSIONMADEBY
-# define VERSIONMADEBY   (0x0) /* platform depedent */
-#endif
-
-#ifndef Z_BUFSIZE
-#define Z_BUFSIZE (16384)
-#endif
-
-#ifndef Z_MAXFILENAMEINZIP
-#define Z_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-/*
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-*/
-
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-#ifndef SEEK_CUR
-#define SEEK_CUR    1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END    2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET    0
-#endif
-
-#ifndef DEF_MEM_LEVEL
-#if MAX_MEM_LEVEL >= 8
-#  define DEF_MEM_LEVEL 8
-#else
-#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
-#endif
-#endif
-const char zip_copyright[] =
-   " zip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-
-#define SIZEDATA_INDATABLOCK (4096-(4*4))
-
-#define LOCALHEADERMAGIC    (0x04034b50)
-#define CENTRALHEADERMAGIC  (0x02014b50)
-#define ENDHEADERMAGIC      (0x06054b50)
-
-#define FLAG_LOCALHEADER_OFFSET (0x06)
-#define CRC_LOCALHEADER_OFFSET  (0x0e)
-
-#define SIZECENTRALHEADER (0x2e) /* 46 */
-
-typedef struct linkedlist_datablock_internal_s
-{
-  struct linkedlist_datablock_internal_s* next_datablock;
-  uLong  avail_in_this_block;
-  uLong  filled_in_this_block;
-  uLong  unused; /* for future use and alignement */
-  unsigned char data[SIZEDATA_INDATABLOCK];
-} linkedlist_datablock_internal;
-
-typedef struct linkedlist_data_s
-{
-    linkedlist_datablock_internal* first_block;
-    linkedlist_datablock_internal* last_block;
-} linkedlist_data;
-
-
-typedef struct
-{
-    z_stream stream;            /* zLib stream structure for inflate */
-    int  stream_initialised;    /* 1 is stream is initialised */
-    uInt pos_in_buffered_data;  /* last written byte in buffered_data */
-
-    uLong pos_local_header;     /* offset of the local header of the file
-                                     currenty writing */
-    char* central_header;       /* central header data for the current file */
-    uLong size_centralheader;   /* size of the central header for cur file */
-    uLong flag;                 /* flag of the file currently writing */
-
-    int  method;                /* compression method of file currenty wr.*/
-    int  raw;                   /* 1 for directly writing raw data */
-    Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
-    uLong dosDate;
-    uLong crc32;
-    int  encrypt;
-#ifndef NOCRPYT
-    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
-    const unsigned long* pcrc_32_tab;
-    int crypt_header_size;
-#endif
-} curfile_info;
-
-typedef struct
-{
-    zlib_filefunc_def z_filefunc;
-    voidpf filestream;        /* io structore of the zipfile */
-    linkedlist_data central_dir;/* datablock with central dir in construction*/
-    int  in_opened_file_inzip;  /* 1 if a file in the zip is currently writ.*/
-    curfile_info ci;            /* info on the file curretly writing */
-
-    uLong begin_pos;            /* position of the beginning of the zipfile */
-    uLong add_position_when_writting_offset;
-    uLong number_entry;
-} zip_internal;
-
-
-
-#ifndef NOCRPYT
-#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-#include "crypt.h"
-#endif
-
-local linkedlist_datablock_internal* allocate_new_datablock()
-{
-    linkedlist_datablock_internal* ldi;
-    ldi = (linkedlist_datablock_internal*)
-                 ALLOC(sizeof(linkedlist_datablock_internal));
-    if (ldi!=NULL)
-    {
-        ldi->next_datablock = NULL ;
-        ldi->filled_in_this_block = 0 ;
-        ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
-    }
-    return ldi;
-}
-
-local void free_datablock(ldi)
-    linkedlist_datablock_internal* ldi;
-{
-    while (ldi!=NULL)
-    {
-        linkedlist_datablock_internal* ldinext = ldi->next_datablock;
-        TRYFREE(ldi);
-        ldi = ldinext;
-    }
-}
-
-local void init_linkedlist(ll)
-    linkedlist_data* ll;
-{
-    ll->first_block = ll->last_block = NULL;
-}
-
-local void free_linkedlist(ll)
-    linkedlist_data* ll;
-{
-    free_datablock(ll->first_block);
-    ll->first_block = ll->last_block = NULL;
-}
-
-
-local int add_data_in_datablock(ll,buf,len)
-    linkedlist_data* ll;
-    const void* buf;
-    uLong len;
-{
-    linkedlist_datablock_internal* ldi;
-    const unsigned char* from_copy;
-
-    if (ll==NULL)
-        return ZIP_INTERNALERROR;
-
-    if (ll->last_block == NULL)
-    {
-        ll->first_block = ll->last_block = allocate_new_datablock();
-        if (ll->first_block == NULL)
-            return ZIP_INTERNALERROR;
-    }
-
-    ldi = ll->last_block;
-    from_copy = (unsigned char*)buf;
-
-    while (len>0)
-    {
-        uInt copy_this;
-        uInt i;
-        unsigned char* to_copy;
-
-        if (ldi->avail_in_this_block==0)
-        {
-            ldi->next_datablock = allocate_new_datablock();
-            if (ldi->next_datablock == NULL)
-                return ZIP_INTERNALERROR;
-            ldi = ldi->next_datablock ;
-            ll->last_block = ldi;
-        }
-
-        if (ldi->avail_in_this_block < len)
-            copy_this = (uInt)ldi->avail_in_this_block;
-        else
-            copy_this = (uInt)len;
-
-        to_copy = &(ldi->data[ldi->filled_in_this_block]);
-
-        for (i=0;i<copy_this;i++)
-            *(to_copy+i)=*(from_copy+i);
-
-        ldi->filled_in_this_block += copy_this;
-        ldi->avail_in_this_block -= copy_this;
-        from_copy += copy_this ;
-        len -= copy_this;
-    }
-    return ZIP_OK;
-}
-
-
-
-/****************************************************************************/
-
-#ifndef NO_ADDFILEINEXISTINGZIP
-/* ===========================================================================
-   Inputs a long in LSB order to the given file
-   nbByte == 1, 2 or 4 (byte, short or long)
-*/
-
-local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,
-                                voidpf filestream, uLong x, int nbByte));
-local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    uLong x;
-    int nbByte;
-{
-    unsigned char buf[4];
-    int n;
-    for (n = 0; n < nbByte; n++) {
-        buf[n] = (unsigned char)(x & 0xff);
-        x >>= 8;
-    }
-    if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
-        return ZIP_ERRNO;
-    else
-        return ZIP_OK;
-}
-
-local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
-local void ziplocal_putValue_inmemory (dest, x, nbByte)
-    void* dest;
-    uLong x;
-    int nbByte;
-{
-    unsigned char* buf=(unsigned char*)dest;
-    int n;
-    for (n = 0; n < nbByte; n++) {
-        buf[n] = (unsigned char)(x & 0xff);
-        x >>= 8;
-    }
-}
-/****************************************************************************/
-
-
-local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
-    const tm_zip* ptm;
-    uLong dosDate;
-{
-    uLong year = (uLong)ptm->tm_year;
-    if (year>1980)
-        year-=1980;
-    else if (year>80)
-        year-=80;
-    return
-      (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
-        ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
-}
-
-
-/****************************************************************************/
-
-local int ziplocal_getByte OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    int *pi));
-
-local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    int *pi;
-{
-    unsigned char c;
-    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
-    if (err==1)
-    {
-        *pi = (int)c;
-        return ZIP_OK;
-    }
-    else
-    {
-        if (ZERROR(*pzlib_filefunc_def,filestream))
-            return ZIP_ERRNO;
-        else
-            return ZIP_EOF;
-    }
-}
-
-
-/* ===========================================================================
-   Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int ziplocal_getShort OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    uLong *pX));
-
-local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    uLong *pX;
-{
-    uLong x ;
-    int i;
-    int err;
-
-    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x = (uLong)i;
-
-    if (err==ZIP_OK)
-        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<8;
-
-    if (err==ZIP_OK)
-        *pX = x;
-    else
-        *pX = 0;
-    return err;
-}
-
-local int ziplocal_getLong OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream,
-    uLong *pX));
-
-local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-    uLong *pX;
-{
-    uLong x ;
-    int i;
-    int err;
-
-    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x = (uLong)i;
-
-    if (err==ZIP_OK)
-        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<8;
-
-    if (err==ZIP_OK)
-        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<16;
-
-    if (err==ZIP_OK)
-        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
-    x += ((uLong)i)<<24;
-
-    if (err==ZIP_OK)
-        *pX = x;
-    else
-        *pX = 0;
-    return err;
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-/*
-  Locate the Central directory of a zipfile (at the end, just before
-    the global comment)
-*/
-local uLong ziplocal_SearchCentralDir OF((
-    const zlib_filefunc_def* pzlib_filefunc_def,
-    voidpf filestream));
-
-local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
-    const zlib_filefunc_def* pzlib_filefunc_def;
-    voidpf filestream;
-{
-    unsigned char* buf;
-    uLong uSizeFile;
-    uLong uBackRead;
-    uLong uMaxBack=0xffff; /* maximum size of global comment */
-    uLong uPosFound=0;
-
-    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
-        return 0;
-
-
-    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
-
-    if (uMaxBack>uSizeFile)
-        uMaxBack = uSizeFile;
-
-    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
-    if (buf==NULL)
-        return 0;
-
-    uBackRead = 4;
-    while (uBackRead<uMaxBack)
-    {
-        uLong uReadSize,uReadPos ;
-        int i;
-        if (uBackRead+BUFREADCOMMENT>uMaxBack)
-            uBackRead = uMaxBack;
-        else
-            uBackRead+=BUFREADCOMMENT;
-        uReadPos = uSizeFile-uBackRead ;
-
-        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
-                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
-        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            break;
-
-        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
-            break;
-
-        for (i=(int)uReadSize-3; (i--)>0;)
-            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
-                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
-            {
-                uPosFound = uReadPos+i;
-                break;
-            }
-
-        if (uPosFound!=0)
-            break;
-    }
-    TRYFREE(buf);
-    return uPosFound;
-}
-#endif /* !NO_ADDFILEINEXISTINGZIP*/
-
-/************************************************************/
-extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)
-    const char *pathname;
-    int append;
-    zipcharpc* globalcomment;
-    zlib_filefunc_def* pzlib_filefunc_def;
-{
-    zip_internal ziinit;
-    zip_internal* zi;
-    int err=ZIP_OK;
-
-
-    if (pzlib_filefunc_def==NULL)
-        fill_fopen_filefunc(&ziinit.z_filefunc);
-    else
-        ziinit.z_filefunc = *pzlib_filefunc_def;
-
-    ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))
-                 (ziinit.z_filefunc.opaque,
-                  pathname,
-                  (append == APPEND_STATUS_CREATE) ?
-                  (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
-                    (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
-
-    if (ziinit.filestream == NULL)
-        return NULL;
-    ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
-    ziinit.in_opened_file_inzip = 0;
-    ziinit.ci.stream_initialised = 0;
-    ziinit.number_entry = 0;
-    ziinit.add_position_when_writting_offset = 0;
-    init_linkedlist(&(ziinit.central_dir));
-
-
-    zi = (zip_internal*)ALLOC(sizeof(zip_internal));
-    if (zi==NULL)
-    {
-        ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
-        return NULL;
-    }
-
-    /* now we add file in a zipfile */
-    #ifndef NO_ADDFILEINEXISTINGZIP
-    if (append == APPEND_STATUS_ADDINZIP)
-    {
-        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-
-        uLong size_central_dir;     /* size of the central directory  */
-        uLong offset_central_dir;   /* offset of start of central directory */
-        uLong central_pos,uL;
-
-        uLong number_disk;          /* number of the current dist, used for
-                                    spaning ZIP, unsupported, always 0*/
-        uLong number_disk_with_CD;  /* number the the disk with central dir, used
-                                    for spaning ZIP, unsupported, always 0*/
-        uLong number_entry;
-        uLong number_entry_CD;      /* total number of entries in
-                                    the central dir
-                                    (same than number_entry on nospan) */
-        uLong size_comment;
-
-        central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
-        if (central_pos==0)
-            err=ZIP_ERRNO;
-
-        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
-                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            err=ZIP_ERRNO;
-
-        /* the signature, already checked */
-        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* number of this disk */
-        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* number of the disk with the start of the central directory */
-        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* total number of entries in the central dir on this disk */
-        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* total number of entries in the central dir */
-        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        if ((number_entry_CD!=number_entry) ||
-            (number_disk_with_CD!=0) ||
-            (number_disk!=0))
-            err=ZIP_BADZIPFILE;
-
-        /* size of the central directory */
-        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* offset of start of central directory with respect to the
-            starting disk number */
-        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        /* zipfile comment length */
-        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
-            err=ZIP_ERRNO;
-
-        if ((central_pos<offset_central_dir+size_central_dir) &&
-            (err==ZIP_OK))
-            err=ZIP_BADZIPFILE;
-
-        if (err!=ZIP_OK)
-        {
-            ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
-            return NULL;
-        }
-
-        byte_before_the_zipfile = central_pos -
-                                (offset_central_dir+size_central_dir);
-        ziinit.add_position_when_writting_offset = byte_before_the_zipfile ;
-
-        {
-            uLong size_central_dir_to_read = size_central_dir;
-            size_t buf_size = SIZEDATA_INDATABLOCK;
-            void* buf_read = (void*)ALLOC(buf_size);
-            if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
-                  offset_central_dir + byte_before_the_zipfile,
-                  ZLIB_FILEFUNC_SEEK_SET) != 0)
-                  err=ZIP_ERRNO;
-
-            while ((size_central_dir_to_read>0) && (err==ZIP_OK))
-            {
-                uLong read_this = SIZEDATA_INDATABLOCK;
-                if (read_this > size_central_dir_to_read)
-                    read_this = size_central_dir_to_read;
-                if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
-                    err=ZIP_ERRNO;
-
-                if (err==ZIP_OK)
-                    err = add_data_in_datablock(&ziinit.central_dir,buf_read,
-                                                (uLong)read_this);
-                size_central_dir_to_read-=read_this;
-            }
-            TRYFREE(buf_read);
-        }
-        ziinit.begin_pos = byte_before_the_zipfile;
-        ziinit.number_entry = number_entry_CD;
-
-        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
-                  offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            err=ZIP_ERRNO;
-    }
-    #endif /* !NO_ADDFILEINEXISTINGZIP*/
-
-    if (err != ZIP_OK)
-    {
-        TRYFREE(zi);
-        return NULL;
-    }
-    else
-    {
-        *zi = ziinit;
-        return (zipFile)zi;
-    }
-}
-
-extern zipFile ZEXPORT zipOpen (pathname, append)
-    const char *pathname;
-    int append;
-{
-    return zipOpen2(pathname,append,NULL,NULL);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
-                                         extrafield_local, size_extrafield_local,
-                                         extrafield_global, size_extrafield_global,
-                                         comment, method, level, raw,
-                                         windowBits, memLevel, strategy,
-                                         password, crcForCrypting)
-    zipFile file;
-    const char* filename;
-    const zip_fileinfo* zipfi;
-    const void* extrafield_local;
-    uInt size_extrafield_local;
-    const void* extrafield_global;
-    uInt size_extrafield_global;
-    const char* comment;
-    int method;
-    int level;
-    int raw;
-    int windowBits;
-    int memLevel;
-    int strategy;
-    const char* password;
-    uLong crcForCrypting;
-{
-    zip_internal* zi;
-    uInt size_filename;
-    uInt size_comment;
-    uInt i;
-    int err = ZIP_OK;
-
-    #ifdef NOCRPYT
-    if (password != NULL)
-        return ZIP_PARAMERROR;
-    #endif
-
-    if (file == NULL)
-        return ZIP_PARAMERROR;
-    if ((method!=0) && (method!=Z_DEFLATED))
-        return ZIP_PARAMERROR;
-
-    zi = (zip_internal*)file;
-
-    if (zi->in_opened_file_inzip == 1)
-    {
-        err = zipCloseFileInZip (file);
-        if (err != ZIP_OK)
-            return err;
-    }
-
-
-    if (filename==NULL)
-        filename="-";
-
-    if (comment==NULL)
-        size_comment = 0;
-    else
-        size_comment = strlen(comment);
-
-    size_filename = strlen(filename);
-
-    if (zipfi == NULL)
-        zi->ci.dosDate = 0;
-    else
-    {
-        if (zipfi->dosDate != 0)
-            zi->ci.dosDate = zipfi->dosDate;
-        else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
-    }
-
-    zi->ci.flag = 0;
-    if ((level==8) || (level==9))
-      zi->ci.flag |= 2;
-    if ((level==2))
-      zi->ci.flag |= 4;
-    if ((level==1))
-      zi->ci.flag |= 6;
-    if (password != NULL)
-      zi->ci.flag |= 1;
-
-    zi->ci.crc32 = 0;
-    zi->ci.method = method;
-    zi->ci.encrypt = 0;
-    zi->ci.stream_initialised = 0;
-    zi->ci.pos_in_buffered_data = 0;
-    zi->ci.raw = raw;
-    zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;
-    zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
-                                      size_extrafield_global + size_comment;
-    zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
-
-    ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
-    /* version info */
-    ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
-    ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
-    ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
-    ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
-    ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
-
-    if (zipfi==NULL)
-        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
-    else
-        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
-
-    if (zipfi==NULL)
-        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
-    else
-        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
-
-    ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);
-
-    for (i=0;i<size_filename;i++)
-        *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
-
-    for (i=0;i<size_extrafield_global;i++)
-        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
-              *(((const char*)extrafield_global)+i);
-
-    for (i=0;i<size_comment;i++)
-        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
-              size_extrafield_global+i) = *(comment+i);
-    if (zi->ci.central_header == NULL)
-        return ZIP_INTERNALERROR;
-
-    /* write the local header */
-    err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
-
-    if (err==ZIP_OK)
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
-
-    if ((err==ZIP_OK) && (size_filename>0))
-        if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
-                err = ZIP_ERRNO;
-
-    if ((err==ZIP_OK) && (size_extrafield_local>0))
-        if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
-                                                                           !=size_extrafield_local)
-                err = ZIP_ERRNO;
-
-    zi->ci.stream.avail_in = (uInt)0;
-    zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
-    zi->ci.stream.next_out = zi->ci.buffered_data;
-    zi->ci.stream.total_in = 0;
-    zi->ci.stream.total_out = 0;
-
-    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-    {
-        zi->ci.stream.zalloc = (alloc_func)0;
-        zi->ci.stream.zfree = (free_func)0;
-        zi->ci.stream.opaque = (voidpf)0;
-
-        if (windowBits>0)
-            windowBits = -windowBits;
-
-        err = deflateInit2(&zi->ci.stream, level,
-               Z_DEFLATED, windowBits, memLevel, strategy);
-
-        if (err==Z_OK)
-            zi->ci.stream_initialised = 1;
-
-        #ifndef NOCRPYT
-        zi->ci.crypt_header_size = 0;
-        if ((err==Z_OK) && (password != NULL))
-        {
-            unsigned char bufHead[RAND_HEAD_LEN];
-            unsigned int sizeHead;
-            zi->ci.encrypt = 1;
-            zi->ci.pcrc_32_tab = get_crc_table();
-            /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
-
-            sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
-            zi->ci.crypt_header_size = sizeHead;
-
-            if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
-                    err = ZIP_ERRNO;
-        }
-        #endif
-    }
-
-
-    if (err==Z_OK)
-        zi->in_opened_file_inzip = 1;
-    return err;
-}
-
-extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
-                                        extrafield_local, size_extrafield_local,
-                                        extrafield_global, size_extrafield_global,
-                                        comment, method, level, raw)
-    zipFile file;
-    const char* filename;
-    const zip_fileinfo* zipfi;
-    const void* extrafield_local;
-    uInt size_extrafield_local;
-    const void* extrafield_global;
-    uInt size_extrafield_global;
-    const char* comment;
-    int method;
-    int level;
-    int raw;
-{
-    return zipOpenNewFileInZip3 (file, filename, zipfi,
-                                 extrafield_local, size_extrafield_local,
-                                 extrafield_global, size_extrafield_global,
-                                 comment, method, level, raw,
-                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
-                                 NULL, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
-                                        extrafield_local, size_extrafield_local,
-                                        extrafield_global, size_extrafield_global,
-                                        comment, method, level)
-    zipFile file;
-    const char* filename;
-    const zip_fileinfo* zipfi;
-    const void* extrafield_local;
-    uInt size_extrafield_local;
-    const void* extrafield_global;
-    uInt size_extrafield_global;
-    const char* comment;
-    int method;
-    int level;
-{
-    return zipOpenNewFileInZip2 (file, filename, zipfi,
-                                 extrafield_local, size_extrafield_local,
-                                 extrafield_global, size_extrafield_global,
-                                 comment, method, level, 0);
-}
-
-local int zipFlushWriteBuffer(zi)
-  zip_internal* zi;
-{
-    int err=ZIP_OK;
-
-    if (zi->ci.encrypt != 0)
-    {
-        uInt i;
-        int t;
-        for (i=0;i<zi->ci.pos_in_buffered_data;i++)
-            zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
-                                       zi->ci.buffered_data[i],t);
-    }
-    if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
-                                                                    !=zi->ci.pos_in_buffered_data)
-      err = ZIP_ERRNO;
-    zi->ci.pos_in_buffered_data = 0;
-    return err;
-}
-
-extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
-    zipFile file;
-    const void* buf;
-    unsigned len;
-{
-    zip_internal* zi;
-    int err=ZIP_OK;
-
-    if (file == NULL)
-        return ZIP_PARAMERROR;
-    zi = (zip_internal*)file;
-
-    if (zi->in_opened_file_inzip == 0)
-        return ZIP_PARAMERROR;
-
-    zi->ci.stream.next_in = (void*)buf;
-    zi->ci.stream.avail_in = len;
-    zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
-
-    while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
-    {
-        if (zi->ci.stream.avail_out == 0)
-        {
-            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
-                err = ZIP_ERRNO;
-            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
-            zi->ci.stream.next_out = zi->ci.buffered_data;
-        }
-
-
-        if(err != ZIP_OK)
-            break;
-
-        if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-        {
-            uLong uTotalOutBefore = zi->ci.stream.total_out;
-            err=deflate(&zi->ci.stream,  Z_NO_FLUSH);
-            zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
-
-        }
-        else
-        {
-            uInt copy_this,i;
-            if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
-                copy_this = zi->ci.stream.avail_in;
-            else
-                copy_this = zi->ci.stream.avail_out;
-            for (i=0;i<copy_this;i++)
-                *(((char*)zi->ci.stream.next_out)+i) =
-                    *(((const char*)zi->ci.stream.next_in)+i);
-            {
-                zi->ci.stream.avail_in -= copy_this;
-                zi->ci.stream.avail_out-= copy_this;
-                zi->ci.stream.next_in+= copy_this;
-                zi->ci.stream.next_out+= copy_this;
-                zi->ci.stream.total_in+= copy_this;
-                zi->ci.stream.total_out+= copy_this;
-                zi->ci.pos_in_buffered_data += copy_this;
-            }
-        }
-    }
-
-    return err;
-}
-
-extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
-    zipFile file;
-    uLong uncompressed_size;
-    uLong crc32;
-{
-    zip_internal* zi;
-    uLong compressed_size;
-    int err=ZIP_OK;
-
-    if (file == NULL)
-        return ZIP_PARAMERROR;
-    zi = (zip_internal*)file;
-
-    if (zi->in_opened_file_inzip == 0)
-        return ZIP_PARAMERROR;
-    zi->ci.stream.avail_in = 0;
-
-    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-        while (err==ZIP_OK)
-    {
-        uLong uTotalOutBefore;
-        if (zi->ci.stream.avail_out == 0)
-        {
-            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
-                err = ZIP_ERRNO;
-            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
-            zi->ci.stream.next_out = zi->ci.buffered_data;
-        }
-        uTotalOutBefore = zi->ci.stream.total_out;
-        err=deflate(&zi->ci.stream,  Z_FINISH);
-        zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
-    }
-
-    if (err==Z_STREAM_END)
-        err=ZIP_OK; /* this is normal */
-
-    if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
-        if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
-            err = ZIP_ERRNO;
-
-    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-    {
-        err=deflateEnd(&zi->ci.stream);
-        zi->ci.stream_initialised = 0;
-    }
-
-    if (!zi->ci.raw)
-    {
-        crc32 = (uLong)zi->ci.crc32;
-        uncompressed_size = (uLong)zi->ci.stream.total_in;
-    }
-    compressed_size = (uLong)zi->ci.stream.total_out;
-    #ifndef NOCRPYT
-    compressed_size += zi->ci.crypt_header_size;
-    #endif
-
-    ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
-    ziplocal_putValue_inmemory(zi->ci.central_header+20,
-                                compressed_size,4); /*compr size*/
-    if (zi->ci.stream.data_type == Z_ASCII)
-        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
-    ziplocal_putValue_inmemory(zi->ci.central_header+24,
-                                uncompressed_size,4); /*uncompr size*/
-
-    if (err==ZIP_OK)
-        err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
-                                       (uLong)zi->ci.size_centralheader);
-    free(zi->ci.central_header);
-
-    if (err==ZIP_OK)
-    {
-        long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
-        if (ZSEEK(zi->z_filefunc,zi->filestream,
-                  zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            err = ZIP_ERRNO;
-
-        if (err==ZIP_OK)
-            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
-
-        if (err==ZIP_OK) /* compressed size, unknown */
-            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
-
-        if (err==ZIP_OK) /* uncompressed size, unknown */
-            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
-
-        if (ZSEEK(zi->z_filefunc,zi->filestream,
-                  cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
-            err = ZIP_ERRNO;
-    }
-
-    zi->number_entry ++;
-    zi->in_opened_file_inzip = 0;
-
-    return err;
-}
-
-extern int ZEXPORT zipCloseFileInZip (file)
-    zipFile file;
-{
-    return zipCloseFileInZipRaw (file,0,0);
-}
-
-extern int ZEXPORT zipClose (file, global_comment)
-    zipFile file;
-    const char* global_comment;
-{
-    zip_internal* zi;
-    int err = 0;
-    uLong size_centraldir = 0;
-    uLong centraldir_pos_inzip ;
-    uInt size_global_comment;
-    if (file == NULL)
-        return ZIP_PARAMERROR;
-    zi = (zip_internal*)file;
-
-    if (zi->in_opened_file_inzip == 1)
-    {
-        err = zipCloseFileInZip (file);
-    }
-
-    if (global_comment==NULL)
-        size_global_comment = 0;
-    else
-        size_global_comment = strlen(global_comment);
-
-
-    centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
-    if (err==ZIP_OK)
-    {
-        linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
-        while (ldi!=NULL)
-        {
-            if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
-                if (ZWRITE(zi->z_filefunc,zi->filestream,
-                           ldi->data,ldi->filled_in_this_block)
-                              !=ldi->filled_in_this_block )
-                    err = ZIP_ERRNO;
-
-            size_centraldir += ldi->filled_in_this_block;
-            ldi = ldi->next_datablock;
-        }
-    }
-    free_datablock(zi->central_dir.first_block);
-
-    if (err==ZIP_OK) /* Magic End */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
-
-    if (err==ZIP_OK) /* number of this disk */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
-    if (err==ZIP_OK) /* number of the disk with the start of the central directory */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
-    if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
-
-    if (err==ZIP_OK) /* total number of entries in the central dir */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
-
-    if (err==ZIP_OK) /* size of the central directory */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
-
-    if (err==ZIP_OK) /* offset of start of central directory with respect to the
-                            starting disk number */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
-                                (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
-
-    if (err==ZIP_OK) /* zipfile comment length */
-        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
-
-    if ((err==ZIP_OK) && (size_global_comment>0))
-        if (ZWRITE(zi->z_filefunc,zi->filestream,
-                   global_comment,size_global_comment) != size_global_comment)
-                err = ZIP_ERRNO;
-
-    if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
-        if (err == ZIP_OK)
-            err = ZIP_ERRNO;
-
-    TRYFREE(zi);
-
-    return err;
-}
+/* zip.c -- IO on .zip files using zlib\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Read zip.h for more info\r
+*/\r
+\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <time.h>\r
+#include "zlib.h"\r
+#include "zip.h"\r
+\r
+#ifdef STDC\r
+#  include <stddef.h>\r
+#  include <string.h>\r
+#  include <stdlib.h>\r
+#endif\r
+#ifdef NO_ERRNO_H\r
+    extern int errno;\r
+#else\r
+#   include <errno.h>\r
+#endif\r
+\r
+\r
+#ifndef local\r
+#  define local static\r
+#endif\r
+/* compile with -Dlocal if your debugger can't find static symbols */\r
+\r
+#ifndef VERSIONMADEBY\r
+# define VERSIONMADEBY   (0x0) /* platform depedent */\r
+#endif\r
+\r
+#ifndef Z_BUFSIZE\r
+#define Z_BUFSIZE (16384)\r
+#endif\r
+\r
+#ifndef Z_MAXFILENAMEINZIP\r
+#define Z_MAXFILENAMEINZIP (256)\r
+#endif\r
+\r
+#ifndef ALLOC\r
+# define ALLOC(size) (malloc(size))\r
+#endif\r
+#ifndef TRYFREE\r
+# define TRYFREE(p) {if (p) free(p);}\r
+#endif\r
+\r
+/*\r
+#define SIZECENTRALDIRITEM (0x2e)\r
+#define SIZEZIPLOCALHEADER (0x1e)\r
+*/\r
+\r
+/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */\r
+\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR    1\r
+#endif\r
+\r
+#ifndef SEEK_END\r
+#define SEEK_END    2\r
+#endif\r
+\r
+#ifndef SEEK_SET\r
+#define SEEK_SET    0\r
+#endif\r
+\r
+#ifndef DEF_MEM_LEVEL\r
+#if MAX_MEM_LEVEL >= 8\r
+#  define DEF_MEM_LEVEL 8\r
+#else\r
+#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL\r
+#endif\r
+#endif\r
+const char zip_copyright[] =\r
+   " zip 0.22 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";\r
+\r
+\r
+#define SIZEDATA_INDATABLOCK (4096-(4*4))\r
+\r
+#define LOCALHEADERMAGIC    (0x04034b50)\r
+#define CENTRALHEADERMAGIC  (0x02014b50)\r
+#define ENDHEADERMAGIC      (0x06054b50)\r
+\r
+#define FLAG_LOCALHEADER_OFFSET (0x06)\r
+#define CRC_LOCALHEADER_OFFSET  (0x0e)\r
+\r
+#define SIZECENTRALHEADER (0x2e) /* 46 */\r
+\r
+typedef struct linkedlist_datablock_internal_s\r
+{\r
+  struct linkedlist_datablock_internal_s* next_datablock;\r
+  uLong  avail_in_this_block;\r
+  uLong  filled_in_this_block;\r
+  uLong  unused; /* for future use and alignement */\r
+  unsigned char data[SIZEDATA_INDATABLOCK];\r
+} linkedlist_datablock_internal;\r
+\r
+typedef struct linkedlist_data_s\r
+{\r
+    linkedlist_datablock_internal* first_block;\r
+    linkedlist_datablock_internal* last_block;\r
+} linkedlist_data;\r
+\r
+\r
+typedef struct\r
+{\r
+    z_stream stream;            /* zLib stream structure for inflate */\r
+    int  stream_initialised;    /* 1 is stream is initialised */\r
+    uInt pos_in_buffered_data;  /* last written byte in buffered_data */\r
+\r
+    uLong pos_local_header;     /* offset of the local header of the file\r
+                                     currenty writing */\r
+    char* central_header;       /* central header data for the current file */\r
+    uLong size_centralheader;   /* size of the central header for cur file */\r
+    uLong flag;                 /* flag of the file currently writing */\r
+\r
+    int  method;                /* compression method of file currenty wr.*/\r
+    int  raw;                   /* 1 for directly writing raw data */\r
+    Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/\r
+    uLong dosDate;\r
+    uLong crc32;\r
+    int  encrypt;\r
+#ifndef NOCRYPT\r
+    unsigned long keys[3];     /* keys defining the pseudo-random sequence */\r
+    const unsigned long* pcrc_32_tab;\r
+    int crypt_header_size;\r
+#endif\r
+} curfile_info;\r
+\r
+typedef struct\r
+{\r
+    zlib_filefunc_def z_filefunc;\r
+    voidpf filestream;        /* io structore of the zipfile */\r
+    linkedlist_data central_dir;/* datablock with central dir in construction*/\r
+    int  in_opened_file_inzip;  /* 1 if a file in the zip is currently writ.*/\r
+    curfile_info ci;            /* info on the file curretly writing */\r
+\r
+    uLong begin_pos;            /* position of the beginning of the zipfile */\r
+    uLong add_position_when_writting_offset;\r
+    uLong number_entry;\r
+} zip_internal;\r
+\r
+\r
+\r
+#ifndef NOCRYPT\r
+#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED\r
+#include "crypt.h"\r
+#endif\r
+\r
+local linkedlist_datablock_internal* allocate_new_datablock()\r
+{\r
+    linkedlist_datablock_internal* ldi;\r
+    ldi = (linkedlist_datablock_internal*)\r
+                 ALLOC(sizeof(linkedlist_datablock_internal));\r
+    if (ldi!=NULL)\r
+    {\r
+        ldi->next_datablock = NULL ;\r
+        ldi->filled_in_this_block = 0 ;\r
+        ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;\r
+    }\r
+    return ldi;\r
+}\r
+\r
+local void free_datablock(ldi)\r
+    linkedlist_datablock_internal* ldi;\r
+{\r
+    while (ldi!=NULL)\r
+    {\r
+        linkedlist_datablock_internal* ldinext = ldi->next_datablock;\r
+        TRYFREE(ldi);\r
+        ldi = ldinext;\r
+    }\r
+}\r
+\r
+local void init_linkedlist(ll)\r
+    linkedlist_data* ll;\r
+{\r
+    ll->first_block = ll->last_block = NULL;\r
+}\r
+\r
+local void free_linkedlist(ll)\r
+    linkedlist_data* ll;\r
+{\r
+    free_datablock(ll->first_block);\r
+    ll->first_block = ll->last_block = NULL;\r
+}\r
+\r
+\r
+local int add_data_in_datablock(ll,buf,len)\r
+    linkedlist_data* ll;\r
+    const void* buf;\r
+    uLong len;\r
+{\r
+    linkedlist_datablock_internal* ldi;\r
+    const unsigned char* from_copy;\r
+\r
+    if (ll==NULL)\r
+        return ZIP_INTERNALERROR;\r
+\r
+    if (ll->last_block == NULL)\r
+    {\r
+        ll->first_block = ll->last_block = allocate_new_datablock();\r
+        if (ll->first_block == NULL)\r
+            return ZIP_INTERNALERROR;\r
+    }\r
+\r
+    ldi = ll->last_block;\r
+    from_copy = (unsigned char*)buf;\r
+\r
+    while (len>0)\r
+    {\r
+        uInt copy_this;\r
+        uInt i;\r
+        unsigned char* to_copy;\r
+\r
+        if (ldi->avail_in_this_block==0)\r
+        {\r
+            ldi->next_datablock = allocate_new_datablock();\r
+            if (ldi->next_datablock == NULL)\r
+                return ZIP_INTERNALERROR;\r
+            ldi = ldi->next_datablock ;\r
+            ll->last_block = ldi;\r
+        }\r
+\r
+        if (ldi->avail_in_this_block < len)\r
+            copy_this = (uInt)ldi->avail_in_this_block;\r
+        else\r
+            copy_this = (uInt)len;\r
+\r
+        to_copy = &(ldi->data[ldi->filled_in_this_block]);\r
+\r
+        for (i=0;i<copy_this;i++)\r
+            *(to_copy+i)=*(from_copy+i);\r
+\r
+        ldi->filled_in_this_block += copy_this;\r
+        ldi->avail_in_this_block -= copy_this;\r
+        from_copy += copy_this ;\r
+        len -= copy_this;\r
+    }\r
+    return ZIP_OK;\r
+}\r
+\r
+\r
+\r
+/****************************************************************************/\r
+\r
+#ifndef NO_ADDFILEINEXISTINGZIP\r
+/* ===========================================================================\r
+   Inputs a long in LSB order to the given file\r
+   nbByte == 1, 2 or 4 (byte, short or long)\r
+*/\r
+\r
+local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,\r
+                                voidpf filestream, uLong x, int nbByte));\r
+local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    uLong x;\r
+    int nbByte;\r
+{\r
+    unsigned char buf[4];\r
+    int n;\r
+    for (n = 0; n < nbByte; n++) {\r
+        buf[n] = (unsigned char)(x & 0xff);\r
+        x >>= 8;\r
+    }\r
+    if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)\r
+        return ZIP_ERRNO;\r
+    else\r
+        return ZIP_OK;\r
+}\r
+\r
+local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));\r
+local void ziplocal_putValue_inmemory (dest, x, nbByte)\r
+    void* dest;\r
+    uLong x;\r
+    int nbByte;\r
+{\r
+    unsigned char* buf=(unsigned char*)dest;\r
+    int n;\r
+    for (n = 0; n < nbByte; n++) {\r
+        buf[n] = (unsigned char)(x & 0xff);\r
+        x >>= 8;\r
+    }\r
+}\r
+/****************************************************************************/\r
+\r
+\r
+local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)\r
+    const tm_zip* ptm;\r
+    uLong dosDate;\r
+{\r
+    uLong year = (uLong)ptm->tm_year;\r
+    if (year>1980)\r
+        year-=1980;\r
+    else if (year>80)\r
+        year-=80;\r
+    return\r
+      (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |\r
+        ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));\r
+}\r
+\r
+\r
+/****************************************************************************/\r
+\r
+local int ziplocal_getByte OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    int *pi));\r
+\r
+local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    int *pi;\r
+{\r
+    unsigned char c;\r
+    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);\r
+    if (err==1)\r
+    {\r
+        *pi = (int)c;\r
+        return ZIP_OK;\r
+    }\r
+    else\r
+    {\r
+        if (ZERROR(*pzlib_filefunc_def,filestream))\r
+            return ZIP_ERRNO;\r
+        else\r
+            return ZIP_EOF;\r
+    }\r
+}\r
+\r
+\r
+/* ===========================================================================\r
+   Reads a long in LSB order from the given gz_stream. Sets\r
+*/\r
+local int ziplocal_getShort OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    uLong *pX));\r
+\r
+local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    uLong *pX;\r
+{\r
+    uLong x ;\r
+    int i;\r
+    int err;\r
+\r
+    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x = (uLong)i;\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<8;\r
+\r
+    if (err==ZIP_OK)\r
+        *pX = x;\r
+    else\r
+        *pX = 0;\r
+    return err;\r
+}\r
+\r
+local int ziplocal_getLong OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream,\r
+    uLong *pX));\r
+\r
+local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+    uLong *pX;\r
+{\r
+    uLong x ;\r
+    int i;\r
+    int err;\r
+\r
+    err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x = (uLong)i;\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<8;\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<16;\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);\r
+    x += ((uLong)i)<<24;\r
+\r
+    if (err==ZIP_OK)\r
+        *pX = x;\r
+    else\r
+        *pX = 0;\r
+    return err;\r
+}\r
+\r
+#ifndef BUFREADCOMMENT\r
+#define BUFREADCOMMENT (0x400)\r
+#endif\r
+/*\r
+  Locate the Central directory of a zipfile (at the end, just before\r
+    the global comment)\r
+*/\r
+local uLong ziplocal_SearchCentralDir OF((\r
+    const zlib_filefunc_def* pzlib_filefunc_def,\r
+    voidpf filestream));\r
+\r
+local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)\r
+    const zlib_filefunc_def* pzlib_filefunc_def;\r
+    voidpf filestream;\r
+{\r
+    unsigned char* buf;\r
+    uLong uSizeFile;\r
+    uLong uBackRead;\r
+    uLong uMaxBack=0xffff; /* maximum size of global comment */\r
+    uLong uPosFound=0;\r
+\r
+    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)\r
+        return 0;\r
+\r
+\r
+    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);\r
+\r
+    if (uMaxBack>uSizeFile)\r
+        uMaxBack = uSizeFile;\r
+\r
+    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);\r
+    if (buf==NULL)\r
+        return 0;\r
+\r
+    uBackRead = 4;\r
+    while (uBackRead<uMaxBack)\r
+    {\r
+        uLong uReadSize,uReadPos ;\r
+        int i;\r
+        if (uBackRead+BUFREADCOMMENT>uMaxBack)\r
+            uBackRead = uMaxBack;\r
+        else\r
+            uBackRead+=BUFREADCOMMENT;\r
+        uReadPos = uSizeFile-uBackRead ;\r
+\r
+        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?\r
+                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);\r
+        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            break;\r
+\r
+        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)\r
+            break;\r
+\r
+        for (i=(int)uReadSize-3; (i--)>0;)\r
+            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&\r
+                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))\r
+            {\r
+                uPosFound = uReadPos+i;\r
+                break;\r
+            }\r
+\r
+        if (uPosFound!=0)\r
+            break;\r
+    }\r
+    TRYFREE(buf);\r
+    return uPosFound;\r
+}\r
+#endif /* !NO_ADDFILEINEXISTINGZIP*/\r
+\r
+/************************************************************/\r
+extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)\r
+    const char *pathname;\r
+    int append;\r
+    zipcharpc* globalcomment;\r
+    zlib_filefunc_def* pzlib_filefunc_def;\r
+{\r
+    zip_internal ziinit;\r
+    zip_internal* zi;\r
+    int err=ZIP_OK;\r
+\r
+\r
+    if (pzlib_filefunc_def==NULL)\r
+        fill_fopen_filefunc(&ziinit.z_filefunc);\r
+    else\r
+        ziinit.z_filefunc = *pzlib_filefunc_def;\r
+\r
+    ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))\r
+                 (ziinit.z_filefunc.opaque,\r
+                  pathname,\r
+                  (append == APPEND_STATUS_CREATE) ?\r
+                  (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :\r
+                    (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));\r
+\r
+    if (ziinit.filestream == NULL)\r
+        return NULL;\r
+    ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);\r
+    ziinit.in_opened_file_inzip = 0;\r
+    ziinit.ci.stream_initialised = 0;\r
+    ziinit.number_entry = 0;\r
+    ziinit.add_position_when_writting_offset = 0;\r
+    init_linkedlist(&(ziinit.central_dir));\r
+\r
+\r
+    zi = (zip_internal*)ALLOC(sizeof(zip_internal));\r
+    if (zi==NULL)\r
+    {\r
+        ZCLOSE(ziinit.z_filefunc,ziinit.filestream);\r
+        return NULL;\r
+    }\r
+\r
+    /* now we add file in a zipfile */\r
+    #ifndef NO_ADDFILEINEXISTINGZIP\r
+    if (append == APPEND_STATUS_ADDINZIP)\r
+    {\r
+        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/\r
+\r
+        uLong size_central_dir;     /* size of the central directory  */\r
+        uLong offset_central_dir;   /* offset of start of central directory */\r
+        uLong central_pos,uL;\r
+\r
+        uLong number_disk;          /* number of the current dist, used for\r
+                                    spaning ZIP, unsupported, always 0*/\r
+        uLong number_disk_with_CD;  /* number the the disk with central dir, used\r
+                                    for spaning ZIP, unsupported, always 0*/\r
+        uLong number_entry;\r
+        uLong number_entry_CD;      /* total number of entries in\r
+                                    the central dir\r
+                                    (same than number_entry on nospan) */\r
+        uLong size_comment;\r
+\r
+        central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);\r
+        if (central_pos==0)\r
+            err=ZIP_ERRNO;\r
+\r
+        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,\r
+                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* the signature, already checked */\r
+        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* number of this disk */\r
+        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* number of the disk with the start of the central directory */\r
+        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* total number of entries in the central dir on this disk */\r
+        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* total number of entries in the central dir */\r
+        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        if ((number_entry_CD!=number_entry) ||\r
+            (number_disk_with_CD!=0) ||\r
+            (number_disk!=0))\r
+            err=ZIP_BADZIPFILE;\r
+\r
+        /* size of the central directory */\r
+        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* offset of start of central directory with respect to the\r
+            starting disk number */\r
+        if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        /* zipfile comment length */\r
+        if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)\r
+            err=ZIP_ERRNO;\r
+\r
+        if ((central_pos<offset_central_dir+size_central_dir) &&\r
+            (err==ZIP_OK))\r
+            err=ZIP_BADZIPFILE;\r
+\r
+        if (err!=ZIP_OK)\r
+        {\r
+            ZCLOSE(ziinit.z_filefunc, ziinit.filestream);\r
+            return NULL;\r
+        }\r
+\r
+        byte_before_the_zipfile = central_pos -\r
+                                (offset_central_dir+size_central_dir);\r
+        ziinit.add_position_when_writting_offset = byte_before_the_zipfile ;\r
+\r
+        {\r
+            uLong size_central_dir_to_read = size_central_dir;\r
+            size_t buf_size = SIZEDATA_INDATABLOCK;\r
+            void* buf_read = (void*)ALLOC(buf_size);\r
+            if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,\r
+                  offset_central_dir + byte_before_the_zipfile,\r
+                  ZLIB_FILEFUNC_SEEK_SET) != 0)\r
+                  err=ZIP_ERRNO;\r
+\r
+            while ((size_central_dir_to_read>0) && (err==ZIP_OK))\r
+            {\r
+                uLong read_this = SIZEDATA_INDATABLOCK;\r
+                if (read_this > size_central_dir_to_read)\r
+                    read_this = size_central_dir_to_read;\r
+                if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)\r
+                    err=ZIP_ERRNO;\r
+\r
+                if (err==ZIP_OK)\r
+                    err = add_data_in_datablock(&ziinit.central_dir,buf_read,\r
+                                                (uLong)read_this);\r
+                size_central_dir_to_read-=read_this;\r
+            }\r
+            TRYFREE(buf_read);\r
+        }\r
+        ziinit.begin_pos = byte_before_the_zipfile;\r
+        ziinit.number_entry = number_entry_CD;\r
+\r
+        if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,\r
+                  offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            err=ZIP_ERRNO;\r
+    }\r
+    #endif /* !NO_ADDFILEINEXISTINGZIP*/\r
+\r
+    if (err != ZIP_OK)\r
+    {\r
+        TRYFREE(zi);\r
+        return NULL;\r
+    }\r
+    else\r
+    {\r
+        *zi = ziinit;\r
+        return (zipFile)zi;\r
+    }\r
+}\r
+\r
+extern zipFile ZEXPORT zipOpen (pathname, append)\r
+    const char *pathname;\r
+    int append;\r
+{\r
+    return zipOpen2(pathname,append,NULL,NULL);\r
+}\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,\r
+                                         extrafield_local, size_extrafield_local,\r
+                                         extrafield_global, size_extrafield_global,\r
+                                         comment, method, level, raw,\r
+                                         windowBits, memLevel, strategy,\r
+                                         password, crcForCrypting)\r
+    zipFile file;\r
+    const char* filename;\r
+    const zip_fileinfo* zipfi;\r
+    const void* extrafield_local;\r
+    uInt size_extrafield_local;\r
+    const void* extrafield_global;\r
+    uInt size_extrafield_global;\r
+    const char* comment;\r
+    int method;\r
+    int level;\r
+    int raw;\r
+    int windowBits;\r
+    int memLevel;\r
+    int strategy;\r
+    const char* password;\r
+    uLong crcForCrypting;\r
+{\r
+    zip_internal* zi;\r
+    uInt size_filename;\r
+    uInt size_comment;\r
+    uInt i;\r
+    int err = ZIP_OK;\r
+\r
+    #ifdef NOCRYPT\r
+    if (password != NULL)\r
+        return ZIP_PARAMERROR;\r
+    #endif\r
+\r
+    if (file == NULL)\r
+        return ZIP_PARAMERROR;\r
+    if ((method!=0) && (method!=Z_DEFLATED))\r
+        return ZIP_PARAMERROR;\r
+\r
+    zi = (zip_internal*)file;\r
+\r
+    if (zi->in_opened_file_inzip == 1)\r
+    {\r
+        err = zipCloseFileInZip (file);\r
+        if (err != ZIP_OK)\r
+            return err;\r
+    }\r
+\r
+\r
+    if (filename==NULL)\r
+        filename="-";\r
+\r
+    if (comment==NULL)\r
+        size_comment = 0;\r
+    else\r
+        size_comment = strlen(comment);\r
+\r
+    size_filename = strlen(filename);\r
+\r
+    if (zipfi == NULL)\r
+        zi->ci.dosDate = 0;\r
+    else\r
+    {\r
+        if (zipfi->dosDate != 0)\r
+            zi->ci.dosDate = zipfi->dosDate;\r
+        else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);\r
+    }\r
+\r
+    zi->ci.flag = 0;\r
+    if ((level==8) || (level==9))\r
+      zi->ci.flag |= 2;\r
+    if ((level==2))\r
+      zi->ci.flag |= 4;\r
+    if ((level==1))\r
+      zi->ci.flag |= 6;\r
+    if (password != NULL)\r
+      zi->ci.flag |= 1;\r
+\r
+    zi->ci.crc32 = 0;\r
+    zi->ci.method = method;\r
+    zi->ci.encrypt = 0;\r
+    zi->ci.stream_initialised = 0;\r
+    zi->ci.pos_in_buffered_data = 0;\r
+    zi->ci.raw = raw;\r
+    zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;\r
+    zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +\r
+                                      size_extrafield_global + size_comment;\r
+    zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);\r
+\r
+    ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);\r
+    /* version info */\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/\r
+\r
+    if (zipfi==NULL)\r
+        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);\r
+    else\r
+        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);\r
+\r
+    if (zipfi==NULL)\r
+        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);\r
+    else\r
+        ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);\r
+\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);\r
+\r
+    for (i=0;i<size_filename;i++)\r
+        *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);\r
+\r
+    for (i=0;i<size_extrafield_global;i++)\r
+        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =\r
+              *(((const char*)extrafield_global)+i);\r
+\r
+    for (i=0;i<size_comment;i++)\r
+        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+\r
+              size_extrafield_global+i) = *(comment+i);\r
+    if (zi->ci.central_header == NULL)\r
+        return ZIP_INTERNALERROR;\r
+\r
+    /* write the local header */\r
+    err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);\r
+\r
+    if (err==ZIP_OK)\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);\r
+\r
+    if ((err==ZIP_OK) && (size_filename>0))\r
+        if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)\r
+                err = ZIP_ERRNO;\r
+\r
+    if ((err==ZIP_OK) && (size_extrafield_local>0))\r
+        if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)\r
+                                                                           !=size_extrafield_local)\r
+                err = ZIP_ERRNO;\r
+\r
+    zi->ci.stream.avail_in = (uInt)0;\r
+    zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;\r
+    zi->ci.stream.next_out = zi->ci.buffered_data;\r
+    zi->ci.stream.total_in = 0;\r
+    zi->ci.stream.total_out = 0;\r
+\r
+    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))\r
+    {\r
+        zi->ci.stream.zalloc = (alloc_func)0;\r
+        zi->ci.stream.zfree = (free_func)0;\r
+        zi->ci.stream.opaque = (voidpf)0;\r
+\r
+        if (windowBits>0)\r
+            windowBits = -windowBits;\r
+\r
+        err = deflateInit2(&zi->ci.stream, level,\r
+               Z_DEFLATED, windowBits, memLevel, strategy);\r
+\r
+        if (err==Z_OK)\r
+            zi->ci.stream_initialised = 1;\r
+    }\r
+    #ifndef NOCRYPT\r
+    zi->ci.crypt_header_size = 0;\r
+    if ((err==Z_OK) && (password != NULL))\r
+    {\r
+        unsigned char bufHead[RAND_HEAD_LEN];\r
+        unsigned int sizeHead;\r
+        zi->ci.encrypt = 1;\r
+        zi->ci.pcrc_32_tab = get_crc_table();\r
+        /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/\r
+\r
+        sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);\r
+        zi->ci.crypt_header_size = sizeHead;\r
+\r
+        if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)\r
+                err = ZIP_ERRNO;\r
+    }\r
+    #endif\r
+\r
+    if (err==Z_OK)\r
+        zi->in_opened_file_inzip = 1;\r
+    return err;\r
+}\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,\r
+                                        extrafield_local, size_extrafield_local,\r
+                                        extrafield_global, size_extrafield_global,\r
+                                        comment, method, level, raw)\r
+    zipFile file;\r
+    const char* filename;\r
+    const zip_fileinfo* zipfi;\r
+    const void* extrafield_local;\r
+    uInt size_extrafield_local;\r
+    const void* extrafield_global;\r
+    uInt size_extrafield_global;\r
+    const char* comment;\r
+    int method;\r
+    int level;\r
+    int raw;\r
+{\r
+    return zipOpenNewFileInZip3 (file, filename, zipfi,\r
+                                 extrafield_local, size_extrafield_local,\r
+                                 extrafield_global, size_extrafield_global,\r
+                                 comment, method, level, raw,\r
+                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,\r
+                                 NULL, 0);\r
+}\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,\r
+                                        extrafield_local, size_extrafield_local,\r
+                                        extrafield_global, size_extrafield_global,\r
+                                        comment, method, level)\r
+    zipFile file;\r
+    const char* filename;\r
+    const zip_fileinfo* zipfi;\r
+    const void* extrafield_local;\r
+    uInt size_extrafield_local;\r
+    const void* extrafield_global;\r
+    uInt size_extrafield_global;\r
+    const char* comment;\r
+    int method;\r
+    int level;\r
+{\r
+    return zipOpenNewFileInZip2 (file, filename, zipfi,\r
+                                 extrafield_local, size_extrafield_local,\r
+                                 extrafield_global, size_extrafield_global,\r
+                                 comment, method, level, 0);\r
+}\r
+\r
+local int zipFlushWriteBuffer(zi)\r
+  zip_internal* zi;\r
+{\r
+    int err=ZIP_OK;\r
+\r
+    if (zi->ci.encrypt != 0)\r
+    {\r
+#ifndef NOCRYPT\r
+        uInt i;\r
+        int t;\r
+        for (i=0;i<zi->ci.pos_in_buffered_data;i++)\r
+            zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,\r
+                                       zi->ci.buffered_data[i],t);\r
+#endif\r
+    }\r
+    if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)\r
+                                                                    !=zi->ci.pos_in_buffered_data)\r
+      err = ZIP_ERRNO;\r
+    zi->ci.pos_in_buffered_data = 0;\r
+    return err;\r
+}\r
+\r
+extern int ZEXPORT zipWriteInFileInZip (file, buf, len)\r
+    zipFile file;\r
+    const void* buf;\r
+    unsigned len;\r
+{\r
+    zip_internal* zi;\r
+    int err=ZIP_OK;\r
+\r
+    if (file == NULL)\r
+        return ZIP_PARAMERROR;\r
+    zi = (zip_internal*)file;\r
+\r
+    if (zi->in_opened_file_inzip == 0)\r
+        return ZIP_PARAMERROR;\r
+\r
+    zi->ci.stream.next_in = (void*)buf;\r
+    zi->ci.stream.avail_in = len;\r
+    zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);\r
+\r
+    while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))\r
+    {\r
+        if (zi->ci.stream.avail_out == 0)\r
+        {\r
+            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)\r
+                err = ZIP_ERRNO;\r
+            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;\r
+            zi->ci.stream.next_out = zi->ci.buffered_data;\r
+        }\r
+\r
+\r
+        if(err != ZIP_OK)\r
+            break;\r
+\r
+        if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))\r
+        {\r
+            uLong uTotalOutBefore = zi->ci.stream.total_out;\r
+            err=deflate(&zi->ci.stream,  Z_NO_FLUSH);\r
+            zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;\r
+\r
+        }\r
+        else\r
+        {\r
+            uInt copy_this,i;\r
+            if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)\r
+                copy_this = zi->ci.stream.avail_in;\r
+            else\r
+                copy_this = zi->ci.stream.avail_out;\r
+            for (i=0;i<copy_this;i++)\r
+                *(((char*)zi->ci.stream.next_out)+i) =\r
+                    *(((const char*)zi->ci.stream.next_in)+i);\r
+            {\r
+                zi->ci.stream.avail_in -= copy_this;\r
+                zi->ci.stream.avail_out-= copy_this;\r
+                zi->ci.stream.next_in+= copy_this;\r
+                zi->ci.stream.next_out+= copy_this;\r
+                zi->ci.stream.total_in+= copy_this;\r
+                zi->ci.stream.total_out+= copy_this;\r
+                zi->ci.pos_in_buffered_data += copy_this;\r
+            }\r
+        }\r
+    }\r
+\r
+    return err;\r
+}\r
+\r
+extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)\r
+    zipFile file;\r
+    uLong uncompressed_size;\r
+    uLong crc32;\r
+{\r
+    zip_internal* zi;\r
+    uLong compressed_size;\r
+    int err=ZIP_OK;\r
+\r
+    if (file == NULL)\r
+        return ZIP_PARAMERROR;\r
+    zi = (zip_internal*)file;\r
+\r
+    if (zi->in_opened_file_inzip == 0)\r
+        return ZIP_PARAMERROR;\r
+    zi->ci.stream.avail_in = 0;\r
+\r
+    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))\r
+        while (err==ZIP_OK)\r
+    {\r
+        uLong uTotalOutBefore;\r
+        if (zi->ci.stream.avail_out == 0)\r
+        {\r
+            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)\r
+                err = ZIP_ERRNO;\r
+            zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;\r
+            zi->ci.stream.next_out = zi->ci.buffered_data;\r
+        }\r
+        uTotalOutBefore = zi->ci.stream.total_out;\r
+        err=deflate(&zi->ci.stream,  Z_FINISH);\r
+        zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;\r
+    }\r
+\r
+    if (err==Z_STREAM_END)\r
+        err=ZIP_OK; /* this is normal */\r
+\r
+    if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))\r
+        if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)\r
+            err = ZIP_ERRNO;\r
+\r
+    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))\r
+    {\r
+        err=deflateEnd(&zi->ci.stream);\r
+        zi->ci.stream_initialised = 0;\r
+    }\r
+\r
+    if (!zi->ci.raw)\r
+    {\r
+        crc32 = (uLong)zi->ci.crc32;\r
+        uncompressed_size = (uLong)zi->ci.stream.total_in;\r
+    }\r
+    compressed_size = (uLong)zi->ci.stream.total_out;\r
+    #ifndef NOCRYPT\r
+    compressed_size += zi->ci.crypt_header_size;\r
+    #endif\r
+\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+20,\r
+                                compressed_size,4); /*compr size*/\r
+    if (zi->ci.stream.data_type == Z_ASCII)\r
+        ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);\r
+    ziplocal_putValue_inmemory(zi->ci.central_header+24,\r
+                                uncompressed_size,4); /*uncompr size*/\r
+\r
+    if (err==ZIP_OK)\r
+        err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,\r
+                                       (uLong)zi->ci.size_centralheader);\r
+    free(zi->ci.central_header);\r
+\r
+    if (err==ZIP_OK)\r
+    {\r
+        long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);\r
+        if (ZSEEK(zi->z_filefunc,zi->filestream,\r
+                  zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            err = ZIP_ERRNO;\r
+\r
+        if (err==ZIP_OK)\r
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */\r
+\r
+        if (err==ZIP_OK) /* compressed size, unknown */\r
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);\r
+\r
+        if (err==ZIP_OK) /* uncompressed size, unknown */\r
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);\r
+\r
+        if (ZSEEK(zi->z_filefunc,zi->filestream,\r
+                  cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)\r
+            err = ZIP_ERRNO;\r
+    }\r
+\r
+    zi->number_entry ++;\r
+    zi->in_opened_file_inzip = 0;\r
+\r
+    return err;\r
+}\r
+\r
+extern int ZEXPORT zipCloseFileInZip (file)\r
+    zipFile file;\r
+{\r
+    return zipCloseFileInZipRaw (file,0,0);\r
+}\r
+\r
+extern int ZEXPORT zipClose (file, global_comment)\r
+    zipFile file;\r
+    const char* global_comment;\r
+{\r
+    zip_internal* zi;\r
+    int err = 0;\r
+    uLong size_centraldir = 0;\r
+    uLong centraldir_pos_inzip ;\r
+    uInt size_global_comment;\r
+    if (file == NULL)\r
+        return ZIP_PARAMERROR;\r
+    zi = (zip_internal*)file;\r
+\r
+    if (zi->in_opened_file_inzip == 1)\r
+    {\r
+        err = zipCloseFileInZip (file);\r
+    }\r
+\r
+    if (global_comment==NULL)\r
+        size_global_comment = 0;\r
+    else\r
+        size_global_comment = strlen(global_comment);\r
+\r
+\r
+    centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);\r
+    if (err==ZIP_OK)\r
+    {\r
+        linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;\r
+        while (ldi!=NULL)\r
+        {\r
+            if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))\r
+                if (ZWRITE(zi->z_filefunc,zi->filestream,\r
+                           ldi->data,ldi->filled_in_this_block)\r
+                              !=ldi->filled_in_this_block )\r
+                    err = ZIP_ERRNO;\r
+\r
+            size_centraldir += ldi->filled_in_this_block;\r
+            ldi = ldi->next_datablock;\r
+        }\r
+    }\r
+    free_datablock(zi->central_dir.first_block);\r
+\r
+    if (err==ZIP_OK) /* Magic End */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);\r
+\r
+    if (err==ZIP_OK) /* number of this disk */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);\r
+\r
+    if (err==ZIP_OK) /* number of the disk with the start of the central directory */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);\r
+\r
+    if (err==ZIP_OK) /* total number of entries in the central dir on this disk */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);\r
+\r
+    if (err==ZIP_OK) /* total number of entries in the central dir */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);\r
+\r
+    if (err==ZIP_OK) /* size of the central directory */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);\r
+\r
+    if (err==ZIP_OK) /* offset of start of central directory with respect to the\r
+                            starting disk number */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,\r
+                                (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);\r
+\r
+    if (err==ZIP_OK) /* zipfile comment length */\r
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);\r
+\r
+    if ((err==ZIP_OK) && (size_global_comment>0))\r
+        if (ZWRITE(zi->z_filefunc,zi->filestream,\r
+                   global_comment,size_global_comment) != size_global_comment)\r
+                err = ZIP_ERRNO;\r
+\r
+    if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)\r
+        if (err == ZIP_OK)\r
+            err = ZIP_ERRNO;\r
+\r
+    TRYFREE(zi);\r
+\r
+    return err;\r
+}\r
index 4bc6aa40d0f9e358c64c7b7535d6a6bc8ca10237..d863e1aca5691ad44ea14d50a791fa47efdd986e 100644 (file)
-/* zip.h -- IO for compress .zip files using zlib
-   Version 0.21, March 10th, 2003
-
-   Copyright (C) 1998-2003 Gilles Vollant
-
-   This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
-     WinZip, InfoZip tools and compatible.
-   Encryption and multi volume ZipFile (span) are not supported.
-   Old compressions used by old PKZip 1.x are not supported
-
-  For uncompress .zip file, look at unzip.h
-
-
-   I WAIT FEEDBACK at mail info@winimage.com
-   Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
-
-   Condition of use and distribution are the same than zlib :
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-
-*/
-
-/* for more info about .ZIP format, see
-      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
-      http://www.info-zip.org/pub/infozip/doc/
-   PkWare has also a specification at :
-      ftp://ftp.pkware.com/probdesc.zip
-*/
-
-#ifndef _zip_H
-#define _zip_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
-    from (void*) without cast */
-typedef struct TagzipFile__ { int unused; } zipFile__;
-typedef zipFile__ *zipFile;
-#else
-typedef voidp zipFile;
-#endif
-
-#define ZIP_OK                          (0)
-#define ZIP_EOF                         (0)
-#define ZIP_ERRNO                       (Z_ERRNO)
-#define ZIP_PARAMERROR                  (-102)
-#define ZIP_BADZIPFILE                  (-103)
-#define ZIP_INTERNALERROR               (-104)
-
-#ifndef DEF_MEM_LEVEL
-#  if MAX_MEM_LEVEL >= 8
-#    define DEF_MEM_LEVEL 8
-#  else
-#    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
-#  endif
-#endif
-/* default memLevel */
-
-/* tm_zip contain date/time info */
-typedef struct tm_zip_s
-{
-    uInt tm_sec;            /* seconds after the minute - [0,59] */
-    uInt tm_min;            /* minutes after the hour - [0,59] */
-    uInt tm_hour;           /* hours since midnight - [0,23] */
-    uInt tm_mday;           /* day of the month - [1,31] */
-    uInt tm_mon;            /* months since January - [0,11] */
-    uInt tm_year;           /* years - [1980..2044] */
-} tm_zip;
-
-typedef struct
-{
-    tm_zip      tmz_date;       /* date in understandable format           */
-    uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
-/*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
-
-    uLong       internal_fa;    /* internal file attributes        2 bytes */
-    uLong       external_fa;    /* external file attributes        4 bytes */
-} zip_fileinfo;
-
-typedef const char* zipcharpc;
-
-
-#define APPEND_STATUS_CREATE        (0)
-#define APPEND_STATUS_CREATEAFTER   (1)
-#define APPEND_STATUS_ADDINZIP      (2)
-
-extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
-/*
-  Create a zipfile.
-     pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
-       an Unix computer "zlib/zlib113.zip".
-     if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
-       will be created at the end of the file.
-         (useful if the file contain a self extractor code)
-     if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
-       add files in existing zip (be sure you don't add file that doesn't exist)
-     If the zipfile cannot be opened, the return value is NULL.
-     Else, the return value is a zipFile Handle, usable with other function
-       of this zip package.
-*/
-
-/* Note : there is no delete function into a zipfile.
-   If you want delete file into a zipfile, you must open a zipfile, and create another
-   Of couse, you can use RAW reading and writing to copy the file you did not want delte
-*/
-
-extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
-                                   int append,
-                                   zipcharpc* globalcomment,
-                                   zlib_filefunc_def* pzlib_filefunc_def));
-
-extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
-                       const char* filename,
-                       const zip_fileinfo* zipfi,
-                       const void* extrafield_local,
-                       uInt size_extrafield_local,
-                       const void* extrafield_global,
-                       uInt size_extrafield_global,
-                       const char* comment,
-                       int method,
-                       int level));
-/*
-  Open a file in the ZIP for writing.
-  filename : the filename in zip (if NULL, '-' without quote will be used
-  *zipfi contain supplemental information
-  if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
-    contains the extrafield data the the local header
-  if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
-    contains the extrafield data the the local header
-  if comment != NULL, comment contain the comment string
-  method contain the compression method (0 for store, Z_DEFLATED for deflate)
-  level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
-*/
-
-
-extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
-                                            const char* filename,
-                                            const zip_fileinfo* zipfi,
-                                            const void* extrafield_local,
-                                            uInt size_extrafield_local,
-                                            const void* extrafield_global,
-                                            uInt size_extrafield_global,
-                                            const char* comment,
-                                            int method,
-                                            int level,
-                                            int raw));
-
-/*
-  Same than zipOpenNewFileInZip, except if raw=1, we write raw file
- */
-
-extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
-                                            const char* filename,
-                                            const zip_fileinfo* zipfi,
-                                            const void* extrafield_local,
-                                            uInt size_extrafield_local,
-                                            const void* extrafield_global,
-                                            uInt size_extrafield_global,
-                                            const char* comment,
-                                            int method,
-                                            int level,
-                                            int raw,
-                                            int windowBits,
-                                            int memLevel,
-                                            int strategy,
-                                            const char* password,
-                                            uLong crcForCtypting));
-
-/*
-  Same than zipOpenNewFileInZip2, except
-    windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
-    password : crypting password (NULL for no crypting)
-    crcForCtypting : crc of file to compress (needed for crypting)
- */
-
-
-extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
-                       const void* buf,
-                       unsigned len));
-/*
-  Write data in the zipfile
-*/
-
-extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
-/*
-  Close the current file in the zipfile
-*/
-
-
-extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
-                                            uLong uncompressed_size,
-                                            uLong crc32));
-/*
-  Close the current file in the zipfile, for fiel opened with
-    parameter raw=1 in zipOpenNewFileInZip2
-  uncompressed_size and crc32 are value for the uncompressed size
-*/
-
-extern int ZEXPORT zipClose OF((zipFile file,
-                const char* global_comment));
-/*
-  Close the zipfile
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _zip_H */
+/* zip.h -- IO for compress .zip files using zlib\r
+   Version 0.22, May 19th, 2003\r
+\r
+   Copyright (C) 1998-2003 Gilles Vollant\r
+\r
+   This unzip package allow creates .ZIP file, compatible with PKZip 2.04g\r
+     WinZip, InfoZip tools and compatible.\r
+   Encryption and multi volume ZipFile (span) are not supported.\r
+   Old compressions used by old PKZip 1.x are not supported\r
+\r
+  For uncompress .zip file, look at unzip.h\r
+\r
+\r
+   I WAIT FEEDBACK at mail info@winimage.com\r
+   Visit also http://www.winimage.com/zLibDll/unzip.html for evolution\r
+\r
+   Condition of use and distribution are the same than zlib :\r
+\r
+  This software is provided 'as-is', without any express or implied\r
+  warranty.  In no event will the authors be held liable for any damages\r
+  arising from the use of this software.\r
+\r
+  Permission is granted to anyone to use this software for any purpose,\r
+  including commercial applications, and to alter it and redistribute it\r
+  freely, subject to the following restrictions:\r
+\r
+  1. The origin of this software must not be misrepresented; you must not\r
+     claim that you wrote the original software. If you use this software\r
+     in a product, an acknowledgment in the product documentation would be\r
+     appreciated but is not required.\r
+  2. Altered source versions must be plainly marked as such, and must not be\r
+     misrepresented as being the original software.\r
+  3. This notice may not be removed or altered from any source distribution.\r
+\r
+\r
+*/\r
+\r
+/* for more info about .ZIP format, see\r
+      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip\r
+      http://www.info-zip.org/pub/infozip/doc/\r
+   PkWare has also a specification at :\r
+      ftp://ftp.pkware.com/probdesc.zip\r
+*/\r
+\r
+#ifndef _zip_H\r
+#define _zip_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifndef _ZLIB_H\r
+#include "zlib.h"\r
+#endif\r
+\r
+#ifndef _ZLIBIOAPI_H\r
+#include "ioapi.h"\r
+#endif\r
+\r
+#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)\r
+/* like the STRICT of WIN32, we define a pointer that cannot be converted\r
+    from (void*) without cast */\r
+typedef struct TagzipFile__ { int unused; } zipFile__;\r
+typedef zipFile__ *zipFile;\r
+#else\r
+typedef voidp zipFile;\r
+#endif\r
+\r
+#define ZIP_OK                          (0)\r
+#define ZIP_EOF                         (0)\r
+#define ZIP_ERRNO                       (Z_ERRNO)\r
+#define ZIP_PARAMERROR                  (-102)\r
+#define ZIP_BADZIPFILE                  (-103)\r
+#define ZIP_INTERNALERROR               (-104)\r
+\r
+#ifndef DEF_MEM_LEVEL\r
+#  if MAX_MEM_LEVEL >= 8\r
+#    define DEF_MEM_LEVEL 8\r
+#  else\r
+#    define DEF_MEM_LEVEL  MAX_MEM_LEVEL\r
+#  endif\r
+#endif\r
+/* default memLevel */\r
+\r
+/* tm_zip contain date/time info */\r
+typedef struct tm_zip_s\r
+{\r
+    uInt tm_sec;            /* seconds after the minute - [0,59] */\r
+    uInt tm_min;            /* minutes after the hour - [0,59] */\r
+    uInt tm_hour;           /* hours since midnight - [0,23] */\r
+    uInt tm_mday;           /* day of the month - [1,31] */\r
+    uInt tm_mon;            /* months since January - [0,11] */\r
+    uInt tm_year;           /* years - [1980..2044] */\r
+} tm_zip;\r
+\r
+typedef struct\r
+{\r
+    tm_zip      tmz_date;       /* date in understandable format           */\r
+    uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */\r
+/*    uLong       flag;        */   /* general purpose bit flag        2 bytes */\r
+\r
+    uLong       internal_fa;    /* internal file attributes        2 bytes */\r
+    uLong       external_fa;    /* external file attributes        4 bytes */\r
+} zip_fileinfo;\r
+\r
+typedef const char* zipcharpc;\r
+\r
+\r
+#define APPEND_STATUS_CREATE        (0)\r
+#define APPEND_STATUS_CREATEAFTER   (1)\r
+#define APPEND_STATUS_ADDINZIP      (2)\r
+\r
+extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));\r
+/*\r
+  Create a zipfile.\r
+     pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on\r
+       an Unix computer "zlib/zlib113.zip".\r
+     if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip\r
+       will be created at the end of the file.\r
+         (useful if the file contain a self extractor code)\r
+     if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will\r
+       add files in existing zip (be sure you don't add file that doesn't exist)\r
+     If the zipfile cannot be opened, the return value is NULL.\r
+     Else, the return value is a zipFile Handle, usable with other function\r
+       of this zip package.\r
+*/\r
+\r
+/* Note : there is no delete function into a zipfile.\r
+   If you want delete file into a zipfile, you must open a zipfile, and create another\r
+   Of couse, you can use RAW reading and writing to copy the file you did not want delte\r
+*/\r
+\r
+extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,\r
+                                   int append,\r
+                                   zipcharpc* globalcomment,\r
+                                   zlib_filefunc_def* pzlib_filefunc_def));\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,\r
+                       const char* filename,\r
+                       const zip_fileinfo* zipfi,\r
+                       const void* extrafield_local,\r
+                       uInt size_extrafield_local,\r
+                       const void* extrafield_global,\r
+                       uInt size_extrafield_global,\r
+                       const char* comment,\r
+                       int method,\r
+                       int level));\r
+/*\r
+  Open a file in the ZIP for writing.\r
+  filename : the filename in zip (if NULL, '-' without quote will be used\r
+  *zipfi contain supplemental information\r
+  if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local\r
+    contains the extrafield data the the local header\r
+  if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global\r
+    contains the extrafield data the the local header\r
+  if comment != NULL, comment contain the comment string\r
+  method contain the compression method (0 for store, Z_DEFLATED for deflate)\r
+  level contain the level of compression (can be Z_DEFAULT_COMPRESSION)\r
+*/\r
+\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,\r
+                                            const char* filename,\r
+                                            const zip_fileinfo* zipfi,\r
+                                            const void* extrafield_local,\r
+                                            uInt size_extrafield_local,\r
+                                            const void* extrafield_global,\r
+                                            uInt size_extrafield_global,\r
+                                            const char* comment,\r
+                                            int method,\r
+                                            int level,\r
+                                            int raw));\r
+\r
+/*\r
+  Same than zipOpenNewFileInZip, except if raw=1, we write raw file\r
+ */\r
+\r
+extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,\r
+                                            const char* filename,\r
+                                            const zip_fileinfo* zipfi,\r
+                                            const void* extrafield_local,\r
+                                            uInt size_extrafield_local,\r
+                                            const void* extrafield_global,\r
+                                            uInt size_extrafield_global,\r
+                                            const char* comment,\r
+                                            int method,\r
+                                            int level,\r
+                                            int raw,\r
+                                            int windowBits,\r
+                                            int memLevel,\r
+                                            int strategy,\r
+                                            const char* password,\r
+                                            uLong crcForCtypting));\r
+\r
+/*\r
+  Same than zipOpenNewFileInZip2, except\r
+    windowBits,memLevel,,strategy : see parameter strategy in deflateInit2\r
+    password : crypting password (NULL for no crypting)\r
+    crcForCtypting : crc of file to compress (needed for crypting)\r
+ */\r
+\r
+\r
+extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,\r
+                       const void* buf,\r
+                       unsigned len));\r
+/*\r
+  Write data in the zipfile\r
+*/\r
+\r
+extern int ZEXPORT zipCloseFileInZip OF((zipFile file));\r
+/*\r
+  Close the current file in the zipfile\r
+*/\r
+\r
+\r
+extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,\r
+                                            uLong uncompressed_size,\r
+                                            uLong crc32));\r
+/*\r
+  Close the current file in the zipfile, for fiel opened with\r
+    parameter raw=1 in zipOpenNewFileInZip2\r
+  uncompressed_size and crc32 are value for the uncompressed size\r
+*/\r
+\r
+extern int ZEXPORT zipClose OF((zipFile file,\r
+                const char* global_comment));\r
+/*\r
+  Close the zipfile\r
+*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _zip_H */\r
index a619b96578a4e3ab8decd1aec41e9e3e8c432ebb..c22ec342680a62f6d0379267297ae1bc61344a2f 100644 (file)
@@ -14,4 +14,9 @@ open zlibvc.sln with Microsoft Visual C++ 7.0 (Visual Studio .net)
 \r
 \r
 Note : You don't need recompile yourself. There is compiled .LIB in\r
-  http://www.winimage.com/zLibDll\r
+  http://www.winimage.com/zLibDll . See this page for more information\r
+\r
+\r
+\r
+Gilles Vollant\r
+info@winimage.com\r
index 89cb8d1e67a6f6e2114d9b505577b50e16d26f08..fdae3d4751e723492b910a1915777ab81921d958 100644 (file)
@@ -4,7 +4,7 @@ DESCRIPTION     '"""zlib data compression library"""'
 \r
 EXETYPE                WINDOWS\r
 \r
-VERSION                1.20\r
+VERSION                1.21\r
 \r
 CODE    PRELOAD MOVEABLE DISCARDABLE\r
 DATA    PRELOAD MOVEABLE SINGLE\r
index 13d0d66a22588c1ec920d628434c40b2f6831000..514585ce57b4c3afa8215de0a5573c929a1f8b06 100644 (file)
@@ -3,8 +3,8 @@
 \r
 #define IDR_VERSION1  1\r
 IDR_VERSION1   VERSIONINFO     MOVEABLE IMPURE LOADONCALL DISCARDABLE\r
-  FILEVERSION   1,2,0,0\r
-  PRODUCTVERSION 1,2,0,0\r
+  FILEVERSION   1,2,1,0\r
+  PRODUCTVERSION 1,2,1,0\r
   FILEFLAGSMASK        VS_FFI_FILEFLAGSMASK\r
   FILEFLAGS    0\r
   FILEOS       VOS_DOS_WINDOWS16\r
@@ -18,7 +18,7 @@ BEGIN
 \r
     BEGIN\r
       VALUE "FileDescription", "zlib data compression library\0"\r
-      VALUE "FileVersion",     "1.2.0\0"\r
+      VALUE "FileVersion",     "1.2.1\0"\r
       VALUE "InternalName",    "zlib16\0"\r
       VALUE "OriginalFilename",        "zlib16.dll\0"\r
       VALUE "ProductName",     "ZLib16.DLL\0"\r
index 5d86e03e3836e48b651f08666a3526bf9c8f6a8b..6c51679853b41409ab1c8e209d65d4900c13e9bc 100644 (file)
@@ -2,8 +2,8 @@
 \r
 #define IDR_VERSION1  1\r
 IDR_VERSION1   VERSIONINFO     MOVEABLE IMPURE LOADONCALL DISCARDABLE\r
-  FILEVERSION   1,2,0,0\r
-  PRODUCTVERSION 1,2,0,0\r
+  FILEVERSION   1,2,1,0\r
+  PRODUCTVERSION 1,2,1,0\r
   FILEFLAGSMASK        VS_FFI_FILEFLAGSMASK\r
   FILEFLAGS    0\r
   FILEOS       VOS_DOS_WINDOWS32\r
@@ -17,7 +17,7 @@ BEGIN
 \r
     BEGIN\r
       VALUE "FileDescription", "zlib data compression library\0"\r
-      VALUE "FileVersion",     "1.2.0.0\0"\r
+      VALUE "FileVersion",     "1.2.1.0\0"\r
       VALUE "InternalName",    "zlib\0"\r
       VALUE "OriginalFilename",        "zlib.dll\0"\r
       VALUE "ProductName",     "ZLib.DLL\0"\r
index 90109d6ae7f3c4f8597734600ade31d85053acc3..c2804a8112719d869aa94551009bad3a98264012 100644 (file)
@@ -1,6 +1,6 @@
 LIBRARY                "zlib"\r
 \r
-VERSION                1.20\r
+VERSION                1.21\r
 \r
 HEAPSIZE       1048576,8192\r
 \r
diff --git a/contrib/zlib_dll_FAQ.txt b/contrib/zlib_dll_FAQ.txt
new file mode 100644 (file)
index 0000000..bc1fd59
--- /dev/null
@@ -0,0 +1,257 @@
+
+            Frequently Asked Questions about ZLIB.DLL
+
+
+This FAQ is about the design, the rationale, and the use of
+ZLIB.DLL. If you have general questions about zlib, you should
+check the file "FAQ" found in the zlib distribution, or at the
+location http://www.gzip.org/zlib/zlib_faq.html
+
+
+ 1. Why am I having problems using ZLIB.DLL? My application works
+    with the static build of zlib just fine, and I didn't make any
+    modification when recompiling it for ZLIB.DLL.
+
+  - Make sure you define ZLIB_DLL before including "zlib.h".
+    Applications that link to ZLIB.DLL will work properly if
+    the source files are compiled in this (or in a compatible)
+    way, and the executables are linked to MSVCRT.DLL.
+
+
+ 2. Why do I have to do this? When I use other libraries, I can
+    link my code to their static or dynamic versions, without
+    needing any source code modification or recompilation.
+
+  - In order to preserve the backwards compatibility with the
+    older versions of ZLIB.DLL, and give the ability to use zlib
+    to the non-C programmers at the same time, we had to do this
+    compromise.
+
+
+ 3. What exactly is this mess about, and why is it happening?
+
+  - It's about the calling convention used for the zlib functions.
+    If linked in statically, zlib uses the C (CDECL) convention.
+    If linked in dynamically (via ZLIB.DLL), it uses the STDCALL
+    convention. The ZLIB_DLL macro switches on the use of STDCALL.
+
+    It happens because we need to preserve compatibility with the
+    old releases of ZLIB.DLL that use STDCALL, and, at the same
+    time, we must provide support for programmers who use other
+    programming languages with bindings that require CDECL.
+
+
+ 4. Why not use the STDCALL convention all the time?
+    It's the standard convention in Win32, and I need it in my
+    Visual Basic project!
+
+  - Most of the Win32 API functions (without varargs) use indeed
+    the STDCALL (WINAPI) convention, but the standard C functions
+    use the default CDECL. If one calls Win32 functions such as
+    CreateFile(), sometimes it makes sense to decorate one's own
+    functions with STDCALL. But if one is aiming at ANSI C or
+    POSIX portability, and calls functions such as fopen(), it is
+    not a sound decision to include <windows.h> or to use non-ANSI
+    constructs only to make one's functions STDCALL-able. This is
+    not the biggest problem, however.
+
+    Technically, STDCALL is not bad; it is even a little faster
+    than CDECL. The problem of using STDCALL is actually a problem
+    of using any explicit calling convention. FASTCALL falls into
+    the same category.
+
+    Explicit specification of calling conventions, whether it's
+    direct or indirect via a macro, happens commonly in Windows,
+    but it is regarded as a noisy, non-standard C quirk on other
+    platforms. It isn't possible to write an ANSI C -conforming
+    program, for example, if it is necessary to specify calling
+    conventions. Libraries can hide the dirty stuff in header
+    files, under macros, but callbacks will still remain exposed.
+    This is why the zlib callbacks will not be decorated.
+    (The old Windows callbacks, such as WndProc, are decorated,
+    but the newer ones are not.)
+
+    There is one more problem with explicit, non-default calling
+    conventions: the ability to use zlib in other programming
+    languages. Some of them, like Ada (GNAT) and Fortran (GNU G77)
+    have C bindings implemented initially on Unix, hence relying
+    on the C calling convention.
+
+    So we are decorating the functions using STDCALL in ZLIB.DLL
+    to maintain compatibility with the old versions, but we are
+    using the default CDECL in the static library, to allow other
+    programming languages to use zlib in a portable fashion, via
+    C bindings.
+
+
+ 5. Why not use the default (CDECL) convention all the time?
+    It's the standard convention in C, and I need it in my Ada
+    project!
+
+  - Originally, ZLIB.DLL was intended to run under Visual Basic,
+    and VB6 and earlier need STDCALL.
+
+    We admit that cluttering the main zlib sources, for the sake
+    of interfacing with Visual Basic and at the expense of other
+    programming languages, is not fair. It would have been better
+    to maintain a "VB-only" project in the contrib/ directory, and
+    to build a custom ZLIBVB.DLL, for example -- as we did with
+    the Delphi projects. Another possible solution would have been
+    to build STDCALL wrappers around the CDECL-exported functions.
+
+    But this was the accident that we have to live with, in order
+    to maintain binary compatibility with the older versions of
+    ZLIB.DLL.
+
+
+ 6. If my application uses ZLIB.DLL, do I have to link it to
+    MSVCRT.DLL? Why?
+
+  - The executables (.EXE, .DLL, etc.) that are involved in the
+    same process and are using the C run-time library (i.e. they
+    are calling any standard C function), must link to the same
+    library. There are several libraries in the Win32 system:
+    CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
+    Since ZLIB.DLL is linked to MSVCRT.DLL, the executables that
+    depend on it must also link to MSVCRT.DLL.
+
+
+ 7. Why are you saying that ZLIB.DLL and my application must be
+    linked to the same C run-time library (CRT)? I linked my
+    application and my DLLs to different C libraries (e.g. my
+    application to a static library, and my DLLs to MSVCRT.DLL),
+    and everything works fine.
+
+  - If a library invokes only pure Win32 API (i.e. accessible
+    via <windows.h>), its DLL build will work in any context.
+    But if a library invokes standard C functions, things get
+    more complicated.
+
+    There is a single Win32 library in a Win32 system. Every
+    function in this library resides in a single DLL module, that
+    is safe to call from anywhere. On the other hand, there are
+    multiple versions of the C library that are all at the same
+    time in the system, and all of them have internal states,
+    therefore it is dangerous to intermix them with each other.
+
+    Intermixing multiple C libraries is possible, as long as their
+    internal states are kept intact. The Microsoft Knowledge Base
+    article Q140584 "HOWTO: Link with the Correct C Run-Time (CRT)
+    Library" enumerates some of the potential problems raised by
+    intermixing, but does not offer a complete description of how
+    to avoid them, except by advising not to mix the C libraries.
+    If you can send us more information about this issue, we will
+    highly appreciate it. (But please do NOT send us source code
+    from Microsoft, even if it comes with your legitimate copy of
+    Visual C++!)
+
+    If this kind of intermixing works for you, it's because your
+    application and DLLs are avoiding the corruption of the CRT's
+    internal states, due to a fortunate accident. It's not because
+    those libraries really work together.
+
+    Also note that linking ZLIB.DLL to non-Microsoft C libraries
+    (such as Borland's) raises similar problems.
+
+
+ 8. Why are you linking ZLIB.DLL to MSVCRT.DLL?
+
+  - MSVCRT.DLL exists on every Windows 95 with a new service pack
+    installed, or with Microsoft Internet Explorer 4 or later, and
+    on all other Windows 4.x or later (Windows 98, Windows NT 4,
+    or later). It is freely distributable; if not present in the
+    system, it can be downloaded from Microsoft or from other
+    software provider for free.
+
+    The fact that MSVCRT.DLL does not exist on a virgin Windows 95
+    is not so problematic. The number of Windows 95 installations
+    is rapidly decreasing, Microsoft stopped supporting it a long
+    time ago, and many recent applications from various vendors
+    including Microsoft, do not even run on it. Even without these
+    arguments, no serious user should run Windows 95 without a
+    proper update installed.
+
+    There is also the fact that the mainstream C compilers for
+    Windows are Microsoft Visual C++ 6.0, and gcc/MinGW. Both
+    are producing executables that link to MSVCRT.DLL by default,
+    without offering other dynamic CRTs as alternatives easy to
+    select by users.
+
+
+ 9. Why are you not linking ZLIB.DLL to
+    <<my favorite C run-time library>> ?
+
+  - We considered and abandoned the following alternatives:
+
+    * Linking ZLIB.DLL to a static C library (LIBC.LIB, or
+      LIBCMT.LIB) is not a good option. People are using ZLIB.DLL
+      mainly to save disk space. If you are linking your program
+      to a static C library, you may as well consider linking zlib
+      in statically, too.
+
+    * Linking ZLIB.DLL to CRTDLL.DLL looks very appealing,
+      because CRTDLL.DLL is present on every Win32 installation.
+      Unfortunately, it has a series of problems: it raises
+      difficulties when linking to the Microsoft C++ libraries,
+      it is not thread-safe, and Microsoft has discontinued its
+      support a long time ago.
+
+    * Linking ZLIB.DLL to MSVCRT70.DLL, supplied with the
+      Microsoft .NET platform and Visual C++ 7.0, is not a good
+      option. Although it can be downloaded and distributed
+      freely, it is hardly present on today's Win32 installations.
+      If it will become more popular than MSVCRT.DLL, and will be
+      pre-installed on the future Win32 systems, we will probably
+      think again about it.
+
+    * Linking ZLIB.DLL to NTDLL.DLL is not possible.
+      NTDLL.DLL exports only a part of the C library, and only
+      on Windows NT systems.
+
+
+10. I understand your reasons. However, my project needs ZLIB.DLL
+    linked to something different than MSVCRT.DLL. What can I do?
+
+    Feel free to rebuild this DLL from the zlib sources, and link
+    it the way you want. It is required, however, to clearly
+    state that your build is unofficial. Another thing that is not
+    required, but highly recommended, is to name that custom DLL
+    differently, and/or to install it in a private directory that
+    can be accessed by your application, but is not visible to the
+    others (e.g. it's not the SYSTEM or the SYSTEM32 directory,
+    and it's not in the PATH). Otherwise, your build may clash
+    with applications that link to the official build.
+
+    For example, in Cygwin, zlib is linked to their runtime
+    CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
+
+
+11. My I include additional pieces of code that I find useful,
+    link them in ZLIB.DLL, and export them?
+
+    No. A legitimate build of ZLIB.DLL must not include code that
+    does not originate from the official zlib sources. But you can
+    make your own private build, and give it a different name, as
+    suggested in the previous answer.
+
+    For example, in Borland Delphi and C++ Builder, zlib is part
+    of the standard VCL library. If an application links to VCL
+    dynamically, the name of the distributable binary (VCLxx.DLL)
+    does not posess any danger of clashing with a legitimate but
+    incompatible ZLIB.DLL.
+
+
+12. I see that I may have all kinds of problems if I use ZLIB.DLL.
+    Do you recommend to link zlib in statically? Do I get rid of
+    problems?
+
+  - Yes, definitely. In fact, unless you are distributing a large
+    number of executables, each of them linking to zlib, you will
+    save space by linking zlib in statically (assuming that you
+    would otherwise distribute ZLIB.DLL with your application).
+    zlib is not a big library, and the space saved by ZLIB.DLL is
+    little. Much of the actual size of the DLL is due to the 4KB
+    alignment in the binary.
+
+    But you may have reasons, other than size, to use the DLL.
+    That is entirely up to you.
diff --git a/crc32.c b/crc32.c
index d0a9f5e983558655330e799d7b08c9ceb2eb62de..f163fe1f9bf1e663e9874564f4907c2d40c64ee1 100644 (file)
--- a/crc32.c
+++ b/crc32.c
 #  endif /* !DYNAMIC_CRC_TABLE */
 #endif /* MAKECRCH */
 
-#include "zlib.h"
+#include "zutil.h"
 
 #define local static
 
 /* Find a four-byte integer type for crc32_little() and crc32_big(). */
 #ifndef NOBYFOUR
-#  ifdef __STDC__       /* need ANSI C limits.h to determine sizes */
+#  ifdef STDC           /* need ANSI C limits.h to determine sizes */
 #    include <limits.h>
 #    define BYFOUR
-#    if (UINT_MAX == 4294967295)
+#    if (UINT_MAX == 0xffffffffUL)
        typedef unsigned int u4;
-#    elif (ULONG_MAX == 4294967295)
-       typedef unsigned long u4;
-#    elif (USHRT_MAX == 4294967295)
-       typedef unsigned short u4;
 #    else
-#      undef BYFOUR     /* can't find a four-byte integer type! */
+#      if (ULONG_MAX == 0xffffffffUL)
+         typedef unsigned long u4;
+#      else
+#        if (USHRT_MAX == 0xffffffffUL)
+           typedef unsigned short u4;
+#        else
+#          undef BYFOUR     /* can't find a four-byte integer type! */
+#        endif
+#      endif
 #    endif
-#  endif /* __STDC__ */
+#  endif /* STDC */
 #endif /* !NOBYFOUR */
 
 /* Definitions for doing the crc four data bytes at a time. */
@@ -95,7 +99,7 @@ local void make_crc_table()
     /* terms of polynomial defining this crc (except x^32): */
     static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
 
-    /* make exclusive-or pattern from polynomial (0xedb88320L) */
+    /* make exclusive-or pattern from polynomial (0xedb88320UL) */
     poly = 0UL;
     for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
         poly |= 1UL << (31 - p[n]);
@@ -240,7 +244,7 @@ local unsigned long crc32_little(crc, buf, len)
 
     c = (u4)crc;
     c = ~c;
-    while (len && ((int)buf & 3)) {
+    while (len && ((size_t)buf & 3)) {
         c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
         len--;
     }
@@ -280,7 +284,7 @@ local unsigned long crc32_big(crc, buf, len)
 
     c = REV((u4)crc);
     c = ~c;
-    while (len && ((int)buf & 3)) {
+    while (len && ((size_t)buf & 3)) {
         c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
         len--;
     }
index 97a080c1815ea22bbf23497252466b46a257c376..bb160d8b5e9228a6dd450f70622245d40426f0ff 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -37,7 +37,7 @@
  *  REFERENCES
  *
  *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- *      Available in ftp://ds.internic.net/rfc/rfc1951.txt
+ *      Available in http://www.ietf.org/rfc/rfc1951.txt
  *
  *      A description of the Rabin and Karp algorithm is given in the book
  *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
@@ -52,7 +52,7 @@
 #include "deflate.h"
 
 const char deflate_copyright[] =
-   " deflate 1.2.0.1 Copyright 1995-2003 Jean-loup Gailly ";
+   " deflate 1.2.0.2 Copyright 1995-2003 Jean-loup Gailly ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -157,7 +157,9 @@ local const config configuration_table[10] = {
 #define EQUAL 0
 /* result of memcmp for equal strings */
 
+#ifndef NO_DUMMY_DECL
 struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
+#endif
 
 /* ===========================================================================
  * Update a hash value with the given input byte
@@ -255,10 +257,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
         windowBits = -windowBits;
     }
     if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
-        windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
+        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
         strategy < 0 || strategy > Z_RLE) {
         return Z_STREAM_ERROR;
     }
+    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
     s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
     if (s == Z_NULL) return Z_MEM_ERROR;
     strm->state = (struct internal_state FAR *)s;
@@ -520,9 +523,16 @@ int ZEXPORT deflate (strm, flush)
     if (s->status == INIT_STATE) {
 
         uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
-        uInt level_flags = (s->level-1) >> 1;
-
-        if (level_flags > 3) level_flags = 3;
+        uInt level_flags;
+
+        if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+            level_flags = 0;
+        else if (s->level < 6)
+            level_flags = 1;
+        else if (s->level == 6)
+            level_flags = 2;
+        else
+            level_flags = 3;
         header |= (level_flags << 6);
         if (s->strstart != 0) header |= PRESET_DICT;
         header += 31 - (header % 31);
@@ -975,7 +985,7 @@ local uInt longest_match_fast(s, cur_match)
     if (len < MIN_MATCH) return MIN_MATCH - 1;
 
     s->match_start = cur_match;
-    return len <= s->lookahead ? len : s->lookahead;
+    return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
 }
 
 #ifdef DEBUG
@@ -1028,19 +1038,22 @@ local void fill_window(s)
         more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
 
         /* Deal with !@#$% 64K limit: */
-        if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
-            more = wsize;
-
-        } else if (more == (unsigned)(-1)) {
-            /* Very unlikely, but possible on 16 bit machine if strstart == 0
-             * and lookahead == 1 (input done one byte at time)
-             */
-            more--;
+        if (sizeof(int) <= 2) {
+            if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+                more = wsize;
+    
+            } else if (more == (unsigned)(-1)) {
+                /* Very unlikely, but possible on 16 bit machine if
+                 * strstart == 0 && lookahead == 1 (input done one byte at time)
+                 */
+                more--;
+            }
+        }
 
         /* If the window is almost full and there is insufficient lookahead,
          * move the upper half to the lower one to make room in the upper half.
          */
-        } else if (s->strstart >= wsize+MAX_DIST(s)) {
+        if (s->strstart >= wsize+MAX_DIST(s)) {
 
             zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
             s->match_start -= wsize;
@@ -1347,9 +1360,12 @@ local block_state deflate_slow(s, flush)
             }
             /* longest_match() or longest_match_fast() sets match_start */
 
-            if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
-                 (s->match_length == MIN_MATCH &&
-                  s->strstart - s->match_start > TOO_FAR))) {
+            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
+#if TOO_FAR < 32768
+                || (s->match_length == MIN_MATCH &&
+                    s->strstart - s->match_start > TOO_FAR)
+#endif
+                )) {
 
                 /* If prev_match is also MIN_MATCH, match_start is garbage
                  * but we will ignore the current match anyway.
index c3f885834fd7679afbf8abba0273f807278b374c..0e8417d410b01f55594eab42283db5f5cca8dbdd 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -10,8 +10,8 @@
 
 /* @(#) $Id$ */
 
-#ifndef _DEFLATE_H
-#define _DEFLATE_H
+#ifndef DEFLATE_H
+#define DEFLATE_H
 
 #include "zutil.h"
 
@@ -315,4 +315,4 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
               flush = _tr_tally(s, distance, length) 
 #endif
 
-#endif
+#endif /* DEFLATE_H */
index 9fd13ce3ad227ba3d546a43a897859b186be5e12..3c53a93a92cf20404e3e5e31ac4136716c9bc52d 100644 (file)
--- a/example.c
+++ b/example.c
@@ -142,13 +142,18 @@ void test_gzio(out, in, uncompr, uncomprLen)
         exit(1);
     }
 
+    if (gzungetc(' ', file) != ' ') {
+        fprintf(stderr, "gzungetc error\n");
+        exit(1);
+    }
+
     gzgets(file, (char*)uncompr, uncomprLen);
     uncomprLen = strlen((char*)uncompr);
-    if (uncomprLen != 6) { /* "hello!" */
+    if (uncomprLen != 7) { /* " hello!" */
         fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
         exit(1);
     }
-    if (strcmp((char*)uncompr, hello+7)) {
+    if (strcmp((char*)uncompr, hello+6)) {
         fprintf(stderr, "bad gzgets after gzseek\n");
         exit(1);
     } else {
@@ -523,6 +528,9 @@ int main(argc, argv)
         fprintf(stderr, "warning: different zlib version\n");
     }
 
+    printf("zlib version %s = 0x%04x, compile flags = 0x%x\n",
+            ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
+
     compr    = (Byte*)calloc((uInt)comprLen, 1);
     uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
     /* compr and uncompr are cleared to avoid reading uninitialized
diff --git a/gzio.c b/gzio.c
index 1f561ac4c81886853e0d0e97d5b33f7a5e03634d..14fc33c438d16f07a6dd62717572c6a4b9fcb4b4 100644 (file)
--- a/gzio.c
+++ b/gzio.c
@@ -11,7 +11,9 @@
 
 #include "zutil.h"
 
+#ifndef NO_DUMMY_DECL
 struct internal_state {int dummy;}; /* for buggy compilers */
+#endif
 
 #ifndef Z_BUFSIZE
 #  ifdef MAXSEG_64K
@@ -55,6 +57,8 @@ typedef struct gz_stream {
     int      transparent; /* 1 if input file is not a .gz file */
     char     mode;    /* 'w' or 'r' */
     long     startpos; /* start of compressed data in file (header skipped) */
+    int      back;    /* one character push-back */
+    int      last;    /* true if push-back is last character */
 } gz_stream;
 
 
@@ -102,6 +106,7 @@ local gzFile gz_open (path, mode, fd)
     s->file = NULL;
     s->z_err = Z_OK;
     s->z_eof = 0;
+    s->back = EOF;
     s->crc = crc32(0L, Z_NULL, 0);
     s->msg = NULL;
     s->transparent = 0;
@@ -391,6 +396,18 @@ int ZEXPORT gzread (file, buf, len)
     s->stream.next_out = (Bytef*)buf;
     s->stream.avail_out = len;
 
+    if (s->stream.avail_out && s->back != EOF) {
+        *next_out++ = s->back;
+        s->stream.next_out++;
+        s->stream.avail_out--;
+        s->back = EOF;
+        s->stream.total_out++;
+        if (s->last) {
+            s->z_err = Z_STREAM_END;
+            return 1;
+        }
+    }
+
     while (s->stream.avail_out != 0) {
 
         if (s->transparent) {
@@ -476,6 +493,24 @@ int ZEXPORT gzgetc(file)
 }
 
 
+/* ===========================================================================
+      Push one byte back onto the stream.
+*/
+int ZEXPORT gzungetc(c, file)
+    int c;
+    gzFile file;
+{
+    gz_stream *s = (gz_stream*)file;
+
+    if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
+    s->back = c;
+    s->stream.total_out--;
+    s->last = (s->z_err == Z_STREAM_END);
+    if (s->z_eof) s->z_eof = 0;
+    return c;
+}
+
+
 /* ===========================================================================
       Reads bytes from the compressed file until len-1 characters are
    read, or a newline character is read and transferred to buf, or an
@@ -535,6 +570,7 @@ int ZEXPORT gzwrite (file, buf, len)
     return (int)(len - s->stream.avail_in);
 }
 
+
 /* ===========================================================================
      Converts, formats, and writes the args to the compressed file under
    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 */ ...)
     va_list va;
     int len;
 
+    buf[sizeof(buf) - 1] = 0;
     va_start(va, format);
 #ifdef NO_vsnprintf
 #  ifdef HAS_vsprintf_void
     (void)vsprintf(buf, format, va);
     va_end(va);
-    len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
-    if (len <= 0) return 0;
+    for (len = 0; len < sizeof(buf); len++)
+        if (buf[len] == 0) break;
 #  else
     len = vsprintf(buf, format, va);
     va_end(va);
-    if (len <= 0 || len >= sizeof(buf))
-        return 0;
 #  endif
 #else
 #  ifdef HAS_vsnprintf_void
     (void)vsnprintf(buf, sizeof(buf), format, va);
     va_end(va);
     len = strlen(buf);
-    if (len <= 0)
-        return 0;
 #  else
     len = vsnprintf(buf, sizeof(buf), format, va);
     va_end(va);
-    if (len <= 0 || len >= sizeof(buf))
-        return 0;
 #  endif
 #endif
-
+    if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
+        return 0;
     return gzwrite(file, buf, (unsigned)len);
 }
 #else /* not ANSI C */
@@ -591,33 +623,29 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
     char buf[Z_PRINTF_BUFSIZE];
     int len;
 
+    buf[sizeof(buf) - 1] = 0;
 #ifdef NO_snprintf
 #  ifdef HAS_sprintf_void
     sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
             a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-    len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
-    if (len <= 0) return 0;
+    for (len = 0; len < sizeof(buf); len++)
+        if (buf[len] == 0) break;
 #  else
     len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
                 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-    if (len <= 0 || len >= sizeof(buf))
-        return 0;
 #  endif
 #else
 #  ifdef HAS_snprintf_void
     snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
              a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
     len = strlen(buf);
-    if (len <= 0)
-        return 0;
 #  else
     len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
                  a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-    if (len <= 0 || len >= sizeof(buf))
-        return 0;
 #  endif
 #endif
-
+    if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
+        return 0;
     return gzwrite(file, buf, len);
 }
 #endif
@@ -762,6 +790,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
 
     if (s->transparent) {
         /* map to fseek */
+        s->back = EOF;
         s->stream.avail_in = 0;
         s->stream.next_in = s->inbuf;
         if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
@@ -782,6 +811,12 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
         s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
         if (s->outbuf == Z_NULL) return -1L;
     }
+    if (offset && s->back != EOF) {
+        s->back == EOF;
+        s->stream.total_out++;
+        offset--;
+        if (s->last) s->z_err = Z_STREAM_END;
+    }
     while (offset > 0)  {
         int size = Z_BUFSIZE;
         if (offset < Z_BUFSIZE) size = (int)offset;
@@ -805,12 +840,13 @@ int ZEXPORT gzrewind (file)
 
     s->z_err = Z_OK;
     s->z_eof = 0;
+    s->back = EOF;
     s->stream.avail_in = 0;
     s->stream.next_in = s->inbuf;
     s->crc = crc32(0L, Z_NULL, 0);
 
     if (s->startpos == 0) { /* not a compressed file */
-        rewind(s->file);
+        fseek(s->file, 0L, SEEK_SET);   /* rewind() is not always available */
         return 0;
     }
 
@@ -906,7 +942,7 @@ int ZEXPORT gzclose (file)
    errnum is set to Z_ERRNO and the application may consult errno
    to get the exact error code.
 */
-const char ZEXPORT gzerror (file, errnum)
+const char * ZEXPORT gzerror (file, errnum)
     gzFile file;
     int *errnum;
 {
@@ -932,3 +968,17 @@ const char*  ZEXPORT gzerror (file, errnum)
     strcat(s->msg, m);
     return (const char*)s->msg;
 }
+
+/* ===========================================================================
+     Clear the error and end-of-file flags, and do the same for the real file.
+*/
+void ZEXPORT gzclearerr (file)
+    gzFile file;
+{
+    gz_stream *s = (gz_stream*)file;
+
+    if (s == NULL) return;
+    if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
+    s->z_eof = 0;
+    clearerr(s->file);
+}
index fdd7d890161a112ee2804add02583f5e00f2e533..0aef86de26b2058bce2faaaa8e5a81493be9e373 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -151,7 +151,7 @@ struct inflate_state FAR *state;
             if (have == 0) { \
                 next = Z_NULL; \
                 ret = Z_BUF_ERROR; \
-                goto leave; \
+                goto inf_leave; \
             } \
         } \
     } while (0)
@@ -203,7 +203,7 @@ struct inflate_state FAR *state;
             left = state->wsize; \
             if (out(out_desc, put, left)) { \
                 ret = Z_BUF_ERROR; \
-                goto leave; \
+                goto inf_leave; \
             } \
         } \
     } while (0)
@@ -582,19 +582,19 @@ void FAR *out_desc;
                 if (out(out_desc, state->window, state->wsize - left))
                     ret = Z_BUF_ERROR;
             }
-            goto leave;
+            goto inf_leave;
 
         case BAD:
             ret = Z_DATA_ERROR;
-            goto leave;
+            goto inf_leave;
 
         default:                /* can't happen, but makes compilers happy */
             ret = Z_STREAM_ERROR;
-            goto leave;
+            goto inf_leave;
         }
 
     /* Return unused input */
-  leave:
+  inf_leave:
     strm->next_in = next;
     strm->avail_in = have;
     return ret;
index 1da27762d4883f9fe208f57340b5b713fcb5e59b..0fd158d8f71dc79e17ac61873e5cff3004f7a2ee 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -77,7 +77,7 @@
  *   and buffer address return values for the input function
  * - Check next_in and next_out for Z_NULL on entry to inflate()
  *
- * The history for versions past 1.2.0 are in ChangeLog in zlib distribution.
+ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
  */
 
 #include "zutil.h"
@@ -147,8 +147,12 @@ int stream_size;
         state->wrap = 0;
         windowBits = -windowBits;
     }
-    else
-        state->wrap = 1;
+    else {
+        state->wrap = (windowBits >> 4) + 1;
+#ifdef GUNZIP
+        windowBits &= 15;
+#endif
+    }
     if (windowBits < 8 || windowBits > 15) {
         ZFREE(strm, state);
         strm->state = Z_NULL;
@@ -403,7 +407,7 @@ unsigned out;
    if there is no input available. */
 #define PULLBYTE() \
     do { \
-        if (have == 0) goto leave; \
+        if (have == 0) goto inf_leave; \
         have--; \
         hold += (unsigned long)(*next++) << bits; \
         bits += 8; \
@@ -502,14 +506,14 @@ unsigned out;
    complete that state.  Those states are copying stored data, writing a
    literal byte, and copying a matching string.
 
-   When returning, a "goto leave" is used to update the total counters, update
-   the check value, and determine whether any progress has been made during
-   that inflate() call in order to return the proper return code.  Progress is
-   defined as a change in either strm->avail_in or strm->avail_out.  When there
-   is a window, goto leave will update the window with the last output written.
-   If a goto leave occurs in the middle of decompression and there is no window
-   currently, goto leave will create one and copy output to the window for the
-   next call of inflate().
+   When returning, a "goto inf_leave" is used to update the total counters,
+   update the check value, and determine whether any progress has been made
+   during that inflate() call in order to return the proper return code.
+   Progress is defined as a change in either strm->avail_in or strm->avail_out.
+   When there is a window, goto inf_leave will update the window with the last
+   output written.  If a goto inf_leave occurs in the middle of decompression
+   and there is no window currently, goto inf_leave will create one and copy
+   output to the window for the next call of inflate().
 
    In this implementation, the flush parameter of inflate() only affects the
    return code (per zlib.h).  inflate() always writes as much as possible to
@@ -562,16 +566,19 @@ int flush;
             }
             NEEDBITS(16);
 #ifdef GUNZIP
-            if (hold == 0x8b1f) {       /* gzip header */
+            if ((state->wrap & 2) && hold == 0x8b1f) {  /* gzip header */
                 state->check = crc32(0L, Z_NULL, 0);
                 CRC2(state->check, hold);
                 INITBITS();
                 state->mode = FLAGS;
                 break;
             }
-            state->flags = 0;                   /* expect zlib header */
+            state->flags = 0;           /* expect zlib header */
+            if (!(state->wrap & 1) ||   /* check if zlib header allowed */
+#else
+            if (
 #endif
-            if (((BITS(8) << 8) + (hold >> 8)) % 31) {
+                ((BITS(8) << 8) + (hold >> 8)) % 31) {
                 strm->msg = (char *)"incorrect header check";
                 state->mode = BAD;
                 break;
@@ -638,12 +645,12 @@ int flush;
                     next += copy;
                     state->length -= copy;
                 }
-                if (state->length) goto leave;
+                if (state->length) goto inf_leave;
             }
             state->mode = NAME;
         case NAME:
             if (state->flags & 0x0800) {
-                if (have == 0) goto leave;
+                if (have == 0) goto inf_leave;
                 copy = 0;
                 do {
                     len = (unsigned)(next[copy++]);
@@ -652,12 +659,12 @@ int flush;
                     state->check = crc32(state->check, next, copy);
                 have -= copy;
                 next += copy;
-                if (len) goto leave;
+                if (len) goto inf_leave;
             }
             state->mode = COMMENT;
         case COMMENT:
             if (state->flags & 0x1000) {
-                if (have == 0) goto leave;
+                if (have == 0) goto inf_leave;
                 copy = 0;
                 do {
                     len = (unsigned)(next[copy++]);
@@ -666,7 +673,7 @@ int flush;
                     state->check = crc32(state->check, next, copy);
                 have -= copy;
                 next += copy;
-                if (len) goto leave;
+                if (len) goto inf_leave;
             }
             state->mode = HCRC;
         case HCRC:
@@ -745,7 +752,7 @@ int flush;
             if (copy) {
                 if (copy > have) copy = have;
                 if (copy > left) copy = left;
-                if (copy == 0) goto leave;
+                if (copy == 0) goto inf_leave;
                 zmemcpy(put, next, copy);
                 have -= copy;
                 next += copy;
@@ -958,7 +965,7 @@ int flush;
             Tracevv((stderr, "inflate:         distance %u\n", state->offset));
             state->mode = MATCH;
         case MATCH:
-            if (left == 0) goto leave;
+            if (left == 0) goto inf_leave;
             copy = out - left;
             if (state->offset > copy) {         /* copy from window */
                 copy = state->offset - copy;
@@ -983,7 +990,7 @@ int flush;
             if (state->length == 0) state->mode = LEN;
             break;
         case LIT:
-            if (left == 0) goto leave;
+            if (left == 0) goto inf_leave;
             *put++ = (unsigned char)(state->length);
             left--;
             state->mode = LEN;
@@ -1015,7 +1022,7 @@ int flush;
         case LENGTH:
             if (state->wrap && state->flags) {
                 NEEDBITS(32);
-                if (hold != (state->total & 0xffffffff)) {
+                if (hold != (state->total & 0xffffffffUL)) {
                     strm->msg = (char *)"incorrect length check";
                     state->mode = BAD;
                     break;
@@ -1027,10 +1034,10 @@ int flush;
             state->mode = DONE;
         case DONE:
             ret = Z_STREAM_END;
-            goto leave;
+            goto inf_leave;
         case BAD:
             ret = Z_DATA_ERROR;
-            goto leave;
+            goto inf_leave;
         case MEM:
             return Z_MEM_ERROR;
         case SYNC:
@@ -1044,7 +1051,7 @@ int flush;
        error.  Call updatewindow() to create and/or update the window state.
        Note: a memory error from inflate() is non-recoverable.
      */
-  leave:
+  inf_leave:
     RESTORE();
     if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
         if (updatewindow(strm, out)) {
index 5bcc82bee96cf8a579d4d0fcfa206b7a8807e39c..2221b2305d34192365006b7c7c386e15276378a5 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -80,7 +80,7 @@ typedef enum {
 struct inflate_state {
     inflate_mode mode;          /* current inflate mode */
     int last;                   /* true if processing last block */
-    int wrap;                   /* true to process header and trailer */
+    int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
     int havedict;               /* true if dictionary provided */
     int flags;                  /* gzip header method and flags (0 if zlib) */
     unsigned long check;        /* protected copy of check value */
index a4e0745b9b22f1d1ef4ab9fc4ac89d11ec48caec..fda55371d92e02008b99927647b7dfed91548290 100644 (file)
@@ -9,7 +9,7 @@
 #define MAXBITS 15
 
 const char inflate_copyright[] =
-   " inflate 1.2.0.1 Copyright 1995-2003 Mark Adler ";
+   " inflate 1.2.0.2 Copyright 1995-2003 Mark Adler ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */
         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
-        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 205, 64};
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 67, 201};
     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
index 3918cbc9ba42b7eca5ec955c924f5e09597a1b9d..e75108f14b57cb57249b510d56da73d1378ef701 100644 (file)
@@ -113,7 +113,7 @@ void gz_compress(in, out)
     if (gz_compress_mmap(in, out) == Z_OK) return;
 #endif
     for (;;) {
-        len = fread(buf, 1, sizeof(buf), in);
+        len = (int)fread(buf, 1, sizeof(buf), in);
         if (ferror(in)) {
             perror("fread");
             exit(1);
@@ -230,7 +230,7 @@ void file_uncompress(file)
     char *infile, *outfile;
     FILE  *out;
     gzFile in;
-    int len = strlen(file);
+    int len = (int)strlen(file);
 
     strcpy(buf, file);
 
diff --git a/old/zlib.3 b/old/zlib.3
deleted file mode 100644 (file)
index 3a6e450..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-.TH ZLIB 3 "11 March 2002"
-.SH NAME
-zlib \- compression/decompression library
-.SH SYNOPSIS
-[see
-.I zlib.h
-for full description]
-.SH DESCRIPTION
-The
-.I zlib
-library is a general purpose data compression library.
-The code is thread safe.
-It provides in-memory compression and decompression functions,
-including integrity checks of the uncompressed data.
-This version of the library supports only one compression method (deflation)
-but other algorithms will be added later and will have the same stream interface.
-.LP
-Compression can be done in a single step if the buffers are large enough
-(for example if an input file is mmap'ed),
-or can be done by repeated calls of the compression function.
-In the latter case,
-the application must provide more input and/or consume the output
-(providing more output space) before each call.
-.LP
-The library also supports reading and writing files in
-.I gzip
-(.gz) format
-with an interface similar to that of stdio.
-.LP
-The library does not install any signal handler. The decoder checks
-the consistency of the compressed data, so the library should never
-crash even in case of corrupted input.
-.LP
-All functions of the compression library are documented in the file
-.IR zlib.h.
-The distribution source includes examples of use of the library
-the files
-.I example.c
-and
-.IR minigzip.c .
-.LP
-A Java implementation of
-.IR zlib
-is available in the Java Development Kit 1.1
-.IP
-http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
-.LP
-A Perl interface to
-.IR zlib ,
-written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
-is available at CPAN (Comprehensive Perl Archive Network) sites,
-such as:
-.IP
-ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
-.LP
-A Python interface to
-.IR zlib
-written by A.M. Kuchling <amk@magnet.com>
-is available from the Python Software Association sites, such as:
-.IP
-ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
-.SH "SEE ALSO"
-Questions about zlib should be sent to:
-.IP
-zlib@quest.jpl.nasa.gov
-or, if this fails, to the author addresses given below.
-The zlib home page is:
-.IP
-http://www.cdrom.com/pub/infozip/zlib/
-.LP
-The data format used by the zlib library is described by RFC
-(Request for Comments) 1950 to 1952 in the files: 
-.IP
-ftp://ds.internic.net/rfc/rfc1950.txt (zlib format)
-.br
-rfc1951.txt (deflate format)
-.br
-rfc1952.txt (gzip format)
-.LP
-These documents are also available in other formats from:
-.IP
-ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
-.SH AUTHORS
-Version 1.1.4
-Copyright (C) 1995-2002 Jean-loup Gailly (jloup@gzip.org)
-and Mark Adler (madler@alumni.caltech.edu).
-.LP
-This software is provided "as-is,"
-without any express or implied warranty.
-In no event will the authors be held liable for any damages
-arising from the use of this software.
-See the distribution directory with respect to requirements
-governing redistribution.
-The deflate format used by
-.I zlib
-was defined by Phil Katz.
-The deflate and
-.I zlib
-specifications were written by L. Peter Deutsch.
-Thanks to all the people who reported problems and suggested various
-improvements in
-.IR zlib ;
-who are too numerous to cite here.
-.LP
-UNIX manual page by R. P. C. Rodgers,
-U.S. National Library of Medicine (rodgers@nlm.nih.gov).
-.\" end of man page
index e4e52cea328ad89970b4b277b183af10c27a272b..5200ebd4fba310692916032829ef0637584d2f81 100644 (file)
--- a/uncompr.c
+++ b/uncompr.c
@@ -5,6 +5,7 @@
 
 /* @(#) $Id$ */
 
+#define ZLIB_INTERNAL
 #include "zlib.h"
 
 /* ===========================================================================
index 7f9973bfa45faf1f181f6af0f1c9ca06a248d0bd..da3285929f9752709c2fc7b4b64bebc264418889 100644 (file)
@@ -16,7 +16,7 @@
 # 
 
 LIB = libz.a
-SHAREDLIB = libz.so
+SHAREDLIB = zlib.dll
 VER = 1.2.0
 
 CC = gcc
@@ -32,6 +32,8 @@ LDFLAGS = $(LOC) -s
 AR = ar
 ARFLAGS = rcs
 
+RC = windres
+
 CP = cp -fp
 # If GNU install is available, replace $(CP) with install.
 INSTALL = $(CP)
@@ -43,12 +45,14 @@ exec_prefix = $(prefix)
 OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
        inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
 
+DLLDEF = win32/zlibgcc.def
+
 # to use the asm code: make OBJA=match.o
 OBJA =
 
 TEST_OBJS = example.o minigzip.o
 
-all: $(LIB) example minigzip
+all: $(LIB) $(SHAREDLIB) example minigzip
 
 test: all
        ./example
@@ -60,12 +64,18 @@ test: all
 libz.a: $(OBJS)
        $(AR) $(ARFLAGS) $@ $(OBJS)
 
+$(SHAREDLIB): $(OBJS) $(DLLDEF) zlibrc.o
+       dllwrap --driver-name $(CC) --def $(DLLDEF) -o $@ $(OBJS) zlibrc.o
+
 example: example.o $(LIB)
        $(LD) -o $@ $< $(LIB)
 
 minigzip: minigzip.o $(LIB)
        $(LD) -o $@ $< $(LIB)
 
+zlibrc.o: win32/zlib.rc
+       -$(RC) -o $@ --define GCC_WINDRES win32/zlib.rc
+
 
 # INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env .
 
@@ -87,6 +97,7 @@ clean:
        $(RM) *.o
        $(RM) *.exe
        $(RM) libz.a
+       $(RM) zlib.dll
        $(RM) foo.gz
 
 adler32.o: zlib.h zconf.h
index 97602086443d6db13fa62cf3076b619426f0aa65..4dc8819b2537f8a5c6cb1317f6a6ef29578789d0 100644 (file)
@@ -1,10 +1,13 @@
-# Makefile for (static) zlib -- Microsoft (Visual) C.\r
-# Author: Cosmin Truta, 11-Mar-2003.\r
+# Makefile for Win32 zlib.dll and the static library zlibstat.lib\r
+# -- Microsoft (Visual) C.\r
+# Author: Cosmin Truta, 11-Mar-2003\r
+#         Christian Spieler, 19-Mar-2003\r
 #\r
 # Usage: nmake -f win32/Makefile.msc\r
 \r
 CC = cl\r
 LD = cl\r
+RC = rc\r
 CFLAGS = -nologo -MD -O2\r
 LDFLAGS = -nologo\r
 \r
@@ -12,19 +15,33 @@ OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \
        inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj\r
 \r
 # targets\r
-all: zlib.lib example.exe minigzip.exe\r
+all: zlib.dll zlibstat.lib example.exe minigzip.exe exampl_s.exe minigz_s.exe\r
 \r
-zlib.lib: $(OBJS)\r
+zlibstat.lib: $(OBJS)\r
        lib -out:$@ $(OBJS)\r
 \r
+zlib.dll: $(OBJS) zlib.res win32/zlib.def\r
+       link -release -def:win32/zlib.def -dll -out:$@ $(OBJS) zlib.res\r
+\r
+zlib.lib: zlib.dll\r
+\r
 example.exe: example.obj zlib.lib\r
        $(LD) $(LDFLAGS) example.obj zlib.lib\r
 \r
 minigzip.exe: minigzip.obj zlib.lib\r
        $(LD) $(LDFLAGS) minigzip.obj zlib.lib\r
 \r
+exampl_s.exe: example.obj zlibstat.lib\r
+       $(LD) $(LDFLAGS) -o $@ example.obj zlibstat.lib\r
+\r
+minigz_s.exe: minigzip.obj zlibstat.lib\r
+       $(LD) $(LDFLAGS) -o $@ minigzip.obj zlibstat.lib\r
+\r
 .c.obj:\r
-       $(CC) -c $(CFLAGS) $*.c\r
+       $(CC) -c $(CFLAGS) $<\r
+\r
+zlib.res: win32/zlib.rc\r
+       $(RC) /l 0x409 /fo$@ /d WIN32 win32/zlib.rc\r
 \r
 adler32.obj: adler32.c zlib.h zconf.h\r
 \r
@@ -62,8 +79,14 @@ test: example.exe minigzip.exe
        example\r
        echo hello world | minigzip | minigzip -d \r
 \r
+teststat: exampl_s.exe minigz_s.exe\r
+       exampl_s\r
+       echo hello world | minigz_s | minigz_s -d \r
+\r
 # cleanup\r
 clean:\r
        del *.obj\r
+       del *.dll\r
        del *.lib\r
+       del *.exp\r
        del *.exe\r
index 3b4b05a53a81c5aec7641f8f1933bb729334cafc..d299ed51709421dd1b81e4138d7391ecb4643fe6 100644 (file)
@@ -1,5 +1,5 @@
 LIBRARY                zlib.dll
-DESCRIPTION    "zlib compression library for Windows"
+DESCRIPTION    "zlib data compression library"
 
 EXPORTS
     adler32                        @1
@@ -43,7 +43,10 @@ EXPORTS
     compress2                      @39
     gzputs                         @40
     gzgets                         @41
-; The following functions exist since zlib-1.2.0
-;   deflateBound                   @42
-;   compressBound                  @43
-; etc.
+; since zlib-1.2.0:
+    inflateCopy                    @42
+    inflateBackInit_               @43
+    inflateBack                    @44
+    inflateBackEnd                 @45
+    compressBound                  @46
+    deflateBound                   @47
diff --git a/zconf.h b/zconf.h
index f3c44301416608ed9bcdde902bea0ed0367cec67..b17d4201e2f4d9d40d1c724703a83754acdfd9b5 100644 (file)
--- a/zconf.h
+++ b/zconf.h
@@ -5,8 +5,8 @@
 
 /* @(#) $Id$ */
 
-#ifndef _ZCONF_H
-#define _ZCONF_H
+#ifndef ZCONF_H
+#define ZCONF_H
 
 /*
  * If you *really* need a unique prefix for all types and library functions,
 #  define NO_DUMMY_DECL
 #endif
 
-/* Old Borland C incorrectly complains about missing returns: */
-#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
-#  define NEED_DUMMY_RETURN
-#endif
-#if defined(__TURBOC__) && !defined(__BORLANDC__)
-#  define NEED_DUMMY_RETURN
-#endif
-
-
 /* Maximum value for memLevel in deflateInit2 */
 #ifndef MAX_MEM_LEVEL
 #  ifdef MAXSEG_64K
 #  endif
 #endif
 
-#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))
-#  define ZLIB_DLL
-#endif
-
-/* Compile with -DZLIB_DLL for Windows DLL support */
-#if defined(ZLIB_DLL)
-#  if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
-#    ifndef WINAPIV
-#      ifdef FAR
-#        undef FAR
-#      endif
-#      include <windows.h>
-#    endif
-#    ifdef WIN32
-#      define ZEXPORT  WINAPI
-#      define ZEXPORTVA  WINAPIV
-#    else
-#      define ZEXPORT  WINAPI _export
-#      define ZEXPORTVA  FAR _cdecl _export
-#    endif
+/* If building or using a Windows DLL, compile with -DZLIB_DLL.
+ * The calls to ZEXTERN functions will be more efficient this way.
+ */
+#if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
+#  ifdef FAR
+#    undef FAR
+#  endif
+   /* For zlib, the basic Win32 API declarations are sufficient.  Whenever
+    * a program that uses zlib requires the full Win32 API set, it has
+    * to include <windows.h> prior to "zlib.h".
+    */
+#  if defined(WIN32) && (!defined(WIN32_LEAN_AND_MEAN))
+#    define WIN32_LEAN_AND_MEAN
 #  endif
-#  if defined (__BORLANDC__)
-#    if (__BORLANDC__ >= 0x0500) && defined (WIN32)
-#      include <windows.h>
-#      define ZEXPORT __declspec(dllexport) WINAPI
-#      define ZEXPORTVA __declspec(dllexport) WINAPIV
+#  include <windows.h>
+#  if !defined(WIN32) || (defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
+#    if defined(ZLIB_DLL) && defined(ZLIB_INTERNAL)
+#      define ZEXPORT   WINAPI _export
+#      define ZEXPORTVA FAR _cdecl _export
 #    else
-#      if defined (_Windows) && defined (__DLL__)
-#        define ZEXPORT _export
-#        define ZEXPORTVA _export
+#      define ZEXPORT   WINAPI
+#      define ZEXPORTVA FAR _cdecl
+#    endif
+#  else
+     /* a fully Win32-compliant compiler */
+#    define ZEXPORT   WINAPI
+#    define ZEXPORTVA CDECL
+#    ifdef ZLIB_DLL
+#      ifdef ZLIB_INTERNAL
+#        define ZEXTERN extern __declspec(dllexport)
+#      else
+#        define ZEXTERN extern __declspec(dllimport)
 #      endif
+#    else
+#      define ZEXTERN extern
 #    endif
 #  endif
 #endif
 
 #if defined (__BEOS__)
-#  if defined (ZLIB_DLL)
-#    define ZEXTERN extern __declspec(dllexport)
-#  else
-#    define ZEXTERN extern __declspec(dllimport)
+#  ifdef ZLIB_DLL
+#    ifdef ZLIB_INTERNAL
+#      define ZEXPORT   __declspec(dllexport)
+#      define ZEXPORTVA __declspec(dllexport)
+#    else
+#      define ZEXPORT   __declspec(dllimport)
+#      define ZEXPORTVA __declspec(dllimport)
+#    endif
 #  endif
 #endif
 
 #endif
 
 #ifndef FAR
-#   define FAR
+#  define FAR
 #endif
 
 #if !defined(__MACTYPES__)
@@ -290,4 +289,4 @@ typedef uLong FAR uLongf;
 #   pragma map(inflate_copyright,"INCOPY")
 #endif
 
-#endif /* _ZCONF_H */
+#endif /* ZCONF_H */
index f3c44301416608ed9bcdde902bea0ed0367cec67..b17d4201e2f4d9d40d1c724703a83754acdfd9b5 100644 (file)
@@ -5,8 +5,8 @@
 
 /* @(#) $Id$ */
 
-#ifndef _ZCONF_H
-#define _ZCONF_H
+#ifndef ZCONF_H
+#define ZCONF_H
 
 /*
  * If you *really* need a unique prefix for all types and library functions,
 #  define NO_DUMMY_DECL
 #endif
 
-/* Old Borland C incorrectly complains about missing returns: */
-#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
-#  define NEED_DUMMY_RETURN
-#endif
-#if defined(__TURBOC__) && !defined(__BORLANDC__)
-#  define NEED_DUMMY_RETURN
-#endif
-
-
 /* Maximum value for memLevel in deflateInit2 */
 #ifndef MAX_MEM_LEVEL
 #  ifdef MAXSEG_64K
 #  endif
 #endif
 
-#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))
-#  define ZLIB_DLL
-#endif
-
-/* Compile with -DZLIB_DLL for Windows DLL support */
-#if defined(ZLIB_DLL)
-#  if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
-#    ifndef WINAPIV
-#      ifdef FAR
-#        undef FAR
-#      endif
-#      include <windows.h>
-#    endif
-#    ifdef WIN32
-#      define ZEXPORT  WINAPI
-#      define ZEXPORTVA  WINAPIV
-#    else
-#      define ZEXPORT  WINAPI _export
-#      define ZEXPORTVA  FAR _cdecl _export
-#    endif
+/* If building or using a Windows DLL, compile with -DZLIB_DLL.
+ * The calls to ZEXTERN functions will be more efficient this way.
+ */
+#if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
+#  ifdef FAR
+#    undef FAR
+#  endif
+   /* For zlib, the basic Win32 API declarations are sufficient.  Whenever
+    * a program that uses zlib requires the full Win32 API set, it has
+    * to include <windows.h> prior to "zlib.h".
+    */
+#  if defined(WIN32) && (!defined(WIN32_LEAN_AND_MEAN))
+#    define WIN32_LEAN_AND_MEAN
 #  endif
-#  if defined (__BORLANDC__)
-#    if (__BORLANDC__ >= 0x0500) && defined (WIN32)
-#      include <windows.h>
-#      define ZEXPORT __declspec(dllexport) WINAPI
-#      define ZEXPORTVA __declspec(dllexport) WINAPIV
+#  include <windows.h>
+#  if !defined(WIN32) || (defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
+#    if defined(ZLIB_DLL) && defined(ZLIB_INTERNAL)
+#      define ZEXPORT   WINAPI _export
+#      define ZEXPORTVA FAR _cdecl _export
 #    else
-#      if defined (_Windows) && defined (__DLL__)
-#        define ZEXPORT _export
-#        define ZEXPORTVA _export
+#      define ZEXPORT   WINAPI
+#      define ZEXPORTVA FAR _cdecl
+#    endif
+#  else
+     /* a fully Win32-compliant compiler */
+#    define ZEXPORT   WINAPI
+#    define ZEXPORTVA CDECL
+#    ifdef ZLIB_DLL
+#      ifdef ZLIB_INTERNAL
+#        define ZEXTERN extern __declspec(dllexport)
+#      else
+#        define ZEXTERN extern __declspec(dllimport)
 #      endif
+#    else
+#      define ZEXTERN extern
 #    endif
 #  endif
 #endif
 
 #if defined (__BEOS__)
-#  if defined (ZLIB_DLL)
-#    define ZEXTERN extern __declspec(dllexport)
-#  else
-#    define ZEXTERN extern __declspec(dllimport)
+#  ifdef ZLIB_DLL
+#    ifdef ZLIB_INTERNAL
+#      define ZEXPORT   __declspec(dllexport)
+#      define ZEXPORTVA __declspec(dllexport)
+#    else
+#      define ZEXPORT   __declspec(dllimport)
+#      define ZEXPORTVA __declspec(dllimport)
+#    endif
 #  endif
 #endif
 
 #endif
 
 #ifndef FAR
-#   define FAR
+#  define FAR
 #endif
 
 #if !defined(__MACTYPES__)
@@ -290,4 +289,4 @@ typedef uLong FAR uLongf;
 #   pragma map(inflate_copyright,"INCOPY")
 #endif
 
-#endif /* _ZCONF_H */
+#endif /* ZCONF_H */
diff --git a/zlib.3 b/zlib.3
new file mode 100644 (file)
index 0000000..949c87e
--- /dev/null
+++ b/zlib.3
@@ -0,0 +1,159 @@
+.TH ZLIB 3 "12 May 2003"
+.SH NAME
+zlib \- compression/decompression library
+.SH SYNOPSIS
+[see
+.I zlib.h
+for full description]
+.SH DESCRIPTION
+The
+.I zlib
+library is a general purpose data compression library.
+The code is thread safe.
+It provides in-memory compression and decompression functions,
+including integrity checks of the uncompressed data.
+This version of the library supports only one compression method (deflation)
+but other algorithms will be added later
+and will have the same stream interface.
+.LP
+Compression can be done in a single step if the buffers are large enough
+(for example if an input file is mmap'ed),
+or can be done by repeated calls of the compression function.
+In the latter case,
+the application must provide more input and/or consume the output
+(providing more output space) before each call.
+.LP
+The library also supports reading and writing files in
+.IR gzip (1)
+(.gz) format
+with an interface similar to that of stdio.
+.LP
+The library does not install any signal handler.
+The decoder checks the consistency of the compressed data,
+so the library should never crash even in case of corrupted input.
+.LP
+All functions of the compression library are documented in the file
+.IR zlib.h .
+The distribution source includes examples of use of the library
+in the files
+.I example.c
+and
+.IR minigzip.c .
+.LP
+Changes to this version are documented in the file
+.I ChangeLog
+that accompanies the source,
+and are concerned primarily with bug fixes and portability enhancements.
+.LP
+A Java implementation of
+.I zlib
+is available in the Java Development Kit 1.1:
+.IP
+http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
+.LP
+A Perl interface to
+.IR zlib ,
+written by Paul Marquess (pmqs@cpan.org),
+is available at CPAN (Comprehensive Perl Archive Network) sites,
+including:
+.IP
+http://www.cpan.org/modules/by-module/Compress/
+.LP
+A Python interface to
+.IR zlib ,
+written by A.M. Kuchling (amk@magnet.com),
+is available in Python 1.5 and later versions:
+.IP
+http://www.python.org/doc/lib/module-zlib.html
+.LP
+A
+.I zlib
+binding for
+.IR tcl (1),
+written by Andreas Kupries (a.kupries@westend.com),
+is availlable at:
+.IP
+http://www.westend.com/~kupries/doc/trf/man/man.html
+.LP
+An experimental package to read and write files in .zip format,
+written on top of
+.I zlib
+by Gilles Vollant (info@winimage.com),
+is available at:
+.IP
+http://www.winimage.com/zLibDll/unzip.html
+and also in the
+.I contrib/minizip
+directory of the main
+.I zlib
+web site.
+.SH "SEE ALSO"
+The
+.I zlib
+web site can be found at either of these locations:
+.IP
+http://www.zlib.org
+.br
+http://www.gzip.org/zlib/
+.LP
+The data format used by the zlib library is described by RFC
+(Request for Comments) 1950 to 1952 in the files: 
+.IP
+http://www.ietf.org/rfc/rfc1950.txt (concerning zlib format)
+.br
+http://www.ietf.org/rfc/rfc1951.txt (concerning deflate format)
+.br
+http://www.ietf.org/rfc/rfc1952.txt (concerning gzip format)
+.LP
+These documents are also available in other formats from:
+.IP
+ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+.LP
+Mark Nelson (markn@ieee.org) wrote an article about
+.I zlib
+for the Jan. 1997 issue of  Dr. Dobb's Journal;
+a copy of the article is available at:
+.IP
+http://dogma.net/markn/articles/zlibtool/zlibtool.htm
+.SH "REPORTING PROBLEMS"
+Before reporting a problem,
+please check the
+.I zlib
+web site to verify that you have the latest version of
+.IR zlib ;
+otherwise,
+obtain the latest version and see if the problem still exists.
+Please read the
+.I zlib
+FAQ at:
+.IP
+http://www.gzip.org/zlib/zlib_faq.html
+.LP
+before asking for help.
+Send questions and/or comments to zlib@gzip.org,
+or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
+.SH AUTHORS
+Version 1.2.0.1
+Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org)
+and Mark Adler (madler@alumni.caltech.edu).
+.LP
+This software is provided "as-is,"
+without any express or implied warranty.
+In no event will the authors be held liable for any damages
+arising from the use of this software.
+See the distribution directory with respect to requirements
+governing redistribution.
+The deflate format used by
+.I zlib
+was defined by Phil Katz.
+The deflate and
+.I zlib
+specifications were written by L. Peter Deutsch.
+Thanks to all the people who reported problems and suggested various
+improvements in
+.IR zlib ;
+who are too numerous to cite here.
+.LP
+UNIX manual page by R. P. C. Rodgers,
+U.S. National Library of Medicine (rodgers@nlm.nih.gov).
+.\" end of man page
diff --git a/zlib.h b/zlib.h
index 2d239a28ec5a1ad47f66b4a7b1d1f259a91560d2..95370d4beae24e984684d761dd6fab9d1f30f5ed 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
 /* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.2.0.1, March 17th, 2003
+  version 1.2.0.2, July 13th, 2003
 
   Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
 
@@ -28,8 +28,8 @@
   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
 */
 
-#ifndef _ZLIB_H
-#define _ZLIB_H
+#ifndef ZLIB_H
+#define ZLIB_H
 
 #include "zconf.h"
 
@@ -37,7 +37,8 @@
 extern "C" {
 #endif
 
-#define ZLIB_VERSION "1.2.0.1"
+#define ZLIB_VERSION "1.2.0.2"
+#define ZLIB_VERNUM 0x1202
 
 /* 
      The 'zlib' compression library provides in-memory compression and
@@ -334,9 +335,9 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
 ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
 /*
     inflate decompresses as much data as possible, and stops when the input
-  buffer becomes empty or the output buffer becomes full. It may some
-  introduce some output latency (reading input without producing any output)
-  except when forced to flush.
+  buffer becomes empty or the output buffer becomes full. It may introduce
+  some output latency (reading input without producing any output) except when
+  forced to flush.
 
   The detailed semantics are as follows. inflate performs one or both of the
   following actions:
@@ -586,20 +587,28 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
      The windowBits parameter is the base two logarithm of the maximum window
    size (the size of the history buffer).  It should be in the range 8..15 for
    this version of the library. The default value is 15 if inflateInit is used
-   instead. If a compressed stream with a larger window size is given as
-   input, inflate() will return with the error code Z_DATA_ERROR instead of
-   trying to allocate a larger window.
-
-     windowBits can also be -8..-15 for raw inflate.  In this case, -windowBits
-   determines the window size.  inflate() will then process raw deflate data,
+   instead. windowBits must be greater than or equal to the windowBits value
+   provided to deflateInit2() while compressing, or it must be equal to 15 if
+   deflateInit2() was not used. If a compressed stream with a larger window
+   size is given as input, inflate() will return with the error code
+   Z_DATA_ERROR instead of trying to allocate a larger window.
+
+     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+   determines the window size. inflate() will then process raw deflate data,
    not looking for a zlib or gzip header, not generating a check value, and not
-   looking for any check values for comparison at the end of the stream.  This
+   looking for any check values for comparison at the end of the stream. This
    is for use with other formats that use the deflate compressed data format
-   such as zip.  Those formats provide their own check values.  If a custom
+   such as zip.  Those formats provide their own check values. If a custom
    format is developed using the raw deflate format for compressed data, it is
    recommended that a check value such as an adler32 or a crc32 be applied to
    the uncompressed data as is done in the zlib, gzip, and zip formats.  For
-   most applications, the zlib format should be used as is.
+   most applications, the zlib format should be used as is. Note that comments
+   above on the use in deflateInit2() applies to the magnitude of windowBits.
+
+     windowBits can also be greater than 15 for optional gzip decoding. Add
+   32 to windowBits to enable zlib and gzip decoding with automatic header
+   detection, or add 16 to decode only the gzip format (the zlib format will
+   return a Z_DATA_ERROR).
 
      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    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);
    state was inconsistent.
 */
 
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
+/* Return flags indicating compile-time options.
+
+    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
+     1.0: size of uInt
+     3.2: size of uLong
+     5.4: size of voidpf (pointers)
+     7.6: size of z_off_t
+
+    Debug options:
+     8: DEBUG
+     9-11: 0 (reserved)
+
+    One-time table building (smaller code, but not thread-safe if true):
+     12: BUILDFIXED -- build static block decoding tables when needed
+     13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
+     14,15: 0 (reserved)
+
+    Library content (indicates missing functionality):
+     16: NO_DEFLATE -- gz* functions cannot compress (to avoid linking deflate
+                       code when not needed)
+     17: NO_GUNZIP -- inflate can't detect and decode gzip streams, to avoid
+                      linking crc code
+     18-19: 0 (reserved)
+
+    Operation variations (changes in library functionality):
+     20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
+     21: FASTEST -- deflate algorithm with only one, lowest compression level
+     22,23: 0 (reserved)
+
+    The sprintf variant used by gzprintf (zero is best):
+     24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
+     25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
+     26: 0 = returns value, 1 = void -- 1 means inferred string length returned
+
+    Remainder:
+     27-31: 0 (reserved)
+ */
+
 
                         /* utility functions */
 
@@ -901,10 +949,10 @@ ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
    control of the format string, as in fprintf. gzprintf returns the number of
    uncompressed bytes actually written (0 in case of error).  The number of
    uncompressed bytes written is limited to 4095. The caller should assure that
-   this limit is not exceeded. If it is exceeded, then either gzprintf() will
-   return an error (0) with nothing written, or there will be a buffer overflow
-   with unpredictable consequences. The latter is possible only if zlib was
-   compiled with insecure variants of printf, i.e. sprintf() or vsprintf()
+   this limit is not exceeded. If it is exceeded, then gzprintf() will return
+   return an error (0) with nothing written. In this case, there may also be a
+   buffer overflow with unpredictable consequences, which is possible only if
+   zlib was compiled with the insecure functions sprintf() or vsprintf()
    because the secure snprintf() or vsnprintf() functions were not available.
 */
 
@@ -936,6 +984,16 @@ ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
    or -1 in case of end of file or error.
 */
 
+ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));
+/*
+      Push one character back onto the stream to be read again later.
+   Only one character of push-back is allowed.  gzungetc() returns the
+   character pushed, or -1 on failure.  gzungetc() will fail if a
+   character has been pushed but not read yet, or if c is -1. The pushed
+   character will be discarded if the stream is repositioned with gzseek()
+   or gzrewind().
+*/
+
 ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
 /*
      Flushes all pending output into the compressed file. The parameter
@@ -1002,6 +1060,13 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
    to get the exact error code.
 */
 
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
+/*
+     Clears the error and end-of-file flags for file. This is analogous to the
+   clearerr() function in stdio. This is useful for continuing to read a gzip
+   file that is being written concurrently.
+*/
+
                         /* checksum functions */
 
 /*
@@ -1077,7 +1142,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
         ZLIB_VERSION, sizeof(z_stream))
 
 
-#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
     struct internal_state {int dummy;}; /* hack for buggy compilers */
 #endif
 
@@ -1089,4 +1154,4 @@ ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
 }
 #endif
 
-#endif /* _ZLIB_H */
+#endif /* ZLIB_H */
diff --git a/zutil.c b/zutil.c
index 4a8118dd0c7dcbf2f06adfb784e485524cf11b32..b8d11a11c28071716bec2076e1147247e84dcd31 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -7,7 +7,9 @@
 
 #include "zutil.h"
 
+#ifndef NO_DUMMY_DECL
 struct internal_state      {int dummy;}; /* for buggy compilers */
+#endif
 
 #ifndef STDC
 extern void exit OF((int));
@@ -31,6 +33,83 @@ const char * ZEXPORT zlibVersion()
     return ZLIB_VERSION;
 }
 
+uLong ZEXPORT zlibCompileFlags()
+{
+    uLong flags;
+
+    flags = 0;
+    switch (sizeof(uInt)) {
+    case 2:     break;
+    case 4:     flags += 1;     break;
+    case 8:     flags += 2;     break;
+    default:    flags += 3;
+    }
+    switch (sizeof(uLong)) {
+    case 2:     break;
+    case 4:     flags += 1 << 2;        break;
+    case 8:     flags += 2 << 2;        break;
+    default:    flags += 3 << 2;
+    }
+    switch (sizeof(voidpf)) {
+    case 2:     break;
+    case 4:     flags += 1 << 4;        break;
+    case 8:     flags += 2 << 4;        break;
+    default:    flags += 3 << 4;
+    }
+    switch (sizeof(z_off_t)) {
+    case 2:     break;
+    case 4:     flags += 1 << 6;        break;
+    case 8:     flags += 2 << 6;        break;
+    default:    flags += 3 << 6;
+    }
+#ifdef DEBUG
+    flags += 1 << 8;
+#endif
+#ifdef BUILDFIXED
+    flags += 1 << 12;
+#endif
+#ifdef DYNAMIC_CRC_TABLE
+    flags += 1 << 13;
+#endif
+#ifdef NO_DEFLATE
+    flags += 1 << 16;
+#endif
+#ifdef NO_GUNZIP
+    flags += 1 << 17;
+#endif
+#ifdef PKZIP_BUG_WORKAROUND
+    flags += 1 << 20;
+#endif
+#ifdef FASTEST
+    flags += 1 << 21;
+#endif
+#ifdef STDC
+#  ifdef NO_vsnprintf
+        flags += 1 << 25;
+#    ifdef HAS_vsprintf_void
+        flags += 1 << 26;
+#    endif
+#  else
+#    ifdef HAS_vsnprintf_void
+        flags += 1 << 26;
+#    endif
+#  endif
+#else
+        flags += 1 << 24;
+#  ifdef NO_snprintf
+        flags += 1 << 25;
+#    ifdef HAS_sprintf_void
+        flags += 1 << 26;
+#    endif
+#  else
+#    ifdef HAS_snprintf_void
+        flags += 1 << 26;
+#    endif
+#  endif
+#endif
+    return flags;
+}
+
 #ifdef DEBUG
 
 #  ifndef verbose
@@ -55,6 +134,10 @@ const char * ZEXPORT zError(err)
     return ERR_MSG(err);
 }
 
+#if defined(_WIN32_WCE)
+    /* does not exist on WCE */
+    int errno = 0;
+#endif
 
 #ifndef HAVE_MEMCPY
 
diff --git a/zutil.h b/zutil.h
index 91083ed7d694b2d4afdae0f6531ecff76c4f7a6e..0eda40c3ff01a1fcb1ffd33ac64e63aa55256534 100644 (file)
--- a/zutil.h
+++ b/zutil.h
 
 /* @(#) $Id$ */
 
-#ifndef _Z_UTIL_H
-#define _Z_UTIL_H
+#ifndef ZUTIL_H
+#define ZUTIL_H
 
+#define ZLIB_INTERNAL
 #include "zlib.h"
 
 #ifdef STDC
@@ -134,7 +135,11 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #endif
 
 #if (defined(_MSC_VER) && (_MSC_VER > 600))
-#  define fdopen(fd,type)  _fdopen(fd,type)
+#  if defined(_WIN32_WCE)
+#    define fdopen(fd,mode) NULL /* No fdopen() */
+#  else
+#    define fdopen(fd,type)  _fdopen(fd,type)
+#  endif
 #endif
 
 
@@ -157,7 +162,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #    endif
 #  endif
 #endif
-#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED)
+#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(HAVE_VSNPRINTF)
 #  ifdef MSDOS
      /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
         but for now we just assume it doesn't. */
@@ -239,4 +244,4 @@ void   zcfree  OF((voidpf opaque, voidpf ptr));
 #define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
 
-#endif /* _Z_UTIL_H */
+#endif /* ZUTIL_H */