zlib update
authorDavid Galeno <davidgaleano@turbulenz.biz>
Mon, 26 Sep 2011 16:33:45 +0000 (17:33 +0100)
committerAndy Green <andy@warmcat.com>
Mon, 26 Sep 2011 16:33:45 +0000 (17:33 +0100)
Signed-off-by: David Galeno <davidgaleano@turbulenz.biz>
21 files changed:
win32port/zlib/ZLib.vcxproj
win32port/zlib/ZLib.vcxproj.filters
win32port/zlib/adler32.c
win32port/zlib/compress.c
win32port/zlib/crc32.c
win32port/zlib/deflate.c
win32port/zlib/deflate.h
win32port/zlib/infback.c
win32port/zlib/inffast.c
win32port/zlib/inffast.h
win32port/zlib/inflate.c
win32port/zlib/inflate.h
win32port/zlib/inftrees.c
win32port/zlib/inftrees.h
win32port/zlib/trees.c
win32port/zlib/trees.h
win32port/zlib/uncompr.c
win32port/zlib/zconf.h
win32port/zlib/zlib.h
win32port/zlib/zutil.c
win32port/zlib/zutil.h

index 1792873..0afc43c 100644 (file)
     <ClCompile Include="compress.c" />\r
     <ClCompile Include="crc32.c" />\r
     <ClCompile Include="deflate.c" />\r
-    <ClCompile Include="gzio.c" />\r
+    <ClCompile Include="gzclose.c" />\r
+    <ClCompile Include="gzlib.c" />\r
+    <ClCompile Include="gzread.c" />\r
+    <ClCompile Include="gzwrite.c" />\r
+    <ClCompile Include="infback.c" />\r
     <ClCompile Include="inffast.c" />\r
     <ClCompile Include="inflate.c" />\r
     <ClCompile Include="inftrees.c" />\r
     <ClCompile Include="zutil.c" />\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <ClInclude Include="crc32.h" />\r
     <ClInclude Include="deflate.h" />\r
+    <ClInclude Include="gzguts.h" />\r
     <ClInclude Include="inffast.h" />\r
     <ClInclude Include="inffixed.h" />\r
+    <ClInclude Include="inflate.h" />\r
     <ClInclude Include="inftrees.h" />\r
     <ClInclude Include="trees.h" />\r
     <ClInclude Include="zconf.h" />\r
index ace4336..3e6c18d 100644 (file)
@@ -23,9 +23,6 @@
     <ClCompile Include="deflate.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="gzio.c">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="inffast.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
     <ClCompile Include="zutil.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="gzlib.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="gzread.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="gzwrite.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="gzclose.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="infback.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="deflate.h">\r
     <ClInclude Include="zutil.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="gzguts.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="inflate.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="crc32.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index dd6d60f..5f2bc6b 100644 (file)
@@ -1,23 +1,27 @@
 /* adler32.c -- compute the Adler-32 checksum of a data stream\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2007 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 /* @(#) $Id$ */\r
 \r
-#define ZLIB_INTERNAL\r
-#include "zlib.h"\r
+#include "zutil.h"\r
+\r
+#define local static\r
+\r
+local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);\r
 \r
 #define BASE 65521UL    /* largest prime smaller than 65536 */\r
 #define NMAX 5552\r
 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */\r
 \r
-#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}\r
+#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}\r
 #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);\r
 #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);\r
 #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);\r
 #define DO16(buf)   DO8(buf,0); DO8(buf,8);\r
 \r
+/* use NO_DIVIDE if your processor does not do division in hardware */\r
 #ifdef NO_DIVIDE\r
 #  define MOD(a) \\r
     do { \\r
         if (a >= (BASE << 1)) a -= (BASE << 1); \\r
         if (a >= BASE) a -= BASE; \\r
     } while (0)\r
+#  define MOD4(a) \\r
+    do { \\r
+        if (a >= (BASE << 4)) a -= (BASE << 4); \\r
+        if (a >= (BASE << 3)) a -= (BASE << 3); \\r
+        if (a >= (BASE << 2)) a -= (BASE << 2); \\r
+        if (a >= (BASE << 1)) a -= (BASE << 1); \\r
+        if (a >= BASE) a -= BASE; \\r
+    } while (0)\r
 #else\r
 #  define MOD(a) a %= BASE\r
+#  define MOD4(a) a %= BASE\r
 #endif\r
 \r
 /* ========================================================================= */\r
@@ -49,26 +62,108 @@ uLong ZEXPORT adler32(adler, buf, len)
     const Bytef *buf;\r
     uInt len;\r
 {\r
-    unsigned long s1 = adler & 0xffff;\r
-    unsigned long s2 = (adler >> 16) & 0xffff;\r
-    int k;\r
+    unsigned long sum2;\r
+    unsigned n;\r
+\r
+    /* split Adler-32 into component sums */\r
+    sum2 = (adler >> 16) & 0xffff;\r
+    adler &= 0xffff;\r
+\r
+    /* in case user likes doing a byte at a time, keep it fast */\r
+    if (len == 1) {\r
+        adler += buf[0];\r
+        if (adler >= BASE)\r
+            adler -= BASE;\r
+        sum2 += adler;\r
+        if (sum2 >= BASE)\r
+            sum2 -= BASE;\r
+        return adler | (sum2 << 16);\r
+    }\r
+\r
+    /* initial Adler-32 value (deferred check for len == 1 speed) */\r
+    if (buf == Z_NULL)\r
+        return 1L;\r
+\r
+    /* in case short lengths are provided, keep it somewhat fast */\r
+    if (len < 16) {\r
+        while (len--) {\r
+            adler += *buf++;\r
+            sum2 += adler;\r
+        }\r
+        if (adler >= BASE)\r
+            adler -= BASE;\r
+        MOD4(sum2);             /* only added so many BASE's */\r
+        return adler | (sum2 << 16);\r
+    }\r
 \r
-    if (buf == Z_NULL) return 1L;\r
+    /* do length NMAX blocks -- requires just one modulo operation */\r
+    while (len >= NMAX) {\r
+        len -= NMAX;\r
+        n = NMAX / 16;          /* NMAX is divisible by 16 */\r
+        do {\r
+            DO16(buf);          /* 16 sums unrolled */\r
+            buf += 16;\r
+        } while (--n);\r
+        MOD(adler);\r
+        MOD(sum2);\r
+    }\r
 \r
-    while (len > 0) {\r
-        k = len < NMAX ? (int)len : NMAX;\r
-        len -= k;\r
-        while (k >= 16) {\r
+    /* do remaining bytes (less than NMAX, still just one modulo) */\r
+    if (len) {                  /* avoid modulos if none remaining */\r
+        while (len >= 16) {\r
+            len -= 16;\r
             DO16(buf);\r
             buf += 16;\r
-            k -= 16;\r
         }\r
-        if (k != 0) do {\r
-            s1 += *buf++;\r
-            s2 += s1;\r
-        } while (--k);\r
-        MOD(s1);\r
-        MOD(s2);\r
+        while (len--) {\r
+            adler += *buf++;\r
+            sum2 += adler;\r
+        }\r
+        MOD(adler);\r
+        MOD(sum2);\r
     }\r
-    return (s2 << 16) | s1;\r
+\r
+    /* return recombined sums */\r
+    return adler | (sum2 << 16);\r
+}\r
+\r
+/* ========================================================================= */\r
+local uLong adler32_combine_(adler1, adler2, len2)\r
+    uLong adler1;\r
+    uLong adler2;\r
+    z_off64_t len2;\r
+{\r
+    unsigned long sum1;\r
+    unsigned long sum2;\r
+    unsigned rem;\r
+\r
+    /* the derivation of this formula is left as an exercise for the reader */\r
+    rem = (unsigned)(len2 % BASE);\r
+    sum1 = adler1 & 0xffff;\r
+    sum2 = rem * sum1;\r
+    MOD(sum2);\r
+    sum1 += (adler2 & 0xffff) + BASE - 1;\r
+    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;\r
+    if (sum1 >= BASE) sum1 -= BASE;\r
+    if (sum1 >= BASE) sum1 -= BASE;\r
+    if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);\r
+    if (sum2 >= BASE) sum2 -= BASE;\r
+    return sum1 | (sum2 << 16);\r
+}\r
+\r
+/* ========================================================================= */\r
+uLong ZEXPORT adler32_combine(adler1, adler2, len2)\r
+    uLong adler1;\r
+    uLong adler2;\r
+    z_off_t len2;\r
+{\r
+    return adler32_combine_(adler1, adler2, len2);\r
+}\r
+\r
+uLong ZEXPORT adler32_combine64(adler1, adler2, len2)\r
+    uLong adler1;\r
+    uLong adler2;\r
+    z_off64_t len2;\r
+{\r
+    return adler32_combine_(adler1, adler2, len2);\r
 }\r
index 5a7eeee..c46727a 100644 (file)
@@ -1,5 +1,5 @@
 /* compress.c -- compress a memory buffer\r
- * Copyright (C) 1995-2002 Jean-loup Gailly.\r
+ * Copyright (C) 1995-2005 Jean-loup Gailly.\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -75,5 +75,6 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
 uLong ZEXPORT compressBound (sourceLen)\r
     uLong sourceLen;\r
 {\r
-    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;\r
+    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +\r
+           (sourceLen >> 25) + 13;\r
 }\r
index 235fa9e..8cb3d8f 100644 (file)
@@ -1,16 +1,24 @@
 /* crc32.c -- compute the CRC-32 of a data stream\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2006, 2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  *\r
  * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster\r
  * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing\r
  * tables for updating the shift register in one step with three exclusive-ors\r
- * instead of four steps with four exclusive-ors.  This results about a factor\r
- * of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.\r
+ * instead of four steps with four exclusive-ors.  This results in about a\r
+ * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.\r
  */\r
 \r
 /* @(#) $Id$ */\r
 \r
+/*\r
+  Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore\r
+  protection on the static variables used to control the first-use generation\r
+  of the crc tables.  Therefore, if you #define DYNAMIC_CRC_TABLE, you should\r
+  first call get_crc_table() to initialize the tables before allowing more than\r
+  one thread to use crc32().\r
+ */\r
+\r
 #ifdef MAKECRCH\r
 #  include <stdio.h>\r
 #  ifndef DYNAMIC_CRC_TABLE\r
@@ -45,7 +53,7 @@
 \r
 /* Definitions for doing the crc four data bytes at a time. */\r
 #ifdef BYFOUR\r
-#  define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \\r
+#  define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \\r
                 (((w)&0xff00)<<8)+(((w)&0xff)<<24))\r
    local unsigned long crc32_little OF((unsigned long,\r
                         const unsigned char FAR *, unsigned));\r
 #  define TBLS 1\r
 #endif /* BYFOUR */\r
 \r
+/* Local functions for crc concatenation */\r
+local unsigned long gf2_matrix_times OF((unsigned long *mat,\r
+                                         unsigned long vec));\r
+local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));\r
+local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);\r
+\r
+\r
 #ifdef DYNAMIC_CRC_TABLE\r
 \r
-local int crc_table_empty = 1;\r
+local volatile int crc_table_empty = 1;\r
 local unsigned long FAR crc_table[TBLS][256];\r
 local void make_crc_table OF((void));\r
 #ifdef MAKECRCH\r
    local void write_table OF((FILE *, const unsigned long FAR *));\r
 #endif /* MAKECRCH */\r
-\r
 /*\r
   Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:\r
   x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.\r
@@ -95,38 +109,51 @@ local void make_crc_table()
 {\r
     unsigned long c;\r
     int n, k;\r
-    unsigned long poly;            /* polynomial exclusive-or pattern */\r
+    unsigned long poly;                 /* polynomial exclusive-or pattern */\r
     /* terms of polynomial defining this crc (except x^32): */\r
+    static volatile int first = 1;      /* flag to limit concurrent making */\r
     static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};\r
 \r
-    /* make exclusive-or pattern from polynomial (0xedb88320UL) */\r
-    poly = 0UL;\r
-    for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)\r
-        poly |= 1UL << (31 - p[n]);\r
-\r
-    /* generate a crc for every 8-bit value */\r
-    for (n = 0; n < 256; n++) {\r
-        c = (unsigned long)n;\r
-        for (k = 0; k < 8; k++)\r
-            c = c & 1 ? poly ^ (c >> 1) : c >> 1;\r
-        crc_table[0][n] = c;\r
-    }\r
+    /* See if another task is already doing this (not thread-safe, but better\r
+       than nothing -- significantly reduces duration of vulnerability in\r
+       case the advice about DYNAMIC_CRC_TABLE is ignored) */\r
+    if (first) {\r
+        first = 0;\r
+\r
+        /* make exclusive-or pattern from polynomial (0xedb88320UL) */\r
+        poly = 0UL;\r
+        for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)\r
+            poly |= 1UL << (31 - p[n]);\r
+\r
+        /* generate a crc for every 8-bit value */\r
+        for (n = 0; n < 256; n++) {\r
+            c = (unsigned long)n;\r
+            for (k = 0; k < 8; k++)\r
+                c = c & 1 ? poly ^ (c >> 1) : c >> 1;\r
+            crc_table[0][n] = c;\r
+        }\r
 \r
 #ifdef BYFOUR\r
-    /* generate crc for each value followed by one, two, and three zeros, and\r
-       then the byte reversal of those as well as the first table */\r
-    for (n = 0; n < 256; n++) {\r
-        c = crc_table[0][n];\r
-        crc_table[4][n] = REV(c);\r
-        for (k = 1; k < 4; k++) {\r
-            c = crc_table[0][c & 0xff] ^ (c >> 8);\r
-            crc_table[k][n] = c;\r
-            crc_table[k + 4][n] = REV(c);\r
+        /* generate crc for each value followed by one, two, and three zeros,\r
+           and then the byte reversal of those as well as the first table */\r
+        for (n = 0; n < 256; n++) {\r
+            c = crc_table[0][n];\r
+            crc_table[4][n] = REV(c);\r
+            for (k = 1; k < 4; k++) {\r
+                c = crc_table[0][c & 0xff] ^ (c >> 8);\r
+                crc_table[k][n] = c;\r
+                crc_table[k + 4][n] = REV(c);\r
+            }\r
         }\r
-    }\r
 #endif /* BYFOUR */\r
 \r
-  crc_table_empty = 0;\r
+        crc_table_empty = 0;\r
+    }\r
+    else {      /* not first */\r
+        /* wait for the other guy to finish (not efficient, but rare) */\r
+        while (crc_table_empty)\r
+            ;\r
+    }\r
 \r
 #ifdef MAKECRCH\r
     /* write out CRC tables to crc32.h */\r
@@ -180,9 +207,10 @@ local void write_table(out, table)
 const unsigned long FAR * ZEXPORT get_crc_table()\r
 {\r
 #ifdef DYNAMIC_CRC_TABLE\r
-  if (crc_table_empty) make_crc_table();\r
+    if (crc_table_empty)\r
+        make_crc_table();\r
 #endif /* DYNAMIC_CRC_TABLE */\r
-  return (const unsigned long FAR *)crc_table;\r
+    return (const unsigned long FAR *)crc_table;\r
 }\r
 \r
 /* ========================================================================= */\r
@@ -193,7 +221,7 @@ const unsigned long FAR * ZEXPORT get_crc_table()
 unsigned long ZEXPORT crc32(crc, buf, len)\r
     unsigned long crc;\r
     const unsigned char FAR *buf;\r
-    unsigned len;\r
+    uInt len;\r
 {\r
     if (buf == Z_NULL) return 0UL;\r
 \r
@@ -248,7 +276,7 @@ local unsigned long crc32_little(crc, buf, len)
         len--;\r
     }\r
 \r
-    buf4 = (const u4 FAR *)buf;\r
+    buf4 = (const u4 FAR *)(const void FAR *)buf;\r
     while (len >= 32) {\r
         DOLIT32;\r
         len -= 32;\r
@@ -288,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
         len--;\r
     }\r
 \r
-    buf4 = (const u4 FAR *)buf;\r
+    buf4 = (const u4 FAR *)(const void FAR *)buf;\r
     buf4--;\r
     while (len >= 32) {\r
         DOBIG32;\r
@@ -309,3 +337,106 @@ local unsigned long crc32_big(crc, buf, len)
 }\r
 \r
 #endif /* BYFOUR */\r
+\r
+#define GF2_DIM 32      /* dimension of GF(2) vectors (length of CRC) */\r
+\r
+/* ========================================================================= */\r
+local unsigned long gf2_matrix_times(mat, vec)\r
+    unsigned long *mat;\r
+    unsigned long vec;\r
+{\r
+    unsigned long sum;\r
+\r
+    sum = 0;\r
+    while (vec) {\r
+        if (vec & 1)\r
+            sum ^= *mat;\r
+        vec >>= 1;\r
+        mat++;\r
+    }\r
+    return sum;\r
+}\r
+\r
+/* ========================================================================= */\r
+local void gf2_matrix_square(square, mat)\r
+    unsigned long *square;\r
+    unsigned long *mat;\r
+{\r
+    int n;\r
+\r
+    for (n = 0; n < GF2_DIM; n++)\r
+        square[n] = gf2_matrix_times(mat, mat[n]);\r
+}\r
+\r
+/* ========================================================================= */\r
+local uLong crc32_combine_(crc1, crc2, len2)\r
+    uLong crc1;\r
+    uLong crc2;\r
+    z_off64_t len2;\r
+{\r
+    int n;\r
+    unsigned long row;\r
+    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */\r
+    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */\r
+\r
+    /* degenerate case (also disallow negative lengths) */\r
+    if (len2 <= 0)\r
+        return crc1;\r
+\r
+    /* put operator for one zero bit in odd */\r
+    odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */\r
+    row = 1;\r
+    for (n = 1; n < GF2_DIM; n++) {\r
+        odd[n] = row;\r
+        row <<= 1;\r
+    }\r
+\r
+    /* put operator for two zero bits in even */\r
+    gf2_matrix_square(even, odd);\r
+\r
+    /* put operator for four zero bits in odd */\r
+    gf2_matrix_square(odd, even);\r
+\r
+    /* apply len2 zeros to crc1 (first square will put the operator for one\r
+       zero byte, eight zero bits, in even) */\r
+    do {\r
+        /* apply zeros operator for this bit of len2 */\r
+        gf2_matrix_square(even, odd);\r
+        if (len2 & 1)\r
+            crc1 = gf2_matrix_times(even, crc1);\r
+        len2 >>= 1;\r
+\r
+        /* if no more bits set, then done */\r
+        if (len2 == 0)\r
+            break;\r
+\r
+        /* another iteration of the loop with odd and even swapped */\r
+        gf2_matrix_square(odd, even);\r
+        if (len2 & 1)\r
+            crc1 = gf2_matrix_times(odd, crc1);\r
+        len2 >>= 1;\r
+\r
+        /* if no more bits set, then done */\r
+    } while (len2 != 0);\r
+\r
+    /* return combined crc */\r
+    crc1 ^= crc2;\r
+    return crc1;\r
+}\r
+\r
+/* ========================================================================= */\r
+uLong ZEXPORT crc32_combine(crc1, crc2, len2)\r
+    uLong crc1;\r
+    uLong crc2;\r
+    z_off_t len2;\r
+{\r
+    return crc32_combine_(crc1, crc2, len2);\r
+}\r
+\r
+uLong ZEXPORT crc32_combine64(crc1, crc2, len2)\r
+    uLong crc1;\r
+    uLong crc2;\r
+    z_off64_t len2;\r
+{\r
+    return crc32_combine_(crc1, crc2, len2);\r
+}\r
index 022d6b8..fa00181 100644 (file)
@@ -1,5 +1,5 @@
 /* deflate.c -- compress data using the deflation algorithm\r
- * Copyright (C) 1995-2003 Jean-loup Gailly.\r
+ * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -52,7 +52,7 @@
 #include "deflate.h"\r
 \r
 const char deflate_copyright[] =\r
-   " deflate 1.2.1 Copyright 1995-2003 Jean-loup Gailly ";\r
+   " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";\r
 /*\r
   If you use the zlib library in a product, an acknowledgment is welcome\r
   in the documentation of your product. If for some reason you cannot\r
@@ -79,19 +79,18 @@ local block_state deflate_fast   OF((deflate_state *s, int flush));
 #ifndef FASTEST\r
 local block_state deflate_slow   OF((deflate_state *s, int flush));\r
 #endif\r
+local block_state deflate_rle    OF((deflate_state *s, int flush));\r
+local block_state deflate_huff   OF((deflate_state *s, int flush));\r
 local void lm_init        OF((deflate_state *s));\r
 local void putShortMSB    OF((deflate_state *s, uInt b));\r
 local void flush_pending  OF((z_streamp strm));\r
 local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size));\r
-#ifndef FASTEST\r
 #ifdef ASMV\r
       void match_init OF((void)); /* asm code initialization */\r
       uInt longest_match  OF((deflate_state *s, IPos cur_match));\r
 #else\r
 local uInt longest_match  OF((deflate_state *s, IPos cur_match));\r
 #endif\r
-#endif\r
-local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));\r
 \r
 #ifdef DEBUG\r
 local  void check_match OF((deflate_state *s, IPos start, IPos match,\r
@@ -110,11 +109,6 @@ local  void check_match OF((deflate_state *s, IPos start, IPos match,
 #endif\r
 /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */\r
 \r
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)\r
-/* Minimum amount of lookahead, except at the end of the input file.\r
- * See deflate.c for comments about the MIN_MATCH+1.\r
- */\r
-\r
 /* Values for max_lazy_match, good_match and max_chain_length, depending on\r
  * the desired pack level (0..9). The values given below have been tuned to\r
  * exclude worst case performance for pathological files. Better values may be\r
@@ -264,7 +258,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
 #endif\r
     if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||\r
         windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||\r
-        strategy < 0 || strategy > Z_RLE) {\r
+        strategy < 0 || strategy > Z_FIXED) {\r
         return Z_STREAM_ERROR;\r
     }\r
     if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */\r
@@ -274,6 +268,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     s->strm = strm;\r
 \r
     s->wrap = wrap;\r
+    s->gzhead = Z_NULL;\r
     s->w_bits = windowBits;\r
     s->w_size = 1 << s->w_bits;\r
     s->w_mask = s->w_size - 1;\r
@@ -287,6 +282,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));\r
     s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));\r
 \r
+    s->high_water = 0;      /* nothing written to s->window yet */\r
+\r
     s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */\r
 \r
     overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);\r
@@ -331,11 +328,9 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
         strm->adler = adler32(strm->adler, dictionary, dictLength);\r
 \r
     if (length < MIN_MATCH) return Z_OK;\r
-    if (length > MAX_DIST(s)) {\r
-        length = MAX_DIST(s);\r
-#ifndef USE_DICT_HEAD\r
+    if (length > s->w_size) {\r
+        length = s->w_size;\r
         dictionary += dictLength - length; /* use the tail of the dictionary */\r
-#endif\r
     }\r
     zmemcpy(s->window, dictionary, length);\r
     s->strstart = length;\r
@@ -391,6 +386,17 @@ int ZEXPORT deflateReset (strm)
 }\r
 \r
 /* ========================================================================= */\r
+int ZEXPORT deflateSetHeader (strm, head)\r
+    z_streamp strm;\r
+    gz_headerp head;\r
+{\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    if (strm->state->wrap != 2) return Z_STREAM_ERROR;\r
+    strm->state->gzhead = head;\r
+    return Z_OK;\r
+}\r
+\r
+/* ========================================================================= */\r
 int ZEXPORT deflatePrime (strm, bits, value)\r
     z_streamp strm;\r
     int bits;\r
@@ -420,14 +426,15 @@ int ZEXPORT deflateParams(strm, level, strategy)
 #else\r
     if (level == Z_DEFAULT_COMPRESSION) level = 6;\r
 #endif\r
