zlib 1.2.1
diff --git a/ChangeLog b/ChangeLog
index e9262ae..48e465f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
 
                 ChangeLog file for zlib
 
+Changes in 1.2.1 (17 November 2003)
+- Remove a tab in contrib/gzappend/gzappend.c
+- Update some interfaces in contrib for new zlib functions
+- Update zlib version number in some contrib entries
+- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
+- Support shared libraries on Hurd and KFreeBSD [Brown]
+- Fix error in NO_DIVIDE option of adler32.c
+
 Changes in 1.2.0.8 (4 November 2003)
 - Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
 - Add experimental NO_DIVIDE #define in adler32.c
@@ -18,7 +26,7 @@
 - Add -p to mkdir's in Makefile.in [vda]
 - Fix configure to properly detect presence or lack of printf functions
 - Add AS400 support [Monnerat]
-- Added a little Cygwin support [Wilson]
+- Add a little Cygwin support [Wilson]
 
 Changes in 1.2.0.7 (21 September 2003)
 - Correct some debug formats in contrib/infback9
diff --git a/Makefile b/Makefile
index fa4f588..ab4611b 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@
 
 LIBS=libz.a
 SHAREDLIB=libz.so
-SHAREDLIBV=libz.so.1.2.0.8
+SHAREDLIBV=libz.so.1.2.1
 SHAREDLIBM=libz.so.1
 
 AR=ar rc
diff --git a/Makefile.in b/Makefile.in
index fa4f588..ab4611b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -30,7 +30,7 @@
 
 LIBS=libz.a
 SHAREDLIB=libz.so
-SHAREDLIBV=libz.so.1.2.0.8
+SHAREDLIBV=libz.so.1.2.1
 SHAREDLIBM=libz.so.1
 
 AR=ar rc
diff --git a/README b/README
index a087104..0f12054 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 ZLIB DATA COMPRESSION LIBRARY
 
-zlib 1.2.0.8 is a general purpose data compression library.  All the code is
+zlib 1.2.1 is a general purpose data compression library.  All the code is
 thread safe.  The data format used by the zlib library is described by RFCs
 (Request for Comments) 1950 to 1952 in the files
 http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
@@ -34,7 +34,7 @@
 issue of  Dr. Dobb's Journal; a copy of the article is available in
 http://dogma.net/markn/articles/zlibtool/zlibtool.htm
 
-The changes made in version 1.2.0.8 are documented in the file ChangeLog.
+The changes made in version 1.2.1 are documented in the file ChangeLog.
 
 Unsupported third party contributions are provided in directory "contrib".
 
diff --git a/adler32.c b/adler32.c
index bad930e..624a169 100644
--- a/adler32.c
+++ b/adler32.c
@@ -21,23 +21,23 @@
 #ifdef NO_DIVIDE
 #  define MOD(a) \
     do { \
-        if (a > (BASE << 16)) a -= (BASE << 16); \
-        if (a > (BASE << 15)) a -= (BASE << 15); \
-        if (a > (BASE << 14)) a -= (BASE << 14); \
-        if (a > (BASE << 13)) a -= (BASE << 13); \
-        if (a > (BASE << 12)) a -= (BASE << 12); \
-        if (a > (BASE << 11)) a -= (BASE << 11); \
-        if (a > (BASE << 10)) a -= (BASE << 10); \
-        if (a > (BASE << 9)) a -= (BASE << 9); \
-        if (a > (BASE << 8)) a -= (BASE << 8); \
-        if (a > (BASE << 7)) a -= (BASE << 7); \
-        if (a > (BASE << 6)) a -= (BASE << 6); \
-        if (a > (BASE << 5)) a -= (BASE << 5); \
-        if (a > (BASE << 4)) a -= (BASE << 4); \
-        if (a > (BASE << 3)) a -= (BASE << 3); \
-        if (a > (BASE << 2)) a -= (BASE << 2); \
-        if (a > (BASE << 1)) a -= (BASE << 1); \
-        if (a > BASE) a -= BASE; \
+        if (a >= (BASE << 16)) a -= (BASE << 16); \
+        if (a >= (BASE << 15)) a -= (BASE << 15); \
+        if (a >= (BASE << 14)) a -= (BASE << 14); \
+        if (a >= (BASE << 13)) a -= (BASE << 13); \
+        if (a >= (BASE << 12)) a -= (BASE << 12); \
+        if (a >= (BASE << 11)) a -= (BASE << 11); \
+        if (a >= (BASE << 10)) a -= (BASE << 10); \
+        if (a >= (BASE << 9)) a -= (BASE << 9); \
+        if (a >= (BASE << 8)) a -= (BASE << 8); \
+        if (a >= (BASE << 7)) a -= (BASE << 7); \
+        if (a >= (BASE << 6)) a -= (BASE << 6); \
+        if (a >= (BASE << 5)) a -= (BASE << 5); \
+        if (a >= (BASE << 4)) a -= (BASE << 4); \
+        if (a >= (BASE << 3)) a -= (BASE << 3); \
+        if (a >= (BASE << 2)) a -= (BASE << 2); \
+        if (a >= (BASE << 1)) a -= (BASE << 1); \
+        if (a >= BASE) a -= BASE; \
     } while (0)
 #else
 #  define MOD(a) a %= BASE
