]> git.ozlabs.org Git - ppp.git/blobdiff - common/zlib.c
updated FILEVERSION
[ppp.git] / common / zlib.c
index ab68d4438bfd54b1489312236c0868d311f6d4d5..b9da5f9fe0511d3327c05886595291a3c7420192 100644 (file)
  * - added Z_PACKET_FLUSH (see zlib.h for details)
  * - added inflateIncomp
  *
- * $Id: zlib.c,v 1.2 1996/04/04 02:43:28 paulus Exp $
+ * $Id: zlib.c,v 1.7 1997/05/22 06:44:39 paulus Exp $
  */
 
+/* 
+ *  ==FILEVERSION 970501==
+ *
+ * This marker is used by the Linux installation script to determine
+ * whether an up-to-date version of this file is already installed.
+ */
 
 /*+++++*/
 /* zutil.h -- internal interface and configuration of the compression library
 
 #include "zlib.h"
 
-#ifdef STDC
-#  include <string.h>
-#endif
-
 #ifndef local
 #  define local static
 #endif
@@ -86,9 +88,20 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
          /* functions */
 
 #if defined(KERNEL) || defined(_KERNEL)
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/systm.h>
 #  define zmemcpy(d, s, n)     bcopy((s), (d), (n))
 #  define zmemzero             bzero
+
 #else
+#if defined(__KERNEL__)
+/* Assume this is Linux */
+#include <linux/string.h>
+#define zmemcpy memcpy
+#define zmemzero(dest, len)    memset(dest, 0, len)
+
+#else /* not kernel */
 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
 #  define HAVE_MEMCPY
 #endif
@@ -99,7 +112,8 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
    extern void zmemcpy  OF((Bytef* dest, Bytef* source, uInt len));
    extern void zmemzero OF((Bytef* dest, uInt len));
 #endif
-#endif
+#endif /* __KERNEL__ */
+#endif /* KERNEL */
 
 /* Diagnostic functions */
 #ifdef DEBUG_ZLIB
@@ -130,6 +144,8 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
 
 #define ZALLOC(strm, items, size) \
            (*((strm)->zalloc))((strm)->opaque, (items), (size))
+#define ZALLOC_INIT(strm, items, size) \
+           (*((strm)->zalloc_init))((strm)->opaque, (items), (size))
 #define ZFREE(strm, addr, size)        \
           (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size))
 #define TRY_FREE(s, p, n) {if (p) ZFREE(s, p, n);}
@@ -153,7 +169,7 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
  */
 
 /* Data type */
-#define BINARY  0
+#define Z_BINARY  0
 #define ASCII   1
 #define UNKNOWN 2
 
@@ -226,7 +242,7 @@ typedef struct deflate_state {
     int   pending;       /* nb of bytes in the pending buffer */
     uLong adler;         /* adler32 of uncompressed data */
     int   noheader;      /* suppress zlib header and adler32 */
-    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */
+    Byte  data_type;     /* UNKNOWN, Z_BINARY or ASCII */
     Byte  method;        /* STORED (for zip only) or DEFLATED */
     int          minCompr;      /* min size decrease for Z_FLUSH_NOSTORE */
 
@@ -620,7 +636,7 @@ int deflateInit2 (strm, level, method, windowBits, memLevel,
         windowBits < 8 || windowBits > 15 || level < 1 || level > 9) {
         return Z_STREAM_ERROR;
     }
-    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
+    s = (deflate_state *) ZALLOC_INIT(strm, 1, sizeof(deflate_state));
     if (s == Z_NULL) return Z_MEM_ERROR;
     strm->state = (struct internal_state FAR *)s;
     s->strm = strm;
@@ -635,13 +651,13 @@ int deflateInit2 (strm, level, method, windowBits, memLevel,
     s->hash_mask = s->hash_size - 1;
     s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
 
-    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
-    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
-    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
+    s->window = (Bytef *) ZALLOC_INIT(strm, s->w_size, 2*sizeof(Byte));
+    s->prev   = (Posf *)  ZALLOC_INIT(strm, s->w_size, sizeof(Pos));
+    s->head   = (Posf *)  ZALLOC_INIT(strm, s->hash_size, sizeof(Pos));
 
     s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
 
-    s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush));
+    s->pending_buf = (uchf *) ZALLOC_INIT(strm, s->lit_bufsize, 2*sizeof(ush));
 
     if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
         s->pending_buf == Z_NULL) {
@@ -672,7 +688,8 @@ int deflateReset (strm)
     deflate_state *s;
     
     if (strm == Z_NULL || strm->state == Z_NULL ||
-        strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
+        strm->zalloc == Z_NULL || strm->zfree == Z_NULL ||
+       strm->zalloc_init == Z_NULL) return Z_STREAM_ERROR;
 
     strm->total_in = strm->total_out = 0;
     strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
@@ -2501,7 +2518,7 @@ local void compress_block(s, ltree, dtree)
 }
 
 /* ===========================================================================
- * Set the data type to ASCII or BINARY, using a crude approximation:
+ * Set the data type to ASCII or Z_BINARY, using a crude approximation:
  * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
  * IN assertion: the fields freq of dyn_ltree are set and the total of all
  * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
@@ -2515,7 +2532,7 @@ local void set_data_type(s)
     while (n < 7)        bin_freq += s->dyn_ltree[n++].Freq;
     while (n < 128)    ascii_freq += s->dyn_ltree[n++].Freq;
     while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
-    s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII);
+    s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : ASCII);
 }
 
 /* ===========================================================================
@@ -2814,7 +2831,7 @@ int w;
 /*  if (z->zalloc == Z_NULL) z->zalloc = zcalloc; */
 /*  if (z->zfree == Z_NULL) z->zfree = zcfree; */
   if ((z->state = (struct internal_state FAR *)
-       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
+       ZALLOC_INIT(z,1,sizeof(struct internal_state))) == Z_NULL)
     return Z_MEM_ERROR;
   z->state->blocks = Z_NULL;
 
@@ -3242,10 +3259,10 @@ uInt w;
 {
   inflate_blocks_statef *s;
 
-  if ((s = (inflate_blocks_statef *)ZALLOC
+  if ((s = (inflate_blocks_statef *)ZALLOC_INIT
        (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
     return s;
-  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
+  if ((s->window = (Bytef *)ZALLOC_INIT(z, 1, w)) == Z_NULL)
   {
     ZFREE(z, s, sizeof(struct inflate_blocks_state));
     return Z_NULL;