-    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) {\r
+    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {\r
         return Z_STREAM_ERROR;\r
     }\r
     func = configuration_table[s->level].func;\r
 \r
-    if (func != configuration_table[level].func && strm->total_in != 0) {\r
+    if ((strategy != s->strategy || func != configuration_table[level].func) &&\r
+        strm->total_in != 0) {\r
         /* Flush the last buffer: */\r
-        err = deflate(strm, Z_PARTIAL_FLUSH);\r
+        err = deflate(strm, Z_BLOCK);\r
     }\r
     if (s->level != level) {\r
         s->level = level;\r
@@ -440,6 +447,25 @@ int ZEXPORT deflateParams(strm, level, strategy)
     return err;\r
 }\r
 \r
+/* ========================================================================= */\r
+int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)\r
+    z_streamp strm;\r
+    int good_length;\r
+    int max_lazy;\r
+    int nice_length;\r
+    int max_chain;\r
+{\r
+    deflate_state *s;\r
+\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    s = strm->state;\r
+    s->good_match = good_length;\r
+    s->max_lazy_match = max_lazy;\r
+    s->nice_match = nice_length;\r
+    s->max_chain_length = max_chain;\r
+    return Z_OK;\r
+}\r
+\r
 /* =========================================================================\r
  * For the default windowBits of 15 and memLevel of 8, this function returns\r
  * a close to exact, as well as small, upper bound on the compressed size.\r
@@ -452,33 +478,66 @@ int ZEXPORT deflateParams(strm, level, strategy)
  * resulting from using fixed blocks instead of stored blocks, which deflate\r
  * can emit on compressed data for some combinations of the parameters.\r
  *\r
- * This function could be more sophisticated to provide closer upper bounds\r
- * for every combination of windowBits and memLevel, as well as wrap.\r
- * But even the conservative upper bound of about 14% expansion does not\r
- * seem onerous for output buffer allocation.\r
+ * This function could be more sophisticated to provide closer upper bounds for\r
+ * every combination of windowBits and memLevel.  But even the conservative\r
+ * upper bound of about 14% expansion does not seem onerous for output buffer\r
+ * allocation.\r
  */\r
 uLong ZEXPORT deflateBound(strm, sourceLen)\r
     z_streamp strm;\r
     uLong sourceLen;\r
 {\r
     deflate_state *s;\r
-    uLong destLen;\r
+    uLong complen, wraplen;\r
+    Bytef *str;\r
 \r
-    /* conservative upper bound */\r
-    destLen = sourceLen +\r
-              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;\r
+    /* conservative upper bound for compressed data */\r
+    complen = sourceLen +\r
+              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;\r
 \r
-    /* if can't get parameters, return conservative bound */\r
+    /* if can't get parameters, return conservative bound plus zlib wrapper */\r
     if (strm == Z_NULL || strm->state == Z_NULL)\r
-        return destLen;\r
+        return complen + 6;\r
 \r
-    /* if not default parameters, return conservative bound */\r
+    /* compute wrapper length */\r
     s = strm->state;\r
+    switch (s->wrap) {\r
+    case 0:                                 /* raw deflate */\r
+        wraplen = 0;\r
+        break;\r
+    case 1:                                 /* zlib wrapper */\r
+        wraplen = 6 + (s->strstart ? 4 : 0);\r
+        break;\r
+    case 2:                                 /* gzip wrapper */\r
+        wraplen = 18;\r
+        if (s->gzhead != Z_NULL) {          /* user-supplied gzip header */\r
+            if (s->gzhead->extra != Z_NULL)\r
+                wraplen += 2 + s->gzhead->extra_len;\r
+            str = s->gzhead->name;\r
+            if (str != Z_NULL)\r
+                do {\r
+                    wraplen++;\r
+                } while (*str++);\r
+            str = s->gzhead->comment;\r
+            if (str != Z_NULL)\r
+                do {\r
+                    wraplen++;\r
+                } while (*str++);\r
+            if (s->gzhead->hcrc)\r
+                wraplen += 2;\r
+        }\r
+        break;\r
+    default:                                /* for compiler happiness */\r
+        wraplen = 6;\r
+    }\r
+\r
+    /* if not default parameters, return conservative bound */\r
     if (s->w_bits != 15 || s->hash_bits != 8 + 7)\r
-        return destLen;\r
+        return complen + wraplen;\r
 \r
     /* default settings: return tight bound for that case */\r
-    return compressBound(sourceLen);\r
+    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +\r
+           (sourceLen >> 25) + 13 - 6 + wraplen;\r
 }\r
 \r
 /* =========================================================================\r
@@ -528,7 +587,7 @@ int ZEXPORT deflate (strm, flush)
     deflate_state *s;\r
 \r
     if (strm == Z_NULL || strm->state == Z_NULL ||\r
-        flush > Z_FINISH || flush < 0) {\r
+        flush > Z_BLOCK || flush < 0) {\r
         return Z_STREAM_ERROR;\r
     }\r
     s = strm->state;\r
@@ -548,20 +607,47 @@ int ZEXPORT deflate (strm, flush)
     if (s->status == INIT_STATE) {\r
 #ifdef GZIP\r
         if (s->wrap == 2) {\r
+            strm->adler = crc32(0L, Z_NULL, 0);\r
             put_byte(s, 31);\r
             put_byte(s, 139);\r
             put_byte(s, 8);\r
-            put_byte(s, 0);\r
-            put_byte(s, 0);\r
-            put_byte(s, 0);\r
-            put_byte(s, 0);\r
-            put_byte(s, 0);\r
-            put_byte(s, s->level == 9 ? 2 :\r
-                        (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?\r
-                         4 : 0));\r
-            put_byte(s, 255);\r
-            s->status = BUSY_STATE;\r
-            strm->adler = crc32(0L, Z_NULL, 0);\r
+            if (s->gzhead == Z_NULL) {\r
+                put_byte(s, 0);\r
+                put_byte(s, 0);\r
+                put_byte(s, 0);\r
+                put_byte(s, 0);\r
+                put_byte(s, 0);\r
+                put_byte(s, s->level == 9 ? 2 :\r
+                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?\r
+                             4 : 0));\r
+                put_byte(s, OS_CODE);\r
+                s->status = BUSY_STATE;\r
+            }\r
+            else {\r
+                put_byte(s, (s->gzhead->text ? 1 : 0) +\r
+                            (s->gzhead->hcrc ? 2 : 0) +\r
+                            (s->gzhead->extra == Z_NULL ? 0 : 4) +\r
+                            (s->gzhead->name == Z_NULL ? 0 : 8) +\r
+                            (s->gzhead->comment == Z_NULL ? 0 : 16)\r
+                        );\r
+                put_byte(s, (Byte)(s->gzhead->time & 0xff));\r
+                put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));\r
+                put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));\r
+                put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));\r
+                put_byte(s, s->level == 9 ? 2 :\r
+                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?\r
+                             4 : 0));\r
+                put_byte(s, s->gzhead->os & 0xff);\r
+                if (s->gzhead->extra != Z_NULL) {\r
+                    put_byte(s, s->gzhead->extra_len & 0xff);\r
+                    put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);\r
+                }\r
+                if (s->gzhead->hcrc)\r
+                    strm->adler = crc32(strm->adler, s->pending_buf,\r
+                                        s->pending);\r
+                s->gzindex = 0;\r
+                s->status = EXTRA_STATE;\r
+            }\r
         }\r
         else\r
 #endif\r
@@ -592,6 +678,110 @@ int ZEXPORT deflate (strm, flush)
             strm->adler = adler32(0L, Z_NULL, 0);\r
         }\r
     }\r
+#ifdef GZIP\r
+    if (s->status == EXTRA_STATE) {\r
+        if (s->gzhead->extra != Z_NULL) {\r
+            uInt beg = s->pending;  /* start of bytes to update crc */\r
+\r
+            while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {\r
+                if (s->pending == s->pending_buf_size) {\r
+                    if (s->gzhead->hcrc && s->pending > beg)\r
+                        strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                            s->pending - beg);\r
+                    flush_pending(strm);\r
+                    beg = s->pending;\r
+                    if (s->pending == s->pending_buf_size)\r
+                        break;\r
+                }\r
+                put_byte(s, s->gzhead->extra[s->gzindex]);\r
+                s->gzindex++;\r
+            }\r
+            if (s->gzhead->hcrc && s->pending > beg)\r
+                strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                    s->pending - beg);\r
+            if (s->gzindex == s->gzhead->extra_len) {\r
+                s->gzindex = 0;\r
+                s->status = NAME_STATE;\r
+            }\r
+        }\r
+        else\r
+            s->status = NAME_STATE;\r
+    }\r
+    if (s->status == NAME_STATE) {\r
+        if (s->gzhead->name != Z_NULL) {\r
+            uInt beg = s->pending;  /* start of bytes to update crc */\r
+            int val;\r
+\r
+            do {\r
+                if (s->pending == s->pending_buf_size) {\r
+                    if (s->gzhead->hcrc && s->pending > beg)\r
+                        strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                            s->pending - beg);\r
+                    flush_pending(strm);\r
+                    beg = s->pending;\r
+                    if (s->pending == s->pending_buf_size) {\r
+                        val = 1;\r
+                        break;\r
+                    }\r
+                }\r
+                val = s->gzhead->name[s->gzindex++];\r
+                put_byte(s, val);\r
+            } while (val != 0);\r
+            if (s->gzhead->hcrc && s->pending > beg)\r
+                strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                    s->pending - beg);\r
+            if (val == 0) {\r
+                s->gzindex = 0;\r
+                s->status = COMMENT_STATE;\r
+            }\r
+        }\r
+        else\r
+            s->status = COMMENT_STATE;\r
+    }\r
+    if (s->status == COMMENT_STATE) {\r
+        if (s->gzhead->comment != Z_NULL) {\r
+            uInt beg = s->pending;  /* start of bytes to update crc */\r
+            int val;\r
+\r
+            do {\r
+                if (s->pending == s->pending_buf_size) {\r
+                    if (s->gzhead->hcrc && s->pending > beg)\r
+                        strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                            s->pending - beg);\r
+                    flush_pending(strm);\r
+                    beg = s->pending;\r
+                    if (s->pending == s->pending_buf_size) {\r
+                        val = 1;\r
+                        break;\r
+                    }\r
+                }\r
+                val = s->gzhead->comment[s->gzindex++];\r
+                put_byte(s, val);\r
+            } while (val != 0);\r
+            if (s->gzhead->hcrc && s->pending > beg)\r
+                strm->adler = crc32(strm->adler, s->pending_buf + beg,\r
+                                    s->pending - beg);\r
+            if (val == 0)\r
+                s->status = HCRC_STATE;\r
+        }\r
+        else\r
+            s->status = HCRC_STATE;\r
+    }\r
+    if (s->status == HCRC_STATE) {\r
+        if (s->gzhead->hcrc) {\r
+            if (s->pending + 2 > s->pending_buf_size)\r
+                flush_pending(strm);\r
+            if (s->pending + 2 <= s->pending_buf_size) {\r
+                put_byte(s, (Byte)(strm->adler & 0xff));\r
+                put_byte(s, (Byte)((strm->adler >> 8) & 0xff));\r
+                strm->adler = crc32(0L, Z_NULL, 0);\r
+                s->status = BUSY_STATE;\r
+            }\r
+        }\r
+        else\r
+            s->status = BUSY_STATE;\r
+    }\r
+#endif\r
 \r
     /* Flush as much pending output as possible */\r
     if (s->pending != 0) {\r
@@ -627,7 +817,9 @@ int ZEXPORT deflate (strm, flush)
         (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {\r
         block_state bstate;\r
 \r
-        bstate = (*(configuration_table[s->level].func))(s, flush);\r
+        bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :\r
+                    (s->strategy == Z_RLE ? deflate_rle(s, flush) :\r
+                        (*(configuration_table[s->level].func))(s, flush));\r
 \r
         if (bstate == finish_started || bstate == finish_done) {\r
             s->status = FINISH_STATE;\r
@@ -648,13 +840,17 @@ int ZEXPORT deflate (strm, flush)
         if (bstate == block_done) {\r
             if (flush == Z_PARTIAL_FLUSH) {\r
                 _tr_align(s);\r
-            } else { /* FULL_FLUSH or SYNC_FLUSH */\r
+            } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */\r
                 _tr_stored_block(s, (char*)0, 0L, 0);\r
                 /* For a full flush, this empty block will be recognized\r
                  * as a special marker by inflate_sync().\r
                  */\r
                 if (flush == Z_FULL_FLUSH) {\r
                     CLEAR_HASH(s);             /* forget history */\r
+                    if (s->lookahead == 0) {\r
+                        s->strstart = 0;\r
+                        s->block_start = 0L;\r
+                    }\r
                 }\r
             }\r
             flush_pending(strm);\r
@@ -704,7 +900,12 @@ int ZEXPORT deflateEnd (strm)
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
 \r
     status = strm->state->status;\r
-    if (status != INIT_STATE && status != BUSY_STATE &&\r
+    if (status != INIT_STATE &&\r
+        status != EXTRA_STATE &&\r
+        status != NAME_STATE &&\r
+        status != COMMENT_STATE &&\r
+        status != HCRC_STATE &&\r
+        status != BUSY_STATE &&\r
         status != FINISH_STATE) {\r
       return Z_STREAM_ERROR;\r
     }\r
@@ -744,12 +945,12 @@ int ZEXPORT deflateCopy (dest, source)
 \r
     ss = source->state;\r
 \r
-    *dest = *source;\r
+    zmemcpy(dest, source, sizeof(z_stream));\r
 \r
     ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));\r
     if (ds == Z_NULL) return Z_MEM_ERROR;\r
     dest->state = (struct internal_state FAR *) ds;\r
-    *ds = *ss;\r
+    zmemcpy(ds, ss, sizeof(deflate_state));\r
     ds->strm = dest;\r
 \r
     ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));\r
@@ -838,9 +1039,11 @@ local void lm_init (s)
     s->match_length = s->prev_length = MIN_MATCH-1;\r
     s->match_available = 0;\r
     s->ins_h = 0;\r
+#ifndef FASTEST\r
 #ifdef ASMV\r
     match_init(); /* initialize the asm code */\r
 #endif\r
+#endif\r
 }\r
 \r
 #ifndef FASTEST\r
@@ -909,7 +1112,12 @@ local uInt longest_match(s, cur_match)
         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
+         * or if the match length is less than 2.  Note that the checks below\r
+         * for insufficient lookahead only occur occasionally for performance\r
+         * reasons.  Therefore uninitialized memory will be accessed, and\r
+         * conditional jumps will be made that depend on those values.\r
+         * However the length of the match is limited to the lookahead, so\r
+         * the output of deflate is not affected by the uninitialized values.\r
          */\r
 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)\r
         /* This code assumes sizeof(unsigned short) == 2. Do not use\r
@@ -995,12 +1203,13 @@ local uInt longest_match(s, cur_match)
     return s->lookahead;\r
 }\r
 #endif /* ASMV */\r
-#endif /* FASTEST */\r
+\r
+#else /* FASTEST */\r
 \r
 /* ---------------------------------------------------------------------------\r
- * Optimized version for level == 1 or strategy == Z_RLE only\r
+ * Optimized version for FASTEST only\r
  */\r
-local uInt longest_match_fast(s, cur_match)\r
+local uInt longest_match(s, cur_match)\r
     deflate_state *s;\r
     IPos cur_match;                             /* current match */\r
 {\r
@@ -1053,6 +1262,8 @@ local uInt longest_match_fast(s, cur_match)
     return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;\r
 }\r
 \r
+#endif /* FASTEST */\r
+\r
 #ifdef DEBUG\r
 /* ===========================================================================\r
  * Check that the match at match_start is indeed a match.\r
@@ -1182,27 +1393,61 @@ local void fill_window(s)
          */\r
 \r
     } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);\r
+\r
+    /* If the WIN_INIT bytes after the end of the current data have never been\r
+     * written, then zero those bytes in order to avoid memory check reports of\r
+     * the use of uninitialized (or uninitialised as Julian writes) bytes by\r
+     * the longest match routines.  Update the high water mark for the next\r
+     * time through here.  WIN_INIT is set to MAX_MATCH since the longest match\r
+     * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.\r
+     */\r
+    if (s->high_water < s->window_size) {\r
+        ulg curr = s->strstart + (ulg)(s->lookahead);\r
+        ulg init;\r
+\r
+        if (s->high_water < curr) {\r
+            /* Previous high water mark below current data -- zero WIN_INIT\r
+             * bytes or up to end of window, whichever is less.\r
+             */\r
+            init = s->window_size - curr;\r
+            if (init > WIN_INIT)\r
+                init = WIN_INIT;\r
+            zmemzero(s->window + curr, (unsigned)init);\r
+            s->high_water = curr + init;\r
+        }\r
+        else if (s->high_water < (ulg)curr + WIN_INIT) {\r
+            /* High water mark at or above current data, but below current data\r
+             * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up\r
+             * to end of window, whichever is less.\r
+             */\r
+            init = (ulg)curr + WIN_INIT - s->high_water;\r
+            if (init > s->window_size - s->high_water)\r
+                init = s->window_size - s->high_water;\r
+            zmemzero(s->window + s->high_water, (unsigned)init);\r
+            s->high_water += init;\r
+        }\r
+    }\r
 }\r
 \r
 /* ===========================================================================\r
  * Flush the current block, with given end-of-file flag.\r
  * IN assertion: strstart is set to the end of the current match.\r
  */\r
-#define FLUSH_BLOCK_ONLY(s, eof) { \\r
+#define FLUSH_BLOCK_ONLY(s, last) { \\r
    _tr_flush_block(s, (s->block_start >= 0L ? \\r
                    (charf *)&s->window[(unsigned)s->block_start] : \\r
                    (charf *)Z_NULL), \\r
                 (ulg)((long)s->strstart - s->block_start), \\r
-                (eof)); \\r
+                (last)); \\r
    s->block_start = s->strstart; \\r
    flush_pending(s->strm); \\r
    Tracev((stderr,"[FLUSH]")); \\r
 }\r
 \r
 /* Same but force premature exit if necessary. */\r
-#define FLUSH_BLOCK(s, eof) { \\r
-   FLUSH_BLOCK_ONLY(s, eof); \\r
-   if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \\r
+#define FLUSH_BLOCK(s, last) { \\r
+   FLUSH_BLOCK_ONLY(s, last); \\r
+   if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \\r
 }\r
 \r
 /* ===========================================================================\r
@@ -1276,7 +1521,7 @@ local block_state deflate_fast(s, flush)
     deflate_state *s;\r
     int flush;\r
 {\r
-    IPos hash_head = NIL; /* head of the hash chain */\r
+    IPos hash_head;       /* head of the hash chain */\r
     int bflush;           /* set if current block must be flushed */\r
 \r
     for (;;) {\r
@@ -1296,6 +1541,7 @@ local block_state deflate_fast(s, flush)
         /* Insert the string window[strstart .. strstart+2] in the\r
          * dictionary, and set hash_head to the head of the hash chain:\r
          */\r
+        hash_head = NIL;\r
         if (s->lookahead >= MIN_MATCH) {\r
             INSERT_STRING(s, s->strstart, hash_head);\r
         }\r
@@ -1308,19 +1554,8 @@ local block_state deflate_fast(s, flush)
              * of window index 0 (in particular we have to avoid a match\r
              * of the string with itself at the start of the input file).\r
              */\r
-#ifdef FASTEST\r
-            if ((s->strategy < Z_HUFFMAN_ONLY) ||\r
-                (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {\r
-                s->match_length = longest_match_fast (s, hash_head);\r
-            }\r
-#else\r
-            if (s->strategy < Z_HUFFMAN_ONLY) {\r
-                s->match_length = longest_match (s, hash_head);\r
-            } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {\r
-                s->match_length = longest_match_fast (s, hash_head);\r
-            }\r
-#endif\r
-            /* longest_match() or longest_match_fast() sets match_start */\r
+            s->match_length = longest_match (s, hash_head);\r
+            /* longest_match() sets match_start */\r
         }\r
         if (s->match_length >= MIN_MATCH) {\r
             check_match(s, s->strstart, s->match_start, s->match_length);\r
@@ -1382,7 +1617,7 @@ local block_state deflate_slow(s, flush)
     deflate_state *s;\r
     int flush;\r
 {\r
-    IPos hash_head = NIL;    /* head of hash chain */\r
+    IPos hash_head;          /* head of hash chain */\r
     int bflush;              /* set if current block must be flushed */\r
 \r
     /* Process the input block. */\r
@@ -1403,6 +1638,7 @@ local block_state deflate_slow(s, flush)
         /* Insert the string window[strstart .. strstart+2] in the\r
          * dictionary, and set hash_head to the head of the hash chain:\r
          */\r
+        hash_head = NIL;\r
         if (s->lookahead >= MIN_MATCH) {\r
             INSERT_STRING(s, s->strstart, hash_head);\r
         }\r
@@ -1418,12 +1654,8 @@ local block_state deflate_slow(s, flush)
              * of window index 0 (in particular we have to avoid a match\r
              * of the string with itself at the start of the input file).\r
              */\r
-            if (s->strategy < Z_HUFFMAN_ONLY) {\r
-                s->match_length = longest_match (s, hash_head);\r
-            } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {\r
-                s->match_length = longest_match_fast (s, hash_head);\r
-            }\r
-            /* longest_match() or longest_match_fast() sets match_start */\r
+            s->match_length = longest_match (s, hash_head);\r
+            /* longest_match() sets match_start */\r
 \r
             if (s->match_length <= 5 && (s->strategy == Z_FILTERED\r
 #if TOO_FAR <= 32767\r
@@ -1500,3 +1732,103 @@ local block_state deflate_slow(s, flush)
     return flush == Z_FINISH ? finish_done : block_done;\r
 }\r
 #endif /* FASTEST */\r
+\r
+/* ===========================================================================\r
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance\r
+ * one.  Do not maintain a hash table.  (It will be regenerated if this run of\r
+ * deflate switches away from Z_RLE.)\r
+ */\r
+local block_state deflate_rle(s, flush)\r
+    deflate_state *s;\r
+    int flush;\r
+{\r
+    int bflush;             /* set if current block must be flushed */\r
+    uInt prev;              /* byte at distance one to match */\r
+    Bytef *scan, *strend;   /* scan goes up to strend for length of run */\r
+\r
+    for (;;) {\r
+        /* Make sure that we always have enough lookahead, except\r
+         * at the end of the input file. We need MAX_MATCH bytes\r
+         * for the longest encodable run.\r
+         */\r
+        if (s->lookahead < MAX_MATCH) {\r
+            fill_window(s);\r
+            if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {\r
+                return need_more;\r
+            }\r
+            if (s->lookahead == 0) break; /* flush the current block */\r
+        }\r
+\r
+        /* See how many times the previous byte repeats */\r
+        s->match_length = 0;\r
+        if (s->lookahead >= MIN_MATCH && s->strstart > 0) {\r
+            scan = s->window + s->strstart - 1;\r
+            prev = *scan;\r
+            if (prev == *++scan && prev == *++scan && prev == *++scan) {\r
+                strend = s->window + s->strstart + MAX_MATCH;\r
+                do {\r
+                } while (prev == *++scan && prev == *++scan &&\r
+                         prev == *++scan && prev == *++scan &&\r
+                         prev == *++scan && prev == *++scan &&\r
+                         prev == *++scan && prev == *++scan &&\r
+                         scan < strend);\r
+                s->match_length = MAX_MATCH - (int)(strend - scan);\r
+                if (s->match_length > s->lookahead)\r
+                    s->match_length = s->lookahead;\r
+            }\r
+        }\r
+\r
+        /* Emit match if have run of MIN_MATCH or longer, else emit literal */\r
+        if (s->match_length >= MIN_MATCH) {\r
+            check_match(s, s->strstart, s->strstart - 1, s->match_length);\r
+\r
+            _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);\r
+\r
+            s->lookahead -= s->match_length;\r
+            s->strstart += s->match_length;\r
+            s->match_length = 0;\r
+        } else {\r
+            /* No match, output a literal byte */\r
+            Tracevv((stderr,"%c", s->window[s->strstart]));\r
+            _tr_tally_lit (s, s->window[s->strstart], bflush);\r
+            s->lookahead--;\r
+            s->strstart++;\r
+        }\r
+        if (bflush) FLUSH_BLOCK(s, 0);\r
+    }\r
+    FLUSH_BLOCK(s, flush == Z_FINISH);\r
+    return flush == Z_FINISH ? finish_done : block_done;\r
+}\r
+\r
+/* ===========================================================================\r
+ * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.\r
+ * (It will be regenerated if this run of deflate switches away from Huffman.)\r
+ */\r
+local block_state deflate_huff(s, flush)\r
+    deflate_state *s;\r
+    int flush;\r
+{\r
+    int bflush;             /* set if current block must be flushed */\r
+\r
+    for (;;) {\r
+        /* Make sure that we have a literal to write. */\r
+        if (s->lookahead == 0) {\r
+            fill_window(s);\r
+            if (s->lookahead == 0) {\r
+                if (flush == Z_NO_FLUSH)\r
+                    return need_more;\r
+                break;      /* flush the current block */\r
+            }\r
+        }\r
+\r
+        /* Output a literal byte */\r
+        s->match_length = 0;\r
+        Tracevv((stderr,"%c", s->window[s->strstart]));\r
+        _tr_tally_lit (s, s->window[s->strstart], bflush);\r
+        s->lookahead--;\r
+        s->strstart++;\r
+        if (bflush) FLUSH_BLOCK(s, 0);\r
+    }\r
+    FLUSH_BLOCK(s, flush == Z_FINISH);\r
+    return flush == Z_FINISH ? finish_done : block_done;\r
+}\r
index ee00773..e9044c1 100644 (file)
@@ -1,5 +1,5 @@
 /* deflate.h -- internal compression state\r
- * Copyright (C) 1995-2002 Jean-loup Gailly\r
+ * Copyright (C) 1995-2010 Jean-loup Gailly\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 /* All codes must not exceed MAX_BITS bits */\r
 \r
 #define INIT_STATE    42\r
+#define EXTRA_STATE   69\r
+#define NAME_STATE    73\r
+#define COMMENT_STATE 91\r
+#define HCRC_STATE   103\r
 #define BUSY_STATE   113\r
 #define FINISH_STATE 666\r
 /* Stream status */\r
@@ -93,9 +97,10 @@ typedef struct internal_state {
     Bytef *pending_buf;  /* output still pending */\r
     ulg   pending_buf_size; /* size of pending_buf */\r
     Bytef *pending_out;  /* next pending byte to output to the stream */\r
-    int   pending;       /* nb of bytes in the pending buffer */\r
+    uInt   pending;      /* nb of bytes in the pending buffer */\r
     int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */\r
-    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */\r
+    gz_headerp  gzhead;  /* gzip header information to write */\r
+    uInt   gzindex;      /* where in extra, name, or comment */\r
     Byte  method;        /* STORED (for zip only) or DEFLATED */\r
     int   last_flush;    /* value of flush param for previous deflate call */\r
 \r
@@ -255,6 +260,13 @@ typedef struct internal_state {
      * are always zero.\r
      */\r
 \r
+    ulg high_water;\r
+    /* High water mark offset in window for initialized bytes -- bytes above\r
+     * this are set to zero in order to avoid memory check warnings when\r
+     * longest match routines access bytes past the input.  This is then\r
+     * updated to the new high water mark.\r
+     */\r
+\r
 } FAR deflate_state;\r
 \r
 /* Output a byte on the stream.\r
@@ -273,14 +285,18 @@ typedef struct internal_state {
  * distances are limited to MAX_DIST instead of WSIZE.\r
  */\r
 \r
+#define WIN_INIT MAX_MATCH\r
+/* Number of bytes after end of data in window to initialize in order to avoid\r
+   memory checker errors from longest match routines */\r
+\r
         /* in trees.c */\r
-void _tr_init         OF((deflate_state *s));\r
-int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));\r
-void _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,\r
-                          int eof));\r
-void _tr_align        OF((deflate_state *s));\r
-void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,\r
-                          int eof));\r
+void ZLIB_INTERNAL _tr_init OF((deflate_state *s));\r
+int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));\r
+void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,\r
+                        ulg stored_len, int last));\r
+void ZLIB_INTERNAL _tr_align OF((deflate_state *s));\r
+void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,\r
+                        ulg stored_len, int last));\r
 \r
 #define d_code(dist) \\r
    ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])\r
@@ -293,11 +309,11 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
 /* Inline versions of _tr_tally for speed: */\r
 \r
 #if defined(GEN_TREES_H) || !defined(STDC)\r
-  extern uch _length_code[];\r
-  extern uch _dist_code[];\r
+  extern uch ZLIB_INTERNAL _length_code[];\r
+  extern uch ZLIB_INTERNAL _dist_code[];\r
 #else\r
-  extern const uch _length_code[];\r
-  extern const uch _dist_code[];\r
+  extern const uch ZLIB_INTERNAL _length_code[];\r
+  extern const uch ZLIB_INTERNAL _dist_code[];\r
 #endif\r
 \r
 # define _tr_tally_lit(s, c, flush) \\r
index 5cf5d22..14770c5 100644 (file)
@@ -1,5 +1,5 @@
 /* infback.c -- inflate using a call-back interface\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2009 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -26,7 +26,7 @@ local void fixedtables OF((struct inflate_state FAR *state));
    window and output buffer that is 2**windowBits bytes.\r
  */\r
 int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)\r
-z_stream FAR *strm;\r
+z_streamstrm;\r
 int windowBits;\r
 unsigned char FAR *window;\r
 const char *version;\r
@@ -50,11 +50,12 @@ int stream_size;
                                                sizeof(struct inflate_state));\r
     if (state == Z_NULL) return Z_MEM_ERROR;\r
     Tracev((stderr, "inflate: allocated\n"));\r
-    strm->state = (voidpf)state;\r
+    strm->state = (struct internal_state FAR *)state;\r
+    state->dmax = 32768U;\r
     state->wbits = windowBits;\r
     state->wsize = 1U << windowBits;\r
     state->window = window;\r
-    state->write = 0;\r
+    state->wnext = 0;\r
     state->whave = 0;\r
     return Z_OK;\r
 }\r
@@ -238,7 +239,7 @@ struct inflate_state FAR *state;
    are not correct, i.e. strm is Z_NULL or the state was not initialized.\r
  */\r
 int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)\r
-z_stream FAR *strm;\r
+z_streamstrm;\r
 in_func in;\r
 void FAR *in_desc;\r
 out_func out;\r
@@ -252,7 +253,7 @@ void FAR *out_desc;
     unsigned bits;              /* bits in bit buffer */\r
     unsigned copy;              /* number of stored or match bytes to copy */\r
     unsigned char FAR *from;    /* where to copy match bytes from */\r
-    code this;                  /* current decoding table entry */\r
+    code here;                  /* current decoding table entry */\r
     code last;                  /* parent table entry */\r
     unsigned len;               /* length to copy for repeats, bits to drop */\r
     int ret;                    /* return code */\r