diff --git a/as400/bndsrc b/as400/bndsrc
index a963e3a..9cf94bb 100644
--- a/as400/bndsrc
+++ b/as400/bndsrc
@@ -87,7 +87,7 @@
   EXPORT SYMBOL("zError")
 
 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
-/*   Version 1.2.0.7 additional entry points.                       */
+/*   Version 1.2.1 additional entry points.                         */
 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
 
 /********************************************************************/
diff --git a/as400/compile.clp b/as400/compile.clp
index 4f8700c..dcd2421 100644
--- a/as400/compile.clp
+++ b/as400/compile.clp
@@ -118,6 +118,6 @@
                                  &MODLIB/INFTREES    &MODLIB/TREES       +
                                  &MODLIB/UNCOMPR     &MODLIB/ZUTIL)      +
                           SRCFILE(&SRCLIB/&CTLFILE) SRCMBR(BNDSRC) +
-                          TEXT('ZLIB 1.2.0.7') TGTRLS(V4R4M0)
+                          TEXT('ZLIB 1.2.1') TGTRLS(V4R4M0)
 
              ENDPGM
diff --git a/as400/readme.txt b/as400/readme.txt
index 7ce5ed1..eef7cb2 100644
--- a/as400/readme.txt
+++ b/as400/readme.txt
@@ -1,4 +1,4 @@
-        ZLIB version 1.2.0.7 for AS400 installation instructions
+        ZLIB version 1.2.1 for AS400 installation instructions
 
 I) From an AS400 *SAVF file:
 
diff --git a/as400/zlib.inc b/as400/zlib.inc
index 9a0fc54..03c6cf0 100644
--- a/as400/zlib.inc
+++ b/as400/zlib.inc
@@ -1,7 +1,7 @@
       *  ZLIB.INC - Interface to the general purpose compression library
       *
       *  ILE RPG400 version by Patrick Monnerat, DATASPHERE.
-      *  Version 1.2.0.7
+      *  Version 1.2.1
       *
       *
       *  WARNING:
@@ -20,8 +20,8 @@
       *                               Constants
       **************************************************************************
       *
-     D ZLIB_VERSION    C                   '1.2.0.8'                            Header's version
-     D ZLIB_VERNUM     C                   X'1208'
+     D ZLIB_VERSION    C                   '1.2.1'                            Header's version
+     D ZLIB_VERNUM     C                   X'1210'
       *
      D Z_NO_FLUSH      C                   0
      D Z_SYNC_FLUSH    C                   2
diff --git a/configure b/configure
index 92a5737..d698479 100755
--- a/configure
+++ b/configure
@@ -76,7 +76,7 @@
   SFLAGS=${CFLAGS-"-fPIC -O3"}
   CFLAGS="$cflags"
   case `(uname -s || echo unknown) 2>/dev/null` in
-  Linux | linux) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};;
+  Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};;
   CYGWIN* | Cygwin* | cygwin* )
              EXE='.exe';;
   QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
diff --git a/contrib/ada/zlib-thin.ads b/contrib/ada/zlib-thin.ads
index af1287a..c227374 100644
--- a/contrib/ada/zlib-thin.ads
+++ b/contrib/ada/zlib-thin.ads
@@ -146,17 +146,6 @@
       strategy : Int)
       return     Int;       -- zlib.h:506
 
