X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=common%2Fzlib.c;h=8883bac1fa7a47bbe2dd8281c83408f3fe8945f1;hp=ef226b525311a8917dcc877245fd835f0156c78e;hb=98516bb41580f3d34d750165e9a65289bc5ad248;hpb=fb9ffbf550b7921e4e965e088ceacded8b2dc4dd diff --git a/common/zlib.c b/common/zlib.c index ef226b5..8883bac 100644 --- a/common/zlib.c +++ b/common/zlib.c @@ -1,14 +1,25 @@ /* - * 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 @@ -21,16 +32,12 @@ 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 -#endif - #ifndef local # define local static #endif @@ -49,6 +56,10 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */ #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 @@ -77,9 +88,20 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */ /* functions */ #if defined(KERNEL) || defined(_KERNEL) +#include +#include +#include # define zmemcpy(d, s, n) bcopy((s), (d), (n)) # define zmemzero bzero + #else +#if defined(__KERNEL__) +/* Assume this is Linux */ +#include +#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 @@ -90,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 @@ -121,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);} @@ -137,14 +162,14 @@ typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len)); /*+++++*/ -/* $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 @@ -217,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 */ @@ -461,9 +486,9 @@ local void ct_stored_type_only OF((deflate_state *s)); * */ -/* $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 @@ -611,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; @@ -626,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) { @@ -663,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 */ @@ -1223,7 +1249,7 @@ local int deflate_fast(s, flush) 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; @@ -1319,7 +1345,7 @@ local int deflate_slow(s, flush) 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. */ @@ -1464,7 +1490,7 @@ local int deflate_slow(s, flush) * 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 @@ -2492,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). @@ -2506,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); } /* =========================================================================== @@ -2805,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; @@ -3201,7 +3227,7 @@ local uInt border[] = { /* Order of the bit length code lengths */ */ -void inflate_blocks_reset(s, z, c) +local void inflate_blocks_reset(s, z, c) inflate_blocks_statef *s; z_stream *z; uLongf *c; @@ -3226,17 +3252,17 @@ 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; @@ -3250,7 +3276,7 @@ uInt w; } -int inflate_blocks(s, z, r) +local int inflate_blocks(s, z, r) inflate_blocks_statef *s; z_stream *z; int r; @@ -3513,7 +3539,7 @@ 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; @@ -3887,7 +3913,7 @@ z_stream *zs; /* for zalloc function */ } -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 */ @@ -3908,7 +3934,7 @@ z_stream *z; /* for zfree function */ } -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 */ @@ -3993,7 +4019,7 @@ uInt n; } -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 */ @@ -4043,7 +4069,7 @@ inflate_huft * FAR *td; /* distance 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 @@ -4115,7 +4141,7 @@ struct inflate_codes_state { }; -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; @@ -4136,7 +4162,7 @@ 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; @@ -4296,7 +4322,7 @@ int r; } -void inflate_codes_free(c, z) +local void inflate_codes_free(c, z) inflate_codes_statef *c; z_stream *z; { @@ -4311,7 +4337,7 @@ 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; @@ -4402,7 +4428,7 @@ 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; @@ -4548,7 +4574,7 @@ z_stream *z; * 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; @@ -4569,7 +4595,7 @@ char *z_errmsg[] = { * 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