@@ -388,19 +389,19 @@ void FAR *out_desc;
             state->have = 0;\r
             while (state->have < state->nlen + state->ndist) {\r
                 for (;;) {\r
-                    this = state->lencode[BITS(state->lenbits)];\r
-                    if ((unsigned)(this.bits) <= bits) break;\r
+                    here = state->lencode[BITS(state->lenbits)];\r
+                    if ((unsigned)(here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
-                if (this.val < 16) {\r
-                    NEEDBITS(this.bits);\r
-                    DROPBITS(this.bits);\r
-                    state->lens[state->have++] = this.val;\r
+                if (here.val < 16) {\r
+                    NEEDBITS(here.bits);\r
+                    DROPBITS(here.bits);\r
+                    state->lens[state->have++] = here.val;\r
                 }\r
                 else {\r
-                    if (this.val == 16) {\r
-                        NEEDBITS(this.bits + 2);\r
-                        DROPBITS(this.bits);\r
+                    if (here.val == 16) {\r
+                        NEEDBITS(here.bits + 2);\r
+                        DROPBITS(here.bits);\r
                         if (state->have == 0) {\r
                             strm->msg = (char *)"invalid bit length repeat";\r
                             state->mode = BAD;\r
@@ -410,16 +411,16 @@ void FAR *out_desc;
                         copy = 3 + BITS(2);\r
                         DROPBITS(2);\r
                     }\r
-                    else if (this.val == 17) {\r
-                        NEEDBITS(this.bits + 3);\r
-                        DROPBITS(this.bits);\r
+                    else if (here.val == 17) {\r
+                        NEEDBITS(here.bits + 3);\r
+                        DROPBITS(here.bits);\r
                         len = 0;\r
                         copy = 3 + BITS(3);\r
                         DROPBITS(3);\r
                     }\r
                     else {\r
-                        NEEDBITS(this.bits + 7);\r
-                        DROPBITS(this.bits);\r
+                        NEEDBITS(here.bits + 7);\r
+                        DROPBITS(here.bits);\r
                         len = 0;\r
                         copy = 11 + BITS(7);\r
                         DROPBITS(7);\r
@@ -434,7 +435,19 @@ void FAR *out_desc;
                 }\r
             }\r
 \r
-            /* build code tables */\r
+            /* handle error breaks in while */\r
+            if (state->mode == BAD) break;\r
+\r
+            /* check for end-of-block code (better have one) */\r
+            if (state->lens[256] == 0) {\r
+                strm->msg = (char *)"invalid code -- missing end-of-block";\r
+                state->mode = BAD;\r
+                break;\r
+            }\r
+\r
+            /* build code tables -- note: do not change the lenbits or distbits\r
+               values here (9 and 6) without reading the comments in inftrees.h\r
+               concerning the ENOUGH constants, which depend on those values */\r
             state->next = state->codes;\r
             state->lencode = (code const FAR *)(state->next);\r
             state->lenbits = 9;\r
@@ -470,28 +483,28 @@ void FAR *out_desc;
 \r
             /* get a literal, length, or end-of-block code */\r
             for (;;) {\r
-                this = state->lencode[BITS(state->lenbits)];\r
-                if ((unsigned)(this.bits) <= bits) break;\r
+                here = state->lencode[BITS(state->lenbits)];\r
+                if ((unsigned)(here.bits) <= bits) break;\r
                 PULLBYTE();\r
             }\r
-            if (this.op && (this.op & 0xf0) == 0) {\r
-                last = this;\r
+            if (here.op && (here.op & 0xf0) == 0) {\r
+                last = here;\r
                 for (;;) {\r
-                    this = state->lencode[last.val +\r
+                    here = state->lencode[last.val +\r
                             (BITS(last.bits + last.op) >> last.bits)];\r
-                    if ((unsigned)(last.bits + this.bits) <= bits) break;\r
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
                 DROPBITS(last.bits);\r
             }\r
-            DROPBITS(this.bits);\r
-            state->length = (unsigned)this.val;\r
+            DROPBITS(here.bits);\r
+            state->length = (unsigned)here.val;\r
 \r
             /* process literal */\r
-            if (this.op == 0) {\r
-                Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?\r
+            if (here.op == 0) {\r
+                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?\r
                         "inflate:         literal '%c'\n" :\r
-                        "inflate:         literal 0x%02x\n", this.val));\r
+                        "inflate:         literal 0x%02x\n", here.val));\r
                 ROOM();\r
                 *put++ = (unsigned char)(state->length);\r
                 left--;\r
@@ -500,21 +513,21 @@ void FAR *out_desc;
             }\r
 \r
             /* process end of block */\r
-            if (this.op & 32) {\r
+            if (here.op & 32) {\r
                 Tracevv((stderr, "inflate:         end of block\n"));\r
                 state->mode = TYPE;\r
                 break;\r
             }\r
 \r
             /* invalid code */\r
-            if (this.op & 64) {\r
+            if (here.op & 64) {\r
                 strm->msg = (char *)"invalid literal/length code";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
 \r
             /* length code -- get extra bits, if any */\r
-            state->extra = (unsigned)(this.op) & 15;\r
+            state->extra = (unsigned)(here.op) & 15;\r
             if (state->extra != 0) {\r
                 NEEDBITS(state->extra);\r
                 state->length += BITS(state->extra);\r
@@ -524,30 +537,30 @@ void FAR *out_desc;
 \r
             /* get distance code */\r
             for (;;) {\r
-                this = state->distcode[BITS(state->distbits)];\r
-                if ((unsigned)(this.bits) <= bits) break;\r
+                here = state->distcode[BITS(state->distbits)];\r
+                if ((unsigned)(here.bits) <= bits) break;\r
                 PULLBYTE();\r
             }\r
-            if ((this.op & 0xf0) == 0) {\r
-                last = this;\r
+            if ((here.op & 0xf0) == 0) {\r
+                last = here;\r
                 for (;;) {\r
-                    this = state->distcode[last.val +\r
+                    here = state->distcode[last.val +\r
                             (BITS(last.bits + last.op) >> last.bits)];\r
-                    if ((unsigned)(last.bits + this.bits) <= bits) break;\r
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
                 DROPBITS(last.bits);\r
             }\r
-            DROPBITS(this.bits);\r
-            if (this.op & 64) {\r
+            DROPBITS(here.bits);\r
+            if (here.op & 64) {\r
                 strm->msg = (char *)"invalid distance code";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
-            state->offset = (unsigned)this.val;\r
+            state->offset = (unsigned)here.val;\r
 \r
             /* get distance extra bits, if any */\r
-            state->extra = (unsigned)(this.op) & 15;\r
+            state->extra = (unsigned)(here.op) & 15;\r
             if (state->extra != 0) {\r
                 NEEDBITS(state->extra);\r
                 state->offset += BITS(state->extra);\r
@@ -608,7 +621,7 @@ void FAR *out_desc;
 }\r
 \r
 int ZEXPORT inflateBackEnd(strm)\r
-z_stream FAR *strm;\r
+z_streamstrm;\r
 {\r
     if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)\r
         return Z_STREAM_ERROR;\r
index 63aa440..2dfd412 100644 (file)
@@ -1,5 +1,5 @@
 /* inffast.c -- fast decoding\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2008, 2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -19,7 +19,7 @@
    - none\r
    No measurable difference:\r
    - Pentium III (Anderson)\r
-   - 68060 (Nikl)\r
+   - M68060 (Nikl)\r
  */\r
 #ifdef POSTINC\r
 #  define OFF 0\r
@@ -64,7 +64,7 @@
       requires strm->avail_out >= 258 for each loop to avoid checking for\r
       output space.\r
  */\r
-void inflate_fast(strm, start)\r
+void ZLIB_INTERNAL inflate_fast(strm, start)\r
 z_streamp strm;\r
 unsigned start;         /* inflate()'s starting value for strm->avail_out */\r
 {\r
@@ -74,9 +74,12 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
     unsigned char FAR *out;     /* local strm->next_out */\r
     unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */\r
     unsigned char FAR *end;     /* while out < end, enough space available */\r
+#ifdef INFLATE_STRICT\r
+    unsigned dmax;              /* maximum distance from zlib header */\r
+#endif\r
     unsigned wsize;             /* window size or zero if not using window */\r
     unsigned whave;             /* valid bytes in the window */\r
-    unsigned write;             /* window write index */\r
+    unsigned wnext;             /* window write index */\r
     unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */\r
     unsigned long hold;         /* local strm->hold */\r
     unsigned bits;              /* local strm->bits */\r
@@ -84,7 +87,7 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
     code const FAR *dcode;      /* local strm->distcode */\r
     unsigned lmask;             /* mask for first level of length codes */\r
     unsigned dmask;             /* mask for first level of distance codes */\r
-    code this;                  /* retrieved table entry */\r
+    code here;                  /* retrieved table entry */\r
     unsigned op;                /* code bits, operation, extra bits, or */\r
                                 /*  window position, window bytes to copy */\r
     unsigned len;               /* match length, unused bytes */\r
@@ -98,9 +101,12 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
     out = strm->next_out - OFF;\r
     beg = out - (start - strm->avail_out);\r
     end = out + (strm->avail_out - 257);\r
+#ifdef INFLATE_STRICT\r
+    dmax = state->dmax;\r
+#endif\r
     wsize = state->wsize;\r
     whave = state->whave;\r
-    write = state->write;\r
+    wnext = state->wnext;\r
     window = state->window;\r
     hold = state->hold;\r
     bits = state->bits;\r
@@ -118,20 +124,20 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
             hold += (unsigned long)(PUP(in)) << bits;\r
             bits += 8;\r
         }\r
-        this = lcode[hold & lmask];\r
+        here = lcode[hold & lmask];\r
       dolen:\r
-        op = (unsigned)(this.bits);\r
+        op = (unsigned)(here.bits);\r
         hold >>= op;\r
         bits -= op;\r
-        op = (unsigned)(this.op);\r
+        op = (unsigned)(here.op);\r
         if (op == 0) {                          /* literal */\r
-            Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?\r
+            Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?\r
                     "inflate:         literal '%c'\n" :\r
-                    "inflate:         literal 0x%02x\n", this.val));\r
-            PUP(out) = (unsigned char)(this.val);\r
+                    "inflate:         literal 0x%02x\n", here.val));\r
+            PUP(out) = (unsigned char)(here.val);\r
         }\r
         else if (op & 16) {                     /* length base */\r
-            len = (unsigned)(this.val);\r
+            len = (unsigned)(here.val);\r
             op &= 15;                           /* number of extra bits */\r
             if (op) {\r
                 if (bits < op) {\r
@@ -149,14 +155,14 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                 hold += (unsigned long)(PUP(in)) << bits;\r
                 bits += 8;\r
             }\r
-            this = dcode[hold & dmask];\r
+            here = dcode[hold & dmask];\r
           dodist:\r
-            op = (unsigned)(this.bits);\r
+            op = (unsigned)(here.bits);\r
             hold >>= op;\r
             bits -= op;\r
-            op = (unsigned)(this.op);\r
+            op = (unsigned)(here.op);\r
             if (op & 16) {                      /* distance base */\r
-                dist = (unsigned)(this.val);\r
+                dist = (unsigned)(here.val);\r
                 op &= 15;                       /* number of extra bits */\r
                 if (bits < op) {\r
                     hold += (unsigned long)(PUP(in)) << bits;\r
@@ -167,6 +173,13 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                     }\r
                 }\r
                 dist += (unsigned)hold & ((1U << op) - 1);\r
+#ifdef INFLATE_STRICT\r
+                if (dist > dmax) {\r
+                    strm->msg = (char *)"invalid distance too far back";\r
+                    state->mode = BAD;\r
+                    break;\r
+                }\r
+#endif\r
                 hold >>= op;\r
                 bits -= op;\r
                 Tracevv((stderr, "inflate:         distance %u\n", dist));\r
@@ -174,12 +187,34 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                 if (dist > op) {                /* see if copy from window */\r
                     op = dist - op;             /* distance back in window */\r
                     if (op > whave) {\r
-                        strm->msg = (char *)"invalid distance too far back";\r
-                        state->mode = BAD;\r
-                        break;\r
+                        if (state->sane) {\r
+                            strm->msg =\r
+                                (char *)"invalid distance too far back";\r
+                            state->mode = BAD;\r
+                            break;\r
+                        }\r
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR\r
+                        if (len <= op - whave) {\r
+                            do {\r
+                                PUP(out) = 0;\r
+                            } while (--len);\r
+                            continue;\r
+                        }\r
+                        len -= op - whave;\r
+                        do {\r
+                            PUP(out) = 0;\r
+                        } while (--op > whave);\r
+                        if (op == 0) {\r
+                            from = out - dist;\r
+                            do {\r
+                                PUP(out) = PUP(from);\r
+                            } while (--len);\r
+                            continue;\r
+                        }\r
+#endif\r
                     }\r
                     from = window - OFF;\r
-                    if (write == 0) {           /* very common case */\r
+                    if (wnext == 0) {           /* very common case */\r
                         from += wsize - op;\r
                         if (op < len) {         /* some from window */\r
                             len -= op;\r
@@ -189,17 +224,17 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                             from = out - dist;  /* rest from output */\r
                         }\r
                     }\r
-                    else if (write < op) {      /* wrap around window */\r
-                        from += wsize + write - op;\r
-                        op -= write;\r
+                    else if (wnext < op) {      /* wrap around window */\r
+                        from += wsize + wnext - op;\r
+                        op -= wnext;\r
                         if (op < len) {         /* some from end of window */\r
                             len -= op;\r
                             do {\r
                                 PUP(out) = PUP(from);\r
                             } while (--op);\r
                             from = window - OFF;\r
-                            if (write < len) {  /* some from start of window */\r
-                                op = write;\r
+                            if (wnext < len) {  /* some from start of window */\r
+                                op = wnext;\r
                                 len -= op;\r
                                 do {\r
                                     PUP(out) = PUP(from);\r
@@ -209,7 +244,7 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                         }\r
                     }\r
                     else {                      /* contiguous in window */\r
-                        from += write - op;\r
+                        from += wnext - op;\r
                         if (op < len) {         /* some from window */\r
                             len -= op;\r
                             do {\r
@@ -246,7 +281,7 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
                 }\r
             }\r
             else if ((op & 64) == 0) {          /* 2nd level distance code */\r
-                this = dcode[this.val + (hold & ((1U << op) - 1))];\r
+                here = dcode[here.val + (hold & ((1U << op) - 1))];\r
                 goto dodist;\r
             }\r
             else {\r
@@ -256,7 +291,7 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
             }\r
         }\r
         else if ((op & 64) == 0) {              /* 2nd level length code */\r
-            this = lcode[this.val + (hold & ((1U << op) - 1))];\r
+            here = lcode[here.val + (hold & ((1U << op) - 1))];\r
             goto dolen;\r
         }\r
         else if (op & 32) {                     /* end-of-block */\r
@@ -292,7 +327,7 @@ unsigned start;         /* inflate()'s starting value for strm->avail_out */
    inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):\r
    - Using bit fields for code structure\r
    - Different op definition to avoid & for extra bits (do & for table bits)\r
-   - Three separate decoding do-loops for direct, window, and write == 0\r
+   - Three separate decoding do-loops for direct, window, and wnext == 0\r
    - Special case for distance > 1 copies to do overlapped load and store copy\r
    - Explicit branch predictions (based on measured branch probabilities)\r
    - Deferring match copy and interspersed it with decoding subsequent codes\r
index 614fa78..e1e6db4 100644 (file)
@@ -1,5 +1,5 @@
 /* inffast.h -- header to use inffast.c\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2003, 2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -8,4 +8,4 @@
    subject to change. Applications should only use zlib.h.\r
  */\r
 \r
-void inflate_fast OF((z_streamp strm, unsigned start));\r
+void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));\r
index 71fe3cc..5bec31e 100644 (file)
@@ -1,5 +1,5 @@
 /* inflate.c -- zlib decompression\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -45,7 +45,7 @@
  * - Rearrange window copies in inflate_fast() for speed and simplification\r
  * - Unroll last copy for window match in inflate_fast()\r
  * - Use local copies of window variables in inflate_fast() for speed\r
- * - Pull out common write == 0 case for speed in inflate_fast()\r
+ * - Pull out common wnext == 0 case for speed in inflate_fast()\r
  * - Make op and len in inflate_fast() unsigned for consistency\r
  * - Add FAR to lcode and dcode declarations in inflate_fast()\r
  * - Simplified bad distance check in inflate_fast()\r
@@ -109,24 +109,69 @@ z_streamp strm;
     state = (struct inflate_state FAR *)strm->state;\r
     strm->total_in = strm->total_out = state->total = 0;\r
     strm->msg = Z_NULL;\r
+    strm->adler = 1;        /* to support ill-conceived Java test suite */\r
     state->mode = HEAD;\r
     state->last = 0;\r
     state->havedict = 0;\r
+    state->dmax = 32768U;\r
+    state->head = Z_NULL;\r
     state->wsize = 0;\r
     state->whave = 0;\r
+    state->wnext = 0;\r
     state->hold = 0;\r
     state->bits = 0;\r
     state->lencode = state->distcode = state->next = state->codes;\r
+    state->sane = 1;\r
+    state->back = -1;\r
     Tracev((stderr, "inflate: reset\n"));\r
     return Z_OK;\r
 }\r
 \r
+int ZEXPORT inflateReset2(strm, windowBits)\r
+z_streamp strm;\r
+int windowBits;\r
+{\r
+    int wrap;\r
+    struct inflate_state FAR *state;\r
+\r
+    /* get the state */\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    state = (struct inflate_state FAR *)strm->state;\r
+\r
+    /* extract wrap request from windowBits parameter */\r
+    if (windowBits < 0) {\r
+        wrap = 0;\r
+        windowBits = -windowBits;\r
+    }\r
+    else {\r
+        wrap = (windowBits >> 4) + 1;\r
+#ifdef GUNZIP\r
+        if (windowBits < 48)\r
+            windowBits &= 15;\r
+#endif\r
+    }\r
+\r
+    /* set number of window bits, free window if different */\r
+    if (windowBits && (windowBits < 8 || windowBits > 15))\r
+        return Z_STREAM_ERROR;\r
+    if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {\r
+        ZFREE(strm, state->window);\r
+        state->window = Z_NULL;\r
+    }\r
+\r
+    /* update state and reset the rest of it */\r
+    state->wrap = wrap;\r
+    state->wbits = (unsigned)windowBits;\r
+    return inflateReset(strm);\r
+}\r
+\r
 int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)\r
 z_streamp strm;\r
 int windowBits;\r
 const char *version;\r
 int stream_size;\r
 {\r
+    int ret;\r
     struct inflate_state FAR *state;\r
 \r
     if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||\r
@@ -143,25 +188,14 @@ int stream_size;
             ZALLOC(strm, 1, sizeof(struct inflate_state));\r
     if (state == Z_NULL) return Z_MEM_ERROR;\r
     Tracev((stderr, "inflate: allocated\n"));\r
-    strm->state = (voidpf)state;\r
-    if (windowBits < 0) {\r
-        state->wrap = 0;\r
-        windowBits = -windowBits;\r
-    }\r
-    else {\r
-        state->wrap = (windowBits >> 4) + 1;\r
-#ifdef GUNZIP\r
-        if (windowBits < 48) windowBits &= 15;\r
-#endif\r
-    }\r
-    if (windowBits < 8 || windowBits > 15) {\r
+    strm->state = (struct internal_state FAR *)state;\r
+    state->window = Z_NULL;\r
+    ret = inflateReset2(strm, windowBits);\r
+    if (ret != Z_OK) {\r
         ZFREE(strm, state);\r
         strm->state = Z_NULL;\r
-        return Z_STREAM_ERROR;\r
     }\r
-    state->wbits = (unsigned)windowBits;\r
-    state->window = Z_NULL;\r
-    return inflateReset(strm);\r
+    return ret;\r
 }\r
 \r
 int ZEXPORT inflateInit_(strm, version, stream_size)\r
@@ -172,6 +206,27 @@ int stream_size;
     return inflateInit2_(strm, DEF_WBITS, version, stream_size);\r
 }\r
 \r
+int ZEXPORT inflatePrime(strm, bits, value)\r
+z_streamp strm;\r
+int bits;\r
+int value;\r
+{\r
+    struct inflate_state FAR *state;\r
+\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    state = (struct inflate_state FAR *)strm->state;\r
+    if (bits < 0) {\r
+        state->hold = 0;\r
+        state->bits = 0;\r
+        return Z_OK;\r
+    }\r
+    if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;\r
+    value &= (1L << bits) - 1;\r
+    state->hold += value << state->bits;\r
+    state->bits += bits;\r
+    return Z_OK;\r
+}\r
+\r
 /*\r
    Return state with length and distance decoding tables and index sizes set to\r
    fixed code decoding.  Normally this returns fixed tables from inffixed.h.\r
@@ -320,7 +375,7 @@ unsigned out;
     /* if window not in use yet, initialize */\r
     if (state->wsize == 0) {\r
         state->wsize = 1U << state->wbits;\r
-        state->write = 0;\r
+        state->wnext = 0;\r
         state->whave = 0;\r
     }\r
 \r
@@ -328,22 +383,22 @@ unsigned out;
     copy = out - strm->avail_out;\r
     if (copy >= state->wsize) {\r
         zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);\r
-        state->write = 0;\r
+        state->wnext = 0;\r
         state->whave = state->wsize;\r
     }\r
     else {\r
-        dist = state->wsize - state->write;\r
+        dist = state->wsize - state->wnext;\r
         if (dist > copy) dist = copy;\r
-        zmemcpy(state->window + state->write, strm->next_out - copy, dist);\r
+        zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);\r
         copy -= dist;\r
         if (copy) {\r
             zmemcpy(state->window, strm->next_out - copy, copy);\r
-            state->write = copy;\r
+            state->wnext = copy;\r
             state->whave = state->wsize;\r
         }\r
         else {\r
-            state->write += dist;\r
-            if (state->write == state->wsize) state->write = 0;\r
+            state->wnext += dist;\r
+            if (state->wnext == state->wsize) state->wnext = 0;\r
             if (state->whave < state->wsize) state->whave += dist;\r
         }\r
     }\r
@@ -544,7 +599,7 @@ int flush;
     unsigned in, out;           /* save starting available input and output */\r
     unsigned copy;              /* number of stored or match bytes to copy */\r
     unsigned char FAR *from;    /* where to copy match bytes from */\r
-    code this;                  /* current decoding table entry */\r
+    code here;                  /* current decoding table entry */\r
     code last;                  /* parent table entry */\r
     unsigned len;               /* length to copy for repeats, bits to drop */\r
     int ret;                    /* return code */\r
@@ -581,6 +636,8 @@ int flush;
                 break;\r
             }\r
             state->flags = 0;           /* expect zlib header */\r
+            if (state->head != Z_NULL)\r
+                state->head->done = -1;\r
             if (!(state->wrap & 1) ||   /* check if zlib header allowed */\r
 #else\r
             if (\r
@@ -596,11 +653,15 @@ int flush;
                 break;\r
             }\r
             DROPBITS(4);\r
-            if (BITS(4) + 8 > state->wbits) {\r
+            len = BITS(4) + 8;\r
+            if (state->wbits == 0)\r
+                state->wbits = len;\r
+            else if (len > state->wbits) {\r
                 strm->msg = (char *)"invalid window size";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
+            state->dmax = 1U << len;\r
             Tracev((stderr, "inflate:   zlib header ok\n"));\r
             strm->adler = state->check = adler32(0L, Z_NULL, 0);\r
             state->mode = hold & 0x200 ? DICTID : TYPE;\r
@@ -620,16 +681,24 @@ int flush;
                 state->mode = BAD;\r
                 break;\r
             }\r
+            if (state->head != Z_NULL)\r
+                state->head->text = (int)((hold >> 8) & 1);\r
             if (state->flags & 0x0200) CRC2(state->check, hold);\r
             INITBITS();\r
             state->mode = TIME;\r
         case TIME:\r
             NEEDBITS(32);\r
+            if (state->head != Z_NULL)\r
+                state->head->time = hold;\r
             if (state->flags & 0x0200) CRC4(state->check, hold);\r
             INITBITS();\r
             state->mode = OS;\r
         case OS:\r
             NEEDBITS(16);\r
+            if (state->head != Z_NULL) {\r
+                state->head->xflags = (int)(hold & 0xff);\r
+                state->head->os = (int)(hold >> 8);\r
+            }\r
             if (state->flags & 0x0200) CRC2(state->check, hold);\r
             INITBITS();\r
             state->mode = EXLEN;\r
@@ -637,15 +706,26 @@ int flush;
             if (state->flags & 0x0400) {\r
                 NEEDBITS(16);\r
                 state->length = (unsigned)(hold);\r
+                if (state->head != Z_NULL)\r
+                    state->head->extra_len = (unsigned)hold;\r
                 if (state->flags & 0x0200) CRC2(state->check, hold);\r
                 INITBITS();\r
             }\r
+            else if (state->head != Z_NULL)\r
+                state->head->extra = Z_NULL;\r
             state->mode = EXTRA;\r
         case EXTRA:\r
             if (state->flags & 0x0400) {\r
                 copy = state->length;\r
                 if (copy > have) copy = have;\r
                 if (copy) {\r
+                    if (state->head != Z_NULL &&\r
+                        state->head->extra != Z_NULL) {\r
+                        len = state->head->extra_len - state->length;\r
+                        zmemcpy(state->head->extra + len, next,\r
+                                len + copy > state->head->extra_max ?\r
+                                state->head->extra_max - len : copy);\r
+                    }\r
                     if (state->flags & 0x0200)\r
                         state->check = crc32(state->check, next, copy);\r
                     have -= copy;\r
@@ -654,6 +734,7 @@ int flush;
                 }\r
                 if (state->length) goto inf_leave;\r
             }\r
+            state->length = 0;\r
             state->mode = NAME;\r
         case NAME:\r
             if (state->flags & 0x0800) {\r
@@ -661,13 +742,20 @@ int flush;
                 copy = 0;\r
                 do {\r
                     len = (unsigned)(next[copy++]);\r
+                    if (state->head != Z_NULL &&\r
+                            state->head->name != Z_NULL &&\r
+                            state->length < state->head->name_max)\r
+                        state->head->name[state->length++] = len;\r
                 } while (len && copy < have);\r
-                if (state->flags & 0x02000)\r
+                if (state->flags & 0x0200)\r
                     state->check = crc32(state->check, next, copy);\r
                 have -= copy;\r
                 next += copy;\r
                 if (len) goto inf_leave;\r
             }\r
+            else if (state->head != Z_NULL)\r
+                state->head->name = Z_NULL;\r
+            state->length = 0;\r
             state->mode = COMMENT;\r
         case COMMENT:\r
             if (state->flags & 0x1000) {\r
@@ -675,13 +763,19 @@ int flush;
                 copy = 0;\r
                 do {\r
                     len = (unsigned)(next[copy++]);\r
+                    if (state->head != Z_NULL &&\r
+                            state->head->comment != Z_NULL &&\r
+                            state->length < state->head->comm_max)\r
+                        state->head->comment[state->length++] = len;\r
                 } while (len && copy < have);\r
-                if (state->flags & 0x02000)\r
+                if (state->flags & 0x0200)\r
                     state->check = crc32(state->check, next, copy);\r
                 have -= copy;\r
                 next += copy;\r
                 if (len) goto inf_leave;\r
             }\r
+            else if (state->head != Z_NULL)\r
+                state->head->comment = Z_NULL;\r
             state->mode = HCRC;\r
         case HCRC:\r
             if (state->flags & 0x0200) {\r
@@ -693,6 +787,10 @@ int flush;
                 }\r
                 INITBITS();\r
             }\r
+            if (state->head != Z_NULL) {\r
+                state->head->hcrc = (int)((state->flags >> 9) & 1);\r
+                state->head->done = 1;\r
+            }\r
             strm->adler = state->check = crc32(0L, Z_NULL, 0);\r
             state->mode = TYPE;\r
             break;\r
@@ -710,7 +808,7 @@ int flush;
             strm->adler = state->check = adler32(0L, Z_NULL, 0);\r
             state->mode = TYPE;\r
         case TYPE:\r
-            if (flush == Z_BLOCK) goto inf_leave;\r
+            if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;\r
         case TYPEDO:\r
             if (state->last) {\r
                 BYTEBITS();\r
@@ -730,7 +828,11 @@ int flush;
                 fixedtables(state);\r
                 Tracev((stderr, "inflate:     fixed codes block%s\n",\r
                         state->last ? " (last)" : ""));\r
-                state->mode = LEN;              /* decode codes */\r
+                state->mode = LEN_;             /* decode codes */\r
+                if (flush == Z_TREES) {\r
+                    DROPBITS(2);\r
+                    goto inf_leave;\r
+                }\r
                 break;\r
             case 2:                             /* dynamic block */\r
                 Tracev((stderr, "inflate:     dynamic codes block%s\n",\r
@@ -755,6 +857,9 @@ int flush;
             Tracev((stderr, "inflate:       stored length %u\n",\r
                     state->length));\r
             INITBITS();\r
+            state->mode = COPY_;\r
+            if (flush == Z_TREES) goto inf_leave;\r
+        case COPY_:\r
             state->mode = COPY;\r
         case COPY:\r
             copy = state->length;\r
@@ -815,19 +920,19 @@ int flush;
         case CODELENS:\r
             while (state->have < state->nlen + state->ndist) {\r
                 for (;;) {\r
-                    this = state->lencode[BITS(state->lenbits)];\r
-                    if ((unsigned)(this.bits) <= bits) break;\r
+                    here = state->lencode[BITS(state->lenbits)];\r
+                    if ((unsigned)(here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
-                if (this.val < 16) {\r
-                    NEEDBITS(this.bits);\r
-                    DROPBITS(this.bits);\r
-                    state->lens[state->have++] = this.val;\r
+                if (here.val < 16) {\r
+                    NEEDBITS(here.bits);\r
+                    DROPBITS(here.bits);\r
+                    state->lens[state->have++] = here.val;\r
                 }\r
                 else {\r
-                    if (this.val == 16) {\r
-                        NEEDBITS(this.bits + 2);\r
-                        DROPBITS(this.bits);\r
+                    if (here.val == 16) {\r
+                        NEEDBITS(here.bits + 2);\r
+                        DROPBITS(here.bits);\r
                         if (state->have == 0) {\r
                             strm->msg = (char *)"invalid bit length repeat";\r
                             state->mode = BAD;\r
@@ -837,16 +942,16 @@ int flush;
                         copy = 3 + BITS(2);\r
                         DROPBITS(2);\r
                     }\r
-                    else if (this.val == 17) {\r
-                        NEEDBITS(this.bits + 3);\r
-                        DROPBITS(this.bits);\r
+                    else if (here.val == 17) {\r
+                        NEEDBITS(here.bits + 3);\r
+                        DROPBITS(here.bits);\r
                         len = 0;\r
                         copy = 3 + BITS(3);\r
                         DROPBITS(3);\r
                     }\r
                     else {\r
-                        NEEDBITS(this.bits + 7);\r
-                        DROPBITS(this.bits);\r
+                        NEEDBITS(here.bits + 7);\r
+                        DROPBITS(here.bits);\r
                         len = 0;\r
                         copy = 11 + BITS(7);\r
                         DROPBITS(7);\r
@@ -861,7 +966,19 @@ int flush;
                 }\r
             }\r
 \r
-            /* build code tables */\r
+            /* handle error breaks in while */\r
+            if (state->mode == BAD) break;\r
+\r
+            /* check for end-of-block code (better have one) */\r
+            if (state->lens[256] == 0) {\r
+                strm->msg = (char *)"invalid code -- missing end-of-block";\r
+                state->mode = BAD;\r
+                break;\r
+            }\r
+\r
+            /* build code tables -- note: do not change the lenbits or distbits\r
+               values here (9 and 6) without reading the comments in inftrees.h\r
+               concerning the ENOUGH constants, which depend on those values */\r
             state->next = state->codes;\r
             state->lencode = (code const FAR *)(state->next);\r
             state->lenbits = 9;\r
@@ -882,94 +999,110 @@ int flush;
                 break;\r
             }\r
             Tracev((stderr, "inflate:       codes ok\n"));\r
+            state->mode = LEN_;\r
+            if (flush == Z_TREES) goto inf_leave;\r
+        case LEN_:\r
             state->mode = LEN;\r
         case LEN:\r
             if (have >= 6 && left >= 258) {\r
                 RESTORE();\r
                 inflate_fast(strm, out);\r
                 LOAD();\r
+                if (state->mode == TYPE)\r
+                    state->back = -1;\r
                 break;\r
             }\r
+            state->back = 0;\r
             for (;;) {\r
-                this = state->lencode[BITS(state->lenbits)];\r
-                if ((unsigned)(this.bits) <= bits) break;\r
+                here = state->lencode[BITS(state->lenbits)];\r
+                if ((unsigned)(here.bits) <= bits) break;\r
                 PULLBYTE();\r
             }\r
-            if (this.op && (this.op & 0xf0) == 0) {\r
-                last = this;\r
+            if (here.op && (here.op & 0xf0) == 0) {\r
+                last = here;\r
                 for (;;) {\r
-                    this = state->lencode[last.val +\r
+                    here = state->lencode[last.val +\r
                             (BITS(last.bits + last.op) >> last.bits)];\r
-                    if ((unsigned)(last.bits + this.bits) <= bits) break;\r
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
                 DROPBITS(last.bits);\r
+                state->back += last.bits;\r
             }\r
-            DROPBITS(this.bits);\r
-            state->length = (unsigned)this.val;\r
-            if ((int)(this.op) == 0) {\r
-                Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?\r
+            DROPBITS(here.bits);\r
+            state->back += here.bits;\r
+            state->length = (unsigned)here.val;\r
+            if ((int)(here.op) == 0) {\r
+                Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?\r
                         "inflate:         literal '%c'\n" :\r
-                        "inflate:         literal 0x%02x\n", this.val));\r
+                        "inflate:         literal 0x%02x\n", here.val));\r
                 state->mode = LIT;\r
                 break;\r
             }\r
-            if (this.op & 32) {\r
+            if (here.op & 32) {\r
                 Tracevv((stderr, "inflate:         end of block\n"));\r
+                state->back = -1;\r
                 state->mode = TYPE;\r
                 break;\r
             }\r
-            if (this.op & 64) {\r
+            if (here.op & 64) {\r
                 strm->msg = (char *)"invalid literal/length code";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
-            state->extra = (unsigned)(this.op) & 15;\r
+            state->extra = (unsigned)(here.op) & 15;\r
             state->mode = LENEXT;\r
         case LENEXT:\r
             if (state->extra) {\r
                 NEEDBITS(state->extra);\r
                 state->length += BITS(state->extra);\r
                 DROPBITS(state->extra);\r
+                state->back += state->extra;\r
             }\r
             Tracevv((stderr, "inflate:         length %u\n", state->length));\r
+            state->was = state->length;\r
             state->mode = DIST;\r
         case DIST:\r
             for (;;) {\r
-                this = state->distcode[BITS(state->distbits)];\r
-                if ((unsigned)(this.bits) <= bits) break;\r
+                here = state->distcode[BITS(state->distbits)];\r
+                if ((unsigned)(here.bits) <= bits) break;\r
                 PULLBYTE();\r
             }\r
-            if ((this.op & 0xf0) == 0) {\r
-                last = this;\r
+            if ((here.op & 0xf0) == 0) {\r
+                last = here;\r
                 for (;;) {\r
-                    this = state->distcode[last.val +\r
+                    here = state->distcode[last.val +\r
                             (BITS(last.bits + last.op) >> last.bits)];\r
-                    if ((unsigned)(last.bits + this.bits) <= bits) break;\r
+                    if ((unsigned)(last.bits + here.bits) <= bits) break;\r
                     PULLBYTE();\r
                 }\r
                 DROPBITS(last.bits);\r
+                state->back += last.bits;\r
             }\r
-            DROPBITS(this.bits);\r
-            if (this.op & 64) {\r
+            DROPBITS(here.bits);\r
+            state->back += here.bits;\r
+            if (here.op & 64) {\r
                 strm->msg = (char *)"invalid distance code";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
-            state->offset = (unsigned)this.val;\r
-            state->extra = (unsigned)(this.op) & 15;\r
+            state->offset = (unsigned)here.val;\r
+            state->extra = (unsigned)(here.op) & 15;\r
             state->mode = DISTEXT;\r
         case DISTEXT:\r
             if (state->extra) {\r
                 NEEDBITS(state->extra);\r
                 state->offset += BITS(state->extra);\r
                 DROPBITS(state->extra);\r
+                state->back += state->extra;\r
             }\r
-            if (state->offset > state->whave + out - left) {\r
+#ifdef INFLATE_STRICT\r
+            if (state->offset > state->dmax) {\r
                 strm->msg = (char *)"invalid distance too far back";\r
                 state->mode = BAD;\r
                 break;\r
             }\r
+#endif\r
             Tracevv((stderr, "inflate:         distance %u\n", state->offset));\r
             state->mode = MATCH;\r
         case MATCH:\r
@@ -977,12 +1110,32 @@ int flush;
             copy = out - left;\r
             if (state->offset > copy) {         /* copy from window */\r
                 copy = state->offset - copy;\r
-                if (copy > state->write) {\r
-                    copy -= state->write;\r
+                if (copy > state->whave) {\r
+                    if (state->sane) {\r
+                        strm->msg = (char *)"invalid distance too far back";\r
+                        state->mode = BAD;\r
+                        break;\r
+                    }\r
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR\r
+                    Trace((stderr, "inflate.c too far\n"));\r
+                    copy -= state->whave;\r
+                    if (copy > state->length) copy = state->length;\r
+                    if (copy > left) copy = left;\r
+                    left -= copy;\r
+                    state->length -= copy;\r
+                    do {\r
+                        *put++ = 0;\r
+                    } while (--copy);\r
+                    if (state->length == 0) state->mode = LEN;\r
+                    break;\r
+#endif\r
+                }\r
+                if (copy > state->wnext) {\r
+                    copy -= state->wnext;\r
                     from = state->window + (state->wsize - copy);\r
                 }\r
                 else\r
-                    from = state->window + (state->write - copy);\r
+                    from = state->window + (state->wnext - copy);\r
                 if (copy > state->length) copy = state->length;\r
             }\r
             else {                              /* copy from output */\r
@@ -1075,7 +1228,8 @@ int flush;
         strm->adler = state->check =\r
             UPDATE(state->check, strm->next_out - out, out);\r
     strm->data_type = state->bits + (state->last ? 64 : 0) +\r
-                      (state->mode == TYPE ? 128 : 0);\r
+                      (state->mode == TYPE ? 128 : 0) +\r
+                      (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);\r
     if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)\r
         ret = Z_BUF_ERROR;\r
     return ret;\r
@@ -1106,12 +1260,16 @@ uInt dictLength;
     /* check state */\r
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
     state = (struct inflate_state FAR *)strm->state;\r
-    if (state->mode != DICT) return Z_STREAM_ERROR;\r
+    if (state->wrap != 0 && state->mode != DICT)\r
+        return Z_STREAM_ERROR;\r
 \r
     /* check for correct dictionary id */\r
-    id = adler32(0L, Z_NULL, 0);\r
-    id = adler32(id, dictionary, dictLength);\r
-    if (id != state->check) return Z_DATA_ERROR;\r
+    if (state->mode == DICT) {\r
+        id = adler32(0L, Z_NULL, 0);\r
+        id = adler32(id, dictionary, dictLength);\r
+        if (id != state->check)\r
+            return Z_DATA_ERROR;\r
+    }\r
 \r
     /* copy dictionary to window */\r
     if (updatewindow(strm, strm->avail_out)) {\r
@@ -1133,6 +1291,23 @@ uInt dictLength;
     return Z_OK;\r
 }\r
 \r
+int ZEXPORT inflateGetHeader(strm, head)\r
+z_streamp strm;\r
+gz_headerp head;\r
+{\r
+    struct inflate_state FAR *state;\r
+\r
+    /* check state */\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    state = (struct inflate_state FAR *)strm->state;\r
+    if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;\r
+\r
+    /* save header structure */\r
+    state->head = head;\r
+    head->done = 0;\r
+    return Z_OK;\r
+}\r
+\r
 /*\r
    Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found\r
    or when out of input.  When called, *have is the number of pattern bytes\r
@@ -1235,6 +1410,7 @@ z_streamp source;
     struct inflate_state FAR *state;\r
     struct inflate_state FAR *copy;\r
     unsigned char FAR *window;\r
+    unsigned wsize;\r
 \r
     /* check input */\r
     if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||\r
@@ -1257,14 +1433,48 @@ z_streamp source;
     }\r
 \r
     /* copy state */\r
-    *dest = *source;\r
-    *copy = *state;\r
-    copy->lencode = copy->codes + (state->lencode - state->codes);\r
-    copy->distcode = copy->codes + (state->distcode - state->codes);\r
+    zmemcpy(dest, source, sizeof(z_stream));\r
+    zmemcpy(copy, state, sizeof(struct inflate_state));\r
+    if (state->lencode >= state->codes &&\r
+        state->lencode <= state->codes + ENOUGH - 1) {\r
+        copy->lencode = copy->codes + (state->lencode - state->codes);\r
+        copy->distcode = copy->codes + (state->distcode - state->codes);\r
+    }\r
     copy->next = copy->codes + (state->next - state->codes);\r
-    if (window != Z_NULL)\r
-        zmemcpy(window, state->window, 1U << state->wbits);\r
+    if (window != Z_NULL) {\r
+        wsize = 1U << state->wbits;\r
+        zmemcpy(window, state->window, wsize);\r
+    }\r
     copy->window = window;\r
-    dest->state = (voidpf)copy;\r
+    dest->state = (struct internal_state FAR *)copy;\r
+    return Z_OK;\r
+}\r
+\r
+int ZEXPORT inflateUndermine(strm, subvert)\r
+z_streamp strm;\r
+int subvert;\r
+{\r
+    struct inflate_state FAR *state;\r
+\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;\r
+    state = (struct inflate_state FAR *)strm->state;\r
+    state->sane = !subvert;\r
+#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR\r
     return Z_OK;\r
+#else\r
+    state->sane = 1;\r
+    return Z_DATA_ERROR;\r
+#endif\r
+}\r
+\r
+long ZEXPORT inflateMark(strm)\r
+z_streamp strm;\r
+{\r
+    struct inflate_state FAR *state;\r
+\r
+    if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;\r
+    state = (struct inflate_state FAR *)strm->state;\r
+    return ((long)(state->back) << 16) +\r
+        (state->mode == COPY ? state->length :\r
+            (state->mode == MATCH ? state->was - state->length : 0));\r
 }\r
index b696512..a8ef428 100644 (file)
@@ -1,5 +1,5 @@
 /* inflate.h -- internal inflate state definition\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2009 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -19,7 +19,6 @@
 /* Possible inflate modes between inflate() calls */\r
 typedef enum {\r
     HEAD,       /* i: waiting for magic header */\r
-#ifdef GUNZIP\r
     FLAGS,      /* i: waiting for method and flags (gzip) */\r
     TIME,       /* i: waiting for modification time (gzip) */\r
     OS,         /* i: waiting for extra flags and operating system (gzip) */\r
@@ -28,26 +27,25 @@ typedef enum {
     NAME,       /* i: waiting for end of file name (gzip) */\r
     COMMENT,    /* i: waiting for end of comment (gzip) */\r
     HCRC,       /* i: waiting for header crc (gzip) */\r
-#endif\r
     DICTID,     /* i: waiting for dictionary check value */\r
     DICT,       /* waiting for inflateSetDictionary() call */\r
         TYPE,       /* i: waiting for type bits, including last-flag bit */\r
         TYPEDO,     /* i: same, but skip check to exit inflate on new block */\r
         STORED,     /* i: waiting for stored size (length and complement) */\r
+        COPY_,      /* i/o: same as COPY below, but only first time in */\r
         COPY,       /* i/o: waiting for input or output to copy stored block */\r
         TABLE,      /* i: waiting for dynamic block table lengths */\r
         LENLENS,    /* i: waiting for code length code lengths */\r
         CODELENS,   /* i: waiting for length/lit and distance code lengths */\r
-            LEN,        /* i: waiting for length/lit code */\r
+            LEN_,       /* i: same as LEN below, but only first time in */\r
+            LEN,        /* i: waiting for length/lit/eob code */\r
             LENEXT,     /* i: waiting for length extra bits */\r
             DIST,       /* i: waiting for distance code */\r
             DISTEXT,    /* i: waiting for distance extra bits */\r
             MATCH,      /* o: waiting for output space to copy string */\r
             LIT,        /* o: waiting for output space to write literal */\r
     CHECK,      /* i: waiting for 32-bit check value */\r
-#ifdef GUNZIP\r
     LENGTH,     /* i: waiting for 32-bit length (gzip) */\r
-#endif\r
     DONE,       /* finished check, done -- remain here until reset */\r
     BAD,        /* got a data error -- remain here until reset */\r
     MEM,        /* got an inflate() memory error -- remain here until reset */\r
@@ -57,19 +55,21 @@ typedef enum {
 /*\r
     State transitions between above modes -\r
 \r
-    (most modes can go to the BAD or MEM mode -- not shown for clarity)\r
+    (most modes can go to BAD or MEM on error -- not shown for clarity)\r
 \r
     Process header:\r
-        HEAD -> (gzip) or (zlib)\r
-        (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME\r
-        NAME -> COMMENT -> HCRC -> TYPE\r
+        HEAD -> (gzip) or (zlib) or (raw)\r
+        (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->\r
+                  HCRC -> TYPE\r
         (zlib) -> DICTID or TYPE\r
         DICTID -> DICT -> TYPE\r
+        (raw) -> TYPEDO\r
     Read deflate blocks:\r
-            TYPE -> STORED or TABLE or LEN or CHECK\r
-            STORED -> COPY -> TYPE\r
-            TABLE -> LENLENS -> CODELENS -> LEN\r
-    Read deflate codes:\r
+            TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK\r
+            STORED -> COPY_ -> COPY -> TYPE\r
+            TABLE -> LENLENS -> CODELENS -> LEN_\r
+            LEN_ -> LEN\r
+    Read deflate codes in fixed or dynamic block:\r
                 LEN -> LENEXT or LIT or TYPE\r
                 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN\r
                 LIT -> LEN\r
@@ -77,20 +77,22 @@ typedef enum {
         CHECK -> LENGTH -> DONE\r
  */\r
 \r
-/* state maintained between inflate() calls.  Approximately 7K bytes. */\r
+/* state maintained between inflate() calls.  Approximately 10K bytes. */\r
 struct inflate_state {\r
     inflate_mode mode;          /* current inflate mode */\r
     int last;                   /* true if processing last block */\r
     int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */\r
     int havedict;               /* true if dictionary provided */\r
     int flags;                  /* gzip header method and flags (0 if zlib) */\r
+    unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */\r
     unsigned long check;        /* protected copy of check value */\r
     unsigned long total;        /* protected copy of output count */\r
+    gz_headerp head;            /* where to save gzip header information */\r
         /* sliding window */\r
     unsigned wbits;             /* log base 2 of requested window size */\r
     unsigned wsize;             /* window size or zero if not using window */\r
     unsigned whave;             /* valid bytes in the window */\r
-    unsigned write;             /* window write index */\r
+    unsigned wnext;             /* window write index */\r
     unsigned char FAR *window;  /* allocated sliding window, if needed */\r
         /* bit accumulator */\r
     unsigned long hold;         /* input bit accumulator */\r
@@ -114,4 +116,7 @@ struct inflate_state {
     unsigned short lens[320];   /* temporary storage for code lengths */\r
     unsigned short work[288];   /* work area for code table building */\r
     code codes[ENOUGH];         /* space for code tables */\r
+    int sane;                   /* if false, allow invalid distance too far */\r
+    int back;                   /* bits back of last unprocessed length/lit */\r
+    unsigned was;               /* initial length of match */\r
 };\r
index 55fd27b..9dbaec3 100644 (file)
@@ -1,5 +1,5 @@
 /* inftrees.c -- generate Huffman trees for efficient decoding\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -9,7 +9,7 @@
 #define MAXBITS 15\r
 \r
 const char inflate_copyright[] =\r
-   " inflate 1.2.1 Copyright 1995-2003 Mark Adler ";\r
+   " inflate 1.2.5 Copyright 1995-2010 Mark Adler ";\r
 /*\r
   If you use the zlib library in a product, an acknowledgment is welcome\r
   in the documentation of your product. If for some reason you cannot\r
@@ -29,7 +29,7 @@ const char inflate_copyright[] =
    table index bits.  It will differ if the request is greater than the\r
    longest code or if it is less than the shortest code.\r
  */\r
-int inflate_table(type, lens, codes, table, bits, work)\r
+int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)\r
 codetype type;\r
 unsigned short FAR *lens;\r
 unsigned codes;\r
@@ -50,7 +50,7 @@ unsigned short FAR *work;
     unsigned fill;              /* index for replicating entries */\r
     unsigned low;               /* low bits for current root entry */\r
     unsigned mask;              /* mask for low root bits */\r
-    code this;                  /* table entry for duplication */\r
+    code here;                  /* table entry for duplication */\r
     code FAR *next;             /* next available space in table */\r
     const unsigned short FAR *base;     /* base value table to use */\r
     const unsigned short FAR *extra;    /* extra bits table to use */\r
@@ -62,7 +62,7 @@ unsigned short FAR *work;
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};\r
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */\r
         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,\r
-        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 76, 66};\r
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195};\r
     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */\r
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\r
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\r
@@ -114,8 +114,16 @@ unsigned short FAR *work;
     for (max = MAXBITS; max >= 1; max--)\r
         if (count[max] != 0) break;\r
     if (root > max) root = max;\r
-    if (max == 0) return -1;            /* no codes! */\r
-    for (min = 1; min <= MAXBITS; min++)\r
+    if (max == 0) {                     /* no symbols to code at all */\r
+        here.op = (unsigned char)64;    /* invalid code marker */\r
+        here.bits = (unsigned char)1;\r
+        here.val = (unsigned short)0;\r
+        *(*table)++ = here;             /* make a table to force an error */\r
+        *(*table)++ = here;\r
+        *bits = 1;\r
+        return 0;     /* no symbols, but wait for decoding to report error */\r
+    }\r
+    for (min = 1; min < max; min++)\r
         if (count[min] != 0) break;\r
     if (root < min) root = min;\r
 \r
@@ -126,7 +134,7 @@ unsigned short FAR *work;
         left -= count[len];\r
         if (left < 0) return -1;        /* over-subscribed */\r
     }\r
-    if (left > 0 && (type == CODES || (codes - count[0] != 1)))\r
+    if (left > 0 && (type == CODES || max != 1))\r
         return -1;                      /* incomplete set */\r
 \r
     /* generate offsets into symbol table for each length for sorting */\r
@@ -158,11 +166,10 @@ unsigned short FAR *work;
        entered in the tables.\r
 \r
        used keeps track of how many table entries have been allocated from the\r
-       provided *table space.  It is checked when a LENS table is being made\r
-       against the space in *table, ENOUGH, minus the maximum space needed by\r
-       the worst case distance code, MAXD.  This should never happen, but the\r
-       sufficiency of ENOUGH has not been proven exhaustively, hence the check.\r
-       This assumes that when type == LENS, bits == 9.\r
+       provided *table space.  It is checked for LENS and DIST tables against\r
+       the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in\r
+       the initial root table size constants.  See the comments in inftrees.h\r
+       for more information.\r
 \r
        sym increments through all symbols, and the loop terminates when\r
        all codes of length max, i.e. all codes, have been processed.  This\r
@@ -201,32 +208,34 @@ unsigned short FAR *work;
     mask = used - 1;            /* mask for comparing low */\r
 \r
     /* check available table space */\r
-    if (type == LENS && used >= ENOUGH - MAXD)\r
+    if ((type == LENS && used >= ENOUGH_LENS) ||\r
+        (type == DISTS && used >= ENOUGH_DISTS))\r
         return 1;\r
 \r
     /* process all codes and make table entries */\r
     for (;;) {\r
         /* create table entry */\r
-        this.bits = (unsigned char)(len - drop);\r
+        here.bits = (unsigned char)(len - drop);\r
         if ((int)(work[sym]) < end) {\r
-            this.op = (unsigned char)0;\r
-            this.val = work[sym];\r
+            here.op = (unsigned char)0;\r
+            here.val = work[sym];\r
         }\r
         else if ((int)(work[sym]) > end) {\r
-            this.op = (unsigned char)(extra[work[sym]]);\r
-            this.val = base[work[sym]];\r
+            here.op = (unsigned char)(extra[work[sym]]);\r
+            here.val = base[work[sym]];\r
         }\r
         else {\r
-            this.op = (unsigned char)(32 + 64);         /* end of block */\r
-            this.val = 0;\r
+            here.op = (unsigned char)(32 + 64);         /* end of block */\r
+            here.val = 0;\r
         }\r
 \r
         /* replicate for those indices with low len bits equal to huff */\r
         incr = 1U << (len - drop);\r
         fill = 1U << curr;\r
+        min = fill;                 /* save offset to next table */\r
         do {\r
             fill -= incr;\r
-            next[(huff >> drop) + fill] = this;\r
+            next[(huff >> drop) + fill] = here;\r
         } while (fill != 0);\r
 \r
         /* backwards increment the len-bit code huff */\r
@@ -254,7 +263,7 @@ unsigned short FAR *work;
                 drop = root;\r
 \r
             /* increment past last table */\r
-            next += 1U << curr;\r
+            next += min;            /* here min is 1 << curr */\r
 \r
             /* determine length of next table */\r
             curr = len - drop;\r
@@ -268,7 +277,8 @@ unsigned short FAR *work;
 \r
             /* check for enough space */\r
             used += 1U << curr;\r
-            if (type == LENS && used >= ENOUGH - MAXD)\r
+            if ((type == LENS && used >= ENOUGH_LENS) ||\r
+                (type == DISTS && used >= ENOUGH_DISTS))\r
                 return 1;\r
 \r
             /* point entry in root table to sub-table */\r
@@ -286,21 +296,20 @@ unsigned short FAR *work;
        through high index bits.  When the current sub-table is filled, the loop\r
        drops back to the root table to fill in any remaining entries there.\r
      */\r
-    this.op = (unsigned char)64;                /* invalid code marker */\r
-    this.bits = (unsigned char)(len - drop);\r
-    this.val = (unsigned short)0;\r
+    here.op = (unsigned char)64;                /* invalid code marker */\r
+    here.bits = (unsigned char)(len - drop);\r
+    here.val = (unsigned short)0;\r
     while (huff != 0) {\r
         /* when done with sub-table, drop back to root table */\r
         if (drop != 0 && (huff & mask) != low) {\r
             drop = 0;\r
             len = root;\r
             next = *table;\r
-            curr = root;\r
-            this.bits = (unsigned char)len;\r
+            here.bits = (unsigned char)len;\r
         }\r
 \r
         /* put invalid code marker in table */\r
-        next[huff >> drop] = this;\r
+        next[huff >> drop] = here;\r
 \r
         /* backwards increment the len-bit code huff */\r
         incr = 1U << (len - 1);\r
index 1dbfe53..a685d8c 100644 (file)
@@ -1,5 +1,5 @@
 /* inftrees.h -- header to use inftrees.c\r
- * Copyright (C) 1995-2003 Mark Adler\r
+ * Copyright (C) 1995-2005, 2010 Mark Adler\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -35,21 +35,28 @@ typedef struct {
     01000000 - invalid code\r
  */\r
 \r
-/* Maximum size of dynamic tree.  The maximum found in a long but non-\r
-   exhaustive search was 1004 code structures (850 for length/literals\r
-   and 154 for distances, the latter actually the result of an\r
-   exhaustive search).  The true maximum is not known, but the value\r
-   below is more than safe. */\r
-#define ENOUGH 1440\r
-#define MAXD 154\r
+/* Maximum size of the dynamic table.  The maximum number of code structures is\r
+   1444, which is the sum of 852 for literal/length codes and 592 for distance\r
+   codes.  These values were found by exhaustive searches using the program\r
+   examples/enough.c found in the zlib distribtution.  The arguments to that\r
+   program are the number of symbols, the initial root table size, and the\r
+   maximum bit length of a code.  "enough 286 9 15" for literal/length codes\r
+   returns returns 852, and "enough 30 6 15" for distance codes returns 592.\r
+   The initial root table size (9 or 6) is found in the fifth argument of the\r
+   inflate_table() calls in inflate.c and infback.c.  If the root table size is\r
+   changed, then these maximum sizes would be need to be recalculated and\r
+   updated. */\r
+#define ENOUGH_LENS 852\r
+#define ENOUGH_DISTS 592\r
+#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)\r
 \r
-/* Type of code to build for inftable() */\r
+/* Type of code to build for inflate_table() */\r
 typedef enum {\r
     CODES,\r
     LENS,\r
     DISTS\r
 } codetype;\r
 \r
-extern int inflate_table OF((codetype type, unsigned short FAR *lens,\r
+int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,\r
                              unsigned codes, code FAR * FAR *table,\r
                              unsigned FAR *bits, unsigned short FAR *work));\r
index 1d36eaa..b4a317a 100644 (file)
@@ -1,5 +1,6 @@
 /* trees.c -- output deflated data using Huffman coding\r
- * Copyright (C) 1995-2003 Jean-loup Gailly\r
+ * Copyright (C) 1995-2010 Jean-loup Gailly\r
+ * detect_data_type() function provided freely by Cosmin Truta, 2006\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
@@ -152,7 +153,7 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
                               int blcodes));\r
 local void compress_block OF((deflate_state *s, ct_data *ltree,\r
                               ct_data *dtree));\r
-local void set_data_type  OF((deflate_state *s));\r
+local int  detect_data_type OF((deflate_state *s));\r
 local unsigned bi_reverse OF((unsigned value, int length));\r
 local void bi_windup      OF((deflate_state *s));\r
 local void bi_flush       OF((deflate_state *s));\r
@@ -203,12 +204,12 @@ local void send_bits(s, value, length)
      * unused bits in value.\r
      */\r
     if (s->bi_valid > (int)Buf_size - length) {\r
-        s->bi_buf |= (value << s->bi_valid);\r
+        s->bi_buf |= (ush)value << s->bi_valid;\r
         put_short(s, s->bi_buf);\r
         s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);\r
         s->bi_valid += length - Buf_size;\r
     } else {\r
-        s->bi_buf |= value << s->bi_valid;\r
+        s->bi_buf |= (ush)value << s->bi_valid;\r
         s->bi_valid += length;\r
     }\r
 }\r
@@ -218,12 +219,12 @@ local void send_bits(s, value, length)
 { int len = length;\\r
   if (s->bi_valid > (int)Buf_size - len) {\\r
     int val = value;\\r
-    s->bi_buf |= (val << s->bi_valid);\\r
+    s->bi_buf |= (ush)val << s->bi_valid;\\r
     put_short(s, s->bi_buf);\\r
     s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\\r
     s->bi_valid += len - Buf_size;\\r
   } else {\\r
-    s->bi_buf |= (value) << s->bi_valid;\\r
+    s->bi_buf |= (ush)(value) << s->bi_valid;\\r
     s->bi_valid += len;\\r
   }\\r
 }\r
@@ -250,11 +251,13 @@ local void tr_static_init()
     if (static_init_done) return;\r
 \r
     /* For some embedded targets, global variables are not initialized: */\r
+#ifdef NO_INIT_GLOBAL_POINTERS\r
     static_l_desc.static_tree = static_ltree;\r
     static_l_desc.extra_bits = extra_lbits;\r
     static_d_desc.static_tree = static_dtree;\r
     static_d_desc.extra_bits = extra_dbits;\r
     static_bl_desc.extra_bits = extra_blbits;\r
+#endif\r
 \r
     /* Initialize the mapping length (0..255) -> length code (0..28) */\r
     length = 0;\r
@@ -348,13 +351,14 @@ void gen_trees_header()
                 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));\r
     }\r
 \r
-    fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");\r
+    fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");\r
     for (i = 0; i < DIST_CODE_LEN; i++) {\r
         fprintf(header, "%2u%s", _dist_code[i],\r
                 SEPARATOR(i, DIST_CODE_LEN-1, 20));\r
     }\r
 \r
-    fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");\r
+    fprintf(header,\r
+        "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");\r
     for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {\r
         fprintf(header, "%2u%s", _length_code[i],\r
                 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));\r
@@ -379,7 +383,7 @@ void gen_trees_header()
 /* ===========================================================================\r
  * Initialize the tree data structures for a new zlib stream.\r
  */\r
-void _tr_init(s)\r
+void ZLIB_INTERNAL _tr_init(s)\r
     deflate_state *s;\r
 {\r
     tr_static_init();\r
@@ -555,7 +559,7 @@ local void gen_bitlen(s, desc)
         while (n != 0) {\r
             m = s->heap[--h];\r
             if (m > max_code) continue;\r
-            if (tree[m].Len != (unsigned) bits) {\r
+            if ((unsigned) tree[m].Len != (unsigned) bits) {\r
                 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));\r
                 s->opt_len += ((long)bits - (long)tree[m].Len)\r
                               *(long)tree[m].Freq;\r
@@ -864,13 +868,13 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
 /* ===========================================================================\r
  * Send a stored block\r
  */\r
-void _tr_stored_block(s, buf, stored_len, eof)\r
+void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)\r
     deflate_state *s;\r
     charf *buf;       /* input block */\r
     ulg stored_len;   /* length of input block */\r
-    int eof;          /* true if this is the last block for a file */\r
+    int last;         /* one if this is the last block for a file */\r
 {\r
-    send_bits(s, (STORED_BLOCK<<1)+eof, 3);  /* send block type */\r
+    send_bits(s, (STORED_BLOCK<<1)+last, 3);    /* send block type */\r
 #ifdef DEBUG\r
     s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;\r
     s->compressed_len += (stored_len + 4) << 3;\r
@@ -889,7 +893,7 @@ void _tr_stored_block(s, buf, stored_len, eof)
  * To simplify the code, we assume the worst case of last real code encoded\r
  * on one bit only.\r
  */\r
-void _tr_align(s)\r
+void ZLIB_INTERNAL _tr_align(s)\r
     deflate_state *s;\r
 {\r
     send_bits(s, STATIC_TREES<<1, 3);\r
@@ -918,11 +922,11 @@ void _tr_align(s)
  * Determine the best encoding for the current block: dynamic trees, static\r
  * trees or store, and output the encoded block to the zip file.\r
  */\r
-void _tr_flush_block(s, buf, stored_len, eof)\r
+void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)\r
     deflate_state *s;\r
     charf *buf;       /* input block, or NULL if too old */\r
     ulg stored_len;   /* length of input block */\r
-    int eof;          /* true if this is the last block for a file */\r
+    int last;         /* one if this is the last block for a file */\r
 {\r
     ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */\r
     int max_blindex = 0;  /* index of last bit length code of non zero freq */\r
@@ -930,8 +934,9 @@ void _tr_flush_block(s, buf, stored_len, eof)
     /* Build the Huffman trees unless a stored block is forced */\r
     if (s->level > 0) {\r
 \r
-         /* Check if the file is ascii or binary */\r
-        if (s->data_type == Z_UNKNOWN) set_data_type(s);\r
+        /* Check if the file is binary or text */\r
+        if (s->strm->data_type == Z_UNKNOWN)\r
+            s->strm->data_type = detect_data_type(s);\r
 \r
         /* Construct the literal and distance trees */\r
         build_tree(s, (tree_desc *)(&(s->l_desc)));\r
@@ -977,20 +982,20 @@ void _tr_flush_block(s, buf, stored_len, eof)
          * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to\r
          * transform a block into a stored block.\r
          */\r
-        _tr_stored_block(s, buf, stored_len, eof);\r
+        _tr_stored_block(s, buf, stored_len, last);\r
 \r
 #ifdef FORCE_STATIC\r
     } else if (static_lenb >= 0) { /* force static trees */\r
 #else\r
-    } else if (static_lenb == opt_lenb) {\r
+    } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {\r
 #endif\r
-        send_bits(s, (STATIC_TREES<<1)+eof, 3);\r
+        send_bits(s, (STATIC_TREES<<1)+last, 3);\r
         compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);\r
 #ifdef DEBUG\r
         s->compressed_len += 3 + s->static_len;\r
 #endif\r
     } else {\r
-        send_bits(s, (DYN_TREES<<1)+eof, 3);\r
+        send_bits(s, (DYN_TREES<<1)+last, 3);\r
         send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,\r
                        max_blindex+1);\r
         compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);\r
@@ -1004,21 +1009,21 @@ void _tr_flush_block(s, buf, stored_len, eof)
      */\r
     init_block(s);\r
 \r
-    if (eof) {\r
+    if (last) {\r
         bi_windup(s);\r
 #ifdef DEBUG\r
         s->compressed_len += 7;  /* align on byte boundary */\r
 #endif\r
     }\r
     Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,\r
-           s->compressed_len-7*eof));\r
+           s->compressed_len-7*last));\r
 }\r
 \r
 /* ===========================================================================\r
  * Save the match info and tally the frequency counts. Return true if\r
  * the current block must be flushed.\r
  */\r
-int _tr_tally (s, dist, lc)\r
+int ZLIB_INTERNAL _tr_tally (s, dist, lc)\r
     deflate_state *s;\r
     unsigned dist;  /* distance of matched string */\r
     unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */\r
@@ -1117,21 +1122,45 @@ local void compress_block(s, ltree, dtree)
 }\r
 \r
 /* ===========================================================================\r
- * Set the data type to ASCII or BINARY, using a crude approximation:\r
- * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.\r
- * IN assertion: the fields freq of dyn_ltree are set and the total of all\r
- * frequencies does not exceed 64K (to fit in an int on 16 bit machines).\r
+ * Check if the data type is TEXT or BINARY, using the following algorithm:\r
+ * - TEXT if the two conditions below are satisfied:\r
+ *    a) There are no non-portable control characters belonging to the\r
+ *       "black list" (0..6, 14..25, 28..31).\r
+ *    b) There is at least one printable character belonging to the\r
+ *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).\r
+ * - BINARY otherwise.\r
+ * - The following partially-portable control characters form a\r
+ *   "gray list" that is ignored in this detection algorithm:\r
+ *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).\r
+ * IN assertion: the fields Freq of dyn_ltree are set.\r
  */\r
-local void set_data_type(s)\r
+local int detect_data_type(s)\r
     deflate_state *s;\r
 {\r
-    int n = 0;\r
-    unsigned ascii_freq = 0;\r
-    unsigned bin_freq = 0;\r
-    while (n < 7)        bin_freq += s->dyn_ltree[n++].Freq;\r
-    while (n < 128)    ascii_freq += s->dyn_ltree[n++].Freq;\r
-    while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;\r
-    s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);\r
+    /* black_mask is the bit mask of black-listed bytes\r
+     * set bits 0..6, 14..25, and 28..31\r
+     * 0xf3ffc07f = binary 11110011111111111100000001111111\r
+     */\r
+    unsigned long black_mask = 0xf3ffc07fUL;\r
+    int n;\r
+\r
+    /* Check for non-textual ("black-listed") bytes. */\r
+    for (n = 0; n <= 31; n++, black_mask >>= 1)\r
+        if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))\r
+            return Z_BINARY;\r
+\r
+    /* Check for textual ("white-listed") bytes. */\r
+    if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0\r
+            || s->dyn_ltree[13].Freq != 0)\r
+        return Z_TEXT;\r
+    for (n = 32; n < LITERALS; n++)\r
+        if (s->dyn_ltree[n].Freq != 0)\r
+            return Z_TEXT;\r
+\r
+    /* There are no "black-listed" or "white-listed" bytes:\r
+     * this stream either is empty or has tolerated ("gray-listed") bytes only.\r
+     */\r
+    return Z_BINARY;\r
 }\r
 \r
 /* ===========================================================================\r
index 1ca868b..ce8f620 100644 (file)
@@ -70,7 +70,7 @@ local const ct_data static_dtree[D_CODES] = {
 {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}\r
 };\r
 \r
-const uch _dist_code[DIST_CODE_LEN] = {\r
+const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\r
  0,  1,  2,  3,  4,  4,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  8,\r
  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10,\r
 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,\r
@@ -99,7 +99,7 @@ const uch _dist_code[DIST_CODE_LEN] = {
 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29\r
 };\r
 \r
-const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\r
+const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\r
  0,  1,  2,  3,  4,  5,  6,  7,  8,  8,  9,  9, 10, 10, 11, 11, 12, 12, 12, 12,\r
 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,\r
 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,\r
index 57dd24a..f07773c 100644 (file)
@@ -1,10 +1,11 @@
 /* uncompr.c -- decompress a memory buffer\r
- * Copyright (C) 1995-2002 Jean-loup Gailly.\r
- * For conditions of distribution and use, see copyright notice in zlib.h \r
+ * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.\r
+ * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 /* @(#) $Id$ */\r
 \r
+#define ZLIB_INTERNAL\r
 #include "zlib.h"\r
 \r
 /* ===========================================================================\r
@@ -15,8 +16,6 @@
    been saved previously by the compressor and transmitted to the decompressor\r
    by some mechanism outside the scope of this compression library.)\r
    Upon exit, destLen is the actual size of the compressed buffer.\r
-     This function can be used to decompress a whole file at once if the\r
-   input file is mmap'ed.\r
 \r
      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not\r
    enough memory, Z_BUF_ERROR if there was not enough room in the output\r
@@ -49,7 +48,9 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
     err = inflate(&stream, Z_FINISH);\r
     if (err != Z_STREAM_END) {\r
         inflateEnd(&stream);\r
-        return err == Z_OK ? Z_BUF_ERROR : err;\r
+        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))\r
+            return Z_DATA_ERROR;\r
+        return err;\r
     }\r
     *destLen = stream.total_out;\r
 \r
index 759d757..88f90f9 100644 (file)
@@ -1,5 +1,5 @@
 /* zconf.h -- configuration of the zlib compression library\r
- * Copyright (C) 1995-2003 Jean-loup Gailly.\r
+ * Copyright (C) 1995-2010 Jean-loup Gailly.\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 /*\r
  * If you *really* need a unique prefix for all types and library functions,\r
  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.\r
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set\r
+ * this permanently in zconf.h using "./configure --zprefix".\r
  */\r
-#ifdef Z_PREFIX\r
-#  define deflateInit_  z_deflateInit_\r
-#  define deflate       z_deflate\r
-#  define deflateEnd    z_deflateEnd\r
-#  define inflateInit_  z_inflateInit_\r
-#  define inflate       z_inflate\r
-#  define inflateEnd    z_inflateEnd\r
-#  define deflateInit2_ z_deflateInit2_\r
-#  define deflateSetDictionary z_deflateSetDictionary\r
-#  define deflateCopy   z_deflateCopy\r
-#  define deflateReset  z_deflateReset\r
-#  define deflatePrime  z_deflatePrime\r
-#  define deflateParams z_deflateParams\r
-#  define deflateBound  z_deflateBound\r
-#  define inflateInit2_ z_inflateInit2_\r
-#  define inflateSetDictionary z_inflateSetDictionary\r
-#  define inflateSync   z_inflateSync\r
-#  define inflateSyncPoint z_inflateSyncPoint\r
-#  define inflateCopy   z_inflateCopy\r
-#  define inflateReset  z_inflateReset\r
-#  define compress      z_compress\r
-#  define compress2     z_compress2\r
-#  define compressBound z_compressBound\r
-#  define uncompress    z_uncompress\r
-#  define adler32       z_adler32\r
-#  define crc32         z_crc32\r
-#  define get_crc_table z_get_crc_table\r
-\r
-#  define Byte          z_Byte\r
-#  define uInt          z_uInt\r
-#  define uLong         z_uLong\r
-#  define Bytef         z_Bytef\r
-#  define charf         z_charf\r
-#  define intf          z_intf\r
-#  define uIntf         z_uIntf\r
-#  define uLongf        z_uLongf\r
-#  define voidpf        z_voidpf\r
-#  define voidp         z_voidp\r
+#ifdef Z_PREFIX     /* may be set to #if 1 by ./configure */\r
+\r
+/* all linked symbols */\r
+#  define _dist_code            z__dist_code\r
+#  define _length_code          z__length_code\r
+#  define _tr_align             z__tr_align\r
+#  define _tr_flush_block       z__tr_flush_block\r
+#  define _tr_init              z__tr_init\r
+#  define _tr_stored_block      z__tr_stored_block\r
+#  define _tr_tally             z__tr_tally\r
+#  define adler32               z_adler32\r
+#  define adler32_combine       z_adler32_combine\r
+#  define adler32_combine64     z_adler32_combine64\r
+#  define compress              z_compress\r
+#  define compress2             z_compress2\r
+#  define compressBound         z_compressBound\r
+#  define crc32                 z_crc32\r
+#  define crc32_combine         z_crc32_combine\r
+#  define crc32_combine64       z_crc32_combine64\r
+#  define deflate               z_deflate\r
+#  define deflateBound          z_deflateBound\r
+#  define deflateCopy           z_deflateCopy\r
+#  define deflateEnd            z_deflateEnd\r
+#  define deflateInit2_         z_deflateInit2_\r
+#  define deflateInit_          z_deflateInit_\r
+#  define deflateParams         z_deflateParams\r
+#  define deflatePrime          z_deflatePrime\r
+#  define deflateReset          z_deflateReset\r
+#  define deflateSetDictionary  z_deflateSetDictionary\r
+#  define deflateSetHeader      z_deflateSetHeader\r
+#  define deflateTune           z_deflateTune\r
+#  define deflate_copyright     z_deflate_copyright\r
+#  define get_crc_table         z_get_crc_table\r
+#  define gz_error              z_gz_error\r
+#  define gz_intmax             z_gz_intmax\r
+#  define gz_strwinerror        z_gz_strwinerror\r
+#  define gzbuffer              z_gzbuffer\r
+#  define gzclearerr            z_gzclearerr\r
+#  define gzclose               z_gzclose\r
+#  define gzclose_r             z_gzclose_r\r
+#  define gzclose_w             z_gzclose_w\r
+#  define gzdirect              z_gzdirect\r
+#  define gzdopen               z_gzdopen\r
+#  define gzeof                 z_gzeof\r
+#  define gzerror               z_gzerror\r
+#  define gzflush               z_gzflush\r
+#  define gzgetc                z_gzgetc\r
+#  define gzgets                z_gzgets\r
+#  define gzoffset              z_gzoffset\r
+#  define gzoffset64            z_gzoffset64\r
+#  define gzopen                z_gzopen\r
+#  define gzopen64              z_gzopen64\r
+#  define gzprintf              z_gzprintf\r
+#  define gzputc                z_gzputc\r
+#  define gzputs                z_gzputs\r
+#  define gzread                z_gzread\r
+#  define gzrewind              z_gzrewind\r
+#  define gzseek                z_gzseek\r
+#  define gzseek64              z_gzseek64\r
+#  define gzsetparams           z_gzsetparams\r
+#  define gztell                z_gztell\r
+#  define gztell64              z_gztell64\r
+#  define gzungetc              z_gzungetc\r
+#  define gzwrite               z_gzwrite\r
+#  define inflate               z_inflate\r
+#  define inflateBack           z_inflateBack\r
+#  define inflateBackEnd        z_inflateBackEnd\r
+#  define inflateBackInit_      z_inflateBackInit_\r
+#  define inflateCopy           z_inflateCopy\r
+#  define inflateEnd            z_inflateEnd\r
+#  define inflateGetHeader      z_inflateGetHeader\r
+#  define inflateInit2_         z_inflateInit2_\r
+#  define inflateInit_          z_inflateInit_\r
+#  define inflateMark           z_inflateMark\r
+#  define inflatePrime          z_inflatePrime\r
+#  define inflateReset          z_inflateReset\r
+#  define inflateReset2         z_inflateReset2\r
+#  define inflateSetDictionary  z_inflateSetDictionary\r
+#  define inflateSync           z_inflateSync\r
+#  define inflateSyncPoint      z_inflateSyncPoint\r
+#  define inflateUndermine      z_inflateUndermine\r
+#  define inflate_copyright     z_inflate_copyright\r
+#  define inflate_fast          z_inflate_fast\r
+#  define inflate_table         z_inflate_table\r
+#  define uncompress            z_uncompress\r
+#  define zError                z_zError\r
+#  define zcalloc               z_zcalloc\r
+#  define zcfree                z_zcfree\r
+#  define zlibCompileFlags      z_zlibCompileFlags\r
+#  define zlibVersion           z_zlibVersion\r
+\r
+/* all zlib typedefs in zlib.h and zconf.h */\r
+#  define Byte                  z_Byte\r
+#  define Bytef                 z_Bytef\r
+#  define alloc_func            z_alloc_func\r
+#  define charf                 z_charf\r
+#  define free_func             z_free_func\r
+#  define gzFile                z_gzFile\r
+#  define gz_header             z_gz_header\r
+#  define gz_headerp            z_gz_headerp\r
+#  define in_func               z_in_func\r
+#  define intf                  z_intf\r
+#  define out_func              z_out_func\r
+#  define uInt                  z_uInt\r
+#  define uIntf                 z_uIntf\r
+#  define uLong                 z_uLong\r
+#  define uLongf                z_uLongf\r
+#  define voidp                 z_voidp\r
+#  define voidpc                z_voidpc\r
+#  define voidpf                z_voidpf\r
+\r
+/* all zlib structs in zlib.h and zconf.h */\r
+#  define gz_header_s           z_gz_header_s\r
+#  define internal_state        z_internal_state\r
+\r
 #endif\r
 \r
 #if defined(__MSDOS__) && !defined(MSDOS)\r
 #if defined(_WINDOWS) && !defined(WINDOWS)\r
 #  define WINDOWS\r
 #endif\r
-#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)\r
-#  define WIN32\r
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)\r
+#  ifndef WIN32\r
+#    define WIN32\r
+#  endif\r
 #endif\r
 #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)\r
 #  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)\r
@@ -275,49 +356,73 @@ typedef uLong FAR uLongf;
    typedef Byte       *voidp;\r
 #endif\r
 \r
-#if 0           /* HAVE_UNISTD_H -- this line is updated by ./configure */\r
-#  include <sys/types.h> /* for off_t */\r
-#  include <unistd.h>    /* for SEEK_* and off_t */\r
+#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */\r
+#  define Z_HAVE_UNISTD_H\r
+#endif\r
+\r
+#ifdef STDC\r
+#  include <sys/types.h>    /* for off_t */\r
+#endif\r
+\r
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and\r
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even\r
+ * though the former does not conform to the LFS document), but considering\r
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as\r
+ * equivalently requesting no 64-bit operations\r
+ */\r
+#if -_LARGEFILE64_SOURCE - -1 == 1\r
+#  undef _LARGEFILE64_SOURCE\r
+#endif\r
+\r
+#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)\r
+#  include <unistd.h>       /* for SEEK_* and off_t */\r
 #  ifdef VMS\r
-#    include <unixio.h>   /* for off_t */\r
+#    include <unixio.h>     /* for off_t */\r
+#  endif\r
+#  ifndef z_off_t\r
+#    define z_off_t off_t\r
 #  endif\r
-#  define z_off_t  off_t\r
 #endif\r
+\r
 #ifndef SEEK_SET\r
 #  define SEEK_SET        0       /* Seek from beginning of file.  */\r
 #  define SEEK_CUR        1       /* Seek from current position.  */\r
 #  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */\r
 #endif\r
+\r
 #ifndef z_off_t\r
-#  define  z_off_t long\r
+#  define z_off_t long\r
+#endif\r
+\r
+#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0\r
+#  define z_off64_t off64_t\r
+#else\r
+#  define z_off64_t z_off_t\r
 #endif\r
 \r
 #if defined(__OS400__)\r
-#define NO_vsnprintf\r
+#  define NO_vsnprintf\r
 #endif\r
 \r
 #if defined(__MVS__)\r
 #  define NO_vsnprintf\r
-#  ifdef FAR\r
-#    undef FAR\r
-#  endif\r
 #endif\r
 \r
 /* MVS linker does not support external names larger than 8 bytes */\r
 #if defined(__MVS__)\r
-#   pragma map(deflateInit_,"DEIN")\r
-#   pragma map(deflateInit2_,"DEIN2")\r
-#   pragma map(deflateEnd,"DEEND")\r
-#   pragma map(deflateBound,"DEBND")\r
-#   pragma map(inflateInit_,"ININ")\r
-#   pragma map(inflateInit2_,"ININ2")\r
-#   pragma map(inflateEnd,"INEND")\r
-#   pragma map(inflateSync,"INSY")\r
-#   pragma map(inflateSetDictionary,"INSEDI")\r
-#   pragma map(compressBound,"CMBND")\r
-#   pragma map(inflate_table,"INTABL")\r
-#   pragma map(inflate_fast,"INFA")\r
-#   pragma map(inflate_copyright,"INCOPY")\r
+  #pragma map(deflateInit_,"DEIN")\r
+  #pragma map(deflateInit2_,"DEIN2")\r
+  #pragma map(deflateEnd,"DEEND")\r
+  #pragma map(deflateBound,"DEBND")\r
+  #pragma map(inflateInit_,"ININ")\r
+  #pragma map(inflateInit2_,"ININ2")\r
+  #pragma map(inflateEnd,"INEND")\r
+  #pragma map(inflateSync,"INSY")\r
+  #pragma map(inflateSetDictionary,"INSEDI")\r
+  #pragma map(compressBound,"CMBND")\r
+  #pragma map(inflate_table,"INTABL")\r
+  #pragma map(inflate_fast,"INFA")\r
+  #pragma map(inflate_copyright,"INCOPY")\r
 #endif\r
 \r
 #endif /* ZCONF_H */\r
index d54ac94..cba7ab2 100644 (file)
@@ -1,7 +1,7 @@
 /* zlib.h -- interface of the 'zlib' general purpose compression library\r
-  version 1.2.1, November 17th, 2003\r
+  version 1.2.5, April 19th, 2010\r
 \r
-  Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler\r
+  Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler\r
 \r
   This software is provided 'as-is', without any express or implied\r
   warranty.  In no event will the authors be held liable for any damages\r
 extern "C" {\r
 #endif\r
 \r
-#define ZLIB_VERSION "1.2.1"\r
-#define ZLIB_VERNUM 0x1210\r
+#define ZLIB_VERSION "1.2.5"\r
+#define ZLIB_VERNUM 0x1250\r
+#define ZLIB_VER_MAJOR 1\r
+#define ZLIB_VER_MINOR 2\r
+#define ZLIB_VER_REVISION 5\r
+#define ZLIB_VER_SUBREVISION 0\r
 \r
 /*\r
-     The 'zlib' compression library provides in-memory compression and\r
-  decompression functions, including integrity checks of the uncompressed\r
-  data.  This version of the library supports only one compression method\r
-  (deflation) but other algorithms will be added later and will have the same\r
-  stream interface.\r
-\r
-     Compression can be done in a single step if the buffers are large\r
-  enough (for example if an input file is mmap'ed), or can be done by\r
-  repeated calls of the compression function.  In the latter case, the\r
-  application must provide more input and/or consume the output\r
+    The 'zlib' compression library provides in-memory compression and\r
+  decompression functions, including integrity checks of the uncompressed data.\r
+  This version of the library supports only one compression method (deflation)\r
+  but other algorithms will be added later and will have the same stream\r
+  interface.\r
+\r
+    Compression can be done in a single step if the buffers are large enough,\r
+  or can be done by repeated calls of the compression function.  In the latter\r
+  case, the application must provide more input and/or consume the output\r
   (providing more output space) before each call.\r
 \r
-     The compressed data format used by the in-memory functions is the zlib\r
-  format, which is a zlib wrapper documented in RFC 1950, wrapped around a\r
-  deflate stream, which is itself documented in RFC 1951.\r
+    The compressed data format used by default by the in-memory functions is\r
+  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped\r
+  around a deflate stream, which is itself documented in RFC 1951.\r
 \r
-     The library also supports reading and writing files in gzip (.gz) format\r
+    The library also supports reading and writing files in gzip (.gz) format\r
   with an interface similar to that of stdio using the functions that start\r
   with "gz".  The gzip format is different from the zlib format.  gzip is a\r
   gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.\r
 \r
-     The zlib format was designed to be compact and fast for use in memory\r
+    This library can optionally read and write gzip streams in memory as well.\r
+\r
+    The zlib format was designed to be compact and fast for use in memory\r
   and on communications channels.  The gzip format was designed for single-\r
   file compression on file systems, has a larger header than zlib to maintain\r
   directory information, and uses a different, slower check method than zlib.\r
 \r
-     This library does not provide any functions to write gzip files in memory.\r
-  However such functions could be easily written using zlib's deflate function,\r
-  the documentation in the gzip RFC, and the examples in gzio.c.\r
-\r
-     The library does not install any signal handler. The decoder checks\r
-  the consistency of the compressed data, so the library should never\r
-  crash even in case of corrupted input.\r
+    The library does not install any signal handler.  The decoder checks\r
+  the consistency of the compressed data, so the library should never crash\r
+  even in case of corrupted input.\r
 */\r
 \r
 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));\r
@@ -97,7 +98,7 @@ typedef struct z_stream_s {
     free_func  zfree;   /* used to free the internal state */\r
     voidpf     opaque;  /* private data object passed to zalloc and zfree */\r
 \r
-    int     data_type;  /* best guess about the data type: ascii or binary */\r
+    int     data_type;  /* best guess about the data type: binary or text */\r
     uLong   adler;      /* adler32 value of the uncompressed data */\r
     uLong   reserved;   /* reserved for future use */\r
 } z_stream;\r
@@ -105,45 +106,68 @@ typedef struct z_stream_s {
 typedef z_stream FAR *z_streamp;\r
 \r
 /*\r
-   The application must update next_in and avail_in when avail_in has\r
-   dropped to zero. It must update next_out and avail_out when avail_out\r
-   has dropped to zero. The application must initialize zalloc, zfree and\r
-   opaque before calling the init function. All other fields are set by the\r
-   compression library and must not be updated by the application.\r
+     gzip header information passed to and from zlib routines.  See RFC 1952\r
+  for more details on the meanings of these fields.\r
+*/\r
+typedef struct gz_header_s {\r
+    int     text;       /* true if compressed data believed to be text */\r
+    uLong   time;       /* modification time */\r
+    int     xflags;     /* extra flags (not used when writing a gzip file) */\r
+    int     os;         /* operating system */\r
+    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */\r
+    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */\r
+    uInt    extra_max;  /* space at extra (only when reading header) */\r
+    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */\r
+    uInt    name_max;   /* space at name (only when reading header) */\r
+    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */\r
+    uInt    comm_max;   /* space at comment (only when reading header) */\r
+    int     hcrc;       /* true if there was or will be a header crc */\r
+    int     done;       /* true when done reading gzip header (not used\r
+                           when writing a gzip file) */\r
+} gz_header;\r
+\r
+typedef gz_header FAR *gz_headerp;\r
 \r
-   The opaque value provided by the application will be passed as the first\r
-   parameter for calls of zalloc and zfree. This can be useful for custom\r
-   memory management. The compression library attaches no meaning to the\r
+/*\r
+     The application must update next_in and avail_in when avail_in has dropped\r
+   to zero.  It must update next_out and avail_out when avail_out has dropped\r
+   to zero.  The application must initialize zalloc, zfree and opaque before\r
+   calling the init function.  All other fields are set by the compression\r
+   library and must not be updated by the application.\r
+\r
+     The opaque value provided by the application will be passed as the first\r
+   parameter for calls of zalloc and zfree.  This can be useful for custom\r
+   memory management.  The compression library attaches no meaning to the\r
    opaque value.\r
 \r
-   zalloc must return Z_NULL if there is not enough memory for the object.\r
+     zalloc must return Z_NULL if there is not enough memory for the object.\r
    If zlib is used in a multi-threaded application, zalloc and zfree must be\r
    thread safe.\r
 \r
-   On 16-bit systems, the functions zalloc and zfree must be able to allocate\r
-   exactly 65536 bytes, but will not be required to allocate more than this\r
-   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,\r
-   pointers returned by zalloc for objects of exactly 65536 bytes *must*\r
-   have their offset normalized to zero. The default allocation function\r
-   provided by this library ensures this (see zutil.c). To reduce memory\r
-   requirements and avoid any allocation of 64K objects, at the expense of\r
-   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).\r
-\r
-   The fields total_in and total_out can be used for statistics or\r
-   progress reports. After compression, total_in holds the total size of\r
-   the uncompressed data and may be saved for use in the decompressor\r
-   (particularly if the decompressor wants to decompress everything in\r
-   a single step).\r
+     On 16-bit systems, the functions zalloc and zfree must be able to allocate\r
+   exactly 65536 bytes, but will not be required to allocate more than this if\r
+   the symbol MAXSEG_64K is defined (see zconf.h).  WARNING: On MSDOS, pointers\r
+   returned by zalloc for objects of exactly 65536 bytes *must* have their\r
+   offset normalized to zero.  The default allocation function provided by this\r
+   library ensures this (see zutil.c).  To reduce memory requirements and avoid\r
+   any allocation of 64K objects, at the expense of compression ratio, compile\r
+   the library with -DMAX_WBITS=14 (see zconf.h).\r
+\r
+     The fields total_in and total_out can be used for statistics or progress\r
+   reports.  After compression, total_in holds the total size of the\r
+   uncompressed data and may be saved for use in the decompressor (particularly\r
+   if the decompressor wants to decompress everything in a single step).\r
 */\r
 \r
                         /* constants */\r
 \r
 #define Z_NO_FLUSH      0\r
-#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */\r
+#define Z_PARTIAL_FLUSH 1\r
 #define Z_SYNC_FLUSH    2\r
 #define Z_FULL_FLUSH    3\r
 #define Z_FINISH        4\r
 #define Z_BLOCK         5\r
+#define Z_TREES         6\r
 /* Allowed flush values; see deflate() and inflate() below for details */\r
 \r
 #define Z_OK            0\r
@@ -155,8 +179,8 @@ typedef z_stream FAR *z_streamp;
 #define Z_MEM_ERROR    (-4)\r
 #define Z_BUF_ERROR    (-5)\r
 #define Z_VERSION_ERROR (-6)\r
-/* Return codes for the compression/decompression functions. Negative\r
- * values are errors, positive values are used for special but normal events.\r
+/* Return codes for the compression/decompression functions. Negative values\r
+ * are errors, positive values are used for special but normal events.\r
  */\r
 \r
 #define Z_NO_COMPRESSION         0\r
@@ -168,11 +192,13 @@ typedef z_stream FAR *z_streamp;
 #define Z_FILTERED            1\r
 #define Z_HUFFMAN_ONLY        2\r
 #define Z_RLE                 3\r
+#define Z_FIXED               4\r
 #define Z_DEFAULT_STRATEGY    0\r
 /* compression strategy; see deflateInit2() below for details */\r
 \r
 #define Z_BINARY   0\r
-#define Z_ASCII    1\r
+#define Z_TEXT     1\r
+#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */\r
 #define Z_UNKNOWN  2\r
 /* Possible values of the data_type field (though see inflate()) */\r
 \r
@@ -184,115 +210,140 @@ typedef z_stream FAR *z_streamp;
 #define zlib_version zlibVersion()\r
 /* for compatibility with versions < 1.0.2 */\r
 \r
+\r
                         /* basic functions */\r
 \r
 ZEXTERN const char * ZEXPORT zlibVersion OF((void));\r
 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.\r
-   If the first character differs, the library code actually used is\r
-   not compatible with the zlib.h header file used by the application.\r
-   This check is automatically made by deflateInit and inflateInit.\r
+   If the first character differs, the library code actually used is not\r
+   compatible with the zlib.h header file used by the application.  This check\r
+   is automatically made by deflateInit and inflateInit.\r
  */\r
 \r
 /*\r
 ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));\r
 \r
-     Initializes the internal stream state for compression. The fields\r
-   zalloc, zfree and opaque must be initialized before by the caller.\r
-   If zalloc and zfree are set to Z_NULL, deflateInit updates them to\r
-   use default allocation functions.\r
+     Initializes the internal stream state for compression.  The fields\r
+   zalloc, zfree and opaque must be initialized before by the caller.  If\r
+   zalloc and zfree are set to Z_NULL, deflateInit updates them to use default\r
+   allocation functions.\r
 \r
      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:\r
-   1 gives best speed, 9 gives best compression, 0 gives no compression at\r
-   all (the input data is simply copied a block at a time).\r
-   Z_DEFAULT_COMPRESSION requests a default compromise between speed and\r
-   compression (currently equivalent to level 6).\r
+   1 gives best speed, 9 gives best compression, 0 gives no compression at all\r
+   (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION\r
+   requests a default compromise between speed and compression (currently\r
+   equivalent to level 6).\r
 \r
-     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not\r
-   enough memory, Z_STREAM_ERROR if level is not a valid compression level,\r
+     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_STREAM_ERROR if level is not a valid compression level, or\r
    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible\r
-   with the version assumed by the caller (ZLIB_VERSION).\r
-   msg is set to null if there is no error message.  deflateInit does not\r
-   perform any compression: this will be done by deflate().\r
+   with the version assumed by the caller (ZLIB_VERSION).  msg is set to null\r
+   if there is no error message.  deflateInit does not perform any compression:\r
+   this will be done by deflate().\r
 */\r
 \r
 \r
 ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));\r
 /*\r
     deflate compresses as much data as possible, and stops when the input\r
-  buffer becomes empty or the output buffer becomes full. It may introduce some\r
-  output latency (reading input without producing any output) except when\r
+  buffer becomes empty or the output buffer becomes full.  It may introduce\r
+  some output latency (reading input without producing any output) except when\r
   forced to flush.\r
 \r
-    The detailed semantics are as follows. deflate performs one or both of the\r
+    The detailed semantics are as follows.  deflate performs one or both of the\r
   following actions:\r
 \r
   - Compress more input starting at next_in and update next_in and avail_in\r
-    accordingly. If not all input can be processed (because there is not\r
+    accordingly.  If not all input can be processed (because there is not\r
     enough room in the output buffer), next_in and avail_in are updated and\r
     processing will resume at this point for the next call of deflate().\r
 \r
   - Provide more output starting at next_out and update next_out and avail_out\r
-    accordingly. This action is forced if the parameter flush is non zero.\r
+    accordingly.  This action is forced if the parameter flush is non zero.\r
     Forcing flush frequently degrades the compression ratio, so this parameter\r
-    should be set only when necessary (in interactive applications).\r
-    Some output may be provided even if flush is not set.\r
-\r
-  Before the call of deflate(), the application should ensure that at least\r
-  one of the actions is possible, by providing more input and/or consuming\r
-  more output, and updating avail_in or avail_out accordingly; avail_out\r
-  should never be zero before the call. The application can consume the\r
-  compressed output when it wants, for example when the output buffer is full\r
-  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK\r
-  and with zero avail_out, it must be called again after making room in the\r
-  output buffer because there might be more output pending.\r
+    should be set only when necessary (in interactive applications).  Some\r
+    output may be provided even if flush is not set.\r
+\r
+    Before the call of deflate(), the application should ensure that at least\r
+  one of the actions is possible, by providing more input and/or consuming more\r
+  output, and updating avail_in or avail_out accordingly; avail_out should\r
+  never be zero before the call.  The application can consume the compressed\r
+  output when it wants, for example when the output buffer is full (avail_out\r
+  == 0), or after each call of deflate().  If deflate returns Z_OK and with\r
+  zero avail_out, it must be called again after making room in the output\r
+  buffer because there might be more output pending.\r
+\r
+    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to\r
+  decide how much data to accumulate before producing output, in order to\r
+  maximize compression.\r
 \r
     If the parameter flush is set to Z_SYNC_FLUSH, all pending output is\r
   flushed to the output buffer and the output is aligned on a byte boundary, so\r
-  that the decompressor can get all input data available so far. (In particular\r
-  avail_in is zero after the call if enough output space has been provided\r
-  before the call.)  Flushing may degrade compression for some compression\r
-  algorithms and so it should be used only when necessary.\r
+  that the decompressor can get all input data available so far.  (In\r
+  particular avail_in is zero after the call if enough output space has been\r
+  provided before the call.) Flushing may degrade compression for some\r
+  compression algorithms and so it should be used only when necessary.  This\r
+  completes the current deflate block and follows it with an empty stored block\r
+  that is three bits plus filler bits to the next byte, followed by four bytes\r
+  (00 00 ff ff).\r
+\r
+    If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the\r
+  output buffer, but the output is not aligned to a byte boundary.  All of the\r
+  input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.\r
+  This completes the current deflate block and follows it with an empty fixed\r
+  codes block that is 10 bits long.  This assures that enough bytes are output\r
+  in order for the decompressor to finish the block before the empty fixed code\r
+  block.\r
+\r
+    If flush is set to Z_BLOCK, a deflate block is completed and emitted, as\r
+  for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to\r
+  seven bits of the current block are held to be written as the next byte after\r
+  the next deflate block is completed.  In this case, the decompressor may not\r
+  be provided enough bits at this point in order to complete decompression of\r
+  the data provided so far to the compressor.  It may need to wait for the next\r
+  block to be emitted.  This is for advanced applications that need to control\r
+  the emission of deflate blocks.\r
 \r
     If flush is set to Z_FULL_FLUSH, all output is flushed as with\r
   Z_SYNC_FLUSH, and the compression state is reset so that decompression can\r
   restart from this point if previous compressed data has been damaged or if\r
-  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade\r
-  the compression.\r
+  random access is desired.  Using Z_FULL_FLUSH too often can seriously degrade\r
+  compression.\r
 \r
     If deflate returns with avail_out == 0, this function must be called again\r
   with the same value of the flush parameter and more output space (updated\r
   avail_out), until the flush is complete (deflate returns with non-zero\r
-  avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that\r
+  avail_out).  In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that\r
   avail_out is greater than six to avoid repeated flush markers due to\r
   avail_out == 0 on return.\r
 \r
     If the parameter flush is set to Z_FINISH, pending input is processed,\r
-  pending output is flushed and deflate returns with Z_STREAM_END if there\r
-  was enough output space; if deflate returns with Z_OK, this function must be\r
+  pending output is flushed and deflate returns with Z_STREAM_END if there was\r
+  enough output space; if deflate returns with Z_OK, this function must be\r
   called again with Z_FINISH and more output space (updated avail_out) but no\r
-  more input data, until it returns with Z_STREAM_END or an error. After\r
-  deflate has returned Z_STREAM_END, the only possible operations on the\r
-  stream are deflateReset or deflateEnd.\r
+  more input data, until it returns with Z_STREAM_END or an error.  After\r
+  deflate has returned Z_STREAM_END, the only possible operations on the stream\r
+  are deflateReset or deflateEnd.\r
 \r
     Z_FINISH can be used immediately after deflateInit if all the compression\r
-  is to be done in a single step. In this case, avail_out must be at least\r
-  the value returned by deflateBound (see below). If deflate does not return\r
+  is to be done in a single step.  In this case, avail_out must be at least the\r
+  value returned by deflateBound (see below).  If deflate does not return\r
   Z_STREAM_END, then it must be called again as described above.\r
 \r
     deflate() sets strm->adler to the adler32 checksum of all input read\r
   so far (that is, total_in bytes).\r
 \r
-    deflate() may update data_type if it can make a good guess about\r
-  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered\r
-  binary. This field is only for information purposes and does not affect\r
-  the compression algorithm in any manner.\r
+    deflate() may update strm->data_type if it can make a good guess about\r
+  the input data type (Z_BINARY or Z_TEXT).  In doubt, the data is considered\r
+  binary.  This field is only for information purposes and does not affect the\r
+  compression algorithm in any manner.\r
 \r
     deflate() returns Z_OK if some progress has been made (more input\r
   processed or more output produced), Z_STREAM_END if all input has been\r
   consumed and all output has been produced (only when flush is set to\r
   Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example\r
-  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible\r
-  (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not\r
+  if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible\r
+  (for example avail_in or avail_out was zero).  Note that Z_BUF_ERROR is not\r
   fatal, and deflate() can be called again with more input and more output\r
   space to continue compressing.\r
 */\r
@@ -301,13 +352,13 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
 ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));\r
 /*\r
      All dynamically allocated data structures for this stream are freed.\r
-   This function discards any unprocessed input and does not flush any\r
-   pending output.\r
+   This function discards any unprocessed input and does not flush any pending\r
+   output.\r
 \r
      deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the\r
    stream state was inconsistent, Z_DATA_ERROR if the stream was freed\r
-   prematurely (some input or output was discarded). In the error case,\r
-   msg may be set but then points to a static string (which must not be\r
+   prematurely (some input or output was discarded).  In the error case, msg\r
+   may be set but then points to a static string (which must not be\r
    deallocated).\r
 */\r
 \r
@@ -315,10 +366,10 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
 /*\r
 ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));\r
 \r
-     Initializes the internal stream state for decompression. The fields\r
+     Initializes the internal stream state for decompression.  The fields\r
    next_in, avail_in, zalloc, zfree and opaque must be initialized before by\r
-   the caller. If next_in is not Z_NULL and avail_in is large enough (the exact\r
-   value depends on the compression method), inflateInit determines the\r
+   the caller.  If next_in is not Z_NULL and avail_in is large enough (the\r
+   exact value depends on the compression method), inflateInit determines the\r
    compression method from the zlib header and allocates all data structures\r
    accordingly; otherwise the allocation will be deferred to the first call of\r
    inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to\r
@@ -326,95 +377,108 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
 \r
      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
    memory, Z_VERSION_ERROR if the zlib library version is incompatible with the\r
-   version assumed by the caller.  msg is set to null if there is no error\r
-   message. inflateInit does not perform any decompression apart from reading\r
-   the zlib header if present: this will be done by inflate().  (So next_in and\r
-   avail_in may be modified, but next_out and avail_out are unchanged.)\r
+   version assumed by the caller, or Z_STREAM_ERROR if the parameters are\r
+   invalid, such as a null pointer to the structure.  msg is set to null if\r
+   there is no error message.  inflateInit does not perform any decompression\r
+   apart from possibly reading the zlib header if present: actual decompression\r
+   will be done by inflate().  (So next_in and avail_in may be modified, but\r
+   next_out and avail_out are unused and unchanged.) The current implementation\r
+   of inflateInit() does not process any header information -- that is deferred\r
+   until inflate() is called.\r
 */\r
 \r
 \r
 ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));\r
 /*\r
     inflate decompresses as much data as possible, and stops when the input\r
-  buffer becomes empty or the output buffer becomes full. It may introduce\r
+  buffer becomes empty or the output buffer becomes full.  It may introduce\r
   some output latency (reading input without producing any output) except when\r
   forced to flush.\r
 \r
-  The detailed semantics are as follows. inflate performs one or both of the\r
+  The detailed semantics are as follows.  inflate performs one or both of the\r
   following actions:\r
 \r
   - Decompress more input starting at next_in and update next_in and avail_in\r
-    accordingly. If not all input can be processed (because there is not\r
-    enough room in the output buffer), next_in is updated and processing\r
-    will resume at this point for the next call of inflate().\r
+    accordingly.  If not all input can be processed (because there is not\r
+    enough room in the output buffer), next_in is updated and processing will\r
+    resume at this point for the next call of inflate().\r
 \r
   - Provide more output starting at next_out and update next_out and avail_out\r
-    accordingly.  inflate() provides as much output as possible, until there\r
-    is no more input data or no more space in the output buffer (see below\r
-    about the flush parameter).\r
-\r
-  Before the call of inflate(), the application should ensure that at least\r
-  one of the actions is possible, by providing more input and/or consuming\r
-  more output, and updating the next_* and avail_* values accordingly.\r
-  The application can consume the uncompressed output when it wants, for\r
-  example when the output buffer is full (avail_out == 0), or after each\r
-  call of inflate(). If inflate returns Z_OK and with zero avail_out, it\r
-  must be called again after making room in the output buffer because there\r
-  might be more output pending.\r
-\r
-    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,\r
-  Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much\r
-  output as possible to the output buffer. Z_BLOCK requests that inflate() stop\r
-  if and when it get to the next deflate block boundary. When decoding the zlib\r
-  or gzip format, this will cause inflate() to return immediately after the\r
-  header and before the first block. When doing a raw inflate, inflate() will\r
-  go ahead and process the first block, and will return when it gets to the end\r
-  of that block, or when it runs out of data.\r
+    accordingly.  inflate() provides as much output as possible, until there is\r
+    no more input data or no more space in the output buffer (see below about\r
+    the flush parameter).\r
+\r
+    Before the call of inflate(), the application should ensure that at least\r
+  one of the actions is possible, by providing more input and/or consuming more\r
+  output, and updating the next_* and avail_* values accordingly.  The\r
+  application can consume the uncompressed output when it wants, for example\r
+  when the output buffer is full (avail_out == 0), or after each call of\r
+  inflate().  If inflate returns Z_OK and with zero avail_out, it must be\r
+  called again after making room in the output buffer because there might be\r
+  more output pending.\r
+\r
+    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,\r
+  Z_BLOCK, or Z_TREES.  Z_SYNC_FLUSH requests that inflate() flush as much\r
+  output as possible to the output buffer.  Z_BLOCK requests that inflate()\r
+  stop if and when it gets to the next deflate block boundary.  When decoding\r
+  the zlib or gzip format, this will cause inflate() to return immediately\r
+  after the header and before the first block.  When doing a raw inflate,\r
+  inflate() will go ahead and process the first block, and will return when it\r
+  gets to the end of that block, or when it runs out of data.\r
 \r
     The Z_BLOCK option assists in appending to or combining deflate streams.\r
   Also to assist in this, on return inflate() will set strm->data_type to the\r
-  number of unused bits in the last byte taken from strm->next_in, plus 64\r
-  if inflate() is currently decoding the last block in the deflate stream,\r
-  plus 128 if inflate() returned immediately after decoding an end-of-block\r
-  code or decoding the complete header up to just before the first byte of the\r
-  deflate stream. The end-of-block will not be indicated until all of the\r
-  uncompressed data from that block has been written to strm->next_out.  The\r
-  number of unused bits may in general be greater than seven, except when\r
-  bit 7 of data_type is set, in which case the number of unused bits will be\r
-  less than eight.\r
+  number of unused bits in the last byte taken from strm->next_in, plus 64 if\r
+  inflate() is currently decoding the last block in the deflate stream, plus\r
+  128 if inflate() returned immediately after decoding an end-of-block code or\r
+  decoding the complete header up to just before the first byte of the deflate\r
+  stream.  The end-of-block will not be indicated until all of the uncompressed\r
+  data from that block has been written to strm->next_out.  The number of\r
+  unused bits may in general be greater than seven, except when bit 7 of\r
+  data_type is set, in which case the number of unused bits will be less than\r
+  eight.  data_type is set as noted here every time inflate() returns for all\r
+  flush options, and so can be used to determine the amount of currently\r
+  consumed input in bits.\r
+\r
+    The Z_TREES option behaves as Z_BLOCK does, but it also returns when the\r
+  end of each deflate block header is reached, before any actual data in that\r
+  block is decoded.  This allows the caller to determine the length of the\r
+  deflate block header for later use in random access within a deflate block.\r
+  256 is added to the value of strm->data_type when inflate() returns\r
+  immediately after reaching the end of the deflate block header.\r
 \r
     inflate() should normally be called until it returns Z_STREAM_END or an\r
-  error. However if all decompression is to be performed in a single step\r
-  (a single call of inflate), the parameter flush should be set to\r
-  Z_FINISH. In this case all pending input is processed and all pending\r
-  output is flushed; avail_out must be large enough to hold all the\r
-  uncompressed data. (The size of the uncompressed data may have been saved\r
-  by the compressor for this purpose.) The next operation on this stream must\r
-  be inflateEnd to deallocate the decompression state. The use of Z_FINISH\r
-  is never required, but can be used to inform inflate that a faster approach\r
-  may be used for the single inflate() call.\r
+  error.  However if all decompression is to be performed in a single step (a\r
+  single call of inflate), the parameter flush should be set to Z_FINISH.  In\r
+  this case all pending input is processed and all pending output is flushed;\r
+  avail_out must be large enough to hold all the uncompressed data.  (The size\r
+  of the uncompressed data may have been saved by the compressor for this\r
+  purpose.) The next operation on this stream must be inflateEnd to deallocate\r
+  the decompression state.  The use of Z_FINISH is never required, but can be\r
+  used to inform inflate that a faster approach may be used for the single\r
+  inflate() call.\r
 \r
      In this implementation, inflate() always flushes as much output as\r
   possible to the output buffer, and always uses the faster approach on the\r
-  first call. So the only effect of the flush parameter in this implementation\r
+  first call.  So the only effect of the flush parameter in this implementation\r
   is on the return value of inflate(), as noted below, or when it returns early\r
-  because Z_BLOCK is used.\r
+  because Z_BLOCK or Z_TREES is used.\r
 \r
      If a preset dictionary is needed after this call (see inflateSetDictionary\r
-  below), inflate sets strm-adler to the adler32 checksum of the dictionary\r
+  below), inflate sets strm->adler to the adler32 checksum of the dictionary\r
   chosen by the compressor and returns Z_NEED_DICT; otherwise it sets\r
   strm->adler to the adler32 checksum of all output produced so far (that is,\r
   total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described\r
-  below. At the end of the stream, inflate() checks that its computed adler32\r
+  below.  At the end of the stream, inflate() checks that its computed adler32\r
   checksum is equal to that saved by the compressor and returns Z_STREAM_END\r
   only if the checksum is correct.\r
 \r
-    inflate() will decompress and check either zlib-wrapped or gzip-wrapped\r
-  deflate data.  The header type is detected automatically.  Any information\r
-  contained in the gzip header is not retained, so applications that need that\r
-  information should instead use raw inflate, see inflateInit2() below, or\r
-  inflateBack() and perform their own processing of the gzip header and\r
-  trailer.\r
+    inflate() can decompress and check either zlib-wrapped or gzip-wrapped\r
+  deflate data.  The header type is detected automatically, if requested when\r
+  initializing with inflateInit2().  Any information contained in the gzip\r
+  header is not retained, so applications that need that information should\r
+  instead use raw inflate, see inflateInit2() below, or inflateBack() and\r
+  perform their own processing of the gzip header and trailer.\r
 \r
     inflate() returns Z_OK if some progress has been made (more input processed\r
   or more output produced), Z_STREAM_END if the end of the compressed data has\r
@@ -422,27 +486,28 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
   preset dictionary is needed at this point, Z_DATA_ERROR if the input data was\r
   corrupted (input stream not conforming to the zlib format or incorrect check\r
   value), Z_STREAM_ERROR if the stream structure was inconsistent (for example\r
-  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,\r
+  next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,\r
   Z_BUF_ERROR if no progress is possible or if there was not enough room in the\r
-  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and\r
+  output buffer when Z_FINISH is used.  Note that Z_BUF_ERROR is not fatal, and\r
   inflate() can be called again with more input and more output space to\r
-  continue decompressing. If Z_DATA_ERROR is returned, the application may then\r
-  call inflateSync() to look for a good compression block if a partial recovery\r
-  of the data is desired.\r
+  continue decompressing.  If Z_DATA_ERROR is returned, the application may\r
+  then call inflateSync() to look for a good compression block if a partial\r
+  recovery of the data is desired.\r
 */\r
 \r
 \r
 ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));\r
 /*\r
      All dynamically allocated data structures for this stream are freed.\r
-   This function discards any unprocessed input and does not flush any\r
-   pending output.\r
+   This function discards any unprocessed input and does not flush any pending\r
+   output.\r
 \r
      inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state\r
-   was inconsistent. In the error case, msg may be set but then points to a\r
+   was inconsistent.  In the error case, msg may be set but then points to a\r
    static string (which must not be deallocated).\r
 */\r
 \r
+\r
                         /* Advanced functions */\r
 \r
 /*\r
@@ -457,52 +522,57 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
                                      int  memLevel,\r
                                      int  strategy));\r
 \r
-     This is another version of deflateInit with more compression options. The\r
-   fields next_in, zalloc, zfree and opaque must be initialized before by\r
-   the caller.\r
+     This is another version of deflateInit with more compression options.  The\r
+   fields next_in, zalloc, zfree and opaque must be initialized before by the\r
+   caller.\r
 \r
-     The method parameter is the compression method. It must be Z_DEFLATED in\r
+     The method parameter is the compression method.  It must be Z_DEFLATED in\r
    this version of the library.\r
 \r
      The windowBits parameter is the base two logarithm of the window size\r
-   (the size of the history buffer). It should be in the range 8..15 for this\r
-   version of the library. Larger values of this parameter result in better\r
-   compression at the expense of memory usage. The default value is 15 if\r
+   (the size of the history buffer).  It should be in the range 8..15 for this\r
+   version of the library.  Larger values of this parameter result in better\r
+   compression at the expense of memory usage.  The default value is 15 if\r
    deflateInit is used instead.\r
 \r
-     windowBits can also be -8..-15 for raw deflate. In this case, -windowBits\r
-   determines the window size. deflate() will then generate raw deflate data\r
+     windowBits can also be -8..-15 for raw deflate.  In this case, -windowBits\r
+   determines the window size.  deflate() will then generate raw deflate data\r
    with no zlib header or trailer, and will not compute an adler32 check value.\r
 \r
-     windowBits can also be greater than 15 for optional gzip encoding. Add\r
+     windowBits can also be greater than 15 for optional gzip encoding.  Add\r
    16 to windowBits to write a simple gzip header and trailer around the\r
-   compressed data instead of a zlib wrapper. The gzip header will have no\r
-   file name, no extra data, no comment, no modification time (set to zero),\r
-   no header crc, and the operating system will be set to 255 (unknown).\r
+   compressed data instead of a zlib wrapper.  The gzip header will have no\r
+   file name, no extra data, no comment, no modification time (set to zero), no\r
+   header crc, and the operating system will be set to 255 (unknown).  If a\r
+   gzip stream is being written, strm->adler is a crc32 instead of an adler32.\r
 \r
      The memLevel parameter specifies how much memory should be allocated\r
-   for the internal compression state. memLevel=1 uses minimum memory but\r
-   is slow and reduces compression ratio; memLevel=9 uses maximum memory\r
-   for optimal speed. The default value is 8. See zconf.h for total memory\r
-   usage as a function of windowBits and memLevel.\r
+   for the internal compression state.  memLevel=1 uses minimum memory but is\r
+   slow and reduces compression ratio; memLevel=9 uses maximum memory for\r
+   optimal speed.  The default value is 8.  See zconf.h for total memory usage\r
+   as a function of windowBits and memLevel.\r
 \r
-     The strategy parameter is used to tune the compression algorithm. Use the\r
+     The strategy parameter is used to tune the compression algorithm.  Use the\r
    value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a\r
    filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no\r
    string match), or Z_RLE to limit match distances to one (run-length\r
-   encoding). Filtered data consists mostly of small values with a somewhat\r
-   random distribution. In this case, the compression algorithm is tuned to\r
-   compress them better. The effect of Z_FILTERED is to force more Huffman\r
+   encoding).  Filtered data consists mostly of small values with a somewhat\r
+   random distribution.  In this case, the compression algorithm is tuned to\r
+   compress them better.  The effect of Z_FILTERED is to force more Huffman\r
    coding and less string matching; it is somewhat intermediate between\r
-   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as\r
-   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy\r
-   parameter only affects the compression ratio but not the correctness of the\r
-   compressed output even if it is not set appropriately.\r
-\r
-      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
-   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid\r
-   method). msg is set to null if there is no error message.  deflateInit2 does\r
-   not perform any compression: this will be done by deflate().\r
+   Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY.  Z_RLE is designed to be almost as\r
+   fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data.  The\r
+   strategy parameter only affects the compression ratio but not the\r
+   correctness of the compressed output even if it is not set appropriately.\r
+   Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler\r
+   decoder for special applications.\r
+\r
+     deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid\r
+   method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is\r
+   incompatible with the version assumed by the caller (ZLIB_VERSION).  msg is\r
+   set to null if there is no error message.  deflateInit2 does not perform any\r
+   compression: this will be done by deflate().\r
 */\r
 \r
 ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,\r
@@ -510,35 +580,37 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
                                              uInt  dictLength));\r
 /*\r
      Initializes the compression dictionary from the given byte sequence\r
-   without producing any compressed output. This function must be called\r
-   immediately after deflateInit, deflateInit2 or deflateReset, before any\r
-   call of deflate. The compressor and decompressor must use exactly the same\r
+   without producing any compressed output.  This function must be called\r
+   immediately after deflateInit, deflateInit2 or deflateReset, before any call\r
+   of deflate.  The compressor and decompressor must use exactly the same\r
    dictionary (see inflateSetDictionary).\r
 \r
      The dictionary should consist of strings (byte sequences) that are likely\r
    to be encountered later in the data to be compressed, with the most commonly\r
-   used strings preferably put towards the end of the dictionary. Using a\r
+   used strings preferably put towards the end of the dictionary.  Using a\r
    dictionary is most useful when the data to be compressed is short and can be\r
    predicted with good accuracy; the data can then be compressed better than\r
    with the default empty dictionary.\r
 \r
      Depending on the size of the compression data structures selected by\r
    deflateInit or deflateInit2, a part of the dictionary may in effect be\r
-   discarded, for example if the dictionary is larger than the window size in\r
-   deflate or deflate2. Thus the strings most likely to be useful should be\r
-   put at the end of the dictionary, not at the front.\r
+   discarded, for example if the dictionary is larger than the window size\r
+   provided in deflateInit or deflateInit2.  Thus the strings most likely to be\r
+   useful should be put at the end of the dictionary, not at the front.  In\r
+   addition, the current implementation of deflate will use at most the window\r
+   size minus 262 bytes of the provided dictionary.\r
 \r
      Upon return of this function, strm->adler is set to the adler32 value\r
    of the dictionary; the decompressor may later use this value to determine\r
-   which dictionary has been used by the compressor. (The adler32 value\r
+   which dictionary has been used by the compressor.  (The adler32 value\r
    applies to the whole dictionary even if only a subset of the dictionary is\r
    actually used by the compressor.) If a raw deflate was requested, then the\r
    adler32 value is not computed and strm->adler is not set.\r
 \r
      deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a\r
-   parameter is invalid (such as NULL dictionary) or the stream state is\r
+   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is\r
    inconsistent (for example if deflate has already been called for this stream\r
-   or if the compression method is bsort). deflateSetDictionary does not\r
+   or if the compression method is bsort).  deflateSetDictionary does not\r
    perform any compression: this will be done by deflate().\r
 */\r
 \r
@@ -549,26 +621,26 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
 \r
      This function can be useful when several compression strategies will be\r
    tried, for example when there are several ways of pre-processing the input\r
-   data with a filter. The streams that will be discarded should then be freed\r
+   data with a filter.  The streams that will be discarded should then be freed\r
    by calling deflateEnd.  Note that deflateCopy duplicates the internal\r
-   compression state which can be quite large, so this strategy is slow and\r
-   can consume lots of memory.\r
+   compression state which can be quite large, so this strategy is slow and can\r
+   consume lots of memory.\r
 \r
      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not\r
    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent\r
-   (such as zalloc being NULL). msg is left unchanged in both source and\r
+   (such as zalloc being Z_NULL).  msg is left unchanged in both source and\r
    destination.\r
 */\r
 \r
 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));\r
 /*\r
      This function is equivalent to deflateEnd followed by deflateInit,\r
-   but does not free and reallocate all the internal compression state.\r
-   The stream will keep the same compression level and any other attributes\r
-   that may have been set by deflateInit2.\r
+   but does not free and reallocate all the internal compression state.  The\r
+   stream will keep the same compression level and any other attributes that\r
+   may have been set by deflateInit2.\r
 \r
-      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
-   stream state was inconsistent (such as zalloc or state being NULL).\r
+     deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent (such as zalloc or state being Z_NULL).\r
 */\r
 \r
 ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,\r
@@ -578,27 +650,45 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
      Dynamically update the compression level and compression strategy.  The\r
    interpretation of level and strategy is as in deflateInit2.  This can be\r
    used to switch between compression and straight copy of the input data, or\r
-   to switch to a different kind of input data requiring a different\r
-   strategy. If the compression level is changed, the input available so far\r
-   is compressed with the old level (and may be flushed); the new level will\r
-   take effect only at the next call of deflate().\r
+   to switch to a different kind of input data requiring a different strategy.\r
+   If the compression level is changed, the input available so far is\r
+   compressed with the old level (and may be flushed); the new level will take\r
+   effect only at the next call of deflate().\r
 \r
      Before the call of deflateParams, the stream state must be set as for\r
-   a call of deflate(), since the currently available input may have to\r
-   be compressed and flushed. In particular, strm->avail_out must be non-zero.\r
+   a call of deflate(), since the currently available input may have to be\r
+   compressed and flushed.  In particular, strm->avail_out must be non-zero.\r
 \r
      deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source\r
-   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR\r
-   if strm->avail_out was zero.\r
+   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if\r
+   strm->avail_out was zero.\r
 */\r
 \r
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,\r
+                                    int good_length,\r
+                                    int max_lazy,\r
+                                    int nice_length,\r
+                                    int max_chain));\r
+/*\r
+     Fine tune deflate's internal compression parameters.  This should only be\r
+   used by someone who understands the algorithm used by zlib's deflate for\r
+   searching for the best matching string, and even then only by the most\r
+   fanatic optimizer trying to squeeze out the last compressed bit for their\r
+   specific input data.  Read the deflate.c source code for the meaning of the\r
+   max_lazy, good_length, nice_length, and max_chain parameters.\r
+\r
+     deflateTune() can be called after deflateInit() or deflateInit2(), and\r
+   returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.\r
+ */\r
+\r
 ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,\r
                                        uLong sourceLen));\r
 /*\r
      deflateBound() returns an upper bound on the compressed size after\r
-   deflation of sourceLen bytes.  It must be called after deflateInit()\r
-   or deflateInit2().  This would be used to allocate an output buffer\r
-   for deflation in a single pass, and so would be called before deflate().\r
+   deflation of sourceLen bytes.  It must be called after deflateInit() or\r
+   deflateInit2(), and after deflateSetHeader(), if used.  This would be used\r
+   to allocate an output buffer for deflation in a single pass, and so would be\r
+   called before deflate().\r
 */\r
 \r
 ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,\r
@@ -606,14 +696,38 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
                                      int value));\r
 /*\r
      deflatePrime() inserts bits in the deflate output stream.  The intent\r
-  is that this function is used to start off the deflate output with the\r
-  bits leftover from a previous deflate stream when appending to it.  As such,\r
-  this function can only be used for raw deflate, and must be used before the\r
-  first deflate() call after a deflateInit2() or deflateReset().  bits must be\r
-  less than or equal to 16, and that many of the least significant bits of\r
-  value will be inserted in the output.\r
-\r
-      deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   is that this function is used to start off the deflate output with the bits\r
+   leftover from a previous deflate stream when appending to it.  As such, this\r
+   function can only be used for raw deflate, and must be used before the first\r
+   deflate() call after a deflateInit2() or deflateReset().  bits must be less\r
+   than or equal to 16, and that many of the least significant bits of value\r
+   will be inserted in the output.\r
+\r
+     deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,\r
+                                         gz_headerp head));\r
+/*\r
+     deflateSetHeader() provides gzip header information for when a gzip\r
+   stream is requested by deflateInit2().  deflateSetHeader() may be called\r
+   after deflateInit2() or deflateReset() and before the first call of\r
+   deflate().  The text, time, os, extra field, name, and comment information\r
+   in the provided gz_header structure are written to the gzip header (xflag is\r
+   ignored -- the extra flags are set according to the compression level).  The\r
+   caller must assure that, if not Z_NULL, name and comment are terminated with\r
+   a zero byte, and that if extra is not Z_NULL, that extra_len bytes are\r
+   available there.  If hcrc is true, a gzip header crc is included.  Note that\r
+   the current versions of the command-line version of gzip (up through version\r
+   1.3.x) do not support header crc's, and will report that it is a "multi-part\r
+   gzip file" and give up.\r
+\r
+     If deflateSetHeader is not used, the default gzip header has text false,\r
+   the time set to zero, and os set to 255, with no extra, name, or comment\r
+   fields.  The gzip header is returned to the default state by deflateReset().\r
+\r
+     deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source\r
    stream state was inconsistent.\r
 */\r
 \r