-   function deflateBound
-     (strm     : Z_Streamp;
-      sourceLen : ULong)
-      return     Int;       -- zlib.h:595
-
-   function deflatePrime
-     (strm     : Z_Streamp;
-      bits     : Int;
-      value    : Int)
-      return     Int;       -- zlib.h:604
-
    function inflateSetDictionary
      (strm       : Z_Streamp;
       dictionary : Byte_Access;
@@ -399,6 +388,12 @@
 
    function zlibCompileFlags return ULong;
 
+   function deflatePrime
+     (strm     : Z_Streamp;
+      bits     : Int;
+      value    : Int)
+      return     Int;
+
 private
 
    type Z_Stream is record            -- zlib.h:68
@@ -432,8 +427,6 @@
    pragma Import (C, deflateCopy, "deflateCopy");
    pragma Import (C, deflateReset, "deflateReset");
    pragma Import (C, deflateParams, "deflateParams");
-   pragma Import (C, deflateBound, "deflateBound");
-   pragma Import (C, deflatePrime, "deflatePrime");
    pragma Import (C, inflateSetDictionary, "inflateSetDictionary");
    pragma Import (C, inflateSync, "inflateSync");
    pragma Import (C, inflateReset, "inflateReset");
@@ -467,13 +460,14 @@
    pragma Import (C, inflateSyncPoint, "inflateSyncPoint");
    pragma Import (C, get_crc_table, "get_crc_table");
 
-   --  since zlib 1.2.0:
+   --  added in zlib 1.2.1:
 
    pragma Import (C, inflateCopy, "inflateCopy");
    pragma Import (C, compressBound, "compressBound");
    pragma Import (C, deflateBound, "deflateBound");
    pragma Import (C, gzungetc, "gzungetc");
    pragma Import (C, zlibCompileFlags, "zlibCompileFlags");
+   pragma Import (C, deflatePrime, "deflatePrime");
 
    pragma Import (C, inflateBackInit, "inflateBackInit_");
 
diff --git a/contrib/delphi/readme.txt b/contrib/delphi/readme.txt
index 65e58b3..2dc9a8b 100644
--- a/contrib/delphi/readme.txt
+++ b/contrib/delphi/readme.txt
@@ -14,7 +14,7 @@
 Summary of modifications
 ========================
 
-- Improved makefile, adapted to zlib version 1.2.0.
+- Improved makefile, adapted to zlib version 1.2.1.
 
 - Some field types from TZStreamRec are changed from Integer to
   Longint, for consistency with the zlib.h header, and for 64-bit
diff --git a/contrib/gzappend/gzappend.c b/contrib/gzappend/gzappend.c
index f051864..f2e9e4f 100644
--- a/contrib/gzappend/gzappend.c
+++ b/contrib/gzappend/gzappend.c
@@ -167,7 +167,7 @@
 /* structure for gzip file read operations */
 typedef struct {
     int fd;                     /* file descriptor */
-    int size;              	/* 1 << size is bytes in buf */
+    int size;                   /* 1 << size is bytes in buf */
     unsigned left;              /* bytes available at next */
     unsigned char *buf;         /* buffer */
     unsigned char *next;        /* next byte in buffer */
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c
index 44ff721..fe76a1b 100644
--- a/contrib/infback9/inftree9.c
+++ b/contrib/infback9/inftree9.c
@@ -9,7 +9,7 @@
 #define MAXBITS 15
 
 const char inflate9_copyright[] =
-   " inflate9 1.2.0.8 Copyright 1995-2003 Mark Adler ";
+   " inflate9 1.2.1 Copyright 1995-2003 Mark Adler ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -64,7 +64,7 @@
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */
         128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
         130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
-        133, 133, 133, 133, 144, 76, 203};
+        133, 133, 133, 133, 144, 76, 66};
     static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
         65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
diff --git a/contrib/pascal/zlibpas.pas b/contrib/pascal/zlibpas.pas
index 9361914..6d5ebe0 100644
--- a/contrib/pascal/zlibpas.pas
+++ b/contrib/pascal/zlibpas.pas
@@ -166,6 +166,7 @@
 function deflateInit_; external;
 function deflateInit2_; external;
 function deflateParams; external;
+function deflatePrime; external;
 function deflateReset; external;
 function deflateSetDictionary; external;
 function inflate; external;
diff --git a/deflate.c b/deflate.c
index 9e90a79..0525b2f 100644
--- a/deflate.c
+++ b/deflate.c
@@ -52,7 +52,7 @@
 #include "deflate.h"
 
 const char deflate_copyright[] =
-   " deflate 1.2.0.8 Copyright 1995-2003 Jean-loup Gailly ";
+   " deflate 1.2.1 Copyright 1995-2003 Jean-loup Gailly ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
diff --git a/inftrees.c b/inftrees.c
index 40de021..3bb5639 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -9,7 +9,7 @@
 #define MAXBITS 15
 
 const char inflate_copyright[] =
-   " inflate 1.2.0.8 Copyright 1995-2003 Mark Adler ";
+   " inflate 1.2.1 Copyright 1995-2003 Mark Adler ";
 /*
   If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */
         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
-        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 76, 203};
+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 76, 66};
     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
diff --git a/old/README b/old/README
index e2700df..06ebe3d 100644
--- a/old/README
+++ b/old/README
@@ -1,3 +1,3 @@
-This directory contains files that have not been updated for zlib 1.2.
+This directory contains files that have not been updated for zlib 1.2.1
 
 (Volunteers are encouraged to help clean this up.  Thanks.)
