Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/ng_zlib.c
- This file was moved from sys/libkern/zlib.c.
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
/* From: zutil.h,v 1.16 1996/07/24 13:41:13 me Exp $ */ | /* From: zutil.h,v 1.16 1996/07/24 13:41:13 me Exp $ */ | ||||
#ifndef _Z_UTIL_H | #ifndef _Z_UTIL_H | ||||
#define _Z_UTIL_H | #define _Z_UTIL_H | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
#include <sys/zlib.h> | #include <netgraph/ng_zlib.h> | ||||
#else | #else | ||||
#include "zlib.h" | #include "zlib.h" | ||||
#endif | #endif | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
/* Assume this is a *BSD or SVR4 kernel */ | /* Assume this is a *BSD or SVR4 kernel */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
▲ Show 20 Lines • Show All 616 Lines • ▼ Show 20 Lines | |||||
/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ | /* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ | ||||
/* 5 */ {8, 16, 32, 32, deflate_slow}, | /* 5 */ {8, 16, 32, 32, deflate_slow}, | ||||
/* 6 */ {8, 16, 128, 128, deflate_slow}, | /* 6 */ {8, 16, 128, 128, deflate_slow}, | ||||
/* 7 */ {8, 32, 128, 256, deflate_slow}, | /* 7 */ {8, 32, 128, 256, deflate_slow}, | ||||
/* 8 */ {32, 128, 258, 1024, deflate_slow}, | /* 8 */ {32, 128, 258, 1024, deflate_slow}, | ||||
/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ | /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ | ||||
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 | /* Note: the ng_deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 | ||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different | * For deflate_fast() (levels <= 3) good is ignored and lazy has a different | ||||
* meaning. | * meaning. | ||||
*/ | */ | ||||
#define EQUAL 0 | #define EQUAL 0 | ||||
/* result of memcmp for equal strings */ | /* result of memcmp for equal strings */ | ||||
#ifndef NO_DUMMY_DECL | #ifndef NO_DUMMY_DECL | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | int deflateReset (strm) | ||||
strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ | strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ | ||||
strm->data_type = Z_UNKNOWN; | strm->data_type = Z_UNKNOWN; | ||||
s = (deflate_state *)strm->state; | s = (deflate_state *)strm->state; | ||||
s->pending = 0; | s->pending = 0; | ||||
s->pending_out = s->pending_buf; | s->pending_out = s->pending_buf; | ||||
if (s->noheader < 0) { | if (s->noheader < 0) { | ||||
s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ | s->noheader = 0; /* was set to -1 by ng_deflate(..., Z_FINISH); */ | ||||
} | } | ||||
s->status = s->noheader ? BUSY_STATE : INIT_STATE; | s->status = s->noheader ? BUSY_STATE : INIT_STATE; | ||||
strm->adler = 1; | strm->adler = 1; | ||||
s->last_flush = Z_NO_FLUSH; | s->last_flush = Z_NO_FLUSH; | ||||
_tr_init(s); | _tr_init(s); | ||||
lm_init(s); | lm_init(s); | ||||
Show All 18 Lines | level = 6; | ||||
} | } | ||||
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { | if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { | ||||
return Z_STREAM_ERROR; | return Z_STREAM_ERROR; | ||||
} | } | ||||
func = configuration_table[s->level].func; | func = configuration_table[s->level].func; | ||||
if (func != configuration_table[level].func && strm->total_in != 0) { | if (func != configuration_table[level].func && strm->total_in != 0) { | ||||
/* Flush the last buffer: */ | /* Flush the last buffer: */ | ||||
err = deflate(strm, Z_PARTIAL_FLUSH); | err = ng_deflate(strm, Z_PARTIAL_FLUSH); | ||||
} | } | ||||
if (s->level != level) { | if (s->level != level) { | ||||
s->level = level; | s->level = level; | ||||
s->max_lazy_match = configuration_table[level].max_lazy; | s->max_lazy_match = configuration_table[level].max_lazy; | ||||
s->good_match = configuration_table[level].good_length; | s->good_match = configuration_table[level].good_length; | ||||
s->nice_match = configuration_table[level].nice_length; | s->nice_match = configuration_table[level].nice_length; | ||||
s->max_chain_length = configuration_table[level].max_chain; | s->max_chain_length = configuration_table[level].max_chain; | ||||
} | } | ||||
Show All 10 Lines | local void putShortMSB (s, b) | ||||
deflate_state *s; | deflate_state *s; | ||||
uInt b; | uInt b; | ||||
{ | { | ||||
put_byte(s, (Byte)(b >> 8)); | put_byte(s, (Byte)(b >> 8)); | ||||
put_byte(s, (Byte)(b & 0xff)); | put_byte(s, (Byte)(b & 0xff)); | ||||
} | } | ||||
/* ========================================================================= | /* ========================================================================= | ||||
* Flush as much pending output as possible. All deflate() output goes | * Flush as much pending output as possible. All ng_deflate() output goes | ||||
* through this function so some applications may wish to modify it | * through this function so some applications may wish to modify it | ||||
* to avoid allocating a large strm->next_out buffer and copying into it. | * to avoid allocating a large strm->next_out buffer and copying into it. | ||||
* (See also read_buf()). | * (See also read_buf()). | ||||
*/ | */ | ||||
local void flush_pending(strm) | local void flush_pending(strm) | ||||
z_streamp strm; | z_streamp strm; | ||||
{ | { | ||||
deflate_state *s = (deflate_state *) strm->state; | deflate_state *s = (deflate_state *) strm->state; | ||||
Show All 11 Lines | strm->next_out += len; | ||||
strm->avail_out -= len; | strm->avail_out -= len; | ||||
s->pending -= len; | s->pending -= len; | ||||
if (s->pending == 0) { | if (s->pending == 0) { | ||||
s->pending_out = s->pending_buf; | s->pending_out = s->pending_buf; | ||||
} | } | ||||
} | } | ||||
/* ========================================================================= */ | /* ========================================================================= */ | ||||
int deflate (strm, flush) | int ng_deflate (strm, flush) | ||||
z_streamp strm; | z_streamp strm; | ||||
int flush; | int flush; | ||||
{ | { | ||||
int old_flush; /* value of flush param for previous deflate call */ | int old_flush; /* value of flush param for previous deflate call */ | ||||
deflate_state *s; | deflate_state *s; | ||||
if (strm == Z_NULL || strm->state == Z_NULL || | if (strm == Z_NULL || strm->state == Z_NULL || | ||||
flush > Z_FINISH || flush < 0) { | flush > Z_FINISH || flush < 0) { | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
if (strm == Z_NULL || strm->state == Z_NULL) return 0; | if (strm == Z_NULL || strm->state == Z_NULL) return 0; | ||||
return ((deflate_state *)(strm->state))->pending; | return ((deflate_state *)(strm->state))->pending; | ||||
} | } | ||||
/* =========================================================================== | /* =========================================================================== | ||||
* Read a new buffer from the current input stream, update the adler32 | * Read a new buffer from the current input stream, update the adler32 | ||||
* and total number of bytes read. All deflate() input goes through | * and total number of bytes read. All ng_deflate() input goes through | ||||
* this function so some applications may wish to modify it to avoid | * this function so some applications may wish to modify it to avoid | ||||
* allocating a large strm->next_in buffer and copying from it. | * allocating a large strm->next_in buffer and copying from it. | ||||
* (See also flush_pending()). | * (See also flush_pending()). | ||||
*/ | */ | ||||
local int read_buf(strm, buf, size) | local int read_buf(strm, buf, size) | ||||
z_streamp strm; | z_streamp strm; | ||||
charf *buf; | charf *buf; | ||||
unsigned size; | unsigned size; | ||||
▲ Show 20 Lines • Show All 1,971 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return inflateInit2_(z, DEF_WBITS, version, stream_size); | return inflateInit2_(z, DEF_WBITS, version, stream_size); | ||||
} | } | ||||
#define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;} | #define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;} | ||||
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) | #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) | ||||
int inflate(z, f) | int ng_inflate(z, f) | ||||
z_streamp z; | z_streamp z; | ||||
int f; | int f; | ||||
{ | { | ||||
int r; | int r; | ||||
uInt b; | uInt b; | ||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL || f < 0) | if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL || f < 0) | ||||
return Z_STREAM_ERROR; | return Z_STREAM_ERROR; | ||||
▲ Show 20 Lines • Show All 2,206 Lines • Show Last 20 Lines |