@@ -621,42 +735,50 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
 ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,\r
                                      int  windowBits));\r
 \r
-     This is another version of inflateInit with an extra parameter. The\r
+     This is another version of inflateInit with an extra parameter.  The\r
    fields next_in, avail_in, zalloc, zfree and opaque must be initialized\r
    before by the caller.\r
 \r
      The windowBits parameter is the base two logarithm of the maximum window\r
    size (the size of the history buffer).  It should be in the range 8..15 for\r
-   this version of the library. The default value is 15 if inflateInit is used\r
-   instead. windowBits must be greater than or equal to the windowBits value\r
+   this version of the library.  The default value is 15 if inflateInit is used\r
+   instead.  windowBits must be greater than or equal to the windowBits value\r
    provided to deflateInit2() while compressing, or it must be equal to 15 if\r
-   deflateInit2() was not used. If a compressed stream with a larger window\r
+   deflateInit2() was not used.  If a compressed stream with a larger window\r
    size is given as input, inflate() will return with the error code\r
    Z_DATA_ERROR instead of trying to allocate a larger window.\r
 \r
-     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits\r
-   determines the window size. inflate() will then process raw deflate data,\r
+     windowBits can also be zero to request that inflate use the window size in\r
+   the zlib header of the compressed stream.\r
+\r
+     windowBits can also be -8..-15 for raw inflate.  In this case, -windowBits\r
+   determines the window size.  inflate() will then process raw deflate data,\r
    not looking for a zlib or gzip header, not generating a check value, and not\r
