Upgrade to zlib-1.2.0.1.
authorjbj <devnull@localhost>
Sun, 18 May 2003 18:33:39 +0000 (18:33 +0000)
committerjbj <devnull@localhost>
Sun, 18 May 2003 18:33:39 +0000 (18:33 +0000)
CVS patchset: 6860
CVS date: 2003/05/18 18:33:39

111 files changed:
zlib/ChangeLog
zlib/FAQ
zlib/INDEX
zlib/Makefile.am
zlib/README
zlib/adler32.c
zlib/aix/README [new file with mode: 0644]
zlib/aix/configure.diff [new file with mode: 0644]
zlib/aix/mkexps [new file with mode: 0644]
zlib/algorithm.txt
zlib/compress.c
zlib/contrib/README.contrib
zlib/contrib/blast/Makefile [new file with mode: 0644]
zlib/contrib/blast/README [new file with mode: 0644]
zlib/contrib/blast/blast.c [new file with mode: 0644]
zlib/contrib/blast/blast.h [new file with mode: 0644]
zlib/contrib/blast/test.pk [new file with mode: 0644]
zlib/contrib/blast/test.txt [new file with mode: 0644]
zlib/contrib/inflate86/inffas86.c [new file with mode: 0644]
zlib/contrib/inflate86/inffast.S
zlib/contrib/minizip/ChangeLogUnzip
zlib/contrib/minizip/Makefile
zlib/contrib/minizip/crypt.h [new file with mode: 0644]
zlib/contrib/minizip/ioapi.c [new file with mode: 0644]
zlib/contrib/minizip/ioapi.h [new file with mode: 0644]
zlib/contrib/minizip/iowin32.c [new file with mode: 0644]
zlib/contrib/minizip/iowin32.h [new file with mode: 0644]
zlib/contrib/minizip/miniunz.c
zlib/contrib/minizip/minizip.c
zlib/contrib/minizip/readme.txt [deleted file]
zlib/contrib/minizip/unzip.c
zlib/contrib/minizip/unzip.def [deleted file]
zlib/contrib/minizip/unzip.h
zlib/contrib/minizip/zip.c
zlib/contrib/minizip/zip.def [deleted file]
zlib/contrib/minizip/zip.h
zlib/contrib/minizip/zlibvc.dsp [deleted file]
zlib/contrib/minizip/zlibvc.dsw [deleted file]
zlib/contrib/puff/Makefile [new file with mode: 0644]
zlib/contrib/puff/README [new file with mode: 0644]
zlib/contrib/puff/puff.c [new file with mode: 0644]
zlib/contrib/puff/puff.h [new file with mode: 0644]
zlib/contrib/puff/zeros.raw [new file with mode: 0644]
zlib/contrib/testzlib/testzlib.c [new file with mode: 0644]
zlib/contrib/testzlib/testzlib.sln [new file with mode: 0644]
zlib/contrib/testzlib/testzlib.vcproj [new file with mode: 0644]
zlib/contrib/vstudio/readme.txt [new file with mode: 0644]
zlib/contrib/vstudio/vc15_16/zlib16.def [new file with mode: 0644]
zlib/contrib/vstudio/vc15_16/zlib16.mak [new file with mode: 0644]
zlib/contrib/vstudio/vc15_16/zlib16.rc [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/gvmat32.asm [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/gvmat32.obj [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/gvmat32c.c [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/inffastAsm.asm [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/inffastAsm.obj [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/miniunz.vcproj [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/minizip.vcproj [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/mkgvmt32.bat [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/zlib.rc [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/zlibstat.vcproj [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/zlibvc.def [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/zlibvc.sln [new file with mode: 0644]
zlib/contrib/vstudio/vc70_32/zlibvc.vcproj [new file with mode: 0644]
zlib/crc32.c
zlib/deflate.c
zlib/example.c
zlib/gzio.c
zlib/infback.c
zlib/inffast.c
zlib/inflate.c
zlib/inflate.h
zlib/inftrees.c
zlib/maketree.c [deleted file]
zlib/minigzip.c
zlib/msdos/Makefile.bor
zlib/msdos/Makefile.tc
zlib/old/Make_vms.com [moved from zlib/Make_vms.com with 100% similarity]
zlib/old/Makefile.riscos [moved from zlib/Makefile.riscos with 100% similarity]
zlib/old/README [new file with mode: 0644]
zlib/old/amiga/Makefile.pup [moved from zlib/amiga/Makefile.pup with 100% similarity]
zlib/old/amiga/Makefile.sas [moved from zlib/amiga/Makefile.sas with 100% similarity]
zlib/old/descrip.mms [moved from zlib/descrip.mms with 100% similarity]
zlib/old/msdos/Makefile.b32 [moved from zlib/msdos/Makefile.b32 with 100% similarity]
zlib/old/msdos/Makefile.dj2 [moved from zlib/msdos/Makefile.dj2 with 100% similarity]
zlib/old/msdos/Makefile.emx [moved from zlib/msdos/Makefile.emx with 100% similarity]
zlib/old/msdos/Makefile.msc [moved from zlib/msdos/Makefile.msc with 100% similarity]
zlib/old/msdos/Makefile.w32 [moved from zlib/msdos/Makefile.w32 with 100% similarity]
zlib/old/msdos/Makefile.wat [moved from zlib/msdos/Makefile.wat with 100% similarity]
zlib/old/msdos/zlib.def [moved from zlib/msdos/zlib.def with 100% similarity]
zlib/old/msdos/zlib.rc [moved from zlib/msdos/zlib.rc with 100% similarity]
zlib/old/nt/Makefile.emx [moved from zlib/nt/Makefile.emx with 100% similarity]
zlib/old/nt/Makefile.gcc [moved from zlib/nt/Makefile.gcc with 100% similarity]
zlib/old/nt/Makefile.nt [moved from zlib/nt/Makefile.nt with 100% similarity]
zlib/old/nt/zlib.dnt [moved from zlib/nt/zlib.dnt with 100% similarity]
zlib/old/os2/Makefile.os2 [moved from zlib/os2/Makefile.os2 with 100% similarity]
zlib/old/os2/zlib.def [moved from zlib/os2/zlib.def with 100% similarity]
zlib/old/zlib.3 [moved from zlib/zlib.3 with 96% similarity]
zlib/old/zlib.html [moved from zlib/zlib.html with 100% similarity]
zlib/trees.c
zlib/uncompr.c
zlib/ung.c [deleted file]
zlib/win32/Makefile-dll.msc [new file with mode: 0644]
zlib/win32/Makefile.bor [new file with mode: 0644]
zlib/win32/Makefile.gcc [new file with mode: 0644]
zlib/win32/Makefile.msc [new file with mode: 0644]
zlib/win32/zlib.def [moved from zlib/contrib/minizip/zlibvc.def with 66% similarity]
zlib/zconf.h
zlib/zconf.in.h [new file with mode: 0644]
zlib/zlib.h
zlib/zutil.c
zlib/zutil.h

index 57386a2..55c29c1 100644 (file)
@@ -1,5 +1,91 @@
 
-               ChangeLog file for zlib
+                ChangeLog file for zlib
+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
+    - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
+- Correct FASTEST compilation to allow level == 0
+- Clean up what gets compiled for FASTEST
+- Incorporate changes to zconf.in.h [Vollant]
+    - Refine detection of Turbo C need for dummy returns
+    - Refine ZLIB_DLL compilation
+    - 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
+  write more than 4095 bytes before compression
+- Remove unused state from inflateBackEnd()
+- Remove exit(0) from minigzip.c, example.c
+- Get rid of all those darn tabs
+- Add "check" target to Makefile.in that does the same thing as "test"
+- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
+- Update contrib/inflate86 [Anderson]
+- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
+- Add msdos and win32 directories with makefiles [Truta]
+- More additions and improvements to the FAQ
+
+Changes in 1.2.0 (9 March 2003)
+- New and improved inflate code
+    - About 20% faster
+    - Does not allocate 32K window unless and until needed
+    - Automatically detects and decompresses gzip streams
+    - Raw inflate no longer needs an extra dummy byte at end
+    - Added inflateBack functions using a callback interface--even faster
+      than inflate, useful for file utilities (gzip, zip)
+    - Added inflateCopy() function to record state for random access on
+      externally generated deflate streams (e.g. in gzip files)
+    - More readable code (I hope)
+- New and improved crc32()
+    - About 50% faster, thanks to suggestions from Rodney Brown
+- Add deflateBound() and compressBound() functions
+- Fix memory leak in deflateInit2()
+- Permit setting dictionary for raw deflate (for parallel deflate)
+- Fix const declaration for gzwrite()
+- Check for some malloc() failures in gzio.c
+- Fix bug in gzopen() on single-byte file 0x1f
+- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
+  and next buffer doesn't start with 0x8b
+- Fix uncompress() to return Z_DATA_ERROR on truncated input
+- Free memory at end of example.c
+- Remove MAX #define in trees.c (conflicted with some libraries)
+- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
+- Declare malloc() and free() in gzio.c if STDC not defined
+- Use malloc() instead of calloc() in zutil.c if int big enough
+- Define STDC for AIX
+- Add aix/ with approach for compiling shared library on AIX
+- Add HP-UX support for shared libraries in configure
+- Add OpenUNIX support for shared libraries in configure
+- Use $cc instead of gcc to build shared library
+- Make prefix directory if needed when installing
+- Correct Macintosh avoidance of typedef Byte in zconf.h
+- Correct Turbo C memory allocation when under Linux
+- Use libz.a instead of -lz in Makefile (assure use of compiled library)
+- Update configure to check for snprintf or vsnprintf functions and their
+  return value, warn during make if using an insecure function
+- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
+  is lost when library is used--resolution is to build new zconf.h
+- Documentation improvements (in zlib.h):
+    - Document raw deflate and inflate
+    - Update RFCs URL
+    - Point out that zlib and gzip formats are different
+    - Note that Z_BUF_ERROR is not fatal
+    - Document string limit for gzprintf() and possible buffer overflow
+    - Note requirement on avail_out when flushing
+    - Note permitted values of flush parameter of inflate()
+- Add some FAQs (and even answers) to the FAQ
+- Add contrib/inflate86/ for x86 faster inflate
+- Add contrib/blast/ for PKWare Data Compression Library decompression
+- Add contrib/puff/ simple inflate for deflate format description
+
+Changes in 1.1.4 (11 March 2002)
+- ZFREE was repeated on same allocation on some error conditions.
+  This creates a security problem described in
+  http://www.zlib.org/advisory-2002-03-11.txt
+- Returned incorrect error (Z_MEM_ERROR) on some invalid data
+- Avoid accesses before window for invalid distances with inflate window
+  less than 32K.
+- force windowBits > 8 to avoid a bug in the encoder for a window size
+  of 256 bytes. (A complete fix will be available in 1.1.5).
 
 Changes in 1.1.3 (9 July 1998)
 - fix "an inflate input buffer bug that shows up on rare but persistent
@@ -174,13 +260,13 @@ Changes in 1.0.6 (19 Jan 1998)
 - added Makefile.nt (thanks to Stephen Williams)
 - added the unsupported "contrib" directory:
    contrib/asm386/ by Gilles Vollant <info@winimage.com>
-       386 asm code replacing longest_match().
+        386 asm code replacing longest_match().
    contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
         A C++ I/O streams interface to the zlib gz* functions
    contrib/iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
-       Another C++ I/O streams interface
+        Another C++ I/O streams interface
    contrib/untgz/  by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
-       A very simple tar.gz file extractor using zlib
+        A very simple tar.gz file extractor using zlib
    contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
         How to use compress(), uncompress() and the gz* functions from VB.
 - pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
@@ -207,7 +293,7 @@ Changes in 1.0.6 (19 Jan 1998)
 - add NEED_DUMMY_RETURN for Borland
 - use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
 - allow compilation with CC
-- defined STDC for OS/2 (David Charlap)        
+- defined STDC for OS/2 (David Charlap)
 - limit external names to 8 chars for MVS (Thomas Lund)
 - in minigzip.c, use static buffers only for 16-bit systems
 - fix suffix check for "minigzip -d foo.gz"
index 0feb6d3..2a8247c 100644 (file)
--- a/zlib/FAQ
+++ b/zlib/FAQ
 
-               Frequently Asked Questions about zlib
+                Frequently Asked Questions about zlib
 
 
 If your question is not there, please check the zlib home page 
-http://www.cdrom.com/pub/infozip/zlib/ which may have more recent information.
+http://www.zlib.org which may have more recent information.
+The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
 
 
-1) I need a Windows DLL
-2) I need a Visual Basic interface to zlib
-3) compress() returns Z_BUF_ERROR
-4) deflate or inflate returns Z_BUF_ERROR
-5) Where is the zlib documentation (man pages, etc...)?
-6) Why don't you use GNU autoconf, libtool, etc...?
-7) There is a bug in zlib.
-8) I get "undefined reference to gzputc"
+ 1. Is zlib Y2K-compliant?
 
+    Yes. zlib doesn't handle dates.
 
+ 2. Where can I get a Windows DLL version?
 
-1) I need a Windows DLL
+    The zlib sources can be compiled without change to produce a DLL. If you
+    want a precompiled DLL, see http://www.winimage.com/zLibDll/ . Questions
+    about the zlib DLL should be sent to Gilles Vollant (info@winimage.com).
 
-  The zlib sources can be compiled without change to produce a DLL.
-  If you want a precompiled DLL, see http://www.winimage.com/zLibDll
+ 3. Where can I get a Visual Basic interface to zlib?
 
+    See
+        * http://www.winimage.com/zLibDll/cmp-z-it.zip
+        * http://www.dogma.net/markn/articles/zlibtool/zlibtool.htm
+        * contrib/visual-basic.txt in the zlib distribution
 
-2) I need a Visual Basic interface to zlib
+ 4. compress() returns Z_BUF_ERROR
 
-  See http://www.tcfb.com/dowseware/cmp-z-it.zip
-      http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
-  and contrib/visual-basic.txt
+    Make sure that before the call of compress, the length of the compressed
+    buffer is equal to the total size of the compressed buffer and not
+    zero. For Visual Basic, check that this parameter is passed by reference
+    ("as any"), not by value ("as long").
 
-3) compress() returns Z_BUF_ERROR
+ 5. deflate() or inflate() returns Z_BUF_ERROR
 
-  Make sure that before the call of compress, the length of the
-  compressed buffer is equal to the total size of the compressed buffer
-  and not zero.  For Visual Basic, check that this parameter is passed
-  by reference ("as any"), not by value ("as long").
+    Before making the call, make sure that avail_in and avail_out are not
+    zero. When setting the parameter flush equal to Z_FINISH, also make sure
+    that avail_out is big enough to allow processing all pending input.
+    Note that a Z_BUF_ERROR is not fatal--another call to deflate() or
+    inflate() can be made with more input or output space. A Z_BUF_ERROR
+    may in fact be unavoidable depending on how the functions are used, since
+    it is not possible to tell whether or not there is more output pending
+    when strm.avail_out returns with zero.
 
+ 6. Where's the zlib documentation (man pages, etc.)?
 
-4) deflate or inflate returns Z_BUF_ERROR
+    It's in zlib.h for the moment, and Francis S. Lin has converted it to a
+    web page zlib.html. Volunteers to transform this to Unix-style man pages,
+    please contact Jean-loup Gailly (jloup@gzip.org). Examples of zlib usage
+    are in the files example.c and minigzip.c.
 
-  Make sure that before the call avail_in and avail_out are not zero.
+ 7. Why don't you use GNU autoconf or libtool or ...?
 
+    Because we would like to keep zlib as a very small and simple
+    package. zlib is rather portable and doesn't need much configuration.
 
-5) Where is the zlib documentation (man pages, etc...)?
+ 8. I found a bug in zlib.
 
-  It's in zlib.h for the moment. Volunteers to transform this
-  to man pages, please contact jloup@gzip.org. Examples of zlib usage
-  are in the files example.c and minigzip.c.
+    Most of the time, such problems are due to an incorrect usage of
+    zlib. Please try to reproduce the problem with a small program and send
+    the corresponding source to us at zlib@gzip.org . Do not send
+    multi-megabyte data files without prior agreement.
 
+ 9. Why do I get "undefined reference to gzputc"?
 
-6) Why don't you use GNU autoconf, libtool, etc...?
+    If "make test" produces something like
 
-  Because we would like to keep zlib as a very small and simple package.
-  zlib is rather portable and doesn't need much configuration.
+       example.o(.text+0x154): undefined reference to `gzputc'
+      
+    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
+    /usr/X11R6/lib. Remove any old versions, then do "make install".
 
+10. I need a Delphi interface to zlib.
 
-7) There is a bug in zlib.
+    See the directories contrib/delphi and contrib/delphi2 in the zlib
+    distribution.
 
-  Most of the time, such problems are due to an incorrect usage
-  of zlib. Please try to reproduce the problem with a small
-  program and send us the corresponding source at zlib@quest.jpl.nasa.gov
-  Do not send multi-megabyte data files without prior agreement.
+11. Can zlib handle .zip archives?
 
+    See the directory contrib/minizip in the zlib distribution.
 
-8) I get "undefined reference to gzputc"
+12. Can zlib handle .Z files?
 
-  If "make test" produces something like
-     example.o(.text+0x174): 
-  check that you don't have old files libz.* in /usr/lib, /usr/local/lib
-  or /usr/X11R6/lib. Remove old versions then do "make install".
+    No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
+    the code of uncompress on your own.
 
+13. How can I make a Unix shared library?
+
+    make clean
+    ./configure -s
+    make
+
+14. How do I install a shared zlib library on Unix?
+
+    make install
+
+    However, many flavors of Unix come with a shared zlib already installed.
+    Before going to the trouble of compiling a shared version of zlib and
+    trying to install it, you may want to check if it's already there! If you
+    can #include <zlib.h>, it's there. The -lz option will probably link to it.
+
+15. I have a question about OttoPDF
+
+    We are not the authors of OttoPDF. The real author is on the OttoPDF web
+    site Joel Hainley jhainley@myndkryme.com.
+
+16. Why does gzip give an error on a file I make with compress/deflate?
+
+    The compress and deflate functions produce data in the zlib format, which
+    is different and incompatible with the gzip format. The gz* functions in
+    zlib on the other hand use the gzip format. Both the zlib and gzip
+    formats use the same compressed data format internally, but have different
+    headers and trailers around the compressed data.
+
+17. Ok, so why are there two different formats?
+
+    The gzip format was designed to retain the directory information about
+    a single file, such as the name and last modification date. The zlib
+    format on the other hand was designed for in-memory and communication
+    channel applications, and has a much more compact header and trailer and
+    uses a faster integrity check than gzip.
+
+18. Well that's nice, but how do I make a gzip file in memory?
+
+    Read RFC 1952 for the gzip header and trailer format, and roll your own
+    gzip formatted data using raw deflate and crc32().
+
+19. Is zlib thread-safe?
+
+    Yes. However any library routines that zlib uses and any application-
+    provided memory allocation routines must also be thread-safe. zlib's gz*
+    functions use stdio library routines, and most of zlib's functions use the
+    library memory allocation routines by default. zlib's Init functions allow
+    for the application to provide custom memory allocation routines.
+
+    Of course, you should only operate on any given zlib or gzip stream from a
+    single thread at a time.
+
+20. Can I use zlib in my commercial application?
+
+    Yes. Please read the license in zlib.h.
+
+21. Is zlib under the GNU license?
+
+    No. Please read the license in zlib.h.
+
+22. The license says that altered source versions must be "plainly marked". So
+    what exactly do I need to do to meet that requirement?
+
+    You need to append something the ZLIB_VERSION string in zlib.h. For
+    example, if the version of the base zlib you are altering is "1.2.3", then
+    you could change the string to "1.2.3-fred-mods-v3". You should not change
+    it to "1.2.4" or "1.2.3.1" since the zlib authors would like to reserve
+    those forms of the version for their own use.
+
+    For altered source distributions, you should also note the origin and
+    nature of the changes in zlib.h, as well as in ChangeLog and README, along
+    with the dates of the alterations. The origin should include at least your
+    name (or your company's name), and an email address to contact for help or
+    issues with the library.
+
+    Note that distributing a compiled zlib library along with zlib.h and
+    zconf.h is also a source distribution, and so you should change
+    ZLIB_VERSION and note the origin and nature of the changes in zlib.h as you
+    would for a full source distribution.
+
+23. Will zlib work on a big-endian or little-endian architecture, and can I
+    exchange compressed data between them?
+
+    Yes and yes.
+
+24. Will zlib work on a 64-bit machine?
+
+    It should. It has been tested on 64-bit machines, and has no dependence
+    on any data types being limited to 32-bits in length. If you have any
+    difficulties, please provide a complete problem report to zlib@gzip.org
+
+25. Will zlib decompress data from the PKWare Data Compression Library?
+
+    No. The PKWare DCL uses a completely different compressed data format
+    than does PKZIP and zlib. However, you can look in zlib's contrib/blast
+    directory for a possible solution to your problem.
+
+26. Can I access data randomly in a compressed stream?
+
+    No, not without some preparation. If when compressing you periodically
+    use Z_FULL_FLUSH, carefully write all the pending data at those points,
+    and keep an index of those locations, then you can start decompression
+    at those points. You have to be careful to not use Z_FULL_FLUSH too
+    often, since it can significantly degrade compression.
+
+27. Does zlib work on MVS, OS/390, CICS, etc.?
+
+    We don't know for sure. We have heard occasional reports of success on
+    these systems. If you do use it on one of these, please provide us with
+    a report, instructions, and patches that we can reference when we get
+    these questions. Thanks.
+
+28. Is there some simpler, easier to read version of inflate I can look at
+    to understand the deflate format?
+
+    First off, you should read RFC 1951. Second, yes. Look in zlib's
+    contrib/puff directory.
+
+29. Does zlib infringe on any patents?
+
+    As far as we know, no. In fact, that was originally the whole point behind
+    zlib. Look here for some more information:
+
+    http://www.gzip.org/#faq11
+
+30. Can zlib work with greater than 4 GB of data?
+
+    Yes. inflate() and deflate() will process any amount of data correctly.
+    However the strm.total_in and strm_total_out counters may be limited to
+    4 GB. The application can easily set up its own counters updated after each
+    call of inflate() or deflate() to count beyond 4 GB. compress() and
+    uncompress() may be limited to 4 GB, since they operate in a single call
+    using unsigned long lengths. gzseek() and gztell() may be limited to 4 GB
+    depending on how zlib is compiled.
+
+31. Does zlib have any security vulnerabilities?
+
+    The only one that we are aware of is potentially in gzprintf(). If zlib
+    is compiled to use sprintf() or vsprintf(), then there is no protection
+    against a buffer overflow of a 4K string space, other than the caller of
+    gzprintf() assuring that the output will not exceed 4K. On the other
+    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().
+
+    If you don't have snprintf() or vsnprintf() and would like one, you can
+    find a portable implementation here:
+
+        http://www.ijs.si/software/snprintf/
+
+    Note that you should be using the most recent version of zlib. Versions
+    1.1.3 and before were subject to a double-free vulnerability.
+
+32. Is there a Java version of zlib?
+
+    Probably what you want is to use zlib in Java. zlib is already included
+    as part of the Java SDK in the java.util.zip class. If you really want
+    a version of zlib written in the Java language, look on the zlib home
+    page for links: http://www.zlib.org/
+
+33. I get this or that compiler or source-code scanner warning when I crank it
+    up to maximally-pendantic. Can't you guys write proper code?
+
+    Many years ago, we gave up attempting to avoid warnings on every compiler
+    in the universe. It just got to be a waste of time, and some compilers
+    were downright silly. So now, we simply make sure that the code always
+    works.
+
+34. Will zlib read the (insert any ancient or arcane format here) compressed
+    data format?
+
+    Probably not. Look in the comp.compression FAQ for pointers to various
+    formats and associated software.
+
+35. How can I encrypt/decrypt zip files with zlib?
+
+    zlib doesn't support encryption. PKZIP encryption is very weak and can be
+    broken with freely available programs. To get strong encryption, use gpg
+    which already includes zlib compression.
+
+36. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
+
+    "gzip" is the gzip format, and "deflate" is the zlib format. They should
+    probably have called the second one "zlib" instead to avoid confusion
+    with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
+    correctly points to the zlib specification in RFC 1950 for the "deflate"
+    transfer encoding, there have been reports of servers and browsers that
+    incorrectly produce or expect raw deflate data per the deflate
+    specficiation in RFC 1951, most notably Microsoft. So even though the
+    "deflate" transfer encoding using the zlib format would be the more
+    efficient approach (and in fact exactly what the zlib format was designed
+    for), using the "gzip" transfer encoding is probably more reliable due to
+    an unfortunate choice of name on the part of the HTTP 1.1 authors.
+
+37. Does zlib support the new "Deflate64" format introduced by PKWare?
+
+    No. PKWare has apparently decided to keep that format proprietary, since
+    they have not documented it as they have previous compression formats.
+    In any case, the compression improvements are so modest compared to other
+    more modern approaches, that it's not worth the effort to implement.
+
+38. Can you please sign these lengthy legal documents and fax them back to us
+    so that we can use your software in our product?
+
+    No. Go away.
index 8a24576..a1463ce 100644 (file)
@@ -1,86 +1,48 @@
-ChangeLog              history of changes
-INDEX                  this file
-FAQ                    Frequently Asked Questions about zlib
-Make_vms.com           script for Vax/VMS
-Makefile               makefile for Unix (generated by configure)
-Makefile.in            makefile for Unix (template for configure)
-Makefile.riscos        makefile for RISCOS
-README                 guess what
-algorithm.txt          description of the (de)compression algorithm
-configure              configure script for Unix
-descrip.mms            makefile for Vax/VMS
-zlib.3                 mini man page for zlib (volunteers to write full
-                       man pages from zlib.h welcome. write to jloup@gzip.org)
-
-amiga/Makefile.sas     makefile for Amiga SAS/C
-amiga/Makefile.pup      makefile for Amiga powerUP SAS/C PPC
-
-msdos/Makefile.w32      makefile for Microsoft Visual C++ 32-bit
-msdos/Makefile.b32     makefile for Borland C++   32-bit
-msdos/Makefile.bor     makefile for Borland C/C++ 16-bit
-msdos/Makefile.dj2     makefile for DJGPP 2.x
-msdos/Makefile.emx     makefile for EMX 0.9c (32-bit DOS/OS2)
-msdos/Makefile.msc     makefile for Microsoft C 16-bit
-msdos/Makefile.tc      makefile for Turbo C
-msdos/Makefile.wat     makefile for Watcom C
-msdos/zlib.def         definition file for Windows DLL
-msdos/zlib.rc          definition file for Windows DLL
-
-nt/Makefile.nt         makefile for Windows NT
-nt/zlib.dnt            definition file for Windows NT DLL
-nt/Makefile.emx                makefile for EMX 0.9c/RSXNT 1.41 (Win32 Intel)
-nt/Makefile.gcc                makefile for Windows NT using GCC (mingw32)
-
-
-               zlib public header files (must be kept):
+ChangeLog       history of changes
+FAQ             Frequently Asked Questions about zlib
+INDEX           this file
+Makefile        makefile for Unix (generated by configure)
+Makefile.in     makefile for Unix (template for configure)
+README          guess what
+algorithm.txt   description of the (de)compression algorithm
+configure       configure script for Unix
+zconf.in.h      template for zconf.h (used by configure)
+
+aix/            instructions for building an AIX shared library
+msdos/         makefiles for MSDOS
+old/            makefiles for various architectures and zlib documentation
+                files that have not yet been updated for zlib 1.2.x
+win32/         makefiles for Windows
+
+                zlib public header files (must be kept):
 zconf.h
 zlib.h
 
-               private source files used to build the zlib library:
+                private source files used to build the zlib library:
 adler32.c
 compress.c
 crc32.c
+crc32.h
 deflate.c
 deflate.h
 gzio.c
-infblock.c
-infblock.h
-infcodes.c
-infcodes.h
+infback.c
 inffast.c
 inffast.h
+inffixed.h
 inflate.c
+inflate.h
 inftrees.c
 inftrees.h
-infutil.c
-infutil.h
-maketree.c
 trees.c
+trees.h
 uncompr.c
 zutil.c
 zutil.h
 
-               source files for sample programs:
+                source files for sample programs:
 example.c
 minigzip.c
 
-               unsupported contribution by third parties
-
-contrib/asm386/ by Gilles Vollant <info@winimage.com>
-       386 asm code replacing longest_match().
-
-contrib/minizip/ by Gilles Vollant <info@winimage.com>
-       Mini zip and unzip based on zlib
-        See http://www.winimage.com/zLibDll/unzip.html
-
-contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
-        A C++ I/O streams interface to the zlib gz* functions
-
-contrib/iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
-       Another C++ I/O streams interface
-
-contrib/untgz/  by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
-       A very simple tar.gz extractor using zlib
-
-contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
-        How to use compress(), uncompress() and the gz* functions from VB.
+                unsupported contribution by third parties
+See contrib/README.contrib
index a140bc1..bdc0253 100644 (file)
@@ -17,7 +17,7 @@ libz_la_SOURCES = \
        infback.c inffast.c inflate.c inftrees.c \
        trees.c uncompr.c zutil.c
 
-noinst_PROGRAMS = example minigzip ung
+noinst_PROGRAMS = example minigzip
 
 example_SOURCES = example.c
 example_LDFLAGS = -L. -lz
@@ -25,9 +25,6 @@ example_LDFLAGS = -L. -lz
 minigzip_SOURCES = minigzip.c
 minigzip_LDFLAGS = -L. -lz
 
-ung_SOURCES = ung.c
-ung_LDFLAGS = -L. -lz
-
 #BUILT_SOURCES = Doxyfile zlib.lcd
 
 zlib.lcd: Makefile.am ${libz_la_SOURCES} ${noinst_HEADERS}
index 8ff4587..8ac79a1 100644 (file)
-zlib 1.1.3 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 
-ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
-format) and rfc1952.txt (gzip format). These documents are also available in
-other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+ZLIB DATA COMPRESSION LIBRARY
+
+zlib 1.2.0.1 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)
+and rfc1952.txt (gzip format). These documents are also available in other
+formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
 
 All functions of the compression library are documented in the file zlib.h
-(volunteer to write man pages welcome, contact jloup@gzip.org). A usage
-example of the library is given in the file example.c which also tests that
-the library is working correctly. Another example is given in the file
-minigzip.c. The compression library itself is composed of all source files
-except example.c and minigzip.c.
-
-To compile all files and run the test program, follow the instructions
-given at the top of Makefile. In short "make test; make install"
-should work for most machines. For Unix: "configure; make test; make install"
-For MSDOS, use one of the special makefiles such as Makefile.msc.
-For VMS, use Make_vms.com or descrip.mms.
-
-Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov>, or to
-Gilles Vollant <info@winimage.com> for the Windows DLL version.
-The zlib home page is http://www.cdrom.com/pub/infozip/zlib/
-The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/
-Before reporting a problem, please check those sites to verify that
-you have the latest version of zlib; otherwise get the latest version and
-check whether the problem still exists or not.
-
-Mark Nelson <markn@tiny.com> wrote an article about zlib for the Jan. 1997
+(volunteer to write man pages welcome, contact jloup@gzip.org). A usage example
+of the library is given in the file example.c which also tests that the library
+is working correctly. Another example is given in the file minigzip.c. The
+compression library itself is composed of all source files except example.c and
+minigzip.c.
+
+To compile all files and run the test program, follow the instructions given at
+the top of Makefile. In short "make test; make install" should work for most
+machines. For Unix: "./configure; make test; make install" For MSDOS, use one
+of the special makefiles such as Makefile.msc. For VMS, use Make_vms.com or
+descrip.mms.
+
+Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
+<info@winimage.com> for the Windows DLL version. The zlib home page is
+http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
+please check this site to verify that you have the latest version of zlib;
+otherwise get the latest version and check whether the problem still exists or
+not.
+
+PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
+for help.
+
+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://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
-
-The changes made in version 1.1.3 are documented in the file ChangeLog.
-The main changes since 1.1.2 are:
-
-- fix "an inflate input buffer bug that shows up on rare but persistent
-  occasions" (Mark)
-- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
-- fix gzseek(..., SEEK_SET) in write mode
-- fix crc check after a gzeek (Frank Faubert)
-- fix miniunzip when the last entry in a zip file is itself a zip file
-  (J Lillge)
-- add contrib/asm586 and contrib/asm686 (Brian Raiter)
-  See http://www.muppetlabs.com/~breadbox/software/assembly.html
-- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
-- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
-- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
-- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
-- added a FAQ file
-
-plus many changes for portability.
+http://dogma.net/markn/articles/zlibtool/zlibtool.htm
+
+The changes made in version 1.2.0.1 are documented in the file ChangeLog.
 
 Unsupported third party contributions are provided in directory "contrib".
 
-A Java implementation of zlib is available in the Java Development Kit 1.1
+A Java implementation of zlib is available in the Java Development Kit
 http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
-See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details.
+See the zlib home page http://www.zlib.org for details.
 
-A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
-is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
-ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
+A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
+CPAN (Comprehensive Perl Archive Network) sites
+http://www.cpan.org/modules/by-module/Compress/
 
-A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
-is available in Python 1.5 and later versions, see
+A Python interface to zlib written by A.M. Kuchling <amk@magnet.com> is
+available in Python 1.5 and later versions, see
 http://www.python.org/doc/lib/module-zlib.html
 
-A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com>
-is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
+A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
+availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
 
-An experimental package to read and write files in .zip format,
-written on top of zlib by Gilles Vollant <info@winimage.com>, is
-available at http://www.winimage.com/zLibDll/unzip.html
-and also in the contrib/minizip directory of zlib.
+An experimental package to read and write files in .zip format, written on top
+of zlib by Gilles Vollant <info@winimage.com>, is available at
+http://www.winimage.com/zLibDll/unzip.html and also in the contrib/minizip
+directory of zlib.
 
 
 Notes for some targets:
 
 - To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
-  and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
-  The zlib DLL support was initially done by Alessandro Iacopetti and is
-  now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL
-  home page at http://www.winimage.com/zLibDll
-
-  From Visual Basic, you can call the DLL functions which do not take
-  a structure as argument: compress, uncompress and all gz* functions.
-  See contrib/visual-basic.txt for more information, or get
+  and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL The
+  zlib DLL support was initially done by Alessandro Iacopetti and is now
+  maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL home
+  page at http://www.winimage.com/zLibDll
+
+  From Visual Basic, you can call the DLL functions which do not take a
+  structure as argument: compress, uncompress and all gz* functions. See
+  contrib/visual-basic.txt for more information, or get
   http://www.tcfb.com/dowseware/cmp-z-it.zip
 
-- For 64-bit Irix, deflate.c must be compiled without any optimization.
-  With -O, one libpng test fails. The test works in 32 bit mode (with
-  the -n32 compiler flag). The compiler bug has been reported to SGI.
+- For 64-bit Irix, deflate.c must be compiled without any optimization. With
+  -O, one libpng test fails. The test works in 32 bit mode (with the -n32
+  compiler flag). The compiler bug has been reported to SGI.
 
-- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1   
-  it works when compiled with cc.
+- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
+  when compiled with cc.
 
-- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1
-  is necessary to get gzprintf working correctly. This is done by configure.
+- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
+  necessary to get gzprintf working correctly. This is done by configure.
 
-- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works
-  with other compilers. Use "make test" to check your compiler.
+- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
+  other compilers. Use "make test" to check your compiler.
 
 - gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
 
 - For Turbo C the small model is supported only with reduced performance to
   avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
 
-- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html
-  Per Harald Myrvang <perm@stud.cs.uit.no>
+- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html Per
+  Harald Myrvang <perm@stud.cs.uit.no>
 
 
 Acknowledgments:
@@ -117,7 +103,7 @@ Acknowledgments:
 
 Copyright notice:
 
- (C) 1995-1998 Jean-loup Gailly and Mark Adler
+ (C) 1995-2003 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -145,4 +131,6 @@ entirely written by Jean-loup Gailly and Mark Adler; it does not
 include third-party code.
 
 If you redistribute modified sources, we would appreciate that you include
-in the file ChangeLog history information documenting your changes.
+in the file ChangeLog history information documenting your changes. Please
+read the FAQ for more information on the distribution of modified source
+versions.
index d40185a..543d56b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2002 Mark Adler
+ * Copyright (C) 1995-2003 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
@@ -30,7 +30,7 @@ uLong ZEXPORT adler32(uLong adler, const Bytef * buf, uInt len)
     if (buf == Z_NULL) return 1L;
 
     while (len > 0) {
-        k = len < NMAX ? len : NMAX;
+        k = len < NMAX ? (int)len : NMAX;
         len -= k;
         while (k >= 16) {
             DO16(buf);
diff --git a/zlib/aix/README b/zlib/aix/README
new file mode 100644 (file)
index 0000000..235ba59
--- /dev/null
@@ -0,0 +1,9 @@
+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/zlib/aix/configure.diff b/zlib/aix/configure.diff
new file mode 100644 (file)
index 0000000..c699129
--- /dev/null
@@ -0,0 +1,57 @@
+*** ../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/zlib/aix/mkexps b/zlib/aix/mkexps
new file mode 100644 (file)
index 0000000..6c55eae
--- /dev/null
@@ -0,0 +1,37 @@
+#!/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 cdc830b..f64f7c3 100644 (file)
@@ -59,10 +59,10 @@ but saves time since there are both fewer insertions and fewer searches.
 
 2.1 Introduction
 
-The real question is, given a Huffman tree, how to decode fast.  The most
-important realization is that shorter codes are much more common than
-longer codes, so pay attention to decoding the short codes fast, and let
-the long codes take longer to decode.
+The key question is how to represent a Huffman code (or any prefix code) so
+that you can decode fast.  The most important characteristic is that shorter
+codes are much more common than longer codes, so pay attention to decoding the
+short codes fast, and let the long codes take longer to decode.
 
 inflate() sets up a first level table that covers some number of bits of
 input less than the length of longest code.  It gets that many bits from the
@@ -77,20 +77,16 @@ table took no time (and if you had infinite memory), then there would only
 be a first level table to cover all the way to the longest code.  However,
 building the table ends up taking a lot longer for more bits since short
 codes are replicated many times in such a table.  What inflate() does is
-simply to make the number of bits in the first table a variable, and set it
-for the maximum speed.
-
-inflate() sends new trees relatively often, so it is possibly set for a
-smaller first level table than an application that has only one tree for
-all the data.  For inflate, which has 286 possible codes for the
-literal/length tree, the size of the first table is nine bits.  Also the
-distance trees have 30 possible values, and the size of the first table is
-six bits.  Note that for each of those cases, the table ended up one bit
-longer than the ``average'' code length, i.e. the code length of an
-approximately flat code which would be a little more than eight bits for
-286 symbols and a little less than five bits for 30 symbols.  It would be
-interesting to see if optimizing the first level table for other
-applications gave values within a bit or two of the flat code size.
+simply to make the number of bits in the first table a variable, and  then
+to set that variable for the maximum speed.
+
+For inflate, which has 286 possible codes for the literal/length tree, the size
+of the first table is nine bits.  Also the distance trees have 30 possible
+values, and the size of the first table is six bits.  Note that for each of
+those cases, the table ended up one bit longer than the ``average'' code
+length, i.e. the code length of an approximately flat code which would be a
+little more than eight bits for 286 symbols and a little less than five bits
+for 30 symbols.
 
 
 2.2 More details on the inflate table lookup
@@ -158,7 +154,7 @@ Let's make the first table three bits long (eight entries):
 110: -> table X (gobble 3 bits)
 111: -> table Y (gobble 3 bits)
 
-Each entry is what the bits decode to and how many bits that is, i.e. how  
+Each entry is what the bits decode as and how many bits that is, i.e. how  
 many bits to gobble.  Or the entry points to another table, with the number of
 bits to gobble implicit in the size of the table.
 
index 3a78cc1..8a935dc 100644 (file)
@@ -64,3 +64,12 @@ int ZEXPORT compress (Bytef * dest, uLongf * destLen, const Bytef * source,
 {
     return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
 }
+
+/* ===========================================================================
+     If the default memLevel or windowBits for deflateInit() is changed, then
+   this function needs to be updated.
+ */
+uLong ZEXPORT compressBound (uLong sourceLen)
+{
+    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
+}
index 7ad191c..3579d43 100644 (file)
@@ -11,12 +11,18 @@ asm586/ and asm686/    by Brian Raiter <breadbox@muppetlabs.com>
         asm code for Pentium and Pentium Pro
         See http://www.muppetlabs.com/~breadbox/software/assembly.html
 
-delphi/      by Bob Dellaca <bobdl@xtra.co.nz>
+blast/      by Mark Adler <madler@alumni.caltech.edu>
+       Decompressor for output of PKWare Data Compression Library (DCL)
+
+delphi/     by Bob Dellaca <bobdl@xtra.co.nz>
        Support for Delphi
 
-delphi2/     by Davide Moretti <dave@rimini.com>
+delphi2/    by Davide Moretti <dave@rimini.com>
         Another support for C++Builder and Delphi
 
+inflate86/  by Chris Anderson <christop@charm.net>
+       Tuned x86 gcc asm code to replace inflate_fast()
+
 minizip/    by Gilles Vollant <info@winimage.com>
        Mini zip and unzip based on zlib
         See http://www.winimage.com/zLibDll/unzip.html
@@ -27,8 +33,15 @@ iostream/   by Kevin Ruland <kevin@rodin.wustl.edu>
 iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
        Another C++ I/O streams interface
 
+testzlib/    by Gilles Vollant <info@winimage.com>
+       Example of the use of zlib
+
 untgz/      by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
        A very simple tar.gz file extractor using zlib
 
 visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
         How to use compress(), uncompress() and the gz* functions from VB.
+
+vstudio/    by Gilles Vollant <info@winimage.com>
+       Building zlib DLL with Visual Studio .NET
+       Includes x86 inffast.asm for MASM
diff --git a/zlib/contrib/blast/Makefile b/zlib/contrib/blast/Makefile
new file mode 100644 (file)
index 0000000..9be80ba
--- /dev/null
@@ -0,0 +1,8 @@
+blast: blast.c blast.h
+       cc -DTEST -o blast blast.c
+
+test: blast
+       blast < test.pk | cmp - test.txt
+
+clean:
+       rm -f blast blast.o
diff --git a/zlib/contrib/blast/README b/zlib/contrib/blast/README
new file mode 100644 (file)
index 0000000..e3a60b3
--- /dev/null
@@ -0,0 +1,4 @@
+Read blast.h for purpose and usage.
+
+Mark Adler
+madler@alumni.caltech.edu
diff --git a/zlib/contrib/blast/blast.c b/zlib/contrib/blast/blast.c
new file mode 100644 (file)
index 0000000..67dab4e
--- /dev/null
@@ -0,0 +1,444 @@
+/* blast.c
+ * Copyright (C) 2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in blast.h
+ * version 1.1, 16 Feb 2003
+ *
+ * blast.c decompresses data compressed by the PKWare Compression Library.
+ * This function provides functionality similar to the explode() function of
+ * the PKWare library, hence the name "blast".
+ *
+ * This decompressor is based on the excellent format description provided by
+ * Ben Rudiak-Gould in comp.compression on August 13, 2001.  Interestingly, the
+ * example Ben provided in the post is incorrect.  The distance 110001 should
+ * instead be 111000.  When corrected, the example byte stream becomes:
+ *
+ *    00 04 82 24 25 8f 80 7f
+ *
+ * which decompresses to "AIAIAIAIAIAIA" (without the quotes).
+ */
+
+/*
+ * Change history:
+ *
+ * 1.0 12 Feb 2003     - First version
+ * 1.1 16 Feb 2003     - Fixed distance check for > 4 GB uncompressed data
+ */
+
+#include <setjmp.h>            /* for setjmp(), longjmp(), and jmp_buf */
+#include "blast.h"             /* prototype for blast() */
+
+#define local static           /* for local function definitions */
+#define MAXBITS 13             /* maximum code length */
+#define MAXWIN 4096            /* maximum window size */
+
+/* input and output state */
+struct state {
+    /* input state */
+    blast_in infun;            /* input function provided by user */
+    void *inhow;               /* opaque information passed to infun() */
+    unsigned char *in;         /* next input location */
+    unsigned left;             /* available input at in */
+    int bitbuf;                        /* bit buffer */
+    int bitcnt;                        /* number of bits in bit buffer */
+
+    /* input limit error return state for bits() and decode() */
+    jmp_buf env;
+
+    /* output state */
+    blast_out outfun;          /* output function provided by user */
+    void *outhow;              /* opaque information passed to outfun() */
+    unsigned next;             /* index of next write location in out[] */
+    int first;                 /* true to check distances (for first 4K) */
+    unsigned char out[MAXWIN]; /* output buffer and sliding window */
+};
+
+/*
+ * Return need bits from the input stream.  This always leaves less than
+ * eight bits in the buffer.  bits() works properly for need == 0.
+ *
+ * Format notes:
+ *
+ * - Bits are stored in bytes from the least significant bit to the most
+ *   significant bit.  Therefore bits are dropped from the bottom of the bit
+ *   buffer, using shift right, and new bytes are appended to the top of the
+ *   bit buffer, using shift left.
+ */
+local int bits(struct state *s, int need)
+{
+    int val;           /* bit accumulator */
+
+    /* load at least need bits into val */
+    val = s->bitbuf;
+    while (s->bitcnt < need) {
+        if (s->left == 0) {
+            s->left = s->infun(s->inhow, &(s->in));
+            if (s->left == 0) longjmp(s->env, 1);      /* out of input */
+        }
+        val |= (int)(*(s->in)++) << s->bitcnt;         /* load eight bits */
+        s->left--;
+        s->bitcnt += 8;
+    }
+
+    /* drop need bits and update buffer, always zero to seven bits left */
+    s->bitbuf = val >> need;
+    s->bitcnt -= need;
+
+    /* return need bits, zeroing the bits above that */
+    return val & ((1 << need) - 1);
+}
+
+/*
+ * Huffman code decoding tables.  count[1..MAXBITS] is the number of symbols of
+ * each length, which for a canonical code are stepped through in order.
+ * symbol[] are the symbol values in canonical order, where the number of
+ * entries is the sum of the counts in count[].  The decoding process can be
+ * seen in the function decode() below.
+ */
+struct huffman {
+    short *count;      /* number of symbols of each length */
+    short *symbol;     /* canonically ordered symbols */
+};
+
+/*
+ * Decode a code from the stream s using huffman table h.  Return the symbol or
+ * a negative value if there is an error.  If all of the lengths are zero, i.e.
+ * an empty code, or if the code is incomplete and an invalid code is received,
+ * then -9 is returned after reading MAXBITS bits.
+ *
+ * Format notes:
+ *
+ * - The codes as stored in the compressed data are bit-reversed relative to
+ *   a simple integer ordering of codes of the same lengths.  Hence below the
+ *   bits are pulled from the compressed data one at a time and used to
+ *   build the code value reversed from what is in the stream in order to
+ *   permit simple integer comparisons for decoding.
+ *
+ * - The first code for the shortest length is all ones.  Subsequent codes of
+ *   the same length are simply integer decrements of the previous code.  When
+ *   moving up a length, a one bit is appended to the code.  For a complete
+ *   code, the last code of the longest length will be all zeros.  To support
+ *   this ordering, the bits pulled during decoding are inverted to apply the
+ *   more "natural" ordering starting with all zeros and incrementing.
+ */
+local int decode(struct state *s, struct huffman *h)
+{
+    int len;           /* current number of bits in code */
+    int code;          /* len bits being decoded */
+    int first;         /* first code of length len */
+    int count;         /* number of codes of length len */
+    int index;         /* index of first code of length len in symbol table */
+    int bitbuf;                /* bits from stream */
+    int left;          /* bits left in next or left to process */
+    short *next;       /* next number of codes */
+
+    bitbuf = s->bitbuf;
+    left = s->bitcnt;
+    code = first = index = 0;
+    len = 1;
+    next = h->count + 1;
+    while (1) {
+        while (left--) {
+            code |= (bitbuf & 1) ^ 1;  /* invert code */
+            bitbuf >>= 1;
+            count = *next++;
+            if (code < first + count) {        /* if length len, return symbol */
+                s->bitbuf = bitbuf;
+                s->bitcnt = (s->bitcnt - len) & 7;
+                return h->symbol[index + (code - first)];
+            }
+            index += count;            /* else update for next length */
+            first += count;
+            first <<= 1;
+            code <<= 1;
+            len++;
+        }
+        left = (MAXBITS+1) - len;
+        if (left == 0) break;
+        if (s->left == 0) {
+            s->left = s->infun(s->inhow, &(s->in));
+            if (s->left == 0) longjmp(s->env, 1);      /* out of input */
+        }
+        bitbuf = *(s->in)++;
+        s->left--;
+        if (left > 8) left = 8;
+    }
+    return -9;                         /* ran out of codes */
+}
+
+/*
+ * Given a list of repeated code lengths rep[0..n-1], where each byte is a
+ * count (high four bits + 1) and a code length (low four bits), generate the
+ * list of code lengths.  This compaction reduces the size of the object code.
+ * Then given the list of code lengths length[0..n-1] representing a canonical
+ * Huffman code for n symbols, construct the tables required to decode those
+ * codes.  Those tables are the number of codes of each length, and the symbols
+ * sorted by length, retaining their original order within each length.  The
+ * return value is zero for a complete code set, negative for an over-
+ * subscribed code set, and positive for an incomplete code set.  The tables
+ * can be used if the return value is zero or positive, but they cannot be used
+ * if the return value is negative.  If the return value is zero, it is not
+ * possible for decode() using that table to return an error--any stream of
+ * enough bits will resolve to a symbol.  If the return value is positive, then
+ * it is possible for decode() using that table to return an error for received
+ * codes past the end of the incomplete lengths.
+ */
+local int construct(struct huffman *h, const unsigned char *rep, int n)
+{
+    int symbol;                /* current symbol when stepping through length[] */
+    int len;           /* current length when stepping through h->count[] */
+    int left;          /* number of possible codes left of current length */
+    short offs[MAXBITS+1];     /* offsets in symbol table for each length */
+    short length[256]; /* code lengths */
+
+    /* convert compact repeat counts into symbol bit length list */
+    symbol = 0;
+    do {
+        len = *rep++;
+        left = (len >> 4) + 1;
+        len &= 15;
+        do {
+            length[symbol++] = len;
+        } while (--left);
+    } while (--n);
+    n = symbol;
+
+    /* count number of codes of each length */
+    for (len = 0; len <= MAXBITS; len++)
+        h->count[len] = 0;
+    for (symbol = 0; symbol < n; symbol++)
+        (h->count[length[symbol]])++;  /* assumes lengths are within bounds */
+    if (h->count[0] == n)              /* no codes! */
+        return 0;                      /* complete, but decode() will fail */
+
+    /* check for an over-subscribed or incomplete set of lengths */
+    left = 1;                          /* one possible code of zero length */
+    for (len = 1; len <= MAXBITS; len++) {
+        left <<= 1;                    /* one more bit, double codes left */
+        left -= h->count[len];         /* deduct count from possible codes */
+        if (left < 0) return left;     /* over-subscribed--return negative */
+    }                                  /* left > 0 means incomplete */
+
+    /* generate offsets into symbol table for each length for sorting */
+    offs[1] = 0;
+    for (len = 1; len < MAXBITS; len++)
+        offs[len + 1] = offs[len] + h->count[len];
+
+    /*
+     * put symbols in table sorted by length, by symbol order within each
+     * length
+     */
+    for (symbol = 0; symbol < n; symbol++)
+        if (length[symbol] != 0)
+            h->symbol[offs[length[symbol]]++] = symbol;
+
+    /* return zero for complete set, positive for incomplete set */
+    return left;
+}
+
+/*
+ * Decode PKWare Compression Library stream.
+ *
+ * Format notes:
+ *
+ * - First byte is 0 if literals are uncoded or 1 if they are coded.  Second
+ *   byte is 4, 5, or 6 for the number of extra bits in the distance code.
+ *   This is the base-2 logarithm of the dictionary size minus six.
+ *
+ * - Compressed data is a combination of literals and length/distance pairs
+ *   terminated by an end code.  Literals are either Huffman coded or
+ *   uncoded bytes.  A length/distance pair is a coded length followed by a
+ *   coded distance to represent a string that occurs earlier in the
+ *   uncompressed data that occurs again at the current location.
+ *
+ * - A bit preceding a literal or length/distance pair indicates which comes
+ *   next, 0 for literals, 1 for length/distance.
+ *
+ * - If literals are uncoded, then the next eight bits are the literal, in the
+ *   normal bit order in th stream, i.e. no bit-reversal is needed. Similarly,
+ *   no bit reversal is needed for either the length extra bits or the distance
+ *   extra bits.
+ *
+ * - Literal bytes are simply written to the output.  A length/distance pair is
+ *   an instruction to copy previously uncompressed bytes to the output.  The
+ *   copy is from distance bytes back in the output stream, copying for length
+ *   bytes.
+ *
+ * - Distances pointing before the beginning of the output data are not
+ *   permitted.
+ *
+ * - Overlapped copies, where the length is greater than the distance, are
+ *   allowed and common.  For example, a distance of one and a length of 518
+ *   simply copies the last byte 518 times.  A distance of four and a length of
+ *   twelve copies the last four bytes three times.  A simple forward copy
+ *   ignoring whether the length is greater than the distance or not implements
+ *   this correctly.
+ */
+local int decomp(struct state *s)
+{
+    int lit;           /* true if literals are coded */
+    int dict;          /* log2(dictionary size) - 6 */
+    int symbol;                /* decoded symbol, extra bits for distance */
+    int len;           /* length for copy */
+    int dist;          /* distance for copy */
+    int copy;          /* copy counter */
+    unsigned char *from, *to;  /* copy pointers */
+    static int virgin = 1;                             /* build tables once */
+    static short litcnt[MAXBITS+1], litsym[256];       /* litcode memory */
+    static short lencnt[MAXBITS+1], lensym[16];                /* lencode memory */
+    static short distcnt[MAXBITS+1], distsym[64];      /* distcode memory */
+    static struct huffman litcode = {litcnt, litsym};  /* length code */
+    static struct huffman lencode = {lencnt, lensym};  /* length code */
+    static struct huffman distcode = {distcnt, distsym};/* distance code */
+        /* bit lengths of literal codes */
+    static const unsigned char litlen[] = {
+       11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
+       9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
+       7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
+       8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
+       44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
+       44, 173};
+        /* bit lengths of length codes 0..15 */
+    static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
+        /* bit lengths of distance codes 0..63 */
+    static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
+    static const short base[16] = {    /* base for length codes */
+        3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
+    static const char extra[16] = {    /* extra bits for length codes */
+        0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
+
+    /* set up decoding tables (once--might not be thread-safe) */
+    if (virgin) {
+        construct(&litcode, litlen, sizeof(litlen));
+        construct(&lencode, lenlen, sizeof(lenlen));
+        construct(&distcode, distlen, sizeof(distlen));
+        virgin = 0;
+    }
+
+    /* read header */
+    lit = bits(s, 8);
+    if (lit > 1) return -1;
+    dict = bits(s, 8);
+    if (dict < 4 || dict > 6) return -2;
+
+    /* decode literals and length/distance pairs */
+    do {
+        if (bits(s, 1)) {
+            /* get length */
+            symbol = decode(s, &lencode);
+            len = base[symbol] + bits(s, extra[symbol]);
+            if (len == 519) break;             /* end code */
+
+            /* get distance */
+            symbol = len == 2 ? 2 : dict;
+            dist = decode(s, &distcode) << symbol;
+            dist += bits(s, symbol);
+            dist++;
+            if (s->first && dist > s->next)
+                return -3;             /* distance too far back */
+
+            /* copy length bytes from distance bytes back */
+            do {
+                to = s->out + s->next;
+                from = to - dist;
+                copy = MAXWIN;
+                if (s->next < dist) {
+                    from += copy;
+                    copy = dist;
+                }
+                copy -= s->next;
+                if (copy > len) copy = len;
+                len -= copy;
+                s->next += copy;
+                do {
+                    *to++ = *from++;
+                } while (--copy);
+                if (s->next == MAXWIN) {
+                    if (s->outfun(s->outhow, s->out, s->next)) return 1;
+                    s->next = 0;
+                    s->first = 0;
+                }
+            } while (len != 0);
+        }
+        else {
+            /* get literal and write it */
+            symbol = lit ? decode(s, &litcode) : bits(s, 8);
+            s->out[s->next++] = symbol;
+            if (s->next == MAXWIN) {
+                if (s->outfun(s->outhow, s->out, s->next)) return 1;
+                s->next = 0;
+                s->first = 0;
+            }
+        }
+    } while (1);
+    return 0;
+}
+
+/* See comments in blast.h */
+int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
+{
+    struct state s;            /* input/output state */
+    int err;                   /* return value */
+
+    /* initialize input state */
+    s.infun = infun;
+    s.inhow = inhow;
+    s.left = 0;
+    s.bitbuf = 0;
+    s.bitcnt = 0;
+
+    /* initialize output state */
+    s.outfun = outfun;
+    s.outhow = outhow;
+    s.next = 0;
+    s.first = 1;
+
+    /* return if bits() or decode() tries to read past available input */
+    if (setjmp(s.env) != 0)            /* if came back here via longjmp(), */
+        err = 2;                       /*  then skip decomp(), return error */
+    else
+        err = decomp(&s);              /* decompress */
+
+    /* write any leftover output and update the error code if needed */
+    if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
+        err = 1;
+    return err;
+}
+
+#ifdef TEST
+/* Example of how to use blast() */
+#include <stdio.h>
+#include <stdlib.h>
+
+#define CHUNK 16384
+
+local unsigned inf(void *how, unsigned char **buf)
+{
+    static unsigned char hold[CHUNK];
+
+    *buf = hold;
+    return fread(hold, 1, CHUNK, (FILE *)how);
+}
+
+local int outf(void *how, unsigned char *buf, unsigned len)
+{
+    return fwrite(buf, 1, len, (FILE *)how) != len;
+}
+
+/* Decompress a PKWare Compression Library stream from stdin to stdout */
+int main(void)
+{
+    int ret, n;
+
+    /* decompress to stdout */
+    ret = blast(inf, stdin, outf, stdout);
+    if (ret != 0) fprintf(stderr, "blast error: %d\n", ret);
+
+    /* see if there are any leftover bytes */
+    n = 0;
+    while (getchar() != EOF) n++;
+    if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n);
+
+    /* return blast() error code */
+    return ret;
+}
+#endif
diff --git a/zlib/contrib/blast/blast.h b/zlib/contrib/blast/blast.h
new file mode 100644 (file)
index 0000000..2417837
--- /dev/null
@@ -0,0 +1,71 @@
+/* blast.h -- interface for blast.c
+  Copyright (C) 2003 Mark Adler
+  version 1.1, 16 Feb 2003
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the author 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.
+
+  Mark Adler   madler@alumni.caltech.edu
+ */
+
+
+/*
+ * blast() decompresses the PKWare Data Compression Library (DCL) compressed
+ * format.  It provides the same functionality as the explode() function in
+ * that library.  (Note: PKWare overused the "implode" verb, and the format
+ * used by their library implode() function is completely different and
+ * incompatible with the implode compression method supported by PKZIP.)
+ */
+
+
+typedef unsigned (*blast_in)(void *how, unsigned char **buf);
+typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
+/* Definitions for input/output functions passed to blast().  See below for
+ * what the provided functions need to do.
+ */
+
+
+int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
+/* Decompress input to output using the provided infun() and outfun() calls.
+ * On success, the return value of blast() is zero.  If there is an error in
+ * the source data, i.e. it is not in the proper format, then a negative value
+ * is returned.  If there is not enough input available or there is not enough
+ * output space, then a positive error is returned.
+ *
+ * The input function is invoked: len = infun(how, &buf), where buf is set by
+ * infun() to point to the input buffer, and infun() returns the number of
+ * available bytes there.  If infun() returns zero, then blast() returns with
+ * an input error.  (blast() only asks for input if it needs it.)  inhow is for
+ * use by the application to pass an input descriptor to infun(), if desired.
+ *
+ * The output function is invoked: err = outfun(how, buf, len), where the bytes
+ * to be written are buf[0..len-1].  If err is not zero, then blast() returns
+ * with an output error.  outfun() is always called with len <= 4096.  outhow
+ * is for use by the application to pass an output descriptor to outfun(), if
+ * desired.
+ *
+ * The return codes are:
+ *
+ *   2:  ran out of input before completing decompression
+ *   1:  output error before completing decompression
+ *   0:  successful decompression
+ *  -1:  literal flag not zero or one
+ *  -2:  dictionary size not in 4..6
+ *  -3:  distance is too far back
+ *
+ * At the bottom of blast.c is an example program that uses blast() that can be
+ * compiled to produce a command-line decompression filter by defining TEST.
+ */
diff --git a/zlib/contrib/blast/test.pk b/zlib/contrib/blast/test.pk
new file mode 100644 (file)
index 0000000..be10b2b
Binary files /dev/null and b/zlib/contrib/blast/test.pk differ
diff --git a/zlib/contrib/blast/test.txt b/zlib/contrib/blast/test.txt
new file mode 100644 (file)
index 0000000..bfdf1c5
--- /dev/null
@@ -0,0 +1 @@
+AIAIAIAIAIAIA
\ No newline at end of file
diff --git a/zlib/contrib/inflate86/inffas86.c b/zlib/contrib/inflate86/inffas86.c
new file mode 100644 (file)
index 0000000..4534693
--- /dev/null
@@ -0,0 +1,783 @@
+/* inffas86.c is a hand tuned assembler version of
+ *
+ * inffast.c -- fast decoding
+ * Copyright (C) 1995-2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Copyright (C) 2003 Chris Anderson <christop@charm.net>
+ * Please use the copyright conditions above.
+ *
+ * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
+ * the gcc -S output of zlib-1.2.0/inffast.c.  Zlib-1.2.0 is in beta release at
+ * the moment.  I have successfully compiled and tested this code with gcc2.96,
+ * gcc3.2, icc5.0, msvc6.0.  It is very close to the speed of inffast.S
+ * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
+ * enabled.  I will attempt to merge the MMX code into this version.  Newer
+ * versions of this and inffast.S can be found at
+ * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+/* Mark Adler's comments from inffast.c: */
+
+/*
+   Decode literal, length, and distance codes and write out the resulting
+   literal and match bytes until either not enough input or output is
+   available, an end-of-block is encountered, or a data error is encountered.
+   When large enough input and output buffers are supplied to inflate(), for
+   example, a 16K input buffer and a 64K output buffer, more than 95% of the
+   inflate execution time is spent in this routine.
+
+   Entry assumptions:
+
+        state->mode == LEN
+        strm->avail_in >= 6
+        strm->avail_out >= 258
+        start >= strm->avail_out
+        state->bits < 8
+
+   On return, state->mode is one of:
+
+        LEN -- ran out of enough output space or enough available input
+        TYPE -- reached end of block code, inflate() to interpret next block
+        BAD -- error in block data
+
+   Notes:
+
+    - The maximum input bits used by a length/distance pair is 15 bits for the
+      length code, 5 bits for the length extra, 15 bits for the distance code,
+      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
+      Therefore if strm->avail_in >= 6, then there is enough input to avoid
+      checking for available input while decoding.
+
+    - The maximum bytes that a single length/distance pair can output is 258
+      bytes, which is the maximum length that can be coded.  inflate_fast()
+      requires strm->avail_out >= 258 for each loop to avoid checking for
+      output space.
+ */
+void inflate_fast(strm, start)
+z_streamp strm;
+unsigned start;         /* inflate()'s starting value for strm->avail_out */
+{
+    struct inflate_state FAR *state;
+    struct inffast_ar {
+      void *esp;                  /* esp save */
+      unsigned char FAR *in;      /* local strm->next_in */
+      unsigned char FAR *last;    /* while in < last, enough input available */
+      unsigned char FAR *out;     /* local strm->next_out */
+      unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
+      unsigned char FAR *end;     /* while out < end, enough space available */
+      unsigned wsize;             /* window size or zero if not using window */
+      unsigned write;             /* window write index */
+      unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
+      unsigned long hold;         /* local strm->hold */
+      unsigned bits;              /* local strm->bits */
+      code const FAR *lcode;      /* local strm->lencode */
+      code const FAR *dcode;      /* local strm->distcode */
+      unsigned lmask;             /* mask for first level of length codes */
+      unsigned dmask;             /* mask for first level of distance codes */
+      unsigned len;               /* match length, unused bytes */
+      unsigned dist;              /* match distance */
+      unsigned status;            /* this is set when state changes */
+    } ar;
+
+    /* copy state to local variables */
+    state = (struct inflate_state FAR *)strm->state;
+    ar.in = strm->next_in;
+    ar.last = ar.in + (strm->avail_in - 5);
+    ar.out = strm->next_out;
+    ar.beg = ar.out - (start - strm->avail_out);
+    ar.end = ar.out + (strm->avail_out - 257);
+    ar.wsize = state->wsize;
+    ar.write = state->write;
+    ar.window = state->window;
+    ar.hold = state->hold;
+    ar.bits = state->bits;
+    ar.lcode = state->lencode;
+    ar.dcode = state->distcode;
+    ar.lmask = (1U << state->lenbits) - 1;
+    ar.dmask = (1U << state->distbits) - 1;
+
+    /* decode literals and length/distances until end-of-block or not enough
+       input data or output space */
+
+    /* align in on 2 byte boundary */
+    if (((unsigned long)(void *)ar.in & 0x1) != 0) {
+        ar.hold += (unsigned long)*ar.in++ << ar.bits;
+        ar.bits += 8;
+    }
+
+#if defined( __GNUC__ ) || defined( __ICC )
+    __asm__ __volatile__ (
+"        leal    %0, %%eax\n"
+"        pushf\n"
+"        pushl   %%ebp\n"
+"        movl    %%esp, (%%eax)\n"
+"        movl    %%eax, %%esp\n"
+"        movl    4(%%esp), %%esi\n"       /* esi = in */
+"        movl    12(%%esp), %%edi\n"      /* edi = out */
+"        movl    36(%%esp), %%edx\n"      /* edx = hold */
+"        movl    40(%%esp), %%ebx\n"      /* ebx = bits */
+"        movl    44(%%esp), %%ebp\n"      /* ebp = lcode */
+
+"        cld\n"
+"        jmp     .L_do_loop\n"
+
+".L_while_test:\n"
+"        cmpl    %%edi, 20(%%esp)\n"
+"        jbe     .L_break_loop\n"
+"        cmpl    %%esi, 8(%%esp)\n"
+"        jbe     .L_break_loop\n"
+
+".L_do_loop:\n"
+"        cmpb    $15, %%bl\n"
+"        ja      .L_get_length_code\n"    /* if (15 < bits) */
+
+"        xorl    %%eax, %%eax\n"
+"        lodsw\n"                         /* al = *(ushort *)in++ */
+"        movb    %%bl, %%cl\n"            /* cl = bits, needs it for shifting */
+"        addb    $16, %%bl\n"             /* bits += 16 */
+"        shll    %%cl, %%eax\n"
+"        orl     %%eax, %%edx\n"        /* hold |= *((ushort *)in)++ << bits */
+
+".L_get_length_code:\n"
+"        movl    52(%%esp), %%eax\n"      /* eax = lmask */
+"        andl    %%edx, %%eax\n"          /* eax &= hold */
+"        movl    (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */
+
+".L_dolen:\n"
+"        movb    %%ah, %%cl\n"            /* cl = this.bits */
+"        subb    %%ah, %%bl\n"            /* bits -= this.bits */
+"        shrl    %%cl, %%edx\n"           /* hold >>= this.bits */
+
+"        testb   %%al, %%al\n"
+"        jnz     .L_test_for_length_base\n" /* if (op != 0) 45.7% */
+
+"        shrl    $16, %%eax\n"            /* output this.val char */
+"        stosb\n"
+"        jmp     .L_while_test\n"
+
+".L_test_for_length_base:\n"
+"        movl    %%eax, %%ecx\n"          /* len = this */
+"        shrl    $16, %%ecx\n"            /* len = this.val */
+"        movl    %%ecx, 60(%%esp)\n"      /* len = this */
+"        movb    %%al, %%cl\n"
+
+"        testb   $16, %%al\n"
+"        jz      .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */
+"        andb    $15, %%cl\n"             /* op &= 15 */
+"        jz      .L_decode_distance\n"    /* if (!op) */
+"        cmpb    %%cl, %%bl\n"
+"        jae     .L_add_bits_to_len\n"    /* if (op <= bits) */
+
+"        movb    %%cl, %%ch\n"            /* stash op in ch, freeing cl */
+"        xorl    %%eax, %%eax\n"
+"        lodsw\n"                         /* al = *(ushort *)in++ */
+"        movb    %%bl, %%cl\n"            /* cl = bits, needs it for shifting */
+"        addb    $16, %%bl\n"             /* bits += 16 */
+"        shll    %%cl, %%eax\n"
+"        orl     %%eax, %%edx\n"         /* hold |= *((ushort *)in)++ << bits */
+"        movb    %%ch, %%cl\n"            /* move op back to ecx */
+
+".L_add_bits_to_len:\n"
+"        movl    $1, %%eax\n"
+"        shll    %%cl, %%eax\n"
+"        decl    %%eax\n"
+"        subb    %%cl, %%bl\n"
+"        andl    %%edx, %%eax\n"          /* eax &= hold */
+"        shrl    %%cl, %%edx\n"
+"        addl    %%eax, 60(%%esp)\n"      /* len += hold & mask[op] */
+
+".L_decode_distance:\n"
+"        cmpb    $15, %%bl\n"
+"        ja      .L_get_distance_code\n"  /* if (15 < bits) */
+
+"        xorl    %%eax, %%eax\n"
+"        lodsw\n"                         /* al = *(ushort *)in++ */
+"        movb    %%bl, %%cl\n"            /* cl = bits, needs it for shifting */
+"        addb    $16, %%bl\n"             /* bits += 16 */
+"        shll    %%cl, %%eax\n"
+"        orl     %%eax, %%edx\n"         /* hold |= *((ushort *)in)++ << bits */
+
+".L_get_distance_code:\n"
+"        movl    56(%%esp), %%eax\n"      /* eax = dmask */
+"        movl    48(%%esp), %%ecx\n"      /* ecx = dcode */
+"        andl    %%edx, %%eax\n"          /* eax &= hold */
+"        movl    (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */
+
+".L_dodist:\n"
+"        movl    %%eax, %%ebp\n"          /* dist = this */
+"        shrl    $16, %%ebp\n"            /* dist = this.val */
+"        movb    %%ah, %%cl\n"
+"        subb    %%ah, %%bl\n"            /* bits -= this.bits */
+"        shrl    %%cl, %%edx\n"           /* hold >>= this.bits */
+"        movb    %%al, %%cl\n"            /* cl = this.op */
+
+"        testb   $16, %%al\n"             /* if ((op & 16) == 0) */
+"        jz      .L_test_for_second_level_dist\n"
+"        andb    $15, %%cl\n"             /* op &= 15 */
+"        jz      .L_check_dist_one\n"
+"        cmpb    %%cl, %%bl\n"
+"        jae     .L_add_bits_to_dist\n"   /* if (op <= bits) 97.6% */
+
+"        movb    %%cl, %%ch\n"            /* stash op in ch, freeing cl */
+"        xorl    %%eax, %%eax\n"
+"        lodsw\n"                         /* al = *(ushort *)in++ */
+"        movb    %%bl, %%cl\n"            /* cl = bits, needs it for shifting */
+"        addb    $16, %%bl\n"             /* bits += 16 */
+"        shll    %%cl, %%eax\n"
+"        orl     %%eax, %%edx\n"        /* hold |= *((ushort *)in)++ << bits */
+"        movb    %%ch, %%cl\n"            /* move op back to ecx */
+
+".L_add_bits_to_dist:\n"
+"        movl    $1, %%eax\n"
+"        shll    %%cl, %%eax\n"
+"        decl    %%eax\n"                 /* (1 << op) - 1 */
+"        subb    %%cl, %%bl\n"
+"        andl    %%edx, %%eax\n"          /* eax &= hold */
+"        shrl    %%cl, %%edx\n"
+"        addl    %%eax, %%ebp\n"          /* dist += hold & ((1 << op) - 1) */
+
+".L_check_window:\n"
+"        movl    %%esi, 4(%%esp)\n"       /* save in so from can use it's reg */
+"        movl    %%edi, %%eax\n"
+"        subl    16(%%esp), %%eax\n"      /* nbytes = out - beg */
+
+"        cmpl    %%ebp, %%eax\n"
+"        jb      .L_clip_window\n"        /* if (dist > nbytes) 4.2% */
+
+"        movl    60(%%esp), %%ecx\n"
+"        movl    %%edi, %%esi\n"
+"        subl    %%ebp, %%esi\n"          /* from = out - dist */
+
+"        subl    $3, %%ecx\n"             /* copy from to out */
+"        movb    (%%esi), %%al\n"
+"        movb    %%al, (%%edi)\n"
+"        movb    1(%%esi), %%al\n"
+"        movb    2(%%esi), %%ah\n"
+"        addl    $3, %%esi\n"
+"        movb    %%al, 1(%%edi)\n"
+"        movb    %%ah, 2(%%edi)\n"
+"        addl    $3, %%edi\n"
+"        rep     movsb\n"
+
+"        movl    4(%%esp), %%esi\n"      /* move in back to %esi, toss from */
+"        movl    44(%%esp), %%ebp\n"     /* ebp = lcode */
+"        jmp     .L_while_test\n"
+
+".L_check_dist_one:\n"
+"        cmpl    $1, %%ebp\n"            /* if dist 1, is a memset */
+"        jne     .L_check_window\n"
+"        cmpl    %%edi, 16(%%esp)\n"
+"        je      .L_check_window\n"
+
+"        decl    %%edi\n"
+"        movl    60(%%esp), %%ecx\n"
+"        movb    (%%edi), %%al\n"
+"        subl    $3, %%ecx\n"
+
+"        movb    %%al, 1(%%edi)\n"       /* memset out with from[-1] */
+"        movb    %%al, 2(%%edi)\n"
+"        movb    %%al, 3(%%edi)\n"
+"        addl    $4, %%edi\n"
+"        rep     stosb\n"
+"        movl    44(%%esp), %%ebp\n"      /* ebp = lcode */
+"        jmp     .L_while_test\n"
+
+".L_test_for_second_level_length:\n"
+"        testb   $64, %%al\n"
+"        jnz     .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */
+
+"        movl    $1, %%eax\n"
+"        shll    %%cl, %%eax\n"
+"        decl    %%eax\n"
+"        andl    %%edx, %%eax\n"         /* eax &= hold */
+"        addl    60(%%esp), %%eax\n"     /* eax += this.val */
+"        movl    (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/
+"        jmp     .L_dolen\n"
+
+".L_test_for_second_level_dist:\n"
+"        testb   $64, %%al\n"
+"        jnz     .L_invalid_distance_code\n" /* if ((op & 64) != 0) */
+
+"        movl    $1, %%eax\n"
+"        shll    %%cl, %%eax\n"
+"        decl    %%eax\n"
+"        andl    %%edx, %%eax\n"         /* eax &= hold */
+"        addl    %%ebp, %%eax\n"         /* eax += this.val */
+"        movl    48(%%esp), %%ecx\n"     /* ecx = dcode */
+"        movl    (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/
+"        jmp     .L_dodist\n"
+
+".L_clip_window:\n"
+"        movl    %%eax, %%ecx\n"
+"        movl    24(%%esp), %%eax\n"     /* prepare for dist compare */
+"        negl    %%ecx\n"                /* nbytes = -nbytes */
+"        movl    32(%%esp), %%esi\n"     /* from = window */
+
+"        cmpl    %%ebp, %%eax\n"
+"        jb      .L_invalid_distance_too_far\n" /* if (dist > wsize) */
+
+"        addl    %%ebp, %%ecx\n"         /* nbytes = dist - nbytes */
+"        cmpl    $0, 28(%%esp)\n"
+"        jne     .L_wrap_around_window\n" /* if (write != 0) */
+
+"        subl    %%ecx, %%eax\n"
+"        addl    %%eax, %%esi\n"         /* from += wsize - nbytes */
+
+"        movl    60(%%esp), %%eax\n"
+"        cmpl    %%ecx, %%eax\n"
+"        jbe     .L_do_copy1\n"          /* if (nbytes >= len) */
+
+"        subl    %%ecx, %%eax\n"         /* len -= nbytes */
+"        rep     movsb\n"
+"        movl    %%edi, %%esi\n"
+"        subl    %%ebp, %%esi\n"         /* from = out - dist */
+"        jmp     .L_do_copy1\n"
+
+"        cmpl    %%ecx, %%eax\n"
+"        jbe     .L_do_copy1\n"          /* if (nbytes >= len) */
+
+"        subl    %%ecx, %%eax\n"         /* len -= nbytes */
+"        rep     movsb\n"
+"        movl    %%edi, %%esi\n"
+"        subl    %%ebp, %%esi\n"         /* from = out - dist */
+"        jmp     .L_do_copy1\n"
+
+".L_wrap_around_window:\n"
+"        movl    28(%%esp), %%eax\n"
+"        cmpl    %%eax, %%ecx\n"
+"        jbe     .L_contiguous_in_window\n" /* if (write >= nbytes) */
+
+"        addl    24(%%esp), %%esi\n"
+"        addl    %%eax, %%esi\n"
+"        subl    %%ecx, %%esi\n"         /* from += wsize + write - nbytes */
+"        subl    %%eax, %%ecx\n"         /* nbytes -= write */
+
+"        movl    60(%%esp), %%eax\n"
+"        cmpl    %%ecx, %%eax\n"
+"        jbe     .L_do_copy1\n"          /* if (nbytes >= len) */
+
+"        subl    %%ecx, %%eax\n"         /* len -= nbytes */
+"        rep     movsb\n"
+"        movl    32(%%esp), %%esi\n"     /* from = window */
+"        movl    28(%%esp), %%ecx\n"     /* nbytes = write */
+"        cmpl    %%ecx, %%eax\n"
+"        jbe     .L_do_copy1\n"          /* if (nbytes >= len) */
+
+"        subl    %%ecx, %%eax\n"         /* len -= nbytes */
+"        rep     movsb\n"
+"        movl    %%edi, %%esi\n"
+"        subl    %%ebp, %%esi\n"         /* from = out - dist */
+"        jmp     .L_do_copy1\n"
+
+".L_contiguous_in_window:\n"
+"        addl    %%eax, %%esi\n"
+"        subl    %%ecx, %%esi\n"         /* from += write - nbytes */
+
+"        movl    60(%%esp), %%eax\n"
+"        cmpl    %%ecx, %%eax\n"
+"        jbe     .L_do_copy1\n"          /* if (nbytes >= len) */
+
+"        subl    %%ecx, %%eax\n"         /* len -= nbytes */
+"        rep     movsb\n"
+"        movl    %%edi, %%esi\n"
+"        subl    %%ebp, %%esi\n"         /* from = out - dist */
+
+".L_do_copy1:\n"
+"        movl    %%eax, %%ecx\n"
+"        rep     movsb\n"
+
+"        movl    4(%%esp), %%esi\n"      /* move in back to %esi, toss from */
+"        movl    44(%%esp), %%ebp\n"     /* ebp = lcode */
+"        jmp     .L_while_test\n"
+
+".L_test_for_end_of_block:\n"
+"        testb   $32, %%al\n"
+"        jz      .L_invalid_literal_length_code\n"
+"        movl    $1, 68(%%esp)\n"
+"        jmp     .L_break_loop_with_status\n"
+
+".L_invalid_literal_length_code:\n"
+"        movl    $2, 68(%%esp)\n"
+"        jmp     .L_break_loop_with_status\n"
+
+".L_invalid_distance_code:\n"
+"        movl    $3, 68(%%esp)\n"
+"        jmp     .L_break_loop_with_status\n"
+
+".L_invalid_distance_too_far:\n"
+"        movl    4(%%esp), %%esi\n"
+"        movl    $4, 68(%%esp)\n"
+"        jmp     .L_break_loop_with_status\n"
+
+".L_break_loop:\n"
+"        movl    $0, 68(%%esp)\n"
+
+".L_break_loop_with_status:\n"
+/* put in, out, bits, and hold back into ar and pop esp */
+"        movl    %%esi, 4(%%esp)\n"
+"        movl    %%edi, 12(%%esp)\n"
+"        movl    %%ebx, 40(%%esp)\n"
+"        movl    %%edx, 36(%%esp)\n"
+"        movl    (%%esp), %%esp\n"
+"        popl    %%ebp\n"
+"        popf\n"
+          :
+          : "m" (ar)
+          : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
+    );
+#elif defined( _MSC_VER )
+    __asm {
+       lea     eax, ar
+       pushfd
+       push    ebp
+       mov     [eax], esp
+       mov     esp, eax
+       mov     esi, [esp+4]       /* esi = in */
+       mov     edi, [esp+12]      /* edi = out */
+       mov     edx, [esp+36]      /* edx = hold */
+       mov     ebx, [esp+40]      /* ebx = bits */
+       mov     ebp, [esp+44]      /* ebp = lcode */
+
+       cld
+       jmp     L_do_loop
+
+L_while_test:
+       cmp     [esp+20], edi
+       jbe     L_break_loop
+       cmp     [esp+8], esi
+       jbe     L_break_loop
+
+L_do_loop:
+       cmp     bl, 15
+       ja      L_get_length_code    /* if (15 < bits) */
+
+       xor     eax, eax
+       lodsw                         /* al = *(ushort *)in++ */
+       mov     cl, bl            /* cl = bits, needs it for shifting */
+       add     bl, 16             /* bits += 16 */
+       shl     eax, cl
+       or      edx, eax        /* hold |= *((ushort *)in)++ << bits */
+
+L_get_length_code:
+       mov     eax, [esp+52]      /* eax = lmask */
+       and     eax, edx          /* eax &= hold */
+       mov     eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */
+
+L_dolen:
+       mov     cl, ah            /* cl = this.bits */
+       sub     bl, ah            /* bits -= this.bits */
+       shr     edx, cl           /* hold >>= this.bits */
+
+       test    al, al
+       jnz     L_test_for_length_base /* if (op != 0) 45.7% */
+
+       shr     eax, 16            /* output this.val char */
+       stosb
+       jmp     L_while_test
+
+L_test_for_length_base:
+       mov     ecx, eax          /* len = this */
+       shr     ecx, 16            /* len = this.val */
+       mov     [esp+60], ecx      /* len = this */
+       mov     cl, al
+
+       test    al, 16
+       jz      L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
+       and     cl, 15             /* op &= 15 */
+       jz      L_decode_distance    /* if (!op) */
+       cmp     bl, cl
+       jae     L_add_bits_to_len    /* if (op <= bits) */
+
+       mov     ch, cl            /* stash op in ch, freeing cl */
+       xor     eax, eax
+       lodsw                         /* al = *(ushort *)in++ */
+       mov     cl, bl            /* cl = bits, needs it for shifting */
+       add     bl, 16             /* bits += 16 */
+       shl     eax, cl
+       or      edx, eax         /* hold |= *((ushort *)in)++ << bits */
+       mov     cl, ch            /* move op back to ecx */
+
+L_add_bits_to_len:
+       mov     eax, 1
+       shl     eax, cl
+       dec     eax
+       sub     bl, cl
+       and     eax, edx          /* eax &= hold */
+       shr     edx, cl
+       add     [esp+60], eax      /* len += hold & mask[op] */
+
+L_decode_distance:
+       cmp     bl, 15
+       ja      L_get_distance_code  /* if (15 < bits) */
+
+       xor     eax, eax
+       lodsw                         /* al = *(ushort *)in++ */
+       mov     cl, bl            /* cl = bits, needs it for shifting */
+       add     bl, 16             /* bits += 16 */
+       shl     eax, cl
+       or      edx, eax         /* hold |= *((ushort *)in)++ << bits */
+
+L_get_distance_code:
+       mov     eax, [esp+56]      /* eax = dmask */
+       mov     ecx, [esp+48]      /* ecx = dcode */
+       and     eax, edx          /* eax &= hold */
+       mov     eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */
+
+L_dodist:
+       mov     ebp, eax          /* dist = this */
+       shr     ebp, 16            /* dist = this.val */
+       mov     cl, ah
+       sub     bl, ah            /* bits -= this.bits */
+       shr     edx, cl           /* hold >>= this.bits */
+       mov     cl, al            /* cl = this.op */
+
+       test    al, 16             /* if ((op & 16) == 0) */
+       jz      L_test_for_second_level_dist
+       and     cl, 15             /* op &= 15 */
+       jz      L_check_dist_one
+       cmp     bl, cl
+       jae     L_add_bits_to_dist   /* if (op <= bits) 97.6% */
+
+       mov     ch, cl            /* stash op in ch, freeing cl */
+       xor     eax, eax
+       lodsw                         /* al = *(ushort *)in++ */
+       mov     cl, bl            /* cl = bits, needs it for shifting */
+       add     bl, 16             /* bits += 16 */
+       shl     eax, cl
+       or      edx, eax        /* hold |= *((ushort *)in)++ << bits */
+       mov     cl, ch            /* move op back to ecx */
+
+L_add_bits_to_dist:
+       mov     eax, 1
+       shl     eax, cl
+       dec     eax                 /* (1 << op) - 1 */
+       sub     bl, cl
+       and     eax, edx          /* eax &= hold */
+       shr     edx, cl
+       add     ebp, eax          /* dist += hold & ((1 << op) - 1) */
+
+L_check_window:
+       mov     [esp+4], esi       /* save in so from can use it's reg */
+       mov     eax, edi
+       sub     eax, [esp+16]      /* nbytes = out - beg */
+
+       cmp     eax, ebp
+       jb      L_clip_window        /* if (dist > nbytes) 4.2% */
+
+       mov     ecx, [esp+60]
+       mov     esi, edi
+       sub     esi, ebp          /* from = out - dist */
+
+       sub     ecx, 3             /* copy from to out */
+       mov     al, [esi]
+       mov     [edi], al
+       mov     al, [esi+1]
+       mov     ah, [esi+2]
+       add     esi, 3
+       mov     [edi+1], al
+       mov     [edi+2], ah
+       add     edi, 3
+       rep     movsb
+
+       mov     esi, [esp+4]      /* move in back to %esi, toss from */
+       mov     ebp, [esp+44]     /* ebp = lcode */
+       jmp     L_while_test
+
+L_check_dist_one:
+       cmp     ebp, 1            /* if dist 1, is a memset */
+       jne     L_check_window
+       cmp     [esp+16], edi
+       je      L_check_window
+
+       dec     edi
+       mov     ecx, [esp+60]
+       mov     al, [edi]
+       sub     ecx, 3
+
+       mov     [edi+1], al       /* memset out with from[-1] */
+       mov     [edi+2], al
+       mov     [edi+3], al
+       add     edi, 4
+       rep     stosb
+       mov     ebp, [esp+44]      /* ebp = lcode */
+       jmp     L_while_test
+
+L_test_for_second_level_length:
+       test    al, 64
+       jnz     L_test_for_end_of_block /* if ((op & 64) != 0) */
+
+       mov     eax, 1
+       shl     eax, cl
+       dec     eax
+       and     eax, edx         /* eax &= hold */
+       add     eax, [esp+60]     /* eax += this.val */
+       mov     eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/
+       jmp     L_dolen
+
+L_test_for_second_level_dist:
+       test    al, 64
+       jnz     L_invalid_distance_code /* if ((op & 64) != 0) */
+
+       mov     eax, 1
+       shl     eax, cl
+       dec     eax
+       and     eax, edx         /* eax &= hold */
+       add     eax, ebp         /* eax += this.val */
+       mov     ecx, [esp+48]     /* ecx = dcode */
+       mov     eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/
+       jmp     L_dodist
+
+L_clip_window:
+       mov     ecx, eax
+       mov     eax, [esp+24]     /* prepare for dist compare */
+       neg     ecx                /* nbytes = -nbytes */
+       mov     esi, [esp+32]     /* from = window */
+
+       cmp     eax, ebp
+       jb      L_invalid_distance_too_far /* if (dist > wsize) */
+
+       add     ecx, ebp         /* nbytes = dist - nbytes */
+       cmp     dword ptr [esp+28], 0
+       jne     L_wrap_around_window /* if (write != 0) */
+
+       sub     eax, ecx
+       add     esi, eax         /* from += wsize - nbytes */
+
+       mov     eax, [esp+60]
+       cmp     eax, ecx
+       jbe     L_do_copy1          /* if (nbytes >= len) */
+
+       sub     eax, ecx         /* len -= nbytes */
+       rep     movsb
+       mov     esi, edi
+       sub     esi, ebp         /* from = out - dist */
+       jmp     L_do_copy1
+
+       cmp     eax, ecx
+       jbe     L_do_copy1          /* if (nbytes >= len) */
+
+       sub     eax, ecx         /* len -= nbytes */
+       rep     movsb
+       mov     esi, edi
+       sub     esi, ebp         /* from = out - dist */
+       jmp     L_do_copy1
+
+L_wrap_around_window:
+       mov     eax, [esp+28]
+       cmp     ecx, eax
+       jbe     L_contiguous_in_window /* if (write >= nbytes) */
+
+       add     esi, [esp+24]
+       add     esi, eax
+       sub     esi, ecx         /* from += wsize + write - nbytes */
+       sub     ecx, eax         /* nbytes -= write */
+
+       mov     eax, [esp+60]
+       cmp     eax, ecx
+       jbe     L_do_copy1          /* if (nbytes >= len) */
+
+       sub     eax, ecx         /* len -= nbytes */
+       rep     movsb
+       mov     esi, [esp+32]     /* from = window */
+       mov     ecx, [esp+28]     /* nbytes = write */
+       cmp     eax, ecx
+       jbe     L_do_copy1          /* if (nbytes >= len) */
+
+       sub     eax, ecx         /* len -= nbytes */
+       rep     movsb
+       mov     esi, edi
+       sub     esi, ebp         /* from = out - dist */
+       jmp     L_do_copy1
+
+L_contiguous_in_window:
+       add     esi, eax
+       sub     esi, ecx         /* from += write - nbytes */
+
+       mov     eax, [esp+60]
+       cmp     eax, ecx
+       jbe     L_do_copy1          /* if (nbytes >= len) */
+
+       sub     eax, ecx         /* len -= nbytes */
+       rep     movsb
+       mov     esi, edi
+       sub     esi, ebp         /* from = out - dist */
+
+L_do_copy1:
+       mov     ecx, eax
+       rep     movsb
+
+       mov     esi, [esp+4]      /* move in back to %esi, toss from */
+       mov     ebp, [esp+44]     /* ebp = lcode */
+       jmp     L_while_test
+
+L_test_for_end_of_block:
+       test    al, 32
+       jz      L_invalid_literal_length_code
+       mov     dword ptr [esp+68], 1
+       jmp     L_break_loop_with_status
+
+L_invalid_literal_length_code:
+       mov     dword ptr [esp+68], 2
+       jmp     L_break_loop_with_status
+
+L_invalid_distance_code:
+       mov     dword ptr [esp+68], 3
+       jmp     L_break_loop_with_status
+
+L_invalid_distance_too_far:
+       mov     esi, [esp+4]
+       mov     dword ptr [esp+68], 4
+       jmp     L_break_loop_with_status
+
+L_break_loop:
+       mov     dword ptr [esp+68], 0
+
+L_break_loop_with_status:
+/* put in, out, bits, and hold back into ar and pop esp */
+       mov     [esp+4], esi
+       mov     [esp+12], edi
+       mov     [esp+40], ebx
+       mov     [esp+36], edx
+       mov     esp, [esp]
+       pop     ebp
+       popfd
+    }
+#endif
+
+    if (ar.status > 1) {
+        if (ar.status == 2)
+            strm->msg = "invalid literal/length code";
+        else if (ar.status == 3)
+            strm->msg = "invalid distance code";
+        else
+            strm->msg = "invalid distance too far back";
+        state->mode = BAD;
+    }
+    else if ( ar.status == 1 ) {
+        state->mode = TYPE;
+    }
+
+    /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
+    ar.len = ar.bits >> 3;
+    ar.in -= ar.len;
+    ar.bits -= ar.len << 3;
+    ar.hold &= (1U << ar.bits) - 1;
+
+    /* update state and return */
+    strm->next_in = ar.in;
+    strm->next_out = ar.out;
+    strm->avail_in = (unsigned)(ar.in < ar.last ? 5 + (ar.last - ar.in) :
+                                                  5 - (ar.in - ar.last));
+    strm->avail_out = (unsigned)(ar.out < ar.end ? 257 + (ar.end - ar.out) :
+                                                   257 - (ar.out - ar.end));
+    state->hold = ar.hold;
+    state->bits = ar.bits;
+    return;
+}
+
index d1e80ef..3602907 100644 (file)
-/*\r
- * inffast.S is a hand tuned assembler version of:\r
- *\r
- * inffast.c -- fast decoding\r
- * Copyright (C) 1995-2003 Mark Adler\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
- *\r
- * Copyright (C) 2003 Chris Anderson <christop@charm.net>\r
- * Please use the copyright conditions above.\r
- * \r
- * This version (Jan-23-2003) of inflate_fast was coded and tested under\r
- * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution.  On that\r
- * machine, I found that gzip style archives decompressed about 20% faster than\r
- * the gcc-3.2 -O3 -fomit-frame-pointer compiled version.  Your results will\r
- * depend on how large of a buffer is used for z_stream.next_in & next_out\r
- * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in\r
- * stream processing I/O and crc32/addler32.  In my case, this routine used\r
- * 70% of the cpu time and crc32 used 20%.\r
- *\r
- * I am confident that this version will work in the general case, but I have\r
- * not tested a wide variety of datasets or a wide variety of platforms.\r
- *\r
- * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating.\r
- * It should be a runtime flag instead of compile time flag...\r
- */\r
-\r
-.file "inffast.S"\r
-\r
-.globl inflate_fast\r
-\r
-.text\r
-.align 4,0\r
-.L_invalid_literal_length_code_msg:\r
-.string "invalid literal/length code"\r
-\r
-.align 4,0\r
-.L_invalid_distance_code_msg:\r
-.string "invalid distance code"\r
-\r
-.align 4,0\r
-.L_invalid_distance_too_far_msg:\r
-.string "invalid distance too far back"\r
-\r
-#if defined( USE_MMX )\r
-.align 4,0\r
-.L_mask: /* mask[N] = ( 1 << N ) - 1 */\r
-.long 0\r
-.long 1\r
-.long 3\r
-.long 7\r
-.long 15\r
-.long 31\r
-.long 63\r
-.long 127\r
-.long 255\r
-.long 511\r
-.long 1023\r
-.long 2047\r
-.long 4095\r
-.long 8191\r
-.long 16383\r
-.long 32767\r
-.long 65535\r
-.long 131071\r
-.long 262143\r
-.long 524287\r
-.long 1048575\r
-.long 2097151\r
-.long 4194303\r
-.long 8388607\r
-.long 16777215\r
-.long 33554431\r
-.long 67108863\r
-.long 134217727\r
-.long 268435455\r
-.long 536870911\r
-.long 1073741823\r
-.long 2147483647\r
-.long 4294967295\r
-#endif\r
-\r
-.text\r
-\r
-/*\r
- * struct z_stream offsets, in zlib.h\r
- */\r
-#define next_in_strm   0   /* strm->next_in */\r
-#define avail_in_strm  4   /* strm->avail_in */\r
-#define next_out_strm  12  /* strm->next_out */\r
-#define avail_out_strm 16  /* strm->avail_out */\r
-#define msg_strm       24  /* strm->msg */\r
-#define state_strm     28  /* strm->state */\r
-\r
-/*\r
- * struct inflate_state offsets, in inflate.h\r
- */\r
-#define mode_state     0   /* state->mode */\r
-#define wsize_state    32  /* state->wsize */\r
-#define write_state    36  /* state->write */\r
-#define window_state   40  /* state->window */\r
-#define hold_state     44  /* state->hold */\r
-#define bits_state     48  /* state->bits */\r
-#define lencode_state  64  /* state->lencode */\r
-#define distcode_state 68  /* state->distcode */\r
-#define lenbits_state  72  /* state->lenbits */\r
-#define distbits_state 76  /* state->distbits */\r
-\r
-/*\r
- * inflate_fast's activation record\r
- */\r
-#define local_var_size 56 /* how much local space for vars */\r
-#define strm_sp        80 /* first arg: z_stream * (local_var_size + 24) */\r
-#define start_sp       84 /* second arg: unsigned int (local_var_size + 28) */\r
-\r
-/*\r
- * offsets for local vars on stack\r
- */\r
-#define out            52  /* unsigned char* */\r
-#define window         48  /* unsigned char* */\r
-#define wsize          44  /* unsigned int */\r
-#define write          40  /* unsigned int */\r
-#define in             36  /* unsigned char* */\r
-#define beg            32  /* unsigned char* */\r
-#define dist           28  /* unsigned int */\r
-#define len            24  /* unsigned int */\r
-#define last           20  /* unsigned char* */\r
-#define end            16  /* unsigned char* */\r
-#define dcode          12  /* code* */\r
-#define lcode           8  /* code* */\r
-#define dmask           4  /* unsigned int */\r
-#define lmask           0  /* unsigned int */\r
-\r
-/*\r
- * typedef enum inflate_mode consts, in inflate.h\r
- */\r
-#ifndef NO_GUNZIP\r
-#define GUNZIP\r
-#endif\r
-\r
-#ifdef GUNZIP\r
-#define INFLATE_MODE_TYPE 11  /* state->mode flags enum-ed in inflate.h */\r
-#define INFLATE_MODE_BAD  26\r
-#else\r
-#define INFLATE_MODE_TYPE 3\r
-#define INFLATE_MODE_BAD  17\r
-#endif\r
-\r
-\r
-.align 16,0x90\r
-inflate_fast:\r
-        pushl   %edi\r
-        pushl   %esi\r
-        pushl   %ebp\r
-        pushl   %ebx\r
-        pushf   /* save eflags (strm_sp, state_sp assumes this is 32 bits) */\r
-        subl    $local_var_size, %esp\r
-        cld\r
-#if defined( USE_MMX )\r
-        emms\r
-#endif\r
-\r
-#define strm_r  %esi\r
-#define state_r %edi\r
-\r
-        movl    strm_sp(%esp), strm_r\r
-        movl    state_strm(strm_r), state_r\r
-\r
-        /* in = strm->next_in;\r
-         * out = strm->next_out;\r
-         * last = in + strm->avail_in - 5;\r
-         * beg = out - (start - strm->avail_out);\r
-         * end = out + (strm->avail_out - 257);\r
-         */\r
-        movl    next_in_strm(strm_r), %eax\r
-        movl    next_out_strm(strm_r), %ebx\r
-        movl    avail_in_strm(strm_r), %edx\r
-        movl    avail_out_strm(strm_r), %ecx\r
-        movl    start_sp(%esp), %ebp\r
-\r
-        addl    %eax, %edx      /* avail_in += next_in */\r
-        subl    $5, %edx        /* avail_in -= 5 */\r
-\r
-        subl    %ecx, %ebp      /* start -= avail_out */\r
-        negl    %ebp            /* start = -start */\r
-        addl    %ebx, %ebp      /* start += next_out */\r
-\r
-        subl    $257, %ecx      /* avail_out -= 257 */\r
-        addl    %ebx, %ecx      /* avail_out += out */\r
-\r
-        movl    %eax, in(%esp)\r
-        movl    %ebx, out(%esp)\r
-        movl    %edx, last(%esp)\r
-        movl    %ebp, beg(%esp)\r
-        movl    %ecx, end(%esp)\r
-\r
-        /* wsize = state->wsize;\r
-         * write = state->write;\r
-         * window = state->window;\r
-         * hold = state->hold;\r
-         * bits = state->bits;\r
-         * lcode = state->lencode;\r
-         * dcode = state->distcode;\r
-         * lmask = ( 1 << state->lenbits ) - 1;\r
-         * dmask = ( 1 << state->distbits ) - 1;\r
-         */\r
-\r
-        movl    lencode_state(state_r), %eax\r
-        movl    distcode_state(state_r), %ecx\r
-\r
-        movl    %eax, lcode(%esp)\r
-        movl    %ecx, dcode(%esp)\r
-\r
-        movl    $1, %eax\r
-        movl    lenbits_state(state_r), %ecx\r
-        shll    %cl, %eax\r
-        decl    %eax\r
-        movl    %eax, lmask(%esp)\r
-\r
-        movl    $1, %eax\r
-        movl    distbits_state(state_r), %ecx\r
-        shll    %cl, %eax\r
-        decl    %eax\r
-        movl    %eax, dmask(%esp)\r
-\r
-        movl    wsize_state(state_r), %eax\r
-        movl    write_state(state_r), %ecx\r
-        movl    window_state(state_r), %edx\r
-\r
-        movl    %eax, wsize(%esp)\r
-        movl    %ecx, write(%esp)\r
-        movl    %edx, window(%esp)\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-#define hold_r     %ebp\r
-#define bits_r     %bl\r
-#define bitslong_r %ebx\r
-\r
-        movl    hold_state(state_r), hold_r\r
-        movl    bits_state(state_r), bitslong_r\r
-\r
-#else /* USE_MMX */\r
-\r
-#define hold_mm    %mm0\r
-#define bits_r     %ebp\r
-#define bitslong_r %ebp\r
-\r
-        movl    hold_state(state_r), %ebx\r
-        movl    bits_state(state_r), bitslong_r\r
-\r
-#endif\r
-\r
-#undef strm_r\r
-#undef state_r\r
-#define in_r       %esi\r
-#define from_r     %esi\r
-#define out_r      %edi\r
-\r
-        movl    in(%esp), in_r\r
-\r
-#if ! defined ( USE_MMX )\r
-\r
-        /* align in_r on word boundary */\r
-        testl   $1, in_r\r
-        jz      .L_is_aligned\r
-        xorl    %eax, %eax\r
-        movb    (in_r), %al\r
-        incl    in_r\r
-        movb    bits_r, %cl\r
-        addb    $8, bits_r\r
-        shll    %cl, %eax\r
-        orl     %eax, hold_r\r
-\r
-#else\r
-        /* align in_r on long boundary */\r
-.L_align_long:\r
-        testl   $3, in_r\r
-        jz      .L_is_aligned\r
-        xorl    %eax, %eax\r
-        movb    (in_r), %al\r
-        incl    in_r\r
-        movl    bits_r, %ecx\r
-        addl    $8, bits_r\r
-        shll    %cl, %eax\r
-        orl     %eax, %ebx\r
-        jmp     .L_align_long\r
-\r
-#endif\r
-\r
-.L_is_aligned:\r
-        movl    out(%esp), out_r\r
-\r
-#if defined ( USE_MMX )\r
-\r
-#define used_mm   %mm1\r
-#define dmask2_mm %mm2\r
-#define lmask2_mm %mm3\r
-#define lmask_mm  %mm4\r
-#define dmask_mm  %mm5\r
-#define tmp_mm    %mm6\r
-\r
-        movl    out(%esp), out_r\r
-        movd    lmask(%esp), lmask_mm \r
-        movq    lmask_mm, lmask2_mm\r
-        movd    dmask(%esp), dmask_mm\r
-        movq    dmask_mm, dmask2_mm\r
-        movd    %ebx, hold_mm\r
-        pxor    used_mm, used_mm\r
-        movl    lcode(%esp), %ebx       /* ebx = lcode */\r
-#endif\r
-\r
-        jmp     .L_do_loop\r
-\r
-.align 16,0x90\r
-\r
-#if ! defined ( USE_MMX )\r
-\r
-.L_do_loop:\r
-        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out\r
-         *\r
-         * do { \r
-         *   if (bits < 15) {\r
-         *     hold |= *((unsigned short *)in)++ << bits;\r
-         *     bits += 16\r
-         *   }\r
-         *   this = lcode[hold & lmask]\r
-         */\r
-        cmpb    $15, bits_r\r
-        ja      .L_get_length_code      /* if (15 < bits) */\r
-\r
-        xorl    %eax, %eax\r
-        lodsw                           /* al = *(ushort *)in++ */\r
-        movb    bits_r, %cl             /* cl = bits, needs it for shifting */\r
-        addb    $16, bits_r             /* bits += 16 */\r
-        shll    %cl, %eax\r
-        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */\r
-\r
-.L_get_length_code:\r
-        movl    lmask(%esp), %edx       /* edx = lmask */\r
-        movl    lcode(%esp), %ecx       /* ecx = lcode */\r
-        andl    hold_r, %edx            /* edx &= hold */\r
-        movl    (%ecx,%edx,4), %eax     /* eax = lcode[hold & lmask] */\r
-\r
-#else /* USE_MMX */\r
-\r
-.L_do_loop:\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-\r
-        cmpl    $32, bits_r\r
-        ja      .L_get_length_code      /* if (32 < bits) */\r
-\r
-        movd    bits_r, tmp_mm\r
-        movd    (in_r), %mm7\r
-        addl    $4, in_r\r
-        psllq   tmp_mm, %mm7\r
-        addl    $32, bits_r\r
-        por     %mm7, hold_mm           /* hold_mm |= *((uint *)in)++ << bits */\r
-\r
-.L_get_length_code:\r
-        pand    hold_mm, lmask_mm\r
-        movd    lmask_mm, %eax\r
-        movq    lmask2_mm, lmask_mm\r
-        movl    (%ebx,%eax,4), %eax     /* eax = lcode[hold & lmask] */\r
-\r
-#endif\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-.L_dolen:\r
-        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out\r
-         *\r
-         * dolen:\r
-         *    bits -= this.bits;\r
-         *    hold >>= this.bits\r
-         */\r
-        movb    %ah, %cl                /* cl = this.bits */\r
-        subb    %ah, bits_r             /* bits -= this.bits */\r
-        shrl    %cl, hold_r             /* hold >>= this.bits */\r
-\r
-        /* check if op is a literal\r
-         * if (op == 0) {\r
-         *    PUP(out) = this.val;\r
-         *  }\r
-         */\r
-        testb   %al, %al\r
-        jnz     .L_test_for_length_base /* if (op != 0) 45.7% */\r
-\r
-        shrl    $16, %eax               /* output this.val char */\r
-        stosb\r
-\r
-#else /* USE_MMX */\r
-\r
-#define len_r  %edx\r
-\r
-.L_dolen:\r
-        movzbl  %ah, %ecx               /* ecx = this.bits */\r
-        movl    %eax, len_r             /* len = this */\r
-        shrl    $16, len_r              /* len = this.val */\r
-        movd    %ecx, used_mm\r
-        subl    %ecx, bits_r            /* bits -= this.bits */\r
-\r
-        testb   %al, %al\r
-        jnz     .L_test_for_length_base /* if (op != 0) 45.7% */\r
-\r
-        movb    %dl, (out_r)\r
-        incl    out_r\r
-\r
-#endif\r
-\r
-.L_while_test:\r
-        /* while (in < last && out < end)\r
-         */\r
-        cmpl    out_r, end(%esp)\r
-        jbe     .L_break_loop           /* if (out >= end) */\r
-\r
-        cmpl    in_r, last(%esp)\r
-        ja      .L_do_loop              /* if (in < last) */\r
-        jmp     .L_break_loop\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-.L_test_for_length_base:\r
-        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len\r
-         *\r
-         * else if (op & 16) {\r
-         *   len = this.val\r
-         *   op &= 15\r
-         *   if (op) {\r
-         *     if (op > bits) {\r
-         *       hold |= *((unsigned short *)in)++ << bits;\r
-         *       bits += 16\r
-         *     }\r
-         *     len += hold & mask[op];\r
-         *     bits -= op;\r
-         *     hold >>= op;\r
-         *   }\r
-         */\r
-#define len_r %edx\r
-        movl    %eax, len_r             /* len = this */\r
-        shrl    $16, len_r              /* len = this.val */\r
-        movb    %al, %cl\r
-\r
-        testb   $16, %al\r
-        jz      .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */\r
-        andb    $15, %cl                /* op &= 15 */\r
-        jz      .L_save_len             /* if (!op) */\r
-        cmpb    %cl, bits_r\r
-        jae     .L_add_bits_to_len      /* if (op <= bits) */\r
-\r
-        movb    %cl, %ch                /* stash op in ch, freeing cl */\r
-        xorl    %eax, %eax\r
-        lodsw                           /* al = *(ushort *)in++ */\r
-        movb    bits_r, %cl             /* cl = bits, needs it for shifting */\r
-        addb    $16, bits_r             /* bits += 16 */\r
-        shll    %cl, %eax\r
-        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */\r
-        movb    %ch, %cl                /* move op back to ecx */\r
-\r
-.L_add_bits_to_len:\r
-        movl    $1, %eax\r
-        shll    %cl, %eax\r
-        decl    %eax\r
-        subb    %cl, bits_r\r
-        andl    hold_r, %eax            /* eax &= hold */\r
-        shrl    %cl, hold_r\r
-        addl    %eax, len_r             /* len += hold & mask[op] */\r
-\r
-.L_save_len:\r
-        movl    len_r, len(%esp)        /* save len */\r
-#undef  len_r\r
-\r
-.L_decode_distance:\r
-        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *\r
-         *   if (bits < 15) {\r
-         *     hold |= *((unsigned short *)in)++ << bits;\r
-         *     bits += 16\r
-         *   }\r
-         *   this = dcode[hold & dmask];\r
-         * dodist:\r
-         *   bits -= this.bits;\r
-         *   hold >>= this.bits;\r
-         *   op = this.op;\r
-         */\r
-\r
-        cmpb    $15, bits_r\r
-        ja      .L_get_distance_code    /* if (15 < bits) */\r
-\r
-        xorl    %eax, %eax\r
-        lodsw                           /* al = *(ushort *)in++ */\r
-        movb    bits_r, %cl             /* cl = bits, needs it for shifting */\r
-        addb    $16, bits_r             /* bits += 16 */\r
-        shll    %cl, %eax\r
-        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */\r
-\r
-.L_get_distance_code:\r
-        movl    dmask(%esp), %edx       /* edx = dmask */\r
-        movl    dcode(%esp), %ecx       /* ecx = dcode */\r
-        andl    hold_r, %edx            /* edx &= hold */\r
-        movl    (%ecx,%edx,4), %eax     /* eax = dcode[hold & dmask] */\r
-\r
-#else /* USE_MMX */\r
-\r
-.L_test_for_length_base:\r
-        testb   $16, %al\r
-        jz      .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */\r
-        andl    $15, %eax               /* op &= 15 */\r
-        jz      .L_decode_distance      /* if (!op) */\r
-\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-        movd    %eax, used_mm\r
-        movd    hold_mm, %ecx\r
-        subl    %eax, bits_r\r
-        andl    .L_mask(,%eax,4), %ecx\r
-        addl    %ecx, len_r             /* len += hold & mask[op] */\r
-\r
-.L_decode_distance:\r
-\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-\r
-        cmpl    $32, bits_r\r
-        ja      .L_get_dist_code        /* if (32 < bits) */\r
-\r
-        movd    bits_r, tmp_mm\r
-        movd    (in_r), %mm7\r
-        addl    $4, in_r\r
-        psllq   tmp_mm, %mm7\r
-        addl    $32, bits_r\r
-        por     %mm7, hold_mm           /* hold_mm |= *((uint *)in)++ << bits */\r
-\r
-.L_get_dist_code:\r
-        movl    dcode(%esp), %ebx       /* ebx = dcode */\r
-        pand    hold_mm, dmask_mm\r
-        movd    dmask_mm, %eax\r
-        movq    dmask2_mm, dmask_mm\r
-        movl    (%ebx,%eax,4), %eax     /* eax = dcode[hold & lmask] */\r
-\r
-#endif\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-#define dist_r %edx\r
-.L_dodist:\r
-        movl    %eax, dist_r            /* dist = this */\r
-        shrl    $16, dist_r             /* dist = this.val */\r
-        movb    %ah, %cl\r
-        subb    %ah, bits_r             /* bits -= this.bits */\r
-        shrl    %cl, hold_r             /* hold >>= this.bits */\r
-\r
-        /* if (op & 16) {\r
-         *   dist = this.val\r
-         *   op &= 15\r
-         *   if (op > bits) {\r
-         *     hold |= *((unsigned short *)in)++ << bits;\r
-         *     bits += 16\r
-         *   }\r
-         *   dist += hold & mask[op];\r
-         *   bits -= op;\r
-         *   hold >>= op;\r
-         */\r
-        movb    %al, %cl                /* cl = this.op */\r
-\r
-        testb   $16, %al                /* if ((op & 16) == 0) */\r
-        jz      .L_test_for_second_level_dist\r
-        andb    $15, %cl                /* op &= 15 */\r
-        jz      .L_check_dist_one\r
-        cmpb    %cl, bits_r\r
-        jae     .L_add_bits_to_dist     /* if (op <= bits) 97.6% */\r
-\r
-        movb    %cl, %ch                /* stash op in ch, freeing cl */\r
-        xorl    %eax, %eax\r
-        lodsw                           /* al = *(ushort *)in++ */\r
-        movb    bits_r, %cl             /* cl = bits, needs it for shifting */\r
-        addb    $16, bits_r             /* bits += 16 */\r
-        shll    %cl, %eax\r
-        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */\r
-        movb    %ch, %cl                /* move op back to ecx */\r
-\r
-.L_add_bits_to_dist:\r
-        movl    $1, %eax\r
-        shll    %cl, %eax\r
-        decl    %eax                    /* (1 << op) - 1 */\r
-        subb    %cl, bits_r\r
-        andl    hold_r, %eax            /* eax &= hold */\r
-        shrl    %cl, hold_r\r
-        addl    %eax, dist_r            /* dist += hold & ((1 << op) - 1) */\r
-        jmp     .L_check_window\r
-\r
-#else /* USE_MMX */\r
-\r
-#define dist_r %ebx\r
-.L_dodist:\r
-        movzbl  %ah, %ecx               /* ecx = this.bits */\r
-        movl    %eax, dist_r\r
-        shrl    $16, dist_r             /* dist  = this.val */\r
-        subl    %ecx, bits_r            /* bits -= this.bits */\r
-        movd    %ecx, used_mm\r
-\r
-        testb   $16, %al                /* if ((op & 16) == 0) */\r
-        jz      .L_test_for_second_level_dist \r
-        andl    $15, %eax               /* op &= 15 */\r
-        jz      .L_check_dist_one\r
-\r
-.L_add_bits_to_dist:\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-        movd    %eax, used_mm           /* save bit length of current op */\r
-        movd    hold_mm, %ecx           /* get the next bits on input stream */\r
-        subl    %eax, bits_r            /* bits -= op bits */\r
-        andl    .L_mask(,%eax,4), %ecx  /* ecx   = hold & mask[op] */\r
-        addl    %ecx, dist_r            /* dist += hold & mask[op] */\r
-        jmp     .L_check_window\r
-\r
-#endif\r
-\r
-.align 16,0x90\r
-\r
-.L_check_dist_one:\r
-        cmpl    $1, dist_r\r
-        jne     .L_check_window\r
-        cmpl    out_r, beg(%esp)\r
-        je      .L_check_window\r
-\r
-        decl    out_r\r
-#if ! defined( USE_MMX )\r
-        movl    len(%esp), %ecx\r
-#else\r
-        movl    len_r, %ecx\r
-#endif\r
-        movb    (out_r), %al\r
-        subl    $3, %ecx\r
-\r
-        movb    %al, 1(out_r)\r
-        movb    %al, 2(out_r)\r
-        movb    %al, 3(out_r)\r
-        addl    $4, out_r\r
-        rep     stosb\r
-\r
-#if defined( USE_MMX )\r
-        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */\r
-#endif\r
-        jmp     .L_while_test\r
-\r
-.align 16,0x90\r
-\r
-.L_check_window:\r
-        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *       %ecx = nbytes\r
-         *\r
-         * nbytes = out - beg;\r
-         * if (dist <= nbytes) {\r
-         *   from = out - dist;\r
-         *   do {\r
-         *     PUP(out) = PUP(from);\r
-         *   } while (--len > 0) {\r
-         * }\r
-         */\r
-\r
-        movl    in_r, in(%esp)          /* save in so from can use it's reg */\r
-        movl    out_r, %eax\r
-        subl    beg(%esp), %eax         /* nbytes = out - beg */\r
-\r
-        cmpl    dist_r, %eax\r
-        jb      .L_clip_window          /* if (dist > nbytes) 4.2% */\r
-\r
-#if ! defined( USE_MMX )\r
-        movl    len(%esp), %ecx\r
-#else\r
-        movl    len_r, %ecx\r
-#endif\r
-        movl    out_r, from_r\r
-        subl    dist_r, from_r          /* from = out - dist */\r
-\r
-        subl    $3, %ecx\r
-        movb    (from_r), %al\r
-        movb    %al, (out_r)\r
-        movb    1(from_r), %al\r
-        movb    2(from_r), %dl\r
-        addl    $3, from_r\r
-        movb    %al, 1(out_r)\r
-        movb    %dl, 2(out_r)\r
-        addl    $3, out_r\r
-        rep     movsb\r
-\r
-        movl    in(%esp), in_r          /* move in back to %esi, toss from */\r
-#if defined( USE_MMX )\r
-        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */\r
-#endif\r
-        jmp     .L_while_test\r
-\r
-.align 16,0x90\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-.L_test_for_second_level_length:\r
-        /* else if ((op & 64) == 0) {\r
-         *   this = lcode[this.val + (hold & mask[op])];\r
-         * }\r
-         */\r
-        testb   $64, %al\r
-        jnz     .L_test_for_end_of_block  /* if ((op & 64) != 0) */\r
-\r
-        movl    $1, %eax\r
-        shll    %cl, %eax\r
-        decl    %eax\r
-        andl    hold_r, %eax            /* eax &= hold */\r
-        addl    %edx, %eax              /* eax += this.val */\r
-        movl    lcode(%esp), %edx       /* edx = lcode */\r
-        movl    (%edx,%eax,4), %eax     /* eax = lcode[val + (hold&mask[op])] */\r
-        jmp     .L_dolen\r
-\r
-#else /* USE_MMX */\r
-\r
-.L_test_for_second_level_length: \r
-        testb   $64, %al\r
-        jnz     .L_test_for_end_of_block  /* if ((op & 64) != 0) */\r
-\r
-        andl    $15, %eax\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-        movd    hold_mm, %ecx\r
-        andl    .L_mask(,%eax,4), %ecx\r
-        addl    len_r, %ecx\r
-        movl    (%ebx,%ecx,4), %eax     /* eax = lcode[hold & lmask] */\r
-        jmp     .L_dolen\r
-\r
-#endif\r
-\r
-.align 16,0x90\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-.L_test_for_second_level_dist:\r
-        /* else if ((op & 64) == 0) {\r
-         *   this = dcode[this.val + (hold & mask[op])];\r
-         * }\r
-         */\r
-        testb   $64, %al\r
-        jnz     .L_invalid_distance_code  /* if ((op & 64) != 0) */\r
-\r
-        movl    $1, %eax\r
-        shll    %cl, %eax\r
-        decl    %eax\r
-        andl    hold_r, %eax            /* eax &= hold */\r
-        addl    %edx, %eax              /* eax += this.val */\r
-        movl    dcode(%esp), %edx       /* edx = dcode */\r
-        movl    (%edx,%eax,4), %eax     /* eax = dcode[val + (hold&mask[op])] */\r
-        jmp     .L_dodist\r
-\r
-#else /* USE_MMX */\r
-\r
-.L_test_for_second_level_dist:\r
-        testb   $64, %al\r
-        jnz     .L_invalid_distance_code  /* if ((op & 64) != 0) */\r
-\r
-        andl    $15, %eax\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-        movd    hold_mm, %ecx\r
-        andl    .L_mask(,%eax,4), %ecx\r
-        movl    dcode(%esp), %eax       /* ecx = dcode */\r
-        addl    dist_r, %ecx\r
-        movl    (%eax,%ecx,4), %eax     /* eax = lcode[hold & lmask] */\r
-        jmp     .L_dodist\r
-\r
-#endif\r
-\r
-.align 16,0x90\r
-.L_clip_window:\r
-        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *       %ecx = nbytes\r
-         *\r
-         * else {\r
-         *   if (dist > wsize) {\r
-         *     invalid distance\r
-         *   }\r
-         *   from = window;\r
-         *   nbytes = dist - nbytes;\r
-         *   if (write == 0) {\r
-         *     from += wsize - nbytes;\r
-         */\r
-#define nbytes_r %ecx\r
-\r
-        movl    %eax, nbytes_r\r
-        movl    wsize(%esp), %eax       /* prepare for dist compare */\r
-        negl    nbytes_r                /* nbytes = -nbytes */\r
-        movl    window(%esp), from_r    /* from = window */\r
-\r
-        cmpl    dist_r, %eax\r
-        jb      .L_invalid_distance_too_far /* if (dist > wsize) */\r
-\r
-        addl    dist_r, nbytes_r        /* nbytes = dist - nbytes */\r
-        cmpl    $0, write(%esp)\r
-        jne     .L_wrap_around_window   /* if (write != 0) */\r
-\r
-        subl    nbytes_r, %eax\r
-        addl    %eax, from_r            /* from += wsize - nbytes */\r
-\r
-        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *       %ecx = nbytes, %eax = len\r
-         *\r
-         *     if (nbytes < len) {\r
-         *       len -= nbytes;\r
-         *       do {\r
-         *         PUP(out) = PUP(from);\r
-         *       } while (--nbytes);\r
-         *       from = out - dist;\r
-         *     }\r
-         *   }\r
-         */\r
-\r
-#if ! defined( USE_MMX )\r
-#define len_r %eax\r
-        movl    len(%esp), len_r\r
-#endif\r
-        cmpl    nbytes_r, len_r\r
-        jbe     .L_do_copy1             /* if (nbytes >= len) */\r
-\r
-        subl    nbytes_r, len_r         /* len -= nbytes */\r
-        rep     movsb\r
-        movl    out_r, from_r\r
-        subl    dist_r, from_r          /* from = out - dist */\r
-        jmp     .L_do_copy1\r
-\r
-        cmpl    nbytes_r, len_r\r
-        jbe     .L_do_copy1             /* if (nbytes >= len) */\r
-\r
-        subl    nbytes_r, len_r         /* len -= nbytes */\r
-        rep     movsb\r
-        movl    out_r, from_r\r
-        subl    dist_r, from_r          /* from = out - dist */\r
-        jmp     .L_do_copy1\r
-\r
-.L_wrap_around_window:\r
-        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *       %ecx = nbytes, %eax = write, %eax = len\r
-         *\r
-         *   else if (write < nbytes) {\r
-         *     from += wsize + write - nbytes;\r
-         *     nbytes -= write;\r
-         *     if (nbytes < len) {\r
-         *       len -= nbytes;\r
-         *       do {\r
-         *         PUP(out) = PUP(from);\r
-         *       } while (--nbytes);\r
-         *       from = window;\r
-         *       nbytes = write;\r
-         *       if (nbytes < len) {\r
-         *         len -= nbytes;\r
-         *         do {\r
-         *           PUP(out) = PUP(from);\r
-         *         } while(--nbytes);\r
-         *         from = out - dist;\r
-         *       }\r
-         *     }\r
-         *   }\r
-         */\r
-#define write_r %eax\r
-\r
-        movl    write(%esp), write_r\r
-        cmpl    write_r, nbytes_r\r
-        jbe     .L_contiguous_in_window /* if (write >= nbytes) */\r
-\r
-        addl    wsize(%esp), from_r\r
-        addl    write_r, from_r\r
-        subl    nbytes_r, from_r        /* from += wsize + write - nbytes */\r
-        subl    write_r, nbytes_r       /* nbytes -= write */\r
-#undef write_r\r
-\r
-#if ! defined( USE_MMX )\r
-        movl    len(%esp), len_r\r
-#endif\r
-        cmpl    nbytes_r, len_r\r
-        jbe     .L_do_copy1             /* if (nbytes >= len) */\r
-\r
-        subl    nbytes_r, len_r         /* len -= nbytes */\r
-        rep     movsb\r
-        movl    window(%esp), from_r    /* from = window */\r
-        movl    write(%esp), nbytes_r   /* nbytes = write */\r
-        cmpl    nbytes_r, len_r\r
-        jbe     .L_do_copy1             /* if (nbytes >= len) */\r
-\r
-        subl    nbytes_r, len_r         /* len -= nbytes */\r
-        rep     movsb\r
-        movl    out_r, from_r\r
-        subl    dist_r, from_r          /* from = out - dist */\r
-        jmp     .L_do_copy1\r
-\r
-.L_contiguous_in_window:\r
-        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist\r
-         *       %ecx = nbytes, %eax = write, %eax = len\r
-         *\r
-         *   else {\r
-         *     from += write - nbytes;\r
-         *     if (nbytes < len) {\r
-         *       len -= nbytes;\r
-         *       do {\r
-         *         PUP(out) = PUP(from);\r
-         *       } while (--nbytes);\r
-         *       from = out - dist;\r
-         *     }\r
-         *   }\r
-         */\r
-#define write_r %eax\r
-\r
-        addl    write_r, from_r\r
-        subl    nbytes_r, from_r        /* from += write - nbytes */\r
-#undef write_r\r
-\r
-#if ! defined( USE_MMX )\r
-        movl    len(%esp), len_r\r
-#endif\r
-        cmpl    nbytes_r, len_r\r
-        jbe     .L_do_copy1             /* if (nbytes >= len) */\r
-\r
-        subl    nbytes_r, len_r         /* len -= nbytes */\r
-        rep     movsb\r
-        movl    out_r, from_r\r
-        subl    dist_r, from_r          /* from = out - dist */\r
-\r
-.L_do_copy1:\r
-        /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out\r
-         *       %eax = len\r
-         *\r
-         *     while (len > 0) {\r
-         *       PUP(out) = PUP(from);\r
-         *       len--;\r
-         *     }\r
-         *   }\r
-         * } while (in < last && out < end);\r
-         */\r
-#undef nbytes_r\r
-#define in_r %esi\r
-\r
-        movl    len_r, %ecx\r
-        rep     movsb\r
-\r
-        movl    in(%esp), in_r          /* move in back to %esi, toss from */\r
-#if defined( USE_MMX )\r
-        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */\r
-#endif\r
-        jmp     .L_while_test\r
-\r
-#undef len_r\r
-#undef from_r\r
-#undef dist_r\r
-\r
-.L_invalid_distance_code:\r
-        /* else {\r
-         *   strm->msg = "invalid distance code";\r
-         *   state->mode = BAD;\r
-         * }\r
-         */\r
-        movl    $.L_invalid_distance_code_msg, %ecx\r
-        movl    $INFLATE_MODE_BAD, %edx\r
-        jmp     .L_update_stream_state\r
-\r
-.L_test_for_end_of_block:\r
-        /* else if (op & 32) {\r
-         *   state->mode = TYPE;\r
-         *   break;\r
-         * }\r
-         */\r
-        testb   $32, %al\r
-        jz      .L_invalid_literal_length_code  /* if ((op & 32) == 0) */\r
-\r
-        movl    $0, %ecx\r
-        movl    $INFLATE_MODE_TYPE, %edx\r
-        jmp     .L_update_stream_state\r
-\r
-.L_invalid_literal_length_code:\r
-        /* else {\r
-         *   strm->msg = "invalid literal/length code";\r
-         *   state->mode = BAD;\r
-         * }\r
-         */\r
-        movl    $.L_invalid_literal_length_code_msg, %ecx\r
-        movl    $INFLATE_MODE_BAD, %edx\r
-        jmp     .L_update_stream_state\r
-\r
-.L_invalid_distance_too_far:\r
-        /* strm->msg = "invalid distance too far back";\r
-         * state->mode = BAD;\r
-         */\r
-        movl    in(%esp), in_r          /* from_r has in's reg, put in back */\r
-        movl    $.L_invalid_distance_too_far_msg, %ecx\r
-        movl    $INFLATE_MODE_BAD, %edx\r
-        jmp     .L_update_stream_state\r
-\r
-.L_update_stream_state:\r
-        /* set strm->msg = %ecx, strm->state->mode = %edx */\r
-        movl    strm_sp(%esp), %eax\r
-        testl   %ecx, %ecx              /* if (msg != NULL) */\r
-        jz      .L_skip_msg\r
-        movl    %ecx, msg_strm(%eax)    /* strm->msg = msg */\r
-.L_skip_msg:\r
-        movl    state_strm(%eax), %eax  /* state = strm->state */\r
-        movl    %edx, mode_state(%eax)  /* state->mode = edx (BAD | TYPE) */\r
-\r
-.L_break_loop:\r
-\r
-#define strm_r  %eax\r
-#define state_r %edx\r
-\r
-        /* len = bits >> 3;\r
-         * in -= len;\r
-         * bits -= len << 3;\r
-         * hold &= (1U << bits) - 1;\r
-         * state->hold = hold;\r
-         * state->bits = bits;\r
-         * strm->next_in = in;\r
-         * strm->next_out = out;\r
-         */\r
-        movl    strm_sp(%esp), strm_r\r
-        movl    bitslong_r, %ecx\r
-        movl    state_strm(strm_r), state_r\r
-        shrl    $3, %ecx\r
-        subl    %ecx, in_r\r
-        shll    $3, %ecx\r
-        subl    %ecx, bitslong_r\r
-        movl    out_r, next_out_strm(strm_r)\r
-        movl    in_r, next_in_strm(strm_r)\r
-        movl    bitslong_r, bits_state(state_r)\r
-\r
-        movl    bitslong_r, %ecx\r
-        movl    $1, %ebx                /* overwrites bitslong_r, %bl */\r
-        shll    %cl, %ebx\r
-        decl    %ebx\r
-\r
-#undef bits_r\r
-#undef bitslong_r\r
-\r
-#if ! defined( USE_MMX )\r
-\r
-        andl    %ebx, hold_r\r
-        movl    hold_r, hold_state(state_r)\r
-\r
-#else /* USE_MMX */\r
-\r
-        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */\r
-        movd    hold_mm, %ecx\r
-        andl    %ebx, %ecx\r
-        movl    %ecx, hold_state(state_r)\r
-\r
-#endif\r
-\r
-#define last_r %ebx\r
-\r
-        /* strm->avail_in = in < last ? 5 + (last - in) : 5 - (in - last) */\r
-        movl    last(%esp), last_r\r
-        cmpl    in_r, last_r\r
-        jbe     .L_last_is_smaller     /* if (in >= last) */\r
-\r
-        subl    in_r, last_r           /* last -= in */\r
-        addl    $5, last_r             /* last += 5 */\r
-        movl    last_r, avail_in_strm(strm_r)\r
-        jmp     .L_fixup_out\r
-.L_last_is_smaller:\r
-        subl    last_r, in_r           /* in -= last */\r
-        negl    in_r                   /* in = -in */\r
-        addl    $5, in_r               /* in += 5 */\r
-        movl    in_r, avail_in_strm(strm_r)\r
-\r
-#undef last_r\r
-#define end_r %ebx\r
-\r
-.L_fixup_out:\r
-        /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/\r
-        movl    end(%esp), end_r\r
-        cmpl    out_r, end_r\r
-        jbe     .L_end_is_smaller      /* if (out >= end) */\r
-\r
-        subl    out_r, end_r           /* end -= out */\r
-        addl    $257, end_r            /* end += 257 */\r
-        movl    end_r, avail_out_strm(strm_r)\r
-        jmp     .L_done\r
-.L_end_is_smaller:\r
-        subl    end_r, out_r           /* out -= end */\r
-        negl    out_r                  /* out = -out */\r
-        addl    $257, out_r            /* out += 257 */\r
-        movl    out_r, avail_out_strm(strm_r)\r
-\r
-#undef end_r\r
-\r
-.L_done:\r
-#if defined( USE_MMX )\r
-        emms\r
-#endif\r
-        addl    $local_var_size, %esp\r
-        popf\r
-        popl    %ebx\r
-        popl    %ebp\r
-        popl    %esi\r
-        popl    %edi\r
-        ret\r
-\r
-.type inflate_fast,@function\r
-.size inflate_fast,.-inflate_fast\r
+/*
+ * inffast.S is a hand tuned assembler version of:
+ *
+ * inffast.c -- fast decoding
+ * Copyright (C) 1995-2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h 
+ *
+ * Copyright (C) 2003 Chris Anderson <christop@charm.net>
+ * Please use the copyright conditions above.
+ * 
+ * This version (Jan-23-2003) of inflate_fast was coded and tested under
+ * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution.  On that
+ * machine, I found that gzip style archives decompressed about 20% faster than
+ * the gcc-3.2 -O3 -fomit-frame-pointer compiled version.  Your results will
+ * depend on how large of a buffer is used for z_stream.next_in & next_out
+ * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in
+ * stream processing I/O and crc32/addler32.  In my case, this routine used
+ * 70% of the cpu time and crc32 used 20%.
+ *
+ * I am confident that this version will work in the general case, but I have
+ * not tested a wide variety of datasets or a wide variety of platforms.
+ *
+ * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating.
+ * It should be a runtime flag instead of compile time flag...
+ *
+ * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction.
+ * With -DUSE_MMX, only MMX code is compiled.  With -DNO_MMX, only non-MMX code
+ * is compiled.  Without either option, runtime detection is enabled.  Runtime
+ * detection should work on all modern cpus and the recomended algorithm (flip
+ * ID bit on eflags and then use the cpuid instruction) is used in many
+ * multimedia applications.  Tested under win2k with gcc-2.95 and gas-2.12
+ * distributed with cygwin3.  Compiling with gcc-2.95 -c inffast.S -o
+ * inffast.obj generates a COFF object which can then be linked with MSVC++
+ * compiled code.  Tested under FreeBSD 4.7 with gcc-2.95.
+ *
+ * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and
+ * slower than compiler generated code).  Adjusted cpuid check to use the MMX
+ * code only for Pentiums < P4 until I have more data on the P4.  Speed
+ * improvment is only about 15% on the Athlon when compared with code generated
+ * with MSVC++.  Not sure yet, but I think the P4 will also be slower using the
+ * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and
+ * have less latency than MMX ops.  Added code to buffer the last 11 bytes of
+ * the input stream since the MMX code grabs bits in chunks of 32, which
+ * differs from the inffast.c algorithm.  I don't think there would have been
+ * read overruns where a page boundary was crossed (a segfault), but there
+ * could have been overruns when next_in ends on unaligned memory (unintialized
+ * memory read).
+ *
+ * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX.  I created a C
+ * version of the non-MMX code so that it doesn't depend on zstrm and zstate
+ * structure offsets which are hard coded in this file.  This was last tested
+ * with zlib-1.2.0 which is currently in beta testing, newer versions of this
+ * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and
+ * http://www.charm.net/~christop/zlib/
+ */
+
+
+/*
+ * if you have underscore linking problems (_inflate_fast undefined), try
+ * using -DGAS_COFF
+ */
+#if ! defined( GAS_COFF ) && ! defined( GAS_ELF )
+
+#if defined( __CYGWIN__ )
+#define GAS_COFF /* windows object format */
+#else
+#define GAS_ELF
+#endif
+
+#endif /* ! GAS_COFF && ! GAS_ELF */
+
+
+#if defined( GAS_COFF )
+
+/* coff externals have underscores */
+#define inflate_fast _inflate_fast
+#define inflate_fast_use_mmx _inflate_fast_use_mmx
+
+#endif /* GAS_COFF */
+
+
+.file "inffast.S"
+
+.globl inflate_fast
+
+.text
+.align 4,0
+.L_invalid_literal_length_code_msg:
+.string "invalid literal/length code"
+
+.align 4,0
+.L_invalid_distance_code_msg:
+.string "invalid distance code"
+
+.align 4,0
+.L_invalid_distance_too_far_msg:
+.string "invalid distance too far back"
+
+#if ! defined( NO_MMX )
+.align 4,0
+.L_mask: /* mask[N] = ( 1 << N ) - 1 */
+.long 0
+.long 1
+.long 3
+.long 7
+.long 15
+.long 31
+.long 63
+.long 127
+.long 255
+.long 511
+.long 1023
+.long 2047
+.long 4095
+.long 8191
+.long 16383
+.long 32767
+.long 65535
+.long 131071
+.long 262143
+.long 524287
+.long 1048575
+.long 2097151
+.long 4194303
+.long 8388607
+.long 16777215
+.long 33554431
+.long 67108863
+.long 134217727
+.long 268435455
+.long 536870911
+.long 1073741823
+.long 2147483647
+.long 4294967295
+#endif /* NO_MMX */
+
+.text
+
+/*
+ * struct z_stream offsets, in zlib.h
+ */
+#define next_in_strm   0   /* strm->next_in */
+#define avail_in_strm  4   /* strm->avail_in */
+#define next_out_strm  12  /* strm->next_out */
+#define avail_out_strm 16  /* strm->avail_out */
+#define msg_strm       24  /* strm->msg */
+#define state_strm     28  /* strm->state */
+
+/*
+ * struct inflate_state offsets, in inflate.h
+ */
+#define mode_state     0   /* state->mode */
+#define wsize_state    32  /* state->wsize */
+#define write_state    36  /* state->write */
+#define window_state   40  /* state->window */
+#define hold_state     44  /* state->hold */
+#define bits_state     48  /* state->bits */
+#define lencode_state  64  /* state->lencode */
+#define distcode_state 68  /* state->distcode */
+#define lenbits_state  72  /* state->lenbits */
+#define distbits_state 76  /* state->distbits */
+
+/*
+ * inflate_fast's activation record
+ */
+#define local_var_size 64 /* how much local space for vars */
+#define strm_sp        88 /* first arg: z_stream * (local_var_size + 24) */
+#define start_sp       92 /* second arg: unsigned int (local_var_size + 28) */
+
+/*
+ * offsets for local vars on stack
+ */
+#define out            60  /* unsigned char* */
+#define window         56  /* unsigned char* */
+#define wsize          52  /* unsigned int */
+#define write          48  /* unsigned int */
+#define in             44  /* unsigned char* */
+#define beg            40  /* unsigned char* */
+#define buf            28  /* char[ 12 ] */
+#define len            24  /* unsigned int */
+#define last           20  /* unsigned char* */
+#define end            16  /* unsigned char* */
+#define dcode          12  /* code* */
+#define lcode           8  /* code* */
+#define dmask           4  /* unsigned int */
+#define lmask           0  /* unsigned int */
+
+/*
+ * typedef enum inflate_mode consts, in inflate.h
+ */
+#ifndef NO_GUNZIP
+#define GUNZIP
+#endif
+
+#ifdef GUNZIP
+#define INFLATE_MODE_TYPE 11  /* state->mode flags enum-ed in inflate.h */
+#define INFLATE_MODE_BAD  26
+#else
+#define INFLATE_MODE_TYPE 3
+#define INFLATE_MODE_BAD  17
+#endif
+
+
+#if ! defined( USE_MMX ) && ! defined( NO_MMX )
+
+#define RUN_TIME_MMX
+
+#define CHECK_MMX    1
+#define DO_USE_MMX   2
+#define DONT_USE_MMX 3
+
+.globl inflate_fast_use_mmx
+
+.data
+
+.align 4,0
+inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */
+.long CHECK_MMX
+
+#if defined( GAS_ELF )
+/* elf info */
+.type   inflate_fast_use_mmx,@object
+.size   inflate_fast_use_mmx,4
+#endif
+
+#endif /* RUN_TIME_MMX */
+
+#if defined( GAS_COFF )
+/* coff info: scl 2 = extern, type 32 = function */
+.def inflate_fast; .scl 2; .type 32; .endef
+#endif
+
+.text
+
+.align 32,0x90
+inflate_fast:
+        pushl   %edi
+        pushl   %esi
+        pushl   %ebp
+        pushl   %ebx
+        pushf   /* save eflags (strm_sp, state_sp assumes this is 32 bits) */
+        subl    $local_var_size, %esp
+        cld
+
+#define strm_r  %esi
+#define state_r %edi
+
+        movl    strm_sp(%esp), strm_r
+        movl    state_strm(strm_r), state_r
+
+        /* in = strm->next_in;
+         * out = strm->next_out;
+         * last = in + strm->avail_in - 11;
+         * beg = out - (start - strm->avail_out);
+         * end = out + (strm->avail_out - 257);
+         */
+        movl    avail_in_strm(strm_r), %edx
+        movl    next_in_strm(strm_r), %eax
+
+        addl    %eax, %edx      /* avail_in += next_in */
+        subl    $11, %edx       /* avail_in -= 11 */
+
+        movl    %eax, in(%esp)
+        movl    %edx, last(%esp)
+
+        movl    start_sp(%esp), %ebp
+        movl    avail_out_strm(strm_r), %ecx
+        movl    next_out_strm(strm_r), %ebx
+
+        subl    %ecx, %ebp      /* start -= avail_out */
+        negl    %ebp            /* start = -start */
+        addl    %ebx, %ebp      /* start += next_out */
+
+        subl    $257, %ecx      /* avail_out -= 257 */
+        addl    %ebx, %ecx      /* avail_out += out */
+
+        movl    %ebx, out(%esp)
+        movl    %ebp, beg(%esp)
+        movl    %ecx, end(%esp)
+
+        /* wsize = state->wsize;
+         * write = state->write;
+         * window = state->window;
+         * hold = state->hold;
+         * bits = state->bits;
+         * lcode = state->lencode;
+         * dcode = state->distcode;
+         * lmask = ( 1 << state->lenbits ) - 1;
+         * dmask = ( 1 << state->distbits ) - 1;
+         */
+
+        movl    lencode_state(state_r), %eax
+        movl    distcode_state(state_r), %ecx
+
+        movl    %eax, lcode(%esp)
+        movl    %ecx, dcode(%esp)
+
+        movl    $1, %eax
+        movl    lenbits_state(state_r), %ecx
+        shll    %cl, %eax
+        decl    %eax
+        movl    %eax, lmask(%esp)
+
+        movl    $1, %eax
+        movl    distbits_state(state_r), %ecx
+        shll    %cl, %eax
+        decl    %eax
+        movl    %eax, dmask(%esp)
+
+        movl    wsize_state(state_r), %eax
+        movl    write_state(state_r), %ecx
+        movl    window_state(state_r), %edx
+
+        movl    %eax, wsize(%esp)
+        movl    %ecx, write(%esp)
+        movl    %edx, window(%esp)
+
+        movl    hold_state(state_r), %ebp
+        movl    bits_state(state_r), %ebx
+
+#undef strm_r
+#undef state_r
+
+#define in_r       %esi
+#define from_r     %esi
+#define out_r      %edi
+
+        movl    in(%esp), in_r
+        movl    last(%esp), %ecx
+        cmpl    in_r, %ecx
+        ja      .L_align_long           /* if in < last */
+
+        addl    $11, %ecx               /* ecx = &in[ avail_in ] */
+        subl    in_r, %ecx              /* ecx = avail_in */
+        movl    $12, %eax
+        subl    %ecx, %eax              /* eax = 12 - avail_in */
+        leal    buf(%esp), %edi
+        rep     movsb                   /* memcpy( buf, in, avail_in ) */
+        movl    %eax, %ecx
+        xorl    %eax, %eax
+        rep     stosb         /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */
+        leal    buf(%esp), in_r         /* in = buf */
+        movl    in_r, last(%esp)        /* last = in, do just one iteration */
+        jmp     .L_is_aligned
+
+        /* align in_r on long boundary */
+.L_align_long:
+        testl   $3, in_r
+        jz      .L_is_aligned
+        xorl    %eax, %eax
+        movb    (in_r), %al
+        incl    in_r
+        movl    %ebx, %ecx
+        addl    $8, %ebx
+        shll    %cl, %eax
+        orl     %eax, %ebp
+        jmp     .L_align_long
+
+.L_is_aligned:
+        movl    out(%esp), out_r
+
+#if defined( NO_MMX )
+        jmp     .L_do_loop
+#endif
+
+#if defined( USE_MMX )
+        jmp     .L_init_mmx
+#endif
+
+/*** Runtime MMX check ***/
+
+#if defined( RUN_TIME_MMX )
+.L_check_mmx:
+        cmpl    $DO_USE_MMX, inflate_fast_use_mmx
+        je      .L_init_mmx
+        ja      .L_do_loop /* > 2 */
+
+        pushl   %eax
+        pushl   %ebx
+        pushl   %ecx
+        pushl   %edx
+        pushf
+        movl    (%esp), %eax      /* copy eflags to eax */
+        xorl    $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21)
+                                   * to see if cpu supports cpuid...
+                                   * ID bit method not supported by NexGen but
+                                   * bios may load a cpuid instruction and
+                                   * cpuid may be disabled on Cyrix 5-6x86 */
+        popf
+        pushf   
+        popl    %edx              /* copy new eflags to edx */
+        xorl    %eax, %edx        /* test if ID bit is flipped */
+        jz      .L_dont_use_mmx   /* not flipped if zero */
+        xorl    %eax, %eax
+        cpuid
+        cmpl    $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */
+        jne     .L_dont_use_mmx
+        cmpl    $0x6c65746e, %ecx
+        jne     .L_dont_use_mmx
+        cmpl    $0x49656e69, %edx
+        jne     .L_dont_use_mmx
+        movl    $1, %eax
+        cpuid                     /* get cpu features */
+        shrl    $8, %eax
+        andl    $15, %eax
+        cmpl    $6, %eax          /* check for Pentium family, is 0xf for P4 */
+        jne     .L_dont_use_mmx
+        testl   $0x800000, %edx   /* test if MMX feature is set (bit 23) */
+        jnz     .L_use_mmx
+        jmp     .L_dont_use_mmx
+.L_use_mmx:
+        movl    $DO_USE_MMX, inflate_fast_use_mmx
+        jmp     .L_check_mmx_pop
+.L_dont_use_mmx:
+        movl    $DONT_USE_MMX, inflate_fast_use_mmx
+.L_check_mmx_pop:
+        popl    %edx
+        popl    %ecx
+        popl    %ebx
+        popl    %eax
+        jmp     .L_check_mmx
+#endif
+        
+
+/*** Non-MMX code ***/
+
+#if defined ( NO_MMX ) || defined( RUN_TIME_MMX )
+
+#define hold_r     %ebp
+#define bits_r     %bl
+#define bitslong_r %ebx
+
+.align 32,0x90
+.L_while_test:
+        /* while (in < last && out < end)
+         */
+        cmpl    out_r, end(%esp)
+        jbe     .L_break_loop           /* if (out >= end) */
+
+        cmpl    in_r, last(%esp)
+        jbe     .L_break_loop
+
+.L_do_loop:
+        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
+         *
+         * do { 
+         *   if (bits < 15) {
+         *     hold |= *((unsigned short *)in)++ << bits;
+         *     bits += 16
+         *   }
+         *   this = lcode[hold & lmask]
+         */
+        cmpb    $15, bits_r
+        ja      .L_get_length_code      /* if (15 < bits) */
+
+        xorl    %eax, %eax
+        lodsw                           /* al = *(ushort *)in++ */
+        movb    bits_r, %cl             /* cl = bits, needs it for shifting */
+        addb    $16, bits_r             /* bits += 16 */
+        shll    %cl, %eax
+        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */
+
+.L_get_length_code:
+        movl    lmask(%esp), %edx       /* edx = lmask */
+        movl    lcode(%esp), %ecx       /* ecx = lcode */
+        andl    hold_r, %edx            /* edx &= hold */
+        movl    (%ecx,%edx,4), %eax     /* eax = lcode[hold & lmask] */
+
+.L_dolen:
+        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
+         *
+         * dolen:
+         *    bits -= this.bits;
+         *    hold >>= this.bits
+         */
+        movb    %ah, %cl                /* cl = this.bits */
+        subb    %ah, bits_r             /* bits -= this.bits */
+        shrl    %cl, hold_r             /* hold >>= this.bits */
+
+        /* check if op is a literal
+         * if (op == 0) {
+         *    PUP(out) = this.val;
+         *  }
+         */
+        testb   %al, %al
+        jnz     .L_test_for_length_base /* if (op != 0) 45.7% */
+
+        shrl    $16, %eax               /* output this.val char */
+        stosb
+        jmp     .L_while_test
+
+.L_test_for_length_base:
+        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len
+         *
+         * else if (op & 16) {
+         *   len = this.val
+         *   op &= 15
+         *   if (op) {
+         *     if (op > bits) {
+         *       hold |= *((unsigned short *)in)++ << bits;
+         *       bits += 16
+         *     }
+         *     len += hold & mask[op];
+         *     bits -= op;
+         *     hold >>= op;
+         *   }
+         */
+#define len_r %edx
+        movl    %eax, len_r             /* len = this */
+        shrl    $16, len_r              /* len = this.val */
+        movb    %al, %cl
+
+        testb   $16, %al
+        jz      .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
+        andb    $15, %cl                /* op &= 15 */
+        jz      .L_save_len             /* if (!op) */
+        cmpb    %cl, bits_r
+        jae     .L_add_bits_to_len      /* if (op <= bits) */
+
+        movb    %cl, %ch                /* stash op in ch, freeing cl */
+        xorl    %eax, %eax
+        lodsw                           /* al = *(ushort *)in++ */
+        movb    bits_r, %cl             /* cl = bits, needs it for shifting */
+        addb    $16, bits_r             /* bits += 16 */
+        shll    %cl, %eax
+        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */
+        movb    %ch, %cl                /* move op back to ecx */
+
+.L_add_bits_to_len:
+        movl    $1, %eax
+        shll    %cl, %eax
+        decl    %eax
+        subb    %cl, bits_r
+        andl    hold_r, %eax            /* eax &= hold */
+        shrl    %cl, hold_r
+        addl    %eax, len_r             /* len += hold & mask[op] */
+
+.L_save_len:
+        movl    len_r, len(%esp)        /* save len */
+#undef  len_r
+
+.L_decode_distance:
+        /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *
+         *   if (bits < 15) {
+         *     hold |= *((unsigned short *)in)++ << bits;
+         *     bits += 16
+         *   }
+         *   this = dcode[hold & dmask];
+         * dodist:
+         *   bits -= this.bits;
+         *   hold >>= this.bits;
+         *   op = this.op;
+         */
+
+        cmpb    $15, bits_r
+        ja      .L_get_distance_code    /* if (15 < bits) */
+
+        xorl    %eax, %eax
+        lodsw                           /* al = *(ushort *)in++ */
+        movb    bits_r, %cl             /* cl = bits, needs it for shifting */
+        addb    $16, bits_r             /* bits += 16 */
+        shll    %cl, %eax
+        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */
+
+.L_get_distance_code:
+        movl    dmask(%esp), %edx       /* edx = dmask */
+        movl    dcode(%esp), %ecx       /* ecx = dcode */
+        andl    hold_r, %edx            /* edx &= hold */
+        movl    (%ecx,%edx,4), %eax     /* eax = dcode[hold & dmask] */
+
+#define dist_r %edx
+.L_dodist:
+        movl    %eax, dist_r            /* dist = this */
+        shrl    $16, dist_r             /* dist = this.val */
+        movb    %ah, %cl
+        subb    %ah, bits_r             /* bits -= this.bits */
+        shrl    %cl, hold_r             /* hold >>= this.bits */
+
+        /* if (op & 16) {
+         *   dist = this.val
+         *   op &= 15
+         *   if (op > bits) {
+         *     hold |= *((unsigned short *)in)++ << bits;
+         *     bits += 16
+         *   }
+         *   dist += hold & mask[op];
+         *   bits -= op;
+         *   hold >>= op;
+         */
+        movb    %al, %cl                /* cl = this.op */
+
+        testb   $16, %al                /* if ((op & 16) == 0) */
+        jz      .L_test_for_second_level_dist
+        andb    $15, %cl                /* op &= 15 */
+        jz      .L_check_dist_one
+        cmpb    %cl, bits_r
+        jae     .L_add_bits_to_dist     /* if (op <= bits) 97.6% */
+
+        movb    %cl, %ch                /* stash op in ch, freeing cl */
+        xorl    %eax, %eax
+        lodsw                           /* al = *(ushort *)in++ */
+        movb    bits_r, %cl             /* cl = bits, needs it for shifting */
+        addb    $16, bits_r             /* bits += 16 */
+        shll    %cl, %eax
+        orl     %eax, hold_r            /* hold |= *((ushort *)in)++ << bits */
+        movb    %ch, %cl                /* move op back to ecx */
+
+.L_add_bits_to_dist:
+        movl    $1, %eax
+        shll    %cl, %eax
+        decl    %eax                    /* (1 << op) - 1 */
+        subb    %cl, bits_r
+        andl    hold_r, %eax            /* eax &= hold */
+        shrl    %cl, hold_r
+        addl    %eax, dist_r            /* dist += hold & ((1 << op) - 1) */
+        jmp     .L_check_window
+
+.L_check_window:
+        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *       %ecx = nbytes
+         *
+         * nbytes = out - beg;
+         * if (dist <= nbytes) {
+         *   from = out - dist;
+         *   do {
+         *     PUP(out) = PUP(from);
+         *   } while (--len > 0) {
+         * }
+         */
+
+        movl    in_r, in(%esp)          /* save in so from can use it's reg */
+        movl    out_r, %eax
+        subl    beg(%esp), %eax         /* nbytes = out - beg */
+
+        cmpl    dist_r, %eax
+        jb      .L_clip_window          /* if (dist > nbytes) 4.2% */
+
+        movl    len(%esp), %ecx
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+
+        subl    $3, %ecx
+        movb    (from_r), %al
+        movb    %al, (out_r)
+        movb    1(from_r), %al
+        movb    2(from_r), %dl
+        addl    $3, from_r
+        movb    %al, 1(out_r)
+        movb    %dl, 2(out_r)
+        addl    $3, out_r
+        rep     movsb
+
+        movl    in(%esp), in_r          /* move in back to %esi, toss from */
+        jmp     .L_while_test
+
+.align 16,0x90
+.L_check_dist_one:
+        cmpl    $1, dist_r
+        jne     .L_check_window
+        cmpl    out_r, beg(%esp)
+        je      .L_check_window
+
+        decl    out_r
+        movl    len(%esp), %ecx
+        movb    (out_r), %al
+        subl    $3, %ecx
+
+        movb    %al, 1(out_r)
+        movb    %al, 2(out_r)
+        movb    %al, 3(out_r)
+        addl    $4, out_r
+        rep     stosb
+
+        jmp     .L_while_test
+
+.align 16,0x90
+.L_test_for_second_level_length:
+        /* else if ((op & 64) == 0) {
+         *   this = lcode[this.val + (hold & mask[op])];
+         * }
+         */
+        testb   $64, %al
+        jnz     .L_test_for_end_of_block  /* if ((op & 64) != 0) */
+
+        movl    $1, %eax
+        shll    %cl, %eax
+        decl    %eax
+        andl    hold_r, %eax            /* eax &= hold */
+        addl    %edx, %eax              /* eax += this.val */
+        movl    lcode(%esp), %edx       /* edx = lcode */
+        movl    (%edx,%eax,4), %eax     /* eax = lcode[val + (hold&mask[op])] */
+        jmp     .L_dolen
+
+.align 16,0x90
+.L_test_for_second_level_dist:
+        /* else if ((op & 64) == 0) {
+         *   this = dcode[this.val + (hold & mask[op])];
+         * }
+         */
+        testb   $64, %al
+        jnz     .L_invalid_distance_code  /* if ((op & 64) != 0) */
+
+        movl    $1, %eax
+        shll    %cl, %eax
+        decl    %eax
+        andl    hold_r, %eax            /* eax &= hold */
+        addl    %edx, %eax              /* eax += this.val */
+        movl    dcode(%esp), %edx       /* edx = dcode */
+        movl    (%edx,%eax,4), %eax     /* eax = dcode[val + (hold&mask[op])] */
+        jmp     .L_dodist
+
+.align 16,0x90
+.L_clip_window:
+        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *       %ecx = nbytes
+         *
+         * else {
+         *   if (dist > wsize) {
+         *     invalid distance
+         *   }
+         *   from = window;
+         *   nbytes = dist - nbytes;
+         *   if (write == 0) {
+         *     from += wsize - nbytes;
+         */
+#define nbytes_r %ecx
+        movl    %eax, nbytes_r
+        movl    wsize(%esp), %eax       /* prepare for dist compare */
+        negl    nbytes_r                /* nbytes = -nbytes */
+        movl    window(%esp), from_r    /* from = window */
+
+        cmpl    dist_r, %eax
+        jb      .L_invalid_distance_too_far /* if (dist > wsize) */
+
+        addl    dist_r, nbytes_r        /* nbytes = dist - nbytes */
+        cmpl    $0, write(%esp)
+        jne     .L_wrap_around_window   /* if (write != 0) */
+
+        subl    nbytes_r, %eax
+        addl    %eax, from_r            /* from += wsize - nbytes */
+
+        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *       %ecx = nbytes, %eax = len
+         *
+         *     if (nbytes < len) {
+         *       len -= nbytes;
+         *       do {
+         *         PUP(out) = PUP(from);
+         *       } while (--nbytes);
+         *       from = out - dist;
+         *     }
+         *   }
+         */
+#define len_r %eax
+        movl    len(%esp), len_r
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1             /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1
+
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1             /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1
+
+.L_wrap_around_window:
+        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *       %ecx = nbytes, %eax = write, %eax = len
+         *
+         *   else if (write < nbytes) {
+         *     from += wsize + write - nbytes;
+         *     nbytes -= write;
+         *     if (nbytes < len) {
+         *       len -= nbytes;
+         *       do {
+         *         PUP(out) = PUP(from);
+         *       } while (--nbytes);
+         *       from = window;
+         *       nbytes = write;
+         *       if (nbytes < len) {
+         *         len -= nbytes;
+         *         do {
+         *           PUP(out) = PUP(from);
+         *         } while(--nbytes);
+         *         from = out - dist;
+         *       }
+         *     }
+         *   }
+         */
+#define write_r %eax
+        movl    write(%esp), write_r
+        cmpl    write_r, nbytes_r
+        jbe     .L_contiguous_in_window /* if (write >= nbytes) */
+
+        addl    wsize(%esp), from_r
+        addl    write_r, from_r
+        subl    nbytes_r, from_r        /* from += wsize + write - nbytes */
+        subl    write_r, nbytes_r       /* nbytes -= write */
+#undef write_r
+
+        movl    len(%esp), len_r
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1             /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    window(%esp), from_r    /* from = window */
+        movl    write(%esp), nbytes_r   /* nbytes = write */
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1             /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1
+
+.L_contiguous_in_window:
+        /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
+         *       %ecx = nbytes, %eax = write, %eax = len
+         *
+         *   else {
+         *     from += write - nbytes;
+         *     if (nbytes < len) {
+         *       len -= nbytes;
+         *       do {
+         *         PUP(out) = PUP(from);
+         *       } while (--nbytes);
+         *       from = out - dist;
+         *     }
+         *   }
+         */
+#define write_r %eax
+        addl    write_r, from_r
+        subl    nbytes_r, from_r        /* from += write - nbytes */
+#undef write_r
+
+        movl    len(%esp), len_r
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1             /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+
+.L_do_copy1:
+        /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out
+         *       %eax = len
+         *
+         *     while (len > 0) {
+         *       PUP(out) = PUP(from);
+         *       len--;
+         *     }
+         *   }
+         * } while (in < last && out < end);
+         */
+#undef nbytes_r
+#define in_r %esi
+        movl    len_r, %ecx
+        rep     movsb
+
+        movl    in(%esp), in_r          /* move in back to %esi, toss from */
+        jmp     .L_while_test
+
+#undef len_r
+#undef dist_r
+
+#endif /* NO_MMX || RUN_TIME_MMX */
+
+
+/*** MMX code ***/
+
+#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
+
+.align 32,0x90
+.L_init_mmx:
+        emms
+
+#undef  bits_r
+#undef  bitslong_r
+#define bitslong_r %ebp
+#define hold_mm    %mm0
+        movd    %ebp, hold_mm
+        movl    %ebx, bitslong_r
+
+#define used_mm   %mm1
+#define dmask2_mm %mm2
+#define lmask2_mm %mm3
+#define lmask_mm  %mm4
+#define dmask_mm  %mm5
+#define tmp_mm    %mm6
+
+        movd    lmask(%esp), lmask_mm 
+        movq    lmask_mm, lmask2_mm
+        movd    dmask(%esp), dmask_mm
+        movq    dmask_mm, dmask2_mm
+        pxor    used_mm, used_mm
+        movl    lcode(%esp), %ebx       /* ebx = lcode */
+        jmp     .L_do_loop_mmx
+
+.align 32,0x90
+.L_while_test_mmx:
+        /* while (in < last && out < end)
+         */
+        cmpl    out_r, end(%esp)
+        jbe     .L_break_loop           /* if (out >= end) */
+
+        cmpl    in_r, last(%esp)
+        jbe     .L_break_loop
+
+.L_do_loop_mmx:
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+
+        cmpl    $32, bitslong_r
+        ja      .L_get_length_code_mmx  /* if (32 < bits) */
+
+        movd    bitslong_r, tmp_mm
+        movd    (in_r), %mm7
+        addl    $4, in_r
+        psllq   tmp_mm, %mm7
+        addl    $32, bitslong_r
+        por     %mm7, hold_mm           /* hold_mm |= *((uint *)in)++ << bits */
+
+.L_get_length_code_mmx:
+        pand    hold_mm, lmask_mm
+        movd    lmask_mm, %eax
+        movq    lmask2_mm, lmask_mm
+        movl    (%ebx,%eax,4), %eax     /* eax = lcode[hold & lmask] */
+
+.L_dolen_mmx:
+        movzbl  %ah, %ecx               /* ecx = this.bits */
+        movd    %ecx, used_mm
+        subl    %ecx, bitslong_r        /* bits -= this.bits */
+
+        testb   %al, %al
+        jnz     .L_test_for_length_base_mmx /* if (op != 0) 45.7% */
+
+        shrl    $16, %eax               /* output this.val char */
+        stosb
+        jmp     .L_while_test_mmx
+
+.L_test_for_length_base_mmx:
+#define len_r  %edx
+        movl    %eax, len_r             /* len = this */
+        shrl    $16, len_r              /* len = this.val */
+
+        testb   $16, %al
+        jz      .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */
+        andl    $15, %eax               /* op &= 15 */
+        jz      .L_decode_distance_mmx  /* if (!op) */
+
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+        movd    %eax, used_mm
+        movd    hold_mm, %ecx
+        subl    %eax, bitslong_r
+        andl    .L_mask(,%eax,4), %ecx
+        addl    %ecx, len_r             /* len += hold & mask[op] */
+
+.L_decode_distance_mmx:
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+
+        cmpl    $32, bitslong_r
+        ja      .L_get_dist_code_mmx    /* if (32 < bits) */
+
+        movd    bitslong_r, tmp_mm
+        movd    (in_r), %mm7
+        addl    $4, in_r
+        psllq   tmp_mm, %mm7
+        addl    $32, bitslong_r
+        por     %mm7, hold_mm           /* hold_mm |= *((uint *)in)++ << bits */
+
+.L_get_dist_code_mmx:
+        movl    dcode(%esp), %ebx       /* ebx = dcode */
+        pand    hold_mm, dmask_mm
+        movd    dmask_mm, %eax
+        movq    dmask2_mm, dmask_mm
+        movl    (%ebx,%eax,4), %eax     /* eax = dcode[hold & lmask] */
+
+.L_dodist_mmx:
+#define dist_r %ebx
+        movzbl  %ah, %ecx               /* ecx = this.bits */
+        movl    %eax, dist_r
+        shrl    $16, dist_r             /* dist  = this.val */
+        subl    %ecx, bitslong_r        /* bits -= this.bits */
+        movd    %ecx, used_mm
+
+        testb   $16, %al                /* if ((op & 16) == 0) */
+        jz      .L_test_for_second_level_dist_mmx
+        andl    $15, %eax               /* op &= 15 */
+        jz      .L_check_dist_one_mmx
+
+.L_add_bits_to_dist_mmx:
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+        movd    %eax, used_mm           /* save bit length of current op */
+        movd    hold_mm, %ecx           /* get the next bits on input stream */
+        subl    %eax, bitslong_r        /* bits -= op bits */
+        andl    .L_mask(,%eax,4), %ecx  /* ecx   = hold & mask[op] */
+        addl    %ecx, dist_r            /* dist += hold & mask[op] */
+
+.L_check_window_mmx:
+        movl    in_r, in(%esp)          /* save in so from can use it's reg */
+        movl    out_r, %eax
+        subl    beg(%esp), %eax         /* nbytes = out - beg */
+
+        cmpl    dist_r, %eax
+        jb      .L_clip_window_mmx      /* if (dist > nbytes) 4.2% */
+
+        movl    len_r, %ecx
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+
+        subl    $3, %ecx
+        movb    (from_r), %al
+        movb    %al, (out_r)
+        movb    1(from_r), %al
+        movb    2(from_r), %dl
+        addl    $3, from_r
+        movb    %al, 1(out_r)
+        movb    %dl, 2(out_r)
+        addl    $3, out_r
+        rep     movsb
+
+        movl    in(%esp), in_r          /* move in back to %esi, toss from */
+        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */
+        jmp     .L_while_test_mmx
+
+.align 16,0x90
+.L_check_dist_one_mmx:
+        cmpl    $1, dist_r
+        jne     .L_check_window_mmx
+        cmpl    out_r, beg(%esp)
+        je      .L_check_window_mmx
+
+        decl    out_r
+        movl    len_r, %ecx
+        movb    (out_r), %al
+        subl    $3, %ecx
+
+        movb    %al, 1(out_r)
+        movb    %al, 2(out_r)
+        movb    %al, 3(out_r)
+        addl    $4, out_r
+        rep     stosb
+
+        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */
+        jmp     .L_while_test_mmx
+
+.align 16,0x90
+.L_test_for_second_level_length_mmx: 
+        testb   $64, %al
+        jnz     .L_test_for_end_of_block  /* if ((op & 64) != 0) */
+
+        andl    $15, %eax
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+        movd    hold_mm, %ecx
+        andl    .L_mask(,%eax,4), %ecx
+        addl    len_r, %ecx
+        movl    (%ebx,%ecx,4), %eax     /* eax = lcode[hold & lmask] */
+        jmp     .L_dolen_mmx
+
+.align 16,0x90
+.L_test_for_second_level_dist_mmx:
+        testb   $64, %al
+        jnz     .L_invalid_distance_code  /* if ((op & 64) != 0) */
+
+        andl    $15, %eax
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+        movd    hold_mm, %ecx
+        andl    .L_mask(,%eax,4), %ecx
+        movl    dcode(%esp), %eax       /* ecx = dcode */
+        addl    dist_r, %ecx
+        movl    (%eax,%ecx,4), %eax     /* eax = lcode[hold & lmask] */
+        jmp     .L_dodist_mmx
+
+.align 16,0x90
+.L_clip_window_mmx:
+#define nbytes_r %ecx
+        movl    %eax, nbytes_r
+        movl    wsize(%esp), %eax       /* prepare for dist compare */
+        negl    nbytes_r                /* nbytes = -nbytes */
+        movl    window(%esp), from_r    /* from = window */
+
+        cmpl    dist_r, %eax
+        jb      .L_invalid_distance_too_far /* if (dist > wsize) */
+
+        addl    dist_r, nbytes_r        /* nbytes = dist - nbytes */
+        cmpl    $0, write(%esp)
+        jne     .L_wrap_around_window_mmx /* if (write != 0) */
+
+        subl    nbytes_r, %eax
+        addl    %eax, from_r            /* from += wsize - nbytes */
+
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1_mmx         /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1_mmx
+
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1_mmx         /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1_mmx
+
+.L_wrap_around_window_mmx:
+#define write_r %eax
+        movl    write(%esp), write_r
+        cmpl    write_r, nbytes_r
+        jbe     .L_contiguous_in_window_mmx /* if (write >= nbytes) */
+
+        addl    wsize(%esp), from_r
+        addl    write_r, from_r
+        subl    nbytes_r, from_r        /* from += wsize + write - nbytes */
+        subl    write_r, nbytes_r       /* nbytes -= write */
+#undef write_r
+
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1_mmx         /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    window(%esp), from_r    /* from = window */
+        movl    write(%esp), nbytes_r   /* nbytes = write */
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1_mmx         /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+        jmp     .L_do_copy1_mmx
+
+.L_contiguous_in_window_mmx:
+#define write_r %eax
+        addl    write_r, from_r
+        subl    nbytes_r, from_r        /* from += write - nbytes */
+#undef write_r
+
+        cmpl    nbytes_r, len_r
+        jbe     .L_do_copy1_mmx         /* if (nbytes >= len) */
+
+        subl    nbytes_r, len_r         /* len -= nbytes */
+        rep     movsb
+        movl    out_r, from_r
+        subl    dist_r, from_r          /* from = out - dist */
+
+.L_do_copy1_mmx:
+#undef nbytes_r
+#define in_r %esi
+        movl    len_r, %ecx
+        rep     movsb
+
+        movl    in(%esp), in_r          /* move in back to %esi, toss from */
+        movl    lcode(%esp), %ebx       /* move lcode back to %ebx, toss dist */
+        jmp     .L_while_test_mmx
+
+#undef hold_r
+#undef bitslong_r
+
+#endif /* USE_MMX || RUN_TIME_MMX */
+
+
+/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/
+
+.L_invalid_distance_code:
+        /* else {
+         *   strm->msg = "invalid distance code";
+         *   state->mode = BAD;
+         * }
+         */
+        movl    $.L_invalid_distance_code_msg, %ecx
+        movl    $INFLATE_MODE_BAD, %edx
+        jmp     .L_update_stream_state
+
+.L_test_for_end_of_block:
+        /* else if (op & 32) {
+         *   state->mode = TYPE;
+         *   break;
+         * }
+         */
+        testb   $32, %al
+        jz      .L_invalid_literal_length_code  /* if ((op & 32) == 0) */
+
+        movl    $0, %ecx
+        movl    $INFLATE_MODE_TYPE, %edx
+        jmp     .L_update_stream_state
+
+.L_invalid_literal_length_code:
+        /* else {
+         *   strm->msg = "invalid literal/length code";
+         *   state->mode = BAD;
+         * }
+         */
+        movl    $.L_invalid_literal_length_code_msg, %ecx
+        movl    $INFLATE_MODE_BAD, %edx
+        jmp     .L_update_stream_state
+
+.L_invalid_distance_too_far:
+        /* strm->msg = "invalid distance too far back";
+         * state->mode = BAD;
+         */
+        movl    in(%esp), in_r          /* from_r has in's reg, put in back */
+        movl    $.L_invalid_distance_too_far_msg, %ecx
+        movl    $INFLATE_MODE_BAD, %edx
+        jmp     .L_update_stream_state
+
+.L_update_stream_state:
+        /* set strm->msg = %ecx, strm->state->mode = %edx */
+        movl    strm_sp(%esp), %eax
+        testl   %ecx, %ecx              /* if (msg != NULL) */
+        jz      .L_skip_msg
+        movl    %ecx, msg_strm(%eax)    /* strm->msg = msg */
+.L_skip_msg:
+        movl    state_strm(%eax), %eax  /* state = strm->state */
+        movl    %edx, mode_state(%eax)  /* state->mode = edx (BAD | TYPE) */
+        jmp     .L_break_loop
+
+.align 32,0x90
+.L_break_loop:
+
+/*
+ * Regs:
+ *
+ * bits = %ebp when mmx, and in %ebx when non-mmx
+ * hold = %hold_mm when mmx, and in %ebp when non-mmx
+ * in   = %esi
+ * out  = %edi
+ */
+
+#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
+
+#if defined( RUN_TIME_MMX )
+
+        cmpl    $DO_USE_MMX, inflate_fast_use_mmx
+        jne     .L_update_next_in
+
+#endif /* RUN_TIME_MMX */
+
+        movl    %ebp, %ebx
+
+.L_update_next_in:
+
+#endif
+
+#define strm_r  %eax
+#define state_r %edx
+
+        /* len = bits >> 3;
+         * in -= len;
+         * bits -= len << 3;
+         * hold &= (1U << bits) - 1;
+         * state->hold = hold;
+         * state->bits = bits;
+         * strm->next_in = in;
+         * strm->next_out = out;
+         */
+        movl    strm_sp(%esp), strm_r
+        movl    %ebx, %ecx
+        movl    state_strm(strm_r), state_r
+        shrl    $3, %ecx
+        subl    %ecx, in_r
+        shll    $3, %ecx
+        subl    %ecx, %ebx
+        movl    out_r, next_out_strm(strm_r)
+        movl    %ebx, bits_state(state_r)
+        movl    %ebx, %ecx
+
+        leal    buf(%esp), %ebx
+        cmpl    %ebx, last(%esp)
+        jne     .L_buf_not_used         /* if buf != last */
+
+        subl    %ebx, in_r              /* in -= buf */
+        movl    next_in_strm(strm_r), %ebx
+        movl    %ebx, last(%esp)        /* last = strm->next_in */
+        addl    %ebx, in_r              /* in += strm->next_in */
+        movl    avail_in_strm(strm_r), %ebx
+        subl    $11, %ebx
+        addl    %ebx, last(%esp)    /* last = &strm->next_in[ avail_in - 11 ] */
+
+.L_buf_not_used:
+        movl    in_r, next_in_strm(strm_r)
+
+        movl    $1, %ebx
+        shll    %cl, %ebx
+        decl    %ebx
+
+#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
+
+#if defined( RUN_TIME_MMX )
+
+        cmpl    $DO_USE_MMX, inflate_fast_use_mmx
+        jne     .L_update_hold
+
+#endif /* RUN_TIME_MMX */
+
+        psrlq   used_mm, hold_mm        /* hold_mm >>= last bit length */
+        movd    hold_mm, %ebp
+
+        emms
+
+.L_update_hold:
+
+#endif /* USE_MMX || RUN_TIME_MMX */
+
+        andl    %ebx, %ebp
+        movl    %ebp, hold_state(state_r)
+
+#define last_r %ebx
+
+        /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */
+        movl    last(%esp), last_r
+        cmpl    in_r, last_r
+        jbe     .L_last_is_smaller     /* if (in >= last) */
+
+        subl    in_r, last_r           /* last -= in */
+        addl    $11, last_r            /* last += 11 */
+        movl    last_r, avail_in_strm(strm_r)
+        jmp     .L_fixup_out
+.L_last_is_smaller:
+        subl    last_r, in_r           /* in -= last */
+        negl    in_r                   /* in = -in */
+        addl    $11, in_r              /* in += 11 */
+        movl    in_r, avail_in_strm(strm_r)
+
+#undef last_r
+#define end_r %ebx
+
+.L_fixup_out:
+        /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/
+        movl    end(%esp), end_r
+        cmpl    out_r, end_r
+        jbe     .L_end_is_smaller      /* if (out >= end) */
+
+        subl    out_r, end_r           /* end -= out */
+        addl    $257, end_r            /* end += 257 */
+        movl    end_r, avail_out_strm(strm_r)
+        jmp     .L_done
+.L_end_is_smaller:
+        subl    end_r, out_r           /* out -= end */
+        negl    out_r                  /* out = -out */
+        addl    $257, out_r            /* out += 257 */
+        movl    out_r, avail_out_strm(strm_r)
+
+#undef end_r
+#undef strm_r
+#undef state_r
+
+.L_done:
+        addl    $local_var_size, %esp
+        popf
+        popl    %ebx
+        popl    %ebp
+        popl    %esi
+        popl    %edi
+        ret
+
+#if defined( GAS_ELF )
+/* elf info */
+.type inflate_fast,@function
+.size inflate_fast,.-inflate_fast
+#endif
index 9987c54..18316fc 100644 (file)
@@ -1,3 +1,12 @@
+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
 
index a1dfc16..84eaad2 100644 (file)
@@ -1,8 +1,8 @@
 CC=cc
 CFLAGS=-O -I../..
 
-UNZ_OBJS = miniunz.o unzip.o ../../libz.a
-ZIP_OBJS = minizip.o zip.o   ../../libz.a
+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
diff --git a/zlib/contrib/minizip/crypt.h b/zlib/contrib/minizip/crypt.h
new file mode 100644 (file)
index 0000000..e5bc627
--- /dev/null
@@ -0,0 +1,104 @@
+
+#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
diff --git a/zlib/contrib/minizip/ioapi.c b/zlib/contrib/minizip/ioapi.c
new file mode 100644 (file)
index 0000000..d35d5f5
--- /dev/null
@@ -0,0 +1,177 @@
+/* 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;
+}
diff --git a/zlib/contrib/minizip/ioapi.h b/zlib/contrib/minizip/ioapi.h
new file mode 100644 (file)
index 0000000..f30fe7a
--- /dev/null
@@ -0,0 +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
+
diff --git a/zlib/contrib/minizip/iowin32.c b/zlib/contrib/minizip/iowin32.c
new file mode 100644 (file)
index 0000000..f1f5546
--- /dev/null
@@ -0,0 +1,271 @@
+/* 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;
+}
diff --git a/zlib/contrib/minizip/iowin32.h b/zlib/contrib/minizip/iowin32.h
new file mode 100644 (file)
index 0000000..d2f5e37
--- /dev/null
@@ -0,0 +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
index f3b7832..938d4ef 100644 (file)
 
 #define CASESENSITIVITY (0)
 #define WRITEBUFFERSIZE (8192)
+#define MAXFILENAME (256)
 
+#ifdef WIN32
+#define USEWIN32IOAPI
+#include "iowin32.h"
+#endif
 /*
   mini unzip, demo of unzip package
 
@@ -34,9 +39,9 @@
     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;
+    const char *filename;
+    uLong dosdate;
+    tm_unz tmu_date;
 {
 #ifdef WIN32
   HANDLE hFile;
@@ -75,17 +80,17 @@ void change_file_date(filename,dosdate,tmu_date)
    As I don't know well Unix, I wait feedback for the unix portion */
 
 int mymkdir(dirname)
-       const char* dirname;
+    const char* dirname;
 {
     int ret=0;
 #ifdef WIN32
-       ret = mkdir(dirname);
+    ret = mkdir(dirname);
 #else
 #ifdef unix
-       ret = mkdir (dirname,0775);
+    ret = mkdir (dirname,0775);
 #endif
 #endif
-       return ret;
+    return ret;
 }
 
 int makedir (newdir)
@@ -93,14 +98,14 @@ int makedir (newdir)
 {
   char *buffer ;
   char *p;
-  int  len = strlen(newdir);  
+  int  len = (int)strlen(newdir);
 
-  if (len <= 0) 
+  if (len <= 0)
     return 0;
 
   buffer = (char*)malloc(len+1);
   strcpy(buffer,newdir);
-  
+
   if (buffer[len-1] == '/') {
     buffer[len-1] = '\0';
   }
@@ -135,104 +140,105 @@ int makedir (newdir)
 
 void do_banner()
 {
-       printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n");
-       printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
+    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") ;
+{
+    printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ;
 }
 
 
 int do_list(uf)
-       unzFile uf;
+    unzFile uf;
 {
-       uLong i;
-       unz_global_info gi;
-       int err;
+    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);
+    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,
+    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;
+                (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)
-       unzFile uf;
-       const int* popt_extract_without_path;
+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;
+    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;
-       }
+    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);
@@ -242,71 +248,71 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
         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 = unzOpenCurrentFile(uf);
-               if (err!=UNZ_OK)
-               {
-                       printf("error %d with zipfile in unzOpenCurrentFile\n",err);
-               }
-
-               if (((*popt_overwrite)==0) && (err==UNZ_OK))
-               {
-                       char rep;
-                       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");
+    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) && 
+            if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
                                 (filename_withoutpath!=(char*)filename_inzip))
             {
                 char c=*(filename_withoutpath-1);
@@ -316,95 +322,100 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
                 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");
+            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);
-                       fclose(fout);
-                       if (err==0) 
-                               change_file_date(write_filename,file_info.dosDate,
-                                                    file_info.tmu_date);
-               }
+                        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);
-                   }
+            err = unzCloseCurrentFile (uf);
+            if (err!=UNZ_OK)
+            {
+                printf("error %d with zipfile in unzCloseCurrentFile\n",err);
+            }
         }
         else
-            unzCloseCurrentFile(uf); /* don't lose the error */       
-       }
+            unzCloseCurrentFile(uf); /* don't lose the error */
+    }
 
-    free(buf);    
+    free(buf);
     return err;
 }
 
 
-int do_extract(uf,opt_extract_without_path,opt_overwrite)
-       unzFile uf;
-       int opt_extract_without_path;
+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;        
+    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);
+    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++)
-       {
+    for (i=0;i<gi.number_entry;i++)
+    {
         if (do_extract_currentfile(uf,&opt_extract_without_path,
-                                      &opt_overwrite) != UNZ_OK)
+                                      &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;
+        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)
-       unzFile uf;
-       const char* filename;
-       int opt_extract_without_path;
+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)
@@ -414,7 +425,8 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
     }
 
     if (do_extract_currentfile(uf,&opt_extract_without_path,
-                                      &opt_overwrite) == UNZ_OK)
+                                      &opt_overwrite,
+                                      password) == UNZ_OK)
         return 0;
     else
         return 1;
@@ -422,87 +434,110 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
 
 
 int main(argc,argv)
-       int argc;
-       char *argv[];
+    int argc;
+    char *argv[];
 {
-       const char *zipfilename=NULL;
+    const char *zipfilename=NULL;
     const char *filename_to_extract=NULL;
-       int i;
-       int opt_do_list=0;
-       int opt_do_extract=1;
-       int opt_do_extract_withoutpath=0;
-       int opt_overwrite=0;
-       char filename_try[512];
-       unzFile uf=NULL;
-
-       do_banner();
-       if (argc==1)
-       {
-               do_help();
-               exit(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;
-                               }
-                       }
-                       else
+    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];
+                if (zipfilename == NULL)
+                    zipfilename = argv[i];
                 else if (filename_to_extract==NULL)
                         filename_to_extract = argv[i] ;
             }
-               }
-       }
-
-       if (zipfilename!=NULL)
-       {
-               strcpy(filename_try,zipfilename);
-               uf = unzOpen(zipfilename);
-               if (uf==NULL)
-               {
-                       strcat(filename_try,".zip");
-                       uf = unzOpen(filename_try);
-               }
-       }
-
-       if (uf==NULL)
-       {
-               printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
-               exit (1);
-       }
+        }
+    }
+
+    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 (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);
+            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);
+                                      opt_do_extract_withoutpath,opt_overwrite,password);
     }
-       unzCloseCurrentFile(uf);
+    unzCloseCurrentFile(uf);
 
-       return 0;  /* to avoid warning */
+    return 0;
 }
index 5e492d2..5792a1e 100644 (file)
 
 #include "zip.h"
 
+#ifdef WIN32
+#define USEWIN32IOAPI
+#include "iowin32.h"
+#endif
+
+
 
 #define WRITEBUFFERSIZE (16384)
 #define MAXFILENAME (256)
@@ -55,12 +61,16 @@ uLong filetime(f, tmzip, dt)
   struct stat s;        /* results of stat() */
   struct tm* filedate;
   time_t tm_t=0;
-  
+
   if (strcmp(f,"-")!=0)
   {
-    char name[MAXFILENAME];
+    char name[MAXFILENAME+1];
     int len = strlen(f);
-    strcpy(name, 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 */
@@ -98,10 +108,10 @@ uLong filetime(f, tmzip, dt)
 int check_exist_file(filename)
     const char* filename;
 {
-       FILE* ftestexist;
+    FILE* ftestexist;
     int ret = 1;
-       ftestexist = fopen(filename,"rb");
-       if (ftestexist==NULL)
+    ftestexist = fopen(filename,"rb");
+    if (ftestexist==NULL)
         ret = 0;
     else
         fclose(ftestexist);
@@ -110,59 +120,107 @@ int check_exist_file(filename)
 
 void do_banner()
 {
-       printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
-       printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
+    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") ;
+{
+    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 argc;
+    char *argv[];
 {
-       int i;
-       int opt_overwrite=0;
+    int i;
+    int opt_overwrite=0;
     int opt_compress_level=Z_DEFAULT_COMPRESSION;
     int zipfilenamearg = 0;
-       char filename_try[MAXFILENAME];
+    char filename_try[MAXFILENAME+16];
     int zipok;
     int err=0;
     int size_buf=0;
-    void* buf=NULL,
+    void* buf=NULL;
+    const char* password=NULL;
 
 
-       do_banner();
-       if (argc==1)
-       {
-               do_help();
-               exit(0);
+    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;
+    }
+    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';
-                               }
-                       }
-                       else
-                               if (zipfilenamearg == 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);
@@ -172,16 +230,19 @@ int main(argc,argv)
         return ZIP_INTERNALERROR;
     }
 
-       if (zipfilenamearg==0)
+    if (zipfilenamearg==0)
         zipok=0;
     else
-       {
+    {
         int i,len;
         int dot_found=0;
 
         zipok = 1 ;
-               strcpy(filename_try,argv[zipfilenamearg]);
-        len=strlen(filename_try);
+        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;
@@ -189,36 +250,52 @@ int main(argc,argv)
         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;
-                               do
-                               {
-                                       char answer[128];
-                                       printf("The file %s exist. Overwrite ? [y]es, [n]o : ",filename_try);
-                                       scanf("%1s",answer);
-                                       rep = answer[0] ;
-                                       if ((rep>='a') && (rep<='z'))
-                                               rep -= 0x20;
-                               }
-                               while ((rep!='Y') && (rep!='N'));
+            {
+                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;
-        zf = zipOpen(filename_try,0);
+        #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 
+        else
             printf("creating %s\n",filename_try);
 
         for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
@@ -229,19 +306,31 @@ int main(argc,argv)
                 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_min = zi.tmz_date.tm_year = 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*/,
+                                 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);
@@ -259,7 +348,7 @@ int main(argc,argv)
                     do
                     {
                         err = ZIP_OK;
-                        size_read = fread(buf,1,size_buf,fin);
+                        size_read = (int)fread(buf,1,size_buf,fin);
                         if (size_read < size_buf)
                             if (feof(fin)==0)
                         {
@@ -275,15 +364,17 @@ int main(argc,argv)
                                 printf("error in writing %s in the zipfile\n",
                                                  filenameinzip);
                             }
-                                
+
                         }
                     } while ((err == ZIP_OK) && (size_read>0));
 
-                fclose(fin);
+                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",
@@ -297,6 +388,5 @@ int main(argc,argv)
    }
 
     free(buf);
-    exit(0);
-       return 0;  /* to avoid warning */
+    return 0;
 }
diff --git a/zlib/contrib/minizip/readme.txt b/zlib/contrib/minizip/readme.txt
deleted file mode 100644 (file)
index 1fc023c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-UnZip 0.15 additionnal library
-
-
-  This unzip package allow extract file from .ZIP file, compatible with 
-PKZip 2.04g, WinZip, InfoZip tools and compatible.
-
-  Multi volume ZipFile (span) are not supported, and old compression used by old 
-PKZip 1.x are not supported.
-
-See probdesc.zip from PKWare for specification of .ZIP format.
-
-What is Unzip
-  The Zlib library support the deflate compression and the creation of gzip (.gz) 
-file. Zlib is free and small.
-  The .Zip format, which can contain several compressed files (.gz can containt
-only one file) is a very popular format. This is why I've written a package for reading file compressed in Zipfile.
-
-Using Unzip package
-
-You need source of Zlib (get zlib111.zip and read zlib.h).
-Get unzlb015.zip and read unzip.h (whith documentation of unzip functions)
-
-The Unzip package is only two file : unzip.h and unzip.c. But it use the Zlib 
-  files.
-unztst.c is a simple sample program, which list file in a zipfile and display
-  README.TXT or FILE_ID.DIZ (if these files are found).
-miniunz.c is a mini unzip program.
-
-I'm also currenlyt writing a zipping portion (zip.h, zip.c and test with minizip.c)
-
-Please email me for feedback.
-I hope my source is compatible with Unix system, but I need your help for be sure
-
-Latest revision : Mar 04th, 1998
-
-Check http://www.winimage.com/zLibDll/unzip.html for up to date info.
index ff71a47..7244523 100644 (file)
@@ -1,9 +1,39 @@
-/* unzip.c -- IO on .zip files using zlib 
-   Version 0.15 beta, Mar 19th, 1998,
+/* 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>
 #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
 
 const char unz_copyright[] =
-   " unzip 0.15 Copyright 1998 Gilles Vollant ";
+   " 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
@@ -83,23 +101,25 @@ typedef struct unz_file_info_internal_s
     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*/
-       FILE* file;                 /* io structore of the zipfile */
-       uLong compression_method;   /* compression method (0==store) */
-       uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
+    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;
 
 
@@ -107,25 +127,35 @@ typedef struct
 */
 typedef struct
 {
-       FILE* file;                 /* 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*/
+    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 */
+                                        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.
@@ -133,12 +163,18 @@ typedef struct
 */
 
 
-local int unzlocal_getByte(fin,pi)
-       FILE *fin;
-       int *pi;
+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 = fread(&c, 1, 1, fin);
+    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
     if (err==1)
     {
         *pi = (int)c;
@@ -146,7 +182,7 @@ local int unzlocal_getByte(fin,pi)
     }
     else
     {
-        if (ferror(fin)) 
+        if (ZERROR(*pzlib_filefunc_def,filestream))
             return UNZ_ERRNO;
         else
             return UNZ_EOF;
@@ -155,23 +191,29 @@ local int unzlocal_getByte(fin,pi)
 
 
 /* ===========================================================================
-   Reads a long in LSB order from the given gz_stream. Sets 
+   Reads a long in LSB order from the given gz_stream. Sets
 */
-local int unzlocal_getShort (fin,pX)
-       FILE* fin;
+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(fin,&i);
+    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x = (uLong)i;
-    
+
     if (err==UNZ_OK)
-        err = unzlocal_getByte(fin,&i);
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x += ((uLong)i)<<8;
-   
+
     if (err==UNZ_OK)
         *pX = x;
     else
@@ -179,29 +221,35 @@ local int unzlocal_getShort (fin,pX)
     return err;
 }
 
-local int unzlocal_getLong (fin,pX)
-       FILE* fin;
+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(fin,&i);
+    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x = (uLong)i;
-    
+
     if (err==UNZ_OK)
-        err = unzlocal_getByte(fin,&i);
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x += ((uLong)i)<<8;
 
     if (err==UNZ_OK)
-        err = unzlocal_getByte(fin,&i);
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x += ((uLong)i)<<16;
 
     if (err==UNZ_OK)
-        err = unzlocal_getByte(fin,&i);
+        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
     x += ((uLong)i)<<24;
-   
+
     if (err==UNZ_OK)
         *pX = x;
     else
@@ -212,26 +260,26 @@ local int unzlocal_getLong (fin,pX)
 
 /* My own strcmpi / strcasecmp */
 local int strcmpcasenosensitive_internal (fileName1,fileName2)
-       const char* fileName1;
-       const char* 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;
-       }
+    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;
+    }
 }
 
 
@@ -245,7 +293,7 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
 #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
@@ -255,203 +303,225 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
 
 */
 extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
-       const char* fileName1;
-       const char* fileName2;
-       int iCaseSensitivity;
+    const char* fileName1;
+    const char* fileName2;
+    int iCaseSensitivity;
 {
-       if (iCaseSensitivity==0)
-               iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
+    if (iCaseSensitivity==0)
+        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
 
-       if (iCaseSensitivity==1)
-               return strcmp(fileName1,fileName2);
+    if (iCaseSensitivity==1)
+        return strcmp(fileName1,fileName2);
 
-       return STRCMPCASENOSENTIVEFUNCTION(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(fin)
-       FILE *fin;
+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 (fseek(fin,0,SEEK_END) != 0)
-               return 0;
-
-
-       uSizeFile = ftell( fin );
-       
-       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)) ? 
+    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 (fseek(fin,uReadPos,SEEK_SET)!=0)
-                       break;
-
-               if (fread(buf,(uInt)uReadSize,1,fin)!=1)
-                       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;
+        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\\zlib109.zip" or on an Unix computer
-        "zlib/zlib109.zip".
-        If the zipfile cannot be opened (file don't exist or in not valid), the
-          return value is NULL.
+     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.
+       of this unzip package.
 */
-extern unzFile ZEXPORT unzOpen (path)
-       const char *path;
+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;
-       FILE * fin ;
+    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) */
+    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;
+    int err=UNZ_OK;
 
     if (unz_copyright[0]!=' ')
         return NULL;
 
-    fin=fopen(path,"rb");
-       if (fin==NULL)
-               return NULL;
-
-       central_pos = unzlocal_SearchCentralDir(fin);
-       if (central_pos==0)
-               err=UNZ_ERRNO;
-
-       if (fseek(fin,central_pos,SEEK_SET)!=0)
-               err=UNZ_ERRNO;
-
-       /* the signature, already checked */
-       if (unzlocal_getLong(fin,&uL)!=UNZ_OK)
-               err=UNZ_ERRNO;
-
-       /* number of this disk */
-       if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)
-               err=UNZ_ERRNO;
-
-       /* number of the disk with the start of the central directory */
-       if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)
-               err=UNZ_ERRNO;
-
-       /* total number of entries in the central dir on this disk */
-       if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)
-               err=UNZ_ERRNO;
-
-       /* total number of entries in the central dir */
-       if (unzlocal_getShort(fin,&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(fin,&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(fin,&us.offset_central_dir)!=UNZ_OK)
-               err=UNZ_ERRNO;
-
-       /* zipfile comment length */
-       if (unzlocal_getShort(fin,&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)
-       {
-               fclose(fin);
-               return NULL;
-       }
-
-       us.file=fin;
-       us.byte_before_the_zipfile = central_pos -
-                                   (us.offset_central_dir+us.size_central_dir);
-       us.central_pos = central_pos;
+    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;      
+
+    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;
+    unzFile file;
 {
-       unz_s* s;
-       if (file==NULL)
-               return UNZ_PARAMERROR;
-       s=(unz_s*)file;
+    unz_s* s;
+    if (file==NULL)
+        return UNZ_PARAMERROR;
+    s=(unz_s*)file;
 
     if (s->pfile_in_zip_read!=NULL)
         unzCloseCurrentFile(file);
 
-       fclose(s->file);
-       TRYFREE(s);
-       return UNZ_OK;
+    ZCLOSE(s->z_filefunc, s->filestream);
+    TRYFREE(s);
+    return UNZ_OK;
 }
 
 
@@ -460,15 +530,15 @@ extern int ZEXPORT unzClose (file)
   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;
+    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;
+    unz_s* s;
+    if (file==NULL)
+        return UNZ_PARAMERROR;
+    s=(unz_s*)file;
+    *pglobal_info=s->gi;
+    return UNZ_OK;
 }
 
 
@@ -495,14 +565,14 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
 */
 local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
                                                   unz_file_info *pfile_info,
-                                                  unz_file_info_internal 
+                                                  unz_file_info_internal
                                                   *pfile_info_internal,
                                                   char *szFileName,
-                                                                                                 uLong fileNameBufferSize,
+                                                  uLong fileNameBufferSize,
                                                   void *extraField,
-                                                                                                 uLong extraFieldBufferSize,
+                                                  uLong extraFieldBufferSize,
                                                   char *szComment,
-                                                                                                 uLong commentBufferSize));
+                                                  uLong commentBufferSize));
 
 local int unzlocal_GetCurrentFileInfoInternal (file,
                                               pfile_info,
@@ -510,156 +580,158 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
                                               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;
+    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 (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
-               err=UNZ_ERRNO;
+    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->file,&uMagic) != UNZ_OK)
-                       err=UNZ_ERRNO;
-               else if (uMagic!=0x02014b50)
-                       err=UNZ_BADZIPFILE;
+    /* 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->file,&file_info.version) != UNZ_OK)
-               err=UNZ_ERRNO;
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
+        err=UNZ_ERRNO;
 
-       if (unzlocal_getShort(s->file,&file_info.version_needed) != 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->file,&file_info.flag) != 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->file,&file_info.compression_method) != 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->file,&file_info.dosDate) != 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->file,&file_info.crc) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)
-               err=UNZ_ERRNO;
-
-       if (unzlocal_getLong(s->file,&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 (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
-                               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 (fseek(s->file,lSeek,SEEK_CUR)==0)
-                               lSeek=0;
-                       else
-                               err=UNZ_ERRNO;
-               if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
-                       if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
-                               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 (fseek(s->file,lSeek,SEEK_CUR)==0)
-                               lSeek=0;
-                       else
-                               err=UNZ_ERRNO;
-               if ((file_info.size_file_comment>0) && (commentBufferSize>0))
-                       if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
-                               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;
+    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;
 }
 
 
@@ -670,23 +742,23 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
   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;
+                                          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);
+    return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
+                                                szFileName,fileNameBufferSize,
+                                                extraField,extraFieldBufferSize,
+                                                szComment,commentBufferSize);
 }
 
 /*
@@ -694,50 +766,49 @@ extern int ZEXPORT unzGetCurrentFileInfo (file,
   return UNZ_OK if there is no problem
 */
 extern int ZEXPORT unzGoToFirstFile (file)
-       unzFile 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;
+    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;
+    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;
+    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;
 }
 
 
@@ -750,52 +821,117 @@ extern int ZEXPORT unzGoToNextFile (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;
+    unzFile file;
+    const char *szFileName;
+    int iCaseSensitivity;
 {
-       unz_s* s;       
-       int err;
+    unz_s* s;
+    int err;
 
-       
-       uLong num_fileSaved;
-       uLong pos_in_central_dirSaved;
 
+    uLong num_fileSaved;
+    uLong pos_in_central_dirSaved;
 
-       if (file==NULL)
-               return UNZ_PARAMERROR;
+
+    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;
+    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
@@ -803,185 +939,256 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
         (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;
+                                                    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;
+    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;
+    *piSizeVar = 0;
+    *poffset_local_extrafield = 0;
+    *psize_local_extrafield = 0;
 
-       if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
-                                                               s->byte_before_the_zipfile,SEEK_SET)!=0)
-               return UNZ_ERRNO;
+    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->file,&uMagic) != UNZ_OK)
-                       err=UNZ_ERRNO;
-               else if (uMagic!=0x04034b50)
-                       err=UNZ_BADZIPFILE;
+    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->file,&uData) != 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.wVersion))
-               err=UNZ_BADZIPFILE;
+    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
+        err=UNZ_BADZIPFILE;
 */
-       if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)
-               err=UNZ_ERRNO;
+    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
+        err=UNZ_ERRNO;
 
-       if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
-               err=UNZ_ERRNO;
-       else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
-               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.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->file,&uData) != UNZ_OK) /* date/time */
-               err=UNZ_ERRNO;
+    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
+        err=UNZ_ERRNO;
 
-       if (unzlocal_getLong(s->file,&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) /* 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->file,&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 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->file,&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_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->file,&size_filename) != UNZ_OK)
-               err=UNZ_ERRNO;
-       else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
-               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;
+    *piSizeVar += (uInt)size_filename;
 
-       if (unzlocal_getShort(s->file,&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;
+    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;
+    *piSizeVar += (uInt)size_extra_field;
 
-       return err;
+    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 unzOpenCurrentFile (file)
-       unzFile file;
+extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
+    unzFile file;
+    int* method;
+    int* level;
+    int raw;
+    const char* password;
 {
-       int err=UNZ_OK;
-       int Store;
-       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 */
-
-       if (file==NULL)
-               return UNZ_PARAMERROR;
-       s=(unz_s*)file;
-       if (!s->current_file_ok)
-               return UNZ_PARAMERROR;
+    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;
-
-       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 ((s->cur_file_info.compression_method!=0) &&
+    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;
-       Store = s->cur_file_info.compression_method==0;
+        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 =
+    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->file=s->file;
-       pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
+    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 (!Store)
-       {
-         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;
+    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 
+         * 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 = 
+    }
+    pfile_in_zip_read_info->rest_read_compressed =
             s->cur_file_info.compressed_size ;
-       pfile_in_zip_read_info->rest_read_uncompressed = 
+    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;
+
+    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
 
 
-       s->pfile_in_zip_read = pfile_in_zip_read_info;
     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.
@@ -994,126 +1201,149 @@ extern int ZEXPORT unzOpenCurrentFile (file)
     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
 */
 extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
-       unzFile file;
-       voidp buf;
-       unsigned 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;
+    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==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;
 
-       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.next_out = (Bytef*)buf;
+    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
 
-       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;
+    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) &&
+    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 (fseek(pfile_in_zip_read_info->file,
-                      pfile_in_zip_read_info->pos_in_zipfile + 
-                         pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
-                               return UNZ_ERRNO;
-                       if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
-                         pfile_in_zip_read_info->file)!=1)
-                               return UNZ_ERRNO;
-                       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 = 
+        {
+            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;
-               }
+            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
+        }
 
-               if (pfile_in_zip_read_info->compression_method==0)
-               {
-                       uInt uDoCopy,i ;
-                       if (pfile_in_zip_read_info->stream.avail_out < 
+        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) =
+                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->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 = 
+            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 -=
+            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;
+            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;
 }
 
 
@@ -1121,42 +1351,42 @@ extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
   Give the current position in uncompressed data
 */
 extern z_off_t ZEXPORT unztell (file)
-       unzFile 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;
+    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==NULL)
+        return UNZ_PARAMERROR;
 
-       return (z_off_t)pfile_in_zip_read_info->stream.total_out;
+    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
 }
 
 
 /*
-  return 1 if the end of file was reached, 0 elsewhere 
+  return 1 if the end of file was reached, 0 elsewhere
 */
 extern int ZEXPORT unzeof (file)
-       unzFile 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;
+    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;
+    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;
 }
 
 
@@ -1169,51 +1399,55 @@ extern int ZEXPORT unzeof (file)
   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
+    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;
+    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;
+    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;
+    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);
+    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 (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 (read_now==0)
-               return 0;
-       
-       if (fseek(pfile_in_zip_read_info->file,
-              pfile_in_zip_read_info->offset_local_extrafield + 
-                         pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
-               return UNZ_ERRNO;
+    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 (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
-               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;
+    return (int)read_now;
 }
 
 /*
@@ -1221,39 +1455,40 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
   Return UNZ_CRCERROR if all the file was read but the CRC is not good
 */
 extern int ZEXPORT unzCloseCurrentFile (file)
-       unzFile file;
+    unzFile file;
 {
-       int err=UNZ_OK;
+    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;
+    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==NULL)
+        return UNZ_PARAMERROR;
 
 
-       if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
-       {
-               if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
-                       err=UNZ_CRCERROR;
-       }
+    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);
+    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);
+    pfile_in_zip_read_info->stream_initialised = 0;
+    TRYFREE(pfile_in_zip_read_info);
 
     s->pfile_in_zip_read=NULL;
 
-       return err;
+    return err;
 }
 
 
@@ -1263,32 +1498,32 @@ extern int ZEXPORT unzCloseCurrentFile (file)
   return the number of byte copied or an error code <0
 */
 extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
-       unzFile file;
-       char *szComment;
-       uLong 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;
+    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;
+    uReadThis = uSizeBuf;
+    if (uReadThis>s->gi.size_comment)
+        uReadThis = s->gi.size_comment;
 
-       if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
-               return UNZ_ERRNO;
+    if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
+        return UNZ_ERRNO;
 
-       if (uReadThis>0)
+    if (uReadThis>0)
     {
       *szComment='\0';
-         if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
-               return UNZ_ERRNO;
+      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;
+    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
+        *(szComment+s->gi.size_comment)='\0';
+    return (int)uReadThis;
 }
diff --git a/zlib/contrib/minizip/unzip.def b/zlib/contrib/minizip/unzip.def
deleted file mode 100644 (file)
index f6ede89..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-       unzOpen                       @61
-       unzClose                      @62
-       unzGetGlobalInfo              @63
-       unzGetCurrentFileInfo         @64
-       unzGoToFirstFile              @65
-       unzGoToNextFile               @66
-       unzOpenCurrentFile            @67
-       unzReadCurrentFile            @68
-       unztell                       @70
-       unzeof                        @71
-       unzCloseCurrentFile           @72
-       unzGetGlobalComment           @73
-       unzStringFileNameCompare      @74
-       unzLocateFile                 @75
-       unzGetLocalExtrafield         @76
index 76692cb..67ca851 100644 (file)
@@ -1,15 +1,14 @@
-/* unzip.h -- IO for uncompress .zip files using zlib 
-   Version 0.15 beta, Mar 19th, 1998,
+/* unzip.h -- IO for uncompress .zip files using zlib
+   Version 0.21, March 10th, 2003
 
-   Copyright (C) 1998 Gilles Vollant
+   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
 
-   THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
-   CAN CHANGE IN FUTURE VERSION !!
+
    I WAIT FEEDBACK at mail info@winimage.com
    Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
 
 
 
 */
-/* for more info about .ZIP format, see 
-      ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
+
+/* 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 */
+      ftp://ftp.pkware.com/probdesc.zip
+*/
 
 #ifndef _unz_H
 #define _unz_H
@@ -49,43 +51,47 @@ extern "C" {
 #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 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_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 
+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] */
+    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 */
+    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;
 
 
@@ -98,8 +104,8 @@ typedef struct unz_file_info_s
     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 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 */
@@ -112,27 +118,34 @@ typedef struct unz_file_info_s
 } unz_file_info;
 
 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
-                                                                                                const char* fileName2,
-                                                                                                int iCaseSensitivity));
+                                                 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)
+                                or strcasecmp)
    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
-       (like 1 on Unix, 2 on Windows)
+    (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 NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
-        "zlib/zlib111.zip".
-        If the zipfile cannot be opened (file don't exist or in not valid), the
-          return value is NULL.
+     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.
+       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));
@@ -143,7 +156,7 @@ extern int ZEXPORT unzClose OF((unzFile file));
   return UNZ_OK if there is no problem. */
 
 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
-                                       unz_global_info *pglobal_info));
+                                        unz_global_info *pglobal_info));
 /*
   Write info about the ZipFile in the *pglobal_info structure.
   No preparation of the structure is needed
@@ -151,8 +164,8 @@ extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
 
 
 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
-                                                                                  char *szComment,
-                                          uLong uSizeBuf));
+                                           char *szComment,
+                                           uLong uSizeBuf));
 /*
   Get the global comment string of the ZipFile, in the szComment buffer.
   uSizeBuf is the size of the szComment buffer.
@@ -176,9 +189,9 @@ extern int ZEXPORT unzGoToNextFile OF((unzFile file));
   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));
+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
@@ -189,25 +202,44 @@ extern int ZEXPORT unzLocateFile OF((unzFile file,
 */
 
 
+/* ****************************************** */
+/* 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));
+                         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
+        the current file
   if szFileName!=NULL, the filemane string will be copied in szFileName
-                       (fileNameBufferSize is the size of the buffer)
+            (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
+            (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)
+            (commentBufferSize is the size of the buffer)
 */
 
 /***************************************************************************/
@@ -221,16 +253,51 @@ extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
   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));
+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
@@ -249,12 +316,12 @@ extern z_off_t ZEXPORT unztell OF((unzFile file));
 
 extern int ZEXPORT unzeof OF((unzFile file));
 /*
-  return 1 if the end of file was reached, 0 elsewhere 
+  return 1 if the end of file was reached, 0 elsewhere
 */
 
 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
-                                                                                        voidp buf,
-                                                                                        unsigned len));
+                                             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
@@ -263,9 +330,9 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
   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
+    buf.
+  the return value is the number of bytes copied in buf, or (if <0)
+    the error code
 */
 
 #ifdef __cplusplus
index 0cae64a..29c17d8 100644 (file)
@@ -1,5 +1,5 @@
-/* zip.c -- IO on .zip files using zlib 
-   Version 0.15 beta, Mar 19th, 1998,
+/* zip.c -- IO on .zip files using zlib
+   Version 0.21, March 10th, 2003
 
    Read zip.h for more info
 */
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include "zlib.h"
 #include "zip.h"
 
 #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.15 Copyright 1998 Gilles Vollant ";
+   " zip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
 
 
 #define SIZEDATA_INDATABLOCK (4096-(4*4))
@@ -99,33 +107,49 @@ typedef struct linkedlist_data_s
 
 typedef struct
 {
-       z_stream stream;            /* zLib stream structure for inflate */
+    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 
+    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
 {
-    FILE * filezip;
+    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;
@@ -166,7 +190,7 @@ local void free_linkedlist(ll)
 
 
 local int add_data_in_datablock(ll,buf,len)
-    linkedlist_data* ll;    
+    linkedlist_data* ll;
     const void* buf;
     uLong len;
 {
@@ -220,32 +244,20 @@ local int add_data_in_datablock(ll,buf,len)
 }
 
 
-local int write_datablock(fout,ll)
-    FILE * fout;
-    linkedlist_data* ll;    
-{
-    linkedlist_datablock_internal* ldi;
-    ldi = ll->first_block;
-    while (ldi!=NULL)
-    {
-        if (ldi->filled_in_this_block > 0)
-            if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,1,fout)!=1)
-                return ZIP_ERRNO;
-        ldi = ldi->next_datablock;
-    }
-    return ZIP_OK;
-}
 
 /****************************************************************************/
 
+#ifndef NO_ADDFILEINEXISTINGZIP
 /* ===========================================================================
-   Outputs a long in LSB order to the given file
+   Inputs a long in LSB order to the given file
    nbByte == 1, 2 or 4 (byte, short or long)
 */
 
-local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte));
-local int ziplocal_putValue (file, x, nbByte)
-    FILE *file;
+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;
 {
@@ -255,7 +267,7 @@ local int ziplocal_putValue (file, x, nbByte)
         buf[n] = (unsigned char)(x & 0xff);
         x >>= 8;
     }
-    if (fwrite(buf,nbByte,1,file)!=1)
+    if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
         return ZIP_ERRNO;
     else
         return ZIP_OK;
@@ -278,7 +290,7 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
 
 
 local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
-    tm_zip* ptm;
+    const tm_zip* ptm;
     uLong dosDate;
 {
     uLong year = (uLong)ptm->tm_year;
@@ -294,38 +306,348 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
 
 /****************************************************************************/
 
-extern zipFile ZEXPORT zipOpen (pathname, append)
+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;
+
 
-    ziinit.filezip = fopen(pathname,(append == 0) ? "wb" : "ab");
-    if (ziinit.filezip == NULL)
+    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 = ftell(ziinit.filezip);
+    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)
     {
-        fclose(ziinit.filezip);
+        ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
         return NULL;
     }
 
-    *zi = ziinit;
-    return (zipFile)zi;
+    /* 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 int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, 
-                                        extrafield_local, size_extrafield_local,
-                                        extrafield_global, size_extrafield_global,
-                                        comment, method, level)
+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;
@@ -336,6 +658,12 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
     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;
@@ -343,6 +671,11 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
     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))
@@ -384,13 +717,17 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
       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.pos_local_header = ftell(zi->filezip);
-    zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + 
+    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);
 
@@ -410,16 +747,16 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
     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); 
+        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); 
+        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); 
+        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,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);
@@ -430,44 +767,44 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
 
     for (i=0;i<size_comment;i++)
         *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
-              size_extrafield_global+i) = *(filename+i);
+              size_extrafield_global+i) = *(comment+i);
     if (zi->ci.central_header == NULL)
         return ZIP_INTERNALERROR;
 
     /* write the local header */
-    err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4);
+    err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
 
     if (err==ZIP_OK)
-        err = ziplocal_putValue(zi->filezip,(uLong)size_extrafield_local,2);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
 
     if ((err==ZIP_OK) && (size_filename>0))
-        if (fwrite(filename,(uInt)size_filename,1,zi->filezip)!=1)
+        if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
                 err = ZIP_ERRNO;
 
     if ((err==ZIP_OK) && (size_extrafield_local>0))
-        if (fwrite(extrafield_local,(uInt)size_extrafield_local,1,zi->filezip)
-                                                                           !=1)
+        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;
@@ -476,17 +813,38 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
     zi->ci.stream.total_in = 0;
     zi->ci.stream.total_out = 0;
 
-    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED))
+    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, -MAX_WBITS, DEF_MEM_LEVEL, 0);
+               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
     }
 
 
@@ -495,9 +853,74 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
     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 voidp buf;
+    const void* buf;
     unsigned len;
 {
     zip_internal* zi;
@@ -510,7 +933,7 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
     if (zi->in_opened_file_inzip == 0)
         return ZIP_PARAMERROR;
 
-    zi->ci.stream.next_in = buf;
+    zi->ci.stream.next_in = (void*)buf;
     zi->ci.stream.avail_in = len;
     zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
 
@@ -518,15 +941,17 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
     {
         if (zi->ci.stream.avail_out == 0)
         {
-            if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
-                                                                           !=1)
+            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
                 err = ZIP_ERRNO;
-            zi->ci.pos_in_buffered_data = 0;
             zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
             zi->ci.stream.next_out = zi->ci.buffered_data;
         }
 
-        if (zi->ci.method == Z_DEFLATED)
+
+        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);
@@ -555,33 +980,34 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
         }
     }
 
-    return 0;
+    return err;
 }
 
-extern int ZEXPORT zipCloseFileInZip (file)
+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)    
+    if (zi->in_opened_file_inzip == 0)
         return ZIP_PARAMERROR;
     zi->ci.stream.avail_in = 0;
-    
-    if (zi->ci.method == Z_DEFLATED)
+
+    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
         while (err==ZIP_OK)
     {
         uLong uTotalOutBefore;
         if (zi->ci.stream.avail_out == 0)
         {
-            if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
-                                                                           !=1)
+            if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
                 err = ZIP_ERRNO;
-            zi->ci.pos_in_buffered_data = 0;
             zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
             zi->ci.stream.next_out = zi->ci.buffered_data;
         }
@@ -594,21 +1020,32 @@ extern int ZEXPORT zipCloseFileInZip (file)
         err=ZIP_OK; /* this is normal */
 
     if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
-        if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
-                                                                       !=1)
+        if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
             err = ZIP_ERRNO;
 
-    if ((zi->ci.method == Z_DEFLATED) && (err==ZIP_OK))
+    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
     {
         err=deflateEnd(&zi->ci.stream);
         zi->ci.stream_initialised = 0;
     }
 
-    ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/
+    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,
-                                (uLong)zi->ci.stream.total_out,4); /*compr size*/
+                                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,
-                                (uLong)zi->ci.stream.total_in,4); /*uncompr size*/
+                                uncompressed_size,4); /*uncompr size*/
 
     if (err==ZIP_OK)
         err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
@@ -617,23 +1054,23 @@ extern int ZEXPORT zipCloseFileInZip (file)
 
     if (err==ZIP_OK)
     {
-        long cur_pos_inzip = ftell(zi->filezip);
-           if (fseek(zi->filezip,
-                  zi->ci.pos_local_header + 14,SEEK_SET)!=0)
-                   err = ZIP_ERRNO;
+        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->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
 
         if (err==ZIP_OK) /* compressed size, unknown */
-            err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4); 
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
 
         if (err==ZIP_OK) /* uncompressed size, unknown */
-            err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4);
+            err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
 
-           if (fseek(zi->filezip,
-                  cur_pos_inzip,SEEK_SET)!=0)
-                   err = ZIP_ERRNO;
+        if (ZSEEK(zi->z_filefunc,zi->filestream,
+                  cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
+            err = ZIP_ERRNO;
     }
 
     zi->number_entry ++;
@@ -642,6 +1079,12 @@ extern int ZEXPORT zipCloseFileInZip (file)
     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;
@@ -666,15 +1109,16 @@ extern int ZEXPORT zipClose (file, global_comment)
         size_global_comment = strlen(global_comment);
 
 
-    centraldir_pos_inzip = ftell(zi->filezip);
+    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 (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,
-                                        1,zi->filezip) !=1 )
+                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;
@@ -684,34 +1128,40 @@ extern int ZEXPORT zipClose (file, global_comment)
     free_datablock(zi->central_dir.first_block);
 
     if (err==ZIP_OK) /* Magic End */
-        err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
 
     if (err==ZIP_OK) /* number of this disk */
-        err = ziplocal_putValue(zi->filezip,(uLong)0,2);
+        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->filezip,(uLong)0,2);
+        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->filezip,(uLong)zi->number_entry,2);
+        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->filezip,(uLong)zi->number_entry,2);
+        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->filezip,(uLong)size_centraldir,4);
+        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->filezip,(uLong)centraldir_pos_inzip ,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->filezip,(uLong)size_global_comment,2);
+        err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
 
     if ((err==ZIP_OK) && (size_global_comment>0))
-        if (fwrite(global_comment,(uInt)size_global_comment,1,zi->filezip) !=1 )
+        if (ZWRITE(zi->z_filefunc,zi->filestream,
+                   global_comment,size_global_comment) != size_global_comment)
                 err = ZIP_ERRNO;
-    fclose(zi->filezip);
+
+    if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
+        if (err == ZIP_OK)
+            err = ZIP_ERRNO;
+
     TRYFREE(zi);
 
     return err;
diff --git a/zlib/contrib/minizip/zip.def b/zlib/contrib/minizip/zip.def
deleted file mode 100644 (file)
index 5d5079f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-       zipOpen                       @80
-       zipOpenNewFileInZip           @81
-       zipWriteInFileInZip           @82
-       zipCloseFileInZip             @83
-       zipClose                      @84
index 678260b..4bc6aa4 100644 (file)
@@ -1,7 +1,7 @@
-/* zip.h -- IO for compress .zip files using zlib 
-   Version 0.15 alpha, Mar 19th, 1998,
+/* zip.h -- IO for compress .zip files using zlib
+   Version 0.21, March 10th, 2003
 
-   Copyright (C) 1998 Gilles Vollant
+   Copyright (C) 1998-2003 Gilles Vollant
 
    This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
      WinZip, InfoZip tools and compatible.
 
   For uncompress .zip file, look at unzip.h
 
-   THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
-   CAN CHANGE IN FUTURE VERSION !!
+
    I WAIT FEEDBACK at mail info@winimage.com
-   Visit also http://www.winimage.com/zLibDll/zip.htm for evolution
+   Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
 
    Condition of use and distribution are the same than zlib :
 
@@ -36,8 +35,9 @@
 
 */
 
-/* for more info about .ZIP format, see 
-      ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
+/* 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
 */
@@ -53,34 +53,49 @@ extern "C" {
 #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 struct TagzipFile__ { int unused; } zipFile__;
 typedef zipFile__ *zipFile;
 #else
 typedef voidp zipFile;
 #endif
 
-#define ZIP_OK                                  (0)
-#define ZIP_ERRNO               (Z_ERRNO)
+#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 
+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] */
+    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           */
+    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 */
 
@@ -88,30 +103,48 @@ typedef struct
     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 NT a filename like "c:\\zlib\\zlib111.zip" or on
-          an Unix computer "zlib/zlib111.zip".
-        if the file pathname exist and append=1, the zip will be created at the end
-          of the file. (useful if the file contain a self extractor code)
-        If the zipfile cannot be opened, the return value is NULL.
+     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.
-
+       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));
+                       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
@@ -125,9 +158,51 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
   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 voidp buf,
-                                          unsigned len));
+                       const void* buf,
+                       unsigned len));
 /*
   Write data in the zipfile
 */
@@ -137,8 +212,18 @@ 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));
+                const char* global_comment));
 /*
   Close the zipfile
 */
diff --git a/zlib/contrib/minizip/zlibvc.dsp b/zlib/contrib/minizip/zlibvc.dsp
deleted file mode 100644 (file)
index a70d4d4..0000000
+++ /dev/null
@@ -1,651 +0,0 @@
-# Microsoft Developer Studio Project File - Name="zlibvc" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-# TARGTYPE "Win32 (ALPHA) Dynamic-Link Library" 0x0602
-
-CFG=zlibvc - Win32 Release
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "zlibvc.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "zlibvc.mak" CFG="zlibvc - Win32 Release"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "zlibvc - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlibvc - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlibvc - Win32 ReleaseAxp" (based on\
- "Win32 (ALPHA) Dynamic-Link Library")
-!MESSAGE "zlibvc - Win32 ReleaseWithoutAsm" (based on\
- "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "zlibvc - Win32 ReleaseWithoutCrtdll" (based on\
- "Win32 (x86) Dynamic-Link Library")
-!MESSAGE 
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir ".\Release"
-# PROP BASE Intermediate_Dir ".\Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir ".\Release"
-# PROP Intermediate_Dir ".\Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /FD /c
-# SUBTRACT CPP /YX
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x40c /d "NDEBUG"
-# ADD RSC /l 0x40c /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir ".\Debug"
-# PROP BASE Intermediate_Dir ".\Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir ".\Debug"
-# PROP Intermediate_Dir ".\Debug"
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /FD /c
-# SUBTRACT CPP /YX
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "_DEBUG" /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x40c /d "_DEBUG"
-# ADD RSC /l 0x40c /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:".\Debug\zlib.dll"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlibvc__"
-# PROP BASE Intermediate_Dir "zlibvc__"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "zlibvc__"
-# PROP Intermediate_Dir "zlibvc__"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-CPP=cl.exe
-# ADD BASE CPP /nologo /MT /Gt0 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /YX /FD /c
-# ADD CPP /nologo /MT /Gt0 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /FD /c
-# SUBTRACT CPP /YX
-RSC=rc.exe
-# ADD BASE RSC /l 0x40c /d "NDEBUG"
-# ADD RSC /l 0x40c /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 crtdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /map /machine:ALPHA /nodefaultlib /out:".\Release\zlib.dll"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 crtdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /map /machine:ALPHA /nodefaultlib /out:"zlibvc__\zlib.dll"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlibvc_0"
-# PROP BASE Intermediate_Dir "zlibvc_0"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "zlibvc_0"
-# PROP Intermediate_Dir "zlibvc_0"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /FD /c
-# SUBTRACT CPP /YX
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x40c /d "NDEBUG"
-# ADD RSC /l 0x40c /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\zlibvc_0\zlib.dll"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "zlibvc_1"
-# PROP BASE Intermediate_Dir "zlibvc_1"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "zlibvc_1"
-# PROP Intermediate_Dir "zlibvc_1"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-CPP=cl.exe
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /FD /c
-# SUBTRACT CPP /YX
-MTL=midl.exe
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-RSC=rc.exe
-# ADD BASE RSC /l 0x40c /d "NDEBUG"
-# ADD RSC /l 0x40c /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\zlibvc_1\zlib.dll"
-# SUBTRACT LINK32 /pdb:none
-
-!ENDIF 
-
-# Begin Target
-
-# Name "zlibvc - Win32 Release"
-# Name "zlibvc - Win32 Debug"
-# Name "zlibvc - Win32 ReleaseAxp"
-# Name "zlibvc - Win32 ReleaseWithoutAsm"
-# Name "zlibvc - Win32 ReleaseWithoutCrtdll"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
-# Begin Source File
-
-SOURCE=.\adler32.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_ADLER=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\compress.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_COMPR=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\crc32.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_CRC32=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\deflate.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_DEFLA=\
-       ".\deflate.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\gvmat32c.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\gzio.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_GZIO_=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\infblock.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFBL=\
-       ".\infblock.h"\
-       ".\infcodes.h"\
-       ".\inftrees.h"\
-       ".\infutil.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\infcodes.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFCO=\
-       ".\infblock.h"\
-       ".\infcodes.h"\
-       ".\inffast.h"\
-       ".\inftrees.h"\
-       ".\infutil.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\inffast.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFFA=\
-       ".\infblock.h"\
-       ".\infcodes.h"\
-       ".\inffast.h"\
-       ".\inftrees.h"\
-       ".\infutil.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\inflate.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFLA=\
-       ".\infblock.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\inftrees.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFTR=\
-       ".\inftrees.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\infutil.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_INFUT=\
-       ".\infblock.h"\
-       ".\infcodes.h"\
-       ".\inftrees.h"\
-       ".\infutil.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\trees.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_TREES=\
-       ".\deflate.h"\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\uncompr.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_UNCOM=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\unzip.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\zip.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=.\zlib.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\zlibvc.def
-# End Source File
-# Begin Source File
-
-SOURCE=.\zutil.c
-
-!IF  "$(CFG)" == "zlibvc - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
-
-DEP_CPP_ZUTIL=\
-       ".\zconf.h"\
-       ".\zlib.h"\
-       ".\zutil.h"\
-       
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
-
-!ELSEIF  "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
-
-!ENDIF 
-
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
-# Begin Source File
-
-SOURCE=.\deflate.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\infblock.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\infcodes.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\inffast.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\inftrees.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\infutil.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\zconf.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\zlib.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\zutil.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/zlib/contrib/minizip/zlibvc.dsw b/zlib/contrib/minizip/zlibvc.dsw
deleted file mode 100644 (file)
index 493cd87..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 5.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "zlibstat"=.\zlibstat.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "zlibvc"=.\zlibvc.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/zlib/contrib/puff/Makefile b/zlib/contrib/puff/Makefile
new file mode 100644 (file)
index 0000000..b6b6940
--- /dev/null
@@ -0,0 +1,8 @@
+puff: puff.c puff.h
+       cc -DTEST -o puff puff.c
+
+test: puff
+       puff zeros.raw
+
+clean:
+       rm -f puff puff.o
diff --git a/zlib/contrib/puff/README b/zlib/contrib/puff/README
new file mode 100644 (file)
index 0000000..59b3533
--- /dev/null
@@ -0,0 +1,63 @@
+Puff -- A Simple Inflate
+3 Mar 2003
+Mark Adler
+madler@alumni.caltech.edu
+
+What this is --
+
+puff.c provides the routine puff() to decompress the deflate data format.  It
+does so more slowly than zlib, but the code is about one-fifth the size of the
+inflate code in zlib, and written to be very easy to read.
+
+Why I wrote this --
+
+puff.c was written to document the deflate format unambiguously, by virtue of
+being working C code.  It is meant to supplement RFC 1951, which formally
+describes the deflate format.  I have received many questions on details of the
+deflate format, and I hope that reading this code will answer those questions. 
+puff.c is heavily commented with details of the deflate format, especially
+those little nooks and cranies of the format that might not be obvious from a
+specification.
+
+puff.c may also be useful in applications where code size or memory usage is a
+very limited resource, and speed is not as important.
+
+How to use it --
+
+Well, most likely you should just be reading puff.c and using zlib for actual
+applications, but if you must ...
+
+Include puff.h in your code, which provides this prototype:
+
+int puff(unsigned char *dest,          /* pointer to destination pointer */
+         unsigned long *destlen,       /* amount of output space */
+         unsigned char *source,                /* pointer to source data pointer */
+         unsigned long *sourcelen);    /* amount of input available */
+
+Then you can call puff() to decompress a deflate stream that is in memory in
+its entirety at source, to a sufficiently sized block of memory for the
+decompressed data at dest.  puff() is the only external symbol in puff.c  The
+only C library functions that puff.c needs are setjmp() and longjmp(), which
+are used to simplify error checking in the code to improve readabilty.  puff.c
+does no memory allocation, and uses less than 2K bytes off of the stack.
+
+If destlen is not enough space for the uncompressed data, then inflate will
+return an error without writing more than destlen bytes.  Note that this means
+that in order to decompress the deflate data successfully, you need to know
+the size of the uncompressed data ahead of time.
+
+If needed, puff() can determine the size of the uncompressed data with no
+output space.  This is done by passing dest equal to (unsigned char *)0.  Then
+the initial value of *destlen is ignored and *destlen is set to the length of
+the uncompressed data.  So if the size of the uncompressed data is not known,
+then two passes of puff() can be used--first to determine the size, and second
+to do the actual inflation after allocating the appropriate memory.  Not
+pretty, but it works.  (This is one of the reasons you should be using zlib.)
+
+The deflate format is self-terminating.  If the deflate stream does not end
+in *sourcelen bytes, puff() will return an error without reading at or past
+endsource.
+
+On return, *sourcelen is updated to the amount of input data consumed, and
+*destlen is updated to the size of the uncompressed data.  See the comments
+in puff.c for the possible return codes for puff().
diff --git a/zlib/contrib/puff/puff.c b/zlib/contrib/puff/puff.c
new file mode 100644 (file)
index 0000000..b6039dd
--- /dev/null
@@ -0,0 +1,833 @@
+/*
+ * puff.c
+ * Copyright (C) 2002, 2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in puff.h
+ * version 1.7, 3 Mar 2003
+ *
+ * puff.c is a simple inflate written to be an unambiguous way to specify the
+ * deflate format.  It is not written for speed but rather simplicity.  As a
+ * side benefit, this code might actually be useful when small code is more
+ * important than speed, such as bootstrap applications.  For typical deflate
+ * data, zlib's inflate() is about four times as fast as puff().  zlib's
+ * inflate compiles to around 20K on my machine, whereas puff.c compiles to
+ * around 4K on my machine (a PowerPC using GNU cc).  If the faster decode()
+ * function here is used, then puff() is only twice as slow as zlib's
+ * inflate().
+ *
+ * All dynamically allocated memory comes from the stack.  The stack required
+ * is less than 2K bytes.  This code is compatible with 16-bit int's and
+ * assumes that long's are at least 32 bits.  puff.c uses the short data type,
+ * assumed to be 16 bits, for arrays in order to to conserve memory.  The code
+ * works whether integers are stored big endian or little endian.
+ *
+ * In the comments below are "Format notes" that describe the inflate process
+ * and document some of the less obvious aspects of the format.  This source
+ * code is meant to supplement RFC 1951, which formally describes the deflate
+ * format:
+ *
+ *    http://www.zlib.org/rfc-deflate.html
+ */
+
+/*
+ * Change history:
+ *
+ * 1.0  10 Feb 2002     - First version
+ * 1.1  17 Feb 2002     - Clarifications of some comments and notes
+ *                      - Update puff() dest and source pointers on negative
+ *                        errors to facilitate debugging deflators
+ *                      - Remove longest from struct huffman -- not needed
+ *                      - Simplify offs[] index in construct()
+ *                      - Add input size and checking, using longjmp() to
+ *                        maintain easy readability
+ *                      - Use short data type for large arrays
+ *                      - Use pointers instead of long to specify source and
+ *                        destination sizes to avoid arbitrary 4 GB limits
+ * 1.2  17 Mar 2002     - Add faster version of decode(), doubles speed (!),
+ *                        but leave simple version for readabilty
+ *                      - Make sure invalid distances detected if pointers
+ *                        are 16 bits
+ *                      - Fix fixed codes table error
+ *                      - Provide a scanning mode for determining size of
+ *                        uncompressed data
+ * 1.3  20 Mar 2002     - Go back to lengths for puff() parameters [Jean-loup]
+ *                      - Add a puff.h file for the interface
+ *                      - Add braces in puff() for else do [Jean-loup]
+ *                      - Use indexes instead of pointers for readability
+ * 1.4  31 Mar 2002     - Simplify construct() code set check
+ *                      - Fix some comments
+ *                      - Add FIXLCODES #define
+ * 1.5   6 Apr 2002     - Minor comment fixes
+ * 1.6   7 Aug 2002     - Minor format changes
+ * 1.7   3 Mar 2002     - Added test code for distribution
+ *                      - Added zlib-like license
+ */
+
+#include <setjmp.h>             /* for setjmp(), longjmp(), and jmp_buf */
+#include "puff.h"               /* prototype for puff() */
+
+#define local static            /* for local function definitions */
+#define NIL ((unsigned char *)0)        /* for no output option */
+
+/*
+ * Maximums for allocations and loops.  It is not useful to change these --
+ * they are fixed by the deflate format.
+ */
+#define MAXBITS 15              /* maximum bits in a code */
+#define MAXLCODES 286           /* maximum number of literal/length codes */
+#define MAXDCODES 30            /* maximum number of distance codes */
+#define MAXCODES (MAXLCODES+MAXDCODES)  /* maximum codes lengths to read */
+#define FIXLCODES 288           /* number of fixed literal/length codes */
+
+/* input and output state */
+struct state {
+    /* output state */
+    unsigned char *out;         /* output buffer */
+    unsigned long outlen;       /* available space at out */
+    unsigned long outcnt;       /* bytes written to out so far */
+
+    /* input state */
+    unsigned char *in;          /* input buffer */
+    unsigned long inlen;        /* available input at in */
+    unsigned long incnt;        /* bytes read so far */
+    int bitbuf;                 /* bit buffer */
+    int bitcnt;                 /* number of bits in bit buffer */
+
+    /* input limit error return state for bits() and decode() */
+    jmp_buf env;
+};
+
+/*
+ * Return need bits from the input stream.  This always leaves less than
+ * eight bits in the buffer.  bits() works properly for need == 0.
+ *
+ * Format notes:
+ *
+ * - Bits are stored in bytes from the least significant bit to the most
+ *   significant bit.  Therefore bits are dropped from the bottom of the bit
+ *   buffer, using shift right, and new bytes are appended to the top of the
+ *   bit buffer, using shift left.
+ */
+local int bits(struct state *s, int need)
+{
+    long val;           /* bit accumulator (can use up to 20 bits) */
+
+    /* load at least need bits into val */
+    val = s->bitbuf;
+    while (s->bitcnt < need) {
+        if (s->incnt == s->inlen) longjmp(s->env, 1);   /* out of input */
+        val |= (long)(s->in[s->incnt++]) << s->bitcnt;  /* load eight bits */
+        s->bitcnt += 8;
+    }
+
+    /* drop need bits and update buffer, always zero to seven bits left */
+    s->bitbuf = (int)(val >> need);
+    s->bitcnt -= need;
+
+    /* return need bits, zeroing the bits above that */
+    return (int)(val & ((1L << need) - 1));
+}
+
+/*
+ * Process a stored block.
+ *
+ * Format notes:
+ *
+ * - After the two-bit stored block type (00), the stored block length and
+ *   stored bytes are byte-aligned for fast copying.  Therefore any leftover
+ *   bits in the byte that has the last bit of the type, as many as seven, are
+ *   discarded.  The value of the discarded bits are not defined and should not
+ *   be checked against any expectation.
+ *
+ * - The second inverted copy of the stored block length does not have to be
+ *   checked, but it's probably a good idea to do so anyway.
+ *
+ * - A stored block can have zero length.  This is sometimes used to byte-align
+ *   subsets of the compressed data for random access or partial recovery.
+ */
+local int stored(struct state *s)
+{
+    unsigned len;       /* length of stored block */
+
+    /* discard leftover bits from current byte (assumes s->bitcnt < 8) */
+    s->bitbuf = 0;
+    s->bitcnt = 0;
+
+    /* get length and check against its one's complement */
+    if (s->incnt + 4 > s->inlen) return 2;      /* not enough input */
+    len = s->in[s->incnt++];
+    len |= s->in[s->incnt++] << 8;
+    if (s->in[s->incnt++] != (~len & 0xff) ||
+        s->in[s->incnt++] != ((~len >> 8) & 0xff))
+        return -2;                              /* didn't match complement! */
+
+    /* copy len bytes from in to out */
+    if (s->incnt + len > s->inlen) return 2;    /* not enough input */
+    if (s->out != NIL) {
+        if (s->outcnt + len > s->outlen)
+            return 1;                           /* not enough output space */
+        while (len--)
+            s->out[s->outcnt++] = s->in[s->incnt++];
+    }
+    else {                                      /* just scanning */
+        s->outcnt += len;
+        s->incnt += len;
+    }
+
+    /* done with a valid stored block */
+    return 0;
+}
+
+/*
+ * Huffman code decoding tables.  count[1..MAXBITS] is the number of symbols of
+ * each length, which for a canonical code are stepped through in order.
+ * symbol[] are the symbol values in canonical order, where the number of
+ * entries is the sum of the counts in count[].  The decoding process can be
+ * seen in the function decode() below.
+ */
+struct huffman {
+    short *count;       /* number of symbols of each length */
+    short *symbol;      /* canonically ordered symbols */
+};
+
+/*
+ * Decode a code from the stream s using huffman table h.  Return the symbol or
+ * a negative value if there is an error.  If all of the lengths are zero, i.e.
+ * an empty code, or if the code is incomplete and an invalid code is received,
+ * then -9 is returned after reading MAXBITS bits.
+ *
+ * Format notes:
+ *
+ * - The codes as stored in the compressed data are bit-reversed relative to
+ *   a simple integer ordering of codes of the same lengths.  Hence below the
+ *   bits are pulled from the compressed data one at a time and used to
+ *   build the code value reversed from what is in the stream in order to
+ *   permit simple integer comparisons for decoding.  A table-based decoding
+ *   scheme (as used in zlib) does not need to do this reversal.
+ *
+ * - The first code for the shortest length is all zeros.  Subsequent codes of
+ *   the same length are simply integer increments of the previous code.  When
+ *   moving up a length, a zero bit is appended to the code.  For a complete
+ *   code, the last code of the longest length will be all ones.
+ *
+ * - Incomplete codes are handled by this decoder, since they are permitted
+ *   in the deflate format.  See the format notes for fixed() and dynamic().
+ */
+#ifdef SLOW
+local int decode(struct state *s, struct huffman *h)
+{
+    int len;            /* current number of bits in code */
+    int code;           /* len bits being decoded */
+    int first;          /* first code of length len */
+    int count;          /* number of codes of length len */
+    int index;          /* index of first code of length len in symbol table */
+
+    code = first = index = 0;
+    for (len = 1; len <= MAXBITS; len++) {
+        code |= bits(s, 1);             /* get next bit */
+        count = h->count[len];
+        if (code < first + count)       /* if length len, return symbol */
+            return h->symbol[index + (code - first)];
+        index += count;                 /* else update for next length */
+        first += count;
+        first <<= 1;
+        code <<= 1;
+    }
+    return -9;                          /* ran out of codes */
+}
+
+/*
+ * A faster version of decode() for real applications of this code.   It's not
+ * as readable, but it makes puff() twice as fast.  And it only makes the code
+ * a few percent larger.
+ */
+#else /* !SLOW */
+local int decode(struct state *s, struct huffman *h)
+{
+    int len;            /* current number of bits in code */
+    int code;           /* len bits being decoded */
+    int first;          /* first code of length len */
+    int count;          /* number of codes of length len */
+    int index;          /* index of first code of length len in symbol table */
+    int bitbuf;         /* bits from stream */
+    int left;           /* bits left in next or left to process */
+    short *next;        /* next number of codes */
+
+    bitbuf = s->bitbuf;
+    left = s->bitcnt;
+    code = first = index = 0;
+    len = 1;
+    next = h->count + 1;
+    while (1) {
+        while (left--) {
+            code |= bitbuf & 1;
+            bitbuf >>= 1;
+            count = *next++;
+            if (code < first + count) { /* if length len, return symbol */
+                s->bitbuf = bitbuf;
+                s->bitcnt = (s->bitcnt - len) & 7;
+                return h->symbol[index + (code - first)];
+            }
+            index += count;             /* else update for next length */
+            first += count;
+            first <<= 1;
+            code <<= 1;
+            len++;
+        }
+        left = (MAXBITS+1) - len;
+        if (left == 0) break;
+        if (s->incnt == s->inlen) longjmp(s->env, 1);   /* out of input */
+        bitbuf = s->in[s->incnt++];
+        if (left > 8) left = 8;
+    }
+    return -9;                          /* ran out of codes */
+}
+#endif /* SLOW */
+
+/*
+ * Given the list of code lengths length[0..n-1] representing a canonical
+ * Huffman code for n symbols, construct the tables required to decode those
+ * codes.  Those tables are the number of codes of each length, and the symbols
+ * sorted by length, retaining their original order within each length.  The
+ * return value is zero for a complete code set, negative for an over-
+ * subscribed code set, and positive for an incomplete code set.  The tables
+ * can be used if the return value is zero or positive, but they cannot be used
+ * if the return value is negative.  If the return value is zero, it is not
+ * possible for decode() using that table to return an error--any stream of
+ * enough bits will resolve to a symbol.  If the return value is positive, then
+ * it is possible for decode() using that table to return an error for received
+ * codes past the end of the incomplete lengths.
+ *
+ * Not used by decode(), but used for error checking, h->count[0] is the number
+ * of the n symbols not in the code.  So n - h->count[0] is the number of
+ * codes.  This is useful for checking for incomplete codes that have more than
+ * one symbol, which is an error in a dynamic block.
+ *
+ * Assumption: for all i in 0..n-1, 0 <= length[i] <= MAXBITS
+ * This is assured by the construction of the length arrays in dynamic() and
+ * fixed() and is not verified by construct().
+ *
+ * Format notes:
+ *
+ * - Permitted and expected examples of incomplete codes are one of the fixed
+ *   codes and any code with a single symbol which in deflate is coded as one
+ *   bit instead of zero bits.  See the format notes for fixed() and dynamic().
+ *
+ * - Within a given code length, the symbols are kept in ascending order for
+ *   the code bits definition.
+ */
+local int construct(struct huffman *h, short *length, int n)
+{
+    int symbol;         /* current symbol when stepping through length[] */
+    int len;            /* current length when stepping through h->count[] */
+    int left;           /* number of possible codes left of current length */
+    short offs[MAXBITS+1];      /* offsets in symbol table for each length */
+
+    /* count number of codes of each length */
+    for (len = 0; len <= MAXBITS; len++)
+        h->count[len] = 0;
+    for (symbol = 0; symbol < n; symbol++)
+        (h->count[length[symbol]])++;   /* assumes lengths are within bounds */
+    if (h->count[0] == n)               /* no codes! */
+        return 0;                       /* complete, but decode() will fail */
+
+    /* check for an over-subscribed or incomplete set of lengths */
+    left = 1;                           /* one possible code of zero length */
+    for (len = 1; len <= MAXBITS; len++) {
+        left <<= 1;                     /* one more bit, double codes left */
+        left -= h->count[len];          /* deduct count from possible codes */
+        if (left < 0) return left;      /* over-subscribed--return negative */
+    }                                   /* left > 0 means incomplete */
+
+    /* generate offsets into symbol table for each length for sorting */
+    offs[1] = 0;
+    for (len = 1; len < MAXBITS; len++)
+        offs[len + 1] = offs[len] + h->count[len];
+
+    /*
+     * put symbols in table sorted by length, by symbol order within each
+     * length
+     */
+    for (symbol = 0; symbol < n; symbol++)
+        if (length[symbol] != 0)
+            h->symbol[offs[length[symbol]]++] = symbol;
+
+    /* return zero for complete set, positive for incomplete set */
+    return left;
+}
+
+/*
+ * Decode literal/length and distance codes until an end-of-block code.
+ *
+ * Format notes:
+ *
+ * - Compressed data that is after the block type if fixed or after the code
+ *   description if dynamic is a combination of literals and length/distance
+ *   pairs terminated by and end-of-block code.  Literals are simply Huffman
+ *   coded bytes.  A length/distance pair is a coded length followed by a
+ *   coded distance to represent a string that occurs earlier in the
+ *   uncompressed data that occurs again at the current location.
+ *
+ * - Literals, lengths, and the end-of-block code are combined into a single
+ *   code of up to 286 symbols.  They are 256 literals (0..255), 29 length
+ *   symbols (257..285), and the end-of-block symbol (256).
+ *
+ * - There are 256 possible lengths (3..258), and so 29 symbols are not enough
+ *   to represent all of those.  Lengths 3..10 and 258 are in fact represented
+ *   by just a length symbol.  Lengths 11..257 are represented as a symbol and
+ *   some number of extra bits that are added as an integer to the base length
+ *   of the length symbol.  The number of extra bits is determined by the base
+ *   length symbol.  These are in the static arrays below, lens[] for the base
+ *   lengths and lext[] for the corresponding number of extra bits.
+ *
+ * - The reason that 258 gets its own symbol is that the longest length is used
+ *   often in highly redundant files.  Note that 258 can also be coded as the
+ *   base value 227 plus the maximum extra value of 31.  While a good deflate
+ *   should never do this, it is not an error, and should be decoded properly.
+ *
+ * - If a length is decoded, including its extra bits if any, then it is
+ *   followed a distance code.  There are up to 30 distance symbols.  Again
+ *   there are many more possible distances (1..32768), so extra bits are added
+ *   to a base value represented by the symbol.  The distances 1..4 get their
+ *   own symbol, but the rest require extra bits.  The base distances and
+ *   corresponding number of extra bits are below in the static arrays dist[]
+ *   and dext[].
+ *
+ * - Literal bytes are simply written to the output.  A length/distance pair is
+ *   an instruction to copy previously uncompressed bytes to the output.  The
+ *   copy is from distance bytes back in the output stream, copying for length
+ *   bytes.
+ *
+ * - Distances pointing before the beginning of the output data are not
+ *   permitted.
+ *
+ * - Overlapped copies, where the length is greater than the distance, are
+ *   allowed and common.  For example, a distance of one and a length of 258
+ *   simply copies the last byte 258 times.  A distance of four and a length of
+ *   twelve copies the last four bytes three times.  A simple forward copy
+ *   ignoring whether the length is greater than the distance or not implements
+ *   this correctly.  You should not use memcpy() since its behavior is not
+ *   defined for overlapped arrays.  You should not use memmove() or bcopy()
+ *   since though their behavior -is- defined for overlapping arrays, it is
+ *   defined to do the wrong thing in this case.
+ */
+local int codes(struct state *s,
+                struct huffman *lencode,
+                struct huffman *distcode)
+{
+    int symbol;         /* decoded symbol */
+    int len;            /* length for copy */
+    unsigned dist;      /* distance for copy */
+    static const short lens[29] = { /* Size base for length codes 257..285 */
+        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
+    static const short lext[29] = { /* Extra bits for length codes 257..285 */
+        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
+    static const short dists[30] = { /* Offset base for distance codes 0..29 */
+        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,
+        8193, 12289, 16385, 24577};
+    static const short dext[30] = { /* Extra bits for distance codes 0..29 */
+        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
+        12, 12, 13, 13};
+
+    /* decode literals and length/distance pairs */
+    do {
+        symbol = decode(s, lencode);
+        if (symbol < 0) return symbol;  /* invalid symbol */
+        if (symbol < 256) {             /* literal: symbol is the byte */
+            /* write out the literal */
+            if (s->out != NIL) {
+                if (s->outcnt == s->outlen) return 1;
+                s->out[s->outcnt] = symbol;
+            }
+            s->outcnt++;
+        }
+        else if (symbol > 256) {        /* length */
+            /* get and compute length */
+            symbol -= 257;
+            if (symbol >= 29) return -9;        /* invalid fixed code */
+            len = lens[symbol] + bits(s, lext[symbol]);
+
+            /* get and check distance */
+            symbol = decode(s, distcode);
+            if (symbol < 0) return symbol;      /* invalid symbol */
+            dist = dists[symbol] + bits(s, dext[symbol]);
+            if (dist > s->outcnt)
+                return -10;     /* distance too far back */
+
+            /* copy length bytes from distance bytes back */
+            if (s->out != NIL) {
+                if (s->outcnt + len > s->outlen) return 1;
+                while (len--) {
+                    s->out[s->outcnt] = s->out[s->outcnt - dist];
+                    s->outcnt++;
+                }
+            }
+            else
+                s->outcnt += len;
+        }
+    } while (symbol != 256);            /* end of block symbol */
+
+    /* done with a valid fixed or dynamic block */
+    return 0;
+}
+
+/*
+ * Process a fixed codes block.
+ *
+ * Format notes:
+ *
+ * - This block type can be useful for compressing small amounts of data for
+ *   which the size of the code descriptions in a dynamic block exceeds the
+ *   benefit of custom codes for that block.  For fixed codes, no bits are
+ *   spent on code descriptions.  Instead the code lengths for literal/length
+ *   codes and distance codes are fixed.  The specific lengths for each symbol
+ *   can be seen in the "for" loops below.
+ *
+ * - The literal/length code is complete, but has two symbols that are invalid
+ *   and should result in an error if received.  This cannot be implemented
+ *   simply as an incomplete code since those two symbols are in the "middle"
+ *   of the code.  They are eight bits long and the longest literal/length\
+ *   code is nine bits.  Therefore the code must be constructed with those
+ *   symbols, and the invalid symbols must be detected after decoding.
+ *
+ * - The fixed distance codes also have two invalid symbols that should result
+ *   in an error if received.  Since all of the distance codes are the same
+ *   length, this can be implemented as an incomplete code.  Then the invalid
+ *   codes are detected while decoding.
+ */
+local int fixed(struct state *s)
+{
+    static int virgin = 1;
+    static short lencnt[MAXBITS+1], lensym[FIXLCODES];
+    static short distcnt[MAXBITS+1], distsym[MAXDCODES];
+    static struct huffman lencode = {lencnt, lensym};
+    static struct huffman distcode = {distcnt, distsym};
+
+    /* build fixed huffman tables if first call (may not be thread safe) */
+    if (virgin) {
+        int symbol;
+        short lengths[FIXLCODES];
+
+        /* literal/length table */
+        for (symbol = 0; symbol < 144; symbol++)
+            lengths[symbol] = 8;
+        for (; symbol < 256; symbol++)
+            lengths[symbol] = 9;
+        for (; symbol < 280; symbol++)
+            lengths[symbol] = 7;
+        for (; symbol < FIXLCODES; symbol++)
+            lengths[symbol] = 8;
+        construct(&lencode, lengths, FIXLCODES);
+
+        /* distance table */
+        for (symbol = 0; symbol < MAXDCODES; symbol++)
+            lengths[symbol] = 5;
+        construct(&distcode, lengths, MAXDCODES);
+
+        /* do this just once */
+        virgin = 0;
+    }
+
+    /* decode data until end-of-block code */
+    return codes(s, &lencode, &distcode);
+}
+
+/*
+ * Process a dynamic codes block.
+ *
+ * Format notes:
+ *
+ * - A dynamic block starts with a description of the literal/length and
+ *   distance codes for that block.  New dynamic blocks allow the compressor to
+ *   rapidly adapt to changing data with new codes optimized for that data.
+ *
+ * - The codes used by the deflate format are "canonical", which means that
+ *   the actual bits of the codes are generated in an unambiguous way simply
+ *   from the number of bits in each code.  Therefore the code descriptions
+ *   are simply a list of code lengths for each symbol.
+ *
+ * - The code lengths are stored in order for the symbols, so lengths are
+ *   provided for each of the literal/length symbols, and for each of the
+ *   distance symbols.
+ *
+ * - If a symbol is not used in the block, this is represented by a zero as
+ *   as the code length.  This does not mean a zero-length code, but rather
+ *   that no code should be created for this symbol.  There is no way in the
+ *   deflate format to represent a zero-length code.
+ *
+ * - The maximum number of bits in a code is 15, so the possible lengths for
+ *   any code are 1..15.
+ *
+ * - The fact that a length of zero is not permitted for a code has an
+ *   interesting consequence.  Normally if only one symbol is used for a given
+ *   code, then in fact that code could be represented with zero bits.  However
+ *   in deflate, that code has to be at least one bit.  So for example, if
+ *   only a single distance base symbol appears in a block, then it will be
+ *   represented by a single code of length one, in particular one 0 bit.  This
+ *   is an incomplete code, since if a 1 bit is received, it has no meaning,
+ *   and should result in an error.  So incomplete distance codes of one symbol
+ *   should be permitted, and the receipt of invalid codes should be handled.
+ *
+ * - It is also possible to have a single literal/length code, but that code
+ *   must be the end-of-block code, since every dynamic block has one.  This
+ *   is not the most efficient way to create an empty block (an empty fixed
+ *   block is fewer bits), but it is allowed by the format.  So incomplete
+ *   literal/length codes of one symbol should also be permitted.
+ *
+ * - The list of up to 286 length/literal lengths and up to 30 distance lengths
+ *   are themselves compressed using Huffman codes and run-length encoding.  In
+ *   the list of code lengths, a 0 symbol means no code, a 1..15 symbol means
+ *   that length, and the symbols 16, 17, and 18 are run-length instructions.
+ *   Each of 16, 17, and 18 are follwed by extra bits to define the length of
+ *   the run.  16 copies the last length 3 to 6 times.  17 represents 3 to 10
+ *   zero lengths, and 18 represents 11 to 138 zero lengths.  Unused symbols
+ *   are common, hence the special coding for zero lengths.
+ *
+ * - The symbols for 0..18 are Huffman coded, and so that code must be
+ *   described first.  This is simply a sequence of up to 19 three-bit values
+ *   representing no code (0) or the code length for that symbol (1..7).
+ *
+ * - A dynamic block starts with three fixed-size counts from which is computed
+ *   the number of literal/length code lengths, the number of distance code
+ *   lengths, and the number of code length code lengths (ok, you come up with
+ *   a better name!) in the code descriptions.  For the literal/length and
+ *   distance codes, lengths after those provided are considered zero, i.e. no
+ *   code.  The code length code lengths are received in a permuted order (see
+ *   the order[] array below) to make a short code length code length list more
+ *   likely.  As it turns out, very short and very long codes are less likely
+ *   to be seen in a dynamic code description, hence what may appear initially
+ *   to be a peculiar ordering.
+ *
+ * - Given the number of literal/length code lengths (nlen) and distance code
+ *   lengths (ndist), then they are treated as one long list of nlen + ndist
+ *   code lengths.  Therefore run-length coding can and often does cross the
+ *   boundary between the two sets of lengths.
+ *
+ * - So to summarize, the code description at the start of a dynamic block is
+ *   three counts for the number of code lengths for the literal/length codes,
+ *   the distance codes, and the code length codes.  This is followed by the
+ *   code length code lengths, three bits each.  This is used to construct the
+ *   code length code which is used to read the remainder of the lengths.  Then
+ *   the literal/length code lengths and distance lengths are read as a single
+ *   set of lengths using the code length codes.  Codes are constructed from
+ *   the resulting two sets of lengths, and then finally you can start
+ *   decoding actual compressed data in the block.
+ *
+ * - For reference, a "typical" size for the code description in a dynamic
+ *   block is around 80 bytes.
+ */
+local int dynamic(struct state *s)
+{
+    int nlen, ndist, ncode;             /* number of lengths in descriptor */
+    int index;                          /* index of lengths[] */
+    int err;                            /* construct() return value */
+    short lengths[MAXCODES];            /* descriptor code lengths */
+    short lencnt[MAXBITS+1], lensym[MAXLCODES];         /* lencode memory */
+    short distcnt[MAXBITS+1], distsym[MAXDCODES];       /* distcode memory */
+    struct huffman lencode = {lencnt, lensym};          /* length code */
+    struct huffman distcode = {distcnt, distsym};       /* distance code */
+    static const short order[19] =      /* permutation of code length codes */
+        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+    /* get number of lengths in each table, check lengths */
+    nlen = bits(s, 5) + 257;
+    ndist = bits(s, 5) + 1;
+    ncode = bits(s, 4) + 4;
+    if (nlen > MAXLCODES || ndist > MAXDCODES)
+        return -3;                      /* bad counts */
+
+    /* read code length code lengths (really), missing lengths are zero */
+    for (index = 0; index < ncode; index++)
+        lengths[order[index]] = bits(s, 3);
+    for (; index < 19; index++)
+        lengths[order[index]] = 0;
+
+    /* build huffman table for code lengths codes (use lencode temporarily) */
+    err = construct(&lencode, lengths, 19);
+    if (err != 0) return -4;            /* require complete code set here */
+
+    /* read length/literal and distance code length tables */
+    index = 0;
+    while (index < nlen + ndist) {
+        int symbol;             /* decoded value */
+        int len;                /* last length to repeat */
+
+        symbol = decode(s, &lencode);
+        if (symbol < 16)                /* length in 0..15 */
+            lengths[index++] = symbol;
+        else {                          /* repeat instruction */
+            len = 0;                    /* assume repeating zeros */
+            if (symbol == 16) {         /* repeat last length 3..6 times */
+                if (index == 0) return -5;      /* no last length! */
+                len = lengths[index - 1];       /* last length */
+                symbol = 3 + bits(s, 2);
+            }
+            else if (symbol == 17)      /* repeat zero 3..10 times */
+                symbol = 3 + bits(s, 3);
+            else                        /* == 18, repeat zero 11..138 times */
+                symbol = 11 + bits(s, 7);
+            if (index + symbol > nlen + ndist)
+                return -6;              /* too many lengths! */
+            while (symbol--)            /* repeat last or zero symbol times */
+                lengths[index++] = len;
+        }
+    }
+
+    /* build huffman table for literal/length codes */
+    err = construct(&lencode, lengths, nlen);
+    if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1))
+        return -7;      /* only allow incomplete codes if just one code */
+
+    /* build huffman table for distance codes */
+    err = construct(&distcode, lengths + nlen, ndist);
+    if (err < 0 || (err > 0 && ndist - distcode.count[0] != 1))
+        return -8;      /* only allow incomplete codes if just one code */
+
+    /* decode data until end-of-block code */
+    return codes(s, &lencode, &distcode);
+}
+
+/*
+ * Inflate source to dest.  On return, destlen and sourcelen are updated to the
+ * size of the uncompressed data and the size of the deflate data respectively.
+ * On success, the return value of puff() is zero.  If there is an error in the
+ * source data, i.e. it is not in the deflate format, then a negative value is
+ * returned.  If there is not enough input available or there is not enough
+ * output space, then a positive error is returned.  In that case, destlen and
+ * sourcelen are not updated to facilitate retrying from the beginning with the
+ * provision of more input data or more output space.  In the case of invalid
+ * inflate data (a negative error), the dest and source pointers are updated to
+ * facilitate the debugging of deflators.
+ *
+ * puff() also has a mode to determine the size of the uncompressed output with
+ * no output written.  For this dest must be (unsigned char *)0.  In this case,
+ * the input value of *destlen is ignored, and on return *destlen is set to the
+ * size of the uncompressed output.
+ *
+ * The return codes are:
+ *
+ *   2:  available inflate data did not terminate
+ *   1:  output space exhausted before completing inflate
+ *   0:  successful inflate
+ *  -1:  invalid block type (type == 3)
+ *  -2:  stored block length did not match one's complement
+ *  -3:  dynamic block code description: too many length or distance codes
+ *  -4:  dynamic block code description: code lengths codes incomplete
+ *  -5:  dynamic block code description: repeat lengths with no first length
+ *  -6:  dynamic block code description: repeat more than specified lengths
+ *  -7:  dynamic block code description: invalid literal/length code lengths
+ *  -8:  dynamic block code description: invalid distance code lengths
+ *  -9:  invalid literal/length or distance code in fixed or dynamic block
+ * -10:  distance is too far back in fixed or dynamic block
+ *
+ * Format notes:
+ *
+ * - Three bits are read for each block to determine the kind of block and
+ *   whether or not it is the last block.  Then the block is decoded and the
+ *   process repeated if it was not the last block.
+ *
+ * - The leftover bits in the last byte of the deflate data after the last
+ *   block (if it was a fixed or dynamic block) are undefined and have no
+ *   expected values to check.
+ */
+int puff(unsigned char *dest,           /* pointer to destination pointer */
+         unsigned long *destlen,        /* amount of output space */
+         unsigned char *source,         /* pointer to source data pointer */
+         unsigned long *sourcelen)      /* amount of input available */
+{
+    struct state s;             /* input/output state */
+    int last, type;             /* block information */
+    int err;                    /* return value */
+
+    /* initialize output state */
+    s.out = dest;
+    s.outlen = *destlen;                /* ignored if dest is NIL */
+    s.outcnt = 0;
+
+    /* initialize input state */
+    s.in = source;
+    s.inlen = *sourcelen;
+    s.incnt = 0;
+    s.bitbuf = 0;
+    s.bitcnt = 0;
+
+    /* return if bits() or decode() tries to read past available input */
+    if (setjmp(s.env) != 0)             /* if came back here via longjmp() */
+        err = 2;                        /* then skip do-loop, return error */
+    else {
+        /* process blocks until last block or error */
+        do {
+            last = bits(&s, 1);         /* one if last block */
+            type = bits(&s, 2);         /* block type 0..3 */
+            err = type == 0 ? stored(&s) :
+                  (type == 1 ? fixed(&s) :
+                   (type == 2 ? dynamic(&s) :
+                    -1));               /* type == 3, invalid */
+            if (err != 0) break;        /* return with error */
+        } while (!last);
+    }
+
+    /* update the lengths and return */
+    if (err <= 0) {
+        *destlen = s.outcnt;
+        *sourcelen = s.incnt;
+    }
+    return err;
+}
+
+#ifdef TEST
+/* Example of how to use puff() */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+local unsigned char *yank(char *name, unsigned long *len)
+{
+    unsigned long size;
+    unsigned char *buf;
+    FILE *in;
+    struct stat s;
+
+    *len = 0;
+    if (stat(name, &s)) return NULL;
+    if ((s.st_mode & S_IFMT) != S_IFREG) return NULL;
+    size = (unsigned long)(s.st_size);
+    if (size == 0 || (off_t)size != s.st_size) return NULL;
+    in = fopen(name, "r");
+    if (in == NULL) return NULL;
+    buf = malloc(size);
+    if (buf != NULL && fread(buf, 1, size, in) != size) {
+        free(buf);
+        buf = NULL;
+    }
+    fclose(in);
+    *len = size;    
+    return buf;
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+    unsigned char *source;
+    unsigned long len, sourcelen, destlen;
+
+    if (argc < 2) return 2;
+    source = yank(argv[1], &len);
+    if (source == NULL) return 2;
+    sourcelen = len;
+    ret = puff(NIL, &destlen, source, &sourcelen);
+    if (ret)
+        printf("puff() failed with return code %d\n", ret);
+    else {
+        printf("puff() succeeded uncompressing %lu bytes\n", destlen);
+        if (sourcelen < len) printf("%lu compressed bytes unused\n",
+                                    len - sourcelen);
+    }
+    free(source);
+    return ret;
+}
+#endif
diff --git a/zlib/contrib/puff/puff.h b/zlib/contrib/puff/puff.h
new file mode 100644 (file)
index 0000000..41ea7e1
--- /dev/null
@@ -0,0 +1,31 @@
+/* puff.h
+  Copyright (C) 2002, 2003 Mark Adler, all rights reserved
+  version 1.7, 3 Mar 2002
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the author 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.
+
+  Mark Adler   madler@alumni.caltech.edu
+ */
+
+
+/*
+ * See puff.c for purpose and usage.
+ */
+int puff(unsigned char *dest,           /* pointer to destination pointer */
+         unsigned long *destlen,        /* amount of output space */
+         unsigned char *source,         /* pointer to source data pointer */
+         unsigned long *sourcelen);     /* amount of input available */
diff --git a/zlib/contrib/puff/zeros.raw b/zlib/contrib/puff/zeros.raw
new file mode 100644 (file)
index 0000000..637b7be
Binary files /dev/null and b/zlib/contrib/puff/zeros.raw differ
diff --git a/zlib/contrib/testzlib/testzlib.c b/zlib/contrib/testzlib/testzlib.c
new file mode 100644 (file)
index 0000000..caae4ef
--- /dev/null
@@ -0,0 +1,149 @@
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <windows.h>\r
+#include "zlib.h"\r
+\r
+int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr)\r
+{\r
+    FILE* stream;\r
+    void* ptr;\r
+    int retVal=1;\r
+    stream=fopen(filename, "rb");\r
+    if (stream==NULL)\r
+        return 0;\r
+\r
+    fseek(stream,0,SEEK_END);\r
+\r
+    *plFileSize=ftell(stream);\r
+    fseek(stream,0,SEEK_SET);\r
+    ptr=malloc((*plFileSize)+1);\r
+    if (ptr==NULL)\r
+        retVal=0;\r
+    else\r
+    {\r
+        if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize))\r
+            retVal=0;\r
+    }\r
+    fclose(stream);\r
+    *pFilePtr=ptr;\r
+    return retVal;\r
+}\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+    int BlockSizeCompress=0x8000;\r
+    int BlockSizeUncompress=0x8000;\r
+    int cprLevel=Z_DEFAULT_COMPRESSION ;\r
+    long lFileSize;\r
+    unsigned char* FilePtr;\r
+    long lBufferSizeCpr;\r
+    long lBufferSizeUncpr;\r
+    long lCompressedSize=0;\r
+    unsigned char* CprPtr;\r
+    unsigned char* UncprPtr;\r
+    long lSizeCpr,lSizeUncpr;\r
+    DWORD dwGetTick;\r
+\r
+    if (argc<=1)\r
+    {\r
+        printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n");\r
+        return 0;\r
+    }\r
+\r
+    if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)\r
+    {\r
+        printf("error reading %s\n",argv[1]);\r
+        return 1;\r
+    }\r
+    else printf("file %s read, %u bytes\n",argv[1],lFileSize);\r
+\r
+    if (argc>=3)\r
+        BlockSizeCompress=atol(argv[2]);\r
+\r
+    if (argc>=4)\r
+        BlockSizeUncompress=atol(argv[3]);\r
+\r
+    if (argc>=5)\r
+        cprLevel=(int)atol(argv[4]);\r
+\r
+    lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200;\r
+    lBufferSizeUncpr = lBufferSizeCpr;\r
+\r
+    CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress);\r
+    UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress);\r
+\r
+    dwGetTick=GetTickCount();\r
+    {\r
+        z_stream zcpr;\r
+        int ret=Z_OK;\r
+        long lOrigToDo = lFileSize;\r
+        long lOrigDone = 0;\r
+        int step=0;\r
+        memset(&zcpr,0,sizeof(z_stream));\r
+        deflateInit(&zcpr,cprLevel);\r
+\r
+        zcpr.next_in = FilePtr;\r
+        zcpr.next_out = CprPtr;\r
+\r
+\r
+        do\r
+        {\r
+            long all_read_before = zcpr.total_in;\r
+            zcpr.avail_in = min(lOrigToDo,BlockSizeCompress);\r
+            zcpr.avail_out = BlockSizeCompress;\r
+            ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH);\r
+            lOrigDone += (zcpr.total_in-all_read_before);\r
+            lOrigToDo -= (zcpr.total_in-all_read_before);\r
+            step++;\r
+        } while (ret==Z_OK);\r
+\r
+        lSizeCpr=zcpr.total_out;\r
+        deflateEnd(&zcpr);\r
+        dwGetTick=GetTickCount()-dwGetTick;\r
+        printf("total compress size = %u, in %u step\n",lSizeCpr,step);\r
+        printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);\r
+    }\r
+\r
+    dwGetTick=GetTickCount();\r
+    {\r
+        z_stream zcpr;\r
+        int ret=Z_OK;\r
+        long lOrigToDo = lSizeCpr;\r
+        long lOrigDone = 0;\r
+        int step=0;\r
+        memset(&zcpr,0,sizeof(z_stream));\r
+        inflateInit(&zcpr);\r
+\r
+        zcpr.next_in = CprPtr;\r
+        zcpr.next_out = UncprPtr;\r
+\r
+\r
+        do\r
+        {\r
+            long all_read_before = zcpr.total_in;\r
+            zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress);\r
+            zcpr.avail_out = BlockSizeUncompress;\r
+            ret=inflate(&zcpr,Z_SYNC_FLUSH);\r
+            lOrigDone += (zcpr.total_in-all_read_before);\r
+            lOrigToDo -= (zcpr.total_in-all_read_before);\r
+            step++;\r
+        } while (ret==Z_OK);\r
+\r
+        lSizeUncpr=zcpr.total_out;\r
+        inflateEnd(&zcpr);\r
+        dwGetTick=GetTickCount()-dwGetTick;\r
+        printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step);\r
+        printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);\r
+    }\r
+\r
+    if (lSizeUncpr==lFileSize)\r
+    {\r
+        if (memcmp(FilePtr,UncprPtr,lFileSize)==0)\r
+            printf("compare ok\n");\r
+\r
+    }\r
+\r
+    return 0;\r
+\r
+}\r
diff --git a/zlib/contrib/testzlib/testzlib.sln b/zlib/contrib/testzlib/testzlib.sln
new file mode 100644 (file)
index 0000000..86da716
--- /dev/null
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 7.00\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfiguration) = preSolution\r
+               ConfigName.0 = Debug\r
+               ConfigName.1 = Release\r
+       EndGlobalSection\r
+       GlobalSection(ProjectDependencies) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfiguration) = postSolution\r
+               {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32\r
+               {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32\r
+               {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32\r
+               {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityGlobals) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityAddIns) = postSolution\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/zlib/contrib/testzlib/testzlib.vcproj b/zlib/contrib/testzlib/testzlib.vcproj
new file mode 100644 (file)
index 0000000..8e4233a
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding = "Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.00"\r
+       Name="testzlib"\r
+       ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"\r
+       Keyword="Win32Proj">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="Debug"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="TRUE"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="5"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/testzlib.exe"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile="$(OutDir)/testzlib.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="Release"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               InlineFunctionExpansion="1"\r
+                               OmitFramePointers="TRUE"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               StringPooling="TRUE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="3"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/testzlib.exe"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="TRUE"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               OptimizeForWindows98="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">\r
+                       <File\r
+                               RelativePath="testzlib.c">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc">\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">\r
+               </Filter>\r
+               <File\r
+                       RelativePath="zlib.lib">\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/zlib/contrib/vstudio/readme.txt b/zlib/contrib/vstudio/readme.txt
new file mode 100644 (file)
index 0000000..a619b96
--- /dev/null
@@ -0,0 +1,17 @@
+For create the 16 and 32 bits DLL of Zlib 1.20\r
+\r
+For the 16 bits :\r
+unzip zlib120.zip and copy file from contrib\vstudio\vc15_16 and from contrib\minizip in the same directory\r
+open zlib16.mak with Microsoft Visual C++ 1.52\r
+\r
+\r
+For the 32 bits :\r
+unzip zlib120.zip and copy file from contrib\vstudio\vc70_32 and from contrib\minizip in the same directory\r
+You can also need unzip http://www.winimage.com/zLibDll/crtdll.zip\r
+\r
+If you are using x86, use target Release\r
+open zlibvc.sln with Microsoft Visual C++ 7.0 (Visual Studio .net)\r
+\r
+\r
+Note : You don't need recompile yourself. There is compiled .LIB in\r
+  http://www.winimage.com/zLibDll\r
diff --git a/zlib/contrib/vstudio/vc15_16/zlib16.def b/zlib/contrib/vstudio/vc15_16/zlib16.def
new file mode 100644 (file)
index 0000000..89cb8d1
--- /dev/null
@@ -0,0 +1,94 @@
+LIBRARY                "zlib"\r
+\r
+DESCRIPTION    '"""zlib data compression library"""'\r
+\r
+EXETYPE                WINDOWS\r
+\r
+VERSION                1.20\r
+\r
+CODE    PRELOAD MOVEABLE DISCARDABLE\r
+DATA    PRELOAD MOVEABLE SINGLE\r
+\r
+\r
+HEAPSIZE       32768,8192\r
+\r
+EXPORTS\r
+        adler32                                  @1\r
+        compress                                 @2\r
+        crc32                                    @3\r
+        deflate                                  @4\r
+        deflateCopy                              @5\r
+        deflateEnd                               @6\r
+        deflateInit2_                            @7\r
+        deflateInit_                             @8\r
+        deflateParams                            @9\r
+        deflateReset                             @10\r
+        deflateSetDictionary                     @11\r
+        gzclose                                  @12\r
+        gzdopen                                  @13\r
+        gzerror                                  @14\r
+        gzflush                                  @15\r
+        gzopen                                   @16\r
+        gzread                                   @17\r
+        gzwrite                                  @18\r
+        inflate                                  @19\r
+        inflateEnd                               @20\r
+        inflateInit2_                            @21\r
+        inflateInit_                             @22\r
+        inflateReset                             @23\r
+        inflateSetDictionary                     @24\r
+        inflateSync                              @25\r
+        uncompress                               @26\r
+        zlibVersion                              @27\r
+        _gzprintf                                @28\r
+        gzputc                                   @29\r
+        gzgetc                                   @30\r
+        gzseek                                   @31\r
+        gzrewind                                 @32\r
+        gztell                                   @33\r
+        gzeof                                    @34\r
+        gzsetparams                              @35\r
+        zError                                   @36\r
+        inflateSyncPoint                         @37\r
+        get_crc_table                            @38\r
+        compress2                                @39\r
+        gzputs                                   @40\r
+        gzgets                                   @41\r
+        inflateCopy                              @42\r
+        inflateBackInit_                         @43\r
+        inflateBack                              @44\r
+        inflateBackEnd                           @45\r
+        compressBound                            @46\r
+\r
+        unzOpen                                  @61\r
+        unzClose                                 @62\r
+        unzGetGlobalInfo                         @63\r
+        unzGetCurrentFileInfo                    @64\r
+        unzGoToFirstFile                         @65\r
+        unzGoToNextFile                          @66\r
+        unzOpenCurrentFile                       @67\r
+        unzReadCurrentFile                       @68\r
+        unzOpenCurrentFile3                      @69\r
+        unztell                                  @70\r
+        unzeof                                   @71\r
+        unzCloseCurrentFile                      @72\r
+        unzGetGlobalComment                      @73\r
+        unzStringFileNameCompare                 @74\r
+        unzLocateFile                            @75\r
+        unzGetLocalExtrafield                    @76\r
+        unzOpen2                                 @77\r
+        unzOpenCurrentFile2                      @78\r
+        unzOpenCurrentFilePassword               @79\r
+\r
+        zipOpen                                  @80\r
+        zipOpenNewFileInZip                      @81\r
+        zipWriteInFileInZip                      @82\r
+        zipCloseFileInZip                        @83\r
+        zipClose                                 @84\r
+        zipOpenNewFileInZip2                     @86\r
+        zipCloseFileInZipRaw                     @87\r
+        zipOpen2                                 @88\r
+        zipOpenNewFileInZip3                     @89\r
+\r
+        unzGetFilePos                            @100\r
+        unzGoToFilePos                           @101\r
diff --git a/zlib/contrib/vstudio/vc15_16/zlib16.mak b/zlib/contrib/vstudio/vc15_16/zlib16.mak
new file mode 100644 (file)
index 0000000..75c8d80
--- /dev/null
@@ -0,0 +1,256 @@
+# Microsoft Visual C++ generated build script - Do not modify\r
+\r
+PROJ = ZLIB16\r
+DEBUG = 0\r
+PROGTYPE = 1\r
+CALLER = \r
+ARGS = \r
+DLLS = \r
+D_RCDEFINES = -d_DEBUG\r
+R_RCDEFINES = -dNDEBUG\r
+ORIGIN = MSVC\r
+ORIGIN_VER = 1.00\r
+PROJPATH = c:\zlib\\r
+USEMFC = 0\r
+CC = cl\r
+CPP = cl\r
+CXX = cl\r
+CCREATEPCHFLAG = \r
+CPPCREATEPCHFLAG = \r
+CUSEPCHFLAG = \r
+CPPUSEPCHFLAG = \r
+FIRSTC = ADLER32.C   \r
+FIRSTCPP =             \r
+RC = rc\r
+CFLAGS_D_WDLL = /nologo /G2 /W3 /Zi /ALw /Od /D "_DEBUG" /D "WINDOWS" /D "ZLIB_DLL" /FR /GD /Fd"ZLIB.PDB"\r
+CFLAGS_R_WDLL = /nologo /W3 /ALw /O1 /D "NDEBUG" /D "WINDOWS" /D "ZLIB_DLL" /FR /GD \r
+LFLAGS_D_WDLL = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /CO /NOE /ALIGN:16 /MAP:FULL\r
+LFLAGS_R_WDLL = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /NOE /ALIGN:16 /MAP:FULL\r
+LIBS_D_WDLL = oldnames libw commdlg shell olecli olesvr ldllcew\r
+LIBS_R_WDLL = oldnames libw commdlg shell olecli olesvr ldllcew\r
+RCFLAGS = /nologo\r
+RESFLAGS = /nologo\r
+RUNFLAGS = \r
+DEFFILE = ZLIB16.DEF\r
+OBJS_EXT = \r
+LIBS_EXT = \r
+!if "$(DEBUG)" == "1"\r
+CFLAGS = $(CFLAGS_D_WDLL)\r
+LFLAGS = $(LFLAGS_D_WDLL)\r
+LIBS = $(LIBS_D_WDLL)\r
+MAPFILE = nul\r
+RCDEFINES = $(D_RCDEFINES)\r
+!else\r
+CFLAGS = $(CFLAGS_R_WDLL)\r
+LFLAGS = $(LFLAGS_R_WDLL)\r
+LIBS = $(LIBS_R_WDLL)\r
+MAPFILE = nul\r
+RCDEFINES = $(R_RCDEFINES)\r
+!endif\r
+!if [if exist MSVC.BND del MSVC.BND]\r
+!endif\r
+SBRS = ADLER32.SBR \\r
+               COMPRESS.SBR \\r
+               CRC32.SBR \\r
+               DEFLATE.SBR \\r
+               GZIO.SBR \\r
+               INFFAST.SBR \\r
+               INFLATE.SBR \\r
+               TREES.SBR \\r
+               UNCOMPR.SBR \\r
+               ZUTIL.SBR \\r
+               ZIP.SBR \\r
+               UNZIP.SBR \\r
+               INFBACK.SBR \\r
+               IOAPI.SBR \\r
+               INFTREES.SBR\r
+\r
+\r
+ADLER32_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+COMPRESS_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+CRC32_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\crc32.h\r
+\r
+\r
+DEFLATE_DEP = c:\zlib\deflate.h \\r
+       c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+GZIO_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+INFFAST_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\inftrees.h \\r
+       c:\zlib\inflate.h \\r
+       c:\zlib\inffast.h\r
+\r
+\r
+INFLATE_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\inftrees.h \\r
+       c:\zlib\inflate.h \\r
+       c:\zlib\inffast.h \\r
+       c:\zlib\inffixed.h\r
+\r
+\r
+TREES_DEP = c:\zlib\deflate.h \\r
+       c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\trees.h\r
+\r
+\r
+UNCOMPR_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+ZUTIL_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h\r
+\r
+\r
+ZLIB16_RCDEP = \r
+\r
+ZIP_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\zip.h \\r
+       c:\zlib\ioapi.h\r
+\r
+\r
+UNZIP_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\unzip.h \\r
+       c:\zlib\ioapi.h\r
+\r
+\r
+INFBACK_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\inftrees.h \\r
+       c:\zlib\inflate.h \\r
+       c:\zlib\inffast.h \\r
+       c:\zlib\inffixed.h\r
+\r
+\r
+IOAPI_DEP = c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\ioapi.h\r
+\r
+\r
+INFTREES_DEP = c:\zlib\zutil.h \\r
+       c:\zlib\zlib.h \\r
+       c:\zlib\zconf.h \\r
+       c:\zlib\inftrees.h\r
+\r
+\r
+all:   $(PROJ).DLL $(PROJ).BSC\r
+\r
+ADLER32.OBJ:   ADLER32.C $(ADLER32_DEP)\r
+       $(CC) $(CFLAGS) $(CCREATEPCHFLAG) /c ADLER32.C\r
+\r
+COMPRESS.OBJ:  COMPRESS.C $(COMPRESS_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c COMPRESS.C\r
+\r
+CRC32.OBJ:     CRC32.C $(CRC32_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c CRC32.C\r
+\r
+DEFLATE.OBJ:   DEFLATE.C $(DEFLATE_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c DEFLATE.C\r
+\r
+GZIO.OBJ:      GZIO.C $(GZIO_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c GZIO.C\r
+\r
+INFFAST.OBJ:   INFFAST.C $(INFFAST_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFFAST.C\r
+\r
+INFLATE.OBJ:   INFLATE.C $(INFLATE_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFLATE.C\r
+\r
+TREES.OBJ:     TREES.C $(TREES_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c TREES.C\r
+\r
+UNCOMPR.OBJ:   UNCOMPR.C $(UNCOMPR_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c UNCOMPR.C\r
+\r
+ZUTIL.OBJ:     ZUTIL.C $(ZUTIL_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c ZUTIL.C\r
+\r
+ZLIB16.RES:    ZLIB16.RC $(ZLIB16_RCDEP)\r
+       $(RC) $(RCFLAGS) $(RCDEFINES) -r ZLIB16.RC\r
+\r
+ZIP.OBJ:       ZIP.C $(ZIP_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c ZIP.C\r
+\r
+UNZIP.OBJ:     UNZIP.C $(UNZIP_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c UNZIP.C\r
+\r
+INFBACK.OBJ:   INFBACK.C $(INFBACK_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFBACK.C\r
+\r
+IOAPI.OBJ:     IOAPI.C $(IOAPI_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c IOAPI.C\r
+\r
+INFTREES.OBJ:  INFTREES.C $(INFTREES_DEP)\r
+       $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFTREES.C\r
+\r
+\r
+$(PROJ).DLL::  ZLIB16.RES\r
+\r
+$(PROJ).DLL::  ADLER32.OBJ COMPRESS.OBJ CRC32.OBJ DEFLATE.OBJ GZIO.OBJ INFFAST.OBJ \\r
+       INFLATE.OBJ TREES.OBJ UNCOMPR.OBJ ZUTIL.OBJ ZIP.OBJ UNZIP.OBJ INFBACK.OBJ IOAPI.OBJ \\r
+       INFTREES.OBJ $(OBJS_EXT) $(DEFFILE)\r
+       echo >NUL @<<$(PROJ).CRF\r
+ADLER32.OBJ +\r
+COMPRESS.OBJ +\r
+CRC32.OBJ +\r
+DEFLATE.OBJ +\r
+GZIO.OBJ +\r
+INFFAST.OBJ +\r
+INFLATE.OBJ +\r
+TREES.OBJ +\r
+UNCOMPR.OBJ +\r
+ZUTIL.OBJ +\r
+ZIP.OBJ +\r
+UNZIP.OBJ +\r
+INFBACK.OBJ +\r
+IOAPI.OBJ +\r
+INFTREES.OBJ +\r
+$(OBJS_EXT)\r
+$(PROJ).DLL\r
+$(MAPFILE)\r
+C:\MSVC\LIB\+\r
+C:\MSVC\MFC\LIB\+\r
+E:\PROGRAMFILES\MICROSOFTVISUALSTUDIO.NET\FRAMEWORKSDK\LIB\+\r
+$(LIBS)\r
+$(DEFFILE);\r
+<<\r
+       link $(LFLAGS) @$(PROJ).CRF\r
+       $(RC) $(RESFLAGS) ZLIB16.RES $@\r
+       @copy $(PROJ).CRF MSVC.BND\r
+       implib /nowep $(PROJ).LIB $(PROJ).DLL\r
+\r
+$(PROJ).DLL::  ZLIB16.RES\r
+       if not exist MSVC.BND   $(RC) $(RESFLAGS) ZLIB16.RES $@\r
+\r
+run: $(PROJ).DLL\r
+       $(PROJ) $(RUNFLAGS)\r
+\r
+\r
+$(PROJ).BSC: $(SBRS)\r
+       bscmake @<<\r
+/o$@ $(SBRS)\r
+<<\r
diff --git a/zlib/contrib/vstudio/vc15_16/zlib16.rc b/zlib/contrib/vstudio/vc15_16/zlib16.rc
new file mode 100644 (file)
index 0000000..13d0d66
--- /dev/null
@@ -0,0 +1,33 @@
+#include <windows.h>\r
+#include <ver.h>\r
+\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
+  FILEFLAGSMASK        VS_FFI_FILEFLAGSMASK\r
+  FILEFLAGS    0\r
+  FILEOS       VOS_DOS_WINDOWS16\r
+  FILETYPE     VFT_DLL\r
+  FILESUBTYPE  0       // not used\r
+BEGIN\r
+  BLOCK "StringFileInfo"\r
+  BEGIN\r
+    BLOCK "040904E4"\r
+    //language ID = U.S. English, char set = Windows, Multilingual\r
+\r
+    BEGIN\r
+      VALUE "FileDescription", "zlib data compression library\0"\r
+      VALUE "FileVersion",     "1.2.0\0"\r
+      VALUE "InternalName",    "zlib16\0"\r
+      VALUE "OriginalFilename",        "zlib16.dll\0"\r
+      VALUE "ProductName",     "ZLib16.DLL\0"\r
+      VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"\r
+      VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"\r
+    END\r
+  END\r
+  BLOCK "VarFileInfo"\r
+  BEGIN\r
+    VALUE "Translation", 0x0409, 1252\r
+  END\r
+END\r
diff --git a/zlib/contrib/vstudio/vc70_32/gvmat32.asm b/zlib/contrib/vstudio/vc70_32/gvmat32.asm
new file mode 100644 (file)
index 0000000..320348f
--- /dev/null
@@ -0,0 +1,905 @@
+;\r
+; gvmat32.asm -- Asm portion of the optimized longest_match for 32 bits x86\r
+; Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.\r
+; File written by Gilles Vollant, by modifiying the longest_match\r
+;  from Jean-loup Gailly in deflate.c\r
+; It need wmask == 0x7fff\r
+;     (assembly code is faster with a fixed wmask)\r
+;\r
+; For Visual C++ 4.2 and ML 6.11c (version in directory \MASM611C of Win95 DDK)\r
+;   I compile with : "ml /coff /Zi /c gvmat32.asm"\r
+;\r
+\r
+;uInt longest_match_7fff(s, cur_match)\r
+;    deflate_state *s;\r
+;    IPos cur_match;                             /* current match */\r
+\r
+        NbStack         equ     76\r
+        cur_match       equ     dword ptr[esp+NbStack-0]\r
+        str_s           equ     dword ptr[esp+NbStack-4]\r
+; 5 dword on top (ret,ebp,esi,edi,ebx)\r
+        adrret          equ     dword ptr[esp+NbStack-8]\r
+        pushebp         equ     dword ptr[esp+NbStack-12]\r
+        pushedi         equ     dword ptr[esp+NbStack-16]\r
+        pushesi         equ     dword ptr[esp+NbStack-20]\r
+        pushebx         equ     dword ptr[esp+NbStack-24]\r
+\r
+        chain_length    equ     dword ptr [esp+NbStack-28]\r
+        limit           equ     dword ptr [esp+NbStack-32]\r
+        best_len        equ     dword ptr [esp+NbStack-36]\r
+        window          equ     dword ptr [esp+NbStack-40]\r
+        prev            equ     dword ptr [esp+NbStack-44]\r
+        scan_start      equ      word ptr [esp+NbStack-48]\r
+        wmask           equ     dword ptr [esp+NbStack-52]\r
+        match_start_ptr equ     dword ptr [esp+NbStack-56]\r
+        nice_match      equ     dword ptr [esp+NbStack-60]\r
+        scan            equ     dword ptr [esp+NbStack-64]\r
+\r
+        windowlen       equ     dword ptr [esp+NbStack-68]\r
+        match_start     equ     dword ptr [esp+NbStack-72]\r
+        strend          equ     dword ptr [esp+NbStack-76]\r
+        NbStackAdd      equ     (NbStack-24)\r
+\r
+    .386p\r
+\r
+    name    gvmatch\r
+    .MODEL  FLAT\r
+\r
+\r
+\r
+;  all the +4 offsets are due to the addition of pending_buf_size (in zlib\r
+;  in the deflate_state structure since the asm code was first written\r
+;  (if you compile with zlib 1.0.4 or older, remove the +4).\r
+;  Note : these value are good with a 8 bytes boundary pack structure\r
+    dep_chain_length    equ     70h+4\r
+    dep_window          equ     2ch+4\r
+    dep_strstart        equ     60h+4\r
+    dep_prev_length     equ     6ch+4\r
+    dep_nice_match      equ     84h+4\r
+    dep_w_size          equ     20h+4\r
+    dep_prev            equ     34h+4\r
+    dep_w_mask          equ     28h+4\r
+    dep_good_match      equ     80h+4\r
+    dep_match_start     equ     64h+4\r
+    dep_lookahead       equ     68h+4\r
+\r
+\r
+_TEXT                   segment\r
+\r
+IFDEF NOUNDERLINE\r
+                        public  longest_match_7fff\r
+                        public  longest_match_686\r
+;                        public  match_init\r
+ELSE\r
+                        public  _longest_match_7fff\r
+                        public  _longest_match_686\r
+;                        public  _match_init\r
+ENDIF\r
+\r
+    MAX_MATCH           equ     258\r
+    MIN_MATCH           equ     3\r
+    MIN_LOOKAHEAD       equ     (MAX_MATCH+MIN_MATCH+1)\r
+\r
+\r
+\r
+IFDEF NOUNDERLINE\r
+;match_init      proc near\r
+;                ret\r
+;match_init      endp\r
+ELSE\r
+;_match_init     proc near\r
+;                ret\r
+;_match_init     endp\r
+ENDIF\r
+\r
+\r
+IFDEF NOUNDERLINE\r
+longest_match_7fff   proc near\r
+ELSE\r
+_longest_match_7fff  proc near\r
+ENDIF\r
+\r
+        mov     edx,[esp+4]\r
+\r
+\r
+\r
+        push    ebp\r
+        push    edi\r
+        push    esi\r
+        push    ebx\r
+\r
+        sub     esp,NbStackAdd\r
+\r
+; initialize or check the variables used in match.asm.\r
+        mov     ebp,edx\r
+\r
+; chain_length = s->max_chain_length\r
+; if (prev_length>=good_match) chain_length >>= 2\r
+        mov     edx,[ebp+dep_chain_length]\r
+        mov     ebx,[ebp+dep_prev_length]\r
+        cmp     [ebp+dep_good_match],ebx\r
+        ja      noshr\r
+        shr     edx,2\r
+noshr:\r
+; we increment chain_length because in the asm, the --chain_lenght is in the beginning of the loop\r
+        inc     edx\r
+        mov     edi,[ebp+dep_nice_match]\r
+        mov     chain_length,edx\r
+        mov     eax,[ebp+dep_lookahead]\r
+        cmp     eax,edi\r
+; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;\r
+        jae     nolookaheadnicematch\r
+        mov     edi,eax\r
+nolookaheadnicematch:\r
+; best_len = s->prev_length\r
+        mov     best_len,ebx\r
+\r
+; window = s->window\r
+        mov     esi,[ebp+dep_window]\r
+        mov     ecx,[ebp+dep_strstart]\r
+        mov     window,esi\r
+\r
+        mov     nice_match,edi\r
+; scan = window + strstart\r
+        add     esi,ecx\r
+        mov     scan,esi\r
+; dx = *window\r
+        mov     dx,word ptr [esi]\r
+; bx = *(window+best_len-1)\r
+        mov     bx,word ptr [esi+ebx-1]\r
+        add     esi,MAX_MATCH-1\r
+; scan_start = *scan\r
+        mov     scan_start,dx\r
+; strend = scan + MAX_MATCH-1\r
+        mov     strend,esi\r
+; bx = scan_end = *(window+best_len-1)\r
+\r
+;    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?\r
+;        s->strstart - (IPos)MAX_DIST(s) : NIL;\r
+\r
+        mov     esi,[ebp+dep_w_size]\r
+        sub     esi,MIN_LOOKAHEAD\r
+; here esi = MAX_DIST(s)\r
+        sub     ecx,esi\r
+        ja      nodist\r
+        xor     ecx,ecx\r
+nodist:\r
+        mov     limit,ecx\r
+\r
+; prev = s->prev\r
+        mov     edx,[ebp+dep_prev]\r
+        mov     prev,edx\r
+\r
+;\r
+        mov     edx,dword ptr [ebp+dep_match_start]\r
+        mov     bp,scan_start\r
+        mov     eax,cur_match\r
+        mov     match_start,edx\r
+\r
+        mov     edx,window\r
+        mov     edi,edx\r
+        add     edi,best_len\r
+        mov     esi,prev\r
+        dec     edi\r
+; windowlen = window + best_len -1\r
+        mov     windowlen,edi\r
+\r
+        jmp     beginloop2\r
+        align   4\r
+\r
+; here, in the loop\r
+;       eax = ax = cur_match\r
+;       ecx = limit\r
+;        bx = scan_end\r
+;        bp = scan_start\r
+;       edi = windowlen (window + best_len -1)\r
+;       esi = prev\r
+\r
+\r
+;// here; chain_length <=16\r
+normalbeg0add16:\r
+        add     chain_length,16\r
+        jz      exitloop\r
+normalbeg0:\r
+        cmp     word ptr[edi+eax],bx\r
+        je      normalbeg2noroll\r
+rcontlabnoroll:\r
+; cur_match = prev[cur_match & wmask]\r
+        and     eax,7fffh\r
+        mov     ax,word ptr[esi+eax*2]\r
+; if cur_match > limit, go to exitloop\r
+        cmp     ecx,eax\r
+        jnb     exitloop\r
+; if --chain_length != 0, go to exitloop\r
+        dec     chain_length\r
+        jnz     normalbeg0\r
+        jmp     exitloop\r
+\r
+normalbeg2noroll:\r
+; if (scan_start==*(cur_match+window)) goto normalbeg2\r
+        cmp     bp,word ptr[edx+eax]\r
+        jne     rcontlabnoroll\r
+        jmp     normalbeg2\r
+\r
+contloop3:\r
+        mov     edi,windowlen\r
+\r
+; cur_match = prev[cur_match & wmask]\r
+        and     eax,7fffh\r
+        mov     ax,word ptr[esi+eax*2]\r
+; if cur_match > limit, go to exitloop\r
+        cmp     ecx,eax\r
+jnbexitloopshort1:\r
+        jnb     exitloop\r
+; if --chain_length != 0, go to exitloop\r
+\r
+\r
+; begin the main loop\r
+beginloop2:\r
+        sub     chain_length,16+1\r
+; if chain_length <=16, don't use the unrolled loop\r
+        jna     normalbeg0add16\r
+\r
+do16:\r
+        cmp     word ptr[edi+eax],bx\r
+        je      normalbeg2dc0\r
+\r
+maccn   MACRO   lab\r
+        and     eax,7fffh\r
+        mov     ax,word ptr[esi+eax*2]\r
+        cmp     ecx,eax\r
+        jnb     exitloop\r
+        cmp     word ptr[edi+eax],bx\r
+        je      lab\r
+        ENDM\r
+\r
+rcontloop0:\r
+        maccn   normalbeg2dc1\r
+\r
+rcontloop1:\r
+        maccn   normalbeg2dc2\r
+\r
+rcontloop2:\r
+        maccn   normalbeg2dc3\r
+\r
+rcontloop3:\r
+        maccn   normalbeg2dc4\r
+\r
+rcontloop4:\r
+        maccn   normalbeg2dc5\r
+\r
+rcontloop5:\r
+        maccn   normalbeg2dc6\r
+\r
+rcontloop6:\r
+        maccn   normalbeg2dc7\r
+\r
+rcontloop7:\r
+        maccn   normalbeg2dc8\r
+\r
+rcontloop8:\r
+        maccn   normalbeg2dc9\r
+\r
+rcontloop9:\r
+        maccn   normalbeg2dc10\r
+\r
+rcontloop10:\r
+        maccn   short normalbeg2dc11\r
+\r
+rcontloop11:\r
+        maccn   short normalbeg2dc12\r
+\r
+rcontloop12:\r
+        maccn   short normalbeg2dc13\r
+\r
+rcontloop13:\r
+        maccn   short normalbeg2dc14\r
+\r
+rcontloop14:\r
+        maccn   short normalbeg2dc15\r
+\r
+rcontloop15:\r
+        and     eax,7fffh\r
+        mov     ax,word ptr[esi+eax*2]\r
+        cmp     ecx,eax\r
+        jnb     exitloop\r
+\r
+        sub     chain_length,16\r
+        ja      do16\r
+        jmp     normalbeg0add16\r
+\r
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
+\r
+normbeg MACRO   rcontlab,valsub\r
+; if we are here, we know that *(match+best_len-1) == scan_end\r
+        cmp     bp,word ptr[edx+eax]\r
+; if (match != scan_start) goto rcontlab\r
+        jne     rcontlab\r
+; calculate the good chain_length, and we'll compare scan and match string\r
+        add     chain_length,16-valsub\r
+        jmp     iseq\r
+        ENDM\r
+\r
+\r
+normalbeg2dc11:\r
+        normbeg rcontloop11,11\r
+\r
+normalbeg2dc12:\r
+        normbeg short rcontloop12,12\r
+\r
+normalbeg2dc13:\r
+        normbeg short rcontloop13,13\r
+\r
+normalbeg2dc14:\r
+        normbeg short rcontloop14,14\r
+\r
+normalbeg2dc15:\r
+        normbeg short rcontloop15,15\r
+\r
+normalbeg2dc10:\r
+        normbeg rcontloop10,10\r
+\r
+normalbeg2dc9:\r
+        normbeg rcontloop9,9\r
+\r
+normalbeg2dc8:\r
+        normbeg rcontloop8,8\r
+\r
+normalbeg2dc7:\r
+        normbeg rcontloop7,7\r
+\r
+normalbeg2dc6:\r
+        normbeg rcontloop6,6\r
+\r
+normalbeg2dc5:\r
+        normbeg rcontloop5,5\r
+\r
+normalbeg2dc4:\r
+        normbeg rcontloop4,4\r
+\r
+normalbeg2dc3:\r
+        normbeg rcontloop3,3\r
+\r
+normalbeg2dc2:\r
+        normbeg rcontloop2,2\r
+\r
+normalbeg2dc1:\r
+        normbeg rcontloop1,1\r
+\r
+normalbeg2dc0:\r
+        normbeg rcontloop0,0\r
+\r
+\r
+; we go in normalbeg2 because *(ushf*)(match+best_len-1) == scan_end\r
+\r
+normalbeg2:\r
+        mov     edi,window\r
+\r
+        cmp     bp,word ptr[edi+eax]\r
+        jne     contloop3                   ; if *(ushf*)match != scan_start, continue\r
+\r
+iseq:\r
+; if we are here, we know that *(match+best_len-1) == scan_end\r
+; and (match == scan_start)\r
+\r
+        mov     edi,edx\r
+        mov     esi,scan                    ; esi = scan\r
+        add     edi,eax                     ; edi = window + cur_match = match\r
+\r
+        mov     edx,[esi+3]                 ; compare manually dword at match+3\r
+        xor     edx,[edi+3]                 ; and scan +3\r
+\r
+        jz      begincompare                ; if equal, go to long compare\r
+\r
+; we will determine the unmatch byte and calculate len (in esi)\r
+        or      dl,dl\r
+        je      eq1rr\r
+        mov     esi,3\r
+        jmp     trfinval\r
+eq1rr:\r
+        or      dx,dx\r
+        je      eq1\r
+\r
+        mov     esi,4\r
+        jmp     trfinval\r
+eq1:\r
+        and     edx,0ffffffh\r
+        jz      eq11\r
+        mov     esi,5\r
+        jmp     trfinval\r
+eq11:\r
+        mov     esi,6\r
+        jmp     trfinval\r
+\r
+begincompare:\r
+        ; here we now scan and match begin same\r
+        add     edi,6\r
+        add     esi,6\r
+        mov     ecx,(MAX_MATCH-(2+4))/4     ; scan for at most MAX_MATCH bytes\r
+        repe    cmpsd                       ; loop until mismatch\r
+\r
+        je      trfin                       ; go to trfin if not unmatch\r
+; we determine the unmatch byte\r
+        sub     esi,4\r
+        mov     edx,[edi-4]\r
+        xor     edx,[esi]\r
+\r
+        or      dl,dl\r
+        jnz     trfin\r
+        inc     esi\r
+\r
+        or      dx,dx\r
+        jnz     trfin\r
+        inc     esi\r
+\r
+        and     edx,0ffffffh\r
+        jnz     trfin\r
+        inc     esi\r
+\r
+trfin:\r
+        sub     esi,scan          ; esi = len\r
+trfinval:\r
+; here we have finised compare, and esi contain len of equal string\r
+        cmp     esi,best_len        ; if len > best_len, go newbestlen\r
+        ja      short newbestlen\r
+; now we restore edx, ecx and esi, for the big loop\r
+        mov     esi,prev\r
+        mov     ecx,limit\r
+        mov     edx,window\r
+        jmp     contloop3\r
+\r
+newbestlen:\r
+        mov     best_len,esi        ; len become best_len\r
+\r
+        mov     match_start,eax     ; save new position as match_start\r
+        cmp     esi,nice_match      ; if best_len >= nice_match, exit\r
+        jae     exitloop\r
+        mov     ecx,scan\r
+        mov     edx,window          ; restore edx=window\r
+        add     ecx,esi\r
+        add     esi,edx\r
+\r
+        dec     esi\r
+        mov     windowlen,esi       ; windowlen = window + best_len-1\r
+        mov     bx,[ecx-1]          ; bx = *(scan+best_len-1) = scan_end\r
+\r
+; now we restore ecx and esi, for the big loop :\r
+        mov     esi,prev\r
+        mov     ecx,limit\r
+        jmp     contloop3\r
+\r
+exitloop:\r
+; exit : s->match_start=match_start\r
+        mov     ebx,match_start\r
+        mov     ebp,str_s\r
+        mov     ecx,best_len\r
+        mov     dword ptr [ebp+dep_match_start],ebx        \r
+        mov     eax,dword ptr [ebp+dep_lookahead]\r
+        cmp     ecx,eax\r
+        ja      minexlo\r
+        mov     eax,ecx\r
+minexlo:\r
+; return min(best_len,s->lookahead)\r
+        \r
+; restore stack and register ebx,esi,edi,ebp\r
+        add     esp,NbStackAdd\r
+\r
+        pop     ebx\r
+        pop     esi\r
+        pop     edi\r
+        pop     ebp\r
+        ret\r
+InfoAuthor:\r
+; please don't remove this string !\r
+; Your are free use gvmat32 in any fre or commercial apps if you don't remove the string in the binary!\r
+        db     0dh,0ah,"GVMat32 optimised assembly code written 1996-98 by Gilles Vollant",0dh,0ah\r
+\r
+\r
+\r
+IFDEF NOUNDERLINE\r
+longest_match_7fff   endp\r
+ELSE\r
+_longest_match_7fff  endp\r
+ENDIF\r
+\r
+\r
+IFDEF NOUNDERLINE\r
+cpudetect32     proc near\r
+ELSE\r
+_cpudetect32    proc near\r
+ENDIF\r
+\r
+       push    ebx\r
+\r
+       pushfd                  ; push original EFLAGS\r
+       pop     eax             ; get original EFLAGS\r
+       mov     ecx, eax        ; save original EFLAGS\r
+       xor     eax, 40000h     ; flip AC bit in EFLAGS\r
+       push    eax             ; save new EFLAGS value on stack\r
+       popfd                   ; replace current EFLAGS value\r
+       pushfd                  ; get new EFLAGS\r
+       pop     eax             ; store new EFLAGS in EAX\r
+       xor     eax, ecx        ; can\92t toggle AC bit, processor=80386\r
+       jz      end_cpu_is_386  ; jump if 80386 processor\r
+       push    ecx\r
+       popfd                   ; restore AC bit in EFLAGS first\r
+\r
+       pushfd\r
+       pushfd\r
+       pop     ecx\r
+                       \r
+       mov     eax, ecx        ; get original EFLAGS\r
+       xor     eax, 200000h    ; flip ID bit in EFLAGS\r
+       push    eax             ; save new EFLAGS value on stack\r
+       popfd                   ; replace current EFLAGS value\r
+       pushfd                  ; get new EFLAGS\r
+       pop             eax                 ; store new EFLAGS in EAX\r
+       popfd                   ; restore original EFLAGS\r
+       xor             eax, ecx        ; can\92t toggle ID bit,\r
+       je              is_old_486              ; processor=old\r
+\r
+       mov     eax,1\r
+       db      0fh,0a2h        ;CPUID   \r
+\r
+exitcpudetect:\r
+       pop     ebx\r
+       ret\r
+\r
+end_cpu_is_386:\r
+       mov     eax,0300h\r
+       jmp     exitcpudetect\r
+\r
+is_old_486:\r
+       mov     eax,0400h\r
+       jmp     exitcpudetect\r
+\r
+IFDEF NOUNDERLINE\r
+cpudetect32     endp\r
+ELSE\r
+_cpudetect32    endp\r
+ENDIF\r
+\r
+\r
+\r
+\r
+MAX_MATCH       equ     258\r
+MIN_MATCH       equ     3\r
+MIN_LOOKAHEAD   equ     (MAX_MATCH + MIN_MATCH + 1)\r
+MAX_MATCH_8_     equ     ((MAX_MATCH + 7) AND 0FFF0h)\r
+\r
+\r
+;;; stack frame offsets\r
+\r
+chainlenwmask  equ  esp + 0    ; high word: current chain len\r
+                                       ; low word: s->wmask\r
+window         equ  esp + 4    ; local copy of s->window\r
+windowbestlen  equ  esp + 8    ; s->window + bestlen\r
+scanstart      equ  esp + 16   ; first two bytes of string\r
+scanend                equ  esp + 12   ; last two bytes of string\r
+scanalign      equ  esp + 20   ; dword-misalignment of string\r
+nicematch      equ  esp + 24   ; a good enough match size\r
+bestlen                equ  esp + 28   ; size of best match so far\r
+scan           equ  esp + 32   ; ptr to string wanting match\r
+\r
+LocalVarsSize  equ 36\r
+;      saved ebx       byte esp + 36\r
+;      saved edi       byte esp + 40\r
+;      saved esi       byte esp + 44\r
+;      saved ebp       byte esp + 48\r
+;      return address  byte esp + 52\r
+deflatestate   equ  esp + 56   ; the function arguments\r
+curmatch       equ  esp + 60\r
+\r
+;;; Offsets for fields in the deflate_state structure. These numbers\r
+;;; are calculated from the definition of deflate_state, with the\r
+;;; assumption that the compiler will dword-align the fields. (Thus,\r
+;;; changing the definition of deflate_state could easily cause this\r
+;;; program to crash horribly, without so much as a warning at\r
+;;; compile time. Sigh.)\r
+\r
+dsWSize                equ 36\r
+dsWMask                equ 44\r
+dsWindow       equ 48\r
+dsPrev         equ 56\r
+dsMatchLen     equ 88\r
+dsPrevMatch    equ 92\r
+dsStrStart     equ 100\r
+dsMatchStart   equ 104\r
+dsLookahead    equ 108\r
+dsPrevLen      equ 112\r
+dsMaxChainLen  equ 116\r
+dsGoodMatch    equ 132\r
+dsNiceMatch    equ 136\r
+\r
+\r
+;;; match.asm -- Pentium-Pro-optimized version of longest_match()\r
+;;; Written for zlib 1.1.2\r
+;;; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>\r
+;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html\r
+;;;\r
+;;; This is free software; you can redistribute it and/or modify it\r
+;;; under the terms of the GNU General Public License.\r
+\r
+;GLOBAL        _longest_match, _match_init\r
+\r
+\r
+;SECTION       .text\r
+\r
+;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch)\r
+\r
+;_longest_match:\r
+IFDEF NOUNDERLINE\r
+longest_match_686   proc near\r
+ELSE\r
+_longest_match_686  proc near\r
+ENDIF\r
+\r
+\r
+;;; Save registers that the compiler may be using, and adjust esp to\r
+;;; make room for our stack frame.\r
+\r
+               push    ebp\r
+               push    edi\r
+               push    esi\r
+               push    ebx\r
+               sub     esp, LocalVarsSize\r
+\r
+;;; Retrieve the function arguments. ecx will hold cur_match\r
+;;; throughout the entire function. edx will hold the pointer to the\r
+;;; deflate_state structure during the function's setup (before\r
+;;; entering the main loop.\r
+\r
+               mov     edx, [deflatestate]\r
+               mov     ecx, [curmatch]\r
+\r
+;;; uInt wmask = s->w_mask;\r
+;;; unsigned chain_length = s->max_chain_length;\r
+;;; if (s->prev_length >= s->good_match) {\r
+;;;     chain_length >>= 2;\r
+;;; }\r
+\r
+               mov     eax, [edx + dsPrevLen]\r
+               mov     ebx, [edx + dsGoodMatch]\r
+               cmp     eax, ebx\r
+               mov     eax, [edx + dsWMask]\r
+               mov     ebx, [edx + dsMaxChainLen]\r
+               jl      LastMatchGood\r
+               shr     ebx, 2\r
+LastMatchGood:\r
+\r
+;;; chainlen is decremented once beforehand so that the function can\r
+;;; use the sign flag instead of the zero flag for the exit test.\r
+;;; It is then shifted into the high word, to make room for the wmask\r
+;;; value, which it will always accompany.\r
+\r
+               dec     ebx\r
+               shl     ebx, 16\r
+               or      ebx, eax\r
+               mov     [chainlenwmask], ebx\r
+\r
+;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;\r
+\r
+               mov     eax, [edx + dsNiceMatch]\r
+               mov     ebx, [edx + dsLookahead]\r
+               cmp     ebx, eax\r
+               jl      LookaheadLess\r
+               mov     ebx, eax\r
+LookaheadLess: mov     [nicematch], ebx\r
+\r
+;;; register Bytef *scan = s->window + s->strstart;\r
+\r
+               mov     esi, [edx + dsWindow]\r
+               mov     [window], esi\r
+               mov     ebp, [edx + dsStrStart]\r
+               lea     edi, [esi + ebp]\r
+               mov     [scan], edi\r
+\r
+;;; Determine how many bytes the scan ptr is off from being\r
+;;; dword-aligned.\r
+\r
+               mov     eax, edi\r
+               neg     eax\r
+               and     eax, 3\r
+               mov     [scanalign], eax\r
+\r
+;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?\r
+;;;     s->strstart - (IPos)MAX_DIST(s) : NIL;\r
+\r
+               mov     eax, [edx + dsWSize]\r
+               sub     eax, MIN_LOOKAHEAD\r
+               sub     ebp, eax\r
+               jg      LimitPositive\r
+               xor     ebp, ebp\r
+LimitPositive:\r
+\r
+;;; int best_len = s->prev_length;\r
+\r
+               mov     eax, [edx + dsPrevLen]\r
+               mov     [bestlen], eax\r
+\r
+;;; Store the sum of s->window + best_len in esi locally, and in esi.\r
+\r
+               add     esi, eax\r
+               mov     [windowbestlen], esi\r
+\r
+;;; register ush scan_start = *(ushf*)scan;\r
+;;; register ush scan_end   = *(ushf*)(scan+best_len-1);\r
+;;; Posf *prev = s->prev;\r
+\r
+               movzx   ebx, word ptr [edi]\r
+               mov     [scanstart], ebx\r
+               movzx   ebx, word ptr [edi + eax - 1]\r
+               mov     [scanend], ebx\r
+               mov     edi, [edx + dsPrev]\r
+\r
+;;; Jump into the main loop.\r
+\r
+               mov     edx, [chainlenwmask]\r
+               jmp     short LoopEntry\r
+\r
+align 4\r
+\r
+;;; do {\r
+;;;     match = s->window + cur_match;\r
+;;;     if (*(ushf*)(match+best_len-1) != scan_end ||\r
+;;;         *(ushf*)match != scan_start) continue;\r
+;;;     [...]\r
+;;; } while ((cur_match = prev[cur_match & wmask]) > limit\r
+;;;          && --chain_length != 0);\r
+;;;\r
+;;; Here is the inner loop of the function. The function will spend the\r
+;;; majority of its time in this loop, and majority of that time will\r
+;;; be spent in the first ten instructions.\r
+;;;\r
+;;; Within this loop:\r
+;;; ebx = scanend\r
+;;; ecx = curmatch\r
+;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)\r
+;;; esi = windowbestlen - i.e., (window + bestlen)\r
+;;; edi = prev\r
+;;; ebp = limit\r
+\r
+LookupLoop:\r
+               and     ecx, edx\r
+               movzx   ecx, word ptr [edi + ecx*2]\r
+               cmp     ecx, ebp\r
+               jbe     LeaveNow\r
+               sub     edx, 00010000h\r
+               js      LeaveNow\r
+LoopEntry:     movzx   eax, word ptr [esi + ecx - 1]\r
+               cmp     eax, ebx\r
+               jnz     LookupLoop\r
+               mov     eax, [window]\r
+               movzx   eax, word ptr [eax + ecx]\r
+               cmp     eax, [scanstart]\r
+               jnz     LookupLoop\r
+\r
+;;; Store the current value of chainlen.\r
+\r
+               mov     [chainlenwmask], edx\r
+\r
+;;; Point edi to the string under scrutiny, and esi to the string we\r
+;;; are hoping to match it up with. In actuality, esi and edi are\r
+;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is\r
+;;; initialized to -(MAX_MATCH_8 - scanalign).\r
+\r
+               mov     esi, [window]\r
+               mov     edi, [scan]\r
+               add     esi, ecx\r
+               mov     eax, [scanalign]\r
+               mov     edx, 0fffffef8h; -(MAX_MATCH_8)\r
+               lea     edi, [edi + eax + 0108h] ;MAX_MATCH_8]\r
+               lea     esi, [esi + eax + 0108h] ;MAX_MATCH_8]\r
+\r
+;;; Test the strings for equality, 8 bytes at a time. At the end,\r
+;;; adjust edx so that it is offset to the exact byte that mismatched.\r
+;;;\r
+;;; We already know at this point that the first three bytes of the\r
+;;; strings match each other, and they can be safely passed over before\r
+;;; starting the compare loop. So what this code does is skip over 0-3\r
+;;; bytes, as much as necessary in order to dword-align the edi\r
+;;; pointer. (esi will still be misaligned three times out of four.)\r
+;;;\r
+;;; It should be confessed that this loop usually does not represent\r
+;;; much of the total running time. Replacing it with a more\r
+;;; straightforward "rep cmpsb" would not drastically degrade\r
+;;; performance.\r
+\r
+LoopCmps:\r
+               mov     eax, [esi + edx]\r
+               xor     eax, [edi + edx]\r
+               jnz     LeaveLoopCmps\r
+               mov     eax, [esi + edx + 4]\r
+               xor     eax, [edi + edx + 4]\r
+               jnz     LeaveLoopCmps4\r
+               add     edx, 8\r
+               jnz     LoopCmps\r
+               jmp     short LenMaximum\r
+LeaveLoopCmps4:        add     edx, 4\r
+LeaveLoopCmps: test    eax, 0000FFFFh\r
+               jnz     LenLower\r
+               add     edx,  2\r
+               shr     eax, 16\r
+LenLower:      sub     al, 1\r
+               adc     edx, 0\r
+\r
+;;; Calculate the length of the match. If it is longer than MAX_MATCH,\r
+;;; then automatically accept it as the best possible match and leave.\r
+\r
+               lea     eax, [edi + edx]\r
+               mov     edi, [scan]\r
+               sub     eax, edi\r
+               cmp     eax, MAX_MATCH\r
+               jge     LenMaximum\r
+\r
+;;; If the length of the match is not longer than the best match we\r
+;;; have so far, then forget it and return to the lookup loop.\r
+\r
+               mov     edx, [deflatestate]\r
+               mov     ebx, [bestlen]\r
+               cmp     eax, ebx\r
+               jg      LongerMatch\r
+               mov     esi, [windowbestlen]\r
+               mov     edi, [edx + dsPrev]\r
+               mov     ebx, [scanend]\r
+               mov     edx, [chainlenwmask]\r
+               jmp     LookupLoop\r
+\r
+;;;         s->match_start = cur_match;\r
+;;;         best_len = len;\r
+;;;         if (len >= nice_match) break;\r
+;;;         scan_end = *(ushf*)(scan+best_len-1);\r
+\r
+LongerMatch:   mov     ebx, [nicematch]\r
+               mov     [bestlen], eax\r
+               mov     [edx + dsMatchStart], ecx\r
+               cmp     eax, ebx\r
+               jge     LeaveNow\r
+               mov     esi, [window]\r
+               add     esi, eax\r
+               mov     [windowbestlen], esi\r
+               movzx   ebx, word ptr [edi + eax - 1]\r
+               mov     edi, [edx + dsPrev]\r
+               mov     [scanend], ebx\r
+               mov     edx, [chainlenwmask]\r
+               jmp     LookupLoop\r
+\r
+;;; Accept the current string, with the maximum possible length.\r
+\r
+LenMaximum:    mov     edx, [deflatestate]\r
+               mov     dword ptr [bestlen], MAX_MATCH\r
+               mov     [edx + dsMatchStart], ecx\r
+\r
+;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;\r
+;;; return s->lookahead;\r
+\r
+LeaveNow:\r
+               mov     edx, [deflatestate]\r
+               mov     ebx, [bestlen]\r
+               mov     eax, [edx + dsLookahead]\r
+               cmp     ebx, eax\r
+               jg      LookaheadRet\r
+               mov     eax, ebx\r
+LookaheadRet:\r
+\r
+;;; Restore the stack and return from whence we came.\r
+\r
+               add     esp, LocalVarsSize\r
+               pop     ebx\r
+               pop     esi\r
+               pop     edi\r
+               pop     ebp\r
+\r
+               ret\r
+; please don't remove this string !\r
+; Your are free use gvmat32 in any fre or commercial apps if you don't remove the string in the binary!\r
+        db     0dh,0ah,"asm686 with masm, code optimised assembly code from Brian Raiter, written 1998",0dh,0ah\r
+\r
+IFDEF NOUNDERLINE\r
+longest_match_686   endp\r
+ELSE\r
+_longest_match_686  endp\r
+ENDIF\r
+\r
+_TEXT   ends\r
+end\r
diff --git a/zlib/contrib/vstudio/vc70_32/gvmat32.obj b/zlib/contrib/vstudio/vc70_32/gvmat32.obj
new file mode 100644 (file)
index 0000000..5b2f856
Binary files /dev/null and b/zlib/contrib/vstudio/vc70_32/gvmat32.obj differ
diff --git a/zlib/contrib/vstudio/vc70_32/gvmat32c.c b/zlib/contrib/vstudio/vc70_32/gvmat32c.c
new file mode 100644 (file)
index 0000000..38be10b
--- /dev/null
@@ -0,0 +1,209 @@
+/* gvmat32.c -- C portion of the optimized longest_match for 32 bits x86\r
+ * Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.\r
+ * File written by Gilles Vollant, by modifiying the longest_match\r
+ *  from Jean-loup Gailly in deflate.c\r
+ *  it prepare all parameters and call the assembly longest_match_gvasm\r
+ *  longest_match execute standard C code is wmask != 0x7fff\r
+ *     (assembly code is faster with a fixed wmask)\r
+ *\r
+ */\r
+\r
+#include "deflate.h"\r
+\r
+#undef FAR\r
+//#include <windows.h>\r
+\r
+#ifdef ASMV\r
+#define NIL 0\r
+\r
+#define UNALIGNED_OK\r
+\r
+\r
+/* if your C compiler don't add underline before function name,\r
+        define ADD_UNDERLINE_ASMFUNC */\r
+#ifdef ADD_UNDERLINE_ASMFUNC\r
+#define longest_match_7fff _longest_match_7fff\r
+#define longest_match_686  _longest_match_686\r
+#define cpudetect32        _cpudetect32\r
+#endif\r
+\r
+\r
+\r
+void match_init()\r
+{\r
+}\r
+\r
+unsigned long cpudetect32();\r
+\r
+uInt longest_match_c(\r
+    deflate_state *s,\r
+    IPos cur_match);                             /* current match */\r
+\r
+\r
+uInt longest_match_7fff(\r
+    deflate_state *s,\r
+    IPos cur_match);                             /* current match */\r
+\r
+uInt longest_match_686(\r
+    deflate_state *s,\r
+    IPos cur_match);                             /* current match */\r
+\r
+uInt longest_match(\r
+    deflate_state *s,\r
+    IPos cur_match)                             /* current match */\r
+{\r
+    static uInt iIsPPro=2;\r
+\r
+    if ((s->w_mask == 0x7fff) && (iIsPPro==0))\r
+        return longest_match_7fff(s,cur_match);\r
+\r
+    if (iIsPPro==1)\r
+        return longest_match_686(s,cur_match);\r
+\r
+    if (iIsPPro==2)\r
+        iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0;\r
+\r
+    return longest_match_c(s,cur_match);\r
+}\r
+\r
+\r
+\r
+uInt longest_match_c(s, cur_match)\r
+    deflate_state *s;\r
+    IPos cur_match;                             /* current match */\r
+{\r
+    unsigned chain_length = s->max_chain_length;/* max hash chain length */\r
+    register Bytef *scan = s->window + s->strstart; /* current string */\r
+    register Bytef *match;                       /* matched string */\r
+    register int len;                           /* length of current match */\r
+    int best_len = s->prev_length;              /* best match length so far */\r
+    int nice_match = s->nice_match;             /* stop if match long enough */\r
+    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?\r
+        s->strstart - (IPos)MAX_DIST(s) : NIL;\r
+    /* Stop when cur_match becomes <= limit. To simplify the code,\r
+     * we prevent matches with the string of window index 0.\r
+     */\r
+    Posf *prev = s->prev;\r
+    uInt wmask = s->w_mask;\r
+\r
+#ifdef UNALIGNED_OK\r
+    /* Compare two bytes at a time. Note: this is not always beneficial.\r
+     * Try with and without -DUNALIGNED_OK to check.\r
+     */\r
+    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;\r
+    register ush scan_start = *(ushf*)scan;\r
+    register ush scan_end   = *(ushf*)(scan+best_len-1);\r
+#else\r
+    register Bytef *strend = s->window + s->strstart + MAX_MATCH;\r
+    register Byte scan_end1  = scan[best_len-1];\r
+    register Byte scan_end   = scan[best_len];\r
+#endif\r
+\r
+    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.\r
+     * It is easy to get rid of this optimization if necessary.\r
+     */\r
+    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");\r
+\r
+    /* Do not waste too much time if we already have a good match: */\r
+    if (s->prev_length >= s->good_match) {\r
+        chain_length >>= 2;\r
+    }\r
+    /* Do not look for matches beyond the end of the input. This is necessary\r
+     * to make deflate deterministic.\r
+     */\r
+    if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;\r
+\r
+    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");\r
+\r
+    do {\r
+        Assert(cur_match < s->strstart, "no future");\r
+        match = s->window + cur_match;\r
+\r
+        /* Skip to next match if the match length cannot increase\r
+         * or if the match length is less than 2:\r
+         */\r
+#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)\r
+        /* This code assumes sizeof(unsigned short) == 2. Do not use\r
+         * UNALIGNED_OK if your compiler uses a different size.\r
+         */\r
+        if (*(ushf*)(match+best_len-1) != scan_end ||\r
+            *(ushf*)match != scan_start) continue;\r
+\r
+        /* It is not necessary to compare scan[2] and match[2] since they are\r
+         * always equal when the other bytes match, given that the hash keys\r
+         * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at\r
+         * strstart+3, +5, ... up to strstart+257. We check for insufficient\r
+         * lookahead only every 4th comparison; the 128th check will be made\r
+         * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is\r
+         * necessary to put more guard bytes at the end of the window, or\r
+         * to check more often for insufficient lookahead.\r
+         */\r
+        Assert(scan[2] == match[2], "scan[2]?");\r
+        scan++, match++;\r
+        do {\r
+        } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&\r
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&\r
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&\r
+                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&\r
+                 scan < strend);\r
+        /* The funny "do {}" generates better code on most compilers */\r
+\r
+        /* Here, scan <= window+strstart+257 */\r
+        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");\r
+        if (*scan == *match) scan++;\r
+\r
+        len = (MAX_MATCH - 1) - (int)(strend-scan);\r
+        scan = strend - (MAX_MATCH-1);\r
+\r
+#else /* UNALIGNED_OK */\r
+\r
+        if (match[best_len]   != scan_end  ||\r
+            match[best_len-1] != scan_end1 ||\r
+            *match            != *scan     ||\r
+            *++match          != scan[1])      continue;\r
+\r
+        /* The check at best_len-1 can be removed because it will be made\r
+         * again later. (This heuristic is not always a win.)\r
+         * It is not necessary to compare scan[2] and match[2] since they\r
+         * are always equal when the other bytes match, given that\r
+         * the hash keys are equal and that HASH_BITS >= 8.\r
+         */\r
+        scan += 2, match++;\r
+        Assert(*scan == *match, "match[2]?");\r
+\r
+        /* We check for insufficient lookahead only every 8th comparison;\r
+         * the 256th check will be made at strstart+258.\r
+         */\r
+        do {\r
+        } while (*++scan == *++match && *++scan == *++match &&\r
+                 *++scan == *++match && *++scan == *++match &&\r
+                 *++scan == *++match && *++scan == *++match &&\r
+                 *++scan == *++match && *++scan == *++match &&\r
+                 scan < strend);\r
+\r
+        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");\r
+\r
+        len = MAX_MATCH - (int)(strend - scan);\r
+        scan = strend - MAX_MATCH;\r
+\r
+#endif /* UNALIGNED_OK */\r
+\r
+        if (len > best_len) {\r
+            s->match_start = cur_match;\r
+            best_len = len;\r
+            if (len >= nice_match) break;\r
+#ifdef UNALIGNED_OK\r
+            scan_end = *(ushf*)(scan+best_len-1);\r
+#else\r
+            scan_end1  = scan[best_len-1];\r
+            scan_end   = scan[best_len];\r
+#endif\r
+        }\r
+    } while ((cur_match = prev[cur_match & wmask]) > limit\r
+             && --chain_length != 0);\r
+\r
+    if ((uInt)best_len <= s->lookahead) return (uInt)best_len;\r
+    return s->lookahead;\r
+}\r
+\r
+#endif /* ASMV */\r
diff --git a/zlib/contrib/vstudio/vc70_32/inffastAsm.asm b/zlib/contrib/vstudio/vc70_32/inffastAsm.asm
new file mode 100644 (file)
index 0000000..f4b6a56
--- /dev/null
@@ -0,0 +1,1020 @@
+; 75 "inffast.S"\r
+;FILE "inffast.S"\r
+\r
+;;;GLOBAL _inflate_fast\r
+\r
+;;;SECTION .text\r
+\r
+\r
+\r
+    .586p\r
+    .mmx\r
+\r
+    name    inflate_fast_x86\r
+    .MODEL  FLAT\r
+\r
+_DATA                   segment\r
+inflate_fast_use_mmx: \r
+dd    1\r
+\r
+\r
+_TEXT                   segment\r
+PUBLIC _inflate_fast\r
+\r
+ALIGN 4\r
+_inflate_fast: \r
+        jmp inflate_fast_entry\r
+\r
+\r
+\r
+ALIGN 4\r
+        db     'Fast decoding Code from Chris Anderson'\r
+        db      0\r
+\r
+ALIGN 4\r
+invalid_literal_length_code_msg: \r
+        db      'invalid literal/length code'\r
+        db      0\r
+\r
+ALIGN 4\r
+invalid_distance_code_msg: \r
+        db      'invalid distance code'\r
+        db      0\r
+\r
+ALIGN 4\r
+invalid_distance_too_far_msg: \r
+        db      'invalid distance too far back'\r
+        db      0\r
+\r
+\r
+ALIGN 4\r
+inflate_fast_mask: \r
+dd    0\r
+dd    1\r
+dd    3\r
+dd    7\r
+dd    15\r
+dd    31\r
+dd    63\r
+dd    127\r
+dd    255\r
+dd    511\r
+dd    1023\r
+dd    2047\r
+dd    4095\r
+dd    8191\r
+dd    16383\r
+dd    32767\r
+dd    65535\r
+dd    131071\r
+dd    262143\r
+dd    524287\r
+dd    1048575\r
+dd    2097151\r
+dd    4194303\r
+dd    8388607\r
+dd    16777215\r
+dd    33554431\r
+dd    67108863\r
+dd    134217727\r
+dd    268435455\r
+dd    536870911\r
+dd    1073741823\r
+dd    2147483647\r
+dd    4294967295\r
+\r
+\r
+;;SECTION .text\r
+; 205 "inffast.S"\r
+;GLOBAL inflate_fast_use_mmx\r
+\r
+;SECTION .data\r
+\r
+\r
+; GLOBAL inflate_fast_use_mmx:object\r
+;.size inflate_fast_use_mmx, 4\r
+; 226 "inffast.S"\r
+;SECTION .text\r
+\r
+ALIGN 4 \r
+inflate_fast_entry: \r
+        push  edi\r
+        push  esi\r
+        push  ebp\r
+        push  ebx\r
+        pushfd\r
+        sub  esp,64\r
+        cld\r
+\r
+\r
+\r
+\r
+        mov  esi, [esp+88]\r
+        mov  edi, [esi+28]\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+        mov  edx, [esi+4]\r
+        mov  eax, [esi+0]\r
+\r
+        add  edx,eax\r
+        sub  edx,11\r
+\r
+        mov  [esp+44],eax\r
+        mov  [esp+20],edx\r
+\r
+        mov  ebp, [esp+92]\r
+        mov  ecx, [esi+16]\r
+        mov  ebx, [esi+12]\r
+\r
+        sub  ebp,ecx\r
+        neg  ebp\r
+        add  ebp,ebx\r
+\r
+        sub  ecx,257\r
+        add  ecx,ebx\r
+\r
+        mov  [esp+60],ebx\r
+        mov  [esp+40],ebp\r
+        mov  [esp+16],ecx\r
+; 285 "inffast.S"\r
+        mov  eax, [edi+64]\r
+        mov  ecx, [edi+68]\r
+\r
+        mov  [esp+8],eax\r
+        mov  [esp+12],ecx\r
+\r
+        mov  eax,1\r
+        mov  ecx, [edi+72]\r
+        shl  eax,cl\r
+        dec  eax\r
+        mov  [esp+0],eax\r
+\r
+        mov  eax,1\r
+        mov  ecx, [edi+76]\r
+        shl  eax,cl\r
+        dec  eax\r
+        mov  [esp+4],eax\r
+\r
+        mov  eax, [edi+32]\r
+        mov  ecx, [edi+36]\r
+        mov  edx, [edi+40]\r
+\r
+        mov  [esp+52],eax\r
+        mov  [esp+48],ecx\r
+        mov  [esp+56],edx\r
+\r
+        mov  ebp, [edi+44]\r
+        mov  ebx, [edi+48]\r
+; 321 "inffast.S"\r
+        mov  esi, [esp+44]\r
+        mov  ecx, [esp+20]\r
+        cmp  ecx,esi\r
+        ja   L_align_long\r
+\r
+        add  ecx,11\r
+        sub  ecx,esi\r
+        mov  eax,12\r
+        sub  eax,ecx\r
+        lea  edi, [esp+28]\r
+        rep movsb\r
+        mov  ecx,eax\r
+        xor  eax,eax\r
+        rep stosb\r
+        lea  esi, [esp+28]\r
+        mov  [esp+20],esi\r
+        jmp  L_is_aligned\r
+\r
+\r
+L_align_long: \r
+        test  esi,3\r
+        jz   L_is_aligned\r
+        xor  eax,eax\r
+        mov  al, [esi]\r
+        inc  esi\r
+        mov  ecx,ebx\r
+        add  ebx,8\r
+        shl  eax,cl\r
+        or  ebp,eax\r
+        jmp L_align_long\r
+\r
+L_is_aligned: \r
+        mov  edi, [esp+60]\r
+; 366 "inffast.S"\r
+L_check_mmx: \r
+        cmp  dword ptr [inflate_fast_use_mmx],2\r
+        je   L_init_mmx\r
+        ja   L_do_loop\r
+\r
+        push  eax\r
+        push  ebx\r
+        push  ecx\r
+        push  edx\r
+        pushfd\r
+        mov  eax, [esp]\r
+        xor  dword ptr [esp],0200000h\r
+\r
+\r
+\r
+\r
+        popfd\r
+        pushfd\r
+        pop  edx\r
+        xor  edx,eax\r
+        jz   L_dont_use_mmx\r
+        xor  eax,eax\r
+        cpuid\r
+        cmp  ebx,0756e6547h\r
+        jne  L_dont_use_mmx\r
+        cmp  ecx,06c65746eh\r
+        jne  L_dont_use_mmx\r
+        cmp  edx,049656e69h\r
+        jne  L_dont_use_mmx\r
+        mov  eax,1\r
+        cpuid\r
+        shr  eax,8\r
+        and  eax,15\r
+        cmp  eax,6\r
+        jne  L_dont_use_mmx\r
+        test  edx,0800000h\r
+        jnz  L_use_mmx\r
+        jmp  L_dont_use_mmx\r
+L_use_mmx: \r
+        mov  dword ptr [inflate_fast_use_mmx],2\r
+        jmp  L_check_mmx_pop\r
+L_dont_use_mmx: \r
+        mov  dword ptr [inflate_fast_use_mmx],3\r
+L_check_mmx_pop: \r
+        pop  edx\r
+        pop  ecx\r
+        pop  ebx\r
+        pop  eax\r
+        jmp  L_check_mmx\r
+; 426 "inffast.S"\r
+ALIGN 4\r
+L_do_loop: \r
+; 437 "inffast.S"\r
+        cmp  bl,15\r
+        ja   L_get_length_code\r
+\r
+        xor  eax,eax\r
+        lodsw\r
+        mov  cl,bl\r
+        add  bl,16\r
+        shl  eax,cl\r
+        or  ebp,eax\r
+\r
+L_get_length_code: \r
+        mov  edx, [esp+0]\r
+        mov  ecx, [esp+8]\r
+        and  edx,ebp\r
+        mov  eax, [ecx+edx*4]\r
+\r
+L_dolen: \r
+\r
+\r
+\r
+\r
+\r
+\r
+        mov  cl,ah\r
+        sub  bl,ah\r
+        shr  ebp,cl\r
+\r
+\r
+\r
+\r
+\r
+\r
+        test  al,al\r
+        jnz   L_test_for_length_base\r
+\r
+        shr  eax,16\r
+        stosb\r
+\r
+L_while_test: \r
+\r
+\r
+        cmp  [esp+16],edi\r
+        jbe  L_break_loop\r
+\r
+        cmp  [esp+20],esi\r
+        ja   L_do_loop\r
+        jmp  L_break_loop\r
+\r
+L_test_for_length_base: \r
+; 502 "inffast.S"\r
+        mov  edx,eax\r
+        shr  edx,16\r
+        mov  cl,al\r
+\r
+        test  al,16\r
+        jz   L_test_for_second_level_length\r
+        and  cl,15\r
+        jz   L_save_len\r
+        cmp  bl,cl\r
+        jae  L_add_bits_to_len\r
+\r
+        mov  ch,cl\r
+        xor  eax,eax\r
+        lodsw\r
+        mov  cl,bl\r
+        add  bl,16\r
+        shl  eax,cl\r
+        or  ebp,eax\r
+        mov  cl,ch\r
+\r
+L_add_bits_to_len: \r
+        mov  eax,1\r
+        shl  eax,cl\r
+        dec  eax\r
+        sub  bl,cl\r
+        and  eax,ebp\r
+        shr  ebp,cl\r
+        add  edx,eax\r
+\r
+L_save_len: \r
+        mov  [esp+24],edx\r
+\r
+\r
+L_decode_distance: \r
+; 549 "inffast.S"\r
+        cmp  bl,15\r
+        ja   L_get_distance_code\r
+\r
+        xor  eax,eax\r
+        lodsw\r
+        mov  cl,bl\r
+        add  bl,16\r
+        shl  eax,cl\r
+        or  ebp,eax\r
+\r
+L_get_distance_code: \r
+        mov  edx, [esp+4]\r
+        mov  ecx, [esp+12]\r
+        and  edx,ebp\r
+        mov  eax, [ecx+edx*4]\r
+\r
+\r
+L_dodist: \r
+        mov  edx,eax\r
+        shr  edx,16\r
+        mov  cl,ah\r
+        sub  bl,ah\r
+        shr  ebp,cl\r
+; 584 "inffast.S"\r
+        mov  cl,al\r
+\r
+        test  al,16\r
+        jz  L_test_for_second_level_dist\r
+        and  cl,15\r
+        jz  L_check_dist_one\r
+        cmp  bl,cl\r
+        jae  L_add_bits_to_dist\r
+\r
+        mov  ch,cl\r
+        xor  eax,eax\r
+        lodsw\r
+        mov  cl,bl\r
+        add  bl,16\r
+        shl  eax,cl\r
+        or  ebp,eax\r
+        mov  cl,ch\r
+\r
+L_add_bits_to_dist: \r
+        mov  eax,1\r
+        shl  eax,cl\r
+        dec  eax\r
+        sub  bl,cl\r
+        and  eax,ebp\r
+        shr  ebp,cl\r
+        add  edx,eax\r
+        jmp  L_check_window\r
+\r
+L_check_window: \r
+; 625 "inffast.S"\r
+        mov  [esp+44],esi\r
+        mov  eax,edi\r
+        sub  eax, [esp+40]\r
+\r
+        cmp  eax,edx\r
+        jb   L_clip_window\r
+\r
+        mov  ecx, [esp+24]\r
+        mov  esi,edi\r
+        sub  esi,edx\r
+\r
+        sub  ecx,3\r
+        mov  al, [esi]\r
+        mov  [edi],al\r
+        mov  al, [esi+1]\r
+        mov  dl, [esi+2]\r
+        add  esi,3\r
+        mov  [edi+1],al\r
+        mov  [edi+2],dl\r
+        add  edi,3\r
+        rep movsb\r
+\r
+        mov  esi, [esp+44]\r
+        jmp  L_while_test\r
+\r
+ALIGN 4\r
+L_check_dist_one: \r
+        cmp  edx,1\r
+        jne  L_check_window\r
+        cmp  [esp+40],edi\r
+        je  L_check_window\r
+\r
+        dec  edi\r
+        mov  ecx, [esp+24]\r
+        mov  al, [edi]\r
+        sub  ecx,3\r
+\r
+        mov  [edi+1],al\r
+        mov  [edi+2],al\r
+        mov  [edi+3],al\r
+        add  edi,4\r
+        rep stosb\r
+\r
+        jmp  L_while_test\r
+\r
+ALIGN 4\r
+L_test_for_second_level_length: \r
+\r
+\r
+\r
+\r
+        test  al,64\r
+        jnz   L_test_for_end_of_block\r
+\r
+        mov  eax,1\r
+        shl  eax,cl\r
+        dec  eax\r
+        and  eax,ebp\r
+        add  eax,edx\r
+        mov  edx, [esp+8]\r
+        mov  eax, [edx+eax*4]\r
+        jmp  L_dolen\r
+\r
+ALIGN 4\r
+L_test_for_second_level_dist: \r
+\r
+\r
+\r
+\r
+        test  al,64\r
+        jnz   L_invalid_distance_code\r
+\r
+        mov  eax,1\r
+        shl  eax,cl\r
+        dec  eax\r
+        and  eax,ebp\r
+        add  eax,edx\r
+        mov  edx, [esp+12]\r
+        mov  eax, [edx+eax*4]\r
+        jmp  L_dodist\r
+\r
+ALIGN 4 \r
+L_clip_window: \r
+; 721 "inffast.S"\r
+        mov  ecx,eax\r
+        mov  eax, [esp+52]\r
+        neg  ecx\r
+        mov  esi, [esp+56]\r
+\r
+        cmp  eax,edx\r
+        jb   L_invalid_distance_too_far\r
+\r
+        add  ecx,edx\r
+        cmp  dword ptr [esp+48],0\r
+        jne  L_wrap_around_window\r
+\r
+        sub  eax,ecx\r
+        add  esi,eax\r
+; 749 "inffast.S"\r
+        mov  eax, [esp+24]\r
+        cmp  eax,ecx\r
+        jbe  L_do_copy1\r
+\r
+        sub  eax,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,edx\r
+        jmp  L_do_copy1\r
+\r
+        cmp  eax,ecx\r
+        jbe  L_do_copy1\r
+\r
+        sub  eax,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,edx\r
+        jmp  L_do_copy1\r
+\r
+L_wrap_around_window: \r
+; 793 "inffast.S"\r
+        mov  eax, [esp+48]\r
+        cmp  ecx,eax\r
+        jbe  L_contiguous_in_window\r
+\r
+        add  esi, [esp+52]\r
+        add  esi,eax\r
+        sub  esi,ecx\r
+        sub  ecx,eax\r
+\r
+\r
+        mov  eax, [esp+24]\r
+        cmp  eax,ecx\r
+        jbe  L_do_copy1\r
+\r
+        sub  eax,ecx\r
+        rep movsb\r
+        mov  esi, [esp+56]\r
+        mov  ecx, [esp+48]\r
+        cmp  eax,ecx\r
+        jbe  L_do_copy1\r
+\r
+        sub  eax,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,edx\r
+        jmp  L_do_copy1\r
+\r
+L_contiguous_in_window: \r
+; 836 "inffast.S"\r
+        add  esi,eax\r
+        sub  esi,ecx\r
+\r
+\r
+        mov  eax, [esp+24]\r
+        cmp  eax,ecx\r
+        jbe  L_do_copy1\r
+\r
+        sub  eax,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,edx\r
+\r
+L_do_copy1: \r
+; 862 "inffast.S"\r
+        mov  ecx,eax\r
+        rep movsb\r
+\r
+        mov  esi, [esp+44]\r
+        jmp  L_while_test\r
+; 878 "inffast.S"\r
+ALIGN 4\r
+L_init_mmx: \r
+        emms\r
+\r
+\r
+\r
+\r
+\r
+        movd mm0,ebp\r
+        mov  ebp,ebx\r
+; 896 "inffast.S"\r
+        movd mm4,[esp+0]\r
+        movq mm3,mm4\r
+        movd mm5,[esp+4]\r
+        movq mm2,mm5\r
+        pxor mm1,mm1\r
+        mov  ebx, [esp+8]\r
+        jmp  L_do_loop_mmx\r
+\r
+ALIGN 4\r
+L_do_loop_mmx: \r
+        psrlq mm0,mm1\r
+\r
+        cmp  ebp,32\r
+        ja  L_get_length_code_mmx\r
+\r
+        movd mm6,ebp\r
+        movd mm7,[esi]\r
+        add  esi,4\r
+        psllq mm7,mm6\r
+        add  ebp,32\r
+        por mm0,mm7\r
+\r
+L_get_length_code_mmx: \r
+        pand mm4,mm0\r
+        movd eax,mm4\r
+        movq mm4,mm3\r
+        mov  eax, [ebx+eax*4]\r
+\r
+L_dolen_mmx: \r
+        movzx  ecx,ah\r
+        movd mm1,ecx\r
+        sub  ebp,ecx\r
+\r
+        test  al,al\r
+        jnz L_test_for_length_base_mmx\r
+\r
+        shr  eax,16\r
+        stosb\r
+\r
+L_while_test_mmx: \r
+\r
+\r
+        cmp  [esp+16],edi\r
+        jbe L_break_loop\r
+\r
+        cmp  [esp+20],esi\r
+        ja L_do_loop_mmx\r
+        jmp L_break_loop\r
+\r
+L_test_for_length_base_mmx: \r
+\r
+        mov  edx,eax\r
+        shr  edx,16\r
+\r
+        test  al,16\r
+        jz  L_test_for_second_level_length_mmx\r
+        and  eax,15\r
+        jz L_decode_distance_mmx\r
+\r
+        psrlq mm0,mm1\r
+        movd mm1,eax\r
+        movd ecx,mm0\r
+        sub  ebp,eax\r
+        and  ecx, [inflate_fast_mask+eax*4]\r
+        add  edx,ecx\r
+\r
+L_decode_distance_mmx: \r
+        psrlq mm0,mm1\r
+\r
+        cmp  ebp,32\r
+        ja L_get_dist_code_mmx\r
+\r
+        movd mm6,ebp\r
+        movd mm7,[esi]\r
+        add  esi,4\r
+        psllq mm7,mm6\r
+        add  ebp,32\r
+        por mm0,mm7\r
+\r
+L_get_dist_code_mmx: \r
+        mov  ebx, [esp+12]\r
+        pand mm5,mm0\r
+        movd eax,mm5\r
+        movq mm5,mm2\r
+        mov  eax, [ebx+eax*4]\r
+\r
+L_dodist_mmx: \r
+\r
+        movzx  ecx,ah\r
+        mov  ebx,eax\r
+        shr  ebx,16\r
+        sub  ebp,ecx\r
+        movd mm1,ecx\r
+\r
+        test  al,16\r
+        jz L_test_for_second_level_dist_mmx\r
+        and  eax,15\r
+        jz L_check_dist_one_mmx\r
+\r
+L_add_bits_to_dist_mmx: \r
+        psrlq mm0,mm1\r
+        movd mm1,eax\r
+        movd ecx,mm0\r
+        sub  ebp,eax\r
+        and  ecx, [inflate_fast_mask+eax*4]\r
+        add  ebx,ecx\r
+\r
+L_check_window_mmx: \r
+        mov  [esp+44],esi\r
+        mov  eax,edi\r
+        sub  eax, [esp+40]\r
+\r
+        cmp  eax,ebx\r
+        jb L_clip_window_mmx\r
+\r
+        mov  ecx,edx\r
+        mov  esi,edi\r
+        sub  esi,ebx\r
+\r
+        sub  ecx,3\r
+        mov  al, [esi]\r
+        mov  [edi],al\r
+        mov  al, [esi+1]\r
+        mov  dl, [esi+2]\r
+        add  esi,3\r
+        mov  [edi+1],al\r
+        mov  [edi+2],dl\r
+        add  edi,3\r
+        rep movsb\r
+\r
+        mov  esi, [esp+44]\r
+        mov  ebx, [esp+8]\r
+        jmp  L_while_test_mmx\r
+\r
+ALIGN 4\r
+L_check_dist_one_mmx: \r
+        cmp  ebx,1\r
+        jne  L_check_window_mmx\r
+        cmp  [esp+40],edi\r
+        je   L_check_window_mmx\r
+\r
+        dec  edi\r
+        mov  ecx,edx\r
+        mov  al, [edi]\r
+        sub  ecx,3\r
+\r
+        mov  [edi+1],al\r
+        mov  [edi+2],al\r
+        mov  [edi+3],al\r
+        add  edi,4\r
+        rep stosb\r
+\r
+        mov  ebx, [esp+8]\r
+        jmp  L_while_test_mmx\r
+\r
+ALIGN 4\r
+L_test_for_second_level_length_mmx: \r
+        test  al,64\r
+        jnz L_test_for_end_of_block\r
+\r
+        and  eax,15\r
+        psrlq mm0,mm1\r
+        movd ecx,mm0\r
+        and  ecx, [inflate_fast_mask+eax*4]\r
+        add  ecx,edx\r
+        mov  eax, [ebx+ecx*4]\r
+        jmp L_dolen_mmx\r
+\r
+ALIGN 4\r
+L_test_for_second_level_dist_mmx: \r
+        test  al,64\r
+        jnz L_invalid_distance_code\r
+\r
+        and  eax,15\r
+        psrlq mm0,mm1\r
+        movd ecx,mm0\r
+        and  ecx, [inflate_fast_mask+eax*4]\r
+        mov  eax, [esp+12]\r
+        add  ecx,ebx\r
+        mov  eax, [eax+ecx*4]\r
+        jmp  L_dodist_mmx\r
+\r
+ALIGN 4\r
+L_clip_window_mmx: \r
+\r
+        mov  ecx,eax\r
+        mov  eax, [esp+52]\r
+        neg  ecx\r
+        mov  esi, [esp+56]\r
+\r
+        cmp  eax,ebx\r
+        jb  L_invalid_distance_too_far\r
+\r
+        add  ecx,ebx\r
+        cmp  dword ptr [esp+48],0\r
+        jne  L_wrap_around_window_mmx\r
+\r
+        sub  eax,ecx\r
+        add  esi,eax\r
+\r
+        cmp  edx,ecx\r
+        jbe  L_do_copy1_mmx\r
+\r
+        sub  edx,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,ebx\r
+        jmp  L_do_copy1_mmx\r
+\r
+        cmp  edx,ecx\r
+        jbe  L_do_copy1_mmx\r
+\r
+        sub  edx,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,ebx\r
+        jmp  L_do_copy1_mmx\r
+\r
+L_wrap_around_window_mmx: \r
+\r
+        mov  eax, [esp+48]\r
+        cmp  ecx,eax\r
+        jbe  L_contiguous_in_window_mmx\r
+\r
+        add  esi, [esp+52]\r
+        add  esi,eax\r
+        sub  esi,ecx\r
+        sub  ecx,eax\r
+\r
+\r
+        cmp  edx,ecx\r
+        jbe  L_do_copy1_mmx\r
+\r
+        sub  edx,ecx\r
+        rep movsb\r
+        mov  esi, [esp+56]\r
+        mov  ecx, [esp+48]\r
+        cmp  edx,ecx\r
+        jbe  L_do_copy1_mmx\r
+\r
+        sub  edx,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,ebx\r
+        jmp  L_do_copy1_mmx\r
+\r
+L_contiguous_in_window_mmx: \r
+\r
+        add  esi,eax\r
+        sub  esi,ecx\r
+\r
+\r
+        cmp  edx,ecx\r
+        jbe  L_do_copy1_mmx\r
+\r
+        sub  edx,ecx\r
+        rep movsb\r
+        mov  esi,edi\r
+        sub  esi,ebx\r
+\r
+L_do_copy1_mmx: \r
+\r
+\r
+        mov  ecx,edx\r
+        rep movsb\r
+\r
+        mov  esi, [esp+44]\r
+        mov  ebx, [esp+8]\r
+        jmp  L_while_test_mmx\r
+; 1174 "inffast.S"\r
+L_invalid_distance_code: \r
+\r
+\r
+\r
+\r
+\r
+        mov  ecx, invalid_distance_code_msg\r
+        mov  edx,26\r
+        jmp  L_update_stream_state\r
+\r
+L_test_for_end_of_block: \r
+\r
+\r
+\r
+\r
+\r
+        test  al,32\r
+        jz  L_invalid_literal_length_code\r
+\r
+        mov  ecx,0\r
+        mov  edx,11\r
+        jmp  L_update_stream_state\r
+\r
+L_invalid_literal_length_code: \r
+\r
+\r
+\r
+\r
+\r
+        mov  ecx, invalid_literal_length_code_msg\r
+        mov  edx,26\r
+        jmp  L_update_stream_state\r
+\r
+L_invalid_distance_too_far: \r
+\r
+\r
+\r
+        mov  esi, [esp+44]\r
+        mov  ecx, invalid_distance_too_far_msg\r
+        mov  edx,26\r
+        jmp  L_update_stream_state\r
+\r
+L_update_stream_state: \r
+\r
+        mov  eax, [esp+88]\r
+        test  ecx,ecx\r
+        jz  L_skip_msg\r
+        mov  [eax+24],ecx\r
+L_skip_msg: \r
+        mov  eax, [eax+28]\r
+        mov  [eax+0],edx\r
+        jmp  L_break_loop\r
+\r
+ALIGN 4\r
+L_break_loop: \r
+; 1243 "inffast.S"\r
+        cmp  dword ptr [inflate_fast_use_mmx],2\r
+        jne  L_update_next_in\r
+\r
+\r
+\r
+        mov  ebx,ebp\r
+\r
+L_update_next_in: \r
+; 1266 "inffast.S"\r
+        mov  eax, [esp+88]\r
+        mov  ecx,ebx\r
+        mov  edx, [eax+28]\r
+        shr  ecx,3\r
+        sub  esi,ecx\r
+        shl  ecx,3\r
+        sub  ebx,ecx\r
+        mov  [eax+12],edi\r
+        mov  [edx+48],ebx\r
+        mov  ecx,ebx\r
+\r
+        lea  ebx, [esp+28]\r
+        cmp  [esp+20],ebx\r
+        jne  L_buf_not_used\r
+\r
+        sub  esi,ebx\r
+        mov  ebx, [eax+0]\r
+        mov  [esp+20],ebx\r
+        add  esi,ebx\r
+        mov  ebx, [eax+4]\r
+        sub  ebx,11\r
+        add  [esp+20],ebx\r
+\r
+L_buf_not_used: \r
+        mov  [eax+0],esi\r
+\r
+        mov  ebx,1\r
+        shl  ebx,cl\r
+        dec  ebx\r
+\r
+\r
+\r
+\r
+\r
+        cmp  dword ptr [inflate_fast_use_mmx],2\r
+        jne  L_update_hold\r
+\r
+\r
+\r
+        psrlq mm0,mm1\r
+        movd ebp,mm0\r
+\r
+        emms\r
+\r
+L_update_hold: \r
+\r
+\r
+\r
+        and  ebp,ebx\r
+        mov  [edx+44],ebp\r
+\r
+\r
+\r
+\r
+        mov  ebx, [esp+20]\r
+        cmp  ebx,esi\r
+        jbe  L_last_is_smaller\r
+\r
+        sub  ebx,esi\r
+        add  ebx,11\r
+        mov  [eax+4],ebx\r
+        jmp  L_fixup_out\r
+L_last_is_smaller: \r
+        sub  esi,ebx\r
+        neg  esi\r
+        add  esi,11\r
+        mov  [eax+4],esi\r
+\r
+\r
+\r
+\r
+L_fixup_out: \r
+\r
+        mov  ebx, [esp+16]\r
+        cmp  ebx,edi\r
+        jbe  L_end_is_smaller\r
+\r
+        sub  ebx,edi\r
+        add  ebx,257\r
+        mov  [eax+16],ebx\r
+        jmp  L_done\r
+L_end_is_smaller: \r
+        sub  edi,ebx\r
+        neg  edi\r
+        add  edi,257\r
+        mov  [eax+16],edi\r
+\r
+\r
+\r
+\r
+\r
+L_done: \r
+        add  esp,64\r
+        popfd\r
+        pop  ebx\r
+        pop  ebp\r
+        pop  esi\r
+        pop  edi\r
+        ret\r
+\r
+\r
+\r
+\r
+_TEXT   ends\r
+end\r
diff --git a/zlib/contrib/vstudio/vc70_32/inffastAsm.obj b/zlib/contrib/vstudio/vc70_32/inffastAsm.obj
new file mode 100644 (file)
index 0000000..3855400
Binary files /dev/null and b/zlib/contrib/vstudio/vc70_32/inffastAsm.obj differ
diff --git a/zlib/contrib/vstudio/vc70_32/miniunz.vcproj b/zlib/contrib/vstudio/vc70_32/miniunz.vcproj
new file mode 100644 (file)
index 0000000..56f0da3
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding = "Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.00"\r
+       Name="miniunz"\r
+       ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694382A}"\r
+       Keyword="Win32Proj">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="Debug"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="TRUE"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="5"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/miniunz.exe"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile="$(OutDir)/miniunz.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="Release"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               InlineFunctionExpansion="1"\r
+                               OmitFramePointers="TRUE"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               StringPooling="TRUE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="3"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/miniunz.exe"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="TRUE"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               OptimizeForWindows98="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">\r
+                       <File\r
+                               RelativePath="miniunz.c">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc">\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">\r
+               </Filter>\r
+               <File\r
+                       RelativePath="zlib.lib">\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/zlib/contrib/vstudio/vc70_32/minizip.vcproj b/zlib/contrib/vstudio/vc70_32/minizip.vcproj
new file mode 100644 (file)
index 0000000..2cc5aca
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding = "Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.00"\r
+       Name="minizip"\r
+       ProjectGUID="{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"\r
+       Keyword="Win32Proj">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="Debug"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="TRUE"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="5"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/minizip.exe"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile="$(OutDir)/minizip.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="Release"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               InlineFunctionExpansion="1"\r
+                               OmitFramePointers="TRUE"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               StringPooling="TRUE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="TRUE"\r
+                               DebugInformationFormat="3"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)/minizip.exe"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="TRUE"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               OptimizeForWindows98="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">\r
+                       <File\r
+                               RelativePath="minizip.c">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc">\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">\r
+               </Filter>\r
+               <File\r
+                       RelativePath="zlib.lib">\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/zlib/contrib/vstudio/vc70_32/mkgvmt32.bat b/zlib/contrib/vstudio/vc70_32/mkgvmt32.bat
new file mode 100644 (file)
index 0000000..9c54db7
--- /dev/null
@@ -0,0 +1,2 @@
+c:\masm611\bin\ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm\r
+c:\masm611\bin\ml /coff /Zi /c /FlinffastAsm.lst inffastAsm.asm\r
diff --git a/zlib/contrib/vstudio/vc70_32/zlib.rc b/zlib/contrib/vstudio/vc70_32/zlib.rc
new file mode 100644 (file)
index 0000000..5d86e03
--- /dev/null
@@ -0,0 +1,32 @@
+#include <windows.h>\r
+\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
+  FILEFLAGSMASK        VS_FFI_FILEFLAGSMASK\r
+  FILEFLAGS    0\r
+  FILEOS       VOS_DOS_WINDOWS32\r
+  FILETYPE     VFT_DLL\r
+  FILESUBTYPE  0       // not used\r
+BEGIN\r
+  BLOCK "StringFileInfo"\r
+  BEGIN\r
+    BLOCK "040904E4"\r
+    //language ID = U.S. English, char set = Windows, Multilingual\r
+\r
+    BEGIN\r
+      VALUE "FileDescription", "zlib data compression library\0"\r
+      VALUE "FileVersion",     "1.2.0.0\0"\r
+      VALUE "InternalName",    "zlib\0"\r
+      VALUE "OriginalFilename",        "zlib.dll\0"\r
+      VALUE "ProductName",     "ZLib.DLL\0"\r
+      VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"\r
+      VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"\r
+    END\r
+  END\r
+  BLOCK "VarFileInfo"\r
+  BEGIN\r
+    VALUE "Translation", 0x0409, 1252\r
+  END\r
+END\r
diff --git a/zlib/contrib/vstudio/vc70_32/zlibstat.vcproj b/zlib/contrib/vstudio/vc70_32/zlibstat.vcproj
new file mode 100644 (file)
index 0000000..94d4a63
--- /dev/null
@@ -0,0 +1,253 @@
+<?xml version="1.0" encoding = "Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.00"\r
+       Name="zlibstat"\r
+       SccProjectName=""\r
+       SccLocalPath="">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory=".\zlibstatDebug"\r
+                       IntermediateDirectory=".\zlibstatDebug"\r
+                       ConfigurationType="4"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="5"\r
+                               PrecompiledHeaderFile=".\zlibstatDebug/zlibstat.pch"\r
+                               AssemblerListingLocation=".\zlibstatDebug/"\r
+                               ObjectFile=".\zlibstatDebug/"\r
+                               ProgramDataBaseFileName=".\zlibstatDebug/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="1"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               AdditionalOptions="/NODEFAULTLIB "\r
+                               OutputFile=".\zlibstatDebug\zlibstat.lib"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="ReleaseAxp|Win32"\r
+                       OutputDirectory=".\zlibsta0"\r
+                       IntermediateDirectory=".\zlibsta0"\r
+                       ConfigurationType="4"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibsta0/zlibstat.pch"\r
+                               AssemblerListingLocation=".\zlibsta0/"\r
+                               ObjectFile=".\zlibsta0/"\r
+                               ProgramDataBaseFileName=".\zlibsta0/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               AdditionalOptions="/NODEFAULTLIB "\r
+                               OutputFile=".\zlibsta0\zlibstat.lib"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory=".\zlibstat"\r
+                       IntermediateDirectory=".\zlibstat"\r
+                       ConfigurationType="4"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32,ASMV"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"\r
+                               AssemblerListingLocation=".\zlibstat/"\r
+                               ObjectFile=".\zlibstat/"\r
+                               ProgramDataBaseFileName=".\zlibstat/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               AdditionalOptions="gvmat32.obj  inffastAsm.obj /NODEFAULTLIB "\r
+                               OutputFile=".\zlibstat\zlibstat.lib"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="ReleaseWithoutAsm|Win32"\r
+                       OutputDirectory="zlibstatWithoutAsm"\r
+                       IntermediateDirectory="zlibstatWithoutAsm"\r
+                       ConfigurationType="4"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="4"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"\r
+                               AssemblerListingLocation=".\zlibstatWithoutAsm/"\r
+                               ObjectFile=".\zlibstatWithoutAsm/"\r
+                               ProgramDataBaseFileName=".\zlibstatWithoutAsm/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                               AdditionalOptions=" /NODEFAULTLIB "\r
+                               OutputFile=".\zlibstatWithoutAsm\zlibstat.lib"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="">\r
+                       <File\r
+                               RelativePath=".\adler32.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\compress.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\crc32.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\deflate.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\gvmat32c.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\gzio.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\infback.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inffast.c">\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32"\r
+                                       ExcludedFromBuild="TRUE">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="ReleaseWithoutAsm|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inflate.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inftrees.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\ioapi.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\trees.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\uncompr.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\unzip.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zip.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zlib.rc">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zlibvc.def">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zutil.c">\r
+                       </File>\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/zlib/contrib/vstudio/vc70_32/zlibvc.def b/zlib/contrib/vstudio/vc70_32/zlibvc.def
new file mode 100644 (file)
index 0000000..90109d6
--- /dev/null
@@ -0,0 +1,88 @@
+LIBRARY                "zlib"\r
+\r
+VERSION                1.20\r
+\r
+HEAPSIZE       1048576,8192\r
+\r
+EXPORTS\r
+        adler32                                  @1\r
+        compress                                 @2\r
+        crc32                                    @3\r
+        deflate                                  @4\r
+        deflateCopy                              @5\r
+        deflateEnd                               @6\r
+        deflateInit2_                            @7\r
+        deflateInit_                             @8\r
+        deflateParams                            @9\r
+        deflateReset                             @10\r
+        deflateSetDictionary                     @11\r
+        gzclose                                  @12\r
+        gzdopen                                  @13\r
+        gzerror                                  @14\r
+        gzflush                                  @15\r
+        gzopen                                   @16\r
+        gzread                                   @17\r
+        gzwrite                                  @18\r
+        inflate                                  @19\r
+        inflateEnd                               @20\r
+        inflateInit2_                            @21\r
+        inflateInit_                             @22\r
+        inflateReset                             @23\r
+        inflateSetDictionary                     @24\r
+        inflateSync                              @25\r
+        uncompress                               @26\r
+        zlibVersion                              @27\r
+        gzprintf                                 @28\r
+        gzputc                                   @29\r
+        gzgetc                                   @30\r
+        gzseek                                   @31\r
+        gzrewind                                 @32\r
+        gztell                                   @33\r
+        gzeof                                    @34\r
+        gzsetparams                              @35\r
+        zError                                   @36\r
+        inflateSyncPoint                         @37\r
+        get_crc_table                            @38\r
+        compress2                                @39\r
+        gzputs                                   @40\r
+        gzgets                                   @41\r
+        inflateCopy                              @42\r
+        inflateBackInit_                         @43\r
+        inflateBack                              @44\r
+        inflateBackEnd                           @45\r
+        compressBound                            @46\r
+\r
+        unzOpen                                  @61\r
+        unzClose                                 @62\r
+        unzGetGlobalInfo                         @63\r
+        unzGetCurrentFileInfo                    @64\r
+        unzGoToFirstFile                         @65\r
+        unzGoToNextFile                          @66\r
+        unzOpenCurrentFile                       @67\r
+        unzReadCurrentFile                       @68\r
+        unzOpenCurrentFile3                      @69\r
+        unztell                                  @70\r
+        unzeof                                   @71\r
+        unzCloseCurrentFile                      @72\r
+        unzGetGlobalComment                      @73\r
+        unzStringFileNameCompare                 @74\r
+        unzLocateFile                            @75\r
+        unzGetLocalExtrafield                    @76\r
+        unzOpen2                                 @77\r
+        unzOpenCurrentFile2                      @78\r
+        unzOpenCurrentFilePassword               @79\r
+\r
+        zipOpen                                  @80\r
+        zipOpenNewFileInZip                      @81\r
+        zipWriteInFileInZip                      @82\r
+        zipCloseFileInZip                        @83\r
+        zipClose                                 @84\r
+        zipOpenNewFileInZip2                     @86\r
+        zipCloseFileInZipRaw                     @87\r
+        zipOpen2                                 @88\r
+        zipOpenNewFileInZip3                     @89\r
+\r
+        unzGetFilePos                            @100\r
+        unzGoToFilePos                           @101\r
+\r
+        fill_win32_filefunc                      @110\r
diff --git a/zlib/contrib/vstudio/vc70_32/zlibvc.sln b/zlib/contrib/vstudio/vc70_32/zlibvc.sln
new file mode 100644 (file)
index 0000000..5a007ff
--- /dev/null
@@ -0,0 +1,66 @@
+Microsoft Visual Studio Solution File, Format Version 7.00\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfiguration) = preSolution\r
+               ConfigName.0 = Debug\r
+               ConfigName.1 = Release\r
+               ConfigName.2 = ReleaseAxp\r
+               ConfigName.3 = ReleaseWithoutAsm\r
+               ConfigName.4 = ReleaseWithoutCrtdll\r
+       EndGlobalSection\r
+       GlobalSection(ProjectDependencies) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfiguration) = postSolution\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.ActiveCfg = Debug|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.Build.0 = Debug|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.ActiveCfg = Release|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.Build.0 = Release|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.Build.0 = ReleaseAxp|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseAxp|Win32\r
+               {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.Build.0 = ReleaseAxp|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.ActiveCfg = Debug|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.Build.0 = Debug|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.ActiveCfg = Release|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.Build.0 = Release|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.Build.0 = ReleaseAxp|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseWithoutCrtdll|Win32\r
+               {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.Build.0 = ReleaseWithoutCrtdll|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.ActiveCfg = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.Build.0 = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.ActiveCfg = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.Build.0 = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32\r
+               {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.Build.0 = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.ActiveCfg = Debug|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.Build.0 = Debug|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.ActiveCfg = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.Build.0 = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.ActiveCfg = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.Build.0 = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.ActiveCfg = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.Build.0 = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32\r
+               {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityGlobals) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityAddIns) = postSolution\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/zlib/contrib/vstudio/vc70_32/zlibvc.vcproj b/zlib/contrib/vstudio/vc70_32/zlibvc.vcproj
new file mode 100644 (file)
index 0000000..fcf9892
--- /dev/null
@@ -0,0 +1,434 @@
+<?xml version="1.0" encoding = "Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.00"\r
+       Name="zlibvc"\r
+       SccProjectName=""\r
+       SccLocalPath="">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory=".\DebugDll"\r
+                       IntermediateDirectory=".\DebugDll"\r
+                       ConfigurationType="2"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32,ASMV"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="1"\r
+                               PrecompiledHeaderFile=".\DebugDll/zlibvc.pch"\r
+                               AssemblerListingLocation=".\DebugDll/"\r
+                               ObjectFile=".\DebugDll/"\r
+                               ProgramDataBaseFileName=".\DebugDll/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="/MACHINE:I386"\r
+                               AdditionalDependencies="gvmat32.obj "\r
+                               OutputFile=".\DebugDll\zlib.dll"\r
+                               LinkIncremental="2"\r
+                               SuppressStartupBanner="TRUE"\r
+                               ModuleDefinitionFile=".\zlibvc.def"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile=".\DebugDll/zlib.pdb"\r
+                               SubSystem="2"\r
+                               ImportLibrary=".\DebugDll/zlib.lib"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               PreprocessorDefinitions="_DEBUG"\r
+                               MkTypLibCompatible="TRUE"\r
+                               SuppressStartupBanner="TRUE"\r
+                               TargetEnvironment="1"\r
+                               TypeLibraryName=".\DebugDll/zlibvc.tlb"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="_DEBUG"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="ReleaseWithoutAsm|Win32"\r
+                       OutputDirectory=".\zlibDllWithoutAsm"\r
+                       IntermediateDirectory=".\zlibDllWithoutAsm"\r
+                       ConfigurationType="2"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibDllWithoutAsm/zlibvc.pch"\r
+                               AssemblerOutput="2"\r
+                               AssemblerListingLocation=".\zlibDllWithoutAsm/"\r
+                               ObjectFile=".\zlibDllWithoutAsm/"\r
+                               ProgramDataBaseFileName=".\zlibDllWithoutAsm/"\r
+                               BrowseInformation="1"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="/MACHINE:I386"\r
+                               AdditionalDependencies="crtdll.lib"\r
+                               OutputFile=".\zlibDllWithoutAsm\zlib.dll"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreAllDefaultLibraries="TRUE"\r
+                               ModuleDefinitionFile=".\zlibvc.def"\r
+                               ProgramDatabaseFile=".\zlibDllWithoutAsm/zlib.pdb"\r
+                               GenerateMapFile="TRUE"\r
+                               MapFileName=".\zlibDllWithoutAsm/zlib.map"\r
+                               SubSystem="2"\r
+                               OptimizeForWindows98="1"\r
+                               ImportLibrary=".\zlibDllWithoutAsm/zlib.lib"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               MkTypLibCompatible="TRUE"\r
+                               SuppressStartupBanner="TRUE"\r
+                               TargetEnvironment="1"\r
+                               TypeLibraryName=".\zlibDllWithoutAsm/zlibvc.tlb"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="ReleaseWithoutCrtdll|Win32"\r
+                       OutputDirectory=".\zlibDllWithoutCrtDll"\r
+                       IntermediateDirectory=".\zlibDllWithoutCrtDll"\r
+                       ConfigurationType="2"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32,ASMV"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibDllWithoutCrtDll/zlibvc.pch"\r
+                               AssemblerOutput="2"\r
+                               AssemblerListingLocation=".\zlibDllWithoutCrtDll/"\r
+                               ObjectFile=".\zlibDllWithoutCrtDll/"\r
+                               ProgramDataBaseFileName=".\zlibDllWithoutCrtDll/"\r
+                               BrowseInformation="1"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="/MACHINE:I386"\r
+                               AdditionalDependencies="gvmat32.obj inffastAsm.obj "\r
+                               OutputFile=".\zlibDllWithoutCrtDll\zlib.dll"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreAllDefaultLibraries="FALSE"\r
+                               ModuleDefinitionFile=".\zlibvc.def"\r
+                               ProgramDatabaseFile=".\zlibDllWithoutCrtDll/zlib.pdb"\r
+                               GenerateMapFile="TRUE"\r
+                               MapFileName=".\zlibDllWithoutCrtDll/zlib.map"\r
+                               SubSystem="2"\r
+                               OptimizeForWindows98="1"\r
+                               ImportLibrary=".\zlibDllWithoutCrtDll/zlib.lib"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               MkTypLibCompatible="TRUE"\r
+                               SuppressStartupBanner="TRUE"\r
+                               TargetEnvironment="1"\r
+                               TypeLibraryName=".\zlibDllWithoutCrtDll/zlibvc.tlb"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="ReleaseAxp|Win32"\r
+                       OutputDirectory=".\zlibvc__"\r
+                       IntermediateDirectory=".\zlibvc__"\r
+                       ConfigurationType="2"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\zlibvc__/zlibvc.pch"\r
+                               AssemblerOutput="2"\r
+                               AssemblerListingLocation=".\zlibvc__/"\r
+                               ObjectFile=".\zlibvc__/"\r
+                               ProgramDataBaseFileName=".\zlibvc__/"\r
+                               BrowseInformation="1"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="crtdll.lib"\r
+                               OutputFile="zlibvc__\zlib.dll"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreAllDefaultLibraries="TRUE"\r
+                               ModuleDefinitionFile=".\zlibvc.def"\r
+                               ProgramDatabaseFile=".\zlibvc__/zlib.pdb"\r
+                               GenerateMapFile="TRUE"\r
+                               MapFileName=".\zlibvc__/zlib.map"\r
+                               SubSystem="2"\r
+                               ImportLibrary=".\zlibvc__/zlib.lib"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               MkTypLibCompatible="TRUE"\r
+                               SuppressStartupBanner="TRUE"\r
+                               TargetEnvironment="1"\r
+                               TypeLibraryName=".\zlibvc__/zlibvc.tlb"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory=".\ReleaseDll"\r
+                       IntermediateDirectory=".\ReleaseDll"\r
+                       ConfigurationType="2"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32,ASMV"\r
+                               StringPooling="TRUE"\r
+                               ExceptionHandling="FALSE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               PrecompiledHeaderFile=".\ReleaseDll/zlibvc.pch"\r
+                               AssemblerOutput="2"\r
+                               AssemblerListingLocation=".\ReleaseDll/"\r
+                               ObjectFile=".\ReleaseDll/"\r
+                               ProgramDataBaseFileName=".\ReleaseDll/"\r
+                               BrowseInformation="1"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="/MACHINE:I386"\r
+                               AdditionalDependencies="gvmat32.obj inffastAsm.obj crtdll.lib"\r
+                               OutputFile=".\ReleaseDll\zlib.dll"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreAllDefaultLibraries="TRUE"\r
+                               ModuleDefinitionFile=".\zlibvc.def"\r
+                               ProgramDatabaseFile=".\ReleaseDll/zlib.pdb"\r
+                               GenerateMapFile="TRUE"\r
+                               MapFileName=".\ReleaseDll/zlib.map"\r
+                               SubSystem="2"\r
+                               OptimizeForWindows98="1"\r
+                               ImportLibrary=".\ReleaseDll/zlib.lib"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               MkTypLibCompatible="TRUE"\r
+                               SuppressStartupBanner="TRUE"\r
+                               TargetEnvironment="1"\r
+                               TypeLibraryName=".\Release/zlibvc.tlb"/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1036"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90">\r
+                       <File\r
+                               RelativePath=".\adler32.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\compress.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\crc32.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\deflate.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\gvmat32c.c">\r
+                               <FileConfiguration\r
+                                       Name="ReleaseWithoutAsm|Win32"\r
+                                       ExcludedFromBuild="TRUE">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\gzio.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\infback.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inffast.c">\r
+                               <FileConfiguration\r
+                                       Name="ReleaseWithoutCrtdll|Win32"\r
+                                       ExcludedFromBuild="TRUE">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32"\r
+                                       ExcludedFromBuild="TRUE">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inflate.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inftrees.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\ioapi.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\iowin32.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\trees.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\uncompr.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\unzip.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zip.c">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zlib.rc">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zlibvc.def">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zutil.c">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;fi;fd">\r
+                       <File\r
+                               RelativePath=".\deflate.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\infblock.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\infcodes.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inffast.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\inftrees.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\infutil.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zconf.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zlib.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\zutil.h">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index 167fd83..cbefc39 100644 (file)
@@ -9,7 +9,7 @@
  * increase in speed on a Power PC using gcc -O3.
  */
 
-/* @(#) $Id: crc32.c,v 1.9 2003/03/08 21:47:46 jbj Exp $ */
+/* @(#) $Id: crc32.c,v 1.10 2003/03/08 23:18:09 jbj Exp $ */
 
 #ifdef MAKECRCH
 #  include <stdio.h>
@@ -99,7 +99,7 @@ local void make_crc_table()
     poly = 0UL;
     for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
         poly |= 1UL << (31 - p[n]);
+
     /* generate a crc for every 8-bit value */
     for (n = 0; n < 256; n++) {
         c = (unsigned long)n;
@@ -128,7 +128,7 @@ local void make_crc_table()
     /* write out CRC tables to crc32.h */
     {
         FILE *out;
-    
+
         out = fopen("crc32.h", "w");
         if (out == NULL) return;
         fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
@@ -199,7 +199,7 @@ unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
 #ifdef BYFOUR
     {
         u4 endian;
-    
+
         endian = 1;
         if (*((unsigned char *)(&endian)))
             return crc32_little(crc, buf, len);
index ecaa5dc..6165944 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
@@ -57,7 +57,7 @@
 /*@-exportheadervar@*/
 /*@unused@*/ /*@observer@*/
 const char deflate_copyright[] =
-   " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly ";
+   " deflate 1.2.0.1 Copyright 1995-2003 Jean-loup Gailly ";
 /*@=exportheadervar@*/
 
 /*
@@ -88,8 +88,10 @@ local block_state deflate_stored OF((deflate_state *s, int flush))
        /*@modifies *s @*/;
 local block_state deflate_fast   OF((deflate_state *s, int flush))
        /*@modifies *s @*/;
+#ifndef FASTEST
 local block_state deflate_slow   OF((deflate_state *s, int flush))
        /*@modifies *s @*/;
+#endif
 local void lm_init        OF((deflate_state *s))
        /*@modifies *s @*/;
 local void putShortMSB    OF((deflate_state *s, uInt b))
@@ -98,6 +100,7 @@ local void flush_pending  OF((z_streamp strm))
        /*@modifies strm @*/;
 local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size))
        /*@modifies strm, *buf @*/;
+#ifndef FASTEST
 #ifdef ASMV
       void match_init OF((void))       /* asm code initialization */
        /*@*/;
@@ -107,6 +110,9 @@ local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size))
 local uInt longest_match  OF((deflate_state *s, IPos cur_match))
        /*@modifies *s @*/;
 #endif
+#endif
+local uInt longest_match_fast  OF((deflate_state *s, IPos cur_match))
+       /*@modifies *s @*/;
 
 #ifdef DEBUG
 local  void check_match OF((deflate_state *s, IPos start, IPos match,
@@ -149,6 +155,12 @@ typedef struct config_s {
 } config;
 
 /*@observer@*/ /*@unchecked@*/
+#ifdef FASTEST
+local const config configuration_table[2] = {
+/*      good lazy nice chain */
+/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
+/* 1 */ {4,    4,  8,    4, deflate_fast}}; /* maximum speed, no lazy matches */
+#else
 local const config configuration_table[10] = {
 /*      good lazy nice chain */
 /* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
@@ -162,6 +174,7 @@ local const config configuration_table[10] = {
 /* 7 */ {8,   32, 128, 256, deflate_slow},
 /* 8 */ {32, 128, 258, 1024, deflate_slow},
 /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
+#endif
 
 /* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
  * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
@@ -252,9 +265,10 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
     }
     if (strm->zfree == Z_NULL) strm->zfree = zcfree;
 
-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
 #ifdef FASTEST
-    level = 1;
+    if (level != 0) level = 1;
+#else
+    if (level == Z_DEFAULT_COMPRESSION) level = 6;
 #endif
 
     if (windowBits < 0) { /* undocumented feature: suppress zlib header */
@@ -263,7 +277,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
     }
     if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
         windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
-       strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
+       strategy < 0 || strategy > Z_RLE) {
         return Z_STREAM_ERROR;
     }
     s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
@@ -293,6 +307,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
 
     if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
         s->pending_buf == Z_NULL) {
+       s->status = FINISH_STATE;
         strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
         deflateEnd (strm);
         return Z_MEM_ERROR;
@@ -317,10 +332,12 @@ int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef * dictionary,
     IPos hash_head = 0;
 
     if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
-        strm->state->status != INIT_STATE) return Z_STREAM_ERROR;
+       (!strm->state->noheader && strm->state->status != INIT_STATE))
+       return Z_STREAM_ERROR;
 
     s = strm->state;
-    strm->adler = adler32(strm->adler, dictionary, dictLength);
+    if (!s->noheader)
+       strm->adler = adler32(strm->adler, dictionary, dictLength);
 
     if (length < MIN_MATCH) return Z_OK;
     if (length > MAX_DIST(s)) {
@@ -350,7 +367,7 @@ int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef * dictionary,
 int ZEXPORT deflateReset (z_streamp strm)
 {
     deflate_state *s;
-    
+
     if (strm == Z_NULL || strm->state == Z_NULL ||
         strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
 
@@ -385,10 +402,12 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
     s = strm->state;
 
-    if (level == Z_DEFAULT_COMPRESSION) {
-       level = 6;
-    }
-    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
+#ifdef FASTEST
+    if (level != 0) level = 1;
+#else
+    if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) {
        return Z_STREAM_ERROR;
     }
     func = configuration_table[s->level].func;
@@ -410,6 +429,46 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
 
 /* ========================================================================= */
 /**
+ * For the default windowBits of 15 and memLevel of 8, this function returns
+ * a close to exact, as well as small, upper bound on the compressed size.
+ * They are coded as constants here for a reason--if the #define's are
+ * changed, then this function needs to be changed as well.  The return
+ * value for 15 and 8 only works for those exact settings.
+ *
+ * For any setting other than those defaults for windowBits and memLevel,
+ * the value returned is a conservative worst case for the maximum expansion
+ * resulting from using fixed blocks instead of stored blocks, which deflate
+ * can emit on compressed data for some combinations of the parameters.
+ *
+ * This function could be more sophisticated to provide closer upper bounds
+ * for every combination of windowBits and memLevel, as well as noheader.
+ * But even the conservative upper bound of about 14% expansion does not
+ * seem onerous for output buffer allocation.
+ */
+uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
+{
+    deflate_state *s;
+    uLong destLen;
+
+    /* conservative upper bound */
+    destLen = sourceLen +
+              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
+
+    /* if can't get parameters, return conservative bound */
+    if (strm == Z_NULL || strm->state == Z_NULL)
+       return destLen;
+
+    /* if not default parameters, return conservative bound */
+    s = strm->state;
+    if (s->w_bits != 15 || s->hash_bits != 8 + 7)
+       return destLen;
+
+    /* default settings: return tight bound for that case */
+    return compressBound(sourceLen);
+}
+
+/* ========================================================================= */
+/**
  * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  * IN assertion: the stream state is correct and there is enough room in
  * pending_buf.
@@ -418,7 +477,7 @@ local void putShortMSB (deflate_state * s, uInt b)
 {
     put_byte(s, (Byte)(b >> 8));
     put_byte(s, (Byte)(b & 0xff));
-}   
+}
 
 /* ========================================================================= */
 /**
@@ -506,7 +565,7 @@ int ZEXPORT deflate (z_streamp strm, int flush)
 
     /* Make sure there is something to do and avoid duplicate consecutive
      * flushes. For repeated and useless calls with Z_FINISH, we keep
-     * returning Z_STREAM_END instead of Z_BUFF_ERROR.
+     * returning Z_STREAM_END instead of Z_BUF_ERROR.
      */
     } else if (strm->avail_in == 0 && flush <= old_flush &&
               flush != Z_FINISH) {
@@ -658,7 +717,7 @@ int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
     ds->bl_desc.dyn_tree = ds->bl_tree;
 
     return Z_OK;
-#endif
+#endif /* MAXSEG_64K */
 }
 
 /* ========================================================================= */
@@ -716,6 +775,7 @@ local void lm_init (deflate_state * s)
 #endif
 }
 
+#ifndef        FASTEST
 /* ========================================================================= */
 /**
  * Set match_start to the longest match starting at the given string and
@@ -730,7 +790,6 @@ local void lm_init (deflate_state * s)
 /* For 80x86 and 680x0, an optimized version will be provided in match.asm or
  * match.S. The code will be functionally equivalent.
  */
-#ifndef FASTEST
 local uInt longest_match(deflate_state * s, IPos cur_match)
 {
     unsigned chain_length = s->max_chain_length;/* max hash chain length */
@@ -866,12 +925,13 @@ local uInt longest_match(deflate_state * s, IPos cur_match)
     if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
     return s->lookahead;
 }
+#endif /* ASMV */
+#endif /* FASTEST */
 
-#else /* FASTEST */
 /* ---------------------------------------------------------------------------
- * Optimized version for level == 1 only
+ * Optimized version for level == 1 or strategy == Z_RLE only
  */
-local uInt longest_match(deflate_state * s, IPos cur_match)
+local uInt longest_match_fast(deflate_state * s, IPos cur_match)
 {
     register Bytef *scan = s->window + s->strstart; /* current string */
     register Bytef *match;                       /* matched string */
@@ -921,8 +981,6 @@ local uInt longest_match(deflate_state * s, IPos cur_match)
     s->match_start = cur_match;
     return len <= s->lookahead ? len : s->lookahead;
 }
-#endif /* FASTEST */
-#endif /* ASMV */
 
 #ifdef DEBUG
 /* ========================================================================= */
@@ -948,7 +1006,7 @@ local void check_match(deflate_state * s, IPos start, IPos match, int length)
 }
 #else
 #  define check_match(s, start, match, length)
-#endif
+#endif /* DEBUG */
 
 /* ========================================================================= */
 /**
@@ -1173,10 +1231,19 @@ local block_state deflate_fast(deflate_state * s, int flush)
              * of window index 0 (in particular we have to avoid a match
              * of the string with itself at the start of the input file).
              */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
+#ifdef FASTEST
+           if ((s->strategy < Z_HUFFMAN_ONLY) ||
+               (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
+               s->match_length = longest_match_fast (s, hash_head);
+           }
+#else
+           if (s->strategy < Z_HUFFMAN_ONLY) {
                 s->match_length = longest_match (s, hash_head);
+           } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+               s->match_length = longest_match_fast (s, hash_head);
             }
-            /* longest_match() sets match_start */
+#endif
+           /* longest_match() or longest_match_fast() sets match_start */
         }
         if (s->match_length >= MIN_MATCH) {
             check_match(s, s->strstart, s->match_start, s->match_length);
@@ -1228,6 +1295,7 @@ local block_state deflate_fast(deflate_state * s, int flush)
     return flush == Z_FINISH ? finish_done : block_done;
 }
 
+#ifndef        FASTEST
 /* ========================================================================= */
 /**
  * Same as above, but achieves better compression. We use a lazy
@@ -1272,10 +1340,12 @@ local block_state deflate_slow(deflate_state * s, int flush)
              * of window index 0 (in particular we have to avoid a match
              * of the string with itself at the start of the input file).
              */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
+            if (s->strategy < Z_HUFFMAN_ONLY) {
                 s->match_length = longest_match (s, hash_head);
-            }
-            /* longest_match() sets match_start */
+            } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+               s->match_length = longest_match_fast (s, hash_head);
+           }
+           /* longest_match() or longest_match_fast() sets match_start */
 
             if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
                  (s->match_length == MIN_MATCH &&
@@ -1348,3 +1418,4 @@ local block_state deflate_slow(deflate_state * s, int flush)
     FLUSH_BLOCK(s, flush == Z_FINISH);
     return flush == Z_FINISH ? finish_done : block_done;
 }
+#endif /* FASTEST */
index 821ebb0..ab4cb87 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
@@ -536,6 +536,8 @@ int main(int argc, char * argv[])
     test_dict_deflate(compr, comprLen);
     test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
 
-    exit(0);
-    return 0; /* to avoid warning */
+    free(compr);
+    free(uncompr);
+
+    return 0;
 }
index eeec8a2..c49192a 100644 (file)
@@ -1,11 +1,11 @@
 /* gzio.c -- IO on .gz files
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h
  *
  * Compile this file with -DNO_DEFLATE to avoid the compression code.
  */
 
-/* @(#) $Id: gzio.c,v 1.10 2002/10/07 09:05:07 jbj Exp $ */
+/* @(#) $Id: gzio.c,v 1.11 2003/03/08 23:18:09 jbj Exp $ */
 
 #include <stdio.h>
 
@@ -24,11 +24,16 @@ struct internal_state {int dummy;}; /* for buggy compilers */
 #  define Z_PRINTF_BUFSIZE 4096
 #endif
 
+#ifndef STDC
+extern voidp  malloc OF((uInt size));
+extern void   free   OF((voidpf ptr));
+#endif
+
 #define ALLOC(size) malloc(size)
 #define TRYFREE(p) {if (p) free(p);}
 
 /*@observer@*/ /*@unchecked@*/
-static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
+static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
 
 /* gzip flag byte */
 #define ASCII_FLAG   0x01 /*!< bit 0 set: file probably ascii text */
@@ -135,12 +140,14 @@ local gzFile gz_open (const char * path, const char * mode, int fd)
          strategy = Z_FILTERED;
        } else if (*p == 'h') {
          strategy = Z_HUFFMAN_ONLY;
+       } else if (*p == 'R') {
+         strategy = Z_RLE;
        } else {
            *m++ = *p; /* copy the mode */
        }
     } while (*p++ && m != fmode + sizeof(fmode));
     if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
-    
+
     if (s->mode == 'w') {
 #ifdef NO_DEFLATE
         err = Z_STREAM_ERROR;
@@ -282,19 +289,33 @@ local void check_header(gz_stream * s)
     uInt len;
     int c;
 
-    /* Check the gzip magic header */
-    for (len = 0; len < 2; len++) {
-       c = get_byte(s);
-       if (c != gz_magic[len]) {
-           if (len != 0) s->stream.avail_in++, s->stream.next_in--;
-           if (c != EOF) {
-               s->stream.avail_in++, s->stream.next_in--;
-               s->transparent = 1;
-           }
-           s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
+    /* Assure two bytes in the buffer so we can peek ahead -- handle case
+       where first byte of header is at the end of the buffer after the last
+       gzip segment */
+    len = s->stream.avail_in;
+    if (len < 2) {
+       if (len) s->inbuf[0] = s->stream.next_in[0];
+       errno = 0;
+       len = fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
+       if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
+       s->stream.avail_in += len;
+       s->stream.next_in = s->inbuf;
+       if (s->stream.avail_in < 2) {
+           s->transparent = s->stream.avail_in;
            return;
        }
     }
+
+    /* Peek ahead to check the gzip magic header */
+    if (s->stream.next_in[0] != gz_magic[0] ||
+       s->stream.next_in[1] != gz_magic[1]) {
+       s->transparent = 1;
+       return;
+    }
+    s->stream.avail_in -= 2;
+    s->stream.next_in += 2;
+
+    /* Check the rest of the gzip header */
     method = get_byte(s);
     flags = get_byte(s);
     if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
@@ -494,7 +515,7 @@ char * ZEXPORT gzgets(gzFile file, char * buf, int len)
  * Writes the given number of uncompressed bytes into the compressed file.
  * gzwrite returns the number of bytes actually written (0 in case of error).
  */
-int ZEXPORT gzwrite (gzFile file, const voidp buf, unsigned len)
+int ZEXPORT gzwrite (gzFile file, voidpc buf, unsigned len)
 {
     gz_stream *s = (gz_stream*)file;
 
@@ -540,14 +561,32 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
     int len;
 
     va_start(va, format);
-#ifdef HAS_vsnprintf
-    (void)vsnprintf(buf, sizeof(buf), format, va);
-#else
+#ifdef NO_vsnprintf
+#  ifdef HAS_vsprintf_void
     (void)vsprintf(buf, format, va);
-#endif
     va_end(va);
     len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
     if (len <= 0) return 0;
+#  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
 
     return gzwrite(file, buf, (unsigned)len);
 }
@@ -563,15 +602,32 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
     char buf[Z_PRINTF_BUFSIZE];
     int len;
 
-#ifdef HAS_snprintf
+#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;
+#  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
-    sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
-           a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+    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
-    len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
-    if (len <= 0) return 0;
 
     return gzwrite(file, buf, len);
 }
@@ -685,6 +741,7 @@ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence)
        /* At this point, offset is the number of zero bytes to write. */
        if (s->inbuf == Z_NULL) {
            s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
+           if (s->inbuf == Z_NULL) return -1L;
            zmemzero(s->inbuf, Z_BUFSIZE);
        }
        while (offset > 0)  {
@@ -727,6 +784,7 @@ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence)
 
     if (offset != 0 && s->outbuf == Z_NULL) {
        s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+       if (s->outbuf == Z_NULL) return -1L;
     }
     while (offset > 0)  {
        int size = Z_BUFSIZE;
@@ -870,6 +928,7 @@ const char*  ZEXPORT gzerror (gzFile file, int * errnum)
 
     TRYFREE(s->msg);
     s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
+    if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
     strcpy(s->msg, s->path);
     strcat(s->msg, ": ");
     strcat(s->msg, m);
index 5e8d9cc..1d96d95 100644 (file)
@@ -143,8 +143,8 @@ local void fixedtables(struct inflate_state FAR *state)
 #define PULL() \
     do { \
         if (have == 0) { \
-            next = in(opaque, &have); \
-            if (next == Z_NULL || have == 0) { \
+            have = in(in_desc, &next); \
+            if (have == 0) { \
                 next = Z_NULL; \
                 ret = Z_BUF_ERROR; \
                 goto leave; \
@@ -197,7 +197,7 @@ local void fixedtables(struct inflate_state FAR *state)
         if (left == 0) { \
             put = state->window; \
             left = state->wsize; \
-            if (out(opaque, put, left)) { \
+            if (out(out_desc, put, left)) { \
                 ret = Z_BUF_ERROR; \
                 goto leave; \
             } \
@@ -217,12 +217,12 @@ local void fixedtables(struct inflate_state FAR *state)
    returns.  The application must not change the window/output buffer until
    inflateBack() returns.
 
-   in() and out() are called with the "opaque" parameter provided in the
+   in() and out() are called with a descriptor parameter provided in the
    inflateBack() call.  This parameter can be a structure that provides the
    information required to do the read or write, as well as accumulated
    information on the input and output such as totals and check values.
 
-   in() should return Z_NULL on failure.  out() should return non-zero on
+   in() should return 0 on failure.  out() should return non-zero on
    failure.  If either in() or out() fails, than inflateBack() returns a
    Z_BUF_ERROR.  strm->next_in can be checked for Z_NULL to see whether it
    was in() or out() that caused in the error.  Otherwise,  inflateBack()
@@ -231,8 +231,8 @@ local void fixedtables(struct inflate_state FAR *state)
    inflateBack() can also return Z_STREAM_ERROR if the input parameters
    are not correct, i.e. strm is Z_NULL or the state was not initialized.
  */
-int ZEXPORT inflateBack(z_stream FAR *strm, in_func in, out_func out,
-               void FAR *opaque)
+int ZEXPORT inflateBack(z_stream FAR *strm, in_func in, void FAR *in_desc,
+               out_func out, void FAR *out_desc)
 {
     struct inflate_state FAR *state;
     unsigned char *next, *put; /* next input and output */
@@ -444,6 +444,7 @@ int ZEXPORT inflateBack(z_stream FAR *strm, in_func in, out_func out,
             }
             Tracev((stderr, "inflate:       codes ok\n"));
             state->mode = LEN;
+
         case LEN:
             /* use inflate_fast() if we have enough input and output */
             if (have >= 6 && left >= 258) {
@@ -570,7 +571,7 @@ int ZEXPORT inflateBack(z_stream FAR *strm, in_func in, out_func out,
             /* inflate stream terminated properly -- write leftover output */
             ret = Z_STREAM_END;
             if (left < state->wsize) {
-                if (out(opaque, state->window, state->wsize - left))
+                if (out(out_desc, state->window, state->wsize - left))
                     ret = Z_BUF_ERROR;
             }
             goto leave;
@@ -593,11 +594,8 @@ int ZEXPORT inflateBack(z_stream FAR *strm, in_func in, out_func out,
 
 int ZEXPORT inflateBackEnd(z_stream FAR *strm)
 {
-    struct inflate_state FAR *state;
-
     if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
         return Z_STREAM_ERROR;
-    state = (struct inflate_state FAR *)strm->state;
     ZFREE(strm, strm->state);
     strm->state = Z_NULL;
     Tracev((stderr, "inflate: end\n"));
index 990a081..4c52afa 100644 (file)
@@ -133,7 +133,7 @@ void inflate_fast(z_streamp strm, unsigned start)
                     hold += (unsigned long)(PUP(in)) << bits;
                     bits += 8;
                 }
-                len += hold & ((1U << op) - 1);
+                len += (unsigned)hold & ((1U << op) - 1);
                 hold >>= op;
                 bits -= op;
             }
@@ -161,7 +161,7 @@ void inflate_fast(z_streamp strm, unsigned start)
                         bits += 8;
                     }
                 }
-                dist += hold & ((1U << op) - 1);
+                dist += (unsigned)hold & ((1U << op) - 1);
                 hold >>= op;
                 bits -= op;
                 Tracevv((stderr, "inflate:         distance %u\n", dist));
index b665aae..6357326 100644 (file)
  * 1.2.beta7   27 Jan 2003
  * - Changed many types to unsigned or unsigned short to avoid warnings
  * - Added inflateCopy() function
+ *
+ * 1.2.0        9 Mar 2003
+ * - Changed inflateBack() interface to provide separate opaque descriptors
+ *   for the in() and out() functions
+ * - Changed inflateBack() argument and in_func typedef to swap the length
+ *   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.
  */
 
 #include "zutil.h"
@@ -529,7 +538,8 @@ int ZEXPORT inflate(z_streamp strm, int flush)
     static const unsigned short order[19] = /* permutation of code lengths */
         {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
 
-    if (strm == Z_NULL || strm->state == Z_NULL)
+    if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
+        (strm->next_in == Z_NULL && strm->avail_in != 0))
         return Z_STREAM_ERROR;
 
     state = (struct inflate_state FAR *)strm->state;
index 01ffe0a..64af7d8 100644 (file)
@@ -8,6 +8,10 @@
    subject to change. Applications should only use zlib.h.
  */
 
+/* define NO_GUNZIP when compiling if you want to disable gzip header and
+   trailer decoding by inflate().  NO_GUNZIP would be used to avoid linking in
+   the crc code when it is not needed.  For shared libraries, gzip decoding
+   should be left enabled. */
 #ifndef NO_GUNZIP
 #  define GUNZIP
 #endif
index 3899710..2424ffa 100644 (file)
@@ -9,7 +9,7 @@
 #define MAXBITS 15
 
 const char inflate_copyright[] =
-   " inflate 1.2.beta7 Copyright 1995-2003 Mark Adler ";
+   " inflate 1.2.0.1 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
@@ -57,7 +57,7 @@ int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes,
         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, 65, 204};
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 205, 64};
     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,
diff --git a/zlib/maketree.c b/zlib/maketree.c
deleted file mode 100644 (file)
index a16d4b1..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* maketree.c -- make inffixed.h table for decoding fixed codes
- * Copyright (C) 1995-2002 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* This program is included in the distribution for completeness.
-   You do not need to compile or run this program since inffixed.h
-   is already included in the distribution.  To use this program
-   you need to compile zlib with BUILDFIXED defined and then compile
-   and link this program with the zlib library.  Then the output of
-   this program can be piped to inffixed.h. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "zutil.h"
-#include "inftrees.h"
-
-/* simplify the use of the inflate_huft type with some defines */
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-/* generate initialization table for an inflate_huft structure array */
-void maketree(uInt b, inflate_huft *t)
-{
-  int i, e;
-
-  i = 0;
-  while (1)
-  {
-    e = t[i].exop;
-    if (e && (e & (16+64)) == 0)        /* table pointer */
-    {
-      fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
-      exit(1);
-    }
-    if (i % 4 == 0)
-      printf("\n   ");
-    printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
-    if (++i == (1<<b))
-      break;
-    putchar(',');
-  }
-  puts("");
-}
-
-/* create the fixed tables in C initialization syntax */
-void main(void)
-{
-  int r;
-  uInt bl, bd;
-  inflate_huft *tl, *td;
-  z_stream z;
-
-  z.zalloc = zcalloc;
-  z.opaque = (voidpf)0;
-  z.zfree = zcfree;
-  r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
-  if (r)
-  {
-    fprintf(stderr, "inflate_trees_fixed error %d\n", r);
-    return;
-  }
-  puts("/* inffixed.h -- table for decoding fixed codes");
-  puts(" * Generated automatically by the maketree.c program");
-  puts(" */");
-  puts("");
-  puts("/* WARNING: this file should *not* be used by applications. It is");
-  puts("   part of the implementation of the compression library and is");
-  puts("   subject to change. Applications should only use zlib.h.");
-  puts(" */");
-  puts("");
-  printf("local uInt fixed_bl = %d;\n", bl);
-  printf("local uInt fixed_bd = %d;\n", bd);
-  printf("local inflate_huft fixed_tl[] = {");
-  maketree(bl, tl);
-  puts("  };");
-  printf("local inflate_huft fixed_td[] = {");
-  maketree(bd, td);
-  puts("  };");
-}
index fecde45..3d8c0b5 100644 (file)
@@ -1,5 +1,6 @@
 /* minigzip.c -- simulate gzip using the zlib compression library
  * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Adapted for Z_RLE by Cosmin Truta, 2003.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
@@ -13,7 +14,7 @@
  * or in pipe mode.
  */
 
-/* @(#) $Id$ */
+/* @(#) $Id: minigzip.c,v 1.5 2002/03/17 15:46:23 jbj Exp $ */
 
 #include <stdio.h>
 #include "zlib.h"
@@ -250,10 +251,11 @@ void file_uncompress(char * file)
 
 
 /* ===========================================================================
- * Usage:  minigzip [-d] [-f] [-h] [-1 to -9] [files...]
+ * Usage:  minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
  *   -d : decompress
  *   -f : compress with Z_FILTERED
  *   -h : compress with Z_HUFFMAN_ONLY
+ *   -r : compress with Z_RLE
  *   -1 to -9 : compression level
  */
 
@@ -275,6 +277,8 @@ int main(int argc, char * argv[])
        outmode[3] = 'f';
       else if (strcmp(*argv, "-h") == 0)
        outmode[3] = 'h';
+      else if (strcmp(*argv, "-r") == 0)
+       outmode[3] = 'R';
       else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
               (*argv)[2] == 0)
        outmode[2] = (*argv)[1];
index f5651b4..4ad4061 100644 (file)
@@ -1,5 +1,6 @@
 # Makefile for zlib
-# Borland C++   ************ UNTESTED ***********
+# Borland C++
+# Updated for zlib-1.2.x by Cosmin Truta, 15-Mar-2003.
 
 # To use, do "make -fmakefile.bor"
 # To compile in small model, set below: MODEL=s
 #   -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
 # See zconf.h for details about the memory requirements.
 
-# ------------- Turbo C++, Borland C++ -------------
+# ------------ Turbo C++, Borland C++ ------------
 
 #    Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
 #    should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
 #    to the declaration of LOC here:
 LOC = $(LOCAL_ZLIB)
 
-# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
+# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
 CPU_TYP = 0
 
-# Memory model: one of s, m, c, l (small, medium, compact, large)
+# memory model: one of s, m, c, l (small, medium, compact, large)
 MODEL=l
 
+# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version
 CC=bcc
-#   replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version
-LD=$(CC)
+LD=bcc
 AR=tlib
 
 # compiler flags
+# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0
 CFLAGS=-O2 -Z -m$(MODEL) $(LOC)
-#   replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0
 
-LDFLAGS=-m$(MODEL)
+LDFLAGS=-m$(MODEL) -f-
 
-O=.obj
 
 # variables
-OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
-  trees$(O)
-OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\
-  trees$(O)
-OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \
-  infutil$(O) inffast$(O)
-OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\
-  infutil$(O)+inffast$(O)
-
-ZLIB_H = zlib.h zconf.h
-ZUTIL_H = zutil.h $(ZLIB_H)
-
 ZLIB_LIB = zlib_$(MODEL).lib
 
-all: test
+OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
+OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
+OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
+OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
 
-# individual dependencies and action rules:
-adler32.obj: adler32.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
 
-compress.obj: compress.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+# targets
+all: $(ZLIB_LIB) example.exe minigzip.exe
 
-crc32.obj: crc32.c $(ZLIB_H)
+.c.obj:
        $(CC) -c $(CFLAGS) $*.c
 
-deflate.obj: deflate.c deflate.h $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+adler32.obj: adler32.c zlib.h zconf.h
 
-gzio.obj: gzio.c $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+compress.obj: compress.c zlib.h zconf.h
 
-infblock.obj: infblock.c $(ZUTIL_H) infblock.h inftrees.h infcodes.h infutil.h
-       $(CC) -c $(CFLAGS) $*.c
+crc32.obj: crc32.c zlib.h zconf.h crc32.h
 
-infcodes.obj: infcodes.c $(ZUTIL_H) inftrees.h infutil.h infcodes.h inffast.h
-       $(CC) -c $(CFLAGS) $*.c
+deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
 
-inflate.obj: inflate.c $(ZUTIL_H) infblock.h
-       $(CC) -c $(CFLAGS) $*.c
+gzio.obj: gzio.c zutil.h zlib.h zconf.h
 
-inftrees.obj: inftrees.c $(ZUTIL_H) inftrees.h
-       $(CC) -c $(CFLAGS) $*.c
+infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
 
-infutil.obj: infutil.c $(ZUTIL_H) inftrees.h infutil.h
-       $(CC) -c $(CFLAGS) $*.c
+inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h
 
-inffast.obj: inffast.c $(ZUTIL_H) inftrees.h infutil.h inffast.h
-       $(CC) -c $(CFLAGS) $*.c
+inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
 
-trees.obj: trees.c deflate.h $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
 
-uncompr.obj: uncompr.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
 
-zutil.obj: zutil.c $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+uncompr.obj: uncompr.c zlib.h zconf.h
 
-example.obj: example.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+zutil.obj: zutil.c zutil.h zlib.h zconf.h
 
-minigzip.obj: minigzip.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+example.obj: example.c zlib.h zconf.h
+
+minigzip.obj: minigzip.c zlib.h zconf.h
 
-# we must cut the command line to fit in the MS/DOS 128 byte limit:
+
+# the command line is cut to fit in the MS-DOS 128 byte limit:
 $(ZLIB_LIB): $(OBJ1) $(OBJ2)
-       del $(ZLIB_LIB)
-       $(AR) $(ZLIB_LIB) +$(OBJP1)
-       $(AR) $(ZLIB_LIB) +$(OBJP2)
+       -del $(ZLIB_LIB)
+       $(AR) $(ZLIB_LIB) $(OBJP1)
+       $(AR) $(ZLIB_LIB) $(OBJP2)
 
 example.exe: example.obj $(ZLIB_LIB)
        $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
@@ -118,8 +99,11 @@ minigzip.exe: minigzip.obj $(ZLIB_LIB)
 
 test: example.exe minigzip.exe
        example
-       echo hello world | minigzip | minigzip -d 
-
-#clean:
-#      del *.obj
-#      del *.exe
+       echo hello world | minigzip | minigzip -d
+
+clean:
+       -del *.obj
+       -del *.exe
+       -del *.lib
+       -del zlib_$(MODEL).bak
+       -del foo.gz
index 63e0550..d0a7864 100644 (file)
@@ -1,8 +1,9 @@
 # Makefile for zlib
-# TurboC 2.0
+# Turbo C 2.01, Turbo C++ 1.01
+# Updated for zlib-1.2.x by Cosmin Truta, 15-Mar-2003.
 
 # To use, do "make -fmakefile.tc"
-# To compile in small model, set below: MODEL=-ms
+# To compile in small model, set below: MODEL=s
 
 # WARNING: the small model is supported but only for small values of
 # MAX_WBITS and MAX_MEM_LEVEL. For example:
 #   -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
 # See zconf.h for details about the memory requirements.
 
-# ------------- Turbo C 2.0 -------------
+# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------
 MODEL=l
+CC=tcc
+LD=tcc
+AR=tlib
 # CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
 CFLAGS=-O2 -G -Z -m$(MODEL)
-CC=tcc -I\tc\include
-LD=tcc -L\tc\lib
-AR=tlib
 LDFLAGS=-m$(MODEL) -f-
-O=.obj
 
-# variables
-OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
-  trees$(O)
-OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\
-  trees$(O)
-OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \
-  infutil$(O) inffast$(O)
-OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\
-  infutil$(O)+inffast$(O)
-
-ZLIB_H = zlib.h zconf.h
-ZUTIL_H = zutil.h $(ZLIB_H)
 
+# variables
 ZLIB_LIB = zlib_$(MODEL).lib
 
-all: test
+OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
+OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
+OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
+OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
 
-adler32.obj: adler32.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
 
-compress.obj: compress.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+# targets
+all: $(ZLIB_LIB) example.exe minigzip.exe
 
-crc32.obj: crc32.c $(ZLIB_H)
+.c.obj:
        $(CC) -c $(CFLAGS) $*.c
 
-deflate.obj: deflate.c deflate.h $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+adler32.obj: adler32.c zlib.h zconf.h
 
-gzio.obj: gzio.c $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+compress.obj: compress.c zlib.h zconf.h
 
-infblock.obj: infblock.c $(ZUTIL_H) infblock.h inftrees.h infcodes.h infutil.h
-       $(CC) -c $(CFLAGS) $*.c
+crc32.obj: crc32.c zlib.h zconf.h crc32.h
 
-infcodes.obj: infcodes.c $(ZUTIL_H) inftrees.h infutil.h infcodes.h inffast.h
-       $(CC) -c $(CFLAGS) $*.c
+deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
 
-inflate.obj: inflate.c $(ZUTIL_H) infblock.h
-       $(CC) -c $(CFLAGS) $*.c
+gzio.obj: gzio.c zutil.h zlib.h zconf.h
 
-inftrees.obj: inftrees.c $(ZUTIL_H) inftrees.h
-       $(CC) -c $(CFLAGS) $*.c
+infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
 
-infutil.obj: infutil.c $(ZUTIL_H) inftrees.h infutil.h
-       $(CC) -c $(CFLAGS) $*.c
+inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h
 
-inffast.obj: inffast.c $(ZUTIL_H) inftrees.h infutil.h inffast.h
-       $(CC) -c $(CFLAGS) $*.c
+inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
 
-trees.obj: trees.c deflate.h $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
 
-uncompr.obj: uncompr.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
 
-zutil.obj: zutil.c $(ZUTIL_H)
-       $(CC) -c $(CFLAGS) $*.c
+uncompr.obj: uncompr.c zlib.h zconf.h
 
-example.obj: example.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+zutil.obj: zutil.c zutil.h zlib.h zconf.h
 
-minigzip.obj: minigzip.c $(ZLIB_H)
-       $(CC) -c $(CFLAGS) $*.c
+example.obj: example.c zlib.h zconf.h
+
+minigzip.obj: minigzip.c zlib.h zconf.h
 
-# we must cut the command line to fit in the MS/DOS 128 byte limit:
+
+# the command line is cut to fit in the MS-DOS 128 byte limit:
 $(ZLIB_LIB): $(OBJ1) $(OBJ2)
-       del $(ZLIB_LIB)
-       $(AR) $(ZLIB_LIB) +$(OBJP1)
-       $(AR) $(ZLIB_LIB) +$(OBJP2)
+       -del $(ZLIB_LIB)
+       $(AR) $(ZLIB_LIB) $(OBJP1)
+       $(AR) $(ZLIB_LIB) $(OBJP2)
 
 example.exe: example.obj $(ZLIB_LIB)
-       $(LD) $(LDFLAGS) -eexample.exe example.obj $(ZLIB_LIB)
+       $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
 
 minigzip.exe: minigzip.obj $(ZLIB_LIB)
-       $(LD) $(LDFLAGS) -eminigzip.exe minigzip.obj $(ZLIB_LIB)
+       $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
 
 test: example.exe minigzip.exe
        example
-       echo hello world | minigzip | minigzip -d 
-
-#clean:
-#      del *.obj
-#      del *.exe
+       echo hello world | minigzip | minigzip -d
+
+clean:
+       -del *.obj
+       -del *.exe
+       -del *.lib
+       -del zlib_$(MODEL).bak
+       -del foo.gz
similarity index 100%
rename from zlib/Make_vms.com
rename to zlib/old/Make_vms.com
diff --git a/zlib/old/README b/zlib/old/README
new file mode 100644 (file)
index 0000000..ea9cd22
--- /dev/null
@@ -0,0 +1,3 @@
+This directory contains files that have not been updated for zlib 1.2.0.
+
+(Volunteers are encouraged to help clean this up.  Thanks.)
similarity index 100%
rename from zlib/descrip.mms
rename to zlib/old/descrip.mms
similarity index 100%
rename from zlib/msdos/zlib.def
rename to zlib/old/msdos/zlib.def
similarity index 100%
rename from zlib/msdos/zlib.rc
rename to zlib/old/msdos/zlib.rc
similarity index 100%
rename from zlib/nt/Makefile.nt
rename to zlib/old/nt/Makefile.nt
similarity index 100%
rename from zlib/nt/zlib.dnt
rename to zlib/old/nt/zlib.dnt
similarity index 100%
rename from zlib/os2/zlib.def
rename to zlib/old/os2/zlib.def
similarity index 96%
rename from zlib/zlib.3
rename to zlib/old/zlib.3
index 25c8495..3a6e450 100644 (file)
@@ -1,4 +1,4 @@
-.TH ZLIB 3 "9 July 1998"
+.TH ZLIB 3 "11 March 2002"
 .SH NAME
 zlib \- compression/decompression library
 .SH SYNOPSIS
@@ -81,8 +81,8 @@ 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.3
-Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org)
+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,"
similarity index 100%
rename from zlib/zlib.html
rename to zlib/old/zlib.html
index 2c1430e..e220de6 100644 (file)
@@ -34,7 +34,7 @@
  *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
  */
 
-/* @(#) $Id: trees.c,v 1.9 2002/06/22 18:51:58 jbj Exp $ */
+/* @(#) $Id: trees.c,v 1.10 2003/03/08 23:18:09 jbj Exp $ */
 
 /* #define GEN_TREES_H */
 
@@ -270,7 +270,6 @@ local void send_bits(deflate_state * s, int value, int length)
 #endif /* DEBUG */
 
 
-#define MAX(a,b) (a >= b ? a : b)
 /* the arguments must not have side effects */
 
 /* ========================================================================= */
@@ -719,7 +718,8 @@ local void build_tree(deflate_state * s, tree_desc * desc)
 
         /* Create a new node father of n and m */
         tree[node].Freq = tree[n].Freq + tree[m].Freq;
-        s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
+        s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
+                                s->depth[n] : s->depth[m]) + 1);
         tree[n].Dad = tree[m].Dad = (ush)node;
 #ifdef DUMP_BL_TREE
         if (tree == s->bl_tree) {
index 54e3a63..75b1e6c 100644 (file)
@@ -1,9 +1,9 @@
 /* uncompr.c -- decompress a memory buffer
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
-/* @(#) $Id$ */
+/* @(#) $Id: uncompr.c,v 1.6 2002/03/17 15:46:23 jbj Exp $ */
 
 #include "zlib.h"
 
@@ -46,7 +46,9 @@ int ZEXPORT uncompress (Bytef * dest, uLongf * destLen, const Bytef * source,
     err = inflate(&stream, Z_FINISH);
     if (err != Z_STREAM_END) {
         inflateEnd(&stream);
-        return err == Z_OK ? Z_BUF_ERROR : err;
+        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+            return Z_DATA_ERROR;
+        return err;
     }
     *destLen = stream.total_out;
 
diff --git a/zlib/ung.c b/zlib/ung.c
deleted file mode 100644 (file)
index 961bfe7..0000000
+++ /dev/null
@@ -1,366 +0,0 @@
-/* ung.c -- simple gunzip to give an example of the use if inflateBack()
- * Copyright (C) 2003 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
-   ung [ -t ] [ name ... ]
-
-   decompresses the data in the named gzip files.  If no arguments are given,
-   ung will decompress from stdin to stdout.  The names must end in .gz, -gz,
-   .z, -z, _z, or .Z.  The uncompressed data will be written to a file name
-   with the suffix stripped.  On success, the original file is deleted.  On
-   failure, the output file is deleted.  For most failures, the command will
-   continue to process the remaining names on the command line.  A memory
-   allocation failure will abort the command.  It -t is specified, then the
-   listed files or stdin will be tested as gzip files for integrity (without
-   checking for a proper suffix), no output will be written, and no files
-   will be deleted.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include "zlib.h"
-
-#define local static
-
-#define INSIZE 32768U
-#define PIECE 16384    /* limits i/o chunks for 16-bit int case */
-
-struct io {
-    int infile;
-    unsigned char *inbuf;
-    int outfile;
-    unsigned long crc;
-    unsigned long total;
-};
-
-local unsigned char *in(void *opaque, unsigned *len)
-{
-    int ret;
-    unsigned char *next;
-    struct io *this = opaque;
-
-    next = this->inbuf;
-    *len = 0;
-    do {
-        ret = PIECE;
-        if ((unsigned)ret > INSIZE - *len) ret = (int)(INSIZE - *len);
-        ret = (int)read(this->infile, next, ret);
-        if (ret == -1) {
-            *len = 0;
-            return Z_NULL;
-        }
-        next += ret;
-        *len += ret;
-    } while (ret != 0 && *len < INSIZE);
-    return this->inbuf;
-}
-
-local int out(void *opaque, unsigned char *buf, unsigned len)
-{
-    int ret;
-    struct io *this = opaque;
-
-    this->crc = crc32(this->crc, buf, len);
-    this->total += len;
-    if (this->outfile != -1)
-        do {
-            ret = PIECE;
-            if ((unsigned)ret > len) ret = (int)len;
-            ret = (int)write(this->outfile, buf, ret);
-            if (ret == -1) return 1;
-            buf += ret;
-            len -= ret;
-        } while (len != 0);
-    return 0;
-}
-
-local int gunpipe(z_stream *strm, int infile, int outfile)
-{
-    int ret;
-    unsigned have, flags, len;
-    unsigned char *next, *window;
-    void *opaque;
-    struct io io;
-
-    /* clear allocations */
-    io.inbuf = NULL;
-    window = NULL;
-    do {
-
-        /* setup input */
-        io.infile = infile;
-        io.inbuf = malloc(INSIZE);
-        if (io.inbuf == NULL) {
-            ret = Z_MEM_ERROR;
-            break;
-        }
-        opaque = (void *)(&io);
-        next = in(opaque, &have);
-
-        /* check and skip gzip header */
-        ret = Z_BUF_ERROR;
-        if (have < 10) break;
-        have -= 10;
-        if (*next++ != 31 || *next++ != 139) {
-            strm->msg = "incorrect header check";
-            ret = Z_DATA_ERROR;
-            break;
-        }
-        if (*next++ != 8) {
-            strm->msg = "unknown compression method";
-            ret = Z_DATA_ERROR;
-            break;
-        }
-        flags = *next++;
-        next += 6;
-        if (flags & 0xe0) {
-            strm->msg = "unknown header flags set";
-            ret = Z_DATA_ERROR;
-            break;
-        }
-        if (flags & 4) {
-            if (have < 2) break;
-            have -= 2;
-            len = *next++;
-            len += *next++ << 8;
-            while (have < len) {
-                len -= have;
-                next = in(opaque, &have);
-                if (have == 0) break;
-            }
-            have -= len;
-            next += len;
-        }
-        if (flags & 8)
-            do {
-                if (have == 0) {
-                    next = in(opaque, &have);
-                    if (have == 0) break;
-                }
-                have--;
-            } while (*next++ != 0);
-        if (flags & 16)
-            do {
-                if (have == 0) {
-                    next = in(opaque, &have);
-                    if (have == 0) break;
-                }
-                have--;
-            } while (*next++ != 0);
-        if (flags & 2) {
-            len = 2;
-            if (have < len) {
-                len -= have;
-                next = in(opaque, &have);
-                if (have == 0) break;
-            }
-            have -= len;
-            next += len;
-        }
-
-        /* set up output */
-        io.outfile = outfile;
-        io.crc = crc32(0L, Z_NULL, 0);
-        io.total = 0;
-
-        /* do inflate */
-        strm->next_in = next;
-        strm->avail_in = have;
-        ret = inflateBack(strm, in, out, opaque);
-        if (ret != Z_STREAM_END) break;
-        next = strm->next_in;
-        have = strm->avail_in;
-
-        /* check trailer */
-        ret = Z_BUF_ERROR;
-        for (len = 0; len < 32; len += 8) {
-            if (have == 0) {
-                next = in(opaque, &have);
-                if (have == 0) break;
-            }
-            have--;
-            if (*next++ != (unsigned char)((io.crc >> len) & 0xff)) {
-                strm->msg = "incorrect data check";
-                ret = Z_DATA_ERROR;
-                break;
-            }
-            ret = Z_OK;
-        }
-        if (ret != Z_OK) break;
-        ret = Z_BUF_ERROR;
-        for (len = 0; len < 32; len += 8) {
-            if (have == 0) {
-                next = in(opaque, &have);
-                if (have == 0) break;
-            }
-            have--;
-            if (*next++ != (unsigned char)((io.total >> len) & 0xff)) {
-                strm->msg = "incorrect length check";
-                ret = Z_DATA_ERROR;
-                break;
-            }
-            ret = Z_OK;
-        }
-        if (ret != Z_OK) break;
-        if (have == 0) next = in(opaque, &have);
-        if (have != 0) ret = Z_ERRNO;
-
-    /* done */
-    } while (0);
-    if (window != NULL) free(window);
-    if (io.inbuf != NULL) free(io.inbuf);
-    return ret;
-}
-
-local int gunzip(z_stream *strm, char *inname, char *outname, int test)
-{
-    int ret;
-    int infile, outfile;
-
-    /* open files */
-    if (inname == NULL || *inname == 0) {
-        inname = "-";
-        infile = 0;    /* stdin */
-    }
-    else {
-        infile = open(inname, O_RDONLY, 0);
-        if (infile == -1) {
-            fprintf(stderr, "ung cannot open %s\n", inname);
-            return 0;
-        }
-    }
-    if (test)
-        outfile = -1;
-    else if (outname == NULL || *outname == 0) {
-        outname = "-";
-        outfile = 1;   /* stdout */
-    }
-    else {
-        outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666);
-        if (outfile == -1) {
-            close(infile);
-            fprintf(stderr, "ung cannot create %s\n", outname);
-            return 0;
-        }
-    }
-    errno = 0;
-
-    /* decompress */
-    ret = gunpipe(strm, infile, outfile);
-    if (outfile > 2) close(outfile);
-    if (infile > 2) close(infile);
-
-    /* interpret result */
-    switch (ret) {
-    case Z_OK:
-        if (infile > 2 && outfile > 2) unlink(inname);
-        return 0;
-    case Z_ERRNO:
-        if (infile > 2 && outfile > 2) unlink(inname);
-        fprintf(stderr, "ung warning: trailing garbage ignored\n");
-        break;
-    case Z_DATA_ERROR:
-        if (outfile > 2) unlink(outname);
-        fprintf(stderr, "ung data error on %s: %s\n", inname, strm->msg);
-        break;
-    case Z_MEM_ERROR:
-        if (outfile > 2) unlink(outname);
-        fprintf(stderr, "ung out of memory error--aborting\n");
-        return 1;
-    case Z_BUF_ERROR:
-        if (outfile > 2) unlink(outname);
-        if (strm->next_in != Z_NULL) {
-            fprintf(stderr, "ung write error on %s: %s\n",
-                    outname, strerror(errno));
-        }
-        else if (errno) {
-            fprintf(stderr, "ung read error on %s: %s\n",
-                    inname, strerror(errno));
-        }
-        else {
-            fprintf(stderr, "ung unexpected end of file on %s\n",
-                    inname);
-        }
-        break;
-    default:
-        if (outfile > 2) unlink(outname);
-        fprintf(stderr, "ung internal error--aborting\n");
-        return 1;
-    }
-    return 0;
-}
-
-int main(int argc, char **argv)
-{
-    int ret, len, test;
-    char *outname;
-    unsigned char *window;
-    z_stream strm;
-
-    /* initialize inflateBack state for repeated use */
-    window = malloc(32768U);   /* alloc failure caught by init */
-    strm.zalloc = Z_NULL;
-    strm.zfree = Z_NULL;
-    strm.opaque = Z_NULL;
-    ret = inflateBackInit(&strm, 15, window);
-    if (ret != Z_OK) {
-        if (window != NULL) free(window);
-        fprintf(stderr, "ung out of memory error--aborting\n");
-        return 1;
-    }
-
-    /* decompress each file to the same name with the suffix removed */
-    argc--;
-    argv++;
-    test = 0;
-    if (argc && strcmp(*argv, "-t") == 0) {
-        test = 1;
-        argc--;
-        argv++;
-    }
-    if (argc)
-        do {
-            if (test)
-                outname = NULL;
-            else {
-                len = (int)strlen(*argv);
-                if (strcmp(*argv + len - 3, ".gz") == 0 ||
-                    strcmp(*argv + len - 3, "-gz") == 0)
-                    len -= 3;
-                else if (strcmp(*argv + len - 2, ".z") == 0 ||
-                    strcmp(*argv + len - 2, "-z") == 0 ||
-                    strcmp(*argv + len - 2, "_z") == 0 ||
-                    strcmp(*argv + len - 2, ".Z") == 0)
-                    len -= 2;
-                else {
-                    fprintf(stderr, "ung error: no gzip suffix on %s--skipping\n",
-                            *argv);
-                    continue;
-                }
-                outname = malloc(len + 1);
-                if (outname == NULL) {
-                    fprintf(stderr, "ung out of memory error--aborting\n");
-                    ret = 1;
-                    break;
-                }
-                memcpy(outname, *argv, len);
-                outname[len] = 0;
-            }
-            ret = gunzip(&strm, *argv, outname, test);
-            if (outname != NULL) free(outname);
-            if (ret) break;
-        } while (argv++, --argc);
-    else
-        ret = gunzip(&strm, NULL, NULL, test);
-
-    /* clean up */
-    inflateBackEnd(&strm);
-    free(window);
-    return ret;
-}
diff --git a/zlib/win32/Makefile-dll.msc b/zlib/win32/Makefile-dll.msc
new file mode 100644 (file)
index 0000000..516f4cf
--- /dev/null
@@ -0,0 +1,76 @@
+# Makefile for zlib.dll -- Microsoft (Visual) C.\r
+# Author: Cosmin Truta, 11-Mar-2003.\r
+#\r
+# Usage: nmake -f win32/Makefile-dll.msc\r
+\r
+CC = cl\r
+LD = cl\r
+CFLAGS = -nologo -MD -O2\r
+LDFLAGS = -nologo\r
+\r
+OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \\r
+       inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj\r
+\r
+# targets\r
+all: zlib.dll zlib.lib example.exe minigzip.exe\r
+\r
+zlib.lib: $(OBJS)\r
+       lib -out:$@ $(OBJS)\r
+\r
+zlib.dll: $(OBJS) win32/zlib.def\r
+       link -release -def:win32/zlib.def -dll -out:$@ $(OBJS)\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
+.c.obj:\r
+       $(CC) -c $(CFLAGS) $*.c\r
+\r
+adler32.obj: adler32.c zlib.h zconf.h\r
+\r
+compress.obj: compress.c zlib.h zconf.h\r
+\r
+crc32.obj: crc32.c zlib.h zconf.h crc32.h\r
+\r
+deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h\r
+\r
+gzio.obj: gzio.c zutil.h zlib.h zconf.h\r
+\r
+infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h inffixed.h\r
+\r
+inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h\r
+\r
+inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h inffixed.h\r
+\r
+inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h\r
+\r
+trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h\r
+\r
+uncompr.obj: uncompr.c zlib.h zconf.h\r
+\r
+zutil.obj: zutil.c zutil.h zlib.h zconf.h\r
+\r
+example.obj: example.c zlib.h zconf.h\r
+\r
+minigzip.obj: minigzip.c zlib.h zconf.h\r
+\r
+# testing\r
+test: example.exe minigzip.exe\r
+       example\r
+       echo hello world | minigzip | minigzip -d \r
+\r
+# cleanup\r
+clean:\r
+       del *.obj\r
+       del *.dll\r
+       del *.lib\r
+       del *.exp\r
+       del *.exe\r
diff --git a/zlib/win32/Makefile.bor b/zlib/win32/Makefile.bor
new file mode 100644 (file)
index 0000000..f1a1c46
--- /dev/null
@@ -0,0 +1,91 @@
+# Makefile for zlib
+# Borland C++ for Win32
+# Updated for zlib-1.2.x by Cosmin Truta, 11-Mar-2003.
+
+# Usage: "make -f win32/makefile.bor"
+
+# ------------ Borland C++ for Win32 ------------
+
+#    Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
+#    should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
+#    to the declaration of LOC here:
+LOC = $(LOCAL_ZLIB)
+
+CC = bcc32
+LD = bcc32
+AR = tlib
+CFLAGS = -O2 -d -k- $(LOC)
+LDFLAGS = $(LOC)
+
+
+# variables
+ZLIB_LIB = zlib.lib
+
+OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
+OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
+OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
+OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
+
+
+# targets
+all: $(ZLIB_LIB) example.exe minigzip.exe
+
+.c.obj:
+       $(CC) -c $(CFLAGS) $*.c
+
+adler32.obj: adler32.c zlib.h zconf.h
+
+compress.obj: compress.c zlib.h zconf.h
+
+crc32.obj: crc32.c zlib.h zconf.h crc32.h
+
+deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
+
+gzio.obj: gzio.c zutil.h zlib.h zconf.h
+
+infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
+
+inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h
+
+inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
+ inffast.h inffixed.h
+
+inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
+
+trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
+
+uncompr.obj: uncompr.c zlib.h zconf.h
+
+zutil.obj: zutil.c zutil.h zlib.h zconf.h
+
+example.obj: example.c zlib.h zconf.h
+
+minigzip.obj: minigzip.c zlib.h zconf.h
+
+
+# For the sake of the old Borland make,
+# the command line is cut to fit in the MS-DOS 128 byte limit:
+$(ZLIB_LIB): $(OBJ1) $(OBJ2)
+       -del $(ZLIB_LIB)
+       $(AR) $(ZLIB_LIB) $(OBJP1)
+       $(AR) $(ZLIB_LIB) $(OBJP2)
+
+example.exe: example.obj $(ZLIB_LIB)
+       $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
+
+minigzip.exe: minigzip.obj $(ZLIB_LIB)
+       $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
+
+test: example.exe minigzip.exe
+       example
+       echo hello world | minigzip | minigzip -d 
+
+clean:
+       -del *.obj
+       -del *.exe
+       -del *.lib
+       -del *.tds
+       -del zlib.bak
+       -del foo.gz
diff --git a/zlib/win32/Makefile.gcc b/zlib/win32/Makefile.gcc
new file mode 100644 (file)
index 0000000..7f9973b
--- /dev/null
@@ -0,0 +1,105 @@
+# Makefile for zlib, derived from Makefile.dj2.
+# Modified for mingw32 by C. Spieler, 6/16/98.
+# Updated for zlib-1.2.x by Cosmin Truta, 11-Mar-2003.
+# Tested under Cygwin and MinGW.
+
+# Copyright (C) 1995-1998 Jean-loup Gailly.
+# For conditions of distribution and use, see copyright notice in zlib.h 
+
+# To compile, or to compile and test, type:
+# 
+#   make -fmakefile.gcc;  make test -fmakefile.gcc
+# 
+# To install libz.a, zconf.h and zlib.h in the system directories, type:
+# 
+#    make install -fmakefile.gcc
+# 
+
+LIB = libz.a
+SHAREDLIB = libz.so
+VER = 1.2.0
+
+CC = gcc
+#CFLAGS = -DDEBUG -MMD -g
+CFLAGS = $(LOC) -O3 -Wall
+
+AS = $(CC)
+ASFLAGS = $(LOC) -Wall
+
+LD = $(CC)
+LDFLAGS = $(LOC) -s
+
+AR = ar
+ARFLAGS = rcs
+
+CP = cp -fp
+# If GNU install is available, replace $(CP) with install.
+INSTALL = $(CP)
+RM = rm -f
+
+prefix = /usr/local
+exec_prefix = $(prefix)
+
+OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
+       inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
+
+# to use the asm code: make OBJA=match.o
+OBJA =
+
+TEST_OBJS = example.o minigzip.o
+
+all: $(LIB) example minigzip
+
+test: all
+       ./example
+       echo hello world | ./minigzip | ./minigzip -d 
+
+.c.o:
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+libz.a: $(OBJS)
+       $(AR) $(ARFLAGS) $@ $(OBJS)
+
+example: example.o $(LIB)
+       $(LD) -o $@ $< $(LIB)
+
+minigzip: minigzip.o $(LIB)
+       $(LD) -o $@ $< $(LIB)
+
+
+# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env .
+
+.PHONY : uninstall clean
+
+install: zlib.h zconf.h $(LIB)
+       -@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH)
+       -@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH)
+       $(INSTALL) zlib.h $(INCLUDE_PATH)
+       $(INSTALL) zconf.h $(INCLUDE_PATH)
+       $(INSTALL) $(LIB) $(LIBRARY_PATH)
+
+uninstall:
+       $(RM) $(INCLUDE_PATH)/zlib.h
+       $(RM) $(INCLUDE_PATH)/zconf.h
+       $(RM) $(LIBRARY_PATH)/libz.a
+
+clean:
+       $(RM) *.o
+       $(RM) *.exe
+       $(RM) libz.a
+       $(RM) foo.gz
+
+adler32.o: zlib.h zconf.h
+compress.o: zlib.h zconf.h
+crc32.o: crc32.h zlib.h zconf.h
+deflate.o: deflate.h zutil.h zlib.h zconf.h
+example.o: zlib.h zconf.h
+gzio.o: zutil.h zlib.h zconf.h
+inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
+inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
+infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
+inftrees.o: zutil.h zlib.h zconf.h inftrees.h
+minigzip.o:  zlib.h zconf.h 
+trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
+uncompr.o: zlib.h zconf.h
+zutil.o: zutil.h zlib.h zconf.h  
diff --git a/zlib/win32/Makefile.msc b/zlib/win32/Makefile.msc
new file mode 100644 (file)
index 0000000..9760208
--- /dev/null
@@ -0,0 +1,69 @@
+# Makefile for (static) zlib -- Microsoft (Visual) C.\r
+# Author: Cosmin Truta, 11-Mar-2003.\r
+#\r
+# Usage: nmake -f win32/Makefile.msc\r
+\r
+CC = cl\r
+LD = cl\r
+CFLAGS = -nologo -MD -O2\r
+LDFLAGS = -nologo\r
+\r
+OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \\r
+       inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj\r
+\r
+# targets\r
+all: zlib.lib example.exe minigzip.exe\r
+\r
+zlib.lib: $(OBJS)\r
+       lib -out:$@ $(OBJS)\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
+.c.obj:\r
+       $(CC) -c $(CFLAGS) $*.c\r
+\r
+adler32.obj: adler32.c zlib.h zconf.h\r
+\r
+compress.obj: compress.c zlib.h zconf.h\r
+\r
+crc32.obj: crc32.c zlib.h zconf.h crc32.h\r
+\r
+deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h\r
+\r
+gzio.obj: gzio.c zutil.h zlib.h zconf.h\r
+\r
+infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h inffixed.h\r
+\r
+inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h\r
+\r
+inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \\r
+             inffast.h inffixed.h\r
+\r
+inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h\r
+\r
+trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h\r
+\r
+uncompr.obj: uncompr.c zlib.h zconf.h\r
+\r
+zutil.obj: zutil.c zutil.h zlib.h zconf.h\r
+\r
+example.obj: example.c zlib.h zconf.h\r
+\r
+minigzip.obj: minigzip.c zlib.h zconf.h\r
+\r
+# testing\r
+test: example.exe minigzip.exe\r
+       example\r
+       echo hello world | minigzip | minigzip -d \r
+\r
+# cleanup\r
+clean:\r
+       del *.obj\r
+       del *.lib\r
+       del *.exe\r
similarity index 66%
rename from zlib/contrib/minizip/zlibvc.def
rename to zlib/win32/zlib.def
index 7e9d60d..3b4b05a 100644 (file)
@@ -1,12 +1,5 @@
-LIBRARY                "zlib"
-
-DESCRIPTION    '"""zlib data compression library"""'
-
-
-VERSION                1.11
-
-
-HEAPSIZE       1048576,8192
+LIBRARY                zlib.dll
+DESCRIPTION    "zlib compression library for Windows"
 
 EXPORTS
     adler32                        @1
@@ -50,25 +43,7 @@ EXPORTS
     compress2                      @39
     gzputs                         @40
     gzgets                         @41
-
-       unzOpen                       @61
-       unzClose                      @62
-       unzGetGlobalInfo              @63
-       unzGetCurrentFileInfo         @64
-       unzGoToFirstFile              @65
-       unzGoToNextFile               @66
-       unzOpenCurrentFile            @67
-       unzReadCurrentFile            @68
-       unztell                       @70
-       unzeof                        @71
-       unzCloseCurrentFile           @72
-       unzGetGlobalComment           @73
-       unzStringFileNameCompare      @74
-       unzLocateFile                 @75
-       unzGetLocalExtrafield         @76
-
-       zipOpen                       @80
-       zipOpenNewFileInZip           @81
-       zipWriteInFileInZip           @82
-       zipCloseFileInZip             @83
-       zipClose                      @84
+; The following functions exist since zlib-1.2.0
+;   deflateBound                   @42
+;   compressBound                  @43
+; etc.
index 9d95980..d8928f4 100644 (file)
@@ -1,10 +1,10 @@
 /*@-constuse -typeuse@*/
 /* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
-/* @(#) $Id: zconf.h,v 1.8 2002/11/05 23:08:19 jbj Exp $ */
+/* @(#) $Id: zconf.h,v 1.9 2003/03/08 21:47:46 jbj Exp $ */
 
 #ifndef _ZCONF_H
 #define _ZCONF_H
@@ -25,6 +25,7 @@
 #  define deflateCopy  z_deflateCopy
 #  define deflateReset z_deflateReset
 #  define deflateParams        z_deflateParams
+#  define deflateBound z_deflateBound
 #  define inflateInit2_        z_inflateInit2_
 #  define inflateSetDictionary z_inflateSetDictionary
 #  define inflateSync  z_inflateSync
@@ -33,6 +34,7 @@
 #  define inflateReset z_inflateReset
 #  define compress     z_compress
 #  define compress2    z_compress2
+#  define compressBound        z_compressBound
 #  define uncompress   z_uncompress
 #  define adler32      z_adler32
 #  define crc32                z_crc32
 #  endif
 #endif
 
+#if defined __HOS_AIX__
+#  ifndef STDC
+#    define STDC
+#  endif
+#endif
+
 #ifndef STDC
 #  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-#    define const
+#    define const      /* note: need a more gentle solution here */
 #  endif
 #endif
 
 #endif
 
 /* Old Borland C incorrectly complains about missing returns: */
-#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
+#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
+#  define NEED_DUMMY_RETURN
+#endif
+#if defined(__TURBOC__) && !defined(__BORLANDC__)
 #  define NEED_DUMMY_RETURN
 #endif
 
 #  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)
+#  if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
+#    ifndef WINAPIV
 #    ifdef FAR
 #      undef FAR
 #    endif
 #    include <windows.h>
-#    define ZEXPORT  WINAPI
+#    endif
 #    ifdef WIN32
+#      define ZEXPORT  WINAPI
 #      define ZEXPORTVA  WINAPIV
 #    else
+#      define ZEXPORT  WINAPI _export
 #      define ZEXPORTVA  FAR _cdecl _export
 #    endif
 #  endif
 #    if (__BORLANDC__ >= 0x0500) && defined (WIN32)
 #      include <windows.h>
 #      define ZEXPORT __declspec(dllexport) WINAPI
-#      define ZEXPORTRVA __declspec(dllexport) WINAPIV
+#      define ZEXPORTVA __declspec(dllexport) WINAPIV
 #    else
 #      if defined (_Windows) && defined (__DLL__)
 #        define ZEXPORT _export
 #   define FAR
 #endif
 
-#if !defined(MACOS) && !defined(TARGET_OS_MAC)
+#if !defined(__MACTYPES__)
 typedef unsigned char  Byte;  /* 8 bits */
 #endif
 typedef unsigned int   uInt;  /* 16 bits or more */
@@ -230,9 +248,11 @@ typedef uInt  FAR uIntf;
 typedef uLong FAR uLongf;
 
 #ifdef STDC
+   typedef void const *voidpc;
    typedef void FAR *voidpf;
    typedef void     *voidp;
 #else
+   typedef Byte const *voidpc;
    typedef Byte FAR *voidpf;
    typedef Byte     *voidp;
 #endif
@@ -240,6 +260,9 @@ typedef uLong FAR uLongf;
 #ifdef HAVE_UNISTD_H
 #  include <sys/types.h> /* for off_t */
 #  include <unistd.h>    /* for SEEK_* and off_t */
+#  ifdef VMS
+#    include <unixio.h>   /* for off_t */
+#  endif
 #  define z_off_t  off_t
 #endif
 #ifndef SEEK_SET
@@ -256,11 +279,13 @@ typedef uLong FAR uLongf;
 #   pragma map(deflateInit_,"DEIN")
 #   pragma map(deflateInit2_,"DEIN2")
 #   pragma map(deflateEnd,"DEEND")
+#   pragma map(deflateBound,"DEBND")
 #   pragma map(inflateInit_,"ININ")
 #   pragma map(inflateInit2_,"ININ2")
 #   pragma map(inflateEnd,"INEND")
 #   pragma map(inflateSync,"INSY")
 #   pragma map(inflateSetDictionary,"INSEDI")
+#   pragma map(compressBound,"CMBND")
 #   pragma map(inflate_table,"INTABL")
 #   pragma map(inflate_fast,"INFA")
 #   pragma map(inflate_copyright,"INCOPY")
diff --git a/zlib/zconf.in.h b/zlib/zconf.in.h
new file mode 100644 (file)
index 0000000..f3c4430
--- /dev/null
@@ -0,0 +1,293 @@
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#ifndef _ZCONF_H
+#define _ZCONF_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ */
+#ifdef Z_PREFIX
+#  define deflateInit_  z_deflateInit_
+#  define deflate       z_deflate
+#  define deflateEnd    z_deflateEnd
+#  define inflateInit_  z_inflateInit_
+#  define inflate       z_inflate
+#  define inflateEnd    z_inflateEnd
+#  define deflateInit2_ z_deflateInit2_
+#  define deflateSetDictionary z_deflateSetDictionary
+#  define deflateCopy   z_deflateCopy
+#  define deflateReset  z_deflateReset
+#  define deflateParams z_deflateParams
+#  define deflateBound  z_deflateBound
+#  define inflateInit2_ z_inflateInit2_
+#  define inflateSetDictionary z_inflateSetDictionary
+#  define inflateSync   z_inflateSync
+#  define inflateSyncPoint z_inflateSyncPoint
+#  define inflateCopy   z_inflateCopy
+#  define inflateReset  z_inflateReset
+#  define compress      z_compress
+#  define compress2     z_compress2
+#  define compressBound z_compressBound
+#  define uncompress    z_uncompress
+#  define adler32       z_adler32
+#  define crc32         z_crc32
+#  define get_crc_table z_get_crc_table
+
+#  define Byte          z_Byte
+#  define uInt          z_uInt
+#  define uLong         z_uLong
+#  define Bytef         z_Bytef
+#  define charf         z_charf
+#  define intf          z_intf
+#  define uIntf         z_uIntf
+#  define uLongf        z_uLongf
+#  define voidpf        z_voidpf
+#  define voidp         z_voidp
+#endif
+
+#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
+#  define WIN32
+#endif
+#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
+#  ifndef __32BIT__
+#    define __32BIT__
+#  endif
+#endif
+#if defined(__MSDOS__) && !defined(MSDOS)
+#  define MSDOS
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#if defined(MSDOS) && !defined(__32BIT__)
+#  define MAXSEG_64K
+#endif
+#ifdef MSDOS
+#  define UNALIGNED_OK
+#endif
+
+#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)
+#  define STDC
+#endif
+#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
+#  ifndef STDC
+#    define STDC
+#  endif
+#endif
+
+#if defined __HOS_AIX__
+#  ifndef STDC
+#    define STDC
+#  endif
+#endif
+
+#ifndef STDC
+#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+#    define const       /* note: need a more gentle solution here */
+#  endif
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
+#  define NO_DUMMY_DECL
+#endif
+
+/* 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
+#    define MAX_MEM_LEVEL 8
+#  else
+#    define MAX_MEM_LEVEL 9
+#  endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+#  define MAX_WBITS   15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+            (1 << (windowBits+2)) +  (1 << (memLevel+9))
+ that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+   The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+                        /* Type declarations */
+
+#ifndef OF /* function prototypes */
+#  ifdef STDC
+#    define OF(args)  args
+#  else
+#    define OF(args)  ()
+#  endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
+   /* MSC small or medium model */
+#  define SMALL_MEDIUM
+#  ifdef _MSC_VER
+#    define FAR _far
+#  else
+#    define FAR far
+#  endif
+#endif
+#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
+#  ifndef __32BIT__
+#    define SMALL_MEDIUM
+#    define FAR _far
+#  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
+#  endif
+#  if defined (__BORLANDC__)
+#    if (__BORLANDC__ >= 0x0500) && defined (WIN32)
+#      include <windows.h>
+#      define ZEXPORT __declspec(dllexport) WINAPI
+#      define ZEXPORTVA __declspec(dllexport) WINAPIV
+#    else
+#      if defined (_Windows) && defined (__DLL__)
+#        define ZEXPORT _export
+#        define ZEXPORTVA _export
+#      endif
+#    endif
+#  endif
+#endif
+
+#if defined (__BEOS__)
+#  if defined (ZLIB_DLL)
+#    define ZEXTERN extern __declspec(dllexport)
+#  else
+#    define ZEXTERN extern __declspec(dllimport)
+#  endif
+#endif
+
+#ifndef ZEXPORT
+#  define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+#  define ZEXPORTVA
+#endif
+#ifndef ZEXTERN
+#  define ZEXTERN extern
+#endif
+
+#ifndef FAR
+#   define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char  Byte;  /* 8 bits */
+#endif
+typedef unsigned int   uInt;  /* 16 bits or more */
+typedef unsigned long  uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+#  define Bytef Byte FAR
+#else
+   typedef Byte  FAR Bytef;
+#endif
+typedef char  FAR charf;
+typedef int   FAR intf;
+typedef uInt  FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+   typedef void const *voidpc;
+   typedef void FAR *voidpf;
+   typedef void     *voidp;
+#else
+   typedef Byte const *voidpc;
+   typedef Byte FAR *voidpf;
+   typedef Byte     *voidp;
+#endif
+
+#if 0           /* HAVE_UNISTD_H -- this line is updated by ./configure */
+#  include <sys/types.h> /* for off_t */
+#  include <unistd.h>    /* for SEEK_* and off_t */
+#  ifdef VMS
+#    include <unixio.h>   /* for off_t */
+#  endif
+#  define z_off_t  off_t
+#endif
+#ifndef SEEK_SET
+#  define SEEK_SET        0       /* Seek from beginning of file.  */
+#  define SEEK_CUR        1       /* Seek from current position.  */
+#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
+#endif
+#ifndef z_off_t
+#  define  z_off_t long
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+#   pragma map(deflateInit_,"DEIN")
+#   pragma map(deflateInit2_,"DEIN2")
+#   pragma map(deflateEnd,"DEEND")
+#   pragma map(deflateBound,"DEBND")
+#   pragma map(inflateInit_,"ININ")
+#   pragma map(inflateInit2_,"ININ2")
+#   pragma map(inflateEnd,"INEND")
+#   pragma map(inflateSync,"INSY")
+#   pragma map(inflateSetDictionary,"INSEDI")
+#   pragma map(compressBound,"CMBND")
+#   pragma map(inflate_table,"INTABL")
+#   pragma map(inflate_fast,"INFA")
+#   pragma map(inflate_copyright,"INCOPY")
+#endif
+
+#endif /* _ZCONF_H */
index c233fac..4e46732 100644 (file)
@@ -1,8 +1,8 @@
 /*@-declundef -fcnuse -noparams -typeuse @*/
 /* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.1.4, March 11th, 2002
+  version 1.2.0.1, March 17th, 2003
 
-  Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
+  Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -25,7 +25,7 @@
 
 
   The data format used by the zlib library is described by RFCs (Request for
-  Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
+  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
 */
 
 extern "C" {
 #endif
 
-#define ZLIB_VERSION "1.1.4"
+/*
+ * Modified (as little as possible) to accomplish:
+ *     - adding splint/doxygen annotations.
+ * Bug reports at http://bugzilla.redhat.com, sez' Jeff Johnson jbj@redhat.com
+ */
+#define ZLIB_VERSION "1.2.0.1-rpm"
 
 /* 
      The 'zlib' compression library provides in-memory compression and
@@ -53,8 +58,23 @@ extern "C" {
   application must provide more input and/or consume the output
   (providing more output space) before each call.
 
+     The compressed data format used by the in-memory functions is the zlib
+  format, which is a zlib wrapper documented in RFC 1950, wrapped around a
+  deflate stream, which is itself documented in RFC 1951.
+
      The library also supports reading and writing files in gzip (.gz) format
-  with an interface similar to that of stdio.
+  with an interface similar to that of stdio using the functions that start
+  with "gz".  The gzip format is different from the zlib format.  gzip is a
+  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+
+     The zlib format was designed to be compact and fast for use in memory
+  and on communications channels.  The gzip format was designed for single-
+  file compression on file systems, has a larger header than zlib to maintain
+  directory information, and uses a different, slower check method than zlib.
+
+     This library does not provide any functions to write gzip files in memory.
+  However such functions could be easily written using zlib's deflate function,
+  the documentation in the gzip RFC, and the examples in gzio.c.
 
      The library does not install any signal handler. The decoder checks
   the consistency of the compressed data, so the library should never
@@ -160,6 +180,7 @@ typedef /*@abstract@*/ z_stream FAR *z_streamp;
 
 #define Z_FILTERED            1
 #define Z_HUFFMAN_ONLY        2
+#define Z_RLE                 3
 #define Z_DEFAULT_STRATEGY    0
 /* compression strategy; see deflateInit2() below for details */
 
@@ -256,7 +277,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush))
     If deflate returns with avail_out == 0, this function must be called again
   with the same value of the flush parameter and more output space (updated
   avail_out), until the flush is complete (deflate returns with non-zero
-  avail_out).
+  avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
+  avail_out is greater than six to avoid repeated flush markers due to
+  avail_out == 0 on return.
 
     If the parameter flush is set to Z_FINISH, pending input is processed,
   pending output is flushed and deflate returns with Z_STREAM_END if there
@@ -268,7 +291,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush))
   
     Z_FINISH can be used immediately after deflateInit if all the compression
   is to be done in a single step. In this case, avail_out must be at least
-  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
+  the value returned by deflateBound (see below). If deflate does not return
   Z_STREAM_END, then it must be called again as described above.
 
     deflate() sets strm->adler to the adler32 checksum of all input read
@@ -284,7 +307,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush))
   consumed and all output has been produced (only when flush is set to
   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
   if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
-  (for example avail_in or avail_out was zero).
+  (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
+  fatal, and deflate() can be called again with more input and more output
+  space to continue compressing.
 */
 
 
@@ -354,11 +379,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush))
   must be called again after making room in the output buffer because there
   might be more output pending.
 
-    If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
-  output as possible to the output buffer. The flushing behavior of inflate is
-  not specified for values of the flush parameter other than Z_SYNC_FLUSH
-  and Z_FINISH, but the current implementation actually flushes as much output
-  as possible anyway.
+    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, or
+  Z_FINISH. Z_SYNC_FLUSH requests that inflate() flush as much output as
+  possible to the output buffer.
 
     inflate() should normally be called until it returns Z_STREAM_END or an
   error. However if all decompression is to be performed in a single step
@@ -368,29 +391,43 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush))
   uncompressed data. (The size of the uncompressed data may have been saved
   by the compressor for this purpose.) The next operation on this stream must
   be inflateEnd to deallocate the decompression state. The use of Z_FINISH
-  is never required, but can be used to inform inflate that a faster routine
+  is never required, but can be used to inform inflate that a faster approach
   may be used for the single inflate() call.
 
-     If a preset dictionary is needed at this point (see inflateSetDictionary
-  below), inflate sets strm-adler to the adler32 checksum of the
-  dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 
-  it sets strm->adler to the adler32 checksum of all output produced
-  so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
-  an error code as described below. At the end of the stream, inflate()
-  checks that its computed adler32 checksum is equal to that saved by the
-  compressor and returns Z_STREAM_END only if the checksum is correct.
+     In this implementation, inflate() always flushes as much output as
+  possible to the output buffer, and always uses the faster approach on the
+  first call. So the only effect of the flush parameter in this implementation
+  is on the return value of inflate(), as noted below.
+
+     If a preset dictionary is needed after this call (see inflateSetDictionary
+  below), inflate sets strm-adler to the adler32 checksum of the dictionary
+  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+  strm->adler to the adler32 checksum of all output produced so far (that is,
+  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
+  below. At the end of the stream, inflate() checks that its computed adler32
+  checksum is equal to that saved by the compressor and returns Z_STREAM_END
+  only if the checksum is correct.
+
+    inflate() will decompress and check either zlib-wrapped or gzip-wrapped
+  deflate data.  The header type is detected automatically.  Any information
+  contained in the gzip header is not retained, so applications that need that
+  information should instead use raw inflate, see inflateInit2() below, or
+  inflateBack() and perform their own processing of the gzip header and
+  trailer.
 
     inflate() returns Z_OK if some progress has been made (more input processed
   or more output produced), Z_STREAM_END if the end of the compressed data has
   been reached and all uncompressed output has been produced, Z_NEED_DICT if a
   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
-  corrupted (input stream not conforming to the zlib format or incorrect
-  adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
-  (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
-  enough memory, Z_BUF_ERROR if no progress is possible or if there was not
-  enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
-  case, the application may then call inflateSync to look for a good
-  compression block.
+  corrupted (input stream not conforming to the zlib format or incorrect check
+  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
+  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
+  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+  inflate() can be called again with more input and more output space to
+  continue decompressing. If Z_DATA_ERROR is returned, the application may then
+  call inflateSync() to look for a good compression block if a partial recovery
+  of the data is desired.
 */
 
 
@@ -433,6 +470,10 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
    compression at the expense of memory usage. The default value is 15 if
    deflateInit is used instead.
 
+     windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits
+   determines the window size. deflate() will then generate raw deflate data
+   with no zlib header or trailer, and will not compute an adler32 check value.
+
      The memLevel parameter specifies how much memory should be allocated
    for the internal compression state. memLevel=1 uses minimum memory but
    is slow and reduces compression ratio; memLevel=9 uses maximum memory
@@ -441,14 +482,16 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
 
      The strategy parameter is used to tune the compression algorithm. Use the
    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
-   filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
-   string match).  Filtered data consists mostly of small values with a
-   somewhat random distribution. In this case, the compression algorithm is
-   tuned to compress them better. The effect of Z_FILTERED is to force more
-   Huffman coding and less string matching; it is somewhat intermediate
-   between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
-   the compression ratio but not the correctness of the compressed output even
-   if it is not set appropriately.
+   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+   string match), or Z_RLE to limit match distances to one (run-length
+   encoding). Filtered data consists mostly of small values with a somewhat
+   random distribution. In this case, the compression algorithm is tuned to
+   compress them better. The effect of Z_FILTERED is to force more Huffman
+   coding and less string matching; it is somewhat intermediate between
+   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
+   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
+   parameter only affects the compression ratio but not the correctness of the
+   compressed output even if it is not set appropriately.
 
       deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
@@ -480,11 +523,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
    deflate or deflate2. Thus the strings most likely to be useful should be
    put at the end of the dictionary, not at the front.
 
-     Upon return of this function, strm->adler is set to the Adler32 value
+     Upon return of this function, strm->adler is set to the adler32 value
    of the dictionary; the decompressor may later use this value to determine
-   which dictionary has been used by the compressor. (The Adler32 value
+   which dictionary has been used by the compressor. (The adler32 value
    applies to the whole dictionary even if only a subset of the dictionary is
-   actually used by the compressor.)
+   actually used by the compressor.) If a raw deflate was requested, then the
+   adler32 value is not computed and strm->adler is not set.
 
      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
    parameter is invalid (such as NULL dictionary) or the stream state is
@@ -547,6 +591,16 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
    if strm->avail_out was zero.
 */
 
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
+                                       uLong sourceLen))
+       /*@modifies strm @*/;
+/*
+     deflateBound() returns an upper bound on the compressed size after
+   deflation of sourceLen bytes.  It must be called after deflateInit()
+   or deflateInit2().  This would be used to allocate an output buffer
+   for deflation in a single pass, and so would be called before deflate().
+*/
+
 /*   
 ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
                                      int  windowBits));
@@ -562,6 +616,17 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
    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
+   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
+   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.
+
       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
    memLevel). msg is set to null if there is no error message.  inflateInit2
@@ -578,37 +643,20 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
      Initializes the decompression dictionary from the given uncompressed byte
    sequence. This function must be called immediately after a call of inflate
    if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
-   can be determined from the Adler32 value returned by this call of
+   can be determined from the adler32 value returned by this call of
    inflate. The compressor and decompressor must use exactly the same
    dictionary (see deflateSetDictionary).
 
      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
    parameter is invalid (such as NULL dictionary) or the stream state is
    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
-   expected one (incorrect Adler32 value). inflateSetDictionary does not
+   expected one (incorrect adler32 value). inflateSetDictionary does not
    perform any decompression: this will be done by subsequent calls of
    inflate().
 */
 
 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm))
        /*@modifies strm @*/;
-/*
-     Sets the destination stream as a complete copy of the source stream.
-
-     This function can be useful when randomly accessing a large stream.  The
-   first pass through the stream can periodically record the inflate state,
-   allowing restarting inflate at those points when randomly accessing the
-   stream.
-
-     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
-   (such as zalloc being NULL). msg is left unchanged in both source and
-   destination.
-*/
-
-ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
-                                     z_streamp source))
-       /*@modifies dest, source @*/;
 /* 
     Skips invalid compressed data until a full flush point (see above the
   description of deflate with Z_FULL_FLUSH) can be found, or until all
@@ -623,6 +671,23 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
   until success or end of the input data.
 */
 
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
+                                     z_streamp source))
+       /*@modifies dest, source @*/;
+/*
+     Sets the destination stream as a complete copy of the source stream.
+
+     This function can be useful when randomly accessing a large stream.  The
+   first pass through the stream can periodically record the inflate state,
+   allowing restarting inflate at those points when randomly accessing the
+   stream.
+
+     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+   (such as zalloc being NULL). msg is left unchanged in both source and
+   destination.
+*/
+
 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm))
        /*@modifies strm @*/;
 /*
@@ -638,15 +703,15 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm))
 ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
                                         unsigned char FAR *window));
 
-     Initializes the internal stream state for decompression using
-   inflateBack() calls.  The fields next_in, avail_in, zalloc, zfree and opaque
-   opaque in strm must be initialized before the call.  If zalloc and zfree are
-   Z_NULL, then the default library-derived memory allocation routines are
-   used.  windowBits is the base two logarithm of the window size, in the range
-   8..15.  window is a caller supplied buffer of that size.  Except for special
-   applications where it is assured that deflate was used with small window
-   sizes, windowBits must be 15 and a 32K byte window must be supplied to be
-   able to decompress general deflate streams.
+     Initialize the internal stream state for decompression using inflateBack()
+   calls.  The fields zalloc, zfree and opaque in strm must be initialized
+   before the call.  If zalloc and zfree are Z_NULL, then the default library-
+   derived memory allocation routines are used.  windowBits is the base two
+   logarithm of the window size, in the range 8..15.  window is a caller
+   supplied buffer of that size.  Except for special applications where it is
+   assured that deflate was used with small window sizes, windowBits must be 15
+   and a 32K byte window must be supplied to be able to decompress general
+   deflate streams.
 
      See inflateBack() for the usage of these routines.
 
@@ -656,13 +721,14 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
    match the version of the header file.
 */
 
-typedef unsigned char FAR *(*in_func) OF((void FAR *, unsigned FAR *))
+typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *))
        /*@*/;
 typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned))
        /*@*/;
 
-ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, in_func in,
-                                    out_func out, void FAR *opaque))
+ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
+                                    in_func in, void FAR *in_desc,
+                                    out_func out, void FAR *out_desc))
        /*@modifies strm @*/;
 /*
      inflateBack() does a raw inflate with a single call using a call-back
@@ -682,37 +748,39 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, in_func in,
    This routine would normally be used in a utility that reads zip or gzip
    files and writes out uncompressed files.  The utility would decode the
    header and process the trailer on its own, hence this routine expects
-   only the raw deflate stream to decompress.
+   only the raw deflate stream to decompress.  This is different from the
+   normal behavior of inflate(), which expects either a zlib or gzip header and
+   trailer around the deflate stream.
 
      inflateBack() uses two subroutines supplied by the caller that are then
    called by inflateBack() for input and output.  inflateBack() calls those
-   routines until it reads a complete deflate stream and writes out all of
-   the uncompressed data, or until it encounters an error.  The function's
+   routines until it reads a complete deflate stream and writes out all of the
+   uncompressed data, or until it encounters an error.  The function's
    parameters and return types are defined above in the in_func and out_func
-   typedefs.  inflateBack() will call in(opaque, &len) which should return a
-   pointer to some input, and return the number of bytes of provided input in
-   len.  If there is no input available, in() can return Z_NULL (len is
-   ignored in that case), or len == 0, and inflateBack() will return an error.
-   inflateBack() will call out(opaque, buf, len) to write the uncompressed
-   data buf[0..len-1].  out() should return zero on success, or non-zero on
-   failure.  If out() returns non-zero, inflateBack() will return with an
-   error.  Neither in() nor out() are permitted to change the contents of the
-   window provided to inflateBackInit(), which is also the buffer that out()
-   uses to write from.  The length written by out() will be at most the window
-   size.  Any non-zero amount of input may be provided by in().
+   typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
+   number of bytes of provided input, and a pointer to that input in buf.  If
+   there is no input available, in() must return zero--buf is ignored in that
+   case--and inflateBack() will return a buffer error.  inflateBack() will call
+   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
+   should return zero on success, or non-zero on failure.  If out() returns
+   non-zero, inflateBack() will return with an error.  Neither in() nor out()
+   are permitted to change the contents of the window provided to
+   inflateBackInit(), which is also the buffer that out() uses to write from.
+   The length written by out() will be at most the window size.  Any non-zero
+   amount of input may be provided by in().
 
      For convenience, inflateBack() can be provided input on the first call by
    setting strm->next_in and strm->avail_in.  If that input is exhausted, then
    in() will be called.  Therefore strm->next_in must be initialized before
    calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
    immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
-   must also be initialized, and then input will initially be taken from
-   strm->next_in[0 .. strm->avail_in - 1].
+   must also be initialized, and then if strm->avail_in is not zero, input will
+   initially be taken from strm->next_in[0 .. strm->avail_in - 1].
 
-     The opaque parameter of inflateBack() is passed as the first parameter of
-   both in() and out() when they are called.  opauqe can be used to pass any
-   information that the caller-supplied in() and out() functions need to do
-   their job.
+     The in_desc and out_desc parameters of inflateBack() is passed as the
+   first parameter of in() and out() respectively when they are called.  These
+   descriptors can be optinally used to pass any information that the caller-
+   supplied in() and out() functions need to do their job.
 
      On return, inflateBack() will set strm->next_in and strm->avail_in to
    pass back any unused input that was provided by the last in() call.  The
@@ -723,7 +791,9 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, in_func in,
    initialized.  In the case of Z_BUF_ERROR, an input or output error can be
    distinguished using strm->next_in which will be Z_NULL only if in() returned
    an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
-   out() returning non-zero.  Note that inflateBack() cannot return Z_OK.
+   out() returning non-zero.  (in() will always be called before out(), so
+   strm->next_in is assured to be defined if out() returns non-zero.)  Note
+   that inflateBack() cannot return Z_OK.
 */
 
 ZEXTERN int ZEXPORT inflateBackEnd(z_stream FAR *strm)
@@ -753,8 +823,8 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
 /*
      Compresses the source buffer into the destination buffer.  sourceLen is
    the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be at least 0.1% larger than
-   sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
+   size of the destination buffer, which must be at least the value returned
+   by compressBound(sourceLen). Upon exit, destLen is the actual size of the
    compressed buffer.
      This function can be used to compress a whole file at once if the
    input file is mmap'ed.
@@ -772,14 +842,23 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
      Compresses the source buffer into the destination buffer. The level
    parameter has the same meaning as in deflateInit.  sourceLen is the byte
    length of the source buffer. Upon entry, destLen is the total size of the
-   destination buffer, which must be at least 0.1% larger than sourceLen plus
-   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+   destination buffer, which must be at least the value returned by
+   compressBound(sourceLen). Upon exit, destLen is the actual size of the
+   compressed buffer.
 
      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    memory, Z_BUF_ERROR if there was not enough room in the output buffer,
    Z_STREAM_ERROR if the level parameter is invalid.
 */
 
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen))
+       /*@*/;
+/*
+     compressBound() returns an upper bound on the compressed size after
+   compress() or compress2() on sourceLen bytes.  It would be used before
+   a compress() or compress2() call to allocate the destination buffer.
+*/
+
 ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
                                    const Bytef *source, uLong sourceLen))
        /*@modifies *dest, *destLen @*/;
@@ -796,7 +875,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 
      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer, or Z_DATA_ERROR if the input data was corrupted.
+   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
 */
 
 
@@ -809,8 +888,9 @@ ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode))
      Opens a gzip (.gz) file for reading or writing. The mode parameter
    is as in fopen ("rb" or "wb") but can also include a compression level
    ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
-   Huffman only compression as in "wb1h". (See the description
-   of deflateInit2 for more information about the strategy parameter.)
+   Huffman only compression as in "wb1h", or 'R' for run-length encoding
+   as in "wb1R". (See the description of deflateInit2 for more information
+   about the strategy parameter.)
 
      gzopen can be used to read a file which is not in gzip format; in this
    case gzread will directly read from the file without decompression.
@@ -856,7 +936,7 @@ ZEXTERN int ZEXPORT    gzread  OF((gzFile file, /*@out@*/ voidp buf, unsigned le
    end of file, -1 for error). */
 
 ZEXTERN int ZEXPORT    gzwrite OF((gzFile file, 
-                                  const voidp buf, unsigned len))
+                                  voidpc buf, unsigned len))
        /*@globals fileSystem @*/
        /*@modifies file, fileSystem @*/;
 /*
@@ -871,7 +951,13 @@ ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...))
 /*
      Converts, formats, and writes the args to the compressed file under
    control of the format string, as in fprintf. gzprintf returns the number of
-   uncompressed bytes actually written (0 in case of error).
+   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()
+   because the secure snprintf() or vsnprintf() functions were not available.
 */
 
 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s))
index e55360a..004cf88 100644 (file)
@@ -1,9 +1,9 @@
 /* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h 
  */
 
-/* @(#) $Id$ */
+/* @(#) $Id: zutil.c,v 1.6 2002/03/17 15:46:23 jbj Exp $ */
 
 #include "zutil.h"
 
@@ -13,7 +13,7 @@ struct internal_state      {int dummy;}; /* for buggy compilers */
 extern void exit OF((int));
 #endif
 
-const char *z_errmsg[10] = {
+const char * const z_errmsg[10] = {
 "need dictionary",     /* Z_NEED_DICT       2  */
 "stream end",          /* Z_STREAM_END      1  */
 "",                    /* Z_OK              0  */
@@ -85,6 +85,7 @@ void zmemzero(Bytef * dest, uInt len)
 
 #ifdef __TURBOC__
 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
+#if !defined(__linux)
 /* Small and medium model in Turbo C are for now limited to near allocation
  * with reduced MAX_WBITS and MAX_MEM_LEVEL
  */
@@ -160,6 +161,7 @@ void  zcfree (voidpf opaque, voidpf ptr)
     Assert(0, "zcfree: ptr not found");
 }
 #endif
+#endif
 #endif /* __TURBOC__ */
 
 
@@ -191,6 +193,7 @@ void  zcfree (voidpf opaque, voidpf ptr)
 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
 
 #ifndef STDC
+extern voidp  malloc OF((uInt size));
 extern voidp  calloc OF((uInt items, uInt size));
 extern void   free   OF((voidpf ptr));
 #endif
index 0a6c0c9..f3f69f0 100644 (file)
@@ -1,5 +1,5 @@
 /* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -8,7 +8,7 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* @(#) $Id: zutil.h,v 1.8 2002/10/07 09:05:07 jbj Exp $ */
+/* @(#) $Id: zutil.h,v 1.9 2003/03/08 23:18:09 jbj Exp $ */
 
 #ifndef _Z_UTIL_H
 #define _Z_UTIL_H
@@ -38,7 +38,7 @@ typedef ush FAR ushf;
 typedef unsigned long  ulg;
 
 /*@unchecked@*/
-extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
+extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 /* (size given to avoid silly warnings with Visual C++) */
 
 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
@@ -151,6 +151,30 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
 
          /* functions */
 
+#ifdef __STDC_VERSION__
+#  if __STDC_VERSION__ >= 199901L
+#    ifndef STDC99
+#      define STDC99
+#    endif
+#  endif
+#endif
+#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED)
+#  ifdef MSDOS
+     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+        but for now we just assume it doesn't. */
+#    define NO_vsnprintf
+#  endif
+#  ifdef WIN32
+     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+#    if !defined(vsnprintf) && !defined(__TURBOC__)
+#      define vsnprintf _vsnprintf
+#    endif
+#  endif
+#  ifdef __TURBOC__
+#    define NO_vsnprintf
+#  endif
+#endif
+
 #ifdef HAVE_STRERROR
    extern char *strerror OF((int));
 #  define zstrerror(errnum) strerror(errnum)