/*
- * This file is a conglomeration of various .h and .c files
- * from the zlib-0.95 library source, slightly hacked.
+ * This file is derived from various .h and .c files from the zlib-0.95
+ * distribution by Jean-loup Gailly and Mark Adler, with some additions
+ * by Paul Mackerras to aid in implementing Deflate compression and
+ * decompression for PPP packets. See zlib.h for conditions of
+ * distribution and use.
*
* Changes that have been made include:
* - changed functions not used outside this file to "local"
* - added minCompression parameter to deflateInit2
* - added Z_PACKET_FLUSH (see zlib.h for details)
* - added inflateIncomp
+ *
+ * $Id: zlib.c,v 1.6 1997/04/30 05:41:19 paulus Exp $
*/
+/*
+ * ==FILEVERSION 970421==
+ *
+ * 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
subject to change. Applications should only use zlib.h.
*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp */
#define _Z_UTIL_H
#include "zlib.h"
-#ifdef STDC
-# include <string.h>
-#endif
-
#ifndef local
# define local static
#endif
#define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
/* To be used only when the state is known to be valid */
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
/* common constants */
#define DEFLATED 8
/* 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
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
#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);}
/*+++++*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp */
/* ===========================================================================
* Internal compression state.
*/
/* Data type */
-#define BINARY 0
+#define Z_BINARY 0
#define ASCII 1
#define UNKNOWN 2
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 */
*
*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: deflate.c,v 1.8 1995/05/03 17:27:08 jloup Exp */
-local char copyright[] = " deflate Copyright 1995 Jean-loup Gailly ";
+local char zlib_copyright[] = " deflate Copyright 1995 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
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;
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) {
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 */
deflate_state *s;
int flush;
{
- IPos hash_head; /* head of the hash chain */
+ IPos hash_head = NIL; /* head of the hash chain */
int bflush; /* set if current block must be flushed */
s->prev_length = MIN_MATCH-1;
deflate_state *s;
int flush;
{
- IPos hash_head; /* head of hash chain */
+ IPos hash_head = NIL; /* head of hash chain */
int bflush; /* set if current block must be flushed */
/* Process the input block. */
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: trees.c,v 1.5 1995/05/03 17:27:12 jloup Exp */
#ifdef DEBUG_ZLIB
# include <ctype.h>
}
/* ===========================================================================
- * 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).
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);
}
/* ===========================================================================
/* 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;
*/
-void inflate_blocks_reset(s, z, c)
+local void inflate_blocks_reset(s, z, c)
inflate_blocks_statef *s;
z_stream *z;
uLongf *c;
}
-inflate_blocks_statef *inflate_blocks_new(z, c, w)
+local inflate_blocks_statef *inflate_blocks_new(z, c, w)
z_stream *z;
check_func c;
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;
}
-int inflate_blocks(s, z, r)
+local int inflate_blocks(s, z, r)
inflate_blocks_statef *s;
z_stream *z;
int r;
}
-int inflate_blocks_free(s, z, c)
+local int inflate_blocks_free(s, z, c)
inflate_blocks_statef *s;
z_stream *z;
uLongf *c;
}
-int inflate_trees_bits(c, bb, tb, z)
+local int inflate_trees_bits(c, bb, tb, z)
uIntf *c; /* 19 code lengths */
uIntf *bb; /* bits tree desired/actual depth */
inflate_huft * FAR *tb; /* bits tree result */
}
-int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
+local int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
uInt nl; /* number of literal/length codes */
uInt nd; /* number of distance codes */
uIntf *c; /* that many (total) code lengths */
}
-int inflate_trees_fixed(bl, bd, tl, td)
+local int inflate_trees_fixed(bl, bd, tl, td)
uIntf *bl; /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
}
-int inflate_trees_free(t, z)
+local int inflate_trees_free(t, z)
inflate_huft *t; /* table to free */
z_stream *z; /* for zfree function */
/* Free the malloc'ed tables built by huft_build(), which makes a linked
};
-inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
+local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
uInt bl, bd;
inflate_huft *tl, *td;
z_stream *z;
}
-int inflate_codes(s, z, r)
+local int inflate_codes(s, z, r)
inflate_blocks_statef *s;
z_stream *z;
int r;
}
-void inflate_codes_free(c, z)
+local void inflate_codes_free(c, z)
inflate_codes_statef *c;
z_stream *z;
{
*/
/* copy as much as possible from the sliding window to the output area */
-int inflate_flush(s, z, r)
+local int inflate_flush(s, z, r)
inflate_blocks_statef *s;
z_stream *z;
int r;
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer. */
-int inflate_fast(bl, bd, tl, td, s, z)
+local int inflate_fast(bl, bd, tl, td, s, z)
uInt bl, bd;
inflate_huft *tl, *td;
inflate_blocks_statef *s;
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */
char *zlib_version = ZLIB_VERSION;
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* $Id: zlib.c,v 1.1 1996/01/18 03:26:49 paulus Exp $ */
+/* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5552