-   looking for any check values for comparison at the end of the stream. This\r
+   looking for any check values for comparison at the end of the stream.  This\r
    is for use with other formats that use the deflate compressed data format\r
-   such as zip.  Those formats provide their own check values. If a custom\r
+   such as zip.  Those formats provide their own check values.  If a custom\r
    format is developed using the raw deflate format for compressed data, it is\r
    recommended that a check value such as an adler32 or a crc32 be applied to\r
    the uncompressed data as is done in the zlib, gzip, and zip formats.  For\r
-   most applications, the zlib format should be used as is. Note that comments\r
+   most applications, the zlib format should be used as is.  Note that comments\r
    above on the use in deflateInit2() applies to the magnitude of windowBits.\r
 \r
-     windowBits can also be greater than 15 for optional gzip decoding. Add\r
+     windowBits can also be greater than 15 for optional gzip decoding.  Add\r
    32 to windowBits to enable zlib and gzip decoding with automatic header\r
    detection, or add 16 to decode only the gzip format (the zlib format will\r
-   return a Z_DATA_ERROR).\r
+   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is a\r
+   crc32 instead of an adler32.\r
 \r
      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
-   memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative\r
-   memLevel). msg is set to null if there is no error message.  inflateInit2\r
-   does not perform any decompression apart from reading the zlib header if\r
-   present: this will be done by inflate(). (So next_in and avail_in may be\r
-   modified, but next_out and avail_out are unchanged.)\r
+   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the\r
+   version assumed by the caller, or Z_STREAM_ERROR if the parameters are\r
+   invalid, such as a null pointer to the structure.  msg is set to null if\r
+   there is no error message.  inflateInit2 does not perform any decompression\r
+   apart from possibly reading the zlib header if present: actual decompression\r
+   will be done by inflate().  (So next_in and avail_in may be modified, but\r
+   next_out and avail_out are unused and unchanged.) The current implementation\r
+   of inflateInit2() does not process any header information -- that is\r
+   deferred until inflate() is called.\r
 */\r
 \r
 ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,\r