diff --git a/qnx/package.qpg b/qnx/package.qpg
index 69336d9..2b7d951 100644
--- a/qnx/package.qpg
+++ b/qnx/package.qpg
@@ -25,10 +25,10 @@
       <QPG:Files>
          <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
          <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
-         <QPG:Add file="../libz.so.1.2.0.8" install="/opt/lib/" user="root:bin" permission="644"/>
-         <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.0.8"/>
-         <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.0.8"/>
-         <QPG:Add file="../libz.so.1.2.0.8" install="/opt/lib/" component="slib"/>
+         <QPG:Add file="../libz.so.1.2.1" install="/opt/lib/" user="root:bin" permission="644"/>
+         <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.1"/>
+         <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.1"/>
+         <QPG:Add file="../libz.so.1.2.1" install="/opt/lib/" component="slib"/>
       </QPG:Files>
 
       <QPG:PackageFilter>
@@ -63,7 +63,7 @@
             </QPM:ProductDescription>
 
             <QPM:ReleaseDescription>
-               <QPM:ReleaseVersion>1.2.0.8</QPM:ReleaseVersion>
+               <QPM:ReleaseVersion>1.2.1</QPM:ReleaseVersion>
                <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
                <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
                <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
diff --git a/win32/zlib1.rc b/win32/zlib1.rc
index 09a06f5..326375d 100644
--- a/win32/zlib1.rc
+++ b/win32/zlib1.rc
@@ -5,8 +5,8 @@
 #else
 VS_VERSION_INFO		VERSIONINFO	MOVEABLE IMPURE LOADONCALL DISCARDABLE
 #endif
-  FILEVERSION		1,2,0,8
-  PRODUCTVERSION	1,2,0,8
+  FILEVERSION		1,2,1,0
+  PRODUCTVERSION	1,2,1,0
   FILEFLAGSMASK		VS_FFI_FILEFLAGSMASK
 #ifdef _DEBUG
   FILEFLAGS		1
@@ -23,12 +23,12 @@
     //language ID = U.S. English, char set = Windows, Multilingual
     BEGIN
       VALUE "FileDescription",	"zlib data compression library\0"
-      VALUE "FileVersion",	"1.2.0.8\0"
+      VALUE "FileVersion",	"1.2.1\0"
       VALUE "InternalName",	"zlib1.dll\0"
       VALUE "LegalCopyright",	"(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
       VALUE "OriginalFilename",	"zlib1.dll\0"
       VALUE "ProductName",	"zlib\0"
-      VALUE "ProductVersion",	"1.2.0.8\0"
+      VALUE "ProductVersion",	"1.2.1\0"
       VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
     END
   END
diff --git a/zlib.3 b/zlib.3
index f0c172b..8900984 100644
--- a/zlib.3
+++ b/zlib.3
@@ -1,4 +1,4 @@
-.TH ZLIB 3 "4 November 2003"
+.TH ZLIB 3 "17 November 2003"
 .SH NAME
 zlib \- compression/decompression library
 .SH SYNOPSIS
@@ -133,7 +133,7 @@
 Send questions and/or comments to zlib@gzip.org,
 or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
 .SH AUTHORS
-Version 1.2.0.8
+Version 1.2.1
 Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org)
 and Mark Adler (madler@alumni.caltech.edu).
 .LP
diff --git a/zlib.h b/zlib.h
index 6dc55cd..92edf96 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
 /* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.2.0.8, November 4th, 2003
+  version 1.2.1, November 17th, 2003
 
   Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
 
@@ -37,8 +37,8 @@
 extern "C" {
 #endif
 
-#define ZLIB_VERSION "1.2.0.8"
-#define ZLIB_VERNUM 0x1208
+#define ZLIB_VERSION "1.2.1"
+#define ZLIB_VERNUM 0x1210
 
 /*
      The 'zlib' compression library provides in-memory compression and
diff --git a/zutil.h b/zutil.h
index c2c98d9..87b70ac 100644
--- a/zutil.h
+++ b/zutil.h
@@ -139,6 +139,10 @@
 #if (defined(_MSC_VER) && (_MSC_VER > 600))
 #  if defined(_WIN32_WCE)
 #    define fdopen(fd,mode) NULL /* No fdopen() */
+#    ifndef _PTRDIFF_T_DEFINED
+       typedef int ptrdiff_t;
+#      define _PTRDIFF_T_DEFINED
+#    endif
 #  else
 #    define fdopen(fd,type)  _fdopen(fd,type)
 #  endif