@@ -664,33 +786,36 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
                                              uInt  dictLength));\r
 /*\r
      Initializes the decompression dictionary from the given uncompressed byte\r
-   sequence. This function must be called immediately after a call of inflate\r
-   if this call returned Z_NEED_DICT. The dictionary chosen by the compressor\r
-   can be determined from the adler32 value returned by this call of\r
-   inflate. The compressor and decompressor must use exactly the same\r
-   dictionary (see deflateSetDictionary).\r
+   sequence.  This function must be called immediately after a call of inflate,\r
+   if that call returned Z_NEED_DICT.  The dictionary chosen by the compressor\r
+   can be determined from the adler32 value returned by that call of inflate.\r
+   The compressor and decompressor must use exactly the same dictionary (see\r
+   deflateSetDictionary).  For raw inflate, this function can be called\r
+   immediately after inflateInit2() or inflateReset() and before any call of\r
+   inflate() to set the dictionary.  The application must insure that the\r
+   dictionary that was used for compression is provided.\r
 \r
      inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a\r
-   parameter is invalid (such as NULL dictionary) or the stream state is\r
+   parameter is invalid (e.g.  dictionary being Z_NULL) or the stream state is\r
    inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the\r
-   expected one (incorrect adler32 value). inflateSetDictionary does not\r
+   expected one (incorrect adler32 value).  inflateSetDictionary does not\r
    perform any decompression: this will be done by subsequent calls of\r
    inflate().\r
 */\r
 \r
 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));\r
 /*\r
-    Skips invalid compressed data until a full flush point (see above the\r
-  description of deflate with Z_FULL_FLUSH) can be found, or until all\r
-  available input is skipped. No output is provided.\r
-\r
-    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR\r
-  if no more input was provided, Z_DATA_ERROR if no flush point has been found,\r
-  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success\r
-  case, the application may save the current current value of total_in which\r
-  indicates where valid compressed data was found. In the error case, the\r
-  application may repeatedly call inflateSync, providing more input each time,\r
-  until success or end of the input data.\r
+     Skips invalid compressed data until a full flush point (see above the\r
+   description of deflate with Z_FULL_FLUSH) can be found, or until all\r
+   available input is skipped.  No output is provided.\r
+\r
+     inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR\r
+   if no more input was provided, Z_DATA_ERROR if no flush point has been\r
+   found, or Z_STREAM_ERROR if the stream structure was inconsistent.  In the\r
+   success case, the application may save the current current value of total_in\r
+   which indicates where valid compressed data was found.  In the error case,\r
+   the application may repeatedly call inflateSync, providing more input each\r
+   time, until success or end of the input data.\r
 */\r
 \r
 ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,\r
@@ -705,22 +830,123 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
 \r
      inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not\r
    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent\r
-   (such as zalloc being NULL). msg is left unchanged in both source and\r
+   (such as zalloc being Z_NULL).  msg is left unchanged in both source and\r
    destination.\r
 */\r
 \r
 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));\r
 /*\r
      This function is equivalent to inflateEnd followed by inflateInit,\r
-   but does not free and reallocate all the internal decompression state.\r
-   The stream will keep attributes that may have been set by inflateInit2.\r
+   but does not free and reallocate all the internal decompression state.  The\r
+   stream will keep attributes that may have been set by inflateInit2.\r
+\r
+     inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent (such as zalloc or state being Z_NULL).\r
+*/\r
 \r
-      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
-   stream state was inconsistent (such as zalloc or state being NULL).\r
+ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,\r
+                                      int windowBits));\r
+/*\r
+     This function is the same as inflateReset, but it also permits changing\r
+   the wrap and window size requests.  The windowBits parameter is interpreted\r
+   the same as it is for inflateInit2.\r
+\r
+     inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent (such as zalloc or state being Z_NULL), or if\r
+   the windowBits parameter is invalid.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,\r
+                                     int bits,\r
+                                     int value));\r
+/*\r
+     This function inserts bits in the inflate input stream.  The intent is\r
+   that this function is used to start inflating at a bit position in the\r
+   middle of a byte.  The provided bits will be used before any bytes are used\r
+   from next_in.  This function should only be used with raw inflate, and\r
+   should be used before the first inflate() call after inflateInit2() or\r
+   inflateReset().  bits must be less than or equal to 16, and that many of the\r
+   least significant bits of value will be inserted in the input.\r
+\r
+     If bits is negative, then the input stream bit buffer is emptied.  Then\r
+   inflatePrime() can be called again to put bits in the buffer.  This is used\r
+   to clear out bits leftover after feeding inflate a block description prior\r
+   to feeding inflate codes.\r
+\r
+     inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
 */\r
 \r
+ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));\r
 /*\r
-ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,\r
+     This function returns two values, one in the lower 16 bits of the return\r
+   value, and the other in the remaining upper bits, obtained by shifting the\r
+   return value down 16 bits.  If the upper value is -1 and the lower value is\r
+   zero, then inflate() is currently decoding information outside of a block.\r
+   If the upper value is -1 and the lower value is non-zero, then inflate is in\r
+   the middle of a stored block, with the lower value equaling the number of\r
+   bytes from the input remaining to copy.  If the upper value is not -1, then\r
+   it is the number of bits back from the current bit position in the input of\r
+   the code (literal or length/distance pair) currently being processed.  In\r
+   that case the lower value is the number of bytes already emitted for that\r
+   code.\r
+\r
+     A code is being processed if inflate is waiting for more input to complete\r
+   decoding of the code, or if it has completed decoding but is waiting for\r
+   more output space to write the literal or match data.\r
+\r
+     inflateMark() is used to mark locations in the input data for random\r
+   access, which may be at bit positions, and to note those cases where the\r
+   output of a code may span boundaries of random access blocks.  The current\r
+   location in the input stream can be determined from avail_in and data_type\r
+   as noted in the description for the Z_BLOCK flush parameter for inflate.\r
+\r
+     inflateMark returns the value noted above or -1 << 16 if the provided\r
+   source stream state was inconsistent.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,\r
+                                         gz_headerp head));\r
+/*\r
+     inflateGetHeader() requests that gzip header information be stored in the\r
+   provided gz_header structure.  inflateGetHeader() may be called after\r
+   inflateInit2() or inflateReset(), and before the first call of inflate().\r
+   As inflate() processes the gzip stream, head->done is zero until the header\r
+   is completed, at which time head->done is set to one.  If a zlib stream is\r
+   being decoded, then head->done is set to -1 to indicate that there will be\r
+   no gzip header information forthcoming.  Note that Z_BLOCK or Z_TREES can be\r
+   used to force inflate() to return immediately after header processing is\r
+   complete and before any actual data is decompressed.\r
+\r
+     The text, time, xflags, and os fields are filled in with the gzip header\r
+   contents.  hcrc is set to true if there is a header CRC.  (The header CRC\r
+   was valid if done is set to one.) If extra is not Z_NULL, then extra_max\r
+   contains the maximum number of bytes to write to extra.  Once done is true,\r
+   extra_len contains the actual extra field length, and extra contains the\r
+   extra field, or that field truncated if extra_max is less than extra_len.\r
+   If name is not Z_NULL, then up to name_max characters are written there,\r
+   terminated with a zero unless the length is greater than name_max.  If\r
+   comment is not Z_NULL, then up to comm_max characters are written there,\r
+   terminated with a zero unless the length is greater than comm_max.  When any\r
+   of extra, name, or comment are not Z_NULL and the respective field is not\r
+   present in the header, then that field is set to Z_NULL to signal its\r
+   absence.  This allows the use of deflateSetHeader() with the returned\r
+   structure to duplicate the header.  However if those fields are set to\r
+   allocated memory, then the application will need to save those pointers\r
+   elsewhere so that they can be eventually freed.\r
+\r
+     If inflateGetHeader is not used, then the header information is simply\r
+   discarded.  The header is always checked for validity, including the header\r
+   CRC if present.  inflateReset() will reset the process to discard the header\r
+   information.  The application would need to call inflateGetHeader() again to\r
+   retrieve the header from the next gzip stream.\r
+\r
+     inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+/*\r
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,\r
                                         unsigned char FAR *window));\r
 \r
      Initialize the internal stream state for decompression using inflateBack()\r
@@ -736,15 +962,15 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
      See inflateBack() for the usage of these routines.\r
 \r
      inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of\r
-   the paramaters are invalid, Z_MEM_ERROR if the internal state could not\r
-   be allocated, or Z_VERSION_ERROR if the version of the library does not\r
-   match the version of the header file.\r
+   the paramaters are invalid, Z_MEM_ERROR if the internal state could not be\r
+   allocated, or Z_VERSION_ERROR if the version of the library does not match\r
+   the version of the header file.\r
 */\r
 \r
 typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));\r
 typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));\r
 \r
-ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,\r
+ZEXTERN int ZEXPORT inflateBack OF((z_streamstrm,\r
                                     in_func in, void FAR *in_desc,\r
                                     out_func out, void FAR *out_desc));\r
 /*\r
@@ -758,15 +984,15 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
      inflateBackInit() must be called first to allocate the internal state\r
    and to initialize the state with the user-provided window buffer.\r
    inflateBack() may then be used multiple times to inflate a complete, raw\r
-   deflate stream with each call.  inflateBackEnd() is then called to free\r
-   the allocated state.\r
+   deflate stream with each call.  inflateBackEnd() is then called to free the\r
+   allocated state.\r
 \r
      A raw deflate stream is one with no zlib or gzip header or trailer.\r
    This routine would normally be used in a utility that reads zip or gzip\r
    files and writes out uncompressed files.  The utility would decode the\r
-   header and process the trailer on its own, hence this routine expects\r
-   only the raw deflate stream to decompress.  This is different from the\r
-   normal behavior of inflate(), which expects either a zlib or gzip header and\r
+   header and process the trailer on its own, hence this routine expects only\r
+   the raw deflate stream to decompress.  This is different from the normal\r
+   behavior of inflate(), which expects either a zlib or gzip header and\r
    trailer around the deflate stream.\r
 \r
      inflateBack() uses two subroutines supplied by the caller that are then\r
@@ -792,7 +1018,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
    calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called\r
    immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in\r
    must also be initialized, and then if strm->avail_in is not zero, input will\r
-   initially be taken from strm->next_in[0 .. strm->avail_in - 1].\r
+   initially be taken from strm->next_in[0 ..  strm->avail_in - 1].\r
 \r
      The in_desc and out_desc parameters of inflateBack() is passed as the\r
    first parameter of in() and out() respectively when they are called.  These\r
@@ -802,18 +1028,18 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
      On return, inflateBack() will set strm->next_in and strm->avail_in to\r
    pass back any unused input that was provided by the last in() call.  The\r
    return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR\r
-   if in() or out() returned an error, Z_DATA_ERROR if there was a format\r
-   error in the deflate stream (in which case strm->msg is set to indicate the\r
-   nature of the error), or Z_STREAM_ERROR if the stream was not properly\r
-   initialized.  In the case of Z_BUF_ERROR, an input or output error can be\r
-   distinguished using strm->next_in which will be Z_NULL only if in() returned\r
-   an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to\r
-   out() returning non-zero.  (in() will always be called before out(), so\r
-   strm->next_in is assured to be defined if out() returns non-zero.)  Note\r
-   that inflateBack() cannot return Z_OK.\r
+   if in() or out() returned an error, Z_DATA_ERROR if there was a format error\r
+   in the deflate stream (in which case strm->msg is set to indicate the nature\r
+   of the error), or Z_STREAM_ERROR if the stream was not properly initialized.\r
+   In the case of Z_BUF_ERROR, an input or output error can be distinguished\r
+   using strm->next_in which will be Z_NULL only if in() returned an error.  If\r
+   strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning\r
+   non-zero.  (in() will always be called before out(), so strm->next_in is\r
+   assured to be defined if out() returns non-zero.) Note that inflateBack()\r
+   cannot return Z_OK.\r
 */\r
 \r
-ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));\r
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamstrm));\r
 /*\r
      All memory allocated by inflateBackInit() is freed.\r
 \r
@@ -866,23 +1092,22 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
                         /* utility functions */\r
 \r
 /*\r
-     The following utility functions are implemented on top of the\r
-   basic stream-oriented functions. To simplify the interface, some\r
-   default options are assumed (compression level and memory usage,\r
-   standard memory allocation functions). The source code of these\r
-   utility functions can easily be modified if you need special options.\r
+     The following utility functions are implemented on top of the basic\r
+   stream-oriented functions.  To simplify the interface, some default options\r
+   are assumed (compression level and memory usage, standard memory allocation\r
+   functions).  The source code of these utility functions can be modified if\r
+   you need special options.\r
 */\r
 \r
 ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,\r
                                  const Bytef *source, uLong sourceLen));\r
 /*\r
      Compresses the source buffer into the destination buffer.  sourceLen is\r
-   the byte length of the source buffer. Upon entry, destLen is the total\r
-   size of the destination buffer, which must be at least the value returned\r
-   by compressBound(sourceLen). Upon exit, destLen is the actual size of the\r
+   the byte length of the source buffer.  Upon entry, destLen is the total size\r
+   of the destination buffer, which must be at least the value returned by\r
+   compressBound(sourceLen).  Upon exit, destLen is the actual size of the\r
    compressed buffer.\r
-     This function can be used to compress a whole file at once if the\r
-   input file is mmap'ed.\r
+\r
      compress returns Z_OK if success, Z_MEM_ERROR if there was not\r
    enough memory, Z_BUF_ERROR if there was not enough room in the output\r
    buffer.\r
@@ -892,11 +1117,11 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
                                   const Bytef *source, uLong sourceLen,\r
                                   int level));\r
 /*\r
-     Compresses the source buffer into the destination buffer. The level\r
+     Compresses the source buffer into the destination buffer.  The level\r
    parameter has the same meaning as in deflateInit.  sourceLen is the byte\r
-   length of the source buffer. Upon entry, destLen is the total size of the\r
+   length of the source buffer.  Upon entry, destLen is the total size of the\r
    destination buffer, which must be at least the value returned by\r
-   compressBound(sourceLen). Upon exit, destLen is the actual size of the\r
+   compressBound(sourceLen).  Upon exit, destLen is the actual size of the\r
    compressed buffer.\r
 \r
      compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
@@ -907,22 +1132,20 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
 ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));\r
 /*\r
      compressBound() returns an upper bound on the compressed size after\r
-   compress() or compress2() on sourceLen bytes.  It would be used before\r
-   compress() or compress2() call to allocate the destination buffer.\r
+   compress() or compress2() on sourceLen bytes.  It would be used before a\r
+   compress() or compress2() call to allocate the destination buffer.\r
 */\r
 \r
 ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r
                                    const Bytef *source, uLong sourceLen));\r
 /*\r
      Decompresses the source buffer into the destination buffer.  sourceLen is\r
-   the byte length of the source buffer. Upon entry, destLen is the total\r
-   size of the destination buffer, which must be large enough to hold the\r
-   entire uncompressed data. (The size of the uncompressed data must have\r
-   been saved previously by the compressor and transmitted to the decompressor\r
-   by some mechanism outside the scope of this compression library.)\r
-   Upon exit, destLen is the actual size of the compressed buffer.\r
-     This function can be used to decompress a whole file at once if the\r
-   input file is mmap'ed.\r
+   the byte length of the source buffer.  Upon entry, destLen is the total size\r
+   of the destination buffer, which must be large enough to hold the entire\r
+   uncompressed data.  (The size of the uncompressed data must have been saved\r
+   previously by the compressor and transmitted to the decompressor by some\r
+   mechanism outside the scope of this compression library.) Upon exit, destLen\r
+   is the actual size of the uncompressed buffer.\r
 \r
      uncompress returns Z_OK if success, Z_MEM_ERROR if there was not\r
    enough memory, Z_BUF_ERROR if there was not enough room in the output\r
@@ -930,136 +1153,199 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 */\r
 \r
 \r
-typedef voidp gzFile;\r
+                        /* gzip file access functions */\r
+\r
+/*\r
+     This library supports reading and writing files in gzip (.gz) format with\r
+   an interface similar to that of stdio, using the functions that start with\r
+   "gz".  The gzip format is different from the zlib format.  gzip is a gzip\r
+   wrapper, documented in RFC 1952, wrapped around a deflate stream.\r
+*/\r
+\r
+typedef voidp gzFile;       /* opaque gzip file descriptor */\r
 \r
-ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));\r
 /*\r
-     Opens a gzip (.gz) file for reading or writing. The mode parameter\r
-   is as in fopen ("rb" or "wb") but can also include a compression level\r
-   ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for\r
-   Huffman only compression as in "wb1h", or 'R' for run-length encoding\r
-   as in "wb1R". (See the description of deflateInit2 for more information\r
-   about the strategy parameter.)\r
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));\r
+\r
+     Opens a gzip (.gz) file for reading or writing.  The mode parameter is as\r
+   in fopen ("rb" or "wb") but can also include a compression level ("wb9") or\r
+   a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only\r
+   compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'\r
+   for fixed code compression as in "wb9F".  (See the description of\r
+   deflateInit2 for more information about the strategy parameter.) Also "a"\r
+   can be used instead of "w" to request that the gzip stream that will be\r
+   written be appended to the file.  "+" will result in an error, since reading\r
+   and writing to the same gzip file is not supported.\r
 \r
      gzopen can be used to read a file which is not in gzip format; in this\r
    case gzread will directly read from the file without decompression.\r
 \r
-     gzopen returns NULL if the file could not be opened or if there was\r
-   insufficient memory to allocate the (de)compression state; errno\r
-   can be checked to distinguish the two cases (if errno is zero, the\r
-   zlib error is Z_MEM_ERROR).  */\r
+     gzopen returns NULL if the file could not be opened, if there was\r
+   insufficient memory to allocate the gzFile state, or if an invalid mode was\r
+   specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).\r
+   errno can be checked to determine if the reason gzopen failed was that the\r
+   file could not be opened.\r
+*/\r
+\r
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));\r
+/*\r
+     gzdopen associates a gzFile with the file descriptor fd.  File descriptors\r
+   are obtained from calls like open, dup, creat, pipe or fileno (if the file\r
+   has been previously opened with fopen).  The mode parameter is as in gzopen.\r
+\r
+     The next call of gzclose on the returned gzFile will also close the file\r
+   descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor\r
+   fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,\r
+   mode);.  The duplicated descriptor should be saved to avoid a leak, since\r
+   gzdopen does not close fd if it fails.\r
+\r
+     gzdopen returns NULL if there was insufficient memory to allocate the\r
+   gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not\r
+   provided, or '+' was provided), or if fd is -1.  The file descriptor is not\r
+   used until the next gz* read, write, seek, or close operation, so gzdopen\r
+   will not detect if fd is invalid (unless fd is -1).\r
+*/\r
 \r
-ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));\r
+ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));\r
 /*\r
-     gzdopen() associates a gzFile with the file descriptor fd.  File\r
-   descriptors are obtained from calls like open, dup, creat, pipe or\r
-   fileno (in the file has been previously opened with fopen).\r
-   The mode parameter is as in gzopen.\r
-     The next call of gzclose on the returned gzFile will also close the\r
-   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file\r
-   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).\r
-     gzdopen returns NULL if there was insufficient memory to allocate\r
-   the (de)compression state.\r
+     Set the internal buffer size used by this library's functions.  The\r
+   default buffer size is 8192 bytes.  This function must be called after\r
+   gzopen() or gzdopen(), and before any other calls that read or write the\r
+   file.  The buffer memory allocation is always deferred to the first read or\r
+   write.  Two buffers are allocated, either both of the specified size when\r
+   writing, or one of the specified size and the other twice that size when\r
+   reading.  A larger buffer size of, for example, 64K or 128K bytes will\r
+   noticeably increase the speed of decompression (reading).\r
+\r
+     The new buffer size also affects the maximum length for gzprintf().\r
+\r
+     gzbuffer() returns 0 on success, or -1 on failure, such as being called\r
+   too late.\r
 */\r
 \r
 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));\r
 /*\r
-     Dynamically update the compression level or strategy. See the description\r
+     Dynamically update the compression level or strategy.  See the description\r
    of deflateInit2 for the meaning of these parameters.\r
+\r
      gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not\r
    opened for writing.\r
 */\r
 \r
-ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));\r
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));\r
 /*\r
-     Reads the given number of uncompressed bytes from the compressed file.\r
-   If the input file was not in gzip format, gzread copies the given number\r
-   of bytes into the buffer.\r
-     gzread returns the number of uncompressed bytes actually read (0 for\r
-   end of file, -1 for error). */\r
+     Reads the given number of uncompressed bytes from the compressed file.  If\r
+   the input file was not in gzip format, gzread copies the given number of\r
+   bytes into the buffer.\r
+\r
+     After reaching the end of a gzip stream in the input, gzread will continue\r
+   to read, looking for another gzip stream, or failing that, reading the rest\r
+   of the input file directly without decompression.  The entire input file\r
+   will be read if gzread is called until it returns less than the requested\r
+   len.\r
+\r
+     gzread returns the number of uncompressed bytes actually read, less than\r
+   len for end of file, or -1 for error.\r
+*/\r
 \r
-ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,\r
-                                   voidpc buf, unsigned len));\r
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,\r
+                                voidpc buf, unsigned len));\r
 /*\r
      Writes the given number of uncompressed bytes into the compressed file.\r
-   gzwrite returns the number of uncompressed bytes actually written\r
-   (0 in case of error).\r
+   gzwrite returns the number of uncompressed bytes written or 0 in case of\r
+   error.\r
 */\r
 \r
-ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));\r
+ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));\r
 /*\r
-     Converts, formats, and writes the args to the compressed file under\r
-   control of the format string, as in fprintf. gzprintf returns the number of\r
-   uncompressed bytes actually written (0 in case of error).  The number of\r
-   uncompressed bytes written is limited to 4095. The caller should assure that\r
-   this limit is not exceeded. If it is exceeded, then gzprintf() will return\r
-   return an error (0) with nothing written. In this case, there may also be a\r
-   buffer overflow with unpredictable consequences, which is possible only if\r
-   zlib was compiled with the insecure functions sprintf() or vsprintf()\r
-   because the secure snprintf() or vsnprintf() functions were not available.\r
+     Converts, formats, and writes the arguments to the compressed file under\r
+   control of the format string, as in fprintf.  gzprintf returns the number of\r
+   uncompressed bytes actually written, or 0 in case of error.  The number of\r
+   uncompressed bytes written is limited to 8191, or one less than the buffer\r
+   size given to gzbuffer().  The caller should assure that this limit is not\r
+   exceeded.  If it is exceeded, then gzprintf() will return an error (0) with\r
+   nothing written.  In this case, there may also be a buffer overflow with\r
+   unpredictable consequences, which is possible only if zlib was compiled with\r
+   the insecure functions sprintf() or vsprintf() because the secure snprintf()\r
+   or vsnprintf() functions were not available.  This can be determined using\r
+   zlibCompileFlags().\r
 */\r
 \r
 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));\r
 /*\r
-      Writes the given null-terminated string to the compressed file, excluding\r
+     Writes the given null-terminated string to the compressed file, excluding\r
    the terminating null character.\r
-      gzputs returns the number of characters written, or -1 in case of error.\r
+\r
+     gzputs returns the number of characters written, or -1 in case of error.\r
 */\r
 \r
 ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));\r
 /*\r
-      Reads bytes from the compressed file until len-1 characters are read, or\r
-   a newline character is read and transferred to buf, or an end-of-file\r
-   condition is encountered.  The string is then terminated with a null\r
-   character.\r
-      gzgets returns buf, or Z_NULL in case of error.\r
+     Reads bytes from the compressed file until len-1 characters are read, or a\r
+   newline character is read and transferred to buf, or an end-of-file\r
+   condition is encountered.  If any characters are read or if len == 1, the\r
+   string is terminated with a null character.  If no characters are read due\r
+   to an end-of-file or len < 1, then the buffer is left untouched.\r
+\r
+     gzgets returns buf which is a null-terminated string, or it returns NULL\r
+   for end-of-file or in case of error.  If there was an error, the contents at\r
+   buf are indeterminate.\r
 */\r
 \r
-ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));\r
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));\r
 /*\r
-      Writes c, converted to an unsigned char, into the compressed file.\r
-   gzputc returns the value that was written, or -1 in case of error.\r
+     Writes c, converted to an unsigned char, into the compressed file.  gzputc\r
+   returns the value that was written, or -1 in case of error.\r
 */\r
 \r
-ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));\r
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));\r
 /*\r
-      Reads one byte from the compressed file. gzgetc returns this byte\r
-   or -1 in case of end of file or error.\r
+     Reads one byte from the compressed file.  gzgetc returns this byte or -1\r
+   in case of end of file or error.\r
 */\r
 \r
-ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));\r
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));\r
 /*\r
-      Push one character back onto the stream to be read again later.\r
-   Only one character of push-back is allowed.  gzungetc() returns the\r
-   character pushed, or -1 on failure.  gzungetc() will fail if a\r
-   character has been pushed but not read yet, or if c is -1. The pushed\r
-   character will be discarded if the stream is repositioned with gzseek()\r
-   or gzrewind().\r
+     Push one character back onto the stream to be read as the first character\r
+   on the next read.  At least one character of push-back is allowed.\r
+   gzungetc() returns the character pushed, or -1 on failure.  gzungetc() will\r
+   fail if c is -1, and may fail if a character has been pushed but not read\r
+   yet.  If gzungetc is used immediately after gzopen or gzdopen, at least the\r
+   output buffer size of pushed characters is allowed.  (See gzbuffer above.)\r
+   The pushed character will be discarded if the stream is repositioned with\r
+   gzseek() or gzrewind().\r
 */\r
 \r
-ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));\r
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));\r
 /*\r
-     Flushes all pending output into the compressed file. The parameter\r
-   flush is as in the deflate() function. The return value is the zlib\r
-   error number (see function gzerror below). gzflush returns Z_OK if\r
-   the flush parameter is Z_FINISH and all output could be flushed.\r
-     gzflush should be called only when strictly necessary because it can\r
-   degrade compression.\r
+     Flushes all pending output into the compressed file.  The parameter flush\r
+   is as in the deflate() function.  The return value is the zlib error number\r
+   (see function gzerror below).  gzflush is only permitted when writing.\r
+\r
+     If the flush parameter is Z_FINISH, the remaining data is written and the\r
+   gzip stream is completed in the output.  If gzwrite() is called again, a new\r
+   gzip stream will be started in the output.  gzread() is able to read such\r
+   concatented gzip streams.\r
+\r
+     gzflush should be called only when strictly necessary because it will\r
+   degrade compression if called too often.\r
 */\r
 \r
-ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,\r
-                                      z_off_t offset, int whence));\r
 /*\r
-      Sets the starting position for the next gzread or gzwrite on the\r
-   given compressed file. The offset represents a number of bytes in the\r
-   uncompressed data stream. The whence parameter is defined as in lseek(2);\r
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,\r
+                                   z_off_t offset, int whence));\r
+\r
+     Sets the starting position for the next gzread or gzwrite on the given\r
+   compressed file.  The offset represents a number of bytes in the\r
+   uncompressed data stream.  The whence parameter is defined as in lseek(2);\r
    the value SEEK_END is not supported.\r
+\r
      If the file is opened for reading, this function is emulated but can be\r
-   extremely slow. If the file is opened for writing, only forward seeks are\r
+   extremely slow.  If the file is opened for writing, only forward seeks are\r
    supported; gzseek then compresses a sequence of zeroes up to the new\r
    starting position.\r
 \r
-      gzseek returns the resulting offset location as measured in bytes from\r
+     gzseek returns the resulting offset location as measured in bytes from\r
    the beginning of the uncompressed stream, or -1 in case of error, in\r
    particular if the file is opened for writing and the new starting position\r
    would be before the current position.\r
@@ -1069,63 +1355,127 @@ ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
 /*\r
      Rewinds the given file. This function is supported only for reading.\r
 \r
-   gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)\r
+     gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)\r
 */\r
 \r
+/*\r
 ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));\r
+\r
+     Returns the starting position for the next gzread or gzwrite on the given\r
+   compressed file.  This position represents a number of bytes in the\r
+   uncompressed data stream, and is zero when starting, even if appending or\r
+   reading a gzip stream from the middle of a file using gzdopen().\r
+\r
+     gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)\r
+*/\r
+\r
 /*\r
-     Returns the starting position for the next gzread or gzwrite on the\r
-   given compressed file. This position represents a number of bytes in the\r
-   uncompressed data stream.\r
+ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));\r
 \r
-   gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)\r
+     Returns the current offset in the file being read or written.  This offset\r
+   includes the count of bytes that precede the gzip stream, for example when\r
+   appending or when using gzdopen() for reading.  When reading, the offset\r
+   does not include as yet unused buffered input.  This information can be used\r
+   for a progress indicator.  On error, gzoffset() returns -1.\r
 */\r
 \r
 ZEXTERN int ZEXPORT gzeof OF((gzFile file));\r
 /*\r
-     Returns 1 when EOF has previously been detected reading the given\r
-   input stream, otherwise zero.\r
+     Returns true (1) if the end-of-file indicator has been set while reading,\r
+   false (0) otherwise.  Note that the end-of-file indicator is set only if the\r
+   read tried to go past the end of the input, but came up short.  Therefore,\r
+   just like feof(), gzeof() may return false even if there is no more data to\r
+   read, in the event that the last read request was for the exact number of\r
+   bytes remaining in the input file.  This will happen if the input file size\r
+   is an exact multiple of the buffer size.\r
+\r
+     If gzeof() returns true, then the read functions will return no more data,\r
+   unless the end-of-file indicator is reset by gzclearerr() and the input file\r
+   has grown since the previous end of file was detected.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));\r
+/*\r
+     Returns true (1) if file is being copied directly while reading, or false\r
+   (0) if file is a gzip stream being decompressed.  This state can change from\r
+   false to true while reading the input file if the end of a gzip stream is\r
+   reached, but is followed by data that is not another gzip stream.\r
+\r
+     If the input file is empty, gzdirect() will return true, since the input\r
+   does not contain a gzip stream.\r
+\r
+     If gzdirect() is used immediately after gzopen() or gzdopen() it will\r
+   cause buffers to be allocated to allow reading the file to determine if it\r
+   is a gzip file.  Therefore if gzbuffer() is used, it should be called before\r
+   gzdirect().\r
 */\r
 \r
 ZEXTERN int ZEXPORT    gzclose OF((gzFile file));\r
 /*\r
-     Flushes all pending output if necessary, closes the compressed file\r
-   and deallocates all the (de)compression state. The return value is the zlib\r
-   error number (see function gzerror below).\r
+     Flushes all pending output if necessary, closes the compressed file and\r
+   deallocates the (de)compression state.  Note that once file is closed, you\r
+   cannot call gzerror with file, since its structures have been deallocated.\r
+   gzclose must not be called more than once on the same file, just as free\r
+   must not be called more than once on the same allocation.\r
+\r
+     gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a\r
+   file operation error, or Z_OK on success.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));\r
+ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));\r
+/*\r
+     Same as gzclose(), but gzclose_r() is only for use when reading, and\r
+   gzclose_w() is only for use when writing or appending.  The advantage to\r
+   using these instead of gzclose() is that they avoid linking in zlib\r
+   compression or decompression code that is not used when only reading or only\r
+   writing respectively.  If gzclose() is used, then both compression and\r
+   decompression code will be included the application when linking to a static\r
+   zlib library.\r
 */\r
 \r
 ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));\r
 /*\r
-     Returns the error message for the last error which occurred on the\r
-   given compressed file. errnum is set to zlib error number. If an\r
-   error occurred in the file system and not in the compression library,\r
-   errnum is set to Z_ERRNO and the application may consult errno\r
-   to get the exact error code.\r
+     Returns the error message for the last error which occurred on the given\r
+   compressed file.  errnum is set to zlib error number.  If an error occurred\r
+   in the file system and not in the compression library, errnum is set to\r
+   Z_ERRNO and the application may consult errno to get the exact error code.\r
+\r
+     The application must not modify the returned string.  Future calls to\r
+   this function may invalidate the previously returned string.  If file is\r
+   closed, then the string previously returned by gzerror will no longer be\r
+   available.\r
+\r
+     gzerror() should be used to distinguish errors from end-of-file for those\r
+   functions above that do not distinguish those cases in their return values.\r
 */\r
 \r
 ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));\r
 /*\r
-     Clears the error and end-of-file flags for file. This is analogous to the\r
-   clearerr() function in stdio. This is useful for continuing to read a gzip\r
+     Clears the error and end-of-file flags for file.  This is analogous to the\r
+   clearerr() function in stdio.  This is useful for continuing to read a gzip\r
    file that is being written concurrently.\r
 */\r
 \r
+\r
                         /* checksum functions */\r
 \r
 /*\r
      These functions are not related to compression but are exported\r
-   anyway because they might be useful in applications using the\r
-   compression library.\r
+   anyway because they might be useful in applications using the compression\r
+   library.\r
 */\r
 \r
 ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));\r
-\r
 /*\r
      Update a running Adler-32 checksum with the bytes buf[0..len-1] and\r
-   return the updated checksum. If buf is NULL, this function returns\r
-   the required initial value for the checksum.\r
-   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed\r
-   much faster. Usage example:\r
+   return the updated checksum.  If buf is Z_NULL, this function returns the\r
+   required initial value for the checksum.\r
+\r
+     An Adler-32 checksum is almost as reliable as a CRC32 but can be computed\r
+   much faster.\r
+\r
+   Usage example:\r
 \r
      uLong adler = adler32(0L, Z_NULL, 0);\r
 \r
@@ -1135,12 +1485,24 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
      if (adler != original_adler) error();\r
 */\r
 \r
+/*\r
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,\r
+                                          z_off_t len2));\r
+\r
+     Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1\r
+   and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for\r
+   each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of\r
+   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.\r
+*/\r
+\r
 ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));\r
 /*\r
-     Update a running crc with the bytes buf[0..len-1] and return the updated\r
-   crc. If buf is NULL, this function returns the required initial value\r
-   for the crc. Pre- and post-conditioning (one's complement) is performed\r
-   within this function so it shouldn't be done by the application.\r
+     Update a running CRC-32 with the bytes buf[0..len-1] and return the\r
+   updated CRC-32.  If buf is Z_NULL, this function returns the required\r
+   initial value for the for the crc.  Pre- and post-conditioning (one's\r
+   complement) is performed within this function so it shouldn't be done by the\r
+   application.\r
+\r
    Usage example:\r
 \r
      uLong crc = crc32(0L, Z_NULL, 0);\r
@@ -1151,6 +1513,16 @@ ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
      if (crc != original_crc) error();\r
 */\r
 \r
+/*\r
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));\r
+\r
+     Combine two CRC-32 check values into one.  For two sequences of bytes,\r
+   seq1 and seq2 with lengths len1 and len2, CRC-32 check values were\r
+   calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32\r
+   check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and\r
+   len2.\r
+*/\r
+\r
 \r
                         /* various hacks, don't look :) */\r
 \r
@@ -1167,7 +1539,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
                                       int stream_size));\r
 ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,\r
                                       const char *version, int stream_size));\r
-ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,\r
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamstrm, int windowBits,\r
                                          unsigned char FAR *window,\r
                                          const char *version,\r
                                          int stream_size));\r
@@ -1182,16 +1554,57 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
         inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))\r
 #define inflateBackInit(strm, windowBits, window) \\r
         inflateBackInit_((strm), (windowBits), (window), \\r
-        ZLIB_VERSION, sizeof(z_stream))\r
+                                            ZLIB_VERSION, sizeof(z_stream))\r
 \r
+/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or\r
+ * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if\r
+ * both are true, the application gets the *64 functions, and the regular\r
+ * functions are changed to 64 bits) -- in case these are set on systems\r
+ * without large file support, _LFS64_LARGEFILE must also be true\r
+ */\r
+#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0\r
+   ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));\r
+   ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));\r
+   ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));\r
+   ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));\r
+   ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));\r
+   ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));\r
+#endif\r
+\r
+#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0\r
+#  define gzopen gzopen64\r
+#  define gzseek gzseek64\r
+#  define gztell gztell64\r
+#  define gzoffset gzoffset64\r
+#  define adler32_combine adler32_combine64\r
+#  define crc32_combine crc32_combine64\r
+#  ifdef _LARGEFILE64_SOURCE\r
+     ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));\r
+     ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));\r
+     ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));\r
+     ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));\r
+     ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));\r
+     ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));\r
+#  endif\r
+#else\r
+   ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));\r
+   ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));\r
+   ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));\r
+   ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));\r
+   ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));\r
+   ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));\r
+#endif\r
 \r
+/* hack for buggy compilers */\r
 #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)\r
-    struct internal_state {int dummy;}; /* hack for buggy compilers */\r
+    struct internal_state {int dummy;};\r
 #endif\r
 \r
-ZEXTERN const char   * ZEXPORT zError           OF((int err));\r
-ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));\r
+/* undocumented functions */\r
+ZEXTERN const char   * ZEXPORT zError           OF((int));\r
+ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp));\r
 ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));\r
+ZEXTERN int            ZEXPORT inflateUndermine OF((z_streamp, int));\r
 \r
 #ifdef __cplusplus\r
 }\r
index a94cdb8..e33ae8b 100644 (file)
@@ -1,5 +1,5 @@
 /* zutil.c -- target dependent utility functions for the compression library\r
- * Copyright (C) 1995-2003 Jean-loup Gailly.\r
+ * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 struct internal_state      {int dummy;}; /* for buggy compilers */\r
 #endif\r
 \r
-#ifndef STDC\r
-extern void exit OF((int));\r
-#endif\r
-\r
 const char * const z_errmsg[10] = {\r
 "need dictionary",     /* Z_NEED_DICT       2  */\r
 "stream end",          /* Z_STREAM_END      1  */\r
@@ -38,25 +34,25 @@ uLong ZEXPORT zlibCompileFlags()
     uLong flags;\r
 \r
     flags = 0;\r
-    switch (sizeof(uInt)) {\r
+    switch ((int)(sizeof(uInt))) {\r
     case 2:     break;\r
     case 4:     flags += 1;     break;\r
     case 8:     flags += 2;     break;\r
     default:    flags += 3;\r
     }\r
-    switch (sizeof(uLong)) {\r
+    switch ((int)(sizeof(uLong))) {\r
     case 2:     break;\r
     case 4:     flags += 1 << 2;        break;\r
     case 8:     flags += 2 << 2;        break;\r
     default:    flags += 3 << 2;\r
     }\r
-    switch (sizeof(voidpf)) {\r
+    switch ((int)(sizeof(voidpf))) {\r
     case 2:     break;\r
     case 4:     flags += 1 << 4;        break;\r
     case 8:     flags += 2 << 4;        break;\r
     default:    flags += 3 << 4;\r
     }\r
-    switch (sizeof(z_off_t)) {\r
+    switch ((int)(sizeof(z_off_t))) {\r
     case 2:     break;\r
     case 4:     flags += 1 << 6;        break;\r
     case 8:     flags += 2 << 6;        break;\r
@@ -78,38 +74,38 @@ uLong ZEXPORT zlibCompileFlags()
     flags += 1 << 13;\r
 #endif\r
 #ifdef NO_GZCOMPRESS\r
-    flags += 1 << 16;\r
+    flags += 1L << 16;\r
 #endif\r
 #ifdef NO_GZIP\r
-    flags += 1 << 17;\r
+    flags += 1L << 17;\r
 #endif\r
 #ifdef PKZIP_BUG_WORKAROUND\r
-    flags += 1 << 20;\r
+    flags += 1L << 20;\r
 #endif\r
 #ifdef FASTEST\r
-    flags += 1 << 21;\r
+    flags += 1L << 21;\r
 #endif\r
 #ifdef STDC\r
 #  ifdef NO_vsnprintf\r
-        flags += 1 << 25;\r
+        flags += 1L << 25;\r
 #    ifdef HAS_vsprintf_void\r
-        flags += 1 << 26;\r
+        flags += 1L << 26;\r
 #    endif\r
 #  else\r
 #    ifdef HAS_vsnprintf_void\r
-        flags += 1 << 26;\r
+        flags += 1L << 26;\r
 #    endif\r
 #  endif\r
 #else\r
-        flags += 1 << 24;\r
+        flags += 1L << 24;\r
 #  ifdef NO_snprintf\r
-        flags += 1 << 25;\r
+        flags += 1L << 25;\r
 #    ifdef HAS_sprintf_void\r
-        flags += 1 << 26;\r
+        flags += 1L << 26;\r
 #    endif\r
 #  else\r
 #    ifdef HAS_snprintf_void\r
-        flags += 1 << 26;\r
+        flags += 1L << 26;\r
 #    endif\r
 #  endif\r
 #endif\r
@@ -121,9 +117,9 @@ uLong ZEXPORT zlibCompileFlags()
 #  ifndef verbose\r
 #    define verbose 0\r
 #  endif\r
-int z_verbose = verbose;\r
+int ZLIB_INTERNAL z_verbose = verbose;\r
 \r
-void z_error (m)\r
+void ZLIB_INTERNAL z_error (m)\r
     char *m;\r
 {\r
     fprintf(stderr, "%s\n", m);\r
@@ -141,13 +137,16 @@ const char * ZEXPORT zError(err)
 }\r
 \r
 #if defined(_WIN32_WCE)\r
-    /* does not exist on WCE */\r
+    /* The Microsoft C Run-Time Library for Windows CE doesn't have\r
+     * errno.  We define it as a global variable to simplify porting.\r
+     * Its value is always 0 and should not be used.\r
+     */\r
     int errno = 0;\r
 #endif\r
 \r
 #ifndef HAVE_MEMCPY\r
 \r
-void zmemcpy(dest, source, len)\r
+void ZLIB_INTERNAL zmemcpy(dest, source, len)\r
     Bytef* dest;\r
     const Bytef* source;\r
     uInt  len;\r
@@ -158,7 +157,7 @@ void zmemcpy(dest, source, len)
     } while (--len != 0);\r
 }\r
 \r
-int zmemcmp(s1, s2, len)\r
+int ZLIB_INTERNAL zmemcmp(s1, s2, len)\r
     const Bytef* s1;\r
     const Bytef* s2;\r
     uInt  len;\r
@@ -171,7 +170,7 @@ int zmemcmp(s1, s2, len)
     return 0;\r
 }\r
 \r
-void zmemzero(dest, len)\r
+void ZLIB_INTERNAL zmemzero(dest, len)\r
     Bytef* dest;\r
     uInt  len;\r
 {\r
@@ -214,7 +213,7 @@ local ptr_table table[MAX_PTR];
  * a protected system like OS/2. Use Microsoft C instead.\r
  */\r
 \r
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)\r
+voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)\r
 {\r
     voidpf buf = opaque; /* just to make some compilers happy */\r
     ulg bsize = (ulg)items*size;\r
@@ -238,7 +237,7 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
     return buf;\r
 }\r
 \r
-void  zcfree (voidpf opaque, voidpf ptr)\r
+void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)\r
 {\r
     int n;\r
     if (*(ush*)&ptr != 0) { /* object < 64K */\r
@@ -273,13 +272,13 @@ void  zcfree (voidpf opaque, voidpf ptr)
 #  define _hfree   hfree\r
 #endif\r
 \r
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)\r
+voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)\r
 {\r
     if (opaque) opaque = 0; /* to make compiler happy */\r
     return _halloc((long)items, size);\r
 }\r
 \r
-void  zcfree (voidpf opaque, voidpf ptr)\r
+void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)\r
 {\r
     if (opaque) opaque = 0; /* to make compiler happy */\r
     _hfree(ptr);\r
@@ -298,7 +297,7 @@ extern voidp  calloc OF((uInt items, uInt size));
 extern void   free   OF((voidpf ptr));\r
 #endif\r
 \r
-voidpf zcalloc (opaque, items, size)\r
+voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)\r
     voidpf opaque;\r
     unsigned items;\r
     unsigned size;\r
@@ -308,7 +307,7 @@ voidpf zcalloc (opaque, items, size)
                               (voidpf)calloc(items, size);\r
 }\r
 \r
-void  zcfree (opaque, ptr)\r
+void ZLIB_INTERNAL zcfree (opaque, ptr)\r
     voidpf opaque;\r
     voidpf ptr;\r
 {\r
index 06cb62e..a36a406 100644 (file)
@@ -1,5 +1,5 @@
 /* zutil.h -- internal interface and configuration of the compression library\r
- * Copyright (C) 1995-2003 Jean-loup Gailly.\r
+ * Copyright (C) 1995-2010 Jean-loup Gailly.\r
  * For conditions of distribution and use, see copyright notice in zlib.h\r
  */\r
 \r
 #ifndef ZUTIL_H\r
 #define ZUTIL_H\r
 \r
-#define ZLIB_INTERNAL\r
+#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)\r
+#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))\r
+#else\r
+#  define ZLIB_INTERNAL\r
+#endif\r
+\r
 #include "zlib.h"\r
 \r
 #ifdef STDC\r
-#  include <stddef.h>\r
+#  if !(defined(_WIN32_WCE) && defined(_MSC_VER))\r
+#    include <stddef.h>\r
+#  endif\r
 #  include <string.h>\r
 #  include <stdlib.h>\r
 #endif\r
-#ifdef NO_ERRNO_H\r
-    extern int errno;\r
-#else\r
-#   include <errno.h>\r
-#endif\r
 \r
 #ifndef local\r
 #  define local static\r
@@ -77,7 +79,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))\r
 #  define OS_CODE  0x00\r
 #  if defined(__TURBOC__) || defined(__BORLANDC__)\r
-#    if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))\r
+#    if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))\r
        /* Allow compilation with ANSI keywords only enabled */\r
        void _Cdecl farfree( void *block );\r
        void *_Cdecl farmalloc( unsigned long nbytes );\r
@@ -105,6 +107,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 \r
 #ifdef OS2\r
 #  define OS_CODE  0x06\r
+#  ifdef M_I86\r
+#    include <malloc.h>\r
+#  endif\r
 #endif\r
 \r
 #if defined(MACOS) || defined(TARGET_OS_MAC)\r
@@ -136,7 +141,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  define fdopen(fd,mode) NULL /* No fdopen() */\r
 #endif\r
 \r
-#if (defined(_MSC_VER) && (_MSC_VER > 600))\r
+#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX\r
 #  if defined(_WIN32_WCE)\r
 #    define fdopen(fd,mode) NULL /* No fdopen() */\r
 #    ifndef _PTRDIFF_T_DEFINED\r
@@ -148,6 +153,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  endif\r
 #endif\r
 \r
+#if defined(__BORLANDC__)\r
+  #pragma warn -8004\r
+  #pragma warn -8008\r
+  #pragma warn -8066\r
+#endif\r
+\r
+/* provide prototypes for these when building zlib without LFS */\r
+#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0\r
+    ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));\r
+    ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));\r
+#endif\r
+\r
         /* common defaults */\r
 \r
 #ifndef OS_CODE\r
@@ -182,19 +199,17 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  ifdef WIN32\r
      /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */\r
 #    if !defined(vsnprintf) && !defined(NO_vsnprintf)\r
-#      define vsnprintf _vsnprintf\r
+#      if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )\r
+#         define vsnprintf _vsnprintf\r
+#      endif\r
 #    endif\r
 #  endif\r
 #  ifdef __SASC\r
 #    define NO_vsnprintf\r
 #  endif\r
 #endif\r
-\r
-#ifdef HAVE_STRERROR\r
-   extern char *strerror OF((int));\r
-#  define zstrerror(errnum) strerror(errnum)\r
-#else\r
-#  define zstrerror(errnum) ""\r
+#ifdef VMS\r
+#  define NO_vsnprintf\r
 #endif\r
 \r
 #if defined(pyr)\r
@@ -221,16 +236,16 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #    define zmemzero(dest, len) memset(dest, 0, len)\r
 #  endif\r
 #else\r
-   extern void zmemcpy  OF((Bytef* dest, const Bytef* source, uInt len));\r
-   extern int  zmemcmp  OF((const Bytef* s1, const Bytef* s2, uInt len));\r
-   extern void zmemzero OF((Bytef* dest, uInt len));\r
+   void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));\r
+   int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));\r
+   void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));\r
 #endif\r
 \r
 /* Diagnostic functions */\r
 #ifdef DEBUG\r
 #  include <stdio.h>\r
-   extern int z_verbose;\r
-   extern void z_error    OF((char *m));\r
+   extern int ZLIB_INTERNAL z_verbose;\r
+   extern void ZLIB_INTERNAL z_error OF((char *m));\r
 #  define Assert(cond,msg) {if(!(cond)) z_error(msg);}\r
 #  define Trace(x) {if (z_verbose>=0) fprintf x ;}\r
 #  define Tracev(x) {if (z_verbose>0) fprintf x ;}\r
@@ -247,8 +262,9 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #endif\r
 \r
 \r
-voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));\r
-void   zcfree  OF((voidpf opaque, voidpf ptr));\r
+voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,\r
+                        unsigned size));\r
+void ZLIB_INTERNAL zcfree  OF((voidpf opaque, voidpf ptr));\r
 \r
 #define ZALLOC(strm, items, size) \\r
            (*((strm)->zalloc))((strm)->opaque, (items), (size))\r